sc: factor out some more code
[LibreOffice.git] / sw / source / ui / vba / vbadocument.cxx
blobb742f6f843e18cd48b858679ace4b4e1bfd18a72
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
53 #include <doc.hxx>
54 #include <docsh.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;
78 namespace {
80 class SwVbaDocumentOutgoingConnectionPoint : public cppu::WeakImplHelper<XConnectionPoint>
82 private:
83 SwVbaDocument* mpDoc;
85 public:
86 SwVbaDocumentOutgoingConnectionPoint( SwVbaDocument* pDoc );
88 // XConnectionPoint
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)
101 Initialize();
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()))
108 Initialize();
111 SwVbaDocument::~SwVbaDocument()
115 void SwVbaDocument::Initialize()
117 SwDocShell& rDocSh = *mxTextDocument->GetDocShell();
118 rDocSh.RegisterAutomationDocumentObject(this);
119 rDocSh.GetDoc()->SetVbaEventProcessor();
122 sal_uInt32
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();
130 void
131 SwVbaDocument::RemoveSink( sal_uInt32 nNumber )
133 if (nNumber < 1 || nNumber > mvSinks.size())
134 return;
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() )
151 return getContent();
153 sal_Int32 nStart = 0;
154 sal_Int32 nEnd = 0;
155 rStart >>= nStart;
156 rEnd >>= nEnd;
158 uno::Reference< text::XTextRange > xStart;
159 uno::Reference< text::XTextRange > xEnd;
161 if( nStart > nEnd)
162 throw uno::RuntimeException();
164 if( nEnd != 0)
166 if( nEnd == nStart )
168 xStart = mxTextDocument->getText()->getEnd();
169 xEnd = mxTextDocument->getText()->getEnd();
171 else
173 xEnd = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nEnd );
175 if( nStart != 0 )
176 xStart = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nStart );
177 else
178 xStart = mxTextDocument->getText()->getStart();
181 else
183 xStart = mxTextDocument->getText()->getEnd();
184 xEnd = mxTextDocument->getText()->getEnd();
187 if( !xStart.is() && !xEnd.is() )
191 // FIXME
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 ) );
203 uno::Any SAL_CALL
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 );
212 uno::Any SAL_CALL
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 );
221 uno::Any SAL_CALL
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)
253 sal_Int32 nLong(0);
254 index >>= nLong;
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)
265 OUString sTag;
266 index >>= sTag;
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)
273 OUString sTitle;
274 index >>= sTitle;
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());
286 uno::Any SAL_CALL
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() );
300 uno::Any SAL_CALL
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 );
309 uno::Any SAL_CALL
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 );
318 uno::Any SAL_CALL
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 );
327 uno::Any SAL_CALL
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 );
338 void SAL_CALL
339 SwVbaDocument::Select()
341 auto xRange = getContent();
342 if ( xRange )
343 xRange->Select();
346 uno::Any SAL_CALL
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 );
355 uno::Any SAL_CALL
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);
372 uno::Any SAL_CALL
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 ) ) );
379 OUString
380 SwVbaDocument::getServiceImplName()
382 return u"SwVbaDocument"_ustr;
385 uno::Any SAL_CALL
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 );
397 void SAL_CALL
398 SwVbaDocument::setAttachedTemplate( const css::uno::Any& _attachedtemplate )
400 OUString sTemplate;
401 if( !( _attachedtemplate >>= sTemplate ) )
403 throw uno::RuntimeException();
405 OUString aURL;
406 INetURLObject aObj;
407 aObj.SetURL( sTemplate );
408 bool bIsURL = aObj.GetProtocol() != INetProtocol::NotValid;
409 if ( bIsURL )
410 aURL = sTemplate;
411 else
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 );
420 uno::Any SAL_CALL
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()
437 //TODO
438 return word::WdProtectionType::wdNoProtection;
441 void SAL_CALL SwVbaDocument::setProtectionType( ::sal_Int32 /*_protectiontype*/ )
443 //TODO
446 sal_Bool SAL_CALL SwVbaDocument::getUpdateStylesOnOpen()
448 //TODO
449 return false;
452 void SAL_CALL SwVbaDocument::setUpdateStylesOnOpen( sal_Bool /*_updatestylesonopen*/ )
454 //TODO
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 )
468 //TODO
469 rtl::Reference< SwXBaseStyle > xParaProps( word::getDefaultParagraphStyle( mxTextDocument ) );
470 xParaProps->setPropertyValue(u"ParaIsHyphenation"_ustr, uno::Any( _autohyphenation ) );
473 ::sal_Int32 SAL_CALL SwVbaDocument::getHyphenationZone()
475 //TODO
476 return 0;
479 void SAL_CALL SwVbaDocument::setHyphenationZone( ::sal_Int32 /*_hyphenationzone*/ )
481 //TODO
484 ::sal_Int32 SAL_CALL SwVbaDocument::getConsecutiveHyphensLimit()
486 //TODO
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*/ )
513 //TODO
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 );
526 uno::Any SAL_CALL
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 );
536 uno::Any SAL_CALL
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 );
546 void SAL_CALL
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.
552 OUString sFileName;
553 FileName >>= sFileName;
554 OUString sURL;
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 );
560 if( sURL.isEmpty() )
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() );
570 OUString sPathUrl;
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( ';' );
575 if( nIndex != -1 )
577 sPathUrl = sPathUrl.copy( nIndex + 1 );
580 aURL.SetURL( sPathUrl );
582 else
584 aURL.SetURL( sURL );
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 );
602 void SAL_CALL
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 );
608 void SAL_CALL
609 SwVbaDocument::Close( const uno::Any& SaveChanges, const uno::Any& /*OriginalFormat*/, const uno::Any& /*RouteDocument*/ )
611 VbaDocumentBase::Close( SaveChanges, uno::Any(), uno::Any() );
614 void SAL_CALL
615 SwVbaDocument::SavePreviewPngAs( const uno::Any& FileName )
617 OUString sFileName;
618 FileName >>= sFileName;
619 OUString sURL;
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 );
629 uno::Any
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() )
645 return aUnoObj;
649 return uno::Any();
652 uno::Reference< beans::XIntrospectionAccess > SAL_CALL
653 SwVbaDocument::getIntrospection( )
655 return uno::Reference< beans::XIntrospectionAccess >();
658 uno::Any SAL_CALL
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
665 void SAL_CALL
666 SwVbaDocument::setValue( const OUString& /*aPropertyName*/, const uno::Any& /*aValue*/ )
668 throw uno::RuntimeException(); // unsupported operation
670 uno::Any SAL_CALL
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 );
681 sal_Bool SAL_CALL
682 SwVbaDocument::hasMethod( const OUString& /*aName*/ )
684 return false;
687 sal_Bool SAL_CALL
688 SwVbaDocument::hasProperty( const OUString& aName )
690 uno::Reference< container::XNameAccess > xFormControls( getFormControls() );
691 if ( xFormControls.is() )
692 return xFormControls->hasByName( aName );
693 return false;
696 uno::Reference< container::XNameAccess >
697 SwVbaDocument::getFormControls() const
699 uno::Reference< container::XNameAccess > xFormControls;
702 rtl::Reference< SwFmDrawPage > xFormSupplier( mxTextDocument->getSwDrawPage() );
703 if (!xFormSupplier)
704 return xFormControls;
705 uno::Reference< container::XIndexAccess > xIndexAccess( xFormSupplier->getForms(), uno::UNO_QUERY );
706 if (!xIndexAccess)
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;
719 // XInterfaceWithIID
721 OUString SAL_CALL
722 SwVbaDocument::getIID()
724 return u"{82154424-0FBF-11d4-8313-005004526AB4}"_ustr;
727 // XConnectable
729 OUString SAL_CALL
730 SwVbaDocument::GetIIDForClassItselfNotCoclass()
732 return u"{82154428-0FBF-11D4-8313-005004526AB4}"_ustr;
735 TypeAndIID SAL_CALL
736 SwVbaDocument::GetConnectionPoint()
738 TypeAndIID aResult =
739 { cppu::UnoType<word::XDocumentOutgoing>::get(),
740 u"{82154429-0FBF-11D4-8313-005004526AB4}"_ustr
743 return aResult;
746 // XSinkCaller
748 void SAL_CALL
749 SwVbaDocument::CallSinks( const OUString& Method, uno::Sequence< uno::Any >& Arguments )
751 for (auto& i : mvSinks)
753 if (i.is())
754 i->Call(Method, Arguments);
758 uno::Reference<XConnectionPoint> SAL_CALL
759 SwVbaDocument::FindConnectionPoint()
761 uno::Reference<XConnectionPoint> xCP(new SwVbaDocumentOutgoingConnectionPoint(this));
762 return xCP;
765 // SwVbaApplicationOutgoingConnectionPoint
767 SwVbaDocumentOutgoingConnectionPoint::SwVbaDocumentOutgoingConnectionPoint( SwVbaDocument* pDoc ) :
768 mpDoc(pDoc)
772 // XConnectionPoint
774 sal_uInt32 SAL_CALL
775 SwVbaDocumentOutgoingConnectionPoint::Advise( const uno::Reference< XSink >& Sink )
777 return mpDoc->AddSink(Sink);
780 void SAL_CALL
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: */