xref: /trunk/main/sw/source/ui/envelp/label1.cxx (revision 737f44756be6e3fccf1468c183ceecf42044f3bb)
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_sw.hxx"
26 #ifdef SW_DLLIMPLEMENTATION
27 #undef SW_DLLIMPLEMENTATION
28 #endif
29 
30 
31 #include <vcl/waitobj.hxx>
32 #include <rtl/ustring.hxx>
33 #include <com/sun/star/uno/Sequence.h>
34 #include <swtypes.hxx>
35 #include <wrtsh.hxx>
36 #include <initui.hxx>
37 #include <labimp.hxx>
38 #include <labfmt.hxx>
39 #include <labprt.hxx>
40 #include <unotools.hxx>
41 #ifndef _DBMGR_HXX
42 #include <dbmgr.hxx>
43 #endif
44 #include "uitool.hxx"
45 #ifndef _CMDID_H
46 #include <cmdid.h>
47 #endif
48 #ifndef _HELPID_H
49 #include <helpid.h>
50 #endif
51 #ifndef _GLOBALS_HRC
52 #include <globals.hrc>
53 #endif
54 #ifndef _LABEL_HRC
55 #include <label.hrc>
56 #endif
57 
58 //impl in envimg.cxx
59 extern SW_DLLPUBLIC String MakeSender();
60 
61 
62 SV_IMPL_PTRARR( SwLabRecs, SwLabRec* );
63 
64 void SwLabRec::SetFromItem( const SwLabItem& rItem )
65 {
66     lHDist  = rItem.lHDist;
67     lVDist  = rItem.lVDist;
68     lWidth  = rItem.lWidth;
69     lHeight = rItem.lHeight;
70     lLeft   = rItem.lLeft;
71     lUpper  = rItem.lUpper;
72     nCols   = rItem.nCols;
73     nRows   = rItem.nRows;
74     lPaperWidth  = rItem.lPaperWidth;
75     lPaperHeight = rItem.lPaperHeight;
76     bCont   = rItem.bCont;
77 }
78 
79 void SwLabRec::FillItem( SwLabItem& rItem ) const
80 {
81     rItem.lHDist  = lHDist;
82     rItem.lVDist  = lVDist;
83     rItem.lWidth  = lWidth;
84     rItem.lHeight = lHeight;
85     rItem.lLeft   = lLeft;
86     rItem.lUpper  = lUpper;
87     rItem.nCols   = nCols;
88     rItem.nRows   = nRows;
89     rItem.lPaperWidth  = lPaperWidth;
90     rItem.lPaperHeight = lPaperHeight;
91 }
92 
93 // --------------------------------------------------------------------------
94 void SwLabDlg::_ReplaceGroup( const String &rMake )
95 {
96     //Die alten Eintraege vernichten.
97     pRecs->Remove( 1, pRecs->Count() - 1 );
98     aLabelsCfg.FillLabels(rtl::OUString(rMake), *pRecs);
99     aLstGroup = rMake;
100 }
101 
102 // --------------------------------------------------------------------------
103 
104 
105 
106 void SwLabDlg::PageCreated(sal_uInt16 nId, SfxTabPage &rPage)
107 {
108     if (nId == TP_LAB_LAB)
109     {
110         if(m_bLabel)
111         {
112             ((SwLabPage*)&rPage)->SetNewDBMgr(pNewDBMgr);
113             ((SwLabPage*)&rPage)->InitDatabaseBox();
114         }
115         else
116             ((SwLabPage*)&rPage)->SetToBusinessCard();
117     }
118     else if (nId == TP_LAB_PRT)
119         pPrtPage = (SwLabPrtPage*)&rPage;
120 }
121 
122 // --------------------------------------------------------------------------
123 
124 
125 
126 SwLabDlg::SwLabDlg(Window* pParent, const SfxItemSet& rSet,
127                                 SwNewDBMgr* pDBMgr, sal_Bool bLabel) :
128     SfxTabDialog( pParent, SW_RES(DLG_LAB), &rSet, sal_False ),
129     pNewDBMgr(pDBMgr),
130     pPrtPage(0),
131 
132     aTypeIds( 50, 10 ),
133     aMakes  (  5,  0 ),
134 
135     pRecs   ( new SwLabRecs() ),
136     sBusinessCardDlg(SW_RES(ST_BUSINESSCARDDLG)),
137     sFormat(SW_RES(ST_FIRSTPAGE_LAB)),
138     sMedium(SW_RES(ST_FIRSTPAGE_BC)),
139     m_bLabel(bLabel)
140 {
141     WaitObject aWait( pParent );
142 
143     FreeResource();
144 
145     GetOKButton().SetText(String(SW_RES(STR_BTN_NEW_DOC)));
146     GetOKButton().SetHelpId(HID_LABEL_INSERT);
147     GetOKButton().SetHelpText(aEmptyStr);   // Damit generierter Hilfetext verwendet wird
148 
149     AddTabPage(TP_LAB_LAB, m_bLabel ? sFormat : sMedium ,SwLabPage   ::Create, 0, sal_False, 0);
150     AddTabPage(TP_VISITING_CARDS, SwVisitingCardPage::Create, 0);
151     AddTabPage(TP_LAB_FMT, SwLabFmtPage::Create, 0);
152     AddTabPage(TP_LAB_PRT, SwLabPrtPage::Create, 0);
153     AddTabPage(TP_BUSINESS_DATA, SwBusinessDataPage::Create, 0 );
154     AddTabPage(TP_PRIVATE_DATA, SwPrivateDataPage::Create, 0);
155 
156 
157     if(m_bLabel)
158     {
159         RemoveTabPage(TP_BUSINESS_DATA);
160         RemoveTabPage(TP_PRIVATE_DATA);
161         RemoveTabPage(TP_VISITING_CARDS);
162     }
163     else
164     {
165         SetText(sBusinessCardDlg);
166     }
167     // Benutzer-Etikette aus writer.cfg lesen
168     SwLabItem aItem((const SwLabItem&)rSet.Get( FN_LABEL ));
169     SwLabRec* pRec = new SwLabRec;
170     const String aTmp( SW_RES( STR_CUSTOM ) );
171     pRec->aMake   = pRec->aType = aTmp;
172     pRec->SetFromItem( aItem );
173 
174     sal_Bool bDouble = sal_False;
175 
176     for (sal_uInt16 nRecPos = 0; nRecPos < pRecs->Count(); nRecPos++)
177     {
178         if (pRec->aMake == pRecs->GetObject(nRecPos)->aMake &&
179             pRec->aType == pRecs->GetObject(nRecPos)->aType)
180         {
181             bDouble = sal_True;
182             break;
183         }
184     }
185 
186     if (!bDouble)
187         pRecs->C40_INSERT( SwLabRec, pRec, 0 );
188 
189     sal_uInt16 nLstGroup = 0;
190     const UNO_NMSPC::Sequence<rtl::OUString>& rMan = aLabelsCfg.GetManufacturers();
191     const rtl::OUString* pMan = rMan.getConstArray();
192     for(sal_Int32 nMan = 0; nMan < rMan.getLength(); nMan++)
193     {
194         aMakes.Insert( new String(pMan[nMan]), aMakes.Count() );
195         if ( pMan[nMan] == aItem.aLstMake )
196             nLstGroup = (sal_uInt16) nMan;
197     }
198 
199     if ( aMakes.Count() )
200         _ReplaceGroup( *aMakes[nLstGroup] );
201     if (pExampleSet)
202         pExampleSet->Put(aItem);
203 }
204 
205 // --------------------------------------------------------------------------
206 
207 SwLabDlg::~SwLabDlg()
208 {
209     delete pRecs;
210 }
211 // --------------------------------------------------------------------------
212 
213 void SwLabDlg::GetLabItem(SwLabItem &rItem)
214 {
215     const SwLabItem& rActItem = (const SwLabItem&)GetExampleSet()->Get(FN_LABEL);
216     const SwLabItem& rOldItem = (const SwLabItem&)GetInputSetImpl()->Get(FN_LABEL);
217 
218     if (rActItem != rOldItem)
219     {   // Wurde schon mal mit (hoffentlich) korrektem Inhalt "geputtet"
220         rItem = rActItem;
221     }
222     else
223     {
224         rItem = rOldItem;
225 
226         // Im rItem stehen (vom Namen mal abgesehen) immer nur die
227         // benutzerdefinierbaren Einstellungen. Daher richtige Werte
228         // direkt aus dem Record besorgen:
229         SwLabRec* pRec = GetRecord(rItem.aType, rItem.bCont);
230         pRec->FillItem( rItem );
231     }
232 }
233 
234 // --------------------------------------------------------------------------
235 
236 SwLabRec* SwLabDlg::GetRecord(const String &rRecName, sal_Bool bCont)
237 {
238     SwLabRec* pRec = NULL;
239     sal_Bool bFound = sal_False;
240     String sCustom(SW_RES(STR_CUSTOM));
241 
242     const sal_uInt16 nCount = Recs().Count();
243     for (sal_uInt16 i = 0; i < nCount; i++)
244     {
245         pRec = Recs()[i];
246         if (pRec->aType != sCustom &&
247             rRecName == pRec->aType && bCont == pRec->bCont)
248         {
249             bFound = sal_True;
250             break;
251         }
252     }
253     if (!bFound)    // Benutzerdefiniert
254         pRec = Recs()[0];
255 
256     return(pRec);
257 }
258 
259 // --------------------------------------------------------------------------
260 
261 Printer *SwLabDlg::GetPrt()
262 {
263     if (pPrtPage)
264         return (pPrtPage->GetPrt());
265     else
266         return (NULL);
267 }
268 
269 // --------------------------------------------------------------------------
270 SwLabPage::SwLabPage(Window* pParent, const SfxItemSet& rSet) :
271     SfxTabPage(pParent, SW_RES(TP_LAB_LAB), rSet),
272     pNewDBMgr(NULL),
273     aItem          ((const SwLabItem&) rSet.Get(FN_LABEL)),
274 
275     aWritingFL     (this, SW_RES(FL_WRITING)),
276     aWritingText   (this, SW_RES(TXT_WRITING)),
277     aAddrBox       (this, SW_RES(BOX_ADDR   )),
278     aWritingEdit   (this, SW_RES(EDT_WRITING)),
279     aDatabaseFT    (this, SW_RES(FT_DATABASE)),
280     aDatabaseLB    (this, SW_RES(LB_DATABASE)),
281     aTableFT       (this, SW_RES(FT_TABLE   )),
282     aTableLB       (this, SW_RES(LB_TABLE   )),
283     aInsertBT      (this, SW_RES(BTN_INSERT )),
284     aDBFieldFT     (this, SW_RES(FT_DBFIELD )),
285     aDBFieldLB     (this, SW_RES(LB_DBFIELD )),
286     aFormatFL      (this, SW_RES(FL_FORMAT )),
287     aContButton    (this, SW_RES(BTN_CONT   )),
288     aSheetButton   (this, SW_RES(BTN_SHEET  )),
289     aMakeText      (this, SW_RES(TXT_MAKE   )),
290     aMakeBox       (this, SW_RES(BOX_MAKE   )),
291     aTypeText      (this, SW_RES(TXT_TYPE   )),
292     aTypeBox       (this, SW_RES(BOX_TYPE   )),
293     aHiddenSortTypeBox(this, WB_SORT|WB_HIDE),
294     aFormatInfo    (this, SW_RES(INF_FORMAT ))
295    {
296     WaitObject aWait( pParent );
297 
298     FreeResource();
299     SetExchangeSupport();
300 
301 
302     // Handler installieren
303     aAddrBox       .SetClickHdl (LINK(this, SwLabPage, AddrHdl         ));
304     aDatabaseLB    .SetSelectHdl(LINK(this, SwLabPage, DatabaseHdl     ));
305     aTableLB       .SetSelectHdl(LINK(this, SwLabPage, DatabaseHdl     ));
306     aInsertBT      .SetClickHdl (LINK(this, SwLabPage, FieldHdl        ));
307     aContButton    .SetClickHdl (LINK(this, SwLabPage, PageHdl         ));
308     aSheetButton   .SetClickHdl (LINK(this, SwLabPage, PageHdl         ));
309     aMakeBox       .SetSelectHdl(LINK(this, SwLabPage, MakeHdl         ));
310     aTypeBox       .SetSelectHdl(LINK(this, SwLabPage, TypeHdl         ));
311 
312     InitDatabaseBox();
313 
314     sal_uInt16 nLstGroup = 0;
315 
316     const sal_uInt16 nCount = (sal_uInt16)GetParent()->Makes().Count();
317     for (sal_uInt16 i = 0; i < nCount; ++i)
318     {
319         String &rStr = *GetParent()->Makes()[i];
320         aMakeBox.InsertEntry( rStr );
321         if ( rStr == String(aItem.aLstMake) )
322             nLstGroup = i;
323     }
324 //  Reset(rSet);
325     aMakeBox.SelectEntryPos( nLstGroup );
326     aMakeBox.GetSelectHdl().Call( &aMakeBox );
327 }
328 
329 // --------------------------------------------------------------------------
330 
331 
332 
333 SwLabPage::~SwLabPage()
334 {
335 }
336 /* -----------------29.09.99 09:08-------------------
337 
338  --------------------------------------------------*/
339 void lcl_ChgYPos(Window& rWin, long nDiff)
340 {
341     Point aTempPos(rWin.GetPosPixel());
342     aTempPos.Y() += nDiff;
343     rWin.SetPosPixel(aTempPos);
344 }
345 
346 void SwLabPage::SetToBusinessCard()
347 {
348     SetHelpId(HID_BUSINESS_FMT_PAGE);
349     aContButton.SetHelpId(HID_BUSINESS_FMT_PAGE_CONT);
350     aSheetButton.SetHelpId(HID_BUSINESS_FMT_PAGE_SHEET);
351     aMakeBox.SetHelpId(HID_BUSINESS_FMT_PAGE_BRAND);
352     aTypeBox.SetHelpId(HID_BUSINESS_FMT_PAGE_TYPE);
353     m_bLabel = sal_False;
354     aWritingText.Hide();
355     aAddrBox.Hide();
356     aWritingEdit.Hide();
357     aDatabaseFT.Hide();
358     aDatabaseLB.Hide();
359     aTableFT.Hide();
360     aTableLB.Hide();
361     aInsertBT.Hide();
362     aDBFieldFT.Hide();
363     aDBFieldLB.Hide();
364     aWritingFL.Hide();
365 
366     //resize the form
367     Point aFLPos(aWritingFL.GetPosPixel());
368     long nDiffPos = aFormatFL.GetPosPixel().Y() - aFLPos.Y();
369     Size aFLSz(aFormatFL.GetSizePixel());
370 //  aFLSz.Height() += nDiffPos;
371     aFormatFL.SetPosSizePixel(aFLPos, aFLSz);
372 
373     // move all controls up
374     lcl_ChgYPos(aContButton, -nDiffPos);
375     lcl_ChgYPos(aSheetButton, -nDiffPos);
376     lcl_ChgYPos(aMakeText, -nDiffPos);
377 
378     lcl_ChgYPos(aTypeText, -nDiffPos);
379     lcl_ChgYPos(aFormatInfo, -nDiffPos);
380 
381     Size aTmpSz(3, 3);
382     aTmpSz = LogicToPixel(aTmpSz, MAP_APPFONT);
383 
384     lcl_ChgYPos(aMakeBox, - nDiffPos);
385     Point aLBPos(aMakeBox.GetPosPixel());
386     aLBPos.Y() += aMakeBox.GetSizePixel().Height() + aTmpSz.Height();
387     aTypeBox.SetPosPixel(aLBPos);
388 };
389 
390 // --------------------------------------------------------------------------
391 
392 
393 IMPL_LINK( SwLabPage, AddrHdl, Button *, EMPTYARG )
394 {
395     String aWriting;
396     if ( aAddrBox.IsChecked() )
397         aWriting = MakeSender();
398     aWritingEdit.SetText( aWriting.ConvertLineEnd() );
399     aWritingEdit.GrabFocus();
400     return 0;
401 }
402 
403 // --------------------------------------------------------------------------
404 
405 
406 
407 IMPL_LINK( SwLabPage, DatabaseHdl, ListBox *, pListBox )
408 {
409     sActDBName = aDatabaseLB.GetSelectEntry();
410 
411     WaitObject aObj( GetParent() );
412 
413     if (pListBox == &aDatabaseLB)
414         GetNewDBMgr()->GetTableNames(&aTableLB, sActDBName);
415     GetNewDBMgr()->GetColumnNames(&aDBFieldLB, sActDBName, aTableLB.GetSelectEntry());
416     return 0;
417 }
418 
419 
420 
421 IMPL_LINK( SwLabPage, FieldHdl, Button *, EMPTYARG )
422 {
423     String aStr ( '<' );
424     aStr += aDatabaseLB.GetSelectEntry();
425     aStr += '.';
426     aStr += aTableLB.GetSelectEntry();
427     aStr += '.';
428     aStr += aTableLB.GetEntryData(aTableLB.GetSelectEntryPos()) == 0 ? '0' : '1';
429     aStr += '.';
430     aStr += aDBFieldLB.GetSelectEntry();
431     aStr += '>';
432     aWritingEdit.ReplaceSelected(aStr);
433     Selection aSel = aWritingEdit.GetSelection();
434     aWritingEdit.GrabFocus();
435     aWritingEdit.SetSelection(aSel);
436     return 0;
437 }
438 
439 // --------------------------------------------------------------------------
440 
441 
442 
443 IMPL_LINK_INLINE_START( SwLabPage, PageHdl, Button *, EMPTYARG )
444 {
445     aMakeBox.GetSelectHdl().Call( &aMakeBox );
446     return 0;
447 }
448 IMPL_LINK_INLINE_END( SwLabPage, PageHdl, Button *, EMPTYARG )
449 
450 // --------------------------------------------------------------------------
451 
452 
453 
454 IMPL_LINK( SwLabPage, MakeHdl, ListBox *, EMPTYARG )
455 {
456     WaitObject aWait( GetParent() );
457 
458     aTypeBox.Clear();
459     aHiddenSortTypeBox.Clear();
460     GetParent()->TypeIds().Remove( 0, GetParent()->TypeIds().Count() );
461 
462     const String aMake = aMakeBox.GetSelectEntry();
463     GetParent()->ReplaceGroup( aMake );
464     aItem.aLstMake = aMake;
465 
466     const sal_Bool   bCont    = aContButton.IsChecked();
467     const sal_uInt16 nCount   = GetParent()->Recs().Count();
468           sal_uInt16 nLstType = 0;
469 
470     const String sCustom(SW_RES(STR_CUSTOM));
471     //insert the entries into the sorted list box
472     for ( sal_uInt16 i = 0; i < nCount; ++i )
473     {
474         const String aType ( GetParent()->Recs()[i]->aType );
475         sal_Bool bInsert = sal_False;
476         if ( GetParent()->Recs()[i]->aType == sCustom )
477         {
478             bInsert = sal_True;
479             aTypeBox.InsertEntry(aType );
480         }
481         else if ( GetParent()->Recs()[i]->bCont == bCont )
482         {
483             if ( aHiddenSortTypeBox.GetEntryPos(aType) == LISTBOX_ENTRY_NOTFOUND )
484             {
485                 bInsert = sal_True;
486                 aHiddenSortTypeBox.InsertEntry( aType );
487             }
488         }
489         if(bInsert)
490         {
491             GetParent()->TypeIds().Insert(i, GetParent()->TypeIds().Count());
492             if ( !nLstType && aType == String(aItem.aLstType) )
493                 nLstType = GetParent()->TypeIds().Count();
494         }
495     }
496     for(sal_uInt16 nEntry = 0; nEntry < aHiddenSortTypeBox.GetEntryCount(); nEntry++)
497     {
498         aTypeBox.InsertEntry(aHiddenSortTypeBox.GetEntry(nEntry));
499     }
500     if (nLstType)
501         aTypeBox.SelectEntry(aItem.aLstType);
502     else
503         aTypeBox.SelectEntryPos(0);
504     aTypeBox.GetSelectHdl().Call( &aTypeBox );
505     return 0;
506 }
507 
508 // --------------------------------------------------------------------------
509 
510 
511 
512 IMPL_LINK_INLINE_START( SwLabPage, TypeHdl, ListBox *, EMPTYARG )
513 {
514     DisplayFormat();
515     aItem.aType = aTypeBox.GetSelectEntry();
516     return 0;
517 }
518 IMPL_LINK_INLINE_END( SwLabPage, TypeHdl, ListBox *, EMPTYARG )
519 
520 // --------------------------------------------------------------------------
521 
522 
523 
524 void SwLabPage::DisplayFormat()
525 {
526     MetricField aField(this, WinBits(0));
527     FieldUnit aMetric = ::GetDfltMetric(sal_False);
528     SetMetric(aField, aMetric);
529     aField.SetDecimalDigits(2);
530     aField.SetMin         (0);
531     aField.SetMax         (LONG_MAX);
532 
533     SwLabRec* pRec = GetSelectedEntryPos();
534     aItem.aLstType = pRec->aType;
535     SETFLDVAL(aField, pRec->lWidth);
536     aField.Reformat();
537     const String aWString = aField.GetText();
538 
539     SETFLDVAL(aField, pRec->lHeight);
540     aField.Reformat();
541 
542     String aText = pRec->aType;
543     aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ": "));
544     aText += aWString;
545     aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM(" x "));
546     aText += aField.GetText();
547     aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM(" ("));
548     aText += String::CreateFromInt32( pRec->nCols );
549     aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM(" x "));
550     aText += String::CreateFromInt32( pRec->nRows );
551     aText += ')';
552     aFormatInfo.SetText(aText);
553 }
554 
555 // --------------------------------------------------------------------------
556 
557 SwLabRec* SwLabPage::GetSelectedEntryPos()
558 {
559     String sSelEntry(aTypeBox.GetSelectEntry());
560 
561     return GetParent()->GetRecord(sSelEntry, aContButton.IsChecked());
562 }
563 
564 // --------------------------------------------------------------------------
565 
566 
567 
568 void SwLabPage::InitDatabaseBox()
569 {
570     if( GetNewDBMgr() )
571     {
572         aDatabaseLB.Clear();
573         UNO_NMSPC::Sequence<rtl::OUString> aDataNames = SwNewDBMgr::GetExistingDatabaseNames();
574         const rtl::OUString* pDataNames = aDataNames.getConstArray();
575         for (long i = 0; i < aDataNames.getLength(); i++)
576             aDatabaseLB.InsertEntry(pDataNames[i]);
577         String sDBName = sActDBName.GetToken( 0, DB_DELIM );
578         String sTableName = sActDBName.GetToken( 1, DB_DELIM );
579         aDatabaseLB.SelectEntry(sDBName);
580         if( sDBName.Len() && GetNewDBMgr()->GetTableNames(&aTableLB, sDBName))
581         {
582             aTableLB.SelectEntry(sTableName);
583             GetNewDBMgr()->GetColumnNames(&aDBFieldLB, sActDBName, sTableName);
584         }
585         else
586             aDBFieldLB.Clear();
587     }
588 }
589 
590 // --------------------------------------------------------------------------
591 SfxTabPage* SwLabPage::Create(Window* pParent, const SfxItemSet& rSet)
592 {
593     return new SwLabPage(pParent, rSet);
594 }
595 
596 // --------------------------------------------------------------------------
597 void SwLabPage::ActivatePage(const SfxItemSet& rSet)
598 {
599     Reset( rSet );
600 }
601 // --------------------------------------------------------------------------
602 int SwLabPage::DeactivatePage(SfxItemSet* _pSet)
603 {
604     if (_pSet)
605         FillItemSet(*_pSet);
606 
607     return sal_True;
608 }
609 
610 // --------------------------------------------------------------------------
611 
612 
613 
614 void SwLabPage::FillItem(SwLabItem& rItem)
615 {
616     rItem.bAddr    = aAddrBox.IsChecked();
617     rItem.aWriting = aWritingEdit.GetText();
618     rItem.bCont    = aContButton.IsChecked();
619     rItem.aMake    = aMakeBox.GetSelectEntry();
620     rItem.aType    = aTypeBox.GetSelectEntry();
621     rItem.sDBName  = sActDBName;
622 
623     SwLabRec* pRec = GetSelectedEntryPos();
624     pRec->FillItem( rItem );
625 
626     rItem.aLstMake = aMakeBox.GetSelectEntry();
627     rItem.aLstType = aTypeBox.GetSelectEntry();
628 }
629 
630 // --------------------------------------------------------------------------
631 
632 
633 
634 sal_Bool SwLabPage::FillItemSet(SfxItemSet& rSet)
635 {
636     FillItem( aItem );
637     rSet.Put( aItem );
638 
639     return sal_True;
640 }
641 
642 // --------------------------------------------------------------------------
643 
644 void SwLabPage::Reset(const SfxItemSet& rSet)
645 {
646     aItem = (const SwLabItem&) rSet.Get(FN_LABEL);
647     String sDBName  = aItem.sDBName;
648 
649     String aWriting( aItem.aWriting );
650 
651     aAddrBox    .Check      ( aItem.bAddr );
652     aWritingEdit.SetText    ( aWriting.ConvertLineEnd() );
653 
654     const sal_uInt16 nCount = (sal_uInt16)GetParent()->Makes().Count();
655     for (sal_uInt16 i = 0; i < nCount; ++i)
656     {
657         String &rStr = *GetParent()->Makes()[i];
658         if(aMakeBox.GetEntryPos(String(rStr)) == LISTBOX_ENTRY_NOTFOUND)
659             aMakeBox.InsertEntry( rStr );
660     }
661 
662 
663     aMakeBox    .SelectEntry( aItem.aMake );
664     //save the current type
665     String sType(aItem.aType);
666     aMakeBox.GetSelectHdl().Call( &aMakeBox );
667     aItem.aType = sType;
668     //#102806# a newly added make may not be in the type ListBox already
669     if (aTypeBox.GetEntryPos(String(aItem.aType)) == LISTBOX_ENTRY_NOTFOUND && aItem.aMake.getLength())
670         GetParent()->UpdateGroup( aItem.aMake );
671     if (aTypeBox.GetEntryPos(String(aItem.aType)) != LISTBOX_ENTRY_NOTFOUND)
672     {
673         aTypeBox.SelectEntry(aItem.aType);
674         aTypeBox.GetSelectHdl().Call(&aTypeBox);
675     }
676     if (aDatabaseLB.GetEntryPos(sDBName) != LISTBOX_ENTRY_NOTFOUND)
677     {
678         aDatabaseLB.SelectEntry(sDBName);
679         aDatabaseLB.GetSelectHdl().Call(&aDatabaseLB);
680     }
681 
682     if (aItem.bCont)
683         aContButton .Check();
684     else
685         aSheetButton.Check();
686 }
687 
688 /*-- 08.07.99 14:00:02---------------------------------------------------
689 
690   -----------------------------------------------------------------------*/
691 //-----------------------------------------------------------------------------
692 void SwVisitingCardPage::ClearUserData()
693 {
694     SvLBoxEntry* pEntry = aAutoTextLB.First();
695     while(pEntry)
696     {
697         delete (String*)pEntry->GetUserData();
698         pEntry = aAutoTextLB.Next(pEntry);
699     }
700 }
701 
702 //-----------------------------------------------------------------------------
703 
704 void SwVisitingCardPage::SetUserData( sal_uInt32 nCnt,
705                 const rtl::OUString* pNames, const rtl::OUString* pValues )
706 {
707     for( sal_uInt32 i = 0; i < nCnt; ++i )
708     {
709         SvLBoxEntry* pEntry = aAutoTextLB.InsertEntry( pNames[ i ] );
710         pEntry->SetUserData( new String( pValues[ i ] ));
711     }
712 }
713 
714 //-----------------------------------------------------------------------------
715 
716 SwVisitingCardPage::SwVisitingCardPage(Window* pParent, const SfxItemSet& rSet) :
717     SfxTabPage(pParent, SW_RES(TP_VISITING_CARDS), rSet),
718     aContentFL(this,        SW_RES( FL_CONTENT           )),
719     aAutoTextLB(this,       SW_RES( LB_AUTO_TEXT            )),
720     aAutoTextGroupFT(this,  SW_RES( FT_AUTO_TEXT_GROUP  )),
721     aAutoTextGroupLB(this,  SW_RES( LB_AUTO_TEXT_GROUP  )),
722     aExampleWIN(this,       SW_RES( WIN_EXAMPLE         )),
723     sVisCardGroup(SW_RES(ST_VISCARD_GROUP)),
724     pExampleFrame(0)
725 {
726     FreeResource();
727     aAutoTextLB.SetStyle( aAutoTextLB.GetStyle() | WB_HSCROLL );
728     aAutoTextLB.SetSpaceBetweenEntries(0);
729     aAutoTextLB.SetSelectionMode( SINGLE_SELECTION );
730     aAutoTextLB.SetHelpId(HID_BUSINESS_CARD_CONTENT);
731 
732     SetExchangeSupport();
733     aAutoTextLB.SetSelectHdl(LINK(this, SwVisitingCardPage, AutoTextSelectHdl));
734     aAutoTextGroupLB.SetSelectHdl(LINK(this, SwVisitingCardPage, AutoTextSelectHdl));
735 
736     aExampleWIN.Hide();
737 
738     aAutoTextLB.Show();
739     aAutoTextGroupFT.Show();
740     aAutoTextGroupLB.Show();
741     InitFrameControl();
742 }
743 /*-- 08.07.99 14:00:03---------------------------------------------------
744 
745   -----------------------------------------------------------------------*/
746 SwVisitingCardPage::~SwVisitingCardPage()
747 {
748     for(sal_uInt16 i = 0; i < aAutoTextGroupLB.GetEntryCount(); i++)
749         delete (String*)aAutoTextGroupLB.GetEntryData( i );
750     _xAutoText = 0;
751 
752     ClearUserData();
753     delete pExampleFrame;
754 }
755 /*-- 08.07.99 14:00:03---------------------------------------------------
756 
757   -----------------------------------------------------------------------*/
758 SfxTabPage* SwVisitingCardPage::Create(Window* pParent, const SfxItemSet& rSet)
759 {
760     return new SwVisitingCardPage(pParent, rSet);
761 }
762 /*-- 08.07.99 14:00:03---------------------------------------------------
763 
764   -----------------------------------------------------------------------*/
765 void SwVisitingCardPage::ActivatePage(const SfxItemSet& rSet)
766 {
767     Reset( rSet );
768     UpdateFields();
769 }
770 /*-- 08.07.99 14:00:04---------------------------------------------------
771 
772   -----------------------------------------------------------------------*/
773 int  SwVisitingCardPage::DeactivatePage(SfxItemSet* _pSet)
774 {
775     if (_pSet)
776         FillItemSet(*_pSet);
777     return LEAVE_PAGE;
778 }
779 /*-- 08.07.99 14:00:04---------------------------------------------------
780 
781   -----------------------------------------------------------------------*/
782 sal_Bool SwVisitingCardPage::FillItemSet(SfxItemSet& rSet)
783 {
784     String* pGroup = (String*)aAutoTextGroupLB.GetEntryData(
785                                     aAutoTextGroupLB.GetSelectEntryPos());
786     DBG_ASSERT(pGroup, "no group selected?");
787     if(pGroup)
788         aLabItem.sGlossaryGroup = *pGroup;
789 
790     SvLBoxEntry* pSelEntry = aAutoTextLB.FirstSelected();
791     if(pSelEntry)
792         aLabItem.sGlossaryBlockName = *(String*)pSelEntry->GetUserData();
793     rSet.Put(aLabItem);
794     return sal_True;
795 }
796 /*-- 08.07.99 14:00:05---------------------------------------------------
797 
798   -----------------------------------------------------------------------*/
799 void lcl_SelectBlock(SvTreeListBox& rAutoTextLB, const String& rBlockName)
800 {
801     SvLBoxEntry* pEntry = rAutoTextLB.First();
802     while(pEntry)
803     {
804         if(*(String*)pEntry->GetUserData() == rBlockName)
805         {
806             rAutoTextLB.Select(pEntry);
807             rAutoTextLB.MakeVisible(pEntry);
808             break;
809         }
810         pEntry = rAutoTextLB.Next(pEntry);
811     }
812 }
813 //-----------------------------------------------------------------------------
814 sal_Bool lcl_FindBlock(SvTreeListBox& rAutoTextLB, const String& rBlockName)
815 {
816     SvLBoxEntry* pEntry = rAutoTextLB.First();
817     while(pEntry)
818     {
819         if(*(String*)pEntry->GetUserData() == rBlockName)
820         {
821             rAutoTextLB.Select(pEntry);
822             return sal_True;
823         }
824         pEntry = rAutoTextLB.Next(pEntry);
825     }
826     return sal_False;
827 }
828 
829 //-----------------------------------------------------------------------------
830 void SwVisitingCardPage::Reset(const SfxItemSet& rSet)
831 {
832     aLabItem = (const SwLabItem&) rSet.Get(FN_LABEL);
833 
834     sal_Bool bFound = sal_False;
835     sal_uInt16 i;
836     for(i = 0; i < aAutoTextGroupLB.GetEntryCount() && !bFound; i++)
837         if( String(aLabItem.sGlossaryGroup) ==
838             *(String*)aAutoTextGroupLB.GetEntryData( i ))
839         {
840             bFound = sal_True;
841             break;
842         }
843 
844     if(!bFound)
845     {
846         // initially search for a group starting with "crd" which is the name of the
847         // business card AutoTexts
848         for(i = 0; i < aAutoTextGroupLB.GetEntryCount() && !bFound; i++)
849             if(0 == (*(String*)aAutoTextGroupLB.GetEntryData( i )).SearchAscii( "crd") )
850             {
851                 bFound = sal_True;
852                 break;
853             }
854     }
855     if(bFound)
856     {
857         if(aAutoTextGroupLB.GetSelectEntryPos() != i)
858         {
859             aAutoTextGroupLB.SelectEntryPos(i);
860             AutoTextSelectHdl(&aAutoTextGroupLB);
861         }
862         if(lcl_FindBlock(aAutoTextLB, aLabItem.sGlossaryBlockName))
863         {
864             SvLBoxEntry* pSelEntry = aAutoTextLB.FirstSelected();
865             if( pSelEntry &&
866                 *(String*)pSelEntry->GetUserData() != String(aLabItem.sGlossaryBlockName))
867             {
868                 lcl_SelectBlock(aAutoTextLB, aLabItem.sGlossaryBlockName);
869                 AutoTextSelectHdl(&aAutoTextLB);
870             }
871         }
872     }
873 }
874 
875 /* -----------------29.09.99 08:55-------------------
876 
877  --------------------------------------------------*/
878 SwPrivateDataPage::SwPrivateDataPage(Window* pParent, const SfxItemSet& rSet) :
879     SfxTabPage(pParent, SW_RES(TP_PRIVATE_DATA), rSet),
880     aDataFL             (this, SW_RES( FL_DATA       )),
881 
882     aNameFT             (this, SW_RES( FT_NAME       )),
883     aFirstNameED        (this, SW_RES( ED_FIRSTNAME )),
884     aNameED             (this, SW_RES( ED_NAME      )),
885     aShortCutED         (this, SW_RES( ED_SHORTCUT  )),
886 
887     aName2FT            (this, SW_RES( FT_NAME_2     )),
888     aFirstName2ED       (this, SW_RES( ED_FIRSTNAME_2)),
889     aName2ED            (this, SW_RES( ED_NAME_2        )),
890     aShortCut2ED        (this, SW_RES( ED_SHORTCUT_2    )),
891 
892     aStreetFT           (this, SW_RES( FT_STREET     )),
893     aStreetED           (this, SW_RES( ED_STREET        )),
894     aZipCityFT          (this, SW_RES( FT_ZIPCITY   )),
895     aZipED              (this, SW_RES( ED_ZIP       )),
896     aCityED             (this, SW_RES( ED_CITY      )),
897     aCountryStateFT     (this, SW_RES( FT_COUNTRYSTATE )),
898     aCountryED          (this, SW_RES( ED_COUNTRY   )),
899     aStateED            (this, SW_RES( ED_STATE     )),
900     aTitleProfessionFT  (this, SW_RES( FT_TITLEPROF )),
901     aTitleED            (this, SW_RES( ED_TITLE     )),
902     aProfessionED       (this, SW_RES( ED_PROFESSION )),
903     aPhoneFT            (this, SW_RES( FT_PHONE_MOBILE  )),
904     aPhoneED            (this, SW_RES( ED_PHONE     )),
905     aMobilePhoneED      (this, SW_RES( ED_MOBILE        )),
906     aFaxFT              (this, SW_RES( FT_FAX       )),
907     aFaxED              (this, SW_RES( ED_FAX       )),
908     aWWWMailFT          (this, SW_RES( FT_WWWMAIL   )),
909     aHomePageED         (this, SW_RES( ED_WWW       )),
910     aMailED             (this, SW_RES( ED_MAIL      ))
911 {
912     FreeResource();
913     SetExchangeSupport();
914 }
915 
916 /*-- 29.09.99 08:55:57---------------------------------------------------
917 
918   -----------------------------------------------------------------------*/
919 SwPrivateDataPage::~SwPrivateDataPage()
920 {
921 }
922 /*-- 29.09.99 08:55:57---------------------------------------------------
923 
924   -----------------------------------------------------------------------*/
925 SfxTabPage* SwPrivateDataPage::Create(Window* pParent, const SfxItemSet& rSet)
926 {
927     return new SwPrivateDataPage(pParent, rSet);
928 }
929 /*-- 29.09.99 08:55:57---------------------------------------------------
930 
931   -----------------------------------------------------------------------*/
932 void SwPrivateDataPage::ActivatePage(const SfxItemSet& rSet)
933 {
934     Reset(rSet);
935 }
936 /*-- 29.09.99 08:55:58---------------------------------------------------
937 
938   -----------------------------------------------------------------------*/
939 int  SwPrivateDataPage::DeactivatePage(SfxItemSet* _pSet)
940 {
941     if (_pSet)
942         FillItemSet(*_pSet);
943     return LEAVE_PAGE;
944 }
945 /*-- 29.09.99 08:55:58---------------------------------------------------
946 
947   -----------------------------------------------------------------------*/
948 sal_Bool SwPrivateDataPage::FillItemSet(SfxItemSet& rSet)
949 {
950 
951     SwLabItem aItem = (const SwLabItem&) GetTabDialog()->GetExampleSet()->Get(FN_LABEL);
952     aItem.aPrivFirstName = aFirstNameED .GetText();
953     aItem.aPrivName      = aNameED      .GetText(  );
954     aItem.aPrivShortCut  = aShortCutED  .GetText(  );
955     aItem.aPrivFirstName2 = aFirstName2ED   .GetText();
956     aItem.aPrivName2     = aName2ED     .GetText(  );
957     aItem.aPrivShortCut2 = aShortCut2ED .GetText(  );
958     aItem.aPrivStreet    = aStreetED    .GetText(  );
959     aItem.aPrivZip       = aZipED       .GetText(  );
960     aItem.aPrivCity      = aCityED      .GetText(  );
961     aItem.aPrivCountry   = aCountryED   .GetText(  );
962     aItem.aPrivState     = aStateED     .GetText(  );
963     aItem.aPrivTitle     = aTitleED     .GetText(  );
964     aItem.aPrivProfession= aProfessionED.GetText(   );
965     aItem.aPrivPhone     = aPhoneED     .GetText(  );
966     aItem.aPrivMobile    = aMobilePhoneED.GetText(  );
967     aItem.aPrivFax       = aFaxED       .GetText(  );
968     aItem.aPrivWWW       = aHomePageED  .GetText(  );
969     aItem.aPrivMail      = aMailED      .GetText(  );
970 
971     rSet.Put(aItem);
972     return sal_True;
973 }
974 /*-- 29.09.99 08:55:59---------------------------------------------------
975 
976   -----------------------------------------------------------------------*/
977 void SwPrivateDataPage::Reset(const SfxItemSet& rSet)
978 {
979     const SwLabItem& aItem = (const SwLabItem&) rSet.Get(FN_LABEL);
980     aFirstNameED.SetText(aItem.aPrivFirstName);
981     aNameED     .SetText(aItem.aPrivName);
982     aShortCutED .SetText(aItem.aPrivShortCut);
983     aFirstName2ED.SetText(aItem.aPrivFirstName2);
984     aName2ED     .SetText(aItem.aPrivName2);
985     aShortCut2ED .SetText(aItem.aPrivShortCut2);
986     aStreetED   .SetText(aItem.aPrivStreet);
987     aZipED      .SetText(aItem.aPrivZip);
988     aCityED     .SetText(aItem.aPrivCity);
989     aCountryED  .SetText(aItem.aPrivCountry);
990     aStateED    .SetText(aItem.aPrivState);
991     aTitleED    .SetText(aItem.aPrivTitle);
992     aProfessionED.SetText(aItem.aPrivProfession);
993     aPhoneED    .SetText(aItem.aPrivPhone);
994     aMobilePhoneED.SetText(aItem.aPrivMobile);
995     aFaxED      .SetText(aItem.aPrivFax);
996     aHomePageED .SetText(aItem.aPrivWWW);
997     aMailED     .SetText(aItem.aPrivMail);
998 }
999 /* -----------------29.09.99 08:56-------------------
1000 
1001  --------------------------------------------------*/
1002 SwBusinessDataPage::SwBusinessDataPage(Window* pParent, const SfxItemSet& rSet) :
1003     SfxTabPage(pParent, SW_RES(TP_BUSINESS_DATA), rSet),
1004     aDataFL             (this, SW_RES( FL_DATA       )),
1005     aCompanyFT          (this, SW_RES( FT_COMP      )),
1006     aCompanyED          (this, SW_RES( ED_COMP      )),
1007     aCompanyExtFT       (this, SW_RES( FT_COMP_EXT  )),
1008     aCompanyExtED       (this, SW_RES( ED_COMP_EXT  )),
1009     aSloganFT           (this, SW_RES( FT_SLOGAN        )),
1010     aSloganED           (this, SW_RES( ED_SLOGAN        )),
1011     aStreetFT           (this, SW_RES( FT_STREET        )),
1012     aStreetED           (this, SW_RES( ED_STREET        )),
1013     aZipCityFT          (this, SW_RES( FT_ZIPCITY   )),
1014     aZipED              (this, SW_RES( ED_ZIP       )),
1015     aCityED             (this, SW_RES( ED_CITY      )),
1016     aCountryStateFT     (this, SW_RES( FT_COUNTRYSTATE  )),
1017     aCountryED          (this, SW_RES( ED_COUNTRY   )),
1018     aStateED            (this, SW_RES( ED_STATE     )),
1019     aPositionFT         (this, SW_RES( FT_POSITION  )),
1020     aPositionED         (this, SW_RES( ED_POSITION  )),
1021     aPhoneFT            (this, SW_RES( FT_PHONE_MOBILE  )),
1022     aPhoneED            (this, SW_RES( ED_PHONE     )),
1023     aMobilePhoneED      (this, SW_RES( ED_MOBILE        )),
1024     aFaxFT              (this, SW_RES( FT_FAX       )),
1025     aFaxED              (this, SW_RES( ED_FAX       )),
1026     aWWWMailFT          (this, SW_RES( FT_WWWMAIL   )),
1027     aHomePageED         (this, SW_RES( ED_WWW       )),
1028     aMailED             (this, SW_RES( ED_MAIL      ))
1029 {
1030     FreeResource();
1031     SetExchangeSupport();
1032 }
1033 
1034 /*-- 29.09.99 08:56:06---------------------------------------------------
1035 
1036   -----------------------------------------------------------------------*/
1037 SwBusinessDataPage::~SwBusinessDataPage()
1038 {
1039 }
1040 /*-- 29.09.99 08:56:06---------------------------------------------------
1041 
1042   -----------------------------------------------------------------------*/
1043 SfxTabPage* SwBusinessDataPage::Create(Window* pParent, const SfxItemSet& rSet)
1044 {
1045     return new SwBusinessDataPage(pParent, rSet);
1046 }
1047 /*-- 29.09.99 08:56:06---------------------------------------------------
1048 
1049   -----------------------------------------------------------------------*/
1050 void SwBusinessDataPage::ActivatePage(const SfxItemSet& rSet)
1051 {
1052     Reset(rSet);
1053 }
1054 /*-- 29.09.99 08:56:06---------------------------------------------------
1055 
1056   -----------------------------------------------------------------------*/
1057 int  SwBusinessDataPage::DeactivatePage(SfxItemSet* _pSet)
1058 {
1059     if (_pSet)
1060         FillItemSet(*_pSet);
1061     return LEAVE_PAGE;
1062 }
1063 /*-- 29.09.99 08:56:06---------------------------------------------------
1064 
1065   -----------------------------------------------------------------------*/
1066 sal_Bool SwBusinessDataPage::FillItemSet(SfxItemSet& rSet)
1067 {
1068     SwLabItem aItem = (const SwLabItem&) GetTabDialog()->GetExampleSet()->Get(FN_LABEL);
1069 
1070     aItem.aCompCompany   = aCompanyED      .GetText();
1071     aItem.aCompCompanyExt= aCompanyExtED   .GetText();
1072     aItem.aCompSlogan    = aSloganED       .GetText();
1073     aItem.aCompStreet    = aStreetED       .GetText();
1074     aItem.aCompZip       = aZipED          .GetText();
1075     aItem.aCompCity      = aCityED         .GetText();
1076     aItem.aCompCountry   = aCountryED      .GetText();
1077     aItem.aCompState     = aStateED        .GetText();
1078     aItem.aCompPosition  = aPositionED     .GetText();
1079     aItem.aCompPhone     = aPhoneED        .GetText();
1080     aItem.aCompMobile    = aMobilePhoneED  .GetText();
1081     aItem.aCompFax       = aFaxED          .GetText();
1082     aItem.aCompWWW       = aHomePageED     .GetText();
1083     aItem.aCompMail      = aMailED         .GetText();
1084 
1085     rSet.Put(aItem);
1086     return sal_True;
1087 }
1088 /*-- 29.09.99 08:56:07---------------------------------------------------
1089 
1090   -----------------------------------------------------------------------*/
1091 void SwBusinessDataPage::Reset(const SfxItemSet& rSet)
1092 {
1093     const SwLabItem& aItem = (const SwLabItem&) rSet.Get(FN_LABEL);
1094     aCompanyED      .SetText(aItem.aCompCompany);
1095     aCompanyExtED   .SetText(aItem.aCompCompanyExt);
1096     aSloganED       .SetText(aItem.aCompSlogan);
1097     aStreetED       .SetText(aItem.aCompStreet);
1098     aZipED          .SetText(aItem.aCompZip);
1099     aCityED         .SetText(aItem.aCompCity);
1100     aCountryED      .SetText(aItem.aCompCountry);
1101     aStateED        .SetText(aItem.aCompState);
1102     aPositionED     .SetText(aItem.aCompPosition);
1103     aPhoneED        .SetText(aItem.aCompPhone);
1104     aMobilePhoneED  .SetText(aItem.aCompMobile);
1105     aFaxED          .SetText(aItem.aCompFax);
1106     aHomePageED     .SetText(aItem.aCompWWW);
1107     aMailED         .SetText(aItem.aCompMail);
1108 }
1109 
1110 
1111 
1112