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