tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / odk / examples / cpp / custompanel / ctp_factory.cxx
blob85b89476d11d301ea286551532a1ae8388dfc9dd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/IllegalArgumentException.hpp>
25 #include <cppuhelper/supportsservice.hxx>
27 namespace sd { namespace colortoolpanel
29 using ::com::sun::star::uno::Reference;
30 using ::com::sun::star::uno::XInterface;
31 using ::com::sun::star::uno::UNO_QUERY;
32 using ::com::sun::star::uno::RuntimeException;
33 using ::com::sun::star::uno::Sequence;
34 using ::com::sun::star::uno::XComponentContext;
35 using ::com::sun::star::lang::IllegalArgumentException;
36 using ::com::sun::star::ui::XUIElement;
37 using ::com::sun::star::beans::PropertyValue;
38 using ::com::sun::star::container::NoSuchElementException;
39 using ::com::sun::star::awt::XWindow;
41 ToolPanelFactory::ToolPanelFactory( const Reference< XComponentContext >& i_rContext )
42 :m_xContext( i_rContext )
47 ToolPanelFactory::~ToolPanelFactory()
52 Reference< XUIElement > SAL_CALL ToolPanelFactory::createUIElement( const OUString& i_rResourceURL, const Sequence< PropertyValue >& i_rArgs )
54 ::osl::MutexGuard aGuard( m_aMutex );
56 if ( !i_rResourceURL.startsWith( "private:resource/toolpanel/org.openoffice.example.colorpanel/" ) )
57 throw NoSuchElementException( i_rResourceURL, *this );
59 const OUString sColor( i_rResourceURL.copy( i_rResourceURL.lastIndexOf( '/' ) + 1 ) );
60 const sal_Int32 nPanelColor = static_cast< sal_Int32 >( sColor.toUInt32( 16 ) );
62 // retrieve the parent window
63 Reference< XWindow > xParentWindow;
64 const PropertyValue* pArg = i_rArgs.getConstArray();
65 const PropertyValue* pArgEnd = i_rArgs.getConstArray() + i_rArgs.getLength();
66 for ( ; pArg != pArgEnd; ++pArg )
68 if ( pArg->Name == "ParentWindow" )
70 xParentWindow.set( pArg->Value, UNO_QUERY );
71 break;
74 if ( !xParentWindow.is() )
76 OSL_FAIL( "ToolPanelFactory::createUIElement: no parent window in the args!" );
77 throw IllegalArgumentException(
78 "No parent window provided in the creation arguments. Cannot create tool panel.",
79 *this,
84 /// create the panel
85 Reference< XUIElement > xUIElement( new PanelUIElement( m_xContext, xParentWindow, i_rResourceURL, nPanelColor ) );
86 return xUIElement;
89 OUString SAL_CALL ToolPanelFactory::getImplementationName( )
91 return getImplementationName_static();
94 OUString SAL_CALL ToolPanelFactory::getImplementationName_static( )
96 return OUString( "org.openoffice.comp.example.custompanel.ToolPanelFactory" );
99 sal_Bool SAL_CALL ToolPanelFactory::supportsService( const OUString& i_rServiceName )
101 return cppu::supportsService(this, i_rServiceName);
104 Sequence< OUString > SAL_CALL ToolPanelFactory::getSupportedServiceNames()
106 return getSupportedServiceNames_static();
109 Sequence< OUString > SAL_CALL ToolPanelFactory::getSupportedServiceNames_static()
111 Sequence< OUString > aServiceNames(1);
112 aServiceNames[0] = "org.openoffice.example.colorpanel.ToolPanelFactory";
113 return aServiceNames;
117 Reference< XInterface > SAL_CALL ToolPanelFactory::Create( const Reference< XComponentContext >& i_rContext )
119 return *( new ToolPanelFactory( i_rContext ) );
123 } } // namespace sd::colortoolpanel
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */