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