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