1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 
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"
37 
38 #include "tp_ChartType.hxx"
39 #include "tp_RangeChooser.hxx"
40 #include "tp_Wizard_TitlesAndObjects.hxx"
41 #include "tp_Location.hxx"
42 
43 #include "tp_DataSource.hxx"
44 #include "ChartTypeTemplateProvider.hxx"
45 #include "DialogModel.hxx"
46 
47 //.............................................................................
48 namespace chart
49 {
50 //.............................................................................
51 using namespace ::com::sun::star;
52 
53 //#define LOCATION_PAGE 1
54 
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
62 
63 #ifdef LOCATION_PAGE
64 #define STATE_LAST         STATE_LOCATION
65 #else
66 #define STATE_LAST         STATE_OBJECTS
67 #endif
68 
69 namespace
70 {
71 #ifdef LOCATION_PAGE
72     const sal_Int32 nPageCount = 5;
73 #else
74     const sal_Int32 nPageCount = 4;
75 #endif
76 }
77 
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
85                   )
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 )
95 {
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( sal_True );
100     defaultButton( WZB_FINISH );
101 
102     if( m_nOnePageOnlyIndex < 0 || m_nOnePageOnlyIndex >= nPageCount )
103     {
104         m_nOnePageOnlyIndex = -1;
105         this->setTitleBase(String(SchResId(STR_DLG_CHART_WIZARD)));
106     }
107     else
108         this->setTitleBase(String());
109 
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
119     );
120     this->SetRoadmapHelpId( 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 );
126 
127     uno::Reference< chart2::XChartDocument > xChartDoc( m_xChartModel, uno::UNO_QUERY );
128     bool bHasOwnData = (xChartDoc.is() && xChartDoc->hasInternalDataProvider());
129 
130     if( bHasOwnData )
131     {
132         this->enableState( STATE_SIMPLE_RANGE, false );
133         this->enableState( STATE_DATA_SERIES, false );
134     }
135 
136     // Call ActivatePage, to create and activate the first page
137     ActivatePage();
138 }
139 CreationWizard::~CreationWizard()
140 {
141 }
142 
143 svt::OWizardPage* CreationWizard::createPage(WizardState nState)
144 {
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 )
150     {
151     case STATE_CHARTTYPE:
152         {
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());
160         }
161         break;
162     case STATE_SIMPLE_RANGE:
163         {
164         m_aTimerTriggeredControllerLock.startTimer();
165         pRet = new RangeChooserTabPage(this,*(m_apDialogModel.get()),m_pTemplateProvider,this);
166         }
167         break;
168     case STATE_DATA_SERIES:
169         {
170         m_aTimerTriggeredControllerLock.startTimer();
171         pRet = new DataSourceTabPage(this,*(m_apDialogModel.get()),m_pTemplateProvider,this);
172         }
173         break;
174     case STATE_OBJECTS:
175         {
176         pRet  = new TitlesAndObjectsTabPage(this,m_xChartModel,m_xCC);
177         m_aTimerTriggeredControllerLock.startTimer();
178         }
179         break;
180 #ifdef LOCATION_PAGE
181     case STATE_LOCATION:
182         {
183         m_aTimerTriggeredControllerLock.startTimer();
184         pRet  = new LocationTabPage(this,m_xChartModel,m_xCC);
185         }
186         break;
187 #endif
188     default:
189         break;
190     }
191     if(pRet)
192         pRet->SetText(String());//remove title of pages to not get them in the wizard title
193     return pRet;
194 }
195 
196 sal_Bool CreationWizard::leaveState( WizardState /*_nState*/ )
197 {
198     return m_bCanTravel;
199 }
200 
201 svt::WizardTypes::WizardState CreationWizard::determineNextState( WizardState nCurrentState ) const
202 {
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;
211 }
212 void CreationWizard::enterState(WizardState nState)
213 {
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);
219 }
220 
221 bool CreationWizard::isClosable()
222 {
223     //@todo
224 	return m_bIsClosable;
225 }
226 
227 void CreationWizard::setInvalidPage( TabPage * /* pTabPage */ )
228 {
229     m_bCanTravel = false;
230 }
231 
232 void CreationWizard::setValidPage( TabPage * /* pTabPage */ )
233 {
234     m_bCanTravel = true;
235 }
236 
237 String CreationWizard::getStateDisplayName( WizardState nState ) const
238 {
239     sal_uInt16 nResId = 0;
240     switch( nState )
241     {
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;
261     }
262     return String(SchResId(nResId));
263 }
264 
265 //.............................................................................
266 } //namespace chart
267 //.............................................................................
268