Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #include "vbadocument.hxx"
20 : #include "vbarange.hxx"
21 : #include "vbarangehelper.hxx"
22 : #include "vbadocumentproperties.hxx"
23 : #include "vbabookmarks.hxx"
24 : #include "vbavariables.hxx"
25 : #include <com/sun/star/text/XBookmarksSupplier.hpp>
26 : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
27 : #include <com/sun/star/document/XDocumentProperties.hpp>
28 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
29 : #include <com/sun/star/drawing/XControlShape.hpp>
30 : #include <com/sun/star/form/XFormsSupplier.hpp>
31 : #include <com/sun/star/document/XRedlinesSupplier.hpp>
32 : #include <ooo/vba/XControlProvider.hpp>
33 : #include <ooo/vba/word/WdProtectionType.hpp>
34 :
35 : #include <vbahelper/helperdecl.hxx>
36 : #include <wordvbahelper.hxx>
37 : #include <docsh.hxx>
38 : #include "vbatemplate.hxx"
39 : #include "vbaparagraph.hxx"
40 : #include "vbastyles.hxx"
41 : #include "vbatables.hxx"
42 : #include "vbafield.hxx"
43 : #include "vbapagesetup.hxx"
44 : #include "vbasections.hxx"
45 : #include "vbatablesofcontents.hxx"
46 : #include <vbahelper/vbashapes.hxx>
47 : #include <vbahelper/vbahelper.hxx>
48 : #include "vbarevisions.hxx"
49 : #include "vbaframes.hxx"
50 : #include <osl/file.hxx>
51 : #include <tools/urlobj.hxx>
52 :
53 : using namespace ::ooo::vba;
54 : using namespace ::com::sun::star;
55 :
56 0 : SwVbaDocument::SwVbaDocument( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< frame::XModel > xModel ): SwVbaDocument_BASE( xParent, xContext, xModel )
57 : {
58 0 : Initialize();
59 0 : }
60 1 : SwVbaDocument::SwVbaDocument( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& xContext ) : SwVbaDocument_BASE( aArgs, xContext )
61 : {
62 1 : Initialize();
63 1 : }
64 :
65 1 : SwVbaDocument::~SwVbaDocument()
66 : {
67 1 : }
68 :
69 1 : void SwVbaDocument::Initialize()
70 : {
71 1 : mxTextDocument.set( getModel(), uno::UNO_QUERY_THROW );
72 1 : }
73 :
74 : uno::Reference< word::XRange > SAL_CALL
75 0 : SwVbaDocument::getContent() throw ( uno::RuntimeException, std::exception )
76 : {
77 0 : uno::Reference< text::XTextRange > xStart = mxTextDocument->getText()->getStart();
78 0 : uno::Reference< text::XTextRange > xEnd;
79 0 : return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, xStart, xEnd, true ) );
80 : }
81 :
82 : uno::Reference< word::XRange > SAL_CALL
83 0 : SwVbaDocument::Range( const uno::Any& rStart, const uno::Any& rEnd )
84 : throw (css::script::BasicErrorException, uno::RuntimeException, std::exception)
85 : {
86 0 : if( !rStart.hasValue() && !rEnd.hasValue() )
87 0 : return getContent();
88 :
89 0 : sal_Int32 nStart = 0;
90 0 : sal_Int32 nEnd = 0;
91 0 : rStart >>= nStart;
92 0 : rEnd >>= nEnd;
93 0 : nStart--;
94 0 : nEnd--;
95 :
96 0 : uno::Reference< text::XTextRange > xStart;
97 0 : uno::Reference< text::XTextRange > xEnd;
98 0 : if( nStart != -1 || nEnd != -1 )
99 : {
100 0 : if( nStart == -1 )
101 0 : xStart = mxTextDocument->getText()->getStart();
102 : else
103 0 : xStart = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nStart );
104 :
105 0 : if( nEnd == -1 )
106 0 : xEnd = mxTextDocument->getText()->getEnd();
107 : else
108 0 : xEnd = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nEnd );
109 : }
110 :
111 0 : if( !xStart.is() && !xEnd.is() )
112 : {
113 : try
114 : {
115 : // FIXME
116 0 : xStart = mxTextDocument->getText()->getStart();
117 0 : xEnd = mxTextDocument->getText()->getEnd();
118 : }
119 0 : catch(const uno::Exception&)
120 : {
121 0 : DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString());
122 : }
123 : }
124 0 : return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, xStart, xEnd ) );
125 : }
126 :
127 : uno::Any SAL_CALL
128 0 : SwVbaDocument::BuiltInDocumentProperties( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
129 : {
130 0 : uno::Reference< XCollection > xCol( new SwVbaBuiltinDocumentProperties( mxParent, mxContext, getModel() ) );
131 0 : if ( index.hasValue() )
132 0 : return xCol->Item( index, uno::Any() );
133 0 : return uno::makeAny( xCol );
134 : }
135 :
136 : uno::Any SAL_CALL
137 0 : SwVbaDocument::CustomDocumentProperties( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
138 : {
139 0 : uno::Reference< XCollection > xCol( new SwVbaCustomDocumentProperties( mxParent, mxContext, getModel() ) );
140 0 : if ( index.hasValue() )
141 0 : return xCol->Item( index, uno::Any() );
142 0 : return uno::makeAny( xCol );
143 : }
144 :
145 : uno::Any SAL_CALL
146 0 : SwVbaDocument::Bookmarks( const uno::Any& rIndex ) throw ( uno::RuntimeException, std::exception )
147 : {
148 0 : uno::Reference< text::XBookmarksSupplier > xBookmarksSupplier( getModel(),uno::UNO_QUERY_THROW );
149 0 : uno::Reference<container::XIndexAccess > xBookmarks( xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY_THROW );
150 0 : uno::Reference< XCollection > xBookmarksVba( new SwVbaBookmarks( this, mxContext, xBookmarks, getModel() ) );
151 0 : if ( rIndex.getValueTypeClass() == uno::TypeClass_VOID )
152 0 : return uno::makeAny( xBookmarksVba );
153 :
154 0 : return uno::Any( xBookmarksVba->Item( rIndex, uno::Any() ) );
155 : }
156 :
157 : uno::Any SAL_CALL
158 0 : SwVbaDocument::Variables( const uno::Any& rIndex ) throw ( uno::RuntimeException, std::exception )
159 : {
160 0 : uno::Reference< document::XDocumentPropertiesSupplier > xDocumentPropertiesSupplier( getModel(),uno::UNO_QUERY_THROW );
161 0 : uno::Reference< document::XDocumentProperties > xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties();
162 0 : uno::Reference< beans::XPropertyAccess > xUserDefined( xDocumentProperties->getUserDefinedProperties(), uno::UNO_QUERY_THROW );
163 :
164 0 : uno::Reference< XCollection > xVariables( new SwVbaVariables( this, mxContext, xUserDefined ) );
165 0 : if ( rIndex.getValueTypeClass() == uno::TypeClass_VOID )
166 0 : return uno::makeAny( xVariables );
167 :
168 0 : return uno::Any( xVariables->Item( rIndex, uno::Any() ) );
169 : }
170 :
171 : uno::Any SAL_CALL
172 0 : SwVbaDocument::Paragraphs( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
173 : {
174 0 : uno::Reference< XCollection > xCol( new SwVbaParagraphs( mxParent, mxContext, mxTextDocument ) );
175 0 : if ( index.hasValue() )
176 0 : return xCol->Item( index, uno::Any() );
177 0 : return uno::makeAny( xCol );
178 : }
179 :
180 : uno::Any SAL_CALL
181 0 : SwVbaDocument::Styles( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
182 : {
183 0 : uno::Reference< XCollection > xCol( new SwVbaStyles( mxParent, mxContext, getModel() ) );
184 0 : if ( index.hasValue() )
185 0 : return xCol->Item( index, uno::Any() );
186 0 : return uno::makeAny( xCol );
187 : }
188 :
189 : uno::Any SAL_CALL
190 0 : SwVbaDocument::Fields( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
191 : {
192 0 : uno::Reference< XCollection > xCol( new SwVbaFields( mxParent, mxContext, getModel() ) );
193 0 : if ( index.hasValue() )
194 0 : return xCol->Item( index, uno::Any() );
195 0 : return uno::makeAny( xCol );
196 : }
197 :
198 : uno::Any SAL_CALL
199 0 : SwVbaDocument::Shapes( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
200 : {
201 0 : uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( getModel(), uno::UNO_QUERY_THROW );
202 0 : uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
203 0 : uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
204 0 : uno::Reference< XCollection > xCol( new ScVbaShapes( this, mxContext, xIndexAccess, xModel ) );
205 :
206 0 : if ( index.hasValue() )
207 0 : return xCol->Item( index, uno::Any() );
208 0 : return uno::makeAny( xCol );
209 : }
210 :
211 : uno::Any SAL_CALL
212 0 : SwVbaDocument::Sections( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
213 : {
214 0 : uno::Reference< XCollection > xCol( new SwVbaSections( mxParent, mxContext, getModel() ) );
215 0 : if ( index.hasValue() )
216 0 : return xCol->Item( index, uno::Any() );
217 0 : return uno::makeAny( xCol );
218 : }
219 :
220 : uno::Any SAL_CALL
221 0 : SwVbaDocument::TablesOfContents( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
222 : {
223 0 : uno::Reference< XCollection > xCol( new SwVbaTablesOfContents( this, mxContext, mxTextDocument ) );
224 0 : if ( index.hasValue() )
225 0 : return xCol->Item( index, uno::Any() );
226 0 : return uno::makeAny( xCol );
227 : }
228 :
229 : uno::Any SAL_CALL
230 0 : SwVbaDocument::FormFields( const uno::Any& /*index*/ ) throw (uno::RuntimeException, std::exception)
231 : {
232 0 : uno::Reference< XCollection > xCol;
233 0 : return uno::makeAny( xCol );
234 : }
235 :
236 : uno::Any SAL_CALL
237 0 : SwVbaDocument::PageSetup( ) throw (uno::RuntimeException, std::exception)
238 : {
239 0 : uno::Reference< beans::XPropertySet > xPageProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW );
240 0 : return uno::makeAny( uno::Reference< word::XPageSetup >( new SwVbaPageSetup( this, mxContext, mxModel, xPageProps ) ) );
241 : }
242 :
243 : OUString
244 0 : SwVbaDocument::getServiceImplName()
245 : {
246 0 : return OUString("SwVbaDocument");
247 : }
248 :
249 : uno::Any SAL_CALL
250 0 : SwVbaDocument::getAttachedTemplate() throw (uno::RuntimeException, std::exception)
251 : {
252 0 : uno::Reference< word::XTemplate > xTemplate;
253 : uno::Reference<document::XDocumentPropertiesSupplier> const xDocPropSupp(
254 0 : getModel(), uno::UNO_QUERY_THROW);
255 0 : uno::Reference< document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW );
256 0 : OUString sTemplateUrl = xDocProps->getTemplateURL();
257 :
258 0 : xTemplate = new SwVbaTemplate( this, mxContext, getModel(), sTemplateUrl );
259 0 : return uno::makeAny( xTemplate );
260 : }
261 :
262 : void SAL_CALL
263 0 : SwVbaDocument::setAttachedTemplate( const css::uno::Any& _attachedtemplate ) throw (uno::RuntimeException, std::exception)
264 : {
265 0 : OUString sTemplate;
266 0 : if( !( _attachedtemplate >>= sTemplate ) )
267 : {
268 0 : throw uno::RuntimeException();
269 : }
270 0 : OUString aURL;
271 0 : INetURLObject aObj;
272 0 : aObj.SetURL( sTemplate );
273 0 : bool bIsURL = aObj.GetProtocol() != INetProtocol::NotValid;
274 0 : if ( bIsURL )
275 0 : aURL = sTemplate;
276 : else
277 0 : osl::FileBase::getFileURLFromSystemPath( sTemplate, aURL );
278 :
279 0 : uno::Reference< word::XTemplate > xTemplate;
280 : uno::Reference<document::XDocumentPropertiesSupplier> const xDocPropSupp(
281 0 : getModel(), uno::UNO_QUERY_THROW );
282 0 : uno::Reference< document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW );
283 0 : xDocProps->setTemplateURL( aURL );
284 0 : }
285 :
286 : uno::Any SAL_CALL
287 0 : SwVbaDocument::Tables( const css::uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
288 : {
289 0 : uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
290 0 : uno::Reference< XCollection > xColl( new SwVbaTables( mxParent, mxContext, xModel ) );
291 :
292 0 : if ( aIndex.hasValue() )
293 0 : return xColl->Item( aIndex, uno::Any() );
294 0 : return uno::makeAny( xColl );
295 : }
296 :
297 0 : void SAL_CALL SwVbaDocument::Activate() throw (uno::RuntimeException, std::exception)
298 : {
299 0 : VbaDocumentBase::Activate();
300 0 : }
301 :
302 0 : ::sal_Int32 SAL_CALL SwVbaDocument::getProtectionType() throw (css::uno::RuntimeException, std::exception)
303 : {
304 : //TODO
305 0 : return word::WdProtectionType::wdNoProtection;
306 : }
307 :
308 0 : void SAL_CALL SwVbaDocument::setProtectionType( ::sal_Int32 /*_protectiontype*/ ) throw (css::uno::RuntimeException, std::exception)
309 : {
310 : //TODO
311 0 : }
312 :
313 0 : sal_Bool SAL_CALL SwVbaDocument::getUpdateStylesOnOpen() throw (css::uno::RuntimeException, std::exception)
314 : {
315 : //TODO
316 0 : return sal_False;
317 : }
318 :
319 0 : void SAL_CALL SwVbaDocument::setUpdateStylesOnOpen( sal_Bool /*_updatestylesonopen*/ ) throw (uno::RuntimeException, std::exception)
320 : {
321 : //TODO
322 0 : }
323 :
324 0 : sal_Bool SAL_CALL SwVbaDocument::getAutoHyphenation() throw (uno::RuntimeException, std::exception)
325 : {
326 : // check this property only in default paragraph style
327 0 : bool IsAutoHyphenation = false;
328 0 : uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
329 0 : xParaProps->getPropertyValue("ParaIsHyphenation") >>= IsAutoHyphenation;
330 0 : return IsAutoHyphenation;
331 : }
332 :
333 0 : void SAL_CALL SwVbaDocument::setAutoHyphenation( sal_Bool _autohyphenation ) throw (uno::RuntimeException, std::exception)
334 : {
335 : //TODO
336 0 : uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
337 0 : xParaProps->setPropertyValue("ParaIsHyphenation", uno::makeAny( _autohyphenation ) );
338 0 : }
339 :
340 0 : ::sal_Int32 SAL_CALL SwVbaDocument::getHyphenationZone() throw (uno::RuntimeException, std::exception)
341 : {
342 : //TODO
343 0 : return 0;
344 : }
345 :
346 0 : void SAL_CALL SwVbaDocument::setHyphenationZone( ::sal_Int32 /*_hyphenationzone*/ ) throw (uno::RuntimeException, std::exception)
347 : {
348 : //TODO
349 0 : }
350 :
351 0 : ::sal_Int32 SAL_CALL SwVbaDocument::getConsecutiveHyphensLimit() throw (uno::RuntimeException, std::exception)
352 : {
353 : //TODO
354 0 : sal_Int16 nHyphensLimit = 0;
355 0 : uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
356 0 : xParaProps->getPropertyValue("ParaHyphenationMaxHyphens") >>= nHyphensLimit;
357 0 : return nHyphensLimit;
358 : }
359 :
360 0 : void SAL_CALL SwVbaDocument::setConsecutiveHyphensLimit( ::sal_Int32 _consecutivehyphenslimit ) throw (uno::RuntimeException, std::exception)
361 : {
362 0 : sal_Int16 nHyphensLimit = static_cast< sal_Int16 >( _consecutivehyphenslimit );
363 0 : uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
364 0 : xParaProps->setPropertyValue("ParaHyphenationMaxHyphens", uno::makeAny( nHyphensLimit ) );
365 0 : }
366 :
367 0 : void SAL_CALL SwVbaDocument::Protect( ::sal_Int32 /*Type*/, const uno::Any& /*NOReset*/, const uno::Any& /*Password*/, const uno::Any& /*UseIRM*/, const uno::Any& /*EnforceStyleLock*/ ) throw (uno::RuntimeException, std::exception)
368 : {
369 : // Seems not support in Writer
370 : // VbaDocumentBase::Protect( Password );
371 0 : }
372 :
373 0 : void SAL_CALL SwVbaDocument::PrintOut( const uno::Any& /*Background*/, const uno::Any& /*Append*/, const uno::Any& /*Range*/, const uno::Any& /*OutputFileName*/, const uno::Any& /*From*/, const uno::Any& /*To*/, const uno::Any& /*Item*/, const uno::Any& /*Copies*/, const uno::Any& /*Pages*/, const uno::Any& /*PageType*/, const uno::Any& /*PrintToFile*/, const uno::Any& /*Collate*/, const uno::Any& /*FileName*/, const uno::Any& /*ActivePrinterMacGX*/, const uno::Any& /*ManualDuplexPrint*/, const uno::Any& /*PrintZoomColumn*/, const uno::Any& /*PrintZoomRow*/, const uno::Any& /*PrintZoomPaperWidth*/, const uno::Any& /*PrintZoomPaperHeight*/ ) throw (uno::RuntimeException, std::exception)
374 : {
375 : //TODO
376 0 : }
377 :
378 0 : void SAL_CALL SwVbaDocument::PrintPreview( ) throw (uno::RuntimeException, std::exception)
379 : {
380 0 : OUString url = ".uno:PrintPreview";
381 0 : dispatchRequests( mxModel,url );
382 0 : }
383 :
384 0 : void SAL_CALL SwVbaDocument::ClosePrintPreview( ) throw (uno::RuntimeException, std::exception)
385 : {
386 0 : OUString url = ".uno:ClosePreview";
387 0 : dispatchRequests( mxModel,url );
388 0 : }
389 :
390 : uno::Any SAL_CALL
391 0 : SwVbaDocument::Revisions( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
392 : {
393 0 : uno::Reference< document::XRedlinesSupplier > xRedlinesSupp( mxTextDocument, uno::UNO_QUERY_THROW );
394 0 : uno::Reference< container::XIndexAccess > xRedlines( xRedlinesSupp->getRedlines(), uno::UNO_QUERY_THROW );
395 0 : uno::Reference< XCollection > xCol( new SwVbaRevisions( this, mxContext, getModel(), xRedlines ) );
396 0 : if ( index.hasValue() )
397 0 : return xCol->Item( index, uno::Any() );
398 0 : return uno::makeAny( xCol );
399 : }
400 :
401 : uno::Any SAL_CALL
402 0 : SwVbaDocument::Frames( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
403 : {
404 0 : uno::Reference< text::XTextFramesSupplier > xTextFramesSupp( mxTextDocument, uno::UNO_QUERY_THROW );
405 0 : uno::Reference< container::XIndexAccess > xFrames( xTextFramesSupp->getTextFrames(), uno::UNO_QUERY_THROW );
406 0 : uno::Reference< XCollection > xCol( new SwVbaFrames( this, mxContext, xFrames, getModel() ) );
407 0 : if ( index.hasValue() )
408 0 : return xCol->Item( index, uno::Any() );
409 0 : return uno::makeAny( xCol );
410 : }
411 :
412 : uno::Any
413 0 : SwVbaDocument::getControlShape( const OUString& sName )
414 : {
415 0 : uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxTextDocument, uno::UNO_QUERY_THROW );
416 0 : uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
417 :
418 0 : sal_Int32 nCount = xIndexAccess->getCount();
419 0 : for( int index = 0; index < nCount; index++ )
420 : {
421 0 : uno::Any aUnoObj = xIndexAccess->getByIndex( index );
422 : // It seems there are some drawing objects that can not query into Control shapes?
423 0 : uno::Reference< drawing::XControlShape > xControlShape( aUnoObj, uno::UNO_QUERY );
424 0 : if( xControlShape.is() )
425 : {
426 0 : uno::Reference< container::XNamed > xNamed( xControlShape->getControl(), uno::UNO_QUERY_THROW );
427 0 : if( sName.equals( xNamed->getName() ))
428 : {
429 0 : return aUnoObj;
430 0 : }
431 : }
432 0 : }
433 0 : return uno::Any();
434 : }
435 :
436 : uno::Reference< beans::XIntrospectionAccess > SAL_CALL
437 0 : SwVbaDocument::getIntrospection( ) throw (uno::RuntimeException, std::exception)
438 : {
439 0 : return uno::Reference< beans::XIntrospectionAccess >();
440 : }
441 :
442 : uno::Any SAL_CALL
443 0 : SwVbaDocument::invoke( const OUString& aFunctionName, const uno::Sequence< uno::Any >& /*aParams*/, uno::Sequence< ::sal_Int16 >& /*aOutParamIndex*/, uno::Sequence< uno::Any >& /*aOutParam*/ ) throw (lang::IllegalArgumentException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException, std::exception)
444 : {
445 : OSL_TRACE("** SwVbaDocument::invoke( %s ), will barf",
446 : OUStringToOString( aFunctionName, RTL_TEXTENCODING_UTF8 ).getStr() );
447 :
448 0 : throw uno::RuntimeException(); // unsupported operation
449 : }
450 :
451 : void SAL_CALL
452 0 : SwVbaDocument::setValue( const OUString& /*aPropertyName*/, const uno::Any& /*aValue*/ ) throw (beans::UnknownPropertyException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException, std::exception)
453 : {
454 0 : throw uno::RuntimeException(); // unsupported operation
455 : }
456 : uno::Any SAL_CALL
457 0 : SwVbaDocument::getValue( const OUString& aPropertyName ) throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
458 : {
459 0 : uno::Reference< drawing::XControlShape > xControlShape( getControlShape( aPropertyName ), uno::UNO_QUERY_THROW );
460 :
461 0 : uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
462 0 : uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext("ooo.vba.ControlProvider", mxContext ), uno::UNO_QUERY_THROW );
463 0 : uno::Reference< msforms::XControl > xControl( xControlProvider->createControl( xControlShape, getModel() ) );
464 0 : return uno::makeAny( xControl );
465 : }
466 :
467 : sal_Bool SAL_CALL
468 0 : SwVbaDocument::hasMethod( const OUString& /*aName*/ ) throw (uno::RuntimeException, std::exception)
469 : {
470 0 : return sal_False;
471 : }
472 :
473 : sal_Bool SAL_CALL
474 0 : SwVbaDocument::hasProperty( const OUString& aName ) throw (uno::RuntimeException, std::exception)
475 : {
476 0 : uno::Reference< container::XNameAccess > xFormControls( getFormControls() );
477 0 : if ( xFormControls.is() )
478 0 : return xFormControls->hasByName( aName );
479 0 : return sal_False;
480 : }
481 :
482 : uno::Reference< container::XNameAccess >
483 0 : SwVbaDocument::getFormControls()
484 : {
485 0 : uno::Reference< container::XNameAccess > xFormControls;
486 : try
487 : {
488 0 : uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxTextDocument, uno::UNO_QUERY_THROW );
489 0 : uno::Reference< form::XFormsSupplier > xFormSupplier( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
490 0 : uno::Reference< container::XIndexAccess > xIndexAccess( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
491 : // get the www-standard container ( maybe we should access the
492 : // 'www-standard' by name rather than index, this seems an
493 : // implementation detail
494 0 : xFormControls.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW );
495 : }
496 0 : catch(const uno::Exception&)
497 : {
498 : }
499 0 : return xFormControls;
500 : }
501 :
502 : uno::Sequence< OUString >
503 0 : SwVbaDocument::getServiceNames()
504 : {
505 0 : static uno::Sequence< OUString > aServiceNames;
506 0 : if ( aServiceNames.getLength() == 0 )
507 : {
508 0 : aServiceNames.realloc( 1 );
509 0 : aServiceNames[ 0 ] = "ooo.vba.word.Document";
510 : }
511 0 : return aServiceNames;
512 : }
513 :
514 : namespace document
515 : {
516 : namespace sdecl = comphelper::service_decl;
517 1 : sdecl::vba_service_class_<SwVbaDocument, sdecl::with_args<true> > serviceImpl;
518 1 : extern sdecl::ServiceDecl const serviceDecl(
519 : serviceImpl,
520 : "SwVbaDocument",
521 : "ooo.vba.word.Document" );
522 3 : }
523 :
524 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|