LibreOffice Module sw (master)  1
vbaglobals.cxx
Go to the documentation of this file.
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 #include <vbahelper/helperdecl.hxx>
20 #include "service.hxx"
21 #include "vbaglobals.hxx"
22 #include <sal/macros.h>
23 #include <sal/log.hxx>
24 
25 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
26 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/frame/XModel.hpp>
29 #include <com/sun/star/container/XNameContainer.hpp>
30 #include <cppuhelper/bootstrap.hxx>
31 #include "vbaapplication.hxx"
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
34 using namespace ::ooo::vba;
35 
36 SwVbaGlobals::SwVbaGlobals( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& rxContext ) : SwVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext, "WordDocumentContext" )
37 {
38  SAL_INFO("sw.vba", "SwVbaGlobals::SwVbaGlobals()");
39  uno::Sequence< beans::PropertyValue > aInitArgs( aArgs.getLength() + 1 );
40  aInitArgs[ 0 ].Name = "Application";
41  aInitArgs[ 0 ].Value <<= getApplication();
42  if ( aArgs.hasElements() )
43  {
44  aInitArgs[ 1 ].Name = "WordDocumentContext";
45  aInitArgs[ 1 ].Value <<= getXSomethingFromArgs< frame::XModel >( aArgs, 0 );
46  }
47  init( aInitArgs );
48 }
49 
51 {
52  SAL_INFO("sw.vba", "SwVbaGlobals::~SwVbaGlobals");
53 }
54 
55 // XGlobals
56 
57 uno::Reference<word::XApplication > const &
59 {
60  SAL_INFO("sw.vba", "In SwVbaGlobals::getApplication");
61  if ( !mxApplication.is() )
62  mxApplication.set( new SwVbaApplication( mxContext) );
63 
64  return mxApplication;
65 }
66 
67 uno::Reference<word::XSystem > SAL_CALL
69 {
70  return getApplication()->getSystem();
71 }
72 
73 uno::Reference< word::XDocument > SAL_CALL
75 {
76  return getApplication()->getActiveDocument();
77 }
78 
79 uno::Reference< word::XWindow > SAL_CALL
81 {
82  return getApplication()->getActiveWindow();
83 }
84 
85 OUString SAL_CALL
87 {
88  return getApplication()->getName();
89 }
90 
91 uno::Reference<word::XOptions > SAL_CALL
93 {
94  return getApplication()->getOptions();
95 }
96 
97 uno::Any SAL_CALL
99 {
100  return getApplication()->CommandBars( aIndex );
101 }
102 
103 uno::Any SAL_CALL
105 {
106  return getApplication()->Documents( index );
107 }
108 
109 uno::Any SAL_CALL
111 {
112  return getApplication()->Addins( index );
113 }
114 
115 uno::Any SAL_CALL
117 {
118  return getApplication()->Dialogs( index );
119 }
120 
121 uno::Any SAL_CALL
123 {
124  return getApplication()->ListGalleries( index );
125 }
126 
127 uno::Reference<word::XSelection > SAL_CALL
129 {
130  return getApplication()->getSelection();
131 }
132 
133 float SAL_CALL SwVbaGlobals::CentimetersToPoints( float Centimeters )
134 {
135  return getApplication()->CentimetersToPoints( Centimeters );
136 }
137 
138 OUString
140 {
141  return "SwVbaGlobals";
142 }
143 
144 uno::Sequence< OUString >
146 {
147  static uno::Sequence< OUString > const aServiceNames
148  {
149  "ooo.vba.word.Globals"
150  };
151  return aServiceNames;
152 }
153 
154 uno::Sequence< OUString >
156 {
157  static uno::Sequence< OUString > const serviceNames = [&]()
158  {
159  uno::Sequence< OUString > tmp = SwVbaGlobals_BASE::getAvailableServiceNames();
160  tmp.realloc( tmp.getLength() + 1 );
161  tmp[ tmp.getLength() - 1 ] = "ooo.vba.word.Document";
162 // #FIXME #TODO make Application a proper service
163 // OUString( "ooo.vba.word.Application" ),
164  return tmp;
165  }();
166  return serviceNames;
167 }
168 
169 namespace globals
170 {
171 namespace sdecl = comphelper::service_decl;
174  serviceImpl,
175  "SwVbaGlobals",
176  "ooo.vba.word.Globals" );
177 }
178 
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< ov::word::XDocument > SAL_CALL getActiveDocument() override
Definition: vbaglobals.cxx:74
virtual OUString SAL_CALL getName() override
Definition: vbaglobals.cxx:86
virtual css::uno::Sequence< OUString > SAL_CALL getAvailableServiceNames() override
Definition: vbaglobals.cxx:155
Reference
sdecl::vba_service_class_< SwVbaGlobals, sdecl::with_args< true > > const serviceImpl
Definition: vbaglobals.cxx:172
virtual float SAL_CALL CentimetersToPoints(float Centimeters) override
Definition: vbaglobals.cxx:133
virtual css::uno::Any SAL_CALL Addins(const css::uno::Any &aIndex) override
Definition: vbaglobals.cxx:110
virtual css::uno::Reference< ooo::vba::word::XSelection > SAL_CALL getSelection() override
Definition: vbaglobals.cxx:128
virtual css::uno::Any SAL_CALL ListGalleries(const css::uno::Any &aIndex) override
Definition: vbaglobals.cxx:122
SwVbaGlobals(css::uno::Sequence< css::uno::Any > const &aArgs, css::uno::Reference< css::uno::XComponentContext >const &rxContext)
Definition: vbaglobals.cxx:36
css::uno::Reference< ooo::vba::word::XApplication > const & getApplication()
Definition: vbaglobals.cxx:58
virtual css::uno::Reference< ov::word::XWindow > SAL_CALL getActiveWindow() override
Definition: vbaglobals.cxx:80
virtual ~SwVbaGlobals() override
Definition: vbaglobals.cxx:50
::cppu::ImplInheritanceHelper< VbaGlobalsBase, ov::word::XGlobals > SwVbaGlobals_BASE
Definition: vbaglobals.hxx:31
virtual css::uno::Reference< ooo::vba::word::XOptions > SAL_CALL getOptions() override
Definition: vbaglobals.cxx:92
comphelper::service_decl::ServiceDecl const serviceDecl
virtual css::uno::Reference< ooo::vba::word::XSystem > SAL_CALL getSystem() override
Definition: vbaglobals.cxx:68
#define SAL_INFO(area, stream)
FILE * init(int, char **)
virtual css::uno::Any SAL_CALL CommandBars(const css::uno::Any &aIndex) override
Definition: vbaglobals.cxx:98
virtual css::uno::Any SAL_CALL Documents(const css::uno::Any &aIndex) override
Definition: vbaglobals.cxx:104
css::uno::Reference< ooo::vba::word::XApplication > mxApplication
Definition: vbaglobals.hxx:36
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbaglobals.cxx:145
virtual css::uno::Any SAL_CALL Dialogs(const css::uno::Any &aIndex) override
Definition: vbaglobals.cxx:116
virtual OUString getServiceImplName() override
Definition: vbaglobals.cxx:139