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"
23 #include "Strings.hrc"
24 #include "HelpIds.hrc"
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 "DialogModel.hxx"
33 #define CHART_WIZARD_PAGEWIDTH 250
34 #define CHART_WIZARD_PAGEHEIGHT 170
38 using namespace ::com::sun::star
;
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
50 const sal_Int32 nPageCount
= 4;
53 CreationWizard::CreationWizard( vcl::Window
* pParent
, const uno::Reference
< frame::XModel
>& xChartModel
54 , const uno::Reference
< uno::XComponentContext
>& xContext
55 , sal_Int32 nOnePageOnlyIndex
)
56 : svt::RoadmapWizard( pParent
,
57 (nOnePageOnlyIndex
>= 0 && nOnePageOnlyIndex
< nPageCount
)
58 ? WizardButtonFlags::HELP
| WizardButtonFlags::CANCEL
| WizardButtonFlags::FINISH
59 : WizardButtonFlags::HELP
| WizardButtonFlags::CANCEL
| WizardButtonFlags::PREVIOUS
| WizardButtonFlags::NEXT
| WizardButtonFlags::FINISH
61 , m_xChartModel(xChartModel
,uno::UNO_QUERY
)
64 , m_nOnePageOnlyIndex(nOnePageOnlyIndex
)
65 , m_pTemplateProvider(0)
66 , m_nFirstState(STATE_FIRST
)
67 , m_nLastState(STATE_LAST
)
68 , m_aTimerTriggeredControllerLock( xChartModel
)
69 , m_bCanTravel( true )
71 m_pDialogModel
.reset( new DialogModel( m_xChartModel
, m_xCC
));
72 defaultButton( WizardButtonFlags::FINISH
);
74 if( m_nOnePageOnlyIndex
< 0 || m_nOnePageOnlyIndex
>= nPageCount
)
76 m_nOnePageOnlyIndex
= -1;
77 this->setTitleBase(SCH_RESSTR(STR_DLG_CHART_WIZARD
));
80 this->setTitleBase(OUString());
82 declarePath( PATH_FULL
89 this->SetRoadmapHelpId( HID_SCH_WIZARD_ROADMAP
);
90 this->SetRoadmapInteractive( true );
91 Size
aAdditionalRoadmapSize( LogicToPixel( Size( 85, 0 ), MAP_APPFONT
) );
92 Size
aSize(LogicToPixel(Size(CHART_WIZARD_PAGEWIDTH
, CHART_WIZARD_PAGEHEIGHT
), MAP_APPFONT
));
93 aSize
.Width() += aAdditionalRoadmapSize
.Width();
94 this->SetSizePixel( aSize
);
96 uno::Reference
< chart2::XChartDocument
> xChartDoc( m_xChartModel
, uno::UNO_QUERY
);
97 bool bHasOwnData
= (xChartDoc
.is() && xChartDoc
->hasInternalDataProvider());
101 this->enableState( STATE_SIMPLE_RANGE
, false );
102 this->enableState( STATE_DATA_SERIES
, false );
105 // Call ActivatePage, to create and activate the first page
109 VclPtr
<TabPage
> CreationWizard::createPage(WizardState nState
)
111 VclPtr
<svt::OWizardPage
> pRet
;
112 if(m_nOnePageOnlyIndex
!=-1 && m_nOnePageOnlyIndex
!=nState
)
114 bool bDoLiveUpdate
= m_nOnePageOnlyIndex
== -1;
117 case STATE_CHARTTYPE
:
119 m_aTimerTriggeredControllerLock
.startTimer();
120 VclPtrInstance
<ChartTypeTabPage
> pChartTypeTabPage(this,m_xChartModel
,m_xCC
,bDoLiveUpdate
);
121 pRet
= pChartTypeTabPage
;
122 m_pTemplateProvider
= pChartTypeTabPage
;
124 m_pDialogModel
->setTemplate( m_pTemplateProvider
->getCurrentTemplate());
127 case STATE_SIMPLE_RANGE
:
129 m_aTimerTriggeredControllerLock
.startTimer();
130 pRet
= VclPtr
<RangeChooserTabPage
>::Create(this, *m_pDialogModel
, m_pTemplateProvider
, this);
133 case STATE_DATA_SERIES
:
135 m_aTimerTriggeredControllerLock
.startTimer();
136 pRet
= VclPtr
<DataSourceTabPage
>::Create(this, *m_pDialogModel
, m_pTemplateProvider
, this);
141 pRet
= VclPtr
<TitlesAndObjectsTabPage
>::Create(this,m_xChartModel
,m_xCC
);
142 m_aTimerTriggeredControllerLock
.startTimer();
149 pRet
->SetText(OUString());//remove title of pages to not get them in the wizard title
153 bool CreationWizard::leaveState( WizardState
/*_nState*/ )
158 svt::WizardTypes::WizardState
CreationWizard::determineNextState( WizardState nCurrentState
) const
161 return WZS_INVALID_STATE
;
162 if( nCurrentState
== m_nLastState
)
163 return WZS_INVALID_STATE
;
164 svt::WizardTypes::WizardState nNextState
= nCurrentState
+ 1;
165 while( !isStateEnabled( nNextState
) && nNextState
<= m_nLastState
)
167 return (nNextState
==m_nLastState
+1) ? WZS_INVALID_STATE
: nNextState
;
169 void CreationWizard::enterState(WizardState nState
)
171 m_aTimerTriggeredControllerLock
.startTimer();
172 enableButtons( WizardButtonFlags::PREVIOUS
, bool( nState
> m_nFirstState
) );
173 enableButtons( WizardButtonFlags::NEXT
, bool( nState
< m_nLastState
) );
174 if( isStateEnabled( nState
))
175 svt::RoadmapWizard::enterState(nState
);
178 void CreationWizard::setInvalidPage( TabPage
* /* pTabPage */ )
180 m_bCanTravel
= false;
183 void CreationWizard::setValidPage( TabPage
* /* pTabPage */ )
188 OUString
CreationWizard::getStateDisplayName( WizardState nState
) const
190 sal_uInt16 nResId
= 0;
193 case STATE_CHARTTYPE
:
194 nResId
= STR_PAGE_CHARTTYPE
;
196 case STATE_SIMPLE_RANGE
:
197 nResId
= STR_PAGE_DATA_RANGE
;
199 case STATE_DATA_SERIES
:
200 nResId
= STR_OBJECT_DATASERIES_PLURAL
;
203 nResId
= STR_PAGE_CHART_ELEMENTS
;
208 return SCH_RESSTR(nResId
);
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */