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