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