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 <strings.hrc>
29 #include <view.hxx>
30 
31 #include <helpids.h>
32 
33 using namespace svt;
34 using namespace ::com::sun::star;
35 
36 SwMailMergeWizard::SwMailMergeWizard(SwView& rView, std::shared_ptr<SwMailMergeConfigItem> const & rItem)
37  : RoadmapWizardMachine(rView.GetFrameWeld())
38  , m_pSwView(&rView)
39  , m_bDocumentLoad(false)
40  , m_xConfigItem(rItem)
41  , m_sStarting(SwResId(ST_STARTING))
42  , m_sDocumentType(SwResId(ST_DOCUMENTTYPE))
43  , m_sAddressBlock(SwResId(ST_ADDRESSBLOCK))
44  , m_sAddressList(SwResId(ST_ADDRESSLIST))
45  , m_sGreetingsLine(SwResId(ST_GREETINGSLINE))
46  , m_sLayout(SwResId(ST_LAYOUT))
47  , m_nRestartPage(MM_DOCUMENTSELECTPAGE)
48 {
49  defaultButton(WizardButtonFlags::NEXT);
50  enableButtons(WizardButtonFlags::FINISH, false);
51 
52  setTitleBase(SwResId(ST_MMWTITLE));
53 
54  m_xFinish->set_label(SwResId( ST_FINISH ));
55  m_xNextPage->set_help_id(HID_MM_NEXT_PAGE);
56  m_xPrevPage->set_help_id(HID_MM_PREV_PAGE);
57 
58  //#i51949# no output type page visible if e-Mail is not supported
59  if (m_xConfigItem->IsMailAvailable())
61  0,
67  );
68  else
70  0,
75  );
76 
77  ActivatePage();
78  m_xAssistant->set_current_page(0);
79  UpdateRoadmap();
80 }
81 
83 {
84 }
85 
86 std::unique_ptr<BuilderPage> SwMailMergeWizard::createPage(WizardState _nState)
87 {
88  OString sIdent(OString::number(_nState));
89  weld::Container* pPageContainer = m_xAssistant->append_page(sIdent);
90 
91  std::unique_ptr<vcl::OWizardPage> xRet;
92  switch(_nState)
93  {
95  xRet = std::make_unique<SwMailMergeDocSelectPage>(pPageContainer, this);
96 
97  /* tdf#52986 Set help ID using SetRoadmapHelpId for all pages
98  so that when by default the focus is on the left side pane of
99  the wizard the relevant help page is displayed when hitting
100  the Help / F1 button */
101  SetRoadmapHelpId("modules/swriter/ui/mmselectpage/MMSelectPage");
102  break;
103  case MM_OUTPUTTYPETPAGE :
104  xRet = std::make_unique<SwMailMergeOutputTypePage>(pPageContainer, this);
105  SetRoadmapHelpId("modules/swriter/ui/mmoutputtypepage/MMOutputTypePage");
106  break;
107  case MM_ADDRESSBLOCKPAGE :
108  xRet = std::make_unique<SwMailMergeAddressBlockPage>(pPageContainer, this);
109  SetRoadmapHelpId("modules/swriter/ui/mmaddressblockpage/MMAddressBlockPage");
110  break;
111  case MM_GREETINGSPAGE :
112  xRet = std::make_unique<SwMailMergeGreetingsPage>(pPageContainer, this);
113  SetRoadmapHelpId("modules/swriter/ui/mmsalutationpage/MMSalutationPage");
114  break;
115  case MM_LAYOUTPAGE :
116  xRet = std::make_unique<SwMailMergeLayoutPage>(pPageContainer, this);
117  SetRoadmapHelpId("modules/swriter/ui/mmlayoutpage/MMLayoutPage");
118  break;
119  }
120 
121  m_xAssistant->set_page_title(sIdent, getStateDisplayName(_nState));
122 
123  OSL_ENSURE(xRet, "no page created in ::createPage");
124  return xRet;
125 }
126 
128 {
130 
131  if (m_xConfigItem->GetTargetView())
132  {
133  //close the dialog, remove the target view, show the source view
134  m_nRestartPage = _nState;
135  //set ResultSet back to start
136  m_xConfigItem->MoveResultSet(1);
137  m_xAssistant->response(RET_REMOVE_TARGET);
138  return;
139  }
140  bool bEnablePrev = true;
141  bool bEnableNext = true;
142  switch(_nState)
143  {
145  bEnablePrev = false; // the first page
146  break;
147  case MM_ADDRESSBLOCKPAGE :
148  bEnableNext = m_xConfigItem->GetResultSet().is();
149  break;
150  case MM_LAYOUTPAGE:
151  bEnableNext = false; // the last page
152  break;
153  }
154  enableButtons( WizardButtonFlags::PREVIOUS, bEnablePrev);
155  enableButtons( WizardButtonFlags::NEXT, bEnableNext);
156 
157  UpdateRoadmap();
158 }
159 
161 {
162  switch(_nState)
163  {
165  return m_sStarting;
166  case MM_OUTPUTTYPETPAGE:
167  return m_sDocumentType;
168  case MM_ADDRESSBLOCKPAGE:
169  return m_xConfigItem->IsOutputToLetter() ?
171  case MM_GREETINGSPAGE:
172  return m_sGreetingsLine;
173  case MM_LAYOUTPAGE:
174  return m_sLayout;
175  }
176  return OUString();
177 }
178 
179 // enables/disables pages in the roadmap depending on the current page and state
181 {
182 /*
183  MM_DOCUMENTSELECTPAGE > inactive after the layoutpage
184  MM_OUTPUTTYPETPAGE : > inactive after the layoutpage
185  MM_ADDRESSBLOCKPAGE > inactive after the layoutpage
186  MM_GREETINGSPAGE > inactive after the layoutpage
187  MM_LAYOUTPAGE > inactive after the layoutpage
188  inactive if address block and greeting are switched off
189  or are already inserted into the source document
190 */
191 
192  // enableState( <page id>, false );
193  const sal_uInt16 nCurPage = m_xAssistant->get_current_page();
194  BuilderPage* pCurPage = GetPage( nCurPage );
195  if(!pCurPage)
196  return;
197  bool bAddressFieldsConfigured = !m_xConfigItem->IsOutputToLetter() ||
198  !m_xConfigItem->IsAddressBlock() ||
199  m_xConfigItem->IsAddressFieldsAssigned();
200  bool bGreetingFieldsConfigured = !m_xConfigItem->IsGreetingLine(false) ||
201  !m_xConfigItem->IsIndividualGreeting(false) ||
202  m_xConfigItem->IsGreetingFieldsAssigned();
203 
204  //#i97436# if a document has to be loaded then enable output type page only
205  m_bDocumentLoad = false;
206  bool bEnableOutputTypePage = (nCurPage != MM_DOCUMENTSELECTPAGE) ||
207  static_cast<vcl::OWizardPage*>(pCurPage)->commitPage( ::vcl::WizardTypes::eValidate );
208 
209  // handle the Finish button
210  bool bCanFinish = !m_bDocumentLoad && bEnableOutputTypePage &&
211  m_xConfigItem->GetResultSet().is() &&
212  bAddressFieldsConfigured &&
213  bGreetingFieldsConfigured;
214  enableButtons(WizardButtonFlags::FINISH, (nCurPage != MM_DOCUMENTSELECTPAGE) && bCanFinish);
215 
216  for(sal_uInt16 nPage = MM_DOCUMENTSELECTPAGE; nPage <= MM_LAYOUTPAGE; ++nPage)
217  {
218  bool bEnable = true;
219  switch(nPage)
220  {
222  bEnable = true;
223  break;
224  case MM_OUTPUTTYPETPAGE:
225  bEnable = bEnableOutputTypePage;
226  break;
227  case MM_ADDRESSBLOCKPAGE:
228  bEnable = !m_bDocumentLoad && bEnableOutputTypePage;
229  // update page title for email vs letter
230  m_xAssistant->set_page_title(OString::number(MM_ADDRESSBLOCKPAGE), getStateDisplayName(MM_ADDRESSBLOCKPAGE));
231  break;
232  case MM_GREETINGSPAGE:
233  bEnable = !m_bDocumentLoad && bEnableOutputTypePage &&
234  m_xConfigItem->GetResultSet().is() &&
235  bAddressFieldsConfigured;
236  break;
237  case MM_LAYOUTPAGE:
238  bEnable = bCanFinish &&
239  ((m_xConfigItem->IsAddressBlock() && !m_xConfigItem->IsAddressInserted()) ||
240  (m_xConfigItem->IsGreetingLine(false) && !m_xConfigItem->IsGreetingInserted() ));
241  break;
242  }
243  enableState( nPage, bEnable );
244  }
245 }
246 
248 {
249  OSL_FAIL("SwMailMergeWizard cannot be executed via Dialog::Execute!\n"
250  "It creates a thread (MailDispatcher instance) that will call"
251  "back to VCL apartment => deadlock!\n"
252  "Use Dialog::StartExecuteAsync to execute the dialog!" );
253  return RET_CANCEL;
254 }
255 
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Button > m_xPrevPage
void declarePath(RoadmapWizardTypes::PathId _nPathId, const RoadmapWizardTypes::WizardPath &_lWizardStates)
virtual std::unique_ptr< BuilderPage > createPage(WizardState _nState) override
#define MM_OUTPUTTYPETPAGE
virtual void ActivatePage()
virtual void enterState(WizardTypes::WizardState nState) override
RET_CANCEL
#define MM_LAYOUTPAGE
void defaultButton(WizardButtonFlags _nWizardButtonFlags)
#define MM_ADDRESSBLOCKPAGE
#define MM_DOCUMENTSELECTPAGE
#define MM_GREETINGSPAGE
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
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
sal_uInt16 m_nRestartPage
virtual ~SwMailMergeWizard() override
OUString SwResId(const char *pId)
Definition: swmodule.cxx:178
void enableState(WizardTypes::WizardState nState, bool _bEnable=true)
#define RET_REMOVE_TARGET
Definition: swabstdlg.hxx:346
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)
#define HID_MM_NEXT_PAGE
Definition: helpids.h:144
void enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable)
BuilderPage * GetPage(WizardTypes::WizardState eState) const
std::shared_ptr< SwMailMergeConfigItem > m_xConfigItem
std::unique_ptr< weld::Assistant > m_xAssistant
virtual short run() override
Definition: view.hxx:146