Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / chart2 / source / controller / dialogs / dlg_CreationWizard.cxx
blob9967c6123a76ce1c9e94e7178aba97a4f434cf86
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
21 #include <ResId.hxx>
22 #include <strings.hrc>
23 #include <helpids.h>
25 #include "tp_ChartType.hxx"
26 #include "tp_RangeChooser.hxx"
27 #include "tp_Wizard_TitlesAndObjects.hxx"
28 #include "tp_DataSource.hxx"
29 #include "ChartTypeTemplateProvider.hxx"
30 #include "DialogModel.hxx"
32 #define CHART_WIZARD_PAGEWIDTH 250
33 #define CHART_WIZARD_PAGEHEIGHT 170
35 using namespace css;
37 namespace chart
39 #define PATH_FULL 1
40 #define STATE_FIRST 0
41 #define STATE_CHARTTYPE STATE_FIRST
42 #define STATE_SIMPLE_RANGE 1
43 #define STATE_DATA_SERIES 2
44 #define STATE_OBJECTS 3
45 #define STATE_LAST STATE_OBJECTS
47 CreationWizard::CreationWizard(vcl::Window* pParent, const uno::Reference<frame::XModel>& xChartModel,
48 const uno::Reference<uno::XComponentContext>& xContext)
49 : svt::RoadmapWizard(pParent)
50 , m_xChartModel(xChartModel,uno::UNO_QUERY)
51 , m_xComponentContext(xContext)
52 , m_pTemplateProvider(nullptr)
53 , m_nLastState(STATE_LAST)
54 , m_aTimerTriggeredControllerLock(xChartModel)
55 , m_bCanTravel(true)
57 m_pDialogModel.reset(new DialogModel(m_xChartModel, m_xComponentContext));
58 defaultButton(WizardButtonFlags::FINISH);
60 setTitleBase(SchResId(STR_DLG_CHART_WIZARD));
62 WizardPath aPath = {
63 STATE_CHARTTYPE,
64 STATE_SIMPLE_RANGE,
65 STATE_DATA_SERIES,
66 STATE_OBJECTS
69 declarePath(PATH_FULL, aPath);
71 SetRoadmapHelpId(HID_SCH_WIZARD_ROADMAP);
72 SetRoadmapInteractive(true);
74 Size aAdditionalRoadmapSize(LogicToPixel(Size(85, 0), MapMode(MapUnit::MapAppFont)));
75 Size aSize(LogicToPixel(Size(CHART_WIZARD_PAGEWIDTH, CHART_WIZARD_PAGEHEIGHT), MapMode(MapUnit::MapAppFont)));
76 aSize.AdjustWidth(aAdditionalRoadmapSize.Width() );
77 SetSizePixel(aSize);
79 if (!m_pDialogModel->getModel().isDataFromSpreadsheet())
81 enableState(STATE_SIMPLE_RANGE, false);
82 enableState(STATE_DATA_SERIES, false);
85 // Call ActivatePage, to create and activate the first page
86 ActivatePage();
89 CreationWizard::~CreationWizard() = default;
91 VclPtr<TabPage> CreationWizard::createPage(WizardState nState)
93 VclPtr<svt::OWizardPage> pRet;
94 switch( nState )
96 case STATE_CHARTTYPE:
98 m_aTimerTriggeredControllerLock.startTimer();
99 VclPtrInstance<ChartTypeTabPage> pChartTypeTabPage(this,m_xChartModel);
100 pRet = pChartTypeTabPage;
101 m_pTemplateProvider = pChartTypeTabPage;
102 if (m_pDialogModel)
103 m_pDialogModel->setTemplate( m_pTemplateProvider->getCurrentTemplate());
105 break;
106 case STATE_SIMPLE_RANGE:
108 m_aTimerTriggeredControllerLock.startTimer();
109 pRet = VclPtr<RangeChooserTabPage>::Create(this, *m_pDialogModel, m_pTemplateProvider, this);
111 break;
112 case STATE_DATA_SERIES:
114 m_aTimerTriggeredControllerLock.startTimer();
115 pRet = VclPtr<DataSourceTabPage>::Create(this, *m_pDialogModel, m_pTemplateProvider, this);
117 break;
118 case STATE_OBJECTS:
120 pRet = VclPtr<TitlesAndObjectsTabPage>::Create(this,m_xChartModel, m_xComponentContext);
121 m_aTimerTriggeredControllerLock.startTimer();
123 break;
124 default:
125 break;
128 if (pRet)
129 pRet->SetText(OUString()); //remove title of pages to not get them in the wizard title
131 return pRet;
134 bool CreationWizard::leaveState( WizardState /*_nState*/ )
136 return m_bCanTravel;
139 svt::WizardTypes::WizardState CreationWizard::determineNextState( WizardState nCurrentState ) const
141 if( !m_bCanTravel )
142 return WZS_INVALID_STATE;
143 if( nCurrentState == m_nLastState )
144 return WZS_INVALID_STATE;
145 svt::WizardTypes::WizardState nNextState = nCurrentState + 1;
146 while( !isStateEnabled( nNextState ) && nNextState <= m_nLastState )
147 ++nNextState;
148 return (nNextState==m_nLastState+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 < m_nLastState );
155 if( isStateEnabled( nState ))
156 svt::RoadmapWizard::enterState(nState);
159 void CreationWizard::setInvalidPage( TabPage * /* pTabPage */ )
161 m_bCanTravel = false;
164 void CreationWizard::setValidPage( TabPage * /* pTabPage */ )
166 m_bCanTravel = true;
169 OUString CreationWizard::getStateDisplayName( WizardState nState ) const
171 const char* pResId = nullptr;
172 switch( nState )
174 case STATE_CHARTTYPE:
175 pResId = STR_PAGE_CHARTTYPE;
176 break;
177 case STATE_SIMPLE_RANGE:
178 pResId = STR_PAGE_DATA_RANGE;
179 break;
180 case STATE_DATA_SERIES:
181 pResId = STR_OBJECT_DATASERIES_PLURAL;
182 break;
183 case STATE_OBJECTS:
184 pResId = STR_PAGE_CHART_ELEMENTS;
185 break;
186 default:
187 break;
189 if (!pResId)
190 return OUString();
191 return SchResId(pResId);
194 } //namespace chart
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */