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

Generated by: LCOV version 1.10