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