1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10*efeef26fSAndrew Rist *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19*efeef26fSAndrew Rist *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir #include <vbahelper/helperdecl.hxx>
24cdf0e10cSrcweir #include "vbaglobals.hxx"
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include <comphelper/unwrapargs.hxx>
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
29cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
30cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
31cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
32cdf0e10cSrcweir #include "vbaapplication.hxx"
33cdf0e10cSrcweir using namespace ::com::sun::star;
34cdf0e10cSrcweir using namespace ::com::sun::star::uno;
35cdf0e10cSrcweir using namespace ::ooo::vba;
36cdf0e10cSrcweir
37cdf0e10cSrcweir
38cdf0e10cSrcweir rtl::OUString sDocCtxName( RTL_CONSTASCII_USTRINGPARAM("WordDocumentContext") );
39cdf0e10cSrcweir
40cdf0e10cSrcweir // =============================================================================
41cdf0e10cSrcweir // SwVbaGlobals
42cdf0e10cSrcweir // =============================================================================
43cdf0e10cSrcweir
SwVbaGlobals(uno::Sequence<uno::Any> const & aArgs,uno::Reference<uno::XComponentContext> const & rxContext)44cdf0e10cSrcweir SwVbaGlobals::SwVbaGlobals( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& rxContext ) : SwVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext, sDocCtxName )
45cdf0e10cSrcweir {
46cdf0e10cSrcweir OSL_TRACE("SwVbaGlobals::SwVbaGlobals()");
47cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aInitArgs( 2 );
48cdf0e10cSrcweir aInitArgs[ 0 ].Name = rtl::OUString::createFromAscii("Application");
49cdf0e10cSrcweir aInitArgs[ 0 ].Value = uno::makeAny( getApplication() );
50cdf0e10cSrcweir aInitArgs[ 1 ].Name = sDocCtxName;
51cdf0e10cSrcweir aInitArgs[ 1 ].Value = uno::makeAny( getXSomethingFromArgs< frame::XModel >( aArgs, 0 ) );
52cdf0e10cSrcweir
53cdf0e10cSrcweir init( aInitArgs );
54cdf0e10cSrcweir }
55cdf0e10cSrcweir
~SwVbaGlobals()56cdf0e10cSrcweir SwVbaGlobals::~SwVbaGlobals()
57cdf0e10cSrcweir {
58cdf0e10cSrcweir OSL_TRACE("SwVbaGlobals::~SwVbaGlobals");
59cdf0e10cSrcweir }
60cdf0e10cSrcweir
61cdf0e10cSrcweir // =============================================================================
62cdf0e10cSrcweir // XGlobals
63cdf0e10cSrcweir // =============================================================================
64cdf0e10cSrcweir uno::Reference<word::XApplication >
getApplication()65cdf0e10cSrcweir SwVbaGlobals::getApplication() throw (uno::RuntimeException)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir OSL_TRACE("In SwVbaGlobals::getApplication");
68cdf0e10cSrcweir if ( !mxApplication.is() )
69cdf0e10cSrcweir mxApplication.set( new SwVbaApplication( mxContext) );
70cdf0e10cSrcweir
71cdf0e10cSrcweir return mxApplication;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
74cdf0e10cSrcweir uno::Reference<word::XSystem > SAL_CALL
getSystem()75cdf0e10cSrcweir SwVbaGlobals::getSystem() throw (uno::RuntimeException)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir return getApplication()->getSystem();
78cdf0e10cSrcweir }
79cdf0e10cSrcweir
80cdf0e10cSrcweir uno::Reference< word::XDocument > SAL_CALL
getActiveDocument()81cdf0e10cSrcweir SwVbaGlobals::getActiveDocument() throw (uno::RuntimeException)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir return getApplication()->getActiveDocument();
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
86cdf0e10cSrcweir uno::Reference< word::XWindow > SAL_CALL
getActiveWindow()87cdf0e10cSrcweir SwVbaGlobals::getActiveWindow() throw (uno::RuntimeException)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir return getApplication()->getActiveWindow();
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
92cdf0e10cSrcweir rtl::OUString SAL_CALL
getName()93cdf0e10cSrcweir SwVbaGlobals::getName() throw (uno::RuntimeException)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir return getApplication()->getName();
96cdf0e10cSrcweir }
97cdf0e10cSrcweir
98cdf0e10cSrcweir uno::Reference<word::XOptions > SAL_CALL
getOptions()99cdf0e10cSrcweir SwVbaGlobals::getOptions() throw (uno::RuntimeException)
100cdf0e10cSrcweir {
101cdf0e10cSrcweir return getApplication()->getOptions();
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
104cdf0e10cSrcweir uno::Any SAL_CALL
CommandBars(const uno::Any & aIndex)105cdf0e10cSrcweir SwVbaGlobals::CommandBars( const uno::Any& aIndex ) throw (uno::RuntimeException)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir return getApplication()->CommandBars( aIndex );
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir uno::Any SAL_CALL
Documents(const uno::Any & index)111cdf0e10cSrcweir SwVbaGlobals::Documents( const uno::Any& index ) throw (uno::RuntimeException)
112cdf0e10cSrcweir {
113cdf0e10cSrcweir return getApplication()->Documents( index );
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
116cdf0e10cSrcweir uno::Any SAL_CALL
Addins(const uno::Any & index)117cdf0e10cSrcweir SwVbaGlobals::Addins( const uno::Any& index ) throw (uno::RuntimeException)
118cdf0e10cSrcweir {
119cdf0e10cSrcweir return getApplication()->Addins( index );
120cdf0e10cSrcweir }
121cdf0e10cSrcweir
122cdf0e10cSrcweir uno::Any SAL_CALL
Dialogs(const uno::Any & index)123cdf0e10cSrcweir SwVbaGlobals::Dialogs( const uno::Any& index ) throw (uno::RuntimeException)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir return getApplication()->Dialogs( index );
126cdf0e10cSrcweir }
127cdf0e10cSrcweir
128cdf0e10cSrcweir uno::Reference<word::XSelection > SAL_CALL
getSelection()129cdf0e10cSrcweir SwVbaGlobals::getSelection() throw (uno::RuntimeException)
130cdf0e10cSrcweir {
131cdf0e10cSrcweir return getApplication()->getSelection();
132cdf0e10cSrcweir }
133cdf0e10cSrcweir
CentimetersToPoints(float _Centimeters)134cdf0e10cSrcweir float SAL_CALL SwVbaGlobals::CentimetersToPoints( float _Centimeters ) throw (uno::RuntimeException)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir return getApplication()->CentimetersToPoints( _Centimeters );
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir rtl::OUString&
getServiceImplName()140cdf0e10cSrcweir SwVbaGlobals::getServiceImplName()
141cdf0e10cSrcweir {
142cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaGlobals") );
143cdf0e10cSrcweir return sImplName;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir
146cdf0e10cSrcweir uno::Sequence< rtl::OUString >
getServiceNames()147cdf0e10cSrcweir SwVbaGlobals::getServiceNames()
148cdf0e10cSrcweir {
149cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames;
150cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir aServiceNames.realloc( 1 );
153cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Globals" ) );
154cdf0e10cSrcweir }
155cdf0e10cSrcweir return aServiceNames;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir
158cdf0e10cSrcweir uno::Sequence< rtl::OUString >
getAvailableServiceNames()159cdf0e10cSrcweir SwVbaGlobals::getAvailableServiceNames( ) throw (uno::RuntimeException)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir static bool bInit = false;
162cdf0e10cSrcweir static uno::Sequence< rtl::OUString > serviceNames( SwVbaGlobals_BASE::getAvailableServiceNames() );
163cdf0e10cSrcweir if ( !bInit )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir rtl::OUString names[] = {
166cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.word.Document" ) ),
167cdf0e10cSrcweir // #FIXME #TODO make Application a proper service
168cdf0e10cSrcweir // ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.word.Application" ) ),
169cdf0e10cSrcweir };
170cdf0e10cSrcweir sal_Int32 nWordServices = ( sizeof( names )/ sizeof( names[0] ) );
171cdf0e10cSrcweir sal_Int32 startIndex = serviceNames.getLength();
172cdf0e10cSrcweir serviceNames.realloc( serviceNames.getLength() + nWordServices );
173cdf0e10cSrcweir for ( sal_Int32 index = 0; index < nWordServices; ++index )
174cdf0e10cSrcweir serviceNames[ startIndex + index ] = names[ index ];
175cdf0e10cSrcweir bInit = true;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir return serviceNames;
178cdf0e10cSrcweir }
179cdf0e10cSrcweir
180cdf0e10cSrcweir namespace globals
181cdf0e10cSrcweir {
182cdf0e10cSrcweir namespace sdecl = comphelper::service_decl;
183cdf0e10cSrcweir sdecl::vba_service_class_<SwVbaGlobals, sdecl::with_args<true> > serviceImpl;
184cdf0e10cSrcweir extern sdecl::ServiceDecl const serviceDecl(
185cdf0e10cSrcweir serviceImpl,
186cdf0e10cSrcweir "SwVbaGlobals",
187cdf0e10cSrcweir "ooo.vba.word.Globals" );
188cdf0e10cSrcweir }
189cdf0e10cSrcweir
190