LCOV - code coverage report
Current view: top level - svtools/source/dialogs - wizardmachine.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 309 0.0 %
Date: 2012-08-25 Functions: 0 51 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 418 0.0 %

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

Generated by: LCOV version 1.10