diff options
author | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-05-20 12:45:50 +0200 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-05-20 12:45:50 +0200 |
commit | b393dc5d63ffdf35459a7a6a1863df066ee82ae1 (patch) | |
tree | 5c6b88760f88d2e9f3204409b40d4ab88050ffde /svtools/source/uno | |
parent | ffe5faef611a17abf300a049f5158dd6662c46de (diff) |
unoawt: UNO API for generic wizards, wrapping around the existing C++ RoadmapWizard
Diffstat (limited to 'svtools/source/uno')
-rw-r--r-- | svtools/source/uno/makefile.mk | 2 | ||||
-rw-r--r-- | svtools/source/uno/miscservices.cxx | 23 | ||||
-rw-r--r-- | svtools/source/uno/unowizard.hxx | 111 | ||||
-rw-r--r-- | svtools/source/uno/wizard/makefile.mk | 48 | ||||
-rw-r--r-- | svtools/source/uno/wizard/unowizard.cxx | 374 | ||||
-rw-r--r-- | svtools/source/uno/wizard/wizardpageshell.cxx | 170 | ||||
-rw-r--r-- | svtools/source/uno/wizard/wizardpageshell.hxx | 73 | ||||
-rw-r--r-- | svtools/source/uno/wizard/wizardshell.cxx | 251 | ||||
-rw-r--r-- | svtools/source/uno/wizard/wizardshell.hxx | 115 |
9 files changed, 1164 insertions, 3 deletions
diff --git a/svtools/source/uno/makefile.mk b/svtools/source/uno/makefile.mk index 4a52960f448c..d207b1effd97 100644 --- a/svtools/source/uno/makefile.mk +++ b/svtools/source/uno/makefile.mk @@ -52,7 +52,7 @@ SLOFILES= \ $(SLO)$/unoevent.obj \ $(SLO)$/unoiface.obj \ $(SLO)$/unoimap.obj \ - $(SLO)$/svtxgridcontrol.obj + $(SLO)$/svtxgridcontrol.obj # --- Targets ------------------------------------------------------ diff --git a/svtools/source/uno/miscservices.cxx b/svtools/source/uno/miscservices.cxx index 433c1e1acbcb..e16a1ecb56dc 100644 --- a/svtools/source/uno/miscservices.cxx +++ b/svtools/source/uno/miscservices.cxx @@ -38,10 +38,13 @@ #include <uno/mapping.hxx> #include "provider.hxx" #include "renderer.hxx" +#include "unowizard.hxx" #include <com/sun/star/registry/XRegistryKey.hpp> #include "comphelper/servicedecl.hxx" +#include "cppuhelper/implementationentry.hxx" + using namespace ::com::sun::star::uno; using namespace ::com::sun::star::registry; using namespace ::com::sun::star::lang; @@ -67,6 +70,20 @@ extern sdecl::ServiceDecl const serviceDecl; Reference< XInterface > SAL_CALL ImplName##_CreateInstance( const Reference< XMultiServiceFactory >& ); \ } +namespace +{ + static struct ::cppu::ImplementationEntry s_aServiceEntries[] = + { + { + ::svt::uno::Wizard::Create, + ::svt::uno::Wizard::getImplementationName_static, + ::svt::uno::Wizard::getSupportedServiceNames_static, + ::cppu::createSingleComponentFactory, NULL, 0 + }, + { 0, 0, 0, 0, 0, 0 } + }; +} + // ------------------------------------------------------------------------------------- DECLARE_CREATEINSTANCE_NAMESPACE( svt, OAddressBookSourceDialogUno ) @@ -126,9 +143,9 @@ SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo ( xNewKey->createKey( aServices.getConstArray()[ i ] ); if ( !component_writeInfoHelper( reinterpret_cast< lang::XMultiServiceFactory* >( pServiceManager ), reinterpret_cast< registry::XRegistryKey* >( _pRegistryKey ), serviceDecl ) ) - return false; + return false; - return sal_True; + return ::cppu::component_writeInfoHelper( pServiceManager, _pRegistryKey, s_aServiceEntries ); } return sal_False; } @@ -185,6 +202,8 @@ SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory ( else { pResult = component_getFactoryHelper( pImplementationName, reinterpret_cast< lang::XMultiServiceFactory * >( _pServiceManager ),reinterpret_cast< registry::XRegistryKey* >( pRegistryKey ), serviceDecl ); + if ( !pResult ) + pResult = ::cppu::component_getFactoryHelper( pImplementationName, _pServiceManager, pRegistryKey, s_aServiceEntries ); } if ( xFactory.is() ) diff --git a/svtools/source/uno/unowizard.hxx b/svtools/source/uno/unowizard.hxx new file mode 100644 index 000000000000..cf09646a690e --- /dev/null +++ b/svtools/source/uno/unowizard.hxx @@ -0,0 +1,111 @@ +/************************************************************************* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SVT_UNO_WIZARD_HXX +#define SVT_UNO_WIZARD_HXX + +#include "svtools/genericunodialog.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/ui/dialogs/XWizard.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/ui/dialogs/XWizardController.hpp> +/** === end UNO includes === **/ + +#include <cppuhelper/implbase1.hxx> +#include <comphelper/componentcontext.hxx> + +//...................................................................................................................... +namespace svt { namespace uno +{ +//...................................................................................................................... + + //================================================================================================================== + //= Wizard - declaration + //================================================================================================================== + typedef ::cppu::ImplInheritanceHelper1 < ::svt::OGenericUnoDialog + , ::com::sun::star::ui::dialogs::XWizard + > Wizard_Base; + class Wizard; + typedef ::comphelper::OPropertyArrayUsageHelper< Wizard > Wizard_PBase; + class Wizard : public Wizard_Base + , public Wizard_PBase + { + public: + Wizard( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& i_rContext ); + + // ::com::sun::star::lang::XServiceInfo - static version + static ::rtl::OUString SAL_CALL getImplementationName_static() throw(::com::sun::star::uno::RuntimeException); + static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static() throw(::com::sun::star::uno::RuntimeException); + static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL Create( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& i_rContext ); + + protected: + // ::com::sun::star::lang::XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::beans::XPropertySet + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException); + virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); + + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; + + // ::com::sun::star::ui::dialogs::XWizard + virtual void SAL_CALL enableButton( ::sal_Int16 WizardButton, ::sal_Bool Enable ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDefaultButton( ::sal_Int16 WizardButton ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL travelNext( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL travelPrevious( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL updateTravelUI( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL advanceTo( ::sal_Int16 PageId ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL goBackTo( ::sal_Int16 PageId ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int16 SAL_CALL getCurrentPage( ) throw (::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::ui::dialogs::XExecutableDialog + virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Int16 SAL_CALL execute( ) throw (::com::sun::star::uno::RuntimeException); + + // ::com::sun::star::lang::XInitialization + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + protected: + ~Wizard(); + + protected: + virtual Dialog* createDialog( Window* _pParent ); + virtual void destroyDialog(); + + private: + ::comphelper::ComponentContext m_aContext; + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< sal_Int16 > > m_aWizardSteps; + ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizardController > m_xController; + }; + +//...................................................................................................................... +} } // namespace svt::uno +//...................................................................................................................... + +#endif // SVT_UNO_WIZARD_HXX diff --git a/svtools/source/uno/wizard/makefile.mk b/svtools/source/uno/wizard/makefile.mk new file mode 100644 index 000000000000..2beef5060475 --- /dev/null +++ b/svtools/source/uno/wizard/makefile.mk @@ -0,0 +1,48 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=../../.. + +PRJNAME=svtools +TARGET=unowiz +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/svt.pmk + +# --- Files -------------------------------------------------------- + +SLOFILES= \ + $(SLO)$/unowizard.obj \ + $(SLO)$/wizardshell.obj \ + $(SLO)$/wizardpageshell.obj + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/svtools/source/uno/wizard/unowizard.cxx b/svtools/source/uno/wizard/unowizard.cxx new file mode 100644 index 000000000000..b832162ef92f --- /dev/null +++ b/svtools/source/uno/wizard/unowizard.cxx @@ -0,0 +1,374 @@ +/************************************************************************* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "precompiled_svtools.hxx" + +#include "../unowizard.hxx" +#include "wizardshell.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/ucb/AlreadyInitializedException.hpp> +#include <com/sun/star/ui/dialogs/XWizardController.hpp> +#include <com/sun/star/ui/dialogs/WizardButton.hpp> +/** === end UNO includes === **/ + +#include <tools/diagnose_ex.h> +#include <rtl/strbuf.hxx> +#include <vos/mutex.hxx> +#include <vcl/svapp.hxx> + +//...................................................................................................................... +namespace svt { namespace uno +{ +//...................................................................................................................... + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::lang::XServiceInfo; + using ::com::sun::star::ui::dialogs::XWizard; + using ::com::sun::star::lang::XInitialization; + using ::com::sun::star::beans::XPropertySetInfo; + using ::com::sun::star::uno::XComponentContext; + using ::com::sun::star::beans::Property; + using ::com::sun::star::lang::IllegalArgumentException; + using ::com::sun::star::ucb::AlreadyInitializedException; + using ::com::sun::star::ui::dialogs::XWizardController; + /** === end UNO using === **/ + namespace WizardButton = ::com::sun::star::ui::dialogs::WizardButton; + + //------------------------------------------------------------------------------------------------------------------ + namespace + { + sal_uInt32 lcl_convertWizardButtonToWZB( const sal_Int16 i_nWizardButton ) + { + switch ( i_nWizardButton ) + { + case WizardButton::NEXT: return WZB_NEXT; + case WizardButton::PREVIOUS: return WZB_PREVIOUS; + case WizardButton::FINISH: return WZB_FINISH; + case WizardButton::CANCEL: return WZB_CANCEL; + case WizardButton::HELP: return WZB_HELP; + } + OSL_ENSURE( false, "lcl_convertWizardButtonToWZB: invalid WizardButton constant!" ); + return 0; + } + } + + //================================================================================================================== + //= Wizard - implementation + //================================================================================================================== + //------------------------------------------------------------------------------------------------------------------ + Wizard::Wizard( const Reference< XComponentContext >& _rxContext ) + :Wizard_Base( _rxContext ) + ,m_aContext( _rxContext ) + { + } + + //-------------------------------------------------------------------- + Wizard::~Wizard() + { + // we do this here cause the base class' call to destroyDialog won't reach us anymore : we're within an dtor, + // so this virtual-method-call the base class does does not work, we're already dead then ... + if ( m_pDialog ) + { + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_pDialog ) + destroyDialog(); + } + } + + //-------------------------------------------------------------------- + Reference< XInterface > SAL_CALL Wizard::Create( const Reference< XComponentContext >& _rxContext ) + { + return *(new Wizard( _rxContext ) ); + } + + //-------------------------------------------------------------------- + namespace + { + static void lcl_checkPaths( const Sequence< Sequence< sal_Int16 > >& i_rPaths, const Reference< XInterface >& i_rContext ) + { + // need at least one path + if ( i_rPaths.getLength() == 0 ) + throw IllegalArgumentException( ::rtl::OUString(), i_rContext, 2 ); + + // each path must be of length 1, at least + for ( sal_Int32 i = 0; i < i_rPaths.getLength(); ++i ) + { + if ( i_rPaths[i].getLength() == 0 ) + throw IllegalArgumentException( ::rtl::OUString(), i_rContext, 2 ); + + // page IDs must be in ascending order + sal_Int16 nPreviousPageID = i_rPaths[i][0]; + for ( sal_Int32 j=1; j<i_rPaths[i].getLength(); ++j ) + { + if ( i_rPaths[i][j] <= nPreviousPageID ) + { + ::rtl::OStringBuffer message; + message.append( "Path " ); + message.append( i ); + message.append( ": invalid page ID sequence - each page ID must be greater than the previous one." ); + throw IllegalArgumentException( + ::rtl::OStringToOUString( message.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US ), + i_rContext, 2 ); + } + nPreviousPageID = i_rPaths[i][j]; + } + } + + // if we have one path, that's okay + if ( i_rPaths.getLength() == 1 ) + return; + + // if we have multiple paths, they must start with the same page id + const sal_Int16 nFirstPageId = i_rPaths[0][0]; + for ( sal_Int32 i = 0; i < i_rPaths.getLength(); ++i ) + { + if ( i_rPaths[i][0] != nFirstPageId ) + throw IllegalArgumentException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "All paths must start with the same page id." ) ), + i_rContext, 2 ); + } + } + } + + //-------------------------------------------------------------------- + void SAL_CALL Wizard::initialize( const Sequence< Any >& i_Arguments ) throw (Exception, RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + if ( m_bInitialized ) + throw AlreadyInitializedException( ::rtl::OUString(), *this ); + + if ( i_Arguments.getLength() != 2 ) + throw IllegalArgumentException( ::rtl::OUString(), *this, -1 ); + + // the second argument must be a XWizardController, for each constructor + m_xController.set( i_Arguments[1], UNO_QUERY ); + if ( !m_xController.is() ) + throw IllegalArgumentException( ::rtl::OUString(), *this, 2 ); + + // the first arg is either a single path (short[]), or multiple paths (short[][]) + Sequence< sal_Int16 > aSinglePath; + i_Arguments[0] >>= aSinglePath; + Sequence< Sequence< sal_Int16 > > aMultiplePaths; + i_Arguments[0] >>= aMultiplePaths; + + if ( !aMultiplePaths.getLength() ) + { + aMultiplePaths.realloc(1); + aMultiplePaths[0] = aSinglePath; + } + lcl_checkPaths( aMultiplePaths, *this ); + // if we survived this, the paths are valid, and we're done here ... + m_aWizardSteps = aMultiplePaths; + + m_bInitialized = true; + } + + //-------------------------------------------------------------------- + Dialog* Wizard::createDialog( Window* i_pParent ) + { + return new WizardShell( i_pParent, this, m_xController, m_aWizardSteps ); + } + + //-------------------------------------------------------------------- + void Wizard::destroyDialog() + { + Wizard_Base::destroyDialog(); + } + + //-------------------------------------------------------------------- + ::rtl::OUString SAL_CALL Wizard::getImplementationName_static() throw(RuntimeException) + { + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.uno.Wizard" ) ); + } + + //-------------------------------------------------------------------- + Sequence< ::rtl::OUString > SAL_CALL Wizard::getSupportedServiceNames_static() throw(RuntimeException) + { + Sequence< ::rtl::OUString > aServices(1); + aServices[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.Wizard" ) ); + return aServices; + } + + //-------------------------------------------------------------------- + ::rtl::OUString SAL_CALL Wizard::getImplementationName() throw(RuntimeException) + { + return getImplementationName_static(); + } + + //-------------------------------------------------------------------- + Sequence< ::rtl::OUString > SAL_CALL Wizard::getSupportedServiceNames() throw(RuntimeException) + { + return getSupportedServiceNames_static(); + } + + //-------------------------------------------------------------------- + Reference< XPropertySetInfo > SAL_CALL Wizard::getPropertySetInfo() throw(RuntimeException) + { + return createPropertySetInfo( getInfoHelper() ); + } + + //-------------------------------------------------------------------- + ::cppu::IPropertyArrayHelper& SAL_CALL Wizard::getInfoHelper() + { + return *const_cast< Wizard* >( this )->getArrayHelper(); + } + + //-------------------------------------------------------------------- + ::cppu::IPropertyArrayHelper* Wizard::createArrayHelper( ) const + { + Sequence< Property > aProps; + describeProperties( aProps ); + return new ::cppu::OPropertyArrayHelper( aProps ); + } + + //------------------------------------------------------------------------------------------------------------------ + void SAL_CALL Wizard::enableButton( ::sal_Int16 i_WizardButton, ::sal_Bool i_Enable ) throw (RuntimeException) + { + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + ::osl::MutexGuard aGuard( m_aMutex ); + + WizardShell* pWizardImpl = dynamic_cast< WizardShell* >( m_pDialog ); + ENSURE_OR_RETURN_VOID( pWizardImpl, "Wizard::enableButtons: invalid dialog implementation!" ); + + pWizardImpl->enableButtons( lcl_convertWizardButtonToWZB( i_WizardButton ), i_Enable ); + } + + //------------------------------------------------------------------------------------------------------------------ + void SAL_CALL Wizard::setDefaultButton( ::sal_Int16 i_WizardButton ) throw (RuntimeException) + { + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + ::osl::MutexGuard aGuard( m_aMutex ); + + WizardShell* pWizardImpl = dynamic_cast< WizardShell* >( m_pDialog ); + ENSURE_OR_RETURN_VOID( pWizardImpl, "Wizard::setDefaultButton: invalid dialog implementation!" ); + + pWizardImpl->defaultButton( lcl_convertWizardButtonToWZB( i_WizardButton ) ); + } + + //------------------------------------------------------------------------------------------------------------------ + sal_Bool SAL_CALL Wizard::travelNext( ) throw (RuntimeException) + { + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + ::osl::MutexGuard aGuard( m_aMutex ); + + WizardShell* pWizardImpl = dynamic_cast< WizardShell* >( m_pDialog ); + ENSURE_OR_RETURN_FALSE( pWizardImpl, "Wizard::travelNext: invalid dialog implementation!" ); + + return pWizardImpl->travelNext(); + } + + //------------------------------------------------------------------------------------------------------------------ + sal_Bool SAL_CALL Wizard::travelPrevious( ) throw (RuntimeException) + { + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + ::osl::MutexGuard aGuard( m_aMutex ); + + WizardShell* pWizardImpl = dynamic_cast< WizardShell* >( m_pDialog ); + ENSURE_OR_RETURN_FALSE( pWizardImpl, "Wizard::travelPrevious: invalid dialog implementation!" ); + + return pWizardImpl->travelPrevious(); + } + + //------------------------------------------------------------------------------------------------------------------ + void SAL_CALL Wizard::updateTravelUI( ) throw (RuntimeException) + { + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + ::osl::MutexGuard aGuard( m_aMutex ); + + WizardShell* pWizardImpl = dynamic_cast< WizardShell* >( m_pDialog ); + ENSURE_OR_RETURN_VOID( pWizardImpl, "Wizard::updateTravelUI: invalid dialog implementation!" ); + + pWizardImpl->updateTravelUI(); + } + + //------------------------------------------------------------------------------------------------------------------ + ::sal_Bool SAL_CALL Wizard::advanceTo( ::sal_Int16 i_PageId ) throw (RuntimeException) + { + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + ::osl::MutexGuard aGuard( m_aMutex ); + + WizardShell* pWizardImpl = dynamic_cast< WizardShell* >( m_pDialog ); + ENSURE_OR_RETURN_FALSE( pWizardImpl, "Wizard::advanceTo: invalid dialog implementation!" ); + + return pWizardImpl->advanceTo( i_PageId ); + } + + //------------------------------------------------------------------------------------------------------------------ + ::sal_Bool SAL_CALL Wizard::goBackTo( ::sal_Int16 i_PageId ) throw (RuntimeException) + { + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + ::osl::MutexGuard aGuard( m_aMutex ); + + WizardShell* pWizardImpl = dynamic_cast< WizardShell* >( m_pDialog ); + ENSURE_OR_RETURN_FALSE( pWizardImpl, "Wizard::goBackTo: invalid dialog implementation!" ); + + return pWizardImpl->goBackTo( i_PageId ); + } + + //------------------------------------------------------------------------------------------------------------------ + ::sal_Int16 SAL_CALL Wizard::getCurrentPage( ) throw (RuntimeException) + { + ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + ::osl::MutexGuard aGuard( m_aMutex ); + + WizardShell* pWizardImpl = dynamic_cast< WizardShell* >( m_pDialog ); + ENSURE_OR_RETURN_FALSE( pWizardImpl, "Wizard::getCurrentPage: invalid dialog implementation!" ); + + return pWizardImpl->getCurrentPage(); + } + + //------------------------------------------------------------------------------------------------------------------ + void SAL_CALL Wizard::setTitle( const ::rtl::OUString& i_Title ) throw (RuntimeException) + { + // simply disambiguate + Wizard_Base::OGenericUnoDialog::setTitle( i_Title ); + } + + //------------------------------------------------------------------------------------------------------------------ + ::sal_Int16 SAL_CALL Wizard::execute( ) throw (RuntimeException) + { + // simply disambiguate + return Wizard_Base::OGenericUnoDialog::execute(); + } + +//...................................................................................................................... +} } // namespace svt::uno +//...................................................................................................................... diff --git a/svtools/source/uno/wizard/wizardpageshell.cxx b/svtools/source/uno/wizard/wizardpageshell.cxx new file mode 100644 index 000000000000..f75efe05da3d --- /dev/null +++ b/svtools/source/uno/wizard/wizardpageshell.cxx @@ -0,0 +1,170 @@ +/************************************************************************* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "precompiled_svtools.hxx" + +#include "wizardpageshell.hxx" +#include "wizardshell.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/lang/XComponent.hpp> +/** === end UNO includes === **/ + +#include <tools/diagnose_ex.h> + +//...................................................................................................................... +namespace svt { namespace uno +{ +//...................................................................................................................... + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::ui::dialogs::XWizardController; + using ::com::sun::star::awt::XWindow; + using ::com::sun::star::lang::XComponent; + /** === end UNO using === **/ + using namespace ::com::sun::star; + + //================================================================================================================== + //= WizardPageShell + //================================================================================================================== + //------------------------------------------------------------------------------------------------------------------ + WizardPageShell::WizardPageShell( WizardShell& i_rParent, const Reference< XWizardController >& i_rController, + const sal_Int16 i_nPageId ) + :OWizardPage( &i_rParent, WB_CHILDDLGCTRL | WB_NODIALOGCONTROL ) + ,m_xController( i_rController ) + ,m_xWizardPage() + ,m_nPageId( i_nPageId ) + { + ENSURE_OR_THROW( m_xController.is(), "no controller" ); + try + { + m_xWizardPage.set( m_xController->createPage( + Reference< XWindow >( GetComponentInterface( TRUE ), UNO_QUERY_THROW ), + m_nPageId + ), UNO_SET_THROW ); + + Reference< XWindow > xPageWindow( m_xWizardPage->getWindow(), UNO_SET_THROW ); + + awt::Rectangle aContentRect( xPageWindow->getPosSize() ); + SetSizePixel( Size( aContentRect.X + aContentRect.Width, aContentRect.Y + aContentRect.Height ) ); + + xPageWindow->setVisible( sal_True ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + Show(); + } + + //------------------------------------------------------------------------------------------------------------------ + WizardPageShell::~WizardPageShell() + { + try + { + if ( m_xWizardPage.is() ) + m_xWizardPage->dispose(); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + //------------------------------------------------------------------------------------------------------------------ + void WizardPageShell::initializePage() + { + OWizardPage::initializePage(); + if ( !m_xWizardPage.is() ) + return; + + try + { + m_xWizardPage->activatePage(); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + //------------------------------------------------------------------------------------------------------------------ + sal_Bool WizardPageShell::commitPage( CommitPageReason i_eReason ) + { + if ( !OWizardPage::commitPage( i_eReason ) ) + return sal_False; + + if ( !m_xWizardPage.is() ) + return sal_True; + + try + { + return m_xWizardPage->commitPage( WizardShell::convertCommitReasonToTravelType( i_eReason ) ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + return sal_True; + } + + //------------------------------------------------------------------------------------------------------------------ + bool WizardPageShell::canAdvance() const + { + if ( !OWizardPage::canAdvance() ) + return false; + + if ( !m_xWizardPage.is() ) + return true; + + try + { + return m_xWizardPage->canAdvance(); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + return true; + } + +//...................................................................................................................... +} } // namespace svt::uno +//...................................................................................................................... diff --git a/svtools/source/uno/wizard/wizardpageshell.hxx b/svtools/source/uno/wizard/wizardpageshell.hxx new file mode 100644 index 000000000000..8f36a19c0fe4 --- /dev/null +++ b/svtools/source/uno/wizard/wizardpageshell.hxx @@ -0,0 +1,73 @@ +/************************************************************************* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SVT_UNOWIZ_WIZARDPAGESHELL_HXX +#define SVT_UNOWIZ_WIZARDPAGESHELL_HXX + +#include "svtools/wizardmachine.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/ui/dialogs/XWizardController.hpp> +/** === end UNO includes === **/ + +//...................................................................................................................... +namespace svt { namespace uno +{ +//...................................................................................................................... + + class WizardShell; + + //================================================================================================================== + //= WizardPageShell + //================================================================================================================== + class WizardPageShell : public OWizardPage + { + public: + WizardPageShell( + WizardShell& i_rParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizardController >& i_rController, + const sal_Int16 i_nPageId + ); + ~WizardPageShell(); + + // IWizardPage overridables + virtual void initializePage(); + virtual sal_Bool commitPage( CommitPageReason _eReason ); + + // OWizardPage overridables (why isn't this method part of IWizardPage?) + virtual bool canAdvance() const; + + private: + const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizardController > m_xController; + ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizardPage > m_xWizardPage; + const sal_Int16 m_nPageId; + }; + +//...................................................................................................................... +} } // namespace svt::uno +//...................................................................................................................... + +#endif // SVT_UNOWIZ_WIZARDPAGESHELL_HXX diff --git a/svtools/source/uno/wizard/wizardshell.cxx b/svtools/source/uno/wizard/wizardshell.cxx new file mode 100644 index 000000000000..859ab38a3f3a --- /dev/null +++ b/svtools/source/uno/wizard/wizardshell.cxx @@ -0,0 +1,251 @@ +/************************************************************************* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "precompiled_svtools.hxx" + +#include "wizardshell.hxx" +#include "wizardpageshell.hxx" + +#include <tools/diagnose_ex.h> + +/** === begin UNO includes === **/ +#include <com/sun/star/ui/dialogs/WizardTravelType.hpp> +/** === end UNO includes === **/ + +#include <vcl/msgbox.hxx> + +//...................................................................................................................... +namespace svt { namespace uno +{ +//...................................................................................................................... + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::ui::dialogs::XWizardController; + using ::com::sun::star::ui::dialogs::XWizard; + /** === end UNO using === **/ + namespace WizardTravelType = ::com::sun::star::ui::dialogs::WizardTravelType; + + //================================================================================================================== + namespace + { + //-------------------------------------------------------------------------------------------------------------- + sal_Int16 lcl_determineFirstPageID( const Sequence< Sequence< sal_Int16 > >& i_rPaths ) + { + ENSURE_OR_THROW( ( i_rPaths.getLength() > 0 ) && ( i_rPaths[0].getLength() > 0 ), "illegal paths" ); + return i_rPaths[0][0]; + } + } + + //================================================================================================================== + //= WizardShell + //================================================================================================================== + //------------------------------------------------------------------------------------------------------------------ + WizardShell::WizardShell( Window* i_pParent, const Reference< XWizard >& i_rWizard, const Reference< XWizardController >& i_rController, + const Sequence< Sequence< sal_Int16 > >& i_rPaths ) + :WizardShell_Base( i_pParent, WB_MOVEABLE | WB_CLOSEABLE ) + ,m_xWizard( i_rWizard ) + ,m_xController( i_rController ) + ,m_nFirstPageID( lcl_determineFirstPageID( i_rPaths ) ) + { + ENSURE_OR_THROW( m_xWizard.is() && m_xController.is(), "invalid wizard/controller" ); + + // declare the paths + for ( sal_Int32 i=0; i<i_rPaths.getLength(); ++i ) + { + const Sequence< sal_Int16 >& rPath( i_rPaths[i] ); + WizardPath aPath( rPath.getLength() ); + for ( sal_Int32 j=0; j<rPath.getLength(); ++j ) + aPath[j] = impl_pageIdToState( rPath[j] ); + declarePath( i, aPath ); + } + + // create the first page, to know the page size + TabPage* pStartPage = GetOrCreatePage( impl_pageIdToState( i_rPaths[0][0] ) ); + SetPageSizePixel( pStartPage->GetSizePixel() ); + + // some defaults + ShowButtonFixedLine( true ); + SetRoadmapInteractive( true ); + enableAutomaticNextButtonState(); + + // activate the first page + ActivatePage(); + } + + //------------------------------------------------------------------------------------------------------------------ + WizardShell::~WizardShell() + { + } + + //------------------------------------------------------------------------------------------------------------------ + sal_Int16 WizardShell::convertCommitReasonToTravelType( const CommitPageReason i_eReason ) + { + switch ( i_eReason ) + { + case WizardTypes::eTravelForward: + return WizardTravelType::FORWARD; + + case WizardTypes::eTravelBackward: + return WizardTravelType::BACKWARD; + + case WizardTypes::eFinish: + return WizardTravelType::FINISH; + } + OSL_ENSURE( false, "WizardShell::convertCommitReasonToTravelType: unsupported CommitPageReason!" ); + return WizardTravelType::FINISH; + } + + //------------------------------------------------------------------------------------------------------------------ + void WizardShell::enterState( WizardState i_nState ) + { + WizardShell_Base::enterState( i_nState ); + + if ( !m_xController.is() ) + return; + + try + { + m_xController->onActivatePage( impl_stateToPageId( i_nState ) ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + //------------------------------------------------------------------------------------------------------------------ + sal_Bool WizardShell::prepareLeaveCurrentState( CommitPageReason i_eReason ) + { + if ( !WizardShell_Base::prepareLeaveCurrentState( i_eReason ) ) + return sal_False; + + if ( !m_xController.is() ) + return sal_True; + + try + { + return m_xController->confirmDeactivatePage( + impl_stateToPageId( getCurrentState() ), + convertCommitReasonToTravelType( i_eReason ) + ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + return sal_True; + } + + //------------------------------------------------------------------------------------------------------------------ + sal_Bool WizardShell::leaveState( WizardState i_nState ) + { + if ( !WizardShell_Base::leaveState( i_nState ) ) + return sal_False; + + if ( !m_xController.is() ) + return sal_True; + + try + { + m_xController->onDeactivatePage( impl_stateToPageId( i_nState ) ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + return sal_True; + } + + //------------------------------------------------------------------------------------------------------------------ + TabPage* WizardShell::createPage( WizardState i_nState ) + { + ENSURE_OR_RETURN( m_xController.is(), "WizardShell::createPage: no WizardController!", NULL ); + return new WizardPageShell( *this, m_xController, impl_stateToPageId( i_nState ) ); + } + + //------------------------------------------------------------------------------------------------------------------ + String WizardShell::getStateDisplayName( WizardState i_nState ) const + { + try + { + if ( m_xController.is() ) + return m_xController->getPageTitle( impl_stateToPageId( i_nState ) ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return String::CreateFromInt32( i_nState ); + } + + //------------------------------------------------------------------------------------------------------------------ + bool WizardShell::canAdvance() const + { + try + { + if ( m_xController.is() && !m_xController->canAdvance() ) + return false; + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + return WizardShell_Base::canAdvance(); + } + + //------------------------------------------------------------------------------------------------------------------ + sal_Bool WizardShell::onFinish( sal_Int32 i_nResult ) + { + try + { + if ( ( i_nResult == RET_OK ) && m_xController.is() && !m_xController->confirmFinish() ) + return sal_False; + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + return WizardShell_Base::onFinish( i_nResult ); + } + +//...................................................................................................................... +} } // namespace svt::uno +//...................................................................................................................... diff --git a/svtools/source/uno/wizard/wizardshell.hxx b/svtools/source/uno/wizard/wizardshell.hxx new file mode 100644 index 000000000000..0d2ba7836ebc --- /dev/null +++ b/svtools/source/uno/wizard/wizardshell.hxx @@ -0,0 +1,115 @@ +/************************************************************************* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SVT_UNO_WIZARD_SHELL +#define SVT_UNO_WIZARD_SHELL + +/** === begin UNO includes === **/ +#include <com/sun/star/ui/dialogs/XWizardController.hpp> +#include <com/sun/star/ui/dialogs/XWizard.hpp> +/** === end UNO includes === **/ + +#include <svtools/roadmapwizard.hxx> + +//...................................................................................................................... +namespace svt { namespace uno +{ +//...................................................................................................................... + + //================================================================================================================== + //= WizardShell + //================================================================================================================== + typedef ::svt::RoadmapWizard WizardShell_Base; + class WizardShell : public WizardShell_Base + { + public: + WizardShell( + Window* _pParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizard >& i_rWizard, + const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizardController >& i_rController, + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< sal_Int16 > >& i_rPaths + ); + virtual ~WizardShell(); + + // OWizardMachine overridables + virtual TabPage* createPage( WizardState i_nState ); + virtual void enterState( WizardState i_nState ); + virtual sal_Bool prepareLeaveCurrentState( CommitPageReason _eReason ); + virtual sal_Bool leaveState( WizardState i_nState ); + virtual String getStateDisplayName( WizardState i_nState ) const; + virtual bool canAdvance() const; + virtual sal_Bool onFinish( sal_Int32 _nResult ); + + // attribute access + const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizard >& + getWizard() const { return m_xWizard; } + + static sal_Int16 convertCommitReasonToTravelType( const CommitPageReason i_eReason ); + + // operations + sal_Bool advanceTo( const sal_Int16 i_nPageId ) + { + return skipUntil( impl_pageIdToState( i_nPageId ) ); + } + sal_Bool goBackTo( const sal_Int16 i_nPageId ) + { + return skipBackwardUntil( impl_pageIdToState( i_nPageId ) ); + } + sal_Int16 getCurrentPage() const + { + return impl_stateToPageId( getCurrentState() ); + } + sal_Bool travelNext() { return WizardShell_Base::travelNext(); } + sal_Bool travelPrevious() { return WizardShell_Base::travelPrevious(); } + + private: + sal_Int16 impl_stateToPageId( const WizardTypes::WizardState i_nState ) const + { + return static_cast< sal_Int16 >( i_nState + m_nFirstPageID ); + } + + WizardState impl_pageIdToState( const sal_Int16 i_nPageId ) const + { + return static_cast< WizardState >( i_nPageId - m_nFirstPageID ); + } + + // prevent outside access to some base class members + using WizardShell_Base::skip; + using WizardShell_Base::skipUntil; + using WizardShell_Base::skipBackwardUntil; + using WizardShell_Base::getCurrentState; + + private: + const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizard > m_xWizard; + const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XWizardController > m_xController; + const sal_Int16 m_nFirstPageID; + }; + +//...................................................................................................................... +} } // namespace svt::uno +//...................................................................................................................... + +#endif // SVT_UNO_WIZARD_SHELL |