LCOV - code coverage report
Current view: top level - sw/source/ui/dbui - mmaddressblockpage.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 931 0.0 %
Date: 2014-04-14 Functions: 0 101 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 <mmaddressblockpage.hxx>
      21             : #include <mailmergewizard.hxx>
      22             : #include <swtypes.hxx>
      23             : #include <addresslistdialog.hxx>
      24             : #include <vcl/layout.hxx>
      25             : #include <vcl/txtattr.hxx>
      26             : #include <vcl/xtextedt.hxx>
      27             : #include <mmconfigitem.hxx>
      28             : #include <com/sun/star/container/XNameAccess.hpp>
      29             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      30             : #include <com/sun/star/sdb/XColumn.hpp>
      31             : #include <comphelper/string.hxx>
      32             : #include "svtools/treelistentry.hxx"
      33             : 
      34             : #include <vector>
      35             : #include <boost/scoped_ptr.hpp>
      36             : #include <mmaddressblockpage.hrc>
      37             : #include <globals.hrc>
      38             : #include <dbui.hrc>
      39             : #include <helpid.h>
      40             : 
      41             : using namespace svt;
      42             : using namespace ::com::sun::star;
      43             : using namespace ::com::sun::star::container;
      44             : using namespace ::com::sun::star::sdb;
      45             : using namespace ::com::sun::star::sdbc;
      46             : using namespace ::com::sun::star::sdbcx;
      47             : 
      48           0 : static void lcl_Move(Control* pCtrl, long nYOffset)
      49             : {
      50           0 :     Point aPos(pCtrl->GetPosPixel());
      51           0 :     aPos.Y() += nYOffset;
      52           0 :     pCtrl->SetPosPixel(aPos);
      53           0 : }
      54             : 
      55           0 : SwMailMergeAddressBlockPage::SwMailMergeAddressBlockPage( SwMailMergeWizard* _pParent) :
      56             :     svt::OWizardPage(_pParent, "MMAddressBlockPage",
      57             :         "modules/swriter/ui/mmaddressblockpage.ui")
      58           0 :     , m_pWizard(_pParent)
      59             : {
      60           0 :     get(m_pAddressListPB, "addresslist");
      61           0 :     get(m_pCurrentAddressFI, "currentaddress");
      62           0 :     get(m_pStep2, "step2");
      63           0 :     get(m_pStep3, "step3");
      64           0 :     get(m_pStep4, "step4");
      65           0 :     get(m_pSettingsFI, "settingsft");
      66           0 :     get(m_pAddressCB, "address");
      67           0 :     get(m_pSettingsWIN, "settingspreview");
      68           0 :     Size aSize(LogicToPixel(Size(164 , 45), MapMode(MAP_APPFONT)));
      69           0 :     m_pSettingsWIN->set_width_request(aSize.Width());
      70           0 :     m_pSettingsWIN->set_height_request(aSize.Height());
      71           0 :     get(m_pSettingsPB, "settings");
      72           0 :     get(m_pHideEmptyParagraphsCB, "hideempty");
      73           0 :     get(m_pAssignPB, "assign");
      74           0 :     get(m_pPreviewWIN, "addresspreview");
      75           0 :     aSize = LogicToPixel(Size(176, 46), MapMode(MAP_APPFONT));
      76           0 :     m_pPreviewWIN->set_width_request(aSize.Width());
      77           0 :     m_pPreviewWIN->set_height_request(aSize.Height());
      78           0 :     get(m_pDocumentIndexFI, "documentindex");
      79           0 :     get(m_pPrevSetIB, "prev");
      80           0 :     get(m_pNextSetIB, "next");
      81           0 :     m_sDocument = m_pDocumentIndexFI->GetText();
      82           0 :     m_sChangeAddress = get<Button>("differentlist")->GetText();
      83             : 
      84           0 :     m_sCurrentAddress = m_pCurrentAddressFI->GetText();
      85           0 :     m_pAddressListPB->SetClickHdl(LINK(this, SwMailMergeAddressBlockPage, AddressListHdl_Impl));
      86           0 :     m_pSettingsPB->SetClickHdl(LINK(this, SwMailMergeAddressBlockPage, SettingsHdl_Impl));
      87           0 :     m_pAssignPB->SetClickHdl(LINK(this, SwMailMergeAddressBlockPage, AssignHdl_Impl ));
      88           0 :     m_pAddressCB->SetClickHdl(LINK(this, SwMailMergeAddressBlockPage, AddressBlockHdl_Impl));
      89           0 :     m_pSettingsWIN->SetSelectHdl(LINK(this, SwMailMergeAddressBlockPage, AddressBlockSelectHdl_Impl));
      90           0 :     m_pHideEmptyParagraphsCB->SetClickHdl(LINK(this, SwMailMergeAddressBlockPage, HideParagraphsHdl_Impl));
      91             : 
      92           0 :     Link aLink = LINK(this, SwMailMergeAddressBlockPage, InsertDataHdl_Impl);
      93           0 :     m_pPrevSetIB->SetClickHdl(aLink);
      94           0 :     m_pNextSetIB->SetClickHdl(aLink);
      95           0 : }
      96             : 
      97           0 : bool SwMailMergeAddressBlockPage::canAdvance() const
      98             : {
      99           0 :     return m_pWizard->GetConfigItem().GetResultSet().is();
     100             : }
     101             : 
     102           0 : void SwMailMergeAddressBlockPage::ActivatePage()
     103             : {
     104           0 :     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
     105           0 :     bool bIsLetter = rConfigItem.IsOutputToLetter();
     106             : 
     107             :     //no address block is created for e-Mail
     108           0 :     m_pStep2->Show(bIsLetter);
     109           0 :     m_pStep3->Show(bIsLetter);
     110           0 :     m_pStep4->Show(bIsLetter);
     111             : 
     112           0 :     if (bIsLetter)
     113             :     {
     114           0 :         m_pHideEmptyParagraphsCB->Check( rConfigItem.IsHideEmptyParagraphs() );
     115           0 :         m_pDocumentIndexFI->SetText(m_sDocument.replaceFirst("%1", OUString::number(1)));
     116             : 
     117           0 :         m_pSettingsWIN->Clear();
     118             :         const uno::Sequence< OUString> aBlocks =
     119           0 :                     m_pWizard->GetConfigItem().GetAddressBlocks();
     120           0 :         for(sal_Int32 nAddress = 0; nAddress < aBlocks.getLength(); ++nAddress)
     121           0 :             m_pSettingsWIN->AddAddress(aBlocks[nAddress]);
     122           0 :         m_pSettingsWIN->SelectAddress((sal_uInt16)rConfigItem.GetCurrentAddressBlockIndex());
     123           0 :         m_pAddressCB->Check(rConfigItem.IsAddressBlock());
     124           0 :         AddressBlockHdl_Impl(m_pAddressCB);
     125           0 :         m_pSettingsWIN->SetLayout(1, 2);
     126           0 :         InsertDataHdl_Impl(0);
     127             :     }
     128           0 : }
     129             : 
     130           0 : bool SwMailMergeAddressBlockPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
     131             : {
     132           0 :     if ( ::svt::WizardTypes::eTravelForward == _eReason && !m_pWizard->GetConfigItem().GetResultSet().is() )
     133           0 :         return false;
     134           0 :     return true;
     135             : }
     136             : 
     137           0 : IMPL_LINK_NOARG(SwMailMergeAddressBlockPage, AddressListHdl_Impl)
     138             : {
     139             :     try
     140             :     {
     141           0 :         boost::scoped_ptr<SwAddressListDialog> xAddrDialog(new SwAddressListDialog(this));
     142           0 :         if(RET_OK == xAddrDialog->Execute())
     143             :         {
     144           0 :             SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
     145             :             rConfigItem.SetCurrentConnection(
     146             :                             xAddrDialog->GetSource(),
     147             :                             xAddrDialog->GetConnection(),
     148             :                             xAddrDialog->GetColumnsSupplier(),
     149           0 :                             xAddrDialog->GetDBData());
     150           0 :             OUString sFilter = xAddrDialog->GetFilter();
     151           0 :             rConfigItem.SetFilter( sFilter );
     152           0 :             InsertDataHdl_Impl(0);
     153           0 :             GetWizard()->UpdateRoadmap();
     154           0 :             GetWizard()->enableButtons(WZB_NEXT, GetWizard()->isStateEnabled(MM_GREETINGSPAGE));
     155           0 :         }
     156             :     }
     157           0 :     catch (const uno::Exception& e)
     158             :     {
     159             :         OSL_FAIL(OUStringToOString(e.Message, osl_getThreadTextEncoding()).getStr());
     160           0 :         MessageDialog(this, e.Message).Execute();
     161             :     }
     162           0 :     return 0;
     163             : }
     164             : 
     165           0 : IMPL_LINK(SwMailMergeAddressBlockPage, SettingsHdl_Impl, PushButton*, pButton)
     166             : {
     167             :     SwSelectAddressBlockDialog* pDlg =
     168           0 :                 new SwSelectAddressBlockDialog(pButton, m_pWizard->GetConfigItem());
     169           0 :     SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
     170           0 :     pDlg->SetAddressBlocks(rConfig.GetAddressBlocks(), m_pSettingsWIN->GetSelectedAddress());
     171           0 :     pDlg->SetSettings(rConfig.IsIncludeCountry(), rConfig.GetExcludeCountry());
     172           0 :     if(RET_OK == pDlg->Execute())
     173             :     {
     174             :         //the dialog provides the selected address at the first position!
     175             :         const uno::Sequence< OUString> aBlocks =
     176           0 :                     pDlg->GetAddressBlocks();
     177           0 :         rConfig.SetAddressBlocks(aBlocks);
     178           0 :         m_pSettingsWIN->Clear();
     179           0 :         for(sal_Int32 nAddress = 0; nAddress < aBlocks.getLength(); ++nAddress)
     180           0 :             m_pSettingsWIN->AddAddress(aBlocks[nAddress]);
     181           0 :         m_pSettingsWIN->SelectAddress(0);
     182           0 :         m_pSettingsWIN->Invalidate();    // #i40408
     183           0 :         rConfig.SetCountrySettings(pDlg->IsIncludeCountry(), pDlg->GetCountry());
     184           0 :         InsertDataHdl_Impl(0);
     185             :     }
     186           0 :     delete pDlg;
     187           0 :     GetWizard()->UpdateRoadmap();
     188           0 :     GetWizard()->enableButtons(WZB_NEXT, GetWizard()->isStateEnabled(MM_GREETINGSPAGE));
     189           0 :     return 0;
     190             : }
     191             : 
     192           0 : IMPL_LINK(SwMailMergeAddressBlockPage, AssignHdl_Impl, PushButton*, pButton)
     193             : {
     194           0 :     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
     195           0 :     sal_uInt16 nSel = m_pSettingsWIN->GetSelectedAddress();
     196           0 :     const uno::Sequence< OUString> aBlocks = rConfigItem.GetAddressBlocks();
     197             :     boost::scoped_ptr<SwAssignFieldsDialog> pDlg(
     198           0 :             new SwAssignFieldsDialog(pButton, m_pWizard->GetConfigItem(), aBlocks[nSel], true));
     199           0 :     if(RET_OK == pDlg->Execute())
     200             :     {
     201             :         //preview update
     202           0 :         InsertDataHdl_Impl(0);
     203           0 :         GetWizard()->UpdateRoadmap();
     204           0 :         GetWizard()->enableButtons(WZB_NEXT, GetWizard()->isStateEnabled(MM_GREETINGSPAGE));
     205             :     }
     206           0 :     return 0;
     207             : }
     208             : 
     209           0 : void SwMailMergeAddressBlockPage::EnableAddressBlock(sal_Bool bAll, sal_Bool bSelective)
     210             : {
     211           0 :     m_pSettingsFI->Enable(bAll);
     212           0 :     m_pAddressCB->Enable(bAll);
     213           0 :     bSelective &= bAll;
     214           0 :     m_pHideEmptyParagraphsCB->Enable(bSelective);
     215           0 :     m_pSettingsWIN->Enable(bSelective);
     216           0 :     m_pSettingsPB->Enable(bSelective);
     217           0 :     m_pStep3->Enable(bSelective);
     218           0 :     m_pStep4->Enable(bSelective);
     219           0 : }
     220             : 
     221           0 : IMPL_LINK(SwMailMergeAddressBlockPage, AddressBlockHdl_Impl, CheckBox*, pBox)
     222             : {
     223           0 :     EnableAddressBlock(pBox->IsEnabled(), pBox->IsChecked());
     224           0 :     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
     225           0 :     rConfigItem.SetAddressBlock(m_pAddressCB->IsChecked());
     226           0 :     m_pWizard->UpdateRoadmap();
     227           0 :     return 0;
     228             : }
     229             : 
     230           0 : IMPL_LINK_NOARG(SwMailMergeAddressBlockPage, AddressBlockSelectHdl_Impl)
     231             : {
     232           0 :     sal_uInt16 nSel = m_pSettingsWIN->GetSelectedAddress();
     233             :     const uno::Sequence< OUString> aBlocks =
     234           0 :                 m_pWizard->GetConfigItem().GetAddressBlocks();
     235           0 :     OUString sPreview = SwAddressPreview::FillData(aBlocks[nSel], m_pWizard->GetConfigItem());
     236           0 :     m_pPreviewWIN->SetAddress(sPreview);
     237           0 :     m_pWizard->GetConfigItem().SetCurrentAddressBlockIndex( nSel );
     238           0 :     GetWizard()->UpdateRoadmap();
     239           0 :     GetWizard()->enableButtons(WZB_NEXT, GetWizard()->isStateEnabled(MM_GREETINGSPAGE));
     240           0 :     return 0;
     241             : }
     242             : 
     243           0 : IMPL_LINK(SwMailMergeAddressBlockPage, HideParagraphsHdl_Impl, CheckBox*, pBox)
     244             : {
     245           0 :     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
     246           0 :     rConfigItem.SetHideEmptyParagraphs( pBox->IsChecked() );
     247           0 :     return 0;
     248             : }
     249             : 
     250           0 : IMPL_LINK(SwMailMergeAddressBlockPage, InsertDataHdl_Impl, ImageButton*, pButton)
     251             : {
     252             :     //if no pButton is given, the first set has to be pre-set
     253           0 :     SwMailMergeConfigItem& rConfig = m_pWizard->GetConfigItem();
     254           0 :     m_pWizard->EnterWait();
     255           0 :     if(!pButton)
     256             :     {
     257           0 :         rConfig.GetResultSet();
     258             :     }
     259             :     else
     260             :     {
     261           0 :         bool bNext = pButton == m_pNextSetIB;
     262           0 :         sal_Int32 nPos = rConfig.GetResultSetPosition();
     263           0 :         rConfig.MoveResultSet( bNext ? ++nPos : --nPos);
     264             :     }
     265           0 :     m_pWizard->LeaveWait();
     266           0 :     sal_Int32 nPos = rConfig.GetResultSetPosition();
     267           0 :     sal_Bool bEnable = sal_True;
     268           0 :     if(nPos < 1)
     269             :     {
     270           0 :         bEnable = sal_False;
     271           0 :         nPos = 1;
     272             :     }
     273             :     else
     274             :     {
     275             :         //if output type is letter
     276           0 :         if(m_pSettingsWIN->IsVisible())
     277             :         {
     278             :             //Fill data into preview
     279           0 :             sal_uInt16 nSel = m_pSettingsWIN->GetSelectedAddress();
     280             :             const uno::Sequence< OUString> aBlocks =
     281           0 :                         m_pWizard->GetConfigItem().GetAddressBlocks();
     282           0 :             OUString sPreview = SwAddressPreview::FillData(aBlocks[nSel], rConfig);
     283           0 :             m_pPreviewWIN->SetAddress(sPreview);
     284             :         }
     285             :     }
     286           0 :     m_pPrevSetIB->Enable(bEnable);
     287           0 :     m_pDocumentIndexFI->SetText(m_sDocument.replaceFirst("%1", OUString::number(nPos)));
     288             : 
     289           0 :     GetWizard()->enableButtons(WZB_NEXT, GetWizard()->isStateEnabled(MM_GREETINGSPAGE));
     290           0 :     sal_Bool bHasResultSet = rConfig.GetResultSet().is();
     291           0 :     m_pCurrentAddressFI->Show(bHasResultSet);
     292           0 :     if(bHasResultSet)
     293             :     {
     294           0 :         m_pCurrentAddressFI->SetText(m_sCurrentAddress.replaceFirst("%1", rConfig.GetCurrentDBData().sDataSource));
     295           0 :         m_pAddressListPB->SetText(m_sChangeAddress);
     296             :     }
     297           0 :     EnableAddressBlock(bHasResultSet, m_pAddressCB->IsChecked());
     298           0 :     return 0;
     299             : }
     300             : 
     301           0 : SwSelectAddressBlockDialog::SwSelectAddressBlockDialog(
     302             :                 Window* pParent, SwMailMergeConfigItem& rConfig)
     303             :     : SfxModalDialog(pParent, "SelectBlockDialog",
     304             :         "modules/swriter/ui/selectblockdialog.ui")
     305           0 :     , m_rConfig(rConfig)
     306             : {
     307           0 :     get(m_pPreview, "preview");
     308           0 :     Size aSize(m_pPreview->LogicToPixel(Size(192, 100), MapMode(MAP_APPFONT)));
     309           0 :     m_pPreview->set_width_request(aSize.Width());
     310           0 :     m_pPreview->set_height_request(aSize.Height());
     311           0 :     get(m_pNewPB, "new");
     312           0 :     get(m_pCustomizePB, "edit");
     313           0 :     get(m_pDeletePB, "delete");
     314           0 :     get(m_pNeverRB, "never");
     315           0 :     get(m_pAlwaysRB, "always");
     316           0 :     get(m_pDependentRB, "dependent");
     317           0 :     get(m_pCountryED, "country");
     318             : 
     319           0 :     Link aCustomizeHdl = LINK(this, SwSelectAddressBlockDialog, NewCustomizeHdl_Impl);
     320           0 :     m_pNewPB->SetClickHdl(aCustomizeHdl);
     321           0 :     m_pCustomizePB->SetClickHdl(aCustomizeHdl);
     322             : 
     323           0 :     m_pDeletePB->SetClickHdl(LINK(this, SwSelectAddressBlockDialog, DeleteHdl_Impl));
     324             : 
     325           0 :     Link aLk = LINK(this, SwSelectAddressBlockDialog, IncludeHdl_Impl);
     326           0 :     m_pNeverRB->SetClickHdl(aLk);
     327           0 :     m_pAlwaysRB->SetClickHdl(aLk);
     328           0 :     m_pDependentRB->SetClickHdl(aLk);
     329           0 :     m_pPreview->SetLayout(2, 2);
     330           0 :     m_pPreview->EnableScrollBar();
     331           0 : }
     332             : 
     333           0 : SwSelectAddressBlockDialog::~SwSelectAddressBlockDialog()
     334             : {
     335           0 : }
     336             : 
     337           0 : void SwSelectAddressBlockDialog::SetAddressBlocks(const uno::Sequence< OUString>& rBlocks,
     338             :         sal_uInt16 nSelectedAddress)
     339             : {
     340           0 :     m_aAddressBlocks = rBlocks;
     341           0 :     for(sal_Int32 nAddress = 0; nAddress < m_aAddressBlocks.getLength(); ++nAddress)
     342           0 :         m_pPreview->AddAddress(m_aAddressBlocks[nAddress]);
     343           0 :     m_pPreview->SelectAddress(nSelectedAddress);
     344           0 : }
     345             : 
     346             : // return the address blocks and put the selected one to the first position
     347           0 : const uno::Sequence< OUString >&    SwSelectAddressBlockDialog::GetAddressBlocks()
     348             : {
     349             :     //put the selected block to the first position
     350           0 :     sal_uInt16 nSelect = m_pPreview->GetSelectedAddress();
     351           0 :     if(nSelect)
     352             :     {
     353           0 :         uno::Sequence< OUString >aTemp = m_aAddressBlocks;
     354           0 :         OUString* pTemp = aTemp.getArray();
     355           0 :         pTemp[0] = m_aAddressBlocks[nSelect];
     356           0 :         sal_uInt32 nIndex = 0;
     357           0 :         const sal_uInt32 nNumBlocks = m_aAddressBlocks.getLength();
     358           0 :         for(sal_uInt32 nAddress = 1; nAddress < nNumBlocks; ++nAddress)
     359             :         {
     360           0 :             if(nIndex == nSelect)
     361           0 :                 ++nIndex;
     362           0 :             pTemp[nAddress] = m_aAddressBlocks[nIndex];
     363           0 :             nIndex++;
     364             :         }
     365           0 :         m_aAddressBlocks = aTemp;
     366             :     }
     367           0 :     return m_aAddressBlocks;
     368             : }
     369             : 
     370           0 : void SwSelectAddressBlockDialog::SetSettings(
     371             :         sal_Bool bIsCountry, const OUString& rCountry)
     372             : {
     373           0 :     RadioButton *pActive = m_pNeverRB;
     374           0 :     if(bIsCountry)
     375             :     {
     376           0 :         pActive = !rCountry.isEmpty() ? m_pDependentRB : m_pAlwaysRB;
     377           0 :         m_pCountryED->SetText(rCountry);
     378             :     }
     379           0 :     pActive->Check();
     380           0 :     IncludeHdl_Impl(pActive);
     381           0 :     m_pDeletePB->Enable(m_aAddressBlocks.getLength() > 1);
     382           0 : }
     383             : 
     384           0 : OUString     SwSelectAddressBlockDialog::GetCountry() const
     385             : {
     386           0 :     OUString sRet;
     387           0 :     if(m_pDependentRB->IsChecked())
     388           0 :         sRet = m_pCountryED->GetText();
     389           0 :     return sRet;
     390             : }
     391             : 
     392           0 : IMPL_LINK(SwSelectAddressBlockDialog, DeleteHdl_Impl, PushButton*, pButton)
     393             : {
     394           0 :     if(m_aAddressBlocks.getLength())
     395             :     {
     396           0 :         sal_uInt16 nSelected = m_pPreview->GetSelectedAddress();
     397           0 :         OUString* pAddressBlocks = m_aAddressBlocks.getArray();
     398           0 :         sal_Int32 nSource = 0;
     399           0 :         for(sal_Int32 nTarget = 0; nTarget < m_aAddressBlocks.getLength() - 1; nTarget++)
     400             :         {
     401           0 :             if(nSource == nSelected)
     402           0 :                 ++nSource;
     403           0 :             pAddressBlocks[nTarget] = pAddressBlocks[nSource++];
     404             :         }
     405           0 :         m_aAddressBlocks.realloc(m_aAddressBlocks.getLength() - 1);
     406           0 :         if(m_aAddressBlocks.getLength() <= 1)
     407           0 :             pButton->Enable(false);
     408           0 :         m_pPreview->RemoveSelectedAddress();
     409             :     }
     410           0 :     return 0;
     411             : }
     412             : 
     413           0 : IMPL_LINK(SwSelectAddressBlockDialog, NewCustomizeHdl_Impl, PushButton*, pButton)
     414             : {
     415           0 :     bool bCustomize = pButton == m_pCustomizePB;
     416             :     SwCustomizeAddressBlockDialog::DialogType nType = bCustomize ?
     417             :         SwCustomizeAddressBlockDialog::ADDRESSBLOCK_EDIT :
     418           0 :         SwCustomizeAddressBlockDialog::ADDRESSBLOCK_NEW;
     419             :     boost::scoped_ptr<SwCustomizeAddressBlockDialog> pDlg(
     420           0 :         new SwCustomizeAddressBlockDialog(pButton,m_rConfig,nType));
     421           0 :     if(bCustomize)
     422             :     {
     423           0 :         pDlg->SetAddress(m_aAddressBlocks[m_pPreview->GetSelectedAddress()]);
     424             :     }
     425           0 :     if(RET_OK == pDlg->Execute())
     426             :     {
     427           0 :         if(bCustomize)
     428             :         {
     429           0 :             OUString sNew = pDlg->GetAddress();
     430           0 :             m_pPreview->ReplaceSelectedAddress(sNew);
     431           0 :             m_aAddressBlocks[m_pPreview->GetSelectedAddress()] = sNew;
     432             :         }
     433             :         else
     434             :         {
     435           0 :             OUString sNew = pDlg->GetAddress();
     436           0 :             m_pPreview->AddAddress(sNew);
     437           0 :             m_aAddressBlocks.realloc(m_aAddressBlocks.getLength() + 1);
     438           0 :             sal_uInt16 nSelect = (sal_uInt16)m_aAddressBlocks.getLength() - 1;
     439           0 :             m_aAddressBlocks[nSelect] = sNew;
     440           0 :             m_pPreview->SelectAddress(nSelect);
     441             :         }
     442           0 :         m_pDeletePB->Enable( m_aAddressBlocks.getLength() > 1);
     443             :     }
     444           0 :     return 0;
     445             : }
     446             : 
     447           0 : IMPL_LINK(SwSelectAddressBlockDialog, IncludeHdl_Impl, RadioButton*, pButton)
     448             : {
     449           0 :     m_pCountryED->Enable(m_pDependentRB == pButton);
     450           0 :     return 0;
     451             : }
     452             : 
     453           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSwRestrictedComboBox(Window *pParent, VclBuilder::stringmap &rMap)
     454             : {
     455           0 :     WinBits nBits = WB_LEFT|WB_VCENTER|WB_3DLOOK;
     456             : 
     457           0 :     bool bDropdown = VclBuilder::extractDropdown(rMap);
     458             : 
     459           0 :     if (bDropdown)
     460           0 :         nBits |= WB_DROPDOWN;
     461             : 
     462           0 :     SwRestrictedComboBox* pComboBox = new SwRestrictedComboBox(pParent, nBits);
     463           0 :     pComboBox->EnableAutoSize(true);
     464           0 :     return pComboBox;
     465             : }
     466             : 
     467           0 : void SwRestrictedComboBox::KeyInput(const KeyEvent& rEvt)
     468             : {
     469           0 :     bool bCallParent = true;
     470           0 :     if(rEvt.GetCharCode())
     471             :     {
     472           0 :         OUString sKey(rEvt.GetCharCode());
     473           0 :         if( -1 != sForbiddenChars.indexOf(sKey))
     474           0 :             bCallParent = false;
     475             :     }
     476           0 :     if(bCallParent)
     477           0 :         ComboBox::KeyInput(rEvt);
     478           0 : }
     479             : 
     480           0 : void SwRestrictedComboBox::Modify()
     481             : {
     482           0 :     Selection aSel = GetSelection();
     483           0 :     OUString sTemp = GetText();
     484           0 :     for(sal_uInt16 i = 0; i < sForbiddenChars.getLength(); i++)
     485             :     {
     486           0 :         sTemp = comphelper::string::remove(sTemp, sForbiddenChars[i]);
     487             :     }
     488           0 :     sal_Int32 nDiff = GetText().getLength() - sTemp.getLength();
     489           0 :     if(nDiff)
     490             :     {
     491           0 :         aSel.setMin(aSel.getMin() - nDiff);
     492           0 :         aSel.setMax(aSel.getMin());
     493           0 :         SetText(sTemp);
     494           0 :         SetSelection(aSel);
     495             :     }
     496           0 :     if(GetModifyHdl().IsSet())
     497           0 :         GetModifyHdl().Call(this);
     498           0 : }
     499             : 
     500             : #define USER_DATA_SALUTATION        -1
     501             : #define USER_DATA_PUNCTUATION       -2
     502             : #define USER_DATA_TEXT              -3
     503             : #define USER_DATA_NONE              -4
     504             : 
     505           0 : SwCustomizeAddressBlockDialog::SwCustomizeAddressBlockDialog(
     506             :         Window* pParent, SwMailMergeConfigItem& rConfig, DialogType eType)
     507             :     : SfxModalDialog(pParent, "AddressBlockDialog",
     508             :         "modules/swriter/ui/addressblockdialog.ui")
     509             :     , m_rConfigItem(rConfig)
     510           0 :     , m_eType(eType)
     511             : {
     512           0 :     get(m_pOK, "ok");
     513           0 :     get(m_pPreviewWIN, "addrpreview");
     514           0 :     get(m_pFieldCB, "custom");
     515           0 :     get(m_pFieldFT, "customft");
     516           0 :     get(m_pDownIB, "down");
     517           0 :     get(m_pRightIB, "right");
     518           0 :     get(m_pLeftIB, "left");
     519           0 :     get(m_pUpIB, "up");
     520           0 :     get(m_pDragED, "addressdest");
     521           0 :     m_pDragED->SetAddressDialog(this);
     522           0 :     get(m_pDragFT, "addressdestft");
     523           0 :     get(m_pRemoveFieldIB, "fromaddr");
     524           0 :     get(m_pInsertFieldIB, "toaddr");
     525           0 :     get(m_pAddressElementsLB, "addresses");
     526           0 :     m_pAddressElementsLB->set_height_request(16 * m_pAddressElementsLB->GetTextHeight());
     527           0 :     m_pAddressElementsLB->SetAddressDialog(this);
     528           0 :     get(m_pAddressElementsFT, "addressesft");
     529             : 
     530           0 :     if( eType >= GREETING_FEMALE )
     531             :     {
     532           0 :         m_pFieldFT->Show();
     533           0 :         m_pFieldCB->Show();
     534           0 :         SvTreeListEntry* pEntry = m_pAddressElementsLB->InsertEntry(OUString(SW_RES(ST_SALUTATION )));
     535           0 :         pEntry->SetUserData((void*)(sal_Int32)USER_DATA_SALUTATION );
     536           0 :         pEntry = m_pAddressElementsLB->InsertEntry(OUString(SW_RES(ST_PUNCTUATION)));
     537           0 :         pEntry->SetUserData((void*)(sal_Int32)USER_DATA_PUNCTUATION );
     538           0 :         pEntry = m_pAddressElementsLB->InsertEntry(OUString(SW_RES(ST_TEXT       )));
     539           0 :         pEntry->SetUserData((void*)(sal_Int32)USER_DATA_TEXT       );
     540           0 :         ResStringArray aSalutArr(SW_RES(RA_SALUTATION));
     541             :         sal_uInt16 i;
     542           0 :         for(i = 0; i < aSalutArr.Count(); ++i)
     543           0 :             m_aSalutations.push_back(aSalutArr.GetString(i));
     544           0 :         ResStringArray aPunctArr(SW_RES(RA_PUNCTUATION));
     545           0 :         for(i = 0; i < aPunctArr.Count(); ++i)
     546           0 :             m_aPunctuations.push_back(aPunctArr.GetString(i));
     547           0 :         m_pDragED->SetText(OUString("            "));
     548           0 :         SetText( OUString( SW_RES( eType == GREETING_MALE ? ST_TITLE_MALE : ST_TITLE_FEMALE)));
     549           0 :         m_pAddressElementsFT->SetText(OUString(SW_RES(ST_SALUTATIONELEMENTS)));
     550           0 :         m_pInsertFieldIB->SetQuickHelpText(OUString(SW_RES(ST_INSERTSALUTATIONFIELD)));
     551           0 :         m_pRemoveFieldIB->SetQuickHelpText(OUString(SW_RES(ST_REMOVESALUTATIONFIELD)));
     552           0 :         m_pDragFT->SetText(OUString(SW_RES(ST_DRAGSALUTATION)));
     553             :     }
     554             :     else
     555             :     {
     556           0 :         if(eType == ADDRESSBLOCK_EDIT)
     557           0 :             SetText(OUString(SW_RES(ST_TITLE_EDIT)));
     558           0 :         m_pDragED->SetText(OUString("\n\n\n\n\n"));
     559             :     }
     560             : 
     561           0 :     const ResStringArray& rHeaders = m_rConfigItem.GetDefaultAddressHeaders();
     562           0 :     for(sal_uInt16 i = 0; i < rHeaders.Count(); ++i)
     563             :     {
     564           0 :         const OUString rHeader = rHeaders.GetString( i );
     565           0 :         SvTreeListEntry* pEntry = m_pAddressElementsLB->InsertEntry(rHeader);
     566           0 :         pEntry->SetUserData((void*)(sal_IntPtr)i);
     567           0 :     }
     568           0 :     m_pOK->SetClickHdl(LINK(this, SwCustomizeAddressBlockDialog, OKHdl_Impl));
     569           0 :     m_pAddressElementsLB->SetSelectHdl(LINK(this, SwCustomizeAddressBlockDialog, ListBoxSelectHdl_Impl ));
     570           0 :     m_pDragED->SetModifyHdl(LINK(this, SwCustomizeAddressBlockDialog, EditModifyHdl_Impl));
     571           0 :     m_pDragED->SetSelectionChangedHdl( LINK( this, SwCustomizeAddressBlockDialog, SelectionChangedHdl_Impl));
     572           0 :     Link aFieldsLink = LINK(this, SwCustomizeAddressBlockDialog, FieldChangeHdl_Impl);
     573           0 :     m_pFieldCB->SetModifyHdl(aFieldsLink);
     574           0 :     m_pFieldCB->SetSelectHdl(aFieldsLink);
     575           0 :     Link aImgButtonHdl = LINK(this, SwCustomizeAddressBlockDialog, ImageButtonHdl_Impl);
     576           0 :     m_pInsertFieldIB->SetClickHdl(aImgButtonHdl);
     577           0 :     m_pRemoveFieldIB->SetClickHdl(aImgButtonHdl);
     578           0 :     m_pUpIB->SetClickHdl(aImgButtonHdl);
     579           0 :     m_pLeftIB->SetClickHdl(aImgButtonHdl);
     580           0 :     m_pRightIB->SetClickHdl(aImgButtonHdl);
     581           0 :     m_pDownIB->SetClickHdl(aImgButtonHdl);
     582           0 :     UpdateImageButtons_Impl();
     583           0 : }
     584             : 
     585           0 : SwCustomizeAddressBlockDialog::~SwCustomizeAddressBlockDialog()
     586             : {
     587           0 : }
     588             : 
     589           0 : IMPL_LINK_NOARG(SwCustomizeAddressBlockDialog, OKHdl_Impl)
     590             : {
     591           0 :     EndDialog(RET_OK);
     592           0 :     return 0;
     593             : }
     594             : 
     595           0 : IMPL_LINK(SwCustomizeAddressBlockDialog, ListBoxSelectHdl_Impl, DDListBox*, pBox)
     596             : {
     597           0 :     sal_Int32 nUserData = (sal_Int32)(sal_IntPtr)pBox->FirstSelected()->GetUserData();
     598             :     // Check if the selected entry is already in the address and then forbid inserting
     599           0 :     m_pInsertFieldIB->Enable(nUserData >= 0 || !HasItem_Impl(nUserData));
     600           0 :     return 0;
     601             : }
     602             : 
     603           0 : IMPL_LINK_NOARG(SwCustomizeAddressBlockDialog, EditModifyHdl_Impl)
     604             : {
     605             :     OUString sAddress = SwAddressPreview::FillData(
     606             :             GetAddress(),
     607           0 :             m_rConfigItem);
     608           0 :     m_pPreviewWIN->SetAddress(sAddress);
     609           0 :     UpdateImageButtons_Impl();
     610           0 :     return 0;
     611             : }
     612             : 
     613           0 : IMPL_LINK(SwCustomizeAddressBlockDialog, ImageButtonHdl_Impl, ImageButton*, pButton)
     614             : {
     615           0 :     if (m_pInsertFieldIB == pButton)
     616             :     {
     617           0 :         SvTreeListEntry* pEntry = m_pAddressElementsLB->GetCurEntry();
     618           0 :         if(pEntry)
     619             :         {
     620           0 :             OUString sEntry = "<" + m_pAddressElementsLB->GetEntryText(pEntry) + ">";
     621           0 :             m_pDragED->InsertNewEntry(sEntry);
     622             :         }
     623             :     }
     624           0 :     else if (m_pRemoveFieldIB == pButton)
     625             :     {
     626           0 :         m_pDragED->RemoveCurrentEntry();
     627             :     }
     628             :     else
     629             :     {
     630           0 :         sal_uInt16 nMove = MOVE_ITEM_DOWN;
     631           0 :         if (m_pUpIB == pButton)
     632           0 :             nMove = MOVE_ITEM_UP;
     633           0 :         else if (m_pLeftIB == pButton)
     634           0 :             nMove = MOVE_ITEM_LEFT;
     635           0 :         else if (m_pRightIB == pButton)
     636           0 :             nMove = MOVE_ITEM_RIGHT;
     637           0 :         m_pDragED->MoveCurrentItem(nMove);
     638             :     }
     639           0 :     UpdateImageButtons_Impl();
     640           0 :     return 0;
     641             : }
     642             : 
     643           0 : sal_Int32 SwCustomizeAddressBlockDialog::GetSelectedItem_Impl()
     644             : {
     645           0 :     sal_Int32 nRet = USER_DATA_NONE;
     646           0 :     OUString sSelected = m_pDragED->GetCurrentItem();
     647           0 :     if(!sSelected.isEmpty())
     648           0 :         for(sal_uLong i = 0; i < m_pAddressElementsLB->GetEntryCount();  ++i)
     649             :         {
     650           0 :             SvTreeListEntry* pEntry = m_pAddressElementsLB->GetEntry(i);
     651           0 :             OUString sEntry = m_pAddressElementsLB->GetEntryText(pEntry);
     652           0 :             if( sEntry == sSelected.copy( 1, sSelected.getLength() - 2 ) )
     653             :             {
     654           0 :                 nRet = (sal_Int32)(sal_IntPtr)pEntry->GetUserData();
     655           0 :                 break;
     656             :             }
     657           0 :         }
     658           0 :     return nRet;
     659             : }
     660             : 
     661           0 : bool   SwCustomizeAddressBlockDialog::HasItem_Impl(sal_Int32 nUserData)
     662             : {
     663             :     //get the entry from the ListBox
     664           0 :     OUString sEntry;
     665           0 :     for(sal_uLong i = 0; i < m_pAddressElementsLB->GetEntryCount();  ++i)
     666             :     {
     667           0 :         SvTreeListEntry* pEntry = m_pAddressElementsLB->GetEntry(i);
     668           0 :         if((sal_Int32)(sal_IntPtr)pEntry->GetUserData() == nUserData)
     669             :         {
     670           0 :             sEntry = m_pAddressElementsLB->GetEntryText(pEntry);
     671           0 :             break;
     672             :         }
     673             :     }
     674             :     //put it into '<>'
     675           0 :     sEntry = "<" + sEntry + ">";
     676             :     //search for this entry in the content
     677           0 :     OUString sText = m_pDragED->GetText();
     678           0 :     bool bRet = sText.indexOf(sEntry) != -1;
     679           0 :     return bRet;
     680             : }
     681             : 
     682           0 : IMPL_LINK(SwCustomizeAddressBlockDialog, SelectionChangedHdl_Impl, AddressMultiLineEdit*, pEdit)
     683             : {
     684             :     // called in case the selection of the edit field changes.
     685             :     // determine selection - if it's one of the editable fields then
     686             :     // enable the related ComboBox and fill it
     687             :     static bool bOnEntry = false;
     688           0 :     if(bOnEntry)
     689           0 :         return 0;
     690             : 
     691           0 :     bOnEntry = true;
     692           0 :     sal_Int32 nSelected = GetSelectedItem_Impl();
     693           0 :     if(USER_DATA_NONE != nSelected)
     694           0 :         pEdit->SelectCurrentItem();
     695             : 
     696           0 :     if(m_pFieldCB->IsVisible() && (USER_DATA_NONE != nSelected) && (nSelected < 0))
     697             :     {
     698             :         //search in ListBox if it's one of the first entries
     699           0 :         OUString sSelect;
     700           0 :         ::std::vector<OUString>* pVector = 0;
     701           0 :         switch(nSelected) {
     702             :             case USER_DATA_SALUTATION:
     703           0 :                 sSelect =  m_sCurrentSalutation;
     704           0 :                 pVector = &m_aSalutations;
     705           0 :                 break;
     706             :             case USER_DATA_PUNCTUATION:
     707           0 :                 sSelect =  m_sCurrentPunctuation;
     708           0 :                 pVector = &m_aPunctuations;
     709           0 :                 break;
     710             :             case USER_DATA_TEXT:
     711           0 :                 sSelect =  m_sCurrentText;
     712           0 :                 break;
     713             :         }
     714           0 :         m_pFieldCB->Clear();
     715           0 :         if(pVector) {
     716           0 :             ::std::vector<OUString>::iterator  aIterator;
     717           0 :             for( aIterator = pVector->begin(); aIterator != pVector->end(); ++aIterator)
     718           0 :                 m_pFieldCB->InsertEntry(*aIterator);
     719             :         }
     720           0 :         m_pFieldCB->SetText(sSelect);
     721           0 :         m_pFieldCB->Enable(true);
     722           0 :         m_pFieldFT->Enable(true);
     723             :     }
     724             :     else
     725             :     {
     726           0 :         m_pFieldCB->Enable(false);
     727           0 :         m_pFieldFT->Enable(false);
     728             :     }
     729             : 
     730           0 :     UpdateImageButtons_Impl();
     731           0 :     bOnEntry = false;
     732           0 :     return 0;
     733             : }
     734             : 
     735           0 : IMPL_LINK_NOARG(SwCustomizeAddressBlockDialog, FieldChangeHdl_Impl)
     736             : {
     737             :     //changing the field content changes the related members, too
     738           0 :     sal_Int32 nSelected = GetSelectedItem_Impl();
     739           0 :     OUString sContent = m_pFieldCB->GetText();
     740           0 :     switch(nSelected) {
     741             :         case USER_DATA_SALUTATION:
     742           0 :             m_sCurrentSalutation = sContent;
     743           0 :             break;
     744             :         case USER_DATA_PUNCTUATION:
     745           0 :             m_sCurrentPunctuation = sContent;
     746           0 :             break;
     747             :         case USER_DATA_TEXT:
     748           0 :             m_sCurrentText = sContent;
     749           0 :             break;
     750             :     }
     751           0 :     UpdateImageButtons_Impl();
     752           0 :     m_pPreviewWIN->SetAddress(GetAddress());
     753           0 :     m_pDragED->Modify();
     754           0 :     return 0;
     755             : }
     756             : 
     757           0 : void SwCustomizeAddressBlockDialog::UpdateImageButtons_Impl()
     758             : {
     759           0 :     sal_uInt16 nMove = m_pDragED->IsCurrentItemMoveable();
     760           0 :     m_pUpIB->Enable(nMove & MOVE_ITEM_UP );
     761           0 :     m_pLeftIB->Enable(nMove & MOVE_ITEM_LEFT );
     762           0 :     m_pRightIB->Enable(nMove & MOVE_ITEM_RIGHT );
     763           0 :     m_pDownIB->Enable(nMove & MOVE_ITEM_DOWN);
     764           0 :     m_pRemoveFieldIB->Enable(m_pDragED->HasCurrentItem() ? sal_True : sal_False);
     765           0 :     SvTreeListEntry* pEntry = m_pAddressElementsLB->GetCurEntry();
     766           0 :     m_pInsertFieldIB->Enable( pEntry &&
     767           0 :             (0 < (sal_Int32)(sal_IntPtr)pEntry->GetUserData() || !m_pFieldCB->GetText().isEmpty()));
     768           0 : }
     769             : 
     770           0 : void SwCustomizeAddressBlockDialog::SetAddress(const OUString& rAddress)
     771             : {
     772           0 :     m_pDragED->SetText( rAddress );
     773           0 :     UpdateImageButtons_Impl();
     774           0 :     m_pDragED->Modify();
     775           0 : }
     776             : 
     777           0 : OUString SwCustomizeAddressBlockDialog::GetAddress()
     778             : {
     779           0 :     OUString sAddress(m_pDragED->GetAddress());
     780             :     //remove placeholders by the actual content
     781           0 :     if(m_pFieldFT->IsVisible())
     782             :     {
     783           0 :         for(sal_uLong i = 0; i < m_pAddressElementsLB->GetEntryCount();  ++i)
     784             :         {
     785           0 :             SvTreeListEntry* pEntry = m_pAddressElementsLB->GetEntry(i);
     786           0 :             OUString sEntry = "<" + m_pAddressElementsLB->GetEntryText(pEntry) + ">";
     787           0 :             sal_Int32 nUserData = (sal_Int32)(sal_IntPtr)pEntry->GetUserData();
     788           0 :             switch(nUserData)
     789             :             {
     790           0 :                 case USER_DATA_SALUTATION : sAddress = sAddress.replaceFirst(sEntry, m_sCurrentSalutation); break;
     791           0 :                 case USER_DATA_PUNCTUATION: sAddress = sAddress.replaceFirst(sEntry, m_sCurrentPunctuation); break;
     792           0 :                 case USER_DATA_TEXT       : sAddress = sAddress.replaceFirst(sEntry, m_sCurrentText); break;
     793             :             }
     794           0 :         }
     795             :     }
     796           0 :     return sAddress;
     797             : }
     798             : 
     799             : class SwAssignFieldsControl : public Control
     800             : {
     801             :     friend class SwAssignFieldsDialog;
     802             :     ScrollBar                   m_aVScroll;
     803             :     HeaderBar                   m_aHeaderHB;
     804             :     Window                      m_aWindow;
     805             : 
     806             :     ::std::vector<FixedInfo*>   m_aFieldNames;
     807             :     ::std::vector<ListBox*>     m_aMatches;
     808             :     ::std::vector<FixedInfo*>   m_aPreviews;
     809             : 
     810             :     SwMailMergeConfigItem&      m_rConfigItem;
     811             : 
     812             :     Link                        m_aModifyHdl;
     813             : 
     814             :     long                        m_nLBStartTopPos;
     815             :     long                        m_nYOffset;
     816             :     long                        m_nFirstYPos;
     817             : 
     818             :     DECL_LINK(ScrollHdl_Impl, ScrollBar*);
     819             :     DECL_LINK(MatchHdl_Impl, ListBox*);
     820             :     DECL_LINK(GotFocusHdl_Impl, ListBox*);
     821             : 
     822             :     virtual bool        PreNotify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
     823             :     virtual void        Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
     824             : 
     825             :     void                MakeVisible( sal_Int32 nIndex );
     826             : public:
     827             :     SwAssignFieldsControl(Window* pParent, const ResId& rResId,
     828             :                                 SwMailMergeConfigItem& rConfigItem);
     829             :     virtual ~SwAssignFieldsControl();
     830             : 
     831           0 :     void        SetModifyHdl(const Link& rModifyHdl)
     832             :                 {
     833           0 :                     m_aModifyHdl = rModifyHdl;
     834           0 :                     m_aModifyHdl.Call(this);
     835           0 :                 }
     836             : };
     837             : 
     838           0 : SwAssignFieldsControl::SwAssignFieldsControl(
     839             :         Window* pParent, const ResId& rResId, SwMailMergeConfigItem& rConfigItem) :
     840             :     Control(pParent, rResId),
     841           0 :     m_aVScroll(this,  ResId(SCR_1, *rResId.GetResMgr()     )),
     842             :     m_aHeaderHB(this, WB_BUTTONSTYLE | WB_BOTTOMBORDER),
     843           0 :     m_aWindow(this, ResId(WIN_DATA, *rResId.GetResMgr())),
     844             :     m_rConfigItem(rConfigItem),
     845             :     m_nLBStartTopPos(0),
     846             :     m_nYOffset(0),
     847           0 :     m_nFirstYPos(0)
     848             : {
     849           0 :     SetStyle(GetStyle()|WB_TABSTOP|WB_DIALOGCONTROL);
     850           0 :     SetHelpId(HID_MM_ASSIGN_FIELDS);
     851           0 :     long nHBHeight = m_aHeaderHB.CalcWindowSizePixel().Height();
     852           0 :     Size aOutputSize(GetOutputSize());
     853             :     m_aHeaderHB.SetSizePixel(
     854           0 :         Size(aOutputSize.Width(), nHBHeight));
     855           0 :     m_aHeaderHB.Show();
     856           0 :     m_aWindow.SetPosPixel(Point( 0, nHBHeight) );
     857           0 :     m_aWindow.SetSizePixel(Size(aOutputSize.Width() - m_aVScroll.GetSizePixel().Width(), aOutputSize.Height() - nHBHeight));
     858           0 :     m_aWindow.Show();
     859             : 
     860             :     //get the name of the default headers
     861           0 :     const ResStringArray& rHeaders = rConfigItem.GetDefaultAddressHeaders();
     862             :     //get the actual data
     863           0 :     uno::Reference< XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), uno::UNO_QUERY);
     864             :     //get the name of the actual columns
     865           0 :     uno::Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
     866           0 :     uno::Sequence< OUString > aFields;
     867           0 :     if(xColAccess.is())
     868           0 :         aFields = xColAccess->getElementNames();
     869           0 :     const OUString* pFields = aFields.getConstArray();
     870             : 
     871             :     //get the current assignment list
     872             :     //each position in this sequence matches the position in the header array rHeaders
     873             :     //if no assignment is available an empty sequence will be returned
     874           0 :     uno::Sequence< OUString> aAssignments = rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
     875           0 :     Link aMatchHdl = LINK(this, SwAssignFieldsControl, MatchHdl_Impl);
     876           0 :     Link aFocusHdl = LINK(this, SwAssignFieldsControl, GotFocusHdl_Impl);
     877             : 
     878             :     static const char* aHIDs[] =
     879             :     {
     880             :          HID_MM_HEADER_0,
     881             :          HID_MM_HEADER_1,
     882             :          HID_MM_HEADER_2,
     883             :          HID_MM_HEADER_3,
     884             :          HID_MM_HEADER_4,
     885             :          HID_MM_HEADER_5,
     886             :          HID_MM_HEADER_6,
     887             :          HID_MM_HEADER_7,
     888             :          HID_MM_HEADER_8,
     889             :          HID_MM_HEADER_9,
     890             :          HID_MM_HEADER_10,
     891             :          HID_MM_HEADER_11,
     892             :          HID_MM_HEADER_12,
     893             :          HID_MM_HEADER_13
     894             :     };
     895             : 
     896             :     //fill the controls
     897           0 :     for(sal_uInt16 i = 0; i < rHeaders.Count(); ++i)
     898             :     {
     899           0 :         const OUString rHeader = rHeaders.GetString( i );
     900           0 :         FixedInfo* pNewText = new FixedInfo(&m_aWindow, ResId( FT_FIELDS, *rResId.GetResMgr()));
     901           0 :         pNewText->SetText("<" + rHeader + ">");
     902           0 :         ListBox* pNewLB = new ListBox(&m_aWindow, ResId(LB_FIELDS, *rResId.GetResMgr()));
     903           0 :         pNewLB->SetHelpId( aHIDs[i] );
     904           0 :         pNewLB->SelectEntryPos(0);
     905           0 :         for(sal_Int32 nField = 0; nField < aFields.getLength(); ++nField)
     906           0 :             pNewLB->InsertEntry(pFields[nField]);
     907           0 :         FixedInfo* pNewPreview = new FixedInfo(&m_aWindow, ResId( FT_PREVIEW, *rResId.GetResMgr() ));
     908             :         //select the ListBox
     909             :         //if there is an assignment
     910           0 :         if(aAssignments.getLength() > i && !aAssignments[i].isEmpty())
     911           0 :             pNewLB->SelectEntry(aAssignments[i]);
     912             :         else //otherwise the current column name may match one of the db columns
     913           0 :             pNewLB->SelectEntry(rHeader);
     914             :         //then the preview can be filled accordingly
     915           0 :         if(xColAccess.is() && pNewLB->GetSelectEntryPos() > 0 &&
     916           0 :                 xColAccess->hasByName(pNewLB->GetSelectEntry()))
     917             :         {
     918           0 :             uno::Any aCol = xColAccess->getByName(pNewLB->GetSelectEntry());
     919           0 :             uno::Reference< XColumn > xColumn;
     920           0 :             aCol >>= xColumn;
     921           0 :             if(xColumn.is())
     922             :             {
     923             :                 try
     924             :                 {
     925           0 :                     pNewPreview->SetText(xColumn->getString());
     926             :                 }
     927           0 :                 catch (const SQLException&)
     928             :                 {
     929             :                 }
     930           0 :             }
     931             :         }
     932           0 :         if(!i)
     933             :         {
     934             :             //determine the vertical offset, use the bottom position of the ListBox
     935           0 :             m_nFirstYPos = m_nYOffset = pNewLB->GetPosPixel().Y();
     936           0 :             m_nLBStartTopPos = m_nYOffset;
     937           0 :             m_nYOffset += pNewLB->GetSizePixel().Height();
     938             :         }
     939             : 
     940           0 :         long nMove = m_nYOffset * i;
     941           0 :         lcl_Move(pNewText, nMove);
     942           0 :         lcl_Move(pNewLB, nMove);
     943           0 :         lcl_Move(pNewPreview, nMove);
     944             :         //set the select handler
     945           0 :         pNewLB->SetSelectHdl(aMatchHdl);
     946           0 :         pNewLB->SetGetFocusHdl(aFocusHdl);
     947             : 
     948           0 :         m_aFieldNames.push_back(pNewText);
     949           0 :         m_aMatches.push_back(pNewLB);
     950           0 :         m_aPreviews.push_back(pNewPreview);
     951           0 :     }
     952           0 :     m_aVScroll.SetRange(Range(0, rHeaders.Count()));
     953           0 :     m_aVScroll.SetPageSize((aOutputSize.Height() - nHBHeight - m_nLBStartTopPos)/ m_nYOffset);
     954           0 :     m_aVScroll.EnableDrag();
     955           0 :     m_aVScroll.SetVisibleSize(m_aVScroll.GetPageSize());
     956           0 :     m_aVScroll.SetScrollHdl(LINK(this, SwAssignFieldsControl, ScrollHdl_Impl));
     957             : 
     958           0 :     FreeResource();
     959           0 :     m_aVScroll.SetPosPixel(Point(aOutputSize.Width() - m_aVScroll.GetSizePixel().Width(), nHBHeight));
     960           0 :     m_aVScroll.SetSizePixel(Size(m_aVScroll.GetSizePixel().Width(), aOutputSize.Height() - nHBHeight));
     961             : 
     962           0 : }
     963             : 
     964           0 : SwAssignFieldsControl::~SwAssignFieldsControl()
     965             : {
     966           0 :     ::std::vector<FixedInfo*>::iterator aFIIter;
     967           0 :     for(aFIIter = m_aFieldNames.begin(); aFIIter != m_aFieldNames.end(); ++aFIIter)
     968           0 :         delete *aFIIter;
     969           0 :     ::std::vector<ListBox*>::iterator aLBIter;
     970           0 :     for(aLBIter = m_aMatches.begin(); aLBIter != m_aMatches.end(); ++aLBIter)
     971           0 :         delete *aLBIter;
     972           0 :     for(aFIIter = m_aPreviews.begin(); aFIIter != m_aPreviews.end(); ++aFIIter)
     973           0 :         delete *aFIIter;
     974           0 : }
     975             : 
     976           0 : void SwAssignFieldsControl::Command( const CommandEvent& rCEvt )
     977             : {
     978           0 :     switch ( rCEvt.GetCommand() )
     979             :     {
     980             :         case COMMAND_WHEEL:
     981             :         case COMMAND_STARTAUTOSCROLL:
     982             :         case COMMAND_AUTOSCROLL:
     983             :         {
     984           0 :             const CommandWheelData* pWheelData = rCEvt.GetWheelData();
     985           0 :             if(pWheelData && !pWheelData->IsHorz() && COMMAND_WHEEL_ZOOM != pWheelData->GetMode())
     986             :             {
     987           0 :                 HandleScrollCommand( rCEvt, 0, &m_aVScroll );
     988             :             }
     989             :         }
     990           0 :         break;
     991             :         default:
     992           0 :             Control::Command(rCEvt);
     993             :     }
     994           0 : }
     995             : 
     996           0 : bool SwAssignFieldsControl::PreNotify( NotifyEvent& rNEvt )
     997             : {
     998           0 :     if(rNEvt.GetType() == EVENT_COMMAND)
     999             :     {
    1000           0 :         const CommandEvent* pCEvt = rNEvt.GetCommandEvent();
    1001           0 :         sal_uInt16 nCmd = pCEvt->GetCommand();
    1002           0 :         if( COMMAND_WHEEL == nCmd )
    1003             :         {
    1004           0 :             Command(*pCEvt);
    1005           0 :             return true;
    1006             :         }
    1007             :     }
    1008           0 :     return Control::PreNotify(rNEvt);
    1009             : }
    1010             : 
    1011           0 : void SwAssignFieldsControl::MakeVisible( sal_Int32 nIndex )
    1012             : {
    1013           0 :     long nThumb = m_aVScroll.GetThumbPos();
    1014           0 :     long nPage = m_aVScroll.GetPageSize();
    1015           0 :     if(nThumb > nIndex)
    1016           0 :         m_aVScroll.SetThumbPos( nIndex );
    1017           0 :     else if( (nThumb + nPage) < nIndex)
    1018           0 :         m_aVScroll.SetThumbPos( nIndex - nPage );
    1019             :     else
    1020           0 :         return;
    1021           0 :     ScrollHdl_Impl( &m_aVScroll );
    1022             : }
    1023             : 
    1024           0 : IMPL_LINK(SwAssignFieldsControl, ScrollHdl_Impl, ScrollBar*, pScroll)
    1025             : {
    1026           0 :     long nThumb = pScroll->GetThumbPos();
    1027             :     // the scrollbar moves on a per line basis
    1028             :     // the height of a line is stored in m_nYOffset
    1029             :     // nThumb determines which line has to be set at the top (m_nYOffset)
    1030             :     // The first line has to be -(nThumb * m_nYOffset) in the negative
    1031           0 :     long nMove = m_nFirstYPos - (*m_aMatches.begin())->GetPosPixel().Y() - (nThumb * m_nYOffset);
    1032             : 
    1033           0 :     SetUpdateMode(false);
    1034             :     long nIndex;
    1035           0 :     ::std::vector<FixedInfo*>::iterator aFIIter;
    1036           0 :     for(nIndex = 0, aFIIter = m_aFieldNames.begin(); aFIIter != m_aFieldNames.end(); ++aFIIter, ++nIndex)
    1037           0 :         lcl_Move(*aFIIter, nMove);
    1038           0 :     ::std::vector<ListBox*>::iterator aLBIter;
    1039           0 :     for(nIndex = 0, aLBIter = m_aMatches.begin(); aLBIter != m_aMatches.end(); ++aLBIter, ++nIndex)
    1040           0 :         lcl_Move(*aLBIter, nMove);
    1041           0 :     for(nIndex = 0, aFIIter = m_aPreviews.begin(); aFIIter != m_aPreviews.end(); ++aFIIter, ++nIndex)
    1042           0 :         lcl_Move(*aFIIter, nMove);
    1043           0 :     SetUpdateMode(true);
    1044             : 
    1045           0 :     return 0;
    1046             : }
    1047             : 
    1048           0 : IMPL_LINK(SwAssignFieldsControl, MatchHdl_Impl, ListBox*, pBox)
    1049             : {
    1050           0 :     const OUString sColumn = pBox->GetSelectEntry();
    1051           0 :     uno::Reference< XColumnsSupplier > xColsSupp( m_rConfigItem.GetResultSet(), uno::UNO_QUERY);
    1052           0 :     uno::Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
    1053           0 :     OUString sPreview;
    1054           0 :     if(xColAccess.is() && xColAccess->hasByName(sColumn))
    1055             :     {
    1056           0 :         uno::Any aCol = xColAccess->getByName(sColumn);
    1057           0 :         uno::Reference< XColumn > xColumn;
    1058           0 :         aCol >>= xColumn;
    1059           0 :         if(xColumn.is())
    1060             :         {
    1061             :             try
    1062             :             {
    1063           0 :                 sPreview = xColumn->getString();
    1064             :             }
    1065           0 :             catch (const sdbc::SQLException&)
    1066             :             {
    1067             :             }
    1068           0 :         }
    1069             :     }
    1070           0 :     ::std::vector<ListBox*>::iterator aLBIter;
    1071           0 :     sal_Int32 nIndex = 0;
    1072           0 :     for(aLBIter = m_aMatches.begin(); aLBIter != m_aMatches.end(); ++aLBIter, ++nIndex)
    1073             :     {
    1074           0 :         if(*aLBIter == pBox)
    1075             :         {
    1076           0 :             m_aPreviews[nIndex]->SetText(sPreview);
    1077           0 :             break;
    1078             :         }
    1079             :     }
    1080           0 :     m_aModifyHdl.Call(0);
    1081           0 :     return 0;
    1082             : }
    1083             : 
    1084           0 : IMPL_LINK(SwAssignFieldsControl, GotFocusHdl_Impl, ListBox*, pBox)
    1085             : {
    1086           0 :     if(0 != (GETFOCUS_TAB & pBox->GetGetFocusFlags()))
    1087             :     {
    1088           0 :         sal_Int32 nIndex = 0;
    1089           0 :         ::std::vector<ListBox*>::iterator aLBIter;
    1090           0 :         for(aLBIter = m_aMatches.begin(); aLBIter != m_aMatches.end(); ++aLBIter, ++nIndex)
    1091             :         {
    1092           0 :             if(*aLBIter == pBox)
    1093             :             {
    1094           0 :                 MakeVisible(nIndex);
    1095           0 :                 break;
    1096             :             }
    1097             :         }
    1098             :     }
    1099           0 :     return 0;
    1100             : }
    1101             : 
    1102           0 : SwAssignFieldsDialog::SwAssignFieldsDialog(
    1103             :         Window* pParent, SwMailMergeConfigItem& rConfigItem,
    1104             :         const OUString& rPreview,
    1105             :         bool bIsAddressBlock) :
    1106             :     SfxModalDialog(pParent, SW_RES(DLG_MM_ASSIGNFIELDS)),
    1107             :     m_aMatchingFI( this, SW_RES(     FI_MATCHING)),
    1108           0 :     m_pFieldsControl( new SwAssignFieldsControl(this, SW_RES(  CT_FIELDS  ), rConfigItem)),
    1109             :     m_aPreviewFI( this, SW_RES(      FI_PREVIEW )),
    1110             :     m_aPreviewWIN( this, SW_RES(     WIN_PREVIEW )),
    1111             :     m_aSeparatorFL( this, SW_RES(    FL_SEPARATOR)),
    1112             :     m_aOK( this, SW_RES(             PB_OK       )),
    1113             :     m_aCancel( this, SW_RES(         PB_CANCEL   )),
    1114             :     m_aHelp( this, SW_RES(           PB_HELP     )),
    1115             :     m_sNone(SW_RESSTR(SW_STR_NONE)),
    1116             :     m_rPreviewString(rPreview),
    1117           0 :     m_rConfigItem(rConfigItem)
    1118             : {
    1119             :     //resize the HeaderBar
    1120           0 :     OUString sAddressElement( SW_RESSTR(ST_ADDRESSELEMENT) );
    1121           0 :     const OUString sMatchesTo( SW_RESSTR(ST_MATCHESTO) );
    1122           0 :     const OUString sPreview( SW_RESSTR(ST_PREVIEW) );
    1123           0 :     if(!bIsAddressBlock)
    1124             :     {
    1125           0 :         m_aPreviewFI.SetText(SW_RESSTR(ST_SALUTATIONPREVIEW));
    1126           0 :         m_aMatchingFI.SetText(SW_RESSTR(ST_SALUTATIONMATCHING));
    1127           0 :         sAddressElement = SW_RESSTR(ST_SALUTATIONELEMENT);
    1128             :     }
    1129           0 :     FreeResource();
    1130           0 :     Size aOutputSize(m_pFieldsControl->m_aHeaderHB.GetSizePixel());
    1131             :     sal_Int32 nFirstWidth;
    1132           0 :     sal_Int32 nSecondWidth = nFirstWidth = aOutputSize.Width() / 3;
    1133           0 :     const WinBits nHeadBits = HIB_VCENTER | HIB_FIXED| HIB_FIXEDPOS;
    1134           0 :     m_pFieldsControl->m_aHeaderHB.InsertItem( 1, sAddressElement, nFirstWidth, nHeadBits|HIB_LEFT);
    1135           0 :     m_pFieldsControl->m_aHeaderHB.InsertItem( 2, sMatchesTo,      nSecondWidth, nHeadBits|HIB_LEFT);
    1136             :     m_pFieldsControl->m_aHeaderHB.InsertItem( 3, sPreview,
    1137           0 :             aOutputSize.Width() - nFirstWidth - nSecondWidth, nHeadBits|HIB_LEFT);
    1138             : 
    1139           0 :     m_pFieldsControl->SetModifyHdl(LINK(this, SwAssignFieldsDialog, AssignmentModifyHdl_Impl ));
    1140             : 
    1141           0 :     m_aMatchingFI.SetText(m_aMatchingFI.GetText().replaceAll("%1", sMatchesTo));
    1142             : 
    1143           0 :     m_aOK.SetClickHdl(LINK(this, SwAssignFieldsDialog, OkHdl_Impl));
    1144           0 : }
    1145             : 
    1146           0 : SwAssignFieldsDialog::~SwAssignFieldsDialog()
    1147             : {
    1148           0 :     delete m_pFieldsControl;
    1149           0 : }
    1150             : 
    1151           0 : uno::Sequence< OUString > SwAssignFieldsDialog::CreateAssignments()
    1152             : {
    1153             :     uno::Sequence< OUString > aAssignments(
    1154           0 :             m_rConfigItem.GetDefaultAddressHeaders().Count());
    1155           0 :     OUString* pAssignments = aAssignments.getArray();
    1156           0 :     ::std::vector<ListBox*>::iterator aLBIter;
    1157           0 :     sal_Int32 nIndex = 0;
    1158           0 :     for(aLBIter = m_pFieldsControl->m_aMatches.begin();
    1159           0 :                 aLBIter != m_pFieldsControl->m_aMatches.end();
    1160             :                     ++aLBIter, ++nIndex)
    1161             :     {
    1162           0 :         const OUString sSelect = (*aLBIter)->GetSelectEntry();
    1163           0 :         pAssignments[nIndex] = (m_sNone != sSelect) ? sSelect : OUString();
    1164           0 :     }
    1165           0 :     return aAssignments;
    1166             : }
    1167             : 
    1168           0 : IMPL_LINK_NOARG(SwAssignFieldsDialog, OkHdl_Impl)
    1169             : {
    1170             :     m_rConfigItem.SetColumnAssignment(
    1171           0 :                             m_rConfigItem.GetCurrentDBData(),
    1172           0 :                             CreateAssignments() );
    1173           0 :     EndDialog(RET_OK);
    1174           0 :     return 0;
    1175             : }
    1176             : 
    1177           0 : IMPL_LINK_NOARG(SwAssignFieldsDialog, AssignmentModifyHdl_Impl)
    1178             : {
    1179           0 :     uno::Sequence< OUString > aAssignments = CreateAssignments();
    1180             :     const OUString sPreview = SwAddressPreview::FillData(
    1181           0 :             m_rPreviewString, m_rConfigItem, &aAssignments);
    1182           0 :     m_aPreviewWIN.SetAddress(sPreview);
    1183           0 :     return 0;
    1184             : }
    1185             : 
    1186           0 : DDListBox::DDListBox(Window* pParent, WinBits nStyle)
    1187             :     : SvTreeListBox(pParent, nStyle)
    1188           0 :     , m_pParentDialog(NULL)
    1189             : {
    1190           0 :     SetStyle( GetStyle() | /*WB_HASBUTTONS|WB_HASBUTTONSATROOT|*/
    1191           0 :                             WB_CLIPCHILDREN );
    1192           0 :     SetSelectionMode( SINGLE_SELECTION );
    1193           0 :     SetDragDropMode( SV_DRAGDROP_CTRL_COPY );
    1194           0 :     EnableAsyncDrag(true);
    1195             :     // expand selection to the complete width of the ListBox
    1196           0 :     SetHighlightRange();
    1197           0 :     Show();
    1198             : 
    1199           0 : }
    1200             : 
    1201           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeDDListBox(Window *pParent, VclBuilder::stringmap &rMap)
    1202             : {
    1203           0 :     WinBits nWinStyle = WB_TABSTOP;
    1204           0 :     OString sBorder = VclBuilder::extractCustomProperty(rMap);
    1205           0 :     if (!sBorder.isEmpty())
    1206           0 :         nWinStyle |= WB_BORDER;
    1207           0 :     return new DDListBox(pParent, nWinStyle);
    1208             : }
    1209             : 
    1210           0 : void DDListBox::SetAddressDialog(SwCustomizeAddressBlockDialog *pParent)
    1211             : {
    1212           0 :     m_pParentDialog = pParent;
    1213           0 : }
    1214             : 
    1215           0 : void  DDListBox::StartDrag( sal_Int8 /*nAction*/, const Point& /*rPosPixel*/ )
    1216             : {
    1217           0 :     SvTreeListEntry* pEntry = GetCurEntry();
    1218           0 :     if(pEntry)
    1219             :     {
    1220           0 :         ReleaseMouse();
    1221             : 
    1222           0 :         TransferDataContainer* pContainer = new TransferDataContainer;
    1223             :         uno::Reference<
    1224           0 :              datatransfer::XTransferable > xRef( pContainer );
    1225             : 
    1226           0 :         sal_Int32 nUserData = (sal_Int32)(sal_IntPtr)pEntry->GetUserData();
    1227             :         //special entries can only be once in the address / greeting
    1228           0 :         if(nUserData >= 0 || !m_pParentDialog->HasItem_Impl(nUserData))
    1229             :         {
    1230           0 :             OUString sEntry = "<" + GetEntryText(pEntry) + ">";
    1231           0 :             pContainer->CopyString( sEntry );
    1232           0 :             pContainer->StartDrag( this, DND_ACTION_COPY, GetDragFinishedHdl() );
    1233           0 :         }
    1234             :     }
    1235           0 : }
    1236             : 
    1237           0 : AddressMultiLineEdit::AddressMultiLineEdit(Window* pParent, WinBits nBits)
    1238             :     : VclMultiLineEdit(pParent, nBits)
    1239           0 :     , m_pParentDialog(NULL)
    1240             : {
    1241           0 :     GetTextView()->SupportProtectAttribute(true);
    1242           0 :     StartListening(*GetTextEngine());
    1243           0 :     EnableFocusSelectionHide(false);
    1244           0 : }
    1245             : 
    1246           0 : Size AddressMultiLineEdit::GetOptimalSize() const
    1247             : {
    1248           0 :     return LogicToPixel(Size(160, 60), MapMode(MAP_APPFONT));
    1249             : }
    1250             : 
    1251           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeAddressMultiLineEdit(Window *pParent, VclBuilder::stringmap &rMap)
    1252             : {
    1253           0 :     WinBits nWinStyle = WB_LEFT|WB_TABSTOP;
    1254           0 :     OString sBorder = VclBuilder::extractCustomProperty(rMap);
    1255           0 :     if (!sBorder.isEmpty())
    1256           0 :         nWinStyle |= WB_BORDER;
    1257           0 :     return new AddressMultiLineEdit(pParent, nWinStyle);
    1258             : }
    1259             : 
    1260           0 : void AddressMultiLineEdit::SetAddressDialog(SwCustomizeAddressBlockDialog *pParent)
    1261             : {
    1262           0 :     m_pParentDialog = pParent;
    1263           0 : }
    1264             : 
    1265           0 : AddressMultiLineEdit::~AddressMultiLineEdit()
    1266             : {
    1267           0 :     EndListening(*GetTextEngine());
    1268           0 : }
    1269             : 
    1270           0 : void AddressMultiLineEdit::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
    1271             : {
    1272           0 :     if (m_aSelectionLink.IsSet() && rHint.ISA(TextHint))
    1273             :     {
    1274           0 :         const TextHint& rTextHint = static_cast<const TextHint&>(rHint);
    1275           0 :         if (rTextHint.GetId() == TEXT_HINT_VIEWSELECTIONCHANGED ||
    1276           0 :             rTextHint.GetId() == TEXT_HINT_VIEWCARETCHANGED)
    1277             :         {
    1278           0 :             m_aSelectionLink.Call(this);
    1279             :         }
    1280             :     }
    1281           0 : }
    1282             : 
    1283           0 : bool AddressMultiLineEdit::PreNotify( NotifyEvent& rNEvt )
    1284             : {
    1285           0 :     bool nHandled = false;
    1286           0 :     if( EVENT_KEYINPUT == rNEvt.GetType()  &&
    1287           0 :         rNEvt.GetKeyEvent()->GetCharCode())
    1288             :     {
    1289           0 :         nHandled = true;
    1290             :     }
    1291           0 :     else if(EVENT_MOUSEBUTTONDOWN == rNEvt.GetType()) {
    1292           0 :         const MouseEvent *pMEvt = rNEvt.GetMouseEvent();
    1293           0 :         if(pMEvt->GetClicks() >= 2)
    1294           0 :             nHandled = true;
    1295             :     }
    1296           0 :     if(!nHandled)
    1297           0 :         nHandled = VclMultiLineEdit::PreNotify( rNEvt );
    1298           0 :     return nHandled;
    1299             : 
    1300             : }
    1301             : 
    1302           0 : void AddressMultiLineEdit::SetText( const OUString& rStr )
    1303             : {
    1304           0 :     VclMultiLineEdit::SetText(rStr);
    1305             :     //set attributes to all address tokens
    1306             : 
    1307           0 :     ExtTextEngine* pTextEngine = GetTextEngine();
    1308           0 :     TextAttribProtect aProtectAttr;
    1309           0 :     sal_uLong  nParaCount = pTextEngine->GetParagraphCount();
    1310           0 :     for(sal_uLong nPara = 0; nPara < nParaCount; ++nPara)
    1311             :     {
    1312           0 :         sal_Int32 nIndex = 0;
    1313           0 :         OUString sPara = pTextEngine->GetText( nPara );
    1314           0 :         if(!sPara.isEmpty() && !sPara.endsWith(" "))
    1315             :         {
    1316           0 :             TextPaM aPaM(nPara, sPara.getLength());
    1317           0 :             pTextEngine->ReplaceText(TextSelection( aPaM ), OUString(' '));
    1318             :         }
    1319             :         while(true)
    1320             :         {
    1321           0 :             sal_Int32 nStart = sPara.indexOf( '<', nIndex );
    1322           0 :             sal_Int32 nEnd = nStart == -1 ? -1 : sPara.indexOf( '>', nStart );
    1323           0 :             nIndex = nEnd;
    1324           0 :             if(nStart != -1 && nEnd != -1)
    1325           0 :                 pTextEngine->SetAttrib( aProtectAttr, nPara, nStart, nEnd + 1, false );
    1326             :             else
    1327             :                 break;
    1328             :         }
    1329             : 
    1330           0 :     }
    1331             :     // add two empty paragraphs at the end
    1332           0 :     if(m_pParentDialog->m_eType == SwCustomizeAddressBlockDialog::ADDRESSBLOCK_NEW ||
    1333           0 :             m_pParentDialog->m_eType == SwCustomizeAddressBlockDialog::ADDRESSBLOCK_EDIT)
    1334             :     {
    1335           0 :         sal_Int32 nLastLen = pTextEngine->GetText(nParaCount - 1).getLength();
    1336           0 :         if(nLastLen)
    1337             :         {
    1338           0 :             TextPaM aPaM(nParaCount ? nParaCount - 1 : 0, nLastLen);
    1339           0 :             pTextEngine->ReplaceText( TextSelection( aPaM ), OUString("\n \n "));
    1340             :         }
    1341           0 :     }
    1342           0 : }
    1343             : 
    1344             : // Insert the new entry in front of the entry at the beginning of the selection
    1345           0 : void AddressMultiLineEdit::InsertNewEntry( const OUString& rStr )
    1346             : {
    1347             :     // insert new entry after current selected one.
    1348           0 :     ExtTextView* pTextView = GetTextView();
    1349           0 :     const TextSelection& rSelection = pTextView->GetSelection();
    1350           0 :     sal_uLong nPara = rSelection.GetStart().GetPara();
    1351           0 :     sal_uInt16 nIndex = rSelection.GetEnd().GetIndex();
    1352           0 :     ExtTextEngine *pTextEngine = GetTextEngine();
    1353             :     const TextCharAttrib *pAttrib;
    1354           0 :     if(0 != (pAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED )))
    1355           0 :         nIndex = pAttrib->GetEnd();
    1356           0 :     InsertNewEntryAtPosition( rStr, nPara, nIndex );
    1357             : 
    1358             :     // select the new entry
    1359           0 :     pAttrib = pTextEngine->FindCharAttrib(TextPaM(nPara, nIndex),TEXTATTR_PROTECTED);
    1360           0 :     sal_uInt16 nEnd = pAttrib ? pAttrib->GetEnd() : nIndex;
    1361           0 :     TextSelection aEntrySel(TextPaM(nPara, nIndex), TextPaM(nPara, nEnd));
    1362           0 :     pTextView->SetSelection(aEntrySel);
    1363           0 :     Invalidate();
    1364           0 :     Modify();
    1365           0 : }
    1366             : 
    1367           0 : void AddressMultiLineEdit::InsertNewEntryAtPosition( const OUString& rStr, sal_uLong nPara, sal_uInt16 nIndex )
    1368             : {
    1369           0 :     ExtTextEngine* pTextEngine = GetTextEngine();
    1370           0 :     TextPaM aInsertPos( nPara, nIndex );
    1371             : 
    1372           0 :     pTextEngine->ReplaceText( aInsertPos, rStr );
    1373             : 
    1374             :     //restore the attributes
    1375           0 :     SetText( GetAddress() );
    1376             :     //select the newly inserted/moved element
    1377           0 :     TextSelection aEntrySel(aInsertPos);
    1378           0 :     ExtTextView* pTextView = GetTextView();
    1379           0 :     pTextView->SetSelection(aEntrySel);
    1380           0 :     m_aSelectionLink.Call(this);
    1381           0 : }
    1382             : 
    1383           0 : void AddressMultiLineEdit::RemoveCurrentEntry()
    1384             : {
    1385           0 :     ExtTextEngine* pTextEngine = GetTextEngine();
    1386           0 :     ExtTextView* pTextView = GetTextView();
    1387           0 :     const TextSelection& rSelection = pTextView->GetSelection();
    1388           0 :     const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
    1389           0 :     if(pBeginAttrib &&
    1390           0 :             (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
    1391           0 :                             && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()))
    1392             :     {
    1393           0 :         sal_uLong nPara = rSelection.GetStart().GetPara();
    1394           0 :         TextSelection aEntrySel(TextPaM( nPara, pBeginAttrib->GetStart()), TextPaM(nPara, pBeginAttrib->GetEnd()));
    1395           0 :         pTextEngine->ReplaceText(aEntrySel, OUString());
    1396             :         //restore the attributes
    1397           0 :         SetText( GetAddress() );
    1398           0 :         Modify();
    1399             :     }
    1400           0 : }
    1401             : 
    1402           0 : void AddressMultiLineEdit::MoveCurrentItem(sal_uInt16 nMove)
    1403             : {
    1404           0 :     ExtTextEngine* pTextEngine = GetTextEngine();
    1405           0 :     ExtTextView* pTextView = GetTextView();
    1406           0 :     const TextSelection& rSelection = pTextView->GetSelection();
    1407           0 :     const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
    1408           0 :     if(pBeginAttrib &&
    1409           0 :             (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
    1410           0 :                             && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()))
    1411             :     {
    1412             :         //current item has been found
    1413           0 :         sal_uLong nPara = rSelection.GetStart().GetPara();
    1414           0 :         sal_uInt16 nIndex = pBeginAttrib->GetStart();
    1415           0 :         TextSelection aEntrySel(TextPaM( nPara, pBeginAttrib->GetStart()), TextPaM(nPara, pBeginAttrib->GetEnd()));
    1416           0 :         OUString sCurrentItem = pTextEngine->GetText(aEntrySel);
    1417           0 :         pTextEngine->RemoveAttrib( nPara, *pBeginAttrib );
    1418           0 :         pTextEngine->ReplaceText(aEntrySel, OUString());
    1419           0 :         switch(nMove)
    1420             :         {
    1421             :             case MOVE_ITEM_LEFT :
    1422           0 :                 if(nIndex)
    1423             :                 {
    1424             :                     //go left to find a predecessor or simple text
    1425           0 :                     --nIndex;
    1426           0 :                     OUString sPara = pTextEngine->GetText( nPara );
    1427           0 :                     sal_Int32 nSearchIndex = sPara.lastIndexOf( '>', nIndex+1 );
    1428           0 :                     if( nSearchIndex != -1 && nSearchIndex == nIndex )
    1429             :                     {
    1430           0 :                         nSearchIndex = sPara.lastIndexOf( '<', nIndex );
    1431           0 :                         if( nSearchIndex != -1 )
    1432           0 :                             nIndex = nSearchIndex;
    1433           0 :                     }
    1434             :                 }
    1435           0 :             break;
    1436             :             case MOVE_ITEM_RIGHT:
    1437             :             {
    1438             :                 //go right to find a successor or simple text
    1439           0 :                 ++nIndex;
    1440           0 :                 const TextCharAttrib* pEndAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
    1441           0 :                 if(pEndAttrib && pEndAttrib->GetEnd() >= nIndex)
    1442             :                 {
    1443           0 :                     nIndex = pEndAttrib->GetEnd();
    1444             :                 }
    1445             :             }
    1446           0 :             break;
    1447             :             case MOVE_ITEM_UP   :
    1448           0 :                 --nPara;
    1449           0 :                 nIndex = 0;
    1450           0 :             break;
    1451             :             case MOVE_ITEM_DOWN :
    1452           0 :                 ++nPara;
    1453           0 :                 nIndex = 0;
    1454           0 :             break;
    1455             :         }
    1456             :         //add a new paragraph if there is none yet
    1457           0 :         if(nPara >= pTextEngine->GetParagraphCount())
    1458             :         {
    1459             : 
    1460           0 :             TextPaM aTemp(nPara - 1, pTextEngine->GetTextLen( nPara - 1 ));
    1461           0 :             pTextEngine->ReplaceText( aTemp, OUString('\n'));
    1462             :         }
    1463           0 :         InsertNewEntryAtPosition( sCurrentItem, nPara, nIndex );
    1464             : 
    1465             :         // select the new entry [#i40817]
    1466           0 :         const TextCharAttrib *pAttrib = pTextEngine->FindCharAttrib(TextPaM(nPara, nIndex),TEXTATTR_PROTECTED);
    1467           0 :         if (pAttrib)
    1468           0 :             aEntrySel = TextSelection(TextPaM(nPara, nIndex), TextPaM(nPara, pAttrib->GetEnd()));
    1469           0 :         pTextView->SetSelection(aEntrySel);
    1470           0 :         Invalidate();
    1471           0 :         Modify();
    1472             :     }
    1473           0 : }
    1474             : 
    1475           0 : sal_uInt16  AddressMultiLineEdit::IsCurrentItemMoveable()
    1476             : {
    1477           0 :     sal_uInt16 nRet = 0;
    1478           0 :     ExtTextEngine* pTextEngine = GetTextEngine();
    1479           0 :     ExtTextView* pTextView = GetTextView();
    1480           0 :     const TextSelection& rSelection = pTextView->GetSelection();
    1481           0 :     const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
    1482           0 :     if(pBeginAttrib &&
    1483           0 :             (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
    1484           0 :                             && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()))
    1485             :     {
    1486           0 :         if(pBeginAttrib->GetStart())
    1487           0 :             nRet |= MOVE_ITEM_LEFT;
    1488             :         //if there is an entry it can always be move to the right and down
    1489           0 :         nRet |= MOVE_ITEM_RIGHT|MOVE_ITEM_DOWN;
    1490           0 :         if(rSelection.GetStart().GetPara() > 0)
    1491           0 :             nRet |= MOVE_ITEM_UP;
    1492             :     }
    1493           0 :     return nRet;
    1494             : }
    1495             : 
    1496           0 : bool AddressMultiLineEdit::HasCurrentItem()
    1497             : {
    1498           0 :     ExtTextEngine* pTextEngine = GetTextEngine();
    1499           0 :     ExtTextView* pTextView = GetTextView();
    1500           0 :     const TextSelection& rSelection = pTextView->GetSelection();
    1501           0 :     const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
    1502           0 :     return (pBeginAttrib &&
    1503           0 :             (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
    1504           0 :                             && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()));
    1505             : }
    1506             : 
    1507           0 : OUString AddressMultiLineEdit::GetCurrentItem()
    1508             : {
    1509           0 :     OUString sRet;
    1510           0 :     ExtTextEngine* pTextEngine = GetTextEngine();
    1511           0 :     ExtTextView* pTextView = GetTextView();
    1512           0 :     const TextSelection& rSelection = pTextView->GetSelection();
    1513           0 :     const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
    1514           0 :     if(pBeginAttrib &&
    1515           0 :             (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
    1516           0 :                             && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()))
    1517             :     {
    1518           0 :         sal_uLong nPara = rSelection.GetStart().GetPara();
    1519           0 :         TextSelection aEntrySel(TextPaM( nPara, pBeginAttrib->GetStart()), TextPaM(nPara, pBeginAttrib->GetEnd()));
    1520           0 :         sRet = pTextEngine->GetText( aEntrySel );
    1521             :     }
    1522           0 :     return sRet;
    1523             : }
    1524             : 
    1525           0 : void AddressMultiLineEdit::SelectCurrentItem()
    1526             : {
    1527           0 :     ExtTextEngine* pTextEngine = GetTextEngine();
    1528           0 :     ExtTextView* pTextView = GetTextView();
    1529           0 :     const TextSelection& rSelection = pTextView->GetSelection();
    1530           0 :     const TextCharAttrib* pBeginAttrib = pTextEngine->FindCharAttrib( rSelection.GetStart(), TEXTATTR_PROTECTED );
    1531           0 :     if(pBeginAttrib &&
    1532           0 :             (pBeginAttrib->GetStart() <= rSelection.GetStart().GetIndex()
    1533           0 :                             && pBeginAttrib->GetEnd() >= rSelection.GetEnd().GetIndex()))
    1534             :     {
    1535           0 :         sal_uLong nPara = rSelection.GetStart().GetPara();
    1536           0 :         TextSelection aEntrySel(TextPaM( nPara, pBeginAttrib->GetStart()), TextPaM(nPara, pBeginAttrib->GetEnd()));
    1537           0 :         pTextView->SetSelection(aEntrySel);
    1538           0 :         Invalidate();
    1539             :     }
    1540           0 : }
    1541             : 
    1542           0 : OUString AddressMultiLineEdit::GetAddress()
    1543             : {
    1544           0 :     OUString sRet;
    1545           0 :     ExtTextEngine* pTextEngine = GetTextEngine();
    1546           0 :     sal_uLong  nParaCount = pTextEngine->GetParagraphCount();
    1547           0 :     for(sal_uLong nPara = nParaCount; nPara; --nPara)
    1548             :     {
    1549           0 :         OUString sPara = comphelper::string::stripEnd(pTextEngine->GetText(nPara - 1), ' ');
    1550             :         //don't add empty trailing paragraphs
    1551           0 :         if(!sRet.isEmpty() || !sPara.isEmpty())
    1552             :         {
    1553           0 :             sRet = sPara + sRet;
    1554             :             //insert the para break
    1555           0 :             if(nPara > 1)
    1556           0 :                 sRet = "\n" + sRet;
    1557             :         }
    1558           0 :     }
    1559           0 :     return sRet;
    1560           0 : }
    1561             : 
    1562             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10