1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #include <stdio.h> 28 #include "vbaapplication.hxx" 29 #include "vbadocument.hxx" 30 #include <osl/file.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 "vbadialogs.hxx" 39 #include <ooo/vba/word/WdEnableCancelKey.hpp> 40 #include <editeng/acorrcfg.hxx> 41 #include "wordvbahelper.hxx" 42 #include <docsh.hxx> 43 44 using namespace ::ooo; 45 using namespace ::ooo::vba; 46 using namespace ::com::sun::star; 47 48 using ::com::sun::star::uno::Reference; 49 using ::com::sun::star::uno::UNO_QUERY_THROW; 50 using ::com::sun::star::uno::UNO_QUERY; 51 using ::rtl::OUString; 52 53 // Enable our own join detection for Intersection and Union 54 // should be more efficient than using ScRangeList::Join ( because 55 // we already are testing the same things ) 56 57 #define OWN_JOIN 1 58 59 // #TODO is this defined somewhere else? 60 #if ( defined UNX ) || ( defined OS2 ) //unix 61 #define FILE_PATH_SEPERATOR "/" 62 #else // windows 63 #define FILE_PATH_SEPERATOR "\\" 64 #endif 65 66 #define EXCELVERSION "11.0" 67 68 uno::Any sbxToUnoValue( SbxVariable* pVar ); 69 70 SwVbaApplication::SwVbaApplication( uno::Reference<uno::XComponentContext >& xContext ): SwVbaApplication_BASE( xContext ) 71 { 72 } 73 74 SwVbaApplication::~SwVbaApplication() 75 { 76 } 77 78 SfxObjectShell* SwVbaApplication::GetDocShell( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) 79 { 80 return static_cast< SfxObjectShell* >( word::getDocShell( xModel ) ); 81 } 82 83 rtl::OUString SAL_CALL 84 SwVbaApplication::getName() throw (uno::RuntimeException) 85 { 86 static rtl::OUString appName( RTL_CONSTASCII_USTRINGPARAM("Microsoft Word" ) ); 87 return appName; 88 } 89 90 uno::Reference< word::XDocument > SAL_CALL 91 SwVbaApplication::getActiveDocument() throw (uno::RuntimeException) 92 { 93 return new SwVbaDocument( this, mxContext, getCurrentDocument() ); 94 } 95 96 uno::Reference< word::XWindow > SAL_CALL 97 SwVbaApplication::getActiveWindow() throw (uno::RuntimeException) 98 { 99 // #FIXME sofar can't determine Parent 100 uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_SET_THROW ); 101 uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW ); 102 return new SwVbaWindow( uno::Reference< XHelperInterface >(), mxContext, xModel, xController ); 103 } 104 105 uno::Reference<word::XSystem > SAL_CALL 106 SwVbaApplication::getSystem() throw (uno::RuntimeException) 107 { 108 return uno::Reference< word::XSystem >( new SwVbaSystem( mxContext ) ); 109 } 110 111 uno::Reference<word::XOptions > SAL_CALL 112 SwVbaApplication::getOptions() throw (uno::RuntimeException) 113 { 114 return uno::Reference< word::XOptions >( new SwVbaOptions( mxContext ) ); 115 } 116 117 uno::Any SAL_CALL 118 SwVbaApplication::CommandBars( const uno::Any& aIndex ) throw (uno::RuntimeException) 119 { 120 return VbaApplicationBase::CommandBars( aIndex ); 121 } 122 123 uno::Reference< word::XSelection > SAL_CALL 124 SwVbaApplication::getSelection() throw (uno::RuntimeException) 125 { 126 return new SwVbaSelection( this, mxContext, getCurrentDocument() ); 127 } 128 129 uno::Any SAL_CALL 130 SwVbaApplication::Documents( const uno::Any& index ) throw (uno::RuntimeException) 131 { 132 uno::Reference< XCollection > xCol( new SwVbaDocuments( this, mxContext ) ); 133 if ( index.hasValue() ) 134 return xCol->Item( index, uno::Any() ); 135 return uno::makeAny( xCol ); 136 } 137 138 uno::Any SAL_CALL 139 SwVbaApplication::Addins( const uno::Any& index ) throw (uno::RuntimeException) 140 { 141 static uno::Reference< XCollection > xCol( new SwVbaAddins( this, mxContext ) ); 142 if ( index.hasValue() ) 143 return xCol->Item( index, uno::Any() ); 144 return uno::makeAny( xCol ); 145 } 146 147 uno::Any SAL_CALL 148 SwVbaApplication::Dialogs( const uno::Any& index ) throw (uno::RuntimeException) 149 { 150 uno::Reference< word::XDialogs > xCol( new SwVbaDialogs( this, mxContext, getCurrentDocument() )); 151 if ( index.hasValue() ) 152 return xCol->Item( index ); 153 return uno::makeAny( xCol ); 154 } 155 156 sal_Bool SAL_CALL SwVbaApplication::getDisplayAutoCompleteTips() throw (css::uno::RuntimeException) 157 { 158 return SvxAutoCorrCfg::Get()->IsAutoTextTip(); 159 } 160 161 void SAL_CALL SwVbaApplication::setDisplayAutoCompleteTips( sal_Bool _displayAutoCompleteTips ) throw (css::uno::RuntimeException) 162 { 163 SvxAutoCorrCfg::Get()->SetAutoTextTip( _displayAutoCompleteTips ); 164 } 165 166 sal_Int32 SAL_CALL SwVbaApplication::getEnableCancelKey() throw (css::uno::RuntimeException) 167 { 168 // the default value is wdCancelInterrupt in Word 169 return word::WdEnableCancelKey::wdCancelInterrupt; 170 } 171 172 void SAL_CALL SwVbaApplication::setEnableCancelKey( sal_Int32/* _enableCancelKey */) throw (css::uno::RuntimeException) 173 { 174 // seems not supported in Writer 175 } 176 177 float SAL_CALL SwVbaApplication::CentimetersToPoints( float _Centimeters ) throw (uno::RuntimeException) 178 { 179 return VbaApplicationBase::CentimetersToPoints( _Centimeters ); 180 } 181 182 uno::Reference< frame::XModel > 183 SwVbaApplication::getCurrentDocument() throw (css::uno::RuntimeException) 184 { 185 return getCurrentWordDoc( mxContext ); 186 } 187 188 rtl::OUString& 189 SwVbaApplication::getServiceImplName() 190 { 191 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaApplication") ); 192 return sImplName; 193 } 194 195 uno::Sequence< rtl::OUString > 196 SwVbaApplication::getServiceNames() 197 { 198 static uno::Sequence< rtl::OUString > aServiceNames; 199 if ( aServiceNames.getLength() == 0 ) 200 { 201 aServiceNames.realloc( 1 ); 202 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Application" ) ); 203 } 204 return aServiceNames; 205 } 206