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