1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26
27 #include "dlg_CreationWizard.hxx"
28 #include "dlg_CreationWizard.hrc"
29 #include "ResId.hxx"
30 #include "macros.hxx"
31 #include "Strings.hrc"
32 #include "HelpIds.hrc"
33
34 #include "tp_ChartType.hxx"
35 #include "tp_RangeChooser.hxx"
36 #include "tp_Wizard_TitlesAndObjects.hxx"
37 #include "tp_Location.hxx"
38
39 #include "tp_DataSource.hxx"
40 #include "ChartTypeTemplateProvider.hxx"
41 #include "DialogModel.hxx"
42
43 //.............................................................................
44 namespace chart
45 {
46 //.............................................................................
47 using namespace ::com::sun::star;
48
49 //#define LOCATION_PAGE 1
50
51 #define PATH_FULL 1
52 #define STATE_FIRST 0
53 #define STATE_CHARTTYPE STATE_FIRST
54 #define STATE_SIMPLE_RANGE 1
55 #define STATE_DATA_SERIES 2
56 #define STATE_OBJECTS 3
57 #define STATE_LOCATION 4
58
59 #ifdef LOCATION_PAGE
60 #define STATE_LAST STATE_LOCATION
61 #else
62 #define STATE_LAST STATE_OBJECTS
63 #endif
64
65 namespace
66 {
67 #ifdef LOCATION_PAGE
68 const sal_Int32 nPageCount = 5;
69 #else
70 const sal_Int32 nPageCount = 4;
71 #endif
72 }
73
CreationWizard(Window * pParent,const uno::Reference<frame::XModel> & xChartModel,const uno::Reference<uno::XComponentContext> & xContext,sal_Int32 nOnePageOnlyIndex)74 CreationWizard::CreationWizard( Window* pParent, const uno::Reference< frame::XModel >& xChartModel
75 , const uno::Reference< uno::XComponentContext >& xContext
76 , sal_Int32 nOnePageOnlyIndex )
77 : svt::RoadmapWizard( pParent, SchResId(DLG_CHART_WIZARD)
78 , ( nOnePageOnlyIndex >= 0 && nOnePageOnlyIndex < nPageCount )
79 ? WZB_HELP | WZB_CANCEL | WZB_FINISH
80 : WZB_HELP | WZB_CANCEL | WZB_PREVIOUS | WZB_NEXT | WZB_FINISH
81 )
82 , m_xChartModel(xChartModel,uno::UNO_QUERY)
83 , m_xCC( xContext )
84 , m_bIsClosable(true)
85 , m_nOnePageOnlyIndex(nOnePageOnlyIndex)
86 , m_pTemplateProvider(0)
87 , m_nFirstState(STATE_FIRST)
88 , m_nLastState(STATE_LAST)
89 , m_aTimerTriggeredControllerLock( xChartModel )
90 , m_bCanTravel( true )
91 {
92 m_apDialogModel.reset( new DialogModel( m_xChartModel, m_xCC ));
93 // Do not call FreeResource(), because there are no sub-elements defined in
94 // the dialog resource
95 ShowButtonFixedLine( sal_True );
96 defaultButton( WZB_FINISH );
97
98 if( m_nOnePageOnlyIndex < 0 || m_nOnePageOnlyIndex >= nPageCount )
99 {
100 m_nOnePageOnlyIndex = -1;
101 this->setTitleBase(String(SchResId(STR_DLG_CHART_WIZARD)));
102 }
103 else
104 this->setTitleBase(String());
105
106 declarePath( PATH_FULL
107 , STATE_CHARTTYPE
108 , STATE_SIMPLE_RANGE
109 , STATE_DATA_SERIES
110 , STATE_OBJECTS
111 #ifdef LOCATION_PAGE
112 , STATE_LOCATION
113 #endif
114 , WZS_INVALID_STATE
115 );
116 this->SetRoadmapHelpId( HID_SCH_WIZARD_ROADMAP );
117 this->SetRoadmapInteractive( sal_True );
118 Size aAdditionalRoadmapSize( LogicToPixel( Size( 85, 0 ), MAP_APPFONT ) );
119 Size aSize( this->GetSizePixel() );
120 aSize.Width() += aAdditionalRoadmapSize.Width();
121 this->SetSizePixel( aSize );
122
123 uno::Reference< chart2::XChartDocument > xChartDoc( m_xChartModel, uno::UNO_QUERY );
124 bool bHasOwnData = (xChartDoc.is() && xChartDoc->hasInternalDataProvider());
125
126 if( bHasOwnData )
127 {
128 this->enableState( STATE_SIMPLE_RANGE, false );
129 this->enableState( STATE_DATA_SERIES, false );
130 }
131
132 // Call ActivatePage, to create and activate the first page
133 ActivatePage();
134 }
~CreationWizard()135 CreationWizard::~CreationWizard()
136 {
137 }
138
createPage(WizardState nState)139 svt::OWizardPage* CreationWizard::createPage(WizardState nState)
140 {
141 svt::OWizardPage* pRet = 0;
142 if(m_nOnePageOnlyIndex!=-1 && m_nOnePageOnlyIndex!=nState)
143 return pRet;
144 bool bDoLiveUpdate = m_nOnePageOnlyIndex == -1;
145 switch( nState )
146 {
147 case STATE_CHARTTYPE:
148 {
149 m_aTimerTriggeredControllerLock.startTimer();
150 ChartTypeTabPage* pChartTypeTabPage = new ChartTypeTabPage(this,m_xChartModel,m_xCC,bDoLiveUpdate);
151 pRet = pChartTypeTabPage;
152 m_pTemplateProvider = pChartTypeTabPage;
153 if( m_pTemplateProvider &&
154 m_apDialogModel.get() )
155 m_apDialogModel->setTemplate( m_pTemplateProvider->getCurrentTemplate());
156 }
157 break;
158 case STATE_SIMPLE_RANGE:
159 {
160 m_aTimerTriggeredControllerLock.startTimer();
161 pRet = new RangeChooserTabPage(this,*(m_apDialogModel.get()),m_pTemplateProvider,this);
162 }
163 break;
164 case STATE_DATA_SERIES:
165 {
166 m_aTimerTriggeredControllerLock.startTimer();
167 pRet = new DataSourceTabPage(this,*(m_apDialogModel.get()),m_pTemplateProvider,this);
168 }
169 break;
170 case STATE_OBJECTS:
171 {
172 pRet = new TitlesAndObjectsTabPage(this,m_xChartModel,m_xCC);
173 m_aTimerTriggeredControllerLock.startTimer();
174 }
175 break;
176 #ifdef LOCATION_PAGE
177 case STATE_LOCATION:
178 {
179 m_aTimerTriggeredControllerLock.startTimer();
180 pRet = new LocationTabPage(this,m_xChartModel,m_xCC);
181 }
182 break;
183 #endif
184 default:
185 break;
186 }
187 if(pRet)
188 pRet->SetText(String());//remove title of pages to not get them in the wizard title
189 return pRet;
190 }
191
leaveState(WizardState)192 sal_Bool CreationWizard::leaveState( WizardState /*_nState*/ )
193 {
194 return m_bCanTravel;
195 }
196
determineNextState(WizardState nCurrentState) const197 svt::WizardTypes::WizardState CreationWizard::determineNextState( WizardState nCurrentState ) const
198 {
199 if( !m_bCanTravel )
200 return WZS_INVALID_STATE;
201 if( nCurrentState == m_nLastState )
202 return WZS_INVALID_STATE;
203 svt::WizardTypes::WizardState nNextState = nCurrentState + 1;
204 while( !isStateEnabled( nNextState ) && nNextState <= m_nLastState )
205 ++nNextState;
206 return (nNextState==m_nLastState+1) ? WZS_INVALID_STATE : nNextState;
207 }
enterState(WizardState nState)208 void CreationWizard::enterState(WizardState nState)
209 {
210 m_aTimerTriggeredControllerLock.startTimer();
211 enableButtons( WZB_PREVIOUS, bool( nState > m_nFirstState ) );
212 enableButtons( WZB_NEXT, bool( nState < m_nLastState ) );
213 if( isStateEnabled( nState ))
214 svt::RoadmapWizard::enterState(nState);
215 }
216
isClosable()217 bool CreationWizard::isClosable()
218 {
219 //@todo
220 return m_bIsClosable;
221 }
222
setInvalidPage(TabPage *)223 void CreationWizard::setInvalidPage( TabPage * /* pTabPage */ )
224 {
225 m_bCanTravel = false;
226 }
227
setValidPage(TabPage *)228 void CreationWizard::setValidPage( TabPage * /* pTabPage */ )
229 {
230 m_bCanTravel = true;
231 }
232
getStateDisplayName(WizardState nState) const233 String CreationWizard::getStateDisplayName( WizardState nState ) const
234 {
235 sal_uInt16 nResId = 0;
236 switch( nState )
237 {
238 case STATE_CHARTTYPE:
239 nResId = STR_PAGE_CHARTTYPE;
240 break;
241 case STATE_SIMPLE_RANGE:
242 nResId = STR_PAGE_DATA_RANGE;
243 break;
244 case STATE_DATA_SERIES:
245 nResId = STR_OBJECT_DATASERIES_PLURAL;
246 break;
247 case STATE_OBJECTS:
248 nResId = STR_PAGE_CHART_ELEMENTS;
249 break;
250 #ifdef LOCATION_PAGE
251 case STATE_LOCATION:
252 nResId = STR_PAGE_CHART_LOCATION;
253 break;
254 #endif
255 default:
256 break;
257 }
258 return String(SchResId(nResId));
259 }
260
261 //.............................................................................
262 } //namespace chart
263 //.............................................................................
264