1760d135fSAriel Constenla-Haile /************************************************************** 2760d135fSAriel Constenla-Haile * 3760d135fSAriel Constenla-Haile * Licensed to the Apache Software Foundation (ASF) under one 4760d135fSAriel Constenla-Haile * or more contributor license agreements. See the NOTICE file 5760d135fSAriel Constenla-Haile * distributed with this work for additional information 6760d135fSAriel Constenla-Haile * regarding copyright ownership. The ASF licenses this file 7760d135fSAriel Constenla-Haile * to you under the Apache License, Version 2.0 (the 8760d135fSAriel Constenla-Haile * "License"); you may not use this file except in compliance 9760d135fSAriel Constenla-Haile * with the License. You may obtain a copy of the License at 10760d135fSAriel Constenla-Haile * 11760d135fSAriel Constenla-Haile * http://www.apache.org/licenses/LICENSE-2.0 12760d135fSAriel Constenla-Haile * 13760d135fSAriel Constenla-Haile * Unless required by applicable law or agreed to in writing, 14760d135fSAriel Constenla-Haile * software distributed under the License is distributed on an 15760d135fSAriel Constenla-Haile * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16760d135fSAriel Constenla-Haile * KIND, either express or implied. See the License for the 17760d135fSAriel Constenla-Haile * specific language governing permissions and limitations 18760d135fSAriel Constenla-Haile * under the License. 19760d135fSAriel Constenla-Haile * 20760d135fSAriel Constenla-Haile *************************************************************/ 21760d135fSAriel Constenla-Haile 22760d135fSAriel Constenla-Haile 23760d135fSAriel Constenla-Haile 24*abfe7a5aSAriel Constenla-Haile 25760d135fSAriel Constenla-Haile 26760d135fSAriel Constenla-Haile #include "ctp_factory.hxx" 27760d135fSAriel Constenla-Haile #include "ctp_panel.hxx" 28760d135fSAriel Constenla-Haile 29760d135fSAriel Constenla-Haile /** === begin UNO includes === **/ 30760d135fSAriel Constenla-Haile #include <com/sun/star/lang/NotInitializedException.hpp> 31760d135fSAriel Constenla-Haile #include <com/sun/star/lang/IllegalArgumentException.hpp> 32760d135fSAriel Constenla-Haile #include <com/sun/star/lang/XComponent.hpp> 33760d135fSAriel Constenla-Haile /** === end UNO includes === **/ 34760d135fSAriel Constenla-Haile 35760d135fSAriel Constenla-Haile //...................................................................................................................... 36760d135fSAriel Constenla-Haile namespace sd { namespace colortoolpanel 37760d135fSAriel Constenla-Haile { 38760d135fSAriel Constenla-Haile //...................................................................................................................... 39760d135fSAriel Constenla-Haile 40760d135fSAriel Constenla-Haile /** === begin UNO using === **/ 41760d135fSAriel Constenla-Haile using ::com::sun::star::uno::Reference; 42760d135fSAriel Constenla-Haile using ::com::sun::star::uno::XInterface; 43760d135fSAriel Constenla-Haile using ::com::sun::star::uno::UNO_QUERY; 44760d135fSAriel Constenla-Haile using ::com::sun::star::uno::UNO_QUERY_THROW; 45760d135fSAriel Constenla-Haile using ::com::sun::star::uno::UNO_SET_THROW; 46760d135fSAriel Constenla-Haile using ::com::sun::star::uno::Exception; 47760d135fSAriel Constenla-Haile using ::com::sun::star::uno::RuntimeException; 48760d135fSAriel Constenla-Haile using ::com::sun::star::uno::Any; 49760d135fSAriel Constenla-Haile using ::com::sun::star::uno::makeAny; 50760d135fSAriel Constenla-Haile using ::com::sun::star::uno::Sequence; 51760d135fSAriel Constenla-Haile using ::com::sun::star::uno::Type; 52760d135fSAriel Constenla-Haile using ::com::sun::star::uno::XComponentContext; 53760d135fSAriel Constenla-Haile using ::com::sun::star::lang::NotInitializedException; 54760d135fSAriel Constenla-Haile using ::com::sun::star::lang::IllegalArgumentException; 55760d135fSAriel Constenla-Haile using ::com::sun::star::lang::XComponent; 56760d135fSAriel Constenla-Haile using ::com::sun::star::ui::XUIElement; 57760d135fSAriel Constenla-Haile using ::com::sun::star::beans::PropertyValue; 58760d135fSAriel Constenla-Haile using ::com::sun::star::container::NoSuchElementException; 59760d135fSAriel Constenla-Haile using ::com::sun::star::beans::PropertyValue; 60760d135fSAriel Constenla-Haile using ::com::sun::star::awt::XWindow; 61760d135fSAriel Constenla-Haile /** === end UNO using === **/ 62760d135fSAriel Constenla-Haile 63760d135fSAriel Constenla-Haile //================================================================================================================== 64760d135fSAriel Constenla-Haile //= ToolPanelFactory 65760d135fSAriel Constenla-Haile //================================================================================================================== 66760d135fSAriel Constenla-Haile //------------------------------------------------------------------------------------------------------------------ ToolPanelFactory(const Reference<XComponentContext> & i_rContext)67760d135fSAriel Constenla-Haile ToolPanelFactory::ToolPanelFactory( const Reference< XComponentContext >& i_rContext ) 68760d135fSAriel Constenla-Haile :m_xContext( i_rContext ) 69760d135fSAriel Constenla-Haile { 70760d135fSAriel Constenla-Haile } 71760d135fSAriel Constenla-Haile 72760d135fSAriel Constenla-Haile //------------------------------------------------------------------------------------------------------------------ ~ToolPanelFactory()73760d135fSAriel Constenla-Haile ToolPanelFactory::~ToolPanelFactory() 74760d135fSAriel Constenla-Haile { 75760d135fSAriel Constenla-Haile } 76760d135fSAriel Constenla-Haile 77760d135fSAriel Constenla-Haile //------------------------------------------------------------------------------------------------------------------ createUIElement(const::rtl::OUString & i_rResourceURL,const Sequence<PropertyValue> & i_rArgs)78760d135fSAriel Constenla-Haile Reference< XUIElement > SAL_CALL ToolPanelFactory::createUIElement( const ::rtl::OUString& i_rResourceURL, const Sequence< PropertyValue >& i_rArgs ) throw (NoSuchElementException, IllegalArgumentException, RuntimeException) 79760d135fSAriel Constenla-Haile { 80760d135fSAriel Constenla-Haile ::osl::MutexGuard aGuard( m_aMutex ); 81760d135fSAriel Constenla-Haile 82760d135fSAriel Constenla-Haile if ( !i_rResourceURL.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "private:resource/toolpanel/org.openoffice.example.colorpanel/" ) ) ) 83760d135fSAriel Constenla-Haile throw NoSuchElementException( i_rResourceURL, *this ); 84760d135fSAriel Constenla-Haile 85760d135fSAriel Constenla-Haile const ::rtl::OUString sColor( i_rResourceURL.copy( i_rResourceURL.lastIndexOf( '/' ) + 1 ) ); 86760d135fSAriel Constenla-Haile const sal_Int32 nPanelColor = sColor.toInt32( 16 ); 87760d135fSAriel Constenla-Haile 88760d135fSAriel Constenla-Haile // retrieve the parent window 89760d135fSAriel Constenla-Haile Reference< XWindow > xParentWindow; 90760d135fSAriel Constenla-Haile const PropertyValue* pArg = i_rArgs.getConstArray(); 91760d135fSAriel Constenla-Haile const PropertyValue* pArgEnd = i_rArgs.getConstArray() + i_rArgs.getLength(); 92760d135fSAriel Constenla-Haile for ( ; pArg != pArgEnd; ++pArg ) 93760d135fSAriel Constenla-Haile { 94760d135fSAriel Constenla-Haile if ( pArg->Name.equalsAscii( "ParentWindow" ) ) 95760d135fSAriel Constenla-Haile { 96760d135fSAriel Constenla-Haile xParentWindow.set( pArg->Value, UNO_QUERY ); 97760d135fSAriel Constenla-Haile break; 98760d135fSAriel Constenla-Haile } 99760d135fSAriel Constenla-Haile } 100760d135fSAriel Constenla-Haile if ( !xParentWindow.is() ) 101760d135fSAriel Constenla-Haile { 102760d135fSAriel Constenla-Haile OSL_ENSURE( false, "ToolPanelFactory::createUIElement: no parent window in the args!" ); 103760d135fSAriel Constenla-Haile throw IllegalArgumentException( 104760d135fSAriel Constenla-Haile ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No parent window provided in the creation arguments. Cannot create tool panel." ) ), 105760d135fSAriel Constenla-Haile *this, 106760d135fSAriel Constenla-Haile 2 107760d135fSAriel Constenla-Haile ); 108760d135fSAriel Constenla-Haile } 109760d135fSAriel Constenla-Haile 110760d135fSAriel Constenla-Haile /// create the panel 111760d135fSAriel Constenla-Haile Reference< XUIElement > xUIElement( new PanelUIElement( m_xContext, xParentWindow, i_rResourceURL, nPanelColor ) ); 112760d135fSAriel Constenla-Haile return xUIElement; 113760d135fSAriel Constenla-Haile } 114760d135fSAriel Constenla-Haile 115760d135fSAriel Constenla-Haile //------------------------------------------------------------------------------------------------------------------ getImplementationName()116760d135fSAriel Constenla-Haile ::rtl::OUString SAL_CALL ToolPanelFactory::getImplementationName( ) throw (RuntimeException) 117760d135fSAriel Constenla-Haile { 118760d135fSAriel Constenla-Haile return getImplementationName_static(); 119760d135fSAriel Constenla-Haile } 120760d135fSAriel Constenla-Haile 121760d135fSAriel Constenla-Haile //------------------------------------------------------------------------------------------------------------------ getImplementationName_static()122760d135fSAriel Constenla-Haile ::rtl::OUString SAL_CALL ToolPanelFactory::getImplementationName_static( ) throw (RuntimeException) 123760d135fSAriel Constenla-Haile { 124760d135fSAriel Constenla-Haile return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.comp.example.custompanel.ToolPanelFactory" ) ); 125760d135fSAriel Constenla-Haile } 126760d135fSAriel Constenla-Haile 127760d135fSAriel Constenla-Haile //------------------------------------------------------------------------------------------------------------------ supportsService(const::rtl::OUString & i_rServiceName)128760d135fSAriel Constenla-Haile ::sal_Bool SAL_CALL ToolPanelFactory::supportsService( const ::rtl::OUString& i_rServiceName ) throw (RuntimeException) 129760d135fSAriel Constenla-Haile { 130760d135fSAriel Constenla-Haile const Sequence< ::rtl::OUString > aServiceNames( getSupportedServiceNames() ); 131760d135fSAriel Constenla-Haile for ( const ::rtl::OUString* serviceName = aServiceNames.getConstArray(); 132760d135fSAriel Constenla-Haile serviceName != aServiceNames.getConstArray() + aServiceNames.getLength(); 133760d135fSAriel Constenla-Haile ++serviceName 134760d135fSAriel Constenla-Haile ) 135760d135fSAriel Constenla-Haile { 136760d135fSAriel Constenla-Haile if ( i_rServiceName == *serviceName ) 137760d135fSAriel Constenla-Haile return sal_True; 138760d135fSAriel Constenla-Haile } 139760d135fSAriel Constenla-Haile return sal_False; 140760d135fSAriel Constenla-Haile } 141760d135fSAriel Constenla-Haile 142760d135fSAriel Constenla-Haile //------------------------------------------------------------------------------------------------------------------ getSupportedServiceNames()143760d135fSAriel Constenla-Haile Sequence< ::rtl::OUString > SAL_CALL ToolPanelFactory::getSupportedServiceNames() throw (RuntimeException) 144760d135fSAriel Constenla-Haile { 145760d135fSAriel Constenla-Haile return getSupportedServiceNames_static(); 146760d135fSAriel Constenla-Haile } 147760d135fSAriel Constenla-Haile 148760d135fSAriel Constenla-Haile //------------------------------------------------------------------------------------------------------------------ getSupportedServiceNames_static()149760d135fSAriel Constenla-Haile Sequence< ::rtl::OUString > SAL_CALL ToolPanelFactory::getSupportedServiceNames_static() throw (RuntimeException) 150760d135fSAriel Constenla-Haile { 151760d135fSAriel Constenla-Haile Sequence< ::rtl::OUString > aServiceNames(1); 152760d135fSAriel Constenla-Haile aServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.example.colorpanel.ToolPanelFactory" ) ); 153760d135fSAriel Constenla-Haile return aServiceNames; 154760d135fSAriel Constenla-Haile } 155760d135fSAriel Constenla-Haile 156760d135fSAriel Constenla-Haile //------------------------------------------------------------------------------------------------------------------ Create(const Reference<XComponentContext> & i_rContext)157760d135fSAriel Constenla-Haile Reference< XInterface > SAL_CALL ToolPanelFactory::Create( const Reference< XComponentContext >& i_rContext ) throw (RuntimeException) 158760d135fSAriel Constenla-Haile { 159760d135fSAriel Constenla-Haile return *( new ToolPanelFactory( i_rContext ) ); 160760d135fSAriel Constenla-Haile } 161760d135fSAriel Constenla-Haile 162760d135fSAriel Constenla-Haile //...................................................................................................................... 163760d135fSAriel Constenla-Haile } } // namespace sd::colortoolpanel 164760d135fSAriel Constenla-Haile //...................................................................................................................... 165