android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / vba / vbadocument.cxx
blobc8985464501d05a5d0b53236beeb4a832701f0c4
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>
71 using namespace ::ooo::vba;
72 using namespace ::com::sun::star;
74 namespace {
76 class SwVbaDocumentOutgoingConnectionPoint : public cppu::WeakImplHelper<XConnectionPoint>
78 private:
79 SwVbaDocument* mpDoc;
81 public:
82 SwVbaDocumentOutgoingConnectionPoint( SwVbaDocument* pDoc );
84 // XConnectionPoint
85 sal_uInt32 SAL_CALL Advise(const uno::Reference< XSink >& Sink ) override;
86 void SAL_CALL Unadvise( sal_uInt32 Cookie ) override;
91 SwVbaDocument::SwVbaDocument( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< frame::XModel > const & xModel ): SwVbaDocument_BASE( xParent, xContext, xModel )
93 Initialize();
95 SwVbaDocument::SwVbaDocument( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& xContext ) : SwVbaDocument_BASE( aArgs, xContext )
97 Initialize();
100 SwVbaDocument::~SwVbaDocument()
104 void SwVbaDocument::Initialize()
106 mxTextDocument.set( getModel(), uno::UNO_QUERY_THROW );
107 SwDocShell& rDocSh = *word::getDocShell(mxModel);
108 rDocSh.RegisterAutomationDocumentObject(this);
109 rDocSh.GetDoc()->SetVbaEventProcessor();
112 sal_uInt32
113 SwVbaDocument::AddSink( const uno::Reference< XSink >& xSink )
115 word::getDocShell( mxModel )->RegisterAutomationDocumentEventsCaller( uno::Reference< XSinkCaller >(this) );
116 mvSinks.push_back(xSink);
117 return mvSinks.size();
120 void
121 SwVbaDocument::RemoveSink( sal_uInt32 nNumber )
123 if (nNumber < 1 || nNumber > mvSinks.size())
124 return;
126 mvSinks[nNumber-1] = uno::Reference< XSink >();
129 uno::Reference< word::XRange > SAL_CALL
130 SwVbaDocument::getContent()
132 uno::Reference< text::XTextRange > xStart = mxTextDocument->getText()->getStart();
133 uno::Reference< text::XTextRange > xEnd;
134 return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, xStart, xEnd ) );
137 uno::Reference< word::XRange > SAL_CALL
138 SwVbaDocument::Range( const uno::Any& rStart, const uno::Any& rEnd )
140 if( !rStart.hasValue() && !rEnd.hasValue() )
141 return getContent();
143 sal_Int32 nStart = 0;
144 sal_Int32 nEnd = 0;
145 rStart >>= nStart;
146 rEnd >>= nEnd;
148 uno::Reference< text::XTextRange > xStart;
149 uno::Reference< text::XTextRange > xEnd;
151 if( nStart > nEnd)
152 throw uno::RuntimeException();
154 if( nEnd != 0)
156 if( nEnd == nStart )
158 xStart = mxTextDocument->getText()->getEnd();
159 xEnd = mxTextDocument->getText()->getEnd();
161 else
163 xEnd = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nEnd );
165 if( nStart != 0 )
166 xStart = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nStart );
167 else
168 xStart = mxTextDocument->getText()->getStart();
171 else
173 xStart = mxTextDocument->getText()->getEnd();
174 xEnd = mxTextDocument->getText()->getEnd();
177 if( !xStart.is() && !xEnd.is() )
181 // FIXME
182 xStart = mxTextDocument->getText()->getStart();
183 xEnd = mxTextDocument->getText()->getEnd();
185 catch(const uno::Exception&)
187 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
190 return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, xStart, xEnd ) );
193 uno::Any SAL_CALL
194 SwVbaDocument::BuiltInDocumentProperties( const uno::Any& index )
196 uno::Reference< XCollection > xCol( new SwVbaBuiltinDocumentProperties( mxParent, mxContext, getModel() ) );
197 if ( index.hasValue() )
198 return xCol->Item( index, uno::Any() );
199 return uno::Any( xCol );
202 uno::Any SAL_CALL
203 SwVbaDocument::CustomDocumentProperties( const uno::Any& index )
205 uno::Reference< XCollection > xCol( new SwVbaCustomDocumentProperties( mxParent, mxContext, getModel() ) );
206 if ( index.hasValue() )
207 return xCol->Item( index, uno::Any() );
208 return uno::Any( xCol );
211 uno::Any SAL_CALL
212 SwVbaDocument::Bookmarks( const uno::Any& rIndex )
214 uno::Reference< text::XBookmarksSupplier > xBookmarksSupplier( getModel(),uno::UNO_QUERY_THROW );
215 uno::Reference<container::XIndexAccess > xBookmarks( xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY_THROW );
216 uno::Reference< XCollection > xBookmarksVba( new SwVbaBookmarks( this, mxContext, xBookmarks, getModel() ) );
217 if ( rIndex.getValueTypeClass() == uno::TypeClass_VOID )
218 return uno::Any( xBookmarksVba );
220 return xBookmarksVba->Item( rIndex, uno::Any() );
223 uno::Any SwVbaDocument::ContentControls(const uno::Any& index)
225 uno::Reference<XCollection> xContentControls(
226 new SwVbaContentControls(this, mxContext, mxTextDocument, "", ""));
227 if (index.hasValue())
231 return xContentControls->Item(index, uno::Any());
233 catch (lang::IndexOutOfBoundsException&)
235 // Hack: Instead of an index, it might be a float that was mistakenly treated as a long,
236 // which can happen with any valid positive integer when specified as a double like
237 // ActiveDocument.ContentControls(1841581653#).
238 if (index.getValueTypeClass() == css::uno::TypeClass_LONG)
240 sal_Int32 nLong(0);
241 index >>= nLong;
242 return xContentControls->Item(uno::Any(static_cast<double>(nLong)), uno::Any());
247 return uno::Any(xContentControls);
250 uno::Any SwVbaDocument::SelectContentControlsByTag(const uno::Any& index)
252 OUString sTag;
253 index >>= sTag;
254 return uno::Any(uno::Reference<XCollection>(
255 new SwVbaContentControls(this, mxContext, mxTextDocument, sTag, "")));
258 uno::Any SwVbaDocument::SelectContentControlsByTitle(const uno::Any& index)
260 OUString sTitle;
261 index >>= sTitle;
262 return uno::Any(uno::Reference<XCollection>(
263 new SwVbaContentControls(this, mxContext, mxTextDocument, "", sTitle)));
266 uno::Reference<word::XWindow> SwVbaDocument::getActiveWindow()
268 // copied from vbaapplication which has a #FIXME so far can't determine Parent
269 return new SwVbaWindow(uno::Reference< XHelperInterface >(), mxContext, mxModel,
270 mxModel->getCurrentController());
273 uno::Any SAL_CALL
274 SwVbaDocument::Variables( const uno::Any& rIndex )
276 uno::Reference< css::document::XDocumentPropertiesSupplier > xDocumentPropertiesSupplier( getModel(),uno::UNO_QUERY_THROW );
277 uno::Reference< css::document::XDocumentProperties > xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties();
278 uno::Reference< beans::XPropertyAccess > xUserDefined( xDocumentProperties->getUserDefinedProperties(), uno::UNO_QUERY_THROW );
280 uno::Reference< XCollection > xVariables( new SwVbaVariables( this, mxContext, xUserDefined ) );
281 if ( rIndex.getValueTypeClass() == uno::TypeClass_VOID )
282 return uno::Any( xVariables );
284 return xVariables->Item( rIndex, uno::Any() );
287 uno::Any SAL_CALL
288 SwVbaDocument::Paragraphs( const uno::Any& index )
290 uno::Reference< XCollection > xCol( new SwVbaParagraphs( mxParent, mxContext, mxTextDocument ) );
291 if ( index.hasValue() )
292 return xCol->Item( index, uno::Any() );
293 return uno::Any( xCol );
296 uno::Any SAL_CALL
297 SwVbaDocument::Styles( const uno::Any& index )
299 uno::Reference< XCollection > xCol( new SwVbaStyles( mxParent, mxContext, getModel() ) );
300 if ( index.hasValue() )
301 return xCol->Item( index, uno::Any() );
302 return uno::Any( xCol );
305 uno::Any SAL_CALL
306 SwVbaDocument::Fields( const uno::Any& index )
308 uno::Reference< XCollection > xCol( new SwVbaFields( mxParent, mxContext, getModel() ) );
309 if ( index.hasValue() )
310 return xCol->Item( index, uno::Any() );
311 return uno::Any( xCol );
314 uno::Any SAL_CALL
315 SwVbaDocument::Shapes( const uno::Any& index )
317 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( getModel(), uno::UNO_QUERY_THROW );
318 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
319 uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
320 uno::Reference< XCollection > xCol( new ScVbaShapes( this, mxContext, xIndexAccess, xModel ) );
322 if ( index.hasValue() )
323 return xCol->Item( index, uno::Any() );
324 return uno::Any( xCol );
327 void SAL_CALL
328 SwVbaDocument::Select()
330 auto xRange = getContent();
331 if ( xRange )
332 xRange->Select();
335 uno::Any SAL_CALL
336 SwVbaDocument::Sections( const uno::Any& index )
338 uno::Reference< XCollection > xCol( new SwVbaSections( mxParent, mxContext, getModel() ) );
339 if ( index.hasValue() )
340 return xCol->Item( index, uno::Any() );
341 return uno::Any( xCol );
344 uno::Any SAL_CALL
345 SwVbaDocument::TablesOfContents( const uno::Any& index )
347 uno::Reference< XCollection > xCol( new SwVbaTablesOfContents( this, mxContext, mxTextDocument ) );
348 if ( index.hasValue() )
349 return xCol->Item( index, uno::Any() );
350 return uno::Any( xCol );
353 uno::Any SAL_CALL SwVbaDocument::FormFields(const uno::Any& index)
355 uno::Reference<XCollection> xCol(new SwVbaFormFields(this, mxContext, mxTextDocument));
356 if (index.hasValue())
357 return xCol->Item(index, uno::Any());
358 return uno::Any(xCol);
361 uno::Any SAL_CALL
362 SwVbaDocument::PageSetup( )
364 uno::Reference< beans::XPropertySet > xPageProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW );
365 return uno::Any( uno::Reference< word::XPageSetup >( new SwVbaPageSetup( this, mxContext, mxModel, xPageProps ) ) );
368 OUString
369 SwVbaDocument::getServiceImplName()
371 return "SwVbaDocument";
374 uno::Any SAL_CALL
375 SwVbaDocument::getAttachedTemplate()
377 uno::Reference< word::XTemplate > xTemplate;
378 uno::Reference<css::document::XDocumentPropertiesSupplier> const xDocPropSupp(
379 getModel(), uno::UNO_QUERY_THROW);
380 uno::Reference< css::document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_SET_THROW );
381 OUString sTemplateUrl = xDocProps->getTemplateURL();
383 xTemplate = new SwVbaTemplate( this, mxContext, sTemplateUrl );
384 return uno::Any( xTemplate );
387 void SAL_CALL
388 SwVbaDocument::setAttachedTemplate( const css::uno::Any& _attachedtemplate )
390 OUString sTemplate;
391 if( !( _attachedtemplate >>= sTemplate ) )
393 throw uno::RuntimeException();
395 OUString aURL;
396 INetURLObject aObj;
397 aObj.SetURL( sTemplate );
398 bool bIsURL = aObj.GetProtocol() != INetProtocol::NotValid;
399 if ( bIsURL )
400 aURL = sTemplate;
401 else
402 osl::FileBase::getFileURLFromSystemPath( sTemplate, aURL );
404 uno::Reference<css::document::XDocumentPropertiesSupplier> const xDocPropSupp(
405 getModel(), uno::UNO_QUERY_THROW );
406 uno::Reference< css::document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_SET_THROW );
407 xDocProps->setTemplateURL( aURL );
410 uno::Any SAL_CALL
411 SwVbaDocument::Tables( const css::uno::Any& aIndex )
413 uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
414 uno::Reference< XCollection > xColl( new SwVbaTables( mxParent, mxContext, xModel ) );
416 if ( aIndex.hasValue() )
417 return xColl->Item( aIndex, uno::Any() );
418 return uno::Any( xColl );
421 void SAL_CALL SwVbaDocument::Activate()
423 VbaDocumentBase::Activate();
426 ::sal_Int32 SAL_CALL SwVbaDocument::getProtectionType()
428 //TODO
429 return word::WdProtectionType::wdNoProtection;
432 void SAL_CALL SwVbaDocument::setProtectionType( ::sal_Int32 /*_protectiontype*/ )
434 //TODO
437 sal_Bool SAL_CALL SwVbaDocument::getUpdateStylesOnOpen()
439 //TODO
440 return false;
443 void SAL_CALL SwVbaDocument::setUpdateStylesOnOpen( sal_Bool /*_updatestylesonopen*/ )
445 //TODO
448 sal_Bool SAL_CALL SwVbaDocument::getAutoHyphenation()
450 // check this property only in default paragraph style
451 bool IsAutoHyphenation = false;
452 uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
453 xParaProps->getPropertyValue("ParaIsHyphenation") >>= IsAutoHyphenation;
454 return IsAutoHyphenation;
457 void SAL_CALL SwVbaDocument::setAutoHyphenation( sal_Bool _autohyphenation )
459 //TODO
460 uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
461 xParaProps->setPropertyValue("ParaIsHyphenation", uno::Any( _autohyphenation ) );
464 ::sal_Int32 SAL_CALL SwVbaDocument::getHyphenationZone()
466 //TODO
467 return 0;
470 void SAL_CALL SwVbaDocument::setHyphenationZone( ::sal_Int32 /*_hyphenationzone*/ )
472 //TODO
475 ::sal_Int32 SAL_CALL SwVbaDocument::getConsecutiveHyphensLimit()
477 //TODO
478 sal_Int16 nHyphensLimit = 0;
479 uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
480 xParaProps->getPropertyValue("ParaHyphenationMaxHyphens") >>= nHyphensLimit;
481 return nHyphensLimit;
484 void SAL_CALL SwVbaDocument::setConsecutiveHyphensLimit( ::sal_Int32 _consecutivehyphenslimit )
486 sal_Int16 nHyphensLimit = static_cast< sal_Int16 >( _consecutivehyphenslimit );
487 uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
488 xParaProps->setPropertyValue("ParaHyphenationMaxHyphens", uno::Any( nHyphensLimit ) );
491 uno::Reference< ooo::vba::word::XMailMerge > SAL_CALL SwVbaDocument::getMailMerge()
493 return SwVbaMailMerge::get(mxParent, mxContext);
496 void SAL_CALL SwVbaDocument::Protect( ::sal_Int32 /*Type*/, const uno::Any& /*NOReset*/, const uno::Any& /*Password*/, const uno::Any& /*UseIRM*/, const uno::Any& /*EnforceStyleLock*/ )
498 // Seems not support in Writer
499 // VbaDocumentBase::Protect( Password );
502 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*/ )
504 //TODO
507 void SAL_CALL SwVbaDocument::PrintPreview( )
509 dispatchRequests( mxModel,".uno:PrintPreview" );
512 void SAL_CALL SwVbaDocument::ClosePrintPreview( )
514 dispatchRequests( mxModel,".uno:ClosePreview" );
517 uno::Any SAL_CALL
518 SwVbaDocument::Revisions( const uno::Any& index )
520 uno::Reference< css::document::XRedlinesSupplier > xRedlinesSupp( mxTextDocument, uno::UNO_QUERY_THROW );
521 uno::Reference< container::XIndexAccess > xRedlines( xRedlinesSupp->getRedlines(), uno::UNO_QUERY_THROW );
522 uno::Reference< XCollection > xCol( new SwVbaRevisions( this, mxContext, getModel(), xRedlines ) );
523 if ( index.hasValue() )
524 return xCol->Item( index, uno::Any() );
525 return uno::Any( xCol );
528 uno::Any SAL_CALL
529 SwVbaDocument::Frames( const uno::Any& index )
531 uno::Reference< text::XTextFramesSupplier > xTextFramesSupp( mxTextDocument, uno::UNO_QUERY_THROW );
532 uno::Reference< container::XIndexAccess > xFrames( xTextFramesSupp->getTextFrames(), uno::UNO_QUERY_THROW );
533 uno::Reference< XCollection > xCol( new SwVbaFrames( this, mxContext, xFrames, getModel() ) );
534 if ( index.hasValue() )
535 return xCol->Item( index, uno::Any() );
536 return uno::Any( xCol );
539 void SAL_CALL
540 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*/ )
542 SAL_INFO("sw.vba", "Document.SaveAs2000(FileName:=" << FileName << ",FileFormat:=" << FileFormat << ")");
544 // Based on ScVbaWorkbook::SaveAs.
545 OUString sFileName;
546 FileName >>= sFileName;
547 OUString sURL;
548 osl::FileBase::getFileURLFromSystemPath( sFileName, sURL );
550 // Detect if there is no path then we need to use the current folder.
551 INetURLObject aURL( sURL );
552 sURL = aURL.GetMainURL( INetURLObject::DecodeMechanism::ToIUri );
553 if( sURL.isEmpty() )
555 // Need to add cur dir ( of this document ) or else the 'Work' dir
556 sURL = getModel()->getURL();
558 if ( sURL.isEmpty() )
560 // Not path available from 'this' document. Need to add the 'document'/work directory then.
561 // Based on SwVbaOptions::getValueEvent()
562 uno::Reference< util::XPathSettings > xPathSettings = util::thePathSettings::get( comphelper::getProcessComponentContext() );
563 OUString sPathUrl;
564 xPathSettings->getPropertyValue( "Work" ) >>= sPathUrl;
565 // Path could be a multipath, Microsoft doesn't support this feature in Word currently.
566 // Only the last path is from interest.
567 sal_Int32 nIndex = sPathUrl.lastIndexOf( ';' );
568 if( nIndex != -1 )
570 sPathUrl = sPathUrl.copy( nIndex + 1 );
573 aURL.SetURL( sPathUrl );
575 else
577 aURL.SetURL( sURL );
578 aURL.Append( sFileName );
580 sURL = aURL.GetMainURL( INetURLObject::DecodeMechanism::ToIUri );
584 sal_Int32 nFileFormat = word::WdSaveFormat::wdFormatDocument;
585 FileFormat >>= nFileFormat;
587 uno::Sequence storeProps{ comphelper::makePropertyValue("FilterName", uno::Any()) };
589 setFilterPropsFromFormat( nFileFormat, storeProps );
591 uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
592 xStor->storeAsURL( sURL, storeProps );
595 void SAL_CALL
596 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*/ )
598 return SaveAs2000( FileName, FileFormat, LockComments, Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter );
601 void SAL_CALL
602 SwVbaDocument::Close( const uno::Any& SaveChanges, const uno::Any& /*OriginalFormat*/, const uno::Any& /*RouteDocument*/ )
604 VbaDocumentBase::Close( SaveChanges, uno::Any(), uno::Any() );
607 void SAL_CALL
608 SwVbaDocument::SavePreviewPngAs( const uno::Any& FileName )
610 OUString sFileName;
611 FileName >>= sFileName;
612 OUString sURL;
613 osl::FileBase::getFileURLFromSystemPath( sFileName, sURL );
615 uno::Sequence storeProps{ comphelper::makePropertyValue("FilterName",
616 OUString("writer_png_Export")) };
618 uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
619 xStor->storeToURL( sURL, storeProps );
622 uno::Any
623 SwVbaDocument::getControlShape( std::u16string_view sName )
625 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxTextDocument, uno::UNO_QUERY_THROW );
626 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
628 sal_Int32 nCount = xIndexAccess->getCount();
629 for( int index = 0; index < nCount; index++ )
631 uno::Any aUnoObj = xIndexAccess->getByIndex( index );
632 // It seems there are some drawing objects that can not query into Control shapes?
633 uno::Reference< drawing::XControlShape > xControlShape( aUnoObj, uno::UNO_QUERY );
634 if( xControlShape.is() )
636 uno::Reference< container::XNamed > xNamed( xControlShape->getControl(), uno::UNO_QUERY_THROW );
637 if( sName == xNamed->getName() )
639 return aUnoObj;
643 return uno::Any();
646 uno::Reference< beans::XIntrospectionAccess > SAL_CALL
647 SwVbaDocument::getIntrospection( )
649 return uno::Reference< beans::XIntrospectionAccess >();
652 uno::Any SAL_CALL
653 SwVbaDocument::invoke( const OUString& aFunctionName, const uno::Sequence< uno::Any >& /*aParams*/, uno::Sequence< ::sal_Int16 >& /*aOutParamIndex*/, uno::Sequence< uno::Any >& /*aOutParam*/ )
655 SAL_INFO("sw.vba", "** will barf " << aFunctionName );
656 throw uno::RuntimeException(); // unsupported operation
659 void SAL_CALL
660 SwVbaDocument::setValue( const OUString& /*aPropertyName*/, const uno::Any& /*aValue*/ )
662 throw uno::RuntimeException(); // unsupported operation
664 uno::Any SAL_CALL
665 SwVbaDocument::getValue( const OUString& aPropertyName )
667 uno::Reference< drawing::XControlShape > xControlShape( getControlShape( aPropertyName ), uno::UNO_QUERY_THROW );
669 uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW );
670 uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext("ooo.vba.ControlProvider", mxContext ), uno::UNO_QUERY_THROW );
671 uno::Reference< msforms::XControl > xControl( xControlProvider->createControl( xControlShape, getModel() ) );
672 return uno::Any( xControl );
675 sal_Bool SAL_CALL
676 SwVbaDocument::hasMethod( const OUString& /*aName*/ )
678 return false;
681 sal_Bool SAL_CALL
682 SwVbaDocument::hasProperty( const OUString& aName )
684 uno::Reference< container::XNameAccess > xFormControls( getFormControls() );
685 if ( xFormControls.is() )
686 return xFormControls->hasByName( aName );
687 return false;
690 uno::Reference< container::XNameAccess >
691 SwVbaDocument::getFormControls() const
693 uno::Reference< container::XNameAccess > xFormControls;
696 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxTextDocument, uno::UNO_QUERY_THROW );
697 uno::Reference< form::XFormsSupplier > xFormSupplier( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
698 uno::Reference< container::XIndexAccess > xIndexAccess( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
699 // get the www-standard container ( maybe we should access the
700 // 'www-standard' by name rather than index, this seems an
701 // implementation detail
702 xFormControls.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW );
704 catch(const uno::Exception&)
707 return xFormControls;
710 // XInterfaceWithIID
712 OUString SAL_CALL
713 SwVbaDocument::getIID()
715 return "{82154424-0FBF-11d4-8313-005004526AB4}";
718 // XConnectable
720 OUString SAL_CALL
721 SwVbaDocument::GetIIDForClassItselfNotCoclass()
723 return "{82154428-0FBF-11D4-8313-005004526AB4}";
726 TypeAndIID SAL_CALL
727 SwVbaDocument::GetConnectionPoint()
729 TypeAndIID aResult =
730 { cppu::UnoType<word::XDocumentOutgoing>::get(),
731 "{82154429-0FBF-11D4-8313-005004526AB4}"
734 return aResult;
737 // XSinkCaller
739 void SAL_CALL
740 SwVbaDocument::CallSinks( const OUString& Method, uno::Sequence< uno::Any >& Arguments )
742 for (auto& i : mvSinks)
744 if (i.is())
745 i->Call(Method, Arguments);
749 uno::Reference<XConnectionPoint> SAL_CALL
750 SwVbaDocument::FindConnectionPoint()
752 uno::Reference<XConnectionPoint> xCP(new SwVbaDocumentOutgoingConnectionPoint(this));
753 return xCP;
756 // SwVbaApplicationOutgoingConnectionPoint
758 SwVbaDocumentOutgoingConnectionPoint::SwVbaDocumentOutgoingConnectionPoint( SwVbaDocument* pDoc ) :
759 mpDoc(pDoc)
763 // XConnectionPoint
765 sal_uInt32 SAL_CALL
766 SwVbaDocumentOutgoingConnectionPoint::Advise( const uno::Reference< XSink >& Sink )
768 return mpDoc->AddSink(Sink);
771 void SAL_CALL
772 SwVbaDocumentOutgoingConnectionPoint::Unadvise( sal_uInt32 Cookie )
774 mpDoc->RemoveSink( Cookie );
777 uno::Sequence< OUString >
778 SwVbaDocument::getServiceNames()
780 static uno::Sequence< OUString > const aServiceNames
782 "ooo.vba.word.Document"
784 return aServiceNames;
787 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
788 Writer_SwVbaDocument_get_implementation(
789 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
791 return cppu::acquire(new SwVbaDocument(args, context));
795 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */