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