Debian Codegraph @

chart2/source/controller/dialogs/dlg_CreationWizard.cxx

raw
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 <dlg_CreationWizard.hxx>
21 #include <ResId.hxx>
22 #include <strings.hrc>
23 #include <helpids.h>
24 #include <ChartModel.hxx>
25
26 #include "tp_ChartType.hxx"
27 #include "tp_RangeChooser.hxx"
28 #include "tp_Wizard_TitlesAndObjects.hxx"
29 #include "tp_DataSource.hxx"
30 #include <ChartTypeTemplateProvider.hxx>
31 #include <ChartTypeTemplate.hxx>
32 #include <utility>
33 #include "DialogModel.hxx"
34
35 using namespace css;
36
37 using vcl::RoadmapWizardTypes::WizardPath;
38 using vcl::RoadmapWizardTypes::PathId;
39
40 namespace chart
41 {
42
43 namespace {
44 enum CreationWizardState{
45 First = 0,
46 CharType = First,
47 SimpleRange = 1,
48 DataSeries = 2,
49 Objects = 3,
50 Last = Objects
51 };
52 }
53
54 CreationWizard::CreationWizard(weld::Window* pParent, const rtl::Reference<::chart::ChartModel>& xChartModel,
55 uno::Reference<uno::XComponentContext> xContext)
56 : vcl::RoadmapWizardMachine(pParent)
57 , m_xChartModel(xChartModel)
58 , m_xComponentContext(std::move(xContext))
59 , m_pTemplateProvider(nullptr)
60 , m_aTimerTriggeredControllerLock(xChartModel)
61 , m_bCanTravel(true)
62 {
63 m_pDialogModel.reset(new DialogModel(m_xChartModel));
64 defaultButton(WizardButtonFlags::FINISH);
65
66 setTitleBase(SchResId(STR_DLG_CHART_WIZARD));
67
68 // tdf#134386 set m_pTemplateProvider before creating any other pages
69 m_pTemplateProvider = static_cast<ChartTypeTabPage*>(GetOrCreatePage(CreationWizardState::CharType));
70 assert(m_pTemplateProvider && "must exist");
71 m_pDialogModel->setTemplate(m_pTemplateProvider->getCurrentTemplate());
72
73 WizardPath aPath = {
74 CreationWizardState::CharType,
75 CreationWizardState::SimpleRange,
76 CreationWizardState::DataSeries,
77 CreationWizardState::Objects
78 };
79
80 declarePath(PathId::COMPLETE, aPath);
81
82 // tdf#135935 ensure help ID is set when no element is clicked in the dialog
83 m_xAssistant->set_help_id(HID_SCH_WIZARD_ROADMAP);
84
85 if (!m_pDialogModel->getModel().isDataFromSpreadsheet())
86 {
87 enableState(CreationWizardState::SimpleRange, false);
88 enableState(CreationWizardState::DataSeries, false);
89 }
90
91 // Call ActivatePage, to create and activate the first page
92 ActivatePage();
93
94 m_xAssistant->set_current_page(0);
95 }
96
97 CreationWizard::~CreationWizard() = default;
98
99 std::unique_ptr<BuilderPage> CreationWizard::createPage(WizardState nState)
100 {
101 std::unique_ptr<vcl::OWizardPage> xRet;
102
103 OUString sIdent(OUString::number(nState));
104 weld::Container* pPageContainer = m_xAssistant->append_page(sIdent);
105
106 switch( nState )
107 {
108 case CreationWizardState::CharType:
109 {
110 m_aTimerTriggeredControllerLock.startTimer();
111 xRet = std::make_unique<ChartTypeTabPage>(pPageContainer, this, m_xChartModel);
112 break;
113 }
114 case CreationWizardState::SimpleRange:
115 {
116 m_aTimerTriggeredControllerLock.startTimer();
117 xRet = std::make_unique<RangeChooserTabPage>(pPageContainer, this, *m_pDialogModel, m_pTemplateProvider);
118 break;
119 }
120 case CreationWizardState::DataSeries:
121 {
122 m_aTimerTriggeredControllerLock.startTimer();
123 xRet = std::make_unique<DataSourceTabPage>(pPageContainer, this, *m_pDialogModel, m_pTemplateProvider);
124 break;
125 }
126 case CreationWizardState::Objects:
127 {
128 xRet = std::make_unique<TitlesAndObjectsTabPage>(pPageContainer, this, m_xChartModel, m_xComponentContext);
129 m_aTimerTriggeredControllerLock.startTimer();
130 break;
131 }
132 default:
133 break;
134 }
135
136 if (xRet)
137 xRet->SetPageTitle(OUString()); //remove title of pages to not get them in the wizard title
138
139 return xRet;
140 }
141
142 bool CreationWizard::leaveState( WizardState /*_nState*/ )
143 {
144 return m_bCanTravel;
145 }
146
147 vcl::WizardTypes::WizardState CreationWizard::determineNextState( WizardState nCurrentState ) const
148 {
149 if( !m_bCanTravel )
150 return WZS_INVALID_STATE;
151 if( nCurrentState == CreationWizardState::Last)
152 return WZS_INVALID_STATE;
153 vcl::WizardTypes::WizardState nNextState = nCurrentState + 1;
154 while( !isStateEnabled( nNextState ) && nNextState <= CreationWizardState::Last )
155 ++nNextState;
156 return (nNextState==CreationWizardState::Last+1) ? WZS_INVALID_STATE : nNextState;
157 }
158
159 void CreationWizard::enterState(WizardState nState)
160 {
161 m_aTimerTriggeredControllerLock.startTimer();
162 enableButtons( WizardButtonFlags::PREVIOUS, nState > CreationWizardState::First);
163 enableButtons( WizardButtonFlags::NEXT, nState < CreationWizardState::Last);
164 if( isStateEnabled( nState ))
165 vcl::RoadmapWizardMachine::enterState(nState);
166 }
167
168 void CreationWizard::setInvalidPage(BuilderPage* pTabPage)
169 {
170 if (pTabPage == m_pCurTabPage)
171 m_bCanTravel = false;
172 }
173
174 void CreationWizard::setValidPage(BuilderPage* pTabPage)
175 {
176 if (pTabPage == m_pCurTabPage)
177 m_bCanTravel = true;
178 }
179
180 OUString CreationWizard::getStateDisplayName( WizardState nState ) const
181 {
182 TranslateId pResId;
183 switch( nState )
184 {
185 case CreationWizardState::CharType:
186 pResId = STR_PAGE_CHARTTYPE;
187 break;
188 case CreationWizardState::SimpleRange:
189 pResId = STR_PAGE_DATA_RANGE;
190 break;
191 case CreationWizardState::DataSeries:
192 pResId = STR_OBJECT_DATASERIES_PLURAL;
193 break;
194 case CreationWizardState::Objects:
195 pResId = STR_PAGE_CHART_ELEMENTS;
196 break;
197 default:
198 break;
199 }
200 if (!pResId)
201 return OUString();
202 return SchResId(pResId);
203 }
204
205 } //namespace chart
206
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */