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