Update ooo320-m1
[ooovba.git] / sw / source / ui / dbui / mmoutputpage.cxx
blobeb1f75d579798523f54fab9623be04a9d941bd75
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 <svtools/ehdl.hxx>
59 #include <svtools/sfxecode.hxx>
60 #include <vcl/msgbox.hxx>
61 #include <sfx2/dinfdlg.hxx>
62 #include <sfx2/printer.hxx>
63 #include <sfx2/fcontnr.hxx>
64 #include <sfx2/viewfrm.hxx>
65 #include <sfx2/dispatch.hxx>
66 #include <sfx2/docfile.hxx>
67 //#ifndef _SFX_DOCFILT_HACK_HXX
68 //#include <sfx2/docfilt.hxx>
69 //#endif
70 #include <tools/urlobj.hxx>
71 #include <svtools/urihelper.hxx>
72 #ifndef _VCL_PRINT_HXX
73 #include <vcl/print.hxx>
74 #endif
75 #include <unotools/tempfile.hxx>
76 #include <osl/file.hxx>
77 #include <mmgreetingspage.hxx>
78 #include <com/sun/star/frame/XStorable.hpp>
79 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
80 #include <com/sun/star/sdb/XColumn.hpp>
81 //#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
82 //#include <com/sun/star/beans/PropertyValue.hpp>
83 //#endif
84 //#ifndef _BASEDLGS_HXX
85 //#include <sfx2/basedlgs.hxx>
86 //#endif
87 #ifndef _DBMGR_HXX
88 #include <dbmgr.hxx>
89 #endif
90 #include <swunohelper.hxx>
91 #include <vos/mutex.hxx>
92 #include <shellio.hxx>
93 #include <svx/htmlcfg.hxx>
94 #include <sfx2/event.hxx>
95 #include <swevent.hxx>
96 #include <mmoutputpage.hrc>
97 #include <dbui.hxx>
98 #include <dbui.hrc>
99 #include <helpid.h>
100 #include <sfx2/app.hxx>
101 #include <statstr.hrc>
102 #include <unomid.h>
104 using namespace svt;
105 using namespace ::com::sun::star;
106 using namespace ::com::sun::star::uno;
108 /*-- 01.07.2004 16:47:49---------------------------------------------------
110 -----------------------------------------------------------------------*/
111 String lcl_GetExtensionForDocType(ULONG nDocType)
113 String sExtension;
114 switch( nDocType )
116 case MM_DOCTYPE_OOO : sExtension = String::CreateFromAscii( "odt" ); break;
117 case MM_DOCTYPE_PDF : sExtension = String::CreateFromAscii( "pdf" ); break;
118 case MM_DOCTYPE_WORD: sExtension = String::CreateFromAscii( "doc" ); break;
119 case MM_DOCTYPE_HTML: sExtension = String::CreateFromAscii( "html" ); break;
120 case MM_DOCTYPE_TEXT: sExtension = String::CreateFromAscii( "txt" ); break;
122 return sExtension;
124 /*-- 28.06.2004 11:49:21---------------------------------------------------
126 -----------------------------------------------------------------------*/
127 ::rtl::OUString lcl_GetColumnValueOf(const ::rtl::OUString& rColumn, Reference < container::XNameAccess>& rxColAccess )
129 ::rtl::OUString sRet;
130 if(rxColAccess->hasByName(rColumn))
132 Any aCol = rxColAccess->getByName(rColumn);
133 Reference< sdb::XColumn > xColumn;
134 aCol >>= xColumn;
135 if(xColumn.is())
136 sRet = xColumn->getString();
138 return sRet;
140 /*-- 21.06.2004 14:01:13---------------------------------------------------
142 -----------------------------------------------------------------------*/
143 class SwSaveWarningBox_Impl : public ModalDialog
145 FixedImage aWarningImageIM;
146 FixedInfo aWarningFI;
148 FixedText aFileNameFT;
149 Edit aFileNameED;
151 FixedLine aSeparatorFL;
152 OKButton aOKPB;
153 CancelButton aCancelPB;
155 DECL_LINK( ModifyHdl, Edit*);
156 public:
157 SwSaveWarningBox_Impl(Window* pParent, const String& rFileName);
158 ~SwSaveWarningBox_Impl();
160 String GetFileName() const {return aFileNameED.GetText();}
162 /*-- 02.07.2004 08:54:42---------------------------------------------------
164 -----------------------------------------------------------------------*/
165 class SwSendQueryBox_Impl : public ModalDialog
167 FixedImage aQueryImageIM;
168 FixedInfo aQueryFI;
170 Edit aTextED;
172 FixedLine aSeparatorFL;
173 OKButton aOKPB;
174 CancelButton aCancelPB;
176 bool bIsEmptyAllowed;
177 DECL_LINK( ModifyHdl, Edit*);
178 public:
179 SwSendQueryBox_Impl(Window* pParent, const String& rQueryText);
180 ~SwSendQueryBox_Impl();
182 void SetValue(const String& rSet)
184 aTextED.SetText(rSet);
185 ModifyHdl( &aTextED );
187 String GetValue() const {return aTextED.GetText();}
189 void SetIsEmptyTextAllowed(bool bSet)
191 bIsEmptyAllowed = bSet;
192 ModifyHdl( &aTextED );
196 /*-- 21.06.2004 14:11:58---------------------------------------------------
198 -----------------------------------------------------------------------*/
199 SwSaveWarningBox_Impl::SwSaveWarningBox_Impl(Window* pParent, const String& rFileName) :
200 ModalDialog(pParent, SW_RES( DLG_MM_SAVEWARNING )),
201 aWarningImageIM(this, SW_RES( IM_WARNING )),
202 aWarningFI(this, SW_RES( FI_WARNING )),
203 aFileNameFT(this, SW_RES( FT_FILENAME )),
204 aFileNameED(this, SW_RES( ED_FILENAME )),
205 aSeparatorFL(this, SW_RES( FL_SEPARATOR )),
206 aOKPB(this, SW_RES( PB_OK )),
207 aCancelPB(this, SW_RES( PB_CANCEL ))
209 FreeResource();
210 aWarningImageIM.SetImage(WarningBox::GetStandardImage());
211 aFileNameED.SetText(rFileName);
212 aFileNameED.SetModifyHdl(LINK(this, SwSaveWarningBox_Impl, ModifyHdl));
213 ModifyHdl( &aFileNameED );
215 /*-- 21.06.2004 14:11:58---------------------------------------------------
217 -----------------------------------------------------------------------*/
218 SwSaveWarningBox_Impl::~SwSaveWarningBox_Impl()
221 /*-- 21.06.2004 14:11:58---------------------------------------------------
223 -----------------------------------------------------------------------*/
224 IMPL_LINK( SwSaveWarningBox_Impl, ModifyHdl, Edit*, pEdit)
226 aOKPB.Enable(pEdit->GetText().Len() > 0);
227 return 0;
229 /*-- 02.07.2004 09:02:53---------------------------------------------------
231 -----------------------------------------------------------------------*/
232 SwSendQueryBox_Impl::SwSendQueryBox_Impl(Window* pParent, const String& rText) :
233 ModalDialog(pParent, SW_RES( DLG_MM_QUERY )),
234 aQueryImageIM( this, SW_RES( IM_QUERY )),
235 aQueryFI( this, SW_RES( FI_QUERY )),
236 aTextED( this, SW_RES( ED_TEXT )),
237 aSeparatorFL(this, SW_RES( FL_SEPARATOR )),
238 aOKPB(this, SW_RES( PB_OK )),
239 aCancelPB(this, SW_RES( PB_CANCEL )),
240 bIsEmptyAllowed(true)
242 FreeResource();
243 aQueryFI.SetText(rText);
244 aQueryImageIM.SetImage(QueryBox::GetStandardImage());
245 aTextED.SetModifyHdl(LINK(this, SwSendQueryBox_Impl, ModifyHdl));
246 ModifyHdl( &aTextED );
248 /*-- 02.07.2004 08:58:45---------------------------------------------------
250 -----------------------------------------------------------------------*/
251 SwSendQueryBox_Impl::~SwSendQueryBox_Impl()
254 /*-- 02.07.2004 08:58:25---------------------------------------------------
256 -----------------------------------------------------------------------*/
257 IMPL_LINK( SwSendQueryBox_Impl, ModifyHdl, Edit*, pEdit)
259 aOKPB.Enable(bIsEmptyAllowed || (pEdit->GetText().Len() > 0));
260 return 0;
263 /*-- 16.04.2004 16:34:48---------------------------------------------------
265 -----------------------------------------------------------------------*/
266 class SwCopyToDialog : public SfxModalDialog
268 FixedInfo m_aDescriptionFI;
269 FixedText m_aCCFT;
270 Edit m_aCCED;
271 FixedText m_aBCCFT;
272 Edit m_aBCCED;
274 FixedInfo m_aNoteFI;
275 FixedLine m_aSeparatorFL;
277 OKButton m_aOK;
278 CancelButton m_aCancel;
279 HelpButton m_aHelp;
281 public:
282 SwCopyToDialog(Window* pParent);
283 ~SwCopyToDialog();
285 String GetCC() {return m_aCCED.GetText();}
286 void SetCC(const String& rSet) {m_aCCED.SetText(rSet);}
288 String GetBCC() {return m_aBCCED.GetText();}
289 void SetBCC(const String& rSet) {m_aBCCED.SetText(rSet);}
292 /*-- 16.04.2004 16:43:18---------------------------------------------------
294 -----------------------------------------------------------------------*/
295 SwCopyToDialog::SwCopyToDialog(Window* pParent) :
296 SfxModalDialog(pParent, SW_RES(DLG_MM_COPYTO)),
297 #ifdef MSC
298 #pragma warning (disable : 4355)
299 #endif
300 m_aDescriptionFI( this, SW_RES( FI_DESCRIPTION )),
301 m_aCCFT( this, SW_RES( FT_CC )),
302 m_aCCED( this, SW_RES( ED_CC )),
303 m_aBCCFT( this, SW_RES( FT_BCC )),
304 m_aBCCED( this, SW_RES( ED_BCC )),
305 m_aNoteFI( this, SW_RES( FI_NOTE )),
306 m_aSeparatorFL( this, SW_RES( FL_SEPARATOR )),
307 m_aOK( this, SW_RES( PB_OK )),
308 m_aCancel( this, SW_RES( PB_CANCEL )),
309 m_aHelp( this, SW_RES( PB_HELP ))
310 #ifdef MSC
311 #pragma warning (default : 4355)
312 #endif
314 FreeResource();
316 /*-- 16.04.2004 16:43:10---------------------------------------------------
318 -----------------------------------------------------------------------*/
319 SwCopyToDialog::~SwCopyToDialog()
323 /*-- 02.04.2004 13:15:54---------------------------------------------------
325 -----------------------------------------------------------------------*/
326 SwMailMergeOutputPage::SwMailMergeOutputPage( SwMailMergeWizard* _pParent) :
327 svt::OWizardPage( _pParent, SW_RES(DLG_MM_OUTPUT_PAGE)),
328 #ifdef MSC
329 #pragma warning (disable : 4355)
330 #endif
331 m_aHeaderFI(this, SW_RES( FI_HEADER ) ),
332 m_aOptionsFI(this, SW_RES( FI_OPTIONS ) ),
333 m_aSaveStartDocRB(this, SW_RES( RB_SAVESTARTDOC ) ),
334 m_aSaveMergedDocRB(this, SW_RES( RB_SAVEMERGEDDOC ) ),
335 m_aPrintRB(this, SW_RES( RB_PRINT ) ),
336 m_aSendMailRB(this, SW_RES( RB_SENDMAIL ) ),
338 m_aSeparatorFL(this, SW_RES( FL_SEPARATOR ) ),
340 m_aSaveStartDocPB(this, SW_RES( PB_SAVESTARTDOC ) ),
342 m_aSaveAsOneRB(this, SW_RES( RB_SAVEASONE ) ),
343 m_aSaveIndividualRB(this, SW_RES( RB_SAVEINDIVIDUAL ) ),
344 m_aPrintAllRB(this, SW_RES( RB_PRINTALL ) ),
345 m_aSendAllRB( this, SW_RES( RB_SENDALL ) ),
347 m_aFromRB(this, SW_RES( RB_FROM ) ),
348 m_aFromNF(this, SW_RES( NF_FROM ) ),
349 m_aToFT(this, SW_RES( FT_TO ) ),
350 m_aToNF(this, SW_RES( NF_TO ) ),
351 m_aSaveNowPB(this, SW_RES( PB_SAVENOW ) ),
353 m_aPrinterFT(this, SW_RES( FT_PRINT ) ),
354 m_aPrinterLB(this, SW_RES( LB_PRINT ) ),
355 m_aPrinterSettingsPB(this, SW_RES( PB_PRINTERSETTINGS ) ),
356 m_aPrintNowPB(this, SW_RES( PB_PRINTNOW ) ),
358 m_aMailToFT( this, SW_RES( FT_MAILTO ) ),
359 m_aMailToLB( this, SW_RES( LB_MAILTO ) ),
360 m_aCopyToPB( this, SW_RES( PB_COPYTO ) ),
361 m_aSubjectFT( this, SW_RES( FT_SUBJECT ) ),
362 m_aSubjectED( this, SW_RES( ED_SUBJECT ) ),
363 m_aSendAsFT( this, SW_RES( FT_SENDAS ) ),
364 m_aSendAsLB( this, SW_RES( LB_SENDAS ) ),
365 m_aAttachmentFT( this, SW_RES( FT_ATTACHMENT ) ),
366 m_aAttachmentED( this, SW_RES( ED_ATTACHMENT ) ),
367 m_aSendAsPB( this, SW_RES( PB_SENDAS ) ),
368 m_aSendDocumentsPB( this, SW_RES( PB_SENDDOCUMENTS ) ),
370 m_sSaveStartST(SW_RES( ST_SAVESTART ) ),
371 m_sSaveMergedST(SW_RES( ST_SAVEMERGED ) ),
372 m_sPrintST(SW_RES( ST_PRINT ) ),
373 m_sSendMailST(SW_RES( ST_SENDMAIL ) ),
375 m_sDefaultAttachmentST(SW_RES( ST_DEFAULTATTACHMENT )),
376 m_sNoSubjectQueryST(SW_RES( ST_SUBJECTQUERY )),
377 m_sNoSubjectST(SW_RES( ST_NOSUBJECT )),
378 m_sNoAttachmentNameST(SW_RES( ST_NOATTACHMENTNAME )),
379 m_sConfigureMail(SW_RES( ST_CONFIGUREMAIL)),
380 #ifdef MSC
381 #pragma warning (default : 4355)
382 #endif
383 m_bCancelSaving( false ),
384 m_pWizard(_pParent),
385 m_pTempPrinter( 0 ),
386 m_pDocumentPrinterCopy(0)
388 FreeResource();
390 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
391 // #i51949# hide e-Mail option if e-Mail is not supported
392 if(!rConfigItem.IsMailAvailable())
393 m_aSendMailRB.Hide();
395 Link aLink = LINK(this, SwMailMergeOutputPage, OutputTypeHdl_Impl);
396 m_aSaveStartDocRB.SetClickHdl(aLink);
397 m_aSaveMergedDocRB.SetClickHdl(aLink);
398 m_aPrintRB.SetClickHdl(aLink);
399 m_aSendMailRB.SetClickHdl(aLink);
400 m_aSaveStartDocRB.Check();
401 m_aPrintAllRB.Check();
402 m_aSaveAsOneRB.Check();
403 m_aSendAllRB.Check();
405 m_aSaveStartDocPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, SaveStartHdl_Impl));
406 m_aSaveNowPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, SaveOutputHdl_Impl));
407 m_aPrinterLB.SetSelectHdl(LINK(this, SwMailMergeOutputPage, PrinterChangeHdl_Impl));
408 m_aPrintNowPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, PrintHdl_Impl));
409 m_aPrinterSettingsPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, PrinterSetupHdl_Impl));
411 m_aSendAsPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, SendAsHdl_Impl)),
412 m_aSendDocumentsPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, SendDocumentsHdl_Impl)),
413 m_aSendAsLB.SetSelectHdl(LINK(this, SwMailMergeOutputPage, SendTypeHdl_Impl));
415 m_nFromToRBPos = m_aFromRB.GetPosPixel().Y();
416 m_nFromToFTPos = m_aToFT.GetPosPixel().Y();
417 m_nFromToNFPos = m_aFromNF.GetPosPixel().Y();
419 m_nRBOffset = m_nFromToRBPos - m_aSaveIndividualRB.GetPosPixel().Y();
421 OutputTypeHdl_Impl(&m_aSaveStartDocRB);
423 m_aCopyToPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, CopyToHdl_Impl));
425 m_aSaveAsOneRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
426 m_aSaveIndividualRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
427 m_aPrintAllRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
428 m_aSendAllRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
430 m_aFromRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
431 //#i63267# printing might be disabled
432 m_aPrintRB.Enable(!Application::GetSettings().GetMiscSettings().GetDisablePrinting());
435 /*-- 02.04.2004 13:15:44---------------------------------------------------
437 -----------------------------------------------------------------------*/
438 SwMailMergeOutputPage::~SwMailMergeOutputPage()
440 delete m_pTempPrinter;
441 delete m_pDocumentPrinterCopy;
443 /*-- 31.01.2005 08:38:14---------------------------------------------------
445 -----------------------------------------------------------------------*/
446 void SwMailMergeOutputPage::ActivatePage()
448 //fill printer ListBox
449 const std::vector<rtl::OUString>& rPrinters = Printer::GetPrinterQueues();
450 unsigned int nCount = rPrinters.size();
451 if ( nCount )
453 for( unsigned int i = 0; i < nCount; i++ )
455 m_aPrinterLB.InsertEntry( rPrinters[i] );
459 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
461 SwView* pTargetView = rConfigItem.GetTargetView();
462 DBG_ASSERT(pTargetView, "no target view exists");
463 if(pTargetView)
465 SfxPrinter* pPrinter = pTargetView->GetWrtShell().getIDocumentDeviceAccess()->getPrinter( true );
466 m_aPrinterLB.SelectEntry( pPrinter->GetName() );
467 m_aToNF.SetValue( rConfigItem.GetMergedDocumentCount() );
468 m_aToNF.SetMax( rConfigItem.GetMergedDocumentCount() );
469 m_pDocumentPrinterCopy = pTargetView->GetWrtShell().getIDocumentDeviceAccess()->getPrinter( true )->Clone();
471 m_aPrinterLB.SelectEntry( rConfigItem.GetSelectedPrinter() );
473 SwView* pSourceView = rConfigItem.GetSourceView();
474 DBG_ASSERT(pSourceView, "no source view exists");
475 if(pSourceView)
477 SwDocShell* pDocShell = pSourceView->GetDocShell();
478 if ( pDocShell->HasName() )
480 INetURLObject aTmp( pDocShell->GetMedium()->GetName() );
481 m_aAttachmentED.SetText(aTmp.getName(
482 INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ));
486 /*-- 05.07.2004 13:54:11---------------------------------------------------
488 -----------------------------------------------------------------------*/
489 bool SwMailMergeOutputPage::canAdvance() const
491 return false;
493 /*-- 02.04.2004 13:15:44---------------------------------------------------
495 -----------------------------------------------------------------------*/
496 IMPL_LINK(SwMailMergeOutputPage, OutputTypeHdl_Impl, RadioButton*, pButton)
498 Control* aControls[] =
500 &m_aSaveStartDocPB,
501 &m_aSaveAsOneRB, &m_aSaveIndividualRB,
502 &m_aFromRB, &m_aFromNF, &m_aToFT, &m_aToNF,
503 &m_aSaveNowPB,
504 &m_aPrinterFT, &m_aPrinterLB, &m_aPrinterSettingsPB, &m_aPrintAllRB,
505 &m_aPrintNowPB,
506 &m_aMailToFT, &m_aMailToLB, &m_aCopyToPB,
507 &m_aSubjectFT, &m_aSubjectED,
508 &m_aSendAsFT, &m_aSendAsLB, &m_aSendAsPB,
509 &m_aAttachmentFT, &m_aAttachmentED,
510 &m_aSendAllRB, &m_aSendDocumentsPB,
513 SetUpdateMode(TRUE);
514 Control** pControl = aControls;
517 (*pControl)->Show(sal_False);
519 } while(*(++pControl));
521 if(&m_aSaveStartDocRB == pButton)
523 m_aSaveStartDocPB.Show();
524 m_aSeparatorFL.SetText(m_sSaveStartST);
527 else if(&m_aSaveMergedDocRB == pButton)
529 Control* aSaveMergedControls[] =
531 &m_aSaveAsOneRB, &m_aSaveIndividualRB,
532 &m_aFromRB, &m_aFromNF, &m_aToFT, &m_aToNF,
533 &m_aSaveNowPB,
536 Control** pSaveMergeControl = aSaveMergedControls;
539 (*pSaveMergeControl)->Show(sal_True);
541 } while(*(++pSaveMergeControl));
542 if(!m_aFromRB.IsChecked() && !m_aSaveAsOneRB.IsChecked())
544 m_aSaveIndividualRB.Check();
546 m_aSeparatorFL.SetText(m_sSaveMergedST);
547 //reposition the from/to line
548 if(m_aFromRB.GetPosPixel().Y() != m_nFromToRBPos)
550 Point aPos(m_aFromRB.GetPosPixel()); aPos.Y() = m_nFromToRBPos; m_aFromRB.SetPosPixel(aPos);
551 aPos = m_aToFT.GetPosPixel(); aPos.Y() = m_nFromToFTPos; m_aToFT.SetPosPixel(aPos);
552 aPos = m_aFromNF.GetPosPixel(); aPos.Y() = m_nFromToNFPos; m_aFromNF.SetPosPixel(aPos);
553 aPos = m_aToNF.GetPosPixel(); aPos.Y() = m_nFromToNFPos; m_aToNF.SetPosPixel(aPos);
556 else if(&m_aPrintRB == pButton)
558 Control* aPrintControls[] =
560 &m_aFromRB, &m_aFromNF, &m_aToFT, &m_aToNF,
561 &m_aPrinterFT, &m_aPrinterLB, &m_aPrinterSettingsPB, &m_aPrintAllRB,
562 &m_aPrintNowPB,
565 Control** pPrinterControl = aPrintControls;
568 (*pPrinterControl)->Show(sal_True);
570 } while(*(++pPrinterControl));
571 if(!m_aFromRB.IsChecked())
572 m_aPrintAllRB.Check();
574 m_aSeparatorFL.SetText(m_sPrintST);
575 //reposition the from/to line
576 long nRB_FT_Offset = m_nFromToRBPos - m_nFromToFTPos;
577 long nNewRBXPos = m_aPrintAllRB.GetPosPixel().Y() + m_nRBOffset;
579 Point aPos(m_aFromRB.GetPosPixel());aPos.Y() = nNewRBXPos; m_aFromRB.SetPosPixel(aPos);
580 aPos = m_aToFT.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aToFT.SetPosPixel(aPos);
581 aPos = m_aFromNF.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aFromNF.SetPosPixel(aPos);
582 aPos = m_aToNF.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aToNF.SetPosPixel(aPos);
584 else /*if(&m_aSendMailRB == pButton)*/
586 Control* aMailControls[] =
588 &m_aFromRB, &m_aFromNF, &m_aToFT, &m_aToNF,
589 &m_aMailToFT, &m_aMailToLB, &m_aCopyToPB,
590 &m_aSubjectFT, &m_aSubjectED,
591 &m_aSendAsFT, &m_aSendAsLB, &m_aSendAsPB,
592 &m_aAttachmentFT, &m_aAttachmentED,
593 &m_aSendAllRB, &m_aSendDocumentsPB, 0
595 Control** pMailControl = aMailControls;
598 (*pMailControl)->Show(sal_True);
600 } while(*(++pMailControl));
602 if(!m_aFromRB.IsChecked())
603 m_aSendAllRB.Check();
604 if(!m_aAttachmentED.GetText().Len())
606 String sAttach( m_sDefaultAttachmentST );
607 sAttach += '.';
608 sAttach += lcl_GetExtensionForDocType(
609 (ULONG)m_aSendAsLB.GetEntryData(m_aSendAsLB.GetSelectEntryPos()));
610 m_aAttachmentED.SetText( sAttach );
613 m_aSeparatorFL.SetText(m_sSendMailST);
614 //fill mail address ListBox
615 if(!m_aMailToLB.GetEntryCount())
617 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
618 //select first column
619 uno::Reference< sdbcx::XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), uno::UNO_QUERY);
620 //get the name of the actual columns
621 uno::Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
622 uno::Sequence< ::rtl::OUString > aFields;
623 if(xColAccess.is())
624 aFields = xColAccess->getElementNames();
625 const ::rtl::OUString* pFields = aFields.getConstArray();
626 for(sal_Int32 nField = 0; nField < aFields.getLength(); ++nField)
627 m_aMailToLB.InsertEntry(pFields[nField]);
629 m_aMailToLB.SelectEntryPos(0);
630 // then select the right one - may not be available
631 const ResStringArray& rHeaders = rConfigItem.GetDefaultAddressHeaders();
632 String sEMailColumn = rHeaders.GetString( MM_PART_E_MAIL );
633 Sequence< ::rtl::OUString> aAssignment =
634 rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
635 if(aAssignment.getLength() > MM_PART_E_MAIL && aAssignment[MM_PART_E_MAIL].getLength())
636 sEMailColumn = aAssignment[MM_PART_E_MAIL];
637 m_aMailToLB.SelectEntry(sEMailColumn);
638 // HTML format pre-selected
639 m_aSendAsLB.SelectEntryPos(3);
640 SendTypeHdl_Impl(&m_aSendAsLB);
642 if(m_aSendAllRB.GetPosPixel().Y() + m_nRBOffset != m_aFromRB.GetPosPixel().Y())
644 long nRB_FT_Offset = m_nFromToRBPos - m_nFromToFTPos;
645 long nNewRBXPos = m_aSendAllRB.GetPosPixel().Y() + m_nRBOffset;
647 Point aPos(m_aFromRB.GetPosPixel());aPos.Y() = nNewRBXPos; m_aFromRB.SetPosPixel(aPos);
648 aPos = m_aToFT.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aToFT.SetPosPixel(aPos);
649 aPos = m_aFromNF.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aFromNF.SetPosPixel(aPos);
650 aPos = m_aToNF.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aToNF.SetPosPixel(aPos);
653 m_aFromRB.GetClickHdl().Call(m_aFromRB.IsChecked() ? &m_aFromRB : 0);
655 SetUpdateMode(FALSE);
656 return 0;
658 /*-- 22.08.2005 12:15:10---------------------------------------------------
660 -----------------------------------------------------------------------*/
661 IMPL_LINK(SwMailMergeOutputPage, DocumentSelectionHdl_Impl, RadioButton*, pButton)
663 sal_Bool bEnableFromTo = pButton == &m_aFromRB;
664 m_aFromNF.Enable(bEnableFromTo);
665 m_aToFT.Enable(bEnableFromTo);
666 m_aToNF.Enable(bEnableFromTo);
667 return 0;
670 /*-- 16.04.2004 16:45:10---------------------------------------------------
672 -----------------------------------------------------------------------*/
673 IMPL_LINK(SwMailMergeOutputPage, CopyToHdl_Impl, PushButton*, pButton)
675 SwCopyToDialog* pDlg = new SwCopyToDialog(pButton);
676 pDlg->SetCC(m_sCC );
677 pDlg->SetBCC(m_sBCC);
678 if(RET_OK == pDlg->Execute())
680 m_sCC = pDlg->GetCC() ;
681 m_sBCC = pDlg->GetBCC();
683 delete pDlg;
684 return 0;
686 /*-- 17.05.2004 13:51:02---------------------------------------------------
688 -----------------------------------------------------------------------*/
689 IMPL_LINK(SwMailMergeOutputPage, SaveStartHdl_Impl, PushButton*, pButton)
691 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
692 SwView* pSourceView = rConfigItem.GetSourceView();
693 DBG_ASSERT( pSourceView, "source view missing");
694 if(pSourceView)
696 SfxViewFrame* pSourceViewFrm = pSourceView->GetViewFrame();
697 uno::Reference< frame::XFrame > xFrame =
698 pSourceViewFrm->GetFrame()->GetFrameInterface();
699 xFrame->getContainerWindow()->setVisible(sal_True);
700 pSourceViewFrm->GetDispatcher()->Execute(SID_SAVEDOC, SFX_CALLMODE_SYNCHRON);
701 xFrame->getContainerWindow()->setVisible(sal_False);
702 SwDocShell* pDocShell = pSourceView->GetDocShell();
703 //if the document has been saved it's URL has to be stored for
704 // later use and it can be closed now
705 if(pDocShell->HasName() && !pDocShell->IsModified())
707 INetURLObject aURL = pDocShell->GetMedium()->GetURLObject();
708 //update the attachment name
709 if(!m_aAttachmentED.GetText().Len())
711 if ( pDocShell->HasName() )
713 m_aAttachmentED.SetText(aURL.getName(
714 INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ));
718 rConfigItem.AddSavedDocument(
719 aURL.GetMainURL(INetURLObject::DECODE_TO_IURI));
720 pButton->Enable(FALSE);
721 m_pWizard->enableButtons(WZB_FINISH, sal_True);
722 pButton->Enable(FALSE);
726 return 0;
728 /*-- 17.07.2008 08:09:06---------------------------------------------------
730 -----------------------------------------------------------------------*/
731 IMPL_LINK(SwMailMergeOutputPage, SaveCancelHdl_Impl, Button*, EMPTYARG )
733 m_bCancelSaving = true;
734 return 0;
736 /*-- 17.05.2004 13:51:02---------------------------------------------------
738 -----------------------------------------------------------------------*/
739 IMPL_LINK(SwMailMergeOutputPage, SaveOutputHdl_Impl, PushButton*, pButton)
741 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
742 SwView* pTargetView = rConfigItem.GetTargetView();
743 DBG_ASSERT(pTargetView, "no target view exists");
744 if(!pTargetView)
745 return 0;
747 if(m_aSaveAsOneRB.IsChecked())
749 String sFilter;
750 String sPath = SwMailMergeHelper::CallSaveAsDialog(sFilter);
751 if(!sPath.Len())
752 return 0;
753 uno::Sequence< beans::PropertyValue > aValues(1);
754 beans::PropertyValue* pValues = aValues.getArray();
755 pValues[0].Name = C2U("FilterName");
756 pValues[0].Value <<= ::rtl::OUString(sFilter);
758 uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
759 sal_uInt32 nErrorCode = ERRCODE_NONE;
762 xStore->storeToURL( sPath, aValues );
764 catch( task::ErrorCodeIOException& aErrorEx )
766 nErrorCode = (sal_uInt32)aErrorEx.ErrCode;
768 catch( Exception& )
770 nErrorCode = ERRCODE_IO_GENERAL;
772 if( nErrorCode != ERRCODE_NONE )
774 SfxErrorContext aEc(ERRCTX_SFX_SAVEASDOC, pTargetView->GetDocShell()->GetTitle());
775 ErrorHandler::HandleError( nErrorCode );
778 else
780 sal_uInt32 nBegin = 0;
781 sal_uInt32 nEnd = 0;
782 if(m_aSaveIndividualRB.IsChecked())
784 nBegin = 0;
785 nEnd = rConfigItem.GetMergedDocumentCount();
787 else
789 nBegin = static_cast< sal_Int32 >(m_aFromNF.GetValue() - 1);
790 nEnd = static_cast< sal_Int32 >(m_aToNF.GetValue());
791 if(nEnd > rConfigItem.GetMergedDocumentCount())
792 nEnd = rConfigItem.GetMergedDocumentCount();
794 String sFilter;
795 String sPath = SwMailMergeHelper::CallSaveAsDialog(sFilter);
796 if(!sPath.Len())
797 return 0;
798 String sTargetTempURL = URIHelper::SmartRel2Abs(
799 INetURLObject(), utl::TempFile::CreateTempName(),
800 URIHelper::GetMaybeFileHdl());
801 const SfxFilter *pSfxFlt = SwIoSystem::GetFilterOfFormat(
802 String::CreateFromAscii( FILTER_XML ),
803 SwDocShell::Factory().GetFilterContainer() );
805 uno::Sequence< beans::PropertyValue > aValues(1);
806 beans::PropertyValue* pValues = aValues.getArray();
807 pValues[0].Name = C2U("FilterName");
808 pValues[0].Value <<= ::rtl::OUString(pSfxFlt->GetFilterName());
810 uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
811 sal_uInt32 nErrorCode = ERRCODE_NONE;
814 xStore->storeToURL( sTargetTempURL, aValues );
816 catch( task::ErrorCodeIOException& aErrorEx )
818 nErrorCode = (sal_uInt32)aErrorEx.ErrCode;
820 catch( Exception& )
822 nErrorCode = ERRCODE_IO_GENERAL;
824 if( nErrorCode != ERRCODE_NONE )
826 SfxErrorContext aEc(ERRCTX_SFX_SAVEASDOC, pTargetView->GetDocShell()->GetTitle());
827 ErrorHandler::HandleError( nErrorCode );
830 SwView* pSourceView = rConfigItem.GetSourceView();
831 PrintMonitor aSaveMonitor(this, PrintMonitor::MONITOR_TYPE_SAVE);
832 aSaveMonitor.aDocName.SetText(pSourceView->GetDocShell()->GetTitle(22));
833 aSaveMonitor.aCancel.SetClickHdl(LINK(this, SwMailMergeOutputPage, SaveCancelHdl_Impl));
834 aSaveMonitor.aPrinter.SetText( INetURLObject( sPath ).getFSysPath( INetURLObject::FSYS_DETECT ) );
835 aSaveMonitor.ResizeControls();
837 m_bCancelSaving = false;
838 aSaveMonitor.Show();
839 m_pWizard->enableButtons(WZB_CANCEL, sal_False);
841 for(sal_uInt32 nDoc = nBegin; nDoc < nEnd && !m_bCancelSaving; ++nDoc)
843 SwDocMergeInfo& rInfo = rConfigItem.GetDocumentMergeInfo(nDoc);
844 INetURLObject aURL(sPath);
845 String sFile = aURL.GetBase();
846 String sExtension = aURL.getExtension();
847 if(!sExtension.Len())
849 sExtension = pSfxFlt->GetWildcard()().GetToken(1, '.');
850 sPath += '.';
851 sPath += sExtension;
853 String sStat(SW_RES(STR_STATSTR_LETTER));
854 sStat += ' ';
855 sStat += String::CreateFromInt32( nDoc );
856 aSaveMonitor.aPrintInfo.SetText(sStat);
858 //now extract a document from the target document
859 SfxObjectShellRef xTempDocShell( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
860 xTempDocShell->DoInitNew( 0 );
861 SfxViewFrame* pTempFrame = SfxViewFrame::CreateViewFrame( *xTempDocShell, 0, TRUE );
862 // pTempFrame->GetFrame()->Appear();
863 SwView* pTempView = static_cast<SwView*>( pTempFrame->GetViewShell() );
864 pTargetView->GetWrtShell().StartAction();
865 SwgReaderOption aOpt;
866 aOpt.SetTxtFmts( sal_True );
867 aOpt.SetFrmFmts( sal_True );
868 aOpt.SetPageDescs( sal_True );
869 aOpt.SetNumRules( sal_True );
870 aOpt.SetMerge( sal_False );
871 pTempView->GetDocShell()->LoadStylesFromFile(
872 sTargetTempURL, aOpt, sal_True );
874 pTargetView->GetWrtShell().PastePages(pTempView->GetWrtShell(),
875 (USHORT)rInfo.nStartPageInTarget, (USHORT)rInfo.nEndPageInTarget );
876 pTargetView->GetWrtShell().EndAction();
877 //then save it
878 String sOutPath = aURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
879 String sCounter('_');
880 sCounter += String::CreateFromInt32(nDoc);
881 sOutPath.Insert(sCounter, sOutPath.Len() - sExtension.Len() - 1);
882 //SfxStringItem aName(SID_FILE_NAME, sOutPath);
883 //SfxStringItem aFilter(SID_FILTER_NAME, sFilter);
885 while(true)
887 //time for other slots is needed
888 for(sal_Int16 r = 0; r < 10; ++r)
889 Application::Reschedule();
890 bool bFailed = false;
893 pValues[0].Value <<= ::rtl::OUString(sFilter);
894 uno::Reference< frame::XStorable > xTempStore( xTempDocShell->GetModel(), uno::UNO_QUERY);
895 xTempStore->storeToURL( sOutPath, aValues );
897 catch( const uno::Exception& )
899 bFailed = true;
902 if(bFailed)
904 SwSaveWarningBox_Impl aWarning( pButton, sOutPath );
905 if(RET_OK == aWarning.Execute())
906 sOutPath = aWarning.GetFileName();
907 else
909 xTempDocShell->DoClose();
910 return 0;
913 else
915 xTempDocShell->DoClose();
916 break;
920 ::osl::File::remove( sTargetTempURL );
922 m_pWizard->enableButtons(WZB_CANCEL, sal_True);
923 m_pWizard->enableButtons(WZB_FINISH, sal_True);
924 return 0;
926 /*-- 22.06.2004 11:51:30---------------------------------------------------
928 -----------------------------------------------------------------------*/
929 IMPL_LINK(SwMailMergeOutputPage, PrinterChangeHdl_Impl, ListBox*, pBox)
931 if( m_pDocumentPrinterCopy && pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
933 const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), false );
935 if( pInfo )
937 if ( !m_pTempPrinter )
939 if( (m_pDocumentPrinterCopy->GetName() == pInfo->GetPrinterName()) &&
940 (m_pDocumentPrinterCopy->GetDriverName() == pInfo->GetDriver()) )
941 m_pTempPrinter = new Printer( m_pDocumentPrinterCopy->GetJobSetup() );
942 else
943 m_pTempPrinter = new Printer( *pInfo );
945 else
947 if( (m_pTempPrinter->GetName() != pInfo->GetPrinterName()) ||
948 (m_pTempPrinter->GetDriverName() != pInfo->GetDriver()) )
950 delete m_pTempPrinter;
951 m_pTempPrinter = new Printer( *pInfo );
955 else if( ! m_pTempPrinter )
956 m_pTempPrinter = new Printer();
958 m_aPrinterSettingsPB.Enable( m_pTempPrinter->HasSupport( SUPPORT_SETUPDIALOG ) );
960 else
961 m_aPrinterSettingsPB.Disable();
962 m_pWizard->GetConfigItem().SetSelectedPrinter( pBox->GetSelectEntry() );
964 // return m_pTempPrinter;
965 return 0;
968 /*-- 17.05.2004 13:51:02---------------------------------------------------
970 -----------------------------------------------------------------------*/
971 IMPL_LINK(SwMailMergeOutputPage, PrintHdl_Impl, PushButton*, EMPTYARG)
973 SwView* pTargetView = m_pWizard->GetConfigItem().GetTargetView();
974 DBG_ASSERT(pTargetView, "no target view exists");
975 if(!pTargetView)
976 return 0;
978 sal_uInt32 nBegin = 0;
979 sal_uInt32 nEnd = 0;
980 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
981 if(m_aPrintAllRB.IsChecked())
983 nBegin = 0;
984 nEnd = rConfigItem.GetMergedDocumentCount();
986 else
988 nBegin = static_cast< sal_Int32 >(m_aFromNF.GetValue() - 1);
989 nEnd = static_cast< sal_Int32 >(m_aToNF.GetValue());
990 if(nEnd > rConfigItem.GetMergedDocumentCount())
991 nEnd = rConfigItem.GetMergedDocumentCount();
993 rConfigItem.SetPrintRange( (USHORT)nBegin, (USHORT)nEnd );
994 SwWrtShell& rSh = pTargetView->GetWrtShell();
995 pTargetView->SetMailMergeConfigItem(&rConfigItem, 0, sal_False);
996 if(m_pTempPrinter)
998 m_pDocumentPrinterCopy->SetPrinterProps(m_pTempPrinter);
999 pTargetView->SetPrinter(m_pDocumentPrinterCopy->Clone());
1002 SfxObjectShell* pObjSh = pTargetView->GetViewFrame()->GetObjectShell();
1003 SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE), pObjSh));
1004 rSh.GetNewDBMgr()->SetMergeType( DBMGR_MERGE_DOCUMENTS );
1005 SfxDispatcher *pDis = pTargetView->GetViewFrame()->GetDispatcher();
1006 SfxBoolItem aMergeSilent(SID_SILENT, sal_False);
1007 m_pWizard->enableButtons(WZB_CANCEL, sal_False);
1008 pDis->Execute(SID_PRINTDOCDIRECT,
1009 SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD, &aMergeSilent, 0L);
1010 SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE_END, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE_END), pObjSh));
1012 pTargetView->SetMailMergeConfigItem(0, 0, sal_False);
1013 m_pWizard->enableButtons(WZB_CANCEL, sal_True);
1014 m_pWizard->enableButtons(WZB_FINISH, sal_True);
1015 return 0;
1017 /*-- 17.05.2004 13:51:02---------------------------------------------------
1019 -----------------------------------------------------------------------*/
1020 IMPL_LINK(SwMailMergeOutputPage, PrinterSetupHdl_Impl, PushButton*, pButton)
1022 if( !m_pTempPrinter )
1023 PrinterChangeHdl_Impl(&m_aPrinterLB);
1024 if(m_pTempPrinter)
1025 m_pTempPrinter->Setup(pButton);
1026 return 0;
1028 /*-- 14.06.2004 09:34:01---------------------------------------------------
1030 -----------------------------------------------------------------------*/
1031 IMPL_LINK(SwMailMergeOutputPage, SendTypeHdl_Impl, ListBox*, pBox)
1033 ULONG nDocType = (ULONG)pBox->GetEntryData(pBox->GetSelectEntryPos());
1034 sal_Bool bEnable = MM_DOCTYPE_HTML != nDocType && MM_DOCTYPE_TEXT != nDocType;
1035 m_aSendAsPB.Enable( bEnable );
1036 m_aAttachmentFT.Enable( bEnable );
1037 m_aAttachmentED.Enable( bEnable );
1038 if(bEnable)
1040 //add the correct extension
1041 String sAttach(m_aAttachmentED.GetText());
1042 //do nothing if the user has removed the name - the warning will come early enough
1043 if(sAttach.Len())
1045 xub_StrLen nTokenCount = sAttach.GetTokenCount( '.' );
1046 if( 2 > nTokenCount)
1048 sAttach += '.';
1049 ++nTokenCount;
1051 sAttach.SetToken( nTokenCount - 1, '.', lcl_GetExtensionForDocType( nDocType ));
1052 m_aAttachmentED.SetText(sAttach);
1055 return 0;
1057 /*-- 17.05.2004 13:51:02---------------------------------------------------
1059 -----------------------------------------------------------------------*/
1060 IMPL_LINK(SwMailMergeOutputPage, SendAsHdl_Impl, PushButton*, pButton)
1062 SwMailBodyDialog* pDlg = new SwMailBodyDialog(pButton, m_pWizard);
1063 pDlg->SetBody(m_sBody);
1064 if(RET_OK == pDlg->Execute())
1066 m_sBody = pDlg->GetBody();
1068 return 0;
1070 /*-- 21.05.2004 12:03:25---------------------------------------------------
1071 Send documents as e-mail
1072 -----------------------------------------------------------------------*/
1073 IMPL_LINK(SwMailMergeOutputPage, SendDocumentsHdl_Impl, PushButton*, pButton)
1075 SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
1077 //get the composed document
1078 SwView* pTargetView = rConfigItem.GetTargetView();
1079 DBG_ASSERT(pTargetView, "no target view exists");
1080 if(!pTargetView)
1081 return 0;
1083 if(!rConfigItem.GetMailServer().getLength() ||
1084 !SwMailMergeHelper::CheckMailAddress(rConfigItem.GetMailAddress()) )
1086 QueryBox aQuery(pButton, WB_YES_NO_CANCEL, m_sConfigureMail);
1087 USHORT nRet = aQuery.Execute();
1088 if(RET_YES == nRet )
1090 SfxAllItemSet aSet(pTargetView->GetPool());
1091 SwMailConfigDlg* pDlg = new SwMailConfigDlg(pButton, aSet);
1092 nRet = pDlg->Execute();
1093 delete pDlg;
1096 if(nRet != RET_OK && nRet != RET_YES)
1097 return 0;
1099 //create the send dialog
1100 SwSendMailDialog* pDlg = new SwSendMailDialog( pButton, rConfigItem );
1101 //add the documents
1102 sal_uInt32 nBegin = 0;
1103 sal_uInt32 nEnd = 0;
1104 if(m_aSendAllRB.IsChecked())
1106 nBegin = 0;
1107 nEnd = rConfigItem.GetMergedDocumentCount();
1109 else
1111 nBegin = static_cast< sal_Int32 >(m_aFromNF.GetValue() - 1);
1112 nEnd = static_cast< sal_Int32 >(m_aToNF.GetValue());
1113 if(nEnd > rConfigItem.GetMergedDocumentCount())
1114 nEnd = rConfigItem.GetMergedDocumentCount();
1116 bool bAsBody = false;
1117 bool bIsPDF = false;
1118 rtl_TextEncoding eEncoding = ::gsl_getSystemTextEncoding();
1119 SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer();
1120 const SfxFilter *pSfxFlt = 0;
1121 ULONG nDocType = (ULONG)m_aSendAsLB.GetEntryData(m_aSendAsLB.GetSelectEntryPos());
1122 String sExtension = lcl_GetExtensionForDocType(nDocType);
1123 switch( nDocType )
1125 case MM_DOCTYPE_OOO : break;
1126 case MM_DOCTYPE_PDF : bIsPDF = true; break;
1127 case MM_DOCTYPE_WORD:
1129 //the method SwIOSystemGetFilterOfFormat( ) returns the template filter
1130 //because it uses the same user data :-(
1131 SfxFilterMatcher aMatcher( pFilterContainer->GetName() );
1132 SfxFilterMatcherIter aIter( &aMatcher );
1133 const SfxFilter* pFilter = aIter.First();
1134 String sFilterUserData( String::CreateFromAscii( FILTER_WW8 ));
1135 while ( pFilter )
1137 if( pFilter->GetUserData() == sFilterUserData && pFilter->CanExport() )
1139 pSfxFlt = pFilter;
1140 break;
1142 pFilter = aIter.Next();
1146 break;
1147 case MM_DOCTYPE_HTML:
1149 bAsBody = true;
1150 SvxHtmlOptions* pHtmlOptions = SvxHtmlOptions::Get();
1151 eEncoding = pHtmlOptions->GetTextEncoding();
1153 break;
1154 case MM_DOCTYPE_TEXT:
1155 bAsBody = true;
1156 break;
1158 if(!pSfxFlt)
1159 pSfxFlt = pFilterContainer->GetFilter4Extension(sExtension, SFX_FILTER_EXPORT);
1161 if(!pSfxFlt)
1162 return 0;
1163 String sMimeType = pSfxFlt->GetMimeType();
1165 if(!m_aSubjectED.GetText().Len())
1167 SwSendQueryBox_Impl aQuery(pButton, m_sNoSubjectQueryST);
1168 aQuery.SetIsEmptyTextAllowed(true);
1169 aQuery.SetValue(m_sNoSubjectST);
1170 if(RET_OK == aQuery.Execute())
1172 if(aQuery.GetValue() != m_sNoSubjectST)
1173 m_aSubjectED.SetText(aQuery.GetValue());
1175 else
1176 return 0;
1178 if(!bAsBody && !m_aAttachmentED.GetText().Len())
1180 SwSendQueryBox_Impl aQuery(pButton, m_sNoAttachmentNameST);
1181 aQuery.SetIsEmptyTextAllowed(false);
1182 if(RET_OK == aQuery.Execute())
1184 String sAttach(aQuery.GetValue());
1185 xub_StrLen nTokenCount = sAttach.GetTokenCount( '.' );
1186 if( 2 > nTokenCount)
1188 sAttach += '.';
1189 ++nTokenCount;
1191 sAttach.SetToken( nTokenCount - 1, '.', lcl_GetExtensionForDocType(
1192 (ULONG)m_aSendAsLB.GetEntryData(m_aSendAsLB.GetSelectEntryPos())));
1193 m_aAttachmentED.SetText(sAttach);
1195 else
1196 return 0;
1198 SfxStringItem aFilterName( SID_FILTER_NAME, pSfxFlt->GetFilterName() );
1199 String sEMailColumn = m_aMailToLB.GetSelectEntry();
1200 DBG_ASSERT( sEMailColumn.Len(), "No email column selected");
1201 Reference< sdbcx::XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
1202 Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
1203 if(!sEMailColumn.Len() || !xColAccess.is() || !xColAccess->hasByName(sEMailColumn))
1204 return 0;
1206 String sFilterOptions;
1207 if(MM_DOCTYPE_TEXT == nDocType)
1209 SwAsciiOptions aOpt;
1210 USHORT nAppScriptType = GetI18NScriptTypeOfLanguage( (USHORT)GetAppLanguage() );
1211 USHORT nWhich = GetWhichOfScript( RES_CHRATR_LANGUAGE, nAppScriptType);
1212 aOpt.SetLanguage( ((SvxLanguageItem&)pTargetView->GetWrtShell().
1213 GetDefault( nWhich )).GetLanguage());
1214 aOpt.SetParaFlags( LINEEND_CR );
1215 aOpt.WriteUserData( sFilterOptions );
1217 String sTargetTempURL = URIHelper::SmartRel2Abs(
1218 INetURLObject(), utl::TempFile::CreateTempName(),
1219 URIHelper::GetMaybeFileHdl());
1220 const SfxFilter *pTargetSfxFlt = SwIoSystem::GetFilterOfFormat(
1221 String::CreateFromAscii( FILTER_XML ),
1222 SwDocShell::Factory().GetFilterContainer() );
1224 uno::Sequence< beans::PropertyValue > aValues(1);
1225 beans::PropertyValue* pValues = aValues.getArray();
1226 pValues[0].Name = C2U("FilterName");
1227 pValues[0].Value <<= ::rtl::OUString(pTargetSfxFlt->GetFilterName());
1229 uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
1230 xStore->storeToURL( sTargetTempURL, aValues );
1232 pDlg->SetDocumentCount( nEnd );
1233 pDlg->ShowDialog();
1234 //help to force painting the dialog
1235 //TODO/CLEANUP
1236 //Sollbruchstelle
1237 for ( sal_Int16 i = 0; i < 25; i++)
1238 Application::Reschedule();
1239 for(sal_uInt32 nDoc = nBegin; nDoc < nEnd; ++nDoc)
1241 m_pWizard->EnterWait();
1242 SwDocMergeInfo& rInfo = rConfigItem.GetDocumentMergeInfo(nDoc);
1244 //now extract a document from the target document
1245 SfxObjectShellRef xTempDocShell( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
1246 xTempDocShell->DoInitNew( 0 );
1247 SfxViewFrame* pTempFrame = SfxViewFrame::CreateViewFrame( *xTempDocShell, 0, TRUE );
1248 // pTempFrame->GetFrame()->Appear();
1249 SwView* pTempView = static_cast<SwView*>( pTempFrame->GetViewShell() );
1250 pTargetView->GetWrtShell().StartAction();
1251 SwgReaderOption aOpt;
1252 aOpt.SetTxtFmts( sal_True );
1253 aOpt.SetFrmFmts( sal_True );
1254 aOpt.SetPageDescs( sal_True );
1255 aOpt.SetNumRules( sal_True );
1256 aOpt.SetMerge( sal_False );
1257 pTempView->GetDocShell()->LoadStylesFromFile(
1258 sTargetTempURL, aOpt, sal_True );
1259 pTargetView->GetWrtShell().PastePages(pTempView->GetWrtShell(),
1260 (USHORT)rInfo.nStartPageInTarget, (USHORT)rInfo.nEndPageInTarget );
1261 pTargetView->GetWrtShell().EndAction();
1263 //then save it
1264 SfxStringItem aName(SID_FILE_NAME,
1265 URIHelper::SmartRel2Abs(
1266 INetURLObject(), utl::TempFile::CreateTempName(0),
1267 URIHelper::GetMaybeFileHdl()) );
1269 /* if(bIsPDF)
1271 SfxDispatcher* pSfxDispatcher = pTempView->GetViewFrame()->GetDispatcher();
1272 pSfxDispatcher->Execute(
1273 SID_DIRECTEXPORTDOCASPDF,
1274 SFX_CALLMODE_SYNCHRON, &aName, &aFilterName, 0L );
1276 else*/
1278 uno::Sequence< beans::PropertyValue > aFilterValues(MM_DOCTYPE_TEXT == nDocType ? 2 : 1);
1279 beans::PropertyValue* pFilterValues = aFilterValues.getArray();
1280 pFilterValues[0].Name = C2U("FilterName");
1281 pFilterValues[0].Value <<= ::rtl::OUString(pSfxFlt->GetFilterName());
1282 if(MM_DOCTYPE_TEXT == nDocType)
1284 pFilterValues[1].Name = C2U("FilterOptions");
1285 pFilterValues[1].Value <<= ::rtl::OUString(sFilterOptions);
1288 uno::Reference< frame::XStorable > xTempStore( pTempView->GetDocShell()->GetModel(), uno::UNO_QUERY);
1289 xTempStore->storeToURL( aName.GetValue(), aFilterValues );
1291 xTempDocShell->DoClose();
1293 #ifdef DBG_UTIL
1294 sal_Int32 nTarget =
1295 #endif
1296 rConfigItem.MoveResultSet(rInfo.nDBRow);
1297 DBG_ASSERT( nTarget == rInfo.nDBRow, "row of current document could not be selected");
1298 DBG_ASSERT( sEMailColumn.Len(), "No email column selected");
1299 ::rtl::OUString sEMail = lcl_GetColumnValueOf(sEMailColumn, xColAccess);
1300 SwMailDescriptor aDesc;
1301 aDesc.sEMail = sEMail;
1302 rtl::OUString sBody;
1303 if(bAsBody)
1306 //read in the temporary file and use it as mail body
1307 SfxMedium aMedium( aName.GetValue(), STREAM_READ, TRUE);
1308 SvStream* pInStream = aMedium.GetInStream();
1309 if(pInStream)
1310 pInStream->SetStreamCharSet( eEncoding );
1311 else
1313 DBG_ERROR("no output file created?");
1314 continue;
1316 ByteString sLine;
1317 sal_Bool bDone = pInStream->ReadLine( sLine );
1318 while ( bDone )
1320 sBody += rtl::OUString(String(sLine, eEncoding));
1321 sBody += rtl::OUString('\n');
1322 bDone = pInStream->ReadLine( sLine );
1325 //remove the temporary file
1326 SWUnoHelper::UCB_DeleteFile( aName.GetValue() );
1328 else
1330 sBody = m_sBody;
1331 aDesc.sAttachmentURL = aName.GetValue();
1332 String sAttachment(m_aAttachmentED.GetText());
1333 xub_StrLen nTokenCount = sAttachment.GetTokenCount( '.' );
1334 if( 2 > nTokenCount)
1336 sAttachment += '.';
1337 sAttachment.SetToken( nTokenCount, '.', sExtension);
1339 else if(sAttachment.GetToken( nTokenCount - 1, '.') != sExtension)
1340 sAttachment += sExtension;
1341 aDesc.sAttachmentName = sAttachment;
1342 aDesc.sMimeType = sMimeType;
1344 if(rConfigItem.IsGreetingLine(sal_True))
1346 ::rtl::OUString sNameColumn = rConfigItem.GetAssignedColumn(MM_PART_LASTNAME);
1347 ::rtl::OUString sName = lcl_GetColumnValueOf(sNameColumn, xColAccess);
1348 String sGreeting;
1349 if(sName.getLength() && rConfigItem.IsIndividualGreeting(sal_True))
1351 ::rtl::OUString sGenderColumn = rConfigItem.GetAssignedColumn(MM_PART_GENDER);
1352 const ::rtl::OUString& sFemaleValue = rConfigItem.GetFemaleGenderValue();
1353 ::rtl::OUString sGenderValue = lcl_GetColumnValueOf(sGenderColumn, xColAccess);
1354 SwMailMergeConfigItem::Gender eGenderType = sGenderValue == sFemaleValue ?
1355 SwMailMergeConfigItem::FEMALE :
1356 SwMailMergeConfigItem::MALE;
1358 sGreeting = SwAddressPreview::FillData(
1359 rConfigItem.GetGreetings(eGenderType)
1360 [rConfigItem.GetCurrentGreeting(eGenderType)],
1361 rConfigItem);
1363 else
1365 sGreeting =
1366 rConfigItem.GetGreetings(SwMailMergeConfigItem::NEUTRAL)
1367 [rConfigItem.GetCurrentGreeting(SwMailMergeConfigItem::NEUTRAL)];
1370 sGreeting += '\n';
1371 ::rtl::OUString sTemp( sGreeting );
1372 sTemp += sBody;
1373 sBody = sTemp;
1376 aDesc.sBodyContent = sBody;
1377 if(MM_DOCTYPE_HTML == nDocType)
1379 aDesc.sBodyMimeType = ::rtl::OUString::createFromAscii("text/html; charset=");
1380 aDesc.sBodyMimeType += ::rtl::OUString::createFromAscii(
1381 rtl_getBestMimeCharsetFromTextEncoding( eEncoding ));
1383 else
1384 aDesc.sBodyMimeType =
1385 ::rtl::OUString::createFromAscii("text/plain; charset=UTF-8; format=flowed");
1387 aDesc.sSubject = m_aSubjectED.GetText();
1388 aDesc.sCC = m_sCC;
1389 aDesc.sBCC = m_sBCC;
1390 pDlg->AddDocument( aDesc );
1391 //help to force painting the dialog
1392 for ( sal_Int16 i = 0; i < 25; i++)
1393 Application::Reschedule();
1394 //stop creating of data when dialog has been closed
1395 if(!pDlg->IsVisible())
1397 m_pWizard->LeaveWait();
1398 break;
1400 m_pWizard->LeaveWait();
1402 pDlg->EnableDesctruction();
1403 ::osl::File::remove( sTargetTempURL );
1405 m_pWizard->enableButtons(WZB_FINISH, sal_True);
1406 //the dialog deletes itself
1407 //delete pDlg;
1408 return 0;