LibreOffice Module sw (master)  1
mailmergewizard.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <mailmergewizard.hxx>
21 #include "mmdocselectpage.hxx"
22 #include "mmoutputtypepage.hxx"
23 #include "mmaddressblockpage.hxx"
24 #include "mmgreetingspage.hxx"
25 #include "mmlayoutpage.hxx"
26 #include <mmconfigitem.hxx>
27 #include <swabstdlg.hxx>
28 #include <dbui.hrc>
29 #include <strings.hrc>
30 #include <view.hxx>
31 #include <dbmgr.hxx>
32 #include <sfx2/viewfrm.hxx>
33 #include <wrtsh.hxx>
35 
36 #include <helpids.h>
37 
38 using namespace svt;
39 using namespace ::com::sun::star;
40 
41 SwMailMergeWizard::SwMailMergeWizard(SwView& rView, std::shared_ptr<SwMailMergeConfigItem> const & rItem) :
42  RoadmapWizard(&rView.GetViewFrame()->GetWindow()),
43  m_pSwView(&rView),
44  m_bDocumentLoad( false ),
45  m_xConfigItem(rItem),
46  m_sStarting( SwResId( ST_STARTING )),
47  m_sDocumentType( SwResId( ST_DOCUMENTTYPE )),
48  m_sAddressBlock( SwResId( ST_ADDRESSBLOCK )),
49  m_sAddressList( SwResId( ST_ADDRESSLIST )),
50  m_sGreetingsLine( SwResId( ST_GREETINGSLINE )),
51  m_sLayout( SwResId( ST_LAYOUT )),
52  m_nRestartPage( MM_DOCUMENTSELECTPAGE )
53 {
54  defaultButton(WizardButtonFlags::NEXT);
55  enableButtons(WizardButtonFlags::FINISH, false);
56 
57  setTitleBase(SwResId( ST_MMWTITLE ) );
58 
59  m_pFinish->SetText(SwResId( ST_FINISH ));
62 
63  //#i51949# no output type page visible if e-Mail is not supported
64  if (m_xConfigItem->IsMailAvailable())
66  0,
72  );
73  else
75  0,
80  );
81 
82  ActivatePage();
83  UpdateRoadmap();
84 }
85 
87 {
88 }
89 
91 {
93  switch(_nState)
94  {
97 
98  /* tdf#52986 Set help ID using SetRoadmapHelpId for all pages
99  so that when by default the focus is on the left side pane of
100  the wizard the relevant help page is displayed when hitting
101  the Help / F1 button */
102  SetRoadmapHelpId("modules/swriter/ui/mmselectpage/MMSelectPage");
103  break;
104  case MM_OUTPUTTYPETPAGE :
106  SetRoadmapHelpId("modules/swriter/ui/mmoutputtypepage/MMOutputTypePage");
107  break;
108  case MM_ADDRESSBLOCKPAGE :
110  SetRoadmapHelpId("modules/swriter/ui/mmaddressblockpage/MMAddressBlockPage");
111  break;
112  case MM_GREETINGSPAGE :
114  SetRoadmapHelpId("modules/swriter/ui/mmsalutationpage/MMSalutationPage");
115  break;
116  case MM_LAYOUTPAGE :
118  SetRoadmapHelpId("modules/swriter/ui/mmlayoutpage/MMLayoutPage");
119  break;
120  }
121  OSL_ENSURE(pRet, "no page created in ::createPage");
122  return pRet;
123 }
124 
126 {
128 
129  if (m_xConfigItem->GetTargetView())
130  {
131  //close the dialog, remove the target view, show the source view
132  m_nRestartPage = _nState;
133  //set ResultSet back to start
134  m_xConfigItem->MoveResultSet(1);
135  EndDialog(RET_REMOVE_TARGET);
136  return;
137  }
138  bool bEnablePrev = true;
139  bool bEnableNext = true;
140  switch(_nState)
141  {
143  bEnablePrev = false; // the first page
144  break;
145  case MM_ADDRESSBLOCKPAGE :
146  bEnableNext = m_xConfigItem->GetResultSet().is();
147  break;
148  case MM_LAYOUTPAGE:
149  bEnableNext = false; // the last page
150  break;
151  }
152  enableButtons( WizardButtonFlags::PREVIOUS, bEnablePrev);
153  enableButtons( WizardButtonFlags::NEXT, bEnableNext);
154 
155  UpdateRoadmap();
156 }
157 
159 {
160  switch(_nState)
161  {
163  return m_sStarting;
164  case MM_OUTPUTTYPETPAGE:
165  return m_sDocumentType;
166  case MM_ADDRESSBLOCKPAGE:
167  return m_xConfigItem->IsOutputToLetter() ?
169  case MM_GREETINGSPAGE:
170  return m_sGreetingsLine;
171  case MM_LAYOUTPAGE:
172  return m_sLayout;
173  }
174  return OUString();
175 }
176 
177 // enables/disables pages in the roadmap depending on the current page and state
179 {
180 /*
181  MM_DOCUMENTSELECTPAGE > inactive after the layoutpage
182  MM_OUTPUTTYPETPAGE : > inactive after the layoutpage
183  MM_ADDRESSBLOCKPAGE > inactive after the layoutpage
184  MM_GREETINGSPAGE > inactive after the layoutpage
185  MM_LAYOUTPAGE > inactive after the layoutpage
186  inactive if address block and greeting are switched off
187  or are already inserted into the source document
188 */
189 
190  // enableState( <page id>, false );
191  const sal_uInt16 nCurPage = GetCurLevel();
192  TabPage* pCurPage = GetPage( nCurPage );
193  if(!pCurPage)
194  return;
195  bool bAddressFieldsConfigured = !m_xConfigItem->IsOutputToLetter() ||
196  !m_xConfigItem->IsAddressBlock() ||
197  m_xConfigItem->IsAddressFieldsAssigned();
198  bool bGreetingFieldsConfigured = !m_xConfigItem->IsGreetingLine(false) ||
199  !m_xConfigItem->IsIndividualGreeting(false) ||
200  m_xConfigItem->IsGreetingFieldsAssigned();
201 
202  //#i97436# if a document has to be loaded then enable output type page only
203  m_bDocumentLoad = false;
204  bool bEnableOutputTypePage = (nCurPage != MM_DOCUMENTSELECTPAGE) ||
205  static_cast<svt::OWizardPage*>(pCurPage)->commitPage( ::svt::WizardTypes::eValidate );
206 
207  // handle the Finish button
208  bool bCanFinish = !m_bDocumentLoad && bEnableOutputTypePage &&
209  m_xConfigItem->GetResultSet().is() &&
210  bAddressFieldsConfigured &&
211  bGreetingFieldsConfigured;
212  enableButtons(WizardButtonFlags::FINISH, (nCurPage != MM_DOCUMENTSELECTPAGE) && bCanFinish);
213 
214  for(sal_uInt16 nPage = MM_DOCUMENTSELECTPAGE; nPage <= MM_LAYOUTPAGE; ++nPage)
215  {
216  bool bEnable = true;
217  switch(nPage)
218  {
220  bEnable = true;
221  break;
222  case MM_OUTPUTTYPETPAGE:
223  bEnable = bEnableOutputTypePage;
224  break;
225  case MM_ADDRESSBLOCKPAGE:
226  bEnable = !m_bDocumentLoad && bEnableOutputTypePage;
227  break;
228  case MM_GREETINGSPAGE:
229  bEnable = !m_bDocumentLoad && bEnableOutputTypePage &&
230  m_xConfigItem->GetResultSet().is() &&
231  bAddressFieldsConfigured;
232  break;
233  case MM_LAYOUTPAGE:
234  bEnable = bCanFinish &&
235  ((m_xConfigItem->IsAddressBlock() && !m_xConfigItem->IsAddressInserted()) ||
236  (m_xConfigItem->IsGreetingLine(false) && !m_xConfigItem->IsGreetingInserted() ));
237  break;
238  }
239  enableState( nPage, bEnable );
240  }
241 }
242 
244 {
245  OSL_FAIL("SwMailMergeWizard cannot be executed via Dialog::Execute!\n"
246  "It creates a thread (MailDispatcher instance) that will call"
247  "back to VCL apartment => deadlock!\n"
248  "Use Dialog::StartExecuteAsync to execute the dialog!" );
249  return RET_CANCEL;
250 }
251 
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString const m_sAddressBlock
OUString const m_sGreetingsLine
VclPtr< PushButton > m_pNextPage
#define MM_OUTPUTTYPETPAGE
void defaultButton(WizardButtonFlags _nWizardButtonFlags)
void SetHelpId(const OString &)
RET_CANCEL
#define MM_LAYOUTPAGE
OUString const m_sLayout
sal_uInt16 GetCurLevel() const
virtual VclPtr< TabPage > createPage(WizardState _nState) override
#define MM_ADDRESSBLOCKPAGE
VclPtr< OKButton > m_pFinish
sal_Int16 WizardState
#define MM_DOCUMENTSELECTPAGE
#define MM_GREETINGSPAGE
SwMailMergeWizard(SwView &rView, std::shared_ptr< SwMailMergeConfigItem > const &rConfigItem)
VclPtr< PushButton > m_pPrevPage
virtual void enterState(WizardState _nState) override
virtual void SetText(const OUString &rStr) override
void enableState(WizardState _nState, bool _bEnable=true)
virtual OUString getStateDisplayName(WizardState _nState) const override
sal_uInt16 m_nRestartPage
virtual ~SwMailMergeWizard() override
void setTitleBase(const OUString &_rTitleBase)
OUString SwResId(const char *pId)
Definition: swmodule.cxx:191
void enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable)
#define RET_REMOVE_TARGET
Definition: swabstdlg.hxx:346
OUString const m_sDocumentType
#define HID_MM_PREV_PAGE
Definition: helpids.h:145
void declarePath(PathId _nPathId, const WizardPath &_lWizardStates)
virtual void ActivatePage() override
virtual void enterState(WizardState _nState) override
TabPage * GetPage(sal_uInt16 nLevel) const
static VclPtr< reference_type > Create(Arg &&...arg)
OUString const m_sAddressList
#define HID_MM_NEXT_PAGE
Definition: helpids.h:144
void SetRoadmapHelpId(const OString &_rId)
OUString const m_sStarting
std::shared_ptr< SwMailMergeConfigItem > m_xConfigItem
Definition: view.hxx:146
virtual short Execute() override