diff options
author | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-03-22 12:09:10 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-03-22 12:09:10 +0100 |
commit | 35ce77a82b374828ef7b85bca8029672dced337f (patch) | |
tree | 78f180478c51f9c7a18d6e9d22f1473192ce6047 /sd/workben | |
parent | 0dec5536c50fb545cf26701c6ecf158d3f9ab38a (diff) |
slidecopy: allow custom tool panels in the task pane to be implemented as extensions
Diffstat (limited to 'sd/workben')
-rw-r--r-- | sd/workben/custompanel/Impress.xcu | 4 | ||||
-rw-r--r-- | sd/workben/custompanel/ctp_factory.cxx | 14 | ||||
-rw-r--r-- | sd/workben/custompanel/ctp_panel.cxx | 161 | ||||
-rw-r--r-- | sd/workben/custompanel/ctp_panel.hxx | 25 | ||||
-rw-r--r-- | sd/workben/custompanel/makefile.mk | 7 |
5 files changed, 194 insertions, 17 deletions
diff --git a/sd/workben/custompanel/Impress.xcu b/sd/workben/custompanel/Impress.xcu index 1c7bb5f6b102..6f8ced4924f3 100644 --- a/sd/workben/custompanel/Impress.xcu +++ b/sd/workben/custompanel/Impress.xcu @@ -6,7 +6,7 @@ <node oor:name="CustomPanels"> <node oor:name="org.openoffice.example.colorpanel.SingleColorPanel" oor:op="replace"> <prop oor:name="ResourceURL" oor:type="xs:string"> - <value>private:resource/view/SingleColorView</value> + <value>private:resource/toolpanel/SingleColorView</value> </prop> <prop oor:name="DisplayTitle" oor:type="xs:string"> <value>Single Color Panel</value> @@ -23,7 +23,7 @@ <node oor:name="ResourceList"> <node oor:name="SingleColorView" oor:op="replace"> <prop oor:name="URL"> - <value>private:resource/view/SingleColorView</value> + <value>private:resource/toolpanel/SingleColorView</value> </prop> </node> </node> diff --git a/sd/workben/custompanel/ctp_factory.cxx b/sd/workben/custompanel/ctp_factory.cxx index caa19170ca59..f63e487fdc3e 100644 --- a/sd/workben/custompanel/ctp_factory.cxx +++ b/sd/workben/custompanel/ctp_factory.cxx @@ -33,6 +33,7 @@ #include <com/sun/star/lang/NotInitializedException.hpp> #include <com/sun/star/lang/IllegalArgumentException.hpp> #include <com/sun/star/drawing/framework/XResourceFactoryManager.hpp> +#include <com/sun/star/lang/XComponent.hpp> /** === end UNO includes === **/ //...................................................................................................................... @@ -59,6 +60,7 @@ namespace sd { namespace colortoolpanel using ::com::sun::star::lang::IllegalArgumentException; using ::com::sun::star::drawing::framework::XResourceFactoryManager; using ::com::sun::star::lang::WrappedTargetException; + using ::com::sun::star::lang::XComponent; /** === end UNO using === **/ //================================================================================================================== @@ -68,7 +70,7 @@ namespace sd { namespace colortoolpanel { const ::rtl::OUString& lcl_getSingleColorViewURL() { - static ::rtl::OUString s_sSingleColorViewURL( RTL_CONSTASCII_USTRINGPARAM( "private:resource/view/SingleColorView" ) ); + static ::rtl::OUString s_sSingleColorViewURL( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolpanel/SingleColorView" ) ); return s_sSingleColorViewURL; } } @@ -105,8 +107,14 @@ namespace sd { namespace colortoolpanel void SAL_CALL ResourceFactory::releaseResource( const Reference< XResource >& i_rResource ) throw (RuntimeException) { FactoryGuard aGuard( *this ); - // TODO: place your code here - (void)i_rResource; + + // here, we could decide to actually not destroy the resource, but cache it. In this case, we would need + // to re-parent the VCL window to another, temporary window, or *at least* hide it. + + // However, for the simplicity of this example, we will simply dispose the component here, which will destroy + // all associated resources, including the VCL window. + Reference< XComponent > xComponent( i_rResource, UNO_QUERY_THROW ); + xComponent->dispose(); } //------------------------------------------------------------------------------------------------------------------ diff --git a/sd/workben/custompanel/ctp_panel.cxx b/sd/workben/custompanel/ctp_panel.cxx index dbbbb8c6f273..7fb8ed8aeabe 100644 --- a/sd/workben/custompanel/ctp_panel.cxx +++ b/sd/workben/custompanel/ctp_panel.cxx @@ -29,8 +29,19 @@ #include "ctp_panel.hxx" /** === begin UNO includes === **/ +#include <com/sun/star/drawing/framework/XPane.hpp> +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/awt/XWindowPeer.hpp> +#include <com/sun/star/awt/XToolkit.hpp> +#include <com/sun/star/awt/WindowClass.hpp> +#include <com/sun/star/awt/WindowAttribute.hpp> +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/awt/XDevice.hpp> +#include <com/sun/star/awt/XGraphics.hpp> /** === end UNO includes === **/ +#include <tools/diagnose_ex.h> + //...................................................................................................................... namespace sd { namespace colortoolpanel { @@ -51,20 +62,98 @@ namespace sd { namespace colortoolpanel using ::com::sun::star::drawing::framework::XConfigurationController; using ::com::sun::star::drawing::framework::XResourceId; using ::com::sun::star::uno::XComponentContext; + using ::com::sun::star::drawing::framework::XPane; + using ::com::sun::star::awt::XWindow; + using ::com::sun::star::rendering::XCanvas; + using ::com::sun::star::lang::DisposedException; + using ::com::sun::star::awt::XWindowPeer; + using ::com::sun::star::lang::XMultiComponentFactory; + using ::com::sun::star::awt::XToolkit; + using ::com::sun::star::awt::WindowDescriptor; + using ::com::sun::star::awt::WindowClass_SIMPLE; + using ::com::sun::star::awt::Rectangle; + using ::com::sun::star::awt::PaintEvent; + using ::com::sun::star::lang::EventObject; + using ::com::sun::star::awt::XDevice; + using ::com::sun::star::awt::XGraphics; /** === end UNO using === **/ + namespace WindowAttribute = ::com::sun::star::awt::WindowAttribute; + namespace PosSize = ::com::sun::star::awt::PosSize; //================================================================================================================== + //= helpers + //================================================================================================================== + namespace + { + Reference< XWindow > lcl_createPlainWindow_nothrow( const Reference< XComponentContext >& i_rContext, + const Reference< XWindowPeer >& i_rParentWindow ) + { + try + { + ENSURE_OR_THROW( i_rContext.is(), "illegal component context" ); + Reference< XMultiComponentFactory > xFactory( i_rContext->getServiceManager(), UNO_SET_THROW ); + Reference< XToolkit > xToolkit( xFactory->createInstanceWithContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ) ), + i_rContext + ), UNO_QUERY_THROW ); + + WindowDescriptor aWindow; + aWindow.Type = WindowClass_SIMPLE; + aWindow.WindowServiceName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "window" ) ); + aWindow.Parent = i_rParentWindow; + aWindow.WindowAttributes = WindowAttribute::BORDER; + + Reference< XWindowPeer > xWindow( xToolkit->createWindow( aWindow ), UNO_SET_THROW ); + return Reference< XWindow >( xWindow, UNO_QUERY_THROW ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return NULL; + } + } + //================================================================================================================== //= class SingleColorPanel //================================================================================================================== //------------------------------------------------------------------------------------------------------------------ SingleColorPanel::SingleColorPanel( const Reference< XComponentContext >& i_rContext, const Reference< XConfigurationController >& i_rConfigController, const Reference< XResourceId >& i_rResourceId ) - :m_xContext( i_rContext ) + :SingleColorPanel_Base( m_aMutex ) + ,m_xContext( i_rContext ) ,m_xResourceId( i_rResourceId ) + ,m_xWindow() { - // TODO: retrieve the resource object for the anchor, ask it for its XPane interface, retrieve the window - // associated with it, create our own window as child of the pane's window - (void)i_rConfigController; + ENSURE_OR_THROW( i_rConfigController.is(), "invalid configuration controller" ); + ENSURE_OR_THROW( m_xResourceId.is(), "invalid resource id" ); + + // retrieve the parent window for our to-be-created pane window + Reference< XWindow > xParentWindow; + Reference< XWindowPeer > xParentPeer; + try + { + Reference< XResource > xAnchor( i_rConfigController->getResource( m_xResourceId->getAnchor() ), UNO_SET_THROW ); + Reference< XPane > xAnchorPane( xAnchor, UNO_QUERY_THROW ); + xParentWindow.set( xAnchorPane->getWindow(), UNO_SET_THROW ); + xParentPeer.set( xParentWindow, UNO_QUERY_THROW ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + osl_incrementInterlockedCount( &m_refCount ); + if ( xParentWindow.is() ) + { + m_xWindow = lcl_createPlainWindow_nothrow( m_xContext, xParentPeer ); + m_xWindow->addPaintListener( this ); + if ( m_xWindow.is() ) + { + const Rectangle aPanelAnchorSize( xParentWindow->getPosSize() ); + m_xWindow->setPosSize( 0, 0, aPanelAnchorSize.Width, aPanelAnchorSize.Height, PosSize::POSSIZE ); + m_xWindow->setVisible( sal_True ); + } + } + osl_decrementInterlockedCount( &m_refCount ); } //------------------------------------------------------------------------------------------------------------------ @@ -72,18 +161,78 @@ namespace sd { namespace colortoolpanel { } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ + Reference< XWindow > SAL_CALL SingleColorPanel::getWindow( ) throw (RuntimeException) + { + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_xWindow.get() ) + throw DisposedException( ::rtl::OUString(), *this ); + return m_xWindow; + } + + //------------------------------------------------------------------------------------------------------------------ Reference< XResourceId > SAL_CALL SingleColorPanel::getResourceId( ) throw (RuntimeException) { + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_xWindow.is() ) + throw DisposedException( ::rtl::OUString(), *this ); return m_xResourceId; } - //-------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------ ::sal_Bool SAL_CALL SingleColorPanel::isAnchorOnly( ) throw (RuntimeException) { + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_xWindow.is() ) + throw DisposedException( ::rtl::OUString(), *this ); return sal_False; } + //------------------------------------------------------------------------------------------------------------------ + void SAL_CALL SingleColorPanel::windowPaint( const PaintEvent& i_rEvent ) throw (RuntimeException) + { + try + { + const Reference< XDevice > xDevice( i_rEvent.Source, UNO_QUERY_THROW ); + const Reference< XGraphics > xGraphics( xDevice->createGraphics(), UNO_SET_THROW ); + xGraphics->setFillColor( 0x80 << 8 ); + xGraphics->setLineColor( 0x80 << 16 ); + + const Reference< XWindow > xWindow( i_rEvent.Source, UNO_QUERY_THROW ); + const Rectangle aWindowRect( xWindow->getPosSize() ); + xGraphics->drawRect( 0, 0, aWindowRect.Width - 1, aWindowRect.Height - 1 ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + //------------------------------------------------------------------------------------------------------------------ + void SAL_CALL SingleColorPanel::disposing( const EventObject& i_rSource ) throw (RuntimeException) + { + (void)i_rSource; + } + + //------------------------------------------------------------------------------------------------------------------ + void SAL_CALL SingleColorPanel::disposing() + { + ::osl::MutexGuard aGuard( m_aMutex ); + if ( !m_xWindow.is() ) + // already disposed + return; + m_xWindow->removePaintListener( this ); + try + { + Reference< XComponent > xWindowComp( m_xWindow, UNO_QUERY_THROW ); + xWindowComp->dispose(); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + m_xWindow.clear(); + } //...................................................................................................................... } } // namespace sd::colortoolpanel diff --git a/sd/workben/custompanel/ctp_panel.hxx b/sd/workben/custompanel/ctp_panel.hxx index c7ecb7c19795..f991cc80516c 100644 --- a/sd/workben/custompanel/ctp_panel.hxx +++ b/sd/workben/custompanel/ctp_panel.hxx @@ -29,14 +29,18 @@ /** === begin UNO includes === **/ #include <com/sun/star/drawing/framework/XView.hpp> +#include <com/sun/star/view/XToolPanel.hpp> #include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/drawing/framework/XConfigurationController.hpp> #include <com/sun/star/drawing/framework/XResourceId.hpp> +#include <com/sun/star/awt/XPaintListener.hpp> /** === end UNO includes === **/ -#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/compbase3.hxx> #include <cppuhelper/basemutex.hxx> +#include <boost/scoped_ptr.hpp> + //...................................................................................................................... namespace sd { namespace colortoolpanel { @@ -45,8 +49,10 @@ namespace sd { namespace colortoolpanel //================================================================================================================== //= class SingleColorPanel //================================================================================================================== - typedef ::cppu::WeakImplHelper1 < ::com::sun::star::drawing::framework::XView - > SingleColorPanel_Base; + typedef ::cppu::WeakComponentImplHelper3 < ::com::sun::star::drawing::framework::XView + , ::com::sun::star::view::XToolPanel + , ::com::sun::star::awt::XPaintListener + > SingleColorPanel_Base; class SingleColorPanel :public ::cppu::BaseMutex ,public SingleColorPanel_Base { @@ -57,6 +63,9 @@ namespace sd { namespace colortoolpanel const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::framework::XResourceId >& i_rResourceId ); + // XToolPanel + virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL getWindow( ) throw (::com::sun::star::uno::RuntimeException); + // XView // (no methods) @@ -64,12 +73,22 @@ namespace sd { namespace colortoolpanel virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::framework::XResourceId > SAL_CALL getResourceId( ) throw (::com::sun::star::uno::RuntimeException); virtual ::sal_Bool SAL_CALL isAnchorOnly( ) throw (::com::sun::star::uno::RuntimeException); + // XPaintListener + virtual void SAL_CALL windowPaint( const ::com::sun::star::awt::PaintEvent& e ) throw (::com::sun::star::uno::RuntimeException); + + // XEventListener + virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); + + // XComponent equivalents + virtual void SAL_CALL disposing(); + protected: ~SingleColorPanel(); private: ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; ::com::sun::star::uno::Reference< ::com::sun::star::drawing::framework::XResourceId > m_xResourceId; + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > m_xWindow; }; //...................................................................................................................... diff --git a/sd/workben/custompanel/makefile.mk b/sd/workben/custompanel/makefile.mk index 7703b7163fa3..6c20c5a4df15 100644 --- a/sd/workben/custompanel/makefile.mk +++ b/sd/workben/custompanel/makefile.mk @@ -62,9 +62,10 @@ LIB1OBJFILES= \ $(SLO)/ctp_panel.obj SHL1STDLIBS= \ - $(CPPULIB) \ - $(SALLIB) \ - $(SALHELPERLIB) \ + $(TOOLSLIB) \ + $(CPPULIB) \ + $(SALLIB) \ + $(SALHELPERLIB) \ $(CPPUHELPERLIB) SHL1VERSIONMAP=$(TARGET).map |