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