1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microoptionss, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "vbaoptions.hxx"
31 #include <vbahelper/vbahelper.hxx>
32 #include <ooo/vba/word/WdDefaultFilePath.hpp>
33 #include <ooo/vba/word/WdLineStyle.hpp>
34 #include <ooo/vba/word/WdLineWidth.hpp>
35 #include <ooo/vba/word/WdColorIndex.hpp>
36 #include <com/sun/star/util/XStringSubstitution.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <osl/file.hxx>
40 using namespace ::ooo::vba
;
41 using namespace ::com::sun::star
;
43 SwVbaOptions::SwVbaOptions( uno::Reference
<uno::XComponentContext
>& xContext
) throw ( uno::RuntimeException
) : SwVbaOptions_BASE( uno::Reference
< XHelperInterface
>(), xContext
)
45 mxFactory
.set( comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW
);
48 SwVbaOptions::~SwVbaOptions()
53 SwVbaOptions::DefaultFilePath( sal_Int32 _path
) throw ( uno::RuntimeException
)
57 case word::WdDefaultFilePath::wdDocumentsPath
:
59 msDefaultFilePath
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Work") );
62 case word::WdDefaultFilePath::wdPicturesPath
:
64 msDefaultFilePath
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Gallery") );
67 case word::WdDefaultFilePath::wdUserTemplatesPath
:
68 case word::WdDefaultFilePath::wdWorkgroupTemplatesPath
:
70 msDefaultFilePath
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Template") );
73 case word::WdDefaultFilePath::wdStartupPath
:
75 msDefaultFilePath
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Addin") );
78 case word::WdDefaultFilePath::wdUserOptionsPath
:
80 msDefaultFilePath
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UserConfig") );
83 case word::WdDefaultFilePath::wdToolsPath
:
84 case word::WdDefaultFilePath::wdProgramPath
:
86 msDefaultFilePath
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Module") );
89 case word::WdDefaultFilePath::wdTempFilePath
:
91 msDefaultFilePath
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Temp") );
96 DebugHelper::exception( SbERR_NOT_IMPLEMENTED
, rtl::OUString() );
100 return uno::makeAny( uno::Reference
< XPropValue
> ( new ScVbaPropValue( this ) ) );
103 void SwVbaOptions::setValueEvent( const uno::Any
& value
)
105 rtl::OUString sNewPath
;
107 rtl::OUString sNewPathUrl
;
108 ::osl::File::getFileURLFromSystemPath( sNewPath
, sNewPathUrl
);
109 uno::Reference
< beans::XPropertySet
> xPathSettings( mxFactory
->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.PathSettings") ), uno::UNO_QUERY_THROW
);
110 rtl::OUString sOldPathUrl
;
111 xPathSettings
->getPropertyValue( msDefaultFilePath
) >>= sOldPathUrl
;
112 // path could be a multipath, Microsoft doesn't support this feature in Word currently
113 // only the last path is from interest.
114 sal_Int32 nIndex
= sOldPathUrl
.lastIndexOf( sal_Unicode(';') );
117 sNewPathUrl
= sOldPathUrl
.copy( 0, nIndex
+ 1 ).concat( sNewPathUrl
);
119 xPathSettings
->setPropertyValue( msDefaultFilePath
, uno::makeAny( sNewPathUrl
) );
122 uno::Any
SwVbaOptions::getValueEvent()
124 uno::Reference
< beans::XPropertySet
> xPathSettings( mxFactory
->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.PathSettings") ), uno::UNO_QUERY_THROW
);
125 rtl::OUString sPathUrl
;
126 xPathSettings
->getPropertyValue( msDefaultFilePath
) >>= sPathUrl
;
127 // path could be a multipath, Microsoft doesn't support this feature in Word currently
128 // only the last path is from interest.
129 sal_Int32 nIndex
= sPathUrl
.lastIndexOf( sal_Unicode(';') );
132 sPathUrl
= sPathUrl
.copy( nIndex
+ 1 );
135 ::osl::File::getSystemPathFromFileURL( sPathUrl
, sPath
);
136 return uno::makeAny( sPath
);
139 sal_Int32 SAL_CALL
SwVbaOptions::getDefaultBorderLineStyle() throw (uno::RuntimeException
)
141 return word::WdLineStyle::wdLineStyleSingle
;
144 void SAL_CALL
SwVbaOptions::setDefaultBorderLineStyle( ::sal_Int32
/*_defaultborderlinestyle*/ ) throw (uno::RuntimeException
)
146 // not support in Writer
149 sal_Int32 SAL_CALL
SwVbaOptions::getDefaultBorderLineWidth() throw (uno::RuntimeException
)
151 return word::WdLineWidth::wdLineWidth050pt
;
154 void SAL_CALL
SwVbaOptions::setDefaultBorderLineWidth( ::sal_Int32
/*_defaultborderlinewidth*/ ) throw (uno::RuntimeException
)
156 // not support in Writer
159 sal_Int32 SAL_CALL
SwVbaOptions::getDefaultBorderColorIndex() throw (uno::RuntimeException
)
161 return word::WdColorIndex::wdAuto
;
164 void SAL_CALL
SwVbaOptions::setDefaultBorderColorIndex( ::sal_Int32
/*_defaultbordercolorindex*/ ) throw (uno::RuntimeException
)
166 // not support in Writer
169 ::sal_Bool SAL_CALL
SwVbaOptions::getReplaceSelection() throw (uno::RuntimeException
)
174 void SAL_CALL
SwVbaOptions::setReplaceSelection( ::sal_Bool
/*_replaceselection*/ ) throw (uno::RuntimeException
)
176 // not support in Writer
179 ::sal_Bool SAL_CALL
SwVbaOptions::getMapPaperSize() throw (uno::RuntimeException
)
184 void SAL_CALL
SwVbaOptions::setMapPaperSize( ::sal_Bool
/*_mappapersize*/ ) throw (uno::RuntimeException
)
186 // not support in Writer
189 ::sal_Bool SAL_CALL
SwVbaOptions::getAutoFormatAsYouTypeApplyHeadings() throw (uno::RuntimeException
)
194 void SAL_CALL
SwVbaOptions::setAutoFormatAsYouTypeApplyHeadings( ::sal_Bool
/*_autoformatasyoutypeapplyheadings*/ ) throw (uno::RuntimeException
)
196 // not support in Writer
199 ::sal_Bool SAL_CALL
SwVbaOptions::getAutoFormatAsYouTypeApplyBulletedLists() throw (uno::RuntimeException
)
204 void SAL_CALL
SwVbaOptions::setAutoFormatAsYouTypeApplyBulletedLists( ::sal_Bool
/*_autoformatasyoutypeapplybulletedlists*/ ) throw (uno::RuntimeException
)
206 // not support in Writer
209 ::sal_Bool SAL_CALL
SwVbaOptions::getAutoFormatAsYouTypeApplyNumberedLists() throw (uno::RuntimeException
)
214 void SAL_CALL
SwVbaOptions::setAutoFormatAsYouTypeApplyNumberedLists( ::sal_Bool
/*_autoformatasyoutypeapplynumberedlists*/ ) throw (uno::RuntimeException
)
216 // not support in Writer
219 ::sal_Bool SAL_CALL
SwVbaOptions::getAutoFormatAsYouTypeFormatListItemBeginning() throw (uno::RuntimeException
)
224 void SAL_CALL
SwVbaOptions::setAutoFormatAsYouTypeFormatListItemBeginning( ::sal_Bool
/*_autoformatasyoutypeformatlistitembeginning*/ ) throw (uno::RuntimeException
)
226 // not support in Writer
229 ::sal_Bool SAL_CALL
SwVbaOptions::getAutoFormatAsYouTypeDefineStyles() throw (uno::RuntimeException
)
234 void SAL_CALL
SwVbaOptions::setAutoFormatAsYouTypeDefineStyles( ::sal_Bool
/*_autoformatasyoutypedefinestyles*/ ) throw (uno::RuntimeException
)
236 // not support in Writer
239 ::sal_Bool SAL_CALL
SwVbaOptions::getAutoFormatApplyHeadings() throw (uno::RuntimeException
)
244 void SAL_CALL
SwVbaOptions::setAutoFormatApplyHeadings( ::sal_Bool
/*_autoformatapplyheadings*/ ) throw (uno::RuntimeException
)
246 // not support in Writer
249 ::sal_Bool SAL_CALL
SwVbaOptions::getAutoFormatApplyLists() throw (uno::RuntimeException
)
254 void SAL_CALL
SwVbaOptions::setAutoFormatApplyLists( ::sal_Bool
/*_autoformatapplylists*/ ) throw (uno::RuntimeException
)
256 // not support in Writer
259 ::sal_Bool SAL_CALL
SwVbaOptions::getAutoFormatApplyBulletedLists() throw (uno::RuntimeException
)
264 void SAL_CALL
SwVbaOptions::setAutoFormatApplyBulletedLists( ::sal_Bool
/*_autoformatapplybulletedlists*/ ) throw (uno::RuntimeException
)
266 // not support in Writer
271 SwVbaOptions::getServiceImplName()
273 static rtl::OUString
sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaOptions") );
277 uno::Sequence
< rtl::OUString
>
278 SwVbaOptions::getServiceNames()
280 static uno::Sequence
< rtl::OUString
> aServiceNames
;
281 if ( aServiceNames
.getLength() == 0 )
283 aServiceNames
.realloc( 1 );
284 aServiceNames
[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Options" ) );
286 return aServiceNames
;