| 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 "vbaglobals.hxx" |
| 20 | #include "vbawordbasic.hxx" |
| 21 | #include <sal/log.hxx> |
| 22 | |
| 23 | #include <com/sun/star/beans/PropertyValue.hpp> |
| 24 | #include <com/sun/star/frame/XModel.hpp> |
| 25 | #include <comphelper/sequence.hxx> |
| 26 | |
| 27 | #include "vbaapplication.hxx" |
| 28 | using namespace ::com::sun::star; |
| 29 | using namespace ::com::sun::star::uno; |
| 30 | using namespace ::ooo::vba; |
| 31 | |
| 32 | SwVbaGlobals::SwVbaGlobals( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& rxContext ) : SwVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext, "WordDocumentContext" ) |
| 33 | { |
| 34 | SAL_INFO("sw.vba", "SwVbaGlobals::SwVbaGlobals()"); |
| 35 | uno::Sequence< beans::PropertyValue > aInitArgs( aArgs.hasElements() ? 2 : 1 ); |
| 36 | auto pInitArgs = aInitArgs.getArray(); |
| 37 | pInitArgs[ 0 ].Name = "Application"; |
| 38 | pInitArgs[ 0 ].Value <<= getApplication(); |
| 39 | if ( aArgs.hasElements() ) |
| 40 | { |
| 41 | pInitArgs[ 1 ].Name = "WordDocumentContext"; |
| 42 | pInitArgs[ 1 ].Value <<= getXSomethingFromArgs< frame::XModel >( aArgs, 0 ); |
| 43 | } |
| 44 | init( aInitArgs ); |
| 45 | } |
| 46 | |
| 47 | SwVbaGlobals::~SwVbaGlobals() |
| 48 | { |
| 49 | SAL_INFO("sw.vba", "SwVbaGlobals::~SwVbaGlobals"); |
| 50 | } |
| 51 | |
| 52 | // XGlobals |
| 53 | |
| 54 | uno::Reference<word::XApplication > const & |
| 55 | SwVbaGlobals::getApplication() |
| 56 | { |
| 57 | SAL_INFO("sw.vba", "In SwVbaGlobals::getApplication"); |
| 58 | if ( !mxApplication.is() ) |
| 59 | mxApplication.set( new SwVbaApplication( mxContext) ); |
| 60 | |
| 61 | return mxApplication; |
| 62 | } |
| 63 | |
| 64 | uno::Reference<word::XSystem > SAL_CALL |
| 65 | SwVbaGlobals::getSystem() |
| 66 | { |
| 67 | return getApplication()->getSystem(); |
| 68 | } |
| 69 | |
| 70 | uno::Reference< word::XDocument > SAL_CALL |
| 71 | SwVbaGlobals::getActiveDocument() |
| 72 | { |
| 73 | return getApplication()->getActiveDocument(); |
| 74 | } |
| 75 | |
| 76 | uno::Reference< word::XWindow > SAL_CALL |
| 77 | SwVbaGlobals::getActiveWindow() |
| 78 | { |
| 79 | return getApplication()->getActiveWindow(); |
| 80 | } |
| 81 | |
| 82 | OUString SAL_CALL |
| 83 | SwVbaGlobals::getName() |
| 84 | { |
| 85 | return getApplication()->getName(); |
| 86 | } |
| 87 | |
| 88 | uno::Reference<word::XOptions > SAL_CALL |
| 89 | SwVbaGlobals::getOptions() |
| 90 | { |
| 91 | return getApplication()->getOptions(); |
| 92 | } |
| 93 | |
| 94 | uno::Any SAL_CALL |
| 95 | SwVbaGlobals::CommandBars( const uno::Any& aIndex ) |
| 96 | { |
| 97 | return getApplication()->CommandBars( aIndex ); |
| 98 | } |
| 99 | |
| 100 | uno::Any SAL_CALL |
| 101 | SwVbaGlobals::Documents( const uno::Any& index ) |
| 102 | { |
| 103 | return getApplication()->Documents( index ); |
| 104 | } |
| 105 | |
| 106 | uno::Any SAL_CALL |
| 107 | SwVbaGlobals::Addins( const uno::Any& index ) |
| 108 | { |
| 109 | return getApplication()->Addins( index ); |
| 110 | } |
| 111 | |
| 112 | uno::Any SAL_CALL |
| 113 | SwVbaGlobals::Dialogs( const uno::Any& index ) |
| 114 | { |
| 115 | return getApplication()->Dialogs( index ); |
| 116 | } |
| 117 | |
| 118 | uno::Any SAL_CALL |
| 119 | SwVbaGlobals::ListGalleries( const uno::Any& index ) |
| 120 | { |
| 121 | return getApplication()->ListGalleries( index ); |
| 122 | } |
| 123 | |
| 124 | uno::Reference<word::XSelection > SAL_CALL |
| 125 | SwVbaGlobals::getSelection() |
| 126 | { |
| 127 | return getApplication()->getSelection(); |
| 128 | } |
| 129 | |
| 130 | uno::Reference<word::XGlobals> SwVbaGlobals::getWord() |
| 131 | { |
| 132 | return uno::Reference<word::XGlobals>(this); |
| 133 | } |
| 134 | |
| 135 | uno::Reference<word::XWordBasic> SAL_CALL SwVbaGlobals::getWordBasic() |
| 136 | { |
| 137 | assert(dynamic_cast<SwVbaApplication*>(getApplication().get())); |
| 138 | SwVbaApplication* pVbaApp = static_cast<SwVbaApplication*>(getApplication().get()); |
| 139 | uno::Reference<word::XWordBasic> xWB(new SwWordBasic(pVbaApp)); |
| 140 | return xWB; |
| 141 | } |
| 142 | |
| 143 | float SAL_CALL SwVbaGlobals::CentimetersToPoints( float Centimeters ) |
| 144 | { |
| 145 | return getApplication()->CentimetersToPoints( Centimeters ); |
| 146 | } |
| 147 | |
| 148 | float SAL_CALL SwVbaGlobals::PointsToCentimeters( float Points ) |
| 149 | { |
| 150 | return getApplication()->PointsToCentimeters( Points ); |
| 151 | } |
| 152 | |
| 153 | float SAL_CALL SwVbaGlobals::PixelsToPoints( float Pixels, ::sal_Bool fVertical ) |
| 154 | { |
| 155 | return getApplication()->PixelsToPoints( Pixels, fVertical ); |
| 156 | } |
| 157 | |
| 158 | float SAL_CALL SwVbaGlobals::PointsToPixels( float Points, ::sal_Bool fVertical ) |
| 159 | { |
| 160 | return getApplication()->PointsToPixels( Points, fVertical ); |
| 161 | } |
| 162 | |
| 163 | float SAL_CALL SwVbaGlobals::InchesToPoints( float Inches ) |
| 164 | { |
| 165 | return getApplication()->InchesToPoints( Inches ); |
| 166 | } |
| 167 | |
| 168 | float SAL_CALL SwVbaGlobals::PointsToInches( float Points ) |
| 169 | { |
| 170 | return getApplication()->PointsToInches( Points ); |
| 171 | } |
| 172 | |
| 173 | float SAL_CALL SwVbaGlobals::MillimetersToPoints( float Millimeters ) |
| 174 | { |
| 175 | return getApplication()->MillimetersToPoints( Millimeters ); |
| 176 | } |
| 177 | |
| 178 | float SAL_CALL SwVbaGlobals::PointsToMillimeters( float Points ) |
| 179 | { |
| 180 | return getApplication()->PointsToMillimeters( Points ); |
| 181 | } |
| 182 | |
| 183 | float SAL_CALL SwVbaGlobals::PicasToPoints( float Picas ) |
| 184 | { |
| 185 | return getApplication()->PicasToPoints( Picas ); |
| 186 | } |
| 187 | |
| 188 | float SAL_CALL SwVbaGlobals::PointsToPicas( float Points ) |
| 189 | { |
| 190 | return getApplication()->PointsToPicas( Points ); |
| 191 | } |
| 192 | |
| 193 | OUString |
| 194 | SwVbaGlobals::getServiceImplName() |
| 195 | { |
| 196 | return u"SwVbaGlobals"_ustr; |
| 197 | } |
| 198 | |
| 199 | uno::Sequence< OUString > |
| 200 | SwVbaGlobals::getServiceNames() |
| 201 | { |
| 202 | return { u"ooo.vba.word.Globals"_ustr }; |
| 203 | } |
| 204 | |
| 205 | uno::Sequence< OUString > |
| 206 | SwVbaGlobals::getAvailableServiceNames( ) |
| 207 | { |
| 208 | static const uno::Sequence<OUString> serviceNames = comphelper::concatSequences( |
| 209 | SwVbaGlobals_BASE::getAvailableServiceNames(), |
| 210 | uno::Sequence<OUString>{ u"ooo.vba.word.Document"_ustr, |
| 211 | // "ooo.vba.word.Globals", |
| 212 | // "ooo.vba.word.WrapFormat", |
| 213 | u"com.sun.star.script.vba.VBATextEventProcessor"_ustr }); |
| 214 | return serviceNames; |
| 215 | } |
| 216 | |
| 217 | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* |
| 218 | Writer_SwVbaGlobals_get_implementation( |
| 219 | css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args) |
| 220 | { |
| 221 | return cppu::acquire(new SwVbaGlobals(args, context)); |
| 222 | } |
| 223 | |
| 224 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |