1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_extensions.hxx" 30 31 32 #include <comphelper/processfactory.hxx> 33 #include <com/sun/star/awt/PosSize.hpp> 34 #include <com/sun/star/sdbc/XRowSet.hpp> 35 #include <com/sun/star/sdb/XColumn.hpp> 36 #include <com/sun/star/sdb/CommandType.hpp> 37 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> 38 #include <com/sun/star/form/ListSourceType.hpp> 39 #include <com/sun/star/awt/XWindow.hpp> 40 #include <toolkit/helper/vclunohelper.hxx> 41 #include <cppuhelper/implbase1.hxx> // helper for implementations 42 #include "general.hxx" 43 #include "sections.hrc" 44 #include "bibresid.hxx" 45 #include "datman.hxx" 46 #include "bibconfig.hxx" 47 #include "bibprop.hrc" 48 #include "bib.hrc" 49 #include "bibmod.hxx" 50 #include "bibtools.hxx" 51 #include "bibliography.hrc" 52 #include <tools/debug.hxx> 53 #include <vcl/mnemonic.hxx> 54 #include <vcl/svapp.hxx> 55 #include <vcl/i18nhelp.hxx> 56 #include <vcl/mnemonic.hxx> 57 #include <algorithm> 58 #include <functional> 59 #include <vector> 60 #include <tools/urlobj.hxx> 61 62 using namespace ::com::sun::star; 63 using namespace ::com::sun::star::uno; 64 using namespace ::com::sun::star::form; 65 using namespace ::com::sun::star::sdb; 66 using namespace ::rtl; 67 68 #define C2U(cChar) OUString::createFromAscii(cChar) 69 #define C2S(cChar) String::CreateFromAscii(cChar) 70 #define DISTANCE_CONTROL_TO_FIXEDTEXT 5 71 72 ::Point lcl_MovePoint(const FixedText& rFixedText) 73 { 74 ::Point aRet(rFixedText.GetPosPixel()); 75 aRet.X() += rFixedText.GetSizePixel().Width(); 76 aRet.X() += DISTANCE_CONTROL_TO_FIXEDTEXT; 77 return aRet; 78 } 79 80 //----------------------------------------------------------------------------- 81 OUString lcl_GetColumnName( const Mapping* pMapping, sal_uInt16 nIndexPos ) 82 { 83 BibConfig* pBibConfig = BibModul::GetConfig(); 84 OUString sRet = pBibConfig->GetDefColumnName(nIndexPos); 85 if(pMapping) 86 for(sal_uInt16 i = 0; i < COLUMN_COUNT; i++) 87 { 88 if(pMapping->aColumnPairs[i].sLogicalColumnName == sRet) 89 { 90 sRet = pMapping->aColumnPairs[i].sRealColumnName; 91 break; 92 } 93 } 94 return sRet; 95 } 96 /* -----------------------------04.01.00 10:54-------------------------------- 97 98 ---------------------------------------------------------------------------*/ 99 class BibPosListener :public cppu::WeakImplHelper1 <sdbc::XRowSetListener> 100 { 101 BibGeneralPage* pParentPage; 102 public: 103 BibPosListener(BibGeneralPage* pParent); 104 105 //XPositioningListener 106 virtual void SAL_CALL cursorMoved(const lang::EventObject& event) throw( uno::RuntimeException ); 107 virtual void SAL_CALL rowChanged(const lang::EventObject& /*event*/) throw( uno::RuntimeException ){ /* not interested in */ } 108 virtual void SAL_CALL rowSetChanged(const lang::EventObject& /*event*/) throw( uno::RuntimeException ){ /* not interested in */ } 109 110 //XEventListener 111 virtual void SAL_CALL disposing(const lang::EventObject& Source) throw( uno::RuntimeException ); 112 113 }; 114 /* -----------------------------04.01.00 10:57-------------------------------- 115 116 ---------------------------------------------------------------------------*/ 117 BibPosListener::BibPosListener(BibGeneralPage* pParent) : 118 pParentPage(pParent) 119 { 120 } 121 /* -----------------------------04.01.00 10:57-------------------------------- 122 123 ---------------------------------------------------------------------------*/ 124 void BibPosListener::cursorMoved(const lang::EventObject& /*aEvent*/) throw( uno::RuntimeException ) 125 { 126 try 127 { 128 uno::Reference< form::XBoundComponent > xLstBox = pParentPage->GetTypeListBoxModel(); 129 uno::Reference< beans::XPropertySet > xPropSet(xLstBox, UNO_QUERY); 130 if(xPropSet.is()) 131 { 132 BibConfig* pBibConfig = BibModul::GetConfig(); 133 BibDataManager* pDatMan = pParentPage->GetDataManager(); 134 BibDBDescriptor aDesc; 135 aDesc.sDataSource = pDatMan->getActiveDataSource(); 136 aDesc.sTableOrQuery = pDatMan->getActiveDataTable(); 137 aDesc.nCommandType = CommandType::TABLE; 138 139 const Mapping* pMapping = pBibConfig->GetMapping(aDesc); 140 OUString sTypeMapping = pBibConfig->GetDefColumnName(AUTHORITYTYPE_POS); 141 if(pMapping) 142 { 143 for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++) 144 { 145 if(pMapping->aColumnPairs[nEntry].sLogicalColumnName == sTypeMapping) 146 { 147 sTypeMapping = pMapping->aColumnPairs[nEntry].sRealColumnName; 148 break; 149 } 150 } 151 } 152 rtl::OUString uTypeMapping = sTypeMapping; 153 154 uno::Reference< form::XForm > xForm = pDatMan->getForm(); 155 uno::Reference< sdbcx::XColumnsSupplier > xSupplyCols(xForm, UNO_QUERY); 156 uno::Reference< container::XNameAccess > xValueAcc; 157 if (xSupplyCols.is()) 158 xValueAcc = xSupplyCols->getColumns(); 159 160 sal_Int16 nTempVal = -1; 161 if(xValueAcc.is() && xValueAcc->hasByName(uTypeMapping)) 162 { 163 uno::Any aVal = xValueAcc->getByName(uTypeMapping); 164 uno::Reference< uno::XInterface > xInt = *(uno::Reference< uno::XInterface > *)aVal.getValue(); 165 uno::Reference< sdb::XColumn > xCol(xInt, UNO_QUERY); 166 DBG_ASSERT(xCol.is(), "BibPosListener::positioned : invalid column (no sdb::XColumn) !"); 167 if (xCol.is()) 168 { 169 nTempVal = xCol->getShort(); 170 // getShort returns zero if the value is not a number 171 if (!nTempVal || xCol->wasNull()) 172 { 173 rtl::OUString sTempVal = xCol->getString(); 174 if(sTempVal != rtl::OUString('0')) 175 nTempVal = -1; 176 } 177 } 178 } 179 if(nTempVal < 0 || nTempVal >= TYPE_COUNT) 180 { 181 uno::Any aSel; 182 uno::Sequence<sal_Int16> aSelSeq(1); 183 sal_Int16* pArr = aSelSeq.getArray(); 184 pArr[0] = TYPE_COUNT; 185 aSel.setValue(&aSelSeq, ::getCppuType((Sequence<sal_Int16>*)0)); 186 xPropSet->setPropertyValue(C2U("SelectedItems"), aSel); 187 } 188 } 189 } 190 catch(Exception& rEx) 191 { 192 (void) rEx; // make compiler happy 193 DBG_ERROR("BibPosListener::positioned: something went wrong !"); 194 } 195 } 196 /* -----------------------------04.01.00 11:28-------------------------------- 197 198 ---------------------------------------------------------------------------*/ 199 void BibPosListener::disposing(const lang::EventObject& /*Source*/) throw( uno::RuntimeException ) 200 { 201 } 202 203 /* -----------------16.11.99 13:06------------------- 204 205 --------------------------------------------------*/ 206 BibGeneralPage::BibGeneralPage(Window* pParent, BibDataManager* pMan): 207 BibTabPage(pParent,BibResId(RID_TP_GENERAL)), 208 aControlParentWin(this, WB_DIALOGCONTROL), 209 aIdentifierFT(&aControlParentWin, BibResId(FT_IDENTIFIER )), 210 aAuthTypeFT(&aControlParentWin, BibResId(FT_AUTHTYPE )), 211 aYearFT(&aControlParentWin, BibResId(FT_YEAR )), 212 aAuthorFT(&aControlParentWin, BibResId(FT_AUTHOR )), 213 aTitleFT(&aControlParentWin, BibResId(FT_TITLE )), 214 aPublisherFT(&aControlParentWin, BibResId(FT_PUBLISHER )), 215 aAddressFT(&aControlParentWin, BibResId(FT_ADDRESS )), 216 aISBNFT(&aControlParentWin, BibResId(FT_ISBN )), 217 aChapterFT(&aControlParentWin, BibResId(FT_CHAPTER )), 218 aPagesFT(&aControlParentWin, BibResId(FT_PAGE )), 219 aFirstFL(&aControlParentWin, BibResId(FL_1 )), 220 aEditorFT(&aControlParentWin, BibResId(FT_EDITOR )), 221 aEditionFT(&aControlParentWin, BibResId(FT_EDITION )), 222 aBooktitleFT(&aControlParentWin, BibResId(FT_BOOKTITLE )), 223 aVolumeFT(&aControlParentWin, BibResId(FT_VOLUME )), 224 aHowpublishedFT(&aControlParentWin, BibResId(FT_HOWPUBLISHED )), 225 aOrganizationsFT(&aControlParentWin,BibResId(FT_ORGANIZATION )), 226 aInstitutionFT(&aControlParentWin, BibResId(FT_INSTITUTION )), 227 aSchoolFT(&aControlParentWin, BibResId(FT_SCHOOL )), 228 aReportTypeFT(&aControlParentWin, BibResId(FT_REPORT )), 229 aMonthFT(&aControlParentWin, BibResId(FT_MONTH )), 230 aSecondFL(&aControlParentWin, BibResId(FL_2 )), 231 aJournalFT(&aControlParentWin, BibResId(FT_JOURNAL )), 232 aNumberFT(&aControlParentWin, BibResId(FT_NUMBER )), 233 aSeriesFT(&aControlParentWin, BibResId(FT_SERIES )), 234 aAnnoteFT(&aControlParentWin, BibResId(FT_ANNOTE )), 235 aNoteFT(&aControlParentWin, BibResId(FT_NOTE )), 236 aURLFT(&aControlParentWin, BibResId(FT_URL )), 237 aThirdFL(&aControlParentWin, BibResId(FL_3 )), 238 aCustom1FT(&aControlParentWin, BibResId(FT_CUSTOM1 )), 239 aCustom2FT(&aControlParentWin, BibResId(FT_CUSTOM2 )), 240 aCustom3FT(&aControlParentWin, BibResId(FT_CUSTOM3 )), 241 aCustom4FT(&aControlParentWin, BibResId(FT_CUSTOM4 )), 242 aCustom5FT(&aControlParentWin, BibResId(FT_CUSTOM5 )), 243 aHoriScroll(this, WB_HORZ), 244 aVertScroll(this, WB_VERT), 245 sErrorPrefix(BibResId(ST_ERROR_PREFIX)), 246 pDatMan(pMan) 247 { 248 aControlParentWin.Show(); 249 aControlParentWin.SetHelpId(HID_BIB_CONTROL_PARENT); 250 aStdSize = GetOutputSizePixel(); 251 252 aBibTypeArr[0] = String(BibResId(ST_TYPE_ARTICLE)); 253 aBibTypeArr[1] = String(BibResId(ST_TYPE_BOOK)); 254 aBibTypeArr[2] = String(BibResId(ST_TYPE_BOOKLET)); 255 aBibTypeArr[3] = String(BibResId(ST_TYPE_CONFERENCE)); 256 aBibTypeArr[4] = String(BibResId(ST_TYPE_INBOOK )); 257 aBibTypeArr[5] = String(BibResId(ST_TYPE_INCOLLECTION)); 258 aBibTypeArr[6] = String(BibResId(ST_TYPE_INPROCEEDINGS)); 259 aBibTypeArr[7] = String(BibResId(ST_TYPE_JOURNAL )); 260 aBibTypeArr[8] = String(BibResId(ST_TYPE_MANUAL )); 261 aBibTypeArr[9] = String(BibResId(ST_TYPE_MASTERSTHESIS)); 262 aBibTypeArr[10] = String(BibResId(ST_TYPE_MISC )); 263 aBibTypeArr[11] = String(BibResId(ST_TYPE_PHDTHESIS )); 264 aBibTypeArr[12] = String(BibResId(ST_TYPE_PROCEEDINGS )); 265 aBibTypeArr[13] = String(BibResId(ST_TYPE_TECHREPORT )); 266 aBibTypeArr[14] = String(BibResId(ST_TYPE_UNPUBLISHED )); 267 aBibTypeArr[15] = String(BibResId(ST_TYPE_EMAIL )); 268 aBibTypeArr[16] = String(BibResId(ST_TYPE_WWW )); 269 aBibTypeArr[17] = String(BibResId(ST_TYPE_CUSTOM1 )); 270 aBibTypeArr[18] = String(BibResId(ST_TYPE_CUSTOM2 )); 271 aBibTypeArr[19] = String(BibResId(ST_TYPE_CUSTOM3 )); 272 aBibTypeArr[20] = String(BibResId(ST_TYPE_CUSTOM4 )); 273 aBibTypeArr[21] = String(BibResId(ST_TYPE_CUSTOM5 )); 274 275 FreeResource(); 276 277 InitFixedTexts(); 278 279 aBasePos = aIdentifierFT.GetPosPixel(); 280 281 sal_Int16* pMap = nFT2CtrlMap; 282 for( sal_uInt16 i = 0 ; i < FIELD_COUNT ; ++i, ++pMap ) 283 { 284 aControls[ i ] = 0; 285 *pMap = -1; 286 } 287 288 AdjustScrollbars(); 289 Link aScrollLnk(LINK(this, BibGeneralPage, ScrollHdl)); 290 aHoriScroll.SetScrollHdl( aScrollLnk ); 291 aVertScroll.SetScrollHdl( aScrollLnk ); 292 aHoriScroll.SetLineSize(10); 293 aVertScroll.SetLineSize(10); 294 aHoriScroll.SetPageSize( aIdentifierFT.GetSizePixel().Width()); 295 aVertScroll.SetPageSize( 296 aPublisherFT.GetPosPixel().Y() - aIdentifierFT.GetPosPixel().Y()); 297 aHoriScroll.Show(); 298 aVertScroll.Show(); 299 300 BibConfig* pBibConfig = BibModul::GetConfig(); 301 BibDBDescriptor aDesc; 302 aDesc.sDataSource = pDatMan->getActiveDataSource(); 303 aDesc.sTableOrQuery = pDatMan->getActiveDataTable(); 304 aDesc.nCommandType = CommandType::TABLE; 305 const Mapping* pMapping = pBibConfig->GetMapping(aDesc); 306 307 xCtrlContnr = VCLUnoHelper::CreateControlContainer(&aControlParentWin); 308 309 xMgr = comphelper::getProcessServiceFactory(); 310 // the control should be a bit smaller than the fixed text 311 Size aControlSize(aIdentifierFT.GetSizePixel()); 312 aControlSize.Width() = aControlSize.Width() * 8 / 10; 313 314 AddControlWithError( lcl_GetColumnName( pMapping, IDENTIFIER_POS ), lcl_MovePoint( aIdentifierFT ), 315 aControlSize, sTableErrorString, aIdentifierFT.GetText(), 316 HID_BIB_IDENTIFIER_POS, 0 ); 317 318 sTypeColumnName = lcl_GetColumnName(pMapping, AUTHORITYTYPE_POS); 319 320 AddControlWithError( sTypeColumnName, lcl_MovePoint(aAuthTypeFT ), aControlSize, sTableErrorString, 321 aAuthTypeFT.GetText(), HID_BIB_AUTHORITYTYPE_POS, 1 ); 322 323 ::Point aYearPos = lcl_MovePoint(aYearFT); 324 AddControlWithError( lcl_GetColumnName( pMapping, YEAR_POS ), aYearPos, 325 aControlSize, sTableErrorString, aYearFT.GetText(), HID_BIB_YEAR_POS, 4 ); 326 327 AddControlWithError( lcl_GetColumnName(pMapping, AUTHOR_POS), lcl_MovePoint(aAuthorFT), 328 aControlSize, sTableErrorString, aAuthorFT.GetText(), HID_BIB_AUTHOR_POS, 2 ); 329 330 ::Point aTitlePos( lcl_MovePoint( aTitleFT ) ); 331 ::Size aTitleSize = aTitleFT.GetSizePixel(); 332 aTitleSize.Width() = aYearPos.X() + aControlSize.Width() - aTitlePos.X(); 333 AddControlWithError( lcl_GetColumnName(pMapping, TITLE_POS), aTitlePos, aTitleSize, sTableErrorString, 334 aTitleFT.GetText(), HID_BIB_TITLE_POS, 22 ); 335 336 AddControlWithError( lcl_GetColumnName( pMapping, PUBLISHER_POS ), lcl_MovePoint( aPublisherFT), 337 aControlSize, sTableErrorString, aPublisherFT.GetText(), HID_BIB_PUBLISHER_POS, 5 ); 338 339 AddControlWithError( lcl_GetColumnName( pMapping, ADDRESS_POS ), lcl_MovePoint( aAddressFT ), 340 aControlSize, sTableErrorString, aAddressFT.GetText(), HID_BIB_ADDRESS_POS, 7 ); 341 342 AddControlWithError( lcl_GetColumnName( pMapping, ISBN_POS ), lcl_MovePoint( aISBNFT ), 343 aControlSize, sTableErrorString, aISBNFT.GetText(), HID_BIB_ISBN_POS, 6 ); 344 345 AddControlWithError( lcl_GetColumnName( pMapping, CHAPTER_POS ), lcl_MovePoint(aChapterFT), 346 aControlSize, sTableErrorString, aChapterFT.GetText(), HID_BIB_CHAPTER_POS, 10 ); 347 348 AddControlWithError( lcl_GetColumnName( pMapping, PAGES_POS ), lcl_MovePoint( aPagesFT ), 349 aControlSize, sTableErrorString, aPagesFT.GetText(), HID_BIB_PAGES_POS, 19 ); 350 351 AddControlWithError( lcl_GetColumnName( pMapping, EDITOR_POS ), lcl_MovePoint( aEditorFT ), 352 aControlSize, sTableErrorString, aEditorFT.GetText(), HID_BIB_EDITOR_POS, 12 ); 353 354 AddControlWithError( lcl_GetColumnName( pMapping, EDITION_POS ), lcl_MovePoint(aEditionFT), 355 aControlSize, sTableErrorString, aEditionFT.GetText(), HID_BIB_EDITION_POS, 11 ); 356 357 AddControlWithError( lcl_GetColumnName(pMapping, BOOKTITLE_POS), lcl_MovePoint(aBooktitleFT), 358 aControlSize, sTableErrorString, aBooktitleFT.GetText(), HID_BIB_BOOKTITLE_POS, 9 ); 359 360 AddControlWithError( lcl_GetColumnName( pMapping, VOLUME_POS ), lcl_MovePoint( aVolumeFT ), 361 aControlSize, sTableErrorString, aVolumeFT.GetText(), HID_BIB_VOLUME_POS, 24 ); 362 363 AddControlWithError( lcl_GetColumnName( pMapping, HOWPUBLISHED_POS ), lcl_MovePoint( aHowpublishedFT ), 364 aControlSize, sTableErrorString, aHowpublishedFT.GetText(), HID_BIB_HOWPUBLISHED_POS, 13 ); 365 366 AddControlWithError( lcl_GetColumnName( pMapping, ORGANIZATIONS_POS ), lcl_MovePoint( aOrganizationsFT ), 367 aControlSize, sTableErrorString, aOrganizationsFT.GetText(), HID_BIB_ORGANIZATIONS_POS, 18 ); 368 369 AddControlWithError( lcl_GetColumnName( pMapping, INSTITUTION_POS ), lcl_MovePoint( aInstitutionFT ), 370 aControlSize, sTableErrorString, aInstitutionFT.GetText(), HID_BIB_INSTITUTION_POS, 14 ); 371 372 AddControlWithError( lcl_GetColumnName( pMapping, SCHOOL_POS ), lcl_MovePoint( aSchoolFT ), 373 aControlSize, sTableErrorString, aSchoolFT.GetText(), HID_BIB_SCHOOL_POS, 20 ); 374 375 AddControlWithError( lcl_GetColumnName( pMapping, REPORTTYPE_POS ), lcl_MovePoint( aReportTypeFT ), 376 aControlSize, sTableErrorString, aReportTypeFT.GetText(), HID_BIB_REPORTTYPE_POS, 23 ); 377 378 AddControlWithError( lcl_GetColumnName( pMapping, MONTH_POS ), lcl_MovePoint( aMonthFT ), 379 aControlSize, sTableErrorString, aMonthFT.GetText(), HID_BIB_MONTH_POS, 3 ); 380 381 AddControlWithError( lcl_GetColumnName( pMapping, JOURNAL_POS ), lcl_MovePoint( aJournalFT ), 382 aControlSize, sTableErrorString, aJournalFT.GetText(), HID_BIB_JOURNAL_POS, 15 ); 383 384 AddControlWithError( lcl_GetColumnName( pMapping, NUMBER_POS ), lcl_MovePoint( aNumberFT ), 385 aControlSize, sTableErrorString, aNumberFT.GetText(), HID_BIB_NUMBER_POS, 17 ); 386 387 AddControlWithError( lcl_GetColumnName( pMapping, SERIES_POS ), lcl_MovePoint( aSeriesFT ), 388 aControlSize, sTableErrorString, aSeriesFT.GetText(), HID_BIB_SERIES_POS, 21 ); 389 390 AddControlWithError( lcl_GetColumnName( pMapping, ANNOTE_POS ), lcl_MovePoint( aAnnoteFT ), 391 aControlSize, sTableErrorString, aAnnoteFT.GetText(), HID_BIB_ANNOTE_POS, 8 ); 392 393 AddControlWithError( lcl_GetColumnName( pMapping, NOTE_POS ), lcl_MovePoint( aNoteFT ), 394 aControlSize, sTableErrorString, aNoteFT.GetText(), HID_BIB_NOTE_POS, 16 ); 395 396 AddControlWithError( lcl_GetColumnName( pMapping, URL_POS ), lcl_MovePoint( aURLFT ), 397 aControlSize, sTableErrorString, aURLFT.GetText(), HID_BIB_URL_POS, 25 ); 398 399 AddControlWithError( lcl_GetColumnName( pMapping, CUSTOM1_POS ), lcl_MovePoint( aCustom1FT ), 400 aControlSize, sTableErrorString, aCustom1FT.GetText(), HID_BIB_CUSTOM1_POS, 26 ); 401 402 AddControlWithError( lcl_GetColumnName( pMapping, CUSTOM2_POS ), lcl_MovePoint( aCustom2FT ), 403 aControlSize, sTableErrorString, aCustom2FT.GetText(), HID_BIB_CUSTOM2_POS, 27 ); 404 405 AddControlWithError( lcl_GetColumnName( pMapping, CUSTOM3_POS ), lcl_MovePoint( aCustom3FT ), 406 aControlSize, sTableErrorString, aCustom3FT.GetText(), HID_BIB_CUSTOM3_POS, 28 ); 407 408 AddControlWithError( lcl_GetColumnName( pMapping, CUSTOM4_POS ), lcl_MovePoint( aCustom4FT ), 409 aControlSize, sTableErrorString, aCustom4FT.GetText(), HID_BIB_CUSTOM4_POS, 29 ); 410 411 AddControlWithError( lcl_GetColumnName( pMapping, CUSTOM5_POS ), lcl_MovePoint( aCustom5FT ), 412 aControlSize, sTableErrorString, aCustom5FT.GetText(), HID_BIB_CUSTOM5_POS, 30 ); 413 414 xPosListener = new BibPosListener(this); 415 uno::Reference< sdbc::XRowSet > xRowSet(pDatMan->getForm(), UNO_QUERY); 416 if(xRowSet.is()) 417 xRowSet->addRowSetListener(xPosListener); 418 uno::Reference< form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController(); 419 xFormCtrl->setContainer(xCtrlContnr); 420 xFormCtrl->activateTabOrder(); 421 422 if(sTableErrorString.Len()) 423 sTableErrorString.Insert(sErrorPrefix, 0); 424 } 425 //----------------------------------------------------------------------------- 426 BibGeneralPage::~BibGeneralPage() 427 { 428 if (pDatMan && xPosListener.is()) 429 { 430 uno::Reference< sdbc::XRowSet > xRowSet(pDatMan->getForm(), UNO_QUERY); 431 if(xRowSet.is()) 432 xRowSet->removeRowSetListener(xPosListener); 433 } 434 } 435 /* -----------------------------14.04.00 13:11-------------------------------- 436 437 ---------------------------------------------------------------------------*/ 438 void BibGeneralPage::RemoveListeners() 439 { 440 for(sal_uInt16 i = 0; i < FIELD_COUNT; i++) 441 { 442 if(aControls[i].is()) 443 { 444 uno::Reference< awt::XWindow > xCtrWin(aControls[i], uno::UNO_QUERY ); 445 xCtrWin->removeFocusListener( this ); 446 aControls[i] = 0; 447 } 448 } 449 } 450 /* -----------------------------21.01.00 17:05-------------------------------- 451 452 ---------------------------------------------------------------------------*/ 453 void BibGeneralPage::CommitActiveControl() 454 { 455 uno::Reference< form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController(); 456 uno::Reference< awt::XControl > xCurr = xFormCtrl->getCurrentControl(); 457 if(xCurr.is()) 458 { 459 uno::Reference< awt::XControlModel > xModel = xCurr->getModel(); 460 uno::Reference< form::XBoundComponent > xBound(xModel, UNO_QUERY); 461 if(xBound.is()) 462 xBound->commit(); 463 } 464 } 465 //----------------------------------------------------------------------------- 466 void BibGeneralPage::AddControlWithError( const OUString& rColumnName, const ::Point& rPos, const ::Size& rSize, 467 String& rErrorString, String aColumnUIName, const rtl::OString& sHelpId, sal_uInt16 nIndexInFTArray ) 468 { 469 // adds also the XControl and creates a map entry in nFT2CtrlMap[] for mapping between control and FT 470 471 sal_Int16 nIndex = -1; 472 uno::Reference< awt::XControlModel > xTmp = AddXControl(rColumnName, rPos, rSize, sHelpId, nIndex ); 473 if( xTmp.is() ) 474 { 475 DBG_ASSERT( nIndexInFTArray < FIELD_COUNT, "*BibGeneralPage::AddControlWithError(): wrong array index!" ); 476 DBG_ASSERT( nFT2CtrlMap[ nIndexInFTArray ] < 0, "+BibGeneralPage::AddControlWithError(): index already in use!" ); 477 478 nFT2CtrlMap[ nIndexInFTArray ] = nIndex; 479 } 480 else 481 { 482 if( rErrorString.Len() ) 483 rErrorString += '\n'; 484 485 rErrorString += MnemonicGenerator::EraseAllMnemonicChars( aColumnUIName ); 486 } 487 } 488 //----------------------------------------------------------------------------- 489 uno::Reference< awt::XControlModel > BibGeneralPage::AddXControl( 490 const String& rName, 491 ::Point rPos, ::Size rSize, const rtl::OString& sHelpId, sal_Int16& rIndex ) 492 { 493 uno::Reference< awt::XControlModel > xCtrModel; 494 try 495 { 496 sal_Bool bTypeListBox = sTypeColumnName == rName; 497 xCtrModel = pDatMan->loadControlModel(rName, bTypeListBox); 498 if ( xCtrModel.is() && xMgr.is()) 499 { 500 uno::Reference< beans::XPropertySet > xPropSet( xCtrModel, UNO_QUERY ); 501 502 if( xPropSet.is()) 503 { 504 uno::Reference< beans::XPropertySetInfo > xPropInfo = xPropSet->getPropertySetInfo(); 505 506 uno::Any aAny = xPropSet->getPropertyValue( C2U("DefaultControl") ); 507 rtl::OUString aControlName; 508 aAny >>= aControlName; 509 510 rtl::OUString uProp(C2U("HelpURL")); 511 if(xPropInfo->hasPropertyByName(uProp)) 512 { 513 ::rtl::OUString sId = ::rtl::OUString::createFromAscii( INET_HID_SCHEME ); 514 DBG_ASSERT( INetURLObject( rtl::OStringToOUString( sHelpId, RTL_TEXTENCODING_UTF8 ) ).GetProtocol() == INET_PROT_NOT_VALID, "Wrong HelpId!" ); 515 sId += ::rtl::OUString( sHelpId, sHelpId.getLength(), RTL_TEXTENCODING_UTF8 ); 516 xPropSet->setPropertyValue( uProp, makeAny( sId ) ); 517 } 518 519 if(bTypeListBox) 520 { 521 //uno::Reference< beans::XPropertySet > xPropSet(xControl, UNO_QUERY); 522 aAny <<= (sal_Int16)1; 523 xPropSet->setPropertyValue(C2U("BoundColumn"), aAny); 524 ListSourceType eSet = ListSourceType_VALUELIST; 525 aAny.setValue( &eSet, ::getCppuType((const ListSourceType*)0) ); 526 xPropSet->setPropertyValue(C2U("ListSourceType"), aAny); 527 528 uno::Sequence<rtl::OUString> aListSource(TYPE_COUNT); 529 rtl::OUString* pListSourceArr = aListSource.getArray(); 530 //pListSourceArr[0] = C2U("select TypeName, TypeIndex from TypeNms"); 531 for(sal_uInt16 i = 0; i < TYPE_COUNT; i++) 532 pListSourceArr[i] = String::CreateFromInt32(i); 533 aAny.setValue(&aListSource, ::getCppuType((uno::Sequence<rtl::OUString>*)0)); 534 535 xPropSet->setPropertyValue(C2U("ListSource"), aAny); 536 537 uno::Sequence<rtl::OUString> aValues(TYPE_COUNT + 1); 538 rtl::OUString* pValuesArr = aValues.getArray(); 539 for(sal_uInt16 j = 0; j < TYPE_COUNT; j++) 540 pValuesArr[j] = aBibTypeArr[j]; 541 // empty string if an invalid value no values is set 542 pValuesArr[TYPE_COUNT] = rtl::OUString(); 543 544 aAny.setValue(&aValues, ::getCppuType((uno::Sequence<rtl::OUString>*)0)); 545 546 xPropSet->setPropertyValue(C2U("StringItemList"), aAny); 547 548 sal_Bool bTrue = sal_True; 549 aAny.setValue( &bTrue, ::getBooleanCppuType() ); 550 xPropSet->setPropertyValue( C2U("Dropdown"), aAny ); 551 552 aControlName = C2U("com.sun.star.form.control.ListBox"); 553 xLBModel = Reference< form::XBoundComponent >(xCtrModel, UNO_QUERY); 554 555 } 556 557 uno::Reference< awt::XControl > xControl(xMgr->createInstance( aControlName ), UNO_QUERY ); 558 if ( xControl.is() ) 559 { 560 xControl->setModel( xCtrModel); 561 562 // Peer als Child zu dem FrameWindow 563 xCtrlContnr->addControl(rName, xControl); 564 uno::Reference< awt::XWindow > xCtrWin(xControl, UNO_QUERY ); 565 xCtrWin->addFocusListener( this ); 566 rIndex = -1; // -> implies, that not found 567 for(sal_uInt16 i = 0; i < FIELD_COUNT; i++) 568 if(!aControls[i].is()) 569 { 570 aControls[i] = xCtrWin; 571 rIndex = sal_Int16( i ); 572 break; 573 } 574 xCtrWin->setVisible( sal_True ); 575 xControl->setDesignMode( sal_True ); 576 // initially switch on the desing mode - switch it off _after_ loading the form 577 // 17.10.2001 - 93107 - frank.schoenheit@sun.com 578 579 xCtrWin->setPosSize(rPos.X(), rPos.Y(), rSize.Width(), 580 rSize.Height(), awt::PosSize::POSSIZE); 581 } 582 } 583 } 584 } 585 catch(Exception& rEx) 586 { 587 (void) rEx; // make compiler happy 588 DBG_ERROR("BibGeneralPage::AddXControl: something went wrong !"); 589 } 590 return xCtrModel; 591 } 592 593 void BibGeneralPage::AdjustScrollbars() 594 { 595 long nVertScrollWidth = aVertScroll.GetSizePixel().Width(); 596 long nHoriScrollHeight = aHoriScroll.GetSizePixel().Height(); 597 ::Size aOutSize(GetOutputSizePixel()); 598 sal_Bool bHoriVisible = aOutSize.Width() <= aStdSize.Width(); 599 sal_Bool bVertVisible = (aOutSize.Height()-(bHoriVisible ? nHoriScrollHeight : 0)) <= (aStdSize.Height()); 600 aHoriScroll.Show(bHoriVisible); 601 aVertScroll.Show(bVertVisible); 602 603 if(bHoriVisible) 604 { 605 ::Size aHoriSize(aOutSize.Width() - (bVertVisible ? nVertScrollWidth : 0), 606 nHoriScrollHeight); 607 aHoriScroll.SetSizePixel(aHoriSize); 608 aHoriScroll.SetRange( Range(0, aStdSize.Width())); 609 aHoriScroll.SetVisibleSize( aHoriSize.Width() - (bVertVisible ? nVertScrollWidth : 0)); 610 } 611 if(bVertVisible) 612 { 613 ::Size aVertSize(nHoriScrollHeight, aOutSize.Height() - 614 (bHoriVisible ? nHoriScrollHeight : 0)); 615 aVertScroll.SetSizePixel(aVertSize); 616 aVertScroll.SetRange( Range(0, aStdSize.Height())); 617 aVertScroll.SetVisibleSize( aVertSize.Height() ); 618 } 619 620 ::Size aSize(8, 8); 621 aSize = LogicToPixel(aSize, MapMode(MAP_APPFONT)); 622 ::Size aScrollSize(aOutSize.Width() - aSize.Height(), aSize.Height()); 623 ::Point aScrollPos(0, aOutSize.Height() - aSize.Height()); 624 aHoriScroll.SetPosSizePixel(aScrollPos, aScrollSize); 625 626 aScrollPos.X() = aOutSize.Width() - aSize.Width(); 627 aScrollPos.Y() = 0; 628 aScrollSize.Width() = aSize.Width(); 629 aScrollSize.Height() = aOutSize.Height() - aSize.Height(); 630 aVertScroll.SetPosSizePixel(aScrollPos, aScrollSize); 631 632 ::Size aControlParentWinSz(aOutSize); 633 if(bHoriVisible) 634 aControlParentWinSz.Height() -= aSize.Height(); 635 if(bVertVisible) 636 aControlParentWinSz.Width() -= aSize.Width(); 637 aControlParentWin.SetSizePixel(aControlParentWinSz); 638 } 639 640 void BibGeneralPage::Resize() 641 { 642 AdjustScrollbars(); 643 ScrollHdl(&aVertScroll); 644 ScrollHdl(&aHoriScroll); 645 Window::Resize(); 646 } 647 648 void BibGeneralPage::InitFixedTexts( void ) 649 { 650 String aFixedStrings[ FIELD_COUNT ] = 651 { 652 String( BibResId( ST_IDENTIFIER ) ), 653 String( BibResId( ST_AUTHTYPE ) ), 654 String( BibResId( ST_AUTHOR ) ), 655 String( BibResId( ST_TITLE ) ), 656 String( BibResId( ST_MONTH ) ), 657 String( BibResId( ST_YEAR ) ), 658 String( BibResId( ST_ISBN ) ), 659 String( BibResId( ST_BOOKTITLE ) ), 660 String( BibResId( ST_CHAPTER ) ), 661 String( BibResId( ST_EDITION ) ), 662 String( BibResId( ST_EDITOR ) ), 663 String( BibResId( ST_HOWPUBLISHED ) ), 664 String( BibResId( ST_INSTITUTION ) ), 665 String( BibResId( ST_JOURNAL ) ), 666 String( BibResId( ST_NOTE ) ), 667 String( BibResId( ST_ANNOTE ) ), 668 String( BibResId( ST_NUMBER ) ), 669 String( BibResId( ST_ORGANIZATION ) ), 670 String( BibResId( ST_PAGE ) ), 671 String( BibResId( ST_PUBLISHER ) ), 672 String( BibResId( ST_ADDRESS ) ), 673 String( BibResId( ST_SCHOOL ) ), 674 String( BibResId( ST_SERIES ) ), 675 String( BibResId( ST_REPORT ) ), 676 String( BibResId( ST_VOLUME ) ), 677 String( BibResId( ST_URL ) ), 678 String( BibResId( ST_CUSTOM1 ) ), 679 String( BibResId( ST_CUSTOM2 ) ), 680 String( BibResId( ST_CUSTOM3 ) ), 681 String( BibResId( ST_CUSTOM4 ) ), 682 String( BibResId( ST_CUSTOM5 ) ) 683 }; 684 685 aFixedTexts[0] = &aIdentifierFT; 686 aFixedTexts[1] = &aAuthTypeFT; 687 aFixedTexts[2] = &aAuthorFT; 688 aFixedTexts[3] = &aTitleFT; 689 aFixedTexts[4] = &aMonthFT; 690 aFixedTexts[5] = &aYearFT; 691 aFixedTexts[6] = &aISBNFT; 692 aFixedTexts[7] = &aBooktitleFT; 693 aFixedTexts[8] = &aChapterFT; 694 aFixedTexts[9] = &aEditionFT; 695 aFixedTexts[10] = &aEditorFT; 696 aFixedTexts[11] = &aHowpublishedFT; 697 aFixedTexts[12] = &aInstitutionFT; 698 aFixedTexts[13] = &aJournalFT; 699 aFixedTexts[14] = &aNoteFT; 700 aFixedTexts[15] = &aAnnoteFT; 701 aFixedTexts[16] = &aNumberFT; 702 aFixedTexts[17] = &aOrganizationsFT; 703 aFixedTexts[18] = &aPagesFT; 704 aFixedTexts[19] = &aPublisherFT; 705 aFixedTexts[20] = &aAddressFT; 706 aFixedTexts[21] = &aSchoolFT; 707 aFixedTexts[22] = &aSeriesFT; 708 aFixedTexts[23] = &aReportTypeFT; 709 aFixedTexts[24] = &aVolumeFT; 710 aFixedTexts[25] = &aURLFT; 711 aFixedTexts[26] = &aCustom1FT; 712 aFixedTexts[27] = &aCustom2FT; 713 aFixedTexts[28] = &aCustom3FT; 714 aFixedTexts[29] = &aCustom4FT; 715 aFixedTexts[30] = &aCustom5FT; 716 717 int i; 718 719 MnemonicGenerator aMnemonicGenerator; 720 // init mnemonics, first register all strings 721 for( i = 0 ; i < FIELD_COUNT ; ++i ) 722 aMnemonicGenerator.RegisterMnemonic( aFixedStrings[ i ] ); 723 724 // ... then get all strings 725 for( i = 0 ; i < FIELD_COUNT ; ++i ) 726 aMnemonicGenerator.CreateMnemonic( aFixedStrings[ i ] ); 727 728 // set texts 729 for( i = 0 ; i < FIELD_COUNT ; ++i ) 730 aFixedTexts[ i ]->SetText( aFixedStrings[ i ] ); 731 } 732 733 IMPL_LINK(BibGeneralPage, ScrollHdl, ScrollBar*, pScroll) 734 { 735 sal_Bool bVertical = &aVertScroll == pScroll; 736 long nOffset = 0; 737 long nCurrentOffset = 0; 738 if(bVertical) 739 nCurrentOffset = aFixedTexts[0]->GetPosPixel().Y() - aBasePos.Y(); 740 else 741 nCurrentOffset = aFixedTexts[0]->GetPosPixel().X() - aBasePos.X(); 742 nOffset = pScroll->IsVisible() ? pScroll->GetThumbPos() + nCurrentOffset : nCurrentOffset;; 743 744 for(sal_uInt16 i = 0; i < FIELD_COUNT; i++) 745 { 746 ::Point aPos = aFixedTexts[i]->GetPosPixel(); 747 if(bVertical) 748 aPos.Y() -= nOffset; 749 else 750 aPos.X() -= nOffset; 751 aFixedTexts[i]->SetPosPixel(aPos); 752 if(aControls[i].is()) 753 { 754 awt::Rectangle aRect = aControls[i]->getPosSize(); 755 long nX = aRect.X; 756 long nY = aRect.Y; 757 if(bVertical) 758 nY -= nOffset; 759 else 760 nX -= nOffset; 761 aControls[i]->setPosSize(nX, nY, 0, 0, awt::PosSize::POS); 762 } 763 } 764 return 0; 765 } 766 767 void BibGeneralPage::focusGained(const awt::FocusEvent& rEvent) throw( uno::RuntimeException ) 768 { 769 Reference<awt::XWindow> xCtrWin(rEvent.Source, UNO_QUERY ); 770 if(xCtrWin.is()) 771 { 772 ::Size aOutSize = aControlParentWin.GetOutputSizePixel(); 773 awt::Rectangle aRect = xCtrWin->getPosSize(); 774 long nX = aRect.X; 775 if(nX < 0) 776 { 777 // left of the visible area 778 aHoriScroll.SetThumbPos(aHoriScroll.GetThumbPos() + nX); 779 ScrollHdl(&aHoriScroll); 780 } 781 else if(nX > aOutSize.Width()) 782 { 783 // right of the visible area 784 aHoriScroll.SetThumbPos(aHoriScroll.GetThumbPos() + nX - aOutSize.Width() + aFixedTexts[0]->GetSizePixel().Width()); 785 ScrollHdl(&aHoriScroll); 786 } 787 long nY = aRect.Y; 788 if(nY < 0) 789 { 790 // below the visible area 791 aVertScroll.SetThumbPos(aVertScroll.GetThumbPos() + nY); 792 ScrollHdl(&aVertScroll); 793 } 794 else if(nY > aOutSize.Height()) 795 { 796 // over the visible area 797 aVertScroll.SetThumbPos(aVertScroll.GetThumbPos() + nY - aOutSize.Height()+ aFixedTexts[0]->GetSizePixel().Height()); 798 ScrollHdl(&aVertScroll); 799 } 800 } 801 } 802 803 void BibGeneralPage::focusLost(const awt::FocusEvent& ) throw( uno::RuntimeException ) 804 { 805 CommitActiveControl(); 806 } 807 808 void BibGeneralPage::disposing(const lang::EventObject& /*Source*/) throw( uno::RuntimeException ) 809 { 810 } 811 812 void BibGeneralPage::GetFocus() 813 { 814 Reference< awt::XWindow >* pxControl = aControls; 815 816 for( int i = FIELD_COUNT ; i ; --i, ++pxControl ) 817 { 818 if( pxControl->is() ) 819 { 820 ( *pxControl )->setFocus(); 821 return; 822 } 823 } 824 825 // fallback 826 aControlParentWin.GrabFocus(); 827 } 828 829 sal_Bool BibGeneralPage::HandleShortCutKey( const KeyEvent& rKeyEvent ) 830 { 831 DBG_ASSERT( KEY_MOD2 == rKeyEvent.GetKeyCode().GetModifier(), "+BibGeneralPage::HandleShortCutKey(): this is not for me!" ); 832 833 const vcl::I18nHelper& rI18nHelper = Application::GetSettings().GetUILocaleI18nHelper(); 834 const xub_Unicode c = rKeyEvent.GetCharCode(); 835 sal_Bool bHandled = sal_False; 836 837 sal_Int16 i; 838 839 typedef std::vector< sal_Int16 > sal_Int16_vector; 840 841 sal_Int16_vector::size_type nFocused = 0xFFFF; // index of focused in vector, no one focused initial 842 DBG_ASSERT( nFocused > 0, "*BibGeneralPage::HandleShortCutKey(): size_type works not as expected!" ); 843 844 sal_Int16_vector aMatchList; 845 846 for( i = 0 ; i < FIELD_COUNT ; ++i ) 847 { 848 if( rI18nHelper.MatchMnemonic( aFixedTexts[ i ]->GetText(), c ) ) 849 { 850 bHandled = sal_True; 851 sal_Int16 nCtrlIndex = nFT2CtrlMap[ i ]; 852 853 if( nCtrlIndex >= 0 ) 854 { // store index of control 855 DBG_ASSERT( aControls[ nCtrlIndex ].is(), "-BibGeneralPage::HandleShortCutKey(): valid index and no control?" ); 856 857 uno::Reference< awt::XControl > xControl( aControls[ nCtrlIndex ], UNO_QUERY ); 858 DBG_ASSERT( xControl.is(), "-BibGeneralPage::HandleShortCutKey(): a control wich is not a control!" ); 859 860 Window* pWindow = VCLUnoHelper::GetWindow( xControl->getPeer() ); 861 862 if( pWindow ) 863 { 864 aMatchList.push_back( nCtrlIndex ); 865 if( pWindow->HasChildPathFocus() ) 866 { // save focused control 867 DBG_ASSERT( nFocused == 0xFFFF, "+BibGeneralPage::HandleShortCutKey(): more than one with focus?!" ); 868 DBG_ASSERT( aMatchList.size() > 0, "+BibGeneralPage::HandleShortCutKey(): push_back and no content?!" ); 869 nFocused = aMatchList.size() - 1; 870 } 871 } 872 } 873 } 874 } 875 876 if( bHandled ) 877 { 878 DBG_ASSERT( aMatchList.size() > 0, "*BibGeneralPage::HandleShortCutKey(): be prepared to crash..." ); 879 880 if( nFocused >= ( aMatchList.size() - 1 ) ) 881 // >=... includes 0xFFFF 882 // no one or last focused, take first 883 nFocused = 0; 884 else 885 // take next one 886 nFocused++; 887 888 aControls[ aMatchList[ nFocused ] ]->setFocus(); 889 } 890 891 return bHandled; 892 } 893