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