merge the formfield patch from ooo-build
[ooovba.git] / vbahelper / source / vbahelper / vbaglobalbase.cxx
blobbc0eda21035e9c7996b81f69a2b7f3e8467d266b
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile$
7 * $Revision$
9 * last change: $Author$ $Date$
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
35 #include "vbahelper/vbaglobalbase.hxx"
37 #include <cppuhelper/component_context.hxx>
38 #include <comphelper/processfactory.hxx>
39 #include <com/sun/star/container/XNameContainer.hpp>
41 using namespace com::sun::star;
42 using namespace ooo::vba;
44 rtl::OUString sApplication( RTL_CONSTASCII_USTRINGPARAM("Application") );
46 VbaGlobalsBase::VbaGlobalsBase(
47 const uno::Reference< ov::XHelperInterface >& xParent,
48 const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sDocCtxName )
49 : Globals_BASE( xParent, xContext )
51 // overwrite context with custom one ( that contains the application )
52 ::cppu::ContextEntry_Init aHandlerContextInfo[] =
54 ::cppu::ContextEntry_Init( sApplication, uno::Any() ),
55 ::cppu::ContextEntry_Init( sDocCtxName, uno::Any() ),
58 mxContext = ::cppu::createComponentContext( aHandlerContextInfo, sizeof( aHandlerContextInfo ) / sizeof( aHandlerContextInfo[0] ), xContext );
63 void
64 VbaGlobalsBase::init( const uno::Sequence< beans::PropertyValue >& aInitArgs )
66 sal_Int32 nLen = aInitArgs.getLength();
67 for ( sal_Int32 nIndex = 0; nIndex < nLen; ++nIndex )
69 uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY_THROW );
70 if ( aInitArgs[ nIndex ].Name.equals( sApplication ) )
72 xNameContainer->replaceByName( sApplication, aInitArgs[ nIndex ].Value );
73 uno::Reference< XHelperInterface > xParent( aInitArgs[ nIndex ].Value, uno::UNO_QUERY );
74 mxParent = xParent;
76 else
77 xNameContainer->replaceByName( aInitArgs[ nIndex ].Name, aInitArgs[ nIndex ].Value );
81 uno::Reference< uno::XInterface > SAL_CALL
82 VbaGlobalsBase::createInstance( const ::rtl::OUString& aServiceSpecifier ) throw (uno::Exception, uno::RuntimeException)
84 uno::Reference< uno::XInterface > xReturn;
86 if ( hasServiceName( aServiceSpecifier ) )
87 xReturn = mxContext->getServiceManager()->createInstanceWithContext( aServiceSpecifier, mxContext );
88 return xReturn;
91 uno::Reference< uno::XInterface > SAL_CALL
92 VbaGlobalsBase::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const uno::Sequence< uno::Any >& Arguments ) throw (uno::Exception, uno::RuntimeException)
95 uno::Reference< uno::XInterface > xReturn;
97 if ( hasServiceName( ServiceSpecifier ) )
98 xReturn = mxContext->getServiceManager()->createInstanceWithArgumentsAndContext( ServiceSpecifier, Arguments, mxContext );
99 return xReturn;
102 uno::Sequence< ::rtl::OUString > SAL_CALL
103 VbaGlobalsBase::getAvailableServiceNames( ) throw (uno::RuntimeException)
105 static const rtl::OUString names[] = {
106 // common
107 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.msforms.UserForm" ) ),
109 static uno::Sequence< rtl::OUString > serviceNames( names, sizeof( names )/ sizeof( names[0] ) );
110 return serviceNames;
113 bool
114 VbaGlobalsBase::hasServiceName( const rtl::OUString& serviceName )
116 uno::Sequence< rtl::OUString > sServiceNames( getAvailableServiceNames() );
117 sal_Int32 nLen = sServiceNames.getLength();
118 for ( sal_Int32 index = 0; index < nLen; ++index )
120 if ( sServiceNames[ index ].equals( serviceName ) )
121 return true;
123 return false;