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>
25 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
27 #include "tp_ChartType.hxx"
28 #include "tp_RangeChooser.hxx"
29 #include "tp_Wizard_TitlesAndObjects.hxx"
30 #include "tp_DataSource.hxx"
31 #include <ChartTypeTemplateProvider.hxx>
32 #include "DialogModel.hxx"
36 using vcl::RoadmapWizardTypes::WizardPath
;
42 #define STATE_CHARTTYPE STATE_FIRST
43 #define STATE_SIMPLE_RANGE 1
44 #define STATE_DATA_SERIES 2
45 #define STATE_OBJECTS 3
46 #define STATE_LAST STATE_OBJECTS
48 CreationWizard::CreationWizard(weld::Window
* pParent
, const uno::Reference
<frame::XModel
>& xChartModel
,
49 const uno::Reference
<uno::XComponentContext
>& xContext
)
50 : vcl::RoadmapWizardMachine(pParent
)
51 , m_xChartModel(xChartModel
,uno::UNO_QUERY
)
52 , m_xComponentContext(xContext
)
53 , m_pTemplateProvider(nullptr)
54 , m_aTimerTriggeredControllerLock(xChartModel
)
57 m_pDialogModel
.reset(new DialogModel(m_xChartModel
, m_xComponentContext
));
58 defaultButton(WizardButtonFlags::FINISH
);
60 setTitleBase(SchResId(STR_DLG_CHART_WIZARD
));
69 declarePath(PATH_FULL
, aPath
);
71 SetRoadmapHelpId(HID_SCH_WIZARD_ROADMAP
);
73 if (!m_pDialogModel
->getModel().isDataFromSpreadsheet())
75 enableState(STATE_SIMPLE_RANGE
, false);
76 enableState(STATE_DATA_SERIES
, false);
79 // Call ActivatePage, to create and activate the first page
82 m_xAssistant
->set_current_page(0);
85 CreationWizard::~CreationWizard() = default;
87 std::unique_ptr
<BuilderPage
> CreationWizard::createPage(WizardState nState
)
89 std::unique_ptr
<vcl::OWizardPage
> xRet
;
91 OString
sIdent(OString::number(nState
));
92 weld::Container
* pPageContainer
= m_xAssistant
->append_page(sIdent
);
98 m_aTimerTriggeredControllerLock
.startTimer();
99 xRet
= std::make_unique
<ChartTypeTabPage
>(pPageContainer
, this, m_xChartModel
);
100 m_pTemplateProvider
= static_cast<ChartTypeTabPage
*>(xRet
.get());
102 m_pDialogModel
->setTemplate( m_pTemplateProvider
->getCurrentTemplate());
105 case STATE_SIMPLE_RANGE
:
107 m_aTimerTriggeredControllerLock
.startTimer();
108 xRet
= std::make_unique
<RangeChooserTabPage
>(pPageContainer
, this, *m_pDialogModel
, m_pTemplateProvider
);
111 case STATE_DATA_SERIES
:
113 m_aTimerTriggeredControllerLock
.startTimer();
114 xRet
= std::make_unique
<DataSourceTabPage
>(pPageContainer
, this, *m_pDialogModel
, m_pTemplateProvider
);
119 xRet
= std::make_unique
<TitlesAndObjectsTabPage
>(pPageContainer
, this, m_xChartModel
, m_xComponentContext
);
120 m_aTimerTriggeredControllerLock
.startTimer();
128 xRet
->SetPageTitle(OUString()); //remove title of pages to not get them in the wizard title
133 bool CreationWizard::leaveState( WizardState
/*_nState*/ )
138 vcl::WizardTypes::WizardState
CreationWizard::determineNextState( WizardState nCurrentState
) const
141 return WZS_INVALID_STATE
;
142 if( nCurrentState
== STATE_LAST
)
143 return WZS_INVALID_STATE
;
144 vcl::WizardTypes::WizardState nNextState
= nCurrentState
+ 1;
145 while( !isStateEnabled( nNextState
) && nNextState
<= STATE_LAST
)
147 return (nNextState
==STATE_LAST
+1) ? WZS_INVALID_STATE
: nNextState
;
150 void CreationWizard::enterState(WizardState nState
)
152 m_aTimerTriggeredControllerLock
.startTimer();
153 enableButtons( WizardButtonFlags::PREVIOUS
, nState
> STATE_FIRST
);
154 enableButtons( WizardButtonFlags::NEXT
, nState
< STATE_LAST
);
155 if( isStateEnabled( nState
))
156 vcl::RoadmapWizardMachine::enterState(nState
);
159 void CreationWizard::setInvalidPage(BuilderPage
* pTabPage
)
161 if (pTabPage
== m_pCurTabPage
)
162 m_bCanTravel
= false;
165 void CreationWizard::setValidPage(BuilderPage
* pTabPage
)
167 if (pTabPage
== m_pCurTabPage
)
171 OUString
CreationWizard::getStateDisplayName( WizardState nState
) const
173 const char* pResId
= nullptr;
176 case STATE_CHARTTYPE
:
177 pResId
= STR_PAGE_CHARTTYPE
;
179 case STATE_SIMPLE_RANGE
:
180 pResId
= STR_PAGE_DATA_RANGE
;
182 case STATE_DATA_SERIES
:
183 pResId
= STR_OBJECT_DATASERIES_PLURAL
;
186 pResId
= STR_PAGE_CHART_ELEMENTS
;
193 return SchResId(pResId
);
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */