1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27 #ifdef SW_DLLIMPLEMENTATION
28 #undef SW_DLLIMPLEMENTATION
29 #endif
30 #include <mmgreetingspage.hxx>
31 #include <mailmergewizard.hxx>
32 #include <mmconfigitem.hxx>
33 #include <mmaddressblockpage.hxx>
34 #include <swtypes.hxx>
35 #include <vcl/msgbox.hxx>
36 #include <mmgreetingspage.hrc>
37 #include <dbui.hrc>
38 #include <com/sun/star/sdb/XColumn.hpp>
39 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
40 #include <com/sun/star/container/XNameAccess.hpp>
41 #include <helpid.h>
42
43 using namespace svt;
44 using namespace ::com::sun::star;
45 using namespace ::com::sun::star::uno;
46 // -----------------------------------------------------------------------
lcl_FillGreetingsBox(ListBox & rBox,SwMailMergeConfigItem & rConfig,SwMailMergeConfigItem::Gender eType)47 void lcl_FillGreetingsBox(ListBox& rBox,
48 SwMailMergeConfigItem& rConfig,
49 SwMailMergeConfigItem::Gender eType)
50 {
51 const Sequence< ::rtl::OUString> rEntries = rConfig.GetGreetings(eType);
52 for(sal_Int32 nEntry = 0; nEntry < rEntries.getLength(); ++nEntry)
53 rBox.InsertEntry(rEntries[nEntry]);
54 rBox.SelectEntryPos((sal_uInt16)rConfig.GetCurrentGreeting(eType));
55 }
56 // -----------------------------------------------------------------------
lcl_FillGreetingsBox(ComboBox & rBox,SwMailMergeConfigItem & rConfig,SwMailMergeConfigItem::Gender eType)57 void lcl_FillGreetingsBox(ComboBox& rBox,
58 SwMailMergeConfigItem& rConfig,
59 SwMailMergeConfigItem::Gender eType)
60 {
61 const Sequence< ::rtl::OUString> rEntries = rConfig.GetGreetings(eType);
62 for(sal_Int32 nEntry = 0; nEntry < rEntries.getLength(); ++nEntry)
63 rBox.InsertEntry(rEntries[nEntry]);
64 rBox.SelectEntryPos((sal_uInt16)rConfig.GetCurrentGreeting(eType));
65 }
66 // -----------------------------------------------------------------------
lcl_StoreGreetingsBox(ListBox & rBox,SwMailMergeConfigItem & rConfig,SwMailMergeConfigItem::Gender eType)67 void lcl_StoreGreetingsBox(ListBox& rBox,
68 SwMailMergeConfigItem& rConfig,
69 SwMailMergeConfigItem::Gender eType)
70 {
71 Sequence< ::rtl::OUString> aEntries(rBox.GetEntryCount());
72 ::rtl::OUString* pEntries = aEntries.getArray();
73 for(sal_uInt16 nEntry = 0; nEntry < rBox.GetEntryCount(); ++nEntry)
74 pEntries[nEntry] = rBox.GetEntry(nEntry);
75 rConfig.SetGreetings(eType, aEntries);
76 rConfig.SetCurrentGreeting(eType, rBox.GetSelectEntryPos());
77 }
78 // -----------------------------------------------------------------------
lcl_StoreGreetingsBox(ComboBox & rBox,SwMailMergeConfigItem & rConfig,SwMailMergeConfigItem::Gender eType)79 void lcl_StoreGreetingsBox(ComboBox& rBox,
80 SwMailMergeConfigItem& rConfig,
81 SwMailMergeConfigItem::Gender eType)
82 {
83 Sequence< ::rtl::OUString> aEntries(rBox.GetEntryCount());
84 ::rtl::OUString* pEntries = aEntries.getArray();
85 for(sal_uInt16 nEntry = 0; nEntry < rBox.GetEntryCount(); ++nEntry)
86 pEntries[nEntry] = rBox.GetEntry(nEntry);
87 rConfig.SetGreetings(eType, aEntries);
88 rConfig.SetCurrentGreeting(eType, rBox.GetSelectEntryPos());
89 }
90 /*-- 30.04.2004 10:42:57---------------------------------------------------
91
92 -----------------------------------------------------------------------*/
IMPL_LINK(SwGreetingsHandler,IndividualHdl_Impl,CheckBox *,EMPTYARG)93 IMPL_LINK(SwGreetingsHandler, IndividualHdl_Impl, CheckBox*, EMPTYARG)
94 {
95 sal_Bool bIndividual = m_pPersonalizedCB->IsEnabled() && m_pPersonalizedCB->IsChecked();
96 m_pFemaleFT->Enable(bIndividual);
97 m_pFemaleLB->Enable(bIndividual);
98 m_pFemalePB->Enable(bIndividual);
99 m_pMaleFT->Enable(bIndividual);
100 m_pMaleLB->Enable(bIndividual);
101 m_pMalePB->Enable(bIndividual);
102 m_pFemaleFI->Enable(bIndividual);
103 m_pFemaleColumnFT->Enable(bIndividual);
104 m_pFemaleColumnLB->Enable(bIndividual);
105 m_pFemaleFieldFT->Enable(bIndividual);
106 m_pFemaleFieldCB->Enable(bIndividual);
107
108 if( m_bIsTabPage )
109 {
110 m_pWizard->GetConfigItem().SetIndividualGreeting(bIndividual, sal_False);
111 m_pWizard->UpdateRoadmap();
112 m_pWizard->enableButtons(WZB_NEXT, m_pWizard->isStateEnabled(MM_PREPAREMERGEPAGE));
113 }
114 UpdatePreview();
115 return 0;
116 }
117 /*-- 30.04.2004 10:42:57---------------------------------------------------
118
119 -----------------------------------------------------------------------*/
IMPL_LINK(SwGreetingsHandler,GreetingHdl_Impl,PushButton *,pButton)120 IMPL_LINK(SwGreetingsHandler, GreetingHdl_Impl, PushButton*, pButton)
121 {
122 SwCustomizeAddressBlockDialog* pDlg =
123 new SwCustomizeAddressBlockDialog(pButton, m_pWizard->GetConfigItem(),
124 pButton == m_pMalePB ?
125 SwCustomizeAddressBlockDialog::GREETING_MALE :
126 SwCustomizeAddressBlockDialog::GREETING_FEMALE );
127 if(RET_OK == pDlg->Execute())
128 {
129 ListBox* pToInsert = pButton == m_pMalePB ? m_pMaleLB : m_pFemaleLB;
130 pToInsert->SelectEntryPos(pToInsert->InsertEntry(pDlg->GetAddress()));
131 if(m_bIsTabPage)
132 {
133 m_pWizard->UpdateRoadmap();
134 m_pWizard->enableButtons(WZB_NEXT, m_pWizard->isStateEnabled(MM_PREPAREMERGEPAGE));
135 }
136 UpdatePreview();
137 }
138 delete pDlg;
139 return 0;
140 }
141 /*-- 16.06.2004 10:56:21---------------------------------------------------
142
143 -----------------------------------------------------------------------*/
UpdatePreview()144 void SwGreetingsHandler::UpdatePreview()
145 {
146 //the base class does nothing
147 }
148 /*-- 30.04.2004 10:42:59---------------------------------------------------
149
150 -----------------------------------------------------------------------*/
IMPL_LINK(SwMailMergeGreetingsPage,AssignHdl_Impl,PushButton *,pButton)151 IMPL_LINK(SwMailMergeGreetingsPage, AssignHdl_Impl, PushButton*, pButton)
152 {
153 String sPreview = m_aFemaleLB.GetSelectEntry();
154 sPreview += '\n';
155 sPreview += m_aMaleLB.GetSelectEntry();
156 SwAssignFieldsDialog* pDlg =
157 new SwAssignFieldsDialog(pButton, m_pWizard->GetConfigItem(), sPreview, false);
158 if(RET_OK == pDlg->Execute())
159 {
160 UpdatePreview();
161 m_pWizard->UpdateRoadmap();
162 m_pWizard->enableButtons(WZB_NEXT, m_pWizard->isStateEnabled(MM_PREPAREMERGEPAGE));
163 }
164 delete pDlg;
165 return 0;
166 }
167 /*-- 05.05.2004 15:25:56---------------------------------------------------
168
169 -----------------------------------------------------------------------*/
IMPL_LINK(SwMailMergeGreetingsPage,GreetingSelectHdl_Impl,ListBox *,EMPTYARG)170 IMPL_LINK(SwMailMergeGreetingsPage, GreetingSelectHdl_Impl, ListBox*, EMPTYARG)
171 {
172 UpdatePreview();
173 return 0;
174 }
175 /*-- 05.05.2004 15:23:43---------------------------------------------------
176
177 -----------------------------------------------------------------------*/
UpdatePreview()178 void SwMailMergeGreetingsPage::UpdatePreview()
179 {
180 //find out which type of greeting should be selected:
181 bool bFemale = false;
182 bool bNoValue = !m_pFemaleColumnLB->IsEnabled();
183 if( !bNoValue )
184 {
185 ::rtl::OUString sFemaleValue = m_aFemaleFieldCB.GetText();
186 ::rtl::OUString sFemaleColumn = m_aFemaleColumnLB.GetSelectEntry();
187 Reference< sdbcx::XColumnsSupplier > xColsSupp( m_pWizard->GetConfigItem().GetResultSet(), UNO_QUERY);
188 Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
189 if(sFemaleValue.getLength() && sFemaleColumn.getLength() &&
190 xColAccess.is() &&
191 xColAccess->hasByName(sFemaleColumn))
192 {
193 //get the content and exchange it in the address string
194 Any aCol = xColAccess->getByName(sFemaleColumn);
195 Reference< sdb::XColumn > xColumn;
196 aCol >>= xColumn;
197 if(xColumn.is())
198 {
199 try
200 {
201 ::rtl::OUString sFemaleColumnValue = xColumn->getString();
202 bFemale = sFemaleColumnValue == sFemaleValue;
203 //bNoValue = !sFemaleColumnValue.getLength();
204 if( !bNoValue )
205 {
206 //no last name value marks the greeting also als neutral
207 SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
208 ::rtl::OUString sLastNameColumn = rConfig.GetAssignedColumn(MM_PART_LASTNAME);
209 if ( xColAccess->hasByName(sLastNameColumn) )
210 {
211 aCol = xColAccess->getByName(sLastNameColumn);
212 aCol >>= xColumn;
213 ::rtl::OUString sLastNameColumnValue = xColumn->getString();
214 bNoValue = !sLastNameColumnValue.getLength();
215 }
216 }
217 }
218 catch( sdbc::SQLException& )
219 {
220 DBG_ERROR("SQLException caught");
221 }
222 }
223 }
224 }
225
226 String sPreview = bFemale ? m_aFemaleLB.GetSelectEntry() :
227 bNoValue ? m_aNeutralCB.GetText() : m_aMaleLB.GetSelectEntry();
228
229 sPreview = SwAddressPreview::FillData(sPreview, m_pWizard->GetConfigItem());
230 m_aPreviewWIN.SetAddress(sPreview);
231 }
232 /*-- 17.05.2004 15:44:53---------------------------------------------------
233
234 -----------------------------------------------------------------------*/
Contains(sal_Bool bContainsGreeting)235 void SwGreetingsHandler::Contains(sal_Bool bContainsGreeting)
236 {
237 m_pPersonalizedCB->Enable(bContainsGreeting);
238 sal_Bool bEnablePersonal = bContainsGreeting && m_pPersonalizedCB->IsChecked();
239 m_pFemaleFT->Enable(bEnablePersonal);
240 m_pFemaleLB->Enable(bEnablePersonal);
241 m_pFemalePB->Enable(bEnablePersonal);
242 m_pMaleFT->Enable(bEnablePersonal);
243 m_pMaleLB->Enable(bEnablePersonal);
244 m_pMalePB->Enable(bEnablePersonal);
245 m_pFemaleFI->Enable(bEnablePersonal);
246 m_pFemaleColumnFT->Enable(bEnablePersonal);
247 m_pFemaleColumnLB->Enable(bEnablePersonal);
248 m_pFemaleFieldFT->Enable(bEnablePersonal);
249 m_pFemaleFieldCB->Enable(bEnablePersonal);
250
251 m_pNeutralFT->Enable(bContainsGreeting);
252 m_pNeutralCB->Enable(bContainsGreeting);
253 }
254 /*-- 02.04.2004 14:17:52---------------------------------------------------
255
256 -----------------------------------------------------------------------*/
SwMailMergeGreetingsPage(SwMailMergeWizard * _pParent)257 SwMailMergeGreetingsPage::SwMailMergeGreetingsPage( SwMailMergeWizard* _pParent) :
258 svt::OWizardPage(_pParent, SW_RES(DLG_MM_GREETINGS_PAGE)),
259 #ifdef MSC
260 #pragma warning (disable : 4355)
261 #endif
262 m_aHeaderFI(this, SW_RES( FI_HEADER ) ),
263 m_aGreetingLineCB(this, SW_RES( CB_GREETINGLINE ) ),
264 m_aPersonalizedCB(this, SW_RES( CB_PERSONALIZED ) ),
265 m_aFemaleFT(this, SW_RES( FT_FEMALE ) ),
266 m_aFemaleLB(this, SW_RES( LB_FEMALE ) ),
267 m_aFemalePB(this, SW_RES( PB_FEMALE ) ),
268 m_aMaleFT(this, SW_RES( FT_MALE ) ),
269 m_aMaleLB(this, SW_RES( LB_MALE ) ),
270 m_aMalePB(this, SW_RES( PB_MALE ) ),
271 m_aFemaleFI(this, SW_RES( FI_FEMALE ) ),
272 m_aFemaleColumnFT(this, SW_RES( FT_FEMALECOLUMN ) ),
273 m_aFemaleColumnLB(this, SW_RES( LB_FEMALECOLUMN ) ),
274 m_aFemaleFieldFT(this, SW_RES( FT_FEMALEFIELD ) ),
275 m_aFemaleFieldCB(this, SW_RES( CB_FEMALEFIELD ) ),
276 m_aNeutralFT(this, SW_RES( FT_NEUTRAL ) ),
277 m_aNeutralCB(this, SW_RES( CB_NEUTRAL ) ),
278 m_aPreviewFI( this, SW_RES( FI_PREVIEW ) ),
279 m_aPreviewWIN( this, SW_RES( WIN_PREVIEW ) ),
280 m_aAssignPB( this, SW_RES( PB_ASSIGN ) ),
281 m_aDocumentIndexFI( this, SW_RES( FI_DOCINDEX ) ),
282 m_aPrevSetIB( this, SW_RES( IB_PREVSET ) ),
283 m_aNextSetIB( this, SW_RES( IB_NEXTSET ) ),
284 m_sDocument( SW_RES( STR_DOCUMENT ) )
285 #ifdef MSC
286 #pragma warning (default : 4355)
287 #endif
288 {
289 m_pWizard = _pParent;
290 m_pGreetingLineCB = &m_aGreetingLineCB;
291 m_pPersonalizedCB = &m_aPersonalizedCB;
292 m_pFemaleFT = & m_aFemaleFT;
293 m_pFemaleLB = & m_aFemaleLB;
294 m_pFemalePB = & m_aFemalePB;
295 m_pMaleFT = & m_aMaleFT;
296 m_pMaleLB = & m_aMaleLB;
297 m_pMalePB = & m_aMalePB;
298 m_pFemaleFI = & m_aFemaleFI;
299 m_pFemaleColumnFT = &m_aFemaleColumnFT;
300 m_pFemaleColumnLB = &m_aFemaleColumnLB;
301 m_pFemaleFieldFT = & m_aFemaleFieldFT;
302 m_pFemaleFieldCB = & m_aFemaleFieldCB;
303 m_pNeutralFT = & m_aNeutralFT;
304 m_pNeutralCB = &m_aNeutralCB;
305 m_bIsTabPage = true;
306
307 m_pPersonalizedCB->SetHelpId( HID_MM_GREETINGS_CB_PERSONALIZED);
308 m_pFemaleLB->SetHelpId( HID_MM_GREETINGS_LB_FEMALE );
309 m_pFemalePB->SetHelpId( HID_MM_GREETINGS_PB_FEMALE );
310 m_pMaleLB->SetHelpId( HID_MM_GREETINGS_LB_MALE );
311 m_pMalePB->SetHelpId( HID_MM_GREETINGS_PB_MALE );
312 m_pFemaleColumnLB->SetHelpId( HID_MM_GREETINGS_LB_FEMALECOLUMN);
313 m_pFemaleFieldCB->SetHelpId( HID_MM_GREETINGS_CB_FEMALEFIELD );
314 m_pNeutralCB->SetHelpId( HID_MM_GREETINGS_CB_NEUTRAL );
315
316 FreeResource();
317 m_aGreetingLineCB.SetClickHdl(LINK(this, SwMailMergeGreetingsPage, ContainsHdl_Impl));
318 Link aIndividualLink = LINK(this, SwGreetingsHandler, IndividualHdl_Impl);
319 m_aPersonalizedCB.SetClickHdl(aIndividualLink);
320 Link aGreetingLink = LINK(this, SwGreetingsHandler, GreetingHdl_Impl);
321 m_aFemalePB.SetClickHdl(aGreetingLink);
322 m_aMalePB.SetClickHdl(aGreetingLink);
323 m_aAssignPB.SetClickHdl(LINK(this, SwMailMergeGreetingsPage, AssignHdl_Impl));
324 Link aLBoxLink = LINK(this, SwMailMergeGreetingsPage, GreetingSelectHdl_Impl);
325 m_aFemaleLB.SetSelectHdl(aLBoxLink);
326 m_aMaleLB.SetSelectHdl(aLBoxLink);
327 m_aFemaleColumnLB.SetSelectHdl(aLBoxLink);
328 m_aFemaleFieldCB.SetSelectHdl(aLBoxLink);
329 m_aFemaleFieldCB.SetModifyHdl(aLBoxLink);
330 m_aNeutralCB.SetSelectHdl(aLBoxLink);
331 m_aNeutralCB.SetModifyHdl(aLBoxLink);
332
333 Link aDataLink = LINK(this, SwMailMergeGreetingsPage, InsertDataHdl_Impl);
334 m_aPrevSetIB.SetClickHdl(aDataLink);
335 m_aNextSetIB.SetClickHdl(aDataLink);
336
337
338 SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
339 m_aGreetingLineCB.Check(rConfig.IsGreetingLine(sal_False));
340 m_aPersonalizedCB.Check(rConfig.IsIndividualGreeting(sal_False));
341 ContainsHdl_Impl(&m_aGreetingLineCB);
342 aIndividualLink.Call(0);
343
344 lcl_FillGreetingsBox(m_aFemaleLB, rConfig, SwMailMergeConfigItem::FEMALE);
345 lcl_FillGreetingsBox(m_aMaleLB, rConfig, SwMailMergeConfigItem::MALE);
346 lcl_FillGreetingsBox(m_aNeutralCB, rConfig, SwMailMergeConfigItem::NEUTRAL);
347
348 String sTemp(m_sDocument);
349 sTemp.SearchAndReplaceAscii("%1", String::CreateFromInt32(1));
350 m_aDocumentIndexFI.SetText(sTemp);
351 }
352 /*-- 02.04.2004 14:17:52---------------------------------------------------
353
354 -----------------------------------------------------------------------*/
~SwMailMergeGreetingsPage()355 SwMailMergeGreetingsPage::~SwMailMergeGreetingsPage()
356 {
357 }
358 /*-- 18.06.2004 12:13:53---------------------------------------------------
359
360 -----------------------------------------------------------------------*/
ActivatePage()361 void SwMailMergeGreetingsPage::ActivatePage()
362 {
363 SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
364
365 //try to find the gender setting
366 m_aFemaleColumnLB.Clear();
367 Reference< sdbcx::XColumnsSupplier > xColsSupp = rConfig.GetColumnsSupplier();
368 if(xColsSupp.is())
369 {
370 Reference < container::XNameAccess> xColAccess = xColsSupp->getColumns();
371 Sequence< ::rtl::OUString > aColumns = xColAccess->getElementNames();
372 for(sal_Int32 nName = 0; nName < aColumns.getLength(); ++nName)
373 m_aFemaleColumnLB.InsertEntry(aColumns[nName]);
374 }
375
376 ::rtl::OUString sGenderColumn = rConfig.GetAssignedColumn(MM_PART_GENDER);
377 m_aFemaleColumnLB.SelectEntry(sGenderColumn);
378 m_aFemaleColumnLB.SaveValue();
379
380 m_aFemaleFieldCB.SetText(rConfig.GetFemaleGenderValue());
381 m_aFemaleFieldCB.SaveValue();
382
383 UpdatePreview();
384 m_pWizard->enableButtons(WZB_NEXT, m_pWizard->isStateEnabled(MM_PREPAREMERGEPAGE));
385 }
386 /*-- 11.05.2004 14:47:10---------------------------------------------------
387
388 -----------------------------------------------------------------------*/
commitPage(::svt::WizardTypes::CommitPageReason)389 sal_Bool SwMailMergeGreetingsPage::commitPage( ::svt::WizardTypes::CommitPageReason )
390 {
391 SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
392
393 if(m_aFemaleColumnLB.GetSelectEntryPos() != m_aFemaleColumnLB.GetSavedValue())
394 {
395 const SwDBData& rDBData = rConfig.GetCurrentDBData();
396 Sequence< ::rtl::OUString> aAssignment = rConfig.GetColumnAssignment( rDBData );
397 if(aAssignment.getLength() <= MM_PART_GENDER)
398 aAssignment.realloc(MM_PART_GENDER + 1);
399 aAssignment[MM_PART_GENDER] = m_aFemaleColumnLB.GetSelectEntry();
400 rConfig.SetColumnAssignment( rDBData, aAssignment );
401 }
402 if(m_aFemaleFieldCB.GetText() != m_aFemaleFieldCB.GetSavedValue())
403 rConfig.SetFemaleGenderValue(m_aFemaleFieldCB.GetText());
404
405 lcl_StoreGreetingsBox(m_aFemaleLB, rConfig, SwMailMergeConfigItem::FEMALE);
406 lcl_StoreGreetingsBox(m_aMaleLB, rConfig, SwMailMergeConfigItem::MALE);
407
408 sal_uInt16 nCurrentTextPos = m_aNeutralCB.GetEntryPos( m_aNeutralCB.GetText() );
409 if(LISTBOX_ENTRY_NOTFOUND == nCurrentTextPos)
410 {
411 sal_uInt16 nCount = m_aNeutralCB.GetEntryCount();
412 m_aNeutralCB.InsertEntry( m_aNeutralCB.GetText(), nCount );
413 m_aNeutralCB.SelectEntryPos(nCount);
414 }
415 lcl_StoreGreetingsBox(m_aNeutralCB, rConfig, SwMailMergeConfigItem::NEUTRAL);
416 rConfig.SetGreetingLine(m_aGreetingLineCB.IsChecked(), sal_False);
417 rConfig.SetIndividualGreeting(m_aPersonalizedCB.IsChecked(), sal_False);
418 return sal_True;
419 }
420 /*-- 30.04.2004 10:42:57---------------------------------------------------
421
422 -----------------------------------------------------------------------*/
IMPL_LINK(SwMailMergeGreetingsPage,ContainsHdl_Impl,CheckBox *,pBox)423 IMPL_LINK(SwMailMergeGreetingsPage, ContainsHdl_Impl, CheckBox*, pBox)
424 {
425 sal_Bool bContainsGreeting = pBox->IsChecked();
426 SwGreetingsHandler::Contains(bContainsGreeting);
427 m_aPreviewFI. Enable(bContainsGreeting);
428 m_aPreviewWIN.Enable(bContainsGreeting);
429 m_aAssignPB. Enable(bContainsGreeting);
430 m_aDocumentIndexFI. Enable(bContainsGreeting);
431 m_aPrevSetIB.Enable(bContainsGreeting);
432 m_aNextSetIB.Enable(bContainsGreeting);
433 SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
434 rConfig.SetGreetingLine(m_aGreetingLineCB.IsChecked(), sal_False);
435 m_pWizard->UpdateRoadmap();
436 return 0;
437 }
438 /*-- 07.05.2004 12:56:42---------------------------------------------------
439
440 -----------------------------------------------------------------------*/
IMPL_LINK(SwMailMergeGreetingsPage,InsertDataHdl_Impl,ImageButton *,pButton)441 IMPL_LINK(SwMailMergeGreetingsPage, InsertDataHdl_Impl, ImageButton*, pButton)
442 {
443 //if no pButton is given, the first set has to be pre-set
444 SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
445 if(!pButton)
446 {
447 rConfig.GetResultSet();
448 }
449 else
450 {
451 sal_Bool bNext = pButton == &m_aNextSetIB;
452 sal_Int32 nPos = rConfig.GetResultSetPosition();
453 rConfig.MoveResultSet( bNext ? ++nPos : --nPos);
454 }
455 sal_Int32 nPos = rConfig.GetResultSetPosition();
456 sal_Bool bEnable = sal_True;
457 if(nPos < 1)
458 {
459 bEnable = sal_False;
460 nPos = 1;
461 }
462 else
463 UpdatePreview();
464 m_aPrevSetIB.Enable(bEnable);
465 m_aNextSetIB.Enable(bEnable);
466 m_aDocumentIndexFI.Enable(bEnable);
467 String sTemp(m_sDocument);
468 sTemp.SearchAndReplaceAscii("%1", String::CreateFromInt32(nPos));
469 m_aDocumentIndexFI.SetText(sTemp);
470 return 0;
471 }
472 /*-- 17.05.2004 15:11:19---------------------------------------------------
473
474 -----------------------------------------------------------------------*/
SwMailBodyDialog(Window * pParent,SwMailMergeWizard * _pWizard)475 SwMailBodyDialog::SwMailBodyDialog(Window* pParent, SwMailMergeWizard* _pWizard) :
476 SfxModalDialog(pParent, SW_RES(DLG_MM_MAILBODY)),
477 #ifdef MSC
478 #pragma warning (disable : 4355)
479 #endif
480 m_aGreetingLineCB(this, SW_RES( CB_GREETINGLINE ) ),
481 m_aPersonalizedCB(this, SW_RES( CB_PERSONALIZED ) ),
482 m_aFemaleFT(this, SW_RES( FT_FEMALE ) ),
483 m_aFemaleLB(this, SW_RES( LB_FEMALE ) ),
484 m_aFemalePB(this, SW_RES( PB_FEMALE ) ),
485 m_aMaleFT(this, SW_RES( FT_MALE ) ),
486 m_aMaleLB(this, SW_RES( LB_MALE ) ),
487 m_aMalePB(this, SW_RES( PB_MALE ) ),
488 m_aFemaleFI(this, SW_RES( FI_FEMALE ) ),
489 m_aFemaleColumnFT(this, SW_RES( FT_FEMALECOLUMN ) ),
490 m_aFemaleColumnLB(this, SW_RES( LB_FEMALECOLUMN ) ),
491 m_aFemaleFieldFT(this, SW_RES( FT_FEMALEFIELD ) ),
492 m_aFemaleFieldCB(this, SW_RES( CB_FEMALEFIELD ) ),
493 m_aNeutralFT(this, SW_RES( FT_NEUTRAL ) ),
494 m_aNeutralCB(this, SW_RES( CB_NEUTRAL ) ),
495 m_aBodyFT( this, SW_RES( FT_BODY ) ),
496 m_aBodyMLE( this, SW_RES( MLE_BODY ) ),
497 m_aSeparatorFL( this, SW_RES( FL_SEPARATOR ) ),
498 m_aOK( this, SW_RES( PB_OK ) ),
499 m_aCancel( this, SW_RES( PB_CANCEL ) ),
500 m_aHelp( this, SW_RES( PB_HELP ) )
501 #ifdef MSC
502 #pragma warning (default : 4355)
503 #endif
504 {
505 m_pWizard = _pWizard;
506 m_pGreetingLineCB = &m_aGreetingLineCB;
507 m_pPersonalizedCB = &m_aPersonalizedCB;
508 m_pFemaleFT = & m_aFemaleFT;
509 m_pFemaleLB = & m_aFemaleLB;
510 m_pFemalePB = & m_aFemalePB;
511 m_pMaleFT = & m_aMaleFT;
512 m_pMaleLB = & m_aMaleLB;
513 m_pMalePB = & m_aMalePB;
514 m_pFemaleFI = & m_aFemaleFI;
515 m_pFemaleColumnFT = &m_aFemaleColumnFT;
516 m_pFemaleColumnLB = &m_aFemaleColumnLB;
517 m_pFemaleFieldFT = & m_aFemaleFieldFT;
518 m_pFemaleFieldCB = & m_aFemaleFieldCB;
519 m_pNeutralFT = & m_aNeutralFT;
520 m_pNeutralCB = &m_aNeutralCB;
521 m_bIsTabPage = false;
522
523 m_pPersonalizedCB->SetHelpId( HID_MM_BODY_CB_PERSONALIZED );
524 m_pFemaleLB->SetHelpId( HID_MM_BODY_LB_FEMALE );
525 m_pFemalePB->SetHelpId( HID_MM_BODY_PB_FEMALE );
526 m_pMaleLB->SetHelpId( HID_MM_BODY_LB_MALE );
527 m_pMalePB->SetHelpId( HID_MM_BODY_PB_MALE );
528 m_pFemaleColumnLB->SetHelpId( HID_MM_BODY_LB_FEMALECOLUMN );
529 m_pFemaleFieldCB->SetHelpId( HID_MM_BODY_CB_FEMALEFIELD );
530 m_pNeutralCB->SetHelpId( HID_MM_BODY_CB_NEUTRAL );
531
532 FreeResource();
533 m_aGreetingLineCB.SetClickHdl(LINK(this, SwMailBodyDialog, ContainsHdl_Impl));
534 Link aIndividualLink = LINK(this, SwGreetingsHandler, IndividualHdl_Impl);
535 m_aPersonalizedCB.SetClickHdl(aIndividualLink);
536 Link aGreetingLink = LINK(this, SwGreetingsHandler, GreetingHdl_Impl);
537 m_aFemalePB.SetClickHdl(aGreetingLink);
538 m_aMalePB.SetClickHdl(aGreetingLink);
539 m_aOK.SetClickHdl(LINK(this, SwMailBodyDialog, OKHdl));
540
541 SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
542 m_aGreetingLineCB.Check(rConfig.IsGreetingLine(sal_True));
543 m_aPersonalizedCB.Check(rConfig.IsIndividualGreeting(sal_True));
544 ContainsHdl_Impl(&m_aGreetingLineCB);
545 aIndividualLink.Call(0);
546
547 lcl_FillGreetingsBox(m_aFemaleLB, rConfig, SwMailMergeConfigItem::FEMALE);
548 lcl_FillGreetingsBox(m_aMaleLB, rConfig, SwMailMergeConfigItem::MALE);
549 lcl_FillGreetingsBox(m_aNeutralCB, rConfig, SwMailMergeConfigItem::NEUTRAL);
550
551 //try to find the gender setting
552 m_aFemaleColumnLB.Clear();
553 Reference< sdbcx::XColumnsSupplier > xColsSupp = rConfig.GetColumnsSupplier();
554 if(xColsSupp.is())
555 {
556 Reference < container::XNameAccess> xColAccess = xColsSupp->getColumns();
557 Sequence< ::rtl::OUString > aColumns = xColAccess->getElementNames();
558 for(sal_Int32 nName = 0; nName < aColumns.getLength(); ++nName)
559 m_aFemaleColumnLB.InsertEntry(aColumns[nName]);
560 }
561
562 ::rtl::OUString sGenderColumn = rConfig.GetAssignedColumn(MM_PART_GENDER);
563 m_aFemaleColumnLB.SelectEntry(sGenderColumn);
564 m_aFemaleColumnLB.SaveValue();
565
566 m_aFemaleFieldCB.SetText(rConfig.GetFemaleGenderValue());
567 m_aFemaleFieldCB.SaveValue();
568 }
569 /*-- 17.05.2004 15:13:07---------------------------------------------------
570
571 -----------------------------------------------------------------------*/
~SwMailBodyDialog()572 SwMailBodyDialog::~SwMailBodyDialog()
573 {
574 }
575
576 /*-- 30.04.2004 10:42:57---------------------------------------------------
577
578 -----------------------------------------------------------------------*/
IMPL_LINK(SwMailBodyDialog,ContainsHdl_Impl,CheckBox *,pBox)579 IMPL_LINK(SwMailBodyDialog, ContainsHdl_Impl, CheckBox*, pBox)
580 {
581 SwGreetingsHandler::Contains(pBox->IsChecked());
582 m_pWizard->GetConfigItem().SetGreetingLine(pBox->IsChecked(), sal_True);
583 return 0;
584 }
585 /*-- 28.06.2004 11:22:42---------------------------------------------------
586
587 -----------------------------------------------------------------------*/
IMPL_LINK(SwMailBodyDialog,OKHdl,PushButton *,EMPTYARG)588 IMPL_LINK(SwMailBodyDialog, OKHdl, PushButton*, EMPTYARG)
589 {
590 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
591 rConfigItem.SetGreetingLine(
592 m_aGreetingLineCB.IsChecked(), sal_False);
593 rConfigItem.SetIndividualGreeting(
594 m_aPersonalizedCB.IsChecked(), sal_False);
595
596 if(m_aFemaleColumnLB.GetSelectEntryPos() != m_aFemaleColumnLB.GetSavedValue())
597 {
598 const SwDBData& rDBData = rConfigItem.GetCurrentDBData();
599 Sequence< ::rtl::OUString> aAssignment = rConfigItem.GetColumnAssignment( rDBData );
600 sal_Int32 nPos = m_aFemaleColumnLB.GetSelectEntryPos();
601 if(aAssignment.getLength() < MM_PART_GENDER)
602 aAssignment.realloc(MM_PART_GENDER);
603 if( nPos > 0 )
604 aAssignment[MM_PART_GENDER] = m_aFemaleColumnLB.GetSelectEntry();
605 else
606 aAssignment[MM_PART_GENDER] = ::rtl::OUString();
607 rConfigItem.SetColumnAssignment( rDBData, aAssignment );
608 }
609 if(m_aFemaleFieldCB.GetText() != m_aFemaleFieldCB.GetSavedValue())
610 rConfigItem.SetFemaleGenderValue(m_aFemaleFieldCB.GetText());
611
612 EndDialog(RET_OK);
613 return 0;
614 }
615
616