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