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