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