bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / source / bibliography / general.cxx
blobde447c4a59f04a72b26f3f6c7305d8168aa8356f
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 <com/sun/star/uno/XComponentContext.hpp>
28 #include <toolkit/helper/vclunohelper.hxx>
29 #include <cppuhelper/implbase.hxx>
30 #include <vcl/builder.hxx>
31 #include <vcl/settings.hxx>
32 #include <vcl/fixed.hxx>
33 #include "general.hxx"
34 #include "bibresid.hxx"
35 #include "datman.hxx"
36 #include "bibconfig.hxx"
37 #include "bibprop.hxx"
38 #include <strings.hrc>
39 #include "bibmod.hxx"
40 #include "bibview.hxx"
41 #include "bibtools.hxx"
42 #include <helpids.h>
43 #include <tools/debug.hxx>
44 #include <vcl/svapp.hxx>
45 #include <vcl/i18nhelp.hxx>
46 #include <vcl/mnemonic.hxx>
47 #include <algorithm>
48 #include <functional>
49 #include <vector>
50 #include <tools/urlobj.hxx>
52 using namespace ::com::sun::star;
53 using namespace ::com::sun::star::uno;
54 using namespace ::com::sun::star::form;
55 using namespace ::com::sun::star::sdb;
57 static OUString lcl_GetColumnName( const Mapping* pMapping, sal_uInt16 nIndexPos )
59 BibConfig* pBibConfig = BibModul::GetConfig();
60 OUString sRet = pBibConfig->GetDefColumnName(nIndexPos);
61 if(pMapping)
62 for(const auto & aColumnPair : pMapping->aColumnPairs)
64 if(aColumnPair.sLogicalColumnName == sRet)
66 sRet = aColumnPair.sRealColumnName;
67 break;
70 return sRet;
73 class BibPosListener :public cppu::WeakImplHelper <sdbc::XRowSetListener>
75 VclPtr<BibGeneralPage> pParentPage;
76 public:
77 explicit BibPosListener(BibGeneralPage* pParent);
79 //XPositioningListener
80 virtual void SAL_CALL cursorMoved(const lang::EventObject& event) override;
81 virtual void SAL_CALL rowChanged(const lang::EventObject& /*event*/) override { /* not interested in */ }
82 virtual void SAL_CALL rowSetChanged(const lang::EventObject& /*event*/) override { /* not interested in */ }
84 //XEventListener
85 virtual void SAL_CALL disposing(const lang::EventObject& Source) override;
89 BibPosListener::BibPosListener(BibGeneralPage* pParent) :
90 pParentPage(pParent)
94 void BibPosListener::cursorMoved(const lang::EventObject& /*aEvent*/)
96 try
98 uno::Reference< form::XBoundComponent > xLstBox = pParentPage->GetTypeListBoxModel();
99 uno::Reference< beans::XPropertySet > xPropSet(xLstBox, UNO_QUERY);
100 if(xPropSet.is())
102 BibConfig* pBibConfig = BibModul::GetConfig();
103 BibDataManager* pDatMan = pParentPage->GetDataManager();
104 BibDBDescriptor aDesc;
105 aDesc.sDataSource = pDatMan->getActiveDataSource();
106 aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
107 aDesc.nCommandType = CommandType::TABLE;
109 const Mapping* pMapping = pBibConfig->GetMapping(aDesc);
110 OUString sTypeMapping = pBibConfig->GetDefColumnName(AUTHORITYTYPE_POS);
111 if(pMapping)
113 for(const auto & aColumnPair : pMapping->aColumnPairs)
115 if(aColumnPair.sLogicalColumnName == sTypeMapping)
117 sTypeMapping = aColumnPair.sRealColumnName;
118 break;
122 OUString uTypeMapping = sTypeMapping;
124 uno::Reference< form::XForm > xForm = pDatMan->getForm();
125 uno::Reference< sdbcx::XColumnsSupplier > xSupplyCols(xForm, UNO_QUERY);
126 uno::Reference< container::XNameAccess > xValueAcc;
127 if (xSupplyCols.is())
128 xValueAcc = xSupplyCols->getColumns();
130 sal_Int16 nTempVal = -1;
131 if(xValueAcc.is() && xValueAcc->hasByName(uTypeMapping))
133 uno::Any aVal = xValueAcc->getByName(uTypeMapping);
134 uno::Reference< sdb::XColumn > xCol(aVal, UNO_QUERY);
135 DBG_ASSERT(xCol.is(), "BibPosListener::cursorMoved : invalid column (no sdb::XColumn) !");
136 if (xCol.is())
138 nTempVal = xCol->getShort();
139 // getShort returns zero if the value is not a number
140 if (!nTempVal || xCol->wasNull())
142 OUString sTempVal = xCol->getString();
143 if(sTempVal != "0")
144 nTempVal = -1;
148 if(nTempVal < 0 || nTempVal >= TYPE_COUNT)
150 uno::Any aSel;
151 uno::Sequence<sal_Int16> aSelSeq(1);
152 sal_Int16* pArr = aSelSeq.getArray();
153 pArr[0] = TYPE_COUNT;
154 aSel <<= aSelSeq;
155 xPropSet->setPropertyValue("SelectedItems", aSel);
159 catch(const Exception&)
161 OSL_FAIL("BibPosListener::cursorMoved: something went wrong !");
165 void BibPosListener::disposing(const lang::EventObject& /*Source*/)
169 BibGeneralPage::BibGeneralPage(vcl::Window* pParent, BibDataManager* pMan):
170 TabPage(pParent, "GeneralPage", "modules/sbibliography/ui/generalpage.ui"),
171 BibShortCutHandler( this ),
172 mxBibGeneralPageFocusListener(new BibGeneralPageFocusListener(this)),
173 pDatMan(pMan)
175 get(pIdentifierFT, "shortname");
176 get(pAuthTypeFT, "authtype");
177 get(pGrid, "grid");
178 get(pScrolledWindow, "scrolledwindow");
179 get(pYearFT, "year");
180 get(pAuthorFT, "authors");
181 get(pTitleFT, "title");
182 get(pPublisherFT, "publisher");
183 get(pAddressFT, "address");
184 get(pISBNFT, "isbn");
185 get(pChapterFT, "chapter");
186 get(pPagesFT, "pages");
187 get(pEditorFT, "editor");
188 get(pEditionFT, "edition");
189 get(pBooktitleFT, "booktitle");
190 get(pVolumeFT, "volume");
191 get(pHowpublishedFT, "publicationtype");
192 get(pOrganizationsFT, "organization");
193 get(pInstitutionFT, "institution");
194 get(pSchoolFT, "university");
195 get(pReportTypeFT, "reporttype");
196 get(pMonthFT, "month");
197 get(pJournalFT, "journal");
198 get(pNumberFT, "number");
199 get(pSeriesFT, "series");
200 get(pAnnoteFT, "annotation");
201 get(pNoteFT, "note");
202 get(pURLFT, "url");
203 get(pCustom1FT, "custom1");
204 get(pCustom2FT, "custom2");
205 get(pCustom3FT, "custom3");
206 get(pCustom4FT, "custom4");
207 get(pCustom5FT, "custom5");
209 InitFixedTexts();
211 sal_Int16* pMap = nFT2CtrlMap;
212 for( sal_uInt16 i = 0 ; i < FIELD_COUNT ; ++i, ++pMap )
214 aControls[ i ] = nullptr;
215 *pMap = -1;
218 BibConfig* pBibConfig = BibModul::GetConfig();
219 BibDBDescriptor aDesc;
220 aDesc.sDataSource = pDatMan->getActiveDataSource();
221 aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
222 aDesc.nCommandType = CommandType::TABLE;
223 const Mapping* pMapping = pBibConfig->GetMapping(aDesc);
225 xCtrlContnr = VCLUnoHelper::CreateControlContainer(pGrid);
227 std::vector<vcl::Window*> aChildren;
229 AddControlWithError(lcl_GetColumnName(pMapping, IDENTIFIER_POS), *pIdentifierFT,
230 sTableErrorString,
231 HID_BIB_IDENTIFIER_POS, 0, aChildren);
233 sTypeColumnName = lcl_GetColumnName(pMapping, AUTHORITYTYPE_POS);
235 AddControlWithError(sTypeColumnName, *pAuthTypeFT, sTableErrorString,
236 HID_BIB_AUTHORITYTYPE_POS, 1, aChildren);
238 AddControlWithError(lcl_GetColumnName(pMapping, YEAR_POS), *pYearFT,
239 sTableErrorString, HID_BIB_YEAR_POS, 2, aChildren);
241 AddControlWithError(lcl_GetColumnName(pMapping, AUTHOR_POS), *pAuthorFT,
242 sTableErrorString, HID_BIB_AUTHOR_POS, 3, aChildren);
244 AddControlWithError(lcl_GetColumnName(pMapping, TITLE_POS), *pTitleFT, sTableErrorString,
245 HID_BIB_TITLE_POS, 4, aChildren);
247 AddControlWithError(lcl_GetColumnName(pMapping, PUBLISHER_POS), *pPublisherFT,
248 sTableErrorString, HID_BIB_PUBLISHER_POS, 5, aChildren);
250 AddControlWithError(lcl_GetColumnName(pMapping, ADDRESS_POS), *pAddressFT,
251 sTableErrorString, HID_BIB_ADDRESS_POS, 6, aChildren);
253 AddControlWithError(lcl_GetColumnName(pMapping, ISBN_POS), *pISBNFT,
254 sTableErrorString, HID_BIB_ISBN_POS, 7, aChildren);
256 AddControlWithError(lcl_GetColumnName(pMapping, CHAPTER_POS), *pChapterFT,
257 sTableErrorString, HID_BIB_CHAPTER_POS, 8, aChildren);
259 AddControlWithError(lcl_GetColumnName(pMapping, PAGES_POS), *pPagesFT,
260 sTableErrorString, HID_BIB_PAGES_POS, 9, aChildren);
262 AddControlWithError(lcl_GetColumnName(pMapping, EDITOR_POS), *pEditorFT,
263 sTableErrorString, HID_BIB_EDITOR_POS, 10, aChildren);
265 AddControlWithError(lcl_GetColumnName(pMapping, EDITION_POS), *pEditionFT,
266 sTableErrorString, HID_BIB_EDITION_POS, 11, aChildren);
268 AddControlWithError(lcl_GetColumnName(pMapping, BOOKTITLE_POS), *pBooktitleFT,
269 sTableErrorString, HID_BIB_BOOKTITLE_POS, 12, aChildren);
271 AddControlWithError(lcl_GetColumnName(pMapping, VOLUME_POS), *pVolumeFT,
272 sTableErrorString, HID_BIB_VOLUME_POS, 13, aChildren);
274 AddControlWithError(lcl_GetColumnName(pMapping, HOWPUBLISHED_POS), *pHowpublishedFT,
275 sTableErrorString, HID_BIB_HOWPUBLISHED_POS, 14, aChildren);
277 AddControlWithError(lcl_GetColumnName(pMapping, ORGANIZATIONS_POS), *pOrganizationsFT,
278 sTableErrorString, HID_BIB_ORGANIZATIONS_POS, 15, aChildren);
280 AddControlWithError(lcl_GetColumnName(pMapping, INSTITUTION_POS), *pInstitutionFT,
281 sTableErrorString, HID_BIB_INSTITUTION_POS, 16, aChildren);
283 AddControlWithError(lcl_GetColumnName(pMapping, SCHOOL_POS), *pSchoolFT,
284 sTableErrorString, HID_BIB_SCHOOL_POS, 17, aChildren);
286 AddControlWithError(lcl_GetColumnName(pMapping, REPORTTYPE_POS), *pReportTypeFT,
287 sTableErrorString, HID_BIB_REPORTTYPE_POS, 18, aChildren);
289 AddControlWithError(lcl_GetColumnName(pMapping, MONTH_POS), *pMonthFT,
290 sTableErrorString, HID_BIB_MONTH_POS, 19, aChildren);
292 AddControlWithError(lcl_GetColumnName(pMapping, JOURNAL_POS), *pJournalFT,
293 sTableErrorString, HID_BIB_JOURNAL_POS, 20, aChildren);
295 AddControlWithError(lcl_GetColumnName(pMapping, NUMBER_POS), *pNumberFT,
296 sTableErrorString, HID_BIB_NUMBER_POS, 21, aChildren);
298 AddControlWithError(lcl_GetColumnName(pMapping, SERIES_POS), *pSeriesFT,
299 sTableErrorString, HID_BIB_SERIES_POS, 22, aChildren);
301 AddControlWithError(lcl_GetColumnName(pMapping, ANNOTE_POS), *pAnnoteFT,
302 sTableErrorString, HID_BIB_ANNOTE_POS, 23, aChildren);
304 AddControlWithError(lcl_GetColumnName(pMapping, NOTE_POS),*pNoteFT,
305 sTableErrorString, HID_BIB_NOTE_POS, 24, aChildren);
307 AddControlWithError(lcl_GetColumnName(pMapping, URL_POS), *pURLFT,
308 sTableErrorString, HID_BIB_URL_POS, 25, aChildren);
310 AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM1_POS), *pCustom1FT,
311 sTableErrorString, HID_BIB_CUSTOM1_POS, 26, aChildren);
313 AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM2_POS), *pCustom2FT,
314 sTableErrorString, HID_BIB_CUSTOM2_POS, 27, aChildren);
316 AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM3_POS), *pCustom3FT,
317 sTableErrorString, HID_BIB_CUSTOM3_POS, 28, aChildren);
319 AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM4_POS), *pCustom4FT,
320 sTableErrorString, HID_BIB_CUSTOM4_POS, 29, aChildren);
322 AddControlWithError(lcl_GetColumnName(pMapping, CUSTOM5_POS), *pCustom5FT,
323 sTableErrorString, HID_BIB_CUSTOM5_POS, 30, aChildren);
325 BuilderUtils::reorderWithinParent(aChildren, false);
327 xPosListener = new BibPosListener(this);
328 uno::Reference< sdbc::XRowSet > xRowSet(pDatMan->getForm(), UNO_QUERY);
329 if(xRowSet.is())
330 xRowSet->addRowSetListener(xPosListener);
331 uno::Reference< form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController();
332 xFormCtrl->setContainer(xCtrlContnr);
333 xFormCtrl->activateTabOrder();
335 if(!sTableErrorString.isEmpty())
336 sTableErrorString = BibResId(ST_ERROR_PREFIX) + sTableErrorString;
338 SetText(BibResId(ST_TYPE_TITLE));
340 Size aSize(LogicToPixel(Size(0, 209), MapMode(MapUnit::MapAppFont)));
341 set_height_request(aSize.Height());
344 BibGeneralPage::~BibGeneralPage()
346 disposeOnce();
349 void BibGeneralPage::dispose()
351 if (pDatMan && xPosListener.is())
353 uno::Reference< sdbc::XRowSet > xRowSet(pDatMan->getForm(), UNO_QUERY);
354 if(xRowSet.is())
355 xRowSet->removeRowSetListener(xPosListener);
357 pGrid.clear();
358 pScrolledWindow.clear();
359 pIdentifierFT.clear();
360 pAuthTypeFT.clear();
361 pYearFT.clear();
362 pAuthorFT.clear();
363 pTitleFT.clear();
364 pPublisherFT.clear();
365 pAddressFT.clear();
366 pISBNFT.clear();
367 pChapterFT.clear();
368 pPagesFT.clear();
369 pEditorFT.clear();
370 pEditionFT.clear();
371 pBooktitleFT.clear();
372 pVolumeFT.clear();
373 pHowpublishedFT.clear();
374 pOrganizationsFT.clear();
375 pInstitutionFT.clear();
376 pSchoolFT.clear();
377 pReportTypeFT.clear();
378 pMonthFT.clear();
379 pJournalFT.clear();
380 pNumberFT.clear();
381 pSeriesFT.clear();
382 pAnnoteFT.clear();
383 pNoteFT.clear();
384 pURLFT.clear();
385 pCustom1FT.clear();
386 pCustom2FT.clear();
387 pCustom3FT.clear();
388 pCustom4FT.clear();
389 pCustom5FT.clear();
390 for (auto & a: aFixedTexts) a.clear();
391 mxBibGeneralPageFocusListener.clear();
392 TabPage::dispose();
395 void BibGeneralPage::RemoveListeners()
397 for(uno::Reference<awt::XWindow> & aControl : aControls)
399 if(aControl.is())
401 uno::Reference< awt::XWindow > xCtrWin(aControl, uno::UNO_QUERY );
402 xCtrWin->removeFocusListener( mxBibGeneralPageFocusListener.get() );
403 aControl = nullptr;
408 void BibGeneralPage::CommitActiveControl()
410 uno::Reference< form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController();
411 uno::Reference< awt::XControl > xCurr = xFormCtrl->getCurrentControl();
412 if(xCurr.is())
414 uno::Reference< awt::XControlModel > xModel = xCurr->getModel();
415 uno::Reference< form::XBoundComponent > xBound(xModel, UNO_QUERY);
416 if(xBound.is())
417 xBound->commit();
421 void BibGeneralPage::AddControlWithError( const OUString& rColumnName, FixedText &rLabel,
422 OUString& rErrorString, const OString& sHelpId, sal_uInt16 nIndexInFTArray, std::vector<vcl::Window*> &rChildren)
424 const OUString aColumnUIName(rLabel.GetText());
425 // adds also the XControl and creates a map entry in nFT2CtrlMap[] for mapping between control and FT
427 sal_Int16 nIndex = -1;
428 uno::Reference< awt::XControlModel > xTmp = AddXControl(rColumnName, rLabel, sHelpId, nIndex, rChildren);
429 if( xTmp.is() )
431 DBG_ASSERT( nIndexInFTArray < FIELD_COUNT, "*BibGeneralPage::AddControlWithError(): wrong array index!" );
432 DBG_ASSERT( nFT2CtrlMap[ nIndexInFTArray ] < 0, "+BibGeneralPage::AddControlWithError(): index already in use!" );
434 nFT2CtrlMap[ nIndexInFTArray ] = nIndex;
436 else
438 if( !rErrorString.isEmpty() )
439 rErrorString += "\n";
441 rErrorString += MnemonicGenerator::EraseAllMnemonicChars( aColumnUIName );
445 uno::Reference< awt::XControlModel > BibGeneralPage::AddXControl(
446 const OUString& rName,
447 FixedText& rLabel, const OString& sHelpId, sal_Int16& rIndex,
448 std::vector<vcl::Window*>& rChildren)
450 uno::Reference< awt::XControlModel > xCtrModel;
453 const bool bTypeListBox = sTypeColumnName == rName;
454 xCtrModel = pDatMan->loadControlModel(rName, bTypeListBox);
455 if ( xCtrModel.is() )
457 uno::Reference< beans::XPropertySet > xPropSet( xCtrModel, UNO_QUERY );
459 if( xPropSet.is())
461 uno::Reference< beans::XPropertySetInfo > xPropInfo = xPropSet->getPropertySetInfo();
463 OUString aControlName;
464 if (bTypeListBox)
466 aControlName = "com.sun.star.form.control.ListBox";
467 xLBModel.set(xCtrModel, UNO_QUERY);
469 else
471 uno::Any aAny = xPropSet->getPropertyValue( "DefaultControl" );
472 aAny >>= aControlName;
475 OUString uProp("HelpURL");
476 if(xPropInfo->hasPropertyByName(uProp))
478 OUString sId( INET_HID_SCHEME );
479 DBG_ASSERT( INetURLObject( OStringToOUString( sHelpId, RTL_TEXTENCODING_UTF8 ) ).GetProtocol() == INetProtocol::NotValid, "Wrong HelpId!" );
480 sId += OStringToOUString( sHelpId, RTL_TEXTENCODING_UTF8 );
481 xPropSet->setPropertyValue( uProp, makeAny( sId ) );
484 uno::Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
485 uno::Reference< awt::XControl > xControl( xContext->getServiceManager()->createInstanceWithContext(aControlName, xContext), UNO_QUERY);
486 if ( xControl.is() )
488 xControl->setModel( xCtrModel);
490 // Peer as Child to the FrameWindow
491 xCtrlContnr->addControl(rName, xControl);
492 uno::Reference< awt::XWindow > xCtrWin(xControl, UNO_QUERY );
493 xCtrWin->addFocusListener( mxBibGeneralPageFocusListener.get() );
494 rIndex = -1; // -> implies, that not found
495 for(sal_uInt16 i = 0; i < FIELD_COUNT; i++)
496 if(!aControls[i].is())
498 aControls[i] = xCtrWin;
499 rIndex = sal_Int16( i );
500 break;
502 // initially switch on the design mode - switch it off _after_ loading the form
503 xCtrWin->setVisible( true );
504 xControl->setDesignMode( true );
506 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xControl->getPeer());
507 pWindow->set_grid_top_attach(rLabel.get_grid_top_attach());
508 pWindow->set_grid_left_attach(rLabel.get_grid_left_attach()+1);
509 pWindow->set_valign(VclAlign::Center);
510 rLabel.set_mnemonic_widget(pWindow);
511 if (&rLabel == pTitleFT)
512 pWindow->set_grid_width(3);
513 else
514 pWindow->set_hexpand(true);
515 rChildren.push_back(&rLabel);
516 rChildren.push_back(pWindow);
521 catch(const Exception&)
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)
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()
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 std::vector<sal_Int16>::size_type nFocused = 0xFFFF; // index of focused in vector, no one focused initial
641 DBG_ASSERT( nFocused > 0, "*BibGeneralPage::HandleShortCutKey(): size_type works not as expected!" );
643 std::vector<sal_Int16> aMatchList;
645 for( i = 0 ; i < FIELD_COUNT ; ++i )
647 if( rI18nHelper.MatchMnemonic( aFixedTexts[ i ]->GetText(), c ) )
649 bHandled = true;
650 sal_Int16 nCtrlIndex = nFT2CtrlMap[ i ];
652 if( nCtrlIndex >= 0 )
653 { // store index of control
654 DBG_ASSERT( aControls[ nCtrlIndex ].is(), "-BibGeneralPage::HandleShortCutKey(): valid index and no control?" );
656 uno::Reference< awt::XControl > xControl( aControls[ nCtrlIndex ], UNO_QUERY );
657 DBG_ASSERT( xControl.is(), "-BibGeneralPage::HandleShortCutKey(): a control which is not a control!" );
659 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xControl->getPeer() );
661 if( pWindow )
663 aMatchList.push_back( nCtrlIndex );
664 if( pWindow->HasChildPathFocus() )
665 { // save focused control
666 DBG_ASSERT( nFocused == 0xFFFF, "+BibGeneralPage::HandleShortCutKey(): more than one with focus?!" );
667 DBG_ASSERT( !aMatchList.empty(), "+BibGeneralPage::HandleShortCutKey(): push_back and no content?!" );
668 nFocused = aMatchList.size() - 1;
675 if( bHandled )
677 DBG_ASSERT( !aMatchList.empty(), "*BibGeneralPage::HandleShortCutKey(): be prepared to crash..." );
679 if( nFocused >= ( aMatchList.size() - 1 ) )
680 // >=... includes 0xFFFF
681 // no one or last focused, take first
682 nFocused = 0;
683 else
684 // take next one
685 nFocused++;
687 aControls[ aMatchList[ nFocused ] ]->setFocus();
690 return bHandled;
693 BibGeneralPageFocusListener::BibGeneralPageFocusListener(BibGeneralPage *pBibGeneralPage): mpBibGeneralPage(pBibGeneralPage)
696 void BibGeneralPageFocusListener::focusGained( const css::awt::FocusEvent& e )
698 mpBibGeneralPage->focusGained(e);
701 void BibGeneralPageFocusListener::focusLost( const css::awt::FocusEvent& )
703 mpBibGeneralPage->focusLost();
706 void BibGeneralPageFocusListener::disposing( const css::lang::EventObject& )
709 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */