Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <svtools/wizardmachine.hxx>
21 : #include <svtools/helpid.hrc>
22 : #include <tools/debug.hxx>
23 : #include <tools/diagnose_ex.h>
24 : #include <vcl/msgbox.hxx>
25 : #include <svtools/svtresid.hxx>
26 : #include <svtools/svtools.hrc>
27 :
28 :
29 : namespace svt
30 : {
31 :
32 :
33 :
34 : //= WizardPageImplData
35 :
36 : struct WizardPageImplData
37 : {
38 0 : WizardPageImplData()
39 : {
40 0 : }
41 : };
42 :
43 0 : OWizardPage::OWizardPage(vcl::Window *pParent, const OString& rID,
44 : const OUString& rUIXMLDescription)
45 : : TabPage(pParent, rID, rUIXMLDescription)
46 0 : , m_pImpl(new WizardPageImplData)
47 : {
48 0 : }
49 :
50 0 : OWizardPage::~OWizardPage()
51 : {
52 0 : delete m_pImpl;
53 0 : }
54 :
55 0 : void OWizardPage::initializePage()
56 : {
57 0 : }
58 :
59 0 : void OWizardPage::ActivatePage()
60 : {
61 0 : TabPage::ActivatePage();
62 0 : updateDialogTravelUI();
63 0 : }
64 :
65 0 : void OWizardPage::updateDialogTravelUI()
66 : {
67 0 : OWizardMachine* pWizardMachine = dynamic_cast< OWizardMachine* >( GetParent() );
68 0 : if ( pWizardMachine )
69 0 : pWizardMachine->updateTravelUI();
70 0 : }
71 :
72 0 : bool OWizardPage::canAdvance() const
73 : {
74 0 : return true;
75 : }
76 :
77 0 : bool OWizardPage::commitPage( WizardTypes::CommitPageReason )
78 : {
79 0 : return true;
80 : }
81 :
82 0 : struct WizardMachineImplData : public WizardTypes
83 : {
84 : OUString sTitleBase; // the base for the title
85 : ::std::stack< WizardState > aStateHistory; // the history of all states (used for implementing "Back")
86 :
87 : WizardState nFirstUnknownPage;
88 : // the WizardDialog does not allow non-linear transitions (e.g. it's
89 : // not possible to add pages in a non-linear order), so we need some own maintainance data
90 :
91 : bool m_bAutoNextButtonState;
92 :
93 : bool m_bTravelingSuspended;
94 :
95 0 : WizardMachineImplData()
96 : :nFirstUnknownPage( 0 )
97 : ,m_bAutoNextButtonState( false )
98 0 : ,m_bTravelingSuspended( false )
99 : {
100 0 : }
101 : };
102 :
103 0 : OWizardMachine::OWizardMachine(vcl::Window* _pParent, const WinBits i_nStyle, sal_uInt32 _nButtonFlags )
104 : :WizardDialog( _pParent, i_nStyle )
105 : ,m_pFinish(NULL)
106 : ,m_pCancel(NULL)
107 : ,m_pNextPage(NULL)
108 : ,m_pPrevPage(NULL)
109 : ,m_pHelp(NULL)
110 0 : ,m_pImpl( new WizardMachineImplData )
111 : {
112 0 : implConstruct( _nButtonFlags );
113 0 : }
114 :
115 0 : OWizardMachine::OWizardMachine(vcl::Window* _pParent, sal_uInt32 _nButtonFlags )
116 : :WizardDialog( _pParent, "WizardDialog", "svt/ui/wizarddialog.ui" )
117 : ,m_pFinish(NULL)
118 : ,m_pCancel(NULL)
119 : ,m_pNextPage(NULL)
120 : ,m_pPrevPage(NULL)
121 : ,m_pHelp(NULL)
122 0 : ,m_pImpl( new WizardMachineImplData )
123 : {
124 0 : implConstruct( _nButtonFlags );
125 0 : }
126 :
127 :
128 0 : void OWizardMachine::implConstruct( const sal_uInt32 _nButtonFlags )
129 : {
130 0 : m_pImpl->sTitleBase = GetText();
131 :
132 : // create the buttons according to the wizard button flags
133 : // the help button
134 0 : if (_nButtonFlags & WZB_HELP)
135 : {
136 0 : m_pHelp= new HelpButton(this, WB_TABSTOP);
137 0 : m_pHelp->SetSizePixel( LogicToPixel( Size( 50, 14 ), MAP_APPFONT ) );
138 0 : m_pHelp->Show();
139 0 : AddButton( m_pHelp, WIZARDDIALOG_BUTTON_STDOFFSET_X);
140 : }
141 :
142 : // the previous button
143 0 : if (_nButtonFlags & WZB_PREVIOUS)
144 : {
145 0 : m_pPrevPage = new PushButton(this, WB_TABSTOP);
146 0 : m_pPrevPage->SetHelpId( HID_WIZARD_PREVIOUS );
147 0 : m_pPrevPage->SetSizePixel( LogicToPixel( Size( 50, 14 ), MAP_APPFONT ) );
148 0 : m_pPrevPage->SetText(SVT_RESSTR(STR_WIZDLG_PREVIOUS));
149 0 : m_pPrevPage->Show();
150 :
151 0 : if (_nButtonFlags & WZB_NEXT)
152 0 : AddButton( m_pPrevPage, ( WIZARDDIALOG_BUTTON_SMALLSTDOFFSET_X) ); // half x-offset to the next button
153 : else
154 0 : AddButton( m_pPrevPage, WIZARDDIALOG_BUTTON_STDOFFSET_X );
155 0 : SetPrevButton( m_pPrevPage );
156 0 : m_pPrevPage->SetClickHdl( LINK( this, OWizardMachine, OnPrevPage ) );
157 : }
158 :
159 : // the next button
160 0 : if (_nButtonFlags & WZB_NEXT)
161 : {
162 0 : m_pNextPage = new PushButton(this, WB_TABSTOP);
163 0 : m_pNextPage->SetHelpId( HID_WIZARD_NEXT );
164 0 : m_pNextPage->SetSizePixel( LogicToPixel( Size( 50, 14 ), MAP_APPFONT ) );
165 0 : m_pNextPage->SetText(OUString(SVT_RESSTR(STR_WIZDLG_NEXT)));
166 0 : m_pNextPage->Show();
167 :
168 0 : AddButton( m_pNextPage, WIZARDDIALOG_BUTTON_STDOFFSET_X );
169 0 : SetNextButton( m_pNextPage );
170 0 : m_pNextPage->SetClickHdl( LINK( this, OWizardMachine, OnNextPage ) );
171 : }
172 :
173 : // the finish button
174 0 : if (_nButtonFlags & WZB_FINISH)
175 : {
176 0 : m_pFinish = new OKButton(this, WB_TABSTOP);
177 0 : m_pFinish->SetSizePixel( LogicToPixel( Size( 50, 14 ), MAP_APPFONT ) );
178 0 : m_pFinish->SetText(SVT_RESSTR(STR_WIZDLG_FINISH));
179 0 : m_pFinish->Show();
180 :
181 0 : AddButton( m_pFinish, WIZARDDIALOG_BUTTON_STDOFFSET_X );
182 0 : m_pFinish->SetClickHdl( LINK( this, OWizardMachine, OnFinish ) );
183 : }
184 :
185 : // the cancel button
186 0 : if (_nButtonFlags & WZB_CANCEL)
187 : {
188 0 : m_pCancel = new CancelButton(this, WB_TABSTOP);
189 0 : m_pCancel->SetSizePixel( LogicToPixel( Size( 50, 14 ), MAP_APPFONT ) );
190 0 : m_pCancel->Show();
191 :
192 0 : AddButton( m_pCancel, WIZARDDIALOG_BUTTON_STDOFFSET_X );
193 : }
194 0 : }
195 :
196 :
197 0 : OWizardMachine::~OWizardMachine()
198 : {
199 0 : delete m_pFinish;
200 0 : delete m_pCancel;
201 0 : delete m_pNextPage;
202 0 : delete m_pPrevPage;
203 0 : delete m_pHelp;
204 :
205 0 : for (WizardState i=0; i<m_pImpl->nFirstUnknownPage; ++i)
206 0 : delete GetPage(i);
207 :
208 0 : delete m_pImpl;
209 0 : }
210 :
211 :
212 0 : void OWizardMachine::implUpdateTitle()
213 : {
214 0 : OUString sCompleteTitle(m_pImpl->sTitleBase);
215 :
216 : // append the page title
217 0 : TabPage* pCurrentPage = GetPage(getCurrentState());
218 0 : if ( pCurrentPage && !pCurrentPage->GetText().isEmpty() )
219 : {
220 0 : sCompleteTitle += (" - " + pCurrentPage->GetText());
221 : }
222 :
223 0 : SetText(sCompleteTitle);
224 0 : }
225 :
226 :
227 0 : void OWizardMachine::setTitleBase(const OUString& _rTitleBase)
228 : {
229 0 : m_pImpl->sTitleBase = _rTitleBase;
230 0 : implUpdateTitle();
231 0 : }
232 :
233 :
234 0 : TabPage* OWizardMachine::GetOrCreatePage( const WizardState i_nState )
235 : {
236 0 : if ( NULL == GetPage( i_nState ) )
237 : {
238 0 : TabPage* pNewPage = createPage( i_nState );
239 : DBG_ASSERT( pNewPage, "OWizardMachine::GetOrCreatePage: invalid new page (NULL)!" );
240 :
241 : // fill up the page sequence of our base class (with dummies)
242 0 : while ( m_pImpl->nFirstUnknownPage < i_nState )
243 : {
244 0 : AddPage( NULL );
245 0 : ++m_pImpl->nFirstUnknownPage;
246 : }
247 :
248 0 : if ( m_pImpl->nFirstUnknownPage == i_nState )
249 : {
250 : // encountered this page number the first time
251 0 : AddPage( pNewPage );
252 0 : ++m_pImpl->nFirstUnknownPage;
253 : }
254 : else
255 : // already had this page - just change it
256 0 : SetPage( i_nState, pNewPage );
257 : }
258 0 : return GetPage( i_nState );
259 : }
260 :
261 :
262 0 : void OWizardMachine::ActivatePage()
263 : {
264 0 : WizardDialog::ActivatePage();
265 :
266 0 : WizardState nCurrentLevel = GetCurLevel();
267 0 : GetOrCreatePage( nCurrentLevel );
268 :
269 0 : enterState( nCurrentLevel );
270 0 : }
271 :
272 :
273 0 : long OWizardMachine::DeactivatePage()
274 : {
275 0 : WizardState nCurrentState = getCurrentState();
276 0 : if (!leaveState(nCurrentState) || !WizardDialog::DeactivatePage())
277 0 : return sal_False;
278 0 : return sal_True;
279 : }
280 :
281 :
282 0 : void OWizardMachine::defaultButton(sal_uInt32 _nWizardButtonFlags)
283 : {
284 : // the new default button
285 0 : PushButton* pNewDefButton = NULL;
286 0 : if (m_pFinish && (_nWizardButtonFlags & WZB_FINISH))
287 0 : pNewDefButton = m_pFinish;
288 0 : if (m_pNextPage && (_nWizardButtonFlags & WZB_NEXT))
289 0 : pNewDefButton = m_pNextPage;
290 0 : if (m_pPrevPage && (_nWizardButtonFlags & WZB_PREVIOUS))
291 0 : pNewDefButton = m_pPrevPage;
292 0 : if (m_pHelp && (_nWizardButtonFlags & WZB_HELP))
293 0 : pNewDefButton = m_pHelp;
294 0 : if (m_pCancel && (_nWizardButtonFlags & WZB_CANCEL))
295 0 : pNewDefButton = m_pCancel;
296 :
297 0 : if ( pNewDefButton )
298 0 : defaultButton( pNewDefButton );
299 : else
300 0 : implResetDefault( this );
301 0 : }
302 :
303 :
304 0 : void OWizardMachine::implResetDefault(vcl::Window* _pWindow)
305 : {
306 0 : vcl::Window* pChildLoop = _pWindow->GetWindow(WINDOW_FIRSTCHILD);
307 0 : while (pChildLoop)
308 : {
309 : // does the window participate in the tabbing order?
310 0 : if (pChildLoop->GetStyle() & WB_DIALOGCONTROL)
311 0 : implResetDefault(pChildLoop);
312 :
313 : // is it a button?
314 0 : WindowType eType = pChildLoop->GetType();
315 0 : if ( (WINDOW_BUTTON == eType)
316 0 : || (WINDOW_PUSHBUTTON == eType)
317 0 : || (WINDOW_OKBUTTON == eType)
318 0 : || (WINDOW_CANCELBUTTON == eType)
319 0 : || (WINDOW_HELPBUTTON == eType)
320 0 : || (WINDOW_IMAGEBUTTON == eType)
321 0 : || (WINDOW_MENUBUTTON == eType)
322 0 : || (WINDOW_MOREBUTTON == eType)
323 : )
324 : {
325 0 : pChildLoop->SetStyle(pChildLoop->GetStyle() & ~WB_DEFBUTTON);
326 : }
327 :
328 : // the next one ...
329 0 : pChildLoop = pChildLoop->GetWindow(WINDOW_NEXT);
330 : }
331 0 : }
332 :
333 :
334 0 : void OWizardMachine::defaultButton(PushButton* _pNewDefButton)
335 : {
336 : // loop through all (direct and indirect) descendants which participate in our tabbing order, and
337 : // reset the WB_DEFBUTTON for every window which is a button
338 0 : implResetDefault(this);
339 :
340 : // set it's new style
341 0 : if (_pNewDefButton)
342 0 : _pNewDefButton->SetStyle(_pNewDefButton->GetStyle() | WB_DEFBUTTON);
343 0 : }
344 :
345 :
346 0 : void OWizardMachine::enableButtons(sal_uInt32 _nWizardButtonFlags, bool _bEnable)
347 : {
348 0 : if (m_pFinish && (_nWizardButtonFlags & WZB_FINISH))
349 0 : m_pFinish->Enable(_bEnable);
350 0 : if (m_pNextPage && (_nWizardButtonFlags & WZB_NEXT))
351 0 : m_pNextPage->Enable(_bEnable);
352 0 : if (m_pPrevPage && (_nWizardButtonFlags & WZB_PREVIOUS))
353 0 : m_pPrevPage->Enable(_bEnable);
354 0 : if (m_pHelp && (_nWizardButtonFlags & WZB_HELP))
355 0 : m_pHelp->Enable(_bEnable);
356 0 : if (m_pCancel && (_nWizardButtonFlags & WZB_CANCEL))
357 0 : m_pCancel->Enable(_bEnable);
358 0 : }
359 :
360 :
361 0 : void OWizardMachine::enterState(WizardState _nState)
362 : {
363 : // tell the page
364 0 : IWizardPageController* pController = getPageController( GetPage( _nState ) );
365 : OSL_ENSURE( pController, "OWizardMachine::enterState: no controller for the given page!" );
366 0 : if ( pController )
367 0 : pController->initializePage();
368 :
369 0 : if ( isAutomaticNextButtonStateEnabled() )
370 0 : enableButtons( WZB_NEXT, canAdvance() );
371 :
372 0 : enableButtons( WZB_PREVIOUS, !m_pImpl->aStateHistory.empty() );
373 :
374 : // set the new title - it depends on the current page (i.e. state)
375 0 : implUpdateTitle();
376 0 : }
377 :
378 :
379 0 : bool OWizardMachine::leaveState(WizardState)
380 : {
381 : // no need to ask the page here.
382 : // If we reach this point, we already gave the current page the chance to commit it's data,
383 : // and it was allowed to commit it's data
384 :
385 0 : return true;
386 : }
387 :
388 :
389 0 : bool OWizardMachine::onFinish()
390 : {
391 0 : return Finish( RET_OK );
392 : }
393 :
394 :
395 0 : IMPL_LINK_NOARG(OWizardMachine, OnFinish)
396 : {
397 0 : if ( isTravelingSuspended() )
398 0 : return 0;
399 0 : WizardTravelSuspension aTravelGuard( *this );
400 0 : if ( !prepareLeaveCurrentState( eFinish ) )
401 : {
402 0 : return 0L;
403 : }
404 0 : return onFinish() ? 1L : 0L;
405 : }
406 :
407 :
408 0 : OWizardMachine::WizardState OWizardMachine::determineNextState( WizardState _nCurrentState ) const
409 : {
410 0 : return _nCurrentState + 1;
411 : }
412 :
413 :
414 0 : bool OWizardMachine::prepareLeaveCurrentState( CommitPageReason _eReason )
415 : {
416 0 : IWizardPageController* pController = getPageController( GetPage( getCurrentState() ) );
417 0 : ENSURE_OR_RETURN( pController != NULL, "OWizardMachine::prepareLeaveCurrentState: no controller for the current page!", true );
418 0 : return pController->commitPage( _eReason );
419 : }
420 :
421 :
422 0 : bool OWizardMachine::skipBackwardUntil( WizardState _nTargetState )
423 : {
424 : // allowed to leave the current page?
425 0 : if ( !prepareLeaveCurrentState( eTravelBackward ) )
426 0 : return false;
427 :
428 : // don't travel directly on m_pImpl->aStateHistory, in case something goes wrong
429 0 : ::std::stack< WizardState > aTravelVirtually = m_pImpl->aStateHistory;
430 0 : ::std::stack< WizardState > aOldStateHistory = m_pImpl->aStateHistory;
431 :
432 0 : WizardState nCurrentRollbackState = getCurrentState();
433 0 : while ( nCurrentRollbackState != _nTargetState )
434 : {
435 : DBG_ASSERT( !aTravelVirtually.empty(), "OWizardMachine::skipBackwardUntil: this target state does not exist in the history!" );
436 0 : nCurrentRollbackState = aTravelVirtually.top();
437 0 : aTravelVirtually.pop();
438 : }
439 0 : m_pImpl->aStateHistory = aTravelVirtually;
440 0 : if ( !ShowPage( _nTargetState ) )
441 : {
442 0 : m_pImpl->aStateHistory = aOldStateHistory;
443 0 : return false;
444 : }
445 0 : return true;
446 : }
447 :
448 :
449 0 : bool OWizardMachine::skipUntil( WizardState _nTargetState )
450 : {
451 0 : WizardState nCurrentState = getCurrentState();
452 :
453 : // allowed to leave the current page?
454 0 : if ( !prepareLeaveCurrentState( nCurrentState < _nTargetState ? eTravelForward : eTravelBackward ) )
455 0 : return false;
456 :
457 : // don't travel directly on m_pImpl->aStateHistory, in case something goes wrong
458 0 : ::std::stack< WizardState > aTravelVirtually = m_pImpl->aStateHistory;
459 0 : ::std::stack< WizardState > aOldStateHistory = m_pImpl->aStateHistory;
460 0 : while ( nCurrentState != _nTargetState )
461 : {
462 0 : WizardState nNextState = determineNextState( nCurrentState );
463 0 : if ( WZS_INVALID_STATE == nNextState )
464 : {
465 : OSL_FAIL( "OWizardMachine::skipUntil: the given target state does not exist!" );
466 0 : return false;
467 : }
468 :
469 : // remember the skipped state in the history
470 0 : aTravelVirtually.push( nCurrentState );
471 :
472 : // get the next state
473 0 : nCurrentState = nNextState;
474 : }
475 0 : m_pImpl->aStateHistory = aTravelVirtually;
476 : // show the target page
477 0 : if ( !ShowPage( nCurrentState ) )
478 : {
479 : // argh! prepareLeaveCurrentPage succeeded, determineNextState succeeded,
480 : // but ShowPage doesn't? Somebody behaves very strange here ....
481 : OSL_FAIL( "OWizardMachine::skipUntil: very unpolite ...." );
482 0 : m_pImpl->aStateHistory = aOldStateHistory;
483 0 : return false;
484 : }
485 0 : return true;
486 : }
487 :
488 :
489 0 : bool OWizardMachine::skip(sal_Int32 _nSteps)
490 : {
491 : DBG_ASSERT(_nSteps > 0, "OWizardMachine::skip: invalid number of steps!");
492 : // allowed to leave the current page?
493 0 : if ( !prepareLeaveCurrentState( eTravelForward ) )
494 0 : return false;
495 :
496 0 : WizardState nCurrentState = getCurrentState();
497 0 : WizardState nNextState = determineNextState(nCurrentState);
498 : // loop _nSteps steps
499 0 : while (_nSteps-- > 0)
500 : {
501 0 : if (WZS_INVALID_STATE == nNextState)
502 0 : return false;
503 :
504 : // remember the skipped state in the history
505 0 : m_pImpl->aStateHistory.push(nCurrentState);
506 :
507 : // get the next state
508 0 : nCurrentState = nNextState;
509 0 : nNextState = determineNextState(nCurrentState);
510 : }
511 :
512 : // show the (n+1)th page
513 0 : if (!ShowPage(nCurrentState))
514 : {
515 : // TODO: this leaves us in a state where we have no current page and an inconsistent state history.
516 : // Perhaps we should rollback the skipping here ....
517 : OSL_FAIL("OWizardMachine::skip: very unpolite ....");
518 : // if somebody does a skip and then does not allow to leave ...
519 : // (can't be a commit error, as we've already committed the current page. So if ShowPage fails here,
520 : // somebody behaves really strange ...)
521 0 : return false;
522 : }
523 :
524 : // all fine
525 0 : return true;
526 : }
527 :
528 :
529 0 : bool OWizardMachine::travelNext()
530 : {
531 : // allowed to leave the current page?
532 0 : if ( !prepareLeaveCurrentState( eTravelForward ) )
533 0 : return false;
534 :
535 : // determine the next state to travel to
536 0 : WizardState nCurrentState = getCurrentState();
537 0 : WizardState nNextState = determineNextState(nCurrentState);
538 0 : if (WZS_INVALID_STATE == nNextState)
539 0 : return false;
540 :
541 : // the state history is used by the enterState method
542 : // all fine
543 0 : m_pImpl->aStateHistory.push(nCurrentState);
544 0 : if (!ShowPage(nNextState))
545 : {
546 0 : m_pImpl->aStateHistory.pop();
547 0 : return false;
548 : }
549 :
550 0 : return true;
551 : }
552 :
553 :
554 0 : bool OWizardMachine::travelPrevious()
555 : {
556 : DBG_ASSERT(m_pImpl->aStateHistory.size() > 0, "OWizardMachine::travelPrevious: have no previous page!");
557 :
558 : // allowed to leave the current page?
559 0 : if ( !prepareLeaveCurrentState( eTravelBackward ) )
560 0 : return false;
561 :
562 : // the next state to switch to
563 0 : WizardState nPreviousState = m_pImpl->aStateHistory.top();
564 :
565 : // the state history is used by the enterState method
566 0 : m_pImpl->aStateHistory.pop();
567 : // show this page
568 0 : if (!ShowPage(nPreviousState))
569 : {
570 0 : m_pImpl->aStateHistory.push(nPreviousState);
571 0 : return false;
572 : }
573 :
574 : // all fine
575 0 : return true;
576 : }
577 :
578 :
579 0 : void OWizardMachine::removePageFromHistory( WizardState nToRemove )
580 : {
581 :
582 0 : ::std::stack< WizardState > aTemp;
583 0 : while(!m_pImpl->aStateHistory.empty())
584 : {
585 0 : WizardState nPreviousState = m_pImpl->aStateHistory.top();
586 0 : m_pImpl->aStateHistory.pop();
587 0 : if(nPreviousState != nToRemove)
588 0 : aTemp.push( nPreviousState );
589 : else
590 0 : break;
591 : }
592 0 : while(!aTemp.empty())
593 : {
594 0 : m_pImpl->aStateHistory.push( aTemp.top() );
595 0 : aTemp.pop();
596 0 : }
597 0 : }
598 :
599 :
600 0 : void OWizardMachine::enableAutomaticNextButtonState( bool _bEnable )
601 : {
602 0 : m_pImpl->m_bAutoNextButtonState = _bEnable;
603 0 : }
604 :
605 :
606 0 : bool OWizardMachine::isAutomaticNextButtonStateEnabled() const
607 : {
608 0 : return m_pImpl->m_bAutoNextButtonState;
609 : }
610 :
611 :
612 0 : IMPL_LINK_NOARG(OWizardMachine, OnPrevPage)
613 : {
614 0 : if ( isTravelingSuspended() )
615 0 : return 0;
616 0 : WizardTravelSuspension aTravelGuard( *this );
617 0 : bool nRet = travelPrevious();
618 0 : return nRet ? 1 : 0;
619 : }
620 :
621 :
622 0 : IMPL_LINK_NOARG(OWizardMachine, OnNextPage)
623 : {
624 0 : if ( isTravelingSuspended() )
625 0 : return 0;
626 0 : WizardTravelSuspension aTravelGuard( *this );
627 0 : bool nRet = travelNext();
628 0 : return nRet ? 1 : 0;
629 : }
630 :
631 :
632 0 : IWizardPageController* OWizardMachine::getPageController( TabPage* _pCurrentPage ) const
633 : {
634 0 : IWizardPageController* pController = dynamic_cast< IWizardPageController* >( _pCurrentPage );
635 0 : return pController;
636 : }
637 :
638 :
639 0 : void OWizardMachine::getStateHistory( ::std::vector< WizardState >& _out_rHistory )
640 : {
641 0 : ::std::stack< WizardState > aHistoryCopy( m_pImpl->aStateHistory );
642 0 : while ( !aHistoryCopy.empty() )
643 : {
644 0 : _out_rHistory.push_back( aHistoryCopy.top() );
645 0 : aHistoryCopy.pop();
646 0 : }
647 0 : }
648 :
649 :
650 0 : bool OWizardMachine::canAdvance() const
651 : {
652 0 : return WZS_INVALID_STATE != determineNextState( getCurrentState() );
653 : }
654 :
655 :
656 0 : void OWizardMachine::updateTravelUI()
657 : {
658 0 : const IWizardPageController* pController = getPageController( GetPage( getCurrentState() ) );
659 : OSL_ENSURE( pController != NULL, "RoadmapWizard::updateTravelUI: no controller for the current page!" );
660 :
661 : bool bCanAdvance =
662 0 : ( !pController || pController->canAdvance() ) // the current page allows to advance
663 0 : && canAdvance(); // the dialog as a whole allows to advance
664 0 : enableButtons( WZB_NEXT, bCanAdvance );
665 0 : }
666 :
667 :
668 0 : bool OWizardMachine::isTravelingSuspended() const
669 : {
670 0 : return m_pImpl->m_bTravelingSuspended;
671 : }
672 :
673 :
674 0 : void OWizardMachine::suspendTraveling( AccessGuard )
675 : {
676 : DBG_ASSERT( !m_pImpl->m_bTravelingSuspended, "OWizardMachine::suspendTraveling: already suspended!" );
677 0 : m_pImpl->m_bTravelingSuspended = true;
678 0 : }
679 :
680 :
681 0 : void OWizardMachine::resumeTraveling( AccessGuard )
682 : {
683 : DBG_ASSERT( m_pImpl->m_bTravelingSuspended, "OWizardMachine::resumeTraveling: nothing to resume!" );
684 0 : m_pImpl->m_bTravelingSuspended = false;
685 0 : }
686 :
687 :
688 1227 : } // namespace svt
689 :
690 :
691 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|