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 "vbaoptions.hxx" 28 #include <vbahelper/vbahelper.hxx> 29 #include <ooo/vba/word/WdDefaultFilePath.hpp> 30 #include <ooo/vba/word/WdLineStyle.hpp> 31 #include <ooo/vba/word/WdLineWidth.hpp> 32 #include <ooo/vba/word/WdColorIndex.hpp> 33 #include <com/sun/star/util/XStringSubstitution.hpp> 34 #include <com/sun/star/beans/XPropertySet.hpp> 35 #include <osl/file.hxx> 36 37 using namespace ::ooo::vba; 38 using namespace ::com::sun::star; 39 40 SwVbaOptions::SwVbaOptions( uno::Reference<uno::XComponentContext >& xContext ) throw ( uno::RuntimeException ) : SwVbaOptions_BASE( uno::Reference< XHelperInterface >(), xContext ) 41 { 42 mxFactory.set( comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); 43 } 44 45 SwVbaOptions::~SwVbaOptions() 46 { 47 } 48 49 uno::Any SAL_CALL 50 SwVbaOptions::DefaultFilePath( sal_Int32 _path ) throw ( uno::RuntimeException ) 51 { 52 switch( _path ) 53 { 54 case word::WdDefaultFilePath::wdDocumentsPath: 55 { 56 msDefaultFilePath = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Work") ); 57 break; 58 } 59 case word::WdDefaultFilePath::wdPicturesPath: 60 { 61 msDefaultFilePath = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Gallery") ); 62 break; 63 } 64 case word::WdDefaultFilePath::wdUserTemplatesPath: 65 case word::WdDefaultFilePath::wdWorkgroupTemplatesPath: 66 { 67 msDefaultFilePath = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Template") ); 68 break; 69 } 70 case word::WdDefaultFilePath::wdStartupPath: 71 { 72 msDefaultFilePath = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Addin") ); 73 break; 74 } 75 case word::WdDefaultFilePath::wdUserOptionsPath: 76 { 77 msDefaultFilePath = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UserConfig") ); 78 break; 79 } 80 case word::WdDefaultFilePath::wdToolsPath: 81 case word::WdDefaultFilePath::wdProgramPath: 82 { 83 msDefaultFilePath = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Module") ); 84 break; 85 } 86 case word::WdDefaultFilePath::wdTempFilePath: 87 { 88 msDefaultFilePath = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Temp") ); 89 break; 90 } 91 default: 92 { 93 DebugHelper::exception( SbERR_NOT_IMPLEMENTED, rtl::OUString() ); 94 break; 95 } 96 } 97 return uno::makeAny( uno::Reference< XPropValue > ( new ScVbaPropValue( this ) ) ); 98 } 99 100 void SwVbaOptions::setValueEvent( const uno::Any& value ) 101 { 102 rtl::OUString sNewPath; 103 value >>= sNewPath; 104 rtl::OUString sNewPathUrl; 105 ::osl::File::getFileURLFromSystemPath( sNewPath, sNewPathUrl ); 106 uno::Reference< beans::XPropertySet > xPathSettings( mxFactory->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.PathSettings") ), uno::UNO_QUERY_THROW ); 107 rtl::OUString sOldPathUrl; 108 xPathSettings->getPropertyValue( msDefaultFilePath ) >>= sOldPathUrl; 109 // path could be a multipath, Microsoft doesn't support this feature in Word currently 110 // only the last path is from interest. 111 sal_Int32 nIndex = sOldPathUrl.lastIndexOf( sal_Unicode(';') ); 112 if( nIndex != -1 ) 113 { 114 sNewPathUrl = sOldPathUrl.copy( 0, nIndex + 1 ).concat( sNewPathUrl ); 115 } 116 xPathSettings->setPropertyValue( msDefaultFilePath, uno::makeAny( sNewPathUrl ) ); 117 } 118 119 uno::Any SwVbaOptions::getValueEvent() 120 { 121 uno::Reference< beans::XPropertySet > xPathSettings( mxFactory->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.PathSettings") ), uno::UNO_QUERY_THROW ); 122 rtl::OUString sPathUrl; 123 xPathSettings->getPropertyValue( msDefaultFilePath ) >>= sPathUrl; 124 // path could be a multipath, Microsoft doesn't support this feature in Word currently 125 // only the last path is from interest. 126 sal_Int32 nIndex = sPathUrl.lastIndexOf( sal_Unicode(';') ); 127 if( nIndex != -1 ) 128 { 129 sPathUrl = sPathUrl.copy( nIndex + 1 ); 130 } 131 rtl::OUString sPath; 132 ::osl::File::getSystemPathFromFileURL( sPathUrl, sPath ); 133 return uno::makeAny( sPath ); 134 } 135 136 sal_Int32 SAL_CALL SwVbaOptions::getDefaultBorderLineStyle() throw (uno::RuntimeException) 137 { 138 return word::WdLineStyle::wdLineStyleSingle; 139 } 140 141 void SAL_CALL SwVbaOptions::setDefaultBorderLineStyle( ::sal_Int32 /*_defaultborderlinestyle*/ ) throw (uno::RuntimeException) 142 { 143 // not support in Writer 144 } 145 146 sal_Int32 SAL_CALL SwVbaOptions::getDefaultBorderLineWidth() throw (uno::RuntimeException) 147 { 148 return word::WdLineWidth::wdLineWidth050pt; 149 } 150 151 void SAL_CALL SwVbaOptions::setDefaultBorderLineWidth( ::sal_Int32 /*_defaultborderlinewidth*/ ) throw (uno::RuntimeException) 152 { 153 // not support in Writer 154 } 155 156 sal_Int32 SAL_CALL SwVbaOptions::getDefaultBorderColorIndex() throw (uno::RuntimeException) 157 { 158 return word::WdColorIndex::wdAuto; 159 } 160 161 void SAL_CALL SwVbaOptions::setDefaultBorderColorIndex( ::sal_Int32 /*_defaultbordercolorindex*/ ) throw (uno::RuntimeException) 162 { 163 // not support in Writer 164 } 165 166 ::sal_Bool SAL_CALL SwVbaOptions::getReplaceSelection() throw (uno::RuntimeException) 167 { 168 return sal_True; 169 } 170 171 void SAL_CALL SwVbaOptions::setReplaceSelection( ::sal_Bool /*_replaceselection*/ ) throw (uno::RuntimeException) 172 { 173 // not support in Writer 174 } 175 176 ::sal_Bool SAL_CALL SwVbaOptions::getMapPaperSize() throw (uno::RuntimeException) 177 { 178 return sal_False; 179 } 180 181 void SAL_CALL SwVbaOptions::setMapPaperSize( ::sal_Bool /*_mappapersize*/ ) throw (uno::RuntimeException) 182 { 183 // not support in Writer 184 } 185 186 ::sal_Bool SAL_CALL SwVbaOptions::getAutoFormatAsYouTypeApplyHeadings() throw (uno::RuntimeException) 187 { 188 return sal_False; 189 } 190 191 void SAL_CALL SwVbaOptions::setAutoFormatAsYouTypeApplyHeadings( ::sal_Bool /*_autoformatasyoutypeapplyheadings*/ ) throw (uno::RuntimeException) 192 { 193 // not support in Writer 194 } 195 196 ::sal_Bool SAL_CALL SwVbaOptions::getAutoFormatAsYouTypeApplyBulletedLists() throw (uno::RuntimeException) 197 { 198 return sal_False; 199 } 200 201 void SAL_CALL SwVbaOptions::setAutoFormatAsYouTypeApplyBulletedLists( ::sal_Bool /*_autoformatasyoutypeapplybulletedlists*/ ) throw (uno::RuntimeException) 202 { 203 // not support in Writer 204 } 205 206 ::sal_Bool SAL_CALL SwVbaOptions::getAutoFormatAsYouTypeApplyNumberedLists() throw (uno::RuntimeException) 207 { 208 return sal_False; 209 } 210 211 void SAL_CALL SwVbaOptions::setAutoFormatAsYouTypeApplyNumberedLists( ::sal_Bool /*_autoformatasyoutypeapplynumberedlists*/ ) throw (uno::RuntimeException) 212 { 213 // not support in Writer 214 } 215 216 ::sal_Bool SAL_CALL SwVbaOptions::getAutoFormatAsYouTypeFormatListItemBeginning() throw (uno::RuntimeException) 217 { 218 return sal_False; 219 } 220 221 void SAL_CALL SwVbaOptions::setAutoFormatAsYouTypeFormatListItemBeginning( ::sal_Bool /*_autoformatasyoutypeformatlistitembeginning*/ ) throw (uno::RuntimeException) 222 { 223 // not support in Writer 224 } 225 226 ::sal_Bool SAL_CALL SwVbaOptions::getAutoFormatAsYouTypeDefineStyles() throw (uno::RuntimeException) 227 { 228 return sal_False; 229 } 230 231 void SAL_CALL SwVbaOptions::setAutoFormatAsYouTypeDefineStyles( ::sal_Bool /*_autoformatasyoutypedefinestyles*/ ) throw (uno::RuntimeException) 232 { 233 // not support in Writer 234 } 235 236 ::sal_Bool SAL_CALL SwVbaOptions::getAutoFormatApplyHeadings() throw (uno::RuntimeException) 237 { 238 return sal_False; 239 } 240 241 void SAL_CALL SwVbaOptions::setAutoFormatApplyHeadings( ::sal_Bool /*_autoformatapplyheadings*/ ) throw (uno::RuntimeException) 242 { 243 // not support in Writer 244 } 245 246 ::sal_Bool SAL_CALL SwVbaOptions::getAutoFormatApplyLists() throw (uno::RuntimeException) 247 { 248 return sal_False; 249 } 250 251 void SAL_CALL SwVbaOptions::setAutoFormatApplyLists( ::sal_Bool /*_autoformatapplylists*/ ) throw (uno::RuntimeException) 252 { 253 // not support in Writer 254 } 255 256 ::sal_Bool SAL_CALL SwVbaOptions::getAutoFormatApplyBulletedLists() throw (uno::RuntimeException) 257 { 258 return sal_False; 259 } 260 261 void SAL_CALL SwVbaOptions::setAutoFormatApplyBulletedLists( ::sal_Bool /*_autoformatapplybulletedlists*/ ) throw (uno::RuntimeException) 262 { 263 // not support in Writer 264 } 265 266 267 rtl::OUString& 268 SwVbaOptions::getServiceImplName() 269 { 270 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaOptions") ); 271 return sImplName; 272 } 273 274 uno::Sequence< rtl::OUString > 275 SwVbaOptions::getServiceNames() 276 { 277 static uno::Sequence< rtl::OUString > aServiceNames; 278 if ( aServiceNames.getLength() == 0 ) 279 { 280 aServiceNames.realloc( 1 ); 281 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Options" ) ); 282 } 283 return aServiceNames; 284 } 285