1*efeef26fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*efeef26fSAndrew Rist * distributed with this work for additional information 6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance 9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*efeef26fSAndrew Rist * software distributed under the License is distributed on an 15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the 17*efeef26fSAndrew Rist * specific language governing permissions and limitations 18*efeef26fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*efeef26fSAndrew Rist *************************************************************/ 21*efeef26fSAndrew Rist 22*efeef26fSAndrew Rist 23cdf0e10cSrcweir #include <stdio.h> 24cdf0e10cSrcweir #include "vbaapplication.hxx" 25cdf0e10cSrcweir #include "vbadocument.hxx" 26cdf0e10cSrcweir #include <osl/file.hxx> 27cdf0e10cSrcweir #include <vbahelper/vbahelper.hxx> 28cdf0e10cSrcweir #include "vbawindow.hxx" 29cdf0e10cSrcweir #include "vbasystem.hxx" 30cdf0e10cSrcweir #include "vbaoptions.hxx" 31cdf0e10cSrcweir #include "vbaselection.hxx" 32cdf0e10cSrcweir #include "vbadocuments.hxx" 33cdf0e10cSrcweir #include "vbaaddins.hxx" 34cdf0e10cSrcweir #include "vbadialogs.hxx" 35cdf0e10cSrcweir #include <ooo/vba/word/WdEnableCancelKey.hpp> 36cdf0e10cSrcweir #include <editeng/acorrcfg.hxx> 37cdf0e10cSrcweir #include "wordvbahelper.hxx" 38cdf0e10cSrcweir #include <docsh.hxx> 39cdf0e10cSrcweir 40cdf0e10cSrcweir using namespace ::ooo; 41cdf0e10cSrcweir using namespace ::ooo::vba; 42cdf0e10cSrcweir using namespace ::com::sun::star; 43cdf0e10cSrcweir 44cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 45cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 46cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 47cdf0e10cSrcweir using ::rtl::OUString; 48cdf0e10cSrcweir 49cdf0e10cSrcweir // Enable our own join detection for Intersection and Union 50cdf0e10cSrcweir // should be more efficient than using ScRangeList::Join ( because 51cdf0e10cSrcweir // we already are testing the same things ) 52cdf0e10cSrcweir 53cdf0e10cSrcweir #define OWN_JOIN 1 54cdf0e10cSrcweir 55cdf0e10cSrcweir // #TODO is this defined somewhere else? 56cdf0e10cSrcweir #if ( defined UNX ) || ( defined OS2 ) //unix 57cdf0e10cSrcweir #define FILE_PATH_SEPERATOR "/" 58cdf0e10cSrcweir #else // windows 59cdf0e10cSrcweir #define FILE_PATH_SEPERATOR "\\" 60cdf0e10cSrcweir #endif 61cdf0e10cSrcweir 62cdf0e10cSrcweir #define EXCELVERSION "11.0" 63cdf0e10cSrcweir 64cdf0e10cSrcweir uno::Any sbxToUnoValue( SbxVariable* pVar ); 65cdf0e10cSrcweir 66cdf0e10cSrcweir SwVbaApplication::SwVbaApplication( uno::Reference<uno::XComponentContext >& xContext ): SwVbaApplication_BASE( xContext ) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir } 69cdf0e10cSrcweir 70cdf0e10cSrcweir SwVbaApplication::~SwVbaApplication() 71cdf0e10cSrcweir { 72cdf0e10cSrcweir } 73cdf0e10cSrcweir 74cdf0e10cSrcweir SfxObjectShell* SwVbaApplication::GetDocShell( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir return static_cast< SfxObjectShell* >( word::getDocShell( xModel ) ); 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir rtl::OUString SAL_CALL 80cdf0e10cSrcweir SwVbaApplication::getName() throw (uno::RuntimeException) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir static rtl::OUString appName( RTL_CONSTASCII_USTRINGPARAM("Microsoft Word" ) ); 83cdf0e10cSrcweir return appName; 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir uno::Reference< word::XDocument > SAL_CALL 87cdf0e10cSrcweir SwVbaApplication::getActiveDocument() throw (uno::RuntimeException) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir return new SwVbaDocument( this, mxContext, getCurrentDocument() ); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir uno::Reference< word::XWindow > SAL_CALL 93cdf0e10cSrcweir SwVbaApplication::getActiveWindow() throw (uno::RuntimeException) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir // #FIXME sofar can't determine Parent 96cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_SET_THROW ); 97cdf0e10cSrcweir uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW ); 98cdf0e10cSrcweir return new SwVbaWindow( uno::Reference< XHelperInterface >(), mxContext, xModel, xController ); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir uno::Reference<word::XSystem > SAL_CALL 102cdf0e10cSrcweir SwVbaApplication::getSystem() throw (uno::RuntimeException) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir return uno::Reference< word::XSystem >( new SwVbaSystem( mxContext ) ); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir uno::Reference<word::XOptions > SAL_CALL 108cdf0e10cSrcweir SwVbaApplication::getOptions() throw (uno::RuntimeException) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir return uno::Reference< word::XOptions >( new SwVbaOptions( mxContext ) ); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir uno::Any SAL_CALL 114cdf0e10cSrcweir SwVbaApplication::CommandBars( const uno::Any& aIndex ) throw (uno::RuntimeException) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir return VbaApplicationBase::CommandBars( aIndex ); 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir uno::Reference< word::XSelection > SAL_CALL 120cdf0e10cSrcweir SwVbaApplication::getSelection() throw (uno::RuntimeException) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir return new SwVbaSelection( this, mxContext, getCurrentDocument() ); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir uno::Any SAL_CALL 126cdf0e10cSrcweir SwVbaApplication::Documents( const uno::Any& index ) throw (uno::RuntimeException) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir uno::Reference< XCollection > xCol( new SwVbaDocuments( this, mxContext ) ); 129cdf0e10cSrcweir if ( index.hasValue() ) 130cdf0e10cSrcweir return xCol->Item( index, uno::Any() ); 131cdf0e10cSrcweir return uno::makeAny( xCol ); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir uno::Any SAL_CALL 135cdf0e10cSrcweir SwVbaApplication::Addins( const uno::Any& index ) throw (uno::RuntimeException) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir static uno::Reference< XCollection > xCol( new SwVbaAddins( this, mxContext ) ); 138cdf0e10cSrcweir if ( index.hasValue() ) 139cdf0e10cSrcweir return xCol->Item( index, uno::Any() ); 140cdf0e10cSrcweir return uno::makeAny( xCol ); 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir uno::Any SAL_CALL 144cdf0e10cSrcweir SwVbaApplication::Dialogs( const uno::Any& index ) throw (uno::RuntimeException) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir uno::Reference< word::XDialogs > xCol( new SwVbaDialogs( this, mxContext, getCurrentDocument() )); 147cdf0e10cSrcweir if ( index.hasValue() ) 148cdf0e10cSrcweir return xCol->Item( index ); 149cdf0e10cSrcweir return uno::makeAny( xCol ); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir sal_Bool SAL_CALL SwVbaApplication::getDisplayAutoCompleteTips() throw (css::uno::RuntimeException) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir return SvxAutoCorrCfg::Get()->IsAutoTextTip(); 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir void SAL_CALL SwVbaApplication::setDisplayAutoCompleteTips( sal_Bool _displayAutoCompleteTips ) throw (css::uno::RuntimeException) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir SvxAutoCorrCfg::Get()->SetAutoTextTip( _displayAutoCompleteTips ); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir sal_Int32 SAL_CALL SwVbaApplication::getEnableCancelKey() throw (css::uno::RuntimeException) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir // the default value is wdCancelInterrupt in Word 165cdf0e10cSrcweir return word::WdEnableCancelKey::wdCancelInterrupt; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir void SAL_CALL SwVbaApplication::setEnableCancelKey( sal_Int32/* _enableCancelKey */) throw (css::uno::RuntimeException) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir // seems not supported in Writer 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir float SAL_CALL SwVbaApplication::CentimetersToPoints( float _Centimeters ) throw (uno::RuntimeException) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir return VbaApplicationBase::CentimetersToPoints( _Centimeters ); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir uno::Reference< frame::XModel > 179cdf0e10cSrcweir SwVbaApplication::getCurrentDocument() throw (css::uno::RuntimeException) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir return getCurrentWordDoc( mxContext ); 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir rtl::OUString& 185cdf0e10cSrcweir SwVbaApplication::getServiceImplName() 186cdf0e10cSrcweir { 187cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaApplication") ); 188cdf0e10cSrcweir return sImplName; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir uno::Sequence< rtl::OUString > 192cdf0e10cSrcweir SwVbaApplication::getServiceNames() 193cdf0e10cSrcweir { 194cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 195cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir aServiceNames.realloc( 1 ); 198cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Application" ) ); 199cdf0e10cSrcweir } 200cdf0e10cSrcweir return aServiceNames; 201cdf0e10cSrcweir } 202