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 
91 std::unique_ptr<BuilderPage> SwMailMergeWizard::createPage(WizardState _nState)
92 {
93  OString sIdent(OString::number(_nState));
94  weld::Container* pPageContainer = m_xAssistant->append_page(sIdent);
95 
96  std::unique_ptr<vcl::OWizardPage> xRet;
97  switch(_nState)
98  {
100  xRet = std::make_unique<SwMailMergeDocSelectPage>(pPageContainer, this);
101 
102  /* tdf#52986 Set help ID using SetRoadmapHelpId for all pages
103  so that when by default the focus is on the left side pane of
104  the wizard the relevant help page is displayed when hitting
105  the Help / F1 button */
106  SetRoadmapHelpId("modules/swriter/ui/mmselectpage/MMSelectPage");
107  break;
108  case MM_OUTPUTTYPETPAGE :
109  xRet = std::make_unique<SwMailMergeOutputTypePage>(pPageContainer, this);
110  SetRoadmapHelpId("modules/swriter/ui/mmoutputtypepage/MMOutputTypePage");
111  break;
112  case MM_ADDRESSBLOCKPAGE :
113  xRet = std::make_unique<SwMailMergeAddressBlockPage>(pPageContainer, this);
114  SetRoadmapHelpId("modules/swriter/ui/mmaddressblockpage/MMAddressBlockPage");
115  break;
116  case MM_GREETINGSPAGE :
117  xRet = std::make_unique<SwMailMergeGreetingsPage>(pPageContainer, this);
118  SetRoadmapHelpId("modules/swriter/ui/mmsalutationpage/MMSalutationPage");
119  break;
120  case MM_LAYOUTPAGE :
121  xRet = std::make_unique<SwMailMergeLayoutPage>(pPageContainer, this);
122  SetRoadmapHelpId("modules/swriter/ui/mmlayoutpage/MMLayoutPage");
123  break;
124  }
125 
126  m_xAssistant->set_page_title(sIdent, getStateDisplayName(_nState));
127 
128  OSL_ENSURE(xRet, "no page created in ::createPage");
129  return xRet;
130 }
131 
133 {
135 
136  if (m_xConfigItem->GetTargetView())
137  {
138  //close the dialog, remove the target view, show the source view
139  m_nRestartPage = _nState;
140  //set ResultSet back to start
141  m_xConfigItem->MoveResultSet(1);
142  m_xAssistant->response(RET_REMOVE_TARGET);
143  return;
144  }
145  bool bEnablePrev = true;
146  bool bEnableNext = true;
147  switch(_nState)
148  {
150  bEnablePrev = false; // the first page
151  break;
152  case MM_ADDRESSBLOCKPAGE :
153  bEnableNext = m_xConfigItem->GetResultSet().is();
154  break;
155  case MM_LAYOUTPAGE:
156  bEnableNext = false; // the last page
157  break;
158  }
159  enableButtons( WizardButtonFlags::PREVIOUS, bEnablePrev);
160  enableButtons( WizardButtonFlags::NEXT, bEnableNext);
161 
162  UpdateRoadmap();
163 }
164 
166 {
167  switch(_nState)
168  {
170  return m_sStarting;
171  case MM_OUTPUTTYPETPAGE:
172  return m_sDocumentType;
173  case MM_ADDRESSBLOCKPAGE:
174  return m_xConfigItem->IsOutputToLetter() ?
176  case MM_GREETINGSPAGE:
177  return m_sGreetingsLine;
178  case MM_LAYOUTPAGE:
179  return m_sLayout;
180  }
181  return OUString();
182 }
183 
184 // enables/disables pages in the roadmap depending on the current page and state
186 {
187 /*
188  MM_DOCUMENTSELECTPAGE > inactive after the layoutpage
189  MM_OUTPUTTYPETPAGE : > inactive after the layoutpage
190  MM_ADDRESSBLOCKPAGE > inactive after the layoutpage
191  MM_GREETINGSPAGE > inactive after the layoutpage
192  MM_LAYOUTPAGE > inactive after the layoutpage
193  inactive if address block and greeting are switched off
194  or are already inserted into the source document
195 */
196 
197  // enableState( <page id>, false );
198  const sal_uInt16 nCurPage = m_xAssistant->get_current_page();
199  BuilderPage* pCurPage = GetPage( nCurPage );
200  if(!pCurPage)
201  return;
202  bool bAddressFieldsConfigured = !m_xConfigItem->IsOutputToLetter() ||
203  !m_xConfigItem->IsAddressBlock() ||
204  m_xConfigItem->IsAddressFieldsAssigned();
205  bool bGreetingFieldsConfigured = !m_xConfigItem->IsGreetingLine(false) ||
206  !m_xConfigItem->IsIndividualGreeting(false) ||
207  m_xConfigItem->IsGreetingFieldsAssigned();
208 
209  //#i97436# if a document has to be loaded then enable output type page only
210  m_bDocumentLoad = false;
211  bool bEnableOutputTypePage = (nCurPage != MM_DOCUMENTSELECTPAGE) ||
212  static_cast<vcl::OWizardPage*>(pCurPage)->commitPage( ::vcl::WizardTypes::eValidate );
213 
214  // handle the Finish button
215  bool bCanFinish = !m_bDocumentLoad && bEnableOutputTypePage &&
216  m_xConfigItem->GetResultSet().is() &&
217  bAddressFieldsConfigured &&
218  bGreetingFieldsConfigured;
219  enableButtons(WizardButtonFlags::FINISH, (nCurPage != MM_DOCUMENTSELECTPAGE) && bCanFinish);
220 
221  for(sal_uInt16 nPage = MM_DOCUMENTSELECTPAGE; nPage <= MM_LAYOUTPAGE; ++nPage)
222  {
223  bool bEnable = true;
224  switch(nPage)
225  {
227  bEnable = true;
228  break;
229  case MM_OUTPUTTYPETPAGE:
230  bEnable = bEnableOutputTypePage;
231  break;
232  case MM_ADDRESSBLOCKPAGE:
233  bEnable = !m_bDocumentLoad && bEnableOutputTypePage;
234  // update page title for email vs letter
235  m_xAssistant->set_page_title(OString::number(MM_ADDRESSBLOCKPAGE), getStateDisplayName(MM_ADDRESSBLOCKPAGE));
236  break;
237  case MM_GREETINGSPAGE:
238  bEnable = !m_bDocumentLoad && bEnableOutputTypePage &&
239  m_xConfigItem->GetResultSet().is() &&
240  bAddressFieldsConfigured;
241  break;
242  case MM_LAYOUTPAGE:
243  bEnable = bCanFinish &&
244  ((m_xConfigItem->IsAddressBlock() && !m_xConfigItem->IsAddressInserted()) ||
245  (m_xConfigItem->IsGreetingLine(false) && !m_xConfigItem->IsGreetingInserted() ));
246  break;
247  }
248  enableState( nPage, bEnable );
249  }
250 }
251 
253 {
254  OSL_FAIL("SwMailMergeWizard cannot be executed via Dialog::Execute!\n"
255  "It creates a thread (MailDispatcher instance) that will call"
256  "back to VCL apartment => deadlock!\n"
257  "Use Dialog::StartExecuteAsync to execute the dialog!" );
258  return RET_CANCEL;
259 }
260 
261 /* 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)
virtual std::unique_ptr< BuilderPage > createPage(WizardState _nState) override
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
#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:190
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)
OUString const m_sAddressList
#define HID_MM_NEXT_PAGE
Definition: helpids.h:144
void enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable)
BuilderPage * GetPage(WizardTypes::WizardState eState) const
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