1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
35 using namespace ::com::sun::star
;
37 SwMailMergeWizard::SwMailMergeWizard(SwView
& rView
, std::shared_ptr
<SwMailMergeConfigItem
> xItem
)
38 : RoadmapWizardMachine(rView
.GetFrameWeld())
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
)
50 defaultButton(WizardButtonFlags::NEXT
);
51 enableButtons(WizardButtonFlags::FINISH
, false);
53 setTitleBase(SwResId(ST_MMWTITLE
));
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
);
59 //#i51949# no output type page visible if e-Mail is not supported
60 if (m_xConfigItem
->IsMailAvailable())
63 {MM_DOCUMENTSELECTPAGE
,
72 {MM_DOCUMENTSELECTPAGE
,
79 m_xAssistant
->set_current_page(0);
83 SwMailMergeWizard::~SwMailMergeWizard()
87 std::unique_ptr
<BuilderPage
> SwMailMergeWizard::createPage(WizardState _nState
)
89 OUString
sIdent(OUString::number(_nState
));
90 weld::Container
* pPageContainer
= m_xAssistant
->append_page(sIdent
);
92 std::unique_ptr
<vcl::OWizardPage
> xRet
;
95 case MM_DOCUMENTSELECTPAGE
:
96 xRet
= std::make_unique
<SwMailMergeDocSelectPage
>(pPageContainer
, this);
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");
104 case MM_OUTPUTTYPETPAGE
:
105 xRet
= std::make_unique
<SwMailMergeOutputTypePage
>(pPageContainer
, this);
106 SetRoadmapHelpId("modules/swriter/ui/mmoutputtypepage/MMOutputTypePage");
108 case MM_ADDRESSBLOCKPAGE
:
109 xRet
= std::make_unique
<SwMailMergeAddressBlockPage
>(pPageContainer
, this);
110 SetRoadmapHelpId("modules/swriter/ui/mmaddressblockpage/MMAddressBlockPage");
112 case MM_GREETINGSPAGE
:
113 xRet
= std::make_unique
<SwMailMergeGreetingsPage
>(pPageContainer
, this);
114 SetRoadmapHelpId("modules/swriter/ui/mmsalutationpage/MMSalutationPage");
117 xRet
= std::make_unique
<SwMailMergeLayoutPage
>(pPageContainer
, this);
118 SetRoadmapHelpId("modules/swriter/ui/mmlayoutpage/MMLayoutPage");
122 m_xAssistant
->set_page_title(sIdent
, getStateDisplayName(_nState
));
124 OSL_ENSURE(xRet
, "no page created in ::createPage");
128 void SwMailMergeWizard::enterState( WizardState _nState
)
130 ::vcl::RoadmapWizardMachine::enterState( _nState
);
132 if (m_xConfigItem
->GetTargetView())
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);
138 m_xAssistant
->response(RET_REMOVE_TARGET
);
141 bool bEnablePrev
= true;
142 bool bEnableNext
= true;
145 case MM_DOCUMENTSELECTPAGE
:
147 bEnablePrev
= false; // the first page
149 OUString sDataSourceName
= GetSwView()->GetDataSourceName();
150 if(!sDataSourceName
.isEmpty() &&
151 !SwView::IsDataSourceAvailable(sDataSourceName
))
157 case MM_ADDRESSBLOCKPAGE
:
158 bEnableNext
= m_xConfigItem
->GetResultSet().is();
161 bEnableNext
= false; // the last page
164 enableButtons( WizardButtonFlags::PREVIOUS
, bEnablePrev
);
165 enableButtons( WizardButtonFlags::NEXT
, bEnableNext
);
170 OUString
SwMailMergeWizard::getStateDisplayName( WizardState _nState
) const
174 case MM_DOCUMENTSELECTPAGE
:
176 case MM_OUTPUTTYPETPAGE
:
177 return m_sDocumentType
;
178 case MM_ADDRESSBLOCKPAGE
:
179 return m_xConfigItem
->IsOutputToLetter() ?
180 m_sAddressBlock
: m_sAddressList
;
181 case MM_GREETINGSPAGE
:
182 return m_sGreetingsLine
;
189 // enables/disables pages in the roadmap depending on the current page and state
190 void SwMailMergeWizard::UpdateRoadmap()
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
202 // enableState( <page id>, false );
203 const sal_uInt16 nCurPage
= m_xAssistant
->get_current_page();
204 BuilderPage
* pCurPage
= GetPage( nCurPage
);
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();
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
);
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
);
226 for(sal_uInt16 nPage
= MM_DOCUMENTSELECTPAGE
; nPage
<= MM_LAYOUTPAGE
; ++nPage
)
231 case MM_DOCUMENTSELECTPAGE
:
234 case MM_OUTPUTTYPETPAGE
:
235 bEnable
= bEnableOutputTypePage
;
237 case MM_ADDRESSBLOCKPAGE
:
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
));
242 case MM_GREETINGSPAGE
:
243 bEnable
= !m_bDocumentLoad
&& bEnableOutputTypePage
&&
244 m_xConfigItem
->GetResultSet().is() &&
245 bAddressFieldsConfigured
;
248 bEnable
= bCanFinish
&&
249 ((m_xConfigItem
->IsAddressBlock() && !m_xConfigItem
->IsAddressInserted()) ||
250 (m_xConfigItem
->IsGreetingLine(false) && !m_xConfigItem
->IsGreetingInserted() ));
253 enableState( nPage
, bEnable
);
257 short SwMailMergeWizard::run()
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!" );
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */