LCOV - code coverage report
Current view: top level - svtools/source/uno/wizard - wizardshell.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 83 1.2 %
Date: 2014-11-03 Functions: 2 18 11.1 %
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( vcl::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 :         SetRoadmapInteractive( true );
      89           0 :         enableAutomaticNextButtonState();
      90           0 :     }
      91             : 
      92             : 
      93           0 :     WizardShell::~WizardShell()
      94             :     {
      95           0 :     }
      96             : 
      97             : 
      98           0 :     short WizardShell::Execute()
      99             :     {
     100           0 :         ActivatePage();
     101           0 :         return WizardShell_Base::Execute();
     102             :     }
     103             : 
     104             : 
     105           0 :     sal_Int16 WizardShell::convertCommitReasonToTravelType( const CommitPageReason i_eReason )
     106             :     {
     107           0 :         switch ( i_eReason )
     108             :         {
     109             :         case WizardTypes::eTravelForward:
     110           0 :             return WizardTravelType::FORWARD;
     111             : 
     112             :         case WizardTypes::eTravelBackward:
     113           0 :             return WizardTravelType::BACKWARD;
     114             : 
     115             :         case WizardTypes::eFinish:
     116           0 :             return WizardTravelType::FINISH;
     117             : 
     118             :         default:
     119           0 :             break;
     120             :         }
     121             :         OSL_FAIL( "WizardShell::convertCommitReasonToTravelType: unsupported CommitPageReason!" );
     122           0 :         return WizardTravelType::FINISH;
     123             :     }
     124             : 
     125             : 
     126           0 :     void WizardShell::enterState( WizardState i_nState )
     127             :     {
     128           0 :         WizardShell_Base::enterState( i_nState );
     129             : 
     130           0 :         if ( !m_xController.is() )
     131           0 :             return;
     132             : 
     133             :         try
     134             :         {
     135           0 :             m_xController->onActivatePage( impl_stateToPageId( i_nState ) );
     136             :         }
     137           0 :         catch( const Exception& )
     138             :         {
     139             :             DBG_UNHANDLED_EXCEPTION();
     140             :         }
     141             :     }
     142             : 
     143             : 
     144           0 :     bool WizardShell::leaveState( WizardState i_nState )
     145             :     {
     146           0 :         if ( !WizardShell_Base::leaveState( i_nState ) )
     147           0 :             return false;
     148             : 
     149           0 :         if ( !m_xController.is() )
     150           0 :             return true;
     151             : 
     152             :         try
     153             :         {
     154           0 :             m_xController->onDeactivatePage( impl_stateToPageId( i_nState ) );
     155             :         }
     156           0 :         catch( const Exception& )
     157             :         {
     158             :             DBG_UNHANDLED_EXCEPTION();
     159             :         }
     160             : 
     161           0 :         return true;
     162             :     }
     163             : 
     164             : 
     165           0 :     PWizardPageController WizardShell::impl_getController( TabPage* i_pPage ) const
     166             :     {
     167           0 :         Page2ControllerMap::const_iterator pos = m_aPageControllers.find( i_pPage );
     168           0 :         ENSURE_OR_RETURN( pos != m_aPageControllers.end(), "WizardShell::impl_getController: no controller for this page!", PWizardPageController() );
     169           0 :         return pos->second;
     170             :     }
     171             : 
     172             : 
     173           0 :     Reference< XWizardPage > WizardShell::getCurrentWizardPage() const
     174             :     {
     175           0 :         const WizardState eState = getCurrentState();
     176             : 
     177           0 :         PWizardPageController pController( impl_getController( GetPage( eState ) ) );
     178           0 :         ENSURE_OR_RETURN( pController, "WizardShell::getCurrentWizardPage: invalid page/controller!", NULL );
     179             : 
     180           0 :         return pController->getWizardPage();
     181             :     }
     182             : 
     183             : 
     184           0 :     void WizardShell::enablePage( const sal_Int16 i_nPageID, const bool i_bEnable )
     185             :     {
     186           0 :         enableState( impl_pageIdToState( i_nPageID ), i_bEnable );
     187           0 :     }
     188             : 
     189             : 
     190           0 :     TabPage* WizardShell::createPage( WizardState i_nState )
     191             :     {
     192           0 :         ENSURE_OR_RETURN( m_xController.is(), "WizardShell::createPage: no WizardController!", NULL );
     193             : 
     194           0 :         ::boost::shared_ptr< WizardPageController > pController( new WizardPageController( *this, m_xController, impl_stateToPageId( i_nState ) ) );
     195           0 :         TabPage* pPage = pController->getTabPage();
     196             :         OSL_ENSURE( pPage != NULL, "WizardShell::createPage: illegal tab page!" );
     197           0 :         if ( pPage == NULL )
     198             :         {
     199             :             // fallback for ill-behaved clients: empty page
     200           0 :             pPage = new TabPage( this, 0 );
     201           0 :             pPage->SetSizePixel( LogicToPixel( Size( 280, 185 ), MAP_APPFONT ) );
     202             :         }
     203             : 
     204           0 :         m_aPageControllers[ pPage ] = pController;
     205           0 :         return pPage;
     206             :     }
     207             : 
     208             : 
     209           0 :     IWizardPageController* WizardShell::getPageController( TabPage* i_pCurrentPage ) const
     210             :     {
     211           0 :         return impl_getController( i_pCurrentPage ).get();
     212             :     }
     213             : 
     214             : 
     215           0 :     OUString WizardShell::getStateDisplayName( WizardState i_nState ) const
     216             :     {
     217             :         try
     218             :         {
     219           0 :             if ( m_xController.is() )
     220           0 :                 return m_xController->getPageTitle( impl_stateToPageId( i_nState ) );
     221             :         }
     222           0 :         catch( const Exception& )
     223             :         {
     224             :             DBG_UNHANDLED_EXCEPTION();
     225             :         }
     226             :         // fallback for ill-behaved clients: the numeric state
     227           0 :         return OUString::number(i_nState);
     228             :     }
     229             : 
     230             : 
     231           0 :     bool WizardShell::canAdvance() const
     232             :     {
     233             :         try
     234             :         {
     235           0 :             if ( m_xController.is() && !m_xController->canAdvance() )
     236           0 :                 return false;
     237             :         }
     238           0 :         catch( const Exception& )
     239             :         {
     240             :             DBG_UNHANDLED_EXCEPTION();
     241             :         }
     242             : 
     243           0 :         return WizardShell_Base::canAdvance();
     244             :     }
     245             : 
     246             : 
     247           0 :     bool WizardShell::onFinish()
     248             :     {
     249             :         try
     250             :         {
     251           0 :             if ( m_xController.is() && !m_xController->confirmFinish() )
     252           0 :                 return false;
     253             :         }
     254           0 :         catch( const Exception& )
     255             :         {
     256             :             DBG_UNHANDLED_EXCEPTION();
     257             :         }
     258             : 
     259           0 :         return WizardShell_Base::onFinish();
     260             :     }
     261             : 
     262             : 
     263        1227 : } } // namespace svt::uno
     264             : 
     265             : 
     266             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10