xref: /AOO41X/main/extensions/source/bibliography/general.cxx (revision 24c56ab9f1bd1305754aa2f564704f38ff57627e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_extensions.hxx"
26 
27 
28 #include <comphelper/processfactory.hxx>
29 #include <com/sun/star/awt/PosSize.hpp>
30 #include <com/sun/star/sdbc/XRowSet.hpp>
31 #include <com/sun/star/sdb/XColumn.hpp>
32 #include <com/sun/star/sdb/CommandType.hpp>
33 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
34 #include <com/sun/star/form/ListSourceType.hpp>
35 #include <com/sun/star/awt/XWindow.hpp>
36 #include <toolkit/helper/vclunohelper.hxx>
37 #include <cppuhelper/implbase1.hxx> // helper for implementations
38 #include "general.hxx"
39 #include "sections.hrc"
40 #include "bibresid.hxx"
41 #include "datman.hxx"
42 #include "bibconfig.hxx"
43 #include "bibprop.hrc"
44 #include "bib.hrc"
45 #include "bibmod.hxx"
46 #include "bibtools.hxx"
47 #include "bibliography.hrc"
48 #include <tools/debug.hxx>
49 #include <vcl/mnemonic.hxx>
50 #include <vcl/svapp.hxx>
51 #include <vcl/i18nhelp.hxx>
52 #include <vcl/mnemonic.hxx>
53 #include <algorithm>
54 #include <functional>
55 #include <vector>
56 #include <tools/urlobj.hxx>
57 
58 using namespace ::com::sun::star;
59 using namespace ::com::sun::star::uno;
60 using namespace ::com::sun::star::form;
61 using namespace ::com::sun::star::sdb;
62 using namespace ::rtl;
63 
64 #define C2U(cChar) OUString::createFromAscii(cChar)
65 #define C2S(cChar) String::CreateFromAscii(cChar)
66 #define DISTANCE_CONTROL_TO_FIXEDTEXT 5
67 
lcl_MovePoint(const FixedText & rFixedText)68 ::Point lcl_MovePoint(const FixedText& rFixedText)
69 {
70     ::Point aRet(rFixedText.GetPosPixel());
71     aRet.X() += rFixedText.GetSizePixel().Width();
72     aRet.X() += DISTANCE_CONTROL_TO_FIXEDTEXT;
73     return aRet;
74 }
75 
76 //-----------------------------------------------------------------------------
lcl_GetColumnName(const Mapping * pMapping,sal_uInt16 nIndexPos)77 OUString lcl_GetColumnName( const Mapping* pMapping, sal_uInt16 nIndexPos )
78 {
79     BibConfig* pBibConfig = BibModul::GetConfig();
80     OUString sRet = pBibConfig->GetDefColumnName(nIndexPos);
81     if(pMapping)
82         for(sal_uInt16 i = 0; i < COLUMN_COUNT; i++)
83         {
84             if(pMapping->aColumnPairs[i].sLogicalColumnName == sRet)
85             {
86                 sRet = pMapping->aColumnPairs[i].sRealColumnName;
87                 break;
88             }
89         }
90     return sRet;
91 }
92 /* -----------------------------04.01.00 10:54--------------------------------
93 
94  ---------------------------------------------------------------------------*/
95 class BibPosListener    :public cppu::WeakImplHelper1 <sdbc::XRowSetListener>
96 {
97     BibGeneralPage*     pParentPage;
98 public:
99     BibPosListener(BibGeneralPage* pParent);
100 
101     //XPositioningListener
102     virtual void SAL_CALL cursorMoved(const lang::EventObject& event) throw( uno::RuntimeException );
rowChanged(const lang::EventObject &)103     virtual void SAL_CALL rowChanged(const lang::EventObject& /*event*/) throw( uno::RuntimeException ){ /* not interested in */ }
rowSetChanged(const lang::EventObject &)104     virtual void SAL_CALL rowSetChanged(const lang::EventObject& /*event*/) throw( uno::RuntimeException ){ /* not interested in */ }
105 
106     //XEventListener
107     virtual void SAL_CALL disposing(const lang::EventObject& Source) throw( uno::RuntimeException );
108 
109 };
110 /* -----------------------------04.01.00 10:57--------------------------------
111 
112  ---------------------------------------------------------------------------*/
BibPosListener(BibGeneralPage * pParent)113 BibPosListener::BibPosListener(BibGeneralPage* pParent) :
114     pParentPage(pParent)
115 {
116 }
117 /* -----------------------------04.01.00 10:57--------------------------------
118 
119  ---------------------------------------------------------------------------*/
cursorMoved(const lang::EventObject &)120 void BibPosListener::cursorMoved(const lang::EventObject& /*aEvent*/) throw( uno::RuntimeException )
121 {
122     try
123     {
124         uno::Reference< form::XBoundComponent >  xLstBox = pParentPage->GetTypeListBoxModel();
125         uno::Reference< beans::XPropertySet >  xPropSet(xLstBox, UNO_QUERY);
126         if(xPropSet.is())
127         {
128             BibConfig* pBibConfig = BibModul::GetConfig();
129             BibDataManager* pDatMan = pParentPage->GetDataManager();
130             BibDBDescriptor aDesc;
131             aDesc.sDataSource = pDatMan->getActiveDataSource();
132             aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
133             aDesc.nCommandType = CommandType::TABLE;
134 
135             const Mapping* pMapping = pBibConfig->GetMapping(aDesc);
136             OUString sTypeMapping = pBibConfig->GetDefColumnName(AUTHORITYTYPE_POS);
137             if(pMapping)
138             {
139                 for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
140                 {
141                     if(pMapping->aColumnPairs[nEntry].sLogicalColumnName == sTypeMapping)
142                     {
143                         sTypeMapping = pMapping->aColumnPairs[nEntry].sRealColumnName;
144                         break;
145                     }
146                 }
147             }
148             rtl::OUString uTypeMapping = sTypeMapping;
149 
150             uno::Reference< form::XForm >  xForm = pDatMan->getForm();
151             uno::Reference< sdbcx::XColumnsSupplier >  xSupplyCols(xForm, UNO_QUERY);
152             uno::Reference< container::XNameAccess >  xValueAcc;
153             if (xSupplyCols.is())
154                 xValueAcc = xSupplyCols->getColumns();
155 
156             sal_Int16 nTempVal = -1;
157             if(xValueAcc.is() && xValueAcc->hasByName(uTypeMapping))
158             {
159                 uno::Any aVal = xValueAcc->getByName(uTypeMapping);
160                 uno::Reference< uno::XInterface >  xInt = *(uno::Reference< uno::XInterface > *)aVal.getValue();
161                 uno::Reference< sdb::XColumn >  xCol(xInt, UNO_QUERY);
162                 DBG_ASSERT(xCol.is(), "BibPosListener::positioned : invalid column (no sdb::XColumn) !");
163                 if (xCol.is())
164                 {
165                     nTempVal = xCol->getShort();
166                     // getShort returns zero if the value is not a number
167                     if (!nTempVal || xCol->wasNull())
168                     {
169                         rtl::OUString sTempVal = xCol->getString();
170                         if(sTempVal != rtl::OUString('0'))
171                             nTempVal = -1;
172                     }
173                 }
174             }
175             if(nTempVal < 0 || nTempVal >= TYPE_COUNT)
176             {
177                 uno::Any aSel;
178                 uno::Sequence<sal_Int16> aSelSeq(1);
179                 sal_Int16* pArr = aSelSeq.getArray();
180                 pArr[0] = TYPE_COUNT;
181                 aSel.setValue(&aSelSeq, ::getCppuType((Sequence<sal_Int16>*)0));
182                 xPropSet->setPropertyValue(C2U("SelectedItems"), aSel);
183             }
184         }
185     }
186     catch(Exception& rEx)
187     {
188         (void) rEx; // make compiler happy
189         DBG_ERROR("BibPosListener::positioned: something went wrong !");
190     }
191 }
192 /* -----------------------------04.01.00 11:28--------------------------------
193 
194  ---------------------------------------------------------------------------*/
disposing(const lang::EventObject &)195 void BibPosListener::disposing(const lang::EventObject& /*Source*/) throw( uno::RuntimeException )
196 {
197 }
198 
199 /* -----------------16.11.99 13:06-------------------
200 
201  --------------------------------------------------*/
BibGeneralPage(Window * pParent,BibDataManager * pMan)202 BibGeneralPage::BibGeneralPage(Window* pParent, BibDataManager* pMan):
203     BibTabPage(pParent,BibResId(RID_TP_GENERAL)),
204     aControlParentWin(this, WB_DIALOGCONTROL),
205     aIdentifierFT(&aControlParentWin,   BibResId(FT_IDENTIFIER  )),
206     aAuthTypeFT(&aControlParentWin,     BibResId(FT_AUTHTYPE        )),
207     aYearFT(&aControlParentWin,         BibResId(FT_YEAR            )),
208     aAuthorFT(&aControlParentWin,       BibResId(FT_AUTHOR      )),
209     aTitleFT(&aControlParentWin,        BibResId(FT_TITLE           )),
210     aPublisherFT(&aControlParentWin,    BibResId(FT_PUBLISHER       )),
211     aAddressFT(&aControlParentWin,      BibResId(FT_ADDRESS     )),
212     aISBNFT(&aControlParentWin,         BibResId(FT_ISBN            )),
213     aChapterFT(&aControlParentWin,      BibResId(FT_CHAPTER     )),
214     aPagesFT(&aControlParentWin,        BibResId(FT_PAGE            )),
215     aFirstFL(&aControlParentWin,        BibResId(FL_1        )),
216     aEditorFT(&aControlParentWin,       BibResId(FT_EDITOR      )),
217     aEditionFT(&aControlParentWin,      BibResId(FT_EDITION     )),
218     aBooktitleFT(&aControlParentWin,    BibResId(FT_BOOKTITLE       )),
219     aVolumeFT(&aControlParentWin,       BibResId(FT_VOLUME      )),
220     aHowpublishedFT(&aControlParentWin, BibResId(FT_HOWPUBLISHED    )),
221     aOrganizationsFT(&aControlParentWin,BibResId(FT_ORGANIZATION    )),
222     aInstitutionFT(&aControlParentWin,  BibResId(FT_INSTITUTION )),
223     aSchoolFT(&aControlParentWin,       BibResId(FT_SCHOOL      )),
224     aReportTypeFT(&aControlParentWin,   BibResId(FT_REPORT      )),
225     aMonthFT(&aControlParentWin,        BibResId(FT_MONTH           )),
226     aSecondFL(&aControlParentWin,       BibResId(FL_2        )),
227     aJournalFT(&aControlParentWin,      BibResId(FT_JOURNAL     )),
228     aNumberFT(&aControlParentWin,       BibResId(FT_NUMBER      )),
229     aSeriesFT(&aControlParentWin,       BibResId(FT_SERIES      )),
230     aAnnoteFT(&aControlParentWin,       BibResId(FT_ANNOTE      )),
231     aNoteFT(&aControlParentWin,         BibResId(FT_NOTE            )),
232     aURLFT(&aControlParentWin,          BibResId(FT_URL         )),
233     aThirdFL(&aControlParentWin,        BibResId(FL_3        )),
234     aCustom1FT(&aControlParentWin,      BibResId(FT_CUSTOM1     )),
235     aCustom2FT(&aControlParentWin,      BibResId(FT_CUSTOM2     )),
236     aCustom3FT(&aControlParentWin,      BibResId(FT_CUSTOM3     )),
237     aCustom4FT(&aControlParentWin,      BibResId(FT_CUSTOM4     )),
238     aCustom5FT(&aControlParentWin,      BibResId(FT_CUSTOM5     )),
239     aHoriScroll(this, WB_HORZ),
240     aVertScroll(this, WB_VERT),
241     sErrorPrefix(BibResId(ST_ERROR_PREFIX)),
242     pDatMan(pMan)
243 {
244     aControlParentWin.Show();
245     aControlParentWin.SetHelpId(HID_BIB_CONTROL_PARENT);
246     aStdSize = GetOutputSizePixel();
247 
248     aBibTypeArr[0] = String(BibResId(ST_TYPE_ARTICLE));
249     aBibTypeArr[1] = String(BibResId(ST_TYPE_BOOK));
250     aBibTypeArr[2] = String(BibResId(ST_TYPE_BOOKLET));
251     aBibTypeArr[3] = String(BibResId(ST_TYPE_CONFERENCE));
252     aBibTypeArr[4] = String(BibResId(ST_TYPE_INBOOK ));
253     aBibTypeArr[5] = String(BibResId(ST_TYPE_INCOLLECTION));
254     aBibTypeArr[6] = String(BibResId(ST_TYPE_INPROCEEDINGS));
255     aBibTypeArr[7] = String(BibResId(ST_TYPE_JOURNAL       ));
256     aBibTypeArr[8] = String(BibResId(ST_TYPE_MANUAL    ));
257     aBibTypeArr[9] = String(BibResId(ST_TYPE_MASTERSTHESIS));
258     aBibTypeArr[10] = String(BibResId(ST_TYPE_MISC      ));
259     aBibTypeArr[11] = String(BibResId(ST_TYPE_PHDTHESIS ));
260     aBibTypeArr[12] = String(BibResId(ST_TYPE_PROCEEDINGS   ));
261     aBibTypeArr[13] = String(BibResId(ST_TYPE_TECHREPORT    ));
262     aBibTypeArr[14] = String(BibResId(ST_TYPE_UNPUBLISHED   ));
263     aBibTypeArr[15] = String(BibResId(ST_TYPE_EMAIL     ));
264     aBibTypeArr[16] = String(BibResId(ST_TYPE_WWW           ));
265     aBibTypeArr[17] = String(BibResId(ST_TYPE_CUSTOM1       ));
266     aBibTypeArr[18] = String(BibResId(ST_TYPE_CUSTOM2       ));
267     aBibTypeArr[19] = String(BibResId(ST_TYPE_CUSTOM3       ));
268     aBibTypeArr[20] = String(BibResId(ST_TYPE_CUSTOM4       ));
269     aBibTypeArr[21] = String(BibResId(ST_TYPE_CUSTOM5       ));
270 
271     FreeResource();
272 
273     InitFixedTexts();
274 
275     aBasePos = aIdentifierFT.GetPosPixel();
276 
277     sal_Int16* pMap = nFT2CtrlMap;
278     for( sal_uInt16 i = 0 ; i < FIELD_COUNT ; ++i, ++pMap )
279     {
280         aControls[ i ] = 0;
281         *pMap = -1;
282     }
283 
284     AdjustScrollbars();
285     Link aScrollLnk(LINK(this, BibGeneralPage, ScrollHdl));
286     aHoriScroll.SetScrollHdl( aScrollLnk );
287     aVertScroll.SetScrollHdl( aScrollLnk );
288     aHoriScroll.SetLineSize(10);
289     aVertScroll.SetLineSize(10);
290     aHoriScroll.SetPageSize( aIdentifierFT.GetSizePixel().Width());
291     aVertScroll.SetPageSize(
292         aPublisherFT.GetPosPixel().Y() - aIdentifierFT.GetPosPixel().Y());
293     aHoriScroll.Show();
294     aVertScroll.Show();
295 
296     BibConfig* pBibConfig = BibModul::GetConfig();
297     BibDBDescriptor aDesc;
298     aDesc.sDataSource = pDatMan->getActiveDataSource();
299     aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
300     aDesc.nCommandType = CommandType::TABLE;
301     const Mapping* pMapping = pBibConfig->GetMapping(aDesc);
302 
303     xCtrlContnr = VCLUnoHelper::CreateControlContainer(&aControlParentWin);
304 
305     xMgr = comphelper::getProcessServiceFactory();
306     // the control should be a bit smaller than the fixed text
307     Size aControlSize(aIdentifierFT.GetSizePixel());
308     aControlSize.Width() = aControlSize.Width() * 8 / 10;
309 
310     AddControlWithError( lcl_GetColumnName( pMapping, IDENTIFIER_POS ), lcl_MovePoint( aIdentifierFT ),
311         aControlSize, sTableErrorString, aIdentifierFT.GetText(),
312         HID_BIB_IDENTIFIER_POS, 0 );
313 
314     sTypeColumnName = lcl_GetColumnName(pMapping, AUTHORITYTYPE_POS);
315 
316     AddControlWithError( sTypeColumnName, lcl_MovePoint(aAuthTypeFT ), aControlSize, sTableErrorString,
317         aAuthTypeFT.GetText(), HID_BIB_AUTHORITYTYPE_POS, 1 );
318 
319     ::Point aYearPos = lcl_MovePoint(aYearFT);
320     AddControlWithError( lcl_GetColumnName( pMapping, YEAR_POS ), aYearPos,
321         aControlSize, sTableErrorString, aYearFT.GetText(), HID_BIB_YEAR_POS, 4 );
322 
323     AddControlWithError( lcl_GetColumnName(pMapping, AUTHOR_POS), lcl_MovePoint(aAuthorFT),
324         aControlSize, sTableErrorString, aAuthorFT.GetText(), HID_BIB_AUTHOR_POS, 2 );
325 
326     ::Point aTitlePos( lcl_MovePoint( aTitleFT ) );
327     ::Size aTitleSize = aTitleFT.GetSizePixel();
328     aTitleSize.Width() = aYearPos.X() + aControlSize.Width() - aTitlePos.X();
329     AddControlWithError( lcl_GetColumnName(pMapping, TITLE_POS), aTitlePos, aTitleSize, sTableErrorString,
330         aTitleFT.GetText(), HID_BIB_TITLE_POS, 22 );
331 
332     AddControlWithError( lcl_GetColumnName( pMapping, PUBLISHER_POS ), lcl_MovePoint( aPublisherFT),
333         aControlSize, sTableErrorString, aPublisherFT.GetText(), HID_BIB_PUBLISHER_POS, 5 );
334 
335     AddControlWithError( lcl_GetColumnName( pMapping, ADDRESS_POS ), lcl_MovePoint( aAddressFT ),
336         aControlSize, sTableErrorString, aAddressFT.GetText(), HID_BIB_ADDRESS_POS, 7 );
337 
338     AddControlWithError( lcl_GetColumnName( pMapping, ISBN_POS ), lcl_MovePoint( aISBNFT ),
339         aControlSize, sTableErrorString, aISBNFT.GetText(), HID_BIB_ISBN_POS, 6 );
340 
341     AddControlWithError( lcl_GetColumnName( pMapping, CHAPTER_POS ), lcl_MovePoint(aChapterFT),
342         aControlSize, sTableErrorString, aChapterFT.GetText(), HID_BIB_CHAPTER_POS, 10 );
343 
344     AddControlWithError( lcl_GetColumnName( pMapping, PAGES_POS ), lcl_MovePoint( aPagesFT ),
345         aControlSize, sTableErrorString, aPagesFT.GetText(), HID_BIB_PAGES_POS, 19 );
346 
347     AddControlWithError( lcl_GetColumnName( pMapping, EDITOR_POS ), lcl_MovePoint( aEditorFT ),
348         aControlSize, sTableErrorString, aEditorFT.GetText(), HID_BIB_EDITOR_POS, 12 );
349 
350     AddControlWithError( lcl_GetColumnName( pMapping, EDITION_POS ), lcl_MovePoint(aEditionFT),
351         aControlSize, sTableErrorString, aEditionFT.GetText(), HID_BIB_EDITION_POS, 11 );
352 
353     AddControlWithError( lcl_GetColumnName(pMapping, BOOKTITLE_POS), lcl_MovePoint(aBooktitleFT),
354         aControlSize, sTableErrorString, aBooktitleFT.GetText(), HID_BIB_BOOKTITLE_POS, 9 );
355 
356     AddControlWithError( lcl_GetColumnName( pMapping, VOLUME_POS ), lcl_MovePoint( aVolumeFT ),
357         aControlSize, sTableErrorString, aVolumeFT.GetText(), HID_BIB_VOLUME_POS, 24 );
358 
359     AddControlWithError( lcl_GetColumnName( pMapping, HOWPUBLISHED_POS ), lcl_MovePoint( aHowpublishedFT ),
360         aControlSize, sTableErrorString, aHowpublishedFT.GetText(), HID_BIB_HOWPUBLISHED_POS, 13 );
361 
362     AddControlWithError( lcl_GetColumnName( pMapping, ORGANIZATIONS_POS ), lcl_MovePoint( aOrganizationsFT ),
363         aControlSize, sTableErrorString, aOrganizationsFT.GetText(), HID_BIB_ORGANIZATIONS_POS, 18 );
364 
365     AddControlWithError( lcl_GetColumnName( pMapping, INSTITUTION_POS ), lcl_MovePoint( aInstitutionFT ),
366         aControlSize, sTableErrorString, aInstitutionFT.GetText(), HID_BIB_INSTITUTION_POS, 14 );
367 
368     AddControlWithError( lcl_GetColumnName( pMapping, SCHOOL_POS ), lcl_MovePoint( aSchoolFT ),
369         aControlSize, sTableErrorString, aSchoolFT.GetText(), HID_BIB_SCHOOL_POS, 20 );
370 
371     AddControlWithError( lcl_GetColumnName( pMapping, REPORTTYPE_POS ), lcl_MovePoint( aReportTypeFT ),
372         aControlSize, sTableErrorString, aReportTypeFT.GetText(), HID_BIB_REPORTTYPE_POS, 23 );
373 
374     AddControlWithError( lcl_GetColumnName( pMapping, MONTH_POS ), lcl_MovePoint( aMonthFT ),
375         aControlSize, sTableErrorString, aMonthFT.GetText(), HID_BIB_MONTH_POS, 3 );
376 
377     AddControlWithError( lcl_GetColumnName( pMapping, JOURNAL_POS ), lcl_MovePoint( aJournalFT ),
378         aControlSize, sTableErrorString, aJournalFT.GetText(), HID_BIB_JOURNAL_POS, 15 );
379 
380     AddControlWithError( lcl_GetColumnName( pMapping, NUMBER_POS ), lcl_MovePoint( aNumberFT ),
381         aControlSize, sTableErrorString, aNumberFT.GetText(), HID_BIB_NUMBER_POS, 17 );
382 
383     AddControlWithError( lcl_GetColumnName( pMapping, SERIES_POS ), lcl_MovePoint( aSeriesFT ),
384         aControlSize, sTableErrorString, aSeriesFT.GetText(), HID_BIB_SERIES_POS, 21 );
385 
386     AddControlWithError( lcl_GetColumnName( pMapping, ANNOTE_POS ), lcl_MovePoint( aAnnoteFT ),
387         aControlSize, sTableErrorString, aAnnoteFT.GetText(), HID_BIB_ANNOTE_POS, 8 );
388 
389     AddControlWithError( lcl_GetColumnName( pMapping, NOTE_POS ), lcl_MovePoint( aNoteFT ),
390         aControlSize, sTableErrorString, aNoteFT.GetText(), HID_BIB_NOTE_POS, 16 );
391 
392     AddControlWithError( lcl_GetColumnName( pMapping, URL_POS ), lcl_MovePoint( aURLFT ),
393         aControlSize, sTableErrorString, aURLFT.GetText(), HID_BIB_URL_POS, 25 );
394 
395     AddControlWithError( lcl_GetColumnName( pMapping, CUSTOM1_POS ), lcl_MovePoint( aCustom1FT ),
396         aControlSize, sTableErrorString, aCustom1FT.GetText(), HID_BIB_CUSTOM1_POS, 26 );
397 
398     AddControlWithError( lcl_GetColumnName( pMapping, CUSTOM2_POS ), lcl_MovePoint( aCustom2FT ),
399         aControlSize, sTableErrorString, aCustom2FT.GetText(), HID_BIB_CUSTOM2_POS, 27 );
400 
401     AddControlWithError( lcl_GetColumnName( pMapping, CUSTOM3_POS ), lcl_MovePoint( aCustom3FT ),
402         aControlSize, sTableErrorString, aCustom3FT.GetText(), HID_BIB_CUSTOM3_POS, 28 );
403 
404     AddControlWithError( lcl_GetColumnName( pMapping, CUSTOM4_POS ), lcl_MovePoint( aCustom4FT ),
405         aControlSize, sTableErrorString, aCustom4FT.GetText(), HID_BIB_CUSTOM4_POS, 29 );
406 
407     AddControlWithError( lcl_GetColumnName( pMapping, CUSTOM5_POS ), lcl_MovePoint( aCustom5FT ),
408         aControlSize, sTableErrorString, aCustom5FT.GetText(), HID_BIB_CUSTOM5_POS, 30 );
409 
410     xPosListener = new BibPosListener(this);
411     uno::Reference< sdbc::XRowSet >  xRowSet(pDatMan->getForm(), UNO_QUERY);
412     if(xRowSet.is())
413         xRowSet->addRowSetListener(xPosListener);
414     uno::Reference< form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController();
415     xFormCtrl->setContainer(xCtrlContnr);
416     xFormCtrl->activateTabOrder();
417 
418     if(sTableErrorString.Len())
419         sTableErrorString.Insert(sErrorPrefix, 0);
420 }
421 //-----------------------------------------------------------------------------
~BibGeneralPage()422 BibGeneralPage::~BibGeneralPage()
423 {
424     if (pDatMan && xPosListener.is())
425     {
426         uno::Reference< sdbc::XRowSet >  xRowSet(pDatMan->getForm(), UNO_QUERY);
427         if(xRowSet.is())
428             xRowSet->removeRowSetListener(xPosListener);
429     }
430 }
431  /* -----------------------------14.04.00 13:11--------------------------------
432 
433   ---------------------------------------------------------------------------*/
RemoveListeners()434  void BibGeneralPage::RemoveListeners()
435  {
436     for(sal_uInt16 i = 0; i < FIELD_COUNT; i++)
437     {
438         if(aControls[i].is())
439         {
440             uno::Reference< awt::XWindow > xCtrWin(aControls[i], uno::UNO_QUERY );
441             xCtrWin->removeFocusListener( this );
442             aControls[i] = 0;
443         }
444     }
445  }
446 /* -----------------------------21.01.00 17:05--------------------------------
447 
448  ---------------------------------------------------------------------------*/
CommitActiveControl()449 void BibGeneralPage::CommitActiveControl()
450 {
451     uno::Reference< form::runtime::XFormController > xFormCtrl = pDatMan->GetFormController();
452     uno::Reference< awt::XControl >  xCurr = xFormCtrl->getCurrentControl();
453     if(xCurr.is())
454     {
455         uno::Reference< awt::XControlModel >  xModel = xCurr->getModel();
456         uno::Reference< form::XBoundComponent >  xBound(xModel, UNO_QUERY);
457         if(xBound.is())
458             xBound->commit();
459     }
460 }
461 //-----------------------------------------------------------------------------
AddControlWithError(const OUString & rColumnName,const::Point & rPos,const::Size & rSize,String & rErrorString,String aColumnUIName,const rtl::OString & sHelpId,sal_uInt16 nIndexInFTArray)462 void BibGeneralPage::AddControlWithError( const OUString& rColumnName, const ::Point& rPos, const ::Size& rSize,
463                                 String& rErrorString, String aColumnUIName, const rtl::OString& sHelpId, sal_uInt16 nIndexInFTArray )
464 {
465     // adds also the XControl and creates a map entry in nFT2CtrlMap[] for mapping between control and FT
466 
467     sal_Int16                                   nIndex = -1;
468     uno::Reference< awt::XControlModel >    xTmp = AddXControl(rColumnName, rPos, rSize, sHelpId, nIndex );
469     if( xTmp.is() )
470     {
471         DBG_ASSERT( nIndexInFTArray < FIELD_COUNT, "*BibGeneralPage::AddControlWithError(): wrong array index!" );
472         DBG_ASSERT( nFT2CtrlMap[ nIndexInFTArray ] < 0, "+BibGeneralPage::AddControlWithError(): index already in use!" );
473 
474         nFT2CtrlMap[ nIndexInFTArray ] = nIndex;
475     }
476     else
477     {
478         if( rErrorString.Len() )
479             rErrorString += '\n';
480 
481         rErrorString += MnemonicGenerator::EraseAllMnemonicChars( aColumnUIName );
482     }
483 }
484 //-----------------------------------------------------------------------------
AddXControl(const String & rName,::Point rPos,::Size rSize,const rtl::OString & sHelpId,sal_Int16 & rIndex)485 uno::Reference< awt::XControlModel >  BibGeneralPage::AddXControl(
486         const String& rName,
487         ::Point rPos, ::Size rSize, const rtl::OString& sHelpId, sal_Int16& rIndex )
488 {
489     uno::Reference< awt::XControlModel >  xCtrModel;
490     try
491     {
492         sal_Bool bTypeListBox = sTypeColumnName == rName;
493         xCtrModel = pDatMan->loadControlModel(rName, bTypeListBox);
494         if ( xCtrModel.is() && xMgr.is())
495         {
496             uno::Reference< beans::XPropertySet >  xPropSet( xCtrModel, UNO_QUERY );
497 
498             if( xPropSet.is())
499             {
500                 uno::Reference< beans::XPropertySetInfo >  xPropInfo = xPropSet->getPropertySetInfo();
501 
502                 uno::Any aAny = xPropSet->getPropertyValue( C2U("DefaultControl") );
503                 rtl::OUString aControlName;
504                 aAny >>= aControlName;
505 
506                 rtl::OUString uProp(C2U("HelpURL"));
507                 if(xPropInfo->hasPropertyByName(uProp))
508                 {
509                     ::rtl::OUString sId = ::rtl::OUString::createFromAscii( INET_HID_SCHEME );
510                     DBG_ASSERT( INetURLObject( rtl::OStringToOUString( sHelpId, RTL_TEXTENCODING_UTF8 ) ).GetProtocol() == INET_PROT_NOT_VALID, "Wrong HelpId!" );
511                     sId += ::rtl::OStringToOUString( sHelpId, RTL_TEXTENCODING_UTF8 );
512                     xPropSet->setPropertyValue( uProp, makeAny( sId ) );
513                 }
514 
515                 if(bTypeListBox)
516                 {
517                     //uno::Reference< beans::XPropertySet >  xPropSet(xControl, UNO_QUERY);
518                     aAny <<= (sal_Int16)1;
519                     xPropSet->setPropertyValue(C2U("BoundColumn"), aAny);
520                     ListSourceType eSet = ListSourceType_VALUELIST;
521                     aAny.setValue( &eSet, ::getCppuType((const ListSourceType*)0) );
522                     xPropSet->setPropertyValue(C2U("ListSourceType"), aAny);
523 
524                     uno::Sequence<rtl::OUString> aListSource(TYPE_COUNT);
525                     rtl::OUString* pListSourceArr = aListSource.getArray();
526                     //pListSourceArr[0] = C2U("select TypeName, TypeIndex from TypeNms");
527                     for(sal_uInt16 i = 0; i < TYPE_COUNT; i++)
528                         pListSourceArr[i] = String::CreateFromInt32(i);
529                     aAny.setValue(&aListSource, ::getCppuType((uno::Sequence<rtl::OUString>*)0));
530 
531                     xPropSet->setPropertyValue(C2U("ListSource"), aAny);
532 
533                     uno::Sequence<rtl::OUString> aValues(TYPE_COUNT + 1);
534                     rtl::OUString* pValuesArr = aValues.getArray();
535                     for(sal_uInt16 j = 0; j < TYPE_COUNT; j++)
536                         pValuesArr[j]  = aBibTypeArr[j];
537                     // empty string if an invalid value no values is set
538                     pValuesArr[TYPE_COUNT] = rtl::OUString();
539 
540                     aAny.setValue(&aValues, ::getCppuType((uno::Sequence<rtl::OUString>*)0));
541 
542                     xPropSet->setPropertyValue(C2U("StringItemList"), aAny);
543 
544                     sal_Bool bTrue = sal_True;
545                     aAny.setValue( &bTrue, ::getBooleanCppuType() );
546                     xPropSet->setPropertyValue( C2U("Dropdown"), aAny );
547 
548                     aControlName = C2U("com.sun.star.form.control.ListBox");
549                     xLBModel = Reference< form::XBoundComponent >(xCtrModel, UNO_QUERY);
550 
551                 }
552 
553                 uno::Reference< awt::XControl >  xControl(xMgr->createInstance( aControlName ), UNO_QUERY );
554                 if ( xControl.is() )
555                 {
556                     xControl->setModel( xCtrModel);
557 
558                     // Peer als Child zu dem FrameWindow
559                     xCtrlContnr->addControl(rName, xControl);
560                     uno::Reference< awt::XWindow >  xCtrWin(xControl, UNO_QUERY );
561                     xCtrWin->addFocusListener( this );
562                     rIndex = -1;    // -> implies, that not found
563                     for(sal_uInt16 i = 0; i < FIELD_COUNT; i++)
564                         if(!aControls[i].is())
565                         {
566                             aControls[i] = xCtrWin;
567                             rIndex = sal_Int16( i );
568                             break;
569                         }
570                     xCtrWin->setVisible( sal_True );
571                     xControl->setDesignMode( sal_True );
572                         // initially switch on the desing mode - switch it off _after_ loading the form
573                         // 17.10.2001 - 93107 - frank.schoenheit@sun.com
574 
575                     xCtrWin->setPosSize(rPos.X(), rPos.Y(), rSize.Width(),
576                         rSize.Height(), awt::PosSize::POSSIZE);
577                 }
578             }
579         }
580     }
581     catch(Exception& rEx)
582     {
583         (void) rEx; // make compiler happy
584         DBG_ERROR("BibGeneralPage::AddXControl: something went wrong !");
585     }
586     return xCtrModel;
587 }
588 
AdjustScrollbars()589 void BibGeneralPage::AdjustScrollbars()
590 {
591     long nVertScrollWidth = aVertScroll.GetSizePixel().Width();
592     long nHoriScrollHeight = aHoriScroll.GetSizePixel().Height();
593     ::Size aOutSize(GetOutputSizePixel());
594     sal_Bool bHoriVisible = aOutSize.Width() <= aStdSize.Width();
595     sal_Bool bVertVisible = (aOutSize.Height()-(bHoriVisible ? nHoriScrollHeight : 0)) <= (aStdSize.Height());
596     aHoriScroll.Show(bHoriVisible);
597     aVertScroll.Show(bVertVisible);
598 
599     if(bHoriVisible)
600     {
601         ::Size aHoriSize(aOutSize.Width() - (bVertVisible ? nVertScrollWidth : 0),
602                         nHoriScrollHeight);
603         aHoriScroll.SetSizePixel(aHoriSize);
604         aHoriScroll.SetRange( Range(0, aStdSize.Width()));
605         aHoriScroll.SetVisibleSize( aHoriSize.Width()  - (bVertVisible ? nVertScrollWidth : 0));
606     }
607     if(bVertVisible)
608     {
609         ::Size aVertSize(nHoriScrollHeight, aOutSize.Height() -
610                                             (bHoriVisible ? nHoriScrollHeight : 0));
611         aVertScroll.SetSizePixel(aVertSize);
612         aVertScroll.SetRange( Range(0, aStdSize.Height()));
613         aVertScroll.SetVisibleSize( aVertSize.Height() );
614     }
615 
616     ::Size aSize(8, 8);
617     aSize = LogicToPixel(aSize, MapMode(MAP_APPFONT));
618     ::Size aScrollSize(aOutSize.Width() - aSize.Height(), aSize.Height());
619     ::Point aScrollPos(0, aOutSize.Height() - aSize.Height());
620     aHoriScroll.SetPosSizePixel(aScrollPos, aScrollSize);
621 
622     aScrollPos.X() = aOutSize.Width() - aSize.Width();
623     aScrollPos.Y() = 0;
624     aScrollSize.Width() = aSize.Width();
625     aScrollSize.Height() = aOutSize.Height() - aSize.Height();
626     aVertScroll.SetPosSizePixel(aScrollPos, aScrollSize);
627 
628     ::Size aControlParentWinSz(aOutSize);
629     if(bHoriVisible)
630         aControlParentWinSz.Height() -=  aSize.Height();
631     if(bVertVisible)
632         aControlParentWinSz.Width() -=  aSize.Width();
633     aControlParentWin.SetSizePixel(aControlParentWinSz);
634 }
635 
Resize()636 void BibGeneralPage::Resize()
637 {
638     AdjustScrollbars();
639     ScrollHdl(&aVertScroll);
640     ScrollHdl(&aHoriScroll);
641     Window::Resize();
642 }
643 
InitFixedTexts(void)644 void BibGeneralPage::InitFixedTexts( void )
645 {
646     String      aFixedStrings[ FIELD_COUNT ] =
647     {
648         String( BibResId( ST_IDENTIFIER     ) ),
649         String( BibResId( ST_AUTHTYPE       ) ),
650         String( BibResId( ST_AUTHOR         ) ),
651         String( BibResId( ST_TITLE          ) ),
652         String( BibResId( ST_MONTH          ) ),
653         String( BibResId( ST_YEAR           ) ),
654         String( BibResId( ST_ISBN           ) ),
655         String( BibResId( ST_BOOKTITLE      ) ),
656         String( BibResId( ST_CHAPTER        ) ),
657         String( BibResId( ST_EDITION        ) ),
658         String( BibResId( ST_EDITOR         ) ),
659         String( BibResId( ST_HOWPUBLISHED   ) ),
660         String( BibResId( ST_INSTITUTION    ) ),
661         String( BibResId( ST_JOURNAL        ) ),
662         String( BibResId( ST_NOTE           ) ),
663         String( BibResId( ST_ANNOTE         ) ),
664         String( BibResId( ST_NUMBER         ) ),
665         String( BibResId( ST_ORGANIZATION   ) ),
666         String( BibResId( ST_PAGE           ) ),
667         String( BibResId( ST_PUBLISHER      ) ),
668         String( BibResId( ST_ADDRESS        ) ),
669         String( BibResId( ST_SCHOOL         ) ),
670         String( BibResId( ST_SERIES         ) ),
671         String( BibResId( ST_REPORT         ) ),
672         String( BibResId( ST_VOLUME         ) ),
673         String( BibResId( ST_URL            ) ),
674         String( BibResId( ST_CUSTOM1        ) ),
675         String( BibResId( ST_CUSTOM2        ) ),
676         String( BibResId( ST_CUSTOM3        ) ),
677         String( BibResId( ST_CUSTOM4        ) ),
678         String( BibResId( ST_CUSTOM5        ) )
679     };
680 
681     aFixedTexts[0] = &aIdentifierFT;
682     aFixedTexts[1] = &aAuthTypeFT;
683     aFixedTexts[2] = &aAuthorFT;
684     aFixedTexts[3] = &aTitleFT;
685     aFixedTexts[4] = &aMonthFT;
686     aFixedTexts[5] = &aYearFT;
687     aFixedTexts[6] = &aISBNFT;
688     aFixedTexts[7] = &aBooktitleFT;
689     aFixedTexts[8] = &aChapterFT;
690     aFixedTexts[9] = &aEditionFT;
691     aFixedTexts[10] = &aEditorFT;
692     aFixedTexts[11] = &aHowpublishedFT;
693     aFixedTexts[12] = &aInstitutionFT;
694     aFixedTexts[13] = &aJournalFT;
695     aFixedTexts[14] = &aNoteFT;
696     aFixedTexts[15] = &aAnnoteFT;
697     aFixedTexts[16] = &aNumberFT;
698     aFixedTexts[17] = &aOrganizationsFT;
699     aFixedTexts[18] = &aPagesFT;
700     aFixedTexts[19] = &aPublisherFT;
701     aFixedTexts[20] = &aAddressFT;
702     aFixedTexts[21] = &aSchoolFT;
703     aFixedTexts[22] = &aSeriesFT;
704     aFixedTexts[23] = &aReportTypeFT;
705     aFixedTexts[24] = &aVolumeFT;
706     aFixedTexts[25] = &aURLFT;
707     aFixedTexts[26] = &aCustom1FT;
708     aFixedTexts[27] = &aCustom2FT;
709     aFixedTexts[28] = &aCustom3FT;
710     aFixedTexts[29] = &aCustom4FT;
711     aFixedTexts[30] = &aCustom5FT;
712 
713     int                 i;
714 
715     MnemonicGenerator   aMnemonicGenerator;
716     // init mnemonics, first register all strings
717     for( i = 0 ; i < FIELD_COUNT ; ++i )
718         aMnemonicGenerator.RegisterMnemonic( aFixedStrings[ i ] );
719 
720     // ... then get all strings
721     for( i = 0 ; i < FIELD_COUNT ; ++i )
722         aMnemonicGenerator.CreateMnemonic( aFixedStrings[ i ] );
723 
724     // set texts
725     for( i = 0 ; i < FIELD_COUNT ; ++i )
726         aFixedTexts[ i ]->SetText( aFixedStrings[ i ] );
727 }
728 
IMPL_LINK(BibGeneralPage,ScrollHdl,ScrollBar *,pScroll)729 IMPL_LINK(BibGeneralPage, ScrollHdl, ScrollBar*, pScroll)
730 {
731     sal_Bool bVertical = &aVertScroll == pScroll;
732     long nOffset = 0;
733     long nCurrentOffset = 0;
734     if(bVertical)
735         nCurrentOffset = aFixedTexts[0]->GetPosPixel().Y() - aBasePos.Y();
736     else
737         nCurrentOffset = aFixedTexts[0]->GetPosPixel().X() - aBasePos.X();
738     nOffset = pScroll->IsVisible() ? pScroll->GetThumbPos() + nCurrentOffset : nCurrentOffset;;
739 
740     for(sal_uInt16 i = 0; i < FIELD_COUNT; i++)
741     {
742         ::Point aPos = aFixedTexts[i]->GetPosPixel();
743         if(bVertical)
744             aPos.Y() -= nOffset;
745         else
746             aPos.X() -= nOffset;
747         aFixedTexts[i]->SetPosPixel(aPos);
748         if(aControls[i].is())
749         {
750             awt::Rectangle aRect = aControls[i]->getPosSize();
751             long nX = aRect.X;
752             long nY = aRect.Y;
753             if(bVertical)
754                 nY -= nOffset;
755             else
756                 nX -= nOffset;
757             aControls[i]->setPosSize(nX, nY, 0, 0, awt::PosSize::POS);
758         }
759     }
760     return 0;
761 }
762 
focusGained(const awt::FocusEvent & rEvent)763 void BibGeneralPage::focusGained(const awt::FocusEvent& rEvent) throw( uno::RuntimeException )
764 {
765     Reference<awt::XWindow> xCtrWin(rEvent.Source, UNO_QUERY );
766     if(xCtrWin.is())
767     {
768         ::Size aOutSize = aControlParentWin.GetOutputSizePixel();
769         awt::Rectangle aRect = xCtrWin->getPosSize();
770         long nX = aRect.X;
771         if(nX < 0)
772         {
773             // left of the visible area
774             aHoriScroll.SetThumbPos(aHoriScroll.GetThumbPos() + nX);
775             ScrollHdl(&aHoriScroll);
776         }
777         else if(nX > aOutSize.Width())
778         {
779             // right of the visible area
780             aHoriScroll.SetThumbPos(aHoriScroll.GetThumbPos() + nX - aOutSize.Width() + aFixedTexts[0]->GetSizePixel().Width());
781             ScrollHdl(&aHoriScroll);
782         }
783         long nY = aRect.Y;
784         if(nY < 0)
785         {
786             // below the visible area
787             aVertScroll.SetThumbPos(aVertScroll.GetThumbPos() + nY);
788             ScrollHdl(&aVertScroll);
789         }
790         else if(nY > aOutSize.Height())
791         {
792             // over the visible area
793             aVertScroll.SetThumbPos(aVertScroll.GetThumbPos() + nY - aOutSize.Height()+ aFixedTexts[0]->GetSizePixel().Height());
794             ScrollHdl(&aVertScroll);
795         }
796     }
797 }
798 
focusLost(const awt::FocusEvent &)799 void BibGeneralPage::focusLost(const awt::FocusEvent& ) throw( uno::RuntimeException )
800 {
801     CommitActiveControl();
802 }
803 
disposing(const lang::EventObject &)804 void BibGeneralPage::disposing(const lang::EventObject& /*Source*/) throw( uno::RuntimeException )
805 {
806 }
807 
GetFocus()808 void BibGeneralPage::GetFocus()
809 {
810     Reference< awt::XWindow >*  pxControl = aControls;
811 
812     for( int i = FIELD_COUNT ; i ; --i, ++pxControl )
813     {
814         if( pxControl->is() )
815         {
816             ( *pxControl )->setFocus();
817             return;
818         }
819     }
820 
821     // fallback
822     aControlParentWin.GrabFocus();
823 }
824 
HandleShortCutKey(const KeyEvent & rKeyEvent)825 sal_Bool BibGeneralPage::HandleShortCutKey( const KeyEvent& rKeyEvent )
826 {
827     DBG_ASSERT( KEY_MOD2 == rKeyEvent.GetKeyCode().GetModifier(), "+BibGeneralPage::HandleShortCutKey(): this is not for me!" );
828 
829     const vcl::I18nHelper&      rI18nHelper = Application::GetSettings().GetUILocaleI18nHelper();
830     const xub_Unicode           c = rKeyEvent.GetCharCode();
831     sal_Bool                        bHandled = sal_False;
832 
833     sal_Int16                   i;
834 
835     typedef std::vector< sal_Int16 >    sal_Int16_vector;
836 
837     sal_Int16_vector::size_type nFocused = 0xFFFF;  // index of focused in vector, no one focused initial
838     DBG_ASSERT( nFocused > 0, "*BibGeneralPage::HandleShortCutKey(): size_type works not as expected!" );
839 
840     sal_Int16_vector            aMatchList;
841 
842     for( i = 0 ; i < FIELD_COUNT ; ++i )
843     {
844         if( rI18nHelper.MatchMnemonic( aFixedTexts[ i ]->GetText(), c ) )
845         {
846             bHandled = sal_True;
847             sal_Int16           nCtrlIndex = nFT2CtrlMap[ i ];
848 
849             if( nCtrlIndex >= 0 )
850             {   // store index of control
851                 DBG_ASSERT( aControls[ nCtrlIndex ].is(), "-BibGeneralPage::HandleShortCutKey(): valid index and no control?" );
852 
853                 uno::Reference< awt::XControl >  xControl( aControls[ nCtrlIndex ], UNO_QUERY );
854                 DBG_ASSERT( xControl.is(), "-BibGeneralPage::HandleShortCutKey(): a control wich is not a control!" );
855 
856                 Window*         pWindow = VCLUnoHelper::GetWindow( xControl->getPeer() );
857 
858                 if( pWindow )
859                 {
860                     aMatchList.push_back( nCtrlIndex );
861                     if( pWindow->HasChildPathFocus() )
862                     {   // save focused control
863                         DBG_ASSERT( nFocused == 0xFFFF, "+BibGeneralPage::HandleShortCutKey(): more than one with focus?!" );
864                         DBG_ASSERT( aMatchList.size() > 0, "+BibGeneralPage::HandleShortCutKey(): push_back and no content?!" );
865                         nFocused = aMatchList.size() - 1;
866                     }
867                 }
868             }
869         }
870     }
871 
872     if( bHandled )
873     {
874         DBG_ASSERT( aMatchList.size() > 0, "*BibGeneralPage::HandleShortCutKey(): be prepared to crash..." );
875 
876         if( nFocused >= ( aMatchList.size() - 1 ) )
877             // >=... includes 0xFFFF
878             // no one or last focused, take first
879             nFocused = 0;
880         else
881             // take next one
882             nFocused++;
883 
884         aControls[ aMatchList[ nFocused ] ]->setFocus();
885     }
886 
887     return bHandled;
888 }
889