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  : RoadmapWizardMachine(rView.GetFrameWeld())
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_xFinish->set_label(SwResId( ST_FINISH ));
60  m_xNextPage->set_help_id(HID_MM_NEXT_PAGE);
61  m_xPrevPage->set_help_id(HID_MM_PREV_PAGE);
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  m_xAssistant->set_current_page(0);
84  UpdateRoadmap();
85 }
86 
88 {
89 }
90 
92 {
93  OString sIdent(OString::number(_nState));
94  weld::Container* pPageContainer = m_xAssistant->append_page(sIdent);
95  // TODO eventually pass DialogController as distinct argument instead of bundling into TabPageParent
96  TabPageParent aParent(pPageContainer, this);
97 
99  switch(_nState)
100  {
101  case MM_DOCUMENTSELECTPAGE :
102  pRet = VclPtr<SwMailMergeDocSelectPage>::Create(this, aParent);
103 
104  /* tdf#52986 Set help ID using SetRoadmapHelpId for all pages
105  so that when by default the focus is on the left side pane of
106  the wizard the relevant help page is displayed when hitting
107  the Help / F1 button */
108  SetRoadmapHelpId("modules/swriter/ui/mmselectpage/MMSelectPage");
109  break;
110  case MM_OUTPUTTYPETPAGE :
111  pRet = VclPtr<SwMailMergeOutputTypePage>::Create(this, aParent);
112  SetRoadmapHelpId("modules/swriter/ui/mmoutputtypepage/MMOutputTypePage");
113  break;
114  case MM_ADDRESSBLOCKPAGE :
115  pRet = VclPtr<SwMailMergeAddressBlockPage>::Create(this, aParent);
116  SetRoadmapHelpId("modules/swriter/ui/mmaddressblockpage/MMAddressBlockPage");
117  break;
118  case MM_GREETINGSPAGE :
119  pRet = VclPtr<SwMailMergeGreetingsPage>::Create(this, aParent);
120  SetRoadmapHelpId("modules/swriter/ui/mmsalutationpage/MMSalutationPage");
121  break;
122  case MM_LAYOUTPAGE :
123  pRet = VclPtr<SwMailMergeLayoutPage>::Create(this, aParent);
124  SetRoadmapHelpId("modules/swriter/ui/mmlayoutpage/MMLayoutPage");
125  break;
126  }
127 
128  m_xAssistant->set_page_title(sIdent, getStateDisplayName(_nState));
129 
130 
131  OSL_ENSURE(pRet, "no page created in ::createPage");
132  return pRet;
133 }
134 
136 {
138 
139  if (m_xConfigItem->GetTargetView())
140  {
141  //close the dialog, remove the target view, show the source view
142  m_nRestartPage = _nState;
143  //set ResultSet back to start
144  m_xConfigItem->MoveResultSet(1);
145  m_xAssistant->response(RET_REMOVE_TARGET);
146  return;
147  }
148  bool bEnablePrev = true;
149  bool bEnableNext = true;
150  switch(_nState)
151  {
153  bEnablePrev = false; // the first page
154  break;
155  case MM_ADDRESSBLOCKPAGE :
156  bEnableNext = m_xConfigItem->GetResultSet().is();
157  break;
158  case MM_LAYOUTPAGE:
159  bEnableNext = false; // the last page
160  break;
161  }
162  enableButtons( WizardButtonFlags::PREVIOUS, bEnablePrev);
163  enableButtons( WizardButtonFlags::NEXT, bEnableNext);
164 
165  UpdateRoadmap();
166 }
167 
169 {
170  switch(_nState)
171  {
173  return m_sStarting;
174  case MM_OUTPUTTYPETPAGE:
175  return m_sDocumentType;
176  case MM_ADDRESSBLOCKPAGE:
177  return m_xConfigItem->IsOutputToLetter() ?
179  case MM_GREETINGSPAGE:
180  return m_sGreetingsLine;
181  case MM_LAYOUTPAGE:
182  return m_sLayout;
183  }
184  return OUString();
185 }
186 
187 // enables/disables pages in the roadmap depending on the current page and state
189 {
190 /*
191  MM_DOCUMENTSELECTPAGE > inactive after the layoutpage
192  MM_OUTPUTTYPETPAGE : > inactive after the layoutpage
193  MM_ADDRESSBLOCKPAGE > inactive after the layoutpage
194  MM_GREETINGSPAGE > inactive after the layoutpage
195  MM_LAYOUTPAGE > inactive after the layoutpage
196  inactive if address block and greeting are switched off
197  or are already inserted into the source document
198 */
199 
200  // enableState( <page id>, false );
201  const sal_uInt16 nCurPage = m_xAssistant->get_current_page();
202  TabPage* pCurPage = GetPage( nCurPage );
203  if(!pCurPage)
204  return;
205  bool bAddressFieldsConfigured = !m_xConfigItem->IsOutputToLetter() ||
206  !m_xConfigItem->IsAddressBlock() ||
207  m_xConfigItem->IsAddressFieldsAssigned();
208  bool bGreetingFieldsConfigured = !m_xConfigItem->IsGreetingLine(false) ||
209  !m_xConfigItem->IsIndividualGreeting(false) ||
210  m_xConfigItem->IsGreetingFieldsAssigned();
211 
212  //#i97436# if a document has to be loaded then enable output type page only
213  m_bDocumentLoad = false;
214  bool bEnableOutputTypePage = (nCurPage != MM_DOCUMENTSELECTPAGE) ||
215  static_cast<vcl::OWizardPage*>(pCurPage)->commitPage( ::vcl::WizardTypes::eValidate );
216 
217  // handle the Finish button
218  bool bCanFinish = !m_bDocumentLoad && bEnableOutputTypePage &&
219  m_xConfigItem->GetResultSet().is() &&
220  bAddressFieldsConfigured &&
221  bGreetingFieldsConfigured;
222  enableButtons(WizardButtonFlags::FINISH, (nCurPage != MM_DOCUMENTSELECTPAGE) && bCanFinish);
223 
224  for(sal_uInt16 nPage = MM_DOCUMENTSELECTPAGE; nPage <= MM_LAYOUTPAGE; ++nPage)
225  {
226  bool bEnable = true;
227  switch(nPage)
228  {
230  bEnable = true;
231  break;
232  case MM_OUTPUTTYPETPAGE:
233  bEnable = bEnableOutputTypePage;
234  break;
235  case MM_ADDRESSBLOCKPAGE:
236  bEnable = !m_bDocumentLoad && bEnableOutputTypePage;
237  // update page title for email vs letter
238  m_xAssistant->set_page_title(OString::number(MM_ADDRESSBLOCKPAGE), getStateDisplayName(MM_ADDRESSBLOCKPAGE));
239  break;
240  case MM_GREETINGSPAGE:
241  bEnable = !m_bDocumentLoad && bEnableOutputTypePage &&
242  m_xConfigItem->GetResultSet().is() &&
243  bAddressFieldsConfigured;
244  break;
245  case MM_LAYOUTPAGE:
246  bEnable = bCanFinish &&
247  ((m_xConfigItem->IsAddressBlock() && !m_xConfigItem->IsAddressInserted()) ||
248  (m_xConfigItem->IsGreetingLine(false) && !m_xConfigItem->IsGreetingInserted() ));
249  break;
250  }
251  enableState( nPage, bEnable );
252  }
253 }
254 
256 {
257  OSL_FAIL("SwMailMergeWizard cannot be executed via Dialog::Execute!\n"
258  "It creates a thread (MailDispatcher instance) that will call"
259  "back to VCL apartment => deadlock!\n"
260  "Use Dialog::StartExecuteAsync to execute the dialog!" );
261  return RET_CANCEL;
262 }
263 
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString const m_sAddressBlock
std::unique_ptr< weld::Button > m_xPrevPage
void declarePath(RoadmapWizardTypes::PathId _nPathId, const RoadmapWizardTypes::WizardPath &_lWizardStates)
OUString const m_sGreetingsLine
#define MM_OUTPUTTYPETPAGE
virtual void ActivatePage()
virtual void enterState(WizardTypes::WizardState nState) override
RET_CANCEL
#define MM_LAYOUTPAGE
void defaultButton(WizardButtonFlags _nWizardButtonFlags)
OUString const m_sLayout
virtual VclPtr< TabPage > createPage(WizardState _nState) override
#define MM_ADDRESSBLOCKPAGE
#define MM_DOCUMENTSELECTPAGE
#define MM_GREETINGSPAGE
SwMailMergeWizard(SwView &rView, std::shared_ptr< SwMailMergeConfigItem > const &rConfigItem)
std::unique_ptr< weld::Button > m_xNextPage
sal_Int16 WizardState
void SetRoadmapHelpId(const OString &_rId)
virtual OUString getStateDisplayName(WizardState _nState) const override
weld::Window * GetFrameWeld(SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
sal_uInt16 m_nRestartPage
virtual ~SwMailMergeWizard() override
OUString SwResId(const char *pId)
Definition: swmodule.cxx:191
void enableState(WizardTypes::WizardState nState, bool _bEnable=true)
#define RET_REMOVE_TARGET
Definition: swabstdlg.hxx:346
OUString const m_sDocumentType
std::unique_ptr< weld::Button > m_xFinish
#define HID_MM_PREV_PAGE
Definition: helpids.h:145
virtual void enterState(WizardState _nState) override
void setTitleBase(const OUString &_rTitleBase)
static VclPtr< reference_type > Create(Arg &&...arg)
OUString const m_sAddressList
#define HID_MM_NEXT_PAGE
Definition: helpids.h:144
void enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable)
OUString const m_sStarting
std::shared_ptr< SwMailMergeConfigItem > m_xConfigItem
std::unique_ptr< weld::Assistant > m_xAssistant
virtual short run() override
Definition: view.hxx:146
TabPage * GetPage(WizardTypes::WizardState eState) const