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