LibreOffice Module sw (master) 1
vbaapplication.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column:100 -*- */
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 <com/sun/star/task/XStatusIndicatorSupplier.hpp>
21#include <com/sun/star/task/XStatusIndicator.hpp>
22#include <com/sun/star/util/thePathSettings.hpp>
23#include <com/sun/star/awt/XDevice.hpp>
24
25#include "vbaapplication.hxx"
26#include "vbadocument.hxx"
28#include <sal/log.hxx>
29#include <osl/file.hxx>
30#include <vcl/svapp.hxx>
32#include "vbawindow.hxx"
33#include "vbasystem.hxx"
34#include "vbaoptions.hxx"
35#include "vbaselection.hxx"
36#include "vbadocuments.hxx"
37#include "vbaaddins.hxx"
38#include "vbamailmerge.hxx"
39#include "vbadialogs.hxx"
40#include "vbawordbasic.hxx"
41#include <ooo/vba/XConnectionPoint.hpp>
42#include <ooo/vba/word/WdEnableCancelKey.hpp>
43#include <ooo/vba/word/WdWindowState.hpp>
44#include <ooo/vba/word/XApplicationOutgoing.hpp>
45#include <ooo/vba/word/XBookmarks.hpp>
48#include <cppu/unotype.hxx>
49#include <editeng/acorrcfg.hxx>
50#include <swdll.hxx>
51#include <swmodule.hxx>
52#include "vbalistgalleries.hxx"
53#include <tools/urlobj.hxx>
54
55using namespace ::ooo;
56using namespace ::ooo::vba;
57using namespace ::com::sun::star;
58
59namespace {
60
61class SwVbaApplicationOutgoingConnectionPoint : public cppu::WeakImplHelper<XConnectionPoint>
62{
63private:
64 SwVbaApplication* mpApp;
65
66public:
67 SwVbaApplicationOutgoingConnectionPoint( SwVbaApplication* pApp );
68
69 // XConnectionPoint
70 sal_uInt32 SAL_CALL Advise(const uno::Reference< XSink >& Sink ) override;
71 void SAL_CALL Unadvise( sal_uInt32 Cookie ) override;
72};
73
74}
75
76SwVbaApplication::SwVbaApplication( uno::Reference<uno::XComponentContext >& xContext ):
77 SwVbaApplication_BASE( xContext )
78{
79}
80
82{
83}
84
85sal_uInt32
86SwVbaApplication::AddSink( const uno::Reference< XSink >& xSink )
87{
88 {
89 SolarMutexGuard aGuard;
91 }
92 // No harm in potentially calling this several times
93 SW_MOD()->RegisterAutomationApplicationEventsCaller( uno::Reference< XSinkCaller >(this) );
94 mvSinks.push_back(xSink);
95 return mvSinks.size();
96}
97
98void
99SwVbaApplication::RemoveSink( sal_uInt32 nNumber )
100{
101 if (nNumber < 1 || nNumber > mvSinks.size())
102 return;
103
104 mvSinks[nNumber-1] = uno::Reference< XSink >();
105}
106
107OUString SAL_CALL
109{
110 return "Microsoft Word";
111}
112
113uno::Reference< word::XDocument > SAL_CALL
115{
116 return new SwVbaDocument( this, mxContext, getCurrentDocument() );
117}
118
121{
122 // #FIXME so far can't determine Parent
123 uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_SET_THROW );
124 uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW );
125 return new SwVbaWindow( uno::Reference< XHelperInterface >(), mxContext, xModel, xController );
126}
127
128uno::Reference< css::uno::XComponentContext > const &
130{
131 return mxContext;
132}
133
134uno::Reference< word::XWindow > SAL_CALL
136{
137 return getActiveSwVbaWindow();
138}
139
140uno::Reference<word::XSystem > SAL_CALL
142{
143 return uno::Reference< word::XSystem >( new SwVbaSystem( mxContext ) );
144}
145
146uno::Reference<word::XOptions > SAL_CALL
148{
149 return uno::Reference< word::XOptions >( new SwVbaOptions( mxContext ) );
150}
151
152uno::Any SAL_CALL
154{
155 try
156 {
158 }
159 catch (const uno::RuntimeException&)
160 {
161 return uno::Any();
162 }
163}
164
165uno::Reference< word::XSelection > SAL_CALL
167{
168 return new SwVbaSelection( this, mxContext, getCurrentDocument() );
169}
170
171uno::Reference< word::XWordBasic > SAL_CALL
173{
174 uno::Reference< word::XWordBasic > xWB( new SwWordBasic( this ) );
175 return xWB;
176}
177
178uno::Any SAL_CALL
180{
181 uno::Reference< XCollection > xCol( new SwVbaDocuments( this, mxContext ) );
182 if ( index.hasValue() )
183 return xCol->Item( index, uno::Any() );
184 return uno::Any( xCol );
185}
186
187uno::Any SAL_CALL
189{
190 static uno::Reference< XCollection > xCol( new SwVbaAddins( this, mxContext ) );
191 if ( index.hasValue() )
192 return xCol->Item( index, uno::Any() );
193 return uno::Any( xCol );
194}
195
196uno::Any SAL_CALL
198{
199 uno::Reference< word::XDialogs > xCol( new SwVbaDialogs( this, mxContext, getCurrentDocument() ));
200 if ( index.hasValue() )
201 return xCol->Item( index );
202 return uno::Any( xCol );
203}
204
205uno::Any SAL_CALL
207{
208 uno::Reference< text::XTextDocument > xTextDoc( getCurrentDocument(), uno::UNO_QUERY_THROW );
209 uno::Reference< XCollection > xCol( new SwVbaListGalleries( this, mxContext, xTextDoc ) );
210 if ( index.hasValue() )
211 return xCol->Item( index, uno::Any() );
212 return uno::Any( xCol );
213}
214
216{
218}
219
220void SAL_CALL SwVbaApplication::setDisplayAutoCompleteTips( sal_Bool _displayAutoCompleteTips )
221{
222 SvxAutoCorrCfg::Get().SetAutoTextTip( _displayAutoCompleteTips );
223}
224
226{
227 // the default value is wdCancelInterrupt in Word
228 return word::WdEnableCancelKey::wdCancelInterrupt;
229}
230
231void SAL_CALL SwVbaApplication::setEnableCancelKey( sal_Int32/* _enableCancelKey */)
232{
233 // seems not supported in Writer
234}
235
237{
238 auto xWindow = getActiveWindow();
239 if (xWindow.is())
240 {
241 uno::Any aState = xWindow->getWindowState();
242 sal_Int32 nState;
243 if (aState >>= nState)
244 return nState;
245 }
246
247 return word::WdWindowState::wdWindowStateNormal; // ?
248}
249
250void SAL_CALL SwVbaApplication::setWindowState( sal_Int32 _windowstate )
251{
252 try
253 {
254 auto xWindow = getActiveWindow();
255 if (xWindow.is())
256 {
257 uno::Any aState;
258 aState <<= _windowstate;
259 xWindow->setWindowState( aState );
260 }
261 }
262 catch (const uno::RuntimeException&)
263 {
264 }
265}
266
267sal_Int32 SAL_CALL SwVbaApplication::getWidth()
268{
269 auto pWindow = getActiveSwVbaWindow();
270 return pWindow->getWidth();
271}
272
273void SAL_CALL SwVbaApplication::setWidth( sal_Int32 _width )
274{
275 auto pWindow = getActiveSwVbaWindow();
276 pWindow->setWidth( _width );
277}
278
279sal_Int32 SAL_CALL SwVbaApplication::getHeight()
280{
281 auto pWindow = getActiveSwVbaWindow();
282 return pWindow->getHeight();
283}
284
285void SAL_CALL SwVbaApplication::setHeight( sal_Int32 _height )
286{
287 auto pWindow = getActiveSwVbaWindow();
288 pWindow->setHeight( _height );
289}
290
291sal_Int32 SAL_CALL SwVbaApplication::getLeft()
292{
293 auto pWindow = getActiveSwVbaWindow();
294 return pWindow->getLeft();
295}
296
297void SAL_CALL SwVbaApplication::setLeft( sal_Int32 _left )
298{
299 auto pWindow = getActiveSwVbaWindow();
300 pWindow->setLeft( _left );
301}
302
303sal_Int32 SAL_CALL SwVbaApplication::getTop()
304{
305 auto pWindow = getActiveSwVbaWindow();
306 return pWindow->getTop();
307}
308
309void SAL_CALL SwVbaApplication::setTop( sal_Int32 _top )
310{
311 auto pWindow = getActiveSwVbaWindow();
312 pWindow->setTop( _top );
313}
314
316{
317 return "";
318}
319
321{
322 return uno::Any(); // ???
323}
324
325void SAL_CALL SwVbaApplication::setCustomizationContext(const uno::Any& /*_customizationcontext*/)
326{
327 // ???
328}
329
330void SAL_CALL SwVbaApplication::setStatusBar( const OUString& _statusbar )
331{
332 // ScVbaAppSettings::setStatusBar() also uses the XStatusIndicator to show this, so maybe that is OK?
333 uno::Reference< frame::XModel > xModel = getCurrentDocument();
334 if (xModel.is())
335 {
336 uno::Reference< task::XStatusIndicatorSupplier > xStatusIndicatorSupplier( xModel->getCurrentController(), uno::UNO_QUERY );
337 if (xStatusIndicatorSupplier.is())
338 {
339 uno::Reference< task::XStatusIndicator > xStatusIndicator = xStatusIndicatorSupplier->getStatusIndicator();
340 if (xStatusIndicator.is())
341 xStatusIndicator->start( _statusbar, 100 );
342 }
343 }
344
345 // Yes, we intentionally use the "extensions.olebridge" tag here even if this is sw. We
346 // interpret setting the StatusBar property as a request from an Automation client to display
347 // the string in LibreOffice's debug output, and all other generic Automation support debug
348 // output (in extensions/source/ole) uses that tag. If the check for "cross-module" or mixed log
349 // areas in compilerplugins/clang/sallogareas.cxx is re-activated, this will have to be added as
350 // a special case.
351
352 SAL_INFO("extensions.olebridge", "Client debug output: " << _statusbar);
353}
354
355float SAL_CALL SwVbaApplication::CentimetersToPoints( float Centimeters )
356{
357 return o3tl::convert(Centimeters, o3tl::Length::cm, o3tl::Length::pt);
358}
359
361{
363}
364
365float SAL_CALL SwVbaApplication::PixelsToPoints( float Pixels, ::sal_Bool fVertical )
366{
367 //Set up xDevice
368 uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_SET_THROW );
369 uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW );
370 uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_SET_THROW );
371 uno::Reference< awt::XWindow > xWindow( xFrame->getContainerWindow(), uno::UNO_SET_THROW );
372 css::uno::Reference< css::awt::XDevice > xDevice( xWindow, css::uno::UNO_QUERY );
373
374 return ooo::vba::PixelsToPoints(xDevice, Pixels, fVertical);
375}
376
377float SAL_CALL SwVbaApplication::PointsToPixels( float Pixels, ::sal_Bool fVertical )
378{
379 uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_SET_THROW );
380 uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW );
381 uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_SET_THROW );
382 uno::Reference< awt::XWindow > xWindow( xFrame->getContainerWindow(), uno::UNO_SET_THROW );
383 css::uno::Reference< css::awt::XDevice > xDevice( xWindow, css::uno::UNO_QUERY );
384
385 return ooo::vba::PointsToPixels(xDevice, Pixels, fVertical);
386}
387
388float SAL_CALL SwVbaApplication::InchesToPoints( float Inches )
389{
391}
392
394{
396}
397
398float SAL_CALL SwVbaApplication::MillimetersToPoints( float Millimeters )
399{
400 return o3tl::convert(Millimeters, o3tl::Length::mm, o3tl::Length::pt);
401}
402
404{
406}
407
408float SAL_CALL SwVbaApplication::PicasToPoints( float Picas )
409{
411}
412
414{
416}
417
419{
420 // Method no longer supported in word - deprecated
421}
422
423void SAL_CALL SwVbaApplication::Resize( sal_Int32 Width, sal_Int32 Height )
424{
425 // Have to do it like this as the Width and Height are hidden away in the ooo::vba::XWindowBase
426 // which ooo::vba::word::XApplication does not inherit from. SwVbaWindow, however, does inherit
427 // from XWindowBase. Ugh.
428 auto pWindow = getActiveSwVbaWindow();
429 pWindow->setWidth( Width );
430 pWindow->setHeight( Height );
431}
432
433void SAL_CALL SwVbaApplication::Move( sal_Int32 Left, sal_Int32 Top )
434{
435 // See comment in Resize().
436 auto pWindow = getActiveSwVbaWindow();
437 pWindow->setLeft( Left );
438 pWindow->setTop( Top );
439}
440
441// XInterfaceWithIID
442
443OUString SAL_CALL
445{
446 return "{82154421-0FBF-11d4-8313-005004526AB4}";
447}
448
449// XConnectable
450
451OUString SAL_CALL
453{
454 return "{82154423-0FBF-11D4-8313-005004526AB4}";
455}
456
457TypeAndIID SAL_CALL
459{
460 TypeAndIID aResult =
462 "{82154422-0FBF-11D4-8313-005004526AB4}"
463 };
464
465 return aResult;
466}
467
468uno::Reference<XConnectionPoint> SAL_CALL
470{
471 uno::Reference<XConnectionPoint> xCP(new SwVbaApplicationOutgoingConnectionPoint(this));
472 return xCP;
473}
474
475OUString
477{
478 return "SwVbaApplication";
479}
480
481uno::Sequence< OUString >
483{
484 static uno::Sequence< OUString > const aServiceNames
485 {
486 "ooo.vba.word.Application"
487 };
488 return aServiceNames;
489}
490
491uno::Reference< frame::XModel >
493{
495}
496
497// XSinkCaller
498
499void SAL_CALL
500SwVbaApplication::CallSinks( const OUString& Method, uno::Sequence< uno::Any >& Arguments )
501{
502 for (auto& i : mvSinks)
503 {
504 if (i.is())
505 i->Call(Method, Arguments);
506 }
507}
508
509// SwVbaApplicationOutgoingConnectionPoint
510
511SwVbaApplicationOutgoingConnectionPoint::SwVbaApplicationOutgoingConnectionPoint( SwVbaApplication* pApp ) :
512 mpApp(pApp)
513{
514}
515
516// XConnectionPoint
517sal_uInt32 SAL_CALL
518SwVbaApplicationOutgoingConnectionPoint::Advise( const uno::Reference< XSink >& Sink )
519{
520 return mpApp->AddSink(Sink);
521}
522
523void SAL_CALL
524SwVbaApplicationOutgoingConnectionPoint::Unadvise( sal_uInt32 Cookie )
525{
526 mpApp->RemoveSink( Cookie );
527}
528
529/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SvxAutoCorrCfg & Get()
bool IsAutoTextTip() const
void SetAutoTextTip(bool bSet)
virtual void SAL_CALL setHeight(sal_Int32 _height) override
virtual OUString SAL_CALL getName() override
virtual css::uno::Any SAL_CALL ListGalleries(const css::uno::Any &aIndex) override
virtual OUString getServiceImplName() override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual sal_Int32 SAL_CALL getHeight() override
virtual void SAL_CALL CallSinks(const OUString &Method, css::uno::Sequence< css::uno::Any > &Arguments) override
virtual css::uno::Reference< ooo::vba::word::XSystem > SAL_CALL getSystem() override
virtual sal_Int32 SAL_CALL getLeft() override
virtual css::uno::Any SAL_CALL Addins(const css::uno::Any &aIndex) override
virtual float SAL_CALL CentimetersToPoints(float Centimeters) override
virtual void SAL_CALL setEnableCancelKey(sal_Int32 _enableCancelKey) override
sal_uInt32 AddSink(const css::uno::Reference< ooo::vba::XSink > &xSink)
virtual sal_Int32 SAL_CALL getTop() override
virtual sal_Bool SAL_CALL getDisplayAutoCompleteTips() override
virtual css::uno::Reference< ov::word::XWindow > SAL_CALL getActiveWindow() override
virtual sal_Int32 SAL_CALL getEnableCancelKey() override
std::vector< css::uno::Reference< ooo::vba::XSink > > mvSinks
virtual OUString SAL_CALL GetIIDForClassItselfNotCoclass() override
virtual css::uno::Reference< ooo::vba::word::XOptions > SAL_CALL getOptions() override
virtual float SAL_CALL PointsToPixels(float Pixels, ::sal_Bool fVertical) override
virtual css::uno::Any SAL_CALL Documents(const css::uno::Any &aIndex) override
virtual OUString SAL_CALL getStatusBar() override
virtual void SAL_CALL setLeft(sal_Int32 _left) override
void RemoveSink(sal_uInt32 nNumber)
virtual sal_Int32 SAL_CALL getWindowState() override
virtual OUString SAL_CALL getIID() override
virtual float SAL_CALL PointsToMillimeters(float Points) override
virtual void SAL_CALL Resize(sal_Int32 Width, sal_Int32 Height) override
virtual void SAL_CALL ShowMe() override
virtual css::uno::Reference< ooo::vba::word::XSelection > SAL_CALL getSelection() override
css::uno::Reference< css::uno::XComponentContext > const & getContext() const
virtual float SAL_CALL InchesToPoints(float Inches) override
virtual float SAL_CALL PointsToInches(float Points) override
virtual float SAL_CALL PointsToCentimeters(float Points) override
virtual void SAL_CALL setCustomizationContext(const css::uno::Any &_customizationcontext) override
virtual css::uno::Reference< ov::XConnectionPoint > SAL_CALL FindConnectionPoint() override
virtual void SAL_CALL Move(sal_Int32 Left, sal_Int32 Top) override
virtual float SAL_CALL PointsToPicas(float Points) override
virtual void SAL_CALL setDisplayAutoCompleteTips(sal_Bool _displayAutoCompleteTips) override
virtual float SAL_CALL MillimetersToPoints(float Millimeters) override
virtual ov::TypeAndIID SAL_CALL GetConnectionPoint() override
virtual css::uno::Any SAL_CALL Dialogs(const css::uno::Any &aIndex) override
virtual ~SwVbaApplication() override
rtl::Reference< SwVbaWindow > getActiveSwVbaWindow()
virtual sal_Int32 SAL_CALL getWidth() override
virtual float SAL_CALL PixelsToPoints(float Pixels, ::sal_Bool fVertical) override
virtual css::uno::Any SAL_CALL CommandBars(const css::uno::Any &aIndex) override
virtual css::uno::Reference< css::frame::XModel > getCurrentDocument() override
SwVbaApplication(css::uno::Reference< css::uno::XComponentContext > &xContext)
virtual css::uno::Reference< ooo::vba::word::XWordBasic > SAL_CALL getWordBasic() override
virtual void SAL_CALL setTop(sal_Int32 _top) override
virtual float SAL_CALL PicasToPoints(float Picas) override
virtual css::uno::Reference< ov::word::XDocument > SAL_CALL getActiveDocument() override
virtual void SAL_CALL setStatusBar(const OUString &_statusbar) override
virtual css::uno::Any SAL_CALL getCustomizationContext() override
virtual void SAL_CALL setWidth(sal_Int32 _width) override
virtual void SAL_CALL setWindowState(sal_Int32 _windowstate) override
This is a representation of the WordBasic statements and functions that were available in Word versio...
virtual css::uno::Any SAL_CALL CommandBars(const css::uno::Any &aIndex) override
css::uno::Type const & get()
uno::Reference< uno::XComponentContext > mxContext
sal_Int32 nState
std::deque< AttacherIndex_Impl > aIndex
Sequence< OUString > aServiceNames
tools::SvRef< SvBaseLink > xSink
#define SAL_INFO(area, stream)
void ensure()
Definition: swdll.cxx:71
int i
index
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
double PixelsToPoints(const css::uno::Reference< css::awt::XDevice > &xDevice, double fPixels, bool bVertical)
VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentWordDoc(const css::uno::Reference< css::uno::XComponentContext > &xContext)
double PointsToPixels(const css::uno::Reference< css::awt::XDevice > &xDevice, double fPoints, bool bVertical)
std::vector< Point > Points
Reference< XController > xController
Reference< XFrame > xFrame
Reference< XModel > xModel
#define SW_MOD()
Definition: swmodule.hxx:254
Left
unsigned char sal_Bool
Method
cppu::ImplInheritanceHelper< VbaApplicationBase, ooo::vba::word::XApplication, ooo::vba::XSinkCaller > SwVbaApplication_BASE