LCOV - code coverage report
Current view: top level - sw/source/ui/dbui - mmgreetingspage.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 335 0.0 %
Date: 2014-04-14 Functions: 0 33 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10