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

Generated by: LCOV version 1.10