1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mmgreetingspage.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
37 #include <mmgreetingspage.hxx>
38 #include <mailmergewizard.hxx>
39 #include <mmconfigitem.hxx>
40 #include <mmaddressblockpage.hxx>
41 #include <swtypes.hxx>
42 #include <vcl/msgbox.hxx>
43 #include <mmgreetingspage.hrc>
45 #include <com/sun/star/sdb/XColumn.hpp>
46 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
47 #include <com/sun/star/container/XNameAccess.hpp>
51 using namespace ::com::sun::star
;
52 using namespace ::com::sun::star::uno
;
53 // -----------------------------------------------------------------------
54 void lcl_FillGreetingsBox(ListBox
& rBox
,
55 SwMailMergeConfigItem
& rConfig
,
56 SwMailMergeConfigItem::Gender eType
)
58 const Sequence
< ::rtl::OUString
> rEntries
= rConfig
.GetGreetings(eType
);
59 for(sal_Int32 nEntry
= 0; nEntry
< rEntries
.getLength(); ++nEntry
)
60 rBox
.InsertEntry(rEntries
[nEntry
]);
61 rBox
.SelectEntryPos((USHORT
)rConfig
.GetCurrentGreeting(eType
));
63 // -----------------------------------------------------------------------
64 void lcl_FillGreetingsBox(ComboBox
& rBox
,
65 SwMailMergeConfigItem
& rConfig
,
66 SwMailMergeConfigItem::Gender eType
)
68 const Sequence
< ::rtl::OUString
> rEntries
= rConfig
.GetGreetings(eType
);
69 for(sal_Int32 nEntry
= 0; nEntry
< rEntries
.getLength(); ++nEntry
)
70 rBox
.InsertEntry(rEntries
[nEntry
]);
71 rBox
.SelectEntryPos((USHORT
)rConfig
.GetCurrentGreeting(eType
));
73 // -----------------------------------------------------------------------
74 void lcl_StoreGreetingsBox(ListBox
& rBox
,
75 SwMailMergeConfigItem
& rConfig
,
76 SwMailMergeConfigItem::Gender eType
)
78 Sequence
< ::rtl::OUString
> aEntries(rBox
.GetEntryCount());
79 ::rtl::OUString
* pEntries
= aEntries
.getArray();
80 for(USHORT nEntry
= 0; nEntry
< rBox
.GetEntryCount(); ++nEntry
)
81 pEntries
[nEntry
] = rBox
.GetEntry(nEntry
);
82 rConfig
.SetGreetings(eType
, aEntries
);
83 rConfig
.SetCurrentGreeting(eType
, rBox
.GetSelectEntryPos());
85 // -----------------------------------------------------------------------
86 void lcl_StoreGreetingsBox(ComboBox
& rBox
,
87 SwMailMergeConfigItem
& rConfig
,
88 SwMailMergeConfigItem::Gender eType
)
90 Sequence
< ::rtl::OUString
> aEntries(rBox
.GetEntryCount());
91 ::rtl::OUString
* pEntries
= aEntries
.getArray();
92 for(USHORT nEntry
= 0; nEntry
< rBox
.GetEntryCount(); ++nEntry
)
93 pEntries
[nEntry
] = rBox
.GetEntry(nEntry
);
94 rConfig
.SetGreetings(eType
, aEntries
);
95 rConfig
.SetCurrentGreeting(eType
, rBox
.GetSelectEntryPos());
97 /*-- 30.04.2004 10:42:57---------------------------------------------------
99 -----------------------------------------------------------------------*/
100 IMPL_LINK(SwGreetingsHandler
, IndividualHdl_Impl
, CheckBox
*, EMPTYARG
)
102 BOOL bIndividual
= m_pPersonalizedCB
->IsEnabled() && m_pPersonalizedCB
->IsChecked();
103 m_pFemaleFT
->Enable(bIndividual
);
104 m_pFemaleLB
->Enable(bIndividual
);
105 m_pFemalePB
->Enable(bIndividual
);
106 m_pMaleFT
->Enable(bIndividual
);
107 m_pMaleLB
->Enable(bIndividual
);
108 m_pMalePB
->Enable(bIndividual
);
109 m_pFemaleFI
->Enable(bIndividual
);
110 m_pFemaleColumnFT
->Enable(bIndividual
);
111 m_pFemaleColumnLB
->Enable(bIndividual
);
112 m_pFemaleFieldFT
->Enable(bIndividual
);
113 m_pFemaleFieldCB
->Enable(bIndividual
);
117 m_pWizard
->GetConfigItem().SetIndividualGreeting(bIndividual
, sal_False
);
118 m_pWizard
->UpdateRoadmap();
119 m_pWizard
->enableButtons(WZB_NEXT
, m_pWizard
->isStateEnabled(MM_PREPAREMERGEPAGE
));
124 /*-- 30.04.2004 10:42:57---------------------------------------------------
126 -----------------------------------------------------------------------*/
127 IMPL_LINK(SwGreetingsHandler
, GreetingHdl_Impl
, PushButton
*, pButton
)
129 SwCustomizeAddressBlockDialog
* pDlg
=
130 new SwCustomizeAddressBlockDialog(pButton
, m_pWizard
->GetConfigItem(),
131 pButton
== m_pMalePB
?
132 SwCustomizeAddressBlockDialog::GREETING_MALE
:
133 SwCustomizeAddressBlockDialog::GREETING_FEMALE
);
134 if(RET_OK
== pDlg
->Execute())
136 ListBox
* pToInsert
= pButton
== m_pMalePB
? m_pMaleLB
: m_pFemaleLB
;
137 pToInsert
->SelectEntryPos(pToInsert
->InsertEntry(pDlg
->GetAddress()));
140 m_pWizard
->UpdateRoadmap();
141 m_pWizard
->enableButtons(WZB_NEXT
, m_pWizard
->isStateEnabled(MM_PREPAREMERGEPAGE
));
148 /*-- 16.06.2004 10:56:21---------------------------------------------------
150 -----------------------------------------------------------------------*/
151 void SwGreetingsHandler::UpdatePreview()
153 //the base class does nothing
155 /*-- 30.04.2004 10:42:59---------------------------------------------------
157 -----------------------------------------------------------------------*/
158 IMPL_LINK(SwMailMergeGreetingsPage
, AssignHdl_Impl
, PushButton
*, pButton
)
160 String sPreview
= m_aFemaleLB
.GetSelectEntry();
162 sPreview
+= m_aMaleLB
.GetSelectEntry();
163 SwAssignFieldsDialog
* pDlg
=
164 new SwAssignFieldsDialog(pButton
, m_pWizard
->GetConfigItem(), sPreview
, false);
165 if(RET_OK
== pDlg
->Execute())
168 m_pWizard
->UpdateRoadmap();
169 m_pWizard
->enableButtons(WZB_NEXT
, m_pWizard
->isStateEnabled(MM_PREPAREMERGEPAGE
));
174 /*-- 05.05.2004 15:25:56---------------------------------------------------
176 -----------------------------------------------------------------------*/
177 IMPL_LINK(SwMailMergeGreetingsPage
, GreetingSelectHdl_Impl
, ListBox
*, EMPTYARG
)
182 /*-- 05.05.2004 15:23:43---------------------------------------------------
184 -----------------------------------------------------------------------*/
185 void SwMailMergeGreetingsPage::UpdatePreview()
187 //find out which type of greeting should be selected:
188 bool bFemale
= false;
189 bool bNoValue
= !m_pFemaleColumnLB
->IsEnabled();
192 ::rtl::OUString sFemaleValue
= m_aFemaleFieldCB
.GetText();
193 ::rtl::OUString sFemaleColumn
= m_aFemaleColumnLB
.GetSelectEntry();
194 Reference
< sdbcx::XColumnsSupplier
> xColsSupp( m_pWizard
->GetConfigItem().GetResultSet(), UNO_QUERY
);
195 Reference
< container::XNameAccess
> xColAccess
= xColsSupp
.is() ? xColsSupp
->getColumns() : 0;
196 if(sFemaleValue
.getLength() && sFemaleColumn
.getLength() &&
198 xColAccess
->hasByName(sFemaleColumn
))
200 //get the content and exchange it in the address string
201 Any aCol
= xColAccess
->getByName(sFemaleColumn
);
202 Reference
< sdb::XColumn
> xColumn
;
208 ::rtl::OUString sFemaleColumnValue
= xColumn
->getString();
209 bFemale
= sFemaleColumnValue
== sFemaleValue
;
210 //bNoValue = !sFemaleColumnValue.getLength();
213 //no last name value marks the greeting also als neutral
214 SwMailMergeConfigItem
& rConfig
= m_pWizard
->GetConfigItem();
215 ::rtl::OUString sLastNameColumn
= rConfig
.GetAssignedColumn(MM_PART_LASTNAME
);
216 if ( xColAccess
->hasByName(sLastNameColumn
) )
218 aCol
= xColAccess
->getByName(sLastNameColumn
);
220 ::rtl::OUString sLastNameColumnValue
= xColumn
->getString();
221 bNoValue
= !sLastNameColumnValue
.getLength();
225 catch( sdbc::SQLException
& )
227 DBG_ERROR("SQLException caught");
233 String sPreview
= bFemale
? m_aFemaleLB
.GetSelectEntry() :
234 bNoValue
? m_aNeutralCB
.GetText() : m_aMaleLB
.GetSelectEntry();
236 sPreview
= SwAddressPreview::FillData(sPreview
, m_pWizard
->GetConfigItem());
237 m_aPreviewWIN
.SetAddress(sPreview
);
239 /*-- 17.05.2004 15:44:53---------------------------------------------------
241 -----------------------------------------------------------------------*/
242 void SwGreetingsHandler::Contains(sal_Bool bContainsGreeting
)
244 m_pPersonalizedCB
->Enable(bContainsGreeting
);
245 sal_Bool bEnablePersonal
= bContainsGreeting
&& m_pPersonalizedCB
->IsChecked();
246 m_pFemaleFT
->Enable(bEnablePersonal
);
247 m_pFemaleLB
->Enable(bEnablePersonal
);
248 m_pFemalePB
->Enable(bEnablePersonal
);
249 m_pMaleFT
->Enable(bEnablePersonal
);
250 m_pMaleLB
->Enable(bEnablePersonal
);
251 m_pMalePB
->Enable(bEnablePersonal
);
252 m_pFemaleFI
->Enable(bEnablePersonal
);
253 m_pFemaleColumnFT
->Enable(bEnablePersonal
);
254 m_pFemaleColumnLB
->Enable(bEnablePersonal
);
255 m_pFemaleFieldFT
->Enable(bEnablePersonal
);
256 m_pFemaleFieldCB
->Enable(bEnablePersonal
);
258 m_pNeutralFT
->Enable(bContainsGreeting
);
259 m_pNeutralCB
->Enable(bContainsGreeting
);
261 /*-- 02.04.2004 14:17:52---------------------------------------------------
263 -----------------------------------------------------------------------*/
264 SwMailMergeGreetingsPage::SwMailMergeGreetingsPage( SwMailMergeWizard
* _pParent
) :
265 svt::OWizardPage(_pParent
, SW_RES(DLG_MM_GREETINGS_PAGE
)),
267 #pragma warning (disable : 4355)
269 m_aHeaderFI(this, SW_RES( FI_HEADER
) ),
270 m_aGreetingLineCB(this, SW_RES( CB_GREETINGLINE
) ),
271 m_aPersonalizedCB(this, SW_RES( CB_PERSONALIZED
) ),
272 m_aFemaleFT(this, SW_RES( FT_FEMALE
) ),
273 m_aFemaleLB(this, SW_RES( LB_FEMALE
) ),
274 m_aFemalePB(this, SW_RES( PB_FEMALE
) ),
275 m_aMaleFT(this, SW_RES( FT_MALE
) ),
276 m_aMaleLB(this, SW_RES( LB_MALE
) ),
277 m_aMalePB(this, SW_RES( PB_MALE
) ),
278 m_aFemaleFI(this, SW_RES( FI_FEMALE
) ),
279 m_aFemaleColumnFT(this, SW_RES( FT_FEMALECOLUMN
) ),
280 m_aFemaleColumnLB(this, SW_RES( LB_FEMALECOLUMN
) ),
281 m_aFemaleFieldFT(this, SW_RES( FT_FEMALEFIELD
) ),
282 m_aFemaleFieldCB(this, SW_RES( CB_FEMALEFIELD
) ),
283 m_aNeutralFT(this, SW_RES( FT_NEUTRAL
) ),
284 m_aNeutralCB(this, SW_RES( CB_NEUTRAL
) ),
285 m_aPreviewFI( this, SW_RES( FI_PREVIEW
) ),
286 m_aPreviewWIN( this, SW_RES( WIN_PREVIEW
) ),
287 m_aAssignPB( this, SW_RES( PB_ASSIGN
) ),
288 m_aDocumentIndexFI( this, SW_RES( FI_DOCINDEX
) ),
289 m_aPrevSetIB( this, SW_RES( IB_PREVSET
) ),
290 m_aNextSetIB( this, SW_RES( IB_NEXTSET
) ),
291 m_sDocument( SW_RES( STR_DOCUMENT
) )
293 #pragma warning (default : 4355)
296 m_pWizard
= _pParent
;
297 m_pGreetingLineCB
= &m_aGreetingLineCB
;
298 m_pPersonalizedCB
= &m_aPersonalizedCB
;
299 m_pFemaleFT
= & m_aFemaleFT
;
300 m_pFemaleLB
= & m_aFemaleLB
;
301 m_pFemalePB
= & m_aFemalePB
;
302 m_pMaleFT
= & m_aMaleFT
;
303 m_pMaleLB
= & m_aMaleLB
;
304 m_pMalePB
= & m_aMalePB
;
305 m_pFemaleFI
= & m_aFemaleFI
;
306 m_pFemaleColumnFT
= &m_aFemaleColumnFT
;
307 m_pFemaleColumnLB
= &m_aFemaleColumnLB
;
308 m_pFemaleFieldFT
= & m_aFemaleFieldFT
;
309 m_pFemaleFieldCB
= & m_aFemaleFieldCB
;
310 m_pNeutralFT
= & m_aNeutralFT
;
311 m_pNeutralCB
= &m_aNeutralCB
;
314 m_pPersonalizedCB
->SetHelpId( HID_MM_GREETINGS_CB_PERSONALIZED
);
315 m_pFemaleLB
->SetHelpId( HID_MM_GREETINGS_LB_FEMALE
);
316 m_pFemalePB
->SetHelpId( HID_MM_GREETINGS_PB_FEMALE
);
317 m_pMaleLB
->SetHelpId( HID_MM_GREETINGS_LB_MALE
);
318 m_pMalePB
->SetHelpId( HID_MM_GREETINGS_PB_MALE
);
319 m_pFemaleColumnLB
->SetHelpId( HID_MM_GREETINGS_LB_FEMALECOLUMN
);
320 m_pFemaleFieldCB
->SetHelpId( HID_MM_GREETINGS_CB_FEMALEFIELD
);
321 m_pNeutralCB
->SetHelpId( HID_MM_GREETINGS_CB_NEUTRAL
);
324 m_aGreetingLineCB
.SetClickHdl(LINK(this, SwMailMergeGreetingsPage
, ContainsHdl_Impl
));
325 Link aIndividualLink
= LINK(this, SwGreetingsHandler
, IndividualHdl_Impl
);
326 m_aPersonalizedCB
.SetClickHdl(aIndividualLink
);
327 Link aGreetingLink
= LINK(this, SwGreetingsHandler
, GreetingHdl_Impl
);
328 m_aFemalePB
.SetClickHdl(aGreetingLink
);
329 m_aMalePB
.SetClickHdl(aGreetingLink
);
330 m_aAssignPB
.SetClickHdl(LINK(this, SwMailMergeGreetingsPage
, AssignHdl_Impl
));
331 Link aLBoxLink
= LINK(this, SwMailMergeGreetingsPage
, GreetingSelectHdl_Impl
);
332 m_aFemaleLB
.SetSelectHdl(aLBoxLink
);
333 m_aMaleLB
.SetSelectHdl(aLBoxLink
);
334 m_aFemaleColumnLB
.SetSelectHdl(aLBoxLink
);
335 m_aFemaleFieldCB
.SetSelectHdl(aLBoxLink
);
336 m_aFemaleFieldCB
.SetModifyHdl(aLBoxLink
);
337 m_aNeutralCB
.SetSelectHdl(aLBoxLink
);
338 m_aNeutralCB
.SetModifyHdl(aLBoxLink
);
340 Link aDataLink
= LINK(this, SwMailMergeGreetingsPage
, InsertDataHdl_Impl
);
341 m_aPrevSetIB
.SetClickHdl(aDataLink
);
342 m_aNextSetIB
.SetClickHdl(aDataLink
);
345 SwMailMergeConfigItem
& rConfig
= m_pWizard
->GetConfigItem();
346 m_aGreetingLineCB
.Check(rConfig
.IsGreetingLine(sal_False
));
347 m_aPersonalizedCB
.Check(rConfig
.IsIndividualGreeting(sal_False
));
348 ContainsHdl_Impl(&m_aGreetingLineCB
);
349 aIndividualLink
.Call(0);
351 lcl_FillGreetingsBox(m_aFemaleLB
, rConfig
, SwMailMergeConfigItem::FEMALE
);
352 lcl_FillGreetingsBox(m_aMaleLB
, rConfig
, SwMailMergeConfigItem::MALE
);
353 lcl_FillGreetingsBox(m_aNeutralCB
, rConfig
, SwMailMergeConfigItem::NEUTRAL
);
355 String
sTemp(m_sDocument
);
356 sTemp
.SearchAndReplaceAscii("%1", String::CreateFromInt32(1));
357 m_aDocumentIndexFI
.SetText(sTemp
);
359 /*-- 02.04.2004 14:17:52---------------------------------------------------
361 -----------------------------------------------------------------------*/
362 SwMailMergeGreetingsPage::~SwMailMergeGreetingsPage()
365 /*-- 18.06.2004 12:13:53---------------------------------------------------
367 -----------------------------------------------------------------------*/
368 void SwMailMergeGreetingsPage::ActivatePage()
370 SwMailMergeConfigItem
& rConfig
= m_pWizard
->GetConfigItem();
372 //try to find the gender setting
373 m_aFemaleColumnLB
.Clear();
374 Reference
< sdbcx::XColumnsSupplier
> xColsSupp
= rConfig
.GetColumnsSupplier();
377 Reference
< container::XNameAccess
> xColAccess
= xColsSupp
->getColumns();
378 Sequence
< ::rtl::OUString
> aColumns
= xColAccess
->getElementNames();
379 for(sal_Int32 nName
= 0; nName
< aColumns
.getLength(); ++nName
)
380 m_aFemaleColumnLB
.InsertEntry(aColumns
[nName
]);
383 ::rtl::OUString sGenderColumn
= rConfig
.GetAssignedColumn(MM_PART_GENDER
);
384 m_aFemaleColumnLB
.SelectEntry(sGenderColumn
);
385 m_aFemaleColumnLB
.SaveValue();
387 m_aFemaleFieldCB
.SetText(rConfig
.GetFemaleGenderValue());
388 m_aFemaleFieldCB
.SaveValue();
391 m_pWizard
->enableButtons(WZB_NEXT
, m_pWizard
->isStateEnabled(MM_PREPAREMERGEPAGE
));
393 /*-- 11.05.2004 14:47:10---------------------------------------------------
395 -----------------------------------------------------------------------*/
396 sal_Bool
SwMailMergeGreetingsPage::commitPage( CommitPageReason
)
398 SwMailMergeConfigItem
& rConfig
= m_pWizard
->GetConfigItem();
400 if(m_aFemaleColumnLB
.GetSelectEntryPos() != m_aFemaleColumnLB
.GetSavedValue())
402 const SwDBData
& rDBData
= rConfig
.GetCurrentDBData();
403 Sequence
< ::rtl::OUString
> aAssignment
= rConfig
.GetColumnAssignment( rDBData
);
404 if(aAssignment
.getLength() <= MM_PART_GENDER
)
405 aAssignment
.realloc(MM_PART_GENDER
+ 1);
406 aAssignment
[MM_PART_GENDER
] = m_aFemaleColumnLB
.GetSelectEntry();
407 rConfig
.SetColumnAssignment( rDBData
, aAssignment
);
409 if(m_aFemaleFieldCB
.GetText() != m_aFemaleFieldCB
.GetSavedValue())
410 rConfig
.SetFemaleGenderValue(m_aFemaleFieldCB
.GetText());
412 lcl_StoreGreetingsBox(m_aFemaleLB
, rConfig
, SwMailMergeConfigItem::FEMALE
);
413 lcl_StoreGreetingsBox(m_aMaleLB
, rConfig
, SwMailMergeConfigItem::MALE
);
415 USHORT nCurrentTextPos
= m_aNeutralCB
.GetEntryPos( m_aNeutralCB
.GetText() );
416 if(LISTBOX_ENTRY_NOTFOUND
== nCurrentTextPos
)
418 USHORT nCount
= m_aNeutralCB
.GetEntryCount();
419 m_aNeutralCB
.InsertEntry( m_aNeutralCB
.GetText(), nCount
);
420 m_aNeutralCB
.SelectEntryPos(nCount
);
422 lcl_StoreGreetingsBox(m_aNeutralCB
, rConfig
, SwMailMergeConfigItem::NEUTRAL
);
423 rConfig
.SetGreetingLine(m_aGreetingLineCB
.IsChecked(), sal_False
);
424 rConfig
.SetIndividualGreeting(m_aPersonalizedCB
.IsChecked(), sal_False
);
427 /*-- 30.04.2004 10:42:57---------------------------------------------------
429 -----------------------------------------------------------------------*/
430 IMPL_LINK(SwMailMergeGreetingsPage
, ContainsHdl_Impl
, CheckBox
*, pBox
)
432 sal_Bool bContainsGreeting
= pBox
->IsChecked();
433 SwGreetingsHandler::Contains(bContainsGreeting
);
434 m_aPreviewFI
. Enable(bContainsGreeting
);
435 m_aPreviewWIN
.Enable(bContainsGreeting
);
436 m_aAssignPB
. Enable(bContainsGreeting
);
437 m_aDocumentIndexFI
. Enable(bContainsGreeting
);
438 m_aPrevSetIB
.Enable(bContainsGreeting
);
439 m_aNextSetIB
.Enable(bContainsGreeting
);
440 SwMailMergeConfigItem
& rConfig
= m_pWizard
->GetConfigItem();
441 rConfig
.SetGreetingLine(m_aGreetingLineCB
.IsChecked(), sal_False
);
442 m_pWizard
->UpdateRoadmap();
445 /*-- 07.05.2004 12:56:42---------------------------------------------------
447 -----------------------------------------------------------------------*/
448 IMPL_LINK(SwMailMergeGreetingsPage
, InsertDataHdl_Impl
, ImageButton
*, pButton
)
450 //if no pButton is given, the first set has to be pre-set
451 SwMailMergeConfigItem
& rConfig
= m_pWizard
->GetConfigItem();
454 rConfig
.GetResultSet();
458 BOOL bNext
= pButton
== &m_aNextSetIB
;
459 sal_Int32 nPos
= rConfig
.GetResultSetPosition();
460 rConfig
.MoveResultSet( bNext
? ++nPos
: --nPos
);
462 sal_Int32 nPos
= rConfig
.GetResultSetPosition();
471 m_aPrevSetIB
.Enable(bEnable
);
472 m_aNextSetIB
.Enable(bEnable
);
473 m_aDocumentIndexFI
.Enable(bEnable
);
474 String
sTemp(m_sDocument
);
475 sTemp
.SearchAndReplaceAscii("%1", String::CreateFromInt32(nPos
));
476 m_aDocumentIndexFI
.SetText(sTemp
);
479 /*-- 17.05.2004 15:11:19---------------------------------------------------
481 -----------------------------------------------------------------------*/
482 SwMailBodyDialog::SwMailBodyDialog(Window
* pParent
, SwMailMergeWizard
* _pWizard
) :
483 SfxModalDialog(pParent
, SW_RES(DLG_MM_MAILBODY
)),
485 #pragma warning (disable : 4355)
487 m_aGreetingLineCB(this, SW_RES( CB_GREETINGLINE
) ),
488 m_aPersonalizedCB(this, SW_RES( CB_PERSONALIZED
) ),
489 m_aFemaleFT(this, SW_RES( FT_FEMALE
) ),
490 m_aFemaleLB(this, SW_RES( LB_FEMALE
) ),
491 m_aFemalePB(this, SW_RES( PB_FEMALE
) ),
492 m_aMaleFT(this, SW_RES( FT_MALE
) ),
493 m_aMaleLB(this, SW_RES( LB_MALE
) ),
494 m_aMalePB(this, SW_RES( PB_MALE
) ),
495 m_aFemaleFI(this, SW_RES( FI_FEMALE
) ),
496 m_aFemaleColumnFT(this, SW_RES( FT_FEMALECOLUMN
) ),
497 m_aFemaleColumnLB(this, SW_RES( LB_FEMALECOLUMN
) ),
498 m_aFemaleFieldFT(this, SW_RES( FT_FEMALEFIELD
) ),
499 m_aFemaleFieldCB(this, SW_RES( CB_FEMALEFIELD
) ),
500 m_aNeutralFT(this, SW_RES( FT_NEUTRAL
) ),
501 m_aNeutralCB(this, SW_RES( CB_NEUTRAL
) ),
502 m_aBodyFT( this, SW_RES( FT_BODY
) ),
503 m_aBodyMLE( this, SW_RES( MLE_BODY
) ),
504 m_aSeparatorFL( this, SW_RES( FL_SEPARATOR
) ),
505 m_aOK( this, SW_RES( PB_OK
) ),
506 m_aCancel( this, SW_RES( PB_CANCEL
) ),
507 m_aHelp( this, SW_RES( PB_HELP
) )
509 #pragma warning (default : 4355)
512 m_pWizard
= _pWizard
;
513 m_pGreetingLineCB
= &m_aGreetingLineCB
;
514 m_pPersonalizedCB
= &m_aPersonalizedCB
;
515 m_pFemaleFT
= & m_aFemaleFT
;
516 m_pFemaleLB
= & m_aFemaleLB
;
517 m_pFemalePB
= & m_aFemalePB
;
518 m_pMaleFT
= & m_aMaleFT
;
519 m_pMaleLB
= & m_aMaleLB
;
520 m_pMalePB
= & m_aMalePB
;
521 m_pFemaleFI
= & m_aFemaleFI
;
522 m_pFemaleColumnFT
= &m_aFemaleColumnFT
;
523 m_pFemaleColumnLB
= &m_aFemaleColumnLB
;
524 m_pFemaleFieldFT
= & m_aFemaleFieldFT
;
525 m_pFemaleFieldCB
= & m_aFemaleFieldCB
;
526 m_pNeutralFT
= & m_aNeutralFT
;
527 m_pNeutralCB
= &m_aNeutralCB
;
528 m_bIsTabPage
= false;
530 m_pPersonalizedCB
->SetHelpId( HID_MM_BODY_CB_PERSONALIZED
);
531 m_pFemaleLB
->SetHelpId( HID_MM_BODY_LB_FEMALE
);
532 m_pFemalePB
->SetHelpId( HID_MM_BODY_PB_FEMALE
);
533 m_pMaleLB
->SetHelpId( HID_MM_BODY_LB_MALE
);
534 m_pMalePB
->SetHelpId( HID_MM_BODY_PB_MALE
);
535 m_pFemaleColumnLB
->SetHelpId( HID_MM_BODY_LB_FEMALECOLUMN
);
536 m_pFemaleFieldCB
->SetHelpId( HID_MM_BODY_CB_FEMALEFIELD
);
537 m_pNeutralCB
->SetHelpId( HID_MM_BODY_CB_NEUTRAL
);
540 m_aGreetingLineCB
.SetClickHdl(LINK(this, SwMailBodyDialog
, ContainsHdl_Impl
));
541 Link aIndividualLink
= LINK(this, SwGreetingsHandler
, IndividualHdl_Impl
);
542 m_aPersonalizedCB
.SetClickHdl(aIndividualLink
);
543 Link aGreetingLink
= LINK(this, SwGreetingsHandler
, GreetingHdl_Impl
);
544 m_aFemalePB
.SetClickHdl(aGreetingLink
);
545 m_aMalePB
.SetClickHdl(aGreetingLink
);
546 m_aOK
.SetClickHdl(LINK(this, SwMailBodyDialog
, OKHdl
));
548 SwMailMergeConfigItem
& rConfig
= m_pWizard
->GetConfigItem();
549 m_aGreetingLineCB
.Check(rConfig
.IsGreetingLine(sal_True
));
550 m_aPersonalizedCB
.Check(rConfig
.IsIndividualGreeting(sal_True
));
551 ContainsHdl_Impl(&m_aGreetingLineCB
);
552 aIndividualLink
.Call(0);
554 lcl_FillGreetingsBox(m_aFemaleLB
, rConfig
, SwMailMergeConfigItem::FEMALE
);
555 lcl_FillGreetingsBox(m_aMaleLB
, rConfig
, SwMailMergeConfigItem::MALE
);
556 lcl_FillGreetingsBox(m_aNeutralCB
, rConfig
, SwMailMergeConfigItem::NEUTRAL
);
558 //try to find the gender setting
559 m_aFemaleColumnLB
.Clear();
560 Reference
< sdbcx::XColumnsSupplier
> xColsSupp
= rConfig
.GetColumnsSupplier();
563 Reference
< container::XNameAccess
> xColAccess
= xColsSupp
->getColumns();
564 Sequence
< ::rtl::OUString
> aColumns
= xColAccess
->getElementNames();
565 for(sal_Int32 nName
= 0; nName
< aColumns
.getLength(); ++nName
)
566 m_aFemaleColumnLB
.InsertEntry(aColumns
[nName
]);
569 ::rtl::OUString sGenderColumn
= rConfig
.GetAssignedColumn(MM_PART_GENDER
);
570 m_aFemaleColumnLB
.SelectEntry(sGenderColumn
);
571 m_aFemaleColumnLB
.SaveValue();
573 m_aFemaleFieldCB
.SetText(rConfig
.GetFemaleGenderValue());
574 m_aFemaleFieldCB
.SaveValue();
576 /*-- 17.05.2004 15:13:07---------------------------------------------------
578 -----------------------------------------------------------------------*/
579 SwMailBodyDialog::~SwMailBodyDialog()
583 /*-- 30.04.2004 10:42:57---------------------------------------------------
585 -----------------------------------------------------------------------*/
586 IMPL_LINK(SwMailBodyDialog
, ContainsHdl_Impl
, CheckBox
*, pBox
)
588 SwGreetingsHandler::Contains(pBox
->IsChecked());
589 m_pWizard
->GetConfigItem().SetGreetingLine(pBox
->IsChecked(), sal_True
);
592 /*-- 28.06.2004 11:22:42---------------------------------------------------
594 -----------------------------------------------------------------------*/
595 IMPL_LINK(SwMailBodyDialog
, OKHdl
, PushButton
*, EMPTYARG
)
597 SwMailMergeConfigItem
& rConfigItem
= m_pWizard
->GetConfigItem();
598 rConfigItem
.SetGreetingLine(
599 m_aGreetingLineCB
.IsChecked(), sal_False
);
600 rConfigItem
.SetIndividualGreeting(
601 m_aPersonalizedCB
.IsChecked(), sal_False
);
603 if(m_aFemaleColumnLB
.GetSelectEntryPos() != m_aFemaleColumnLB
.GetSavedValue())
605 const SwDBData
& rDBData
= rConfigItem
.GetCurrentDBData();
606 Sequence
< ::rtl::OUString
> aAssignment
= rConfigItem
.GetColumnAssignment( rDBData
);
607 sal_Int32 nPos
= m_aFemaleColumnLB
.GetSelectEntryPos();
608 if(aAssignment
.getLength() < MM_PART_GENDER
)
609 aAssignment
.realloc(MM_PART_GENDER
);
611 aAssignment
[MM_PART_GENDER
] = m_aFemaleColumnLB
.GetSelectEntry();
613 aAssignment
[MM_PART_GENDER
] = ::rtl::OUString();
614 rConfigItem
.SetColumnAssignment( rDBData
, aAssignment
);
616 if(m_aFemaleFieldCB
.GetText() != m_aFemaleFieldCB
.GetSavedValue())
617 rConfigItem
.SetFemaleGenderValue(m_aFemaleFieldCB
.GetText());