Update ooo320-m1
[ooovba.git] / sw / source / ui / dbui / mailmergewizard.cxx
blob6df323da4a6f739d69344cf690cd7888924a46ff
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mailmergewizard.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #ifdef SW_DLLIMPLEMENTATION
34 #undef SW_DLLIMPLEMENTATION
35 #endif
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>
49 #ifndef _DBUI_HRC
50 #include <dbui.hrc>
51 #endif
52 #include <view.hxx>
53 #ifndef _DBMGR_HXX
54 #include <dbmgr.hxx>
55 #endif
56 #include <sfx2/viewfrm.hxx>
57 #include <wrtsh.hxx>
58 #include <sfx2/viewfrm.hxx>
59 #include "vcl/msgbox.hxx" // RET_CANCEL
61 #include <helpid.h>
62 #include <dbui.hrc>
63 #include <mailmergewizard.hrc>
65 using namespace svt;
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),
74 m_pSwView(&rView),
75 m_bDocumentLoad( false ),
76 m_rConfigItem(rItem),
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 )
89 FreeResource();
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())
100 declarePath(
102 MM_DOCUMENTSELECTPAGE,
103 MM_OUTPUTTYPETPAGE,
104 MM_ADDRESSBLOCKPAGE,
105 MM_GREETINGSPAGE,
106 MM_LAYOUTPAGE,
107 MM_PREPAREMERGEPAGE,
108 MM_MERGEPAGE,
109 MM_OUTPUTPAGE,
110 WZS_INVALID_STATE
112 else
113 declarePath(
115 MM_DOCUMENTSELECTPAGE,
116 MM_ADDRESSBLOCKPAGE,
117 MM_GREETINGSPAGE,
118 MM_LAYOUTPAGE,
119 MM_PREPAREMERGEPAGE,
120 MM_MERGEPAGE,
121 MM_OUTPUTPAGE,
122 WZS_INVALID_STATE
125 ActivatePage();
126 UpdateRoadmap();
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;
140 switch(_nState)
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");
152 return pRet;
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);
177 return;
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);
186 return;
188 bool bEnablePrev = true;
189 bool bEnableNext = true;
190 switch(_nState)
192 case MM_DOCUMENTSELECTPAGE :
193 bEnablePrev = false;
194 break;
195 case MM_ADDRESSBLOCKPAGE :
196 bEnableNext = m_rConfigItem.GetResultSet().is();
197 break;
198 case MM_OUTPUTPAGE :
199 bEnableNext = false;
200 break;
202 enableButtons( WZB_PREVIOUS, bEnablePrev);
203 enableButtons( WZB_NEXT, bEnableNext);
205 UpdateRoadmap();
207 /*-- 04.06.2004 12:54:13---------------------------------------------------
209 -----------------------------------------------------------------------*/
210 String SwMailMergeWizard::getStateDisplayName( WizardState _nState ) const
212 String sRet;
213 switch(_nState)
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;
221 break;
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;
228 return sRet;
230 /*-- 24.06.2004 09:24:45---------------------------------------------------
231 enables/disables pages in the roadmap depending on the current
232 page and state
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 );
254 if(!pCurPage)
255 return;
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)
270 switch(nPage)
272 case MM_DOCUMENTSELECTPAGE :
273 bEnable = sal_True;
274 break;
275 case MM_OUTPUTTYPETPAGE :
276 bEnable = bEnableOutputTypePage;
277 break;
278 case MM_ADDRESSBLOCKPAGE :
279 bEnable = !m_bDocumentLoad && bEnableOutputTypePage;
280 break;
281 case MM_GREETINGSPAGE :
282 bEnable = !m_bDocumentLoad && bEnableOutputTypePage &&
283 m_rConfigItem.GetResultSet().is() &&
284 bAddressFieldsConfigured;
285 break;
286 case MM_PREPAREMERGEPAGE :
287 case MM_MERGEPAGE :
288 case MM_OUTPUTPAGE :
289 case MM_LAYOUTPAGE :
290 bEnable = !m_bDocumentLoad && bEnableOutputTypePage &&
291 m_rConfigItem.GetResultSet().is() &&
292 bAddressFieldsConfigured &&
293 bGreetingFieldsConfigured;
294 if(MM_LAYOUTPAGE == nPage)
295 bEnable &=
296 ((m_rConfigItem.IsAddressBlock() && !m_rConfigItem.IsAddressInserted()) ||
297 (m_rConfigItem.IsGreetingLine(sal_False) && !m_rConfigItem.IsGreetingInserted() ));
298 break;
300 enableState( nPage, bEnable );
303 /*-- 24.06.2004 09:24:45---------------------------------------------------
304 enables/disables pages in the roadmap depending on the current
305 page and state
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!" );
331 return RET_CANCEL;
334 // ------------------------------------------------------------------------
336 void SwMailMergeWizard::StartExecuteModal( const Link& rEndDialogHdl )
338 ::svt::RoadmapWizard::StartExecuteModal( rEndDialogHdl );