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