xref: /AOO41X/main/sw/source/ui/vba/vbadocument.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir #include "vbadocument.hxx"
28*cdf0e10cSrcweir #include "vbarange.hxx"
29*cdf0e10cSrcweir #include "vbarangehelper.hxx"
30*cdf0e10cSrcweir #include "vbadocumentproperties.hxx"
31*cdf0e10cSrcweir #include "vbabookmarks.hxx"
32*cdf0e10cSrcweir #include "vbavariables.hxx"
33*cdf0e10cSrcweir #include <com/sun/star/text/XBookmarksSupplier.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentInfoSupplier.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/drawing/XControlShape.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/drawing/XControlShape.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/form/XFormsSupplier.hpp>
41*cdf0e10cSrcweir #include <ooo/vba/XControlProvider.hpp>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include <vbahelper/helperdecl.hxx>
44*cdf0e10cSrcweir #include <wordvbahelper.hxx>
45*cdf0e10cSrcweir #include <docsh.hxx>
46*cdf0e10cSrcweir #include "vbatemplate.hxx"
47*cdf0e10cSrcweir #include "vbaparagraph.hxx"
48*cdf0e10cSrcweir #include "vbastyles.hxx"
49*cdf0e10cSrcweir #include "vbatables.hxx"
50*cdf0e10cSrcweir #include "vbafield.hxx"
51*cdf0e10cSrcweir #include "vbapagesetup.hxx"
52*cdf0e10cSrcweir #include "vbasections.hxx"
53*cdf0e10cSrcweir #include <vbahelper/vbashapes.hxx>
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir using namespace ::ooo::vba;
56*cdf0e10cSrcweir using namespace ::com::sun::star;
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir SwVbaDocument::SwVbaDocument( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< frame::XModel > xModel ): SwVbaDocument_BASE( xParent, xContext, xModel )
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir     Initialize();
61*cdf0e10cSrcweir }
62*cdf0e10cSrcweir SwVbaDocument::SwVbaDocument( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& xContext ) : SwVbaDocument_BASE( aArgs, xContext )
63*cdf0e10cSrcweir {
64*cdf0e10cSrcweir     Initialize();
65*cdf0e10cSrcweir }
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir SwVbaDocument::~SwVbaDocument()
68*cdf0e10cSrcweir {
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir void SwVbaDocument::Initialize()
72*cdf0e10cSrcweir {
73*cdf0e10cSrcweir     mxTextDocument.set( getModel(), uno::UNO_QUERY_THROW );
74*cdf0e10cSrcweir }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir uno::Reference< word::XRange > SAL_CALL
77*cdf0e10cSrcweir SwVbaDocument::getContent() throw ( uno::RuntimeException )
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir     uno::Reference< text::XTextRange > xStart = mxTextDocument->getText()->getStart();
80*cdf0e10cSrcweir     uno::Reference< text::XTextRange > xEnd;
81*cdf0e10cSrcweir     return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, xStart, xEnd, sal_True ) );
82*cdf0e10cSrcweir }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir uno::Reference< word::XRange > SAL_CALL
85*cdf0e10cSrcweir SwVbaDocument::Range( const uno::Any& rStart, const uno::Any& rEnd ) throw ( uno::RuntimeException )
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir     if( !rStart.hasValue() && !rEnd.hasValue() )
88*cdf0e10cSrcweir         return getContent();
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir     sal_Int32 nStart = 0;
91*cdf0e10cSrcweir     sal_Int32 nEnd = 0;
92*cdf0e10cSrcweir     rStart >>= nStart;
93*cdf0e10cSrcweir     rEnd >>= nEnd;
94*cdf0e10cSrcweir     nStart--;
95*cdf0e10cSrcweir     nEnd--;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir     uno::Reference< text::XTextRange > xStart;
98*cdf0e10cSrcweir     uno::Reference< text::XTextRange > xEnd;
99*cdf0e10cSrcweir     if( nStart != -1 || nEnd != -1 )
100*cdf0e10cSrcweir     {
101*cdf0e10cSrcweir         if( nStart == -1 )
102*cdf0e10cSrcweir             xStart = mxTextDocument->getText()->getStart();
103*cdf0e10cSrcweir         else
104*cdf0e10cSrcweir             xStart = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nStart );
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir         if( nEnd == -1 )
107*cdf0e10cSrcweir             xEnd = mxTextDocument->getText()->getEnd();
108*cdf0e10cSrcweir         else
109*cdf0e10cSrcweir             xEnd = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nEnd );
110*cdf0e10cSrcweir     }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     if( !xStart.is() && !xEnd.is() )
113*cdf0e10cSrcweir     {
114*cdf0e10cSrcweir         try
115*cdf0e10cSrcweir         {
116*cdf0e10cSrcweir             // FIXME
117*cdf0e10cSrcweir             xStart = mxTextDocument->getText()->getStart();
118*cdf0e10cSrcweir             xEnd = mxTextDocument->getText()->getEnd();
119*cdf0e10cSrcweir         }
120*cdf0e10cSrcweir         catch( uno::Exception )
121*cdf0e10cSrcweir         {
122*cdf0e10cSrcweir             DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
123*cdf0e10cSrcweir         }
124*cdf0e10cSrcweir     }
125*cdf0e10cSrcweir     return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, xStart, xEnd ) );
126*cdf0e10cSrcweir }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir uno::Any SAL_CALL
129*cdf0e10cSrcweir SwVbaDocument::BuiltInDocumentProperties( const uno::Any& index ) throw (uno::RuntimeException)
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir     uno::Reference< XCollection > xCol( new SwVbaBuiltinDocumentProperties( mxParent, mxContext, getModel() ) );
132*cdf0e10cSrcweir     if ( index.hasValue() )
133*cdf0e10cSrcweir         return xCol->Item( index, uno::Any() );
134*cdf0e10cSrcweir     return uno::makeAny( xCol );
135*cdf0e10cSrcweir }
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir uno::Any SAL_CALL
138*cdf0e10cSrcweir SwVbaDocument::CustomDocumentProperties( const uno::Any& index ) throw (uno::RuntimeException)
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir     uno::Reference< XCollection > xCol( new SwVbaCustomDocumentProperties( mxParent, mxContext, getModel() ) );
141*cdf0e10cSrcweir     if ( index.hasValue() )
142*cdf0e10cSrcweir         return xCol->Item( index, uno::Any() );
143*cdf0e10cSrcweir     return uno::makeAny( xCol );
144*cdf0e10cSrcweir }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir uno::Any SAL_CALL
147*cdf0e10cSrcweir SwVbaDocument::Bookmarks( const uno::Any& rIndex ) throw ( uno::RuntimeException )
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir     uno::Reference< text::XBookmarksSupplier > xBookmarksSupplier( getModel(),uno::UNO_QUERY_THROW );
150*cdf0e10cSrcweir     uno::Reference<container::XIndexAccess > xBookmarks( xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY_THROW );
151*cdf0e10cSrcweir     uno::Reference< XCollection > xBookmarksVba( new SwVbaBookmarks( this, mxContext, xBookmarks, getModel() ) );
152*cdf0e10cSrcweir     if (  rIndex.getValueTypeClass() == uno::TypeClass_VOID )
153*cdf0e10cSrcweir         return uno::makeAny( xBookmarksVba );
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir     return uno::Any( xBookmarksVba->Item( rIndex, uno::Any() ) );
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir uno::Any SAL_CALL
159*cdf0e10cSrcweir SwVbaDocument::Variables( const uno::Any& rIndex ) throw ( uno::RuntimeException )
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir     uno::Reference< document::XDocumentPropertiesSupplier > xDocumentPropertiesSupplier( getModel(),uno::UNO_QUERY_THROW );
162*cdf0e10cSrcweir     uno::Reference< document::XDocumentProperties > xDocumentProperties =  xDocumentPropertiesSupplier->getDocumentProperties();
163*cdf0e10cSrcweir     uno::Reference< beans::XPropertyAccess > xUserDefined( xDocumentProperties->getUserDefinedProperties(), uno::UNO_QUERY_THROW );
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir     uno::Reference< XCollection > xVariables( new SwVbaVariables( this, mxContext, xUserDefined ) );
166*cdf0e10cSrcweir     if (  rIndex.getValueTypeClass() == uno::TypeClass_VOID )
167*cdf0e10cSrcweir         return uno::makeAny( xVariables );
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir     return uno::Any( xVariables->Item( rIndex, uno::Any() ) );
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir uno::Any SAL_CALL
173*cdf0e10cSrcweir SwVbaDocument::Paragraphs( const uno::Any& index ) throw (uno::RuntimeException)
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir     uno::Reference< XCollection > xCol( new SwVbaParagraphs( mxParent, mxContext, mxTextDocument ) );
176*cdf0e10cSrcweir     if ( index.hasValue() )
177*cdf0e10cSrcweir         return xCol->Item( index, uno::Any() );
178*cdf0e10cSrcweir     return uno::makeAny( xCol );
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir uno::Any SAL_CALL
182*cdf0e10cSrcweir SwVbaDocument::Styles( const uno::Any& index ) throw (uno::RuntimeException)
183*cdf0e10cSrcweir {
184*cdf0e10cSrcweir     uno::Reference< XCollection > xCol( new SwVbaStyles( mxParent, mxContext, getModel() ) );
185*cdf0e10cSrcweir     if ( index.hasValue() )
186*cdf0e10cSrcweir         return xCol->Item( index, uno::Any() );
187*cdf0e10cSrcweir     return uno::makeAny( xCol );
188*cdf0e10cSrcweir }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir uno::Any SAL_CALL
191*cdf0e10cSrcweir SwVbaDocument::Fields( const uno::Any& index ) throw (uno::RuntimeException)
192*cdf0e10cSrcweir {
193*cdf0e10cSrcweir     uno::Reference< XCollection > xCol( new SwVbaFields( mxParent, mxContext, getModel() ) );
194*cdf0e10cSrcweir     if ( index.hasValue() )
195*cdf0e10cSrcweir         return xCol->Item( index, uno::Any() );
196*cdf0e10cSrcweir     return uno::makeAny( xCol );
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir uno::Any SAL_CALL
200*cdf0e10cSrcweir SwVbaDocument::Shapes( const uno::Any& index ) throw (uno::RuntimeException)
201*cdf0e10cSrcweir {
202*cdf0e10cSrcweir     uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( getModel(), uno::UNO_QUERY_THROW );
203*cdf0e10cSrcweir     //uno::Reference< drawing::XShapes > xShapes( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
204*cdf0e10cSrcweir     uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
205*cdf0e10cSrcweir     uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
206*cdf0e10cSrcweir     uno::Reference< XCollection > xCol( new ScVbaShapes( this, mxContext, xIndexAccess, xModel ) );
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir     if ( index.hasValue() )
209*cdf0e10cSrcweir         return xCol->Item( index, uno::Any() );
210*cdf0e10cSrcweir     return uno::makeAny( xCol );
211*cdf0e10cSrcweir }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir uno::Any SAL_CALL
214*cdf0e10cSrcweir SwVbaDocument::Sections( const uno::Any& index ) throw (uno::RuntimeException)
215*cdf0e10cSrcweir {
216*cdf0e10cSrcweir     uno::Reference< XCollection > xCol( new SwVbaSections( mxParent, mxContext, getModel() ) );
217*cdf0e10cSrcweir     if ( index.hasValue() )
218*cdf0e10cSrcweir         return xCol->Item( index, uno::Any() );
219*cdf0e10cSrcweir     return uno::makeAny( xCol );
220*cdf0e10cSrcweir }
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir uno::Any SAL_CALL
223*cdf0e10cSrcweir SwVbaDocument::PageSetup( ) throw (uno::RuntimeException)
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xPageProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW );
226*cdf0e10cSrcweir     return uno::makeAny( uno::Reference< word::XPageSetup >( new SwVbaPageSetup( this, mxContext, mxModel, xPageProps ) ) );
227*cdf0e10cSrcweir }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir rtl::OUString&
230*cdf0e10cSrcweir SwVbaDocument::getServiceImplName()
231*cdf0e10cSrcweir {
232*cdf0e10cSrcweir 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaDocument") );
233*cdf0e10cSrcweir 	return sImplName;
234*cdf0e10cSrcweir }
235*cdf0e10cSrcweir uno::Any SAL_CALL
236*cdf0e10cSrcweir SwVbaDocument::getAttachedTemplate() throw (uno::RuntimeException)
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir     uno::Reference< word::XTemplate > xTemplate;
239*cdf0e10cSrcweir     uno::Reference< document::XDocumentInfoSupplier > xDocInfoSupp( getModel(), uno::UNO_QUERY_THROW );
240*cdf0e10cSrcweir     uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSupp( xDocInfoSupp->getDocumentInfo(), uno::UNO_QUERY_THROW );
241*cdf0e10cSrcweir     uno::Reference< document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW );
242*cdf0e10cSrcweir     rtl::OUString sTemplateName = xDocProps->getTemplateName();
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir     xTemplate = new SwVbaTemplate( this, mxContext, getModel(), sTemplateName );
245*cdf0e10cSrcweir     return uno::makeAny( xTemplate );
246*cdf0e10cSrcweir }
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir void SAL_CALL
249*cdf0e10cSrcweir SwVbaDocument::setAttachedTemplate( const css::uno::Any& /*_attachedtemplate*/ ) throw (uno::RuntimeException)
250*cdf0e10cSrcweir {
251*cdf0e10cSrcweir     throw uno::RuntimeException();
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir uno::Any SAL_CALL
255*cdf0e10cSrcweir SwVbaDocument::Tables( const css::uno::Any& aIndex ) throw (uno::RuntimeException)
256*cdf0e10cSrcweir {
257*cdf0e10cSrcweir     uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
258*cdf0e10cSrcweir     uno::Reference< XCollection > xColl( new SwVbaTables( mxParent, mxContext, xModel ) );
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir     if ( aIndex.hasValue() )
261*cdf0e10cSrcweir         return xColl->Item( aIndex, uno::Any() );
262*cdf0e10cSrcweir     return uno::makeAny( xColl );
263*cdf0e10cSrcweir }
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir void SAL_CALL SwVbaDocument::Activate() throw (uno::RuntimeException)
266*cdf0e10cSrcweir {
267*cdf0e10cSrcweir     VbaDocumentBase::Activate();
268*cdf0e10cSrcweir }
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir uno::Any
271*cdf0e10cSrcweir SwVbaDocument::getControlShape( const ::rtl::OUString& sName )
272*cdf0e10cSrcweir {
273*cdf0e10cSrcweir     uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxTextDocument, uno::UNO_QUERY_THROW );
274*cdf0e10cSrcweir     uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir     sal_Int32 nCount = xIndexAccess->getCount();
277*cdf0e10cSrcweir     for( int index = 0; index < nCount; index++ )
278*cdf0e10cSrcweir     {
279*cdf0e10cSrcweir         uno::Any aUnoObj =  xIndexAccess->getByIndex( index );
280*cdf0e10cSrcweir         // It seems there are some drawing objects that can not query into Control shapes?
281*cdf0e10cSrcweir         uno::Reference< drawing::XControlShape > xControlShape( aUnoObj, uno::UNO_QUERY );
282*cdf0e10cSrcweir         if( xControlShape.is() )
283*cdf0e10cSrcweir         {
284*cdf0e10cSrcweir      	    uno::Reference< container::XNamed > xNamed( xControlShape->getControl(), uno::UNO_QUERY_THROW );
285*cdf0e10cSrcweir             if( sName.equals( xNamed->getName() ))
286*cdf0e10cSrcweir             {
287*cdf0e10cSrcweir                 return aUnoObj;
288*cdf0e10cSrcweir             }
289*cdf0e10cSrcweir         }
290*cdf0e10cSrcweir     }
291*cdf0e10cSrcweir     return uno::Any();
292*cdf0e10cSrcweir }
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir uno::Reference< beans::XIntrospectionAccess > SAL_CALL
295*cdf0e10cSrcweir SwVbaDocument::getIntrospection(  ) throw (uno::RuntimeException)
296*cdf0e10cSrcweir {
297*cdf0e10cSrcweir 	return uno::Reference< beans::XIntrospectionAccess >();
298*cdf0e10cSrcweir }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir uno::Any SAL_CALL
301*cdf0e10cSrcweir SwVbaDocument::invoke( const ::rtl::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)
302*cdf0e10cSrcweir {
303*cdf0e10cSrcweir 	OSL_TRACE("** SwVbaDocument::invoke( %s ), will barf",
304*cdf0e10cSrcweir 		rtl::OUStringToOString( aFunctionName, RTL_TEXTENCODING_UTF8 ).getStr() );
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir 	throw uno::RuntimeException(); // unsupported operation
307*cdf0e10cSrcweir }
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir void SAL_CALL
310*cdf0e10cSrcweir SwVbaDocument::setValue( const ::rtl::OUString& /*aPropertyName*/, const uno::Any& /*aValue*/ ) throw (beans::UnknownPropertyException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException)
311*cdf0e10cSrcweir {
312*cdf0e10cSrcweir 	throw uno::RuntimeException(); // unsupported operation
313*cdf0e10cSrcweir }
314*cdf0e10cSrcweir uno::Any SAL_CALL
315*cdf0e10cSrcweir SwVbaDocument::getValue( const ::rtl::OUString& aPropertyName ) throw (beans::UnknownPropertyException, uno::RuntimeException)
316*cdf0e10cSrcweir {
317*cdf0e10cSrcweir     uno::Reference< drawing::XControlShape > xControlShape( getControlShape( aPropertyName ), uno::UNO_QUERY_THROW );
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir     uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
320*cdf0e10cSrcweir     uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.ControlProvider" ) ), mxContext ), uno::UNO_QUERY_THROW );
321*cdf0e10cSrcweir     uno::Reference< msforms::XControl > xControl( xControlProvider->createControl(  xControlShape, getModel() ) );
322*cdf0e10cSrcweir     return uno::makeAny( xControl );
323*cdf0e10cSrcweir }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir ::sal_Bool SAL_CALL
326*cdf0e10cSrcweir SwVbaDocument::hasMethod( const ::rtl::OUString& /*aName*/ ) throw (uno::RuntimeException)
327*cdf0e10cSrcweir {
328*cdf0e10cSrcweir 	return sal_False;
329*cdf0e10cSrcweir }
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir ::sal_Bool SAL_CALL
332*cdf0e10cSrcweir SwVbaDocument::hasProperty( const ::rtl::OUString& aName ) throw (uno::RuntimeException)
333*cdf0e10cSrcweir {
334*cdf0e10cSrcweir 	uno::Reference< container::XNameAccess > xFormControls( getFormControls() );
335*cdf0e10cSrcweir 	if ( xFormControls.is() )
336*cdf0e10cSrcweir 		return xFormControls->hasByName( aName );
337*cdf0e10cSrcweir 	return sal_False;
338*cdf0e10cSrcweir }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir uno::Reference< container::XNameAccess >
341*cdf0e10cSrcweir SwVbaDocument::getFormControls()
342*cdf0e10cSrcweir {
343*cdf0e10cSrcweir 	uno::Reference< container::XNameAccess > xFormControls;
344*cdf0e10cSrcweir 	try
345*cdf0e10cSrcweir 	{
346*cdf0e10cSrcweir 		uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxTextDocument, uno::UNO_QUERY_THROW );
347*cdf0e10cSrcweir 		uno::Reference< form::XFormsSupplier >  xFormSupplier( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
348*cdf0e10cSrcweir     		uno::Reference< container::XIndexAccess > xIndexAccess( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
349*cdf0e10cSrcweir 		// get the www-standard container ( maybe we should access the
350*cdf0e10cSrcweir 		// 'www-standard' by name rather than index, this seems an
351*cdf0e10cSrcweir 		// implementation detail
352*cdf0e10cSrcweir 		xFormControls.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW );
353*cdf0e10cSrcweir 	}
354*cdf0e10cSrcweir 	catch( uno::Exception& )
355*cdf0e10cSrcweir 	{
356*cdf0e10cSrcweir 	}
357*cdf0e10cSrcweir 	return xFormControls;
358*cdf0e10cSrcweir }
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir uno::Sequence< rtl::OUString >
361*cdf0e10cSrcweir SwVbaDocument::getServiceNames()
362*cdf0e10cSrcweir {
363*cdf0e10cSrcweir 	static uno::Sequence< rtl::OUString > aServiceNames;
364*cdf0e10cSrcweir 	if ( aServiceNames.getLength() == 0 )
365*cdf0e10cSrcweir 	{
366*cdf0e10cSrcweir 		aServiceNames.realloc( 1 );
367*cdf0e10cSrcweir 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Document" ) );
368*cdf0e10cSrcweir 	}
369*cdf0e10cSrcweir 	return aServiceNames;
370*cdf0e10cSrcweir }
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir namespace document
373*cdf0e10cSrcweir {
374*cdf0e10cSrcweir namespace sdecl = comphelper::service_decl;
375*cdf0e10cSrcweir sdecl::vba_service_class_<SwVbaDocument, sdecl::with_args<true> > serviceImpl;
376*cdf0e10cSrcweir extern sdecl::ServiceDecl const serviceDecl(
377*cdf0e10cSrcweir     serviceImpl,
378*cdf0e10cSrcweir     "SwVbaDocument",
379*cdf0e10cSrcweir     "ooo.vba.word.Document" );
380*cdf0e10cSrcweir }
381*cdf0e10cSrcweir 
382