1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
23 #include "vbafilterpropsfromformat.hxx"
24 #include "vbacontentcontrols.hxx"
25 #include "vbadocument.hxx"
26 #include "vbaformfields.hxx"
27 #include "vbarange.hxx"
28 #include "vbarangehelper.hxx"
29 #include "vbadocumentproperties.hxx"
30 #include "vbabookmarks.hxx"
31 #include "vbamailmerge.hxx"
32 #include "vbavariables.hxx"
33 #include "vbawindow.hxx"
34 #include <comphelper/processfactory.hxx>
35 #include <comphelper/propertyvalue.hxx>
36 #include <cppu/unotype.hxx>
38 #include <com/sun/star/text/XBookmarksSupplier.hpp>
39 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
40 #include <com/sun/star/document/XDocumentProperties.hpp>
41 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
42 #include <com/sun/star/drawing/XControlShape.hpp>
43 #include <com/sun/star/form/XFormsSupplier.hpp>
44 #include <com/sun/star/frame/XStorable.hpp>
45 #include <com/sun/star/document/XRedlinesSupplier.hpp>
46 #include <com/sun/star/util/thePathSettings.hpp>
47 #include <ooo/vba/XControlProvider.hpp>
48 #include <ooo/vba/word/WdProtectionType.hpp>
49 #include <ooo/vba/word/WdSaveFormat.hpp>
50 #include <ooo/vba/word/XDocumentOutgoing.hpp>
52 #include "wordvbahelper.hxx"
55 #include "vbatemplate.hxx"
56 #include "vbaparagraph.hxx"
57 #include "vbastyles.hxx"
58 #include "vbatables.hxx"
59 #include "vbafield.hxx"
60 #include "vbapagesetup.hxx"
61 #include "vbasections.hxx"
62 #include "vbatablesofcontents.hxx"
63 #include <vbahelper/vbashapes.hxx>
64 #include <vbahelper/vbahelper.hxx>
65 #include "vbarevisions.hxx"
66 #include "vbaframes.hxx"
67 #include <basic/sberrors.hxx>
68 #include <osl/file.hxx>
69 #include <tools/urlobj.hxx>
70 #include <unotxdoc.hxx>
71 #include <unoredlines.hxx>
72 #include <unodraw.hxx>
73 #include <unobasestyle.hxx>
75 using namespace ::ooo::vba
;
76 using namespace ::com::sun::star
;
80 class SwVbaDocumentOutgoingConnectionPoint
: public cppu::WeakImplHelper
<XConnectionPoint
>
86 SwVbaDocumentOutgoingConnectionPoint( SwVbaDocument
* pDoc
);
89 sal_uInt32 SAL_CALL
Advise(const uno::Reference
< XSink
>& Sink
) override
;
90 void SAL_CALL
Unadvise( sal_uInt32 Cookie
) override
;
95 SwVbaDocument::SwVbaDocument( const uno::Reference
< XHelperInterface
>& xParent
,
96 const uno::Reference
< uno::XComponentContext
>& xContext
,
97 rtl::Reference
< SwXTextDocument
> const & xModel
)
98 : SwVbaDocument_BASE( xParent
, xContext
),
99 mxTextDocument(xModel
)
104 SwVbaDocument::SwVbaDocument( uno::Sequence
< uno::Any
> const& aArgs
, uno::Reference
< uno::XComponentContext
>const& xContext
)
105 : SwVbaDocument_BASE( aArgs
, xContext
),
106 mxTextDocument(dynamic_cast<SwXTextDocument
*>(getXSomethingFromArgs
< frame::XModel
>( aArgs
, 1 ).get()))
111 SwVbaDocument::~SwVbaDocument()
115 void SwVbaDocument::Initialize()
117 SwDocShell
& rDocSh
= *mxTextDocument
->GetDocShell();
118 rDocSh
.RegisterAutomationDocumentObject(this);
119 rDocSh
.GetDoc()->SetVbaEventProcessor();
123 SwVbaDocument::AddSink( const uno::Reference
< XSink
>& xSink
)
125 mxTextDocument
->GetDocShell()->RegisterAutomationDocumentEventsCaller( uno::Reference
< XSinkCaller
>(this) );
126 mvSinks
.push_back(xSink
);
127 return mvSinks
.size();
131 SwVbaDocument::RemoveSink( sal_uInt32 nNumber
)
133 if (nNumber
< 1 || nNumber
> mvSinks
.size())
136 mvSinks
[nNumber
-1] = uno::Reference
< XSink
>();
139 uno::Reference
< word::XRange
> SAL_CALL
140 SwVbaDocument::getContent()
142 uno::Reference
< text::XTextRange
> xStart
= mxTextDocument
->getText()->getStart();
143 uno::Reference
< text::XTextRange
> xEnd
;
144 return uno::Reference
< word::XRange
>( new SwVbaRange( this, mxContext
, mxTextDocument
, xStart
, xEnd
) );
147 uno::Reference
< word::XRange
> SAL_CALL
148 SwVbaDocument::Range( const uno::Any
& rStart
, const uno::Any
& rEnd
)
150 if( !rStart
.hasValue() && !rEnd
.hasValue() )
153 sal_Int32 nStart
= 0;
158 uno::Reference
< text::XTextRange
> xStart
;
159 uno::Reference
< text::XTextRange
> xEnd
;
162 throw uno::RuntimeException();
168 xStart
= mxTextDocument
->getText()->getEnd();
169 xEnd
= mxTextDocument
->getText()->getEnd();
173 xEnd
= SwVbaRangeHelper::getRangeByPosition( mxTextDocument
->getText(), nEnd
);
176 xStart
= SwVbaRangeHelper::getRangeByPosition( mxTextDocument
->getText(), nStart
);
178 xStart
= mxTextDocument
->getText()->getStart();
183 xStart
= mxTextDocument
->getText()->getEnd();
184 xEnd
= mxTextDocument
->getText()->getEnd();
187 if( !xStart
.is() && !xEnd
.is() )
192 xStart
= mxTextDocument
->getText()->getStart();
193 xEnd
= mxTextDocument
->getText()->getEnd();
195 catch(const uno::Exception
&)
197 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
200 return uno::Reference
< word::XRange
>( new SwVbaRange( this, mxContext
, mxTextDocument
, xStart
, xEnd
) );
204 SwVbaDocument::BuiltInDocumentProperties( const uno::Any
& index
)
206 uno::Reference
< XCollection
> xCol( new SwVbaBuiltinDocumentProperties( mxParent
, mxContext
, mxTextDocument
) );
207 if ( index
.hasValue() )
208 return xCol
->Item( index
, uno::Any() );
209 return uno::Any( xCol
);
213 SwVbaDocument::CustomDocumentProperties( const uno::Any
& index
)
215 uno::Reference
< XCollection
> xCol( new SwVbaCustomDocumentProperties( mxParent
, mxContext
, mxTextDocument
) );
216 if ( index
.hasValue() )
217 return xCol
->Item( index
, uno::Any() );
218 return uno::Any( xCol
);
222 SwVbaDocument::Bookmarks( const uno::Any
& rIndex
)
224 uno::Reference
< text::XBookmarksSupplier
> xBookmarksSupplier( getModel(),uno::UNO_QUERY_THROW
);
225 uno::Reference
<container::XIndexAccess
> xBookmarks( xBookmarksSupplier
->getBookmarks(), uno::UNO_QUERY_THROW
);
226 uno::Reference
< XCollection
> xBookmarksVba( new SwVbaBookmarks( this, mxContext
, xBookmarks
, mxTextDocument
) );
227 if ( rIndex
.getValueTypeClass() == uno::TypeClass_VOID
)
228 return uno::Any( xBookmarksVba
);
230 return xBookmarksVba
->Item( rIndex
, uno::Any() );
233 uno::Reference
< frame::XModel
> SwVbaDocument::getModel() const
234 { return static_cast<SfxBaseModel
*>(mxTextDocument
.get()); }
236 uno::Any
SwVbaDocument::ContentControls(const uno::Any
& index
)
238 uno::Reference
<XCollection
> xContentControls(
239 new SwVbaContentControls(this, mxContext
, mxTextDocument
, u
""_ustr
, u
""_ustr
));
240 if (index
.hasValue())
244 return xContentControls
->Item(index
, uno::Any());
246 catch (lang::IndexOutOfBoundsException
&)
248 // Hack: Instead of an index, it might be a float that was mistakenly treated as a long,
249 // which can happen with any valid positive integer when specified as a double like
250 // ActiveDocument.ContentControls(1841581653#).
251 if (index
.getValueTypeClass() == css::uno::TypeClass_LONG
)
255 return xContentControls
->Item(uno::Any(static_cast<double>(nLong
)), uno::Any());
260 return uno::Any(xContentControls
);
263 uno::Any
SwVbaDocument::SelectContentControlsByTag(const uno::Any
& index
)
267 return uno::Any(uno::Reference
<XCollection
>(
268 new SwVbaContentControls(this, mxContext
, mxTextDocument
, sTag
, u
""_ustr
)));
271 uno::Any
SwVbaDocument::SelectContentControlsByTitle(const uno::Any
& index
)
275 return uno::Any(uno::Reference
<XCollection
>(
276 new SwVbaContentControls(this, mxContext
, mxTextDocument
, u
""_ustr
, sTitle
)));
279 uno::Reference
<word::XWindow
> SwVbaDocument::getActiveWindow()
281 // copied from vbaapplication which has a #FIXME so far can't determine Parent
282 return new SwVbaWindow(uno::Reference
< XHelperInterface
>(), mxContext
, mxTextDocument
,
283 mxTextDocument
->getCurrentController());
287 SwVbaDocument::Variables( const uno::Any
& rIndex
)
289 uno::Reference
< css::document::XDocumentPropertiesSupplier
> xDocumentPropertiesSupplier( getModel(),uno::UNO_QUERY_THROW
);
290 uno::Reference
< css::document::XDocumentProperties
> xDocumentProperties
= xDocumentPropertiesSupplier
->getDocumentProperties();
291 uno::Reference
< beans::XPropertyAccess
> xUserDefined( xDocumentProperties
->getUserDefinedProperties(), uno::UNO_QUERY_THROW
);
293 uno::Reference
< XCollection
> xVariables( new SwVbaVariables( this, mxContext
, xUserDefined
) );
294 if ( rIndex
.getValueTypeClass() == uno::TypeClass_VOID
)
295 return uno::Any( xVariables
);
297 return xVariables
->Item( rIndex
, uno::Any() );
301 SwVbaDocument::Paragraphs( const uno::Any
& index
)
303 uno::Reference
< XCollection
> xCol( new SwVbaParagraphs( mxParent
, mxContext
, mxTextDocument
) );
304 if ( index
.hasValue() )
305 return xCol
->Item( index
, uno::Any() );
306 return uno::Any( xCol
);
310 SwVbaDocument::Styles( const uno::Any
& index
)
312 uno::Reference
< XCollection
> xCol( new SwVbaStyles( mxParent
, mxContext
, mxTextDocument
) );
313 if ( index
.hasValue() )
314 return xCol
->Item( index
, uno::Any() );
315 return uno::Any( xCol
);
319 SwVbaDocument::Fields( const uno::Any
& index
)
321 uno::Reference
< XCollection
> xCol( new SwVbaFields( mxParent
, mxContext
, mxTextDocument
) );
322 if ( index
.hasValue() )
323 return xCol
->Item( index
, uno::Any() );
324 return uno::Any( xCol
);
328 SwVbaDocument::Shapes( const uno::Any
& index
)
330 rtl::Reference
< SwFmDrawPage
> xIndexAccess( mxTextDocument
->getSwDrawPage() );
331 uno::Reference
< XCollection
> xCol( new ScVbaShapes( this, mxContext
, xIndexAccess
, static_cast<SfxBaseModel
*>(mxTextDocument
.get()) ) );
333 if ( index
.hasValue() )
334 return xCol
->Item( index
, uno::Any() );
335 return uno::Any( xCol
);
339 SwVbaDocument::Select()
341 auto xRange
= getContent();
347 SwVbaDocument::Sections( const uno::Any
& index
)
349 uno::Reference
< XCollection
> xCol( new SwVbaSections( mxParent
, mxContext
, mxTextDocument
) );
350 if ( index
.hasValue() )
351 return xCol
->Item( index
, uno::Any() );
352 return uno::Any( xCol
);
356 SwVbaDocument::TablesOfContents( const uno::Any
& index
)
358 uno::Reference
< XCollection
> xCol( new SwVbaTablesOfContents( this, mxContext
, mxTextDocument
) );
359 if ( index
.hasValue() )
360 return xCol
->Item( index
, uno::Any() );
361 return uno::Any( xCol
);
364 uno::Any SAL_CALL
SwVbaDocument::FormFields(const uno::Any
& index
)
366 uno::Reference
<XCollection
> xCol(new SwVbaFormFields(this, mxContext
, mxTextDocument
));
367 if (index
.hasValue())
368 return xCol
->Item(index
, uno::Any());
369 return uno::Any(xCol
);
373 SwVbaDocument::PageSetup( )
375 rtl::Reference
< SwXBaseStyle
> xPageProps( word::getCurrentPageStyle( mxTextDocument
) );
376 return uno::Any( uno::Reference
< word::XPageSetup
>( new SwVbaPageSetup( this, mxContext
, mxTextDocument
, xPageProps
) ) );
380 SwVbaDocument::getServiceImplName()
382 return u
"SwVbaDocument"_ustr
;
386 SwVbaDocument::getAttachedTemplate()
388 uno::Reference
< word::XTemplate
> xTemplate
;
389 uno::Reference
<css::document::XDocumentPropertiesSupplier
> const xDocPropSupp(
390 getModel(), uno::UNO_QUERY_THROW
);
391 uno::Reference
< css::document::XDocumentProperties
> xDocProps( xDocPropSupp
->getDocumentProperties(), uno::UNO_SET_THROW
);
393 xTemplate
= new SwVbaTemplate( this, mxContext
, xDocProps
->getTemplateURL() );
394 return uno::Any( xTemplate
);
398 SwVbaDocument::setAttachedTemplate( const css::uno::Any
& _attachedtemplate
)
401 if( !( _attachedtemplate
>>= sTemplate
) )
403 throw uno::RuntimeException();
407 aObj
.SetURL( sTemplate
);
408 bool bIsURL
= aObj
.GetProtocol() != INetProtocol::NotValid
;
412 osl::FileBase::getFileURLFromSystemPath( sTemplate
, aURL
);
414 uno::Reference
<css::document::XDocumentPropertiesSupplier
> const xDocPropSupp(
415 getModel(), uno::UNO_QUERY_THROW
);
416 uno::Reference
< css::document::XDocumentProperties
> xDocProps( xDocPropSupp
->getDocumentProperties(), uno::UNO_SET_THROW
);
417 xDocProps
->setTemplateURL( aURL
);
421 SwVbaDocument::Tables( const css::uno::Any
& aIndex
)
423 uno::Reference
< XCollection
> xColl( new SwVbaTables( mxParent
, mxContext
, mxTextDocument
) );
425 if ( aIndex
.hasValue() )
426 return xColl
->Item( aIndex
, uno::Any() );
427 return uno::Any( xColl
);
430 void SAL_CALL
SwVbaDocument::Activate()
432 VbaDocumentBase::Activate();
435 ::sal_Int32 SAL_CALL
SwVbaDocument::getProtectionType()
438 return word::WdProtectionType::wdNoProtection
;
441 void SAL_CALL
SwVbaDocument::setProtectionType( ::sal_Int32
/*_protectiontype*/ )
446 sal_Bool SAL_CALL
SwVbaDocument::getUpdateStylesOnOpen()
452 void SAL_CALL
SwVbaDocument::setUpdateStylesOnOpen( sal_Bool
/*_updatestylesonopen*/ )
457 sal_Bool SAL_CALL
SwVbaDocument::getAutoHyphenation()
459 // check this property only in default paragraph style
460 bool IsAutoHyphenation
= false;
461 rtl::Reference
< SwXBaseStyle
> xParaProps( word::getDefaultParagraphStyle( mxTextDocument
) );
462 xParaProps
->getPropertyValue(u
"ParaIsHyphenation"_ustr
) >>= IsAutoHyphenation
;
463 return IsAutoHyphenation
;
466 void SAL_CALL
SwVbaDocument::setAutoHyphenation( sal_Bool _autohyphenation
)
469 rtl::Reference
< SwXBaseStyle
> xParaProps( word::getDefaultParagraphStyle( mxTextDocument
) );
470 xParaProps
->setPropertyValue(u
"ParaIsHyphenation"_ustr
, uno::Any( _autohyphenation
) );
473 ::sal_Int32 SAL_CALL
SwVbaDocument::getHyphenationZone()
479 void SAL_CALL
SwVbaDocument::setHyphenationZone( ::sal_Int32
/*_hyphenationzone*/ )
484 ::sal_Int32 SAL_CALL
SwVbaDocument::getConsecutiveHyphensLimit()
487 sal_Int16 nHyphensLimit
= 0;
488 rtl::Reference
< SwXBaseStyle
> xParaProps( word::getDefaultParagraphStyle( mxTextDocument
) );
489 xParaProps
->getPropertyValue(u
"ParaHyphenationMaxHyphens"_ustr
) >>= nHyphensLimit
;
490 return nHyphensLimit
;
493 void SAL_CALL
SwVbaDocument::setConsecutiveHyphensLimit( ::sal_Int32 _consecutivehyphenslimit
)
495 sal_Int16 nHyphensLimit
= static_cast< sal_Int16
>( _consecutivehyphenslimit
);
496 rtl::Reference
< SwXBaseStyle
> xParaProps( word::getDefaultParagraphStyle( mxTextDocument
) );
497 xParaProps
->setPropertyValue(u
"ParaHyphenationMaxHyphens"_ustr
, uno::Any( nHyphensLimit
) );
500 uno::Reference
< ooo::vba::word::XMailMerge
> SAL_CALL
SwVbaDocument::getMailMerge()
502 return SwVbaMailMerge::get(mxParent
, mxContext
);
505 void SAL_CALL
SwVbaDocument::Protect( ::sal_Int32
/*Type*/, const uno::Any
& /*NOReset*/, const uno::Any
& /*Password*/, const uno::Any
& /*UseIRM*/, const uno::Any
& /*EnforceStyleLock*/ )
507 // Seems not support in Writer
508 // VbaDocumentBase::Protect( Password );
511 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*/ )
516 void SAL_CALL
SwVbaDocument::PrintPreview( )
518 dispatchRequests( static_cast<SfxBaseModel
*>(mxTextDocument
.get()), u
".uno:PrintPreview"_ustr
);
521 void SAL_CALL
SwVbaDocument::ClosePrintPreview( )
523 dispatchRequests( static_cast<SfxBaseModel
*>(mxTextDocument
.get()), u
".uno:ClosePreview"_ustr
);
527 SwVbaDocument::Revisions( const uno::Any
& index
)
529 rtl::Reference
< SwXRedlines
> xRedlines( mxTextDocument
->getSwRedlines() );
530 uno::Reference
< XCollection
> xCol( new SwVbaRevisions( this, mxContext
, mxTextDocument
, xRedlines
) );
531 if ( index
.hasValue() )
532 return xCol
->Item( index
, uno::Any() );
533 return uno::Any( xCol
);
537 SwVbaDocument::Frames( const uno::Any
& index
)
539 rtl::Reference
< SwXTextFrames
> xFrames( mxTextDocument
->getSwTextFrames() );
540 uno::Reference
< XCollection
> xCol( new SwVbaFrames( this, mxContext
, xFrames
, mxTextDocument
) );
541 if ( index
.hasValue() )
542 return xCol
->Item( index
, uno::Any() );
543 return uno::Any( xCol
);
547 SwVbaDocument::SaveAs2000( const uno::Any
& FileName
, const uno::Any
& FileFormat
, const uno::Any
& /*LockComments*/, const uno::Any
& /*Password*/, const uno::Any
& /*AddToRecentFiles*/, const uno::Any
& /*WritePassword*/, const uno::Any
& /*ReadOnlyRecommended*/, const uno::Any
& /*EmbedTrueTypeFonts*/, const uno::Any
& /*SaveNativePictureFormat*/, const uno::Any
& /*SaveFormsData*/, const uno::Any
& /*SaveAsAOCELetter*/ )
549 SAL_INFO("sw.vba", "Document.SaveAs2000(FileName:=" << FileName
<< ",FileFormat:=" << FileFormat
<< ")");
551 // Based on ScVbaWorkbook::SaveAs.
553 FileName
>>= sFileName
;
555 osl::FileBase::getFileURLFromSystemPath( sFileName
, sURL
);
557 // Detect if there is no path then we need to use the current folder.
558 INetURLObject
aURL( sURL
);
559 sURL
= aURL
.GetMainURL( INetURLObject::DecodeMechanism::ToIUri
);
562 // Need to add cur dir ( of this document ) or else the 'Work' dir
563 sURL
= getModel()->getURL();
565 if ( sURL
.isEmpty() )
567 // Not path available from 'this' document. Need to add the 'document'/work directory then.
568 // Based on SwVbaOptions::getValueEvent()
569 uno::Reference
< util::XPathSettings
> xPathSettings
= util::thePathSettings::get( comphelper::getProcessComponentContext() );
571 xPathSettings
->getPropertyValue( u
"Work"_ustr
) >>= sPathUrl
;
572 // Path could be a multipath, Microsoft doesn't support this feature in Word currently.
573 // Only the last path is from interest.
574 sal_Int32 nIndex
= sPathUrl
.lastIndexOf( ';' );
577 sPathUrl
= sPathUrl
.copy( nIndex
+ 1 );
580 aURL
.SetURL( sPathUrl
);
585 aURL
.Append( sFileName
);
587 sURL
= aURL
.GetMainURL( INetURLObject::DecodeMechanism::ToIUri
);
591 sal_Int32 nFileFormat
= word::WdSaveFormat::wdFormatDocument
;
592 FileFormat
>>= nFileFormat
;
594 uno::Sequence storeProps
{ comphelper::makePropertyValue(u
"FilterName"_ustr
, uno::Any()) };
596 setFilterPropsFromFormat( nFileFormat
, storeProps
);
598 uno::Reference
< frame::XStorable
> xStor( getModel(), uno::UNO_QUERY_THROW
);
599 xStor
->storeAsURL( sURL
, storeProps
);
603 SwVbaDocument::SaveAs( const uno::Any
& FileName
, const uno::Any
& FileFormat
, const uno::Any
& LockComments
, const uno::Any
& Password
, const uno::Any
& AddToRecentFiles
, const uno::Any
& WritePassword
, const uno::Any
& ReadOnlyRecommended
, const uno::Any
& EmbedTrueTypeFonts
, const uno::Any
& SaveNativePictureFormat
, const uno::Any
& SaveFormsData
, const uno::Any
& SaveAsAOCELetter
, const uno::Any
& /*Encoding*/, const uno::Any
& /*InsertLineBreaks*/, const uno::Any
& /*AllowSubstitutions*/, const uno::Any
& /*LineEnding*/, const uno::Any
& /*AddBiDiMarks*/ )
605 return SaveAs2000( FileName
, FileFormat
, LockComments
, Password
, AddToRecentFiles
, WritePassword
, ReadOnlyRecommended
, EmbedTrueTypeFonts
, SaveNativePictureFormat
, SaveFormsData
, SaveAsAOCELetter
);
609 SwVbaDocument::Close( const uno::Any
& SaveChanges
, const uno::Any
& /*OriginalFormat*/, const uno::Any
& /*RouteDocument*/ )
611 VbaDocumentBase::Close( SaveChanges
, uno::Any(), uno::Any() );
615 SwVbaDocument::SavePreviewPngAs( const uno::Any
& FileName
)
618 FileName
>>= sFileName
;
620 osl::FileBase::getFileURLFromSystemPath( sFileName
, sURL
);
622 uno::Sequence storeProps
{ comphelper::makePropertyValue(u
"FilterName"_ustr
,
623 u
"writer_png_Export"_ustr
) };
625 uno::Reference
< frame::XStorable
> xStor( getModel(), uno::UNO_QUERY_THROW
);
626 xStor
->storeToURL( sURL
, storeProps
);
630 SwVbaDocument::getControlShape( std::u16string_view sName
)
632 rtl::Reference
< SwFmDrawPage
> xIndexAccess( mxTextDocument
->getSwDrawPage() );
634 sal_Int32 nCount
= xIndexAccess
->getCount();
635 for( int index
= 0; index
< nCount
; index
++ )
637 uno::Any aUnoObj
= xIndexAccess
->getByIndex( index
);
638 // It seems there are some drawing objects that can not query into Control shapes?
639 uno::Reference
< drawing::XControlShape
> xControlShape( aUnoObj
, uno::UNO_QUERY
);
640 if( xControlShape
.is() )
642 uno::Reference
< container::XNamed
> xNamed( xControlShape
->getControl(), uno::UNO_QUERY_THROW
);
643 if( sName
== xNamed
->getName() )
652 uno::Reference
< beans::XIntrospectionAccess
> SAL_CALL
653 SwVbaDocument::getIntrospection( )
655 return uno::Reference
< beans::XIntrospectionAccess
>();
659 SwVbaDocument::invoke( const OUString
& aFunctionName
, const uno::Sequence
< uno::Any
>& /*aParams*/, uno::Sequence
< ::sal_Int16
>& /*aOutParamIndex*/, uno::Sequence
< uno::Any
>& /*aOutParam*/ )
661 SAL_INFO("sw.vba", "** will barf " << aFunctionName
);
662 throw uno::RuntimeException(); // unsupported operation
666 SwVbaDocument::setValue( const OUString
& /*aPropertyName*/, const uno::Any
& /*aValue*/ )
668 throw uno::RuntimeException(); // unsupported operation
671 SwVbaDocument::getValue( const OUString
& aPropertyName
)
673 uno::Reference
< drawing::XControlShape
> xControlShape( getControlShape( aPropertyName
), uno::UNO_QUERY_THROW
);
675 uno::Reference
<lang::XMultiComponentFactory
> xServiceManager( mxContext
->getServiceManager(), uno::UNO_SET_THROW
);
676 uno::Reference
< XControlProvider
> xControlProvider( xServiceManager
->createInstanceWithContext(u
"ooo.vba.ControlProvider"_ustr
, mxContext
), uno::UNO_QUERY_THROW
);
677 uno::Reference
< msforms::XControl
> xControl( xControlProvider
->createControl( xControlShape
, getModel() ) );
678 return uno::Any( xControl
);
682 SwVbaDocument::hasMethod( const OUString
& /*aName*/ )
688 SwVbaDocument::hasProperty( const OUString
& aName
)
690 uno::Reference
< container::XNameAccess
> xFormControls( getFormControls() );
691 if ( xFormControls
.is() )
692 return xFormControls
->hasByName( aName
);
696 uno::Reference
< container::XNameAccess
>
697 SwVbaDocument::getFormControls() const
699 uno::Reference
< container::XNameAccess
> xFormControls
;
702 rtl::Reference
< SwFmDrawPage
> xFormSupplier( mxTextDocument
->getSwDrawPage() );
704 return xFormControls
;
705 uno::Reference
< container::XIndexAccess
> xIndexAccess( xFormSupplier
->getForms(), uno::UNO_QUERY
);
707 return xFormControls
;
708 // get the www-standard container ( maybe we should access the
709 // 'www-standard' by name rather than index, this seems an
710 // implementation detail
711 xFormControls
.set( xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
713 catch(const uno::Exception
&)
716 return xFormControls
;
722 SwVbaDocument::getIID()
724 return u
"{82154424-0FBF-11d4-8313-005004526AB4}"_ustr
;
730 SwVbaDocument::GetIIDForClassItselfNotCoclass()
732 return u
"{82154428-0FBF-11D4-8313-005004526AB4}"_ustr
;
736 SwVbaDocument::GetConnectionPoint()
739 { cppu::UnoType
<word::XDocumentOutgoing
>::get(),
740 u
"{82154429-0FBF-11D4-8313-005004526AB4}"_ustr
749 SwVbaDocument::CallSinks( const OUString
& Method
, uno::Sequence
< uno::Any
>& Arguments
)
751 for (auto& i
: mvSinks
)
754 i
->Call(Method
, Arguments
);
758 uno::Reference
<XConnectionPoint
> SAL_CALL
759 SwVbaDocument::FindConnectionPoint()
761 uno::Reference
<XConnectionPoint
> xCP(new SwVbaDocumentOutgoingConnectionPoint(this));
765 // SwVbaApplicationOutgoingConnectionPoint
767 SwVbaDocumentOutgoingConnectionPoint::SwVbaDocumentOutgoingConnectionPoint( SwVbaDocument
* pDoc
) :
775 SwVbaDocumentOutgoingConnectionPoint::Advise( const uno::Reference
< XSink
>& Sink
)
777 return mpDoc
->AddSink(Sink
);
781 SwVbaDocumentOutgoingConnectionPoint::Unadvise( sal_uInt32 Cookie
)
783 mpDoc
->RemoveSink( Cookie
);
786 uno::Sequence
< OUString
>
787 SwVbaDocument::getServiceNames()
789 static uno::Sequence
< OUString
> const aServiceNames
791 u
"ooo.vba.word.Document"_ustr
793 return aServiceNames
;
796 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
797 Writer_SwVbaDocument_get_implementation(
798 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const& args
)
800 return cppu::acquire(new SwVbaDocument(args
, context
));
804 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */