update ooo310-m15
[ooovba.git] / sw / source / ui / dbui / mmoutputpage.cxx
blob06d4534918fc415e9f07106632e2d27bdf396b1e
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: mmoutputpage.cxx,v $
10 * $Revision: 1.23.136.2 $
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
36 #include <mmoutputpage.hxx>
37 #include <mailmergewizard.hxx>
38 #include <mmconfigitem.hxx>
39 #include <mailmergechildwindow.hxx>
40 #include <mailconfigpage.hxx>
41 #include <cmdid.h>
42 #include <swtypes.hxx>
43 #ifndef _VIEW_HXX
44 #include <view.hxx>
45 #endif
46 #include <wrtsh.hxx>
47 #ifndef _DOCSH_HXX
48 #include <docsh.hxx>
49 #endif
50 #ifndef IDOCUMENTDEVICEACCESS_HXX_INCLUDED
51 #include <IDocumentDeviceAccess.hxx>
52 #endif
53 #include <hintids.hxx>
54 #include <svx/scripttypeitem.hxx>
55 #include <svx/langitem.hxx>
56 #include <svtools/itemset.hxx>
57 #include <svtools/stritem.hxx>
58 #include <vcl/msgbox.hxx>
59 #include <sfx2/dinfdlg.hxx>
60 #include <sfx2/printer.hxx>
61 #include <sfx2/fcontnr.hxx>
62 #include <sfx2/viewfrm.hxx>
63 #include <sfx2/dispatch.hxx>
64 #include <sfx2/docfile.hxx>
65 //#ifndef _SFX_DOCFILT_HACK_HXX
66 //#include <sfx2/docfilt.hxx>
67 //#endif
68 #include <tools/urlobj.hxx>
69 #include <svtools/urihelper.hxx>
70 #ifndef _VCL_PRINT_HXX
71 #include <vcl/print.hxx>
72 #endif
73 #include <unotools/tempfile.hxx>
74 #include <osl/file.hxx>
75 #include <mmgreetingspage.hxx>
76 #include <com/sun/star/frame/XStorable.hpp>
77 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
78 #include <com/sun/star/sdb/XColumn.hpp>
79 //#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
80 //#include <com/sun/star/beans/PropertyValue.hpp>
81 //#endif
82 //#ifndef _BASEDLGS_HXX
83 //#include <sfx2/basedlgs.hxx>
84 //#endif
85 #ifndef _DBMGR_HXX
86 #include <dbmgr.hxx>
87 #endif
88 #include <swunohelper.hxx>
89 #include <vos/mutex.hxx>
90 #include <shellio.hxx>
91 #include <svx/htmlcfg.hxx>
92 #include <sfx2/event.hxx>
93 #include <swevent.hxx>
94 #include <mmoutputpage.hrc>
95 #include <dbui.hxx>
96 #include <dbui.hrc>
97 #include <helpid.h>
98 #include <sfx2/app.hxx>
99 #include <statstr.hrc>
100 #include <unomid.h>
102 using namespace svt;
103 using namespace ::com::sun::star;
104 using namespace ::com::sun::star::uno;
106 /*-- 01.07.2004 16:47:49---------------------------------------------------
108 -----------------------------------------------------------------------*/
109 String lcl_GetExtensionForDocType(ULONG nDocType)
111 String sExtension;
112 switch( nDocType )
114 case MM_DOCTYPE_OOO : sExtension = String::CreateFromAscii( "odt" ); break;
115 case MM_DOCTYPE_PDF : sExtension = String::CreateFromAscii( "pdf" ); break;
116 case MM_DOCTYPE_WORD: sExtension = String::CreateFromAscii( "doc" ); break;
117 case MM_DOCTYPE_HTML: sExtension = String::CreateFromAscii( "html" ); break;
118 case MM_DOCTYPE_TEXT: sExtension = String::CreateFromAscii( "txt" ); break;
120 return sExtension;
122 /*-- 28.06.2004 11:49:21---------------------------------------------------
124 -----------------------------------------------------------------------*/
125 ::rtl::OUString lcl_GetColumnValueOf(const ::rtl::OUString& rColumn, Reference < container::XNameAccess>& rxColAccess )
127 ::rtl::OUString sRet;
128 if(rxColAccess->hasByName(rColumn))
130 Any aCol = rxColAccess->getByName(rColumn);
131 Reference< sdb::XColumn > xColumn;
132 aCol >>= xColumn;
133 if(xColumn.is())
134 sRet = xColumn->getString();
136 return sRet;
138 /*-- 21.06.2004 14:01:13---------------------------------------------------
140 -----------------------------------------------------------------------*/
141 class SwSaveWarningBox_Impl : public ModalDialog
143 FixedImage aWarningImageIM;
144 FixedInfo aWarningFI;
146 FixedText aFileNameFT;
147 Edit aFileNameED;
149 FixedLine aSeparatorFL;
150 OKButton aOKPB;
151 CancelButton aCancelPB;
153 DECL_LINK( ModifyHdl, Edit*);
154 public:
155 SwSaveWarningBox_Impl(Window* pParent, const String& rFileName);
156 ~SwSaveWarningBox_Impl();
158 String GetFileName() const {return aFileNameED.GetText();}
160 /*-- 02.07.2004 08:54:42---------------------------------------------------
162 -----------------------------------------------------------------------*/
163 class SwSendQueryBox_Impl : public ModalDialog
165 FixedImage aQueryImageIM;
166 FixedInfo aQueryFI;
168 Edit aTextED;
170 FixedLine aSeparatorFL;
171 OKButton aOKPB;
172 CancelButton aCancelPB;
174 bool bIsEmptyAllowed;
175 DECL_LINK( ModifyHdl, Edit*);
176 public:
177 SwSendQueryBox_Impl(Window* pParent, const String& rQueryText);
178 ~SwSendQueryBox_Impl();
180 void SetValue(const String& rSet)
182 aTextED.SetText(rSet);
183 ModifyHdl( &aTextED );
185 String GetValue() const {return aTextED.GetText();}
187 void SetIsEmptyTextAllowed(bool bSet)
189 bIsEmptyAllowed = bSet;
190 ModifyHdl( &aTextED );
194 /*-- 21.06.2004 14:11:58---------------------------------------------------
196 -----------------------------------------------------------------------*/
197 SwSaveWarningBox_Impl::SwSaveWarningBox_Impl(Window* pParent, const String& rFileName) :
198 ModalDialog(pParent, SW_RES( DLG_MM_SAVEWARNING )),
199 aWarningImageIM(this, SW_RES( IM_WARNING )),
200 aWarningFI(this, SW_RES( FI_WARNING )),
201 aFileNameFT(this, SW_RES( FT_FILENAME )),
202 aFileNameED(this, SW_RES( ED_FILENAME )),
203 aSeparatorFL(this, SW_RES( FL_SEPARATOR )),
204 aOKPB(this, SW_RES( PB_OK )),
205 aCancelPB(this, SW_RES( PB_CANCEL ))
207 FreeResource();
208 aWarningImageIM.SetImage(WarningBox::GetStandardImage());
209 aFileNameED.SetText(rFileName);
210 aFileNameED.SetModifyHdl(LINK(this, SwSaveWarningBox_Impl, ModifyHdl));
211 ModifyHdl( &aFileNameED );
213 /*-- 21.06.2004 14:11:58---------------------------------------------------
215 -----------------------------------------------------------------------*/
216 SwSaveWarningBox_Impl::~SwSaveWarningBox_Impl()
219 /*-- 21.06.2004 14:11:58---------------------------------------------------
221 -----------------------------------------------------------------------*/
222 IMPL_LINK( SwSaveWarningBox_Impl, ModifyHdl, Edit*, pEdit)
224 aOKPB.Enable(pEdit->GetText().Len() > 0);
225 return 0;
227 /*-- 02.07.2004 09:02:53---------------------------------------------------
229 -----------------------------------------------------------------------*/
230 SwSendQueryBox_Impl::SwSendQueryBox_Impl(Window* pParent, const String& rText) :
231 ModalDialog(pParent, SW_RES( DLG_MM_QUERY )),
232 aQueryImageIM( this, SW_RES( IM_QUERY )),
233 aQueryFI( this, SW_RES( FI_QUERY )),
234 aTextED( this, SW_RES( ED_TEXT )),
235 aSeparatorFL(this, SW_RES( FL_SEPARATOR )),
236 aOKPB(this, SW_RES( PB_OK )),
237 aCancelPB(this, SW_RES( PB_CANCEL )),
238 bIsEmptyAllowed(true)
240 FreeResource();
241 aQueryFI.SetText(rText);
242 aQueryImageIM.SetImage(QueryBox::GetStandardImage());
243 aTextED.SetModifyHdl(LINK(this, SwSendQueryBox_Impl, ModifyHdl));
244 ModifyHdl( &aTextED );
246 /*-- 02.07.2004 08:58:45---------------------------------------------------
248 -----------------------------------------------------------------------*/
249 SwSendQueryBox_Impl::~SwSendQueryBox_Impl()
252 /*-- 02.07.2004 08:58:25---------------------------------------------------
254 -----------------------------------------------------------------------*/
255 IMPL_LINK( SwSendQueryBox_Impl, ModifyHdl, Edit*, pEdit)
257 aOKPB.Enable(bIsEmptyAllowed || (pEdit->GetText().Len() > 0));
258 return 0;
261 /*-- 16.04.2004 16:34:48---------------------------------------------------
263 -----------------------------------------------------------------------*/
264 class SwCopyToDialog : public SfxModalDialog
266 FixedInfo m_aDescriptionFI;
267 FixedText m_aCCFT;
268 Edit m_aCCED;
269 FixedText m_aBCCFT;
270 Edit m_aBCCED;
272 FixedInfo m_aNoteFI;
273 FixedLine m_aSeparatorFL;
275 OKButton m_aOK;
276 CancelButton m_aCancel;
277 HelpButton m_aHelp;
279 public:
280 SwCopyToDialog(Window* pParent);
281 ~SwCopyToDialog();
283 String GetCC() {return m_aCCED.GetText();}
284 void SetCC(const String& rSet) {m_aCCED.SetText(rSet);}
286 String GetBCC() {return m_aBCCED.GetText();}
287 void SetBCC(const String& rSet) {m_aBCCED.SetText(rSet);}
290 /*-- 16.04.2004 16:43:18---------------------------------------------------
292 -----------------------------------------------------------------------*/
293 SwCopyToDialog::SwCopyToDialog(Window* pParent) :
294 SfxModalDialog(pParent, SW_RES(DLG_MM_COPYTO)),
295 #ifdef MSC
296 #pragma warning (disable : 4355)
297 #endif
298 m_aDescriptionFI( this, SW_RES( FI_DESCRIPTION )),
299 m_aCCFT( this, SW_RES( FT_CC )),
300 m_aCCED( this, SW_RES( ED_CC )),
301 m_aBCCFT( this, SW_RES( FT_BCC )),
302 m_aBCCED( this, SW_RES( ED_BCC )),
303 m_aNoteFI( this, SW_RES( FI_NOTE )),
304 m_aSeparatorFL( this, SW_RES( FL_SEPARATOR )),
305 m_aOK( this, SW_RES( PB_OK )),
306 m_aCancel( this, SW_RES( PB_CANCEL )),
307 m_aHelp( this, SW_RES( PB_HELP ))
308 #ifdef MSC
309 #pragma warning (default : 4355)
310 #endif
312 FreeResource();
314 /*-- 16.04.2004 16:43:10---------------------------------------------------
316 -----------------------------------------------------------------------*/
317 SwCopyToDialog::~SwCopyToDialog()
321 /*-- 02.04.2004 13:15:54---------------------------------------------------
323 -----------------------------------------------------------------------*/
324 SwMailMergeOutputPage::SwMailMergeOutputPage( SwMailMergeWizard* _pParent) :
325 svt::OWizardPage( _pParent, SW_RES(DLG_MM_OUTPUT_PAGE)),
326 #ifdef MSC
327 #pragma warning (disable : 4355)
328 #endif
329 m_aHeaderFI(this, SW_RES( FI_HEADER ) ),
330 m_aOptionsFI(this, SW_RES( FI_OPTIONS ) ),
331 m_aSaveStartDocRB(this, SW_RES( RB_SAVESTARTDOC ) ),
332 m_aSaveMergedDocRB(this, SW_RES( RB_SAVEMERGEDDOC ) ),
333 m_aPrintRB(this, SW_RES( RB_PRINT ) ),
334 m_aSendMailRB(this, SW_RES( RB_SENDMAIL ) ),
336 m_aSeparatorFL(this, SW_RES( FL_SEPARATOR ) ),
338 m_aSaveStartDocPB(this, SW_RES( PB_SAVESTARTDOC ) ),
340 m_aSaveAsOneRB(this, SW_RES( RB_SAVEASONE ) ),
341 m_aSaveIndividualRB(this, SW_RES( RB_SAVEINDIVIDUAL ) ),
342 m_aPrintAllRB(this, SW_RES( RB_PRINTALL ) ),
343 m_aSendAllRB( this, SW_RES( RB_SENDALL ) ),
345 m_aFromRB(this, SW_RES( RB_FROM ) ),
346 m_aFromNF(this, SW_RES( NF_FROM ) ),
347 m_aToFT(this, SW_RES( FT_TO ) ),
348 m_aToNF(this, SW_RES( NF_TO ) ),
349 m_aSaveNowPB(this, SW_RES( PB_SAVENOW ) ),
351 m_aPrinterFT(this, SW_RES( FT_PRINT ) ),
352 m_aPrinterLB(this, SW_RES( LB_PRINT ) ),
353 m_aPrinterSettingsPB(this, SW_RES( PB_PRINTERSETTINGS ) ),
354 m_aPrintNowPB(this, SW_RES( PB_PRINTNOW ) ),
356 m_aMailToFT( this, SW_RES( FT_MAILTO ) ),
357 m_aMailToLB( this, SW_RES( LB_MAILTO ) ),
358 m_aCopyToPB( this, SW_RES( PB_COPYTO ) ),
359 m_aSubjectFT( this, SW_RES( FT_SUBJECT ) ),
360 m_aSubjectED( this, SW_RES( ED_SUBJECT ) ),
361 m_aSendAsFT( this, SW_RES( FT_SENDAS ) ),
362 m_aSendAsLB( this, SW_RES( LB_SENDAS ) ),
363 m_aAttachmentFT( this, SW_RES( FT_ATTACHMENT ) ),
364 m_aAttachmentED( this, SW_RES( ED_ATTACHMENT ) ),
365 m_aSendAsPB( this, SW_RES( PB_SENDAS ) ),
366 m_aSendDocumentsPB( this, SW_RES( PB_SENDDOCUMENTS ) ),
368 m_sSaveStartST(SW_RES( ST_SAVESTART ) ),
369 m_sSaveMergedST(SW_RES( ST_SAVEMERGED ) ),
370 m_sPrintST(SW_RES( ST_PRINT ) ),
371 m_sSendMailST(SW_RES( ST_SENDMAIL ) ),
373 m_sDefaultAttachmentST(SW_RES( ST_DEFAULTATTACHMENT )),
374 m_sNoSubjectQueryST(SW_RES( ST_SUBJECTQUERY )),
375 m_sNoSubjectST(SW_RES( ST_NOSUBJECT )),
376 m_sNoAttachmentNameST(SW_RES( ST_NOATTACHMENTNAME )),
377 m_sConfigureMail(SW_RES( ST_CONFIGUREMAIL)),
378 #ifdef MSC
379 #pragma warning (default : 4355)
380 #endif
381 m_bCancelSaving( false ),
382 m_pWizard(_pParent),
383 m_pTempPrinter( 0 ),
384 m_pDocumentPrinterCopy(0)
386 FreeResource();
388 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
389 // #i51949# hide e-Mail option if e-Mail is not supported
390 if(!rConfigItem.IsMailAvailable())
391 m_aSendMailRB.Hide();
393 Link aLink = LINK(this, SwMailMergeOutputPage, OutputTypeHdl_Impl);
394 m_aSaveStartDocRB.SetClickHdl(aLink);
395 m_aSaveMergedDocRB.SetClickHdl(aLink);
396 m_aPrintRB.SetClickHdl(aLink);
397 m_aSendMailRB.SetClickHdl(aLink);
398 m_aSaveStartDocRB.Check();
399 m_aPrintAllRB.Check();
400 m_aSaveAsOneRB.Check();
401 m_aSendAllRB.Check();
403 m_aSaveStartDocPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, SaveStartHdl_Impl));
404 m_aSaveNowPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, SaveOutputHdl_Impl));
405 m_aPrinterLB.SetSelectHdl(LINK(this, SwMailMergeOutputPage, PrinterChangeHdl_Impl));
406 m_aPrintNowPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, PrintHdl_Impl));
407 m_aPrinterSettingsPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, PrinterSetupHdl_Impl));
409 m_aSendAsPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, SendAsHdl_Impl)),
410 m_aSendDocumentsPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, SendDocumentsHdl_Impl)),
411 m_aSendAsLB.SetSelectHdl(LINK(this, SwMailMergeOutputPage, SendTypeHdl_Impl));
413 m_nFromToRBPos = m_aFromRB.GetPosPixel().Y();
414 m_nFromToFTPos = m_aToFT.GetPosPixel().Y();
415 m_nFromToNFPos = m_aFromNF.GetPosPixel().Y();
417 m_nRBOffset = m_nFromToRBPos - m_aSaveIndividualRB.GetPosPixel().Y();
419 OutputTypeHdl_Impl(&m_aSaveStartDocRB);
421 m_aCopyToPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, CopyToHdl_Impl));
423 m_aSaveAsOneRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
424 m_aSaveIndividualRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
425 m_aPrintAllRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
426 m_aSendAllRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
428 m_aFromRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
431 /*-- 02.04.2004 13:15:44---------------------------------------------------
433 -----------------------------------------------------------------------*/
434 SwMailMergeOutputPage::~SwMailMergeOutputPage()
436 delete m_pTempPrinter;
437 delete m_pDocumentPrinterCopy;
439 /*-- 31.01.2005 08:38:14---------------------------------------------------
441 -----------------------------------------------------------------------*/
442 void SwMailMergeOutputPage::ActivatePage()
444 //fill printer ListBox
445 const std::vector<rtl::OUString>& rPrinters = Printer::GetPrinterQueues();
446 unsigned int nCount = rPrinters.size();
447 if ( nCount )
449 for( unsigned int i = 0; i < nCount; i++ )
451 m_aPrinterLB.InsertEntry( rPrinters[i] );
455 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
457 SwView* pTargetView = rConfigItem.GetTargetView();
458 DBG_ASSERT(pTargetView, "no target view exists");
459 if(pTargetView)
461 SfxPrinter* pPrinter = pTargetView->GetWrtShell().getIDocumentDeviceAccess()->getPrinter( true );
462 m_aPrinterLB.SelectEntry( pPrinter->GetName() );
463 m_aToNF.SetValue( rConfigItem.GetMergedDocumentCount() );
464 m_aToNF.SetMax( rConfigItem.GetMergedDocumentCount() );
465 m_pDocumentPrinterCopy = pTargetView->GetWrtShell().getIDocumentDeviceAccess()->getPrinter( true )->Clone();
467 m_aPrinterLB.SelectEntry( rConfigItem.GetSelectedPrinter() );
469 SwView* pSourceView = rConfigItem.GetSourceView();
470 DBG_ASSERT(pSourceView, "no source view exists");
471 if(pSourceView)
473 SwDocShell* pDocShell = pSourceView->GetDocShell();
474 if ( pDocShell->HasName() )
476 INetURLObject aTmp( pDocShell->GetMedium()->GetName() );
477 m_aAttachmentED.SetText(aTmp.getName(
478 INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ));
482 /*-- 05.07.2004 13:54:11---------------------------------------------------
484 -----------------------------------------------------------------------*/
485 bool SwMailMergeOutputPage::canAdvance() const
487 return false;
489 /*-- 02.04.2004 13:15:44---------------------------------------------------
491 -----------------------------------------------------------------------*/
492 IMPL_LINK(SwMailMergeOutputPage, OutputTypeHdl_Impl, RadioButton*, pButton)
494 Control* aControls[] =
496 &m_aSaveStartDocPB,
497 &m_aSaveAsOneRB, &m_aSaveIndividualRB,
498 &m_aFromRB, &m_aFromNF, &m_aToFT, &m_aToNF,
499 &m_aSaveNowPB,
500 &m_aPrinterFT, &m_aPrinterLB, &m_aPrinterSettingsPB, &m_aPrintAllRB,
501 &m_aPrintNowPB,
502 &m_aMailToFT, &m_aMailToLB, &m_aCopyToPB,
503 &m_aSubjectFT, &m_aSubjectED,
504 &m_aSendAsFT, &m_aSendAsLB, &m_aSendAsPB,
505 &m_aAttachmentFT, &m_aAttachmentED,
506 &m_aSendAllRB, &m_aSendDocumentsPB,
509 SetUpdateMode(TRUE);
510 Control** pControl = aControls;
513 (*pControl)->Show(sal_False);
515 } while(*(++pControl));
517 if(&m_aSaveStartDocRB == pButton)
519 m_aSaveStartDocPB.Show();
520 m_aSeparatorFL.SetText(m_sSaveStartST);
523 else if(&m_aSaveMergedDocRB == pButton)
525 Control* aSaveMergedControls[] =
527 &m_aSaveAsOneRB, &m_aSaveIndividualRB,
528 &m_aFromRB, &m_aFromNF, &m_aToFT, &m_aToNF,
529 &m_aSaveNowPB,
532 Control** pSaveMergeControl = aSaveMergedControls;
535 (*pSaveMergeControl)->Show(sal_True);
537 } while(*(++pSaveMergeControl));
538 if(!m_aFromRB.IsChecked() && !m_aSaveAsOneRB.IsChecked())
540 m_aSaveIndividualRB.Check();
542 m_aSeparatorFL.SetText(m_sSaveMergedST);
543 //reposition the from/to line
544 if(m_aFromRB.GetPosPixel().Y() != m_nFromToRBPos)
546 Point aPos(m_aFromRB.GetPosPixel()); aPos.Y() = m_nFromToRBPos; m_aFromRB.SetPosPixel(aPos);
547 aPos = m_aToFT.GetPosPixel(); aPos.Y() = m_nFromToFTPos; m_aToFT.SetPosPixel(aPos);
548 aPos = m_aFromNF.GetPosPixel(); aPos.Y() = m_nFromToNFPos; m_aFromNF.SetPosPixel(aPos);
549 aPos = m_aToNF.GetPosPixel(); aPos.Y() = m_nFromToNFPos; m_aToNF.SetPosPixel(aPos);
552 else if(&m_aPrintRB == pButton)
554 Control* aPrintControls[] =
556 &m_aFromRB, &m_aFromNF, &m_aToFT, &m_aToNF,
557 &m_aPrinterFT, &m_aPrinterLB, &m_aPrinterSettingsPB, &m_aPrintAllRB,
558 &m_aPrintNowPB,
561 Control** pPrinterControl = aPrintControls;
564 (*pPrinterControl)->Show(sal_True);
566 } while(*(++pPrinterControl));
567 if(!m_aFromRB.IsChecked())
568 m_aPrintAllRB.Check();
570 m_aSeparatorFL.SetText(m_sPrintST);
571 //reposition the from/to line
572 long nRB_FT_Offset = m_nFromToRBPos - m_nFromToFTPos;
573 long nNewRBXPos = m_aPrintAllRB.GetPosPixel().Y() + m_nRBOffset;
575 Point aPos(m_aFromRB.GetPosPixel());aPos.Y() = nNewRBXPos; m_aFromRB.SetPosPixel(aPos);
576 aPos = m_aToFT.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aToFT.SetPosPixel(aPos);
577 aPos = m_aFromNF.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aFromNF.SetPosPixel(aPos);
578 aPos = m_aToNF.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aToNF.SetPosPixel(aPos);
580 else /*if(&m_aSendMailRB == pButton)*/
582 Control* aMailControls[] =
584 &m_aFromRB, &m_aFromNF, &m_aToFT, &m_aToNF,
585 &m_aMailToFT, &m_aMailToLB, &m_aCopyToPB,
586 &m_aSubjectFT, &m_aSubjectED,
587 &m_aSendAsFT, &m_aSendAsLB, &m_aSendAsPB,
588 &m_aAttachmentFT, &m_aAttachmentED,
589 &m_aSendAllRB, &m_aSendDocumentsPB, 0
591 Control** pMailControl = aMailControls;
594 (*pMailControl)->Show(sal_True);
596 } while(*(++pMailControl));
598 if(!m_aFromRB.IsChecked())
599 m_aSendAllRB.Check();
600 if(!m_aAttachmentED.GetText().Len())
602 String sAttach( m_sDefaultAttachmentST );
603 sAttach += '.';
604 sAttach += lcl_GetExtensionForDocType(
605 (ULONG)m_aSendAsLB.GetEntryData(m_aSendAsLB.GetSelectEntryPos()));
606 m_aAttachmentED.SetText( sAttach );
609 m_aSeparatorFL.SetText(m_sSendMailST);
610 //fill mail address ListBox
611 if(!m_aMailToLB.GetEntryCount())
613 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
614 //select first column
615 uno::Reference< sdbcx::XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), uno::UNO_QUERY);
616 //get the name of the actual columns
617 uno::Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
618 uno::Sequence< ::rtl::OUString > aFields;
619 if(xColAccess.is())
620 aFields = xColAccess->getElementNames();
621 const ::rtl::OUString* pFields = aFields.getConstArray();
622 for(sal_Int32 nField = 0; nField < aFields.getLength(); ++nField)
623 m_aMailToLB.InsertEntry(pFields[nField]);
625 m_aMailToLB.SelectEntryPos(0);
626 // then select the right one - may not be available
627 const ResStringArray& rHeaders = rConfigItem.GetDefaultAddressHeaders();
628 String sEMailColumn = rHeaders.GetString( MM_PART_E_MAIL );
629 Sequence< ::rtl::OUString> aAssignment =
630 rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
631 if(aAssignment.getLength() > MM_PART_E_MAIL && aAssignment[MM_PART_E_MAIL].getLength())
632 sEMailColumn = aAssignment[MM_PART_E_MAIL];
633 m_aMailToLB.SelectEntry(sEMailColumn);
634 // HTML format pre-selected
635 m_aSendAsLB.SelectEntryPos(3);
636 SendTypeHdl_Impl(&m_aSendAsLB);
638 if(m_aSendAllRB.GetPosPixel().Y() + m_nRBOffset != m_aFromRB.GetPosPixel().Y())
640 long nRB_FT_Offset = m_nFromToRBPos - m_nFromToFTPos;
641 long nNewRBXPos = m_aSendAllRB.GetPosPixel().Y() + m_nRBOffset;
643 Point aPos(m_aFromRB.GetPosPixel());aPos.Y() = nNewRBXPos; m_aFromRB.SetPosPixel(aPos);
644 aPos = m_aToFT.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aToFT.SetPosPixel(aPos);
645 aPos = m_aFromNF.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aFromNF.SetPosPixel(aPos);
646 aPos = m_aToNF.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aToNF.SetPosPixel(aPos);
649 m_aFromRB.GetClickHdl().Call(m_aFromRB.IsChecked() ? &m_aFromRB : 0);
651 SetUpdateMode(FALSE);
652 return 0;
654 /*-- 22.08.2005 12:15:10---------------------------------------------------
656 -----------------------------------------------------------------------*/
657 IMPL_LINK(SwMailMergeOutputPage, DocumentSelectionHdl_Impl, RadioButton*, pButton)
659 sal_Bool bEnableFromTo = pButton == &m_aFromRB;
660 m_aFromNF.Enable(bEnableFromTo);
661 m_aToFT.Enable(bEnableFromTo);
662 m_aToNF.Enable(bEnableFromTo);
663 return 0;
666 /*-- 16.04.2004 16:45:10---------------------------------------------------
668 -----------------------------------------------------------------------*/
669 IMPL_LINK(SwMailMergeOutputPage, CopyToHdl_Impl, PushButton*, pButton)
671 SwCopyToDialog* pDlg = new SwCopyToDialog(pButton);
672 pDlg->SetCC(m_sCC );
673 pDlg->SetBCC(m_sBCC);
674 if(RET_OK == pDlg->Execute())
676 m_sCC = pDlg->GetCC() ;
677 m_sBCC = pDlg->GetBCC();
679 delete pDlg;
680 return 0;
682 /*-- 17.05.2004 13:51:02---------------------------------------------------
684 -----------------------------------------------------------------------*/
685 IMPL_LINK(SwMailMergeOutputPage, SaveStartHdl_Impl, PushButton*, pButton)
687 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
688 SwView* pSourceView = rConfigItem.GetSourceView();
689 DBG_ASSERT( pSourceView, "source view missing");
690 if(pSourceView)
692 SfxViewFrame* pSourceViewFrm = pSourceView->GetViewFrame();
693 uno::Reference< frame::XFrame > xFrame =
694 pSourceViewFrm->GetFrame()->GetFrameInterface();
695 xFrame->getContainerWindow()->setVisible(sal_True);
696 pSourceViewFrm->GetDispatcher()->Execute(SID_SAVEDOC, SFX_CALLMODE_SYNCHRON);
697 xFrame->getContainerWindow()->setVisible(sal_False);
698 SwDocShell* pDocShell = pSourceView->GetDocShell();
699 //if the document has been saved it's URL has to be stored for
700 // later use and it can be closed now
701 if(pDocShell->HasName() && !pDocShell->IsModified())
703 INetURLObject aURL = pDocShell->GetMedium()->GetURLObject();
704 //update the attachment name
705 if(!m_aAttachmentED.GetText().Len())
707 if ( pDocShell->HasName() )
709 m_aAttachmentED.SetText(aURL.getName(
710 INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ));
714 rConfigItem.AddSavedDocument(
715 aURL.GetMainURL(INetURLObject::DECODE_TO_IURI));
716 pButton->Enable(FALSE);
717 m_pWizard->enableButtons(WZB_FINISH, sal_True);
718 pButton->Enable(FALSE);
722 return 0;
724 /*-- 17.07.2008 08:09:06---------------------------------------------------
726 -----------------------------------------------------------------------*/
727 IMPL_LINK(SwMailMergeOutputPage, SaveCancelHdl_Impl, Button*, EMPTYARG )
729 m_bCancelSaving = true;
730 return 0;
732 /*-- 17.05.2004 13:51:02---------------------------------------------------
734 -----------------------------------------------------------------------*/
735 IMPL_LINK(SwMailMergeOutputPage, SaveOutputHdl_Impl, PushButton*, pButton)
737 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
738 SwView* pTargetView = rConfigItem.GetTargetView();
739 DBG_ASSERT(pTargetView, "no target view exists");
740 if(!pTargetView)
741 return 0;
743 if(m_aSaveAsOneRB.IsChecked())
745 String sFilter;
746 String sPath = SwMailMergeHelper::CallSaveAsDialog(sFilter);
747 if(!sPath.Len())
748 return 0;
749 uno::Sequence< beans::PropertyValue > aValues(1);
750 beans::PropertyValue* pValues = aValues.getArray();
751 pValues[0].Name = C2U("FilterName");
752 pValues[0].Value <<= ::rtl::OUString(sFilter);
754 uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
755 xStore->storeToURL( sPath, aValues );
757 else
759 sal_uInt32 nBegin = 0;
760 sal_uInt32 nEnd = 0;
761 if(m_aSaveIndividualRB.IsChecked())
763 nBegin = 0;
764 nEnd = rConfigItem.GetMergedDocumentCount();
766 else
768 nBegin = static_cast< sal_Int32 >(m_aFromNF.GetValue() - 1);
769 nEnd = static_cast< sal_Int32 >(m_aToNF.GetValue());
770 if(nEnd > rConfigItem.GetMergedDocumentCount())
771 nEnd = rConfigItem.GetMergedDocumentCount();
773 String sFilter;
774 String sPath = SwMailMergeHelper::CallSaveAsDialog(sFilter);
775 if(!sPath.Len())
776 return 0;
777 String sTargetTempURL = URIHelper::SmartRel2Abs(
778 INetURLObject(), utl::TempFile::CreateTempName(),
779 URIHelper::GetMaybeFileHdl());
780 const SfxFilter *pSfxFlt = SwIoSystem::GetFilterOfFormat(
781 String::CreateFromAscii( FILTER_XML ),
782 SwDocShell::Factory().GetFilterContainer() );
784 uno::Sequence< beans::PropertyValue > aValues(1);
785 beans::PropertyValue* pValues = aValues.getArray();
786 pValues[0].Name = C2U("FilterName");
787 pValues[0].Value <<= ::rtl::OUString(pSfxFlt->GetFilterName());
789 uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
790 xStore->storeToURL( sTargetTempURL, aValues );
792 SwView* pSourceView = rConfigItem.GetSourceView();
793 PrintMonitor aSaveMonitor(this, PrintMonitor::MONITOR_TYPE_SAVE);
794 aSaveMonitor.aDocName.SetText(pSourceView->GetDocShell()->GetTitle(22));
795 aSaveMonitor.aCancel.SetClickHdl(LINK(this, SwMailMergeOutputPage, SaveCancelHdl_Impl));
796 aSaveMonitor.aPrinter.SetText( INetURLObject( sPath ).getFSysPath( INetURLObject::FSYS_DETECT ) );
797 aSaveMonitor.ResizeControls();
799 m_bCancelSaving = false;
800 aSaveMonitor.Show();
801 m_pWizard->enableButtons(WZB_CANCEL, sal_False);
803 for(sal_uInt32 nDoc = nBegin; nDoc < nEnd && !m_bCancelSaving; ++nDoc)
805 SwDocMergeInfo& rInfo = rConfigItem.GetDocumentMergeInfo(nDoc);
806 INetURLObject aURL(sPath);
807 String sFile = aURL.GetBase();
808 String sExtension = aURL.getExtension();
809 if(!sExtension.Len())
811 sExtension = pSfxFlt->GetWildcard()().GetToken(1, '.');
812 sPath += '.';
813 sPath += sExtension;
815 String sStat(SW_RES(STR_STATSTR_LETTER));
816 sStat += ' ';
817 sStat += String::CreateFromInt32( nDoc );
818 aSaveMonitor.aPrintInfo.SetText(sStat);
820 //now extract a document from the target document
821 SfxObjectShellRef xTempDocShell( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
822 xTempDocShell->DoInitNew( 0 );
823 SfxViewFrame* pTempFrame = SfxViewFrame::CreateViewFrame( *xTempDocShell, 0, TRUE );
824 // pTempFrame->GetFrame()->Appear();
825 SwView* pTempView = static_cast<SwView*>( pTempFrame->GetViewShell() );
826 pTargetView->GetWrtShell().StartAction();
827 SwgReaderOption aOpt;
828 aOpt.SetTxtFmts( sal_True );
829 aOpt.SetFrmFmts( sal_True );
830 aOpt.SetPageDescs( sal_True );
831 aOpt.SetNumRules( sal_True );
832 aOpt.SetMerge( sal_False );
833 pTempView->GetDocShell()->LoadStylesFromFile(
834 sTargetTempURL, aOpt, sal_True );
836 pTargetView->GetWrtShell().PastePages(pTempView->GetWrtShell(),
837 (USHORT)rInfo.nStartPageInTarget, (USHORT)rInfo.nEndPageInTarget );
838 pTargetView->GetWrtShell().EndAction();
839 //then save it
840 String sOutPath = aURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
841 String sCounter('_');
842 sCounter += String::CreateFromInt32(nDoc);
843 sOutPath.Insert(sCounter, sOutPath.Len() - sExtension.Len() - 1);
844 //SfxStringItem aName(SID_FILE_NAME, sOutPath);
845 //SfxStringItem aFilter(SID_FILTER_NAME, sFilter);
847 while(true)
849 //time for other slots is needed
850 for(sal_Int16 r = 0; r < 10; ++r)
851 Application::Reschedule();
852 bool bFailed = false;
855 pValues[0].Value <<= ::rtl::OUString(sFilter);
856 uno::Reference< frame::XStorable > xTempStore( xTempDocShell->GetModel(), uno::UNO_QUERY);
857 xTempStore->storeToURL( sOutPath, aValues );
859 catch( const uno::Exception& )
861 bFailed = true;
864 if(bFailed)
866 SwSaveWarningBox_Impl aWarning( pButton, sOutPath );
867 if(RET_OK == aWarning.Execute())
868 sOutPath = aWarning.GetFileName();
869 else
871 xTempDocShell->DoClose();
872 return 0;
875 else
877 xTempDocShell->DoClose();
878 break;
882 ::osl::File::remove( sTargetTempURL );
884 m_pWizard->enableButtons(WZB_CANCEL, sal_True);
885 m_pWizard->enableButtons(WZB_FINISH, sal_True);
886 return 0;
888 /*-- 22.06.2004 11:51:30---------------------------------------------------
890 -----------------------------------------------------------------------*/
891 IMPL_LINK(SwMailMergeOutputPage, PrinterChangeHdl_Impl, ListBox*, pBox)
893 if( m_pDocumentPrinterCopy && pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
895 const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), false );
897 if( pInfo )
899 if ( !m_pTempPrinter )
901 if( (m_pDocumentPrinterCopy->GetName() == pInfo->GetPrinterName()) &&
902 (m_pDocumentPrinterCopy->GetDriverName() == pInfo->GetDriver()) )
903 m_pTempPrinter = new Printer( m_pDocumentPrinterCopy->GetJobSetup() );
904 else
905 m_pTempPrinter = new Printer( *pInfo );
907 else
909 if( (m_pTempPrinter->GetName() != pInfo->GetPrinterName()) ||
910 (m_pTempPrinter->GetDriverName() != pInfo->GetDriver()) )
912 delete m_pTempPrinter;
913 m_pTempPrinter = new Printer( *pInfo );
917 else if( ! m_pTempPrinter )
918 m_pTempPrinter = new Printer();
920 m_aPrinterSettingsPB.Enable( m_pTempPrinter->HasSupport( SUPPORT_SETUPDIALOG ) );
922 else
923 m_aPrinterSettingsPB.Disable();
924 m_pWizard->GetConfigItem().SetSelectedPrinter( pBox->GetSelectEntry() );
926 // return m_pTempPrinter;
927 return 0;
930 /*-- 17.05.2004 13:51:02---------------------------------------------------
932 -----------------------------------------------------------------------*/
933 IMPL_LINK(SwMailMergeOutputPage, PrintHdl_Impl, PushButton*, EMPTYARG)
935 SwView* pTargetView = m_pWizard->GetConfigItem().GetTargetView();
936 DBG_ASSERT(pTargetView, "no target view exists");
937 if(!pTargetView)
938 return 0;
940 sal_uInt32 nBegin = 0;
941 sal_uInt32 nEnd = 0;
942 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
943 if(m_aPrintAllRB.IsChecked())
945 nBegin = 0;
946 nEnd = rConfigItem.GetMergedDocumentCount();
948 else
950 nBegin = static_cast< sal_Int32 >(m_aFromNF.GetValue() - 1);
951 nEnd = static_cast< sal_Int32 >(m_aToNF.GetValue());
952 if(nEnd > rConfigItem.GetMergedDocumentCount())
953 nEnd = rConfigItem.GetMergedDocumentCount();
955 rConfigItem.SetPrintRange( (USHORT)nBegin, (USHORT)nEnd );
956 SwWrtShell& rSh = pTargetView->GetWrtShell();
957 pTargetView->SetMailMergeConfigItem(&rConfigItem, 0, sal_False);
958 if(m_pTempPrinter)
960 m_pDocumentPrinterCopy->SetPrinterProps(m_pTempPrinter);
961 pTargetView->SetPrinter(m_pDocumentPrinterCopy->Clone());
964 SfxObjectShell* pObjSh = pTargetView->GetViewFrame()->GetObjectShell();
965 SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE, pObjSh));
966 rSh.GetNewDBMgr()->SetMergeType( DBMGR_MERGE_DOCUMENTS );
967 SfxDispatcher *pDis = pTargetView->GetViewFrame()->GetDispatcher();
968 SfxBoolItem aMergeSilent(SID_SILENT, sal_False);
969 m_pWizard->enableButtons(WZB_CANCEL, sal_False);
970 pDis->Execute(SID_PRINTDOCDIRECT,
971 SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD, &aMergeSilent, 0L);
972 SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE_END, pObjSh));
974 pTargetView->SetMailMergeConfigItem(0, 0, sal_False);
975 m_pWizard->enableButtons(WZB_CANCEL, sal_True);
976 m_pWizard->enableButtons(WZB_FINISH, sal_True);
977 return 0;
979 /*-- 17.05.2004 13:51:02---------------------------------------------------
981 -----------------------------------------------------------------------*/
982 IMPL_LINK(SwMailMergeOutputPage, PrinterSetupHdl_Impl, PushButton*, pButton)
984 if( !m_pTempPrinter )
985 PrinterChangeHdl_Impl(&m_aPrinterLB);
986 if(m_pTempPrinter)
987 m_pTempPrinter->Setup(pButton);
988 return 0;
990 /*-- 14.06.2004 09:34:01---------------------------------------------------
992 -----------------------------------------------------------------------*/
993 IMPL_LINK(SwMailMergeOutputPage, SendTypeHdl_Impl, ListBox*, pBox)
995 ULONG nDocType = (ULONG)pBox->GetEntryData(pBox->GetSelectEntryPos());
996 sal_Bool bEnable = MM_DOCTYPE_HTML != nDocType && MM_DOCTYPE_TEXT != nDocType;
997 m_aSendAsPB.Enable( bEnable );
998 m_aAttachmentFT.Enable( bEnable );
999 m_aAttachmentED.Enable( bEnable );
1000 if(bEnable)
1002 //add the correct extension
1003 String sAttach(m_aAttachmentED.GetText());
1004 //do nothing if the user has removed the name - the warning will come early enough
1005 if(sAttach.Len())
1007 xub_StrLen nTokenCount = sAttach.GetTokenCount( '.' );
1008 if( 2 > nTokenCount)
1010 sAttach += '.';
1011 ++nTokenCount;
1013 sAttach.SetToken( nTokenCount - 1, '.', lcl_GetExtensionForDocType( nDocType ));
1014 m_aAttachmentED.SetText(sAttach);
1017 return 0;
1019 /*-- 17.05.2004 13:51:02---------------------------------------------------
1021 -----------------------------------------------------------------------*/
1022 IMPL_LINK(SwMailMergeOutputPage, SendAsHdl_Impl, PushButton*, pButton)
1024 SwMailBodyDialog* pDlg = new SwMailBodyDialog(pButton, m_pWizard);
1025 pDlg->SetBody(m_sBody);
1026 if(RET_OK == pDlg->Execute())
1028 m_sBody = pDlg->GetBody();
1030 return 0;
1032 /*-- 21.05.2004 12:03:25---------------------------------------------------
1033 Send documents as e-mail
1034 -----------------------------------------------------------------------*/
1035 IMPL_LINK(SwMailMergeOutputPage, SendDocumentsHdl_Impl, PushButton*, pButton)
1037 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
1039 //get the composed document
1040 SwView* pTargetView = rConfigItem.GetTargetView();
1041 DBG_ASSERT(pTargetView, "no target view exists");
1042 if(!pTargetView)
1043 return 0;
1045 if(!rConfigItem.GetMailServer().getLength() ||
1046 !SwMailMergeHelper::CheckMailAddress(rConfigItem.GetMailAddress()) )
1048 QueryBox aQuery(pButton, WB_YES_NO_CANCEL, m_sConfigureMail);
1049 USHORT nRet = aQuery.Execute();
1050 if(RET_YES == nRet )
1052 SfxAllItemSet aSet(pTargetView->GetPool());
1053 SwMailConfigDlg* pDlg = new SwMailConfigDlg(pButton, aSet);
1054 nRet = pDlg->Execute();
1055 delete pDlg;
1058 if(nRet != RET_OK && nRet != RET_YES)
1059 return 0;
1061 //create the send dialog
1062 SwSendMailDialog* pDlg = new SwSendMailDialog( pButton, rConfigItem );
1063 //add the documents
1064 sal_uInt32 nBegin = 0;
1065 sal_uInt32 nEnd = 0;
1066 if(m_aSendAllRB.IsChecked())
1068 nBegin = 0;
1069 nEnd = rConfigItem.GetMergedDocumentCount();
1071 else
1073 nBegin = static_cast< sal_Int32 >(m_aFromNF.GetValue() - 1);
1074 nEnd = static_cast< sal_Int32 >(m_aToNF.GetValue());
1075 if(nEnd > rConfigItem.GetMergedDocumentCount())
1076 nEnd = rConfigItem.GetMergedDocumentCount();
1078 bool bAsBody = false;
1079 bool bIsPDF = false;
1080 rtl_TextEncoding eEncoding = ::gsl_getSystemTextEncoding();
1081 SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer();
1082 const SfxFilter *pSfxFlt = 0;
1083 ULONG nDocType = (ULONG)m_aSendAsLB.GetEntryData(m_aSendAsLB.GetSelectEntryPos());
1084 String sExtension = lcl_GetExtensionForDocType(nDocType);
1085 switch( nDocType )
1087 case MM_DOCTYPE_OOO : break;
1088 case MM_DOCTYPE_PDF : bIsPDF = true; break;
1089 case MM_DOCTYPE_WORD:
1091 //the method SwIOSystemGetFilterOfFormat( ) returns the template filter
1092 //because it uses the same user data :-(
1093 SfxFilterMatcher aMatcher( pFilterContainer->GetName() );
1094 SfxFilterMatcherIter aIter( &aMatcher );
1095 const SfxFilter* pFilter = aIter.First();
1096 String sFilterUserData( String::CreateFromAscii( FILTER_WW8 ));
1097 while ( pFilter )
1099 if( pFilter->GetUserData() == sFilterUserData && pFilter->CanExport() )
1101 pSfxFlt = pFilter;
1102 break;
1104 pFilter = aIter.Next();
1108 break;
1109 case MM_DOCTYPE_HTML:
1111 bAsBody = true;
1112 SvxHtmlOptions* pHtmlOptions = SvxHtmlOptions::Get();
1113 eEncoding = pHtmlOptions->GetTextEncoding();
1115 break;
1116 case MM_DOCTYPE_TEXT:
1117 bAsBody = true;
1118 break;
1120 if(!pSfxFlt)
1121 pSfxFlt = pFilterContainer->GetFilter4Extension(sExtension, SFX_FILTER_EXPORT);
1123 if(!pSfxFlt)
1124 return 0;
1125 String sMimeType = pSfxFlt->GetMimeType();
1127 if(!m_aSubjectED.GetText().Len())
1129 SwSendQueryBox_Impl aQuery(pButton, m_sNoSubjectQueryST);
1130 aQuery.SetIsEmptyTextAllowed(true);
1131 aQuery.SetValue(m_sNoSubjectST);
1132 if(RET_OK == aQuery.Execute())
1134 if(aQuery.GetValue() != m_sNoSubjectST)
1135 m_aSubjectED.SetText(aQuery.GetValue());
1137 else
1138 return 0;
1140 if(!bAsBody && !m_aAttachmentED.GetText().Len())
1142 SwSendQueryBox_Impl aQuery(pButton, m_sNoAttachmentNameST);
1143 aQuery.SetIsEmptyTextAllowed(false);
1144 if(RET_OK == aQuery.Execute())
1146 String sAttach(aQuery.GetValue());
1147 xub_StrLen nTokenCount = sAttach.GetTokenCount( '.' );
1148 if( 2 > nTokenCount)
1150 sAttach += '.';
1151 ++nTokenCount;
1153 sAttach.SetToken( nTokenCount - 1, '.', lcl_GetExtensionForDocType(
1154 (ULONG)m_aSendAsLB.GetEntryData(m_aSendAsLB.GetSelectEntryPos())));
1155 m_aAttachmentED.SetText(sAttach);
1157 else
1158 return 0;
1160 SfxStringItem aFilterName( SID_FILTER_NAME, pSfxFlt->GetFilterName() );
1161 String sEMailColumn = m_aMailToLB.GetSelectEntry();
1162 DBG_ASSERT( sEMailColumn.Len(), "No email column selected");
1163 Reference< sdbcx::XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
1164 Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
1165 if(!sEMailColumn.Len() || !xColAccess.is() || !xColAccess->hasByName(sEMailColumn))
1166 return 0;
1168 String sFilterOptions;
1169 if(MM_DOCTYPE_TEXT == nDocType)
1171 SwAsciiOptions aOpt;
1172 USHORT nAppScriptType = GetI18NScriptTypeOfLanguage( (USHORT)GetAppLanguage() );
1173 USHORT nWhich = GetWhichOfScript( RES_CHRATR_LANGUAGE, nAppScriptType);
1174 aOpt.SetLanguage( ((SvxLanguageItem&)pTargetView->GetWrtShell().
1175 GetDefault( nWhich )).GetLanguage());
1176 aOpt.SetParaFlags( LINEEND_CR );
1177 aOpt.WriteUserData( sFilterOptions );
1179 String sTargetTempURL = URIHelper::SmartRel2Abs(
1180 INetURLObject(), utl::TempFile::CreateTempName(),
1181 URIHelper::GetMaybeFileHdl());
1182 const SfxFilter *pTargetSfxFlt = SwIoSystem::GetFilterOfFormat(
1183 String::CreateFromAscii( FILTER_XML ),
1184 SwDocShell::Factory().GetFilterContainer() );
1186 uno::Sequence< beans::PropertyValue > aValues(1);
1187 beans::PropertyValue* pValues = aValues.getArray();
1188 pValues[0].Name = C2U("FilterName");
1189 pValues[0].Value <<= ::rtl::OUString(pTargetSfxFlt->GetFilterName());
1191 uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
1192 xStore->storeToURL( sTargetTempURL, aValues );
1194 pDlg->SetDocumentCount( nEnd );
1195 pDlg->ShowDialog();
1196 //help to force painting the dialog
1197 //TODO/CLEANUP
1198 //Sollbruchstelle
1199 for ( sal_Int16 i = 0; i < 25; i++)
1200 Application::Reschedule();
1201 for(sal_uInt32 nDoc = nBegin; nDoc < nEnd; ++nDoc)
1203 m_pWizard->EnterWait();
1204 SwDocMergeInfo& rInfo = rConfigItem.GetDocumentMergeInfo(nDoc);
1206 //now extract a document from the target document
1207 SfxObjectShellRef xTempDocShell( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
1208 xTempDocShell->DoInitNew( 0 );
1209 SfxViewFrame* pTempFrame = SfxViewFrame::CreateViewFrame( *xTempDocShell, 0, TRUE );
1210 // pTempFrame->GetFrame()->Appear();
1211 SwView* pTempView = static_cast<SwView*>( pTempFrame->GetViewShell() );
1212 pTargetView->GetWrtShell().StartAction();
1213 SwgReaderOption aOpt;
1214 aOpt.SetTxtFmts( sal_True );
1215 aOpt.SetFrmFmts( sal_True );
1216 aOpt.SetPageDescs( sal_True );
1217 aOpt.SetNumRules( sal_True );
1218 aOpt.SetMerge( sal_False );
1219 pTempView->GetDocShell()->LoadStylesFromFile(
1220 sTargetTempURL, aOpt, sal_True );
1221 pTargetView->GetWrtShell().PastePages(pTempView->GetWrtShell(),
1222 (USHORT)rInfo.nStartPageInTarget, (USHORT)rInfo.nEndPageInTarget );
1223 pTargetView->GetWrtShell().EndAction();
1225 //then save it
1226 SfxStringItem aName(SID_FILE_NAME,
1227 URIHelper::SmartRel2Abs(
1228 INetURLObject(), utl::TempFile::CreateTempName(0),
1229 URIHelper::GetMaybeFileHdl()) );
1231 /* if(bIsPDF)
1233 SfxDispatcher* pSfxDispatcher = pTempView->GetViewFrame()->GetDispatcher();
1234 pSfxDispatcher->Execute(
1235 SID_DIRECTEXPORTDOCASPDF,
1236 SFX_CALLMODE_SYNCHRON, &aName, &aFilterName, 0L );
1238 else*/
1240 uno::Sequence< beans::PropertyValue > aFilterValues(MM_DOCTYPE_TEXT == nDocType ? 2 : 1);
1241 beans::PropertyValue* pFilterValues = aFilterValues.getArray();
1242 pFilterValues[0].Name = C2U("FilterName");
1243 pFilterValues[0].Value <<= ::rtl::OUString(pSfxFlt->GetFilterName());
1244 if(MM_DOCTYPE_TEXT == nDocType)
1246 pFilterValues[1].Name = C2U("FilterOptions");
1247 pFilterValues[1].Value <<= ::rtl::OUString(sFilterOptions);
1250 uno::Reference< frame::XStorable > xTempStore( pTempView->GetDocShell()->GetModel(), uno::UNO_QUERY);
1251 xTempStore->storeToURL( aName.GetValue(), aFilterValues );
1253 xTempDocShell->DoClose();
1255 #ifdef DBG_UTIL
1256 sal_Int32 nTarget =
1257 #endif
1258 rConfigItem.MoveResultSet(rInfo.nDBRow);
1259 DBG_ASSERT( nTarget == rInfo.nDBRow, "row of current document could not be selected");
1260 DBG_ASSERT( sEMailColumn.Len(), "No email column selected");
1261 ::rtl::OUString sEMail = lcl_GetColumnValueOf(sEMailColumn, xColAccess);
1262 SwMailDescriptor aDesc;
1263 aDesc.sEMail = sEMail;
1264 rtl::OUString sBody;
1265 if(bAsBody)
1268 //read in the temporary file and use it as mail body
1269 SfxMedium aMedium( aName.GetValue(), STREAM_READ, TRUE);
1270 SvStream* pInStream = aMedium.GetInStream();
1271 if(pInStream)
1272 pInStream->SetStreamCharSet( eEncoding );
1273 else
1275 DBG_ERROR("no output file created?");
1276 continue;
1278 ByteString sLine;
1279 sal_Bool bDone = pInStream->ReadLine( sLine );
1280 while ( bDone )
1282 sBody += rtl::OUString(String(sLine, eEncoding));
1283 sBody += rtl::OUString('\n');
1284 bDone = pInStream->ReadLine( sLine );
1287 //remove the temporary file
1288 SWUnoHelper::UCB_DeleteFile( aName.GetValue() );
1290 else
1292 sBody = m_sBody;
1293 aDesc.sAttachmentURL = aName.GetValue();
1294 String sAttachment(m_aAttachmentED.GetText());
1295 xub_StrLen nTokenCount = sAttachment.GetTokenCount( '.' );
1296 if( 2 > nTokenCount)
1298 sAttachment += '.';
1299 sAttachment.SetToken( nTokenCount, '.', sExtension);
1301 else if(sAttachment.GetToken( nTokenCount - 1, '.') != sExtension)
1302 sAttachment += sExtension;
1303 aDesc.sAttachmentName = sAttachment;
1304 aDesc.sMimeType = sMimeType;
1306 if(rConfigItem.IsGreetingLine(sal_True))
1308 ::rtl::OUString sNameColumn = rConfigItem.GetAssignedColumn(MM_PART_LASTNAME);
1309 ::rtl::OUString sName = lcl_GetColumnValueOf(sNameColumn, xColAccess);
1310 String sGreeting;
1311 if(sName.getLength() && rConfigItem.IsIndividualGreeting(sal_True))
1313 ::rtl::OUString sGenderColumn = rConfigItem.GetAssignedColumn(MM_PART_GENDER);
1314 const ::rtl::OUString& sFemaleValue = rConfigItem.GetFemaleGenderValue();
1315 ::rtl::OUString sGenderValue = lcl_GetColumnValueOf(sGenderColumn, xColAccess);
1316 SwMailMergeConfigItem::Gender eGenderType = sGenderValue == sFemaleValue ?
1317 SwMailMergeConfigItem::FEMALE :
1318 SwMailMergeConfigItem::MALE;
1320 sGreeting = SwAddressPreview::FillData(
1321 rConfigItem.GetGreetings(eGenderType)
1322 [rConfigItem.GetCurrentGreeting(eGenderType)],
1323 rConfigItem);
1325 else
1327 sGreeting =
1328 rConfigItem.GetGreetings(SwMailMergeConfigItem::NEUTRAL)
1329 [rConfigItem.GetCurrentGreeting(SwMailMergeConfigItem::NEUTRAL)];
1332 sGreeting += '\n';
1333 ::rtl::OUString sTemp( sGreeting );
1334 sTemp += sBody;
1335 sBody = sTemp;
1338 aDesc.sBodyContent = sBody;
1339 if(MM_DOCTYPE_HTML == nDocType)
1341 aDesc.sBodyMimeType = ::rtl::OUString::createFromAscii("text/html; charset=");
1342 aDesc.sBodyMimeType += ::rtl::OUString::createFromAscii(
1343 rtl_getBestMimeCharsetFromTextEncoding( eEncoding ));
1345 else
1346 aDesc.sBodyMimeType =
1347 ::rtl::OUString::createFromAscii("text/plain; charset=UTF-8; format=flowed");
1349 aDesc.sSubject = m_aSubjectED.GetText();
1350 aDesc.sCC = m_sCC;
1351 aDesc.sBCC = m_sBCC;
1352 pDlg->AddDocument( aDesc );
1353 //help to force painting the dialog
1354 for ( sal_Int16 i = 0; i < 25; i++)
1355 Application::Reschedule();
1356 //stop creating of data when dialog has been closed
1357 if(!pDlg->IsVisible())
1359 m_pWizard->LeaveWait();
1360 break;
1362 m_pWizard->LeaveWait();
1364 pDlg->EnableDesctruction();
1365 ::osl::File::remove( sTargetTempURL );
1367 m_pWizard->enableButtons(WZB_FINISH, sal_True);
1368 //the dialog deletes itself
1369 //delete pDlg;
1370 return 0;