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