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 <dlg_CreationWizard.hxx>
22 #include <strings.hrc>
24 #include <ChartModel.hxx>
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>
33 #include "DialogModel.hxx"
37 using vcl::RoadmapWizardTypes::WizardPath
;
38 using vcl::RoadmapWizardTypes::PathId
;
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
49 CreationWizard::CreationWizard(weld::Window
* pParent
, const rtl::Reference
<::chart::ChartModel
>& xChartModel
,
50 uno::Reference
<uno::XComponentContext
> xContext
)
51 : vcl::RoadmapWizardMachine(pParent
)
52 , m_xChartModel(xChartModel
)
53 , m_xComponentContext(std::move(xContext
))
54 , m_pTemplateProvider(nullptr)
55 , m_aTimerTriggeredControllerLock(xChartModel
)
58 m_pDialogModel
.reset(new DialogModel(m_xChartModel
));
59 defaultButton(WizardButtonFlags::FINISH
);
61 setTitleBase(SchResId(STR_DLG_CHART_WIZARD
));
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());
75 declarePath(PathId::COMPLETE
, aPath
);
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
);
80 if (!m_pDialogModel
->getModel().isDataFromSpreadsheet())
82 enableState(STATE_SIMPLE_RANGE
, false);
83 enableState(STATE_DATA_SERIES
, false);
86 // Call ActivatePage, to create and activate the first page
89 m_xAssistant
->set_current_page(0);
92 CreationWizard::~CreationWizard() = default;
94 std::unique_ptr
<BuilderPage
> CreationWizard::createPage(WizardState nState
)
96 std::unique_ptr
<vcl::OWizardPage
> xRet
;
98 OUString
sIdent(OUString::number(nState
));
99 weld::Container
* pPageContainer
= m_xAssistant
->append_page(sIdent
);
103 case STATE_CHARTTYPE
:
105 m_aTimerTriggeredControllerLock
.startTimer();
106 xRet
= std::make_unique
<ChartTypeTabPage
>(pPageContainer
, this, m_xChartModel
);
109 case STATE_SIMPLE_RANGE
:
111 m_aTimerTriggeredControllerLock
.startTimer();
112 xRet
= std::make_unique
<RangeChooserTabPage
>(pPageContainer
, this, *m_pDialogModel
, m_pTemplateProvider
);
115 case STATE_DATA_SERIES
:
117 m_aTimerTriggeredControllerLock
.startTimer();
118 xRet
= std::make_unique
<DataSourceTabPage
>(pPageContainer
, this, *m_pDialogModel
, m_pTemplateProvider
);
123 xRet
= std::make_unique
<TitlesAndObjectsTabPage
>(pPageContainer
, this, m_xChartModel
, m_xComponentContext
);
124 m_aTimerTriggeredControllerLock
.startTimer();
132 xRet
->SetPageTitle(OUString()); //remove title of pages to not get them in the wizard title
137 bool CreationWizard::leaveState( WizardState
/*_nState*/ )
142 vcl::WizardTypes::WizardState
CreationWizard::determineNextState( WizardState nCurrentState
) const
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
)
151 return (nNextState
==STATE_LAST
+1) ? WZS_INVALID_STATE
: nNextState
;
154 void CreationWizard::enterState(WizardState nState
)
156 m_aTimerTriggeredControllerLock
.startTimer();
157 enableButtons( WizardButtonFlags::PREVIOUS
, nState
> STATE_FIRST
);
158 enableButtons( WizardButtonFlags::NEXT
, nState
< STATE_LAST
);
159 if( isStateEnabled( nState
))
160 vcl::RoadmapWizardMachine::enterState(nState
);
163 void CreationWizard::setInvalidPage(BuilderPage
* pTabPage
)
165 if (pTabPage
== m_pCurTabPage
)
166 m_bCanTravel
= false;
169 void CreationWizard::setValidPage(BuilderPage
* pTabPage
)
171 if (pTabPage
== m_pCurTabPage
)
175 OUString
CreationWizard::getStateDisplayName( WizardState nState
) const
180 case STATE_CHARTTYPE
:
181 pResId
= STR_PAGE_CHARTTYPE
;
183 case STATE_SIMPLE_RANGE
:
184 pResId
= STR_PAGE_DATA_RANGE
;
186 case STATE_DATA_SERIES
:
187 pResId
= STR_OBJECT_DATASERIES_PLURAL
;
190 pResId
= STR_PAGE_CHART_ELEMENTS
;
197 return SchResId(pResId
);
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */