bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / envelp / mailmrge.cxx
blob4937fe1d98505bc7b6a2719c2c75edb2b94b8944
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/msgbox.hxx>
21 #include <vcl/svapp.hxx>
22 #include <tools/urlobj.hxx>
23 #include <svl/urihelper.hxx>
24 #include <unotools/pathoptions.hxx>
25 #include <svl/mailenum.hxx>
26 #include <svx/svxdlg.hxx>
27 #include <svx/dialogs.hrc>
28 #include <helpid.h>
29 #include <view.hxx>
30 #include <docsh.hxx>
31 #include <IDocumentDeviceAccess.hxx>
32 #include <wrtsh.hxx>
33 #include <dbmgr.hxx>
34 #include <dbui.hxx>
35 #include <prtopt.hxx>
36 #include <swmodule.hxx>
37 #include <modcfg.hxx>
38 #include <mailmergehelper.hxx>
39 #include <envelp.hrc>
40 #include <mailmrge.hrc>
41 #include <mailmrge.hxx>
42 #include <sfx2/docfile.hxx>
43 #include <sfx2/docfilt.hxx>
44 #include <comphelper/sequenceashashmap.hxx>
45 #include <com/sun/star/frame/XDispatchProvider.hpp>
46 #include <com/sun/star/container/XChild.hpp>
47 #include <com/sun/star/container/XContainerQuery.hpp>
48 #include <com/sun/star/container/XEnumeration.hpp>
49 #include <com/sun/star/form/runtime/XFormController.hpp>
50 #include <com/sun/star/frame/Frame.hpp>
51 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
52 #include <com/sun/star/sdbcx/XRowLocate.hpp>
53 #include <com/sun/star/sdb/XResultSetAccess.hpp>
54 #include <com/sun/star/sdbc/XDataSource.hpp>
55 #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
56 #include <toolkit/unohlp.hxx>
57 #include <comphelper/processfactory.hxx>
58 #include <cppuhelper/implbase1.hxx>
60 #include <unomid.h>
62 #include <algorithm>
64 using namespace ::com::sun::star;
65 using namespace ::com::sun::star::container;
66 using namespace ::com::sun::star::lang;
67 using namespace ::com::sun::star::sdb;
68 using namespace ::com::sun::star::sdbc;
69 using namespace ::com::sun::star::sdbcx;
70 using namespace ::com::sun::star::beans;
71 using namespace ::com::sun::star::util;
72 using namespace ::com::sun::star::uno;
73 using namespace ::com::sun::star::frame;
74 using namespace ::com::sun::star::form;
75 using namespace ::com::sun::star::view;
76 using namespace ::com::sun::star::ui::dialogs;
79 struct SwMailMergeDlg_Impl
81 uno::Reference<runtime::XFormController> xFController;
82 uno::Reference<XSelectionChangeListener> xChgLstnr;
83 uno::Reference<XSelectionSupplier> xSelSupp;
86 /* --------------------------------------------------------------------------
87 helper classes
88 ----------------------------------------------------------------------------*/
89 class SwXSelChgLstnr_Impl : public cppu::WeakImplHelper1
91 view::XSelectionChangeListener
94 SwMailMergeDlg& rParent;
95 public:
96 SwXSelChgLstnr_Impl(SwMailMergeDlg& rParentDlg);
97 ~SwXSelChgLstnr_Impl();
99 virtual void SAL_CALL selectionChanged( const EventObject& aEvent ) throw (RuntimeException);
100 virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException);
103 SwXSelChgLstnr_Impl::SwXSelChgLstnr_Impl(SwMailMergeDlg& rParentDlg) :
104 rParent(rParentDlg)
107 SwXSelChgLstnr_Impl::~SwXSelChgLstnr_Impl()
110 void SwXSelChgLstnr_Impl::selectionChanged( const EventObject& ) throw (RuntimeException)
112 //call the parent to enable selection mode
113 Sequence <Any> aSelection;
114 if(rParent.pImpl->xSelSupp.is())
115 rParent.pImpl->xSelSupp->getSelection() >>= aSelection;
117 sal_Bool bEnable = aSelection.getLength() > 0;
118 rParent.aMarkedRB.Enable(bEnable);
119 if(bEnable)
120 rParent.aMarkedRB.Check();
121 else if(rParent.aMarkedRB.IsChecked())
123 rParent.aAllRB.Check();
124 rParent.m_aSelection.realloc(0);
128 void SwXSelChgLstnr_Impl::disposing( const EventObject& ) throw (RuntimeException)
130 OSL_FAIL("disposing");
133 SwMailMergeDlg::SwMailMergeDlg(Window* pParent, SwWrtShell& rShell,
134 const String& rSourceName,
135 const String& rTblName,
136 sal_Int32 nCommandType,
137 const uno::Reference< XConnection>& _xConnection,
138 Sequence< Any >* pSelection) :
140 SvxStandardDialog(pParent, SW_RES(DLG_MAILMERGE)),
141 pBeamerWin (new Window(this, SW_RES(WIN_BEAMER))),
143 aAllRB (this, SW_RES(RB_ALL)),
144 aMarkedRB (this, SW_RES(RB_MARKED)),
145 aFromRB (this, SW_RES(RB_FROM)),
146 aFromNF (this, SW_RES(NF_FROM)),
147 aBisFT (this, SW_RES(FT_BIS)),
148 aToNF (this, SW_RES(NF_TO)),
149 aRecordFL (this, SW_RES(FL_RECORD)),
151 aSeparatorFL (this, SW_RES(FL_SEPARATOR)),
153 aPrinterRB (this, SW_RES(RB_PRINTER)),
154 aMailingRB (this, SW_RES(RB_MAILING)),
155 aFileRB (this, SW_RES(RB_FILE)),
157 aSingleJobsCB (this, SW_RES(CB_SINGLE_JOBS)),
159 aSaveMergedDocumentFL(this, SW_RES( FL_SAVE_MERGED_DOCUMENT)),
160 aSaveSingleDocRB(this, SW_RES( RB_SAVE_SINGLE_DOC )),
161 aSaveIndividualRB(this, SW_RES( RB_SAVE_INDIVIDUAL )),
162 aGenerateFromDataBaseCB(this, SW_RES( RB_GENERATE_FROM_DATABASE )),
164 aColumnFT (this, SW_RES(FT_COLUMN)),
165 aColumnLB (this, SW_RES(LB_COLUMN)),
167 aPathFT (this, SW_RES(FT_PATH)),
168 aPathED (this, SW_RES(ED_PATH)),
169 aPathPB (this, SW_RES(PB_PATH)),
170 aFilterFT (this, SW_RES(FT_FILTER)),
171 aFilterLB (this, SW_RES(LB_FILTER)),
173 aAddressFldLB (this, SW_RES(LB_ADDRESSFLD)),
174 aSubjectFT (this, SW_RES(FT_SUBJECT)),
175 aSubjectED (this, SW_RES(ED_SUBJECT)),
176 aFormatFT (this, SW_RES(FT_FORMAT)),
177 aAttachFT (this, SW_RES(FT_ATTACH)),
178 aAttachED (this, SW_RES(ED_ATTACH)),
179 aAttachPB (this, SW_RES(PB_ATTACH)),
180 aFormatHtmlCB (this, SW_RES(CB_FORMAT_HTML)),
181 aFormatRtfCB (this, SW_RES(CB_FORMAT_RTF)),
182 aFormatSwCB (this, SW_RES(CB_FORMAT_SW)),
183 aDestFL (this, SW_RES(FL_DEST)),
185 aBottomSeparatorFL(this, SW_RES(FL_BOTTOM_SEPARATOR)),
187 aOkBTN (this, SW_RES(BTN_OK)),
188 aCancelBTN (this, SW_RES(BTN_CANCEL)),
189 aHelpBTN (this, SW_RES(BTN_HELP)),
191 pImpl (new SwMailMergeDlg_Impl),
193 rSh (rShell),
194 rDBName (rSourceName),
195 rTableName (rTblName),
196 nMergeType (DBMGR_MERGE_MAILING),
197 m_aDialogSize( GetSizePixel() )
199 FreeResource();
200 aSingleJobsCB.Show(sal_False); // not supported in since cws printerpullpages anymore
201 //task #97066# mailing of form letters is currently not supported
202 aMailingRB.Show(sal_False);
203 aSubjectFT.Show(sal_False);
204 aSubjectED.Show(sal_False);
205 aFormatFT.Show(sal_False);
206 aFormatSwCB.Show(sal_False);
207 aFormatHtmlCB.Show(sal_False);
208 aFormatRtfCB.Show(sal_False);
209 aAttachFT.Show(sal_False);
210 aAttachED.Show(sal_False);
211 aAttachPB.Show(sal_False);
213 Point aMailPos = aMailingRB.GetPosPixel();
214 Point aFilePos = aFileRB.GetPosPixel();
215 aFilePos.X() -= (aFilePos.X() - aMailPos.X()) /2;
216 aFileRB.SetPosPixel(aFilePos);
217 uno::Reference< lang::XMultiServiceFactory > xMSF = comphelper::getProcessServiceFactory();
218 if(pSelection)
220 m_aSelection = *pSelection;
221 //move all controls
222 long nDiff = aRecordFL.GetPosPixel().Y() - pBeamerWin->GetPosPixel().Y();
223 pBeamerWin->Show(sal_False);
224 ::Size aSize = GetSizePixel();
225 aSize.Height() -= nDiff;
226 SetSizePixel(aSize);
227 Window* aCntrlArr[] = {
228 &aAllRB ,
229 &aMarkedRB ,
230 &aFromRB ,
231 &aFromNF ,
232 &aBisFT ,
233 &aToNF ,
234 &aRecordFL ,
235 &aPrinterRB ,
236 &aMailingRB ,
237 &aFileRB ,
238 &aSingleJobsCB,
239 &aPathFT ,
240 &aPathED ,
241 &aPathPB ,
242 &aFilterFT ,
243 &aFilterLB ,
244 &aColumnLB ,
245 &aAddressFldLB,
246 &aSubjectFT ,
247 &aSubjectED ,
248 &aFormatFT ,
249 &aAttachFT ,
250 &aAttachED ,
251 &aAttachPB ,
252 &aFormatHtmlCB,
253 &aFormatRtfCB ,
254 &aFormatSwCB ,
255 &aDestFL ,
256 &aSeparatorFL ,
259 for( Window** ppW = aCntrlArr; *ppW; ++ppW )
261 ::Point aPnt( (*ppW)->GetPosPixel() );
262 aPnt.Y() -= nDiff;
263 (*ppW)->SetPosPixel( aPnt );
266 else
270 // create a frame wrapper for myself
271 m_xFrame = frame::Frame::create( comphelper::getProcessComponentContext() );
272 m_xFrame->initialize( VCLUnoHelper::GetInterface ( pBeamerWin ) );
274 catch (const Exception&)
276 m_xFrame.clear();
278 if(m_xFrame.is())
280 URL aURL;
281 aURL.Complete = ".component:DB/DataSourceBrowser";
282 uno::Reference<XDispatch> xD = m_xFrame->queryDispatch(aURL,
284 0x0C);
285 if(xD.is())
287 Sequence<PropertyValue> aProperties(3);
288 PropertyValue* pProperties = aProperties.getArray();
289 pProperties[0].Name = "DataSourceName";
290 pProperties[0].Value <<= OUString(rSourceName);
291 pProperties[1].Name = "Command";
292 pProperties[1].Value <<= OUString(rTableName);
293 pProperties[2].Name = "CommandType";
294 pProperties[2].Value <<= nCommandType;
295 xD->dispatch(aURL, aProperties);
296 pBeamerWin->Show();
298 uno::Reference<XController> xController = m_xFrame->getController();
299 pImpl->xFController = uno::Reference<runtime::XFormController>(xController, UNO_QUERY);
300 if(pImpl->xFController.is())
302 uno::Reference< awt::XControl > xCtrl = pImpl->xFController->getCurrentControl( );
303 pImpl->xSelSupp = uno::Reference<XSelectionSupplier>(xCtrl, UNO_QUERY);
304 if(pImpl->xSelSupp.is())
306 pImpl->xChgLstnr = new SwXSelChgLstnr_Impl(*this);
307 pImpl->xSelSupp->addSelectionChangeListener( pImpl->xChgLstnr );
313 pModOpt = SW_MOD()->GetModuleConfig();
315 sal_Int16 nMailingMode(pModOpt->GetMailingFormats());
316 aFormatSwCB.Check((nMailingMode & TXTFORMAT_OFFICE) != 0);
317 aFormatHtmlCB.Check((nMailingMode & TXTFORMAT_HTML) != 0);
318 aFormatRtfCB.Check((nMailingMode & TXTFORMAT_RTF) != 0);
320 aAllRB.Check(sal_True);
322 // Install handlers
323 Link aLk = LINK(this, SwMailMergeDlg, ButtonHdl);
324 aOkBTN.SetClickHdl(aLk);
326 aPathPB.SetClickHdl(LINK(this, SwMailMergeDlg, InsertPathHdl));
327 aAttachPB.SetClickHdl(LINK(this, SwMailMergeDlg, AttachFileHdl));
329 aLk = LINK(this, SwMailMergeDlg, OutputTypeHdl);
330 aPrinterRB.SetClickHdl(aLk);
331 aMailingRB.SetClickHdl(aLk);
332 aFileRB.SetClickHdl(aLk);
334 //#i63267# printing might be disabled
335 bool bIsPrintable = !Application::GetSettings().GetMiscSettings().GetDisablePrinting();
336 aPrinterRB.Enable(bIsPrintable);
337 OutputTypeHdl(bIsPrintable ? &aPrinterRB : &aFileRB);
339 aLk = LINK(this, SwMailMergeDlg, FilenameHdl);
340 aGenerateFromDataBaseCB.SetClickHdl( aLk );
341 bool bColumn = pModOpt->IsNameFromColumn();
342 if(bColumn)
343 aGenerateFromDataBaseCB.Check();
345 FilenameHdl( &aGenerateFromDataBaseCB );
346 aLk = LINK(this, SwMailMergeDlg, SaveTypeHdl);
347 aSaveSingleDocRB.Check( true );
348 aSaveSingleDocRB.SetClickHdl( aLk );
349 aSaveIndividualRB.SetClickHdl( aLk );
350 aLk.Call( &aSaveSingleDocRB );
352 aLk = LINK(this, SwMailMergeDlg, ModifyHdl);
353 aFromNF.SetModifyHdl(aLk);
354 aToNF.SetModifyHdl(aLk);
355 aFromNF.SetMax(SAL_MAX_INT32);
356 aToNF.SetMax(SAL_MAX_INT32);
358 SwNewDBMgr* pNewDBMgr = rSh.GetNewDBMgr();
359 if(_xConnection.is())
360 pNewDBMgr->GetColumnNames(&aAddressFldLB, _xConnection, rTableName);
361 else
362 pNewDBMgr->GetColumnNames(&aAddressFldLB, rDBName, rTableName);
363 for(sal_uInt16 nEntry = 0; nEntry < aAddressFldLB.GetEntryCount(); nEntry++)
364 aColumnLB.InsertEntry(aAddressFldLB.GetEntry(nEntry));
366 aAddressFldLB.SelectEntry(OUString("EMAIL"));
368 String sPath(pModOpt->GetMailingPath());
369 if(!sPath.Len())
371 SvtPathOptions aPathOpt;
372 sPath = aPathOpt.GetWorkPath();
374 INetURLObject aURL(sPath);
375 if(aURL.GetProtocol() == INET_PROT_FILE)
376 aPathED.SetText(aURL.PathToFileName());
377 else
378 aPathED.SetText(aURL.GetFull());
380 if (!bColumn )
382 aColumnLB.SelectEntry(OUString("NAME"));
384 else
385 aColumnLB.SelectEntry(pModOpt->GetNameFromColumn());
387 if (aAddressFldLB.GetSelectEntryCount() == 0)
388 aAddressFldLB.SelectEntryPos(0);
389 if (aColumnLB.GetSelectEntryCount() == 0)
390 aColumnLB.SelectEntryPos(0);
392 const sal_Bool bEnable = m_aSelection.getLength() != 0;
393 aMarkedRB.Enable(bEnable);
394 if (bEnable)
395 aMarkedRB.Check();
396 else
398 aAllRB.Check();
399 aMarkedRB.Enable(sal_False);
401 SetMinOutputSizePixel(m_aDialogSize);
404 uno::Reference< container::XNameContainer> xFilterFactory(
405 xMSF->createInstance("com.sun.star.document.FilterFactory"), UNO_QUERY_THROW);
406 uno::Reference< container::XContainerQuery > xQuery(xFilterFactory, UNO_QUERY_THROW);
407 OUString sCommand("matchByDocumentService=com.sun.star.text.TextDocument:iflags=");
408 sCommand += OUString::number(SFX_FILTER_EXPORT);
409 sCommand += ":eflags=";
410 sCommand += OUString::number(SFX_FILTER_NOTINFILEDLG);
411 sCommand += ":default_first";
412 uno::Reference< container::XEnumeration > xList = xQuery->createSubSetEnumerationByQuery(sCommand);
413 const OUString sName("Name");
414 sal_uInt16 nODT = USHRT_MAX;
415 while(xList->hasMoreElements())
417 comphelper::SequenceAsHashMap aFilter(xList->nextElement());
418 OUString sFilter = aFilter.getUnpackedValueOrDefault(sName, OUString());
420 uno::Any aProps = xFilterFactory->getByName(sFilter);
421 uno::Sequence< beans::PropertyValue > aFilterProperties;
422 aProps >>= aFilterProperties;
423 OUString sUIName2;
424 const beans::PropertyValue* pFilterProperties = aFilterProperties.getConstArray();
425 for(int nProp = 0; nProp < aFilterProperties.getLength(); nProp++)
427 if(!pFilterProperties[nProp].Name.compareToAscii("UIName"))
429 pFilterProperties[nProp].Value >>= sUIName2;
430 break;
433 if( !sUIName2.isEmpty() )
435 sal_uInt16 nFilter = aFilterLB.InsertEntry( sUIName2 );
436 if( 0 == sFilter.compareToAscii("writer8") )
437 nODT = nFilter;
438 aFilterLB.SetEntryData( nFilter, new OUString( sFilter ) );
441 aFilterLB.SelectEntryPos( nODT );
443 catch (const uno::Exception&)
448 SwMailMergeDlg::~SwMailMergeDlg()
450 if(m_xFrame.is())
452 m_xFrame->setComponent(NULL, NULL);
453 m_xFrame->dispose();
455 else
456 delete pBeamerWin;
458 for( sal_uInt16 nFilter = 0; nFilter < aFilterLB.GetEntryCount(); ++nFilter )
460 OUString* pData = reinterpret_cast< OUString* >( aFilterLB.GetEntryData(nFilter) );
461 delete pData;
463 delete pImpl;
466 void SwMailMergeDlg::Apply()
470 static void lcl_MoveControlY( Window* ppW, long nDiffSize )
472 Point aPos( ppW->GetPosPixel());
473 aPos.Y() += nDiffSize;
474 ppW->SetPosPixel( aPos );
477 static void lcl_MoveControlX( Window* ppW, long nDiffSize )
479 Point aPos( ppW->GetPosPixel());
480 aPos.X() += nDiffSize;
481 ppW->SetPosPixel( aPos );
484 static void lcl_ChangeWidth( Window* ppW, long nDiffSize )
486 Size aSize( ppW->GetSizePixel());
487 aSize.Width() += nDiffSize;
488 ppW->SetSizePixel( aSize );
491 void SwMailMergeDlg::Resize()
493 //the only controls that profit from the resize is pBeamerWin
494 // and aPathED, aFilenameED and aColumnLB
496 Size aCurSize( GetSizePixel() );
497 //find the difference
498 Size aDiffSize( aCurSize.Width() - m_aDialogSize.Width(),
499 aCurSize.Height() - m_aDialogSize.Height() );
500 m_aDialogSize = aCurSize;
501 if( pBeamerWin->IsVisible() )
503 Window* aCntrlArr[] = {
504 &aAllRB ,
505 &aMarkedRB ,
506 &aFromRB ,
507 &aFromNF ,
508 &aBisFT ,
509 &aToNF ,
510 &aRecordFL ,
511 &aPrinterRB ,
512 &aMailingRB ,
513 &aFileRB ,
514 &aSingleJobsCB,
515 &aSaveMergedDocumentFL,
516 &aSaveSingleDocRB,
517 &aSaveIndividualRB,
518 &aGenerateFromDataBaseCB,
519 &aPathFT ,
520 &aPathED ,
521 &aPathPB ,
522 &aColumnFT,
523 &aColumnLB ,
524 &aFilterFT ,
525 &aFilterLB ,
526 &aAddressFldLB,
527 &aSubjectFT ,
528 &aSubjectED ,
529 &aFormatFT ,
530 &aAttachFT ,
531 &aAttachED ,
532 &aAttachPB ,
533 &aFormatHtmlCB,
534 &aFormatRtfCB ,
535 &aFormatSwCB ,
536 &aDestFL ,
537 &aSeparatorFL ,
538 &aBottomSeparatorFL,
539 &aOkBTN,
540 &aCancelBTN,
541 &aHelpBTN,
543 for( Window** ppW = aCntrlArr; *ppW; ++ppW )
545 lcl_MoveControlY( *ppW, aDiffSize.Height() );
547 //some controls have to be extended horizontally
548 lcl_MoveControlX( &aOkBTN, aDiffSize.Width() );
549 lcl_MoveControlX( &aCancelBTN, aDiffSize.Width() );
550 lcl_MoveControlX( &aHelpBTN, aDiffSize.Width() );
551 lcl_MoveControlX( &aPathPB, aDiffSize.Width() );
552 lcl_MoveControlX( &aFileRB, aDiffSize.Width()/2 );
554 lcl_ChangeWidth( &aBottomSeparatorFL, aDiffSize.Width() );
555 lcl_ChangeWidth( &aSaveMergedDocumentFL, aDiffSize.Width() );
556 lcl_ChangeWidth( &aColumnLB, aDiffSize.Width() );
557 lcl_ChangeWidth( &aPathED, aDiffSize.Width() );
558 lcl_ChangeWidth( &aFilterLB, aDiffSize.Width() );
559 lcl_ChangeWidth( &aDestFL, aDiffSize.Width() );
561 Size aBeamerSize( pBeamerWin->GetSizePixel() ) ;
562 aBeamerSize.Width() += aDiffSize.Width();
563 aBeamerSize.Height() += aDiffSize.Height();
564 pBeamerWin->SetSizePixel(aBeamerSize);
568 IMPL_LINK( SwMailMergeDlg, ButtonHdl, Button *, pBtn )
570 if (pBtn == &aOkBTN)
572 if( ExecQryShell() )
573 EndDialog(RET_OK);
575 return 0;
578 IMPL_LINK( SwMailMergeDlg, OutputTypeHdl, RadioButton *, pBtn )
580 sal_Bool bPrint = pBtn == &aPrinterRB;
581 aSingleJobsCB.Enable(bPrint);
583 aSaveMergedDocumentFL.Enable( !bPrint );
584 aSaveSingleDocRB.Enable( !bPrint );
585 aSaveIndividualRB.Enable( !bPrint );
587 if( !bPrint )
589 SaveTypeHdl( aSaveSingleDocRB.IsChecked() ? &aSaveSingleDocRB : &aSaveIndividualRB );
591 else
593 aPathFT.Enable(false);
594 aPathED.Enable(false);
595 aPathPB.Enable(false);
596 aColumnFT.Enable(false);
597 aColumnLB.Enable(false);
598 aFilterFT.Enable(false);
599 aFilterLB.Enable(false);
600 aGenerateFromDataBaseCB.Enable(false);
603 return 0;
606 IMPL_LINK( SwMailMergeDlg, SaveTypeHdl, RadioButton*, pBtn )
608 bool bIndividual = pBtn == &aSaveIndividualRB;
610 aGenerateFromDataBaseCB.Enable( bIndividual );
611 if( bIndividual )
613 FilenameHdl( &aGenerateFromDataBaseCB );
615 else
617 aColumnFT.Enable(false);
618 aColumnLB.Enable(false);
619 aPathFT.Enable( false );
620 aPathED.Enable( false );
621 aPathPB.Enable( false );
622 aFilterFT.Enable( false );
623 aFilterLB.Enable( false );
625 return 0;
628 IMPL_LINK( SwMailMergeDlg, FilenameHdl, CheckBox*, pBox )
630 sal_Bool bEnable = pBox->IsChecked();
631 aColumnFT.Enable( bEnable );
632 aColumnLB.Enable(bEnable);
633 aPathFT.Enable( bEnable );
634 aPathED.Enable(bEnable);
635 aPathPB.Enable( bEnable );
636 aFilterFT.Enable( bEnable );
637 aFilterLB.Enable( bEnable );
638 return 0;
641 IMPL_LINK_NOARG(SwMailMergeDlg, ModifyHdl)
643 aFromRB.Check();
644 return (0);
647 bool SwMailMergeDlg::ExecQryShell()
649 if(pImpl->xSelSupp.is())
651 pImpl->xSelSupp->removeSelectionChangeListener( pImpl->xChgLstnr );
653 SwNewDBMgr* pMgr = rSh.GetNewDBMgr();
655 if (aPrinterRB.IsChecked())
656 nMergeType = DBMGR_MERGE_MAILMERGE;
657 else if (aMailingRB.IsChecked())
659 nMergeType = DBMGR_MERGE_MAILING;
660 pMgr->SetEMailColumn(aAddressFldLB.GetSelectEntry());
661 pMgr->SetSubject(aSubjectED.GetText());
662 pMgr->SetAttachment(aAttachED.GetText());
664 else
666 nMergeType = static_cast< sal_uInt16 >( aSaveSingleDocRB.IsChecked() ?
667 DBMGR_MERGE_SINGLE_FILE : DBMGR_MERGE_MAILFILES );
668 SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium();
669 INetURLObject aAbs;
670 if( pMedium )
671 aAbs = pMedium->GetURLObject();
672 String sPath(
673 URIHelper::SmartRel2Abs(
674 aAbs, aPathED.GetText(), URIHelper::GetMaybeFileHdl()));
675 pModOpt->SetMailingPath(sPath);
676 String sDelim = OUString(INET_PATH_TOKEN);
678 if (sPath.Len() >= sDelim.Len() &&
679 sPath.Copy(sPath.Len()-sDelim.Len()).CompareTo(sDelim) != COMPARE_EQUAL)
680 sPath += sDelim;
682 pModOpt->SetIsNameFromColumn(aGenerateFromDataBaseCB.IsChecked());
684 if (aGenerateFromDataBaseCB.IsEnabled() && aGenerateFromDataBaseCB.IsChecked())
686 pMgr->SetEMailColumn(aColumnLB.GetSelectEntry());
687 pModOpt->SetNameFromColumn(aColumnLB.GetSelectEntry());
688 if( aFilterLB.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND)
689 m_sSaveFilter = *static_cast<const OUString*>(aFilterLB.GetEntryData( aFilterLB.GetSelectEntryPos() ));
691 else
693 //#i97667# reset column name - otherwise it's remembered from the last run
694 pMgr->SetEMailColumn(OUString());
695 //start save as dialog
696 String sFilter;
697 sPath = SwMailMergeHelper::CallSaveAsDialog(sFilter);
698 if(!sPath.Len())
699 return false;
700 m_sSaveFilter = sFilter;
703 pMgr->SetSubject(sPath);
706 if (aFromRB.IsChecked()) // Insert list
708 // Safe: the maximal value of the fields is limited
709 sal_Int32 nStart = sal::static_int_cast<sal_Int32>(aFromNF.GetValue());
710 sal_Int32 nEnd = sal::static_int_cast<sal_Int32>(aToNF.GetValue());
712 if (nEnd < nStart)
713 std::swap(nEnd, nStart);
715 m_aSelection.realloc(nEnd - nStart + 1);
716 Any* pSelection = m_aSelection.getArray();
717 for (sal_Int32 i = nStart; i <= nEnd; ++i, ++pSelection)
718 *pSelection <<= i;
720 else if (aAllRB.IsChecked() )
721 m_aSelection.realloc(0); // Empty selection = insert all
722 else
724 if(pImpl->xSelSupp.is())
726 //update selection
727 uno::Reference< XRowLocate > xRowLocate(GetResultSet(),UNO_QUERY);
728 uno::Reference< XResultSet > xRes(xRowLocate,UNO_QUERY);
729 pImpl->xSelSupp->getSelection() >>= m_aSelection;
730 if ( xRowLocate.is() )
732 Any* pBegin = m_aSelection.getArray();
733 Any* pEnd = pBegin + m_aSelection.getLength();
734 for (;pBegin != pEnd ; ++pBegin)
736 if ( xRowLocate->moveToBookmark(*pBegin) )
737 *pBegin <<= xRes->getRow();
742 IDocumentDeviceAccess* pIDDA = rSh.getIDocumentDeviceAccess();
743 SwPrintData aPrtData( pIDDA->getPrintData() );
744 aPrtData.SetPrintSingleJobs(aSingleJobsCB.IsChecked());
745 pIDDA->setPrintData(aPrtData);
747 pModOpt->SetSinglePrintJob(aSingleJobsCB.IsChecked());
749 sal_uInt8 nMailingMode = 0;
751 if (aFormatSwCB.IsChecked())
752 nMailingMode |= TXTFORMAT_OFFICE;
753 if (aFormatHtmlCB.IsChecked())
754 nMailingMode |= TXTFORMAT_HTML;
755 if (aFormatRtfCB.IsChecked())
756 nMailingMode |= TXTFORMAT_RTF;
757 pModOpt->SetMailingFormats(nMailingMode);
758 return true;
761 IMPL_LINK_NOARG(SwMailMergeDlg, InsertPathHdl)
763 String sPath( aPathED.GetText() );
764 if( !sPath.Len() )
766 SvtPathOptions aPathOpt;
767 sPath = aPathOpt.GetWorkPath();
770 uno::Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
771 uno::Reference < XFolderPicker2 > xFP = FolderPicker::create(xContext);
772 xFP->setDisplayDirectory(sPath);
773 if( xFP->execute() == RET_OK )
775 INetURLObject aURL(xFP->getDirectory());
776 if(aURL.GetProtocol() == INET_PROT_FILE)
777 aPathED.SetText(aURL.PathToFileName());
778 else
779 aPathED.SetText(aURL.GetFull());
781 return 0;
784 IMPL_LINK_NOARG(SwMailMergeDlg, AttachFileHdl)
786 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
787 if(pFact)
789 AbstractSvxMultiFileDialog* pFileDlg = pFact->CreateSvxMultiFileDialog( this );
790 OSL_ENSURE(pFileDlg, "Dialogdiet fail!");
791 pFileDlg->SetFiles(aAttachED.GetText());
792 pFileDlg->SetHelpId(HID_FILEDLG_MAILMRGE2);
794 if (pFileDlg->Execute())
795 aAttachED.SetText(pFileDlg->GetFiles());
797 delete pFileDlg;
799 return 0;
802 uno::Reference<XResultSet> SwMailMergeDlg::GetResultSet() const
804 uno::Reference< XResultSet > xResSetClone;
805 if ( pImpl->xFController.is() )
807 // we create a clone to do the task
808 uno::Reference< XResultSetAccess > xResultSetAccess( pImpl->xFController->getModel(),UNO_QUERY);
809 if ( xResultSetAccess.is() )
810 xResSetClone = xResultSetAccess->createResultSet();
812 return xResSetClone;
815 SwMailMergeCreateFromDlg::SwMailMergeCreateFromDlg(Window* pParent) :
816 ModalDialog(pParent, SW_RES(DLG_MERGE_CREATE)),
817 aCreateFromFL( this, SW_RES( FL_CREATEFROM )),
818 aThisDocRB( this, SW_RES( RB_THISDOC )),
819 aUseTemplateRB( this, SW_RES( RB_TEMPLATE )),
820 aOK( this, SW_RES( BT_OK )),
821 aCancel( this, SW_RES( BT_CANCEL )),
822 aHelp( this, SW_RES( BT_HELP ))
824 FreeResource();
827 SwMailMergeCreateFromDlg::~SwMailMergeCreateFromDlg()
831 SwMailMergeFieldConnectionsDlg::SwMailMergeFieldConnectionsDlg(Window* pParent) :
832 ModalDialog(pParent, SW_RES(DLG_MERGE_FIELD_CONNECTIONS)),
833 aConnectionsFL( this, SW_RES( FL_CONNECTIONS )),
834 aUseExistingRB( this, SW_RES( RB_USEEXISTING )),
835 aCreateNewRB( this, SW_RES( RB_CREATENEW )),
836 aInfoFI( this, SW_RES( FT_INFO )),
837 aOK( this, SW_RES( BT_OK )),
838 aCancel( this, SW_RES( BT_CANCEL )),
839 aHelp( this, SW_RES( BT_HELP ))
841 FreeResource();
844 SwMailMergeFieldConnectionsDlg::~SwMailMergeFieldConnectionsDlg()
848 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */