1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mailmergewizard.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #ifdef SW_DLLIMPLEMENTATION
34 #undef SW_DLLIMPLEMENTATION
38 #include <mailmergewizard.hxx>
39 #include <mmdocselectpage.hxx>
40 #include <mmoutputtypepage.hxx>
41 #include <mmaddressblockpage.hxx>
42 #include <mmpreparemergepage.hxx>
43 #include <mmmergepage.hxx>
44 #include <mmgreetingspage.hxx>
45 #include <mmoutputpage.hxx>
46 #include <mmlayoutpage.hxx>
47 #include <mmconfigitem.hxx>
48 #include <swabstdlg.hxx>
56 #include <sfx2/viewfrm.hxx>
58 #include <sfx2/viewfrm.hxx>
59 #include "vcl/msgbox.hxx" // RET_CANCEL
63 #include <mailmergewizard.hrc>
66 using namespace ::com::sun::star
;
67 /*-- 01.04.2004 16:52:49---------------------------------------------------
69 -----------------------------------------------------------------------*/
70 SwMailMergeWizard::SwMailMergeWizard(SwView
& rView
, SwMailMergeConfigItem
& rItem
) :
71 RoadmapWizard(&rView
.GetViewFrame()->GetWindow(),
72 SW_RES(DLG_MAILMERGEWIZARD
),
73 WZB_NEXT
|WZB_PREVIOUS
|WZB_FINISH
|WZB_CANCEL
|WZB_HELP
),
75 m_bDocumentLoad( false ),
77 m_sStarting( SW_RES( ST_STARTING
)),
78 m_sDocumentType( SW_RES( ST_DOCUMETNTYPE
)),
79 m_sAddressBlock( SW_RES( ST_ADDRESSBLOCK
)),
80 m_sAddressList( SW_RES( ST_ADDRESSLIST
)),
81 m_sGreetingsLine( SW_RES( ST_GREETINGSLINE
)),
82 m_sLayout( SW_RES( ST_LAYOUT
)),
83 m_sPrepareMerge( SW_RES( ST_PREPAREMERGE
)),
84 m_sMerge( SW_RES( ST_MERGE
)),
85 m_sOutput( SW_RES( ST_OUTPUT
)),
86 m_sFinish( SW_RES( ST_FINISH
)),
87 m_nRestartPage( MM_DOCUMENTSELECTPAGE
)
90 ShowButtonFixedLine(sal_True
);
91 defaultButton(WZB_NEXT
);
92 enableButtons(WZB_FINISH
, sal_False
);
94 m_pFinish
->SetText(m_sFinish
);
95 m_pNextPage
->SetHelpId(HID_MM_NEXT_PAGE
);
96 m_pPrevPage
->SetHelpId(HID_MM_PREV_PAGE
);
98 //#i51949# no output type page visible if e-Mail is not supported
99 if(rItem
.IsMailAvailable())
102 MM_DOCUMENTSELECTPAGE
,
115 MM_DOCUMENTSELECTPAGE
,
128 /*-- 01.04.2004 16:52:53---------------------------------------------------
130 -----------------------------------------------------------------------*/
131 SwMailMergeWizard::~SwMailMergeWizard()
134 /*-- 01.04.2004 16:52:53---------------------------------------------------
136 -----------------------------------------------------------------------*/
137 OWizardPage
* SwMailMergeWizard::createPage(WizardState _nState
)
139 OWizardPage
* pRet
= 0;
142 case MM_DOCUMENTSELECTPAGE
: pRet
= new SwMailMergeDocSelectPage(this); break;
143 case MM_OUTPUTTYPETPAGE
: pRet
= new SwMailMergeOutputTypePage(this); break;
144 case MM_ADDRESSBLOCKPAGE
: pRet
= new SwMailMergeAddressBlockPage(this); break;
145 case MM_GREETINGSPAGE
: pRet
= new SwMailMergeGreetingsPage(this); break;
146 case MM_LAYOUTPAGE
: pRet
= new SwMailMergeLayoutPage(this); break;
147 case MM_PREPAREMERGEPAGE
: pRet
= new SwMailMergePrepareMergePage(this); break;
148 case MM_MERGEPAGE
: pRet
= new SwMailMergeMergePage(this); break;
149 case MM_OUTPUTPAGE
: pRet
= new SwMailMergeOutputPage(this); break;
151 DBG_ASSERT(pRet
, "no page created in ::createPage");
154 /*-- 04.06.2004 13:18:47---------------------------------------------------
156 -----------------------------------------------------------------------*/
157 void SwMailMergeWizard::enterState( WizardState _nState
)
159 ::svt::RoadmapWizard::enterState( _nState
);
161 entering a page after the layoutpage requires the insertion
162 of greeting and address block - if not yet done
163 entering the merge or output page requires to create the output document
165 if(_nState
> MM_LAYOUTPAGE
&& m_rConfigItem
.GetSourceView() &&
166 ((m_rConfigItem
.IsAddressBlock() && !m_rConfigItem
.IsAddressInserted()) ||
167 (m_rConfigItem
.IsGreetingLine(sal_False
) && !m_rConfigItem
.IsGreetingInserted() )))
169 SwMailMergeLayoutPage::InsertAddressAndGreeting(m_rConfigItem
.GetSourceView(),
170 m_rConfigItem
, Point(-1, -1), true);
172 if(_nState
>= MM_MERGEPAGE
&& !m_rConfigItem
.GetTargetView())
174 CreateTargetDocument();
175 m_nRestartPage
= _nState
;
176 EndDialog(RET_TARGET_CREATED
);
179 else if(_nState
< MM_MERGEPAGE
&& m_rConfigItem
.GetTargetView())
181 //close the dialog, remove the target view, show the source view
182 m_nRestartPage
= _nState
;
183 //set ResultSet back to start
184 m_rConfigItem
.MoveResultSet(1);
185 EndDialog(RET_REMOVE_TARGET
);
188 bool bEnablePrev
= true;
189 bool bEnableNext
= true;
192 case MM_DOCUMENTSELECTPAGE
:
195 case MM_ADDRESSBLOCKPAGE
:
196 bEnableNext
= m_rConfigItem
.GetResultSet().is();
202 enableButtons( WZB_PREVIOUS
, bEnablePrev
);
203 enableButtons( WZB_NEXT
, bEnableNext
);
207 /*-- 04.06.2004 12:54:13---------------------------------------------------
209 -----------------------------------------------------------------------*/
210 String
SwMailMergeWizard::getStateDisplayName( WizardState _nState
) const
215 case MM_DOCUMENTSELECTPAGE
:sRet
= m_sStarting
; break;
216 case MM_OUTPUTTYPETPAGE
: sRet
= m_sDocumentType
; break;
217 case MM_ADDRESSBLOCKPAGE
:
218 sRet
= m_rConfigItem
.IsOutputToLetter() ?
219 m_sAddressBlock
: m_sAddressList
;
222 case MM_GREETINGSPAGE
: sRet
= m_sGreetingsLine
; break;
223 case MM_LAYOUTPAGE
: sRet
= m_sLayout
; break;
224 case MM_PREPAREMERGEPAGE
: sRet
= m_sPrepareMerge
; break;
225 case MM_MERGEPAGE
: sRet
= m_sMerge
; break;
226 case MM_OUTPUTPAGE
: sRet
= m_sOutput
; break;
230 /*-- 24.06.2004 09:24:45---------------------------------------------------
231 enables/disables pages in the roadmap depending on the current
233 -----------------------------------------------------------------------*/
234 void SwMailMergeWizard::UpdateRoadmap()
237 MM_DOCUMENTSELECTPAGE > inactive after the layoutpage
238 MM_OUTPUTTYPETPAGE : > inactive after the layoutpage
239 MM_ADDRESSBLOCKPAGE > inactive after the layoutpage
240 MM_GREETINGSPAGE > inactive after the layoutpage
241 MM_LAYOUTPAGE > inactive after the layoutpage
242 inactive if address block and greeting are switched off
243 or are already inserted into the source document
244 MM_PREPAREMERGEPAGE > only active if address data has been selected
245 inactive after preparemerge page
246 MM_MERGEPAGE > only active if address data has been selected
248 MM_OUTPUTPAGE > only active if address data has been selected
251 // enableState( <page id>, false );
252 const sal_uInt16 nCurPage
= GetCurLevel();
253 TabPage
* pCurPage
= GetPage( nCurPage
);
256 bool bEnable
= false;
257 bool bAddressFieldsConfigured
= !m_rConfigItem
.IsOutputToLetter() ||
258 !m_rConfigItem
.IsAddressBlock() ||
259 m_rConfigItem
.IsAddressFieldsAssigned();
260 bool bGreetingFieldsConfigured
= !m_rConfigItem
.IsGreetingLine(sal_False
) ||
261 !m_rConfigItem
.IsIndividualGreeting(sal_False
)||
262 m_rConfigItem
.IsGreetingFieldsAssigned();
263 //#i97436# if a document has to be loaded then enable output type page only
264 m_bDocumentLoad
= false;
265 bool bEnableOutputTypePage
= (nCurPage
!= MM_DOCUMENTSELECTPAGE
) ||
266 static_cast<svt::OWizardPage
*>(pCurPage
)->commitPage( eValidate
);
268 for(sal_uInt16 nPage
= MM_DOCUMENTSELECTPAGE
; nPage
<= MM_OUTPUTPAGE
; ++nPage
)
272 case MM_DOCUMENTSELECTPAGE
:
275 case MM_OUTPUTTYPETPAGE
:
276 bEnable
= bEnableOutputTypePage
;
278 case MM_ADDRESSBLOCKPAGE
:
279 bEnable
= !m_bDocumentLoad
&& bEnableOutputTypePage
;
281 case MM_GREETINGSPAGE
:
282 bEnable
= !m_bDocumentLoad
&& bEnableOutputTypePage
&&
283 m_rConfigItem
.GetResultSet().is() &&
284 bAddressFieldsConfigured
;
286 case MM_PREPAREMERGEPAGE
:
290 bEnable
= !m_bDocumentLoad
&& bEnableOutputTypePage
&&
291 m_rConfigItem
.GetResultSet().is() &&
292 bAddressFieldsConfigured
&&
293 bGreetingFieldsConfigured
;
294 if(MM_LAYOUTPAGE
== nPage
)
296 ((m_rConfigItem
.IsAddressBlock() && !m_rConfigItem
.IsAddressInserted()) ||
297 (m_rConfigItem
.IsGreetingLine(sal_False
) && !m_rConfigItem
.IsGreetingInserted() ));
300 enableState( nPage
, bEnable
);
303 /*-- 24.06.2004 09:24:45---------------------------------------------------
304 enables/disables pages in the roadmap depending on the current
306 -----------------------------------------------------------------------*/
307 void SwMailMergeWizard::CreateTargetDocument()
309 GetSwView()->GetWrtShell().GetNewDBMgr()->
310 MergeDocuments( m_rConfigItem
, *GetSwView() );
311 m_rConfigItem
.SetMergeDone();
312 if( m_rConfigItem
.GetTargetView() )
313 m_rConfigItem
.GetTargetView()->GetViewFrame()->GetFrame()->Appear();
315 /*-- 23.08.2004 08:51:36---------------------------------------------------
317 -----------------------------------------------------------------------*/
318 void SwMailMergeWizard::updateRoadmapItemLabel( WizardState _nState
)
320 svt::RoadmapWizard::updateRoadmapItemLabel( _nState
);
323 // ------------------------------------------------------------------------
325 short SwMailMergeWizard::Execute()
327 DBG_ERROR( "SwMailMergeWizard cannot be executed via Dialog::Execute!\n"
328 "It creates a thread (MailDispatcher instance) that will call"
329 "back to VCL apartment => deadlock!\n"
330 "Use Dialog::StartExecuteModal to execute the dialog!" );
334 // ------------------------------------------------------------------------
336 void SwMailMergeWizard::StartExecuteModal( const Link
& rEndDialogHdl
)
338 ::svt::RoadmapWizard::StartExecuteModal( rEndDialogHdl
);