bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / bibliography / general.cxx
blob19e816894993f454c050fe9b75c48b422e6a0fc2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <comphelper/processfactory.hxx>
21 #include <com/sun/star/awt/PosSize.hpp>
22 #include <com/sun/star/sdbc/XRowSet.hpp>
23 #include <com/sun/star/sdb/XColumn.hpp>
24 #include <com/sun/star/sdb/CommandType.hpp>
25 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
26 #include <com/sun/star/awt/XWindow.hpp>
27 #include <toolkit/helper/vclunohelper.hxx>
28 #include <cppuhelper/implbase1.hxx>
29 #include <vcl/builder.hxx>
30 #include <vcl/settings.hxx>
31 #include "general.hxx"
32 #include "bibresid.hxx"
33 #include "datman.hxx"
34 #include "bibconfig.hxx"
35 #include "bibprop.hrc"
36 #include "bib.hrc"
37 #include "bibmod.hxx"
38 #include "bibview.hxx"
39 #include "bibtools.hxx"
40 #include "bibliography.hrc"
41 #include <tools/debug.hxx>
42 #include <vcl/svapp.hxx>
43 #include <vcl/i18nhelp.hxx>
44 #include <vcl/mnemonic.hxx>
45 #include <algorithm>
46 #include <functional>
47 #include <vector>
48 #include <tools/urlobj.hxx>
50 using namespace ::com::sun::star;
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::form;
53 using namespace ::com::sun::star::sdb;
55 static OUString lcl_GetColumnName( const Mapping* pMapping, sal_uInt16 nIndexPos )
57 BibConfig* pBibConfig = BibModul::GetConfig();
58 OUString sRet = pBibConfig->GetDefColumnName(nIndexPos);
59 if(pMapping)
60 for(sal_uInt16 i = 0; i < COLUMN_COUNT; i++)
62 if(pMapping->aColumnPairs[i].sLogicalColumnName == sRet)
64 sRet = pMapping->aColumnPairs[i].sRealColumnName;
65 break;
68 return sRet;
71 class BibPosListener :public cppu::WeakImplHelper1 <sdbc::XRowSetListener>
73 VclPtr<BibGeneralPage> pParentPage;
74 public:
75 BibPosListener(BibGeneralPage* pParent);
77 //XPositioningListener
78 virtual void SAL_CALL cursorMoved(const lang::EventObject& event) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
79 virtual void SAL_CALL rowChanged(const lang::EventObject& /*event*/) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE { /* not interested in */ }
80 virtual void SAL_CALL rowSetChanged(const lang::EventObject& /*event*/) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE { /* not interested in */ }
82 //XEventListener
83 virtual void SAL_CALL disposing(const lang::EventObject& Source) throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
87 BibPosListener::BibPosListener(BibGeneralPage* pParent) :
88 pParentPage(pParent)
92 void BibPosListener::cursorMoved(const lang::EventObject& /*aEvent*/) throw( uno::RuntimeException, std::exception )
94 try
96 uno::Reference< form::XBoundComponent > xLstBox = pParentPage->GetTypeListBoxModel();
97 uno::Reference< beans::XPropertySet > xPropSet(xLstBox, UNO_QUERY);
98 if(xPropSet.is())
100 BibConfig* pBibConfig = BibModul::GetConfig();
101 BibDataManager* pDatMan = pParentPage->GetDataManager();
102 BibDBDescriptor aDesc;
103 aDesc.sDataSource = pDatMan->getActiveDataSource();
104 aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
105 aDesc.nCommandType = CommandType::TABLE;
107 const Mapping* pMapping = pBibConfig->GetMapping(aDesc);
108 OUString sTypeMapping = pBibConfig->GetDefColumnName(AUTHORITYTYPE_POS);
109 if(pMapping)
111 for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
113 if(pMapping->aColumnPairs[nEntry].sLogicalColumnName == sTypeMapping)
115 sTypeMapping = pMapping->aColumnPairs[nEntry].sRealColumnName;
116 break;
120 OUString uTypeMapping = sTypeMapping;
122 uno::Reference< form::XForm > xForm = pDatMan->getForm();
123 uno::Reference< sdbcx::XColumnsSupplier > xSupplyCols(xForm, UNO_QUERY);
124 uno::Reference< container::XNameAccess > xValueAcc;
125 if (xSupplyCols.is())
126 xValueAcc = xSupplyCols->getColumns();
128 sal_Int16 nTempVal = -1;
129 if(xValueAcc.is() && xValueAcc->hasByName(uTypeMapping))
131 uno::Any aVal = xValueAcc->getByName(uTypeMapping);
132 uno::Reference< uno::XInterface > xInt = *static_cast<uno::Reference< uno::XInterface > const *>(aVal.getValue());
133 uno::Reference< sdb::XColumn > xCol(xInt, UNO_QUERY);
134 DBG_ASSERT(xCol.is(), "BibPosListener::cursorMoved : invalid column (no sdb::XColumn) !");
135 if (xCol.is())
137 nTempVal = xCol->getShort();
138 // getShort returns zero if the value is not a number
139 if (!nTempVal || xCol->wasNull())
141 OUString sTempVal = xCol->getString();
142 if(sTempVal != "0")
143 nTempVal = -1;
147 if(nTempVal < 0 || nTempVal >= TYPE_COUNT)
149 uno::Any aSel;
150 uno::Sequence<sal_Int16> aSelSeq(1);
151 sal_Int16* pArr = aSelSeq.getArray();
152 pArr[0] = TYPE_COUNT;
153 aSel.setValue(&aSelSeq, cppu::UnoType<Sequence<sal_Int16>>::get());
154 xPropSet->setPropertyValue("SelectedItems", aSel);
158 catch(const Exception&)
160 OSL_FAIL("BibPosListener::cursorMoved: something went wrong !");
164 void BibPosListener::disposing(const lang::EventObject& /*Source*/) throw( uno::RuntimeException, std::exception )
168 BibGeneralPage::BibGeneralPage(vcl::Window* pParent, BibDataManager* pMan):
169 BibTabPage(pParent, "GeneralPage", "modules/sbibliography/ui/generalpage.ui"),
170 sErrorPrefix(BIB_RESSTR(ST_ERROR_PREFIX)),
171 mxBibGeneralPageFocusListener(new BibGeneralPageFocusListener(this)),
172 pDatMan(pMan)
174 get(pIdentifierFT, "shortname");
175 get(pAuthTypeFT, "authtype");
176 get(pGrid, "grid");
177 get(pScrolledWindow, "scrolledwindow");
178 get(pYearFT, "year");
179 get(pAuthorFT, "authors");
180 get(pTitleFT, "title");
181 get(pPublisherFT, "publisher");
182 get(pAddressFT, "address");
183 get(pISBNFT, "isbn");
184 get(pChapterFT, "chapter");
185 get(pPagesFT, "pages");
186 get(pEditorFT, "editor");
187 get(pEditionFT, "edition");
188 get(pBooktitleFT, "booktitle");
189 get(pVolumeFT, "volume");
190 get(pHowpublishedFT, "publicationtype");
191 get(pOrganizationsFT, "organization");
192 get(pInstitutionFT, "institution");
193 get(pSchoolFT, "university");
194 get(pReportTypeFT, "reporttype");
195 get(pMonthFT, "month");
196 get(pJournalFT, "journal");
197 get(pNumberFT, "number");
198 get(pSeriesFT, "series");
199 get(pAnnoteFT, "annotation");
200 get(pNoteFT, "note");
201 get(pURLFT, "url");
202 get(pCustom1FT, "custom1");
203 get(pCustom2FT, "custom2");
204 get(pCustom3FT, "custom3");
205 get(pCustom4FT, "custom4");
206 get(pCustom5FT, "custom5");
208 InitFixedTexts();
210 sal_Int16* pMap = nFT2CtrlMap;
211 for( sal_uInt16 i = 0 ; i < FIELD_COUNT ; ++i, ++pMap )
213 aControls[ i ] = 0;
214 *pMap = -1;
217 BibConfig* pBibConfig = BibModul::GetConfig();
218 BibDBDescriptor aDesc;
219 aDesc.sDataSource = pDatMan->getActiveDataSource();
220 aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
221 aDesc.nCommandType = CommandType::TABLE;
222 const Mapping* pMapping = pBibConfig->GetMapping(aDesc);
224 xCtrlContnr = VCLUnoHelper::CreateControlContainer(pGrid);
226 std::vector<vcl::Window*> aChildren;
228 AddControlWithError(lcl_GetColumnName(pMapping, IDENTIFIER_POS), *pIdentifierFT,
229 sTableErrorString,
230 HID_BIB_IDENTIFIER_POS, 0, aChildren);
232 sTypeColumnName = lcl_GetColumnName(pMapping, AUTHORITYTYPE_POS);
234 AddControlWithError(sTypeColumnName, *pAuthTypeFT, sTableErrorString,
235 HID_BIB_AUTHORITYTYPE_POS, 1, aChildren);
237 AddControlWithError(lcl_GetColumnName(pMapping, YEAR_POS), *pYearFT,
238 sTableErrorString, HID_BIB_YEAR_POS, 2, aChildren);
240 AddControlWithError(lcl_GetColumnName(pMapping, AUTHOR_POS), *pAuthorFT,
241 sTableErrorString, HID_BIB_AUTHOR_POS, 3, aChildren);
243 AddControlWithError(lcl_GetColumnName(pMapping, TITLE_POS), *pTitleFT, sTableErrorString,
244 HID_BIB_TITLE_POS, 4, aChildren);
246 AddControlWithError(lcl_GetColumnName(pMapping, PUBLISHER_POS), *pPublisherFT,
247 sTableErrorString, HID_BIB_PUBLISHER_POS, 5, aChildren);
249 AddControlWithError(lcl_GetColumnName(pMapping, ADDRESS_POS), *pAddressFT,
250 sTableErrorString, HID_BIB_ADDRESS_POS, 6, aChildren);
252 AddControlWithError(lcl_GetColumnName(pMapping, ISBN_POS), *pISBNFT,
253 sTableErrorString, HID_BIB_ISBN_POS, 7, aChildren);
255 AddControlWithError(lcl_GetColumnName(pMapping, CHAPTER_POS), *pChapterFT,
256 sTableErrorString, HID_BIB_CHAPTER_POS, 8, aChildren);
258 AddControlWithError(lcl_GetColumnName(pMapping, PAGES_POS), *pPagesFT,
259 sTableErrorString, HID_BIB_PAGES_POS, 9, aChildren);
261 AddControlWithError(lcl_GetColumnName(pMapping, EDITOR_POS), *pEditorFT,
262 sTableErrorString, HID_BIB_EDITOR_POS, 10, aChildren);
264 AddControlWithError(lcl_GetColumnName(pMapping, EDITION_POS), *pEditionFT,
265 sTableErrorString, HID_BIB_EDITION_POS, 11, aChildren);
267 AddControlWithError(lcl_GetColumnName(pMapping, BOOKTITLE_POS), *pBooktitleFT,
268 sTableErrorString, HID_BIB_BOOKTITLE_POS, 12, aChildren);
270 AddControlWithError(lcl_GetColumnName(pMapping, VOLUME_POS), *pVolumeFT,
271 sTableErrorString, HID_BIB_VOLUME_POS, 13, aChildren);
273 AddControlWithError(lcl_GetColumnName(pMapping, HOWPUBLISHED_POS), *pHowpublishedFT,
274 sTableErrorString, HID_BIB_HOWPUBLISHED_POS, 14, aChildren);
276 AddControlWithError(lcl_GetColumnName(pMapping, ORGANIZATIONS_POS), *pOrganizationsFT,
277 sTableErrorString, HID_BIB_ORGANIZATIONS_POS, 15, aChildren);
279 AddControlWithError(lcl_GetColumnName(pMapping, INSTITUTION_POS), *pInstitutionFT,
280 sTableErrorString, HID_BIB_INSTITUTION_POS, 16, aChildren);
282 AddControlWithError(lcl_GetColumnName(pMapping, SCHOOL_POS), *pSchoolFT,
283 sTableErrorString, HID_BIB_SCHOOL_POS, 17, aChildren);
285 AddControlWithError(lcl_GetColumnName(pMapping, REPORTTYPE_POS), *pReportTypeFT,
286 sTableErrorString, HID_BIB_REPORTTYPE_POS, 18, aChildren);
288 AddControlWithError(lcl_GetColumnName(pMapping, MONTH_POS), *pMonthFT,
289 sTableErrorString, HID_BIB_MONTH_POS, 19, aChildren);
291 AddControlWithError(lcl_GetColumnName(pMapping, JOURNAL_POS), *pJournalFT,
292 sTableErrorString, HID_BIB_JOURNAL_POS, 20, aChildren);
294 AddControlWithError(lcl_GetColumnName(pMapping, NUMBER_POS), *pNumberFT,
295 sTableErrorString, HID_BIB_NUMBER_POS, 21, aChildren);
297 AddControlWithError(lcl_GetColumnName(pMapping, SERIES_POS), *pSeriesFT,
298 sTableErrorString, HID_BIB_SERIES_POS, 22, aChildren);
300 AddControlWithError(lcl_GetColumnName(pMapping, ANNOTE_POS), *pAnnoteFT,
301 sTableErrorString, HID_BIB_ANNOTE_POS, 23, aChildren);
303 AddControlWithError(lcl_GetColumnName(pMapping, NOTE_POS),*pNoteFT,
304 sTableErrorString, HID_BIB_NOTE_POS, 24, aChildren);
306 AddControlWithError(lcl_GetColumnName(pMapping, URL_POS), *pURLFT,
307 sTableErrorString, HID_BIB_URL_POS, 25, aChildren);
309 AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM1_POS), *pCustom1FT,
310 sTableErrorString, HID_BIB_CUSTOM1_POS, 26, aChildren);
312 AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM2_POS), *pCustom2FT,
313 sTableErrorString, HID_BIB_CUSTOM2_POS, 27, aChildren);
315 AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM3_POS), *pCustom3FT,
316 sTableErrorString, HID_BIB_CUSTOM3_POS, 28, aChildren);
318 AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM4_POS), *pCustom4FT,
319 sTableErrorString, HID_BIB_CUSTOM4_POS, 29, aChildren);
321 AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM5_POS), *pCustom5FT,
322 sTableErrorString, HID_BIB_CUSTOM5_POS, 30, aChildren);
324 VclBuilder::reorderWithinParent(aChildren, false);
326 xPosListener = new BibPosListener(this);
327 uno::Reference< sdbc::XRowSet > xRowSet(pDatMan->getForm(), UNO_QUERY);
328 if(xRowSet.is())
329 xRowSet->addRowSetListener(xPosListener);
330 uno::Reference< form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController();
331 xFormCtrl->setContainer(xCtrlContnr);
332 xFormCtrl->activateTabOrder();
334 if(!sTableErrorString.isEmpty())
335 sTableErrorString = sErrorPrefix + sTableErrorString;
337 SetText(BIB_RESSTR(ST_TYPE_TITLE));
339 Size aSize(LogicToPixel(Size(0, 209), MapMode(MAP_APPFONT)));
340 set_height_request(aSize.Height());
343 BibGeneralPage::~BibGeneralPage()
345 disposeOnce();
348 void BibGeneralPage::dispose()
350 if (pDatMan && xPosListener.is())
352 uno::Reference< sdbc::XRowSet > xRowSet(pDatMan->getForm(), UNO_QUERY);
353 if(xRowSet.is())
354 xRowSet->removeRowSetListener(xPosListener);
356 pGrid.clear();
357 pScrolledWindow.clear();
358 pIdentifierFT.clear();
359 pAuthTypeFT.clear();
360 pYearFT.clear();
361 pAuthorFT.clear();
362 pTitleFT.clear();
363 pPublisherFT.clear();
364 pAddressFT.clear();
365 pISBNFT.clear();
366 pChapterFT.clear();
367 pPagesFT.clear();
368 pEditorFT.clear();
369 pEditionFT.clear();
370 pBooktitleFT.clear();
371 pVolumeFT.clear();
372 pHowpublishedFT.clear();
373 pOrganizationsFT.clear();
374 pInstitutionFT.clear();
375 pSchoolFT.clear();
376 pReportTypeFT.clear();
377 pMonthFT.clear();
378 pJournalFT.clear();
379 pNumberFT.clear();
380 pSeriesFT.clear();
381 pAnnoteFT.clear();
382 pNoteFT.clear();
383 pURLFT.clear();
384 pCustom1FT.clear();
385 pCustom2FT.clear();
386 pCustom3FT.clear();
387 pCustom4FT.clear();
388 pCustom5FT.clear();
389 for (auto & a: aFixedTexts) a.clear();
390 mxBibGeneralPageFocusListener.clear();
391 BibTabPage::dispose();
394 void BibGeneralPage::RemoveListeners()
396 for(sal_uInt16 i = 0; i < FIELD_COUNT; i++)
398 if(aControls[i].is())
400 uno::Reference< awt::XWindow > xCtrWin(aControls[i], uno::UNO_QUERY );
401 xCtrWin->removeFocusListener( mxBibGeneralPageFocusListener.get() );
402 aControls[i] = 0;
407 void BibGeneralPage::CommitActiveControl()
409 uno::Reference< form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController();
410 uno::Reference< awt::XControl > xCurr = xFormCtrl->getCurrentControl();
411 if(xCurr.is())
413 uno::Reference< awt::XControlModel > xModel = xCurr->getModel();
414 uno::Reference< form::XBoundComponent > xBound(xModel, UNO_QUERY);
415 if(xBound.is())
416 xBound->commit();
420 void BibGeneralPage::AddControlWithError( const OUString& rColumnName, FixedText &rLabel,
421 OUString& rErrorString, const OString& sHelpId, sal_uInt16 nIndexInFTArray, std::vector<vcl::Window*> &rChildren)
423 const OUString aColumnUIName(rLabel.GetText());
424 // adds also the XControl and creates a map entry in nFT2CtrlMap[] for mapping between control and FT
426 sal_Int16 nIndex = -1;
427 uno::Reference< awt::XControlModel > xTmp = AddXControl(rColumnName, rLabel, sHelpId, nIndex, rChildren);
428 if( xTmp.is() )
430 DBG_ASSERT( nIndexInFTArray < FIELD_COUNT, "*BibGeneralPage::AddControlWithError(): wrong array index!" );
431 DBG_ASSERT( nFT2CtrlMap[ nIndexInFTArray ] < 0, "+BibGeneralPage::AddControlWithError(): index already in use!" );
433 nFT2CtrlMap[ nIndexInFTArray ] = nIndex;
435 else
437 if( !rErrorString.isEmpty() )
438 rErrorString += "\n";
440 rErrorString += MnemonicGenerator::EraseAllMnemonicChars( aColumnUIName );
444 uno::Reference< awt::XControlModel > BibGeneralPage::AddXControl(
445 const OUString& rName,
446 FixedText& rLabel, const OString& sHelpId, sal_Int16& rIndex,
447 std::vector<vcl::Window*>& rChildren)
449 uno::Reference< awt::XControlModel > xCtrModel;
452 const bool bTypeListBox = sTypeColumnName == rName;
453 xCtrModel = pDatMan->loadControlModel(rName, bTypeListBox);
454 if ( xCtrModel.is() )
456 uno::Reference< beans::XPropertySet > xPropSet( xCtrModel, UNO_QUERY );
458 if( xPropSet.is())
460 uno::Reference< beans::XPropertySetInfo > xPropInfo = xPropSet->getPropertySetInfo();
462 OUString aControlName;
463 if (bTypeListBox)
465 aControlName = "com.sun.star.form.control.ListBox";
466 xLBModel = Reference< form::XBoundComponent >(xCtrModel, UNO_QUERY);
468 else
470 uno::Any aAny = xPropSet->getPropertyValue( "DefaultControl" );
471 aAny >>= aControlName;
474 OUString uProp("HelpURL");
475 if(xPropInfo->hasPropertyByName(uProp))
477 OUString sId( INET_HID_SCHEME );
478 DBG_ASSERT( INetURLObject( OStringToOUString( sHelpId, RTL_TEXTENCODING_UTF8 ) ).GetProtocol() == INetProtocol::NotValid, "Wrong HelpId!" );
479 sId += OStringToOUString( sHelpId, RTL_TEXTENCODING_UTF8 );
480 xPropSet->setPropertyValue( uProp, makeAny( sId ) );
483 uno::Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
484 uno::Reference< awt::XControl > xControl( xContext->getServiceManager()->createInstanceWithContext(aControlName, xContext), UNO_QUERY);
485 if ( xControl.is() )
487 xControl->setModel( xCtrModel);
489 // Peer as Child to the FrameWindow
490 xCtrlContnr->addControl(rName, xControl);
491 uno::Reference< awt::XWindow > xCtrWin(xControl, UNO_QUERY );
492 xCtrWin->addFocusListener( mxBibGeneralPageFocusListener.get() );
493 rIndex = -1; // -> implies, that not found
494 for(sal_uInt16 i = 0; i < FIELD_COUNT; i++)
495 if(!aControls[i].is())
497 aControls[i] = xCtrWin;
498 rIndex = sal_Int16( i );
499 break;
501 // initially switch on the design mode - switch it off _after_ loading the form
502 xCtrWin->setVisible( sal_True );
503 xControl->setDesignMode( sal_True );
505 vcl::Window* pWindow = VCLUnoHelper::GetWindow(xControl->getPeer());
506 pWindow->set_grid_top_attach(rLabel.get_grid_top_attach());
507 pWindow->set_grid_left_attach(rLabel.get_grid_left_attach()+1);
508 pWindow->set_valign(VCL_ALIGN_CENTER);
509 rLabel.set_mnemonic_widget(pWindow);
510 if (&rLabel == pTitleFT)
511 pWindow->set_grid_width(3);
512 else
513 pWindow->set_hexpand(true);
514 rChildren.push_back(&rLabel);
515 rChildren.push_back(pWindow);
520 catch(const Exception& rEx)
522 (void) rEx; // make compiler happy
523 OSL_FAIL("BibGeneralPage::AddXControl: something went wrong!");
525 return xCtrModel;
528 void BibGeneralPage::InitFixedTexts()
530 aFixedTexts[0] = pIdentifierFT;
531 aFixedTexts[1] = pAuthTypeFT;
532 aFixedTexts[2] = pYearFT;
533 aFixedTexts[3] = pAuthorFT;
534 aFixedTexts[4] = pTitleFT;
535 aFixedTexts[5] = pPublisherFT;
536 aFixedTexts[6] = pAddressFT;
537 aFixedTexts[7] = pISBNFT;
538 aFixedTexts[8] = pChapterFT;
539 aFixedTexts[9] = pPagesFT;
541 aFixedTexts[10] = pEditorFT;
542 aFixedTexts[11] = pEditionFT;
543 aFixedTexts[12] = pBooktitleFT;
544 aFixedTexts[13] = pVolumeFT;
545 aFixedTexts[14] = pHowpublishedFT;
546 aFixedTexts[15] = pOrganizationsFT;
547 aFixedTexts[16] = pInstitutionFT;
548 aFixedTexts[17] = pSchoolFT;
549 aFixedTexts[18] = pReportTypeFT;
550 aFixedTexts[19] = pMonthFT;
552 aFixedTexts[20] = pJournalFT;
553 aFixedTexts[21] = pNumberFT;
554 aFixedTexts[22] = pSeriesFT;
555 aFixedTexts[23] = pAnnoteFT;
556 aFixedTexts[24] = pNoteFT;
557 aFixedTexts[25] = pURLFT;
559 aFixedTexts[26] = pCustom1FT;
560 aFixedTexts[27] = pCustom2FT;
561 aFixedTexts[28] = pCustom3FT;
562 aFixedTexts[29] = pCustom4FT;
563 aFixedTexts[30] = pCustom5FT;
565 int i;
567 MnemonicGenerator aMnemonicGenerator;
569 OUString aFixedStrings[ FIELD_COUNT ];
570 for( i = 0 ; i < FIELD_COUNT ; ++i )
571 aFixedStrings[i] = aFixedTexts[i]->GetText();
573 // init mnemonics, first register all strings
574 for( i = 0 ; i < FIELD_COUNT ; ++i )
575 aMnemonicGenerator.RegisterMnemonic( aFixedStrings[ i ] );
577 // ... then get all strings
578 for( i = 0 ; i < FIELD_COUNT ; ++i )
579 aMnemonicGenerator.CreateMnemonic( aFixedStrings[ i ] );
581 // set texts
582 for( i = 0 ; i < FIELD_COUNT ; ++i )
583 aFixedTexts[ i ]->SetText( aFixedStrings[ i ] );
586 void BibGeneralPage::focusGained(const awt::FocusEvent& rEvent) throw( uno::RuntimeException, std::exception )
588 Reference<awt::XWindow> xCtrWin(rEvent.Source, UNO_QUERY );
589 if(xCtrWin.is())
591 ::Size aOutSize = pScrolledWindow->getVisibleChildSize();
592 awt::Rectangle aRect = xCtrWin->getPosSize();
593 Point aOffset(pGrid->GetPosPixel());
594 long nX = aRect.X + aOffset.X();
595 if (nX < 0 || nX > aOutSize.Width())
597 pScrolledWindow->getHorzScrollBar().DoScroll(aRect.X);
600 long nY = aRect.Y + aOffset.Y();
601 if (nY < 0 || nY > aOutSize.Height())
603 pScrolledWindow->getVertScrollBar().DoScroll(aRect.Y);
608 void BibGeneralPage::focusLost(const awt::FocusEvent& ) throw( uno::RuntimeException, std::exception )
610 CommitActiveControl();
613 void BibGeneralPage::GetFocus()
615 Reference< awt::XWindow >* pxControl = aControls;
617 for( int i = FIELD_COUNT ; i ; --i, ++pxControl )
619 if( pxControl->is() )
621 ( *pxControl )->setFocus();
622 return;
626 // fallback
627 GrabFocus();
630 bool BibGeneralPage::HandleShortCutKey( const KeyEvent& rKeyEvent )
632 DBG_ASSERT( KEY_MOD2 == rKeyEvent.GetKeyCode().GetModifier(), "+BibGeneralPage::HandleShortCutKey(): this is not for me!" );
634 const vcl::I18nHelper& rI18nHelper = Application::GetSettings().GetUILocaleI18nHelper();
635 const sal_Unicode c = rKeyEvent.GetCharCode();
636 bool bHandled = false;
638 sal_Int16 i;
640 typedef std::vector< sal_Int16 > sal_Int16_vector;
642 sal_Int16_vector::size_type nFocused = 0xFFFF; // index of focused in vector, no one focused initial
643 DBG_ASSERT( nFocused > 0, "*BibGeneralPage::HandleShortCutKey(): size_type works not as expected!" );
645 sal_Int16_vector aMatchList;
647 for( i = 0 ; i < FIELD_COUNT ; ++i )
649 if( rI18nHelper.MatchMnemonic( aFixedTexts[ i ]->GetText(), c ) )
651 bHandled = true;
652 sal_Int16 nCtrlIndex = nFT2CtrlMap[ i ];
654 if( nCtrlIndex >= 0 )
655 { // store index of control
656 DBG_ASSERT( aControls[ nCtrlIndex ].is(), "-BibGeneralPage::HandleShortCutKey(): valid index and no control?" );
658 uno::Reference< awt::XControl > xControl( aControls[ nCtrlIndex ], UNO_QUERY );
659 DBG_ASSERT( xControl.is(), "-BibGeneralPage::HandleShortCutKey(): a control which is not a control!" );
661 vcl::Window* pWindow = VCLUnoHelper::GetWindow( xControl->getPeer() );
663 if( pWindow )
665 aMatchList.push_back( nCtrlIndex );
666 if( pWindow->HasChildPathFocus() )
667 { // save focused control
668 DBG_ASSERT( nFocused == 0xFFFF, "+BibGeneralPage::HandleShortCutKey(): more than one with focus?!" );
669 DBG_ASSERT( !aMatchList.empty(), "+BibGeneralPage::HandleShortCutKey(): push_back and no content?!" );
670 nFocused = aMatchList.size() - 1;
677 if( bHandled )
679 DBG_ASSERT( !aMatchList.empty(), "*BibGeneralPage::HandleShortCutKey(): be prepared to crash..." );
681 if( nFocused >= ( aMatchList.size() - 1 ) )
682 // >=... includes 0xFFFF
683 // no one or last focused, take first
684 nFocused = 0;
685 else
686 // take next one
687 nFocused++;
689 aControls[ aMatchList[ nFocused ] ]->setFocus();
692 return bHandled;
695 BibGeneralPageFocusListener::BibGeneralPageFocusListener(BibGeneralPage *pBibGeneralPage): mpBibGeneralPage(pBibGeneralPage)
698 void BibGeneralPageFocusListener::focusGained( const ::com::sun::star::awt::FocusEvent& e ) throw( com::sun::star::uno::RuntimeException, std::exception )
700 mpBibGeneralPage->focusGained(e);
703 void BibGeneralPageFocusListener::focusLost( const ::com::sun::star::awt::FocusEvent& e ) throw( com::sun::star::uno::RuntimeException, std::exception )
705 mpBibGeneralPage->focusLost(e);
708 void BibGeneralPageFocusListener::disposing( const ::com::sun::star::lang::EventObject& ) throw( com::sun::star::uno::RuntimeException, std::exception )
711 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */