Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <vcl/msgbox.hxx>
21 : #include <vcl/svapp.hxx>
22 : #include <vcl/settings.hxx>
23 :
24 : #include <tools/urlobj.hxx>
25 : #include <svl/urihelper.hxx>
26 : #include <unotools/pathoptions.hxx>
27 : #include <svl/mailenum.hxx>
28 : #include <svx/svxdlg.hxx>
29 : #include <svx/dialogs.hrc>
30 : #include <helpid.h>
31 : #include <view.hxx>
32 : #include <docsh.hxx>
33 : #include <IDocumentDeviceAccess.hxx>
34 : #include <wrtsh.hxx>
35 : #include <dbmgr.hxx>
36 : #include <dbui.hxx>
37 : #include <prtopt.hxx>
38 : #include <swmodule.hxx>
39 : #include <modcfg.hxx>
40 : #include <mailmergehelper.hxx>
41 : #include <envelp.hrc>
42 : #include <mailmrge.hrc>
43 : #include <mailmrge.hxx>
44 : #include <sfx2/docfile.hxx>
45 : #include <sfx2/docfilt.hxx>
46 : #include <comphelper/sequenceashashmap.hxx>
47 : #include <com/sun/star/frame/XDispatchProvider.hpp>
48 : #include <com/sun/star/container/XChild.hpp>
49 : #include <com/sun/star/container/XContainerQuery.hpp>
50 : #include <com/sun/star/container/XEnumeration.hpp>
51 : #include <com/sun/star/form/runtime/XFormController.hpp>
52 : #include <com/sun/star/frame/Frame.hpp>
53 : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
54 : #include <com/sun/star/sdbcx/XRowLocate.hpp>
55 : #include <com/sun/star/sdb/XResultSetAccess.hpp>
56 : #include <com/sun/star/sdbc/XDataSource.hpp>
57 : #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
58 : #include <toolkit/helper/vclunohelper.hxx>
59 : #include <comphelper/processfactory.hxx>
60 : #include <cppuhelper/implbase1.hxx>
61 :
62 : #include <unomid.h>
63 :
64 : #include <algorithm>
65 :
66 : using namespace ::com::sun::star;
67 : using namespace ::com::sun::star::container;
68 : using namespace ::com::sun::star::lang;
69 : using namespace ::com::sun::star::sdb;
70 : using namespace ::com::sun::star::sdbc;
71 : using namespace ::com::sun::star::sdbcx;
72 : using namespace ::com::sun::star::beans;
73 : using namespace ::com::sun::star::util;
74 : using namespace ::com::sun::star::uno;
75 : using namespace ::com::sun::star::frame;
76 : using namespace ::com::sun::star::form;
77 : using namespace ::com::sun::star::view;
78 : using namespace ::com::sun::star::ui::dialogs;
79 :
80 0 : struct SwMailMergeDlg_Impl
81 : {
82 : uno::Reference<runtime::XFormController> xFController;
83 : uno::Reference<XSelectionChangeListener> xChgLstnr;
84 : uno::Reference<XSelectionSupplier> xSelSupp;
85 : };
86 :
87 : /* --------------------------------------------------------------------------
88 : helper classes
89 : ----------------------------------------------------------------------------*/
90 : class SwXSelChgLstnr_Impl : public cppu::WeakImplHelper1
91 : <
92 : view::XSelectionChangeListener
93 : >
94 : {
95 : SwMailMergeDlg& rParent;
96 : public:
97 : SwXSelChgLstnr_Impl(SwMailMergeDlg& rParentDlg);
98 : virtual ~SwXSelChgLstnr_Impl();
99 :
100 : virtual void SAL_CALL selectionChanged( const EventObject& aEvent ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
101 : virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
102 : };
103 :
104 0 : SwXSelChgLstnr_Impl::SwXSelChgLstnr_Impl(SwMailMergeDlg& rParentDlg) :
105 0 : rParent(rParentDlg)
106 0 : {}
107 :
108 0 : SwXSelChgLstnr_Impl::~SwXSelChgLstnr_Impl()
109 0 : {}
110 :
111 0 : void SwXSelChgLstnr_Impl::selectionChanged( const EventObject& ) throw (RuntimeException, std::exception)
112 : {
113 : //call the parent to enable selection mode
114 0 : Sequence <Any> aSelection;
115 0 : if(rParent.pImpl->xSelSupp.is())
116 0 : rParent.pImpl->xSelSupp->getSelection() >>= aSelection;
117 :
118 0 : sal_Bool bEnable = aSelection.getLength() > 0;
119 0 : rParent.aMarkedRB.Enable(bEnable);
120 0 : if(bEnable)
121 0 : rParent.aMarkedRB.Check();
122 0 : else if(rParent.aMarkedRB.IsChecked())
123 : {
124 0 : rParent.aAllRB.Check();
125 0 : rParent.m_aSelection.realloc(0);
126 0 : }
127 0 : }
128 :
129 0 : void SwXSelChgLstnr_Impl::disposing( const EventObject& ) throw (RuntimeException, std::exception)
130 : {
131 : OSL_FAIL("disposing");
132 0 : }
133 :
134 0 : SwMailMergeDlg::SwMailMergeDlg(Window* pParent, SwWrtShell& rShell,
135 : const OUString& rSourceName,
136 : const OUString& rTblName,
137 : sal_Int32 nCommandType,
138 : const uno::Reference< XConnection>& _xConnection,
139 : Sequence< Any >* pSelection) :
140 :
141 : SvxStandardDialog(pParent, SW_RES(DLG_MAILMERGE)),
142 0 : pBeamerWin (new Window(this, SW_RES(WIN_BEAMER))),
143 :
144 : aAllRB (this, SW_RES(RB_ALL)),
145 : aMarkedRB (this, SW_RES(RB_MARKED)),
146 : aFromRB (this, SW_RES(RB_FROM)),
147 : aFromNF (this, SW_RES(NF_FROM)),
148 : aBisFT (this, SW_RES(FT_BIS)),
149 : aToNF (this, SW_RES(NF_TO)),
150 : aRecordFL (this, SW_RES(FL_RECORD)),
151 :
152 : aSeparatorFL (this, SW_RES(FL_SEPARATOR)),
153 :
154 : aPrinterRB (this, SW_RES(RB_PRINTER)),
155 : aMailingRB (this, SW_RES(RB_MAILING)),
156 : aFileRB (this, SW_RES(RB_FILE)),
157 :
158 : aSingleJobsCB (this, SW_RES(CB_SINGLE_JOBS)),
159 :
160 : aSaveMergedDocumentFL(this, SW_RES( FL_SAVE_MERGED_DOCUMENT)),
161 : aSaveSingleDocRB(this, SW_RES( RB_SAVE_SINGLE_DOC )),
162 : aSaveIndividualRB(this, SW_RES( RB_SAVE_INDIVIDUAL )),
163 : aGenerateFromDataBaseCB(this, SW_RES( RB_GENERATE_FROM_DATABASE )),
164 :
165 : aColumnFT (this, SW_RES(FT_COLUMN)),
166 : aColumnLB (this, SW_RES(LB_COLUMN)),
167 :
168 : aPathFT (this, SW_RES(FT_PATH)),
169 : aPathED (this, SW_RES(ED_PATH)),
170 : aPathPB (this, SW_RES(PB_PATH)),
171 : aFilterFT (this, SW_RES(FT_FILTER)),
172 : aFilterLB (this, SW_RES(LB_FILTER)),
173 :
174 : aAddressFldLB (this, SW_RES(LB_ADDRESSFLD)),
175 : aSubjectFT (this, SW_RES(FT_SUBJECT)),
176 : aSubjectED (this, SW_RES(ED_SUBJECT)),
177 : aFormatFT (this, SW_RES(FT_FORMAT)),
178 : aAttachFT (this, SW_RES(FT_ATTACH)),
179 : aAttachED (this, SW_RES(ED_ATTACH)),
180 : aAttachPB (this, SW_RES(PB_ATTACH)),
181 : aFormatHtmlCB (this, SW_RES(CB_FORMAT_HTML)),
182 : aFormatRtfCB (this, SW_RES(CB_FORMAT_RTF)),
183 : aFormatSwCB (this, SW_RES(CB_FORMAT_SW)),
184 : aDestFL (this, SW_RES(FL_DEST)),
185 :
186 : aBottomSeparatorFL(this, SW_RES(FL_BOTTOM_SEPARATOR)),
187 :
188 : aOkBTN (this, SW_RES(BTN_OK)),
189 : aCancelBTN (this, SW_RES(BTN_CANCEL)),
190 : aHelpBTN (this, SW_RES(BTN_HELP)),
191 :
192 0 : pImpl (new SwMailMergeDlg_Impl),
193 :
194 : rSh (rShell),
195 : nMergeType (DBMGR_MERGE_MAILING),
196 0 : m_aDialogSize( GetSizePixel() )
197 : {
198 0 : FreeResource();
199 0 : aSingleJobsCB.Show(false); // not supported in since cws printerpullpages anymore
200 : //task #97066# mailing of form letters is currently not supported
201 0 : aMailingRB.Show(false);
202 0 : aSubjectFT.Show(false);
203 0 : aSubjectED.Show(false);
204 0 : aFormatFT.Show(false);
205 0 : aFormatSwCB.Show(false);
206 0 : aFormatHtmlCB.Show(false);
207 0 : aFormatRtfCB.Show(false);
208 0 : aAttachFT.Show(false);
209 0 : aAttachED.Show(false);
210 0 : aAttachPB.Show(false);
211 :
212 0 : Point aMailPos = aMailingRB.GetPosPixel();
213 0 : Point aFilePos = aFileRB.GetPosPixel();
214 0 : aFilePos.X() -= (aFilePos.X() - aMailPos.X()) /2;
215 0 : aFileRB.SetPosPixel(aFilePos);
216 0 : uno::Reference< lang::XMultiServiceFactory > xMSF = comphelper::getProcessServiceFactory();
217 0 : if(pSelection)
218 : {
219 0 : m_aSelection = *pSelection;
220 : //move all controls
221 0 : long nDiff = aRecordFL.GetPosPixel().Y() - pBeamerWin->GetPosPixel().Y();
222 0 : pBeamerWin->Show(false);
223 0 : ::Size aSize = GetSizePixel();
224 0 : aSize.Height() -= nDiff;
225 0 : SetSizePixel(aSize);
226 : Window* aCntrlArr[] = {
227 : &aAllRB ,
228 : &aMarkedRB ,
229 : &aFromRB ,
230 : &aFromNF ,
231 : &aBisFT ,
232 : &aToNF ,
233 : &aRecordFL ,
234 : &aPrinterRB ,
235 : &aMailingRB ,
236 : &aFileRB ,
237 : &aSingleJobsCB,
238 : &aPathFT ,
239 : &aPathED ,
240 : &aPathPB ,
241 : &aFilterFT ,
242 : &aFilterLB ,
243 : &aColumnLB ,
244 : &aAddressFldLB,
245 : &aSubjectFT ,
246 : &aSubjectED ,
247 : &aFormatFT ,
248 : &aAttachFT ,
249 : &aAttachED ,
250 : &aAttachPB ,
251 : &aFormatHtmlCB,
252 : &aFormatRtfCB ,
253 : &aFormatSwCB ,
254 : &aDestFL ,
255 : &aSeparatorFL ,
256 0 : 0};
257 :
258 0 : for( Window** ppW = aCntrlArr; *ppW; ++ppW )
259 : {
260 0 : ::Point aPnt( (*ppW)->GetPosPixel() );
261 0 : aPnt.Y() -= nDiff;
262 0 : (*ppW)->SetPosPixel( aPnt );
263 : }
264 : }
265 : else
266 : {
267 : try
268 : {
269 : // create a frame wrapper for myself
270 0 : m_xFrame = frame::Frame::create( comphelper::getProcessComponentContext() );
271 0 : m_xFrame->initialize( VCLUnoHelper::GetInterface ( pBeamerWin ) );
272 : }
273 0 : catch (const Exception&)
274 : {
275 0 : m_xFrame.clear();
276 : }
277 0 : if(m_xFrame.is())
278 : {
279 0 : URL aURL;
280 0 : aURL.Complete = ".component:DB/DataSourceBrowser";
281 0 : uno::Reference<XDispatch> xD = m_xFrame->queryDispatch(aURL,
282 : "",
283 0 : 0x0C);
284 0 : if(xD.is())
285 : {
286 0 : Sequence<PropertyValue> aProperties(3);
287 0 : PropertyValue* pProperties = aProperties.getArray();
288 0 : pProperties[0].Name = "DataSourceName";
289 0 : pProperties[0].Value <<= rSourceName;
290 0 : pProperties[1].Name = "Command";
291 0 : pProperties[1].Value <<= rTblName;
292 0 : pProperties[2].Name = "CommandType";
293 0 : pProperties[2].Value <<= nCommandType;
294 0 : xD->dispatch(aURL, aProperties);
295 0 : pBeamerWin->Show();
296 : }
297 0 : uno::Reference<XController> xController = m_xFrame->getController();
298 0 : pImpl->xFController = uno::Reference<runtime::XFormController>(xController, UNO_QUERY);
299 0 : if(pImpl->xFController.is())
300 : {
301 0 : uno::Reference< awt::XControl > xCtrl = pImpl->xFController->getCurrentControl( );
302 0 : pImpl->xSelSupp = uno::Reference<XSelectionSupplier>(xCtrl, UNO_QUERY);
303 0 : if(pImpl->xSelSupp.is())
304 : {
305 0 : pImpl->xChgLstnr = new SwXSelChgLstnr_Impl(*this);
306 0 : pImpl->xSelSupp->addSelectionChangeListener( pImpl->xChgLstnr );
307 0 : }
308 0 : }
309 : }
310 : }
311 :
312 0 : pModOpt = SW_MOD()->GetModuleConfig();
313 :
314 0 : sal_Int16 nMailingMode(pModOpt->GetMailingFormats());
315 0 : aFormatSwCB.Check((nMailingMode & TXTFORMAT_OFFICE) != 0);
316 0 : aFormatHtmlCB.Check((nMailingMode & TXTFORMAT_HTML) != 0);
317 0 : aFormatRtfCB.Check((nMailingMode & TXTFORMAT_RTF) != 0);
318 :
319 0 : aAllRB.Check(true);
320 :
321 : // Install handlers
322 0 : Link aLk = LINK(this, SwMailMergeDlg, ButtonHdl);
323 0 : aOkBTN.SetClickHdl(aLk);
324 :
325 0 : aPathPB.SetClickHdl(LINK(this, SwMailMergeDlg, InsertPathHdl));
326 :
327 0 : aLk = LINK(this, SwMailMergeDlg, OutputTypeHdl);
328 0 : aPrinterRB.SetClickHdl(aLk);
329 0 : aFileRB.SetClickHdl(aLk);
330 :
331 : //#i63267# printing might be disabled
332 0 : bool bIsPrintable = !Application::GetSettings().GetMiscSettings().GetDisablePrinting();
333 0 : aPrinterRB.Enable(bIsPrintable);
334 0 : OutputTypeHdl(bIsPrintable ? &aPrinterRB : &aFileRB);
335 :
336 0 : aLk = LINK(this, SwMailMergeDlg, FilenameHdl);
337 0 : aGenerateFromDataBaseCB.SetClickHdl( aLk );
338 0 : bool bColumn = pModOpt->IsNameFromColumn();
339 0 : if(bColumn)
340 0 : aGenerateFromDataBaseCB.Check();
341 :
342 0 : FilenameHdl( &aGenerateFromDataBaseCB );
343 0 : aLk = LINK(this, SwMailMergeDlg, SaveTypeHdl);
344 0 : aSaveSingleDocRB.Check( true );
345 0 : aSaveSingleDocRB.SetClickHdl( aLk );
346 0 : aSaveIndividualRB.SetClickHdl( aLk );
347 0 : aLk.Call( &aSaveSingleDocRB );
348 :
349 0 : aLk = LINK(this, SwMailMergeDlg, ModifyHdl);
350 0 : aFromNF.SetModifyHdl(aLk);
351 0 : aToNF.SetModifyHdl(aLk);
352 0 : aFromNF.SetMax(SAL_MAX_INT32);
353 0 : aToNF.SetMax(SAL_MAX_INT32);
354 :
355 0 : SwNewDBMgr* pNewDBMgr = rSh.GetNewDBMgr();
356 0 : if(_xConnection.is())
357 0 : pNewDBMgr->GetColumnNames(&aAddressFldLB, _xConnection, rTblName);
358 : else
359 0 : pNewDBMgr->GetColumnNames(&aAddressFldLB, rSourceName, rTblName);
360 0 : for(sal_Int32 nEntry = 0; nEntry < aAddressFldLB.GetEntryCount(); ++nEntry)
361 0 : aColumnLB.InsertEntry(aAddressFldLB.GetEntry(nEntry));
362 :
363 0 : aAddressFldLB.SelectEntry("EMAIL");
364 :
365 0 : OUString sPath(pModOpt->GetMailingPath());
366 0 : if(sPath.isEmpty())
367 : {
368 0 : SvtPathOptions aPathOpt;
369 0 : sPath = aPathOpt.GetWorkPath();
370 : }
371 0 : INetURLObject aURL(sPath);
372 0 : if(aURL.GetProtocol() == INET_PROT_FILE)
373 0 : aPathED.SetText(aURL.PathToFileName());
374 : else
375 0 : aPathED.SetText(aURL.GetFull());
376 :
377 0 : if (!bColumn )
378 : {
379 0 : aColumnLB.SelectEntry("NAME");
380 : }
381 : else
382 0 : aColumnLB.SelectEntry(pModOpt->GetNameFromColumn());
383 :
384 0 : if (aAddressFldLB.GetSelectEntryCount() == 0)
385 0 : aAddressFldLB.SelectEntryPos(0);
386 0 : if (aColumnLB.GetSelectEntryCount() == 0)
387 0 : aColumnLB.SelectEntryPos(0);
388 :
389 0 : const sal_Bool bEnable = m_aSelection.getLength() != 0;
390 0 : aMarkedRB.Enable(bEnable);
391 0 : if (bEnable)
392 0 : aMarkedRB.Check();
393 : else
394 : {
395 0 : aAllRB.Check();
396 0 : aMarkedRB.Enable(false);
397 : }
398 0 : SetMinOutputSizePixel(m_aDialogSize);
399 : try
400 : {
401 : uno::Reference< container::XNameContainer> xFilterFactory(
402 0 : xMSF->createInstance("com.sun.star.document.FilterFactory"), UNO_QUERY_THROW);
403 0 : uno::Reference< container::XContainerQuery > xQuery(xFilterFactory, UNO_QUERY_THROW);
404 : const OUString sCommand("matchByDocumentService=com.sun.star.text.TextDocument:iflags="
405 0 : + OUString::number(SFX_FILTER_EXPORT)
406 0 : + ":eflags="
407 0 : + OUString::number(SFX_FILTER_NOTINFILEDLG)
408 0 : + ":default_first");
409 0 : uno::Reference< container::XEnumeration > xList = xQuery->createSubSetEnumerationByQuery(sCommand);
410 0 : const OUString sName("Name");
411 0 : sal_Int32 nODT = -1;
412 0 : while(xList->hasMoreElements())
413 : {
414 0 : comphelper::SequenceAsHashMap aFilter(xList->nextElement());
415 0 : const OUString sFilter = aFilter.getUnpackedValueOrDefault(sName, OUString());
416 :
417 0 : uno::Any aProps = xFilterFactory->getByName(sFilter);
418 0 : uno::Sequence< beans::PropertyValue > aFilterProperties;
419 0 : aProps >>= aFilterProperties;
420 0 : OUString sUIName2;
421 0 : const beans::PropertyValue* pFilterProperties = aFilterProperties.getConstArray();
422 0 : for(sal_Int32 nProp = 0; nProp < aFilterProperties.getLength(); ++nProp)
423 : {
424 0 : if(pFilterProperties[nProp].Name == "UIName")
425 : {
426 0 : pFilterProperties[nProp].Value >>= sUIName2;
427 0 : break;
428 : }
429 : }
430 0 : if( !sUIName2.isEmpty() )
431 : {
432 0 : const sal_Int32 nFilter = aFilterLB.InsertEntry( sUIName2 );
433 0 : if( sFilter.equalsAscii("writer8") )
434 0 : nODT = nFilter;
435 0 : aFilterLB.SetEntryData( nFilter, new OUString( sFilter ) );
436 : }
437 0 : }
438 0 : aFilterLB.SelectEntryPos( nODT );
439 : }
440 0 : catch (const uno::Exception&)
441 : {
442 0 : }
443 0 : }
444 :
445 0 : SwMailMergeDlg::~SwMailMergeDlg()
446 : {
447 0 : if(m_xFrame.is())
448 : {
449 0 : m_xFrame->setComponent(NULL, NULL);
450 0 : m_xFrame->dispose();
451 : }
452 : else
453 0 : delete pBeamerWin;
454 :
455 0 : for( sal_Int32 nFilter = 0; nFilter < aFilterLB.GetEntryCount(); ++nFilter )
456 : {
457 0 : OUString* pData = reinterpret_cast< OUString* >( aFilterLB.GetEntryData(nFilter) );
458 0 : delete pData;
459 : }
460 0 : delete pImpl;
461 0 : }
462 :
463 0 : void SwMailMergeDlg::Apply()
464 : {
465 0 : }
466 :
467 0 : static void lcl_MoveControlY( Window* ppW, long nDiffSize )
468 : {
469 0 : Point aPos( ppW->GetPosPixel());
470 0 : aPos.Y() += nDiffSize;
471 0 : ppW->SetPosPixel( aPos );
472 0 : }
473 :
474 0 : static void lcl_MoveControlX( Window* ppW, long nDiffSize )
475 : {
476 0 : Point aPos( ppW->GetPosPixel());
477 0 : aPos.X() += nDiffSize;
478 0 : ppW->SetPosPixel( aPos );
479 0 : }
480 :
481 0 : static void lcl_ChangeWidth( Window* ppW, long nDiffSize )
482 : {
483 0 : Size aSize( ppW->GetSizePixel());
484 0 : aSize.Width() += nDiffSize;
485 0 : ppW->SetSizePixel( aSize );
486 0 : }
487 :
488 0 : void SwMailMergeDlg::Resize()
489 : {
490 : //the only controls that profit from the resize is pBeamerWin
491 : // and aPathED, aFilenameED and aColumnLB
492 :
493 0 : Size aCurSize( GetSizePixel() );
494 : //find the difference
495 0 : Size aDiffSize( aCurSize.Width() - m_aDialogSize.Width(),
496 0 : aCurSize.Height() - m_aDialogSize.Height() );
497 0 : m_aDialogSize = aCurSize;
498 0 : if( pBeamerWin->IsVisible() )
499 : {
500 : Window* aCntrlArr[] = {
501 : &aAllRB ,
502 : &aMarkedRB ,
503 : &aFromRB ,
504 : &aFromNF ,
505 : &aBisFT ,
506 : &aToNF ,
507 : &aRecordFL ,
508 : &aPrinterRB ,
509 : &aMailingRB ,
510 : &aFileRB ,
511 : &aSingleJobsCB,
512 : &aSaveMergedDocumentFL,
513 : &aSaveSingleDocRB,
514 : &aSaveIndividualRB,
515 : &aGenerateFromDataBaseCB,
516 : &aPathFT ,
517 : &aPathED ,
518 : &aPathPB ,
519 : &aColumnFT,
520 : &aColumnLB ,
521 : &aFilterFT ,
522 : &aFilterLB ,
523 : &aAddressFldLB,
524 : &aSubjectFT ,
525 : &aSubjectED ,
526 : &aFormatFT ,
527 : &aAttachFT ,
528 : &aAttachED ,
529 : &aAttachPB ,
530 : &aFormatHtmlCB,
531 : &aFormatRtfCB ,
532 : &aFormatSwCB ,
533 : &aDestFL ,
534 : &aSeparatorFL ,
535 : &aBottomSeparatorFL,
536 : &aOkBTN,
537 : &aCancelBTN,
538 : &aHelpBTN,
539 0 : 0};
540 0 : for( Window** ppW = aCntrlArr; *ppW; ++ppW )
541 : {
542 0 : lcl_MoveControlY( *ppW, aDiffSize.Height() );
543 : }
544 : //some controls have to be extended horizontally
545 0 : lcl_MoveControlX( &aOkBTN, aDiffSize.Width() );
546 0 : lcl_MoveControlX( &aCancelBTN, aDiffSize.Width() );
547 0 : lcl_MoveControlX( &aHelpBTN, aDiffSize.Width() );
548 0 : lcl_MoveControlX( &aPathPB, aDiffSize.Width() );
549 0 : lcl_MoveControlX( &aFileRB, aDiffSize.Width()/2 );
550 :
551 0 : lcl_ChangeWidth( &aBottomSeparatorFL, aDiffSize.Width() );
552 0 : lcl_ChangeWidth( &aSaveMergedDocumentFL, aDiffSize.Width() );
553 0 : lcl_ChangeWidth( &aColumnLB, aDiffSize.Width() );
554 0 : lcl_ChangeWidth( &aPathED, aDiffSize.Width() );
555 0 : lcl_ChangeWidth( &aFilterLB, aDiffSize.Width() );
556 0 : lcl_ChangeWidth( &aDestFL, aDiffSize.Width() );
557 :
558 0 : Size aBeamerSize( pBeamerWin->GetSizePixel() ) ;
559 0 : aBeamerSize.Width() += aDiffSize.Width();
560 0 : aBeamerSize.Height() += aDiffSize.Height();
561 0 : pBeamerWin->SetSizePixel(aBeamerSize);
562 : }
563 0 : }
564 :
565 0 : IMPL_LINK( SwMailMergeDlg, ButtonHdl, Button *, pBtn )
566 : {
567 0 : if (pBtn == &aOkBTN)
568 : {
569 0 : if( ExecQryShell() )
570 0 : EndDialog(RET_OK);
571 : }
572 0 : return 0;
573 : }
574 :
575 0 : IMPL_LINK( SwMailMergeDlg, OutputTypeHdl, RadioButton *, pBtn )
576 : {
577 0 : sal_Bool bPrint = pBtn == &aPrinterRB;
578 0 : aSingleJobsCB.Enable(bPrint);
579 :
580 0 : aSaveMergedDocumentFL.Enable( !bPrint );
581 0 : aSaveSingleDocRB.Enable( !bPrint );
582 0 : aSaveIndividualRB.Enable( !bPrint );
583 :
584 0 : if( !bPrint )
585 : {
586 0 : SaveTypeHdl( aSaveSingleDocRB.IsChecked() ? &aSaveSingleDocRB : &aSaveIndividualRB );
587 : }
588 : else
589 : {
590 0 : aPathFT.Enable(false);
591 0 : aPathED.Enable(false);
592 0 : aPathPB.Enable(false);
593 0 : aColumnFT.Enable(false);
594 0 : aColumnLB.Enable(false);
595 0 : aFilterFT.Enable(false);
596 0 : aFilterLB.Enable(false);
597 0 : aGenerateFromDataBaseCB.Enable(false);
598 : }
599 :
600 0 : return 0;
601 : }
602 :
603 0 : IMPL_LINK( SwMailMergeDlg, SaveTypeHdl, RadioButton*, pBtn )
604 : {
605 0 : bool bIndividual = pBtn == &aSaveIndividualRB;
606 :
607 0 : aGenerateFromDataBaseCB.Enable( bIndividual );
608 0 : if( bIndividual )
609 : {
610 0 : FilenameHdl( &aGenerateFromDataBaseCB );
611 : }
612 : else
613 : {
614 0 : aColumnFT.Enable(false);
615 0 : aColumnLB.Enable(false);
616 0 : aPathFT.Enable( false );
617 0 : aPathED.Enable( false );
618 0 : aPathPB.Enable( false );
619 0 : aFilterFT.Enable( false );
620 0 : aFilterLB.Enable( false );
621 : }
622 0 : return 0;
623 : }
624 :
625 0 : IMPL_LINK( SwMailMergeDlg, FilenameHdl, CheckBox*, pBox )
626 : {
627 0 : sal_Bool bEnable = pBox->IsChecked();
628 0 : aColumnFT.Enable( bEnable );
629 0 : aColumnLB.Enable(bEnable);
630 0 : aPathFT.Enable( bEnable );
631 0 : aPathED.Enable(bEnable);
632 0 : aPathPB.Enable( bEnable );
633 0 : aFilterFT.Enable( bEnable );
634 0 : aFilterLB.Enable( bEnable );
635 0 : return 0;
636 : }
637 :
638 0 : IMPL_LINK_NOARG(SwMailMergeDlg, ModifyHdl)
639 : {
640 0 : aFromRB.Check();
641 0 : return (0);
642 : }
643 :
644 0 : bool SwMailMergeDlg::ExecQryShell()
645 : {
646 0 : if(pImpl->xSelSupp.is())
647 : {
648 0 : pImpl->xSelSupp->removeSelectionChangeListener( pImpl->xChgLstnr );
649 : }
650 0 : SwNewDBMgr* pMgr = rSh.GetNewDBMgr();
651 :
652 0 : if (aPrinterRB.IsChecked())
653 0 : nMergeType = DBMGR_MERGE_MAILMERGE;
654 : else
655 : {
656 0 : nMergeType = static_cast< sal_uInt16 >( aSaveSingleDocRB.IsChecked() ?
657 0 : DBMGR_MERGE_SINGLE_FILE : DBMGR_MERGE_MAILFILES );
658 0 : SfxMedium* pMedium = rSh.GetView().GetDocShell()->GetMedium();
659 0 : INetURLObject aAbs;
660 0 : if( pMedium )
661 0 : aAbs = pMedium->GetURLObject();
662 : OUString sPath(
663 : URIHelper::SmartRel2Abs(
664 0 : aAbs, aPathED.GetText(), URIHelper::GetMaybeFileHdl()));
665 0 : pModOpt->SetMailingPath(sPath);
666 :
667 0 : if (!sPath.endsWith("/"))
668 0 : sPath += "/";
669 :
670 0 : pModOpt->SetIsNameFromColumn(aGenerateFromDataBaseCB.IsChecked());
671 :
672 0 : if (aGenerateFromDataBaseCB.IsEnabled() && aGenerateFromDataBaseCB.IsChecked())
673 : {
674 0 : pMgr->SetEMailColumn(aColumnLB.GetSelectEntry());
675 0 : pModOpt->SetNameFromColumn(aColumnLB.GetSelectEntry());
676 0 : if( aFilterLB.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND)
677 0 : m_sSaveFilter = *static_cast<const OUString*>(aFilterLB.GetEntryData( aFilterLB.GetSelectEntryPos() ));
678 : }
679 : else
680 : {
681 : //#i97667# reset column name - otherwise it's remembered from the last run
682 0 : pMgr->SetEMailColumn(OUString());
683 : //start save as dialog
684 0 : OUString sFilter;
685 0 : sPath = SwMailMergeHelper::CallSaveAsDialog(sFilter);
686 0 : if (sPath.isEmpty())
687 0 : return false;
688 0 : m_sSaveFilter = sFilter;
689 : }
690 :
691 0 : pMgr->SetSubject(sPath);
692 : }
693 :
694 0 : if (aFromRB.IsChecked()) // Insert list
695 : {
696 : // Safe: the maximal value of the fields is limited
697 0 : sal_Int32 nStart = sal::static_int_cast<sal_Int32>(aFromNF.GetValue());
698 0 : sal_Int32 nEnd = sal::static_int_cast<sal_Int32>(aToNF.GetValue());
699 :
700 0 : if (nEnd < nStart)
701 0 : std::swap(nEnd, nStart);
702 :
703 0 : m_aSelection.realloc(nEnd - nStart + 1);
704 0 : Any* pSelection = m_aSelection.getArray();
705 0 : for (sal_Int32 i = nStart; i <= nEnd; ++i, ++pSelection)
706 0 : *pSelection <<= i;
707 : }
708 0 : else if (aAllRB.IsChecked() )
709 0 : m_aSelection.realloc(0); // Empty selection = insert all
710 : else
711 : {
712 0 : if(pImpl->xSelSupp.is())
713 : {
714 : //update selection
715 0 : uno::Reference< XRowLocate > xRowLocate(GetResultSet(),UNO_QUERY);
716 0 : uno::Reference< XResultSet > xRes(xRowLocate,UNO_QUERY);
717 0 : pImpl->xSelSupp->getSelection() >>= m_aSelection;
718 0 : if ( xRowLocate.is() )
719 : {
720 0 : Any* pBegin = m_aSelection.getArray();
721 0 : Any* pEnd = pBegin + m_aSelection.getLength();
722 0 : for (;pBegin != pEnd ; ++pBegin)
723 : {
724 0 : if ( xRowLocate->moveToBookmark(*pBegin) )
725 0 : *pBegin <<= xRes->getRow();
726 : }
727 0 : }
728 : }
729 : }
730 0 : IDocumentDeviceAccess* pIDDA = rSh.getIDocumentDeviceAccess();
731 0 : SwPrintData aPrtData( pIDDA->getPrintData() );
732 0 : aPrtData.SetPrintSingleJobs(aSingleJobsCB.IsChecked());
733 0 : pIDDA->setPrintData(aPrtData);
734 :
735 0 : pModOpt->SetSinglePrintJob(aSingleJobsCB.IsChecked());
736 :
737 0 : sal_uInt8 nMailingMode = 0;
738 :
739 0 : if (aFormatSwCB.IsChecked())
740 0 : nMailingMode |= TXTFORMAT_OFFICE;
741 0 : if (aFormatHtmlCB.IsChecked())
742 0 : nMailingMode |= TXTFORMAT_HTML;
743 0 : if (aFormatRtfCB.IsChecked())
744 0 : nMailingMode |= TXTFORMAT_RTF;
745 0 : pModOpt->SetMailingFormats(nMailingMode);
746 0 : return true;
747 : }
748 :
749 0 : IMPL_LINK_NOARG(SwMailMergeDlg, InsertPathHdl)
750 : {
751 0 : OUString sPath( aPathED.GetText() );
752 0 : if( sPath.isEmpty() )
753 : {
754 0 : SvtPathOptions aPathOpt;
755 0 : sPath = aPathOpt.GetWorkPath();
756 : }
757 :
758 0 : uno::Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
759 0 : uno::Reference < XFolderPicker2 > xFP = FolderPicker::create(xContext);
760 0 : xFP->setDisplayDirectory(sPath);
761 0 : if( xFP->execute() == RET_OK )
762 : {
763 0 : INetURLObject aURL(xFP->getDirectory());
764 0 : if(aURL.GetProtocol() == INET_PROT_FILE)
765 0 : aPathED.SetText(aURL.PathToFileName());
766 : else
767 0 : aPathED.SetText(aURL.GetFull());
768 : }
769 0 : return 0;
770 : }
771 :
772 0 : uno::Reference<XResultSet> SwMailMergeDlg::GetResultSet() const
773 : {
774 0 : uno::Reference< XResultSet > xResSetClone;
775 0 : if ( pImpl->xFController.is() )
776 : {
777 : // we create a clone to do the task
778 0 : uno::Reference< XResultSetAccess > xResultSetAccess( pImpl->xFController->getModel(),UNO_QUERY);
779 0 : if ( xResultSetAccess.is() )
780 0 : xResSetClone = xResultSetAccess->createResultSet();
781 : }
782 0 : return xResSetClone;
783 : }
784 :
785 0 : SwMailMergeCreateFromDlg::SwMailMergeCreateFromDlg(Window* pParent)
786 : : ModalDialog(pParent, "MailMergeDialog",
787 0 : "modules/swriter/ui/mailmergedialog.ui")
788 : {
789 0 : get(m_pThisDocRB, "document");
790 0 : }
791 :
792 0 : SwMailMergeFieldConnectionsDlg::SwMailMergeFieldConnectionsDlg(Window* pParent)
793 : : ModalDialog(pParent, "MergeConnectDialog",
794 0 : "modules/swriter/ui/mergeconnectdialog.ui")
795 : {
796 0 : get(m_pUseExistingRB, "existing");
797 0 : }
798 :
799 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|