merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / vba / vbaglobals.cxx
blob935a95cf10226c364eabbe227262fd0168783fc5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbaglobals.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include <vbahelper/helperdecl.hxx>
31 #include "vbaglobals.hxx"
33 #include <comphelper/unwrapargs.hxx>
35 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/container/XNameContainer.hpp>
38 #include <cppuhelper/bootstrap.hxx>
39 #include "vbaapplication.hxx"
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::ooo::vba;
45 rtl::OUString sDocCtxName( RTL_CONSTASCII_USTRINGPARAM("WordDocumentContext") );
47 // =============================================================================
48 // SwVbaGlobals
49 // =============================================================================
51 SwVbaGlobals::SwVbaGlobals( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& rxContext ) : SwVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext, sDocCtxName )
53 OSL_TRACE("SwVbaGlobals::SwVbaGlobals()");
54 uno::Sequence< beans::PropertyValue > aInitArgs( 2 );
55 aInitArgs[ 0 ].Name = rtl::OUString::createFromAscii("Application");
56 aInitArgs[ 0 ].Value = uno::makeAny( getApplication() );
57 aInitArgs[ 1 ].Name = sDocCtxName;
58 aInitArgs[ 1 ].Value = uno::makeAny( getXSomethingFromArgs< frame::XModel >( aArgs, 0 ) );
60 init( aInitArgs );
63 SwVbaGlobals::~SwVbaGlobals()
65 OSL_TRACE("SwVbaGlobals::~SwVbaGlobals");
68 // =============================================================================
69 // XGlobals
70 // =============================================================================
71 uno::Reference<word::XApplication >
72 SwVbaGlobals::getApplication() throw (uno::RuntimeException)
74 OSL_TRACE("In SwVbaGlobals::getApplication");
75 if ( !mxApplication.is() )
76 mxApplication.set( new SwVbaApplication( mxContext) );
78 return mxApplication;
81 uno::Reference<word::XSystem > SAL_CALL
82 SwVbaGlobals::getSystem() throw (uno::RuntimeException)
84 return getApplication()->getSystem();
87 uno::Reference< word::XDocument > SAL_CALL
88 SwVbaGlobals::getActiveDocument() throw (uno::RuntimeException)
90 return getApplication()->getActiveDocument();
93 uno::Reference< word::XWindow > SAL_CALL
94 SwVbaGlobals::getActiveWindow() throw (uno::RuntimeException)
96 return getApplication()->getActiveWindow();
99 rtl::OUString SAL_CALL
100 SwVbaGlobals::getName() throw (uno::RuntimeException)
102 return getApplication()->getName();
105 uno::Reference<word::XOptions > SAL_CALL
106 SwVbaGlobals::getOptions() throw (uno::RuntimeException)
108 return getApplication()->getOptions();
111 uno::Any SAL_CALL
112 SwVbaGlobals::CommandBars( const uno::Any& aIndex ) throw (uno::RuntimeException)
114 return getApplication()->CommandBars( aIndex );
117 uno::Any SAL_CALL
118 SwVbaGlobals::Documents( const uno::Any& index ) throw (uno::RuntimeException)
120 return getApplication()->Documents( index );
123 uno::Any SAL_CALL
124 SwVbaGlobals::Addins( const uno::Any& index ) throw (uno::RuntimeException)
126 return getApplication()->Addins( index );
129 uno::Any SAL_CALL
130 SwVbaGlobals::Dialogs( const uno::Any& index ) throw (uno::RuntimeException)
132 return getApplication()->Dialogs( index );
135 uno::Reference<word::XSelection > SAL_CALL
136 SwVbaGlobals::getSelection() throw (uno::RuntimeException)
138 return getApplication()->getSelection();
141 float SAL_CALL SwVbaGlobals::CentimetersToPoints( float _Centimeters ) throw (uno::RuntimeException)
143 return getApplication()->CentimetersToPoints( _Centimeters );
146 rtl::OUString&
147 SwVbaGlobals::getServiceImplName()
149 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaGlobals") );
150 return sImplName;
153 uno::Sequence< rtl::OUString >
154 SwVbaGlobals::getServiceNames()
156 static uno::Sequence< rtl::OUString > aServiceNames;
157 if ( aServiceNames.getLength() == 0 )
159 aServiceNames.realloc( 1 );
160 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Globals" ) );
162 return aServiceNames;
165 uno::Sequence< rtl::OUString >
166 SwVbaGlobals::getAvailableServiceNames( ) throw (uno::RuntimeException)
168 static bool bInit = false;
169 static uno::Sequence< rtl::OUString > serviceNames( SwVbaGlobals_BASE::getAvailableServiceNames() );
170 if ( !bInit )
172 rtl::OUString names[] = {
173 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.word.Document" ) ),
174 // #FIXME #TODO make Application a proper service
175 // ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.word.Application" ) ),
177 sal_Int32 nWordServices = ( sizeof( names )/ sizeof( names[0] ) );
178 sal_Int32 startIndex = serviceNames.getLength();
179 serviceNames.realloc( serviceNames.getLength() + nWordServices );
180 for ( sal_Int32 index = 0; index < nWordServices; ++index )
181 serviceNames[ startIndex + index ] = names[ index ];
182 bInit = true;
184 return serviceNames;
187 namespace globals
189 namespace sdecl = comphelper::service_decl;
190 sdecl::vba_service_class_<SwVbaGlobals, sdecl::with_args<true> > serviceImpl;
191 extern sdecl::ServiceDecl const serviceDecl(
192 serviceImpl,
193 "SwVbaGlobals",
194 "ooo.vba.word.Globals" );