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