1d119d52dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3d119d52dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4d119d52dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5d119d52dSAndrew Rist * distributed with this work for additional information 6d119d52dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7d119d52dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8d119d52dSAndrew Rist * "License"); you may not use this file except in compliance 9d119d52dSAndrew Rist * with the License. You may obtain a copy of the License at 10d119d52dSAndrew Rist * 11d119d52dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12d119d52dSAndrew Rist * 13d119d52dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14d119d52dSAndrew Rist * software distributed under the License is distributed on an 15d119d52dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16d119d52dSAndrew Rist * KIND, either express or implied. See the License for the 17d119d52dSAndrew Rist * specific language governing permissions and limitations 18d119d52dSAndrew Rist * under the License. 19d119d52dSAndrew Rist * 20d119d52dSAndrew Rist *************************************************************/ 21d119d52dSAndrew Rist 22d119d52dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir 25cdf0e10cSrcweir #include "ctp_panel.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir /** === begin UNO includes === **/ 28cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 29cdf0e10cSrcweir #include <com/sun/star/awt/XWindowPeer.hpp> 30cdf0e10cSrcweir #include <com/sun/star/awt/XToolkit.hpp> 31cdf0e10cSrcweir #include <com/sun/star/awt/WindowClass.hpp> 32cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp> 33cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp> 34cdf0e10cSrcweir #include <com/sun/star/awt/XDevice.hpp> 35cdf0e10cSrcweir #include <com/sun/star/awt/XGraphics.hpp> 36cdf0e10cSrcweir #include <com/sun/star/ui/UIElementType.hpp> 37cdf0e10cSrcweir /** === end UNO includes === **/ 38cdf0e10cSrcweir 39*abfe7a5aSAriel Constenla-Haile #include <osl/diagnose.h> 40cdf0e10cSrcweir 41cdf0e10cSrcweir //...................................................................................................................... 42cdf0e10cSrcweir namespace sd { namespace colortoolpanel 43cdf0e10cSrcweir { 44cdf0e10cSrcweir //...................................................................................................................... 45cdf0e10cSrcweir 46cdf0e10cSrcweir /** === begin UNO using === **/ 47cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 48cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 49cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 50cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 51cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW; 52cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 53cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 54cdf0e10cSrcweir using ::com::sun::star::uno::Any; 55cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 56cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 57cdf0e10cSrcweir using ::com::sun::star::uno::Type; 58cdf0e10cSrcweir using ::com::sun::star::uno::XComponentContext; 59cdf0e10cSrcweir using ::com::sun::star::awt::XWindow; 60cdf0e10cSrcweir using ::com::sun::star::lang::DisposedException; 61cdf0e10cSrcweir using ::com::sun::star::awt::XWindowPeer; 62cdf0e10cSrcweir using ::com::sun::star::lang::XMultiComponentFactory; 63cdf0e10cSrcweir using ::com::sun::star::awt::XToolkit; 64cdf0e10cSrcweir using ::com::sun::star::awt::WindowDescriptor; 65cdf0e10cSrcweir using ::com::sun::star::awt::WindowClass_SIMPLE; 66cdf0e10cSrcweir using ::com::sun::star::awt::Rectangle; 67cdf0e10cSrcweir using ::com::sun::star::awt::PaintEvent; 68cdf0e10cSrcweir using ::com::sun::star::lang::EventObject; 69cdf0e10cSrcweir using ::com::sun::star::awt::XDevice; 70cdf0e10cSrcweir using ::com::sun::star::awt::XGraphics; 71cdf0e10cSrcweir using ::com::sun::star::accessibility::XAccessible; 72cdf0e10cSrcweir using ::com::sun::star::frame::XFrame; 73cdf0e10cSrcweir /** === end UNO using === **/ 74cdf0e10cSrcweir namespace WindowAttribute = ::com::sun::star::awt::WindowAttribute; 75cdf0e10cSrcweir namespace PosSize = ::com::sun::star::awt::PosSize; 76cdf0e10cSrcweir namespace UIElementType = ::com::sun::star::ui::UIElementType; 77cdf0e10cSrcweir 78cdf0e10cSrcweir //================================================================================================================== 79cdf0e10cSrcweir //= helpers 80cdf0e10cSrcweir //================================================================================================================== 81cdf0e10cSrcweir namespace 82cdf0e10cSrcweir { lcl_createPlainWindow_nothrow(const Reference<XComponentContext> & i_rContext,const Reference<XWindowPeer> & i_rParentWindow)83cdf0e10cSrcweir Reference< XWindow > lcl_createPlainWindow_nothrow( const Reference< XComponentContext >& i_rContext, 84cdf0e10cSrcweir const Reference< XWindowPeer >& i_rParentWindow ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir try 87cdf0e10cSrcweir { 88*abfe7a5aSAriel Constenla-Haile OSL_ENSURE( i_rContext.is(), "illegal component context" ); 89cdf0e10cSrcweir Reference< XMultiComponentFactory > xFactory( i_rContext->getServiceManager(), UNO_SET_THROW ); 90cdf0e10cSrcweir Reference< XToolkit > xToolkit( xFactory->createInstanceWithContext( 91cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ) ), 92cdf0e10cSrcweir i_rContext 93cdf0e10cSrcweir ), UNO_QUERY_THROW ); 94cdf0e10cSrcweir 95cdf0e10cSrcweir WindowDescriptor aWindow; 96cdf0e10cSrcweir aWindow.Type = WindowClass_SIMPLE; 97cdf0e10cSrcweir aWindow.WindowServiceName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "window" ) ); 98cdf0e10cSrcweir aWindow.Parent = i_rParentWindow; 99cdf0e10cSrcweir aWindow.WindowAttributes = WindowAttribute::BORDER; 100cdf0e10cSrcweir 101cdf0e10cSrcweir Reference< XWindowPeer > xWindow( xToolkit->createWindow( aWindow ), UNO_SET_THROW ); 102cdf0e10cSrcweir return Reference< XWindow >( xWindow, UNO_QUERY_THROW ); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir catch( const Exception& ) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir } 107cdf0e10cSrcweir return NULL; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir } 110cdf0e10cSrcweir //================================================================================================================== 111cdf0e10cSrcweir //= class SingleColorPanel 112cdf0e10cSrcweir //================================================================================================================== 113cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ SingleColorPanel(const Reference<XComponentContext> & i_rContext,const Reference<XWindow> & i_rParentWindow,const::sal_Int32 i_nPanelColor)114cdf0e10cSrcweir SingleColorPanel::SingleColorPanel( const Reference< XComponentContext >& i_rContext, const Reference< XWindow >& i_rParentWindow, const ::sal_Int32 i_nPanelColor ) 115cdf0e10cSrcweir :SingleColorPanel_Base( m_aMutex ) 116cdf0e10cSrcweir ,m_xWindow() 117cdf0e10cSrcweir ,m_nPanelColor( i_nPanelColor ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir // retrieve the parent window for our to-be-created pane window 120cdf0e10cSrcweir Reference< XWindowPeer > xParentPeer( i_rParentWindow, UNO_QUERY ); 121cdf0e10cSrcweir 122cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 123cdf0e10cSrcweir if ( xParentPeer.is() ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir m_xWindow = lcl_createPlainWindow_nothrow( i_rContext, xParentPeer ); 126cdf0e10cSrcweir m_xWindow->addPaintListener( this ); 127cdf0e10cSrcweir if ( m_xWindow.is() ) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir const Rectangle aPanelAnchorSize( i_rParentWindow->getPosSize() ); 130cdf0e10cSrcweir m_xWindow->setPosSize( 0, 0, aPanelAnchorSize.Width, aPanelAnchorSize.Height, PosSize::POSSIZE ); 131cdf0e10cSrcweir m_xWindow->setVisible( sal_True ); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir } 134cdf0e10cSrcweir osl_decrementInterlockedCount( &m_refCount ); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ ~SingleColorPanel()138cdf0e10cSrcweir SingleColorPanel::~SingleColorPanel() 139cdf0e10cSrcweir { 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ getWindow()143cdf0e10cSrcweir Reference< XWindow > SAL_CALL SingleColorPanel::getWindow() throw (RuntimeException) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 146cdf0e10cSrcweir if ( !m_xWindow.is() ) 147cdf0e10cSrcweir throw DisposedException( ::rtl::OUString(), *this ); 148cdf0e10cSrcweir return m_xWindow; 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ createAccessible(const Reference<XAccessible> & i_rParentAccessible)152cdf0e10cSrcweir Reference< XAccessible > SAL_CALL SingleColorPanel::createAccessible( const Reference< XAccessible >& i_rParentAccessible ) throw (RuntimeException) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 155cdf0e10cSrcweir if ( !m_xWindow.is() ) 156cdf0e10cSrcweir throw DisposedException( ::rtl::OUString(), *this ); 157cdf0e10cSrcweir 158cdf0e10cSrcweir // TODO: the following is wrong, since it doesn't respect i_rParentAccessible. In a real extension, you should 159cdf0e10cSrcweir // implement this correctly :) 160cdf0e10cSrcweir (void)i_rParentAccessible; 161cdf0e10cSrcweir return Reference< XAccessible >( getWindow(), UNO_QUERY ); 162cdf0e10cSrcweir } 163cdf0e10cSrcweir 164cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ windowPaint(const PaintEvent & i_rEvent)165cdf0e10cSrcweir void SAL_CALL SingleColorPanel::windowPaint( const PaintEvent& i_rEvent ) throw (RuntimeException) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir try 168cdf0e10cSrcweir { 169cdf0e10cSrcweir const Reference< XDevice > xDevice( i_rEvent.Source, UNO_QUERY_THROW ); 170cdf0e10cSrcweir const Reference< XGraphics > xGraphics( xDevice->createGraphics(), UNO_SET_THROW ); 171cdf0e10cSrcweir xGraphics->setFillColor( m_nPanelColor ); 172cdf0e10cSrcweir xGraphics->setLineColor( 0x00FFFFFF ); 173cdf0e10cSrcweir 174cdf0e10cSrcweir const Reference< XWindow > xWindow( i_rEvent.Source, UNO_QUERY_THROW ); 175cdf0e10cSrcweir const Rectangle aWindowRect( xWindow->getPosSize() ); 176cdf0e10cSrcweir xGraphics->drawRect( 0, 0, aWindowRect.Width - 1, aWindowRect.Height - 1 ); 177cdf0e10cSrcweir } 178cdf0e10cSrcweir catch( const Exception& ) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir } 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ disposing(const EventObject & i_rSource)184cdf0e10cSrcweir void SAL_CALL SingleColorPanel::disposing( const EventObject& i_rSource ) throw (RuntimeException) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir (void)i_rSource; 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ disposing()190cdf0e10cSrcweir void SAL_CALL SingleColorPanel::disposing() 191cdf0e10cSrcweir { 192cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 193cdf0e10cSrcweir if ( !m_xWindow.is() ) 194cdf0e10cSrcweir // already disposed 195cdf0e10cSrcweir return; 196cdf0e10cSrcweir m_xWindow->removePaintListener( this ); 197cdf0e10cSrcweir try 198cdf0e10cSrcweir { 199cdf0e10cSrcweir Reference< XComponent > xWindowComp( m_xWindow, UNO_QUERY_THROW ); 200cdf0e10cSrcweir xWindowComp->dispose(); 201cdf0e10cSrcweir } 202cdf0e10cSrcweir catch( const Exception& ) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir } 205cdf0e10cSrcweir m_xWindow.clear(); 206cdf0e10cSrcweir } 207cdf0e10cSrcweir 208cdf0e10cSrcweir //================================================================================================================== 209cdf0e10cSrcweir //= PanelUIElement 210cdf0e10cSrcweir //================================================================================================================== 211cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ PanelUIElement(const Reference<XComponentContext> & i_rContext,const Reference<XWindow> & i_rParentWindow,const::rtl::OUString & i_rResourceURL,const::sal_Int32 i_nPanelColor)212cdf0e10cSrcweir PanelUIElement::PanelUIElement( const Reference< XComponentContext >& i_rContext, const Reference< XWindow >& i_rParentWindow, 213cdf0e10cSrcweir const ::rtl::OUString& i_rResourceURL, const ::sal_Int32 i_nPanelColor ) 214cdf0e10cSrcweir :PanelUIElement_Base( m_aMutex ) 215cdf0e10cSrcweir ,m_sResourceURL( i_rResourceURL ) 216cdf0e10cSrcweir ,m_xToolPanel( new SingleColorPanel( i_rContext, i_rParentWindow, i_nPanelColor ) ) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir } 219cdf0e10cSrcweir 220cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ ~PanelUIElement()221cdf0e10cSrcweir PanelUIElement::~PanelUIElement() 222cdf0e10cSrcweir { 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ getFrame()226cdf0e10cSrcweir Reference< XFrame > SAL_CALL PanelUIElement::getFrame() throw (RuntimeException) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir // TODO 229cdf0e10cSrcweir return NULL; 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ getResourceURL()233cdf0e10cSrcweir ::rtl::OUString SAL_CALL PanelUIElement::getResourceURL() throw (RuntimeException) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir return m_sResourceURL; 236cdf0e10cSrcweir } 237cdf0e10cSrcweir 238cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ getType()239cdf0e10cSrcweir ::sal_Int16 SAL_CALL PanelUIElement::getType() throw (RuntimeException) 240cdf0e10cSrcweir { 241cdf0e10cSrcweir return UIElementType::TOOLPANEL; 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ getRealInterface()245cdf0e10cSrcweir Reference< XInterface > SAL_CALL PanelUIElement::getRealInterface( ) throw (RuntimeException) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 248cdf0e10cSrcweir if ( !m_xToolPanel.is() ) 249cdf0e10cSrcweir throw DisposedException(); 250cdf0e10cSrcweir return m_xToolPanel; 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ disposing()254cdf0e10cSrcweir void SAL_CALL PanelUIElement::disposing() 255cdf0e10cSrcweir { 256cdf0e10cSrcweir Reference< XComponent > xPanelComponent( m_xToolPanel, UNO_QUERY_THROW ); 257cdf0e10cSrcweir m_xToolPanel.clear(); 258cdf0e10cSrcweir xPanelComponent->dispose(); 259cdf0e10cSrcweir } 260cdf0e10cSrcweir 261cdf0e10cSrcweir //...................................................................................................................... 262cdf0e10cSrcweir } } // namespace sd::colortoolpanel 263cdf0e10cSrcweir //...................................................................................................................... 264