xref: /aoo41x/main/sw/source/ui/dbui/mmoutputpage.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 #ifdef SW_DLLIMPLEMENTATION
31 #undef SW_DLLIMPLEMENTATION
32 #endif
33 #include <mmoutputpage.hxx>
34 #include <mailmergewizard.hxx>
35 #include <mmconfigitem.hxx>
36 #include <mailmergechildwindow.hxx>
37 #include <mailconfigpage.hxx>
38 #include <cmdid.h>
39 #include <swtypes.hxx>
40 #ifndef _VIEW_HXX
41 #include <view.hxx>
42 #endif
43 #include <wrtsh.hxx>
44 #ifndef _DOCSH_HXX
45 #include <docsh.hxx>
46 #endif
47 #ifndef IDOCUMENTDEVICEACCESS_HXX_INCLUDED
48 #include <IDocumentDeviceAccess.hxx>
49 #endif
50 #include <hintids.hxx>
51 #include <editeng/scripttypeitem.hxx>
52 #include <editeng/langitem.hxx>
53 #include <svl/itemset.hxx>
54 #include <svl/stritem.hxx>
55 #include <svtools/ehdl.hxx>
56 #include <svtools/sfxecode.hxx>
57 #include <vcl/msgbox.hxx>
58 #include <sfx2/dinfdlg.hxx>
59 #include <sfx2/printer.hxx>
60 #include <sfx2/fcontnr.hxx>
61 #include <sfx2/viewfrm.hxx>
62 #include <sfx2/dispatch.hxx>
63 #include <sfx2/docfile.hxx>
64 //#ifndef _SFX_DOCFILT_HACK_HXX
65 //#include <sfx2/docfilt.hxx>
66 //#endif
67 #include <tools/urlobj.hxx>
68 #include <svl/urihelper.hxx>
69 #ifndef _VCL_PRINT_HXX
70 #include <vcl/print.hxx>
71 #endif
72 #include <unotools/tempfile.hxx>
73 #include <osl/file.hxx>
74 #include <mmgreetingspage.hxx>
75 #include <com/sun/star/frame/XStorable.hpp>
76 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
77 #include <com/sun/star/sdb/XColumn.hpp>
78 //#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
79 //#include <com/sun/star/beans/PropertyValue.hpp>
80 //#endif
81 //#ifndef _BASEDLGS_HXX
82 //#include <sfx2/basedlgs.hxx>
83 //#endif
84 #ifndef _DBMGR_HXX
85 #include <dbmgr.hxx>
86 #endif
87 #include <swunohelper.hxx>
88 #include <vos/mutex.hxx>
89 #include <shellio.hxx>
90 #include <svtools/htmlcfg.hxx>
91 #include <sfx2/event.hxx>
92 #include <swevent.hxx>
93 #include <mmoutputpage.hrc>
94 #include <dbui.hxx>
95 #include <dbui.hrc>
96 #include <helpid.h>
97 #include <sfx2/app.hxx>
98 #include <statstr.hrc>
99 #include <unomid.h>
100 
101 using namespace svt;
102 using namespace ::com::sun::star;
103 using namespace ::com::sun::star::uno;
104 
105 /*-- 01.07.2004 16:47:49---------------------------------------------------
106 
107   -----------------------------------------------------------------------*/
108 String lcl_GetExtensionForDocType(sal_uLong nDocType)
109 {
110     String sExtension;
111     switch( nDocType )
112     {
113         case MM_DOCTYPE_OOO : sExtension = String::CreateFromAscii( "odt" ); break;
114         case MM_DOCTYPE_PDF : sExtension = String::CreateFromAscii( "pdf" ); break;
115         case MM_DOCTYPE_WORD: sExtension = String::CreateFromAscii( "doc" ); break;
116         case MM_DOCTYPE_HTML: sExtension = String::CreateFromAscii( "html" ); break;
117         case MM_DOCTYPE_TEXT: sExtension = String::CreateFromAscii( "txt" ); break;
118     }
119     return sExtension;
120 }
121 /*-- 28.06.2004 11:49:21---------------------------------------------------
122 
123   -----------------------------------------------------------------------*/
124 ::rtl::OUString lcl_GetColumnValueOf(const ::rtl::OUString& rColumn, Reference < container::XNameAccess>& rxColAccess )
125 {
126     ::rtl::OUString sRet;
127     if(rxColAccess->hasByName(rColumn))
128     {
129         Any aCol = rxColAccess->getByName(rColumn);
130         Reference< sdb::XColumn > xColumn;
131         aCol >>= xColumn;
132         if(xColumn.is())
133             sRet = xColumn->getString();
134     }
135     return sRet;
136 }
137 /*-- 21.06.2004 14:01:13---------------------------------------------------
138 
139   -----------------------------------------------------------------------*/
140 class SwSaveWarningBox_Impl : public ModalDialog
141 {
142     FixedImage      aWarningImageIM;
143     FixedInfo       aWarningFI;
144 
145     FixedText       aFileNameFT;
146     Edit            aFileNameED;
147 
148     FixedLine       aSeparatorFL;
149     OKButton        aOKPB;
150     CancelButton    aCancelPB;
151 
152     DECL_LINK( ModifyHdl, Edit*);
153 public:
154     SwSaveWarningBox_Impl(Window* pParent, const String& rFileName);
155     ~SwSaveWarningBox_Impl();
156 
157     String          GetFileName() const {return aFileNameED.GetText();}
158 };
159 /*-- 02.07.2004 08:54:42---------------------------------------------------
160 
161   -----------------------------------------------------------------------*/
162 class SwSendQueryBox_Impl : public ModalDialog
163 {
164     FixedImage      aQueryImageIM;
165     FixedInfo       aQueryFI;
166 
167     Edit            aTextED;
168 
169     FixedLine       aSeparatorFL;
170     OKButton        aOKPB;
171     CancelButton    aCancelPB;
172 
173     bool            bIsEmptyAllowed;
174     DECL_LINK( ModifyHdl, Edit*);
175 public:
176     SwSendQueryBox_Impl(Window* pParent, const String& rQueryText);
177     ~SwSendQueryBox_Impl();
178 
179     void            SetValue(const String& rSet)
180                         {
181                             aTextED.SetText(rSet);
182                             ModifyHdl( &aTextED );
183                         }
184     String          GetValue() const {return aTextED.GetText();}
185 
186     void            SetIsEmptyTextAllowed(bool bSet)
187                         {
188                             bIsEmptyAllowed = bSet;
189                             ModifyHdl( &aTextED );
190                         }
191 };
192 
193 /*-- 21.06.2004 14:11:58---------------------------------------------------
194 
195   -----------------------------------------------------------------------*/
196 SwSaveWarningBox_Impl::SwSaveWarningBox_Impl(Window* pParent, const String& rFileName) :
197     ModalDialog(pParent, SW_RES(   DLG_MM_SAVEWARNING )),
198     aWarningImageIM(this,   SW_RES( IM_WARNING   )),
199     aWarningFI(this,        SW_RES( FI_WARNING   )),
200     aFileNameFT(this,       SW_RES( FT_FILENAME  )),
201     aFileNameED(this,       SW_RES( ED_FILENAME  )),
202     aSeparatorFL(this,      SW_RES( FL_SEPARATOR )),
203     aOKPB(this,             SW_RES( PB_OK        )),
204     aCancelPB(this,         SW_RES( PB_CANCEL    ))
205 {
206     FreeResource();
207     aWarningImageIM.SetImage(WarningBox::GetStandardImage());
208     aFileNameED.SetText(rFileName);
209     aFileNameED.SetModifyHdl(LINK(this, SwSaveWarningBox_Impl, ModifyHdl));
210     ModifyHdl( &aFileNameED );
211 }
212 /*-- 21.06.2004 14:11:58---------------------------------------------------
213 
214   -----------------------------------------------------------------------*/
215 SwSaveWarningBox_Impl::~SwSaveWarningBox_Impl()
216 {
217 }
218 /*-- 21.06.2004 14:11:58---------------------------------------------------
219 
220   -----------------------------------------------------------------------*/
221 IMPL_LINK( SwSaveWarningBox_Impl, ModifyHdl, Edit*, pEdit)
222 {
223     aOKPB.Enable(pEdit->GetText().Len() > 0);
224     return 0;
225 }
226 /*-- 02.07.2004 09:02:53---------------------------------------------------
227 
228   -----------------------------------------------------------------------*/
229 SwSendQueryBox_Impl::SwSendQueryBox_Impl(Window* pParent, const String& rText) :
230     ModalDialog(pParent, SW_RES(   DLG_MM_QUERY )),
231     aQueryImageIM( this,    SW_RES( IM_QUERY     )),
232     aQueryFI( this,         SW_RES( FI_QUERY     )),
233     aTextED( this,          SW_RES( ED_TEXT      )),
234     aSeparatorFL(this,      SW_RES( FL_SEPARATOR )),
235     aOKPB(this,             SW_RES( PB_OK        )),
236     aCancelPB(this,         SW_RES( PB_CANCEL    )),
237     bIsEmptyAllowed(true)
238 {
239     FreeResource();
240     aQueryFI.SetText(rText);
241     aQueryImageIM.SetImage(QueryBox::GetStandardImage());
242     aTextED.SetModifyHdl(LINK(this, SwSendQueryBox_Impl, ModifyHdl));
243     ModifyHdl( &aTextED );
244 }
245 /*-- 02.07.2004 08:58:45---------------------------------------------------
246 
247   -----------------------------------------------------------------------*/
248 SwSendQueryBox_Impl::~SwSendQueryBox_Impl()
249 {
250 }
251 /*-- 02.07.2004 08:58:25---------------------------------------------------
252 
253   -----------------------------------------------------------------------*/
254 IMPL_LINK( SwSendQueryBox_Impl, ModifyHdl, Edit*, pEdit)
255 {
256     aOKPB.Enable(bIsEmptyAllowed  || (pEdit->GetText().Len() > 0));
257     return 0;
258 }
259 
260 /*-- 16.04.2004 16:34:48---------------------------------------------------
261 
262   -----------------------------------------------------------------------*/
263 class SwCopyToDialog : public SfxModalDialog
264 {
265     FixedInfo       m_aDescriptionFI;
266     FixedText       m_aCCFT;
267     Edit            m_aCCED;
268     FixedText       m_aBCCFT;
269     Edit            m_aBCCED;
270 
271     FixedInfo       m_aNoteFI;
272     FixedLine       m_aSeparatorFL;
273 
274     OKButton        m_aOK;
275     CancelButton    m_aCancel;
276     HelpButton      m_aHelp;
277 
278 public:
279     SwCopyToDialog(Window* pParent);
280     ~SwCopyToDialog();
281 
282     String          GetCC() {return m_aCCED.GetText();}
283     void            SetCC(const String& rSet) {m_aCCED.SetText(rSet);}
284 
285     String          GetBCC() {return m_aBCCED.GetText();}
286     void            SetBCC(const String& rSet) {m_aBCCED.SetText(rSet);}
287 };
288 
289 /*-- 16.04.2004 16:43:18---------------------------------------------------
290 
291   -----------------------------------------------------------------------*/
292 SwCopyToDialog::SwCopyToDialog(Window* pParent) :
293     SfxModalDialog(pParent, SW_RES(DLG_MM_COPYTO)),
294 #ifdef MSC
295 #pragma warning (disable : 4355)
296 #endif
297     m_aDescriptionFI( this, SW_RES(       FI_DESCRIPTION )),
298     m_aCCFT( this, SW_RES(                FT_CC          )),
299     m_aCCED( this, SW_RES(                ED_CC          )),
300     m_aBCCFT( this, SW_RES(               FT_BCC         )),
301     m_aBCCED( this, SW_RES(               ED_BCC         )),
302     m_aNoteFI( this, SW_RES(              FI_NOTE        )),
303     m_aSeparatorFL( this, SW_RES(         FL_SEPARATOR   )),
304     m_aOK( this, SW_RES(                  PB_OK          )),
305     m_aCancel( this, SW_RES(              PB_CANCEL      )),
306     m_aHelp( this, SW_RES(                PB_HELP        ))
307 #ifdef MSC
308 #pragma warning (default : 4355)
309 #endif
310 {
311     FreeResource();
312 }
313 /*-- 16.04.2004 16:43:10---------------------------------------------------
314 
315   -----------------------------------------------------------------------*/
316 SwCopyToDialog::~SwCopyToDialog()
317 {
318 }
319 
320 /*-- 02.04.2004 13:15:54---------------------------------------------------
321 
322   -----------------------------------------------------------------------*/
323 SwMailMergeOutputPage::SwMailMergeOutputPage( SwMailMergeWizard* _pParent) :
324     svt::OWizardPage( _pParent, SW_RES(DLG_MM_OUTPUT_PAGE)),
325 #ifdef MSC
326 #pragma warning (disable : 4355)
327 #endif
328     m_aHeaderFI(this,           SW_RES(  FI_HEADER           ) ),
329     m_aOptionsFI(this,          SW_RES(  FI_OPTIONS          ) ),
330     m_aSaveStartDocRB(this,     SW_RES(  RB_SAVESTARTDOC     ) ),
331     m_aSaveMergedDocRB(this,    SW_RES(  RB_SAVEMERGEDDOC    ) ),
332     m_aPrintRB(this,            SW_RES(  RB_PRINT            ) ),
333     m_aSendMailRB(this,         SW_RES(  RB_SENDMAIL         ) ),
334 
335     m_aSeparatorFL(this,        SW_RES(  FL_SEPARATOR        ) ),
336 
337     m_aSaveStartDocPB(this,     SW_RES(  PB_SAVESTARTDOC     ) ),
338 
339     m_aSaveAsOneRB(this,        SW_RES(  RB_SAVEASONE        ) ),
340     m_aSaveIndividualRB(this,   SW_RES(  RB_SAVEINDIVIDUAL   ) ),
341     m_aPrintAllRB(this,         SW_RES(  RB_PRINTALL         ) ),
342     m_aSendAllRB( this, SW_RES(       RB_SENDALL             ) ),
343 
344     m_aFromRB(this,             SW_RES(  RB_FROM             ) ),
345     m_aFromNF(this,             SW_RES(  NF_FROM             ) ),
346     m_aToFT(this,               SW_RES(  FT_TO               ) ),
347     m_aToNF(this,               SW_RES(  NF_TO               ) ),
348     m_aSaveNowPB(this,          SW_RES(  PB_SAVENOW          ) ),
349 
350     m_aPrinterFT(this,          SW_RES(  FT_PRINT            ) ),
351     m_aPrinterLB(this,          SW_RES(  LB_PRINT            ) ),
352     m_aPrinterSettingsPB(this,  SW_RES(  PB_PRINTERSETTINGS  ) ),
353     m_aPrintNowPB(this,         SW_RES(  PB_PRINTNOW         ) ),
354 
355     m_aMailToFT( this, SW_RES(        FT_MAILTO              ) ),
356     m_aMailToLB( this, SW_RES(        LB_MAILTO              ) ),
357     m_aCopyToPB( this, SW_RES(        PB_COPYTO              ) ),
358     m_aSubjectFT( this, SW_RES(       FT_SUBJECT             ) ),
359     m_aSubjectED( this, SW_RES(       ED_SUBJECT             ) ),
360     m_aSendAsFT( this, SW_RES(        FT_SENDAS              ) ),
361     m_aSendAsLB( this, SW_RES(        LB_SENDAS              ) ),
362     m_aAttachmentFT( this, SW_RES(    FT_ATTACHMENT              ) ),
363     m_aAttachmentED( this, SW_RES(    ED_ATTACHMENT              ) ),
364     m_aSendAsPB( this, SW_RES(        PB_SENDAS              ) ),
365     m_aSendDocumentsPB( this, SW_RES( PB_SENDDOCUMENTS       ) ),
366 
367     m_sSaveStartST(SW_RES(           ST_SAVESTART  ) ),
368     m_sSaveMergedST(SW_RES(          ST_SAVEMERGED ) ),
369     m_sPrintST(SW_RES(               ST_PRINT      ) ),
370     m_sSendMailST(SW_RES(            ST_SENDMAIL   ) ),
371 
372     m_sDefaultAttachmentST(SW_RES(   ST_DEFAULTATTACHMENT )),
373     m_sNoSubjectQueryST(SW_RES(      ST_SUBJECTQUERY      )),
374     m_sNoSubjectST(SW_RES(           ST_NOSUBJECT )),
375     m_sNoAttachmentNameST(SW_RES(    ST_NOATTACHMENTNAME )),
376     m_sConfigureMail(SW_RES(         ST_CONFIGUREMAIL)),
377 #ifdef MSC
378 #pragma warning (default : 4355)
379 #endif
380     m_bCancelSaving( false ),
381     m_pWizard(_pParent),
382     m_pTempPrinter( 0 ),
383     m_pDocumentPrinterCopy(0)
384 {
385     FreeResource();
386 
387     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
388     // #i51949# hide e-Mail option if e-Mail is not supported
389     if(!rConfigItem.IsMailAvailable())
390         m_aSendMailRB.Hide();
391 
392     Link aLink = LINK(this, SwMailMergeOutputPage, OutputTypeHdl_Impl);
393     m_aSaveStartDocRB.SetClickHdl(aLink);
394     m_aSaveMergedDocRB.SetClickHdl(aLink);
395     m_aPrintRB.SetClickHdl(aLink);
396     m_aSendMailRB.SetClickHdl(aLink);
397     m_aSaveStartDocRB.Check();
398     m_aPrintAllRB.Check();
399     m_aSaveAsOneRB.Check();
400     m_aSendAllRB.Check();
401 
402     m_aSaveStartDocPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, SaveStartHdl_Impl));
403     m_aSaveNowPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, SaveOutputHdl_Impl));
404     m_aPrinterLB.SetSelectHdl(LINK(this, SwMailMergeOutputPage, PrinterChangeHdl_Impl));
405     m_aPrintNowPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, PrintHdl_Impl));
406     m_aPrinterSettingsPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, PrinterSetupHdl_Impl));
407 
408     m_aSendAsPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, SendAsHdl_Impl)),
409     m_aSendDocumentsPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, SendDocumentsHdl_Impl)),
410     m_aSendAsLB.SetSelectHdl(LINK(this, SwMailMergeOutputPage, SendTypeHdl_Impl));
411 
412     m_nFromToRBPos = m_aFromRB.GetPosPixel().Y();
413     m_nFromToFTPos = m_aToFT.GetPosPixel().Y();
414     m_nFromToNFPos = m_aFromNF.GetPosPixel().Y();
415 
416     m_nRBOffset = m_nFromToRBPos - m_aSaveIndividualRB.GetPosPixel().Y();
417 
418     OutputTypeHdl_Impl(&m_aSaveStartDocRB);
419 
420     m_aCopyToPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, CopyToHdl_Impl));
421 
422     m_aSaveAsOneRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
423     m_aSaveIndividualRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
424     m_aPrintAllRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
425     m_aSendAllRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
426 
427     m_aFromRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
428     //#i63267# printing might be disabled
429     m_aPrintRB.Enable(!Application::GetSettings().GetMiscSettings().GetDisablePrinting());
430 }
431 
432 /*-- 02.04.2004 13:15:44---------------------------------------------------
433 
434   -----------------------------------------------------------------------*/
435 SwMailMergeOutputPage::~SwMailMergeOutputPage()
436 {
437     delete m_pTempPrinter;
438     delete m_pDocumentPrinterCopy;
439 }
440 /*-- 31.01.2005 08:38:14---------------------------------------------------
441 
442   -----------------------------------------------------------------------*/
443 void SwMailMergeOutputPage::ActivatePage()
444 {
445     //fill printer ListBox
446     const std::vector<rtl::OUString>& rPrinters = Printer::GetPrinterQueues();
447     unsigned int nCount = rPrinters.size();
448     if ( nCount )
449     {
450         for( unsigned int i = 0; i < nCount; i++ )
451         {
452             m_aPrinterLB.InsertEntry( rPrinters[i] );
453         }
454 
455     }
456     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
457 
458     SwView* pTargetView = rConfigItem.GetTargetView();
459     DBG_ASSERT(pTargetView, "no target view exists");
460     if(pTargetView)
461     {
462         SfxPrinter* pPrinter = pTargetView->GetWrtShell().getIDocumentDeviceAccess()->getPrinter( true );
463         m_aPrinterLB.SelectEntry( pPrinter->GetName() );
464         m_aToNF.SetValue( rConfigItem.GetMergedDocumentCount() );
465         m_aToNF.SetMax( rConfigItem.GetMergedDocumentCount() );
466         m_pDocumentPrinterCopy = pTargetView->GetWrtShell().getIDocumentDeviceAccess()->getPrinter( true )->Clone();
467     }
468     m_aPrinterLB.SelectEntry( rConfigItem.GetSelectedPrinter() );
469 
470     SwView* pSourceView = rConfigItem.GetSourceView();
471     DBG_ASSERT(pSourceView, "no source view exists");
472     if(pSourceView)
473     {
474         SwDocShell* pDocShell = pSourceView->GetDocShell();
475         if ( pDocShell->HasName() )
476         {
477             INetURLObject aTmp( pDocShell->GetMedium()->GetName() );
478             m_aAttachmentED.SetText(aTmp.getName(
479                     INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ));
480         }
481     }
482 }
483 /*-- 05.07.2004 13:54:11---------------------------------------------------
484 
485   -----------------------------------------------------------------------*/
486 bool SwMailMergeOutputPage::canAdvance() const
487 {
488     return false;
489 }
490 /*-- 02.04.2004 13:15:44---------------------------------------------------
491 
492   -----------------------------------------------------------------------*/
493 IMPL_LINK(SwMailMergeOutputPage, OutputTypeHdl_Impl, RadioButton*, pButton)
494 {
495     Control* aControls[] =
496     {
497         &m_aSaveStartDocPB,
498         &m_aSaveAsOneRB, &m_aSaveIndividualRB,
499         &m_aFromRB, &m_aFromNF, &m_aToFT, &m_aToNF,
500         &m_aSaveNowPB,
501         &m_aPrinterFT, &m_aPrinterLB, &m_aPrinterSettingsPB, &m_aPrintAllRB,
502         &m_aPrintNowPB,
503         &m_aMailToFT, &m_aMailToLB, &m_aCopyToPB,
504         &m_aSubjectFT, &m_aSubjectED,
505         &m_aSendAsFT, &m_aSendAsLB, &m_aSendAsPB,
506         &m_aAttachmentFT, &m_aAttachmentED,
507         &m_aSendAllRB, &m_aSendDocumentsPB,
508         0
509     };
510     SetUpdateMode(sal_True);
511     Control** pControl = aControls;
512     do
513     {
514         (*pControl)->Show(sal_False);
515 
516     } while(*(++pControl));
517 
518     if(&m_aSaveStartDocRB == pButton)
519     {
520         m_aSaveStartDocPB.Show();
521         m_aSeparatorFL.SetText(m_sSaveStartST);
522 
523     }
524     else if(&m_aSaveMergedDocRB == pButton)
525     {
526         Control* aSaveMergedControls[] =
527         {
528             &m_aSaveAsOneRB, &m_aSaveIndividualRB,
529             &m_aFromRB, &m_aFromNF, &m_aToFT, &m_aToNF,
530             &m_aSaveNowPB,
531             0
532         };
533         Control** pSaveMergeControl = aSaveMergedControls;
534         do
535         {
536             (*pSaveMergeControl)->Show(sal_True);
537 
538         } while(*(++pSaveMergeControl));
539         if(!m_aFromRB.IsChecked() && !m_aSaveAsOneRB.IsChecked())
540         {
541             m_aSaveIndividualRB.Check();
542         }
543         m_aSeparatorFL.SetText(m_sSaveMergedST);
544         //reposition the from/to line
545         if(m_aFromRB.GetPosPixel().Y() != m_nFromToRBPos)
546         {
547             Point aPos(m_aFromRB.GetPosPixel()); aPos.Y() = m_nFromToRBPos; m_aFromRB.SetPosPixel(aPos);
548             aPos =   m_aToFT.GetPosPixel();      aPos.Y() = m_nFromToFTPos; m_aToFT.SetPosPixel(aPos);
549             aPos =   m_aFromNF.GetPosPixel();    aPos.Y() = m_nFromToNFPos; m_aFromNF.SetPosPixel(aPos);
550             aPos =   m_aToNF.GetPosPixel();      aPos.Y() = m_nFromToNFPos; m_aToNF.SetPosPixel(aPos);
551         }
552     }
553     else if(&m_aPrintRB == pButton)
554     {
555         Control* aPrintControls[] =
556         {
557             &m_aFromRB, &m_aFromNF, &m_aToFT, &m_aToNF,
558             &m_aPrinterFT, &m_aPrinterLB, &m_aPrinterSettingsPB, &m_aPrintAllRB,
559             &m_aPrintNowPB,
560             0
561         };
562         Control** pPrinterControl = aPrintControls;
563         do
564         {
565             (*pPrinterControl)->Show(sal_True);
566 
567         } while(*(++pPrinterControl));
568         if(!m_aFromRB.IsChecked())
569             m_aPrintAllRB.Check();
570 
571         m_aSeparatorFL.SetText(m_sPrintST);
572         //reposition the from/to line
573         long nRB_FT_Offset = m_nFromToRBPos - m_nFromToFTPos;
574         long nNewRBXPos = m_aPrintAllRB.GetPosPixel().Y() + m_nRBOffset;
575 
576         Point aPos(m_aFromRB.GetPosPixel());aPos.Y() = nNewRBXPos;                 m_aFromRB.SetPosPixel(aPos);
577         aPos = m_aToFT.GetPosPixel();       aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aToFT.SetPosPixel(aPos);
578         aPos = m_aFromNF.GetPosPixel();     aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aFromNF.SetPosPixel(aPos);
579         aPos = m_aToNF.GetPosPixel();       aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aToNF.SetPosPixel(aPos);
580     }
581     else /*if(&m_aSendMailRB == pButton)*/
582     {
583         Control* aMailControls[] =
584         {
585             &m_aFromRB, &m_aFromNF, &m_aToFT, &m_aToNF,
586             &m_aMailToFT, &m_aMailToLB, &m_aCopyToPB,
587             &m_aSubjectFT, &m_aSubjectED,
588             &m_aSendAsFT, &m_aSendAsLB, &m_aSendAsPB,
589             &m_aAttachmentFT, &m_aAttachmentED,
590             &m_aSendAllRB, &m_aSendDocumentsPB, 0
591         };
592         Control** pMailControl = aMailControls;
593         do
594         {
595             (*pMailControl)->Show(sal_True);
596 
597         } while(*(++pMailControl));
598 
599         if(!m_aFromRB.IsChecked())
600             m_aSendAllRB.Check();
601         if(!m_aAttachmentED.GetText().Len())
602         {
603             String sAttach( m_sDefaultAttachmentST );
604             sAttach += '.';
605             sAttach += lcl_GetExtensionForDocType(
606                         (sal_uLong)m_aSendAsLB.GetEntryData(m_aSendAsLB.GetSelectEntryPos()));
607             m_aAttachmentED.SetText( sAttach );
608 
609         }
610         m_aSeparatorFL.SetText(m_sSendMailST);
611         //fill mail address ListBox
612         if(!m_aMailToLB.GetEntryCount())
613         {
614             SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
615             //select first column
616             uno::Reference< sdbcx::XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), uno::UNO_QUERY);
617             //get the name of the actual columns
618             uno::Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
619             uno::Sequence< ::rtl::OUString > aFields;
620             if(xColAccess.is())
621                 aFields = xColAccess->getElementNames();
622             const ::rtl::OUString* pFields = aFields.getConstArray();
623             for(sal_Int32 nField = 0; nField < aFields.getLength(); ++nField)
624                 m_aMailToLB.InsertEntry(pFields[nField]);
625 
626             m_aMailToLB.SelectEntryPos(0);
627             // then select the right one - may not be available
628             const ResStringArray& rHeaders = rConfigItem.GetDefaultAddressHeaders();
629             String sEMailColumn = rHeaders.GetString( MM_PART_E_MAIL );
630             Sequence< ::rtl::OUString> aAssignment =
631                             rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
632             if(aAssignment.getLength() > MM_PART_E_MAIL && aAssignment[MM_PART_E_MAIL].getLength())
633                 sEMailColumn = aAssignment[MM_PART_E_MAIL];
634             m_aMailToLB.SelectEntry(sEMailColumn);
635             // HTML format pre-selected
636             m_aSendAsLB.SelectEntryPos(3);
637             SendTypeHdl_Impl(&m_aSendAsLB);
638         }
639         if(m_aSendAllRB.GetPosPixel().Y() + m_nRBOffset != m_aFromRB.GetPosPixel().Y())
640         {
641             long nRB_FT_Offset = m_nFromToRBPos - m_nFromToFTPos;
642             long nNewRBXPos = m_aSendAllRB.GetPosPixel().Y() + m_nRBOffset;
643 
644             Point aPos(m_aFromRB.GetPosPixel());aPos.Y() = nNewRBXPos;                 m_aFromRB.SetPosPixel(aPos);
645             aPos = m_aToFT.GetPosPixel();       aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aToFT.SetPosPixel(aPos);
646             aPos = m_aFromNF.GetPosPixel();     aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aFromNF.SetPosPixel(aPos);
647             aPos = m_aToNF.GetPosPixel();       aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aToNF.SetPosPixel(aPos);
648         }
649     }
650     m_aFromRB.GetClickHdl().Call(m_aFromRB.IsChecked() ? &m_aFromRB : 0);
651 
652     SetUpdateMode(sal_False);
653     return 0;
654 }
655 /*-- 22.08.2005 12:15:10---------------------------------------------------
656 
657   -----------------------------------------------------------------------*/
658 IMPL_LINK(SwMailMergeOutputPage, DocumentSelectionHdl_Impl, RadioButton*, pButton)
659 {
660     sal_Bool bEnableFromTo = pButton == &m_aFromRB;
661     m_aFromNF.Enable(bEnableFromTo);
662     m_aToFT.Enable(bEnableFromTo);
663     m_aToNF.Enable(bEnableFromTo);
664     return 0;
665 }
666 
667 /*-- 16.04.2004 16:45:10---------------------------------------------------
668 
669   -----------------------------------------------------------------------*/
670 IMPL_LINK(SwMailMergeOutputPage, CopyToHdl_Impl, PushButton*, pButton)
671 {
672     SwCopyToDialog* pDlg = new SwCopyToDialog(pButton);
673     pDlg->SetCC(m_sCC );
674     pDlg->SetBCC(m_sBCC);
675     if(RET_OK == pDlg->Execute())
676     {
677         m_sCC =     pDlg->GetCC() ;
678         m_sBCC =    pDlg->GetBCC();
679     }
680     delete pDlg;
681     return 0;
682 }
683 /*-- 17.05.2004 13:51:02---------------------------------------------------
684 
685   -----------------------------------------------------------------------*/
686 IMPL_LINK(SwMailMergeOutputPage, SaveStartHdl_Impl, PushButton*, pButton)
687 {
688     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
689     SwView* pSourceView = rConfigItem.GetSourceView();
690     DBG_ASSERT( pSourceView, "source view missing");
691     if(pSourceView)
692     {
693         SfxViewFrame* pSourceViewFrm = pSourceView->GetViewFrame();
694         uno::Reference< frame::XFrame > xFrame =
695                 pSourceViewFrm->GetFrame().GetFrameInterface();
696         xFrame->getContainerWindow()->setVisible(sal_True);
697         pSourceViewFrm->GetDispatcher()->Execute(SID_SAVEDOC, SFX_CALLMODE_SYNCHRON);
698         xFrame->getContainerWindow()->setVisible(sal_False);
699         SwDocShell* pDocShell = pSourceView->GetDocShell();
700         //if the document has been saved it's URL has to be stored for
701         // later use and it can be closed now
702         if(pDocShell->HasName() && !pDocShell->IsModified())
703         {
704             INetURLObject aURL = pDocShell->GetMedium()->GetURLObject();
705             //update the attachment name
706             if(!m_aAttachmentED.GetText().Len())
707             {
708                 if ( pDocShell->HasName() )
709                 {
710                     m_aAttachmentED.SetText(aURL.getName(
711                             INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ));
712                 }
713             }
714 
715             rConfigItem.AddSavedDocument(
716                     aURL.GetMainURL(INetURLObject::DECODE_TO_IURI));
717             pButton->Enable(sal_False);
718             m_pWizard->enableButtons(WZB_FINISH, sal_True);
719             pButton->Enable(sal_False);
720 
721         }
722     }
723     return 0;
724 }
725 /*-- 17.07.2008 08:09:06---------------------------------------------------
726 
727   -----------------------------------------------------------------------*/
728 IMPL_LINK(SwMailMergeOutputPage, SaveCancelHdl_Impl, Button*, EMPTYARG )
729 {
730     m_bCancelSaving = true;
731     return 0;
732 }
733 /*-- 17.05.2004 13:51:02---------------------------------------------------
734 
735   -----------------------------------------------------------------------*/
736 IMPL_LINK(SwMailMergeOutputPage, SaveOutputHdl_Impl, PushButton*, pButton)
737 {
738     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
739     SwView* pTargetView = rConfigItem.GetTargetView();
740     DBG_ASSERT(pTargetView, "no target view exists");
741     if(!pTargetView)
742         return 0;
743 
744     if(m_aSaveAsOneRB.IsChecked())
745     {
746         String sFilter;
747         String sPath = SwMailMergeHelper::CallSaveAsDialog(sFilter);
748         if(!sPath.Len())
749             return 0;
750         uno::Sequence< beans::PropertyValue > aValues(1);
751         beans::PropertyValue* pValues = aValues.getArray();
752         pValues[0].Name = C2U("FilterName");
753         pValues[0].Value <<= ::rtl::OUString(sFilter);
754 
755         uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
756         sal_uInt32 nErrorCode = ERRCODE_NONE;
757         try
758         {
759             xStore->storeToURL( sPath, aValues );
760         }
761         catch( task::ErrorCodeIOException& aErrorEx )
762         {
763             nErrorCode = (sal_uInt32)aErrorEx.ErrCode;
764         }
765         catch( Exception& )
766         {
767             nErrorCode = ERRCODE_IO_GENERAL;
768         }
769         if( nErrorCode != ERRCODE_NONE )
770         {
771             SfxErrorContext aEc(ERRCTX_SFX_SAVEASDOC, pTargetView->GetDocShell()->GetTitle());
772             ErrorHandler::HandleError( nErrorCode );
773         }
774     }
775     else
776     {
777         sal_uInt32 nBegin = 0;
778         sal_uInt32 nEnd = 0;
779         if(m_aSaveIndividualRB.IsChecked())
780         {
781             nBegin = 0;
782             nEnd = rConfigItem.GetMergedDocumentCount();
783         }
784         else
785         {
786             nBegin  = static_cast< sal_Int32 >(m_aFromNF.GetValue() - 1);
787             nEnd    = static_cast< sal_Int32 >(m_aToNF.GetValue());
788             if(nEnd > rConfigItem.GetMergedDocumentCount())
789                 nEnd = rConfigItem.GetMergedDocumentCount();
790         }
791         String sFilter;
792         String sPath = SwMailMergeHelper::CallSaveAsDialog(sFilter);
793         if(!sPath.Len())
794             return 0;
795         String sTargetTempURL = URIHelper::SmartRel2Abs(
796             INetURLObject(), utl::TempFile::CreateTempName(),
797             URIHelper::GetMaybeFileHdl());
798         const SfxFilter *pSfxFlt = SwIoSystem::GetFilterOfFormat(
799                 String::CreateFromAscii( FILTER_XML ),
800                 SwDocShell::Factory().GetFilterContainer() );
801 
802         uno::Sequence< beans::PropertyValue > aValues(1);
803         beans::PropertyValue* pValues = aValues.getArray();
804         pValues[0].Name = C2U("FilterName");
805         pValues[0].Value <<= ::rtl::OUString(pSfxFlt->GetFilterName());
806 
807         uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
808         sal_uInt32 nErrorCode = ERRCODE_NONE;
809         try
810         {
811             xStore->storeToURL( sTargetTempURL, aValues );
812         }
813         catch( task::ErrorCodeIOException& aErrorEx )
814         {
815             nErrorCode = (sal_uInt32)aErrorEx.ErrCode;
816         }
817         catch( Exception& )
818         {
819             nErrorCode = ERRCODE_IO_GENERAL;
820         }
821         if( nErrorCode != ERRCODE_NONE )
822         {
823             SfxErrorContext aEc(ERRCTX_SFX_SAVEASDOC, pTargetView->GetDocShell()->GetTitle());
824             ErrorHandler::HandleError( nErrorCode );
825         }
826 
827         SwView* pSourceView = rConfigItem.GetSourceView();
828         PrintMonitor aSaveMonitor(this, PrintMonitor::MONITOR_TYPE_SAVE);
829         aSaveMonitor.aDocName.SetText(pSourceView->GetDocShell()->GetTitle(22));
830         aSaveMonitor.aCancel.SetClickHdl(LINK(this, SwMailMergeOutputPage, SaveCancelHdl_Impl));
831         aSaveMonitor.aPrinter.SetText( INetURLObject( sPath ).getFSysPath( INetURLObject::FSYS_DETECT ) );
832 	    aSaveMonitor.ResizeControls();
833 
834         m_bCancelSaving = false;
835         aSaveMonitor.Show();
836         m_pWizard->enableButtons(WZB_CANCEL, sal_False);
837 
838         for(sal_uInt32 nDoc = nBegin; nDoc < nEnd && !m_bCancelSaving; ++nDoc)
839         {
840             SwDocMergeInfo& rInfo = rConfigItem.GetDocumentMergeInfo(nDoc);
841             INetURLObject aURL(sPath);
842             String sFile = aURL.GetBase();
843             String sExtension = aURL.getExtension();
844             if(!sExtension.Len())
845             {
846                 sExtension = pSfxFlt->GetWildcard()().GetToken(1, '.');
847                 sPath += '.';
848                 sPath += sExtension;
849             }
850             String sStat(SW_RES(STR_STATSTR_LETTER));
851             sStat += ' ';
852             sStat += String::CreateFromInt32( nDoc );
853             aSaveMonitor.aPrintInfo.SetText(sStat);
854 
855             //now extract a document from the target document
856             // the shell will be closed at the end, but it is more safe to use SfxObjectShellLock here
857             SfxObjectShellLock xTempDocShell( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
858             xTempDocShell->DoInitNew( 0 );
859             SfxViewFrame* pTempFrame = SfxViewFrame::LoadHiddenDocument( *xTempDocShell, 0 );
860 //            pTempFrame->GetFrame().Appear();
861             SwView* pTempView = static_cast<SwView*>( pTempFrame->GetViewShell() );
862             pTargetView->GetWrtShell().StartAction();
863             SwgReaderOption aOpt;
864             aOpt.SetTxtFmts( sal_True );
865             aOpt.SetFrmFmts( sal_True );
866             aOpt.SetPageDescs( sal_True );
867             aOpt.SetNumRules( sal_True );
868             aOpt.SetMerge( sal_False );
869             pTempView->GetDocShell()->LoadStylesFromFile(
870                     sTargetTempURL, aOpt, sal_True );
871 
872             pTargetView->GetWrtShell().PastePages(pTempView->GetWrtShell(),
873                     (sal_uInt16)rInfo.nStartPageInTarget, (sal_uInt16)rInfo.nEndPageInTarget );
874             pTargetView->GetWrtShell().EndAction();
875             //then save it
876             String sOutPath = aURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
877             String sCounter('_');
878             sCounter += String::CreateFromInt32(nDoc);
879             sOutPath.Insert(sCounter, sOutPath.Len() - sExtension.Len() - 1);
880             //SfxStringItem aName(SID_FILE_NAME, sOutPath);
881             //SfxStringItem aFilter(SID_FILTER_NAME, sFilter);
882 
883             while(true)
884             {
885                 //time for other slots is needed
886                 for(sal_Int16 r = 0; r < 10; ++r)
887                     Application::Reschedule();
888                 bool bFailed = false;
889                 try
890                 {
891                     pValues[0].Value <<= ::rtl::OUString(sFilter);
892                     uno::Reference< frame::XStorable > xTempStore( xTempDocShell->GetModel(), uno::UNO_QUERY);
893                     xTempStore->storeToURL( sOutPath, aValues   );
894                 }
895                 catch( const uno::Exception& )
896                 {
897                     bFailed = true;
898                 }
899 
900                 if(bFailed)
901                 {
902                     SwSaveWarningBox_Impl aWarning( pButton, sOutPath );
903                     if(RET_OK == aWarning.Execute())
904                         sOutPath = aWarning.GetFileName();
905                     else
906                     {
907                         xTempDocShell->DoClose();
908                         return 0;
909                     }
910                 }
911                 else
912                 {
913                     xTempDocShell->DoClose();
914                     break;
915                 }
916             }
917         }
918         ::osl::File::remove( sTargetTempURL );
919     }
920     m_pWizard->enableButtons(WZB_CANCEL, sal_True);
921     m_pWizard->enableButtons(WZB_FINISH, sal_True);
922     return 0;
923 }
924 /*-- 22.06.2004 11:51:30---------------------------------------------------
925 
926   -----------------------------------------------------------------------*/
927 IMPL_LINK(SwMailMergeOutputPage, PrinterChangeHdl_Impl, ListBox*, pBox)
928 {
929     if( m_pDocumentPrinterCopy && pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
930     {
931         const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), false );
932 
933         if( pInfo )
934         {
935             if ( !m_pTempPrinter )
936             {
937                 if( (m_pDocumentPrinterCopy->GetName() == pInfo->GetPrinterName()) &&
938                      (m_pDocumentPrinterCopy->GetDriverName() == pInfo->GetDriver()) )
939                     m_pTempPrinter = new Printer( m_pDocumentPrinterCopy->GetJobSetup() );
940                 else
941                     m_pTempPrinter = new Printer( *pInfo );
942             }
943             else
944             {
945                 if( (m_pTempPrinter->GetName() != pInfo->GetPrinterName()) ||
946                      (m_pTempPrinter->GetDriverName() != pInfo->GetDriver()) )
947                 {
948                     delete m_pTempPrinter;
949                     m_pTempPrinter = new Printer( *pInfo );
950                 }
951             }
952         }
953         else if( ! m_pTempPrinter )
954             m_pTempPrinter = new Printer();
955 
956         m_aPrinterSettingsPB.Enable( m_pTempPrinter->HasSupport( SUPPORT_SETUPDIALOG ) );
957     }
958     else
959         m_aPrinterSettingsPB.Disable();
960     m_pWizard->GetConfigItem().SetSelectedPrinter( pBox->GetSelectEntry() );
961 
962 //    return m_pTempPrinter;
963     return 0;
964 }
965 
966 /*-- 17.05.2004 13:51:02---------------------------------------------------
967 
968   -----------------------------------------------------------------------*/
969 IMPL_LINK(SwMailMergeOutputPage, PrintHdl_Impl, PushButton*, EMPTYARG)
970 {
971     SwView* pTargetView = m_pWizard->GetConfigItem().GetTargetView();
972     DBG_ASSERT(pTargetView, "no target view exists");
973     if(!pTargetView)
974         return 0;
975 
976     sal_uInt32 nBegin = 0;
977     sal_uInt32 nEnd = 0;
978     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
979     if(m_aPrintAllRB.IsChecked())
980     {
981         nBegin = 0;
982         nEnd = rConfigItem.GetMergedDocumentCount();
983     }
984     else
985     {
986         nBegin  = static_cast< sal_Int32 >(m_aFromNF.GetValue() - 1);
987         nEnd    = static_cast< sal_Int32 >(m_aToNF.GetValue());
988         if(nEnd > rConfigItem.GetMergedDocumentCount())
989             nEnd = rConfigItem.GetMergedDocumentCount();
990     }
991     rConfigItem.SetPrintRange( (sal_uInt16)nBegin, (sal_uInt16)nEnd );
992     SwDocMergeInfo& rStartInfo = rConfigItem.GetDocumentMergeInfo(nBegin);
993     SwDocMergeInfo& rEndInfo = rConfigItem.GetDocumentMergeInfo(nEnd - 1);
994 
995     rtl::OUString sPages(rtl::OUString::valueOf( rStartInfo.nStartPageInTarget ));
996     sPages += rtl::OUString::createFromAscii( " - ");
997     sPages += rtl::OUString::valueOf(  rEndInfo.nEndPageInTarget );
998 
999     SwWrtShell& rSh = pTargetView->GetWrtShell();
1000     pTargetView->SetMailMergeConfigItem(&rConfigItem, 0, sal_False);
1001     if(m_pTempPrinter)
1002     {
1003         m_pDocumentPrinterCopy->SetPrinterProps(m_pTempPrinter);
1004         pTargetView->SetPrinter(m_pDocumentPrinterCopy->Clone());
1005     }
1006 
1007     SfxObjectShell* pObjSh = pTargetView->GetViewFrame()->GetObjectShell();
1008     SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE), pObjSh));
1009     rSh.GetNewDBMgr()->SetMergeType( DBMGR_MERGE_DOCUMENTS );
1010     //SfxDispatcher *pDis = pTargetView->GetViewFrame()->GetDispatcher();
1011     SfxBoolItem aMergeSilent(SID_SILENT, sal_False);
1012     m_pWizard->enableButtons(WZB_CANCEL, sal_False);
1013 
1014     uno::Sequence < beans::PropertyValue > aProps( 2 );
1015     aProps[0]. Name = rtl::OUString::createFromAscii("MonitorVisible");
1016     aProps[0].Value <<= sal_True;
1017     aProps[1]. Name = rtl::OUString::createFromAscii("Pages");
1018     aProps[1]. Value <<= sPages;
1019 
1020     pTargetView->ExecPrint( aProps, false, true );
1021     SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE_END, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE_END), pObjSh));
1022 
1023     pTargetView->SetMailMergeConfigItem(0, 0, sal_False);
1024     m_pWizard->enableButtons(WZB_CANCEL, sal_True);
1025     m_pWizard->enableButtons(WZB_FINISH, sal_True);
1026     return 0;
1027 }
1028 /*-- 17.05.2004 13:51:02---------------------------------------------------
1029 
1030   -----------------------------------------------------------------------*/
1031 IMPL_LINK(SwMailMergeOutputPage, PrinterSetupHdl_Impl, PushButton*, pButton)
1032 {
1033     if( !m_pTempPrinter )
1034         PrinterChangeHdl_Impl(&m_aPrinterLB);
1035     if(m_pTempPrinter)
1036         m_pTempPrinter->Setup(pButton);
1037     return 0;
1038 }
1039 /*-- 14.06.2004 09:34:01---------------------------------------------------
1040 
1041   -----------------------------------------------------------------------*/
1042 IMPL_LINK(SwMailMergeOutputPage, SendTypeHdl_Impl, ListBox*, pBox)
1043 {
1044     sal_uLong nDocType = (sal_uLong)pBox->GetEntryData(pBox->GetSelectEntryPos());
1045     sal_Bool bEnable = MM_DOCTYPE_HTML != nDocType && MM_DOCTYPE_TEXT != nDocType;
1046     m_aSendAsPB.Enable( bEnable );
1047     m_aAttachmentFT.Enable( bEnable );
1048     m_aAttachmentED.Enable( bEnable );
1049     if(bEnable)
1050     {
1051         //add the correct extension
1052         String sAttach(m_aAttachmentED.GetText());
1053         //do nothing if the user has removed the name - the warning will come early enough
1054         if(sAttach.Len())
1055         {
1056             xub_StrLen nTokenCount = sAttach.GetTokenCount( '.' );
1057             if( 2 > nTokenCount)
1058             {
1059                 sAttach += '.';
1060                 ++nTokenCount;
1061             }
1062             sAttach.SetToken( nTokenCount - 1, '.', lcl_GetExtensionForDocType( nDocType ));
1063             m_aAttachmentED.SetText(sAttach);
1064         }
1065     }
1066     return 0;
1067 }
1068 /*-- 17.05.2004 13:51:02---------------------------------------------------
1069 
1070   -----------------------------------------------------------------------*/
1071 IMPL_LINK(SwMailMergeOutputPage, SendAsHdl_Impl, PushButton*, pButton)
1072 {
1073     SwMailBodyDialog* pDlg = new SwMailBodyDialog(pButton, m_pWizard);
1074     pDlg->SetBody(m_sBody);
1075     if(RET_OK == pDlg->Execute())
1076     {
1077         m_sBody = pDlg->GetBody();
1078     }
1079     return 0;
1080 }
1081 /*-- 21.05.2004 12:03:25---------------------------------------------------
1082     Send documents as e-mail
1083   -----------------------------------------------------------------------*/
1084 IMPL_LINK(SwMailMergeOutputPage, SendDocumentsHdl_Impl, PushButton*, pButton)
1085 {
1086     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
1087 
1088     //get the composed document
1089     SwView* pTargetView = rConfigItem.GetTargetView();
1090     DBG_ASSERT(pTargetView, "no target view exists");
1091     if(!pTargetView)
1092         return 0;
1093 
1094     if(!rConfigItem.GetMailServer().getLength() ||
1095             !SwMailMergeHelper::CheckMailAddress(rConfigItem.GetMailAddress()) )
1096     {
1097         QueryBox aQuery(pButton, WB_YES_NO_CANCEL, m_sConfigureMail);
1098         sal_uInt16 nRet = aQuery.Execute();
1099         if(RET_YES == nRet )
1100         {
1101             SfxAllItemSet aSet(pTargetView->GetPool());
1102             SwMailConfigDlg* pDlg = new SwMailConfigDlg(pButton, aSet);
1103             nRet = pDlg->Execute();
1104             delete pDlg;
1105         }
1106 
1107         if(nRet != RET_OK && nRet != RET_YES)
1108             return 0;
1109     }
1110     //add the documents
1111     sal_uInt32 nBegin = 0;
1112     sal_uInt32 nEnd = 0;
1113     if(m_aSendAllRB.IsChecked())
1114     {
1115         nBegin = 0;
1116         nEnd = rConfigItem.GetMergedDocumentCount();
1117     }
1118     else
1119     {
1120         nBegin  = static_cast< sal_Int32 >(m_aFromNF.GetValue() - 1);
1121         nEnd    = static_cast< sal_Int32 >(m_aToNF.GetValue());
1122         if(nEnd > rConfigItem.GetMergedDocumentCount())
1123             nEnd = rConfigItem.GetMergedDocumentCount();
1124     }
1125     bool bAsBody = false;
1126     bool bIsPDF = false;
1127     rtl_TextEncoding eEncoding = ::gsl_getSystemTextEncoding();
1128     SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer();
1129     const SfxFilter *pSfxFlt = 0;
1130     sal_uLong nDocType = (sal_uLong)m_aSendAsLB.GetEntryData(m_aSendAsLB.GetSelectEntryPos());
1131     String sExtension = lcl_GetExtensionForDocType(nDocType);
1132     switch( nDocType )
1133     {
1134         case MM_DOCTYPE_OOO : break;
1135         case MM_DOCTYPE_PDF : bIsPDF = true;
1136         {
1137             //the method SwIOSystemGetFilterOfFormat( ) returns the template filter
1138             //because it uses the same user data :-(
1139             SfxFilterMatcher aMatcher( pFilterContainer->GetName() );
1140             SfxFilterMatcherIter aIter( &aMatcher );
1141             const SfxFilter* pFilter = aIter.First();
1142             String sFilterMime( String::CreateFromAscii( "application/pdf" ));
1143             while ( pFilter )
1144             {
1145                 if( pFilter->GetMimeType() == sFilterMime  && pFilter->CanExport() )
1146                 {
1147                     pSfxFlt = pFilter;
1148                     break;
1149                 }
1150                 pFilter = aIter.Next();
1151             }
1152 
1153         }
1154         break;
1155         case MM_DOCTYPE_WORD:
1156         {
1157             //the method SwIOSystemGetFilterOfFormat( ) returns the template filter
1158             //because it uses the same user data :-(
1159             SfxFilterMatcher aMatcher( pFilterContainer->GetName() );
1160             SfxFilterMatcherIter aIter( &aMatcher );
1161             const SfxFilter* pFilter = aIter.First();
1162             String sFilterUserData( String::CreateFromAscii( FILTER_WW8 ));
1163             while ( pFilter )
1164             {
1165                 if( pFilter->GetUserData() == sFilterUserData   && pFilter->CanExport() )
1166                 {
1167                     pSfxFlt = pFilter;
1168                     break;
1169                 }
1170                 pFilter = aIter.Next();
1171             }
1172 
1173         }
1174         break;
1175         case MM_DOCTYPE_HTML:
1176         {
1177             bAsBody = true;
1178             SvxHtmlOptions* pHtmlOptions = SvxHtmlOptions::Get();
1179             eEncoding = pHtmlOptions->GetTextEncoding();
1180         }
1181         break;
1182         case MM_DOCTYPE_TEXT:
1183             bAsBody = true;
1184         break;
1185     }
1186     if(!pSfxFlt)
1187         pSfxFlt = pFilterContainer->GetFilter4Extension(sExtension, SFX_FILTER_EXPORT);
1188 
1189     if(!pSfxFlt)
1190         return 0;
1191     String sMimeType = pSfxFlt->GetMimeType();
1192 
1193     if(!m_aSubjectED.GetText().Len())
1194     {
1195         SwSendQueryBox_Impl aQuery(pButton, m_sNoSubjectQueryST);
1196         aQuery.SetIsEmptyTextAllowed(true);
1197         aQuery.SetValue(m_sNoSubjectST);
1198         if(RET_OK == aQuery.Execute())
1199         {
1200             if(aQuery.GetValue() != m_sNoSubjectST)
1201                 m_aSubjectED.SetText(aQuery.GetValue());
1202         }
1203         else
1204             return 0;
1205     }
1206     if(!bAsBody && !m_aAttachmentED.GetText().Len())
1207     {
1208         SwSendQueryBox_Impl aQuery(pButton, m_sNoAttachmentNameST);
1209         aQuery.SetIsEmptyTextAllowed(false);
1210         if(RET_OK == aQuery.Execute())
1211         {
1212             String sAttach(aQuery.GetValue());
1213             xub_StrLen nTokenCount = sAttach.GetTokenCount( '.' );
1214             if( 2 > nTokenCount)
1215             {
1216                 sAttach += '.';
1217                 ++nTokenCount;
1218             }
1219             sAttach.SetToken( nTokenCount - 1, '.', lcl_GetExtensionForDocType(
1220                      (sal_uLong)m_aSendAsLB.GetEntryData(m_aSendAsLB.GetSelectEntryPos())));
1221             m_aAttachmentED.SetText(sAttach);
1222         }
1223         else
1224             return 0;
1225     }
1226     SfxStringItem aFilterName( SID_FILTER_NAME, pSfxFlt->GetFilterName() );
1227     String sEMailColumn = m_aMailToLB.GetSelectEntry();
1228     DBG_ASSERT( sEMailColumn.Len(), "No email column selected");
1229     Reference< sdbcx::XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
1230     Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
1231     if(!sEMailColumn.Len() || !xColAccess.is() || !xColAccess->hasByName(sEMailColumn))
1232         return 0;
1233 
1234     String sFilterOptions;
1235     if(MM_DOCTYPE_TEXT == nDocType)
1236     {
1237         SwAsciiOptions aOpt;
1238         sal_uInt16 nAppScriptType = GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage() );
1239         sal_uInt16 nWhich = GetWhichOfScript( RES_CHRATR_LANGUAGE, nAppScriptType);
1240         aOpt.SetLanguage( ((SvxLanguageItem&)pTargetView->GetWrtShell().
1241                             GetDefault( nWhich )).GetLanguage());
1242         aOpt.SetParaFlags( LINEEND_CR );
1243         aOpt.WriteUserData( sFilterOptions );
1244     }
1245     String sTargetTempURL = URIHelper::SmartRel2Abs(
1246         INetURLObject(), utl::TempFile::CreateTempName(),
1247         URIHelper::GetMaybeFileHdl());
1248     const SfxFilter *pTargetSfxFlt = SwIoSystem::GetFilterOfFormat(
1249             String::CreateFromAscii( FILTER_XML ),
1250             SwDocShell::Factory().GetFilterContainer() );
1251 
1252     uno::Sequence< beans::PropertyValue > aValues(1);
1253     beans::PropertyValue* pValues = aValues.getArray();
1254     pValues[0].Name = C2U("FilterName");
1255     pValues[0].Value <<= ::rtl::OUString(pTargetSfxFlt->GetFilterName());
1256 
1257     uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
1258     xStore->storeToURL( sTargetTempURL, aValues   );
1259 
1260     //create the send dialog
1261     SwSendMailDialog* pDlg = new SwSendMailDialog( pButton, rConfigItem );
1262     pDlg->SetDocumentCount( nEnd );
1263     pDlg->ShowDialog();
1264     //help to force painting the dialog
1265     //TODO/CLEANUP
1266     //Sollbruchstelle
1267     for ( sal_Int16 i = 0; i < 25; i++)
1268         Application::Reschedule();
1269     for(sal_uInt32 nDoc = nBegin; nDoc < nEnd; ++nDoc)
1270     {
1271         m_pWizard->EnterWait();
1272         SwDocMergeInfo& rInfo = rConfigItem.GetDocumentMergeInfo(nDoc);
1273 
1274         //now extract a document from the target document
1275         // the shell will be closed at the end, but it is more safe to use SfxObjectShellLock here
1276         SfxObjectShellLock xTempDocShell( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
1277         xTempDocShell->DoInitNew( 0 );
1278         SfxViewFrame* pTempFrame = SfxViewFrame::LoadHiddenDocument( *xTempDocShell, 0 );
1279 //        pTempFrame->GetFrame().Appear();
1280         SwView* pTempView = static_cast<SwView*>( pTempFrame->GetViewShell() );
1281         pTargetView->GetWrtShell().StartAction();
1282         SwgReaderOption aOpt;
1283         aOpt.SetTxtFmts( sal_True );
1284         aOpt.SetFrmFmts( sal_True );
1285         aOpt.SetPageDescs( sal_True );
1286         aOpt.SetNumRules( sal_True );
1287         aOpt.SetMerge( sal_False );
1288         pTempView->GetDocShell()->LoadStylesFromFile(
1289                 sTargetTempURL, aOpt, sal_True );
1290         pTargetView->GetWrtShell().PastePages(pTempView->GetWrtShell(),
1291                 (sal_uInt16)rInfo.nStartPageInTarget, (sal_uInt16)rInfo.nEndPageInTarget );
1292         pTargetView->GetWrtShell().EndAction();
1293 
1294         //then save it
1295         SfxStringItem aName(SID_FILE_NAME,
1296                 URIHelper::SmartRel2Abs(
1297                     INetURLObject(), utl::TempFile::CreateTempName(0),
1298                     URIHelper::GetMaybeFileHdl()) );
1299 
1300 /*        if(bIsPDF)
1301         {
1302             SfxDispatcher* pSfxDispatcher = pTempView->GetViewFrame()->GetDispatcher();
1303             pSfxDispatcher->Execute(
1304                             SID_DIRECTEXPORTDOCASPDF,
1305                                   SFX_CALLMODE_SYNCHRON, &aName, &aFilterName, 0L );
1306         }
1307         else*/
1308         {
1309             uno::Sequence< beans::PropertyValue > aFilterValues(MM_DOCTYPE_TEXT == nDocType ? 2 : 1);
1310             beans::PropertyValue* pFilterValues = aFilterValues.getArray();
1311             pFilterValues[0].Name = C2U("FilterName");
1312             pFilterValues[0].Value <<= ::rtl::OUString(pSfxFlt->GetFilterName());
1313             if(MM_DOCTYPE_TEXT == nDocType)
1314             {
1315                 pFilterValues[1].Name = C2U("FilterOptions");
1316                 pFilterValues[1].Value <<= ::rtl::OUString(sFilterOptions);
1317             }
1318 
1319             uno::Reference< frame::XStorable > xTempStore( pTempView->GetDocShell()->GetModel(), uno::UNO_QUERY);
1320             xTempStore->storeToURL( aName.GetValue(), aFilterValues );
1321         }
1322         xTempDocShell->DoClose();
1323 
1324 #ifdef DBG_UTIL
1325         sal_Int32 nTarget =
1326 #endif
1327                 rConfigItem.MoveResultSet(rInfo.nDBRow);
1328         DBG_ASSERT( nTarget == rInfo.nDBRow, "row of current document could not be selected");
1329         DBG_ASSERT( sEMailColumn.Len(), "No email column selected");
1330         ::rtl::OUString sEMail = lcl_GetColumnValueOf(sEMailColumn, xColAccess);
1331         SwMailDescriptor aDesc;
1332         aDesc.sEMail = sEMail;
1333         rtl::OUString sBody;
1334         if(bAsBody)
1335         {
1336             {
1337                 //read in the temporary file and use it as mail body
1338                 SfxMedium aMedium( aName.GetValue(),    STREAM_READ, sal_True);
1339                 SvStream* pInStream = aMedium.GetInStream();
1340                 if(pInStream)
1341                     pInStream->SetStreamCharSet( eEncoding );
1342                 else
1343                 {
1344                     DBG_ERROR("no output file created?");
1345                     continue;
1346                 }
1347                 ByteString sLine;
1348                 sal_Bool bDone = pInStream->ReadLine( sLine );
1349                 while ( bDone )
1350                 {
1351                     sBody += rtl::OUString(String(sLine, eEncoding));
1352                     sBody += rtl::OUString('\n');
1353                     bDone = pInStream->ReadLine( sLine );
1354                 }
1355             }
1356             //remove the temporary file
1357             SWUnoHelper::UCB_DeleteFile( aName.GetValue() );
1358         }
1359         else
1360         {
1361             sBody = m_sBody;
1362             aDesc.sAttachmentURL = aName.GetValue();
1363             String sAttachment(m_aAttachmentED.GetText());
1364             xub_StrLen nTokenCount = sAttachment.GetTokenCount( '.' );
1365             if( 2 > nTokenCount)
1366             {
1367                 sAttachment += '.';
1368                 sAttachment.SetToken( nTokenCount, '.', sExtension);
1369             }
1370             else if(sAttachment.GetToken( nTokenCount - 1, '.') != sExtension)
1371                 sAttachment += sExtension;
1372             aDesc.sAttachmentName = sAttachment;
1373             aDesc.sMimeType = sMimeType;
1374 
1375             if(rConfigItem.IsGreetingLine(sal_True))
1376             {
1377                 ::rtl::OUString sNameColumn = rConfigItem.GetAssignedColumn(MM_PART_LASTNAME);
1378                 ::rtl::OUString sName = lcl_GetColumnValueOf(sNameColumn, xColAccess);
1379                 String sGreeting;
1380                 if(sName.getLength() && rConfigItem.IsIndividualGreeting(sal_True))
1381                 {
1382                     ::rtl::OUString sGenderColumn = rConfigItem.GetAssignedColumn(MM_PART_GENDER);
1383                     const ::rtl::OUString& sFemaleValue = rConfigItem.GetFemaleGenderValue();
1384                     ::rtl::OUString sGenderValue = lcl_GetColumnValueOf(sGenderColumn, xColAccess);
1385                     SwMailMergeConfigItem::Gender eGenderType = sGenderValue == sFemaleValue ?
1386                         SwMailMergeConfigItem::FEMALE :
1387                         SwMailMergeConfigItem::MALE;
1388 
1389                     sGreeting = SwAddressPreview::FillData(
1390                         rConfigItem.GetGreetings(eGenderType)
1391                         [rConfigItem.GetCurrentGreeting(eGenderType)],
1392                             rConfigItem);
1393                 }
1394                 else
1395                 {
1396                     sGreeting =
1397                         rConfigItem.GetGreetings(SwMailMergeConfigItem::NEUTRAL)
1398                         [rConfigItem.GetCurrentGreeting(SwMailMergeConfigItem::NEUTRAL)];
1399 
1400                 }
1401                 sGreeting += '\n';
1402                 ::rtl::OUString sTemp( sGreeting );
1403                 sTemp += sBody;
1404                 sBody = sTemp;
1405             }
1406         }
1407         aDesc.sBodyContent = sBody;
1408         if(MM_DOCTYPE_HTML == nDocType)
1409         {
1410             aDesc.sBodyMimeType = ::rtl::OUString::createFromAscii("text/html; charset=");
1411             aDesc.sBodyMimeType += ::rtl::OUString::createFromAscii(
1412                                 rtl_getBestMimeCharsetFromTextEncoding( eEncoding ));
1413         }
1414         else
1415             aDesc.sBodyMimeType =
1416                 ::rtl::OUString::createFromAscii("text/plain; charset=UTF-8; format=flowed");
1417 
1418         aDesc.sSubject = m_aSubjectED.GetText();
1419         aDesc.sCC = m_sCC;
1420         aDesc.sBCC = m_sBCC;
1421         pDlg->AddDocument( aDesc );
1422         //help to force painting the dialog
1423         for ( sal_Int16 i = 0; i < 25; i++)
1424             Application::Reschedule();
1425         //stop creating of data when dialog has been closed
1426         if(!pDlg->IsVisible())
1427         {
1428             m_pWizard->LeaveWait();
1429             break;
1430         }
1431         m_pWizard->LeaveWait();
1432     }
1433     pDlg->EnableDesctruction();
1434     ::osl::File::remove( sTargetTempURL );
1435 
1436     m_pWizard->enableButtons(WZB_FINISH, sal_True);
1437     //the dialog deletes itself
1438     //delete pDlg;
1439     return 0;
1440 }
1441