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 <mmgreetingspage.hxx>
21 : #include <mailmergewizard.hxx>
22 : #include <mmconfigitem.hxx>
23 : #include <mmaddressblockpage.hxx>
24 : #include <swtypes.hxx>
25 : #include <vcl/msgbox.hxx>
26 : #include <dbui.hrc>
27 : #include <com/sun/star/sdb/XColumn.hpp>
28 : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
29 : #include <com/sun/star/container/XNameAccess.hpp>
30 : #include <helpid.h>
31 :
32 : #include <boost/scoped_ptr.hpp>
33 :
34 : using namespace svt;
35 : using namespace ::com::sun::star;
36 : using namespace ::com::sun::star::uno;
37 :
38 0 : static void lcl_FillGreetingsBox(ListBox& rBox,
39 : SwMailMergeConfigItem& rConfig,
40 : SwMailMergeConfigItem::Gender eType)
41 : {
42 0 : const Sequence< OUString> rEntries = rConfig.GetGreetings(eType);
43 0 : for(sal_Int32 nEntry = 0; nEntry < rEntries.getLength(); ++nEntry)
44 0 : rBox.InsertEntry(rEntries[nEntry]);
45 0 : rBox.SelectEntryPos(rConfig.GetCurrentGreeting(eType));
46 0 : }
47 :
48 0 : static void lcl_FillGreetingsBox(ComboBox& rBox,
49 : SwMailMergeConfigItem& rConfig,
50 : SwMailMergeConfigItem::Gender eType)
51 : {
52 0 : const Sequence< OUString> rEntries = rConfig.GetGreetings(eType);
53 0 : for(sal_Int32 nEntry = 0; nEntry < rEntries.getLength(); ++nEntry)
54 0 : rBox.InsertEntry(rEntries[nEntry]);
55 0 : rBox.SelectEntryPos(rConfig.GetCurrentGreeting(eType));
56 0 : }
57 :
58 0 : static void lcl_StoreGreetingsBox(ListBox& rBox,
59 : SwMailMergeConfigItem& rConfig,
60 : SwMailMergeConfigItem::Gender eType)
61 : {
62 0 : Sequence< OUString> aEntries(rBox.GetEntryCount());
63 0 : OUString* pEntries = aEntries.getArray();
64 0 : for(sal_Int32 nEntry = 0; nEntry < rBox.GetEntryCount(); ++nEntry)
65 0 : pEntries[nEntry] = rBox.GetEntry(nEntry);
66 0 : rConfig.SetGreetings(eType, aEntries);
67 0 : rConfig.SetCurrentGreeting(eType, rBox.GetSelectEntryPos());
68 0 : }
69 :
70 0 : static void lcl_StoreGreetingsBox(ComboBox& rBox,
71 : SwMailMergeConfigItem& rConfig,
72 : SwMailMergeConfigItem::Gender eType)
73 : {
74 0 : Sequence< OUString> aEntries(rBox.GetEntryCount());
75 0 : OUString* pEntries = aEntries.getArray();
76 0 : for(sal_Int32 nEntry = 0; nEntry < rBox.GetEntryCount(); ++nEntry)
77 0 : pEntries[nEntry] = rBox.GetEntry(nEntry);
78 0 : rConfig.SetGreetings(eType, aEntries);
79 0 : rConfig.SetCurrentGreeting(eType, rBox.GetSelectEntryPos());
80 0 : }
81 :
82 0 : IMPL_LINK_NOARG(SwGreetingsHandler, IndividualHdl_Impl)
83 : {
84 0 : bool bIndividual = m_pPersonalizedCB->IsEnabled() && m_pPersonalizedCB->IsChecked();
85 0 : m_pFemaleFT->Enable(bIndividual);
86 0 : m_pFemaleLB->Enable(bIndividual);
87 0 : m_pFemalePB->Enable(bIndividual);
88 0 : m_pMaleFT->Enable(bIndividual);
89 0 : m_pMaleLB->Enable(bIndividual);
90 0 : m_pMalePB->Enable(bIndividual);
91 0 : m_pFemaleFI->Enable(bIndividual);
92 0 : m_pFemaleColumnFT->Enable(bIndividual);
93 0 : m_pFemaleColumnLB->Enable(bIndividual);
94 0 : m_pFemaleFieldFT->Enable(bIndividual);
95 0 : m_pFemaleFieldCB->Enable(bIndividual);
96 :
97 0 : if( m_bIsTabPage )
98 : {
99 0 : m_pWizard->GetConfigItem().SetIndividualGreeting(bIndividual, false);
100 0 : m_pWizard->UpdateRoadmap();
101 0 : m_pWizard->enableButtons(WizardButtonFlags::NEXT, m_pWizard->isStateEnabled(MM_PREPAREMERGEPAGE));
102 : }
103 0 : UpdatePreview();
104 0 : return 0;
105 : }
106 :
107 0 : IMPL_LINK(SwGreetingsHandler, GreetingHdl_Impl, PushButton*, pButton)
108 : {
109 : VclPtr<SwCustomizeAddressBlockDialog> pDlg(
110 0 : VclPtr<SwCustomizeAddressBlockDialog>::Create(pButton, m_pWizard->GetConfigItem(),
111 0 : pButton == m_pMalePB ?
112 : SwCustomizeAddressBlockDialog::GREETING_MALE :
113 0 : SwCustomizeAddressBlockDialog::GREETING_FEMALE ));
114 0 : if(RET_OK == pDlg->Execute())
115 : {
116 0 : ListBox* pToInsert = pButton == m_pMalePB ? m_pMaleLB : m_pFemaleLB;
117 0 : pToInsert->SelectEntryPos(pToInsert->InsertEntry(pDlg->GetAddress()));
118 0 : if(m_bIsTabPage)
119 : {
120 0 : m_pWizard->UpdateRoadmap();
121 0 : m_pWizard->enableButtons(WizardButtonFlags::NEXT, m_pWizard->isStateEnabled(MM_PREPAREMERGEPAGE));
122 : }
123 0 : UpdatePreview();
124 : }
125 0 : return 0;
126 : }
127 :
128 0 : void SwGreetingsHandler::UpdatePreview()
129 : {
130 : //the base class does nothing
131 0 : }
132 :
133 0 : IMPL_LINK(SwMailMergeGreetingsPage, AssignHdl_Impl, PushButton*, pButton)
134 : {
135 0 : const OUString sPreview(m_pFemaleLB->GetSelectEntry() + "\n" + m_pMaleLB->GetSelectEntry());
136 : VclPtr<SwAssignFieldsDialog> pDlg(
137 0 : VclPtr<SwAssignFieldsDialog>::Create(pButton, m_pWizard->GetConfigItem(), sPreview, false));
138 0 : if(RET_OK == pDlg->Execute())
139 : {
140 0 : UpdatePreview();
141 0 : m_pWizard->UpdateRoadmap();
142 0 : m_pWizard->enableButtons(WizardButtonFlags::NEXT, m_pWizard->isStateEnabled(MM_PREPAREMERGEPAGE));
143 : }
144 0 : return 0;
145 : }
146 :
147 0 : IMPL_LINK_NOARG(SwMailMergeGreetingsPage, GreetingSelectHdl_Impl)
148 : {
149 0 : UpdatePreview();
150 0 : return 0;
151 : }
152 :
153 0 : void SwMailMergeGreetingsPage::UpdatePreview()
154 : {
155 : //find out which type of greeting should be selected:
156 0 : bool bFemale = false;
157 0 : bool bNoValue = !m_pFemaleColumnLB->IsEnabled();
158 0 : if( !bNoValue )
159 : {
160 0 : const OUString sFemaleValue = m_pFemaleFieldCB->GetText();
161 0 : const OUString sFemaleColumn = m_pFemaleColumnLB->GetSelectEntry();
162 0 : Reference< sdbcx::XColumnsSupplier > xColsSupp( m_pWizard->GetConfigItem().GetResultSet(), UNO_QUERY);
163 0 : Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
164 0 : if(!sFemaleValue.isEmpty() && !sFemaleColumn.isEmpty() &&
165 0 : xColAccess.is() &&
166 0 : xColAccess->hasByName(sFemaleColumn))
167 : {
168 : //get the content and exchange it in the address string
169 0 : Any aCol = xColAccess->getByName(sFemaleColumn);
170 0 : Reference< sdb::XColumn > xColumn;
171 0 : aCol >>= xColumn;
172 0 : if(xColumn.is())
173 : {
174 : try
175 : {
176 0 : bFemale = xColumn->getString() == sFemaleValue;
177 0 : if( !bNoValue )
178 : {
179 : //no last name value marks the greeting also als neutral
180 0 : SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
181 : const OUString sLastNameColumn =
182 0 : rConfig.GetAssignedColumn(MM_PART_LASTNAME);
183 0 : if ( xColAccess->hasByName(sLastNameColumn) )
184 : {
185 0 : aCol = xColAccess->getByName(sLastNameColumn);
186 0 : aCol >>= xColumn;
187 0 : bNoValue = xColumn->getString().isEmpty();
188 0 : }
189 : }
190 : }
191 0 : catch (const sdbc::SQLException&)
192 : {
193 : OSL_FAIL("SQLException caught");
194 : }
195 0 : }
196 0 : }
197 : }
198 :
199 : OUString sPreview = bFemale ? m_pFemaleLB->GetSelectEntry() :
200 0 : bNoValue ? m_pNeutralCB->GetText() : m_pMaleLB->GetSelectEntry();
201 :
202 0 : sPreview = SwAddressPreview::FillData(sPreview, m_pWizard->GetConfigItem());
203 0 : m_pPreviewWIN->SetAddress(sPreview);
204 0 : }
205 :
206 0 : void SwGreetingsHandler::Contains(bool bContainsGreeting)
207 : {
208 0 : m_pPersonalizedCB->Enable(bContainsGreeting);
209 0 : bool bEnablePersonal = bContainsGreeting && m_pPersonalizedCB->IsChecked();
210 0 : m_pFemaleFT->Enable(bEnablePersonal);
211 0 : m_pFemaleLB->Enable(bEnablePersonal);
212 0 : m_pFemalePB->Enable(bEnablePersonal);
213 0 : m_pMaleFT->Enable(bEnablePersonal);
214 0 : m_pMaleLB->Enable(bEnablePersonal);
215 0 : m_pMalePB->Enable(bEnablePersonal);
216 0 : m_pFemaleFI->Enable(bEnablePersonal);
217 0 : m_pFemaleColumnFT->Enable(bEnablePersonal);
218 0 : m_pFemaleColumnLB->Enable(bEnablePersonal);
219 0 : m_pFemaleFieldFT->Enable(bEnablePersonal);
220 0 : m_pFemaleFieldCB->Enable(bEnablePersonal);
221 :
222 0 : m_pNeutralFT->Enable(bContainsGreeting);
223 0 : m_pNeutralCB->Enable(bContainsGreeting);
224 0 : }
225 :
226 0 : SwMailMergeGreetingsPage::SwMailMergeGreetingsPage(SwMailMergeWizard* _pParent)
227 : : svt::OWizardPage(_pParent, "MMSalutationPage",
228 0 : "modules/swriter/ui/mmsalutationpage.ui")
229 : {
230 0 : m_pWizard = _pParent;
231 :
232 0 : get(m_pGreetingLineCB, "greeting");
233 0 : get(m_pPersonalizedCB, "personalized");
234 0 : get(m_pFemaleFT, "femaleft");
235 0 : get(m_pFemaleLB, "female");
236 0 : get(m_pFemalePB, "newfemale");
237 0 : get(m_pMaleFT, "maleft");
238 0 : get(m_pMaleLB, "male");
239 0 : get(m_pMalePB, "newmale");
240 0 : get(m_pFemaleFI, "femalefi");
241 0 : get(m_pFemaleColumnFT, "femalecolft");
242 0 : get(m_pFemaleColumnLB, "femalecol");
243 0 : get(m_pFemaleFieldFT, "femalefieldft");
244 0 : get(m_pFemaleFieldCB, "femalefield");
245 0 : get(m_pNeutralFT, "generalft");
246 0 : get(m_pNeutralCB, "general");
247 0 : get(m_pPreviewFI, "previewft");
248 0 : get(m_pPreviewWIN, "preview");
249 0 : Size aSize(LogicToPixel(Size(186, 21), MapMode(MAP_APPFONT)));
250 0 : m_pPreviewWIN->set_width_request(aSize.Width());
251 0 : m_pPreviewWIN->set_height_request(aSize.Height());
252 0 : get(m_pAssignPB, "assign");
253 0 : get(m_pDocumentIndexFI, "documentindex");
254 0 : m_sDocument = m_pDocumentIndexFI->GetText();
255 0 : get(m_pPrevSetIB, "prev");
256 0 : get(m_pNextSetIB, "next");
257 :
258 0 : m_bIsTabPage = true;
259 :
260 0 : m_pGreetingLineCB->SetClickHdl(LINK(this, SwMailMergeGreetingsPage, ContainsHdl_Impl));
261 0 : Link<> aIndividualLink = LINK(this, SwGreetingsHandler, IndividualHdl_Impl);
262 0 : m_pPersonalizedCB->SetClickHdl(aIndividualLink);
263 0 : Link<> aGreetingLink = LINK(this, SwGreetingsHandler, GreetingHdl_Impl);
264 0 : m_pFemalePB->SetClickHdl(aGreetingLink);
265 0 : m_pMalePB->SetClickHdl(aGreetingLink);
266 0 : m_pAssignPB->SetClickHdl(LINK(this, SwMailMergeGreetingsPage, AssignHdl_Impl));
267 0 : Link<> aLBoxLink = LINK(this, SwMailMergeGreetingsPage, GreetingSelectHdl_Impl);
268 0 : m_pFemaleLB->SetSelectHdl(aLBoxLink);
269 0 : m_pMaleLB->SetSelectHdl(aLBoxLink);
270 0 : m_pFemaleColumnLB->SetSelectHdl(aLBoxLink);
271 0 : m_pFemaleFieldCB->SetSelectHdl(aLBoxLink);
272 0 : m_pFemaleFieldCB->SetModifyHdl(aLBoxLink);
273 0 : m_pNeutralCB->SetSelectHdl(aLBoxLink);
274 0 : m_pNeutralCB->SetModifyHdl(aLBoxLink);
275 :
276 0 : Link<> aDataLink = LINK(this, SwMailMergeGreetingsPage, InsertDataHdl_Impl);
277 0 : m_pPrevSetIB->SetClickHdl(aDataLink);
278 0 : m_pNextSetIB->SetClickHdl(aDataLink);
279 :
280 0 : SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
281 0 : m_pGreetingLineCB->Check(rConfig.IsGreetingLine(false));
282 0 : m_pPersonalizedCB->Check(rConfig.IsIndividualGreeting(false));
283 0 : ContainsHdl_Impl(m_pGreetingLineCB);
284 0 : aIndividualLink.Call(0);
285 :
286 0 : lcl_FillGreetingsBox(*m_pFemaleLB, rConfig, SwMailMergeConfigItem::FEMALE);
287 0 : lcl_FillGreetingsBox(*m_pMaleLB, rConfig, SwMailMergeConfigItem::MALE);
288 0 : lcl_FillGreetingsBox(*m_pNeutralCB, rConfig, SwMailMergeConfigItem::NEUTRAL);
289 :
290 0 : m_pDocumentIndexFI->SetText(m_sDocument.replaceFirst("%1", "1"));
291 0 : }
292 :
293 0 : SwMailMergeGreetingsPage::~SwMailMergeGreetingsPage()
294 : {
295 0 : disposeOnce();
296 0 : }
297 :
298 0 : void SwMailMergeGreetingsPage::dispose()
299 : {
300 0 : m_pPreviewFI.clear();
301 0 : m_pPreviewWIN.clear();
302 0 : m_pAssignPB.clear();
303 0 : m_pDocumentIndexFI.clear();
304 0 : m_pPrevSetIB.clear();
305 0 : m_pNextSetIB.clear();
306 0 : svt::OWizardPage::dispose();
307 0 : }
308 :
309 0 : void SwMailMergeGreetingsPage::ActivatePage()
310 : {
311 0 : SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
312 :
313 : //try to find the gender setting
314 0 : m_pFemaleColumnLB->Clear();
315 0 : Reference< sdbcx::XColumnsSupplier > xColsSupp = rConfig.GetColumnsSupplier();
316 0 : if(xColsSupp.is())
317 : {
318 0 : Reference < container::XNameAccess> xColAccess = xColsSupp->getColumns();
319 0 : Sequence< OUString > aColumns = xColAccess->getElementNames();
320 0 : for(sal_Int32 nName = 0; nName < aColumns.getLength(); ++nName)
321 0 : m_pFemaleColumnLB->InsertEntry(aColumns[nName]);
322 : }
323 :
324 0 : m_pFemaleColumnLB->SelectEntry(rConfig.GetAssignedColumn(MM_PART_GENDER));
325 0 : m_pFemaleColumnLB->SaveValue();
326 :
327 0 : m_pFemaleFieldCB->SetText(rConfig.GetFemaleGenderValue());
328 0 : m_pFemaleFieldCB->SaveValue();
329 :
330 0 : UpdatePreview();
331 0 : m_pWizard->enableButtons(WizardButtonFlags::NEXT, m_pWizard->isStateEnabled(MM_PREPAREMERGEPAGE));
332 0 : }
333 :
334 0 : bool SwMailMergeGreetingsPage::commitPage( ::svt::WizardTypes::CommitPageReason )
335 : {
336 0 : SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
337 :
338 0 : if (m_pFemaleColumnLB->IsValueChangedFromSaved())
339 : {
340 0 : const SwDBData& rDBData = rConfig.GetCurrentDBData();
341 0 : Sequence< OUString> aAssignment = rConfig.GetColumnAssignment( rDBData );
342 0 : if(aAssignment.getLength() <= MM_PART_GENDER)
343 0 : aAssignment.realloc(MM_PART_GENDER + 1);
344 0 : aAssignment[MM_PART_GENDER] = m_pFemaleColumnLB->GetSelectEntry();
345 0 : rConfig.SetColumnAssignment( rDBData, aAssignment );
346 : }
347 0 : if (m_pFemaleFieldCB->IsValueChangedFromSaved())
348 0 : rConfig.SetFemaleGenderValue(m_pFemaleFieldCB->GetText());
349 :
350 0 : lcl_StoreGreetingsBox(*m_pFemaleLB, rConfig, SwMailMergeConfigItem::FEMALE);
351 0 : lcl_StoreGreetingsBox(*m_pMaleLB, rConfig, SwMailMergeConfigItem::MALE);
352 :
353 0 : sal_Int32 nCurrentTextPos = m_pNeutralCB->GetEntryPos(m_pNeutralCB->GetText());
354 0 : if(COMBOBOX_ENTRY_NOTFOUND == nCurrentTextPos)
355 : {
356 0 : sal_Int32 nCount = m_pNeutralCB->GetEntryCount();
357 0 : m_pNeutralCB->InsertEntry(m_pNeutralCB->GetText(), nCount);
358 0 : m_pNeutralCB->SelectEntryPos(nCount);
359 : }
360 0 : lcl_StoreGreetingsBox(*m_pNeutralCB, rConfig, SwMailMergeConfigItem::NEUTRAL);
361 0 : rConfig.SetGreetingLine(m_pGreetingLineCB->IsChecked(), false);
362 0 : rConfig.SetIndividualGreeting(m_pPersonalizedCB->IsChecked(), false);
363 0 : return true;
364 : }
365 :
366 0 : IMPL_LINK(SwMailMergeGreetingsPage, ContainsHdl_Impl, CheckBox*, pBox)
367 : {
368 0 : bool bContainsGreeting = pBox->IsChecked();
369 0 : SwGreetingsHandler::Contains(bContainsGreeting);
370 0 : m_pPreviewFI-> Enable(bContainsGreeting);
371 0 : m_pPreviewWIN->Enable(bContainsGreeting);
372 0 : m_pAssignPB-> Enable(bContainsGreeting);
373 0 : m_pDocumentIndexFI-> Enable(bContainsGreeting);
374 0 : m_pPrevSetIB->Enable(bContainsGreeting);
375 0 : m_pNextSetIB->Enable(bContainsGreeting);
376 0 : SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
377 0 : rConfig.SetGreetingLine(m_pGreetingLineCB->IsChecked(), false);
378 0 : m_pWizard->UpdateRoadmap();
379 0 : return 0;
380 : }
381 :
382 0 : IMPL_LINK(SwMailMergeGreetingsPage, InsertDataHdl_Impl, ImageButton*, pButton)
383 : {
384 : //if no pButton is given, the first set has to be pre-set
385 0 : SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
386 0 : if(!pButton)
387 : {
388 0 : rConfig.GetResultSet();
389 : }
390 : else
391 : {
392 0 : bool bNext = pButton == m_pNextSetIB;
393 0 : sal_Int32 nPos = rConfig.GetResultSetPosition();
394 0 : rConfig.MoveResultSet( bNext ? ++nPos : --nPos);
395 : }
396 0 : sal_Int32 nPos = rConfig.GetResultSetPosition();
397 0 : bool bEnable = true;
398 0 : if(nPos < 1)
399 : {
400 0 : bEnable = false;
401 0 : nPos = 1;
402 : }
403 : else
404 0 : UpdatePreview();
405 0 : m_pPrevSetIB->Enable(bEnable);
406 0 : m_pNextSetIB->Enable(bEnable);
407 0 : m_pDocumentIndexFI->Enable(bEnable);
408 0 : m_pDocumentIndexFI->SetText(m_sDocument.replaceFirst("%1", OUString::number(nPos)));
409 0 : return 0;
410 : }
411 :
412 0 : SwMailBodyDialog::SwMailBodyDialog(vcl::Window* pParent, SwMailMergeWizard* _pWizard) :
413 0 : SfxModalDialog(pParent, "MailBodyDialog", "modules/swriter/ui/mmmailbody.ui")
414 : {
415 0 : m_pWizard = _pWizard;
416 0 : get(m_pGreetingLineCB, "greeting");
417 0 : get(m_pPersonalizedCB, "personalized");
418 0 : get(m_pFemaleFT, "femaleft");
419 0 : get(m_pFemaleLB, "female");
420 0 : get(m_pFemalePB, "newfemale");
421 0 : get(m_pMaleFT, "maleft");
422 0 : get(m_pMaleLB, "male");
423 0 : get(m_pMalePB, "newmale");
424 0 : get(m_pFemaleFI, "femalefi");
425 0 : get(m_pFemaleColumnFT, "femalecolft");
426 0 : get(m_pFemaleColumnLB, "femalecol");
427 0 : get(m_pFemaleFieldFT, "femalefieldft");
428 0 : get(m_pFemaleFieldCB, "femalefield");
429 0 : get(m_pNeutralFT, "generalft");
430 0 : get(m_pNeutralCB, "general");
431 0 : get(m_pBodyFT, "bodyft");
432 0 : get(m_pBodyMLE, "bodymle");
433 0 : m_pBodyMLE->SetStyle(m_pBodyMLE->GetStyle() | WB_HSCROLL | WB_VSCROLL | WB_IGNORETAB);
434 0 : Size aSize(LogicToPixel(Size(180, 50), MAP_APPFONT));
435 0 : m_pBodyMLE->set_width_request(aSize.Width());
436 0 : m_pBodyMLE->set_height_request(aSize.Height());
437 0 : get(m_pOK, "ok");
438 0 : m_bIsTabPage = false;
439 :
440 0 : m_pPersonalizedCB->SetHelpId( HID_MM_BODY_CB_PERSONALIZED );
441 0 : m_pFemaleLB->SetHelpId( HID_MM_BODY_LB_FEMALE );
442 0 : m_pFemalePB->SetHelpId( HID_MM_BODY_PB_FEMALE );
443 0 : m_pMaleLB->SetHelpId( HID_MM_BODY_LB_MALE );
444 0 : m_pMalePB->SetHelpId( HID_MM_BODY_PB_MALE );
445 0 : m_pFemaleColumnLB->SetHelpId( HID_MM_BODY_LB_FEMALECOLUMN );
446 0 : m_pFemaleFieldCB->SetHelpId( HID_MM_BODY_CB_FEMALEFIELD );
447 0 : m_pNeutralCB->SetHelpId( HID_MM_BODY_CB_NEUTRAL );
448 :
449 0 : m_pGreetingLineCB->SetClickHdl(LINK(this, SwMailBodyDialog, ContainsHdl_Impl));
450 0 : Link<> aIndividualLink = LINK(this, SwGreetingsHandler, IndividualHdl_Impl);
451 0 : m_pPersonalizedCB->SetClickHdl(aIndividualLink);
452 0 : Link<> aGreetingLink = LINK(this, SwGreetingsHandler, GreetingHdl_Impl);
453 0 : m_pFemalePB->SetClickHdl(aGreetingLink);
454 0 : m_pMalePB->SetClickHdl(aGreetingLink);
455 0 : m_pOK->SetClickHdl(LINK(this, SwMailBodyDialog, OKHdl));
456 :
457 0 : SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
458 0 : m_pGreetingLineCB->Check(rConfig.IsGreetingLine(true));
459 0 : m_pPersonalizedCB->Check(rConfig.IsIndividualGreeting(true));
460 0 : ContainsHdl_Impl(m_pGreetingLineCB);
461 0 : aIndividualLink.Call(0);
462 :
463 0 : lcl_FillGreetingsBox(*m_pFemaleLB, rConfig, SwMailMergeConfigItem::FEMALE);
464 0 : lcl_FillGreetingsBox(*m_pMaleLB, rConfig, SwMailMergeConfigItem::MALE);
465 0 : lcl_FillGreetingsBox(*m_pNeutralCB, rConfig, SwMailMergeConfigItem::NEUTRAL);
466 :
467 : //try to find the gender setting
468 0 : m_pFemaleColumnLB->Clear();
469 0 : Reference< sdbcx::XColumnsSupplier > xColsSupp = rConfig.GetColumnsSupplier();
470 0 : if(xColsSupp.is())
471 : {
472 0 : Reference < container::XNameAccess> xColAccess = xColsSupp->getColumns();
473 0 : Sequence< OUString > aColumns = xColAccess->getElementNames();
474 0 : for(sal_Int32 nName = 0; nName < aColumns.getLength(); ++nName)
475 0 : m_pFemaleColumnLB->InsertEntry(aColumns[nName]);
476 : }
477 :
478 0 : m_pFemaleColumnLB->SelectEntry(rConfig.GetAssignedColumn(MM_PART_GENDER));
479 0 : m_pFemaleColumnLB->SaveValue();
480 :
481 0 : m_pFemaleFieldCB->SetText(rConfig.GetFemaleGenderValue());
482 0 : m_pFemaleFieldCB->SaveValue();
483 0 : }
484 :
485 0 : SwMailBodyDialog::~SwMailBodyDialog()
486 : {
487 0 : disposeOnce();
488 0 : }
489 :
490 0 : void SwMailBodyDialog::dispose()
491 : {
492 0 : m_pBodyFT.clear();
493 0 : m_pBodyMLE.clear();
494 0 : m_pOK.clear();
495 0 : SfxModalDialog::dispose();
496 0 : }
497 :
498 0 : IMPL_LINK(SwMailBodyDialog, ContainsHdl_Impl, CheckBox*, pBox)
499 : {
500 0 : SwGreetingsHandler::Contains(pBox->IsChecked());
501 0 : m_pWizard->GetConfigItem().SetGreetingLine(pBox->IsChecked(), true);
502 0 : return 0;
503 : }
504 :
505 0 : IMPL_LINK_NOARG(SwMailBodyDialog, OKHdl)
506 : {
507 0 : SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
508 : rConfigItem.SetGreetingLine(
509 0 : m_pGreetingLineCB->IsChecked(), false);
510 : rConfigItem.SetIndividualGreeting(
511 0 : m_pPersonalizedCB->IsChecked(), false);
512 :
513 0 : if(m_pFemaleColumnLB->IsValueChangedFromSaved())
514 : {
515 0 : const SwDBData& rDBData = rConfigItem.GetCurrentDBData();
516 0 : Sequence< OUString> aAssignment = rConfigItem.GetColumnAssignment( rDBData );
517 0 : sal_Int32 nPos = m_pFemaleColumnLB->GetSelectEntryPos();
518 0 : if(aAssignment.getLength() < MM_PART_GENDER)
519 0 : aAssignment.realloc(MM_PART_GENDER);
520 0 : if( nPos > 0 )
521 0 : aAssignment[MM_PART_GENDER] = m_pFemaleColumnLB->GetSelectEntry();
522 : else
523 0 : aAssignment[MM_PART_GENDER].clear();
524 0 : rConfigItem.SetColumnAssignment( rDBData, aAssignment );
525 : }
526 0 : if(m_pFemaleFieldCB->IsValueChangedFromSaved())
527 0 : rConfigItem.SetFemaleGenderValue(m_pFemaleFieldCB->GetText());
528 :
529 0 : EndDialog(RET_OK);
530 0 : return 0;
531 0 : }
532 :
533 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|