LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/envelp - mailmrge.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 397 0.0 %
Date: 2012-12-27 Functions: 0 39 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 <vcl/msgbox.hxx>
      21             : #include <vcl/svapp.hxx>
      22             : #include <tools/urlobj.hxx>
      23             : #include <svl/urihelper.hxx>
      24             : #include <unotools/pathoptions.hxx>
      25             : #include <svl/mailenum.hxx>
      26             : #include <svx/svxdlg.hxx>
      27             : #include <svx/dialogs.hrc>
      28             : #include <helpid.h>
      29             : #include <view.hxx>
      30             : #include <docsh.hxx>
      31             : #include <IDocumentDeviceAccess.hxx>
      32             : #include <wrtsh.hxx>
      33             : #include <dbmgr.hxx>
      34             : #include <dbui.hxx>
      35             : #include <prtopt.hxx>
      36             : #include <swmodule.hxx>
      37             : #include <modcfg.hxx>
      38             : #include <mailmergehelper.hxx>
      39             : #include <envelp.hrc>
      40             : #include <mailmrge.hrc>
      41             : #include <mailmrge.hxx>
      42             : #include <sfx2/docfile.hxx>
      43             : #include <sfx2/docfilt.hxx>
      44             : #include <comphelper/sequenceashashmap.hxx>
      45             : #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
      46             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      47             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      48             : #include <com/sun/star/sdbcx/XRowLocate.hpp>
      49             : #include <com/sun/star/sdb/XResultSetAccess.hpp>
      50             : #include <com/sun/star/sdbc/XDataSource.hpp>
      51             : #include <toolkit/unohlp.hxx>
      52             : #include <comphelper/processfactory.hxx>
      53             : #include <com/sun/star/form/runtime/XFormController.hpp>
      54             : #include <cppuhelper/implbase1.hxx>
      55             : #include <com/sun/star/container/XChild.hpp>
      56             : #include <com/sun/star/container/XContainerQuery.hpp>
      57             : #include <com/sun/star/container/XEnumeration.hpp>
      58             : 
      59             : #include <unomid.h>
      60             : 
      61             : #include <algorithm>
      62             : 
      63             : using namespace ::com::sun::star;
      64             : using namespace ::com::sun::star::container;
      65             : using namespace ::com::sun::star::lang;
      66             : using namespace ::com::sun::star::sdb;
      67             : using namespace ::com::sun::star::sdbc;
      68             : using namespace ::com::sun::star::sdbcx;
      69             : using namespace ::com::sun::star::beans;
      70             : using namespace ::com::sun::star::util;
      71             : using namespace ::com::sun::star::uno;
      72             : using namespace ::com::sun::star::frame;
      73             : using namespace ::com::sun::star::form;
      74             : using namespace ::com::sun::star::view;
      75             : using namespace ::com::sun::star::ui::dialogs;
      76             : 
      77             : using ::rtl::OUString;
      78             : 
      79           0 : struct SwMailMergeDlg_Impl
      80             : {
      81             :     uno::Reference<runtime::XFormController> xFController;
      82             :     uno::Reference<XSelectionChangeListener> xChgLstnr;
      83             :     uno::Reference<XSelectionSupplier> xSelSupp;
      84             : };
      85             : 
      86             : /* --------------------------------------------------------------------------
      87             :     helper classes
      88             : ----------------------------------------------------------------------------*/
      89             : class SwXSelChgLstnr_Impl : public cppu::WeakImplHelper1
      90             : <
      91             :     view::XSelectionChangeListener
      92             : >
      93             : {
      94             :     SwMailMergeDlg& rParent;
      95             : public:
      96             :     SwXSelChgLstnr_Impl(SwMailMergeDlg& rParentDlg);
      97             :     ~SwXSelChgLstnr_Impl();
      98             : 
      99             :     virtual void SAL_CALL selectionChanged( const EventObject& aEvent ) throw (RuntimeException);
     100             :     virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException);
     101             : };
     102             : 
     103           0 : SwXSelChgLstnr_Impl::SwXSelChgLstnr_Impl(SwMailMergeDlg& rParentDlg) :
     104           0 :     rParent(rParentDlg)
     105           0 : {}
     106             : 
     107           0 : SwXSelChgLstnr_Impl::~SwXSelChgLstnr_Impl()
     108           0 : {}
     109             : 
     110           0 : void SwXSelChgLstnr_Impl::selectionChanged( const EventObject&  ) throw (RuntimeException)
     111             : {
     112             :     //call the parent to enable selection mode
     113           0 :     Sequence <Any> aSelection;
     114           0 :     if(rParent.pImpl->xSelSupp.is())
     115           0 :         rParent.pImpl->xSelSupp->getSelection() >>= aSelection;
     116             : 
     117           0 :     sal_Bool bEnable = aSelection.getLength() > 0;
     118           0 :     rParent.aMarkedRB.Enable(bEnable);
     119           0 :     if(bEnable)
     120           0 :         rParent.aMarkedRB.Check();
     121           0 :     else if(rParent.aMarkedRB.IsChecked())
     122             :     {
     123           0 :         rParent.aAllRB.Check();
     124           0 :         rParent.m_aSelection.realloc(0);
     125           0 :     }
     126           0 : }
     127             : 
     128           0 : void SwXSelChgLstnr_Impl::disposing( const EventObject&  ) throw (RuntimeException)
     129             : {
     130             :     OSL_FAIL("disposing");
     131           0 : }
     132             : 
     133           0 : SwMailMergeDlg::SwMailMergeDlg(Window* pParent, SwWrtShell& rShell,
     134             :          const String& rSourceName,
     135             :         const String& rTblName,
     136             :         sal_Int32 nCommandType,
     137             :         const uno::Reference< XConnection>& _xConnection,
     138             :         Sequence< Any >* pSelection) :
     139             : 
     140             :     SvxStandardDialog(pParent, SW_RES(DLG_MAILMERGE)),
     141           0 :     pBeamerWin      (new Window(this, SW_RES(WIN_BEAMER))),
     142             : 
     143             :     aAllRB          (this, SW_RES(RB_ALL)),
     144             :     aMarkedRB       (this, SW_RES(RB_MARKED)),
     145             :     aFromRB         (this, SW_RES(RB_FROM)),
     146             :     aFromNF         (this, SW_RES(NF_FROM)),
     147             :     aBisFT          (this, SW_RES(FT_BIS)),
     148             :     aToNF           (this, SW_RES(NF_TO)),
     149             :     aRecordFL       (this, SW_RES(FL_RECORD)),
     150             : 
     151             :     aSeparatorFL    (this, SW_RES(FL_SEPARATOR)),
     152             : 
     153             :     aPrinterRB      (this, SW_RES(RB_PRINTER)),
     154             :     aMailingRB      (this, SW_RES(RB_MAILING)),
     155             :     aFileRB         (this, SW_RES(RB_FILE)),
     156             : 
     157             :     aSingleJobsCB   (this, SW_RES(CB_SINGLE_JOBS)),
     158             : 
     159             :     aSaveMergedDocumentFL(this, SW_RES(     FL_SAVE_MERGED_DOCUMENT)),
     160             :     aSaveSingleDocRB(this, SW_RES(          RB_SAVE_SINGLE_DOC )),
     161             :     aSaveIndividualRB(this, SW_RES(         RB_SAVE_INDIVIDUAL )),
     162             :     aGenerateFromDataBaseCB(this, SW_RES(   RB_GENERATE_FROM_DATABASE )),
     163             : 
     164             :     aColumnFT       (this, SW_RES(FT_COLUMN)),
     165             :     aColumnLB       (this, SW_RES(LB_COLUMN)),
     166             : 
     167             :     aPathFT         (this, SW_RES(FT_PATH)),
     168             :     aPathED         (this, SW_RES(ED_PATH)),
     169             :     aPathPB         (this, SW_RES(PB_PATH)),
     170             :     aFilterFT       (this, SW_RES(FT_FILTER)),
     171             :     aFilterLB       (this, SW_RES(LB_FILTER)),
     172             : 
     173             :     aAddressFldLB   (this, SW_RES(LB_ADDRESSFLD)),
     174             :     aSubjectFT      (this, SW_RES(FT_SUBJECT)),
     175             :     aSubjectED      (this, SW_RES(ED_SUBJECT)),
     176             :     aFormatFT       (this, SW_RES(FT_FORMAT)),
     177             :     aAttachFT       (this, SW_RES(FT_ATTACH)),
     178             :     aAttachED       (this, SW_RES(ED_ATTACH)),
     179             :     aAttachPB       (this, SW_RES(PB_ATTACH)),
     180             :     aFormatHtmlCB   (this, SW_RES(CB_FORMAT_HTML)),
     181             :     aFormatRtfCB    (this, SW_RES(CB_FORMAT_RTF)),
     182             :     aFormatSwCB     (this, SW_RES(CB_FORMAT_SW)),
     183             :     aDestFL         (this, SW_RES(FL_DEST)),
     184             : 
     185             :     aBottomSeparatorFL(this, SW_RES(FL_BOTTOM_SEPARATOR)),
     186             : 
     187             :     aOkBTN          (this, SW_RES(BTN_OK)),
     188             :     aCancelBTN      (this, SW_RES(BTN_CANCEL)),
     189             :     aHelpBTN        (this, SW_RES(BTN_HELP)),
     190             : 
     191           0 :     pImpl           (new SwMailMergeDlg_Impl),
     192             : 
     193             :     rSh             (rShell),
     194             :     rDBName         (rSourceName),
     195             :     rTableName      (rTblName),
     196             :     nMergeType      (DBMGR_MERGE_MAILING),
     197           0 :     m_aDialogSize( GetSizePixel() )
     198             : {
     199           0 :     FreeResource();
     200           0 :     aSingleJobsCB.Show(sal_False); // not supported in since cws printerpullpages anymore
     201             :     //task #97066# mailing of form letters is currently not supported
     202           0 :     aMailingRB.Show(sal_False);
     203           0 :     aSubjectFT.Show(sal_False);
     204           0 :     aSubjectED.Show(sal_False);
     205           0 :     aFormatFT.Show(sal_False);
     206           0 :     aFormatSwCB.Show(sal_False);
     207           0 :     aFormatHtmlCB.Show(sal_False);
     208           0 :     aFormatRtfCB.Show(sal_False);
     209           0 :     aAttachFT.Show(sal_False);
     210           0 :     aAttachED.Show(sal_False);
     211           0 :     aAttachPB.Show(sal_False);
     212             : 
     213           0 :     Point aMailPos = aMailingRB.GetPosPixel();
     214           0 :     Point aFilePos = aFileRB.GetPosPixel();
     215           0 :     aFilePos.X() -= (aFilePos.X() - aMailPos.X()) /2;
     216           0 :     aFileRB.SetPosPixel(aFilePos);
     217           0 :     uno::Reference< lang::XMultiServiceFactory > xMSF = comphelper::getProcessServiceFactory();
     218           0 :     if(pSelection)
     219             :     {
     220           0 :         m_aSelection = *pSelection;
     221             :         //move all controls
     222           0 :         long nDiff = aRecordFL.GetPosPixel().Y() - pBeamerWin->GetPosPixel().Y();
     223           0 :         pBeamerWin->Show(sal_False);
     224           0 :         ::Size aSize = GetSizePixel();
     225           0 :         aSize.Height() -= nDiff;
     226           0 :         SetSizePixel(aSize);
     227             :         Window* aCntrlArr[] = {
     228             :             &aAllRB       ,
     229             :             &aMarkedRB    ,
     230             :             &aFromRB      ,
     231             :             &aFromNF      ,
     232             :             &aBisFT       ,
     233             :             &aToNF        ,
     234             :             &aRecordFL    ,
     235             :             &aPrinterRB   ,
     236             :             &aMailingRB   ,
     237             :             &aFileRB      ,
     238             :             &aSingleJobsCB,
     239             :             &aPathFT      ,
     240             :             &aPathED      ,
     241             :             &aPathPB      ,
     242             :             &aFilterFT    ,
     243             :             &aFilterLB    ,
     244             :             &aColumnLB    ,
     245             :             &aAddressFldLB,
     246             :             &aSubjectFT   ,
     247             :             &aSubjectED   ,
     248             :             &aFormatFT    ,
     249             :             &aAttachFT    ,
     250             :             &aAttachED    ,
     251             :             &aAttachPB    ,
     252             :             &aFormatHtmlCB,
     253             :             &aFormatRtfCB ,
     254             :             &aFormatSwCB  ,
     255             :             &aDestFL      ,
     256             :             &aSeparatorFL ,
     257           0 :             0};
     258             : 
     259           0 :         for( Window** ppW = aCntrlArr; *ppW; ++ppW )
     260             :         {
     261           0 :             ::Point aPnt( (*ppW)->GetPosPixel() );
     262           0 :             aPnt.Y() -= nDiff;
     263           0 :             (*ppW)->SetPosPixel( aPnt );
     264             :         }
     265             :     }
     266             :     else
     267             :     {
     268             :         try
     269             :         {
     270             :             // create a frame wrapper for myself
     271             :             uno::Reference< XMultiServiceFactory >
     272           0 :                                         xMgr = comphelper::getProcessServiceFactory();
     273           0 :             xFrame = uno::Reference< XFrame >(xMgr->createInstance("com.sun.star.frame.Frame"), UNO_QUERY);
     274           0 :             if(xFrame.is())
     275             :             {
     276           0 :                 xFrame->initialize( VCLUnoHelper::GetInterface ( pBeamerWin ) );
     277           0 :             }
     278             :         }
     279           0 :         catch (const Exception&)
     280             :         {
     281           0 :             xFrame.clear();
     282             :         }
     283           0 :         if(xFrame.is())
     284             :         {
     285           0 :             uno::Reference<XDispatchProvider> xDP(xFrame, UNO_QUERY);
     286           0 :             URL aURL;
     287           0 :             aURL.Complete = ".component:DB/DataSourceBrowser";
     288           0 :             uno::Reference<XDispatch> xD = xDP->queryDispatch(aURL,
     289             :                         "",
     290           0 :                         0x0C);
     291           0 :             if(xD.is())
     292             :             {
     293           0 :                 Sequence<PropertyValue> aProperties(3);
     294           0 :                 PropertyValue* pProperties = aProperties.getArray();
     295           0 :                 pProperties[0].Name = "DataSourceName";
     296           0 :                 pProperties[0].Value <<= OUString(rSourceName);
     297           0 :                 pProperties[1].Name = "Command";
     298           0 :                 pProperties[1].Value <<= OUString(rTableName);
     299           0 :                 pProperties[2].Name = "CommandType";
     300           0 :                 pProperties[2].Value <<= nCommandType;
     301           0 :                 xD->dispatch(aURL, aProperties);
     302           0 :                 pBeamerWin->Show();
     303             :             }
     304           0 :             uno::Reference<XController> xController = xFrame->getController();
     305           0 :             pImpl->xFController = uno::Reference<runtime::XFormController>(xController, UNO_QUERY);
     306           0 :             if(pImpl->xFController.is())
     307             :             {
     308           0 :                 uno::Reference< awt::XControl > xCtrl = pImpl->xFController->getCurrentControl(  );
     309           0 :                 pImpl->xSelSupp = uno::Reference<XSelectionSupplier>(xCtrl, UNO_QUERY);
     310           0 :                 if(pImpl->xSelSupp.is())
     311             :                 {
     312           0 :                     pImpl->xChgLstnr = new SwXSelChgLstnr_Impl(*this);
     313           0 :                     pImpl->xSelSupp->addSelectionChangeListener(  pImpl->xChgLstnr );
     314           0 :                 }
     315           0 :             }
     316             :         }
     317             :     }
     318             : 
     319           0 :     pModOpt = SW_MOD()->GetModuleConfig();
     320             : 
     321           0 :     sal_Int16 nMailingMode(pModOpt->GetMailingFormats());
     322           0 :     aFormatSwCB.Check((nMailingMode & TXTFORMAT_OFFICE) != 0);
     323           0 :     aFormatHtmlCB.Check((nMailingMode & TXTFORMAT_HTML) != 0);
     324           0 :     aFormatRtfCB.Check((nMailingMode & TXTFORMAT_RTF) != 0);
     325             : 
     326           0 :     aAllRB.Check(sal_True);
     327             : 
     328             :     // Install handlers
     329           0 :     Link aLk = LINK(this, SwMailMergeDlg, ButtonHdl);
     330           0 :     aOkBTN.SetClickHdl(aLk);
     331             : 
     332           0 :     aPathPB.SetClickHdl(LINK(this, SwMailMergeDlg, InsertPathHdl));
     333           0 :     aAttachPB.SetClickHdl(LINK(this, SwMailMergeDlg, AttachFileHdl));
     334             : 
     335           0 :     aLk = LINK(this, SwMailMergeDlg, OutputTypeHdl);
     336           0 :     aPrinterRB.SetClickHdl(aLk);
     337           0 :     aMailingRB.SetClickHdl(aLk);
     338           0 :     aFileRB.SetClickHdl(aLk);
     339             : 
     340             :     //#i63267# printing might be disabled
     341           0 :     bool bIsPrintable = !Application::GetSettings().GetMiscSettings().GetDisablePrinting();
     342           0 :     aPrinterRB.Enable(bIsPrintable);
     343           0 :     OutputTypeHdl(bIsPrintable ? &aPrinterRB : &aFileRB);
     344             : 
     345           0 :     aLk = LINK(this, SwMailMergeDlg, FilenameHdl);
     346           0 :     aGenerateFromDataBaseCB.SetClickHdl( aLk );
     347           0 :     sal_Bool bColumn = pModOpt->IsNameFromColumn();
     348           0 :     if(bColumn)
     349           0 :         aGenerateFromDataBaseCB.Check();
     350             : 
     351           0 :     FilenameHdl( &aGenerateFromDataBaseCB );
     352           0 :     aLk = LINK(this, SwMailMergeDlg, SaveTypeHdl);
     353           0 :     aSaveSingleDocRB.Check( true );
     354           0 :     aSaveSingleDocRB.SetClickHdl( aLk );
     355           0 :     aSaveIndividualRB.SetClickHdl( aLk );
     356           0 :     aLk.Call( &aSaveSingleDocRB );
     357             : 
     358           0 :     aLk = LINK(this, SwMailMergeDlg, ModifyHdl);
     359           0 :     aFromNF.SetModifyHdl(aLk);
     360           0 :     aToNF.SetModifyHdl(aLk);
     361           0 :     aFromNF.SetMax(SAL_MAX_INT32);
     362           0 :     aToNF.SetMax(SAL_MAX_INT32);
     363             : 
     364           0 :     SwNewDBMgr* pNewDBMgr = rSh.GetNewDBMgr();
     365           0 :     if(_xConnection.is())
     366           0 :         pNewDBMgr->GetColumnNames(&aAddressFldLB, _xConnection, rTableName);
     367             :     else
     368           0 :         pNewDBMgr->GetColumnNames(&aAddressFldLB, rDBName, rTableName);
     369           0 :     for(sal_uInt16 nEntry = 0; nEntry < aAddressFldLB.GetEntryCount(); nEntry++)
     370           0 :         aColumnLB.InsertEntry(aAddressFldLB.GetEntry(nEntry));
     371             : 
     372           0 :     aAddressFldLB.SelectEntry(rtl::OUString("EMAIL"));
     373             : 
     374           0 :     String sPath(pModOpt->GetMailingPath());
     375           0 :     if(!sPath.Len())
     376             :     {
     377           0 :         SvtPathOptions aPathOpt;
     378           0 :         sPath = aPathOpt.GetWorkPath();
     379             :     }
     380           0 :     INetURLObject aURL(sPath);
     381           0 :     if(aURL.GetProtocol() == INET_PROT_FILE)
     382           0 :         aPathED.SetText(aURL.PathToFileName());
     383             :     else
     384           0 :         aPathED.SetText(aURL.GetFull());
     385             : 
     386           0 :     if (!bColumn )
     387             :     {
     388           0 :         aColumnLB.SelectEntry(rtl::OUString("NAME"));
     389             :     }
     390             :     else
     391           0 :         aColumnLB.SelectEntry(pModOpt->GetNameFromColumn());
     392             : 
     393           0 :     if (aAddressFldLB.GetSelectEntryCount() == 0)
     394           0 :         aAddressFldLB.SelectEntryPos(0);
     395           0 :     if (aColumnLB.GetSelectEntryCount() == 0)
     396           0 :         aColumnLB.SelectEntryPos(0);
     397             : 
     398           0 :     const sal_Bool bEnable = m_aSelection.getLength() != 0;
     399           0 :     aMarkedRB.Enable(bEnable);
     400           0 :     if (bEnable)
     401           0 :         aMarkedRB.Check();
     402             :     else
     403             :     {
     404           0 :         aAllRB.Check();
     405           0 :         aMarkedRB.Enable(sal_False);
     406             :     }
     407           0 :     SetMinOutputSizePixel(m_aDialogSize);
     408             :     try
     409             :     {
     410             :         uno::Reference< container::XNameContainer> xFilterFactory(
     411           0 :                 xMSF->createInstance("com.sun.star.document.FilterFactory"), UNO_QUERY_THROW);
     412           0 :         uno::Reference< container::XContainerQuery > xQuery(xFilterFactory, UNO_QUERY_THROW);
     413           0 :         OUString sCommand("matchByDocumentService=com.sun.star.text.TextDocument:iflags=");
     414           0 :         sCommand += String::CreateFromInt32(SFX_FILTER_EXPORT);
     415           0 :         sCommand += ":eflags=";
     416           0 :         sCommand += String::CreateFromInt32(SFX_FILTER_NOTINFILEDLG);
     417           0 :         sCommand += ":default_first";
     418           0 :         uno::Reference< container::XEnumeration > xList = xQuery->createSubSetEnumerationByQuery(sCommand);
     419           0 :         const ::rtl::OUString sName(RTL_CONSTASCII_USTRINGPARAM("Name"));
     420           0 :         sal_uInt16 nODT = USHRT_MAX;
     421           0 :         while(xList->hasMoreElements())
     422             :         {
     423           0 :             comphelper::SequenceAsHashMap aFilter(xList->nextElement());
     424           0 :             OUString sFilter = aFilter.getUnpackedValueOrDefault(sName, OUString());
     425             : 
     426           0 :             uno::Any aProps = xFilterFactory->getByName(sFilter);
     427           0 :             uno::Sequence< beans::PropertyValue > aFilterProperties;
     428           0 :             aProps >>= aFilterProperties;
     429           0 :             ::rtl::OUString sUIName2;
     430           0 :             const beans::PropertyValue* pFilterProperties = aFilterProperties.getConstArray();
     431           0 :             for(int nProp = 0; nProp < aFilterProperties.getLength(); nProp++)
     432             :             {
     433           0 :                 if(!pFilterProperties[nProp].Name.compareToAscii("UIName"))
     434             :                 {
     435           0 :                     pFilterProperties[nProp].Value >>= sUIName2;
     436           0 :                     break;
     437             :                 }
     438             :             }
     439           0 :             if( !sUIName2.isEmpty() )
     440             :             {
     441           0 :                 sal_uInt16 nFilter = aFilterLB.InsertEntry( sUIName2 );
     442           0 :                 if( 0 == sFilter.compareToAscii("writer8") )
     443           0 :                     nODT = nFilter;
     444           0 :                 aFilterLB.SetEntryData( nFilter, new ::rtl::OUString( sFilter ) );
     445             :             }
     446           0 :         }
     447           0 :         aFilterLB.SelectEntryPos( nODT );
     448             :     }
     449           0 :     catch (const uno::Exception&)
     450             :     {
     451           0 :     }
     452           0 : }
     453             : 
     454           0 : SwMailMergeDlg::~SwMailMergeDlg()
     455             : {
     456           0 :     if(xFrame.is())
     457             :     {
     458           0 :         xFrame->setComponent(NULL, NULL);
     459           0 :         xFrame->dispose();
     460             :     }
     461             :     else
     462           0 :         delete pBeamerWin;
     463             : 
     464           0 :     for( sal_uInt16 nFilter = 0; nFilter < aFilterLB.GetEntryCount(); ++nFilter )
     465             :     {
     466           0 :         ::rtl::OUString* pData = reinterpret_cast< ::rtl::OUString* >( aFilterLB.GetEntryData(nFilter) );
     467           0 :         delete pData;
     468             :     }
     469           0 :     delete pImpl;
     470           0 : }
     471             : 
     472           0 : void SwMailMergeDlg::Apply()
     473             : {
     474           0 : }
     475             : 
     476           0 : static void lcl_MoveControlY( Window* ppW, long nDiffSize )
     477             : {
     478           0 :     Point aPos( ppW->GetPosPixel());
     479           0 :     aPos.Y() += nDiffSize;
     480           0 :     ppW->SetPosPixel( aPos );
     481           0 : }
     482             : 
     483           0 : static void lcl_MoveControlX( Window* ppW, long nDiffSize )
     484             : {
     485           0 :     Point aPos( ppW->GetPosPixel());
     486           0 :     aPos.X() += nDiffSize;
     487           0 :     ppW->SetPosPixel( aPos );
     488           0 : }
     489             : 
     490           0 : static void lcl_ChangeWidth( Window* ppW, long nDiffSize )
     491             : {
     492           0 :     Size aSize( ppW->GetSizePixel());
     493           0 :     aSize.Width() += nDiffSize;
     494           0 :     ppW->SetSizePixel( aSize );
     495           0 : }
     496             : 
     497           0 : void    SwMailMergeDlg::Resize()
     498             : {
     499             :     //the only controls that profit from the resize is pBeamerWin
     500             :     // and aPathED, aFilenameED and aColumnLB
     501             : 
     502           0 :     Size aCurSize( GetSizePixel() );
     503             :     //find the difference
     504           0 :     Size aDiffSize( aCurSize.Width() - m_aDialogSize.Width(),
     505           0 :                             aCurSize.Height() - m_aDialogSize.Height() );
     506           0 :     m_aDialogSize = aCurSize;
     507           0 :     if( pBeamerWin->IsVisible() )
     508             :     {
     509             :         Window* aCntrlArr[] = {
     510             :             &aAllRB       ,
     511             :             &aMarkedRB    ,
     512             :             &aFromRB      ,
     513             :             &aFromNF      ,
     514             :             &aBisFT       ,
     515             :             &aToNF        ,
     516             :             &aRecordFL    ,
     517             :             &aPrinterRB   ,
     518             :             &aMailingRB   ,
     519             :             &aFileRB      ,
     520             :             &aSingleJobsCB,
     521             :             &aSaveMergedDocumentFL,
     522             :             &aSaveSingleDocRB,
     523             :             &aSaveIndividualRB,
     524             :             &aGenerateFromDataBaseCB,
     525             :             &aPathFT      ,
     526             :             &aPathED      ,
     527             :             &aPathPB      ,
     528             :             &aColumnFT,
     529             :             &aColumnLB    ,
     530             :             &aFilterFT    ,
     531             :             &aFilterLB    ,
     532             :             &aAddressFldLB,
     533             :             &aSubjectFT   ,
     534             :             &aSubjectED   ,
     535             :             &aFormatFT    ,
     536             :             &aAttachFT    ,
     537             :             &aAttachED    ,
     538             :             &aAttachPB    ,
     539             :             &aFormatHtmlCB,
     540             :             &aFormatRtfCB ,
     541             :             &aFormatSwCB  ,
     542             :             &aDestFL      ,
     543             :             &aSeparatorFL ,
     544             :             &aBottomSeparatorFL,
     545             :             &aOkBTN,
     546             :             &aCancelBTN,
     547             :             &aHelpBTN,
     548           0 :             0};
     549           0 :         for( Window** ppW = aCntrlArr; *ppW; ++ppW )
     550             :         {
     551           0 :             lcl_MoveControlY( *ppW, aDiffSize.Height() );
     552             :         }
     553             :         //some controls have to be extended horizontally
     554           0 :         lcl_MoveControlX( &aOkBTN, aDiffSize.Width() );
     555           0 :         lcl_MoveControlX( &aCancelBTN, aDiffSize.Width() );
     556           0 :         lcl_MoveControlX( &aHelpBTN, aDiffSize.Width() );
     557           0 :         lcl_MoveControlX( &aPathPB, aDiffSize.Width() );
     558           0 :         lcl_MoveControlX( &aFileRB, aDiffSize.Width()/2 );
     559             : 
     560           0 :         lcl_ChangeWidth( &aBottomSeparatorFL, aDiffSize.Width() );
     561           0 :         lcl_ChangeWidth( &aSaveMergedDocumentFL, aDiffSize.Width() );
     562           0 :         lcl_ChangeWidth( &aColumnLB, aDiffSize.Width() );
     563           0 :         lcl_ChangeWidth( &aPathED, aDiffSize.Width() );
     564           0 :         lcl_ChangeWidth( &aFilterLB, aDiffSize.Width() );
     565           0 :         lcl_ChangeWidth( &aDestFL, aDiffSize.Width() );
     566             : 
     567           0 :         Size aBeamerSize( pBeamerWin->GetSizePixel() ) ;
     568           0 :         aBeamerSize.Width() += aDiffSize.Width();
     569           0 :         aBeamerSize.Height() += aDiffSize.Height();
     570           0 :         pBeamerWin->SetSizePixel(aBeamerSize);
     571             :     }
     572           0 : }
     573             : 
     574           0 : IMPL_LINK( SwMailMergeDlg, ButtonHdl, Button *, pBtn )
     575             : {
     576           0 :     if (pBtn == &aOkBTN)
     577             :     {
     578           0 :         if( ExecQryShell() )
     579           0 :             EndDialog(RET_OK);
     580             :     }
     581           0 :     return 0;
     582             : }
     583             : 
     584           0 : IMPL_LINK( SwMailMergeDlg, OutputTypeHdl, RadioButton *, pBtn )
     585             : {
     586           0 :     sal_Bool bPrint = pBtn == &aPrinterRB;
     587           0 :     aSingleJobsCB.Enable(bPrint);
     588             : 
     589           0 :     aSaveMergedDocumentFL.Enable( !bPrint );
     590           0 :     aSaveSingleDocRB.Enable( !bPrint );
     591           0 :     aSaveIndividualRB.Enable( !bPrint );
     592             : 
     593           0 :     if( !bPrint )
     594             :     {
     595           0 :         SaveTypeHdl( aSaveSingleDocRB.IsChecked() ? &aSaveSingleDocRB : &aSaveIndividualRB );
     596             :     }
     597             :     else
     598             :     {
     599           0 :         aPathFT.Enable(false);
     600           0 :         aPathED.Enable(false);
     601           0 :         aPathPB.Enable(false);
     602           0 :         aColumnFT.Enable(false);
     603           0 :         aColumnLB.Enable(false);
     604           0 :         aFilterFT.Enable(false);
     605           0 :         aFilterLB.Enable(false);
     606           0 :         aGenerateFromDataBaseCB.Enable(false);
     607             :     }
     608             : 
     609           0 :     return 0;
     610             : }
     611             : 
     612           0 : IMPL_LINK( SwMailMergeDlg, SaveTypeHdl, RadioButton*,  pBtn )
     613             : {
     614           0 :     bool bIndividual = pBtn == &aSaveIndividualRB;
     615             : 
     616           0 :     aGenerateFromDataBaseCB.Enable( bIndividual );
     617           0 :     if( bIndividual )
     618             :     {
     619           0 :         FilenameHdl( &aGenerateFromDataBaseCB );
     620             :     }
     621             :     else
     622             :     {
     623           0 :         aColumnFT.Enable(false);
     624           0 :         aColumnLB.Enable(false);
     625           0 :         aPathFT.Enable( false );
     626           0 :         aPathED.Enable( false );
     627           0 :         aPathPB.Enable( false );
     628           0 :         aFilterFT.Enable( false );
     629           0 :         aFilterLB.Enable( false );
     630             :     }
     631           0 :     return 0;
     632             : }
     633             : 
     634           0 : IMPL_LINK( SwMailMergeDlg, FilenameHdl, CheckBox*, pBox )
     635             : {
     636           0 :     sal_Bool bEnable = pBox->IsChecked();
     637           0 :     aColumnFT.Enable( bEnable );
     638           0 :     aColumnLB.Enable(bEnable);
     639           0 :     aPathFT.Enable( bEnable );
     640           0 :     aPathED.Enable(bEnable);
     641           0 :     aPathPB.Enable( bEnable );
     642           0 :     aFilterFT.Enable( bEnable );
     643           0 :     aFilterLB.Enable( bEnable );
     644           0 :  return 0;
     645             : }
     646             : 
     647           0 : IMPL_LINK_NOARG(SwMailMergeDlg, ModifyHdl)
     648             : {
     649           0 :     aFromRB.Check();
     650           0 :     return (0);
     651             : }
     652             : 
     653           0 : bool SwMailMergeDlg::ExecQryShell()
     654             : {
     655           0 :     if(pImpl->xSelSupp.is())
     656             :     {
     657           0 :         pImpl->xSelSupp->removeSelectionChangeListener(  pImpl->xChgLstnr );
     658             :     }
     659           0 :     SwNewDBMgr* pMgr = rSh.GetNewDBMgr();
     660             : 
     661           0 :     if (aPrinterRB.IsChecked())
     662           0 :         nMergeType = DBMGR_MERGE_MAILMERGE;
     663           0 :     else if (aMailingRB.IsChecked())
     664             :     {
     665           0 :         nMergeType = DBMGR_MERGE_MAILING;
     666           0 :         pMgr->SetEMailColumn(aAddressFldLB.GetSelectEntry());
     667           0 :         pMgr->SetSubject(aSubjectED.GetText());
     668           0 :         pMgr->SetAttachment(aAttachED.GetText());
     669             :     }
     670             :     else
     671             :     {
     672           0 :         nMergeType = static_cast< sal_uInt16 >( aSaveSingleDocRB.IsChecked() ?
     673           0 :                     DBMGR_MERGE_SINGLE_FILE : DBMGR_MERGE_MAILFILES );
     674           0 :         SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium();
     675           0 :         INetURLObject aAbs;
     676           0 :         if( pMedium )
     677           0 :             aAbs = pMedium->GetURLObject();
     678             :         String sPath(
     679             :             URIHelper::SmartRel2Abs(
     680           0 :                 aAbs, aPathED.GetText(), URIHelper::GetMaybeFileHdl()));
     681           0 :         pModOpt->SetMailingPath(sPath);
     682           0 :         String sDelim = rtl::OUString(INET_PATH_TOKEN);
     683             : 
     684           0 :         if (sPath.Len() >= sDelim.Len() &&
     685           0 :             sPath.Copy(sPath.Len()-sDelim.Len()).CompareTo(sDelim) != COMPARE_EQUAL)
     686           0 :             sPath += sDelim;
     687             : 
     688           0 :         pModOpt->SetIsNameFromColumn(aGenerateFromDataBaseCB.IsChecked());
     689             : 
     690           0 :         if (aGenerateFromDataBaseCB.IsEnabled() && aGenerateFromDataBaseCB.IsChecked())
     691             :         {
     692           0 :             pMgr->SetEMailColumn(aColumnLB.GetSelectEntry());
     693           0 :             pModOpt->SetNameFromColumn(aColumnLB.GetSelectEntry());
     694           0 :             if( aFilterLB.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND)
     695           0 :                 m_sSaveFilter = *static_cast<const ::rtl::OUString*>(aFilterLB.GetEntryData( aFilterLB.GetSelectEntryPos() ));
     696             :         }
     697             :         else
     698             :         {
     699             :             //#i97667# reset column name - otherwise it's remembered from the last run
     700           0 :             pMgr->SetEMailColumn(::rtl::OUString());
     701             :             //start save as dialog
     702           0 :             String sFilter;
     703           0 :             sPath = SwMailMergeHelper::CallSaveAsDialog(sFilter);
     704           0 :             if(!sPath.Len())
     705           0 :                 return false;
     706           0 :             m_sSaveFilter = sFilter;
     707             :         }
     708             : 
     709           0 :         pMgr->SetSubject(sPath);
     710             :     }
     711             : 
     712           0 :     if (aFromRB.IsChecked())    // Insert list
     713             :     {
     714             :         // Safe: the maximal value of the fields is limited
     715           0 :         sal_Int32 nStart = sal::static_int_cast<sal_Int32>(aFromNF.GetValue());
     716           0 :         sal_Int32 nEnd = sal::static_int_cast<sal_Int32>(aToNF.GetValue());
     717             : 
     718           0 :         if (nEnd < nStart)
     719           0 :             std::swap(nEnd, nStart);
     720             : 
     721           0 :         m_aSelection.realloc(nEnd - nStart + 1);
     722           0 :         Any* pSelection = m_aSelection.getArray();
     723           0 :         for (sal_Int32 i = nStart; i <= nEnd; ++i, ++pSelection)
     724           0 :             *pSelection <<= i;
     725             :     }
     726           0 :     else if (aAllRB.IsChecked() )
     727           0 :         m_aSelection.realloc(0);    // Empty selection = insert all
     728             :     else
     729             :     {
     730           0 :         if(pImpl->xSelSupp.is())
     731             :         {
     732             :             //update selection
     733           0 :             uno::Reference< XRowLocate > xRowLocate(GetResultSet(),UNO_QUERY);
     734           0 :             uno::Reference< XResultSet > xRes(xRowLocate,UNO_QUERY);
     735           0 :             pImpl->xSelSupp->getSelection() >>= m_aSelection;
     736           0 :             if ( xRowLocate.is() )
     737             :             {
     738           0 :                 Any* pBegin = m_aSelection.getArray();
     739           0 :                 Any* pEnd   = pBegin + m_aSelection.getLength();
     740           0 :                 for (;pBegin != pEnd ; ++pBegin)
     741             :                 {
     742           0 :                     if ( xRowLocate->moveToBookmark(*pBegin) )
     743           0 :                         *pBegin <<= xRes->getRow();
     744             :                 }
     745           0 :             }
     746             :         }
     747             :     }
     748           0 :     IDocumentDeviceAccess* pIDDA = rSh.getIDocumentDeviceAccess();
     749           0 :     SwPrintData aPrtData( pIDDA->getPrintData() );
     750           0 :     aPrtData.SetPrintSingleJobs(aSingleJobsCB.IsChecked());
     751           0 :     pIDDA->setPrintData(aPrtData);
     752             : 
     753           0 :     pModOpt->SetSinglePrintJob(aSingleJobsCB.IsChecked());
     754             : 
     755           0 :     sal_uInt8 nMailingMode = 0;
     756             : 
     757           0 :     if (aFormatSwCB.IsChecked())
     758           0 :         nMailingMode |= TXTFORMAT_OFFICE;
     759           0 :     if (aFormatHtmlCB.IsChecked())
     760           0 :         nMailingMode |= TXTFORMAT_HTML;
     761           0 :     if (aFormatRtfCB.IsChecked())
     762           0 :         nMailingMode |= TXTFORMAT_RTF;
     763           0 :     pModOpt->SetMailingFormats(nMailingMode);
     764           0 :     return true;
     765             : }
     766             : 
     767           0 : IMPL_LINK_NOARG(SwMailMergeDlg, InsertPathHdl)
     768             : {
     769           0 :     String sPath( aPathED.GetText() );
     770           0 :     if( !sPath.Len() )
     771             :     {
     772           0 :         SvtPathOptions aPathOpt;
     773           0 :         sPath = aPathOpt.GetWorkPath();
     774             :     }
     775             : 
     776           0 :     uno::Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     777           0 :     uno::Reference < XFolderPicker2 > xFP = FolderPicker::create(xContext);
     778           0 :     xFP->setDisplayDirectory(sPath);
     779           0 :     if( xFP->execute() == RET_OK )
     780             :     {
     781           0 :         INetURLObject aURL(xFP->getDirectory());
     782           0 :         if(aURL.GetProtocol() == INET_PROT_FILE)
     783           0 :             aPathED.SetText(aURL.PathToFileName());
     784             :         else
     785           0 :             aPathED.SetText(aURL.GetFull());
     786             :     }
     787           0 :     return 0;
     788             : }
     789             : 
     790           0 : IMPL_LINK_NOARG(SwMailMergeDlg, AttachFileHdl)
     791             : {
     792           0 :     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     793           0 :     if(pFact)
     794             :     {
     795           0 :         AbstractSvxMultiFileDialog* pFileDlg = pFact->CreateSvxMultiFileDialog( this );
     796             :         OSL_ENSURE(pFileDlg, "Dialogdiet fail!");
     797           0 :         pFileDlg->SetFiles(aAttachED.GetText());
     798           0 :         pFileDlg->SetHelpId(HID_FILEDLG_MAILMRGE2);
     799             : 
     800           0 :         if (pFileDlg->Execute())
     801           0 :             aAttachED.SetText(pFileDlg->GetFiles());
     802             : 
     803           0 :         delete pFileDlg;
     804             :     }
     805           0 :     return 0;
     806             : }
     807             : 
     808           0 : uno::Reference<XResultSet> SwMailMergeDlg::GetResultSet() const
     809             : {
     810           0 :     uno::Reference< XResultSet >  xResSetClone;
     811           0 :     if ( pImpl->xFController.is() )
     812             :     {
     813             :         // we create a clone to do the task
     814           0 :         uno::Reference< XResultSetAccess > xResultSetAccess( pImpl->xFController->getModel(),UNO_QUERY);
     815           0 :         if ( xResultSetAccess.is() )
     816           0 :             xResSetClone = xResultSetAccess->createResultSet();
     817             :     }
     818           0 :     return xResSetClone;
     819             : }
     820             : 
     821           0 : SwMailMergeCreateFromDlg::SwMailMergeCreateFromDlg(Window* pParent) :
     822             :     ModalDialog(pParent, SW_RES(DLG_MERGE_CREATE)),
     823             :     aCreateFromFL(  this, SW_RES( FL_CREATEFROM  )),
     824             :     aThisDocRB(     this, SW_RES( RB_THISDOC     )),
     825             :     aUseTemplateRB( this, SW_RES( RB_TEMPLATE    )),
     826             :     aOK(            this, SW_RES( BT_OK          )),
     827             :     aCancel(        this, SW_RES( BT_CANCEL      )),
     828           0 :     aHelp(          this, SW_RES( BT_HELP        ))
     829             : {
     830           0 :     FreeResource();
     831           0 : }
     832             : 
     833           0 : SwMailMergeCreateFromDlg::~SwMailMergeCreateFromDlg()
     834             : {
     835           0 : }
     836             : 
     837           0 : SwMailMergeFieldConnectionsDlg::SwMailMergeFieldConnectionsDlg(Window* pParent) :
     838             :     ModalDialog(pParent, SW_RES(DLG_MERGE_FIELD_CONNECTIONS)),
     839             :     aConnectionsFL( this, SW_RES( FL_CONNECTIONS  )),
     840             :     aUseExistingRB( this, SW_RES( RB_USEEXISTING )),
     841             :     aCreateNewRB(   this, SW_RES( RB_CREATENEW    )),
     842             :     aInfoFI(        this, SW_RES( FT_INFO        )),
     843             :     aOK(            this, SW_RES( BT_OK          )),
     844             :     aCancel(        this, SW_RES( BT_CANCEL      )),
     845           0 :     aHelp(          this, SW_RES( BT_HELP        ))
     846             : {
     847           0 :     FreeResource();
     848           0 : }
     849             : 
     850           0 : SwMailMergeFieldConnectionsDlg::~SwMailMergeFieldConnectionsDlg()
     851             : {
     852           0 : }
     853             : 
     854             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10