1 /************************************************************************* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * 4 * Copyright 2000, 2010 Oracle and/or its affiliates. 5 * 6 * OpenOffice.org - a multi-platform office productivity suite 7 * 8 * This file is part of OpenOffice.org. 9 * 10 * OpenOffice.org is free software: you can redistribute it and/or modify 11 * it under the terms of the GNU Lesser General Public License version 3 12 * only, as published by the Free Software Foundation. 13 * 14 * OpenOffice.org is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU Lesser General Public License version 3 for more details 18 * (a copy is included in the LICENSE file that accompanied this code). 19 * 20 * You should have received a copy of the GNU Lesser General Public License 21 * version 3 along with OpenOffice.org. If not, see 22 * <http://www.openoffice.org/license.html> 23 * for a copy of the LGPLv3 License. 24 * 25 ************************************************************************/ 26 27 #include "precompiled_sfx2.hxx" 28 29 #include "ctp_factory.hxx" 30 #include "ctp_panel.hxx" 31 32 /** === begin UNO includes === **/ 33 #include <com/sun/star/lang/NotInitializedException.hpp> 34 #include <com/sun/star/lang/IllegalArgumentException.hpp> 35 #include <com/sun/star/lang/XComponent.hpp> 36 /** === end UNO includes === **/ 37 38 //...................................................................................................................... 39 namespace sd { namespace colortoolpanel 40 { 41 //...................................................................................................................... 42 43 /** === begin UNO using === **/ 44 using ::com::sun::star::uno::Reference; 45 using ::com::sun::star::uno::XInterface; 46 using ::com::sun::star::uno::UNO_QUERY; 47 using ::com::sun::star::uno::UNO_QUERY_THROW; 48 using ::com::sun::star::uno::UNO_SET_THROW; 49 using ::com::sun::star::uno::Exception; 50 using ::com::sun::star::uno::RuntimeException; 51 using ::com::sun::star::uno::Any; 52 using ::com::sun::star::uno::makeAny; 53 using ::com::sun::star::uno::Sequence; 54 using ::com::sun::star::uno::Type; 55 using ::com::sun::star::uno::XComponentContext; 56 using ::com::sun::star::lang::NotInitializedException; 57 using ::com::sun::star::lang::IllegalArgumentException; 58 using ::com::sun::star::lang::XComponent; 59 using ::com::sun::star::ui::XUIElement; 60 using ::com::sun::star::beans::PropertyValue; 61 using ::com::sun::star::container::NoSuchElementException; 62 using ::com::sun::star::beans::PropertyValue; 63 using ::com::sun::star::awt::XWindow; 64 /** === end UNO using === **/ 65 66 //================================================================================================================== 67 //= ToolPanelFactory 68 //================================================================================================================== 69 //------------------------------------------------------------------------------------------------------------------ 70 ToolPanelFactory::ToolPanelFactory( const Reference< XComponentContext >& i_rContext ) 71 :m_xContext( i_rContext ) 72 { 73 } 74 75 //------------------------------------------------------------------------------------------------------------------ 76 ToolPanelFactory::~ToolPanelFactory() 77 { 78 } 79 80 //------------------------------------------------------------------------------------------------------------------ 81 Reference< XUIElement > SAL_CALL ToolPanelFactory::createUIElement( const ::rtl::OUString& i_rResourceURL, const Sequence< PropertyValue >& i_rArgs ) throw (NoSuchElementException, IllegalArgumentException, RuntimeException) 82 { 83 ::osl::MutexGuard aGuard( m_aMutex ); 84 85 if ( !i_rResourceURL.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "private:resource/toolpanel/org.openoffice.example.colorpanel/" ) ) ) 86 throw NoSuchElementException( i_rResourceURL, *this ); 87 88 const ::rtl::OUString sColor( i_rResourceURL.copy( i_rResourceURL.lastIndexOf( '/' ) + 1 ) ); 89 const sal_Int32 nPanelColor = sColor.toInt32( 16 ); 90 91 // retrieve the parent window 92 Reference< XWindow > xParentWindow; 93 const PropertyValue* pArg = i_rArgs.getConstArray(); 94 const PropertyValue* pArgEnd = i_rArgs.getConstArray() + i_rArgs.getLength(); 95 for ( ; pArg != pArgEnd; ++pArg ) 96 { 97 if ( pArg->Name.equalsAscii( "ParentWindow" ) ) 98 { 99 xParentWindow.set( pArg->Value, UNO_QUERY ); 100 break; 101 } 102 } 103 if ( !xParentWindow.is() ) 104 { 105 OSL_ENSURE( false, "ToolPanelFactory::createUIElement: no parent window in the args!" ); 106 throw IllegalArgumentException( 107 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No parent window provided in the creation arguments. Cannot create tool panel." ) ), 108 *this, 109 2 110 ); 111 } 112 113 /// create the panel 114 Reference< XUIElement > xUIElement( new PanelUIElement( m_xContext, xParentWindow, i_rResourceURL, nPanelColor ) ); 115 return xUIElement; 116 } 117 118 //------------------------------------------------------------------------------------------------------------------ 119 ::rtl::OUString SAL_CALL ToolPanelFactory::getImplementationName( ) throw (RuntimeException) 120 { 121 return getImplementationName_static(); 122 } 123 124 //------------------------------------------------------------------------------------------------------------------ 125 ::rtl::OUString SAL_CALL ToolPanelFactory::getImplementationName_static( ) throw (RuntimeException) 126 { 127 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.comp.example.custompanel.ToolPanelFactory" ) ); 128 } 129 130 //------------------------------------------------------------------------------------------------------------------ 131 ::sal_Bool SAL_CALL ToolPanelFactory::supportsService( const ::rtl::OUString& i_rServiceName ) throw (RuntimeException) 132 { 133 const Sequence< ::rtl::OUString > aServiceNames( getSupportedServiceNames() ); 134 for ( const ::rtl::OUString* serviceName = aServiceNames.getConstArray(); 135 serviceName != aServiceNames.getConstArray() + aServiceNames.getLength(); 136 ++serviceName 137 ) 138 { 139 if ( i_rServiceName == *serviceName ) 140 return sal_True; 141 } 142 return sal_False; 143 } 144 145 //------------------------------------------------------------------------------------------------------------------ 146 Sequence< ::rtl::OUString > SAL_CALL ToolPanelFactory::getSupportedServiceNames() throw (RuntimeException) 147 { 148 return getSupportedServiceNames_static(); 149 } 150 151 //------------------------------------------------------------------------------------------------------------------ 152 Sequence< ::rtl::OUString > SAL_CALL ToolPanelFactory::getSupportedServiceNames_static() throw (RuntimeException) 153 { 154 Sequence< ::rtl::OUString > aServiceNames(1); 155 aServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.example.colorpanel.ToolPanelFactory" ) ); 156 return aServiceNames; 157 } 158 159 //------------------------------------------------------------------------------------------------------------------ 160 Reference< XInterface > SAL_CALL ToolPanelFactory::Create( const Reference< XComponentContext >& i_rContext ) throw (RuntimeException) 161 { 162 return *( new ToolPanelFactory( i_rContext ) ); 163 } 164 165 //...................................................................................................................... 166 } } // namespace sd::colortoolpanel 167 //...................................................................................................................... 168