Update ooo320-m1
[ooovba.git] / sw / source / ui / dbui / mmaddressblockpage.cxx
blobe310882e7299c50011563f4c15f117942a0a64e4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mmaddressblockpage.cxx,v $
10 * $Revision: 1.25 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #ifdef SW_DLLIMPLEMENTATION
34 #undef SW_DLLIMPLEMENTATION
35 #endif
36 #include <mmaddressblockpage.hxx>
37 #include <mailmergewizard.hxx>
38 #include <swtypes.hxx>
39 #include <addresslistdialog.hxx>
40 #include <svtools/xtextedt.hxx>
41 #include <svtools/txtattr.hxx>
42 #include <vcl/msgbox.hxx>
43 #include <mmconfigitem.hxx>
44 #include <com/sun/star/container/XNameAccess.hpp>
45 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
46 #include <com/sun/star/sdb/XColumn.hpp>
48 #include <vector>
49 #include <mmaddressblockpage.hrc>
50 #include <dbui.hrc>
51 #include <helpid.h>
53 using namespace svt;
54 using namespace ::com::sun::star;
55 using namespace ::com::sun::star::container;
56 using namespace ::com::sun::star::sdb;
57 using namespace ::com::sun::star::sdbc;
58 using namespace ::com::sun::star::sdbcx;
60 //-------------------------------------------------------------------------
61 void lcl_Move(Control* pCtrl, long nYOffset)
63 Point aPos(pCtrl->GetPosPixel());
64 aPos.Y() += nYOffset;
65 pCtrl->SetPosPixel(aPos);
67 /*-- 02.04.2004 12:46:40---------------------------------------------------
69 -----------------------------------------------------------------------*/
70 SwMailMergeAddressBlockPage::SwMailMergeAddressBlockPage( SwMailMergeWizard* _pParent) :
71 svt::OWizardPage(_pParent, SW_RES(DLG_MM_ADDRESSBLOCK_PAGE)),
72 #ifdef MSC
73 #pragma warning (disable : 4355)
74 #endif
75 m_aHeaderFI( this, SW_RES( FI_HEADER ) ),
76 m_aFirstFI( this, SW_RES( FI_FIRST ) ),
77 m_aAddressListFI( this, SW_RES( FI_ADDRESSLIST ) ),
78 m_aAddressListPB( this, SW_RES( PB_ADDRESSLIST ) ),
79 m_aCurrentAddressFI( this, SW_RES( FI_CURRENTADDRESS ) ),
80 m_aFirstFL( this, SW_RES( FL_FIRST ) ),
81 m_aSecondFI( this, SW_RES( FI_SECOND )),
82 m_aSettingsFI( this, SW_RES( FI_SECOND ) ),
83 m_aAddressCB( this, SW_RES( CB_ADDRESS ) ),
84 m_aSettingsWIN( this, SW_RES( WIN_SETTINGS ) ),
85 m_aSettingsPB( this, SW_RES( PB_SETTINGS ) ),
86 m_aHideEmptyParagraphsCB( this, SW_RES( CB_HIDE_EMPTY_PARA ) ),
87 m_aSecondFL( this, SW_RES( FL_SECOND )),
88 m_aThirdFI( this, SW_RES( FI_THIRD ) ),
89 m_aMatchFieldsFI( this, SW_RES( FI_MATCH_FIELDS ) ),
90 m_aAssignPB( this, SW_RES( PB_ASSIGN ) ),
91 m_aThirdFL( this, SW_RES( FL_THIRD ) ),
92 m_aFourthFI( this, SW_RES( FI_FOURTH ) ),
93 m_aPreviewFI( this, SW_RES( FI_PREVIEW ) ),
94 m_aPreviewWIN( this, SW_RES( WIN_PREVIEW ) ),
95 m_aDocumentIndexFI( this, SW_RES( FI_DOCINDEX ) ),
96 m_aPrevSetIB( this, SW_RES( IB_PREVSET ) ),
97 m_aNextSetIB( this, SW_RES( IB_NEXTSET ) ),
98 #ifdef MSC
99 #pragma warning (default : 4355)
100 #endif
101 m_sDocument( SW_RES( STR_DOCUMENT ) ),
102 m_sChangeAddress( SW_RES( STR_CHANGEADDRESS )),
103 m_pWizard(_pParent)
105 FreeResource();
106 m_sCurrentAddress = m_aCurrentAddressFI.GetText();
107 m_aAddressListPB.SetClickHdl(LINK(this, SwMailMergeAddressBlockPage, AddressListHdl_Impl));
108 m_aSettingsPB.SetClickHdl(LINK(this, SwMailMergeAddressBlockPage, SettingsHdl_Impl));
109 m_aAssignPB.SetClickHdl(LINK(this, SwMailMergeAddressBlockPage, AssignHdl_Impl ));
110 m_aAddressCB.SetClickHdl(LINK(this, SwMailMergeAddressBlockPage, AddressBlockHdl_Impl));
111 m_aSettingsWIN.SetSelectHdl(LINK(this, SwMailMergeAddressBlockPage, AddressBlockSelectHdl_Impl));
112 m_aHideEmptyParagraphsCB.SetClickHdl(LINK(this, SwMailMergeAddressBlockPage, HideParagraphsHdl_Impl));
114 Link aLink = LINK(this, SwMailMergeAddressBlockPage, InsertDataHdl_Impl);
115 m_aPrevSetIB.SetClickHdl(aLink);
116 m_aNextSetIB.SetClickHdl(aLink);
118 /*-- 02.04.2004 12:46:40---------------------------------------------------
120 -----------------------------------------------------------------------*/
121 SwMailMergeAddressBlockPage::~SwMailMergeAddressBlockPage()
124 /*-- 05.07.2004 13:55:15---------------------------------------------------
126 -----------------------------------------------------------------------*/
127 bool SwMailMergeAddressBlockPage::canAdvance() const
129 return m_pWizard->GetConfigItem().GetResultSet().is();
131 /*-- 16.06.2004 12:34:09---------------------------------------------------
133 -----------------------------------------------------------------------*/
134 void SwMailMergeAddressBlockPage::ActivatePage()
136 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
137 bool bIsLetter = rConfigItem.IsOutputToLetter();
139 //no address block is created for e-Mail
140 m_aSettingsFI.Show( bIsLetter );
141 m_aAddressCB.Show( bIsLetter );
142 m_aSettingsWIN.Show( bIsLetter );
143 m_aSettingsPB.Show( bIsLetter );
144 m_aPreviewFI.Show( bIsLetter );
145 m_aPreviewWIN.Show( bIsLetter );
146 m_aAssignPB.Show( bIsLetter );
147 m_aDocumentIndexFI.Show( bIsLetter );
148 m_aPrevSetIB.Show( bIsLetter );
149 m_aNextSetIB.Show( bIsLetter );
150 m_aHideEmptyParagraphsCB.Show( bIsLetter );
151 m_aSecondFL.Show( bIsLetter );
152 m_aSecondFI.Show( bIsLetter );
153 m_aSettingsFI.Show( bIsLetter );
154 m_aMatchFieldsFI.Show( bIsLetter );
155 m_aThirdFI.Show( bIsLetter );
156 m_aThirdFL.Show( bIsLetter );
157 m_aFourthFI.Show( bIsLetter );
159 if(bIsLetter)
161 m_aHideEmptyParagraphsCB.Check( rConfigItem.IsHideEmptyParagraphs() );
162 String sTemp(m_sDocument);
163 sTemp.SearchAndReplaceAscii("%1", String::CreateFromInt32(1));
164 m_aDocumentIndexFI.SetText(sTemp);
166 m_aSettingsWIN.Clear();
167 const uno::Sequence< ::rtl::OUString> aBlocks =
168 m_pWizard->GetConfigItem().GetAddressBlocks();
169 for(sal_Int32 nAddress = 0; nAddress < aBlocks.getLength(); ++nAddress)
170 m_aSettingsWIN.AddAddress(aBlocks[nAddress]);
171 m_aSettingsWIN.SelectAddress((sal_uInt16)rConfigItem.GetCurrentAddressBlockIndex());
172 m_aAddressCB.Check(rConfigItem.IsAddressBlock());
173 AddressBlockHdl_Impl(&m_aAddressCB);
174 m_aSettingsWIN.SetLayout(1, 2);
175 InsertDataHdl_Impl(0);
178 /*-- 27.05.2004 13:59:15---------------------------------------------------
180 -----------------------------------------------------------------------*/
181 sal_Bool SwMailMergeAddressBlockPage::commitPage( CommitPageReason _eReason )
183 if ( eTravelForward == _eReason && !m_pWizard->GetConfigItem().GetResultSet().is() )
184 return sal_False;
185 return sal_True;
187 /*-- 07.04.2004 16:19:30---------------------------------------------------
189 -----------------------------------------------------------------------*/
190 IMPL_LINK(SwMailMergeAddressBlockPage, AddressListHdl_Impl, PushButton*, EMPTYARG)
192 SwAddressListDialog* pAddrDialog = new SwAddressListDialog(this);
193 if(RET_OK == pAddrDialog->Execute())
195 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
196 rConfigItem.SetCurrentConnection(
197 pAddrDialog->GetSource(),
198 pAddrDialog->GetConnection(),
199 pAddrDialog->GetColumnsSupplier(),
200 pAddrDialog->GetDBData());
201 ::rtl::OUString sFilter = pAddrDialog->GetFilter();
202 rConfigItem.SetFilter( sFilter );
203 InsertDataHdl_Impl(0);
204 GetWizard()->UpdateRoadmap();
205 GetWizard()->enableButtons(WZB_NEXT, GetWizard()->isStateEnabled(MM_GREETINGSPAGE));
207 delete pAddrDialog;
208 return 0;
210 /*-- 07.04.2004 16:19:30---------------------------------------------------
212 -----------------------------------------------------------------------*/
213 IMPL_LINK(SwMailMergeAddressBlockPage, SettingsHdl_Impl, PushButton*, pButton)
215 SwSelectAddressBlockDialog* pDlg =
216 new SwSelectAddressBlockDialog(pButton, m_pWizard->GetConfigItem());
217 SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
218 pDlg->SetAddressBlocks(rConfig.GetAddressBlocks(), m_aSettingsWIN.GetSelectedAddress());
219 pDlg->SetSettings(rConfig.IsIncludeCountry(), rConfig.GetExcludeCountry());
220 if(RET_OK == pDlg->Execute())
222 //the dialog provides the selected address at the first position!
223 const uno::Sequence< ::rtl::OUString> aBlocks =
224 pDlg->GetAddressBlocks();
225 rConfig.SetAddressBlocks(aBlocks);
226 m_aSettingsWIN.Clear();
227 for(sal_Int32 nAddress = 0; nAddress < aBlocks.getLength(); ++nAddress)
228 m_aSettingsWIN.AddAddress(aBlocks[nAddress]);
229 m_aSettingsWIN.SelectAddress(0);
230 m_aSettingsWIN.Invalidate(); // #i40408
231 rConfig.SetCountrySettings(pDlg->IsIncludeCountry(), pDlg->GetCountry());
232 InsertDataHdl_Impl(0);
234 delete pDlg;
235 GetWizard()->UpdateRoadmap();
236 GetWizard()->enableButtons(WZB_NEXT, GetWizard()->isStateEnabled(MM_GREETINGSPAGE));
237 return 0;
239 /*-- 07.04.2004 16:19:31---------------------------------------------------
241 -----------------------------------------------------------------------*/
242 IMPL_LINK(SwMailMergeAddressBlockPage, AssignHdl_Impl, PushButton*, pButton)
244 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
245 sal_uInt16 nSel = m_aSettingsWIN.GetSelectedAddress();
246 const uno::Sequence< ::rtl::OUString> aBlocks = rConfigItem.GetAddressBlocks();
247 SwAssignFieldsDialog* pDlg =
248 new SwAssignFieldsDialog(pButton, m_pWizard->GetConfigItem(), aBlocks[nSel], true);
249 if(RET_OK == pDlg->Execute())
251 //preview update
252 InsertDataHdl_Impl(0);
253 GetWizard()->UpdateRoadmap();
254 GetWizard()->enableButtons(WZB_NEXT, GetWizard()->isStateEnabled(MM_GREETINGSPAGE));
256 delete pDlg;
257 return 0;
259 /*-- 11.06.2004 13:37:22---------------------------------------------------
261 -----------------------------------------------------------------------*/
262 void SwMailMergeAddressBlockPage::EnableAddressBlock(sal_Bool bAll, sal_Bool bSelective)
264 m_aSettingsFI.Enable(bAll);
265 m_aAddressCB.Enable(bAll);
266 bSelective &= bAll;
267 m_aHideEmptyParagraphsCB.Enable(bSelective);
268 m_aSettingsWIN.Enable(bSelective);
269 m_aSettingsPB.Enable(bSelective);
270 m_aPreviewFI.Enable(bSelective);
271 m_aPreviewWIN.Enable(bSelective);
272 m_aThirdFI.Enable(bSelective);
273 m_aMatchFieldsFI.Enable(bSelective);
274 m_aAssignPB.Enable(bSelective);
275 m_aDocumentIndexFI.Enable(bSelective);
276 m_aPrevSetIB.Enable(bSelective);
277 m_aNextSetIB.Enable(bSelective);
279 /*-- 28.04.2004 12:45:58---------------------------------------------------
281 -----------------------------------------------------------------------*/
282 IMPL_LINK(SwMailMergeAddressBlockPage, AddressBlockHdl_Impl, CheckBox*, pBox)
284 EnableAddressBlock(pBox->IsEnabled(), pBox->IsChecked());
285 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
286 rConfigItem.SetAddressBlock(m_aAddressCB.IsChecked());
287 m_pWizard->UpdateRoadmap();
288 return 0;
290 /*-- 08.06.2004 13:00:29---------------------------------------------------
292 -----------------------------------------------------------------------*/
293 IMPL_LINK(SwMailMergeAddressBlockPage, AddressBlockSelectHdl_Impl, SwAddressPreview*, EMPTYARG)
295 sal_uInt16 nSel = m_aSettingsWIN.GetSelectedAddress();
296 const uno::Sequence< ::rtl::OUString> aBlocks =
297 m_pWizard->GetConfigItem().GetAddressBlocks();
298 String sPreview = SwAddressPreview::FillData(aBlocks[nSel], m_pWizard->GetConfigItem());
299 m_aPreviewWIN.SetAddress(sPreview);
300 m_pWizard->GetConfigItem().SetCurrentAddressBlockIndex( nSel );
301 GetWizard()->UpdateRoadmap();
302 GetWizard()->enableButtons(WZB_NEXT, GetWizard()->isStateEnabled(MM_GREETINGSPAGE));
303 return 0;
305 /*-- 31.08.2005 15:34:55---------------------------------------------------
307 -----------------------------------------------------------------------*/
308 IMPL_LINK(SwMailMergeAddressBlockPage, HideParagraphsHdl_Impl, CheckBox*, pBox)
310 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
311 rConfigItem.SetHideEmptyParagraphs( pBox->IsChecked() );
312 return 0;
315 // ------------------------------------------------------------------------------
316 IMPL_LINK(SwMailMergeAddressBlockPage, InsertDataHdl_Impl, ImageButton*, pButton)
318 //if no pButton is given, the first set has to be pre-set
319 SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
320 m_pWizard->EnterWait();
321 if(!pButton)
323 rConfig.GetResultSet();
325 else
327 BOOL bNext = pButton == &m_aNextSetIB;
328 sal_Int32 nPos = rConfig.GetResultSetPosition();
329 rConfig.MoveResultSet( bNext ? ++nPos : --nPos);
331 m_pWizard->LeaveWait();
332 sal_Int32 nPos = rConfig.GetResultSetPosition();
333 BOOL bEnable = TRUE;
334 if(nPos < 1)
336 bEnable = FALSE;
337 nPos = 1;
339 else
341 //if output type is letter
342 if(m_aSettingsWIN.IsVisible())
344 //Fill data into preview
345 sal_uInt16 nSel = m_aSettingsWIN.GetSelectedAddress();
346 const uno::Sequence< ::rtl::OUString> aBlocks =
347 m_pWizard->GetConfigItem().GetAddressBlocks();
348 String sPreview = SwAddressPreview::FillData(aBlocks[nSel], rConfig);
349 m_aPreviewWIN.SetAddress(sPreview);
352 m_aPrevSetIB.Enable(bEnable);
353 //m_aNextSetIB.Enable(bEnable);
354 //m_aDocumentIndexFI.Enable(bEnable);
355 String sTemp(m_sDocument);
356 sTemp.SearchAndReplaceAscii("%1", String::CreateFromInt32(nPos));
357 m_aDocumentIndexFI.SetText(sTemp);
359 GetWizard()->enableButtons(WZB_NEXT, GetWizard()->isStateEnabled(MM_GREETINGSPAGE));
360 sal_Bool bHasResultSet = rConfig.GetResultSet().is();
361 m_aCurrentAddressFI.Show(bHasResultSet);
362 if(bHasResultSet)
364 String sTmp = m_sCurrentAddress;
365 sTmp.SearchAndReplaceAscii("%1", rConfig.GetCurrentDBData().sDataSource );
366 m_aCurrentAddressFI.SetText(sTmp);
367 m_aAddressListPB.SetText(m_sChangeAddress);
369 EnableAddressBlock(bHasResultSet, m_aAddressCB.IsChecked());
370 return 0;
372 /*-- 13.04.2004 16:01:26---------------------------------------------------
374 -----------------------------------------------------------------------*/
375 SwSelectAddressBlockDialog::SwSelectAddressBlockDialog(
376 Window* pParent, SwMailMergeConfigItem& rConfig) :
377 SfxModalDialog(pParent, SW_RES(DLG_MM_SELECTADDRESSBLOCK)),
378 #ifdef MSC
379 #pragma warning (disable : 4355)
380 #endif
381 m_aSelectFT( this, SW_RES( FT_SELECT)),
382 m_aPreview( this, SW_RES( WIN_PREVIEW)),
383 m_aNewPB( this, SW_RES( PB_NEW)),
384 m_aCustomizePB( this, SW_RES( PB_CUSTOMIZE)),
385 m_aDeletePB( this, SW_RES( PB_DELETE)),
386 m_aSettingsFI( this, SW_RES( FI_SETTINGS)),
387 m_aNeverRB( this, SW_RES( RB_NEVER)),
388 m_aAlwaysRB( this, SW_RES( RB_ALWAYS)),
389 m_aDependentRB( this, SW_RES( RB_DEPENDENT)),
390 m_aCountryED( this, SW_RES( ED_COUNTRY)),
391 m_aSeparatorFL( this, SW_RES( FL_SEPARATOR)),
392 m_aOK( this, SW_RES( PB_OK)),
393 m_aCancel( this, SW_RES( PB_CANCEL)),
394 m_aHelp( this, SW_RES( PB_HELP)),
395 #ifdef MSC
396 #pragma warning (default : 4355)
397 #endif
398 m_rConfig(rConfig)
400 FreeResource();
402 Link aCustomizeHdl = LINK(this, SwSelectAddressBlockDialog, NewCustomizeHdl_Impl);
403 m_aNewPB.SetClickHdl(aCustomizeHdl);
404 m_aCustomizePB.SetClickHdl(aCustomizeHdl);
406 m_aDeletePB.SetClickHdl(LINK(this, SwSelectAddressBlockDialog, DeleteHdl_Impl));
408 Link aLk = LINK(this, SwSelectAddressBlockDialog, IncludeHdl_Impl);
409 m_aNeverRB.SetClickHdl(aLk);
410 m_aAlwaysRB.SetClickHdl(aLk);
411 m_aDependentRB.SetClickHdl(aLk);
412 m_aPreview.SetLayout(2, 2);
413 m_aPreview.EnableScrollBar();
415 /*-- 13.04.2004 16:01:27---------------------------------------------------
417 -----------------------------------------------------------------------*/
418 SwSelectAddressBlockDialog::~SwSelectAddressBlockDialog()
421 /*-- 28.04.2004 11:48:11---------------------------------------------------
423 -----------------------------------------------------------------------*/
424 void SwSelectAddressBlockDialog::SetAddressBlocks(const uno::Sequence< ::rtl::OUString>& rBlocks,
425 sal_uInt16 nSelectedAddress)
427 m_aAddressBlocks = rBlocks;
428 for(sal_Int32 nAddress = 0; nAddress < m_aAddressBlocks.getLength(); ++nAddress)
429 m_aPreview.AddAddress(m_aAddressBlocks[nAddress]);
430 m_aPreview.SelectAddress(nSelectedAddress);
432 /*-- 25.06.2004 10:51:36---------------------------------------------------
433 return the address blocks and put the selected one to the first position
434 -----------------------------------------------------------------------*/
435 const uno::Sequence< ::rtl::OUString >& SwSelectAddressBlockDialog::GetAddressBlocks()
437 //put the selected block to the first position
438 sal_uInt16 nSelect = m_aPreview.GetSelectedAddress();
439 if(nSelect)
441 uno::Sequence< ::rtl::OUString >aTemp = m_aAddressBlocks;
442 ::rtl::OUString* pTemp = aTemp.getArray();
443 pTemp[0] = m_aAddressBlocks[nSelect];
444 sal_uInt32 nIndex = 0;
445 const sal_uInt32 nNumBlocks = m_aAddressBlocks.getLength();
446 for(sal_uInt32 nAddress = 1; nAddress < nNumBlocks; ++nAddress)
448 if(nIndex == nSelect)
449 ++nIndex;
450 pTemp[nAddress] = m_aAddressBlocks[nIndex];
451 nIndex++;
453 m_aAddressBlocks = aTemp;
455 return m_aAddressBlocks;
457 /*-- 28.04.2004 11:48:11---------------------------------------------------
459 -----------------------------------------------------------------------*/
460 void SwSelectAddressBlockDialog::SetSettings(
461 sal_Bool bIsCountry, ::rtl::OUString rCountry)
463 if(bIsCountry)
465 rCountry.getLength() ? m_aDependentRB.Check() : m_aAlwaysRB.Check();
466 m_aCountryED.SetText(rCountry);
468 else
469 m_aNeverRB.Check();
470 m_aDeletePB.Enable(m_aAddressBlocks.getLength() > 1);
472 /*-- 10.05.2004 11:17:06---------------------------------------------------
474 -----------------------------------------------------------------------*/
475 ::rtl::OUString SwSelectAddressBlockDialog::GetCountry() const
477 ::rtl::OUString sRet;
478 if(m_aDependentRB.IsChecked())
479 sRet = m_aCountryED.GetText();
480 return sRet;
483 /*-- 13.04.2004 16:02:32---------------------------------------------------
485 -----------------------------------------------------------------------*/
486 IMPL_LINK(SwSelectAddressBlockDialog, DeleteHdl_Impl, PushButton*, pButton)
488 if(m_aAddressBlocks.getLength())
490 sal_uInt16 nSelected = m_aPreview.GetSelectedAddress();
491 ::rtl::OUString* pAddressBlocks = m_aAddressBlocks.getArray();
492 sal_Int32 nSource = 0;
493 for(sal_Int32 nTarget = 0; nTarget < m_aAddressBlocks.getLength() - 1; nTarget++)
495 if(nSource == nSelected)
496 ++nSource;
497 pAddressBlocks[nTarget] = pAddressBlocks[nSource++];
499 m_aAddressBlocks.realloc(m_aAddressBlocks.getLength() - 1);
500 if(m_aAddressBlocks.getLength() <= 1)
501 pButton->Enable(sal_False);
502 m_aPreview.RemoveSelectedAddress();
504 return 0;
506 /*-- 13.04.2004 16:02:32---------------------------------------------------
508 -----------------------------------------------------------------------*/
509 IMPL_LINK(SwSelectAddressBlockDialog, NewCustomizeHdl_Impl, PushButton*, pButton)
511 bool bCustomize = pButton == &m_aCustomizePB;
512 SwCustomizeAddressBlockDialog::DialogType nType = bCustomize ?
513 SwCustomizeAddressBlockDialog::ADDRESSBLOCK_EDIT :
514 SwCustomizeAddressBlockDialog::ADDRESSBLOCK_NEW;
515 SwCustomizeAddressBlockDialog *pDlg =
516 new SwCustomizeAddressBlockDialog(pButton,m_rConfig,nType);
517 if(bCustomize)
519 pDlg->SetAddress(m_aAddressBlocks[m_aPreview.GetSelectedAddress()]);
521 if(RET_OK == pDlg->Execute())
523 if(bCustomize)
525 ::rtl::OUString sNew = pDlg->GetAddress();
526 m_aPreview.ReplaceSelectedAddress(sNew);
527 m_aAddressBlocks[m_aPreview.GetSelectedAddress()] = sNew;
529 else
531 ::rtl::OUString sNew = pDlg->GetAddress();
532 m_aPreview.AddAddress(sNew);
533 m_aAddressBlocks.realloc(m_aAddressBlocks.getLength() + 1);
534 sal_uInt16 nSelect = (sal_uInt16)m_aAddressBlocks.getLength() - 1;
535 m_aAddressBlocks[nSelect] = sNew;
536 m_aPreview.SelectAddress(nSelect);
538 m_aDeletePB.Enable( m_aAddressBlocks.getLength() > 1);
540 delete pDlg;
541 return 0;
543 /*-- 13.04.2004 16:02:33---------------------------------------------------
545 -----------------------------------------------------------------------*/
546 IMPL_LINK(SwSelectAddressBlockDialog, IncludeHdl_Impl, RadioButton*, pButton)
548 m_aCountryED.Enable(&m_aDependentRB == pButton);
549 return 0;
552 /* -----------------------------28.02.05 09:00--------------------------------
554 ---------------------------------------------------------------------------*/
555 SwRestrictedComboBox::~SwRestrictedComboBox()
558 /* -----------------------------28.02.05 09:00--------------------------------
560 ---------------------------------------------------------------------------*/
561 void SwRestrictedComboBox::KeyInput(const KeyEvent& rEvt)
563 BOOL bCallParent = TRUE;
564 if(rEvt.GetCharCode())
566 String sKey = rEvt.GetCharCode();
567 if( STRING_NOTFOUND != sForbiddenChars.Search(sKey))
568 bCallParent = FALSE;
570 if(bCallParent)
571 ComboBox::KeyInput(rEvt);
573 /* -----------------------------28.02.05 09:00--------------------------------
575 ---------------------------------------------------------------------------*/
576 void SwRestrictedComboBox::Modify()
578 Selection aSel = GetSelection();
579 String sTemp = GetText();
580 for(USHORT i = 0; i < sForbiddenChars.Len(); i++)
582 sTemp.EraseAllChars( sForbiddenChars.GetChar(i) );
584 USHORT nDiff = GetText().Len() - sTemp.Len();
585 if(nDiff)
587 aSel.setMin(aSel.getMin() - nDiff);
588 aSel.setMax(aSel.getMin());
589 SetText(sTemp);
590 SetSelection(aSel);
592 if(GetModifyHdl().IsSet())
593 GetModifyHdl().Call(this);
596 /*-- 13.04.2004 16:01:08---------------------------------------------------
598 -----------------------------------------------------------------------*/
599 #define USER_DATA_SALUTATION -1
600 #define USER_DATA_PUNCTUATION -2
601 #define USER_DATA_TEXT -3
602 #define USER_DATA_NONE -4
604 SwCustomizeAddressBlockDialog::SwCustomizeAddressBlockDialog(
605 Window* pParent, SwMailMergeConfigItem& rConfig, DialogType eType) :
606 SfxModalDialog(pParent, SW_RES(DLG_MM_CUSTOMIZEADDRESSBLOCK)),
607 #ifdef MSC
608 #pragma warning (disable : 4355)
609 #endif
610 m_aAddressElementsFT( this, SW_RES( FT_ADDRESSELEMENTS )),
611 m_aAddressElementsLB( this, SW_RES( LB_ADDRESSELEMENTS )),
612 m_aInsertFieldIB( this, SW_RES( IB_INSERTFIELD )),
613 m_aRemoveFieldIB( this, SW_RES( IB_REMOVEFIELD )),
614 m_aDragFT( this, SW_RES( FT_DRAG )),
615 m_aDragED( this, SW_RES( ED_DRAG )),
616 m_aUpIB( this, SW_RES( IB_UP )),
617 m_aLeftIB( this, SW_RES( IB_LEFT )),
618 m_aRightIB( this, SW_RES( IB_RIGHT )),
619 m_aDownIB( this, SW_RES( IB_DOWN )),
620 m_aFieldFT( this, SW_RES( FT_FIELD )),
621 m_aFieldCB( this, SW_RES( CB_FIELD )),
622 m_aPreviewFI( this, SW_RES( FI_PREVIEW )),
623 m_aPreviewWIN( this, SW_RES( WIN_PREVIEW )),
624 m_aSeparatorFL( this, SW_RES( FL_SEPARATOR )),
625 m_aOK( this, SW_RES( PB_OK )),
626 m_aCancel( this, SW_RES( PB_CANCEL )),
627 m_aHelp( this, SW_RES( PB_HELP )),
628 #ifdef MSC
629 #pragma warning (default : 4355)
630 #endif
631 m_rConfigItem(rConfig),
632 m_eType(eType)
634 m_aFieldCB.SetForbiddenChars( String::CreateFromAscii("<>"));
635 m_aDragED.SetStyle(m_aDragED.GetStyle() |WB_NOHIDESELECTION);
636 if( eType >= GREETING_FEMALE )
638 m_aFieldFT.Show();
639 m_aFieldCB.Show();
640 SvLBoxEntry* pEntry = m_aAddressElementsLB.InsertEntry(String(SW_RES(ST_SALUTATION )));
641 pEntry->SetUserData((void*)(sal_Int32)USER_DATA_SALUTATION );
642 pEntry = m_aAddressElementsLB.InsertEntry(String(SW_RES(ST_PUNCTUATION)));
643 pEntry->SetUserData((void*)(sal_Int32)USER_DATA_PUNCTUATION );
644 pEntry = m_aAddressElementsLB.InsertEntry(String(SW_RES(ST_TEXT )));
645 pEntry->SetUserData((void*)(sal_Int32)USER_DATA_TEXT );
646 ResStringArray aSalutArr(SW_RES(
647 eType == GREETING_MALE ? RA_SALUTATION_MALE : RA_SALUTATION_FEMALE));
648 sal_uInt16 i;
649 for(i = 0; i < aSalutArr.Count(); ++i)
650 m_aSalutations.push_back(aSalutArr.GetString(i));
651 ResStringArray aPunctArr(SW_RES(RA_PUNCTUATION));
652 for(i = 0; i < aPunctArr.Count(); ++i)
653 m_aPunctuations.push_back(aPunctArr.GetString(i));
654 m_aDragED.SetText(String::CreateFromAscii(" "));
655 SetText( String( SW_RES( eType == GREETING_MALE ? ST_TITLE_MALE : ST_TITLE_FEMALE)));
656 m_aAddressElementsFT.SetText(String(SW_RES(ST_SALUTATIONELEMENTS)));
657 m_aInsertFieldIB.SetQuickHelpText(String(SW_RES(ST_INSERTSALUTATIONFIELD)));
658 m_aRemoveFieldIB.SetQuickHelpText(String(SW_RES(ST_REMOVESALUTATIONFIELD)));
659 m_aDragFT.SetText(String(SW_RES(ST_DRAGSALUTATION)));
661 else
663 if(eType == ADDRESSBLOCK_EDIT)
664 SetText(String(SW_RES(ST_TITLE_EDIT)));
666 //resize the preview
667 Point aFieldPos(m_aFieldFT.GetPosPixel());
668 long nDiff = m_aPreviewFI.GetPosPixel().Y() - aFieldPos.Y();
669 m_aPreviewFI.SetPosPixel(aFieldPos);
670 Size aPreviewSize = m_aPreviewWIN.GetSizePixel();
671 aPreviewSize.Height() += nDiff;
672 m_aPreviewWIN.SetSizePixel(aPreviewSize);
673 m_aPreviewWIN.SetPosPixel(m_aFieldCB.GetPosPixel());
674 m_aDragED.SetText(String::CreateFromAscii("\n\n\n\n\n"));
676 FreeResource();
677 const ResStringArray& rHeaders = m_rConfigItem.GetDefaultAddressHeaders();
678 for(USHORT i = 0; i < rHeaders.Count(); ++i)
680 const XubString& rHeader = rHeaders.GetString( i );
681 SvLBoxEntry* pEntry = m_aAddressElementsLB.InsertEntry(rHeader);
682 pEntry->SetUserData((void*)(sal_Int32)i);
684 m_aOK.SetClickHdl(LINK(this, SwCustomizeAddressBlockDialog, OKHdl_Impl));
685 m_aAddressElementsLB.SetSelectHdl(LINK(this, SwCustomizeAddressBlockDialog, ListBoxSelectHdl_Impl ));
686 m_aDragED.SetModifyHdl(LINK(this, SwCustomizeAddressBlockDialog, EditModifyHdl_Impl));
687 m_aDragED.SetSelectionChangedHdl( LINK( this, SwCustomizeAddressBlockDialog, SelectionChangedHdl_Impl));
688 Link aFieldsLink = LINK(this, SwCustomizeAddressBlockDialog, FieldChangeHdl_Impl);
689 m_aFieldCB.SetModifyHdl(aFieldsLink);
690 m_aFieldCB.SetSelectHdl(aFieldsLink);
691 Link aImgButtonHdl = LINK(this, SwCustomizeAddressBlockDialog, ImageButtonHdl_Impl);
692 m_aInsertFieldIB.SetClickHdl(aImgButtonHdl);
693 m_aRemoveFieldIB.SetClickHdl(aImgButtonHdl);
694 m_aUpIB.SetClickHdl(aImgButtonHdl);
695 m_aLeftIB.SetClickHdl(aImgButtonHdl);
696 m_aRightIB.SetClickHdl(aImgButtonHdl);
697 m_aDownIB.SetClickHdl(aImgButtonHdl);
698 UpdateImageButtons_Impl();
700 /*-- 13.04.2004 16:01:08---------------------------------------------------
702 -----------------------------------------------------------------------*/
703 SwCustomizeAddressBlockDialog::~SwCustomizeAddressBlockDialog()
706 /*-- 07.06.2004 13:51:11---------------------------------------------------
708 -----------------------------------------------------------------------*/
709 IMPL_LINK(SwCustomizeAddressBlockDialog, OKHdl_Impl, OKButton*, EMPTYARG)
711 EndDialog(RET_OK);
712 return 0;
714 /*-- 24.06.2004 11:36:05---------------------------------------------------
716 -----------------------------------------------------------------------*/
717 IMPL_LINK(SwCustomizeAddressBlockDialog, ListBoxSelectHdl_Impl, DDListBox*, pBox)
719 sal_Int32 nUserData = (sal_Int32)(sal_IntPtr)pBox->FirstSelected()->GetUserData();
720 // Check if the selected entry is already in the address and then forbid inserting
721 m_aInsertFieldIB.Enable(nUserData >= 0 || !HasItem_Impl(nUserData));
722 return 0;
724 /*-- 25.06.2004 11:21:24---------------------------------------------------
726 -----------------------------------------------------------------------*/
727 IMPL_LINK(SwCustomizeAddressBlockDialog, EditModifyHdl_Impl, AddressMultiLineEdit*, EMPTYARG)
729 String sAddress = SwAddressPreview::FillData(
730 GetAddress(),
731 m_rConfigItem);
732 m_aPreviewWIN.SetAddress(sAddress);
733 UpdateImageButtons_Impl();
734 return 0;
736 /*-- 25.06.2004 12:14:11---------------------------------------------------
738 -----------------------------------------------------------------------*/
739 IMPL_LINK(SwCustomizeAddressBlockDialog, ImageButtonHdl_Impl, ImageButton*, pButton)
741 if(&m_aInsertFieldIB == pButton)
743 SvLBoxEntry* pEntry = m_aAddressElementsLB.GetCurEntry();
744 if(pEntry)
746 String sEntry = m_aAddressElementsLB.GetEntryText(pEntry);
747 sEntry.Insert('<', 0);
748 sEntry += '>';
749 m_aDragED.InsertNewEntry(sEntry);
752 else if(&m_aRemoveFieldIB == pButton)
754 m_aDragED.RemoveCurrentEntry();
756 else
758 sal_uInt16 nMove = MOVE_ITEM_DOWN;
759 if(&m_aUpIB == pButton)
760 nMove = MOVE_ITEM_UP;
761 else if(&m_aLeftIB == pButton)
762 nMove = MOVE_ITEM_LEFT;
763 else if(&m_aRightIB == pButton)
764 nMove = MOVE_ITEM_RIGHT;
765 m_aDragED.MoveCurrentItem(nMove);
767 UpdateImageButtons_Impl();
768 return 0;
770 /*-- 01.07.2004 09:27:02---------------------------------------------------
772 -----------------------------------------------------------------------*/
773 sal_Int32 SwCustomizeAddressBlockDialog::GetSelectedItem_Impl()
775 sal_Int32 nRet = USER_DATA_NONE;
776 String sSelected = m_aDragED.GetCurrentItem();
777 if(sSelected.Len())
778 for(ULONG i = 0; i < m_aAddressElementsLB.GetEntryCount(); ++i)
780 SvLBoxEntry* pEntry = m_aAddressElementsLB.GetEntry(i);
781 String sEntry = m_aAddressElementsLB.GetEntryText(pEntry);
782 if( sSelected.Equals( sEntry, 1, sSelected.Len() - 2 ) )
784 nRet = (sal_Int32)(sal_IntPtr)pEntry->GetUserData();
785 break;
788 return nRet;
790 /*-- 01.07.2004 10:01:19---------------------------------------------------
792 -----------------------------------------------------------------------*/
793 bool SwCustomizeAddressBlockDialog::HasItem_Impl(sal_Int32 nUserData)
795 //get the entry from the ListBox
796 String sEntry;
797 for(ULONG i = 0; i < m_aAddressElementsLB.GetEntryCount(); ++i)
799 SvLBoxEntry* pEntry = m_aAddressElementsLB.GetEntry(i);
800 if((sal_Int32)(sal_IntPtr)pEntry->GetUserData() == nUserData)
802 sEntry = m_aAddressElementsLB.GetEntryText(pEntry);
803 break;
806 //put it into '<>'
807 sEntry += '>';
808 sEntry.Insert( '<', 0);
809 //search for this entry in the content
810 String sText = m_aDragED.GetText();
811 bool bRet = sText.Search(sEntry) != STRING_NOTFOUND;
812 return bRet;
814 /*-- 25.06.2004 13:10:16---------------------------------------------------
816 -----------------------------------------------------------------------*/
817 IMPL_LINK(SwCustomizeAddressBlockDialog, SelectionChangedHdl_Impl, AddressMultiLineEdit*, pEdit)
819 // called in case the selection of the edit field changes.
820 // determine selection - if it's one of the editable fields then
821 // enable the related ComboBox and fill it
822 static bool bOnEntry = false;
823 if(bOnEntry)
824 return 0;
826 bOnEntry = true;
827 sal_Int32 nSelected = GetSelectedItem_Impl();
828 if(USER_DATA_NONE != nSelected)
829 pEdit->SelectCurrentItem();
831 if(m_aFieldCB.IsVisible() && (USER_DATA_NONE != nSelected) && (nSelected < 0))
833 //search in ListBox if it's one of the first entries
834 String sSelect;
835 ::std::vector<String>* pVector = 0;
836 switch(nSelected) {
837 case USER_DATA_SALUTATION:
838 sSelect = m_sCurrentSalutation;
839 pVector = &m_aSalutations;
840 break;
841 case USER_DATA_PUNCTUATION:
842 sSelect = m_sCurrentPunctuation;
843 pVector = &m_aPunctuations;
844 break;
845 case USER_DATA_TEXT:
846 sSelect = m_sCurrentText;
847 break;
849 m_aFieldCB.Clear();
850 if(pVector) {
851 ::std::vector<String>::iterator aIterator;
852 for( aIterator = pVector->begin(); aIterator != pVector->end(); ++aIterator)
853 m_aFieldCB.InsertEntry(*aIterator);
855 m_aFieldCB.SetText(sSelect);
856 m_aFieldCB.Enable(sal_True);
857 m_aFieldFT.Enable(sal_True);
859 else
861 m_aFieldCB.Enable(sal_False);
862 m_aFieldFT.Enable(sal_False);
865 UpdateImageButtons_Impl();
866 bOnEntry = false;
867 return 0;
869 /*-- 25.06.2004 13:36:29---------------------------------------------------
871 -----------------------------------------------------------------------*/
872 IMPL_LINK(SwCustomizeAddressBlockDialog, FieldChangeHdl_Impl, ComboBox*, EMPTYARG)
874 //changing the field content changes the related members, too
875 sal_Int32 nSelected = GetSelectedItem_Impl();
876 String sContent = m_aFieldCB.GetText();
877 switch(nSelected) {
878 case USER_DATA_SALUTATION:
879 m_sCurrentSalutation = sContent;
880 break;
881 case USER_DATA_PUNCTUATION:
882 m_sCurrentPunctuation = sContent;
883 break;
884 case USER_DATA_TEXT:
885 m_sCurrentText = sContent;
886 break;
888 UpdateImageButtons_Impl();
889 m_aPreviewWIN.SetAddress(GetAddress());
890 m_aDragED.Modify();
891 return 0;
894 /*-- 25.06.2004 12:35:51---------------------------------------------------
896 -----------------------------------------------------------------------*/
897 void SwCustomizeAddressBlockDialog::UpdateImageButtons_Impl()
899 sal_uInt16 nMove = m_aDragED.IsCurrentItemMoveable();
900 m_aUpIB.Enable(nMove & MOVE_ITEM_UP );
901 m_aLeftIB.Enable(nMove & MOVE_ITEM_LEFT );
902 m_aRightIB.Enable(nMove & MOVE_ITEM_RIGHT );
903 m_aDownIB.Enable(nMove & MOVE_ITEM_DOWN);
904 m_aRemoveFieldIB.Enable(m_aDragED.HasCurrentItem() ? sal_True : sal_False);
905 SvLBoxEntry* pEntry = m_aAddressElementsLB.GetCurEntry();
906 m_aInsertFieldIB.Enable( pEntry &&
907 (0 < (sal_Int32)(sal_IntPtr)pEntry->GetUserData() || m_aFieldCB.GetText().Len()));
909 /*-- 28.04.2004 12:04:14---------------------------------------------------
911 -----------------------------------------------------------------------*/
912 void SwCustomizeAddressBlockDialog::SetAddress(const ::rtl::OUString& rAddress)
914 m_aDragED.SetText( rAddress );
915 UpdateImageButtons_Impl();
916 m_aDragED.Modify();
918 /*-- 28.04.2004 12:04:14---------------------------------------------------
920 -----------------------------------------------------------------------*/
921 ::rtl::OUString SwCustomizeAddressBlockDialog::GetAddress()
923 String sAddress(m_aDragED.GetAddress());
924 //remove placeholders by the actual content
925 if(m_aFieldFT.IsVisible())
927 for(ULONG i = 0; i < m_aAddressElementsLB.GetEntryCount(); ++i)
929 SvLBoxEntry* pEntry = m_aAddressElementsLB.GetEntry(i);
930 String sEntry = m_aAddressElementsLB.GetEntryText(pEntry);
931 sEntry += '>';
932 sEntry.Insert('<', 0);
933 sal_Int32 nUserData = (sal_Int32)(sal_IntPtr)pEntry->GetUserData();
934 switch(nUserData)
936 case USER_DATA_SALUTATION : sAddress.SearchAndReplace(sEntry, m_sCurrentSalutation); break;
937 case USER_DATA_PUNCTUATION: sAddress.SearchAndReplace(sEntry, m_sCurrentPunctuation); break;
938 case USER_DATA_TEXT : sAddress.SearchAndReplace(sEntry, m_sCurrentText); break;
942 return sAddress;
944 /*-- 28.02.2005 11:03:35---------------------------------------------------
946 -----------------------------------------------------------------------*/
947 void SwCustomizeAddressBlockDialog::MoveFocus( Window* pMember, bool bNext )
949 ::std::vector< Window* > aControls;
951 aControls.push_back(&m_aAddressElementsLB);
952 aControls.push_back(&m_aInsertFieldIB);
953 aControls.push_back(&m_aRemoveFieldIB);
954 aControls.push_back(&m_aDragED);
955 aControls.push_back(&m_aUpIB);
956 aControls.push_back(&m_aLeftIB);
957 aControls.push_back(&m_aRightIB);
958 aControls.push_back(&m_aDownIB);
959 aControls.push_back(&m_aFieldCB);
960 aControls.push_back(&m_aOK);
961 aControls.push_back(&m_aCancel);
962 aControls.push_back(&m_aHelp);
964 ::std::vector< Window* >::iterator aMemberIter = aControls.begin();
965 for( ; aMemberIter != aControls.end(); ++aMemberIter)
967 if(*aMemberIter == pMember)
968 break;
970 if( aMemberIter == aControls.end() )
972 DBG_ERROR( "Window not found?" );
973 return;
976 if( bNext )
978 ::std::vector< Window* >::iterator aSearch = aMemberIter;
979 ++aSearch;
980 while( true )
982 if( aSearch == aControls.end())
983 aSearch = aControls.begin();
984 else if( (*aSearch)->IsEnabled() )
986 (*aSearch)->GrabFocus();
987 break;
989 else
990 ++aSearch;
993 else
995 ::std::vector< Window* >::iterator aSearch = aMemberIter;
996 if(aSearch == aControls.begin())
997 aSearch = aControls.end();
998 while( true )
1000 if(aSearch == aControls.begin())
1001 aSearch = aControls.end();
1002 else
1003 --aSearch;
1004 if( (*aSearch)->IsEnabled() )
1006 (*aSearch)->GrabFocus();
1007 break;
1013 /*-- 13.04.2004 17:49:45---------------------------------------------------
1015 -----------------------------------------------------------------------*/
1016 class SwAssignFieldsControl : public Control
1018 friend class SwAssignFieldsDialog;
1019 ScrollBar m_aVScroll;
1020 HeaderBar m_aHeaderHB;
1021 Window m_aWindow;
1023 ::std::vector<FixedInfo*> m_aFieldNames;
1024 ::std::vector<ListBox*> m_aMatches;
1025 ::std::vector<FixedInfo*> m_aPreviews;
1027 SwMailMergeConfigItem& m_rConfigItem;
1029 Link m_aModifyHdl;
1031 long m_nLBStartTopPos;
1032 long m_nYOffset;
1033 long m_nFirstYPos;
1035 DECL_LINK(ScrollHdl_Impl, ScrollBar*);
1036 DECL_LINK(MatchHdl_Impl, ListBox*);
1037 DECL_LINK(GotFocusHdl_Impl, ListBox*);
1039 virtual long PreNotify( NotifyEvent& rNEvt );
1040 virtual void Command( const CommandEvent& rCEvt );
1042 void MakeVisible( sal_Int32 nIndex );
1043 public:
1044 SwAssignFieldsControl(Window* pParent, const ResId& rResId,
1045 SwMailMergeConfigItem& rConfigItem);
1046 ~SwAssignFieldsControl();
1048 void SetModifyHdl(const Link& rModifyHdl)
1050 m_aModifyHdl = rModifyHdl;
1051 m_aModifyHdl.Call(this);
1054 /*-- 13.04.2004 17:51:27---------------------------------------------------
1056 -----------------------------------------------------------------------*/
1057 //-------------------------------------------------------------------------
1058 SwAssignFieldsControl::SwAssignFieldsControl(
1059 Window* pParent, const ResId& rResId, SwMailMergeConfigItem& rConfigItem) :
1060 Control(pParent, rResId),
1061 #ifdef MSC
1062 #pragma warning (disable : 4355)
1063 #endif
1064 m_aVScroll(this, ResId(SCR_1, *rResId.GetResMgr() )),
1065 m_aHeaderHB(this, WB_BUTTONSTYLE | WB_BOTTOMBORDER),
1066 m_aWindow(this, ResId(WIN_DATA, *rResId.GetResMgr())),
1067 #ifdef MSC
1068 #pragma warning (default : 4355)
1069 #endif
1070 m_rConfigItem(rConfigItem),
1071 m_nLBStartTopPos(0),
1072 m_nYOffset(0),
1073 m_nFirstYPos(0)
1075 SetStyle(GetStyle()|WB_TABSTOP|WB_DIALOGCONTROL);
1076 SetHelpId(HID_MM_ASSIGN_FIELDS);
1077 long nHBHeight = m_aHeaderHB.CalcWindowSizePixel().Height();
1078 Size aOutputSize(GetOutputSize());
1079 m_aHeaderHB.SetSizePixel(
1080 Size(aOutputSize.Width(), nHBHeight));
1081 m_aHeaderHB.Show();
1082 m_aWindow.SetPosPixel(Point( 0, nHBHeight) );
1083 m_aWindow.SetSizePixel(Size(aOutputSize.Width() - m_aVScroll.GetSizePixel().Width(), aOutputSize.Height() - nHBHeight));
1084 m_aWindow.Show();
1086 //get the name of the default headers
1087 const ResStringArray& rHeaders = rConfigItem.GetDefaultAddressHeaders();
1088 //get the actual data
1089 uno::Reference< XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), uno::UNO_QUERY);
1090 //get the name of the actual columns
1091 uno::Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
1092 uno::Sequence< ::rtl::OUString > aFields;
1093 if(xColAccess.is())
1094 aFields = xColAccess->getElementNames();
1095 const ::rtl::OUString* pFields = aFields.getConstArray();
1097 //get the current assignment list
1098 //each position in this sequence matches the position in the header array rHeaders
1099 //if no assignment is available an empty sequence will be returned
1100 uno::Sequence< ::rtl::OUString> aAssignments = rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
1101 Link aMatchHdl = LINK(this, SwAssignFieldsControl, MatchHdl_Impl);
1102 Link aFocusHdl = LINK(this, SwAssignFieldsControl, GotFocusHdl_Impl);
1103 //fill the controls
1104 for(USHORT i = 0; i < rHeaders.Count(); ++i)
1106 const XubString& rHeader = rHeaders.GetString( i );
1107 FixedInfo* pNewText = new FixedInfo(&m_aWindow, ResId( FT_FIELDS, *rResId.GetResMgr()));
1108 String sLabel(String::CreateFromAscii("<>"));
1109 sLabel.Insert(rHeader, 1);
1110 pNewText->SetText(sLabel);
1111 ListBox* pNewLB = new ListBox(&m_aWindow, ResId(LB_FIELDS, *rResId.GetResMgr()));
1112 pNewLB->SetHelpId( HID_MM_HEADER_0 + i );
1113 pNewLB->SelectEntryPos(0);
1114 for(sal_Int32 nField = 0; nField < aFields.getLength(); ++nField)
1115 pNewLB->InsertEntry(pFields[nField]);
1116 FixedInfo* pNewPreview = new FixedInfo(&m_aWindow, ResId( FT_PREVIEW, *rResId.GetResMgr() ));
1117 //select the ListBox
1118 //if there is an assignment
1119 if(aAssignments.getLength() > i && aAssignments[i].getLength())
1120 pNewLB->SelectEntry(aAssignments[i]);
1121 else //otherwise the current column name may match one of the db columns
1122 pNewLB->SelectEntry(rHeader);
1123 //then the preview can be filled accordingly
1124 if(xColAccess.is() && pNewLB->GetSelectEntryPos() > 0 &&
1125 xColAccess->hasByName(pNewLB->GetSelectEntry()))
1127 uno::Any aCol = xColAccess->getByName(pNewLB->GetSelectEntry());
1128 uno::Reference< XColumn > xColumn;
1129 aCol >>= xColumn;
1130 if(xColumn.is())
1133 pNewPreview->SetText(xColumn->getString());
1135 catch(SQLException& )
1139 if(!i)
1141 //determine the vertical offset, use the bottom position of the ListBox
1142 m_nFirstYPos = m_nYOffset = pNewLB->GetPosPixel().Y();
1143 m_nLBStartTopPos = m_nYOffset;
1144 m_nYOffset += pNewLB->GetSizePixel().Height();
1147 long nMove = m_nYOffset * i;
1148 lcl_Move(pNewText, nMove);
1149 lcl_Move(pNewLB, nMove);
1150 lcl_Move(pNewPreview, nMove);
1151 //set the select handler
1152 pNewLB->SetSelectHdl(aMatchHdl);
1153 pNewLB->SetGetFocusHdl(aFocusHdl);
1155 m_aFieldNames.push_back(pNewText);
1156 m_aMatches.push_back(pNewLB);
1157 m_aPreviews.push_back(pNewPreview);
1159 ListBox* pBottomBox = m_aMatches[rHeaders.Count() -1];
1160 long nYBottom = pBottomBox->GetPosPixel().Y();
1161 nYBottom += pBottomBox->GetDropDownPosSizePixel().GetHeight();
1162 m_aVScroll.SetRange(Range(0, rHeaders.Count()));
1163 m_aVScroll.SetPageSize((aOutputSize.Height() - nHBHeight - m_nLBStartTopPos)/ m_nYOffset);
1164 m_aVScroll.EnableDrag();
1165 m_aVScroll.SetVisibleSize(m_aVScroll.GetPageSize());
1166 m_aVScroll.SetScrollHdl(LINK(this, SwAssignFieldsControl, ScrollHdl_Impl));
1168 FreeResource();
1169 m_aVScroll.SetPosPixel(Point(aOutputSize.Width() - m_aVScroll.GetSizePixel().Width(), nHBHeight));
1170 m_aVScroll.SetSizePixel(Size(m_aVScroll.GetSizePixel().Width(), aOutputSize.Height() - nHBHeight));
1173 /*-- 13.04.2004 17:51:28---------------------------------------------------
1175 -----------------------------------------------------------------------*/
1176 SwAssignFieldsControl::~SwAssignFieldsControl()
1178 ::std::vector<FixedInfo*>::iterator aFIIter;
1179 for(aFIIter = m_aFieldNames.begin(); aFIIter != m_aFieldNames.end(); ++aFIIter)
1180 delete *aFIIter;
1181 ::std::vector<ListBox*>::iterator aLBIter;
1182 for(aLBIter = m_aMatches.begin(); aLBIter != m_aMatches.end(); ++aLBIter)
1183 delete *aLBIter;
1184 for(aFIIter = m_aPreviews.begin(); aFIIter != m_aPreviews.end(); ++aFIIter)
1185 delete *aFIIter;
1188 /*-- 07.05.2004 13:11:26---------------------------------------------------
1190 -----------------------------------------------------------------------*/
1191 void SwAssignFieldsControl::Command( const CommandEvent& rCEvt )
1193 switch ( rCEvt.GetCommand() )
1195 case COMMAND_WHEEL:
1196 case COMMAND_STARTAUTOSCROLL:
1197 case COMMAND_AUTOSCROLL:
1199 const CommandWheelData* pWheelData = rCEvt.GetWheelData();
1200 if(pWheelData && !pWheelData->IsHorz() && COMMAND_WHEEL_ZOOM != pWheelData->GetMode())
1202 HandleScrollCommand( rCEvt, 0, &m_aVScroll );
1205 break;
1206 default:
1207 Control::Command(rCEvt);
1210 /*-- 07.05.2004 13:11:21---------------------------------------------------
1212 -----------------------------------------------------------------------*/
1213 long SwAssignFieldsControl::PreNotify( NotifyEvent& rNEvt )
1215 if(rNEvt.GetType() == EVENT_COMMAND)
1217 const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
1218 USHORT nCmd = pCEvt->GetCommand();
1219 if( COMMAND_WHEEL == nCmd )
1221 Command(*pCEvt);
1222 return 1;
1225 return Control::PreNotify(rNEvt);
1227 /*-- 03.09.2004 13:19:09---------------------------------------------------
1229 -----------------------------------------------------------------------*/
1230 void SwAssignFieldsControl::MakeVisible( sal_Int32 nIndex )
1232 long nThumb = m_aVScroll.GetThumbPos();
1233 long nPage = m_aVScroll.GetPageSize();
1234 if(nThumb > nIndex)
1235 m_aVScroll.SetThumbPos( nIndex );
1236 else if( (nThumb + nPage) < nIndex)
1237 m_aVScroll.SetThumbPos( nIndex - nPage );
1238 else
1239 return;
1240 ScrollHdl_Impl( &m_aVScroll );
1242 /*-- 30.04.2004 16:10:58---------------------------------------------------
1244 -----------------------------------------------------------------------*/
1245 IMPL_LINK(SwAssignFieldsControl, ScrollHdl_Impl, ScrollBar*, pScroll)
1247 long nThumb = pScroll->GetThumbPos();
1248 // the scrollbar moves on a per line basis
1249 // the height of a line is stored in m_nYOffset
1250 // nThumb determines which line has to be set at the top (m_nYOffset)
1251 // The first line has to be -(nThumb * m_nYOffset) in the negative
1252 long nMove = m_nFirstYPos - (*m_aMatches.begin())->GetPosPixel().Y() - (nThumb * m_nYOffset);
1254 SetUpdateMode(FALSE);
1255 long nIndex;
1256 ::std::vector<FixedInfo*>::iterator aFIIter;
1257 for(nIndex = 0, aFIIter = m_aFieldNames.begin(); aFIIter != m_aFieldNames.end(); ++aFIIter, ++nIndex)
1258 lcl_Move(*aFIIter, nMove);
1259 ::std::vector<ListBox*>::iterator aLBIter;
1260 for(nIndex = 0, aLBIter = m_aMatches.begin(); aLBIter != m_aMatches.end(); ++aLBIter, ++nIndex)
1261 lcl_Move(*aLBIter, nMove);
1262 for(nIndex = 0, aFIIter = m_aPreviews.begin(); aFIIter != m_aPreviews.end(); ++aFIIter, ++nIndex)
1263 lcl_Move(*aFIIter, nMove);
1264 SetUpdateMode(TRUE);
1266 return 0;
1269 /*-- 03.05.2004 15:37:52---------------------------------------------------
1271 -----------------------------------------------------------------------*/
1272 IMPL_LINK(SwAssignFieldsControl, MatchHdl_Impl, ListBox*, pBox)
1274 String sColumn = pBox->GetSelectEntry();
1275 uno::Reference< XColumnsSupplier > xColsSupp( m_rConfigItem.GetResultSet(), uno::UNO_QUERY);
1276 uno::Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
1277 ::rtl::OUString sPreview;
1278 if(xColAccess.is() && xColAccess->hasByName(sColumn))
1280 uno::Any aCol = xColAccess->getByName(sColumn);
1281 uno::Reference< XColumn > xColumn;
1282 aCol >>= xColumn;
1283 if(xColumn.is())
1287 sPreview = xColumn->getString();
1289 catch( sdbc::SQLException& )
1294 ::std::vector<ListBox*>::iterator aLBIter;
1295 sal_Int32 nIndex = 0;
1296 for(aLBIter = m_aMatches.begin(); aLBIter != m_aMatches.end(); ++aLBIter, ++nIndex)
1298 if(*aLBIter == pBox)
1300 m_aPreviews[nIndex]->SetText(sPreview);
1301 break;
1304 m_aModifyHdl.Call(0);
1305 return 0;
1307 /*-- 03.09.2004 13:16:04---------------------------------------------------
1309 -----------------------------------------------------------------------*/
1310 IMPL_LINK(SwAssignFieldsControl, GotFocusHdl_Impl, ListBox*, pBox)
1312 if(0 != (GETFOCUS_TAB & pBox->GetGetFocusFlags()))
1314 sal_Int32 nIndex = 0;
1315 ::std::vector<ListBox*>::iterator aLBIter;
1316 for(aLBIter = m_aMatches.begin(); aLBIter != m_aMatches.end(); ++aLBIter, ++nIndex)
1318 if(*aLBIter == pBox)
1320 MakeVisible(nIndex);
1321 break;
1325 return 0;
1327 /*-- 13.04.2004 17:44:01---------------------------------------------------
1329 -----------------------------------------------------------------------*/
1330 SwAssignFieldsDialog::SwAssignFieldsDialog(
1331 Window* pParent, SwMailMergeConfigItem& rConfigItem,
1332 const ::rtl::OUString& rPreview,
1333 bool bIsAddressBlock) :
1334 SfxModalDialog(pParent, SW_RES(DLG_MM_ASSIGNFIELDS)),
1335 #ifdef MSC
1336 #pragma warning (disable : 4355)
1337 #endif
1338 m_aMatchingFI( this, SW_RES( FI_MATCHING)),
1339 m_pFieldsControl( new SwAssignFieldsControl(this, SW_RES( CT_FIELDS ), rConfigItem)),
1340 m_aPreviewFI( this, SW_RES( FI_PREVIEW )),
1341 m_aPreviewWIN( this, SW_RES( WIN_PREVIEW )),
1342 m_aSeparatorFL( this, SW_RES( FL_SEPARATOR)),
1343 m_aOK( this, SW_RES( PB_OK )),
1344 m_aCancel( this, SW_RES( PB_CANCEL )),
1345 m_aHelp( this, SW_RES( PB_HELP )),
1346 #ifdef MSC
1347 #pragma warning (default : 4355)
1348 #endif
1349 m_sNone(SW_RES(ST_NONE)),
1350 m_rPreviewString(rPreview),
1351 m_rConfigItem(rConfigItem)
1353 //resize the HeaderBar
1354 String sAddressElement( SW_RES(ST_ADDRESSELEMENT ));
1355 String sMatchesTo( SW_RES(ST_MATCHESTO ));
1356 String sPreview( SW_RES(ST_PREVIEW ));
1357 if(!bIsAddressBlock)
1359 m_aPreviewFI.SetText(String(SW_RES(ST_SALUTATIONPREVIEW)));
1360 m_aMatchingFI.SetText(String(SW_RES(ST_SALUTATIONMATCHING)));
1361 sAddressElement = String(SW_RES(ST_SALUTATIONELEMENT));
1363 FreeResource();
1364 Size aOutputSize(m_pFieldsControl->m_aHeaderHB.GetSizePixel());
1365 sal_Int32 nFirstWidth;
1366 sal_Int32 nSecondWidth = nFirstWidth = aOutputSize.Width() / 3;
1367 const WinBits nHeadBits = HIB_VCENTER | HIB_FIXED| HIB_FIXEDPOS;
1368 m_pFieldsControl->m_aHeaderHB.InsertItem( 1, sAddressElement, nFirstWidth, nHeadBits|HIB_LEFT);
1369 m_pFieldsControl->m_aHeaderHB.InsertItem( 2, sMatchesTo, nSecondWidth, nHeadBits|HIB_LEFT);
1370 m_pFieldsControl->m_aHeaderHB.InsertItem( 3, sPreview,
1371 aOutputSize.Width() - nFirstWidth - nSecondWidth, nHeadBits|HIB_LEFT);
1373 m_pFieldsControl->SetModifyHdl(LINK(this, SwAssignFieldsDialog, AssignmentModifyHdl_Impl ));
1375 String sMatching = m_aMatchingFI.GetText();
1376 sMatching.SearchAndReplaceAscii("%1", sMatchesTo);
1377 m_aMatchingFI.SetText(sMatching);
1379 m_aOK.SetClickHdl(LINK(this, SwAssignFieldsDialog, OkHdl_Impl));
1381 /*-- 13.04.2004 17:44:02---------------------------------------------------
1383 -----------------------------------------------------------------------*/
1384 SwAssignFieldsDialog::~SwAssignFieldsDialog()
1386 delete m_pFieldsControl;
1388 /*-- 05.05.2004 14:39:13---------------------------------------------------
1390 -----------------------------------------------------------------------*/
1391 uno::Sequence< ::rtl::OUString > SwAssignFieldsDialog::CreateAssignments()
1393 uno::Sequence< ::rtl::OUString > aAssignments(
1394 m_rConfigItem.GetDefaultAddressHeaders().Count());
1395 ::rtl::OUString* pAssignments = aAssignments.getArray();
1396 ::std::vector<ListBox*>::iterator aLBIter;
1397 sal_Int32 nIndex = 0;
1398 for(aLBIter = m_pFieldsControl->m_aMatches.begin();
1399 aLBIter != m_pFieldsControl->m_aMatches.end();
1400 ++aLBIter, ++nIndex)
1402 String sSelect = (*aLBIter)->GetSelectEntry();
1403 if(m_sNone != sSelect)
1404 pAssignments[nIndex] = sSelect;
1405 else
1406 pAssignments[nIndex] = ::rtl::OUString();
1408 return aAssignments;
1410 /*-- 03.05.2004 18:04:00---------------------------------------------------
1412 -----------------------------------------------------------------------*/
1413 IMPL_LINK(SwAssignFieldsDialog, OkHdl_Impl, PushButton*, EMPTYARG)
1415 m_rConfigItem.SetColumnAssignment(
1416 m_rConfigItem.GetCurrentDBData(),
1417 CreateAssignments() );
1418 EndDialog(RET_OK);
1419 return 0;
1421 /*-- 05.05.2004 14:37:19---------------------------------------------------
1423 -----------------------------------------------------------------------*/
1424 IMPL_LINK(SwAssignFieldsDialog, AssignmentModifyHdl_Impl, void*, EMPTYARG)
1426 uno::Sequence< ::rtl::OUString > aAssignments = CreateAssignments();
1427 String sPreview = SwAddressPreview::FillData(
1428 m_rPreviewString, m_rConfigItem, &aAssignments);
1429 m_aPreviewWIN.SetAddress(sPreview);
1430 return 0;
1433 /*-- 26.05.2004 11:20:11---------------------------------------------------
1435 -----------------------------------------------------------------------*/
1436 DDListBox::DDListBox(SwCustomizeAddressBlockDialog* pParent, const ResId rResId) :
1437 SvTreeListBox(pParent, rResId),
1438 m_pParentDialog(pParent)
1440 SetWindowBits( /*WB_HASBUTTONS|WB_HASBUTTONSATROOT|*/
1441 WB_CLIPCHILDREN );
1442 // SetSpaceBetweenEntries(3);
1443 SetSelectionMode( SINGLE_SELECTION );
1444 SetDragDropMode( SV_DRAGDROP_CTRL_COPY );
1445 EnableAsyncDrag(TRUE);
1446 SetHelpId(HID_MM_CUSTOMFIELDS);
1447 // expand selection to the complete width of the ListBox
1448 SetHighlightRange();
1449 Show();
1452 /*-- 26.05.2004 11:20:15---------------------------------------------------
1454 -----------------------------------------------------------------------*/
1455 DDListBox::~DDListBox()
1458 /*-- 26.05.2004 11:20:16---------------------------------------------------
1460 -----------------------------------------------------------------------*/
1461 void DDListBox::StartDrag( sal_Int8 /*nAction*/, const Point& /*rPosPixel*/ )
1463 SvLBoxEntry* pEntry = GetCurEntry();
1464 if(pEntry)
1466 ReleaseMouse();
1468 TransferDataContainer* pContainer = new TransferDataContainer;
1469 uno::Reference<
1470 datatransfer::XTransferable > xRef( pContainer );
1472 sal_Int32 nUserData = (sal_Int32)(sal_IntPtr)pEntry->GetUserData();
1473 //special entries can only be once in the address / greeting
1474 if(nUserData >= 0 || !m_pParentDialog->HasItem_Impl(nUserData))
1476 String sEntry;
1477 sEntry = GetEntryText(pEntry);
1478 sEntry.Insert('<', 0);
1479 sEntry += '>';
1480 if(sEntry.Len())
1482 pContainer->CopyString( sEntry );
1483 pContainer->StartDrag( this, DND_ACTION_COPY, GetDragFinishedHdl() );
1488 /*-- 26.05.2004 13:14:53---------------------------------------------------
1490 -----------------------------------------------------------------------*/
1491 AddressMultiLineEdit::AddressMultiLineEdit(SwCustomizeAddressBlockDialog* pParent, const ResId& rResId) :
1492 MultiLineEdit(pParent, rResId),
1493 m_pParentDialog(pParent)
1496 GetTextView()->SupportProtectAttribute(sal_True);
1497 StartListening(*GetTextEngine());
1498 //DisableSelectionOnFocus();
1499 EnableFocusSelectionHide(FALSE);
1501 /*-- 26.05.2004 13:14:53---------------------------------------------------
1503 -----------------------------------------------------------------------*/
1504 AddressMultiLineEdit::~AddressMultiLineEdit()
1506 EndListening(*GetTextEngine());
1508 /*-- 25.06.2004 13:02:49---------------------------------------------------
1510 -----------------------------------------------------------------------*/
1511 void AddressMultiLineEdit::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
1513 if(rHint.ISA(TextHint) &&
1514 static_cast<const TextHint&>(rHint).GetId() == TEXT_HINT_VIEWSELECTIONCHANGED &&
1515 m_aSelectionLink.IsSet())
1517 m_aSelectionLink.Call(this);
1520 /*-- 26.05.2004 13:45:46---------------------------------------------------
1522 -----------------------------------------------------------------------*/
1523 long AddressMultiLineEdit::PreNotify( NotifyEvent& rNEvt )
1525 long nHandled = 0;
1526 if( EVENT_KEYINPUT == rNEvt.GetType() &&
1527 rNEvt.GetKeyEvent()->GetCharCode())
1529 const KeyEvent* pKEvent = rNEvt.GetKeyEvent();
1530 if('\t' == pKEvent->GetCharCode() &&
1531 0 == (pKEvent->GetKeyCode().GetModifier() & (KEY_MOD1|KEY_MOD2)))
1533 m_pParentDialog->MoveFocus(this, !pKEvent->GetKeyCode().IsShift());
1535 nHandled = 1;
1537 else if(EVENT_MOUSEBUTTONDOWN == rNEvt.GetType()) {
1538 const MouseEvent *pMEvt = rNEvt.GetMouseEvent();
1539 if(pMEvt->GetClicks() >= 2)
1540 nHandled = 1;
1542 if(!nHandled)
1543 nHandled = MultiLineEdit::PreNotify( rNEvt );
1544 return nHandled;
1547 /*-- 25.06.2004 08:20:54---------------------------------------------------
1549 -----------------------------------------------------------------------*/
1550 void AddressMultiLineEdit::SetText( const String& rStr )
1552 MultiLineEdit::SetText(rStr);
1553 //set attributes to all address tokens
1555 ExtTextEngine* pTextEngine = GetTextEngine();
1556 TextAttribProtect aProtectAttr;
1557 ULONG nParaCount = pTextEngine->GetParagraphCount();
1558 for(ULONG nPara = 0; nPara < nParaCount; ++nPara)
1560 xub_StrLen nIndex = 0;
1561 String sPara = pTextEngine->GetText( nPara );
1562 if(sPara.Len() && sPara.GetChar(sPara.Len() - 1) != ' ')
1564 TextPaM aPaM(nPara, sPara.Len());
1565 pTextEngine->ReplaceText(TextSelection( aPaM ), String(' '));
1567 while(true)
1569 USHORT nStart = sPara.Search( '<', nIndex );
1570 USHORT nEnd = sPara.Search( '>', nStart );
1571 nIndex = nEnd;
1572 if(nStart != STRING_NOTFOUND && nEnd != STRING_NOTFOUND)
1573 pTextEngine->SetAttrib( aProtectAttr, nPara, nStart, nEnd + 1, FALSE );
1574 else
1575 break;
1579 // add two empty paragraphs at the end
1580 if(m_pParentDialog->m_eType == SwCustomizeAddressBlockDialog::ADDRESSBLOCK_NEW ||
1581 m_pParentDialog->m_eType == SwCustomizeAddressBlockDialog::ADDRESSBLOCK_EDIT)
1583 xub_StrLen nLastLen = pTextEngine->GetText(nParaCount - 1).Len();
1584 if(nLastLen)
1586 TextPaM aPaM(nParaCount ? nParaCount - 1 : 0, nLastLen);
1587 pTextEngine->ReplaceText( TextSelection( aPaM ), String::CreateFromAscii("\n \n "));
1592 /*-- 25.06.2004 12:32:41---------------------------------------------------
1593 Insert the new entry in front of the entry at the beginning of the selection
1595 -----------------------------------------------------------------------*/
1596 void AddressMultiLineEdit::InsertNewEntry( const String& rStr )
1598 // insert new entry after current selected one.
1599 ExtTextView* pTextView = GetTextView();
1600 const TextSelection& rSelection = pTextView->GetSelection();
1601 ULONG nPara = rSelection.GetStart().GetPara();
1602 USHORT nIndex = rSelection.GetEnd().GetIndex();
1603 ExtTextEngine *pTextEngine = GetTextEngine();
1604 const TextCharAttrib *pAttrib;
1605 if(0 != (pAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED )))
1606 nIndex = pAttrib->GetEnd();
1607 InsertNewEntryAtPosition( rStr, nPara, nIndex );
1609 // select the new entry
1610 pAttrib = pTextEngine->FindCharAttrib(TextPaM(nPara, nIndex),TEXTATTR_PROTECTED);
1611 TextSelection aEntrySel(TextPaM(nPara, nIndex), TextPaM(nPara, pAttrib->GetEnd()));
1612 pTextView->SetSelection(aEntrySel);
1613 Invalidate();
1614 Modify();
1617 void AddressMultiLineEdit::InsertNewEntryAtPosition( const String& rStr, ULONG nPara, USHORT nIndex )
1619 ExtTextEngine* pTextEngine = GetTextEngine();
1620 TextPaM aInsertPos( nPara, nIndex );
1622 pTextEngine->ReplaceText( aInsertPos, rStr );
1624 //restore the attributes
1625 SetText( GetAddress() );
1626 //select the newly inserted/moved element
1627 TextSelection aEntrySel(aInsertPos);
1628 ExtTextView* pTextView = GetTextView();
1629 pTextView->SetSelection(aEntrySel);
1630 m_aSelectionLink.Call(this);
1632 /*-- 25.06.2004 12:32:41---------------------------------------------------
1634 -----------------------------------------------------------------------*/
1635 void AddressMultiLineEdit::RemoveCurrentEntry()
1637 ExtTextEngine* pTextEngine = GetTextEngine();
1638 ExtTextView* pTextView = GetTextView();
1639 const TextSelection& rSelection = pTextView->GetSelection();
1640 const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
1641 // const TextCharAttrib* pEndAttrib = pTextEngine->FindCharAttrib( rSelection.GetEnd(), TEXTATTR_PROTECTED );
1642 if(pBeginAttrib &&
1643 (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
1644 && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()))
1646 ULONG nPara = rSelection.GetStart().GetPara();
1647 TextSelection aEntrySel(TextPaM( nPara, pBeginAttrib->GetStart()), TextPaM(nPara, pBeginAttrib->GetEnd()));
1648 pTextEngine->ReplaceText(aEntrySel, String());
1649 //restore the attributes
1650 SetText( GetAddress() );
1651 Modify();
1654 /*-- 25.06.2004 12:32:41---------------------------------------------------
1656 -----------------------------------------------------------------------*/
1657 void AddressMultiLineEdit::MoveCurrentItem(sal_uInt16 nMove)
1659 ExtTextEngine* pTextEngine = GetTextEngine();
1660 ExtTextView* pTextView = GetTextView();
1661 const TextSelection& rSelection = pTextView->GetSelection();
1662 const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
1663 if(pBeginAttrib &&
1664 (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
1665 && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()))
1667 //current item has been found
1668 ULONG nPara = rSelection.GetStart().GetPara();
1669 USHORT nIndex = pBeginAttrib->GetStart();
1670 TextSelection aEntrySel(TextPaM( nPara, pBeginAttrib->GetStart()), TextPaM(nPara, pBeginAttrib->GetEnd()));
1671 String sCurrentItem = pTextEngine->GetText(aEntrySel);
1672 pTextEngine->RemoveAttrib( nPara, *pBeginAttrib );
1673 pTextEngine->ReplaceText(aEntrySel, String());
1674 switch(nMove)
1676 case MOVE_ITEM_LEFT :
1677 if(nIndex)
1679 //go left to find a predecessor or simple text
1680 --nIndex;
1681 String sPara = pTextEngine->GetText( nPara );
1682 xub_StrLen nSearchIndex = sPara.SearchBackward( '>', nIndex+1 );
1683 if( nSearchIndex != STRING_NOTFOUND && nSearchIndex == nIndex )
1685 nSearchIndex = sPara.SearchBackward( '<', nIndex );
1686 if( nSearchIndex != STRING_NOTFOUND )
1687 nIndex = nSearchIndex;
1690 break;
1691 case MOVE_ITEM_RIGHT:
1693 //go right to find a successor or simple text
1694 ++nIndex;
1695 const TextCharAttrib* pEndAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
1696 if(pEndAttrib && pEndAttrib->GetEnd() >= nIndex)
1698 nIndex = pEndAttrib->GetEnd();
1701 break;
1702 case MOVE_ITEM_UP :
1703 --nPara;
1704 nIndex = 0;
1705 break;
1706 case MOVE_ITEM_DOWN :
1707 ++nPara;
1708 nIndex = 0;
1709 break;
1711 //add a new paragraph if there is none yet
1712 if(nPara >= pTextEngine->GetParagraphCount())
1715 TextPaM aTemp(nPara - 1, pTextEngine->GetTextLen( nPara - 1 ));
1716 pTextEngine->ReplaceText( aTemp, String('\n'));
1718 InsertNewEntryAtPosition( sCurrentItem, nPara, nIndex );
1720 // select the new entry [#i40817]
1721 const TextCharAttrib *pAttrib;
1722 pAttrib = pTextEngine->FindCharAttrib(TextPaM(nPara, nIndex),TEXTATTR_PROTECTED);
1723 aEntrySel = TextSelection(TextPaM(nPara, nIndex), TextPaM(nPara, pAttrib->GetEnd()));
1724 pTextView->SetSelection(aEntrySel);
1725 Invalidate();
1726 Modify();
1729 /*-- 25.06.2004 12:32:41---------------------------------------------------
1731 -----------------------------------------------------------------------*/
1732 sal_uInt16 AddressMultiLineEdit::IsCurrentItemMoveable()
1734 sal_uInt16 nRet = 0;
1735 ExtTextEngine* pTextEngine = GetTextEngine();
1736 ExtTextView* pTextView = GetTextView();
1737 const TextSelection& rSelection = pTextView->GetSelection();
1738 const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
1739 // const TextCharAttrib* pEndAttrib = pTextEngine->FindCharAttrib( rSelection.GetEnd(), TEXTATTR_PROTECTED );
1740 if(pBeginAttrib &&
1741 (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
1742 && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()))
1744 if(pBeginAttrib->GetStart())
1745 nRet |= MOVE_ITEM_LEFT;
1746 //if there is an entry it can always be move to the right and down
1747 nRet |= MOVE_ITEM_RIGHT|MOVE_ITEM_DOWN;
1748 if(rSelection.GetStart().GetPara() > 0)
1749 nRet |= MOVE_ITEM_UP;
1751 return nRet;
1753 /*-- 25.06.2004 12:32:42---------------------------------------------------
1755 -----------------------------------------------------------------------*/
1756 bool AddressMultiLineEdit::HasCurrentItem()
1758 ExtTextEngine* pTextEngine = GetTextEngine();
1759 ExtTextView* pTextView = GetTextView();
1760 const TextSelection& rSelection = pTextView->GetSelection();
1761 const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
1762 return (pBeginAttrib &&
1763 (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
1764 && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()));
1766 /*-- 01.07.2004 09:07:44---------------------------------------------------
1768 -----------------------------------------------------------------------*/
1769 String AddressMultiLineEdit::GetCurrentItem()
1771 String sRet;
1772 ExtTextEngine* pTextEngine = GetTextEngine();
1773 ExtTextView* pTextView = GetTextView();
1774 const TextSelection& rSelection = pTextView->GetSelection();
1775 const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
1776 if(pBeginAttrib &&
1777 (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
1778 && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()))
1780 ULONG nPara = rSelection.GetStart().GetPara();
1781 TextSelection aEntrySel(TextPaM( nPara, pBeginAttrib->GetStart()), TextPaM(nPara, pBeginAttrib->GetEnd()));
1782 sRet = pTextEngine->GetText( aEntrySel );
1784 return sRet;
1786 /*-- 05.07.2004 14:29:02---------------------------------------------------
1788 -----------------------------------------------------------------------*/
1789 void AddressMultiLineEdit::SelectCurrentItem()
1791 ExtTextEngine* pTextEngine = GetTextEngine();
1792 ExtTextView* pTextView = GetTextView();
1793 const TextSelection& rSelection = pTextView->GetSelection();
1794 const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
1795 if(pBeginAttrib &&
1796 (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
1797 && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()))
1799 ULONG nPara = rSelection.GetStart().GetPara();
1800 TextSelection aEntrySel(TextPaM( nPara, pBeginAttrib->GetStart()), TextPaM(nPara, pBeginAttrib->GetEnd()));
1801 pTextView->SetSelection(aEntrySel);
1802 Invalidate();
1805 /*-- 25.06.2004 09:10:43---------------------------------------------------
1806 returns the address
1807 remove trailing spaces
1808 and trailing empty paragraphs
1809 -----------------------------------------------------------------------*/
1810 String AddressMultiLineEdit::GetAddress()
1812 String sRet;
1813 ExtTextEngine* pTextEngine = GetTextEngine();
1814 ULONG nParaCount = pTextEngine->GetParagraphCount();
1815 for(ULONG nPara = nParaCount; nPara; --nPara)
1817 String sPara = pTextEngine->GetText( nPara - 1);
1818 sPara.EraseTrailingChars(' ');
1819 //don't add empty trailing paragraphs
1820 if(sRet.Len() || sPara.Len())
1822 sRet.Insert(sPara, 0);
1823 //insert the para break
1824 if(nPara > 1)
1825 sRet.Insert( '\n', 0);
1828 return sRet;