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>
27 #include <cppuhelper/supportsservice.hxx>
29 namespace sd
{ namespace colortoolpanel
31 using ::com::sun::star::uno::Reference
;
32 using ::com::sun::star::uno::XInterface
;
33 using ::com::sun::star::uno::UNO_QUERY
;
34 using ::com::sun::star::uno::UNO_QUERY_THROW
;
35 using ::com::sun::star::uno::UNO_SET_THROW
;
36 using ::com::sun::star::uno::Exception
;
37 using ::com::sun::star::uno::RuntimeException
;
38 using ::com::sun::star::uno::Any
;
39 using ::com::sun::star::uno::makeAny
;
40 using ::com::sun::star::uno::Sequence
;
41 using ::com::sun::star::uno::Type
;
42 using ::com::sun::star::uno::XComponentContext
;
43 using ::com::sun::star::lang::NotInitializedException
;
44 using ::com::sun::star::lang::IllegalArgumentException
;
45 using ::com::sun::star::lang::XComponent
;
46 using ::com::sun::star::ui::XUIElement
;
47 using ::com::sun::star::beans::PropertyValue
;
48 using ::com::sun::star::container::NoSuchElementException
;
49 using ::com::sun::star::awt::XWindow
;
51 ToolPanelFactory::ToolPanelFactory( const Reference
< XComponentContext
>& i_rContext
)
52 :m_xContext( i_rContext
)
57 ToolPanelFactory::~ToolPanelFactory()
62 Reference
< XUIElement
> SAL_CALL
ToolPanelFactory::createUIElement( const OUString
& i_rResourceURL
, const Sequence
< PropertyValue
>& i_rArgs
) throw (NoSuchElementException
, IllegalArgumentException
, RuntimeException
)
64 ::osl::MutexGuard
aGuard( m_aMutex
);
66 if ( !i_rResourceURL
.startsWith( "private:resource/toolpanel/org.openoffice.example.colorpanel/" ) )
67 throw NoSuchElementException( i_rResourceURL
, *this );
69 const OUString
sColor( i_rResourceURL
.copy( i_rResourceURL
.lastIndexOf( '/' ) + 1 ) );
70 const sal_Int32 nPanelColor
= static_cast< sal_Int32
>( sColor
.toUInt32( 16 ) );
72 // retrieve the parent window
73 Reference
< XWindow
> xParentWindow
;
74 const PropertyValue
* pArg
= i_rArgs
.getConstArray();
75 const PropertyValue
* pArgEnd
= i_rArgs
.getConstArray() + i_rArgs
.getLength();
76 for ( ; pArg
!= pArgEnd
; ++pArg
)
78 if ( pArg
->Name
== "ParentWindow" )
80 xParentWindow
.set( pArg
->Value
, UNO_QUERY
);
84 if ( !xParentWindow
.is() )
86 OSL_FAIL( "ToolPanelFactory::createUIElement: no parent window in the args!" );
87 throw IllegalArgumentException(
88 "No parent window provided in the creation arguments. Cannot create tool panel.",
95 Reference
< XUIElement
> xUIElement( new PanelUIElement( m_xContext
, xParentWindow
, i_rResourceURL
, nPanelColor
) );
99 OUString SAL_CALL
ToolPanelFactory::getImplementationName( ) throw (RuntimeException
)
101 return getImplementationName_static();
104 OUString SAL_CALL
ToolPanelFactory::getImplementationName_static( ) throw (RuntimeException
)
106 return OUString( "org.openoffice.comp.example.custompanel.ToolPanelFactory" );
109 sal_Bool SAL_CALL
ToolPanelFactory::supportsService( const OUString
& i_rServiceName
) throw (RuntimeException
)
111 return cppu::supportsService(this, i_rServiceName
);
114 Sequence
< OUString
> SAL_CALL
ToolPanelFactory::getSupportedServiceNames() throw (RuntimeException
)
116 return getSupportedServiceNames_static();
119 Sequence
< OUString
> SAL_CALL
ToolPanelFactory::getSupportedServiceNames_static() throw (RuntimeException
)
121 Sequence
< OUString
> aServiceNames(1);
122 aServiceNames
[0] = "org.openoffice.example.colorpanel.ToolPanelFactory";
123 return aServiceNames
;
127 Reference
< XInterface
> SAL_CALL
ToolPanelFactory::Create( const Reference
< XComponentContext
>& i_rContext
) throw (RuntimeException
)
129 return *( new ToolPanelFactory( i_rContext
) );
133 } } // namespace sd::colortoolpanel
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */