merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / controller / dialogs / dlg_CreationWizard.cxx
blob5b82e57f704444598b1e2bf2cee912367215de0b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "dlg_CreationWizard.hxx"
32 #include "dlg_CreationWizard.hrc"
33 #include "ResId.hxx"
34 #include "macros.hxx"
35 #include "Strings.hrc"
36 #include "HelpIds.hrc"
38 #include "tp_ChartType.hxx"
39 #include "tp_RangeChooser.hxx"
40 #include "tp_Wizard_TitlesAndObjects.hxx"
41 #include "tp_Location.hxx"
43 #include "tp_DataSource.hxx"
44 #include "ChartTypeTemplateProvider.hxx"
45 #include "DialogModel.hxx"
47 //.............................................................................
48 namespace chart
50 //.............................................................................
51 using namespace ::com::sun::star;
53 //#define LOCATION_PAGE 1
55 #define PATH_FULL 1
56 #define STATE_FIRST 0
57 #define STATE_CHARTTYPE STATE_FIRST
58 #define STATE_SIMPLE_RANGE 1
59 #define STATE_DATA_SERIES 2
60 #define STATE_OBJECTS 3
61 #define STATE_LOCATION 4
63 #ifdef LOCATION_PAGE
64 #define STATE_LAST STATE_LOCATION
65 #else
66 #define STATE_LAST STATE_OBJECTS
67 #endif
69 namespace
71 #ifdef LOCATION_PAGE
72 const sal_Int32 nPageCount = 5;
73 #else
74 const sal_Int32 nPageCount = 4;
75 #endif
78 CreationWizard::CreationWizard( Window* pParent, const uno::Reference< frame::XModel >& xChartModel
79 , const uno::Reference< uno::XComponentContext >& xContext
80 , sal_Int32 nOnePageOnlyIndex )
81 : svt::RoadmapWizard( pParent, SchResId(DLG_CHART_WIZARD)
82 , ( nOnePageOnlyIndex >= 0 && nOnePageOnlyIndex < nPageCount )
83 ? WZB_HELP | WZB_CANCEL | WZB_FINISH
84 : WZB_HELP | WZB_CANCEL | WZB_PREVIOUS | WZB_NEXT | WZB_FINISH
86 , m_xChartModel(xChartModel,uno::UNO_QUERY)
87 , m_xCC( xContext )
88 , m_bIsClosable(true)
89 , m_nOnePageOnlyIndex(nOnePageOnlyIndex)
90 , m_pTemplateProvider(0)
91 , m_nFirstState(STATE_FIRST)
92 , m_nLastState(STATE_LAST)
93 , m_aTimerTriggeredControllerLock( xChartModel )
94 , m_bCanTravel( true )
96 m_apDialogModel.reset( new DialogModel( m_xChartModel, m_xCC ));
97 // Do not call FreeResource(), because there are no sub-elements defined in
98 // the dialog resource
99 ShowButtonFixedLine( TRUE );
100 defaultButton( WZB_FINISH );
102 if( m_nOnePageOnlyIndex < 0 || m_nOnePageOnlyIndex >= nPageCount )
104 m_nOnePageOnlyIndex = -1;
105 this->setTitleBase(String(SchResId(STR_DLG_CHART_WIZARD)));
107 else
108 this->setTitleBase(String());
110 declarePath( PATH_FULL
111 , STATE_CHARTTYPE
112 , STATE_SIMPLE_RANGE
113 , STATE_DATA_SERIES
114 , STATE_OBJECTS
115 #ifdef LOCATION_PAGE
116 , STATE_LOCATION
117 #endif
118 , WZS_INVALID_STATE
120 this->SetRoadmapSmartHelpId( SmartId( HID_SCH_WIZARD_ROADMAP ) );
121 this->SetRoadmapInteractive( sal_True );
122 Size aAdditionalRoadmapSize( LogicToPixel( Size( 85, 0 ), MAP_APPFONT ) );
123 Size aSize( this->GetSizePixel() );
124 aSize.Width() += aAdditionalRoadmapSize.Width();
125 this->SetSizePixel( aSize );
127 uno::Reference< chart2::XChartDocument > xChartDoc( m_xChartModel, uno::UNO_QUERY );
128 bool bHasOwnData = (xChartDoc.is() && xChartDoc->hasInternalDataProvider());
130 if( bHasOwnData )
132 this->enableState( STATE_SIMPLE_RANGE, false );
133 this->enableState( STATE_DATA_SERIES, false );
136 // Call ActivatePage, to create and activate the first page
137 ActivatePage();
139 CreationWizard::~CreationWizard()
143 svt::OWizardPage* CreationWizard::createPage(WizardState nState)
145 svt::OWizardPage* pRet = 0;
146 if(m_nOnePageOnlyIndex!=-1 && m_nOnePageOnlyIndex!=nState)
147 return pRet;
148 bool bDoLiveUpdate = m_nOnePageOnlyIndex == -1;
149 switch( nState )
151 case STATE_CHARTTYPE:
153 m_aTimerTriggeredControllerLock.startTimer();
154 ChartTypeTabPage* pChartTypeTabPage = new ChartTypeTabPage(this,m_xChartModel,m_xCC,bDoLiveUpdate);
155 pRet = pChartTypeTabPage;
156 m_pTemplateProvider = pChartTypeTabPage;
157 if( m_pTemplateProvider &&
158 m_apDialogModel.get() )
159 m_apDialogModel->setTemplate( m_pTemplateProvider->getCurrentTemplate());
161 break;
162 case STATE_SIMPLE_RANGE:
164 m_aTimerTriggeredControllerLock.startTimer();
165 pRet = new RangeChooserTabPage(this,*(m_apDialogModel.get()),m_pTemplateProvider,this);
167 break;
168 case STATE_DATA_SERIES:
170 m_aTimerTriggeredControllerLock.startTimer();
171 pRet = new DataSourceTabPage(this,*(m_apDialogModel.get()),m_pTemplateProvider,this);
173 break;
174 case STATE_OBJECTS:
176 pRet = new TitlesAndObjectsTabPage(this,m_xChartModel,m_xCC);
177 m_aTimerTriggeredControllerLock.startTimer();
179 break;
180 #ifdef LOCATION_PAGE
181 case STATE_LOCATION:
183 m_aTimerTriggeredControllerLock.startTimer();
184 pRet = new LocationTabPage(this,m_xChartModel,m_xCC);
186 break;
187 #endif
188 default:
189 break;
191 if(pRet)
192 pRet->SetText(String());//remove title of pages to not get them in the wizard title
193 return pRet;
196 sal_Bool CreationWizard::leaveState( WizardState /*_nState*/ )
198 return m_bCanTravel;
201 svt::WizardTypes::WizardState CreationWizard::determineNextState( WizardState nCurrentState ) const
203 if( !m_bCanTravel )
204 return WZS_INVALID_STATE;
205 if( nCurrentState == m_nLastState )
206 return WZS_INVALID_STATE;
207 svt::WizardTypes::WizardState nNextState = nCurrentState + 1;
208 while( !isStateEnabled( nNextState ) && nNextState <= m_nLastState )
209 ++nNextState;
210 return (nNextState==m_nLastState+1) ? WZS_INVALID_STATE : nNextState;
212 void CreationWizard::enterState(WizardState nState)
214 m_aTimerTriggeredControllerLock.startTimer();
215 enableButtons( WZB_PREVIOUS, bool( nState > m_nFirstState ) );
216 enableButtons( WZB_NEXT, bool( nState < m_nLastState ) );
217 if( isStateEnabled( nState ))
218 svt::RoadmapWizard::enterState(nState);
221 bool CreationWizard::isClosable()
223 //@todo
224 return m_bIsClosable;
227 void CreationWizard::setInvalidPage( TabPage * /* pTabPage */ )
229 m_bCanTravel = false;
232 void CreationWizard::setValidPage( TabPage * /* pTabPage */ )
234 m_bCanTravel = true;
237 String CreationWizard::getStateDisplayName( WizardState nState ) const
239 USHORT nResId = 0;
240 switch( nState )
242 case STATE_CHARTTYPE:
243 nResId = STR_PAGE_CHARTTYPE;
244 break;
245 case STATE_SIMPLE_RANGE:
246 nResId = STR_PAGE_DATA_RANGE;
247 break;
248 case STATE_DATA_SERIES:
249 nResId = STR_OBJECT_DATASERIES_PLURAL;
250 break;
251 case STATE_OBJECTS:
252 nResId = STR_PAGE_CHART_ELEMENTS;
253 break;
254 #ifdef LOCATION_PAGE
255 case STATE_LOCATION:
256 nResId = STR_PAGE_CHART_LOCATION;
257 break;
258 #endif
259 default:
260 break;
262 return String(SchResId(nResId));
265 //.............................................................................
266 } //namespace chart
267 //.............................................................................