1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "ctp_factory.hxx"
22 #include "ctp_panel.hxx"
24 #include <com/sun/star/lang/NotInitializedException.hpp>
25 #include <com/sun/star/lang/IllegalArgumentException.hpp>
26 #include <com/sun/star/lang/XComponent.hpp>
28 //......................................................................................................................
29 namespace sd
{ namespace colortoolpanel
31 //......................................................................................................................
33 using ::com::sun::star::uno::Reference
;
34 using ::com::sun::star::uno::XInterface
;
35 using ::com::sun::star::uno::UNO_QUERY
;
36 using ::com::sun::star::uno::UNO_QUERY_THROW
;
37 using ::com::sun::star::uno::UNO_SET_THROW
;
38 using ::com::sun::star::uno::Exception
;
39 using ::com::sun::star::uno::RuntimeException
;
40 using ::com::sun::star::uno::Any
;
41 using ::com::sun::star::uno::makeAny
;
42 using ::com::sun::star::uno::Sequence
;
43 using ::com::sun::star::uno::Type
;
44 using ::com::sun::star::uno::XComponentContext
;
45 using ::com::sun::star::lang::NotInitializedException
;
46 using ::com::sun::star::lang::IllegalArgumentException
;
47 using ::com::sun::star::lang::XComponent
;
48 using ::com::sun::star::ui::XUIElement
;
49 using ::com::sun::star::beans::PropertyValue
;
50 using ::com::sun::star::container::NoSuchElementException
;
51 using ::com::sun::star::awt::XWindow
;
53 //==================================================================================================================
55 //==================================================================================================================
56 //------------------------------------------------------------------------------------------------------------------
57 ToolPanelFactory::ToolPanelFactory( const Reference
< XComponentContext
>& i_rContext
)
58 :m_xContext( i_rContext
)
62 //------------------------------------------------------------------------------------------------------------------
63 ToolPanelFactory::~ToolPanelFactory()
67 //------------------------------------------------------------------------------------------------------------------
68 Reference
< XUIElement
> SAL_CALL
ToolPanelFactory::createUIElement( const OUString
& i_rResourceURL
, const Sequence
< PropertyValue
>& i_rArgs
) throw (NoSuchElementException
, IllegalArgumentException
, RuntimeException
)
70 ::osl::MutexGuard
aGuard( m_aMutex
);
72 if ( !i_rResourceURL
.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "private:resource/toolpanel/org.openoffice.example.colorpanel/" ) ) )
73 throw NoSuchElementException( i_rResourceURL
, *this );
75 const OUString
sColor( i_rResourceURL
.copy( i_rResourceURL
.lastIndexOf( '/' ) + 1 ) );
76 const sal_Int32 nPanelColor
= sColor
.toInt32( 16 );
78 // retrieve the parent window
79 Reference
< XWindow
> xParentWindow
;
80 const PropertyValue
* pArg
= i_rArgs
.getConstArray();
81 const PropertyValue
* pArgEnd
= i_rArgs
.getConstArray() + i_rArgs
.getLength();
82 for ( ; pArg
!= pArgEnd
; ++pArg
)
84 if ( pArg
->Name
== "ParentWindow" )
86 xParentWindow
.set( pArg
->Value
, UNO_QUERY
);
90 if ( !xParentWindow
.is() )
92 OSL_FAIL( "ToolPanelFactory::createUIElement: no parent window in the args!" );
93 throw IllegalArgumentException(
94 OUString( "No parent window provided in the creation arguments. Cannot create tool panel." ),
101 Reference
< XUIElement
> xUIElement( new PanelUIElement( m_xContext
, xParentWindow
, i_rResourceURL
, nPanelColor
) );
105 //------------------------------------------------------------------------------------------------------------------
106 OUString SAL_CALL
ToolPanelFactory::getImplementationName( ) throw (RuntimeException
)
108 return getImplementationName_static();
111 //------------------------------------------------------------------------------------------------------------------
112 OUString SAL_CALL
ToolPanelFactory::getImplementationName_static( ) throw (RuntimeException
)
114 return OUString( "org.openoffice.comp.example.custompanel.ToolPanelFactory" );
117 //------------------------------------------------------------------------------------------------------------------
118 ::sal_Bool SAL_CALL
ToolPanelFactory::supportsService( const OUString
& i_rServiceName
) throw (RuntimeException
)
120 const Sequence
< OUString
> aServiceNames( getSupportedServiceNames() );
121 for ( const OUString
* serviceName
= aServiceNames
.getConstArray();
122 serviceName
!= aServiceNames
.getConstArray() + aServiceNames
.getLength();
126 if ( i_rServiceName
== *serviceName
)
132 //------------------------------------------------------------------------------------------------------------------
133 Sequence
< OUString
> SAL_CALL
ToolPanelFactory::getSupportedServiceNames() throw (RuntimeException
)
135 return getSupportedServiceNames_static();
138 //------------------------------------------------------------------------------------------------------------------
139 Sequence
< OUString
> SAL_CALL
ToolPanelFactory::getSupportedServiceNames_static() throw (RuntimeException
)
141 Sequence
< OUString
> aServiceNames(1);
142 aServiceNames
[0] = OUString( "org.openoffice.example.colorpanel.ToolPanelFactory" );
143 return aServiceNames
;
146 //------------------------------------------------------------------------------------------------------------------
147 Reference
< XInterface
> SAL_CALL
ToolPanelFactory::Create( const Reference
< XComponentContext
>& i_rContext
) throw (RuntimeException
)
149 return *( new ToolPanelFactory( i_rContext
) );
152 //......................................................................................................................
153 } } // namespace sd::colortoolpanel
154 //......................................................................................................................
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */