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 #include <mmaddressblockpage.hxx>
30 #include <mailmergewizard.hxx>
31 #include <swtypes.hxx>
32 #include <addresslistdialog.hxx>
33 #include <svtools/xtextedt.hxx>
34 #include <svtools/txtattr.hxx>
35 #include <vcl/msgbox.hxx>
36 #include <mmconfigitem.hxx>
37 #include <com/sun/star/container/XNameAccess.hpp>
38 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
39 #include <com/sun/star/sdb/XColumn.hpp>
40 
41 #include <vector>
42 #include <mmaddressblockpage.hrc>
43 #include <dbui.hrc>
44 #include <helpid.h>
45 
46 using namespace svt;
47 using namespace ::com::sun::star;
48 using namespace ::com::sun::star::container;
49 using namespace ::com::sun::star::sdb;
50 using namespace ::com::sun::star::sdbc;
51 using namespace ::com::sun::star::sdbcx;
52 
53 //-------------------------------------------------------------------------
lcl_Move(Control * pCtrl,long nYOffset)54 void lcl_Move(Control* pCtrl, long nYOffset)
55 {
56     Point aPos(pCtrl->GetPosPixel());
57     aPos.Y() += nYOffset;
58     pCtrl->SetPosPixel(aPos);
59 }
60 /*-- 02.04.2004 12:46:40---------------------------------------------------
61 
62   -----------------------------------------------------------------------*/
SwMailMergeAddressBlockPage(SwMailMergeWizard * _pParent)63 SwMailMergeAddressBlockPage::SwMailMergeAddressBlockPage( SwMailMergeWizard* _pParent) :
64     svt::OWizardPage(_pParent, SW_RES(DLG_MM_ADDRESSBLOCK_PAGE)),
65 #ifdef MSC
66 #pragma warning (disable : 4355)
67 #endif
68     m_aHeaderFI(        this, SW_RES(  FI_HEADER           ) ),
69     m_aFirstFI(         this, SW_RES( FI_FIRST ) ),
70     m_aAddressListFI(   this, SW_RES( FI_ADDRESSLIST ) ),
71     m_aAddressListPB(   this, SW_RES( PB_ADDRESSLIST ) ),
72     m_aCurrentAddressFI( this, SW_RES( FI_CURRENTADDRESS ) ),
73     m_aFirstFL(         this, SW_RES( FL_FIRST ) ),
74     m_aSecondFI(        this, SW_RES( FI_SECOND )),
75     m_aSettingsFI(      this, SW_RES( FI_SECOND    ) ),
76     m_aAddressCB(       this, SW_RES( CB_ADDRESS   ) ),
77     m_aSettingsWIN(     this, SW_RES( WIN_SETTINGS   ) ),
78     m_aSettingsPB(      this, SW_RES( PB_SETTINGS    ) ),
79     m_aHideEmptyParagraphsCB( this, SW_RES( CB_HIDE_EMPTY_PARA ) ),
80     m_aSecondFL(        this, SW_RES( FL_SECOND )),
81     m_aThirdFI(         this, SW_RES( FI_THIRD ) ),
82     m_aMatchFieldsFI(   this, SW_RES( FI_MATCH_FIELDS ) ),
83     m_aAssignPB(        this, SW_RES( PB_ASSIGN      ) ),
84     m_aThirdFL(         this, SW_RES( FL_THIRD ) ),
85     m_aFourthFI(        this, SW_RES( FI_FOURTH ) ),
86     m_aPreviewFI(       this, SW_RES( FI_PREVIEW     ) ),
87     m_aPreviewWIN(      this, SW_RES( WIN_PREVIEW    ) ),
88     m_aDocumentIndexFI( this, SW_RES( FI_DOCINDEX    ) ),
89     m_aPrevSetIB(       this, SW_RES( IB_PREVSET     ) ),
90     m_aNextSetIB(       this, SW_RES( IB_NEXTSET     ) ),
91 #ifdef MSC
92 #pragma warning (default : 4355)
93 #endif
94     m_sDocument(        SW_RES(       STR_DOCUMENT  ) ),
95     m_sChangeAddress(   SW_RES(      STR_CHANGEADDRESS )),
96     m_pWizard(_pParent)
97 {
98     FreeResource();
99     m_sCurrentAddress = m_aCurrentAddressFI.GetText();
100     m_aAddressListPB.SetClickHdl(LINK(this, SwMailMergeAddressBlockPage, AddressListHdl_Impl));
101     m_aSettingsPB.SetClickHdl(LINK(this, SwMailMergeAddressBlockPage, SettingsHdl_Impl));
102     m_aAssignPB.SetClickHdl(LINK(this, SwMailMergeAddressBlockPage, AssignHdl_Impl ));
103     m_aAddressCB.SetClickHdl(LINK(this, SwMailMergeAddressBlockPage, AddressBlockHdl_Impl));
104     m_aSettingsWIN.SetSelectHdl(LINK(this, SwMailMergeAddressBlockPage, AddressBlockSelectHdl_Impl));
105     m_aHideEmptyParagraphsCB.SetClickHdl(LINK(this, SwMailMergeAddressBlockPage, HideParagraphsHdl_Impl));
106 
107     Link aLink = LINK(this, SwMailMergeAddressBlockPage, InsertDataHdl_Impl);
108     m_aPrevSetIB.SetClickHdl(aLink);
109     m_aNextSetIB.SetClickHdl(aLink);
110 }
111 /*-- 02.04.2004 12:46:40---------------------------------------------------
112 
113   -----------------------------------------------------------------------*/
~SwMailMergeAddressBlockPage()114 SwMailMergeAddressBlockPage::~SwMailMergeAddressBlockPage()
115 {
116 }
117 /*-- 05.07.2004 13:55:15---------------------------------------------------
118 
119   -----------------------------------------------------------------------*/
canAdvance() const120 bool SwMailMergeAddressBlockPage::canAdvance() const
121 {
122     return m_pWizard->GetConfigItem().GetResultSet().is();
123 }
124 /*-- 16.06.2004 12:34:09---------------------------------------------------
125 
126   -----------------------------------------------------------------------*/
ActivatePage()127 void SwMailMergeAddressBlockPage::ActivatePage()
128 {
129     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
130     bool bIsLetter = rConfigItem.IsOutputToLetter();
131 
132     //no address block is created for e-Mail
133     m_aSettingsFI.Show( bIsLetter );
134     m_aAddressCB.Show( bIsLetter );
135     m_aSettingsWIN.Show( bIsLetter );
136     m_aSettingsPB.Show( bIsLetter );
137     m_aPreviewFI.Show( bIsLetter );
138     m_aPreviewWIN.Show( bIsLetter );
139     m_aAssignPB.Show( bIsLetter );
140     m_aDocumentIndexFI.Show( bIsLetter );
141     m_aPrevSetIB.Show( bIsLetter );
142     m_aNextSetIB.Show( bIsLetter );
143     m_aHideEmptyParagraphsCB.Show( bIsLetter );
144     m_aSecondFL.Show( bIsLetter );
145     m_aSecondFI.Show( bIsLetter );
146     m_aSettingsFI.Show( bIsLetter );
147     m_aMatchFieldsFI.Show( bIsLetter );
148     m_aThirdFI.Show( bIsLetter );
149     m_aThirdFL.Show( bIsLetter );
150     m_aFourthFI.Show( bIsLetter );
151 
152     if(bIsLetter)
153     {
154         m_aHideEmptyParagraphsCB.Check( rConfigItem.IsHideEmptyParagraphs() );
155         String sTemp(m_sDocument);
156         sTemp.SearchAndReplaceAscii("%1", String::CreateFromInt32(1));
157         m_aDocumentIndexFI.SetText(sTemp);
158 
159         m_aSettingsWIN.Clear();
160         const uno::Sequence< ::rtl::OUString> aBlocks =
161                     m_pWizard->GetConfigItem().GetAddressBlocks();
162         for(sal_Int32 nAddress = 0; nAddress < aBlocks.getLength(); ++nAddress)
163             m_aSettingsWIN.AddAddress(aBlocks[nAddress]);
164         m_aSettingsWIN.SelectAddress((sal_uInt16)rConfigItem.GetCurrentAddressBlockIndex());
165         m_aAddressCB.Check(rConfigItem.IsAddressBlock());
166         AddressBlockHdl_Impl(&m_aAddressCB);
167         m_aSettingsWIN.SetLayout(1, 2);
168         InsertDataHdl_Impl(0);
169     }
170 }
171 /*-- 27.05.2004 13:59:15---------------------------------------------------
172 
173   -----------------------------------------------------------------------*/
commitPage(::svt::WizardTypes::CommitPageReason _eReason)174 sal_Bool    SwMailMergeAddressBlockPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
175 {
176     if ( ::svt::WizardTypes::eTravelForward == _eReason && !m_pWizard->GetConfigItem().GetResultSet().is() )
177         return sal_False;
178     return sal_True;
179 }
180 /*-- 07.04.2004 16:19:30---------------------------------------------------
181 
182   -----------------------------------------------------------------------*/
IMPL_LINK(SwMailMergeAddressBlockPage,AddressListHdl_Impl,PushButton *,EMPTYARG)183 IMPL_LINK(SwMailMergeAddressBlockPage, AddressListHdl_Impl, PushButton*, EMPTYARG)
184 {
185     SwAddressListDialog* pAddrDialog = new SwAddressListDialog(this);
186     if(RET_OK == pAddrDialog->Execute())
187     {
188         SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
189         rConfigItem.SetCurrentConnection(
190                         pAddrDialog->GetSource(),
191                         pAddrDialog->GetConnection(),
192                         pAddrDialog->GetColumnsSupplier(),
193                         pAddrDialog->GetDBData());
194         ::rtl::OUString sFilter = pAddrDialog->GetFilter();
195         rConfigItem.SetFilter( sFilter );
196         InsertDataHdl_Impl(0);
197         GetWizard()->UpdateRoadmap();
198         GetWizard()->enableButtons(WZB_NEXT, GetWizard()->isStateEnabled(MM_GREETINGSPAGE));
199     }
200     delete pAddrDialog;
201     return 0;
202 }
203 /*-- 07.04.2004 16:19:30---------------------------------------------------
204 
205   -----------------------------------------------------------------------*/
IMPL_LINK(SwMailMergeAddressBlockPage,SettingsHdl_Impl,PushButton *,pButton)206 IMPL_LINK(SwMailMergeAddressBlockPage, SettingsHdl_Impl, PushButton*, pButton)
207 {
208     SwSelectAddressBlockDialog* pDlg =
209                 new SwSelectAddressBlockDialog(pButton, m_pWizard->GetConfigItem());
210     SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
211     pDlg->SetAddressBlocks(rConfig.GetAddressBlocks(), m_aSettingsWIN.GetSelectedAddress());
212     pDlg->SetSettings(rConfig.IsIncludeCountry(), rConfig.GetExcludeCountry());
213     if(RET_OK == pDlg->Execute())
214     {
215         //the dialog provides the selected address at the first position!
216         const uno::Sequence< ::rtl::OUString> aBlocks =
217                     pDlg->GetAddressBlocks();
218         rConfig.SetAddressBlocks(aBlocks);
219         m_aSettingsWIN.Clear();
220         for(sal_Int32 nAddress = 0; nAddress < aBlocks.getLength(); ++nAddress)
221             m_aSettingsWIN.AddAddress(aBlocks[nAddress]);
222         m_aSettingsWIN.SelectAddress(0);
223         m_aSettingsWIN.Invalidate();	// #i40408
224         rConfig.SetCountrySettings(pDlg->IsIncludeCountry(), pDlg->GetCountry());
225         InsertDataHdl_Impl(0);
226     }
227     delete pDlg;
228     GetWizard()->UpdateRoadmap();
229     GetWizard()->enableButtons(WZB_NEXT, GetWizard()->isStateEnabled(MM_GREETINGSPAGE));
230     return 0;
231 }
232 /*-- 07.04.2004 16:19:31---------------------------------------------------
233 
234   -----------------------------------------------------------------------*/
IMPL_LINK(SwMailMergeAddressBlockPage,AssignHdl_Impl,PushButton *,pButton)235 IMPL_LINK(SwMailMergeAddressBlockPage, AssignHdl_Impl, PushButton*, pButton)
236 {
237     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
238     sal_uInt16 nSel = m_aSettingsWIN.GetSelectedAddress();
239     const uno::Sequence< ::rtl::OUString> aBlocks = rConfigItem.GetAddressBlocks();
240     SwAssignFieldsDialog* pDlg =
241             new SwAssignFieldsDialog(pButton, m_pWizard->GetConfigItem(), aBlocks[nSel], true);
242     if(RET_OK == pDlg->Execute())
243     {
244         //preview update
245         InsertDataHdl_Impl(0);
246         GetWizard()->UpdateRoadmap();
247         GetWizard()->enableButtons(WZB_NEXT, GetWizard()->isStateEnabled(MM_GREETINGSPAGE));
248     }
249     delete pDlg;
250     return 0;
251 }
252 /*-- 11.06.2004 13:37:22---------------------------------------------------
253 
254   -----------------------------------------------------------------------*/
EnableAddressBlock(sal_Bool bAll,sal_Bool bSelective)255 void SwMailMergeAddressBlockPage::EnableAddressBlock(sal_Bool bAll, sal_Bool bSelective)
256 {
257     m_aSettingsFI.Enable(bAll);
258     m_aAddressCB.Enable(bAll);
259     bSelective &= bAll;
260     m_aHideEmptyParagraphsCB.Enable(bSelective);
261     m_aSettingsWIN.Enable(bSelective);
262     m_aSettingsPB.Enable(bSelective);
263     m_aPreviewFI.Enable(bSelective);
264     m_aPreviewWIN.Enable(bSelective);
265     m_aThirdFI.Enable(bSelective);
266     m_aMatchFieldsFI.Enable(bSelective);
267     m_aAssignPB.Enable(bSelective);
268     m_aDocumentIndexFI.Enable(bSelective);
269     m_aPrevSetIB.Enable(bSelective);
270     m_aNextSetIB.Enable(bSelective);
271 }
272 /*-- 28.04.2004 12:45:58---------------------------------------------------
273 
274   -----------------------------------------------------------------------*/
IMPL_LINK(SwMailMergeAddressBlockPage,AddressBlockHdl_Impl,CheckBox *,pBox)275 IMPL_LINK(SwMailMergeAddressBlockPage, AddressBlockHdl_Impl, CheckBox*, pBox)
276 {
277     EnableAddressBlock(pBox->IsEnabled(), pBox->IsChecked());
278     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
279     rConfigItem.SetAddressBlock(m_aAddressCB.IsChecked());
280     m_pWizard->UpdateRoadmap();
281     return 0;
282 }
283 /*-- 08.06.2004 13:00:29---------------------------------------------------
284 
285   -----------------------------------------------------------------------*/
IMPL_LINK(SwMailMergeAddressBlockPage,AddressBlockSelectHdl_Impl,SwAddressPreview *,EMPTYARG)286 IMPL_LINK(SwMailMergeAddressBlockPage, AddressBlockSelectHdl_Impl, SwAddressPreview*, EMPTYARG)
287 {
288     sal_uInt16 nSel = m_aSettingsWIN.GetSelectedAddress();
289     const uno::Sequence< ::rtl::OUString> aBlocks =
290                 m_pWizard->GetConfigItem().GetAddressBlocks();
291     String sPreview = SwAddressPreview::FillData(aBlocks[nSel], m_pWizard->GetConfigItem());
292     m_aPreviewWIN.SetAddress(sPreview);
293     m_pWizard->GetConfigItem().SetCurrentAddressBlockIndex( nSel );
294     GetWizard()->UpdateRoadmap();
295     GetWizard()->enableButtons(WZB_NEXT, GetWizard()->isStateEnabled(MM_GREETINGSPAGE));
296     return 0;
297 }
298 /*-- 31.08.2005 15:34:55---------------------------------------------------
299 
300   -----------------------------------------------------------------------*/
IMPL_LINK(SwMailMergeAddressBlockPage,HideParagraphsHdl_Impl,CheckBox *,pBox)301 IMPL_LINK(SwMailMergeAddressBlockPage, HideParagraphsHdl_Impl, CheckBox*, pBox)
302 {
303     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
304     rConfigItem.SetHideEmptyParagraphs( pBox->IsChecked() );
305     return 0;
306 }
307 
308 // ------------------------------------------------------------------------------
IMPL_LINK(SwMailMergeAddressBlockPage,InsertDataHdl_Impl,ImageButton *,pButton)309 IMPL_LINK(SwMailMergeAddressBlockPage, InsertDataHdl_Impl, ImageButton*, pButton)
310 {
311     //if no pButton is given, the first set has to be pre-set
312     SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
313     m_pWizard->EnterWait();
314     if(!pButton)
315     {
316         rConfig.GetResultSet();
317     }
318     else
319     {
320         sal_Bool bNext = pButton == &m_aNextSetIB;
321         sal_Int32 nPos = rConfig.GetResultSetPosition();
322         rConfig.MoveResultSet( bNext ? ++nPos : --nPos);
323     }
324     m_pWizard->LeaveWait();
325     sal_Int32 nPos = rConfig.GetResultSetPosition();
326     sal_Bool bEnable = sal_True;
327     if(nPos < 1)
328     {
329         bEnable = sal_False;
330         nPos = 1;
331     }
332     else
333     {
334         //if output type is letter
335         if(m_aSettingsWIN.IsVisible())
336         {
337             //Fill data into preview
338             sal_uInt16 nSel = m_aSettingsWIN.GetSelectedAddress();
339             const uno::Sequence< ::rtl::OUString> aBlocks =
340                         m_pWizard->GetConfigItem().GetAddressBlocks();
341             String sPreview = SwAddressPreview::FillData(aBlocks[nSel], rConfig);
342             m_aPreviewWIN.SetAddress(sPreview);
343         }
344     }
345     m_aPrevSetIB.Enable(bEnable);
346     //m_aNextSetIB.Enable(bEnable);
347     //m_aDocumentIndexFI.Enable(bEnable);
348     String sTemp(m_sDocument);
349     sTemp.SearchAndReplaceAscii("%1", String::CreateFromInt32(nPos));
350     m_aDocumentIndexFI.SetText(sTemp);
351 
352     GetWizard()->enableButtons(WZB_NEXT, GetWizard()->isStateEnabled(MM_GREETINGSPAGE));
353     sal_Bool bHasResultSet = rConfig.GetResultSet().is();
354     m_aCurrentAddressFI.Show(bHasResultSet);
355     if(bHasResultSet)
356     {
357         String sTmp = m_sCurrentAddress;
358         sTmp.SearchAndReplaceAscii("%1", rConfig.GetCurrentDBData().sDataSource );
359         m_aCurrentAddressFI.SetText(sTmp);
360         m_aAddressListPB.SetText(m_sChangeAddress);
361     }
362     EnableAddressBlock(bHasResultSet, m_aAddressCB.IsChecked());
363     return 0;
364 }
365 /*-- 13.04.2004 16:01:26---------------------------------------------------
366 
367   -----------------------------------------------------------------------*/
SwSelectAddressBlockDialog(Window * pParent,SwMailMergeConfigItem & rConfig)368 SwSelectAddressBlockDialog::SwSelectAddressBlockDialog(
369                 Window* pParent, SwMailMergeConfigItem& rConfig) :
370     SfxModalDialog(pParent, SW_RES(DLG_MM_SELECTADDRESSBLOCK)),
371 #ifdef MSC
372 #pragma warning (disable : 4355)
373 #endif
374     m_aSelectFT( this, SW_RES(         FT_SELECT)),
375     m_aPreview( this, SW_RES(          WIN_PREVIEW)),
376     m_aNewPB( this, SW_RES(            PB_NEW)),
377     m_aCustomizePB( this, SW_RES(      PB_CUSTOMIZE)),
378     m_aDeletePB( this, SW_RES(         PB_DELETE)),
379     m_aSettingsFI( this, SW_RES(       FI_SETTINGS)),
380     m_aNeverRB( this, SW_RES(          RB_NEVER)),
381     m_aAlwaysRB( this, SW_RES(         RB_ALWAYS)),
382     m_aDependentRB( this, SW_RES(      RB_DEPENDENT)),
383     m_aCountryED( this, SW_RES(        ED_COUNTRY)),
384     m_aSeparatorFL( this, SW_RES(      FL_SEPARATOR)),
385     m_aOK( this, SW_RES(               PB_OK)),
386     m_aCancel( this, SW_RES(           PB_CANCEL)),
387     m_aHelp( this, SW_RES(             PB_HELP)),
388 #ifdef MSC
389 #pragma warning (default : 4355)
390 #endif
391     m_rConfig(rConfig)
392 {
393     FreeResource();
394 
395     Link aCustomizeHdl = LINK(this, SwSelectAddressBlockDialog, NewCustomizeHdl_Impl);
396     m_aNewPB.SetClickHdl(aCustomizeHdl);
397     m_aCustomizePB.SetClickHdl(aCustomizeHdl);
398 
399     m_aDeletePB.SetClickHdl(LINK(this, SwSelectAddressBlockDialog, DeleteHdl_Impl));
400 
401     Link aLk = LINK(this, SwSelectAddressBlockDialog, IncludeHdl_Impl);
402     m_aNeverRB.SetClickHdl(aLk);
403     m_aAlwaysRB.SetClickHdl(aLk);
404     m_aDependentRB.SetClickHdl(aLk);
405     m_aPreview.SetLayout(2, 2);
406     m_aPreview.EnableScrollBar();
407 }
408 /*-- 13.04.2004 16:01:27---------------------------------------------------
409 
410   -----------------------------------------------------------------------*/
~SwSelectAddressBlockDialog()411 SwSelectAddressBlockDialog::~SwSelectAddressBlockDialog()
412 {
413 }
414 /*-- 28.04.2004 11:48:11---------------------------------------------------
415 
416   -----------------------------------------------------------------------*/
SetAddressBlocks(const uno::Sequence<::rtl::OUString> & rBlocks,sal_uInt16 nSelectedAddress)417 void SwSelectAddressBlockDialog::SetAddressBlocks(const uno::Sequence< ::rtl::OUString>& rBlocks,
418         sal_uInt16 nSelectedAddress)
419 {
420     m_aAddressBlocks = rBlocks;
421     for(sal_Int32 nAddress = 0; nAddress < m_aAddressBlocks.getLength(); ++nAddress)
422         m_aPreview.AddAddress(m_aAddressBlocks[nAddress]);
423     m_aPreview.SelectAddress(nSelectedAddress);
424 }
425 /*-- 25.06.2004 10:51:36---------------------------------------------------
426     return the address blocks and put the selected one to the first position
427   -----------------------------------------------------------------------*/
GetAddressBlocks()428 const uno::Sequence< ::rtl::OUString >&    SwSelectAddressBlockDialog::GetAddressBlocks()
429 {
430     //put the selected block to the first position
431     sal_uInt16 nSelect = m_aPreview.GetSelectedAddress();
432     if(nSelect)
433     {
434         uno::Sequence< ::rtl::OUString >aTemp = m_aAddressBlocks;
435         ::rtl::OUString* pTemp = aTemp.getArray();
436         pTemp[0] = m_aAddressBlocks[nSelect];
437         sal_uInt32 nIndex = 0;
438 		const sal_uInt32 nNumBlocks = m_aAddressBlocks.getLength();
439         for(sal_uInt32 nAddress = 1; nAddress < nNumBlocks; ++nAddress)
440         {
441 			if(nIndex == nSelect)
442                 ++nIndex;
443             pTemp[nAddress] = m_aAddressBlocks[nIndex];
444             nIndex++;
445         }
446         m_aAddressBlocks = aTemp;
447     }
448     return m_aAddressBlocks;
449 }
450 /*-- 28.04.2004 11:48:11---------------------------------------------------
451 
452   -----------------------------------------------------------------------*/
SetSettings(sal_Bool bIsCountry,::rtl::OUString rCountry)453 void SwSelectAddressBlockDialog::SetSettings(
454         sal_Bool bIsCountry, ::rtl::OUString rCountry)
455 {
456     if(bIsCountry)
457     {
458         rCountry.getLength() ? m_aDependentRB.Check() : m_aAlwaysRB.Check();
459         m_aCountryED.SetText(rCountry);
460     }
461     else
462         m_aNeverRB.Check();
463     m_aDeletePB.Enable(m_aAddressBlocks.getLength() > 1);
464 }
465 /*-- 10.05.2004 11:17:06---------------------------------------------------
466 
467   -----------------------------------------------------------------------*/
GetCountry() const468 ::rtl::OUString     SwSelectAddressBlockDialog::GetCountry() const
469 {
470     ::rtl::OUString sRet;
471     if(m_aDependentRB.IsChecked())
472         sRet = m_aCountryED.GetText();
473     return sRet;
474 }
475 
476 /*-- 13.04.2004 16:02:32---------------------------------------------------
477 
478   -----------------------------------------------------------------------*/
IMPL_LINK(SwSelectAddressBlockDialog,DeleteHdl_Impl,PushButton *,pButton)479 IMPL_LINK(SwSelectAddressBlockDialog, DeleteHdl_Impl, PushButton*, pButton)
480 {
481     if(m_aAddressBlocks.getLength())
482     {
483         sal_uInt16 nSelected = m_aPreview.GetSelectedAddress();
484         ::rtl::OUString* pAddressBlocks = m_aAddressBlocks.getArray();
485         sal_Int32 nSource = 0;
486         for(sal_Int32 nTarget = 0; nTarget < m_aAddressBlocks.getLength() - 1; nTarget++)
487         {
488             if(nSource == nSelected)
489                 ++nSource;
490             pAddressBlocks[nTarget] = pAddressBlocks[nSource++];
491         }
492         m_aAddressBlocks.realloc(m_aAddressBlocks.getLength() - 1);
493         if(m_aAddressBlocks.getLength() <= 1)
494             pButton->Enable(sal_False);
495         m_aPreview.RemoveSelectedAddress();
496     }
497     return 0;
498 }
499 /*-- 13.04.2004 16:02:32---------------------------------------------------
500 
501   -----------------------------------------------------------------------*/
IMPL_LINK(SwSelectAddressBlockDialog,NewCustomizeHdl_Impl,PushButton *,pButton)502 IMPL_LINK(SwSelectAddressBlockDialog, NewCustomizeHdl_Impl, PushButton*, pButton)
503 {
504     bool bCustomize = pButton == &m_aCustomizePB;
505 	SwCustomizeAddressBlockDialog::DialogType nType = bCustomize ?
506 		SwCustomizeAddressBlockDialog::ADDRESSBLOCK_EDIT :
507 		SwCustomizeAddressBlockDialog::ADDRESSBLOCK_NEW;
508     SwCustomizeAddressBlockDialog *pDlg =
509 		new SwCustomizeAddressBlockDialog(pButton,m_rConfig,nType);
510     if(bCustomize)
511     {
512         pDlg->SetAddress(m_aAddressBlocks[m_aPreview.GetSelectedAddress()]);
513     }
514     if(RET_OK == pDlg->Execute())
515     {
516         if(bCustomize)
517         {
518             ::rtl::OUString sNew = pDlg->GetAddress();
519             m_aPreview.ReplaceSelectedAddress(sNew);
520             m_aAddressBlocks[m_aPreview.GetSelectedAddress()] = sNew;
521         }
522         else
523         {
524             ::rtl::OUString sNew = pDlg->GetAddress();
525             m_aPreview.AddAddress(sNew);
526             m_aAddressBlocks.realloc(m_aAddressBlocks.getLength() + 1);
527             sal_uInt16 nSelect = (sal_uInt16)m_aAddressBlocks.getLength() - 1;
528             m_aAddressBlocks[nSelect] = sNew;
529             m_aPreview.SelectAddress(nSelect);
530         }
531         m_aDeletePB.Enable( m_aAddressBlocks.getLength() > 1);
532     }
533     delete pDlg;
534     return 0;
535 }
536 /*-- 13.04.2004 16:02:33---------------------------------------------------
537 
538   -----------------------------------------------------------------------*/
IMPL_LINK(SwSelectAddressBlockDialog,IncludeHdl_Impl,RadioButton *,pButton)539 IMPL_LINK(SwSelectAddressBlockDialog, IncludeHdl_Impl, RadioButton*, pButton)
540 {
541     m_aCountryED.Enable(&m_aDependentRB == pButton);
542     return 0;
543 }
544 
545 /* -----------------------------28.02.05 09:00--------------------------------
546 
547  ---------------------------------------------------------------------------*/
~SwRestrictedComboBox()548 SwRestrictedComboBox::~SwRestrictedComboBox()
549 {
550 }
551 /* -----------------------------28.02.05 09:00--------------------------------
552 
553  ---------------------------------------------------------------------------*/
KeyInput(const KeyEvent & rEvt)554 void SwRestrictedComboBox::KeyInput(const KeyEvent& rEvt)
555 {
556 	sal_Bool bCallParent = sal_True;
557 	if(rEvt.GetCharCode())
558 	{
559 		String sKey = rEvt.GetCharCode();
560 		if(	STRING_NOTFOUND != sForbiddenChars.Search(sKey))
561 			bCallParent = sal_False;
562 	}
563 	if(bCallParent)
564 		ComboBox::KeyInput(rEvt);
565 }
566 /* -----------------------------28.02.05 09:00--------------------------------
567 
568  ---------------------------------------------------------------------------*/
Modify()569 void SwRestrictedComboBox::Modify()
570 {
571 	Selection aSel = GetSelection();
572 	String sTemp = GetText();
573 	for(sal_uInt16 i = 0; i < sForbiddenChars.Len(); i++)
574 	{
575 		sTemp.EraseAllChars( sForbiddenChars.GetChar(i) );
576 	}
577 	sal_uInt16 nDiff = GetText().Len() - sTemp.Len();
578 	if(nDiff)
579 	{
580 		aSel.setMin(aSel.getMin() - nDiff);
581 		aSel.setMax(aSel.getMin());
582 		SetText(sTemp);
583 		SetSelection(aSel);
584 	}
585 	if(GetModifyHdl().IsSet())
586 		GetModifyHdl().Call(this);
587 }
588 
589 /*-- 13.04.2004 16:01:08---------------------------------------------------
590 
591   -----------------------------------------------------------------------*/
592 #define USER_DATA_SALUTATION        -1
593 #define USER_DATA_PUNCTUATION       -2
594 #define USER_DATA_TEXT              -3
595 #define USER_DATA_NONE              -4
596 
SwCustomizeAddressBlockDialog(Window * pParent,SwMailMergeConfigItem & rConfig,DialogType eType)597 SwCustomizeAddressBlockDialog::SwCustomizeAddressBlockDialog(
598         Window* pParent, SwMailMergeConfigItem& rConfig, DialogType eType) :
599     SfxModalDialog(pParent, SW_RES(DLG_MM_CUSTOMIZEADDRESSBLOCK)),
600 #ifdef MSC
601 #pragma warning (disable : 4355)
602 #endif
603     m_aAddressElementsFT( this, SW_RES(       FT_ADDRESSELEMENTS             )),
604     m_aAddressElementsLB( this, SW_RES(       LB_ADDRESSELEMENTS             )),
605     m_aInsertFieldIB( this, SW_RES(           IB_INSERTFIELD                 )),
606     m_aRemoveFieldIB( this, SW_RES(           IB_REMOVEFIELD                 )),
607     m_aDragFT( this, SW_RES(                  FT_DRAG                        )),
608     m_aDragED( this, SW_RES(                  ED_DRAG                        )),
609     m_aUpIB( this, SW_RES(                    IB_UP                          )),
610     m_aLeftIB( this, SW_RES(                  IB_LEFT                        )),
611     m_aRightIB( this, SW_RES(                 IB_RIGHT                       )),
612     m_aDownIB( this, SW_RES(                  IB_DOWN                        )),
613     m_aFieldFT( this, SW_RES(                 FT_FIELD                       )),
614     m_aFieldCB( this, SW_RES(                 CB_FIELD                       )),
615     m_aPreviewFI( this, SW_RES(               FI_PREVIEW                     )),
616     m_aPreviewWIN( this, SW_RES(               WIN_PREVIEW                    )),
617     m_aSeparatorFL( this, SW_RES(             FL_SEPARATOR                   )),
618     m_aOK( this, SW_RES(                      PB_OK                          )),
619     m_aCancel( this, SW_RES(                  PB_CANCEL                      )),
620     m_aHelp( this, SW_RES(                    PB_HELP                        )),
621 #ifdef MSC
622 #pragma warning (default : 4355)
623 #endif
624     m_rConfigItem(rConfig),
625     m_eType(eType)
626 {
627     m_aFieldCB.SetForbiddenChars( String::CreateFromAscii("<>"));
628     m_aDragED.SetStyle(m_aDragED.GetStyle() |WB_NOHIDESELECTION);
629     if( eType >= GREETING_FEMALE )
630     {
631         m_aFieldFT.Show();
632         m_aFieldCB.Show();
633         SvLBoxEntry* pEntry = m_aAddressElementsLB.InsertEntry(String(SW_RES(ST_SALUTATION )));
634         pEntry->SetUserData((void*)(sal_Int32)USER_DATA_SALUTATION );
635         pEntry = m_aAddressElementsLB.InsertEntry(String(SW_RES(ST_PUNCTUATION)));
636         pEntry->SetUserData((void*)(sal_Int32)USER_DATA_PUNCTUATION );
637         pEntry = m_aAddressElementsLB.InsertEntry(String(SW_RES(ST_TEXT       )));
638         pEntry->SetUserData((void*)(sal_Int32)USER_DATA_TEXT       );
639         ResStringArray aSalutArr(SW_RES(
640                     eType == GREETING_MALE ? RA_SALUTATION_MALE : RA_SALUTATION_FEMALE));
641         sal_uInt16 i;
642         for(i = 0; i < aSalutArr.Count(); ++i)
643             m_aSalutations.push_back(aSalutArr.GetString(i));
644         ResStringArray aPunctArr(SW_RES(RA_PUNCTUATION));
645         for(i = 0; i < aPunctArr.Count(); ++i)
646             m_aPunctuations.push_back(aPunctArr.GetString(i));
647         m_aDragED.SetText(String::CreateFromAscii("            "));
648         SetText( String( SW_RES( eType == GREETING_MALE ? ST_TITLE_MALE : ST_TITLE_FEMALE)));
649         m_aAddressElementsFT.SetText(String(SW_RES(ST_SALUTATIONELEMENTS)));
650         m_aInsertFieldIB.SetQuickHelpText(String(SW_RES(ST_INSERTSALUTATIONFIELD)));
651         m_aRemoveFieldIB.SetQuickHelpText(String(SW_RES(ST_REMOVESALUTATIONFIELD)));
652         m_aDragFT.SetText(String(SW_RES(ST_DRAGSALUTATION)));
653     }
654     else
655     {
656 		if(eType == ADDRESSBLOCK_EDIT)
657 	        SetText(String(SW_RES(ST_TITLE_EDIT)));
658 
659         //resize the preview
660         Point aFieldPos(m_aFieldFT.GetPosPixel());
661         long nDiff = m_aPreviewFI.GetPosPixel().Y() - aFieldPos.Y();
662         m_aPreviewFI.SetPosPixel(aFieldPos);
663         Size aPreviewSize = m_aPreviewWIN.GetSizePixel();
664         aPreviewSize.Height() += nDiff;
665         m_aPreviewWIN.SetSizePixel(aPreviewSize);
666         m_aPreviewWIN.SetPosPixel(m_aFieldCB.GetPosPixel());
667         m_aDragED.SetText(String::CreateFromAscii("\n\n\n\n\n"));
668     }
669     FreeResource();
670     const ResStringArray& rHeaders = m_rConfigItem.GetDefaultAddressHeaders();
671     for(sal_uInt16 i = 0; i < rHeaders.Count(); ++i)
672     {
673         const XubString& rHeader = rHeaders.GetString( i );
674         SvLBoxEntry* pEntry = m_aAddressElementsLB.InsertEntry(rHeader);
675         pEntry->SetUserData((void*)(sal_Int32)i);
676     }
677     m_aOK.SetClickHdl(LINK(this, SwCustomizeAddressBlockDialog, OKHdl_Impl));
678     m_aAddressElementsLB.SetSelectHdl(LINK(this, SwCustomizeAddressBlockDialog, ListBoxSelectHdl_Impl ));
679     m_aDragED.SetModifyHdl(LINK(this, SwCustomizeAddressBlockDialog, EditModifyHdl_Impl));
680     m_aDragED.SetSelectionChangedHdl( LINK( this, SwCustomizeAddressBlockDialog, SelectionChangedHdl_Impl));
681     Link aFieldsLink = LINK(this, SwCustomizeAddressBlockDialog, FieldChangeHdl_Impl);
682     m_aFieldCB.SetModifyHdl(aFieldsLink);
683     m_aFieldCB.SetSelectHdl(aFieldsLink);
684     Link aImgButtonHdl = LINK(this, SwCustomizeAddressBlockDialog, ImageButtonHdl_Impl);
685     m_aInsertFieldIB.SetClickHdl(aImgButtonHdl);
686     m_aRemoveFieldIB.SetClickHdl(aImgButtonHdl);
687     m_aUpIB.SetClickHdl(aImgButtonHdl);
688     m_aLeftIB.SetClickHdl(aImgButtonHdl);
689     m_aRightIB.SetClickHdl(aImgButtonHdl);
690     m_aDownIB.SetClickHdl(aImgButtonHdl);
691     UpdateImageButtons_Impl();
692 }
693 /*-- 13.04.2004 16:01:08---------------------------------------------------
694 
695   -----------------------------------------------------------------------*/
~SwCustomizeAddressBlockDialog()696 SwCustomizeAddressBlockDialog::~SwCustomizeAddressBlockDialog()
697 {
698 }
699 /*-- 07.06.2004 13:51:11---------------------------------------------------
700 
701   -----------------------------------------------------------------------*/
IMPL_LINK(SwCustomizeAddressBlockDialog,OKHdl_Impl,OKButton *,EMPTYARG)702 IMPL_LINK(SwCustomizeAddressBlockDialog, OKHdl_Impl, OKButton*, EMPTYARG)
703 {
704     EndDialog(RET_OK);
705     return 0;
706 }
707 /*-- 24.06.2004 11:36:05---------------------------------------------------
708 
709   -----------------------------------------------------------------------*/
IMPL_LINK(SwCustomizeAddressBlockDialog,ListBoxSelectHdl_Impl,DDListBox *,pBox)710 IMPL_LINK(SwCustomizeAddressBlockDialog, ListBoxSelectHdl_Impl, DDListBox*, pBox)
711 {
712     sal_Int32 nUserData = (sal_Int32)(sal_IntPtr)pBox->FirstSelected()->GetUserData();
713     // Check if the selected entry is already in the address and then forbid inserting
714     m_aInsertFieldIB.Enable(nUserData >= 0 || !HasItem_Impl(nUserData));
715     return 0;
716 }
717 /*-- 25.06.2004 11:21:24---------------------------------------------------
718 
719   -----------------------------------------------------------------------*/
IMPL_LINK(SwCustomizeAddressBlockDialog,EditModifyHdl_Impl,AddressMultiLineEdit *,EMPTYARG)720 IMPL_LINK(SwCustomizeAddressBlockDialog, EditModifyHdl_Impl, AddressMultiLineEdit*, EMPTYARG)
721 {
722     String sAddress = SwAddressPreview::FillData(
723             GetAddress(),
724             m_rConfigItem);
725     m_aPreviewWIN.SetAddress(sAddress);
726     UpdateImageButtons_Impl();
727     return 0;
728 }
729 /*-- 25.06.2004 12:14:11---------------------------------------------------
730 
731   -----------------------------------------------------------------------*/
IMPL_LINK(SwCustomizeAddressBlockDialog,ImageButtonHdl_Impl,ImageButton *,pButton)732 IMPL_LINK(SwCustomizeAddressBlockDialog, ImageButtonHdl_Impl, ImageButton*, pButton)
733 {
734     if(&m_aInsertFieldIB == pButton)
735     {
736         SvLBoxEntry* pEntry = m_aAddressElementsLB.GetCurEntry();
737         if(pEntry)
738         {
739             String sEntry = m_aAddressElementsLB.GetEntryText(pEntry);
740             sEntry.Insert('<', 0);
741             sEntry += '>';
742             m_aDragED.InsertNewEntry(sEntry);
743         }
744     }
745     else if(&m_aRemoveFieldIB == pButton)
746     {
747         m_aDragED.RemoveCurrentEntry();
748     }
749     else
750     {
751         sal_uInt16 nMove = MOVE_ITEM_DOWN;
752         if(&m_aUpIB == pButton)
753             nMove = MOVE_ITEM_UP;
754         else if(&m_aLeftIB == pButton)
755             nMove = MOVE_ITEM_LEFT;
756         else if(&m_aRightIB == pButton)
757             nMove = MOVE_ITEM_RIGHT;
758         m_aDragED.MoveCurrentItem(nMove);
759     }
760     UpdateImageButtons_Impl();
761     return 0;
762 }
763 /*-- 01.07.2004 09:27:02---------------------------------------------------
764 
765   -----------------------------------------------------------------------*/
GetSelectedItem_Impl()766 sal_Int32 SwCustomizeAddressBlockDialog::GetSelectedItem_Impl()
767 {
768     sal_Int32 nRet = USER_DATA_NONE;
769     String sSelected = m_aDragED.GetCurrentItem();
770     if(sSelected.Len())
771         for(sal_uLong i = 0; i < m_aAddressElementsLB.GetEntryCount();  ++i)
772         {
773             SvLBoxEntry* pEntry = m_aAddressElementsLB.GetEntry(i);
774             String sEntry = m_aAddressElementsLB.GetEntryText(pEntry);
775             if( sSelected.Equals( sEntry, 1, sSelected.Len() - 2 ) )
776             {
777                 nRet = (sal_Int32)(sal_IntPtr)pEntry->GetUserData();
778                 break;
779             }
780         }
781     return nRet;
782 }
783 /*-- 01.07.2004 10:01:19---------------------------------------------------
784 
785   -----------------------------------------------------------------------*/
HasItem_Impl(sal_Int32 nUserData)786 bool   SwCustomizeAddressBlockDialog::HasItem_Impl(sal_Int32 nUserData)
787 {
788     //get the entry from the ListBox
789     String sEntry;
790     for(sal_uLong i = 0; i < m_aAddressElementsLB.GetEntryCount();  ++i)
791     {
792         SvLBoxEntry* pEntry = m_aAddressElementsLB.GetEntry(i);
793         if((sal_Int32)(sal_IntPtr)pEntry->GetUserData() == nUserData)
794         {
795             sEntry = m_aAddressElementsLB.GetEntryText(pEntry);
796             break;
797         }
798     }
799     //put it into '<>'
800     sEntry += '>';
801     sEntry.Insert( '<', 0);
802     //search for this entry in the content
803     String sText = m_aDragED.GetText();
804     bool bRet = sText.Search(sEntry) != STRING_NOTFOUND;
805     return bRet;
806 }
807 /*-- 25.06.2004 13:10:16---------------------------------------------------
808 
809   -----------------------------------------------------------------------*/
IMPL_LINK(SwCustomizeAddressBlockDialog,SelectionChangedHdl_Impl,AddressMultiLineEdit *,pEdit)810 IMPL_LINK(SwCustomizeAddressBlockDialog, SelectionChangedHdl_Impl, AddressMultiLineEdit*, pEdit)
811 {
812 	// called in case the selection of the edit field changes.
813     // determine selection - if it's one of the editable fields then
814     // enable the related ComboBox and fill it
815 	static bool bOnEntry = false;
816 	if(bOnEntry)
817 		return 0;
818 
819 	bOnEntry = true;
820     sal_Int32 nSelected = GetSelectedItem_Impl();
821     if(USER_DATA_NONE != nSelected)
822 		pEdit->SelectCurrentItem();
823 
824     if(m_aFieldCB.IsVisible() && (USER_DATA_NONE != nSelected) && (nSelected < 0))
825     {
826         //search in ListBox if it's one of the first entries
827         String sSelect;
828         ::std::vector<String>* pVector = 0;
829         switch(nSelected) {
830             case USER_DATA_SALUTATION:
831                 sSelect =  m_sCurrentSalutation;
832                 pVector = &m_aSalutations;
833 				break;
834             case USER_DATA_PUNCTUATION:
835                 sSelect =  m_sCurrentPunctuation;
836                 pVector = &m_aPunctuations;
837 				break;
838             case USER_DATA_TEXT:
839 				sSelect =  m_sCurrentText;
840 				break;
841         }
842         m_aFieldCB.Clear();
843         if(pVector) {
844             ::std::vector<String>::iterator  aIterator;
845             for( aIterator = pVector->begin(); aIterator != pVector->end(); ++aIterator)
846                 m_aFieldCB.InsertEntry(*aIterator);
847         }
848 		m_aFieldCB.SetText(sSelect);
849         m_aFieldCB.Enable(sal_True);
850         m_aFieldFT.Enable(sal_True);
851     }
852     else
853     {
854         m_aFieldCB.Enable(sal_False);
855         m_aFieldFT.Enable(sal_False);
856     }
857 
858     UpdateImageButtons_Impl();
859 	bOnEntry = false;
860     return 0;
861 }
862 /*-- 25.06.2004 13:36:29---------------------------------------------------
863 
864   -----------------------------------------------------------------------*/
IMPL_LINK(SwCustomizeAddressBlockDialog,FieldChangeHdl_Impl,ComboBox *,EMPTYARG)865 IMPL_LINK(SwCustomizeAddressBlockDialog, FieldChangeHdl_Impl, ComboBox*, EMPTYARG)
866 {
867     //changing the field content changes the related members, too
868     sal_Int32 nSelected = GetSelectedItem_Impl();
869     String sContent = m_aFieldCB.GetText();
870     switch(nSelected) {
871         case USER_DATA_SALUTATION:
872             m_sCurrentSalutation = sContent;
873 			break;
874         case USER_DATA_PUNCTUATION:
875             m_sCurrentPunctuation = sContent;
876 			break;
877         case USER_DATA_TEXT:
878 			m_sCurrentText = sContent;
879 			break;
880     }
881     UpdateImageButtons_Impl();
882     m_aPreviewWIN.SetAddress(GetAddress());
883 	m_aDragED.Modify();
884     return 0;
885 }
886 
887 /*-- 25.06.2004 12:35:51---------------------------------------------------
888 
889   -----------------------------------------------------------------------*/
UpdateImageButtons_Impl()890 void SwCustomizeAddressBlockDialog::UpdateImageButtons_Impl()
891 {
892     sal_uInt16 nMove = m_aDragED.IsCurrentItemMoveable();
893     m_aUpIB.Enable(nMove & MOVE_ITEM_UP );
894     m_aLeftIB.Enable(nMove & MOVE_ITEM_LEFT );
895     m_aRightIB.Enable(nMove & MOVE_ITEM_RIGHT );
896     m_aDownIB.Enable(nMove & MOVE_ITEM_DOWN);
897     m_aRemoveFieldIB.Enable(m_aDragED.HasCurrentItem() ? sal_True : sal_False);
898     SvLBoxEntry* pEntry = m_aAddressElementsLB.GetCurEntry();
899     m_aInsertFieldIB.Enable( pEntry &&
900             (0 < (sal_Int32)(sal_IntPtr)pEntry->GetUserData() || m_aFieldCB.GetText().Len()));
901 }
902 /*-- 28.04.2004 12:04:14---------------------------------------------------
903 
904   -----------------------------------------------------------------------*/
SetAddress(const::rtl::OUString & rAddress)905 void SwCustomizeAddressBlockDialog::SetAddress(const ::rtl::OUString& rAddress)
906 {
907     m_aDragED.SetText( rAddress );
908     UpdateImageButtons_Impl();
909 	m_aDragED.Modify();
910 }
911 /*-- 28.04.2004 12:04:14---------------------------------------------------
912 
913   -----------------------------------------------------------------------*/
GetAddress()914 ::rtl::OUString SwCustomizeAddressBlockDialog::GetAddress()
915 {
916     String sAddress(m_aDragED.GetAddress());
917     //remove placeholders by the actual content
918     if(m_aFieldFT.IsVisible())
919     {
920         for(sal_uLong i = 0; i < m_aAddressElementsLB.GetEntryCount();  ++i)
921         {
922             SvLBoxEntry* pEntry = m_aAddressElementsLB.GetEntry(i);
923             String sEntry = m_aAddressElementsLB.GetEntryText(pEntry);
924             sEntry += '>';
925             sEntry.Insert('<', 0);
926             sal_Int32 nUserData = (sal_Int32)(sal_IntPtr)pEntry->GetUserData();
927             switch(nUserData)
928             {
929                 case USER_DATA_SALUTATION : sAddress.SearchAndReplace(sEntry, m_sCurrentSalutation); break;
930                 case USER_DATA_PUNCTUATION: sAddress.SearchAndReplace(sEntry, m_sCurrentPunctuation); break;
931                 case USER_DATA_TEXT       : sAddress.SearchAndReplace(sEntry, m_sCurrentText); break;
932             }
933         }
934     }
935     return sAddress;
936 }
937 /*-- 28.02.2005 11:03:35---------------------------------------------------
938 
939   -----------------------------------------------------------------------*/
MoveFocus(Window * pMember,bool bNext)940 void SwCustomizeAddressBlockDialog::MoveFocus( Window* pMember, bool bNext )
941 {
942     ::std::vector< Window* > aControls;
943 
944     aControls.push_back(&m_aAddressElementsLB);
945     aControls.push_back(&m_aInsertFieldIB);
946     aControls.push_back(&m_aRemoveFieldIB);
947     aControls.push_back(&m_aDragED);
948     aControls.push_back(&m_aUpIB);
949     aControls.push_back(&m_aLeftIB);
950     aControls.push_back(&m_aRightIB);
951     aControls.push_back(&m_aDownIB);
952     aControls.push_back(&m_aFieldCB);
953     aControls.push_back(&m_aOK);
954     aControls.push_back(&m_aCancel);
955     aControls.push_back(&m_aHelp);
956 
957     ::std::vector< Window* >::iterator aMemberIter = aControls.begin();
958     for( ; aMemberIter != aControls.end(); ++aMemberIter)
959     {
960         if(*aMemberIter == pMember)
961             break;
962     }
963     if( aMemberIter == aControls.end() )
964     {
965         DBG_ERROR( "Window not found?" );
966         return;
967     }
968 
969     if( bNext )
970     {
971         ::std::vector< Window* >::iterator aSearch = aMemberIter;
972         ++aSearch;
973         while( true )
974         {
975             if( aSearch == aControls.end())
976                 aSearch = aControls.begin();
977             else if( (*aSearch)->IsEnabled() )
978             {
979                 (*aSearch)->GrabFocus();
980                 break;
981             }
982             else
983                 ++aSearch;
984         }
985     }
986     else
987     {
988         ::std::vector< Window* >::iterator aSearch = aMemberIter;
989         if(aSearch == aControls.begin())
990             aSearch = aControls.end();
991         while( true )
992         {
993             if(aSearch == aControls.begin())
994                 aSearch = aControls.end();
995             else
996                 --aSearch;
997             if( (*aSearch)->IsEnabled() )
998             {
999                 (*aSearch)->GrabFocus();
1000                 break;
1001             }
1002         }
1003     }
1004 
1005 }
1006 /*-- 13.04.2004 17:49:45---------------------------------------------------
1007 
1008   -----------------------------------------------------------------------*/
1009 class SwAssignFieldsControl : public Control
1010 {
1011     friend class SwAssignFieldsDialog;
1012     ScrollBar                   m_aVScroll;
1013     HeaderBar                   m_aHeaderHB;
1014     Window                      m_aWindow;
1015 
1016     ::std::vector<FixedInfo*>   m_aFieldNames;
1017     ::std::vector<ListBox*>     m_aMatches;
1018     ::std::vector<FixedInfo*>   m_aPreviews;
1019 
1020     SwMailMergeConfigItem&      m_rConfigItem;
1021 
1022     Link                        m_aModifyHdl;
1023 
1024     long                        m_nLBStartTopPos;
1025     long                        m_nYOffset;
1026     long                        m_nFirstYPos;
1027 
1028     DECL_LINK(ScrollHdl_Impl, ScrollBar*);
1029     DECL_LINK(MatchHdl_Impl, ListBox*);
1030     DECL_LINK(GotFocusHdl_Impl, ListBox*);
1031 
1032     virtual long        PreNotify( NotifyEvent& rNEvt );
1033     virtual void        Command( const CommandEvent& rCEvt );
1034 
1035     void                MakeVisible( sal_Int32 nIndex );
1036 public:
1037     SwAssignFieldsControl(Window* pParent, const ResId& rResId,
1038                                 SwMailMergeConfigItem& rConfigItem);
1039     ~SwAssignFieldsControl();
1040 
SetModifyHdl(const Link & rModifyHdl)1041     void        SetModifyHdl(const Link& rModifyHdl)
1042                 {
1043                     m_aModifyHdl = rModifyHdl;
1044                     m_aModifyHdl.Call(this);
1045                 }
1046 };
1047 /*-- 13.04.2004 17:51:27---------------------------------------------------
1048 
1049   -----------------------------------------------------------------------*/
1050 //-------------------------------------------------------------------------
SwAssignFieldsControl(Window * pParent,const ResId & rResId,SwMailMergeConfigItem & rConfigItem)1051 SwAssignFieldsControl::SwAssignFieldsControl(
1052         Window* pParent, const ResId& rResId, SwMailMergeConfigItem& rConfigItem) :
1053     Control(pParent, rResId),
1054 #ifdef MSC
1055 #pragma warning (disable : 4355)
1056 #endif
1057     m_aVScroll(this,  ResId(SCR_1, *rResId.GetResMgr()     )),
1058     m_aHeaderHB(this, WB_BUTTONSTYLE | WB_BOTTOMBORDER),
1059     m_aWindow(this, ResId(WIN_DATA, *rResId.GetResMgr())),
1060 #ifdef MSC
1061 #pragma warning (default : 4355)
1062 #endif
1063     m_rConfigItem(rConfigItem),
1064     m_nLBStartTopPos(0),
1065     m_nYOffset(0),
1066     m_nFirstYPos(0)
1067 {
1068     SetStyle(GetStyle()|WB_TABSTOP|WB_DIALOGCONTROL);
1069     SetHelpId(HID_MM_ASSIGN_FIELDS);
1070     long nHBHeight = m_aHeaderHB.CalcWindowSizePixel().Height();
1071     Size aOutputSize(GetOutputSize());
1072     m_aHeaderHB.SetSizePixel(
1073         Size(aOutputSize.Width(), nHBHeight));
1074     m_aHeaderHB.Show();
1075     m_aWindow.SetPosPixel(Point( 0, nHBHeight) );
1076     m_aWindow.SetSizePixel(Size(aOutputSize.Width() - m_aVScroll.GetSizePixel().Width(), aOutputSize.Height() - nHBHeight));
1077     m_aWindow.Show();
1078 
1079     //get the name of the default headers
1080     const ResStringArray& rHeaders = rConfigItem.GetDefaultAddressHeaders();
1081     //get the actual data
1082     uno::Reference< XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), uno::UNO_QUERY);
1083     //get the name of the actual columns
1084     uno::Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
1085     uno::Sequence< ::rtl::OUString > aFields;
1086     if(xColAccess.is())
1087         aFields = xColAccess->getElementNames();
1088     const ::rtl::OUString* pFields = aFields.getConstArray();
1089 
1090     //get the current assignment list
1091     //each position in this sequence matches the position in the header array rHeaders
1092     //if no assignment is available an empty sequence will be returned
1093     uno::Sequence< ::rtl::OUString> aAssignments = rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
1094     Link aMatchHdl = LINK(this, SwAssignFieldsControl, MatchHdl_Impl);
1095     Link aFocusHdl = LINK(this, SwAssignFieldsControl, GotFocusHdl_Impl);
1096 
1097     static const char* aHIDs[] =
1098     {
1099          HID_MM_HEADER_0,
1100          HID_MM_HEADER_1,
1101          HID_MM_HEADER_2,
1102          HID_MM_HEADER_3,
1103          HID_MM_HEADER_4,
1104          HID_MM_HEADER_5,
1105          HID_MM_HEADER_6,
1106          HID_MM_HEADER_7,
1107          HID_MM_HEADER_8,
1108          HID_MM_HEADER_9,
1109          HID_MM_HEADER_10,
1110          HID_MM_HEADER_11,
1111          HID_MM_HEADER_12,
1112          HID_MM_HEADER_13
1113     };
1114 
1115     //fill the controls
1116     for(sal_uInt16 i = 0; i < rHeaders.Count(); ++i)
1117     {
1118         const XubString& rHeader = rHeaders.GetString( i );
1119         FixedInfo* pNewText = new FixedInfo(&m_aWindow, ResId( FT_FIELDS, *rResId.GetResMgr()));
1120         String sLabel(String::CreateFromAscii("<>"));
1121         sLabel.Insert(rHeader, 1);
1122         pNewText->SetText(sLabel);
1123         ListBox* pNewLB = new ListBox(&m_aWindow, ResId(LB_FIELDS, *rResId.GetResMgr()));
1124         pNewLB->SetHelpId( aHIDs[i] );
1125         pNewLB->SelectEntryPos(0);
1126         for(sal_Int32 nField = 0; nField < aFields.getLength(); ++nField)
1127             pNewLB->InsertEntry(pFields[nField]);
1128         FixedInfo* pNewPreview = new FixedInfo(&m_aWindow, ResId( FT_PREVIEW, *rResId.GetResMgr() ));
1129         //select the ListBox
1130         //if there is an assignment
1131         if(aAssignments.getLength() > i && aAssignments[i].getLength())
1132             pNewLB->SelectEntry(aAssignments[i]);
1133         else //otherwise the current column name may match one of the db columns
1134             pNewLB->SelectEntry(rHeader);
1135         //then the preview can be filled accordingly
1136         if(xColAccess.is() && pNewLB->GetSelectEntryPos() > 0 &&
1137                 xColAccess->hasByName(pNewLB->GetSelectEntry()))
1138         {
1139             uno::Any aCol = xColAccess->getByName(pNewLB->GetSelectEntry());
1140             uno::Reference< XColumn > xColumn;
1141             aCol >>= xColumn;
1142             if(xColumn.is())
1143                 try
1144                 {
1145                     pNewPreview->SetText(xColumn->getString());
1146                 }
1147                 catch(SQLException& )
1148                 {
1149                 }
1150         }
1151         if(!i)
1152         {
1153             //determine the vertical offset, use the bottom position of the ListBox
1154             m_nFirstYPos = m_nYOffset = pNewLB->GetPosPixel().Y();
1155             m_nLBStartTopPos = m_nYOffset;
1156             m_nYOffset += pNewLB->GetSizePixel().Height();
1157         }
1158 
1159         long nMove = m_nYOffset * i;
1160         lcl_Move(pNewText, nMove);
1161         lcl_Move(pNewLB, nMove);
1162         lcl_Move(pNewPreview, nMove);
1163         //set the select handler
1164         pNewLB->SetSelectHdl(aMatchHdl);
1165         pNewLB->SetGetFocusHdl(aFocusHdl);
1166 
1167         m_aFieldNames.push_back(pNewText);
1168         m_aMatches.push_back(pNewLB);
1169         m_aPreviews.push_back(pNewPreview);
1170     }
1171     ListBox* pBottomBox = m_aMatches[rHeaders.Count() -1];
1172     long nYBottom = pBottomBox->GetPosPixel().Y();
1173     nYBottom += pBottomBox->GetDropDownPosSizePixel().GetHeight();
1174     m_aVScroll.SetRange(Range(0, rHeaders.Count()));
1175     m_aVScroll.SetPageSize((aOutputSize.Height() - nHBHeight - m_nLBStartTopPos)/ m_nYOffset);
1176     m_aVScroll.EnableDrag();
1177     m_aVScroll.SetVisibleSize(m_aVScroll.GetPageSize());
1178     m_aVScroll.SetScrollHdl(LINK(this, SwAssignFieldsControl, ScrollHdl_Impl));
1179 
1180     FreeResource();
1181     m_aVScroll.SetPosPixel(Point(aOutputSize.Width() - m_aVScroll.GetSizePixel().Width(), nHBHeight));
1182     m_aVScroll.SetSizePixel(Size(m_aVScroll.GetSizePixel().Width(), aOutputSize.Height() - nHBHeight));
1183 
1184 }
1185 /*-- 13.04.2004 17:51:28---------------------------------------------------
1186 
1187   -----------------------------------------------------------------------*/
~SwAssignFieldsControl()1188 SwAssignFieldsControl::~SwAssignFieldsControl()
1189 {
1190     ::std::vector<FixedInfo*>::iterator aFIIter;
1191     for(aFIIter = m_aFieldNames.begin(); aFIIter != m_aFieldNames.end(); ++aFIIter)
1192         delete *aFIIter;
1193     ::std::vector<ListBox*>::iterator aLBIter;
1194     for(aLBIter = m_aMatches.begin(); aLBIter != m_aMatches.end(); ++aLBIter)
1195         delete *aLBIter;
1196     for(aFIIter = m_aPreviews.begin(); aFIIter != m_aPreviews.end(); ++aFIIter)
1197         delete *aFIIter;
1198 }
1199 
1200 /*-- 07.05.2004 13:11:26---------------------------------------------------
1201 
1202   -----------------------------------------------------------------------*/
Command(const CommandEvent & rCEvt)1203 void SwAssignFieldsControl::Command( const CommandEvent& rCEvt )
1204 {
1205     switch ( rCEvt.GetCommand() )
1206     {
1207         case COMMAND_WHEEL:
1208         case COMMAND_STARTAUTOSCROLL:
1209         case COMMAND_AUTOSCROLL:
1210         {
1211             const CommandWheelData* pWheelData = rCEvt.GetWheelData();
1212             if(pWheelData && !pWheelData->IsHorz() && COMMAND_WHEEL_ZOOM != pWheelData->GetMode())
1213             {
1214                 HandleScrollCommand( rCEvt, 0, &m_aVScroll );
1215             }
1216         }
1217         break;
1218         default:
1219             Control::Command(rCEvt);
1220     }
1221 }
1222 /*-- 07.05.2004 13:11:21---------------------------------------------------
1223 
1224   -----------------------------------------------------------------------*/
PreNotify(NotifyEvent & rNEvt)1225 long SwAssignFieldsControl::PreNotify( NotifyEvent& rNEvt )
1226 {
1227     if(rNEvt.GetType() == EVENT_COMMAND)
1228     {
1229         const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
1230         sal_uInt16 nCmd = pCEvt->GetCommand();
1231         if( COMMAND_WHEEL == nCmd )
1232         {
1233             Command(*pCEvt);
1234             return 1;
1235         }
1236     }
1237     return Control::PreNotify(rNEvt);
1238 }
1239 /*-- 03.09.2004 13:19:09---------------------------------------------------
1240 
1241   -----------------------------------------------------------------------*/
MakeVisible(sal_Int32 nIndex)1242 void SwAssignFieldsControl::MakeVisible( sal_Int32 nIndex )
1243 {
1244     long nThumb = m_aVScroll.GetThumbPos();
1245     long nPage = m_aVScroll.GetPageSize();
1246     if(nThumb > nIndex)
1247         m_aVScroll.SetThumbPos( nIndex );
1248     else if( (nThumb + nPage) < nIndex)
1249         m_aVScroll.SetThumbPos( nIndex - nPage );
1250     else
1251         return;
1252     ScrollHdl_Impl( &m_aVScroll );
1253 }
1254 /*-- 30.04.2004 16:10:58---------------------------------------------------
1255 
1256   -----------------------------------------------------------------------*/
IMPL_LINK(SwAssignFieldsControl,ScrollHdl_Impl,ScrollBar *,pScroll)1257 IMPL_LINK(SwAssignFieldsControl, ScrollHdl_Impl, ScrollBar*, pScroll)
1258 {
1259     long nThumb = pScroll->GetThumbPos();
1260     // the scrollbar moves on a per line basis
1261     // the height of a line is stored in m_nYOffset
1262     // nThumb determines which line has to be set at the top (m_nYOffset)
1263     // The first line has to be -(nThumb * m_nYOffset) in the negative
1264     long nMove = m_nFirstYPos - (*m_aMatches.begin())->GetPosPixel().Y() - (nThumb * m_nYOffset);
1265 
1266     SetUpdateMode(sal_False);
1267     long nIndex;
1268     ::std::vector<FixedInfo*>::iterator aFIIter;
1269     for(nIndex = 0, aFIIter = m_aFieldNames.begin(); aFIIter != m_aFieldNames.end(); ++aFIIter, ++nIndex)
1270         lcl_Move(*aFIIter, nMove);
1271     ::std::vector<ListBox*>::iterator aLBIter;
1272     for(nIndex = 0, aLBIter = m_aMatches.begin(); aLBIter != m_aMatches.end(); ++aLBIter, ++nIndex)
1273         lcl_Move(*aLBIter, nMove);
1274     for(nIndex = 0, aFIIter = m_aPreviews.begin(); aFIIter != m_aPreviews.end(); ++aFIIter, ++nIndex)
1275         lcl_Move(*aFIIter, nMove);
1276     SetUpdateMode(sal_True);
1277 
1278     return 0;
1279 }
1280 
1281 /*-- 03.05.2004 15:37:52---------------------------------------------------
1282 
1283   -----------------------------------------------------------------------*/
IMPL_LINK(SwAssignFieldsControl,MatchHdl_Impl,ListBox *,pBox)1284 IMPL_LINK(SwAssignFieldsControl, MatchHdl_Impl, ListBox*, pBox)
1285 {
1286     String sColumn = pBox->GetSelectEntry();
1287     uno::Reference< XColumnsSupplier > xColsSupp( m_rConfigItem.GetResultSet(), uno::UNO_QUERY);
1288     uno::Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
1289     ::rtl::OUString sPreview;
1290     if(xColAccess.is() && xColAccess->hasByName(sColumn))
1291     {
1292         uno::Any aCol = xColAccess->getByName(sColumn);
1293         uno::Reference< XColumn > xColumn;
1294         aCol >>= xColumn;
1295         if(xColumn.is())
1296         {
1297             try
1298             {
1299                 sPreview = xColumn->getString();
1300             }
1301             catch( sdbc::SQLException& )
1302             {
1303             }
1304         }
1305     }
1306     ::std::vector<ListBox*>::iterator aLBIter;
1307     sal_Int32 nIndex = 0;
1308     for(aLBIter = m_aMatches.begin(); aLBIter != m_aMatches.end(); ++aLBIter, ++nIndex)
1309     {
1310         if(*aLBIter == pBox)
1311         {
1312             m_aPreviews[nIndex]->SetText(sPreview);
1313             break;
1314         }
1315     }
1316     m_aModifyHdl.Call(0);
1317     return 0;
1318 }
1319 /*-- 03.09.2004 13:16:04---------------------------------------------------
1320 
1321   -----------------------------------------------------------------------*/
IMPL_LINK(SwAssignFieldsControl,GotFocusHdl_Impl,ListBox *,pBox)1322 IMPL_LINK(SwAssignFieldsControl, GotFocusHdl_Impl, ListBox*, pBox)
1323 {
1324     if(0 != (GETFOCUS_TAB & pBox->GetGetFocusFlags()))
1325     {
1326         sal_Int32 nIndex = 0;
1327         ::std::vector<ListBox*>::iterator aLBIter;
1328         for(aLBIter = m_aMatches.begin(); aLBIter != m_aMatches.end(); ++aLBIter, ++nIndex)
1329         {
1330             if(*aLBIter == pBox)
1331             {
1332                 MakeVisible(nIndex);
1333                 break;
1334             }
1335         }
1336     }
1337     return 0;
1338 }
1339 /*-- 13.04.2004 17:44:01---------------------------------------------------
1340 
1341   -----------------------------------------------------------------------*/
SwAssignFieldsDialog(Window * pParent,SwMailMergeConfigItem & rConfigItem,const::rtl::OUString & rPreview,bool bIsAddressBlock)1342 SwAssignFieldsDialog::SwAssignFieldsDialog(
1343         Window* pParent, SwMailMergeConfigItem& rConfigItem,
1344         const ::rtl::OUString& rPreview,
1345         bool bIsAddressBlock) :
1346     SfxModalDialog(pParent, SW_RES(DLG_MM_ASSIGNFIELDS)),
1347 #ifdef MSC
1348 #pragma warning (disable : 4355)
1349 #endif
1350     m_aMatchingFI( this, SW_RES(     FI_MATCHING)),
1351     m_pFieldsControl( new SwAssignFieldsControl(this, SW_RES(  CT_FIELDS  ), rConfigItem)),
1352     m_aPreviewFI( this, SW_RES(      FI_PREVIEW )),
1353     m_aPreviewWIN( this, SW_RES(     WIN_PREVIEW )),
1354     m_aSeparatorFL( this, SW_RES(    FL_SEPARATOR)),
1355     m_aOK( this, SW_RES(             PB_OK       )),
1356     m_aCancel( this, SW_RES(         PB_CANCEL   )),
1357     m_aHelp( this, SW_RES(           PB_HELP     )),
1358 #ifdef MSC
1359 #pragma warning (default : 4355)
1360 #endif
1361     m_sNone(SW_RES(ST_NONE)),
1362     m_rPreviewString(rPreview),
1363     m_rConfigItem(rConfigItem)
1364 {
1365     //resize the HeaderBar
1366     String sAddressElement(  SW_RES(ST_ADDRESSELEMENT ));
1367     String sMatchesTo(       SW_RES(ST_MATCHESTO      ));
1368     String sPreview(         SW_RES(ST_PREVIEW        ));
1369     if(!bIsAddressBlock)
1370     {
1371         m_aPreviewFI.SetText(String(SW_RES(ST_SALUTATIONPREVIEW)));
1372         m_aMatchingFI.SetText(String(SW_RES(ST_SALUTATIONMATCHING)));
1373         sAddressElement = String(SW_RES(ST_SALUTATIONELEMENT));
1374     }
1375     FreeResource();
1376     Size aOutputSize(m_pFieldsControl->m_aHeaderHB.GetSizePixel());
1377     sal_Int32 nFirstWidth;
1378     sal_Int32 nSecondWidth = nFirstWidth = aOutputSize.Width() / 3;
1379     const WinBits nHeadBits = HIB_VCENTER | HIB_FIXED| HIB_FIXEDPOS;
1380     m_pFieldsControl->m_aHeaderHB.InsertItem( 1, sAddressElement, nFirstWidth, nHeadBits|HIB_LEFT);
1381     m_pFieldsControl->m_aHeaderHB.InsertItem( 2, sMatchesTo,      nSecondWidth, nHeadBits|HIB_LEFT);
1382     m_pFieldsControl->m_aHeaderHB.InsertItem( 3, sPreview,
1383             aOutputSize.Width() - nFirstWidth - nSecondWidth, nHeadBits|HIB_LEFT);
1384 
1385     m_pFieldsControl->SetModifyHdl(LINK(this, SwAssignFieldsDialog, AssignmentModifyHdl_Impl ));
1386 
1387     String sMatching = m_aMatchingFI.GetText();
1388     sMatching.SearchAndReplaceAscii("%1", sMatchesTo);
1389     m_aMatchingFI.SetText(sMatching);
1390 
1391     m_aOK.SetClickHdl(LINK(this, SwAssignFieldsDialog, OkHdl_Impl));
1392 }
1393 /*-- 13.04.2004 17:44:02---------------------------------------------------
1394 
1395   -----------------------------------------------------------------------*/
~SwAssignFieldsDialog()1396 SwAssignFieldsDialog::~SwAssignFieldsDialog()
1397 {
1398     delete m_pFieldsControl;
1399 }
1400 /*-- 05.05.2004 14:39:13---------------------------------------------------
1401 
1402   -----------------------------------------------------------------------*/
CreateAssignments()1403 uno::Sequence< ::rtl::OUString > SwAssignFieldsDialog::CreateAssignments()
1404 {
1405     uno::Sequence< ::rtl::OUString > aAssignments(
1406             m_rConfigItem.GetDefaultAddressHeaders().Count());
1407     ::rtl::OUString* pAssignments = aAssignments.getArray();
1408     ::std::vector<ListBox*>::iterator aLBIter;
1409     sal_Int32 nIndex = 0;
1410     for(aLBIter = m_pFieldsControl->m_aMatches.begin();
1411                 aLBIter != m_pFieldsControl->m_aMatches.end();
1412                     ++aLBIter, ++nIndex)
1413     {
1414         String sSelect = (*aLBIter)->GetSelectEntry();
1415         if(m_sNone != sSelect)
1416             pAssignments[nIndex] = sSelect;
1417         else
1418             pAssignments[nIndex] = ::rtl::OUString();
1419     }
1420     return aAssignments;
1421 }
1422 /*-- 03.05.2004 18:04:00---------------------------------------------------
1423 
1424   -----------------------------------------------------------------------*/
IMPL_LINK(SwAssignFieldsDialog,OkHdl_Impl,PushButton *,EMPTYARG)1425 IMPL_LINK(SwAssignFieldsDialog, OkHdl_Impl, PushButton*, EMPTYARG)
1426 {
1427     m_rConfigItem.SetColumnAssignment(
1428                             m_rConfigItem.GetCurrentDBData(),
1429                             CreateAssignments() );
1430     EndDialog(RET_OK);
1431     return 0;
1432 }
1433 /*-- 05.05.2004 14:37:19---------------------------------------------------
1434 
1435   -----------------------------------------------------------------------*/
IMPL_LINK(SwAssignFieldsDialog,AssignmentModifyHdl_Impl,void *,EMPTYARG)1436 IMPL_LINK(SwAssignFieldsDialog, AssignmentModifyHdl_Impl, void*, EMPTYARG)
1437 {
1438     uno::Sequence< ::rtl::OUString > aAssignments = CreateAssignments();
1439     String sPreview = SwAddressPreview::FillData(
1440             m_rPreviewString, m_rConfigItem, &aAssignments);
1441     m_aPreviewWIN.SetAddress(sPreview);
1442     return 0;
1443 }
1444 
1445 /*-- 26.05.2004 11:20:11---------------------------------------------------
1446 
1447   -----------------------------------------------------------------------*/
DDListBox(SwCustomizeAddressBlockDialog * pParent,const ResId rResId)1448 DDListBox::DDListBox(SwCustomizeAddressBlockDialog* pParent, const ResId rResId) :
1449         SvTreeListBox(pParent, rResId),
1450         m_pParentDialog(pParent)
1451 {
1452     SetStyle( GetStyle() | /*WB_HASBUTTONS|WB_HASBUTTONSATROOT|*/
1453                             WB_CLIPCHILDREN );
1454 //    SetSpaceBetweenEntries(3);
1455     SetSelectionMode( SINGLE_SELECTION );
1456     SetDragDropMode(   SV_DRAGDROP_CTRL_COPY );
1457     EnableAsyncDrag(sal_True);
1458     SetHelpId(HID_MM_CUSTOMFIELDS);
1459     // expand selection to the complete width of the ListBox
1460     SetHighlightRange();
1461     Show();
1462 
1463 }
1464 /*-- 26.05.2004 11:20:15---------------------------------------------------
1465 
1466   -----------------------------------------------------------------------*/
~DDListBox()1467 DDListBox::~DDListBox()
1468 {
1469 }
1470 /*-- 26.05.2004 11:20:16---------------------------------------------------
1471 
1472   -----------------------------------------------------------------------*/
StartDrag(sal_Int8,const Point &)1473 void  DDListBox::StartDrag( sal_Int8 /*nAction*/, const Point& /*rPosPixel*/ )
1474 {
1475     SvLBoxEntry* pEntry = GetCurEntry();
1476     if(pEntry)
1477     {
1478         ReleaseMouse();
1479 
1480         TransferDataContainer* pContainer = new TransferDataContainer;
1481         uno::Reference<
1482              datatransfer::XTransferable > xRef( pContainer );
1483 
1484         sal_Int32 nUserData = (sal_Int32)(sal_IntPtr)pEntry->GetUserData();
1485         //special entries can only be once in the address / greeting
1486         if(nUserData >= 0 || !m_pParentDialog->HasItem_Impl(nUserData))
1487         {
1488             String sEntry;
1489             sEntry = GetEntryText(pEntry);
1490             sEntry.Insert('<', 0);
1491             sEntry += '>';
1492             if(sEntry.Len())
1493             {
1494                 pContainer->CopyString( sEntry );
1495                 pContainer->StartDrag( this, DND_ACTION_COPY, GetDragFinishedHdl() );
1496             }
1497         }
1498     }
1499 }
1500 /*-- 26.05.2004 13:14:53---------------------------------------------------
1501 
1502   -----------------------------------------------------------------------*/
AddressMultiLineEdit(SwCustomizeAddressBlockDialog * pParent,const ResId & rResId)1503 AddressMultiLineEdit::AddressMultiLineEdit(SwCustomizeAddressBlockDialog* pParent, const ResId& rResId) :
1504     MultiLineEdit(pParent, rResId),
1505     m_pParentDialog(pParent)
1506 
1507 {
1508     GetTextView()->SupportProtectAttribute(sal_True);
1509     StartListening(*GetTextEngine());
1510     //DisableSelectionOnFocus();
1511 	EnableFocusSelectionHide(sal_False);
1512 }
1513 /*-- 26.05.2004 13:14:53---------------------------------------------------
1514 
1515   -----------------------------------------------------------------------*/
~AddressMultiLineEdit()1516 AddressMultiLineEdit::~AddressMultiLineEdit()
1517 {
1518     EndListening(*GetTextEngine());
1519 }
1520 /*-- 25.06.2004 13:02:49---------------------------------------------------
1521 
1522   -----------------------------------------------------------------------*/
Notify(SfxBroadcaster &,const SfxHint & rHint)1523 void    AddressMultiLineEdit::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
1524 {
1525     if(rHint.ISA(TextHint) &&
1526             static_cast<const TextHint&>(rHint).GetId() == TEXT_HINT_VIEWSELECTIONCHANGED &&
1527             m_aSelectionLink.IsSet())
1528     {
1529         m_aSelectionLink.Call(this);
1530     }
1531 }
1532 /*-- 26.05.2004 13:45:46---------------------------------------------------
1533 
1534   -----------------------------------------------------------------------*/
PreNotify(NotifyEvent & rNEvt)1535 long  AddressMultiLineEdit::PreNotify( NotifyEvent& rNEvt )
1536 {
1537     long nHandled = 0;
1538     if( EVENT_KEYINPUT == rNEvt.GetType()  &&
1539         rNEvt.GetKeyEvent()->GetCharCode())
1540     {
1541         const KeyEvent* pKEvent = rNEvt.GetKeyEvent();
1542         if('\t' == pKEvent->GetCharCode() &&
1543             0 == (pKEvent->GetKeyCode().GetModifier() & (KEY_MOD1|KEY_MOD2)))
1544         {
1545             m_pParentDialog->MoveFocus(this, !pKEvent->GetKeyCode().IsShift());
1546         }
1547         nHandled = 1;
1548     }
1549 	else if(EVENT_MOUSEBUTTONDOWN == rNEvt.GetType()) {
1550 		const MouseEvent *pMEvt = rNEvt.GetMouseEvent();
1551 		if(pMEvt->GetClicks() >= 2)
1552 			nHandled = 1;
1553 	}
1554     if(!nHandled)
1555         nHandled = MultiLineEdit::PreNotify( rNEvt );
1556     return nHandled;
1557 
1558 }
1559 /*-- 25.06.2004 08:20:54---------------------------------------------------
1560 
1561   -----------------------------------------------------------------------*/
SetText(const String & rStr)1562 void AddressMultiLineEdit::SetText( const String& rStr )
1563 {
1564     MultiLineEdit::SetText(rStr);
1565     //set attributes to all address tokens
1566 
1567     ExtTextEngine* pTextEngine = GetTextEngine();
1568     TextAttribProtect aProtectAttr;
1569     sal_uLong  nParaCount = pTextEngine->GetParagraphCount();
1570     for(sal_uLong nPara = 0; nPara < nParaCount; ++nPara)
1571     {
1572         xub_StrLen nIndex = 0;
1573         String sPara = pTextEngine->GetText( nPara );
1574         if(sPara.Len() && sPara.GetChar(sPara.Len() - 1) != ' ')
1575         {
1576             TextPaM aPaM(nPara, sPara.Len());
1577             pTextEngine->ReplaceText(TextSelection( aPaM ), String(' '));
1578         }
1579         while(true)
1580         {
1581             sal_uInt16 nStart = sPara.Search( '<', nIndex );
1582             sal_uInt16 nEnd = sPara.Search( '>', nStart );
1583             nIndex = nEnd;
1584             if(nStart != STRING_NOTFOUND && nEnd != STRING_NOTFOUND)
1585                 pTextEngine->SetAttrib( aProtectAttr, nPara, nStart, nEnd + 1, sal_False );
1586             else
1587                 break;
1588         }
1589 
1590     }
1591     // add two empty paragraphs at the end
1592     if(m_pParentDialog->m_eType == SwCustomizeAddressBlockDialog::ADDRESSBLOCK_NEW ||
1593             m_pParentDialog->m_eType == SwCustomizeAddressBlockDialog::ADDRESSBLOCK_EDIT)
1594     {
1595         xub_StrLen nLastLen = pTextEngine->GetText(nParaCount - 1).Len();
1596         if(nLastLen)
1597         {
1598             TextPaM aPaM(nParaCount ? nParaCount - 1 : 0, nLastLen);
1599             pTextEngine->ReplaceText( TextSelection( aPaM ), String::CreateFromAscii("\n \n "));
1600         }
1601     }
1602 }
1603 
1604 /*-- 25.06.2004 12:32:41---------------------------------------------------
1605     Insert the new entry in front of the entry at the beginning of the selection
1606 
1607   -----------------------------------------------------------------------*/
InsertNewEntry(const String & rStr)1608 void AddressMultiLineEdit::InsertNewEntry( const String& rStr )
1609 {
1610 	// insert new entry after current selected one.
1611     ExtTextView* pTextView = GetTextView();
1612     const TextSelection& rSelection = pTextView->GetSelection();
1613     sal_uLong nPara = rSelection.GetStart().GetPara();
1614     sal_uInt16 nIndex = rSelection.GetEnd().GetIndex();
1615     ExtTextEngine *pTextEngine = GetTextEngine();
1616 	const TextCharAttrib *pAttrib;
1617     if(0 != (pAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED )))
1618 		nIndex = pAttrib->GetEnd();
1619     InsertNewEntryAtPosition( rStr, nPara, nIndex );
1620 
1621 	// select the new entry
1622     pAttrib = pTextEngine->FindCharAttrib(TextPaM(nPara, nIndex),TEXTATTR_PROTECTED);
1623 	TextSelection aEntrySel(TextPaM(nPara, nIndex), TextPaM(nPara, pAttrib->GetEnd()));
1624 	pTextView->SetSelection(aEntrySel);
1625 	Invalidate();
1626 	Modify();
1627 }
1628 
InsertNewEntryAtPosition(const String & rStr,sal_uLong nPara,sal_uInt16 nIndex)1629 void AddressMultiLineEdit::InsertNewEntryAtPosition( const String& rStr, sal_uLong nPara, sal_uInt16 nIndex )
1630 {
1631     ExtTextEngine* pTextEngine = GetTextEngine();
1632     TextPaM aInsertPos( nPara, nIndex );
1633 
1634     pTextEngine->ReplaceText( aInsertPos, rStr );
1635 
1636     //restore the attributes
1637     SetText( GetAddress() );
1638     //select the newly inserted/moved element
1639     TextSelection aEntrySel(aInsertPos);
1640     ExtTextView* pTextView = GetTextView();
1641     pTextView->SetSelection(aEntrySel);
1642     m_aSelectionLink.Call(this);
1643 }
1644 /*-- 25.06.2004 12:32:41---------------------------------------------------
1645 
1646   -----------------------------------------------------------------------*/
RemoveCurrentEntry()1647 void AddressMultiLineEdit::RemoveCurrentEntry()
1648 {
1649     ExtTextEngine* pTextEngine = GetTextEngine();
1650     ExtTextView* pTextView = GetTextView();
1651     const TextSelection& rSelection = pTextView->GetSelection();
1652     const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
1653 //    const TextCharAttrib* pEndAttrib = pTextEngine->FindCharAttrib( rSelection.GetEnd(), TEXTATTR_PROTECTED );
1654     if(pBeginAttrib &&
1655             (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
1656                             && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()))
1657     {
1658         sal_uLong nPara = rSelection.GetStart().GetPara();
1659         TextSelection aEntrySel(TextPaM( nPara, pBeginAttrib->GetStart()), TextPaM(nPara, pBeginAttrib->GetEnd()));
1660         pTextEngine->ReplaceText(aEntrySel, String());
1661         //restore the attributes
1662         SetText( GetAddress() );
1663 		Modify();
1664     }
1665 }
1666 /*-- 25.06.2004 12:32:41---------------------------------------------------
1667 
1668   -----------------------------------------------------------------------*/
MoveCurrentItem(sal_uInt16 nMove)1669 void AddressMultiLineEdit::MoveCurrentItem(sal_uInt16 nMove)
1670 {
1671     ExtTextEngine* pTextEngine = GetTextEngine();
1672     ExtTextView* pTextView = GetTextView();
1673     const TextSelection& rSelection = pTextView->GetSelection();
1674     const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
1675     if(pBeginAttrib &&
1676             (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
1677                             && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()))
1678     {
1679         //current item has been found
1680         sal_uLong nPara = rSelection.GetStart().GetPara();
1681         sal_uInt16 nIndex = pBeginAttrib->GetStart();
1682         TextSelection aEntrySel(TextPaM( nPara, pBeginAttrib->GetStart()), TextPaM(nPara, pBeginAttrib->GetEnd()));
1683         String sCurrentItem = pTextEngine->GetText(aEntrySel);
1684         pTextEngine->RemoveAttrib( nPara, *pBeginAttrib );
1685         pTextEngine->ReplaceText(aEntrySel, String());
1686         switch(nMove)
1687         {
1688             case MOVE_ITEM_LEFT :
1689                 if(nIndex)
1690                 {
1691                     //go left to find a predecessor or simple text
1692                     --nIndex;
1693                     String sPara = pTextEngine->GetText( nPara );
1694                     xub_StrLen nSearchIndex = sPara.SearchBackward( '>', nIndex+1 );
1695                     if( nSearchIndex != STRING_NOTFOUND && nSearchIndex == nIndex )
1696                     {
1697                         nSearchIndex = sPara.SearchBackward( '<', nIndex );
1698                         if( nSearchIndex != STRING_NOTFOUND )
1699                             nIndex = nSearchIndex;
1700                     }
1701                 }
1702             break;
1703             case MOVE_ITEM_RIGHT:
1704             {
1705                 //go right to find a successor or simple text
1706                 ++nIndex;
1707                 const TextCharAttrib* pEndAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
1708                 if(pEndAttrib && pEndAttrib->GetEnd() >= nIndex)
1709                 {
1710                     nIndex = pEndAttrib->GetEnd();
1711                 }
1712             }
1713             break;
1714             case MOVE_ITEM_UP   :
1715                 --nPara;
1716                 nIndex = 0;
1717             break;
1718             case MOVE_ITEM_DOWN :
1719                 ++nPara;
1720                 nIndex = 0;
1721             break;
1722 		}
1723         //add a new paragraph if there is none yet
1724         if(nPara >= pTextEngine->GetParagraphCount())
1725         {
1726 
1727             TextPaM aTemp(nPara - 1, pTextEngine->GetTextLen( nPara - 1 ));
1728             pTextEngine->ReplaceText( aTemp, String('\n'));
1729         }
1730         InsertNewEntryAtPosition( sCurrentItem, nPara, nIndex );
1731 
1732 		// select the new entry [#i40817]
1733 		const TextCharAttrib *pAttrib;
1734 		pAttrib = pTextEngine->FindCharAttrib(TextPaM(nPara, nIndex),TEXTATTR_PROTECTED);
1735 		aEntrySel = TextSelection(TextPaM(nPara, nIndex), TextPaM(nPara, pAttrib->GetEnd()));
1736 		pTextView->SetSelection(aEntrySel);
1737 		Invalidate();
1738 		Modify();
1739     }
1740 }
1741 /*-- 25.06.2004 12:32:41---------------------------------------------------
1742 
1743   -----------------------------------------------------------------------*/
IsCurrentItemMoveable()1744 sal_uInt16  AddressMultiLineEdit::IsCurrentItemMoveable()
1745 {
1746     sal_uInt16 nRet = 0;
1747     ExtTextEngine* pTextEngine = GetTextEngine();
1748     ExtTextView* pTextView = GetTextView();
1749     const TextSelection& rSelection = pTextView->GetSelection();
1750     const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
1751 //    const TextCharAttrib* pEndAttrib = pTextEngine->FindCharAttrib( rSelection.GetEnd(), TEXTATTR_PROTECTED );
1752     if(pBeginAttrib &&
1753             (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
1754                             && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()))
1755     {
1756         if(pBeginAttrib->GetStart())
1757             nRet |= MOVE_ITEM_LEFT;
1758         //if there is an entry it can always be move to the right and down
1759         nRet |= MOVE_ITEM_RIGHT|MOVE_ITEM_DOWN;
1760         if(rSelection.GetStart().GetPara() > 0)
1761             nRet |= MOVE_ITEM_UP;
1762     }
1763     return nRet;
1764 }
1765 /*-- 25.06.2004 12:32:42---------------------------------------------------
1766 
1767   -----------------------------------------------------------------------*/
HasCurrentItem()1768 bool AddressMultiLineEdit::HasCurrentItem()
1769 {
1770     ExtTextEngine* pTextEngine = GetTextEngine();
1771     ExtTextView* pTextView = GetTextView();
1772     const TextSelection& rSelection = pTextView->GetSelection();
1773     const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
1774     return (pBeginAttrib &&
1775             (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
1776                             && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()));
1777 }
1778 /*-- 01.07.2004 09:07:44---------------------------------------------------
1779 
1780   -----------------------------------------------------------------------*/
GetCurrentItem()1781 String AddressMultiLineEdit::GetCurrentItem()
1782 {
1783     String sRet;
1784     ExtTextEngine* pTextEngine = GetTextEngine();
1785     ExtTextView* pTextView = GetTextView();
1786     const TextSelection& rSelection = pTextView->GetSelection();
1787     const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
1788     if(pBeginAttrib &&
1789             (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
1790                             && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()))
1791     {
1792         sal_uLong nPara = rSelection.GetStart().GetPara();
1793         TextSelection aEntrySel(TextPaM( nPara, pBeginAttrib->GetStart()), TextPaM(nPara, pBeginAttrib->GetEnd()));
1794         sRet = pTextEngine->GetText( aEntrySel );
1795     }
1796     return sRet;
1797 }
1798 /*-- 05.07.2004 14:29:02---------------------------------------------------
1799 
1800   -----------------------------------------------------------------------*/
SelectCurrentItem()1801 void AddressMultiLineEdit::SelectCurrentItem()
1802 {
1803     ExtTextEngine* pTextEngine = GetTextEngine();
1804     ExtTextView* pTextView = GetTextView();
1805     const TextSelection& rSelection = pTextView->GetSelection();
1806     const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
1807     if(pBeginAttrib &&
1808             (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
1809                             && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()))
1810     {
1811         sal_uLong nPara = rSelection.GetStart().GetPara();
1812         TextSelection aEntrySel(TextPaM( nPara, pBeginAttrib->GetStart()), TextPaM(nPara, pBeginAttrib->GetEnd()));
1813         pTextView->SetSelection(aEntrySel);
1814         Invalidate();
1815     }
1816 }
1817 /*-- 25.06.2004 09:10:43---------------------------------------------------
1818     returns the address
1819     remove trailing spaces
1820     and trailing empty paragraphs
1821   -----------------------------------------------------------------------*/
GetAddress()1822 String AddressMultiLineEdit::GetAddress()
1823 {
1824     String sRet;
1825     ExtTextEngine* pTextEngine = GetTextEngine();
1826     sal_uLong  nParaCount = pTextEngine->GetParagraphCount();
1827     for(sal_uLong nPara = nParaCount; nPara; --nPara)
1828     {
1829         String sPara = pTextEngine->GetText( nPara - 1);
1830         sPara.EraseTrailingChars(' ');
1831         //don't add empty trailing paragraphs
1832         if(sRet.Len() || sPara.Len())
1833         {
1834             sRet.Insert(sPara, 0);
1835             //insert the para break
1836             if(nPara > 1)
1837                 sRet.Insert( '\n', 0);
1838         }
1839     }
1840     return sRet;
1841 }
1842 
1843