1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10*efeef26fSAndrew Rist *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19*efeef26fSAndrew Rist *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir #ifdef SW_DLLIMPLEMENTATION
27cdf0e10cSrcweir #undef SW_DLLIMPLEMENTATION
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <mailmergewizard.hxx>
32cdf0e10cSrcweir #include <mmdocselectpage.hxx>
33cdf0e10cSrcweir #include <mmoutputtypepage.hxx>
34cdf0e10cSrcweir #include <mmaddressblockpage.hxx>
35cdf0e10cSrcweir #include <mmpreparemergepage.hxx>
36cdf0e10cSrcweir #include <mmmergepage.hxx>
37cdf0e10cSrcweir #include <mmgreetingspage.hxx>
38cdf0e10cSrcweir #include <mmoutputpage.hxx>
39cdf0e10cSrcweir #include <mmlayoutpage.hxx>
40cdf0e10cSrcweir #include <mmconfigitem.hxx>
41cdf0e10cSrcweir #include <swabstdlg.hxx>
42cdf0e10cSrcweir #ifndef _DBUI_HRC
43cdf0e10cSrcweir #include <dbui.hrc>
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir #include <view.hxx>
46cdf0e10cSrcweir #ifndef _DBMGR_HXX
47cdf0e10cSrcweir #include <dbmgr.hxx>
48cdf0e10cSrcweir #endif
49cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
50cdf0e10cSrcweir #include <wrtsh.hxx>
51cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
52cdf0e10cSrcweir #include "vcl/msgbox.hxx" // RET_CANCEL
53cdf0e10cSrcweir
54cdf0e10cSrcweir #include <helpid.h>
55cdf0e10cSrcweir #include <dbui.hrc>
56cdf0e10cSrcweir #include <mailmergewizard.hrc>
57cdf0e10cSrcweir
58cdf0e10cSrcweir using namespace svt;
59cdf0e10cSrcweir using namespace ::com::sun::star;
60cdf0e10cSrcweir /*-- 01.04.2004 16:52:49---------------------------------------------------
61cdf0e10cSrcweir
62cdf0e10cSrcweir -----------------------------------------------------------------------*/
SwMailMergeWizard(SwView & rView,SwMailMergeConfigItem & rItem)63cdf0e10cSrcweir SwMailMergeWizard::SwMailMergeWizard(SwView& rView, SwMailMergeConfigItem& rItem) :
64cdf0e10cSrcweir RoadmapWizard(&rView.GetViewFrame()->GetWindow(),
65cdf0e10cSrcweir SW_RES(DLG_MAILMERGEWIZARD),
66cdf0e10cSrcweir WZB_NEXT|WZB_PREVIOUS|WZB_FINISH|WZB_CANCEL|WZB_HELP),
67cdf0e10cSrcweir m_pSwView(&rView),
68cdf0e10cSrcweir m_bDocumentLoad( false ),
69cdf0e10cSrcweir m_rConfigItem(rItem),
70cdf0e10cSrcweir m_sStarting( SW_RES( ST_STARTING )),
71cdf0e10cSrcweir m_sDocumentType( SW_RES( ST_DOCUMETNTYPE )),
72cdf0e10cSrcweir m_sAddressBlock( SW_RES( ST_ADDRESSBLOCK )),
73cdf0e10cSrcweir m_sAddressList( SW_RES( ST_ADDRESSLIST )),
74cdf0e10cSrcweir m_sGreetingsLine( SW_RES( ST_GREETINGSLINE )),
75cdf0e10cSrcweir m_sLayout( SW_RES( ST_LAYOUT )),
76cdf0e10cSrcweir m_sPrepareMerge( SW_RES( ST_PREPAREMERGE )),
77cdf0e10cSrcweir m_sMerge( SW_RES( ST_MERGE )),
78cdf0e10cSrcweir m_sOutput( SW_RES( ST_OUTPUT )),
79cdf0e10cSrcweir m_sFinish( SW_RES( ST_FINISH )),
80cdf0e10cSrcweir m_nRestartPage( MM_DOCUMENTSELECTPAGE )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir FreeResource();
83cdf0e10cSrcweir ShowButtonFixedLine(sal_True);
84cdf0e10cSrcweir defaultButton(WZB_NEXT);
85cdf0e10cSrcweir enableButtons(WZB_FINISH, sal_False);
86cdf0e10cSrcweir
87cdf0e10cSrcweir m_pFinish->SetText(m_sFinish);
88cdf0e10cSrcweir m_pNextPage->SetHelpId(HID_MM_NEXT_PAGE);
89cdf0e10cSrcweir m_pPrevPage->SetHelpId(HID_MM_PREV_PAGE);
90cdf0e10cSrcweir
91cdf0e10cSrcweir //#i51949# no output type page visible if e-Mail is not supported
92cdf0e10cSrcweir if(rItem.IsMailAvailable())
93cdf0e10cSrcweir declarePath(
94cdf0e10cSrcweir 0,
95cdf0e10cSrcweir MM_DOCUMENTSELECTPAGE,
96cdf0e10cSrcweir MM_OUTPUTTYPETPAGE,
97cdf0e10cSrcweir MM_ADDRESSBLOCKPAGE,
98cdf0e10cSrcweir MM_GREETINGSPAGE,
99cdf0e10cSrcweir MM_LAYOUTPAGE,
100cdf0e10cSrcweir MM_PREPAREMERGEPAGE,
101cdf0e10cSrcweir MM_MERGEPAGE,
102cdf0e10cSrcweir MM_OUTPUTPAGE,
103cdf0e10cSrcweir WZS_INVALID_STATE
104cdf0e10cSrcweir );
105cdf0e10cSrcweir else
106cdf0e10cSrcweir declarePath(
107cdf0e10cSrcweir 0,
108cdf0e10cSrcweir MM_DOCUMENTSELECTPAGE,
109cdf0e10cSrcweir MM_ADDRESSBLOCKPAGE,
110cdf0e10cSrcweir MM_GREETINGSPAGE,
111cdf0e10cSrcweir MM_LAYOUTPAGE,
112cdf0e10cSrcweir MM_PREPAREMERGEPAGE,
113cdf0e10cSrcweir MM_MERGEPAGE,
114cdf0e10cSrcweir MM_OUTPUTPAGE,
115cdf0e10cSrcweir WZS_INVALID_STATE
116cdf0e10cSrcweir );
117cdf0e10cSrcweir
118cdf0e10cSrcweir ActivatePage();
119cdf0e10cSrcweir UpdateRoadmap();
120cdf0e10cSrcweir }
121cdf0e10cSrcweir /*-- 01.04.2004 16:52:53---------------------------------------------------
122cdf0e10cSrcweir
123cdf0e10cSrcweir -----------------------------------------------------------------------*/
~SwMailMergeWizard()124cdf0e10cSrcweir SwMailMergeWizard::~SwMailMergeWizard()
125cdf0e10cSrcweir {
126cdf0e10cSrcweir }
127cdf0e10cSrcweir /*-- 01.04.2004 16:52:53---------------------------------------------------
128cdf0e10cSrcweir
129cdf0e10cSrcweir -----------------------------------------------------------------------*/
createPage(WizardState _nState)130cdf0e10cSrcweir OWizardPage* SwMailMergeWizard::createPage(WizardState _nState)
131cdf0e10cSrcweir {
132cdf0e10cSrcweir OWizardPage* pRet = 0;
133cdf0e10cSrcweir switch(_nState)
134cdf0e10cSrcweir {
135cdf0e10cSrcweir case MM_DOCUMENTSELECTPAGE : pRet = new SwMailMergeDocSelectPage(this); break;
136cdf0e10cSrcweir case MM_OUTPUTTYPETPAGE : pRet = new SwMailMergeOutputTypePage(this); break;
137cdf0e10cSrcweir case MM_ADDRESSBLOCKPAGE : pRet = new SwMailMergeAddressBlockPage(this); break;
138cdf0e10cSrcweir case MM_GREETINGSPAGE : pRet = new SwMailMergeGreetingsPage(this); break;
139cdf0e10cSrcweir case MM_LAYOUTPAGE : pRet = new SwMailMergeLayoutPage(this); break;
140cdf0e10cSrcweir case MM_PREPAREMERGEPAGE : pRet = new SwMailMergePrepareMergePage(this); break;
141cdf0e10cSrcweir case MM_MERGEPAGE : pRet = new SwMailMergeMergePage(this); break;
142cdf0e10cSrcweir case MM_OUTPUTPAGE : pRet = new SwMailMergeOutputPage(this); break;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir DBG_ASSERT(pRet, "no page created in ::createPage");
145cdf0e10cSrcweir return pRet;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir /*-- 04.06.2004 13:18:47---------------------------------------------------
148cdf0e10cSrcweir
149cdf0e10cSrcweir -----------------------------------------------------------------------*/
enterState(WizardState _nState)150cdf0e10cSrcweir void SwMailMergeWizard::enterState( WizardState _nState )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir ::svt::RoadmapWizard::enterState( _nState );
153cdf0e10cSrcweir /*
154cdf0e10cSrcweir entering a page after the layoutpage requires the insertion
155cdf0e10cSrcweir of greeting and address block - if not yet done
156cdf0e10cSrcweir entering the merge or output page requires to create the output document
157cdf0e10cSrcweir */
158cdf0e10cSrcweir if(_nState > MM_LAYOUTPAGE && m_rConfigItem.GetSourceView() &&
159cdf0e10cSrcweir ((m_rConfigItem.IsAddressBlock() && !m_rConfigItem.IsAddressInserted()) ||
160cdf0e10cSrcweir (m_rConfigItem.IsGreetingLine(sal_False) && !m_rConfigItem.IsGreetingInserted() )))
161cdf0e10cSrcweir {
162cdf0e10cSrcweir SwMailMergeLayoutPage::InsertAddressAndGreeting(m_rConfigItem.GetSourceView(),
163cdf0e10cSrcweir m_rConfigItem, Point(-1, -1), true);
164cdf0e10cSrcweir }
165cdf0e10cSrcweir if(_nState >= MM_MERGEPAGE && !m_rConfigItem.GetTargetView())
166cdf0e10cSrcweir {
167cdf0e10cSrcweir CreateTargetDocument();
168cdf0e10cSrcweir m_nRestartPage = _nState;
169cdf0e10cSrcweir EndDialog(RET_TARGET_CREATED);
170cdf0e10cSrcweir return;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir else if(_nState < MM_MERGEPAGE && m_rConfigItem.GetTargetView())
173cdf0e10cSrcweir {
174cdf0e10cSrcweir //close the dialog, remove the target view, show the source view
175cdf0e10cSrcweir m_nRestartPage = _nState;
176cdf0e10cSrcweir //set ResultSet back to start
177cdf0e10cSrcweir m_rConfigItem.MoveResultSet(1);
178cdf0e10cSrcweir EndDialog(RET_REMOVE_TARGET);
179cdf0e10cSrcweir return;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir bool bEnablePrev = true;
182cdf0e10cSrcweir bool bEnableNext = true;
183cdf0e10cSrcweir switch(_nState)
184cdf0e10cSrcweir {
185cdf0e10cSrcweir case MM_DOCUMENTSELECTPAGE :
186cdf0e10cSrcweir bEnablePrev = false;
187cdf0e10cSrcweir break;
188cdf0e10cSrcweir case MM_ADDRESSBLOCKPAGE :
189cdf0e10cSrcweir bEnableNext = m_rConfigItem.GetResultSet().is();
190cdf0e10cSrcweir break;
191cdf0e10cSrcweir case MM_OUTPUTPAGE :
192cdf0e10cSrcweir bEnableNext = false;
193cdf0e10cSrcweir break;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir enableButtons( WZB_PREVIOUS, bEnablePrev);
196cdf0e10cSrcweir enableButtons( WZB_NEXT, bEnableNext);
197cdf0e10cSrcweir
198cdf0e10cSrcweir UpdateRoadmap();
199cdf0e10cSrcweir }
200cdf0e10cSrcweir /*-- 04.06.2004 12:54:13---------------------------------------------------
201cdf0e10cSrcweir
202cdf0e10cSrcweir -----------------------------------------------------------------------*/
getStateDisplayName(WizardState _nState) const203cdf0e10cSrcweir String SwMailMergeWizard::getStateDisplayName( WizardState _nState ) const
204cdf0e10cSrcweir {
205cdf0e10cSrcweir String sRet;
206cdf0e10cSrcweir switch(_nState)
207cdf0e10cSrcweir {
208cdf0e10cSrcweir case MM_DOCUMENTSELECTPAGE :sRet = m_sStarting; break;
209cdf0e10cSrcweir case MM_OUTPUTTYPETPAGE : sRet = m_sDocumentType; break;
210cdf0e10cSrcweir case MM_ADDRESSBLOCKPAGE :
211cdf0e10cSrcweir sRet = m_rConfigItem.IsOutputToLetter() ?
212cdf0e10cSrcweir m_sAddressBlock : m_sAddressList;
213cdf0e10cSrcweir
214cdf0e10cSrcweir break;
215cdf0e10cSrcweir case MM_GREETINGSPAGE : sRet = m_sGreetingsLine; break;
216cdf0e10cSrcweir case MM_LAYOUTPAGE : sRet = m_sLayout; break;
217cdf0e10cSrcweir case MM_PREPAREMERGEPAGE : sRet = m_sPrepareMerge; break;
218cdf0e10cSrcweir case MM_MERGEPAGE : sRet = m_sMerge; break;
219cdf0e10cSrcweir case MM_OUTPUTPAGE : sRet = m_sOutput; break;
220cdf0e10cSrcweir }
221cdf0e10cSrcweir return sRet;
222cdf0e10cSrcweir }
223cdf0e10cSrcweir /*-- 24.06.2004 09:24:45---------------------------------------------------
224cdf0e10cSrcweir enables/disables pages in the roadmap depending on the current
225cdf0e10cSrcweir page and state
226cdf0e10cSrcweir -----------------------------------------------------------------------*/
UpdateRoadmap()227cdf0e10cSrcweir void SwMailMergeWizard::UpdateRoadmap()
228cdf0e10cSrcweir {
229cdf0e10cSrcweir /*
230cdf0e10cSrcweir MM_DOCUMENTSELECTPAGE > inactive after the layoutpage
231cdf0e10cSrcweir MM_OUTPUTTYPETPAGE : > inactive after the layoutpage
232cdf0e10cSrcweir MM_ADDRESSBLOCKPAGE > inactive after the layoutpage
233cdf0e10cSrcweir MM_GREETINGSPAGE > inactive after the layoutpage
234cdf0e10cSrcweir MM_LAYOUTPAGE > inactive after the layoutpage
235cdf0e10cSrcweir inactive if address block and greeting are switched off
236cdf0e10cSrcweir or are already inserted into the source document
237cdf0e10cSrcweir MM_PREPAREMERGEPAGE > only active if address data has been selected
238cdf0e10cSrcweir inactive after preparemerge page
239cdf0e10cSrcweir MM_MERGEPAGE > only active if address data has been selected
240cdf0e10cSrcweir
241cdf0e10cSrcweir MM_OUTPUTPAGE > only active if address data has been selected
242cdf0e10cSrcweir */
243cdf0e10cSrcweir
244cdf0e10cSrcweir // enableState( <page id>, false );
245cdf0e10cSrcweir const sal_uInt16 nCurPage = GetCurLevel();
246cdf0e10cSrcweir TabPage* pCurPage = GetPage( nCurPage );
247cdf0e10cSrcweir if(!pCurPage)
248cdf0e10cSrcweir return;
249cdf0e10cSrcweir bool bEnable = false;
250cdf0e10cSrcweir bool bAddressFieldsConfigured = !m_rConfigItem.IsOutputToLetter() ||
251cdf0e10cSrcweir !m_rConfigItem.IsAddressBlock() ||
252cdf0e10cSrcweir m_rConfigItem.IsAddressFieldsAssigned();
253cdf0e10cSrcweir bool bGreetingFieldsConfigured = !m_rConfigItem.IsGreetingLine(sal_False) ||
254cdf0e10cSrcweir !m_rConfigItem.IsIndividualGreeting(sal_False)||
255cdf0e10cSrcweir m_rConfigItem.IsGreetingFieldsAssigned();
256cdf0e10cSrcweir //#i97436# if a document has to be loaded then enable output type page only
257cdf0e10cSrcweir m_bDocumentLoad = false;
258cdf0e10cSrcweir bool bEnableOutputTypePage = (nCurPage != MM_DOCUMENTSELECTPAGE) ||
259cdf0e10cSrcweir static_cast<svt::OWizardPage*>(pCurPage)->commitPage( ::svt::WizardTypes::eValidate );
260cdf0e10cSrcweir
261cdf0e10cSrcweir for(sal_uInt16 nPage = MM_DOCUMENTSELECTPAGE; nPage <= MM_OUTPUTPAGE; ++nPage)
262cdf0e10cSrcweir {
263cdf0e10cSrcweir switch(nPage)
264cdf0e10cSrcweir {
265cdf0e10cSrcweir case MM_DOCUMENTSELECTPAGE :
266cdf0e10cSrcweir bEnable = sal_True;
267cdf0e10cSrcweir break;
268cdf0e10cSrcweir case MM_OUTPUTTYPETPAGE :
269cdf0e10cSrcweir bEnable = bEnableOutputTypePage;
270cdf0e10cSrcweir break;
271cdf0e10cSrcweir case MM_ADDRESSBLOCKPAGE :
272cdf0e10cSrcweir bEnable = !m_bDocumentLoad && bEnableOutputTypePage;
273cdf0e10cSrcweir break;
274cdf0e10cSrcweir case MM_GREETINGSPAGE :
275cdf0e10cSrcweir bEnable = !m_bDocumentLoad && bEnableOutputTypePage &&
276cdf0e10cSrcweir m_rConfigItem.GetResultSet().is() &&
277cdf0e10cSrcweir bAddressFieldsConfigured;
278cdf0e10cSrcweir break;
279cdf0e10cSrcweir case MM_PREPAREMERGEPAGE :
280cdf0e10cSrcweir case MM_MERGEPAGE :
281cdf0e10cSrcweir case MM_OUTPUTPAGE :
282cdf0e10cSrcweir case MM_LAYOUTPAGE :
283cdf0e10cSrcweir bEnable = !m_bDocumentLoad && bEnableOutputTypePage &&
284cdf0e10cSrcweir m_rConfigItem.GetResultSet().is() &&
285cdf0e10cSrcweir bAddressFieldsConfigured &&
286cdf0e10cSrcweir bGreetingFieldsConfigured;
287cdf0e10cSrcweir if(MM_LAYOUTPAGE == nPage)
288cdf0e10cSrcweir bEnable &=
289cdf0e10cSrcweir ((m_rConfigItem.IsAddressBlock() && !m_rConfigItem.IsAddressInserted()) ||
290cdf0e10cSrcweir (m_rConfigItem.IsGreetingLine(sal_False) && !m_rConfigItem.IsGreetingInserted() ));
291cdf0e10cSrcweir break;
292cdf0e10cSrcweir }
293cdf0e10cSrcweir enableState( nPage, bEnable );
294cdf0e10cSrcweir }
295cdf0e10cSrcweir }
296cdf0e10cSrcweir /*-- 24.06.2004 09:24:45---------------------------------------------------
297cdf0e10cSrcweir enables/disables pages in the roadmap depending on the current
298cdf0e10cSrcweir page and state
299cdf0e10cSrcweir -----------------------------------------------------------------------*/
CreateTargetDocument()300cdf0e10cSrcweir void SwMailMergeWizard::CreateTargetDocument()
301cdf0e10cSrcweir {
302cdf0e10cSrcweir GetSwView()->GetWrtShell().GetNewDBMgr()->
303cdf0e10cSrcweir MergeDocuments( m_rConfigItem, *GetSwView() );
304cdf0e10cSrcweir m_rConfigItem.SetMergeDone();
305cdf0e10cSrcweir if( m_rConfigItem.GetTargetView() )
306cdf0e10cSrcweir m_rConfigItem.GetTargetView()->GetViewFrame()->GetFrame().Appear();
307cdf0e10cSrcweir }
308cdf0e10cSrcweir /*-- 23.08.2004 08:51:36---------------------------------------------------
309cdf0e10cSrcweir
310cdf0e10cSrcweir -----------------------------------------------------------------------*/
updateRoadmapItemLabel(WizardState _nState)311cdf0e10cSrcweir void SwMailMergeWizard::updateRoadmapItemLabel( WizardState _nState )
312cdf0e10cSrcweir {
313cdf0e10cSrcweir svt::RoadmapWizard::updateRoadmapItemLabel( _nState );
314cdf0e10cSrcweir }
315cdf0e10cSrcweir
316cdf0e10cSrcweir // ------------------------------------------------------------------------
317cdf0e10cSrcweir
Execute()318cdf0e10cSrcweir short SwMailMergeWizard::Execute()
319cdf0e10cSrcweir {
320cdf0e10cSrcweir DBG_ERROR( "SwMailMergeWizard cannot be executed via Dialog::Execute!\n"
321cdf0e10cSrcweir "It creates a thread (MailDispatcher instance) that will call"
322cdf0e10cSrcweir "back to VCL apartment => deadlock!\n"
323cdf0e10cSrcweir "Use Dialog::StartExecuteModal to execute the dialog!" );
324cdf0e10cSrcweir return RET_CANCEL;
325cdf0e10cSrcweir }
326cdf0e10cSrcweir
327cdf0e10cSrcweir // ------------------------------------------------------------------------
328cdf0e10cSrcweir
StartExecuteModal(const Link & rEndDialogHdl)329cdf0e10cSrcweir void SwMailMergeWizard::StartExecuteModal( const Link& rEndDialogHdl )
330cdf0e10cSrcweir {
331cdf0e10cSrcweir ::svt::RoadmapWizard::StartExecuteModal( rEndDialogHdl );
332cdf0e10cSrcweir }
333