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