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 
24*abfe7a5aSAriel Constenla-Haile 
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "ctp_factory.hxx"
27cdf0e10cSrcweir #include "ctp_panel.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir /** === begin UNO includes === **/
30cdf0e10cSrcweir #include <com/sun/star/lang/NotInitializedException.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
32cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
33cdf0e10cSrcweir /** === end UNO includes === **/
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //......................................................................................................................
36cdf0e10cSrcweir namespace sd { namespace colortoolpanel
37cdf0e10cSrcweir {
38cdf0e10cSrcweir //......................................................................................................................
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 	/** === begin UNO using === **/
41cdf0e10cSrcweir 	using ::com::sun::star::uno::Reference;
42cdf0e10cSrcweir 	using ::com::sun::star::uno::XInterface;
43cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY;
44cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY_THROW;
45cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_SET_THROW;
46cdf0e10cSrcweir 	using ::com::sun::star::uno::Exception;
47cdf0e10cSrcweir 	using ::com::sun::star::uno::RuntimeException;
48cdf0e10cSrcweir 	using ::com::sun::star::uno::Any;
49cdf0e10cSrcweir 	using ::com::sun::star::uno::makeAny;
50cdf0e10cSrcweir 	using ::com::sun::star::uno::Sequence;
51cdf0e10cSrcweir 	using ::com::sun::star::uno::Type;
52cdf0e10cSrcweir     using ::com::sun::star::uno::XComponentContext;
53cdf0e10cSrcweir     using ::com::sun::star::lang::NotInitializedException;
54cdf0e10cSrcweir     using ::com::sun::star::lang::IllegalArgumentException;
55cdf0e10cSrcweir     using ::com::sun::star::lang::XComponent;
56cdf0e10cSrcweir     using ::com::sun::star::ui::XUIElement;
57cdf0e10cSrcweir     using ::com::sun::star::beans::PropertyValue;
58cdf0e10cSrcweir     using ::com::sun::star::container::NoSuchElementException;
59cdf0e10cSrcweir     using ::com::sun::star::beans::PropertyValue;
60cdf0e10cSrcweir     using ::com::sun::star::awt::XWindow;
61cdf0e10cSrcweir 	/** === end UNO using === **/
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	//==================================================================================================================
64cdf0e10cSrcweir 	//= ToolPanelFactory
65cdf0e10cSrcweir 	//==================================================================================================================
66cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
ToolPanelFactory(const Reference<XComponentContext> & i_rContext)67cdf0e10cSrcweir     ToolPanelFactory::ToolPanelFactory( const Reference< XComponentContext >& i_rContext )
68cdf0e10cSrcweir         :m_xContext( i_rContext )
69cdf0e10cSrcweir     {
70cdf0e10cSrcweir     }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
~ToolPanelFactory()73cdf0e10cSrcweir     ToolPanelFactory::~ToolPanelFactory()
74cdf0e10cSrcweir     {
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
createUIElement(const::rtl::OUString & i_rResourceURL,const Sequence<PropertyValue> & i_rArgs)78cdf0e10cSrcweir     Reference< XUIElement > SAL_CALL ToolPanelFactory::createUIElement( const ::rtl::OUString& i_rResourceURL, const Sequence< PropertyValue >& i_rArgs ) throw (NoSuchElementException, IllegalArgumentException, RuntimeException)
79cdf0e10cSrcweir     {
80cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
81cdf0e10cSrcweir 
82cdf0e10cSrcweir         if ( !i_rResourceURL.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "private:resource/toolpanel/org.openoffice.example.colorpanel/" ) ) )
83cdf0e10cSrcweir             throw NoSuchElementException( i_rResourceURL, *this );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         const ::rtl::OUString sColor( i_rResourceURL.copy( i_rResourceURL.lastIndexOf( '/' ) + 1 ) );
86cdf0e10cSrcweir         const sal_Int32 nPanelColor = sColor.toInt32( 16 );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         // retrieve the parent window
89cdf0e10cSrcweir         Reference< XWindow > xParentWindow;
90cdf0e10cSrcweir         const PropertyValue* pArg = i_rArgs.getConstArray();
91cdf0e10cSrcweir         const PropertyValue* pArgEnd = i_rArgs.getConstArray() + i_rArgs.getLength();
92cdf0e10cSrcweir         for ( ; pArg != pArgEnd; ++pArg )
93cdf0e10cSrcweir         {
94cdf0e10cSrcweir             if ( pArg->Name.equalsAscii( "ParentWindow" ) )
95cdf0e10cSrcweir             {
96cdf0e10cSrcweir                 xParentWindow.set( pArg->Value, UNO_QUERY );
97cdf0e10cSrcweir                 break;
98cdf0e10cSrcweir             }
99cdf0e10cSrcweir         }
100cdf0e10cSrcweir         if ( !xParentWindow.is() )
101cdf0e10cSrcweir         {
102cdf0e10cSrcweir             OSL_ENSURE( false, "ToolPanelFactory::createUIElement: no parent window in the args!" );
103cdf0e10cSrcweir             throw IllegalArgumentException(
104cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No parent window provided in the creation arguments. Cannot create tool panel." ) ),
105cdf0e10cSrcweir                 *this,
106cdf0e10cSrcweir                 2
107cdf0e10cSrcweir             );
108cdf0e10cSrcweir         }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         /// create the panel
111cdf0e10cSrcweir         Reference< XUIElement > xUIElement( new PanelUIElement( m_xContext, xParentWindow, i_rResourceURL, nPanelColor ) );
112cdf0e10cSrcweir         return xUIElement;
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getImplementationName()116cdf0e10cSrcweir     ::rtl::OUString SAL_CALL ToolPanelFactory::getImplementationName(  ) throw (RuntimeException)
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         return getImplementationName_static();
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getImplementationName_static()122cdf0e10cSrcweir     ::rtl::OUString SAL_CALL ToolPanelFactory::getImplementationName_static(  ) throw (RuntimeException)
123cdf0e10cSrcweir     {
124cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.comp.example.custompanel.ToolPanelFactory" ) );
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
supportsService(const::rtl::OUString & i_rServiceName)128cdf0e10cSrcweir     ::sal_Bool SAL_CALL ToolPanelFactory::supportsService( const ::rtl::OUString& i_rServiceName ) throw (RuntimeException)
129cdf0e10cSrcweir     {
130cdf0e10cSrcweir         const Sequence< ::rtl::OUString > aServiceNames( getSupportedServiceNames() );
131cdf0e10cSrcweir         for (   const ::rtl::OUString* serviceName = aServiceNames.getConstArray();
132cdf0e10cSrcweir                 serviceName != aServiceNames.getConstArray() + aServiceNames.getLength();
133cdf0e10cSrcweir                 ++serviceName
134cdf0e10cSrcweir             )
135cdf0e10cSrcweir         {
136cdf0e10cSrcweir             if ( i_rServiceName == *serviceName )
137cdf0e10cSrcweir                 return  sal_True;
138cdf0e10cSrcweir         }
139cdf0e10cSrcweir         return sal_False;
140cdf0e10cSrcweir     }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getSupportedServiceNames()143cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL ToolPanelFactory::getSupportedServiceNames() throw (RuntimeException)
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         return getSupportedServiceNames_static();
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getSupportedServiceNames_static()149cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL ToolPanelFactory::getSupportedServiceNames_static() throw (RuntimeException)
150cdf0e10cSrcweir     {
151cdf0e10cSrcweir         Sequence< ::rtl::OUString > aServiceNames(1);
152cdf0e10cSrcweir         aServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.example.colorpanel.ToolPanelFactory" ) );
153cdf0e10cSrcweir         return aServiceNames;
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
Create(const Reference<XComponentContext> & i_rContext)157cdf0e10cSrcweir     Reference< XInterface > SAL_CALL ToolPanelFactory::Create( const Reference< XComponentContext >& i_rContext ) throw (RuntimeException)
158cdf0e10cSrcweir     {
159cdf0e10cSrcweir         return *( new ToolPanelFactory( i_rContext ) );
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir //......................................................................................................................
163cdf0e10cSrcweir } } // namespace sd::colortoolpanel
164cdf0e10cSrcweir //......................................................................................................................
165