Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include "vbahelper/vbaapplicationbase.hxx"
21 : : #include <sal/macros.h>
22 : :
23 : : #include <com/sun/star/container/XIndexAccess.hpp>
24 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 : : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
26 : : #include <com/sun/star/lang/XComponent.hpp>
27 : : #include <com/sun/star/container/XEnumeration.hpp>
28 : : #include <com/sun/star/frame/XLayoutManager.hpp>
29 : : #include <com/sun/star/frame/XDesktop.hpp>
30 : : #include <com/sun/star/container/XEnumerationAccess.hpp>
31 : : #include <com/sun/star/document/XDocumentInfoSupplier.hpp>
32 : : #include <com/sun/star/document/XDocumentProperties.hpp>
33 : : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
34 : : #include <com/sun/star/document/XEmbeddedScripts.hpp>
35 : : #include <com/sun/star/awt/XWindow2.hpp>
36 : :
37 : : #include <boost/unordered_map.hpp>
38 : : #include <filter/msfilter/msvbahelper.hxx>
39 : : #include <tools/datetime.hxx>
40 : :
41 : : #include <basic/sbx.hxx>
42 : : #include <basic/sbstar.hxx>
43 : : #include <basic/sbuno.hxx>
44 : : #include <basic/sbmeth.hxx>
45 : : #include <basic/sbmod.hxx>
46 : : #include <basic/vbahelper.hxx>
47 : :
48 : : #include "vbacommandbars.hxx"
49 : :
50 : : using namespace ::com::sun::star;
51 : : using namespace ::ooo::vba;
52 : :
53 : : #define OFFICEVERSION "11.0"
54 : :
55 : : // ====VbaTimerInfo==================================
56 : : typedef ::std::pair< ::rtl::OUString, ::std::pair< double, double > > VbaTimerInfo;
57 : :
58 : : // ====VbaTimer==================================
59 : : class VbaTimer
60 : : {
61 : : Timer m_aTimer;
62 : : VbaTimerInfo m_aTimerInfo;
63 : : ::rtl::Reference< VbaApplicationBase > m_xBase;
64 : :
65 : : // the following declarations are here to prevent the usage of them
66 : : VbaTimer( const VbaTimer& );
67 : : VbaTimer& operator=( const VbaTimer& );
68 : :
69 : : public:
70 : 0 : VbaTimer()
71 [ # # ]: 0 : {}
72 : :
73 : 0 : virtual ~VbaTimer()
74 : 0 : {
75 [ # # ]: 0 : m_aTimer.Stop();
76 [ # # ]: 0 : }
77 : :
78 : 0 : static double GetNow()
79 : : {
80 [ # # ]: 0 : Date aDateNow( Date::SYSTEM );
81 [ # # ]: 0 : Time aTimeNow( Time::SYSTEM );
82 : 0 : Date aRefDate( 1,1,1900 );
83 [ # # ]: 0 : long nDiffDays = (long)(aDateNow - aRefDate);
84 : 0 : nDiffDays += 2; // Change VisualBasic: 1.Jan.1900 == 2
85 : :
86 : 0 : long nDiffSeconds = aTimeNow.GetHour() * 3600 + aTimeNow.GetMin() * 60 + aTimeNow.GetSec();
87 : 0 : return (double)nDiffDays + ((double)nDiffSeconds)/(double)(24*3600);
88 : : }
89 : :
90 : 0 : static sal_Int32 GetTimerMiliseconds( double nFrom, double nTo )
91 : : {
92 : 0 : double nResult = nTo - nFrom;
93 [ # # ]: 0 : if ( nResult > 0 )
94 : 0 : nResult *= 24*3600*1000;
95 : : else
96 : 0 : nResult = 50;
97 : :
98 : 0 : return (sal_Int32) nResult;
99 : : }
100 : :
101 : 0 : void Start( const ::rtl::Reference< VbaApplicationBase > xBase, const ::rtl::OUString& aFunction, double nFrom, double nTo )
102 : : {
103 [ # # ][ # # ]: 0 : if ( !xBase.is() || aFunction.isEmpty() )
[ # # ]
104 [ # # ]: 0 : throw uno::RuntimeException( ::rtl::OUString( "Unexpected arguments!" ), uno::Reference< uno::XInterface >() );
105 : :
106 : 0 : m_xBase = xBase;
107 [ # # ]: 0 : m_aTimerInfo = VbaTimerInfo( aFunction, ::std::pair< double, double >( nFrom, nTo ) );
108 : 0 : m_aTimer.SetTimeoutHdl( LINK( this, VbaTimer, MacroCallHdl ) );
109 : 0 : m_aTimer.SetTimeout( GetTimerMiliseconds( GetNow(), nFrom ) );
110 : 0 : m_aTimer.Start();
111 : 0 : }
112 : :
113 : : DECL_LINK( MacroCallHdl, void* );
114 : : };
115 : :
116 : 0 : IMPL_LINK_NOARG(VbaTimer, MacroCallHdl)
117 : : {
118 [ # # ][ # # ]: 0 : if ( m_aTimerInfo.second.second == 0 || GetNow() < m_aTimerInfo.second.second )
[ # # ]
119 : : {
120 : 0 : uno::Any aDummyArg;
121 : : try
122 : : {
123 [ # # ]: 0 : m_xBase->Run( m_aTimerInfo.first, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg );
124 : : }
125 [ # # ]: 0 : catch( uno::Exception& )
126 : 0 : {}
127 : : }
128 : :
129 : : // mast be the last call in the method since it deletes the timer
130 : : try
131 : : {
132 [ # # ][ # # ]: 0 : m_xBase->OnTime( uno::makeAny( m_aTimerInfo.second.first ), m_aTimerInfo.first, uno::makeAny( m_aTimerInfo.second.second ), uno::makeAny( sal_False ) );
[ # # ][ # # ]
[ # # ]
133 : 0 : } catch( uno::Exception& )
134 : : {}
135 : :
136 [ # # ]: 0 : return 0;
137 : : }
138 : :
139 : : // ====VbaTimerInfoHash==================================
140 : : struct VbaTimerInfoHash
141 : : {
142 : 0 : size_t operator()( const VbaTimerInfo& rTimerInfo ) const
143 : : {
144 : 0 : return (size_t)rTimerInfo.first.hashCode()
145 : 0 : + (size_t)rtl_str_hashCode_WithLength( (char*)&rTimerInfo.second.first, sizeof( double ) )
146 : 0 : + (size_t)rtl_str_hashCode_WithLength( (char*)&rTimerInfo.second.second, sizeof( double ) );
147 : : }
148 : : };
149 : :
150 : : // ====VbaTimerHashMap==================================
151 : : typedef ::boost::unordered_map< VbaTimerInfo, VbaTimer*, VbaTimerInfoHash, ::std::equal_to< VbaTimerInfo > > VbaTimerHashMap;
152 : :
153 : : // ====VbaApplicationBase_Impl==================================
154 : : struct VbaApplicationBase_Impl
155 : : {
156 : : VbaTimerHashMap m_aTimerHash;
157 : : sal_Bool mbVisible;
158 : :
159 [ + - ]: 8 : inline VbaApplicationBase_Impl() : mbVisible( sal_True ) {}
160 : :
161 : 16 : virtual ~VbaApplicationBase_Impl()
162 : 8 : {
163 : : // remove the remaining timers
164 [ + - ][ - + ]: 16 : for ( VbaTimerHashMap::iterator aIter = m_aTimerHash.begin();
165 [ + - ]: 8 : aIter != m_aTimerHash.end();
166 : : ++aIter )
167 : : {
168 [ # # ][ # # ]: 0 : delete aIter->second;
[ # # ]
169 [ # # ]: 0 : aIter->second = NULL;
170 : : }
171 [ - + ]: 16 : }
172 : : };
173 : :
174 : : // ====VbaApplicationBase==================================
175 : 8 : VbaApplicationBase::VbaApplicationBase( const uno::Reference< uno::XComponentContext >& xContext )
176 : : : ApplicationBase_BASE( uno::Reference< XHelperInterface >(), xContext )
177 [ + - ][ + - ]: 8 : , m_pImpl( new VbaApplicationBase_Impl )
[ + - ]
178 : : {
179 : 8 : }
180 : :
181 : 8 : VbaApplicationBase::~VbaApplicationBase()
182 : : {
183 [ + - ][ + - ]: 8 : delete m_pImpl;
184 [ - + ]: 8 : }
185 : :
186 : : sal_Bool SAL_CALL
187 : 0 : VbaApplicationBase::getScreenUpdating() throw (uno::RuntimeException)
188 : : {
189 [ # # ][ # # ]: 0 : uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
190 [ # # ][ # # ]: 0 : return !xModel->hasControllersLocked();
191 : : }
192 : :
193 : : void SAL_CALL
194 : 0 : VbaApplicationBase::setScreenUpdating(sal_Bool bUpdate) throw (uno::RuntimeException)
195 : : {
196 [ # # ][ # # ]: 0 : uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
197 : : // #163808# use helper from module "basic" to lock all documents of this application
198 [ # # ]: 0 : ::basic::vba::lockControllersOfAllDocuments( xModel, !bUpdate );
199 : 0 : }
200 : :
201 : : sal_Bool SAL_CALL
202 : 0 : VbaApplicationBase::getDisplayStatusBar() throw (uno::RuntimeException)
203 : : {
204 [ # # ][ # # ]: 0 : uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
205 [ # # ][ # # ]: 0 : uno::Reference< frame::XFrame > xFrame( xModel->getCurrentController()->getFrame(), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ]
206 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xProps( xFrame, uno::UNO_QUERY_THROW );
207 : :
208 [ # # ]: 0 : if( xProps.is() ){
209 [ # # ][ # # ]: 0 : uno::Reference< frame::XLayoutManager > xLayoutManager( xProps->getPropertyValue( rtl::OUString("LayoutManager") ), uno::UNO_QUERY_THROW );
[ # # ]
210 : 0 : rtl::OUString url( "private:resource/statusbar/statusbar" );
211 [ # # ][ # # ]: 0 : if( xLayoutManager.is() && xLayoutManager->isElementVisible( url ) ){
[ # # ][ # # ]
[ # # ]
212 : 0 : return sal_True;
213 [ # # ][ # # ]: 0 : }
214 : : }
215 : 0 : return sal_False;
216 : : }
217 : :
218 : : void SAL_CALL
219 : 0 : VbaApplicationBase::setDisplayStatusBar(sal_Bool bDisplayStatusBar) throw (uno::RuntimeException)
220 : : {
221 [ # # ][ # # ]: 0 : uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
222 [ # # ][ # # ]: 0 : uno::Reference< frame::XFrame > xFrame( xModel->getCurrentController()->getFrame(), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ]
223 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xProps( xFrame, uno::UNO_QUERY_THROW );
224 : :
225 [ # # ]: 0 : if( xProps.is() ){
226 [ # # ][ # # ]: 0 : uno::Reference< frame::XLayoutManager > xLayoutManager( xProps->getPropertyValue( rtl::OUString("LayoutManager") ), uno::UNO_QUERY_THROW );
[ # # ]
227 : 0 : rtl::OUString url( "private:resource/statusbar/statusbar" );
228 [ # # ]: 0 : if( xLayoutManager.is() ){
229 [ # # ][ # # ]: 0 : if( bDisplayStatusBar && !xLayoutManager->isElementVisible( url ) ){
[ # # ][ # # ]
[ # # ]
230 [ # # ][ # # ]: 0 : if( !xLayoutManager->showElement( url ) )
[ # # ]
231 [ # # ][ # # ]: 0 : xLayoutManager->createElement( url );
232 : : return;
233 : : }
234 [ # # ][ # # ]: 0 : else if( !bDisplayStatusBar && xLayoutManager->isElementVisible( url ) ){
[ # # ][ # # ]
[ # # ]
235 [ # # ][ # # ]: 0 : xLayoutManager->hideElement( url );
236 : : return;
237 : : }
238 [ # # ][ # # ]: 0 : }
239 : : }
240 : 0 : return;
241 : : }
242 : :
243 : 0 : ::sal_Bool SAL_CALL VbaApplicationBase::getInteractive()
244 : : throw (uno::RuntimeException)
245 : : {
246 [ # # ][ # # ]: 0 : uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
247 [ # # ][ # # ]: 0 : uno::Reference< frame::XFrame > xFrame( xModel->getCurrentController()->getFrame(), uno::UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ]
248 [ # # ][ # # ]: 0 : uno::Reference< awt::XWindow2 > xWindow( xFrame->getContainerWindow(), uno::UNO_QUERY_THROW );
[ # # ]
249 : :
250 [ # # ][ # # ]: 0 : return xWindow->isEnabled();
251 : : }
252 : :
253 : 0 : void SAL_CALL VbaApplicationBase::setInteractive( ::sal_Bool bInteractive )
254 : : throw (uno::RuntimeException)
255 : : {
256 [ # # ][ # # ]: 0 : uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
257 : : // #163808# use helper from module "basic" to enable/disable all container windows of all documents of this application
258 [ # # ]: 0 : ::basic::vba::enableContainerWindowsOfAllDocuments( xModel, bInteractive );
259 : 0 : }
260 : :
261 : 0 : sal_Bool SAL_CALL VbaApplicationBase::getVisible() throw (uno::RuntimeException)
262 : : {
263 : 0 : return m_pImpl->mbVisible; // dummy implementation
264 : : }
265 : :
266 : 0 : void SAL_CALL VbaApplicationBase::setVisible( sal_Bool bVisible ) throw (uno::RuntimeException)
267 : : {
268 : 0 : m_pImpl->mbVisible = bVisible; // dummy implementation
269 : 0 : }
270 : :
271 : :
272 : : void SAL_CALL
273 : 0 : VbaApplicationBase::OnKey( const ::rtl::OUString& Key, const uno::Any& Procedure ) throw (uno::RuntimeException)
274 : : {
275 : : // parse the Key & modifiers
276 [ # # ]: 0 : awt::KeyEvent aKeyEvent = parseKeyEvent( Key );
277 : 0 : rtl::OUString MacroName;
278 : 0 : Procedure >>= MacroName;
279 : 0 : uno::Reference< frame::XModel > xModel;
280 [ # # ]: 0 : SbMethod* pMeth = StarBASIC::GetActiveMethod();
281 [ # # ]: 0 : if ( pMeth )
282 : : {
283 [ # # ][ # # ]: 0 : SbModule* pMod = dynamic_cast< SbModule* >( pMeth->GetParent() );
284 [ # # ]: 0 : if ( pMod )
285 [ # # ][ # # ]: 0 : xModel = StarBASIC::GetModelFromBasic( pMod );
286 : : }
287 : :
288 [ # # ]: 0 : if ( !xModel.is() )
289 [ # # ][ # # ]: 0 : xModel = getCurrentDocument();
290 : :
291 [ # # ][ # # ]: 0 : applyShortCutKeyBinding( xModel, aKeyEvent, MacroName );
292 : 0 : }
293 : :
294 : : uno::Any SAL_CALL
295 : 0 : VbaApplicationBase::CommandBars( const uno::Any& aIndex ) throw (uno::RuntimeException)
296 : : {
297 [ # # ][ # # ]: 0 : uno::Reference< XCommandBars > xCommandBars( new ScVbaCommandBars( this, mxContext, uno::Reference< container::XIndexAccess >(), getCurrentDocument() ) );
[ # # ][ # # ]
[ # # ]
298 [ # # ]: 0 : if( aIndex.hasValue() )
299 [ # # ][ # # ]: 0 : return uno::makeAny( xCommandBars->Item( aIndex, uno::Any() ) );
[ # # ]
300 [ # # ]: 0 : return uno::makeAny( xCommandBars );
301 : : }
302 : :
303 : : ::rtl::OUString SAL_CALL
304 : 0 : VbaApplicationBase::getVersion() throw (uno::RuntimeException)
305 : : {
306 : 0 : return rtl::OUString(OFFICEVERSION);
307 : : }
308 : :
309 : 0 : uno::Any SAL_CALL VbaApplicationBase::Run( const ::rtl::OUString& MacroName, const uno::Any& varg1, const uno::Any& varg2, const uno::Any& varg3, const uno::Any& varg4, const uno::Any& varg5, const uno::Any& varg6, const uno::Any& varg7, const uno::Any& varg8, const uno::Any& varg9, const uno::Any& varg10, const uno::Any& varg11, const uno::Any& varg12, const uno::Any& varg13, const uno::Any& varg14, const uno::Any& varg15, const uno::Any& varg16, const uno::Any& varg17, const uno::Any& varg18, const uno::Any& varg19, const uno::Any& varg20, const uno::Any& varg21, const uno::Any& varg22, const uno::Any& varg23, const uno::Any& varg24, const uno::Any& varg25, const uno::Any& varg26, const uno::Any& varg27, const uno::Any& varg28, const uno::Any& varg29, const uno::Any& varg30 ) throw (uno::RuntimeException)
310 : : {
311 : 0 : ::rtl::OUString aMacroName = MacroName.trim();
312 [ # # ]: 0 : if (0 == aMacroName.indexOf('!'))
313 : 0 : aMacroName = aMacroName.copy(1).trim();
314 : :
315 : 0 : uno::Reference< frame::XModel > xModel;
316 [ # # ]: 0 : SbMethod* pMeth = StarBASIC::GetActiveMethod();
317 [ # # ]: 0 : if ( pMeth )
318 : : {
319 [ # # ][ # # ]: 0 : SbModule* pMod = dynamic_cast< SbModule* >( pMeth->GetParent() );
320 [ # # ]: 0 : if ( pMod )
321 [ # # ][ # # ]: 0 : xModel = StarBASIC::GetModelFromBasic( pMod );
322 : : }
323 : :
324 [ # # ]: 0 : if ( !xModel.is() )
325 [ # # ][ # # ]: 0 : xModel = getCurrentDocument();
326 : :
327 [ # # ][ # # ]: 0 : MacroResolvedInfo aMacroInfo = resolveVBAMacro( getSfxObjShell( xModel ), aMacroName );
328 [ # # ]: 0 : if( aMacroInfo.mbFound )
329 : : {
330 : : // handle the arguments
331 : 0 : const uno::Any* aArgsPtrArray[] = { &varg1, &varg2, &varg3, &varg4, &varg5, &varg6, &varg7, &varg8, &varg9, &varg10, &varg11, &varg12, &varg13, &varg14, &varg15, &varg16, &varg17, &varg18, &varg19, &varg20, &varg21, &varg22, &varg23, &varg24, &varg25, &varg26, &varg27, &varg28, &varg29, &varg30 };
332 : :
333 : 0 : int nArg = sizeof( aArgsPtrArray ) / sizeof( aArgsPtrArray[0] );
334 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs( nArg );
335 : :
336 : 0 : const uno::Any** pArg = aArgsPtrArray;
337 : 0 : const uno::Any** pArgEnd = ( aArgsPtrArray + nArg );
338 : :
339 : 0 : sal_Int32 nArgProcessed = 0;
340 : :
341 [ # # ]: 0 : for ( ; pArg != pArgEnd; ++pArg, ++nArgProcessed )
342 [ # # ]: 0 : aArgs[ nArgProcessed ] = **pArg;
343 : :
344 : : // resize array to position of last param with value
345 [ # # ]: 0 : aArgs.realloc( nArgProcessed + 1 );
346 : :
347 : 0 : uno::Any aRet;
348 : 0 : uno::Any aDummyCaller;
349 [ # # ]: 0 : executeMacro( aMacroInfo.mpDocContext, aMacroInfo.msResolvedMacro, aArgs, aRet, aDummyCaller );
350 : :
351 [ # # ]: 0 : return aRet;
352 : : }
353 : : else
354 : : {
355 [ # # ]: 0 : throw uno::RuntimeException( rtl::OUString( "The macro doesn't exist" ), uno::Reference< uno::XInterface >() );
356 [ # # ]: 0 : }
357 : : }
358 : :
359 : 0 : void SAL_CALL VbaApplicationBase::OnTime( const uno::Any& aEarliestTime, const ::rtl::OUString& aFunction, const uno::Any& aLatestTime, const uno::Any& aSchedule )
360 : : throw ( uno::RuntimeException )
361 : : {
362 [ # # ]: 0 : if ( aFunction.isEmpty() )
363 [ # # ]: 0 : throw uno::RuntimeException( ::rtl::OUString( "Unexpected function name!" ), uno::Reference< uno::XInterface >() );
364 : :
365 : 0 : double nEarliestTime = 0;
366 : 0 : double nLatestTime = 0;
367 [ # # # # : 0 : if ( !( aEarliestTime >>= nEarliestTime )
# # ][ # # ]
368 : 0 : || ( aLatestTime.hasValue() && !( aLatestTime >>= nLatestTime ) ) )
369 [ # # ]: 0 : throw uno::RuntimeException( ::rtl::OUString( "Only double is supported as time for now!" ), uno::Reference< uno::XInterface >() );
370 : :
371 : 0 : sal_Bool bSetTimer = sal_True;
372 : 0 : aSchedule >>= bSetTimer;
373 : :
374 [ # # ][ # # ]: 0 : VbaTimerInfo aTimerIndex( aFunction, ::std::pair< double, double >( nEarliestTime, nLatestTime ) );
375 : :
376 [ # # ]: 0 : VbaTimerHashMap::iterator aIter = m_pImpl->m_aTimerHash.find( aTimerIndex );
377 [ # # ][ # # ]: 0 : if ( aIter != m_pImpl->m_aTimerHash.end() )
378 : : {
379 [ # # ][ # # ]: 0 : delete aIter->second;
[ # # ]
380 [ # # ]: 0 : aIter->second = NULL;
381 [ # # ]: 0 : m_pImpl->m_aTimerHash.erase( aIter );
382 : : }
383 : :
384 [ # # ]: 0 : if ( bSetTimer )
385 : : {
386 [ # # ][ # # ]: 0 : VbaTimer* pTimer = new VbaTimer;
387 [ # # ]: 0 : m_pImpl->m_aTimerHash[ aTimerIndex ] = pTimer;
388 [ # # ]: 0 : pTimer->Start( this, aFunction, nEarliestTime, nLatestTime );
389 : 0 : }
390 : 0 : }
391 : :
392 : 0 : float SAL_CALL VbaApplicationBase::CentimetersToPoints( float _Centimeters ) throw (uno::RuntimeException)
393 : : {
394 : : // i cm = 28.35 points
395 : : static const float rate = 28.35f;
396 : 0 : return ( _Centimeters * rate );
397 : : }
398 : :
399 : 0 : uno::Any SAL_CALL VbaApplicationBase::getVBE() throw (uno::RuntimeException)
400 : : {
401 : : try // return empty object on error
402 : : {
403 : : // "VBE" object does not have a parent, but pass document model to be able to determine application type
404 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs( 1 );
405 [ # # ][ # # ]: 0 : aArgs[ 0 ] <<= getCurrentDocument();
[ # # ]
406 [ # # ][ # # ]: 0 : uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW );
[ # # ]
407 [ # # ]: 0 : uno::Reference< uno::XInterface > xVBE = xServiceManager->createInstanceWithArgumentsAndContext(
408 [ # # ]: 0 : ::rtl::OUString( "ooo.vba.vbide.VBE" ), aArgs, mxContext );
409 [ # # ][ # # ]: 0 : return uno::Any( xVBE );
[ # # ]
410 : : }
411 : 0 : catch( const uno::Exception& )
412 : : {
413 : : }
414 : 0 : return uno::Any();
415 : : }
416 : :
417 : : rtl::OUString
418 : 0 : VbaApplicationBase::getServiceImplName()
419 : : {
420 : 0 : return rtl::OUString("VbaApplicationBase");
421 : : }
422 : :
423 : : uno::Sequence<rtl::OUString>
424 : 0 : VbaApplicationBase::getServiceNames()
425 : : {
426 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
427 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
428 : : {
429 : 0 : aServiceNames.realloc( 1 );
430 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( "ooo.vba.VbaApplicationBase" );
431 : : }
432 : 0 : return aServiceNames;
433 : : }
434 : :
435 : 0 : void SAL_CALL VbaApplicationBase::Undo()
436 : : throw (uno::RuntimeException)
437 : : {
438 [ # # ][ # # ]: 0 : uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW );
439 [ # # ]: 0 : dispatchRequests( xModel, ::rtl::OUString( ".uno:Undo" ) );
440 : 0 : }
441 : :
442 : 0 : void VbaApplicationBase::Quit() throw (uno::RuntimeException)
443 : : {
444 : : // need to stop basic
445 : 0 : SbMethod* pMeth = StarBASIC::GetActiveMethod();
446 [ # # ]: 0 : if ( pMeth )
447 : : {
448 [ # # ]: 0 : SbModule* pMod = dynamic_cast< SbModule* >( pMeth->GetParent() );
449 [ # # ]: 0 : if ( pMod )
450 : : {
451 [ # # ]: 0 : StarBASIC* pBasic = dynamic_cast< StarBASIC* >( pMod->GetParent() );
452 [ # # ]: 0 : if ( pBasic )
453 : 0 : pBasic->QuitAndExitApplication();
454 : : }
455 : : }
456 : 0 : }
457 : :
458 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|