1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
36 #include "bibconfig.hxx"
37 #include "bibprop.hxx"
38 #include <strings.hrc>
40 #include "bibview.hxx"
41 #include "bibtools.hxx"
43 #include <tools/debug.hxx>
44 #include <vcl/svapp.hxx>
45 #include <vcl/i18nhelp.hxx>
46 #include <vcl/mnemonic.hxx>
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
);
62 for(const auto & aColumnPair
: pMapping
->aColumnPairs
)
64 if(aColumnPair
.sLogicalColumnName
== sRet
)
66 sRet
= aColumnPair
.sRealColumnName
;
73 class BibPosListener
:public cppu::WeakImplHelper
<sdbc::XRowSetListener
>
75 VclPtr
<BibGeneralPage
> pParentPage
;
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 */ }
85 virtual void SAL_CALL
disposing(const lang::EventObject
& Source
) override
;
89 BibPosListener::BibPosListener(BibGeneralPage
* pParent
) :
94 void BibPosListener::cursorMoved(const lang::EventObject
& /*aEvent*/)
98 uno::Reference
< form::XBoundComponent
> xLstBox
= pParentPage
->GetTypeListBoxModel();
99 uno::Reference
< beans::XPropertySet
> xPropSet(xLstBox
, UNO_QUERY
);
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
);
113 for(const auto & aColumnPair
: pMapping
->aColumnPairs
)
115 if(aColumnPair
.sLogicalColumnName
== sTypeMapping
)
117 sTypeMapping
= aColumnPair
.sRealColumnName
;
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) !");
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();
148 if(nTempVal
< 0 || nTempVal
>= TYPE_COUNT
)
151 uno::Sequence
<sal_Int16
> aSelSeq(1);
152 sal_Int16
* pArr
= aSelSeq
.getArray();
153 pArr
[0] = TYPE_COUNT
;
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)),
175 get(pIdentifierFT
, "shortname");
176 get(pAuthTypeFT
, "authtype");
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");
203 get(pCustom1FT
, "custom1");
204 get(pCustom2FT
, "custom2");
205 get(pCustom3FT
, "custom3");
206 get(pCustom4FT
, "custom4");
207 get(pCustom5FT
, "custom5");
211 sal_Int16
* pMap
= nFT2CtrlMap
;
212 for( sal_uInt16 i
= 0 ; i
< FIELD_COUNT
; ++i
, ++pMap
)
214 aControls
[ i
] = nullptr;
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
,
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
);
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()
349 void BibGeneralPage::dispose()
351 if (pDatMan
&& xPosListener
.is())
353 uno::Reference
< sdbc::XRowSet
> xRowSet(pDatMan
->getForm(), UNO_QUERY
);
355 xRowSet
->removeRowSetListener(xPosListener
);
358 pScrolledWindow
.clear();
359 pIdentifierFT
.clear();
364 pPublisherFT
.clear();
371 pBooktitleFT
.clear();
373 pHowpublishedFT
.clear();
374 pOrganizationsFT
.clear();
375 pInstitutionFT
.clear();
377 pReportTypeFT
.clear();
390 for (auto & a
: aFixedTexts
) a
.clear();
391 mxBibGeneralPageFocusListener
.clear();
395 void BibGeneralPage::RemoveListeners()
397 for(uno::Reference
<awt::XWindow
> & aControl
: aControls
)
401 aControl
->removeFocusListener( mxBibGeneralPageFocusListener
.get() );
407 void BibGeneralPage::CommitActiveControl()
409 uno::Reference
< form::runtime::XFormController
> xFormCtrl
= pDatMan
->GetFormController();
410 uno::Reference
< awt::XControl
> xCurr
= xFormCtrl
->getCurrentControl();
413 uno::Reference
< awt::XControlModel
> xModel
= xCurr
->getModel();
414 uno::Reference
< form::XBoundComponent
> xBound(xModel
, UNO_QUERY
);
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
);
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
;
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
);
460 uno::Reference
< beans::XPropertySetInfo
> xPropInfo
= xPropSet
->getPropertySetInfo();
462 OUString aControlName
;
465 aControlName
= "com.sun.star.form.control.ListBox";
466 xLBModel
.set(xCtrModel
, UNO_QUERY
);
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
);
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
);
501 // initially switch on the design mode - switch it off _after_ loading the form
502 xCtrWin
->setVisible( true );
503 xControl
->setDesignMode( true );
505 VclPtr
<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(VclAlign::Center
);
509 rLabel
.set_mnemonic_widget(pWindow
);
510 if (&rLabel
== pTitleFT
)
511 pWindow
->set_grid_width(3);
513 pWindow
->set_hexpand(true);
514 rChildren
.push_back(&rLabel
);
515 rChildren
.push_back(pWindow
);
520 catch(const Exception
&)
522 OSL_FAIL("BibGeneralPage::AddXControl: something went wrong!");
527 void BibGeneralPage::InitFixedTexts()
529 aFixedTexts
[0] = pIdentifierFT
;
530 aFixedTexts
[1] = pAuthTypeFT
;
531 aFixedTexts
[2] = pYearFT
;
532 aFixedTexts
[3] = pAuthorFT
;
533 aFixedTexts
[4] = pTitleFT
;
534 aFixedTexts
[5] = pPublisherFT
;
535 aFixedTexts
[6] = pAddressFT
;
536 aFixedTexts
[7] = pISBNFT
;
537 aFixedTexts
[8] = pChapterFT
;
538 aFixedTexts
[9] = pPagesFT
;
540 aFixedTexts
[10] = pEditorFT
;
541 aFixedTexts
[11] = pEditionFT
;
542 aFixedTexts
[12] = pBooktitleFT
;
543 aFixedTexts
[13] = pVolumeFT
;
544 aFixedTexts
[14] = pHowpublishedFT
;
545 aFixedTexts
[15] = pOrganizationsFT
;
546 aFixedTexts
[16] = pInstitutionFT
;
547 aFixedTexts
[17] = pSchoolFT
;
548 aFixedTexts
[18] = pReportTypeFT
;
549 aFixedTexts
[19] = pMonthFT
;
551 aFixedTexts
[20] = pJournalFT
;
552 aFixedTexts
[21] = pNumberFT
;
553 aFixedTexts
[22] = pSeriesFT
;
554 aFixedTexts
[23] = pAnnoteFT
;
555 aFixedTexts
[24] = pNoteFT
;
556 aFixedTexts
[25] = pURLFT
;
558 aFixedTexts
[26] = pCustom1FT
;
559 aFixedTexts
[27] = pCustom2FT
;
560 aFixedTexts
[28] = pCustom3FT
;
561 aFixedTexts
[29] = pCustom4FT
;
562 aFixedTexts
[30] = pCustom5FT
;
566 MnemonicGenerator aMnemonicGenerator
;
568 OUString aFixedStrings
[ FIELD_COUNT
];
569 for( i
= 0 ; i
< FIELD_COUNT
; ++i
)
570 aFixedStrings
[i
] = aFixedTexts
[i
]->GetText();
572 // init mnemonics, first register all strings
573 for( i
= 0 ; i
< FIELD_COUNT
; ++i
)
574 aMnemonicGenerator
.RegisterMnemonic( aFixedStrings
[ i
] );
576 // ... then get all strings
577 for( i
= 0 ; i
< FIELD_COUNT
; ++i
)
578 aMnemonicGenerator
.CreateMnemonic( aFixedStrings
[ i
] );
581 for( i
= 0 ; i
< FIELD_COUNT
; ++i
)
582 aFixedTexts
[ i
]->SetText( aFixedStrings
[ i
] );
585 void BibGeneralPage::focusGained(const awt::FocusEvent
& rEvent
)
587 Reference
<awt::XWindow
> xCtrWin(rEvent
.Source
, UNO_QUERY
);
590 ::Size aOutSize
= pScrolledWindow
->getVisibleChildSize();
591 awt::Rectangle aRect
= xCtrWin
->getPosSize();
592 Point
aOffset(pGrid
->GetPosPixel());
593 long nX
= aRect
.X
+ aOffset
.X();
594 if (nX
< 0 || nX
> aOutSize
.Width())
596 pScrolledWindow
->getHorzScrollBar().DoScroll(aRect
.X
);
599 long nY
= aRect
.Y
+ aOffset
.Y();
600 if (nY
< 0 || nY
> aOutSize
.Height())
602 pScrolledWindow
->getVertScrollBar().DoScroll(aRect
.Y
);
607 void BibGeneralPage::focusLost()
609 CommitActiveControl();
612 void BibGeneralPage::GetFocus()
614 Reference
< awt::XWindow
>* pxControl
= aControls
;
616 for( int i
= FIELD_COUNT
; i
; --i
, ++pxControl
)
618 if( pxControl
->is() )
620 ( *pxControl
)->setFocus();
629 bool BibGeneralPage::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
631 DBG_ASSERT( KEY_MOD2
== rKeyEvent
.GetKeyCode().GetModifier(), "+BibGeneralPage::HandleShortCutKey(): this is not for me!" );
633 const vcl::I18nHelper
& rI18nHelper
= Application::GetSettings().GetUILocaleI18nHelper();
634 const sal_Unicode c
= rKeyEvent
.GetCharCode();
635 bool bHandled
= false;
639 std::vector
<sal_Int16
>::size_type nFocused
= 0xFFFF; // index of focused in vector, no one focused initial
640 DBG_ASSERT( nFocused
> 0, "*BibGeneralPage::HandleShortCutKey(): size_type works not as expected!" );
642 std::vector
<sal_Int16
> aMatchList
;
644 for( i
= 0 ; i
< FIELD_COUNT
; ++i
)
646 if( rI18nHelper
.MatchMnemonic( aFixedTexts
[ i
]->GetText(), c
) )
649 sal_Int16 nCtrlIndex
= nFT2CtrlMap
[ i
];
651 if( nCtrlIndex
>= 0 )
652 { // store index of control
653 DBG_ASSERT( aControls
[ nCtrlIndex
].is(), "-BibGeneralPage::HandleShortCutKey(): valid index and no control?" );
655 uno::Reference
< awt::XControl
> xControl( aControls
[ nCtrlIndex
], UNO_QUERY
);
656 DBG_ASSERT( xControl
.is(), "-BibGeneralPage::HandleShortCutKey(): a control which is not a control!" );
658 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow( xControl
->getPeer() );
662 aMatchList
.push_back( nCtrlIndex
);
663 if( pWindow
->HasChildPathFocus() )
664 { // save focused control
665 DBG_ASSERT( nFocused
== 0xFFFF, "+BibGeneralPage::HandleShortCutKey(): more than one with focus?!" );
666 DBG_ASSERT( !aMatchList
.empty(), "+BibGeneralPage::HandleShortCutKey(): push_back and no content?!" );
667 nFocused
= aMatchList
.size() - 1;
676 DBG_ASSERT( !aMatchList
.empty(), "*BibGeneralPage::HandleShortCutKey(): be prepared to crash..." );
678 if( nFocused
>= ( aMatchList
.size() - 1 ) )
679 // >=... includes 0xFFFF
680 // no one or last focused, take first
686 aControls
[ aMatchList
[ nFocused
] ]->setFocus();
692 BibGeneralPageFocusListener::BibGeneralPageFocusListener(BibGeneralPage
*pBibGeneralPage
): mpBibGeneralPage(pBibGeneralPage
)
695 void BibGeneralPageFocusListener::focusGained( const css::awt::FocusEvent
& e
)
697 mpBibGeneralPage
->focusGained(e
);
700 void BibGeneralPageFocusListener::focusLost( const css::awt::FocusEvent
& )
702 mpBibGeneralPage
->focusLost();
705 void BibGeneralPageFocusListener::disposing( const css::lang::EventObject
& )
708 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */