LCOV - code coverage report
Current view: top level - svtools/source/uno/wizard - wizardshell.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 83 0.0 %
Date: 2014-04-14 Functions: 0 16 0.0 %
Legend: Lines: hit not hit

          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             : 
      21             : #include "wizardshell.hxx"
      22             : #include "wizardpagecontroller.hxx"
      23             : 
      24             : #include <tools/diagnose_ex.h>
      25             : 
      26             : #include <com/sun/star/ui/dialogs/WizardTravelType.hpp>
      27             : 
      28             : #include <vcl/msgbox.hxx>
      29             : 
      30             : 
      31             : namespace svt { namespace uno
      32             : {
      33             : 
      34             : 
      35             :     using ::com::sun::star::uno::Reference;
      36             :     using ::com::sun::star::uno::XInterface;
      37             :     using ::com::sun::star::uno::UNO_QUERY;
      38             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      39             :     using ::com::sun::star::uno::UNO_SET_THROW;
      40             :     using ::com::sun::star::uno::Exception;
      41             :     using ::com::sun::star::uno::RuntimeException;
      42             :     using ::com::sun::star::uno::Any;
      43             :     using ::com::sun::star::uno::makeAny;
      44             :     using ::com::sun::star::uno::Sequence;
      45             :     using ::com::sun::star::uno::Type;
      46             :     using ::com::sun::star::ui::dialogs::XWizardController;
      47             :     using ::com::sun::star::ui::dialogs::XWizard;
      48             :     using ::com::sun::star::ui::dialogs::XWizardPage;
      49             : 
      50             :     namespace WizardTravelType = ::com::sun::star::ui::dialogs::WizardTravelType;
      51             : 
      52             : 
      53             :     namespace
      54             :     {
      55             : 
      56           0 :         sal_Int16 lcl_determineFirstPageID( const Sequence< Sequence< sal_Int16 > >& i_rPaths )
      57             :         {
      58           0 :             ENSURE_OR_THROW( ( i_rPaths.getLength() > 0 ) && ( i_rPaths[0].getLength() > 0 ), "illegal paths" );
      59           0 :             return i_rPaths[0][0];
      60             :         }
      61             :     }
      62             : 
      63             : 
      64             :     //= WizardShell
      65           0 :     WizardShell::WizardShell( Window* i_pParent, const Reference< XWizardController >& i_rController,
      66             :             const Sequence< Sequence< sal_Int16 > >& i_rPaths )
      67             :         :WizardShell_Base( i_pParent, WB_MOVEABLE | WB_CLOSEABLE )
      68             :         ,m_xController( i_rController )
      69           0 :         ,m_nFirstPageID( lcl_determineFirstPageID( i_rPaths ) )
      70             :     {
      71           0 :         ENSURE_OR_THROW( m_xController.is(), "invalid controller" );
      72             : 
      73             :         // declare the paths
      74           0 :         for ( sal_Int32 i=0; i<i_rPaths.getLength(); ++i )
      75             :         {
      76           0 :             const Sequence< sal_Int16 >& rPath( i_rPaths[i] );
      77           0 :             WizardPath aPath( rPath.getLength() );
      78           0 :             for ( sal_Int32 j=0; j<rPath.getLength(); ++j )
      79           0 :                 aPath[j] = impl_pageIdToState( rPath[j] );
      80           0 :             declarePath( i, aPath );
      81           0 :         }
      82             : 
      83             :         // create the first page, to know the page size
      84           0 :         TabPage* pStartPage = GetOrCreatePage( impl_pageIdToState( i_rPaths[0][0] ) );
      85           0 :         SetPageSizePixel( pStartPage->GetSizePixel() );
      86             : 
      87             :         // some defaults
      88           0 :         ShowButtonFixedLine( true );
      89           0 :         SetRoadmapInteractive( true );
      90           0 :         enableAutomaticNextButtonState();
      91           0 :     }
      92             : 
      93             : 
      94           0 :     WizardShell::~WizardShell()
      95             :     {
      96           0 :     }
      97             : 
      98             : 
      99           0 :     short WizardShell::Execute()
     100             :     {
     101           0 :         ActivatePage();
     102           0 :         return WizardShell_Base::Execute();
     103             :     }
     104             : 
     105             : 
     106           0 :     sal_Int16 WizardShell::convertCommitReasonToTravelType( const CommitPageReason i_eReason )
     107             :     {
     108           0 :         switch ( i_eReason )
     109             :         {
     110             :         case WizardTypes::eTravelForward:
     111           0 :             return WizardTravelType::FORWARD;
     112             : 
     113             :         case WizardTypes::eTravelBackward:
     114           0 :             return WizardTravelType::BACKWARD;
     115             : 
     116             :         case WizardTypes::eFinish:
     117           0 :             return WizardTravelType::FINISH;
     118             : 
     119             :         default:
     120           0 :             break;
     121             :         }
     122             :         OSL_FAIL( "WizardShell::convertCommitReasonToTravelType: unsupported CommitPageReason!" );
     123           0 :         return WizardTravelType::FINISH;
     124             :     }
     125             : 
     126             : 
     127           0 :     void WizardShell::enterState( WizardState i_nState )
     128             :     {
     129           0 :         WizardShell_Base::enterState( i_nState );
     130             : 
     131           0 :         if ( !m_xController.is() )
     132           0 :             return;
     133             : 
     134             :         try
     135             :         {
     136           0 :             m_xController->onActivatePage( impl_stateToPageId( i_nState ) );
     137             :         }
     138           0 :         catch( const Exception& )
     139             :         {
     140             :             DBG_UNHANDLED_EXCEPTION();
     141             :         }
     142             :     }
     143             : 
     144             : 
     145           0 :     bool WizardShell::leaveState( WizardState i_nState )
     146             :     {
     147           0 :         if ( !WizardShell_Base::leaveState( i_nState ) )
     148           0 :             return false;
     149             : 
     150           0 :         if ( !m_xController.is() )
     151           0 :             return true;
     152             : 
     153             :         try
     154             :         {
     155           0 :             m_xController->onDeactivatePage( impl_stateToPageId( i_nState ) );
     156             :         }
     157           0 :         catch( const Exception& )
     158             :         {
     159             :             DBG_UNHANDLED_EXCEPTION();
     160             :         }
     161             : 
     162           0 :         return true;
     163             :     }
     164             : 
     165             : 
     166           0 :     PWizardPageController WizardShell::impl_getController( TabPage* i_pPage ) const
     167             :     {
     168           0 :         Page2ControllerMap::const_iterator pos = m_aPageControllers.find( i_pPage );
     169           0 :         ENSURE_OR_RETURN( pos != m_aPageControllers.end(), "WizardShell::impl_getController: no controller for this page!", PWizardPageController() );
     170           0 :         return pos->second;
     171             :     }
     172             : 
     173             : 
     174           0 :     Reference< XWizardPage > WizardShell::getCurrentWizardPage() const
     175             :     {
     176           0 :         const WizardState eState = getCurrentState();
     177             : 
     178           0 :         PWizardPageController pController( impl_getController( GetPage( eState ) ) );
     179           0 :         ENSURE_OR_RETURN( pController, "WizardShell::getCurrentWizardPage: invalid page/controller!", NULL );
     180             : 
     181           0 :         return pController->getWizardPage();
     182             :     }
     183             : 
     184             : 
     185           0 :     void WizardShell::enablePage( const sal_Int16 i_nPageID, const sal_Bool i_bEnable )
     186             :     {
     187           0 :         enableState( impl_pageIdToState( i_nPageID ), i_bEnable );
     188           0 :     }
     189             : 
     190             : 
     191           0 :     TabPage* WizardShell::createPage( WizardState i_nState )
     192             :     {
     193           0 :         ENSURE_OR_RETURN( m_xController.is(), "WizardShell::createPage: no WizardController!", NULL );
     194             : 
     195           0 :         ::boost::shared_ptr< WizardPageController > pController( new WizardPageController( *this, m_xController, impl_stateToPageId( i_nState ) ) );
     196           0 :         TabPage* pPage = pController->getTabPage();
     197             :         OSL_ENSURE( pPage != NULL, "WizardShell::createPage: illegal tab page!" );
     198           0 :         if ( pPage == NULL )
     199             :         {
     200             :             // fallback for ill-behaved clients: empty page
     201           0 :             pPage = new TabPage( this, 0 );
     202           0 :             pPage->SetSizePixel( LogicToPixel( Size( 280, 185 ), MAP_APPFONT ) );
     203             :         }
     204             : 
     205           0 :         m_aPageControllers[ pPage ] = pController;
     206           0 :         return pPage;
     207             :     }
     208             : 
     209             : 
     210           0 :     IWizardPageController* WizardShell::getPageController( TabPage* i_pCurrentPage ) const
     211             :     {
     212           0 :         return impl_getController( i_pCurrentPage ).get();
     213             :     }
     214             : 
     215             : 
     216           0 :     OUString WizardShell::getStateDisplayName( WizardState i_nState ) const
     217             :     {
     218             :         try
     219             :         {
     220           0 :             if ( m_xController.is() )
     221           0 :                 return m_xController->getPageTitle( impl_stateToPageId( i_nState ) );
     222             :         }
     223           0 :         catch( const Exception& )
     224             :         {
     225             :             DBG_UNHANDLED_EXCEPTION();
     226             :         }
     227             :         // fallback for ill-behaved clients: the numeric state
     228           0 :         return OUString::number(i_nState);
     229             :     }
     230             : 
     231             : 
     232           0 :     bool WizardShell::canAdvance() const
     233             :     {
     234             :         try
     235             :         {
     236           0 :             if ( m_xController.is() && !m_xController->canAdvance() )
     237           0 :                 return false;
     238             :         }
     239           0 :         catch( const Exception& )
     240             :         {
     241             :             DBG_UNHANDLED_EXCEPTION();
     242             :         }
     243             : 
     244           0 :         return WizardShell_Base::canAdvance();
     245             :     }
     246             : 
     247             : 
     248           0 :     bool WizardShell::onFinish()
     249             :     {
     250             :         try
     251             :         {
     252           0 :             if ( m_xController.is() && !m_xController->confirmFinish() )
     253           0 :                 return false;
     254             :         }
     255           0 :         catch( const Exception& )
     256             :         {
     257             :             DBG_UNHANDLED_EXCEPTION();
     258             :         }
     259             : 
     260           0 :         return WizardShell_Base::onFinish();
     261             :     }
     262             : 
     263             : 
     264             : } } // namespace svt::uno
     265             : 
     266             : 
     267             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10