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/form/ListSourceType.hpp>
27 #include <com/sun/star/awt/XWindow.hpp>
28 #include <toolkit/helper/vclunohelper.hxx>
29 #include <cppuhelper/implbase1.hxx> // helper for implementations
30 #include "general.hxx"
31 #include "sections.hrc"
32 #include "bibresid.hxx"
34 #include "bibconfig.hxx"
35 #include "bibprop.hrc"
38 #include "bibtools.hxx"
39 #include "bibliography.hrc"
40 #include <tools/debug.hxx>
41 #include <vcl/svapp.hxx>
42 #include <vcl/i18nhelp.hxx>
43 #include <vcl/mnemonic.hxx>
47 #include <tools/urlobj.hxx>
49 using namespace ::com::sun::star
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::form
;
52 using namespace ::com::sun::star::sdb
;
53 using namespace ::rtl
;
55 #define DISTANCE_CONTROL_TO_FIXEDTEXT 5
57 static ::Point
lcl_MovePoint(const FixedText
& rFixedText
)
59 ::Point
aRet(rFixedText
.GetPosPixel());
60 aRet
.X() += rFixedText
.GetSizePixel().Width();
61 aRet
.X() += DISTANCE_CONTROL_TO_FIXEDTEXT
;
65 //-----------------------------------------------------------------------------
66 static OUString
lcl_GetColumnName( const Mapping
* pMapping
, sal_uInt16 nIndexPos
)
68 BibConfig
* pBibConfig
= BibModul::GetConfig();
69 OUString sRet
= pBibConfig
->GetDefColumnName(nIndexPos
);
71 for(sal_uInt16 i
= 0; i
< COLUMN_COUNT
; i
++)
73 if(pMapping
->aColumnPairs
[i
].sLogicalColumnName
== sRet
)
75 sRet
= pMapping
->aColumnPairs
[i
].sRealColumnName
;
82 class BibPosListener
:public cppu::WeakImplHelper1
<sdbc::XRowSetListener
>
84 BibGeneralPage
* pParentPage
;
86 BibPosListener(BibGeneralPage
* pParent
);
88 //XPositioningListener
89 virtual void SAL_CALL
cursorMoved(const lang::EventObject
& event
) throw( uno::RuntimeException
);
90 virtual void SAL_CALL
rowChanged(const lang::EventObject
& /*event*/) throw( uno::RuntimeException
){ /* not interested in */ }
91 virtual void SAL_CALL
rowSetChanged(const lang::EventObject
& /*event*/) throw( uno::RuntimeException
){ /* not interested in */ }
94 virtual void SAL_CALL
disposing(const lang::EventObject
& Source
) throw( uno::RuntimeException
);
98 BibPosListener::BibPosListener(BibGeneralPage
* pParent
) :
103 void BibPosListener::cursorMoved(const lang::EventObject
& /*aEvent*/) throw( uno::RuntimeException
)
107 uno::Reference
< form::XBoundComponent
> xLstBox
= pParentPage
->GetTypeListBoxModel();
108 uno::Reference
< beans::XPropertySet
> xPropSet(xLstBox
, UNO_QUERY
);
111 BibConfig
* pBibConfig
= BibModul::GetConfig();
112 BibDataManager
* pDatMan
= pParentPage
->GetDataManager();
113 BibDBDescriptor aDesc
;
114 aDesc
.sDataSource
= pDatMan
->getActiveDataSource();
115 aDesc
.sTableOrQuery
= pDatMan
->getActiveDataTable();
116 aDesc
.nCommandType
= CommandType::TABLE
;
118 const Mapping
* pMapping
= pBibConfig
->GetMapping(aDesc
);
119 OUString sTypeMapping
= pBibConfig
->GetDefColumnName(AUTHORITYTYPE_POS
);
122 for(sal_uInt16 nEntry
= 0; nEntry
< COLUMN_COUNT
; nEntry
++)
124 if(pMapping
->aColumnPairs
[nEntry
].sLogicalColumnName
== sTypeMapping
)
126 sTypeMapping
= pMapping
->aColumnPairs
[nEntry
].sRealColumnName
;
131 OUString uTypeMapping
= sTypeMapping
;
133 uno::Reference
< form::XForm
> xForm
= pDatMan
->getForm();
134 uno::Reference
< sdbcx::XColumnsSupplier
> xSupplyCols(xForm
, UNO_QUERY
);
135 uno::Reference
< container::XNameAccess
> xValueAcc
;
136 if (xSupplyCols
.is())
137 xValueAcc
= xSupplyCols
->getColumns();
139 sal_Int16 nTempVal
= -1;
140 if(xValueAcc
.is() && xValueAcc
->hasByName(uTypeMapping
))
142 uno::Any aVal
= xValueAcc
->getByName(uTypeMapping
);
143 uno::Reference
< uno::XInterface
> xInt
= *(uno::Reference
< uno::XInterface
> *)aVal
.getValue();
144 uno::Reference
< sdb::XColumn
> xCol(xInt
, UNO_QUERY
);
145 DBG_ASSERT(xCol
.is(), "BibPosListener::cursorMoved : invalid column (no sdb::XColumn) !");
148 nTempVal
= xCol
->getShort();
149 // getShort returns zero if the value is not a number
150 if (!nTempVal
|| xCol
->wasNull())
152 OUString sTempVal
= xCol
->getString();
153 if(sTempVal
!= OUString('0'))
158 if(nTempVal
< 0 || nTempVal
>= TYPE_COUNT
)
161 uno::Sequence
<sal_Int16
> aSelSeq(1);
162 sal_Int16
* pArr
= aSelSeq
.getArray();
163 pArr
[0] = TYPE_COUNT
;
164 aSel
.setValue(&aSelSeq
, ::getCppuType((Sequence
<sal_Int16
>*)0));
165 xPropSet
->setPropertyValue("SelectedItems", aSel
);
169 catch(const Exception
&)
171 OSL_FAIL("BibPosListener::cursorMoved: something went wrong !");
175 void BibPosListener::disposing(const lang::EventObject
& /*Source*/) throw( uno::RuntimeException
)
179 BibGeneralPage::BibGeneralPage(Window
* pParent
, BibDataManager
* pMan
):
180 BibTabPage(pParent
,BibResId(RID_TP_GENERAL
)),
181 aControlParentWin(this, WB_DIALOGCONTROL
),
182 aIdentifierFT(&aControlParentWin
, BibResId(FT_IDENTIFIER
)),
183 aAuthTypeFT(&aControlParentWin
, BibResId(FT_AUTHTYPE
)),
184 aYearFT(&aControlParentWin
, BibResId(FT_YEAR
)),
185 aAuthorFT(&aControlParentWin
, BibResId(FT_AUTHOR
)),
186 aTitleFT(&aControlParentWin
, BibResId(FT_TITLE
)),
187 aPublisherFT(&aControlParentWin
, BibResId(FT_PUBLISHER
)),
188 aAddressFT(&aControlParentWin
, BibResId(FT_ADDRESS
)),
189 aISBNFT(&aControlParentWin
, BibResId(FT_ISBN
)),
190 aChapterFT(&aControlParentWin
, BibResId(FT_CHAPTER
)),
191 aPagesFT(&aControlParentWin
, BibResId(FT_PAGE
)),
192 aFirstFL(&aControlParentWin
, BibResId(FL_1
)),
193 aEditorFT(&aControlParentWin
, BibResId(FT_EDITOR
)),
194 aEditionFT(&aControlParentWin
, BibResId(FT_EDITION
)),
195 aBooktitleFT(&aControlParentWin
, BibResId(FT_BOOKTITLE
)),
196 aVolumeFT(&aControlParentWin
, BibResId(FT_VOLUME
)),
197 aHowpublishedFT(&aControlParentWin
, BibResId(FT_HOWPUBLISHED
)),
198 aOrganizationsFT(&aControlParentWin
,BibResId(FT_ORGANIZATION
)),
199 aInstitutionFT(&aControlParentWin
, BibResId(FT_INSTITUTION
)),
200 aSchoolFT(&aControlParentWin
, BibResId(FT_SCHOOL
)),
201 aReportTypeFT(&aControlParentWin
, BibResId(FT_REPORT
)),
202 aMonthFT(&aControlParentWin
, BibResId(FT_MONTH
)),
203 aSecondFL(&aControlParentWin
, BibResId(FL_2
)),
204 aJournalFT(&aControlParentWin
, BibResId(FT_JOURNAL
)),
205 aNumberFT(&aControlParentWin
, BibResId(FT_NUMBER
)),
206 aSeriesFT(&aControlParentWin
, BibResId(FT_SERIES
)),
207 aAnnoteFT(&aControlParentWin
, BibResId(FT_ANNOTE
)),
208 aNoteFT(&aControlParentWin
, BibResId(FT_NOTE
)),
209 aURLFT(&aControlParentWin
, BibResId(FT_URL
)),
210 aThirdFL(&aControlParentWin
, BibResId(FL_3
)),
211 aCustom1FT(&aControlParentWin
, BibResId(FT_CUSTOM1
)),
212 aCustom2FT(&aControlParentWin
, BibResId(FT_CUSTOM2
)),
213 aCustom3FT(&aControlParentWin
, BibResId(FT_CUSTOM3
)),
214 aCustom4FT(&aControlParentWin
, BibResId(FT_CUSTOM4
)),
215 aCustom5FT(&aControlParentWin
, BibResId(FT_CUSTOM5
)),
216 aHoriScroll(this, WB_HORZ
),
217 aVertScroll(this, WB_VERT
),
218 sErrorPrefix(BibResId(ST_ERROR_PREFIX
)),
221 aControlParentWin
.Show();
222 aControlParentWin
.SetHelpId(HID_BIB_CONTROL_PARENT
);
223 aStdSize
= GetOutputSizePixel();
225 aBibTypeArr
[0] = String(BibResId(ST_TYPE_ARTICLE
));
226 aBibTypeArr
[1] = String(BibResId(ST_TYPE_BOOK
));
227 aBibTypeArr
[2] = String(BibResId(ST_TYPE_BOOKLET
));
228 aBibTypeArr
[3] = String(BibResId(ST_TYPE_CONFERENCE
));
229 aBibTypeArr
[4] = String(BibResId(ST_TYPE_INBOOK
));
230 aBibTypeArr
[5] = String(BibResId(ST_TYPE_INCOLLECTION
));
231 aBibTypeArr
[6] = String(BibResId(ST_TYPE_INPROCEEDINGS
));
232 aBibTypeArr
[7] = String(BibResId(ST_TYPE_JOURNAL
));
233 aBibTypeArr
[8] = String(BibResId(ST_TYPE_MANUAL
));
234 aBibTypeArr
[9] = String(BibResId(ST_TYPE_MASTERSTHESIS
));
235 aBibTypeArr
[10] = String(BibResId(ST_TYPE_MISC
));
236 aBibTypeArr
[11] = String(BibResId(ST_TYPE_PHDTHESIS
));
237 aBibTypeArr
[12] = String(BibResId(ST_TYPE_PROCEEDINGS
));
238 aBibTypeArr
[13] = String(BibResId(ST_TYPE_TECHREPORT
));
239 aBibTypeArr
[14] = String(BibResId(ST_TYPE_UNPUBLISHED
));
240 aBibTypeArr
[15] = String(BibResId(ST_TYPE_EMAIL
));
241 aBibTypeArr
[16] = String(BibResId(ST_TYPE_WWW
));
242 aBibTypeArr
[17] = String(BibResId(ST_TYPE_CUSTOM1
));
243 aBibTypeArr
[18] = String(BibResId(ST_TYPE_CUSTOM2
));
244 aBibTypeArr
[19] = String(BibResId(ST_TYPE_CUSTOM3
));
245 aBibTypeArr
[20] = String(BibResId(ST_TYPE_CUSTOM4
));
246 aBibTypeArr
[21] = String(BibResId(ST_TYPE_CUSTOM5
));
252 aBasePos
= aIdentifierFT
.GetPosPixel();
254 sal_Int16
* pMap
= nFT2CtrlMap
;
255 for( sal_uInt16 i
= 0 ; i
< FIELD_COUNT
; ++i
, ++pMap
)
262 Link
aScrollLnk(LINK(this, BibGeneralPage
, ScrollHdl
));
263 aHoriScroll
.SetScrollHdl( aScrollLnk
);
264 aVertScroll
.SetScrollHdl( aScrollLnk
);
265 aHoriScroll
.SetLineSize(10);
266 aVertScroll
.SetLineSize(10);
267 aHoriScroll
.SetPageSize( aIdentifierFT
.GetSizePixel().Width());
268 aVertScroll
.SetPageSize(
269 aPublisherFT
.GetPosPixel().Y() - aIdentifierFT
.GetPosPixel().Y());
273 BibConfig
* pBibConfig
= BibModul::GetConfig();
274 BibDBDescriptor aDesc
;
275 aDesc
.sDataSource
= pDatMan
->getActiveDataSource();
276 aDesc
.sTableOrQuery
= pDatMan
->getActiveDataTable();
277 aDesc
.nCommandType
= CommandType::TABLE
;
278 const Mapping
* pMapping
= pBibConfig
->GetMapping(aDesc
);
280 xCtrlContnr
= VCLUnoHelper::CreateControlContainer(&aControlParentWin
);
282 // the control should be a bit smaller than the fixed text
283 Size
aControlSize(aIdentifierFT
.GetSizePixel());
284 aControlSize
.Width() = aControlSize
.Width() * 8 / 10;
286 AddControlWithError( lcl_GetColumnName( pMapping
, IDENTIFIER_POS
), lcl_MovePoint( aIdentifierFT
),
287 aControlSize
, sTableErrorString
, aIdentifierFT
.GetText(),
288 HID_BIB_IDENTIFIER_POS
, 0 );
290 sTypeColumnName
= lcl_GetColumnName(pMapping
, AUTHORITYTYPE_POS
);
292 AddControlWithError( sTypeColumnName
, lcl_MovePoint(aAuthTypeFT
), aControlSize
, sTableErrorString
,
293 aAuthTypeFT
.GetText(), HID_BIB_AUTHORITYTYPE_POS
, 1 );
295 ::Point aYearPos
= lcl_MovePoint(aYearFT
);
296 AddControlWithError( lcl_GetColumnName( pMapping
, YEAR_POS
), aYearPos
,
297 aControlSize
, sTableErrorString
, aYearFT
.GetText(), HID_BIB_YEAR_POS
, 4 );
299 AddControlWithError( lcl_GetColumnName(pMapping
, AUTHOR_POS
), lcl_MovePoint(aAuthorFT
),
300 aControlSize
, sTableErrorString
, aAuthorFT
.GetText(), HID_BIB_AUTHOR_POS
, 2 );
302 ::Point
aTitlePos( lcl_MovePoint( aTitleFT
) );
303 ::Size aTitleSize
= aTitleFT
.GetSizePixel();
304 aTitleSize
.Width() = aYearPos
.X() + aControlSize
.Width() - aTitlePos
.X();
305 AddControlWithError( lcl_GetColumnName(pMapping
, TITLE_POS
), aTitlePos
, aTitleSize
, sTableErrorString
,
306 aTitleFT
.GetText(), HID_BIB_TITLE_POS
, 22 );
308 AddControlWithError( lcl_GetColumnName( pMapping
, PUBLISHER_POS
), lcl_MovePoint( aPublisherFT
),
309 aControlSize
, sTableErrorString
, aPublisherFT
.GetText(), HID_BIB_PUBLISHER_POS
, 5 );
311 AddControlWithError( lcl_GetColumnName( pMapping
, ADDRESS_POS
), lcl_MovePoint( aAddressFT
),
312 aControlSize
, sTableErrorString
, aAddressFT
.GetText(), HID_BIB_ADDRESS_POS
, 7 );
314 AddControlWithError( lcl_GetColumnName( pMapping
, ISBN_POS
), lcl_MovePoint( aISBNFT
),
315 aControlSize
, sTableErrorString
, aISBNFT
.GetText(), HID_BIB_ISBN_POS
, 6 );
317 AddControlWithError( lcl_GetColumnName( pMapping
, CHAPTER_POS
), lcl_MovePoint(aChapterFT
),
318 aControlSize
, sTableErrorString
, aChapterFT
.GetText(), HID_BIB_CHAPTER_POS
, 10 );
320 AddControlWithError( lcl_GetColumnName( pMapping
, PAGES_POS
), lcl_MovePoint( aPagesFT
),
321 aControlSize
, sTableErrorString
, aPagesFT
.GetText(), HID_BIB_PAGES_POS
, 19 );
323 AddControlWithError( lcl_GetColumnName( pMapping
, EDITOR_POS
), lcl_MovePoint( aEditorFT
),
324 aControlSize
, sTableErrorString
, aEditorFT
.GetText(), HID_BIB_EDITOR_POS
, 12 );
326 AddControlWithError( lcl_GetColumnName( pMapping
, EDITION_POS
), lcl_MovePoint(aEditionFT
),
327 aControlSize
, sTableErrorString
, aEditionFT
.GetText(), HID_BIB_EDITION_POS
, 11 );
329 AddControlWithError( lcl_GetColumnName(pMapping
, BOOKTITLE_POS
), lcl_MovePoint(aBooktitleFT
),
330 aControlSize
, sTableErrorString
, aBooktitleFT
.GetText(), HID_BIB_BOOKTITLE_POS
, 9 );
332 AddControlWithError( lcl_GetColumnName( pMapping
, VOLUME_POS
), lcl_MovePoint( aVolumeFT
),
333 aControlSize
, sTableErrorString
, aVolumeFT
.GetText(), HID_BIB_VOLUME_POS
, 24 );
335 AddControlWithError( lcl_GetColumnName( pMapping
, HOWPUBLISHED_POS
), lcl_MovePoint( aHowpublishedFT
),
336 aControlSize
, sTableErrorString
, aHowpublishedFT
.GetText(), HID_BIB_HOWPUBLISHED_POS
, 13 );
338 AddControlWithError( lcl_GetColumnName( pMapping
, ORGANIZATIONS_POS
), lcl_MovePoint( aOrganizationsFT
),
339 aControlSize
, sTableErrorString
, aOrganizationsFT
.GetText(), HID_BIB_ORGANIZATIONS_POS
, 18 );
341 AddControlWithError( lcl_GetColumnName( pMapping
, INSTITUTION_POS
), lcl_MovePoint( aInstitutionFT
),
342 aControlSize
, sTableErrorString
, aInstitutionFT
.GetText(), HID_BIB_INSTITUTION_POS
, 14 );
344 AddControlWithError( lcl_GetColumnName( pMapping
, SCHOOL_POS
), lcl_MovePoint( aSchoolFT
),
345 aControlSize
, sTableErrorString
, aSchoolFT
.GetText(), HID_BIB_SCHOOL_POS
, 20 );
347 AddControlWithError( lcl_GetColumnName( pMapping
, REPORTTYPE_POS
), lcl_MovePoint( aReportTypeFT
),
348 aControlSize
, sTableErrorString
, aReportTypeFT
.GetText(), HID_BIB_REPORTTYPE_POS
, 23 );
350 AddControlWithError( lcl_GetColumnName( pMapping
, MONTH_POS
), lcl_MovePoint( aMonthFT
),
351 aControlSize
, sTableErrorString
, aMonthFT
.GetText(), HID_BIB_MONTH_POS
, 3 );
353 AddControlWithError( lcl_GetColumnName( pMapping
, JOURNAL_POS
), lcl_MovePoint( aJournalFT
),
354 aControlSize
, sTableErrorString
, aJournalFT
.GetText(), HID_BIB_JOURNAL_POS
, 15 );
356 AddControlWithError( lcl_GetColumnName( pMapping
, NUMBER_POS
), lcl_MovePoint( aNumberFT
),
357 aControlSize
, sTableErrorString
, aNumberFT
.GetText(), HID_BIB_NUMBER_POS
, 17 );
359 AddControlWithError( lcl_GetColumnName( pMapping
, SERIES_POS
), lcl_MovePoint( aSeriesFT
),
360 aControlSize
, sTableErrorString
, aSeriesFT
.GetText(), HID_BIB_SERIES_POS
, 21 );
362 AddControlWithError( lcl_GetColumnName( pMapping
, ANNOTE_POS
), lcl_MovePoint( aAnnoteFT
),
363 aControlSize
, sTableErrorString
, aAnnoteFT
.GetText(), HID_BIB_ANNOTE_POS
, 8 );
365 AddControlWithError( lcl_GetColumnName( pMapping
, NOTE_POS
), lcl_MovePoint( aNoteFT
),
366 aControlSize
, sTableErrorString
, aNoteFT
.GetText(), HID_BIB_NOTE_POS
, 16 );
368 AddControlWithError( lcl_GetColumnName( pMapping
, URL_POS
), lcl_MovePoint( aURLFT
),
369 aControlSize
, sTableErrorString
, aURLFT
.GetText(), HID_BIB_URL_POS
, 25 );
371 AddControlWithError( lcl_GetColumnName( pMapping
, CUSTOM1_POS
), lcl_MovePoint( aCustom1FT
),
372 aControlSize
, sTableErrorString
, aCustom1FT
.GetText(), HID_BIB_CUSTOM1_POS
, 26 );
374 AddControlWithError( lcl_GetColumnName( pMapping
, CUSTOM2_POS
), lcl_MovePoint( aCustom2FT
),
375 aControlSize
, sTableErrorString
, aCustom2FT
.GetText(), HID_BIB_CUSTOM2_POS
, 27 );
377 AddControlWithError( lcl_GetColumnName( pMapping
, CUSTOM3_POS
), lcl_MovePoint( aCustom3FT
),
378 aControlSize
, sTableErrorString
, aCustom3FT
.GetText(), HID_BIB_CUSTOM3_POS
, 28 );
380 AddControlWithError( lcl_GetColumnName( pMapping
, CUSTOM4_POS
), lcl_MovePoint( aCustom4FT
),
381 aControlSize
, sTableErrorString
, aCustom4FT
.GetText(), HID_BIB_CUSTOM4_POS
, 29 );
383 AddControlWithError( lcl_GetColumnName( pMapping
, CUSTOM5_POS
), lcl_MovePoint( aCustom5FT
),
384 aControlSize
, sTableErrorString
, aCustom5FT
.GetText(), HID_BIB_CUSTOM5_POS
, 30 );
386 xPosListener
= new BibPosListener(this);
387 uno::Reference
< sdbc::XRowSet
> xRowSet(pDatMan
->getForm(), UNO_QUERY
);
389 xRowSet
->addRowSetListener(xPosListener
);
390 uno::Reference
< form::runtime::XFormController
> xFormCtrl
= pDatMan
->GetFormController();
391 xFormCtrl
->setContainer(xCtrlContnr
);
392 xFormCtrl
->activateTabOrder();
394 if(sTableErrorString
.Len())
395 sTableErrorString
.Insert(sErrorPrefix
, 0);
397 //-----------------------------------------------------------------------------
398 BibGeneralPage::~BibGeneralPage()
400 if (pDatMan
&& xPosListener
.is())
402 uno::Reference
< sdbc::XRowSet
> xRowSet(pDatMan
->getForm(), UNO_QUERY
);
404 xRowSet
->removeRowSetListener(xPosListener
);
408 void BibGeneralPage::RemoveListeners()
410 for(sal_uInt16 i
= 0; i
< FIELD_COUNT
; i
++)
412 if(aControls
[i
].is())
414 uno::Reference
< awt::XWindow
> xCtrWin(aControls
[i
], uno::UNO_QUERY
);
415 xCtrWin
->removeFocusListener( this );
421 void BibGeneralPage::CommitActiveControl()
423 uno::Reference
< form::runtime::XFormController
> xFormCtrl
= pDatMan
->GetFormController();
424 uno::Reference
< awt::XControl
> xCurr
= xFormCtrl
->getCurrentControl();
427 uno::Reference
< awt::XControlModel
> xModel
= xCurr
->getModel();
428 uno::Reference
< form::XBoundComponent
> xBound(xModel
, UNO_QUERY
);
433 //-----------------------------------------------------------------------------
434 void BibGeneralPage::AddControlWithError( const OUString
& rColumnName
, const ::Point
& rPos
, const ::Size
& rSize
,
435 String
& rErrorString
, String aColumnUIName
, const OString
& sHelpId
, sal_uInt16 nIndexInFTArray
)
437 // adds also the XControl and creates a map entry in nFT2CtrlMap[] for mapping between control and FT
439 sal_Int16 nIndex
= -1;
440 uno::Reference
< awt::XControlModel
> xTmp
= AddXControl(rColumnName
, rPos
, rSize
, sHelpId
, nIndex
);
443 DBG_ASSERT( nIndexInFTArray
< FIELD_COUNT
, "*BibGeneralPage::AddControlWithError(): wrong array index!" );
444 DBG_ASSERT( nFT2CtrlMap
[ nIndexInFTArray
] < 0, "+BibGeneralPage::AddControlWithError(): index already in use!" );
446 nFT2CtrlMap
[ nIndexInFTArray
] = nIndex
;
450 if( rErrorString
.Len() )
451 rErrorString
+= '\n';
453 rErrorString
+= MnemonicGenerator::EraseAllMnemonicChars( aColumnUIName
);
456 //-----------------------------------------------------------------------------
457 uno::Reference
< awt::XControlModel
> BibGeneralPage::AddXControl(
459 ::Point rPos
, ::Size rSize
, const OString
& sHelpId
, sal_Int16
& rIndex
)
461 uno::Reference
< awt::XControlModel
> xCtrModel
;
464 sal_Bool bTypeListBox
= sTypeColumnName
== rName
;
465 xCtrModel
= pDatMan
->loadControlModel(rName
, bTypeListBox
);
466 if ( xCtrModel
.is() )
468 uno::Reference
< beans::XPropertySet
> xPropSet( xCtrModel
, UNO_QUERY
);
472 uno::Reference
< beans::XPropertySetInfo
> xPropInfo
= xPropSet
->getPropertySetInfo();
474 uno::Any aAny
= xPropSet
->getPropertyValue( "DefaultControl" );
475 OUString aControlName
;
476 aAny
>>= aControlName
;
478 OUString
uProp("HelpURL");
479 if(xPropInfo
->hasPropertyByName(uProp
))
481 OUString sId
= OUString::createFromAscii( INET_HID_SCHEME
);
482 DBG_ASSERT( INetURLObject( OStringToOUString( sHelpId
, RTL_TEXTENCODING_UTF8
) ).GetProtocol() == INET_PROT_NOT_VALID
, "Wrong HelpId!" );
483 sId
+= OStringToOUString( sHelpId
, RTL_TEXTENCODING_UTF8
);
484 xPropSet
->setPropertyValue( uProp
, makeAny( sId
) );
489 //uno::Reference< beans::XPropertySet > xPropSet(xControl, UNO_QUERY);
490 aAny
<<= (sal_Int16
)1;
491 xPropSet
->setPropertyValue("BoundColumn", aAny
);
492 ListSourceType eSet
= ListSourceType_VALUELIST
;
493 aAny
.setValue( &eSet
, ::getCppuType((const ListSourceType
*)0) );
494 xPropSet
->setPropertyValue("ListSourceType", aAny
);
496 uno::Sequence
<OUString
> aListSource(TYPE_COUNT
);
497 OUString
* pListSourceArr
= aListSource
.getArray();
498 //pListSourceArr[0] = "select TypeName, TypeIndex from TypeNms";
499 for(sal_Int32 i
= 0; i
< TYPE_COUNT
; ++i
)
500 pListSourceArr
[i
] = OUString::valueOf(i
);
501 aAny
.setValue(&aListSource
, ::getCppuType((uno::Sequence
<OUString
>*)0));
503 xPropSet
->setPropertyValue("ListSource", aAny
);
505 uno::Sequence
<OUString
> aValues(TYPE_COUNT
+ 1);
506 OUString
* pValuesArr
= aValues
.getArray();
507 for(sal_uInt16 j
= 0; j
< TYPE_COUNT
; j
++)
508 pValuesArr
[j
] = aBibTypeArr
[j
];
509 // empty string if an invalid value no values is set
510 pValuesArr
[TYPE_COUNT
] = OUString();
512 aAny
.setValue(&aValues
, ::getCppuType((uno::Sequence
<OUString
>*)0));
514 xPropSet
->setPropertyValue("StringItemList", aAny
);
516 sal_Bool bTrue
= sal_True
;
517 aAny
.setValue( &bTrue
, ::getBooleanCppuType() );
518 xPropSet
->setPropertyValue( "Dropdown", aAny
);
520 aControlName
= "com.sun.star.form.control.ListBox";
521 xLBModel
= Reference
< form::XBoundComponent
>(xCtrModel
, UNO_QUERY
);
525 uno::Reference
< XComponentContext
> xContext
= comphelper::getProcessComponentContext();
526 uno::Reference
< awt::XControl
> xControl( xContext
->getServiceManager()->createInstanceWithContext(aControlName
, xContext
), UNO_QUERY
);
529 xControl
->setModel( xCtrModel
);
531 // Peer als Child zu dem FrameWindow
532 xCtrlContnr
->addControl(rName
, xControl
);
533 uno::Reference
< awt::XWindow
> xCtrWin(xControl
, UNO_QUERY
);
534 xCtrWin
->addFocusListener( this );
535 rIndex
= -1; // -> implies, that not found
536 for(sal_uInt16 i
= 0; i
< FIELD_COUNT
; i
++)
537 if(!aControls
[i
].is())
539 aControls
[i
] = xCtrWin
;
540 rIndex
= sal_Int16( i
);
543 xCtrWin
->setVisible( sal_True
);
544 xControl
->setDesignMode( sal_True
);
545 // initially switch on the desing mode - switch it off _after_ loading the form
547 xCtrWin
->setPosSize(rPos
.X(), rPos
.Y(), rSize
.Width(),
548 rSize
.Height(), awt::PosSize::POSSIZE
);
553 catch(Exception
& rEx
)
555 (void) rEx
; // make compiler happy
556 OSL_FAIL("BibGeneralPage::AddXControl: something went wrong !");
561 void BibGeneralPage::AdjustScrollbars()
563 long nVertScrollWidth
= aVertScroll
.GetSizePixel().Width();
564 long nHoriScrollHeight
= aHoriScroll
.GetSizePixel().Height();
565 ::Size
aOutSize(GetOutputSizePixel());
566 sal_Bool bHoriVisible
= aOutSize
.Width() <= aStdSize
.Width();
567 sal_Bool bVertVisible
= (aOutSize
.Height()-(bHoriVisible
? nHoriScrollHeight
: 0)) <= (aStdSize
.Height());
568 aHoriScroll
.Show(bHoriVisible
);
569 aVertScroll
.Show(bVertVisible
);
573 ::Size
aHoriSize(aOutSize
.Width() - (bVertVisible
? nVertScrollWidth
: 0),
575 aHoriScroll
.SetSizePixel(aHoriSize
);
576 aHoriScroll
.SetRange( Range(0, aStdSize
.Width()));
577 aHoriScroll
.SetVisibleSize( aHoriSize
.Width() - (bVertVisible
? nVertScrollWidth
: 0));
581 ::Size
aVertSize(nHoriScrollHeight
, aOutSize
.Height() -
582 (bHoriVisible
? nHoriScrollHeight
: 0));
583 aVertScroll
.SetSizePixel(aVertSize
);
584 aVertScroll
.SetRange( Range(0, aStdSize
.Height()));
585 aVertScroll
.SetVisibleSize( aVertSize
.Height() );
589 aSize
= LogicToPixel(aSize
, MapMode(MAP_APPFONT
));
590 ::Size
aScrollSize(aOutSize
.Width() - aSize
.Height(), aSize
.Height());
591 ::Point
aScrollPos(0, aOutSize
.Height() - aSize
.Height());
592 aHoriScroll
.SetPosSizePixel(aScrollPos
, aScrollSize
);
594 aScrollPos
.X() = aOutSize
.Width() - aSize
.Width();
596 aScrollSize
.Width() = aSize
.Width();
597 aScrollSize
.Height() = aOutSize
.Height() - aSize
.Height();
598 aVertScroll
.SetPosSizePixel(aScrollPos
, aScrollSize
);
600 ::Size
aControlParentWinSz(aOutSize
);
602 aControlParentWinSz
.Height() -= aSize
.Height();
604 aControlParentWinSz
.Width() -= aSize
.Width();
605 aControlParentWin
.SetSizePixel(aControlParentWinSz
);
608 void BibGeneralPage::Resize()
611 ScrollHdl(&aVertScroll
);
612 ScrollHdl(&aHoriScroll
);
616 void BibGeneralPage::InitFixedTexts( void )
618 String aFixedStrings
[ FIELD_COUNT
] =
620 String( BibResId( ST_IDENTIFIER
) ),
621 String( BibResId( ST_AUTHTYPE
) ),
622 String( BibResId( ST_AUTHOR
) ),
623 String( BibResId( ST_TITLE
) ),
624 String( BibResId( ST_MONTH
) ),
625 String( BibResId( ST_YEAR
) ),
626 String( BibResId( ST_ISBN
) ),
627 String( BibResId( ST_BOOKTITLE
) ),
628 String( BibResId( ST_CHAPTER
) ),
629 String( BibResId( ST_EDITION
) ),
630 String( BibResId( ST_EDITOR
) ),
631 String( BibResId( ST_HOWPUBLISHED
) ),
632 String( BibResId( ST_INSTITUTION
) ),
633 String( BibResId( ST_JOURNAL
) ),
634 String( BibResId( ST_NOTE
) ),
635 String( BibResId( ST_ANNOTE
) ),
636 String( BibResId( ST_NUMBER
) ),
637 String( BibResId( ST_ORGANIZATION
) ),
638 String( BibResId( ST_PAGE
) ),
639 String( BibResId( ST_PUBLISHER
) ),
640 String( BibResId( ST_ADDRESS
) ),
641 String( BibResId( ST_SCHOOL
) ),
642 String( BibResId( ST_SERIES
) ),
643 String( BibResId( ST_REPORT
) ),
644 String( BibResId( ST_VOLUME
) ),
645 String( BibResId( ST_URL
) ),
646 String( BibResId( ST_CUSTOM1
) ),
647 String( BibResId( ST_CUSTOM2
) ),
648 String( BibResId( ST_CUSTOM3
) ),
649 String( BibResId( ST_CUSTOM4
) ),
650 String( BibResId( ST_CUSTOM5
) )
653 aFixedTexts
[0] = &aIdentifierFT
;
654 aFixedTexts
[1] = &aAuthTypeFT
;
655 aFixedTexts
[2] = &aAuthorFT
;
656 aFixedTexts
[3] = &aTitleFT
;
657 aFixedTexts
[4] = &aMonthFT
;
658 aFixedTexts
[5] = &aYearFT
;
659 aFixedTexts
[6] = &aISBNFT
;
660 aFixedTexts
[7] = &aBooktitleFT
;
661 aFixedTexts
[8] = &aChapterFT
;
662 aFixedTexts
[9] = &aEditionFT
;
663 aFixedTexts
[10] = &aEditorFT
;
664 aFixedTexts
[11] = &aHowpublishedFT
;
665 aFixedTexts
[12] = &aInstitutionFT
;
666 aFixedTexts
[13] = &aJournalFT
;
667 aFixedTexts
[14] = &aNoteFT
;
668 aFixedTexts
[15] = &aAnnoteFT
;
669 aFixedTexts
[16] = &aNumberFT
;
670 aFixedTexts
[17] = &aOrganizationsFT
;
671 aFixedTexts
[18] = &aPagesFT
;
672 aFixedTexts
[19] = &aPublisherFT
;
673 aFixedTexts
[20] = &aAddressFT
;
674 aFixedTexts
[21] = &aSchoolFT
;
675 aFixedTexts
[22] = &aSeriesFT
;
676 aFixedTexts
[23] = &aReportTypeFT
;
677 aFixedTexts
[24] = &aVolumeFT
;
678 aFixedTexts
[25] = &aURLFT
;
679 aFixedTexts
[26] = &aCustom1FT
;
680 aFixedTexts
[27] = &aCustom2FT
;
681 aFixedTexts
[28] = &aCustom3FT
;
682 aFixedTexts
[29] = &aCustom4FT
;
683 aFixedTexts
[30] = &aCustom5FT
;
687 MnemonicGenerator aMnemonicGenerator
;
688 // init mnemonics, first register all strings
689 for( i
= 0 ; i
< FIELD_COUNT
; ++i
)
690 aMnemonicGenerator
.RegisterMnemonic( aFixedStrings
[ i
] );
692 // ... then get all strings
693 for( i
= 0 ; i
< FIELD_COUNT
; ++i
)
694 aMnemonicGenerator
.CreateMnemonic( aFixedStrings
[ i
] );
697 for( i
= 0 ; i
< FIELD_COUNT
; ++i
)
698 aFixedTexts
[ i
]->SetText( aFixedStrings
[ i
] );
701 IMPL_LINK(BibGeneralPage
, ScrollHdl
, ScrollBar
*, pScroll
)
703 sal_Bool bVertical
= &aVertScroll
== pScroll
;
705 long nCurrentOffset
= 0;
707 nCurrentOffset
= aFixedTexts
[0]->GetPosPixel().Y() - aBasePos
.Y();
709 nCurrentOffset
= aFixedTexts
[0]->GetPosPixel().X() - aBasePos
.X();
710 nOffset
= pScroll
->IsVisible() ? pScroll
->GetThumbPos() + nCurrentOffset
: nCurrentOffset
;
712 for(sal_uInt16 i
= 0; i
< FIELD_COUNT
; i
++)
714 ::Point aPos
= aFixedTexts
[i
]->GetPosPixel();
719 aFixedTexts
[i
]->SetPosPixel(aPos
);
720 if(aControls
[i
].is())
722 awt::Rectangle aRect
= aControls
[i
]->getPosSize();
729 aControls
[i
]->setPosSize(nX
, nY
, 0, 0, awt::PosSize::POS
);
735 void BibGeneralPage::focusGained(const awt::FocusEvent
& rEvent
) throw( uno::RuntimeException
)
737 Reference
<awt::XWindow
> xCtrWin(rEvent
.Source
, UNO_QUERY
);
740 ::Size aOutSize
= aControlParentWin
.GetOutputSizePixel();
741 awt::Rectangle aRect
= xCtrWin
->getPosSize();
745 // left of the visible area
746 aHoriScroll
.SetThumbPos(aHoriScroll
.GetThumbPos() + nX
);
747 ScrollHdl(&aHoriScroll
);
749 else if(nX
> aOutSize
.Width())
751 // right of the visible area
752 aHoriScroll
.SetThumbPos(aHoriScroll
.GetThumbPos() + nX
- aOutSize
.Width() + aFixedTexts
[0]->GetSizePixel().Width());
753 ScrollHdl(&aHoriScroll
);
758 // below the visible area
759 aVertScroll
.SetThumbPos(aVertScroll
.GetThumbPos() + nY
);
760 ScrollHdl(&aVertScroll
);
762 else if(nY
> aOutSize
.Height())
764 // over the visible area
765 aVertScroll
.SetThumbPos(aVertScroll
.GetThumbPos() + nY
- aOutSize
.Height()+ aFixedTexts
[0]->GetSizePixel().Height());
766 ScrollHdl(&aVertScroll
);
771 void BibGeneralPage::focusLost(const awt::FocusEvent
& ) throw( uno::RuntimeException
)
773 CommitActiveControl();
776 void BibGeneralPage::disposing(const lang::EventObject
& /*Source*/) throw( uno::RuntimeException
)
780 void BibGeneralPage::GetFocus()
782 Reference
< awt::XWindow
>* pxControl
= aControls
;
784 for( int i
= FIELD_COUNT
; i
; --i
, ++pxControl
)
786 if( pxControl
->is() )
788 ( *pxControl
)->setFocus();
794 aControlParentWin
.GrabFocus();
797 sal_Bool
BibGeneralPage::HandleShortCutKey( const KeyEvent
& rKeyEvent
)
799 DBG_ASSERT( KEY_MOD2
== rKeyEvent
.GetKeyCode().GetModifier(), "+BibGeneralPage::HandleShortCutKey(): this is not for me!" );
801 const vcl::I18nHelper
& rI18nHelper
= Application::GetSettings().GetUILocaleI18nHelper();
802 const sal_Unicode c
= rKeyEvent
.GetCharCode();
803 sal_Bool bHandled
= sal_False
;
807 typedef std::vector
< sal_Int16
> sal_Int16_vector
;
809 sal_Int16_vector::size_type nFocused
= 0xFFFF; // index of focused in vector, no one focused initial
810 DBG_ASSERT( nFocused
> 0, "*BibGeneralPage::HandleShortCutKey(): size_type works not as expected!" );
812 sal_Int16_vector aMatchList
;
814 for( i
= 0 ; i
< FIELD_COUNT
; ++i
)
816 if( rI18nHelper
.MatchMnemonic( aFixedTexts
[ i
]->GetText(), c
) )
819 sal_Int16 nCtrlIndex
= nFT2CtrlMap
[ i
];
821 if( nCtrlIndex
>= 0 )
822 { // store index of control
823 DBG_ASSERT( aControls
[ nCtrlIndex
].is(), "-BibGeneralPage::HandleShortCutKey(): valid index and no control?" );
825 uno::Reference
< awt::XControl
> xControl( aControls
[ nCtrlIndex
], UNO_QUERY
);
826 DBG_ASSERT( xControl
.is(), "-BibGeneralPage::HandleShortCutKey(): a control which is not a control!" );
828 Window
* pWindow
= VCLUnoHelper::GetWindow( xControl
->getPeer() );
832 aMatchList
.push_back( nCtrlIndex
);
833 if( pWindow
->HasChildPathFocus() )
834 { // save focused control
835 DBG_ASSERT( nFocused
== 0xFFFF, "+BibGeneralPage::HandleShortCutKey(): more than one with focus?!" );
836 DBG_ASSERT( !aMatchList
.empty(), "+BibGeneralPage::HandleShortCutKey(): push_back and no content?!" );
837 nFocused
= aMatchList
.size() - 1;
846 DBG_ASSERT( !aMatchList
.empty(), "*BibGeneralPage::HandleShortCutKey(): be prepared to crash..." );
848 if( nFocused
>= ( aMatchList
.size() - 1 ) )
849 // >=... includes 0xFFFF
850 // no one or last focused, take first
856 aControls
[ aMatchList
[ nFocused
] ]->setFocus();
862 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */