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