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