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