android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / vba / vbaapplication.cxx
blobd3f290db28ab7f2c2f6c92670188339958751a1c
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.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
25 #include "vbaapplication.hxx"
26 #include "vbadocument.hxx"
27 #include "vbafilterpropsfromformat.hxx"
28 #include <sal/log.hxx>
29 #include <osl/file.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vbahelper/vbahelper.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>
46 #include <comphelper/processfactory.hxx>
47 #include <comphelper/propertyvalue.hxx>
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>
55 using namespace ::ooo;
56 using namespace ::ooo::vba;
57 using namespace ::com::sun::star;
59 namespace {
61 class SwVbaApplicationOutgoingConnectionPoint : public cppu::WeakImplHelper<XConnectionPoint>
63 private:
64 SwVbaApplication* mpApp;
66 public:
67 SwVbaApplicationOutgoingConnectionPoint( SwVbaApplication* pApp );
69 // XConnectionPoint
70 sal_uInt32 SAL_CALL Advise(const uno::Reference< XSink >& Sink ) override;
71 void SAL_CALL Unadvise( sal_uInt32 Cookie ) override;
76 SwVbaApplication::SwVbaApplication( uno::Reference<uno::XComponentContext >& xContext ):
77 SwVbaApplication_BASE( xContext )
81 SwVbaApplication::~SwVbaApplication()
85 sal_uInt32
86 SwVbaApplication::AddSink( const uno::Reference< XSink >& xSink )
89 SolarMutexGuard aGuard;
90 SwGlobals::ensure();
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();
98 void
99 SwVbaApplication::RemoveSink( sal_uInt32 nNumber )
101 if (nNumber < 1 || nNumber > mvSinks.size())
102 return;
104 mvSinks[nNumber-1] = uno::Reference< XSink >();
107 OUString SAL_CALL
108 SwVbaApplication::getName()
110 return "Microsoft Word";
113 uno::Reference< word::XDocument > SAL_CALL
114 SwVbaApplication::getActiveDocument()
116 return new SwVbaDocument( this, mxContext, getCurrentDocument() );
119 rtl::Reference<SwVbaWindow>
120 SwVbaApplication::getActiveSwVbaWindow()
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 );
128 uno::Reference< css::uno::XComponentContext > const &
129 SwVbaApplication::getContext() const
131 return mxContext;
134 uno::Reference< word::XWindow > SAL_CALL
135 SwVbaApplication::getActiveWindow()
137 return getActiveSwVbaWindow();
140 uno::Reference<word::XSystem > SAL_CALL
141 SwVbaApplication::getSystem()
143 return uno::Reference< word::XSystem >( new SwVbaSystem( mxContext ) );
146 uno::Reference<word::XOptions > SAL_CALL
147 SwVbaApplication::getOptions()
149 return uno::Reference< word::XOptions >( new SwVbaOptions( mxContext ) );
152 uno::Any SAL_CALL
153 SwVbaApplication::CommandBars( const uno::Any& aIndex )
157 return VbaApplicationBase::CommandBars( aIndex );
159 catch (const uno::RuntimeException&)
161 return uno::Any();
165 uno::Reference< word::XSelection > SAL_CALL
166 SwVbaApplication::getSelection()
168 return new SwVbaSelection( this, mxContext, getCurrentDocument() );
171 uno::Reference< word::XWordBasic > SAL_CALL
172 SwVbaApplication::getWordBasic()
174 uno::Reference< word::XWordBasic > xWB( new SwWordBasic( this ) );
175 return xWB;
178 uno::Any SAL_CALL
179 SwVbaApplication::Documents( const uno::Any& index )
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 );
187 uno::Any SAL_CALL
188 SwVbaApplication::Addins( const uno::Any& index )
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 );
196 uno::Any SAL_CALL
197 SwVbaApplication::Dialogs( const uno::Any& index )
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 );
205 uno::Any SAL_CALL
206 SwVbaApplication::ListGalleries( const uno::Any& index )
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 );
215 sal_Bool SAL_CALL SwVbaApplication::getDisplayAutoCompleteTips()
217 return SvxAutoCorrCfg::Get().IsAutoTextTip();
220 void SAL_CALL SwVbaApplication::setDisplayAutoCompleteTips( sal_Bool _displayAutoCompleteTips )
222 SvxAutoCorrCfg::Get().SetAutoTextTip( _displayAutoCompleteTips );
225 sal_Int32 SAL_CALL SwVbaApplication::getEnableCancelKey()
227 // the default value is wdCancelInterrupt in Word
228 return word::WdEnableCancelKey::wdCancelInterrupt;
231 void SAL_CALL SwVbaApplication::setEnableCancelKey( sal_Int32/* _enableCancelKey */)
233 // seems not supported in Writer
236 sal_Int32 SAL_CALL SwVbaApplication::getWindowState()
238 auto xWindow = getActiveWindow();
239 if (xWindow.is())
241 uno::Any aState = xWindow->getWindowState();
242 sal_Int32 nState;
243 if (aState >>= nState)
244 return nState;
247 return word::WdWindowState::wdWindowStateNormal; // ?
250 void SAL_CALL SwVbaApplication::setWindowState( sal_Int32 _windowstate )
254 auto xWindow = getActiveWindow();
255 if (xWindow.is())
257 uno::Any aState;
258 aState <<= _windowstate;
259 xWindow->setWindowState( aState );
262 catch (const uno::RuntimeException&)
267 sal_Int32 SAL_CALL SwVbaApplication::getWidth()
269 auto pWindow = getActiveSwVbaWindow();
270 return pWindow->getWidth();
273 void SAL_CALL SwVbaApplication::setWidth( sal_Int32 _width )
275 auto pWindow = getActiveSwVbaWindow();
276 pWindow->setWidth( _width );
279 sal_Int32 SAL_CALL SwVbaApplication::getHeight()
281 auto pWindow = getActiveSwVbaWindow();
282 return pWindow->getHeight();
285 void SAL_CALL SwVbaApplication::setHeight( sal_Int32 _height )
287 auto pWindow = getActiveSwVbaWindow();
288 pWindow->setHeight( _height );
291 sal_Int32 SAL_CALL SwVbaApplication::getLeft()
293 auto pWindow = getActiveSwVbaWindow();
294 return pWindow->getLeft();
297 void SAL_CALL SwVbaApplication::setLeft( sal_Int32 _left )
299 auto pWindow = getActiveSwVbaWindow();
300 pWindow->setLeft( _left );
303 sal_Int32 SAL_CALL SwVbaApplication::getTop()
305 auto pWindow = getActiveSwVbaWindow();
306 return pWindow->getTop();
309 void SAL_CALL SwVbaApplication::setTop( sal_Int32 _top )
311 auto pWindow = getActiveSwVbaWindow();
312 pWindow->setTop( _top );
315 OUString SAL_CALL SwVbaApplication::getStatusBar()
317 return "";
320 uno::Any SAL_CALL SwVbaApplication::getCustomizationContext()
322 return uno::Any(); // ???
325 void SAL_CALL SwVbaApplication::setCustomizationContext(const uno::Any& /*_customizationcontext*/)
327 // ???
330 void SAL_CALL SwVbaApplication::setStatusBar( const OUString& _statusbar )
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())
336 uno::Reference< task::XStatusIndicatorSupplier > xStatusIndicatorSupplier( xModel->getCurrentController(), uno::UNO_QUERY );
337 if (xStatusIndicatorSupplier.is())
339 uno::Reference< task::XStatusIndicator > xStatusIndicator = xStatusIndicatorSupplier->getStatusIndicator();
340 if (xStatusIndicator.is())
341 xStatusIndicator->start( _statusbar, 100 );
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.
352 SAL_INFO("extensions.olebridge", "Client debug output: " << _statusbar);
355 float SAL_CALL SwVbaApplication::CentimetersToPoints( float Centimeters )
357 return o3tl::convert(Centimeters, o3tl::Length::cm, o3tl::Length::pt);
360 float SAL_CALL SwVbaApplication::PointsToCentimeters( float Points )
362 return o3tl::convert(Points, o3tl::Length::pt, o3tl::Length::cm);
365 float SAL_CALL SwVbaApplication::PixelsToPoints( float Pixels, ::sal_Bool fVertical )
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 );
374 return ooo::vba::PixelsToPoints(xDevice, Pixels, fVertical);
377 float SAL_CALL SwVbaApplication::PointsToPixels( float Pixels, ::sal_Bool fVertical )
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 );
385 return ooo::vba::PointsToPixels(xDevice, Pixels, fVertical);
388 float SAL_CALL SwVbaApplication::InchesToPoints( float Inches )
390 return o3tl::convert(Inches, o3tl::Length::in, o3tl::Length::pt);
393 float SAL_CALL SwVbaApplication::PointsToInches( float Points )
395 return o3tl::convert(Points, o3tl::Length::pt, o3tl::Length::in);
398 float SAL_CALL SwVbaApplication::MillimetersToPoints( float Millimeters )
400 return o3tl::convert(Millimeters, o3tl::Length::mm, o3tl::Length::pt);
403 float SAL_CALL SwVbaApplication::PointsToMillimeters( float Points )
405 return o3tl::convert(Points, o3tl::Length::pt, o3tl::Length::mm);
408 float SAL_CALL SwVbaApplication::PicasToPoints( float Picas )
410 return o3tl::convert(Picas, o3tl::Length::pc, o3tl::Length::pt);
413 float SAL_CALL SwVbaApplication::PointsToPicas( float Points )
415 return o3tl::convert(Points, o3tl::Length::pt, o3tl::Length::pc);
418 void SAL_CALL SwVbaApplication::ShowMe()
420 // Method no longer supported in word - deprecated
423 void SAL_CALL SwVbaApplication::Resize( sal_Int32 Width, sal_Int32 Height )
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 );
433 void SAL_CALL SwVbaApplication::Move( sal_Int32 Left, sal_Int32 Top )
435 // See comment in Resize().
436 auto pWindow = getActiveSwVbaWindow();
437 pWindow->setLeft( Left );
438 pWindow->setTop( Top );
441 // XInterfaceWithIID
443 OUString SAL_CALL
444 SwVbaApplication::getIID()
446 return "{82154421-0FBF-11d4-8313-005004526AB4}";
449 // XConnectable
451 OUString SAL_CALL
452 SwVbaApplication::GetIIDForClassItselfNotCoclass()
454 return "{82154423-0FBF-11D4-8313-005004526AB4}";
457 TypeAndIID SAL_CALL
458 SwVbaApplication::GetConnectionPoint()
460 TypeAndIID aResult =
461 { cppu::UnoType<word::XApplicationOutgoing>::get(),
462 "{82154422-0FBF-11D4-8313-005004526AB4}"
465 return aResult;
468 uno::Reference<XConnectionPoint> SAL_CALL
469 SwVbaApplication::FindConnectionPoint()
471 uno::Reference<XConnectionPoint> xCP(new SwVbaApplicationOutgoingConnectionPoint(this));
472 return xCP;
475 OUString
476 SwVbaApplication::getServiceImplName()
478 return "SwVbaApplication";
481 uno::Sequence< OUString >
482 SwVbaApplication::getServiceNames()
484 static uno::Sequence< OUString > const aServiceNames
486 "ooo.vba.word.Application"
488 return aServiceNames;
491 uno::Reference< frame::XModel >
492 SwVbaApplication::getCurrentDocument()
494 return getCurrentWordDoc( mxContext );
497 // XSinkCaller
499 void SAL_CALL
500 SwVbaApplication::CallSinks( const OUString& Method, uno::Sequence< uno::Any >& Arguments )
502 for (auto& i : mvSinks)
504 if (i.is())
505 i->Call(Method, Arguments);
509 // SwVbaApplicationOutgoingConnectionPoint
511 SwVbaApplicationOutgoingConnectionPoint::SwVbaApplicationOutgoingConnectionPoint( SwVbaApplication* pApp ) :
512 mpApp(pApp)
516 // XConnectionPoint
517 sal_uInt32 SAL_CALL
518 SwVbaApplicationOutgoingConnectionPoint::Advise( const uno::Reference< XSink >& Sink )
520 return mpApp->AddSink(Sink);
523 void SAL_CALL
524 SwVbaApplicationOutgoingConnectionPoint::Unadvise( sal_uInt32 Cookie )
526 mpApp->RemoveSink( Cookie );
529 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */