LibreOffice Module sw (master) 1
vbadocument.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21#include <sal/log.hxx>
22
25#include "vbadocument.hxx"
26#include "vbaformfields.hxx"
27#include "vbarange.hxx"
28#include "vbarangehelper.hxx"
30#include "vbabookmarks.hxx"
31#include "vbamailmerge.hxx"
32#include "vbavariables.hxx"
33#include "vbawindow.hxx"
36#include <cppu/unotype.hxx>
37
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>
51
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"
65#include "vbarevisions.hxx"
66#include "vbaframes.hxx"
67#include <basic/sberrors.hxx>
68#include <osl/file.hxx>
69#include <tools/urlobj.hxx>
70
71using namespace ::ooo::vba;
72using namespace ::com::sun::star;
73
74namespace {
75
76class SwVbaDocumentOutgoingConnectionPoint : public cppu::WeakImplHelper<XConnectionPoint>
77{
78private:
79 SwVbaDocument* mpDoc;
80
81public:
82 SwVbaDocumentOutgoingConnectionPoint( SwVbaDocument* pDoc );
83
84 // XConnectionPoint
85 sal_uInt32 SAL_CALL Advise(const uno::Reference< XSink >& Sink ) override;
86 void SAL_CALL Unadvise( sal_uInt32 Cookie ) override;
87};
88
89}
90
91SwVbaDocument::SwVbaDocument( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< frame::XModel > const & xModel ): SwVbaDocument_BASE( xParent, xContext, xModel )
92{
93 Initialize();
94}
95SwVbaDocument::SwVbaDocument( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& xContext ) : SwVbaDocument_BASE( aArgs, xContext )
96{
97 Initialize();
98}
99
101{
102}
103
105{
106 mxTextDocument.set( getModel(), uno::UNO_QUERY_THROW );
109 rDocSh.GetDoc()->SetVbaEventProcessor();
110}
111
112sal_uInt32
113SwVbaDocument::AddSink( const uno::Reference< XSink >& xSink )
114{
115 word::getDocShell( mxModel )->RegisterAutomationDocumentEventsCaller( uno::Reference< XSinkCaller >(this) );
116 mvSinks.push_back(xSink);
117 return mvSinks.size();
118}
119
120void
121SwVbaDocument::RemoveSink( sal_uInt32 nNumber )
122{
123 if (nNumber < 1 || nNumber > mvSinks.size())
124 return;
125
126 mvSinks[nNumber-1] = uno::Reference< XSink >();
127}
128
129uno::Reference< word::XRange > SAL_CALL
131{
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 ) );
135}
136
137uno::Reference< word::XRange > SAL_CALL
138SwVbaDocument::Range( const uno::Any& rStart, const uno::Any& rEnd )
139{
140 if( !rStart.hasValue() && !rEnd.hasValue() )
141 return getContent();
142
143 sal_Int32 nStart = 0;
144 sal_Int32 nEnd = 0;
145 rStart >>= nStart;
146 rEnd >>= nEnd;
147
148 uno::Reference< text::XTextRange > xStart;
149 uno::Reference< text::XTextRange > xEnd;
150
151 if( nStart > nEnd)
152 throw uno::RuntimeException();
153
154 if( nEnd != 0)
155 {
156 if( nEnd == nStart )
157 {
158 xStart = mxTextDocument->getText()->getEnd();
159 xEnd = mxTextDocument->getText()->getEnd();
160 }
161 else
162 {
163 xEnd = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nEnd );
164
165 if( nStart != 0 )
166 xStart = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nStart );
167 else
168 xStart = mxTextDocument->getText()->getStart();
169 }
170 }
171 else
172 {
173 xStart = mxTextDocument->getText()->getEnd();
174 xEnd = mxTextDocument->getText()->getEnd();
175 }
176
177 if( !xStart.is() && !xEnd.is() )
178 {
179 try
180 {
181 // FIXME
182 xStart = mxTextDocument->getText()->getStart();
183 xEnd = mxTextDocument->getText()->getEnd();
184 }
185 catch(const uno::Exception&)
186 {
187 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
188 }
189 }
190 return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, xStart, xEnd ) );
191}
192
193uno::Any SAL_CALL
195{
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 );
200}
201
202uno::Any SAL_CALL
204{
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 );
209}
210
211uno::Any SAL_CALL
213{
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 );
219
220 return xBookmarksVba->Item( rIndex, uno::Any() );
221}
222
224{
225 uno::Reference<XCollection> xContentControls(
226 new SwVbaContentControls(this, mxContext, mxTextDocument, "", ""));
227 if (index.hasValue())
228 {
229 try
230 {
231 return xContentControls->Item(index, uno::Any());
232 }
233 catch (lang::IndexOutOfBoundsException&)
234 {
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)
239 {
240 sal_Int32 nLong(0);
241 index >>= nLong;
242 return xContentControls->Item(uno::Any(static_cast<double>(nLong)), uno::Any());
243 }
244 }
245 }
246
247 return uno::Any(xContentControls);
248}
249
251{
252 OUString sTag;
253 index >>= sTag;
254 return uno::Any(uno::Reference<XCollection>(
255 new SwVbaContentControls(this, mxContext, mxTextDocument, sTag, "")));
256}
257
259{
260 OUString sTitle;
261 index >>= sTitle;
262 return uno::Any(uno::Reference<XCollection>(
263 new SwVbaContentControls(this, mxContext, mxTextDocument, "", sTitle)));
264}
265
266uno::Reference<word::XWindow> SwVbaDocument::getActiveWindow()
267{
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());
271}
272
273uno::Any SAL_CALL
275{
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 );
279
280 uno::Reference< XCollection > xVariables( new SwVbaVariables( this, mxContext, xUserDefined ) );
281 if ( rIndex.getValueTypeClass() == uno::TypeClass_VOID )
282 return uno::Any( xVariables );
283
284 return xVariables->Item( rIndex, uno::Any() );
285}
286
287uno::Any SAL_CALL
289{
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 );
294}
295
296uno::Any SAL_CALL
298{
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 );
303}
304
305uno::Any SAL_CALL
307{
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 );
312}
313
314uno::Any SAL_CALL
316{
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 ) );
321
322 if ( index.hasValue() )
323 return xCol->Item( index, uno::Any() );
324 return uno::Any( xCol );
325}
326
327void SAL_CALL
329{
330 auto xRange = getContent();
331 if ( xRange )
332 xRange->Select();
333}
334
335uno::Any SAL_CALL
337{
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 );
342}
343
344uno::Any SAL_CALL
346{
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 );
351}
352
354{
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);
359}
360
361uno::Any SAL_CALL
363{
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 ) ) );
366}
367
368OUString
370{
371 return "SwVbaDocument";
372}
373
374uno::Any SAL_CALL
376{
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();
382
383 xTemplate = new SwVbaTemplate( this, mxContext, sTemplateUrl );
384 return uno::Any( xTemplate );
385}
386
387void SAL_CALL
388SwVbaDocument::setAttachedTemplate( const css::uno::Any& _attachedtemplate )
389{
390 OUString sTemplate;
391 if( !( _attachedtemplate >>= sTemplate ) )
392 {
393 throw uno::RuntimeException();
394 }
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 );
403
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 );
408}
409
410uno::Any SAL_CALL
411SwVbaDocument::Tables( const css::uno::Any& aIndex )
412{
413 uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
414 uno::Reference< XCollection > xColl( new SwVbaTables( mxParent, mxContext, xModel ) );
415
416 if ( aIndex.hasValue() )
417 return xColl->Item( aIndex, uno::Any() );
418 return uno::Any( xColl );
419}
420
422{
424}
425
427{
428 //TODO
429 return word::WdProtectionType::wdNoProtection;
430}
431
432void SAL_CALL SwVbaDocument::setProtectionType( ::sal_Int32 /*_protectiontype*/ )
433{
434 //TODO
435}
436
438{
439 //TODO
440 return false;
441}
442
443void SAL_CALL SwVbaDocument::setUpdateStylesOnOpen( sal_Bool /*_updatestylesonopen*/ )
444{
445 //TODO
446}
447
449{
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;
455}
456
457void SAL_CALL SwVbaDocument::setAutoHyphenation( sal_Bool _autohyphenation )
458{
459 //TODO
460 uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
461 xParaProps->setPropertyValue("ParaIsHyphenation", uno::Any( _autohyphenation ) );
462}
463
465{
466 //TODO
467 return 0;
468}
469
470void SAL_CALL SwVbaDocument::setHyphenationZone( ::sal_Int32 /*_hyphenationzone*/ )
471{
472 //TODO
473}
474
476{
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;
482}
483
484void SAL_CALL SwVbaDocument::setConsecutiveHyphensLimit( ::sal_Int32 _consecutivehyphenslimit )
485{
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 ) );
489}
490
491uno::Reference< ooo::vba::word::XMailMerge > SAL_CALL SwVbaDocument::getMailMerge()
492{
494}
495
496void SAL_CALL SwVbaDocument::Protect( ::sal_Int32 /*Type*/, const uno::Any& /*NOReset*/, const uno::Any& /*Password*/, const uno::Any& /*UseIRM*/, const uno::Any& /*EnforceStyleLock*/ )
497{
498 // Seems not support in Writer
499 // VbaDocumentBase::Protect( Password );
500}
501
502void 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*/ )
503{
504 //TODO
505}
506
508{
509 dispatchRequests( mxModel,".uno:PrintPreview" );
510}
511
513{
514 dispatchRequests( mxModel,".uno:ClosePreview" );
515}
516
517uno::Any SAL_CALL
519{
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 );
526}
527
528uno::Any SAL_CALL
530{
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 );
537}
538
539void SAL_CALL
540SwVbaDocument::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*/ )
541{
542 SAL_INFO("sw.vba", "Document.SaveAs2000(FileName:=" << FileName << ",FileFormat:=" << FileFormat << ")");
543
544 // Based on ScVbaWorkbook::SaveAs.
545 OUString sFileName;
546 FileName >>= sFileName;
547 OUString sURL;
548 osl::FileBase::getFileURLFromSystemPath( sFileName, sURL );
549
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() )
554 {
555 // Need to add cur dir ( of this document ) or else the 'Work' dir
556 sURL = getModel()->getURL();
557
558 if ( sURL.isEmpty() )
559 {
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 )
569 {
570 sPathUrl = sPathUrl.copy( nIndex + 1 );
571 }
572
573 aURL.SetURL( sPathUrl );
574 }
575 else
576 {
577 aURL.SetURL( sURL );
578 aURL.Append( sFileName );
579 }
580 sURL = aURL.GetMainURL( INetURLObject::DecodeMechanism::ToIUri );
581
582 }
583
584 sal_Int32 nFileFormat = word::WdSaveFormat::wdFormatDocument;
585 FileFormat >>= nFileFormat;
586
587 uno::Sequence storeProps{ comphelper::makePropertyValue("FilterName", uno::Any()) };
588
589 setFilterPropsFromFormat( nFileFormat, storeProps );
590
591 uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
592 xStor->storeAsURL( sURL, storeProps );
593}
594
595void SAL_CALL
596SwVbaDocument::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*/ )
597{
598 return SaveAs2000( FileName, FileFormat, LockComments, Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter );
599}
600
601void SAL_CALL
602SwVbaDocument::Close( const uno::Any& SaveChanges, const uno::Any& /*OriginalFormat*/, const uno::Any& /*RouteDocument*/ )
603{
604 VbaDocumentBase::Close( SaveChanges, uno::Any(), uno::Any() );
605}
606
607void SAL_CALL
609{
610 OUString sFileName;
611 FileName >>= sFileName;
612 OUString sURL;
613 osl::FileBase::getFileURLFromSystemPath( sFileName, sURL );
614
615 uno::Sequence storeProps{ comphelper::makePropertyValue("FilterName",
616 OUString("writer_png_Export")) };
617
618 uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
619 xStor->storeToURL( sURL, storeProps );
620}
621
623SwVbaDocument::getControlShape( std::u16string_view sName )
624{
625 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxTextDocument, uno::UNO_QUERY_THROW );
626 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
627
628 sal_Int32 nCount = xIndexAccess->getCount();
629 for( int index = 0; index < nCount; index++ )
630 {
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() )
635 {
636 uno::Reference< container::XNamed > xNamed( xControlShape->getControl(), uno::UNO_QUERY_THROW );
637 if( sName == xNamed->getName() )
638 {
639 return aUnoObj;
640 }
641 }
642 }
643 return uno::Any();
644}
645
646uno::Reference< beans::XIntrospectionAccess > SAL_CALL
648{
649 return uno::Reference< beans::XIntrospectionAccess >();
650}
651
652uno::Any SAL_CALL
653SwVbaDocument::invoke( const OUString& aFunctionName, const uno::Sequence< uno::Any >& /*aParams*/, uno::Sequence< ::sal_Int16 >& /*aOutParamIndex*/, uno::Sequence< uno::Any >& /*aOutParam*/ )
654{
655 SAL_INFO("sw.vba", "** will barf " << aFunctionName );
656 throw uno::RuntimeException(); // unsupported operation
657}
658
659void SAL_CALL
660SwVbaDocument::setValue( const OUString& /*aPropertyName*/, const uno::Any& /*aValue*/ )
661{
662 throw uno::RuntimeException(); // unsupported operation
663}
664uno::Any SAL_CALL
665SwVbaDocument::getValue( const OUString& aPropertyName )
666{
667 uno::Reference< drawing::XControlShape > xControlShape( getControlShape( aPropertyName ), uno::UNO_QUERY_THROW );
668
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 );
673}
674
675sal_Bool SAL_CALL
676SwVbaDocument::hasMethod( const OUString& /*aName*/ )
677{
678 return false;
679}
680
681sal_Bool SAL_CALL
682SwVbaDocument::hasProperty( const OUString& aName )
683{
684 uno::Reference< container::XNameAccess > xFormControls( getFormControls() );
685 if ( xFormControls.is() )
686 return xFormControls->hasByName( aName );
687 return false;
688}
689
690uno::Reference< container::XNameAccess >
692{
693 uno::Reference< container::XNameAccess > xFormControls;
694 try
695 {
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 );
703 }
704 catch(const uno::Exception&)
705 {
706 }
707 return xFormControls;
708}
709
710// XInterfaceWithIID
711
712OUString SAL_CALL
714{
715 return "{82154424-0FBF-11d4-8313-005004526AB4}";
716}
717
718// XConnectable
719
720OUString SAL_CALL
722{
723 return "{82154428-0FBF-11D4-8313-005004526AB4}";
724}
725
726TypeAndIID SAL_CALL
728{
729 TypeAndIID aResult =
731 "{82154429-0FBF-11D4-8313-005004526AB4}"
732 };
733
734 return aResult;
735}
736
737// XSinkCaller
738
739void SAL_CALL
740SwVbaDocument::CallSinks( const OUString& Method, uno::Sequence< uno::Any >& Arguments )
741{
742 for (auto& i : mvSinks)
743 {
744 if (i.is())
745 i->Call(Method, Arguments);
746 }
747}
748
749uno::Reference<XConnectionPoint> SAL_CALL
751{
752 uno::Reference<XConnectionPoint> xCP(new SwVbaDocumentOutgoingConnectionPoint(this));
753 return xCP;
754}
755
756// SwVbaApplicationOutgoingConnectionPoint
757
758SwVbaDocumentOutgoingConnectionPoint::SwVbaDocumentOutgoingConnectionPoint( SwVbaDocument* pDoc ) :
759 mpDoc(pDoc)
760{
761}
762
763// XConnectionPoint
764
765sal_uInt32 SAL_CALL
766SwVbaDocumentOutgoingConnectionPoint::Advise( const uno::Reference< XSink >& Sink )
767{
768 return mpDoc->AddSink(Sink);
769}
770
771void SAL_CALL
772SwVbaDocumentOutgoingConnectionPoint::Unadvise( sal_uInt32 Cookie )
773{
774 mpDoc->RemoveSink( Cookie );
775}
776
777uno::Sequence< OUString >
779{
780 static uno::Sequence< OUString > const aServiceNames
781 {
782 "ooo.vba.word.Document"
783 };
784 return aServiceNames;
785}
786
787extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
789 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
790{
791 return cppu::acquire(new SwVbaDocument(args, context));
792}
793
794
795/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::frame::XModel2 > mxModel
unotools::WeakReference< AnimationNode > mxParent
INetProtocol GetProtocol() const
bool SetURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
void RegisterAutomationDocumentObject(css::uno::Reference< ooo::vba::word::XDocument > const &xDocument)
Definition: docsh.cxx:1426
void RegisterAutomationDocumentEventsCaller(css::uno::Reference< ooo::vba::XSinkCaller > const &xCaller)
Definition: docsh.cxx:1415
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:204
void SetVbaEventProcessor()
Definition: doc.cxx:1838
css::uno::Any SAL_CALL ContentControls(const css::uno::Any &index) override
virtual ::sal_Int32 SAL_CALL getProtectionType() override
std::vector< css::uno::Reference< ooo::vba::XSink > > mvSinks
Definition: vbadocument.hxx:38
virtual void SAL_CALL SaveAs2000(const css::uno::Any &FileName, const css::uno::Any &FileFormat, const css::uno::Any &LockComments, const css::uno::Any &Password, const css::uno::Any &AddToRecentFiles, const css::uno::Any &WritePassword, const css::uno::Any &ReadOnlyRecommended, const css::uno::Any &EmbedTrueTypeFonts, const css::uno::Any &SaveNativePictureFormat, const css::uno::Any &SaveFormsData, const css::uno::Any &SaveAsAOCELetter) override
void RemoveSink(sal_uInt32 nNumber)
virtual css::uno::Reference< ooo::vba::word::XMailMerge > SAL_CALL getMailMerge() override
virtual ov::TypeAndIID SAL_CALL GetConnectionPoint() override
virtual css::uno::Any SAL_CALL invoke(const OUString &aFunctionName, const css::uno::Sequence< css::uno::Any > &aParams, css::uno::Sequence< ::sal_Int16 > &aOutParamIndex, css::uno::Sequence< css::uno::Any > &aOutParam) override
virtual void SAL_CALL setAutoHyphenation(sal_Bool _autohyphenation) override
css::uno::Any SAL_CALL SelectContentControlsByTag(const css::uno::Any &index) override
virtual css::uno::Any SAL_CALL getValue(const OUString &aPropertyName) override
css::uno::Reference< ov::word::XWindow > SAL_CALL getActiveWindow() override
virtual css::uno::Any SAL_CALL Frames(const css::uno::Any &aIndex) override
virtual css::uno::Any SAL_CALL Shapes(const css::uno::Any &aIndex) override
virtual void SAL_CALL ClosePrintPreview() override
virtual void SAL_CALL Activate() override
virtual void SAL_CALL setProtectionType(::sal_Int32 _protectiontype) override
virtual sal_Bool SAL_CALL hasMethod(const OUString &aName) override
virtual void SAL_CALL Select() override
virtual void SAL_CALL Protect(::sal_Int32 Type, const css::uno::Any &NOReset, const css::uno::Any &Password, const css::uno::Any &UseIRM, const css::uno::Any &EnforceStyleLock) override
css::uno::Any getControlShape(std::u16string_view sName)
virtual css::uno::Any SAL_CALL Sections(const css::uno::Any &aIndex) override
virtual css::uno::Any SAL_CALL BuiltInDocumentProperties(const css::uno::Any &index) override
virtual void SAL_CALL Close(const css::uno::Any &SaveChanges, const css::uno::Any &OriginalFormat, const css::uno::Any &RouteDocument) override
virtual css::uno::Reference< ov::XConnectionPoint > SAL_CALL FindConnectionPoint() override
virtual css::uno::Reference< ooo::vba::word::XRange > SAL_CALL getContent() override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual void SAL_CALL setValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual ~SwVbaDocument() override
virtual void SAL_CALL setAttachedTemplate(const css::uno::Any &_attachedtemplate) override
virtual void SAL_CALL SaveAs(const css::uno::Any &FileName, const css::uno::Any &FileFormat, const css::uno::Any &LockComments, const css::uno::Any &Password, const css::uno::Any &AddToRecentFiles, const css::uno::Any &WritePassword, const css::uno::Any &ReadOnlyRecommended, const css::uno::Any &EmbedTrueTypeFonts, const css::uno::Any &SaveNativePictureFormat, const css::uno::Any &SaveFormsData, const css::uno::Any &SaveAsAOCELetter, const css::uno::Any &Encoding, const css::uno::Any &InsertLineBreaks, const css::uno::Any &AllowSubstitutions, const css::uno::Any &LineEnding, const css::uno::Any &AddBiDiMarks) override
virtual css::uno::Any SAL_CALL Fields(const css::uno::Any &aIndex) override
virtual OUString SAL_CALL getIID() override
virtual css::uno::Any SAL_CALL CustomDocumentProperties(const css::uno::Any &index) override
virtual void SAL_CALL setUpdateStylesOnOpen(sal_Bool _updatestylesonopen) override
css::uno::Reference< css::text::XTextDocument > mxTextDocument
Definition: vbadocument.hxx:36
virtual css::uno::Any SAL_CALL TablesOfContents(const css::uno::Any &aIndex) override
virtual sal_Bool SAL_CALL hasProperty(const OUString &aName) override
virtual css::uno::Any SAL_CALL Paragraphs(const css::uno::Any &rIndex) override
virtual void SAL_CALL setHyphenationZone(::sal_Int32 _hyphenationzone) override
virtual OUString getServiceImplName() override
virtual css::uno::Reference< css::beans::XIntrospectionAccess > SAL_CALL getIntrospection() override
virtual void SAL_CALL PrintOut(const css::uno::Any &Background, const css::uno::Any &Append, const css::uno::Any &Range, const css::uno::Any &OutputFileName, const css::uno::Any &From, const css::uno::Any &To, const css::uno::Any &Item, const css::uno::Any &Copies, const css::uno::Any &Pages, const css::uno::Any &PageType, const css::uno::Any &PrintToFile, const css::uno::Any &Collate, const css::uno::Any &FileName, const css::uno::Any &ActivePrinterMacGX, const css::uno::Any &ManualDuplexPrint, const css::uno::Any &PrintZoomColumn, const css::uno::Any &PrintZoomRow, const css::uno::Any &PrintZoomPaperWidth, const css::uno::Any &PrintZoomPaperHeight) override
virtual void SAL_CALL CallSinks(const OUString &Method, css::uno::Sequence< css::uno::Any > &Arguments) override
virtual css::uno::Any SAL_CALL Styles(const css::uno::Any &rIndex) override
virtual css::uno::Any SAL_CALL FormFields(const css::uno::Any &aIndex) override
sal_uInt32 AddSink(const css::uno::Reference< ooo::vba::XSink > &xSink)
SwVbaDocument(const css::uno::Reference< ooo::vba::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &m_xContext, css::uno::Reference< css::frame::XModel > const &xModel)
css::uno::Any SAL_CALL SelectContentControlsByTitle(const css::uno::Any &index) override
virtual void SAL_CALL SavePreviewPngAs(const css::uno::Any &FileName) override
virtual css::uno::Any SAL_CALL getAttachedTemplate() override
css::uno::Reference< css::container::XNameAccess > getFormControls() const
virtual css::uno::Any SAL_CALL Revisions(const css::uno::Any &aIndex) override
virtual css::uno::Any SAL_CALL Tables(const css::uno::Any &aIndex) override
virtual css::uno::Any SAL_CALL PageSetup() override
virtual ::sal_Int32 SAL_CALL getConsecutiveHyphensLimit() override
virtual void SAL_CALL setConsecutiveHyphensLimit(::sal_Int32 _consecutivehyphenslimit) override
virtual css::uno::Any SAL_CALL Bookmarks(const css::uno::Any &rIndex) override
virtual OUString SAL_CALL GetIIDForClassItselfNotCoclass() override
virtual ::sal_Int32 SAL_CALL getHyphenationZone() override
virtual sal_Bool SAL_CALL getUpdateStylesOnOpen() override
virtual css::uno::Reference< ooo::vba::word::XRange > SAL_CALL Range(const css::uno::Any &rStart, const css::uno::Any &rEnd) override
virtual void SAL_CALL PrintPreview() override
virtual css::uno::Any SAL_CALL Variables(const css::uno::Any &rIndex) override
virtual sal_Bool SAL_CALL getAutoHyphenation() override
static rtl::Reference< SwVbaMailMerge > const & get(const css::uno::Reference< ooo::vba::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext)
static css::uno::Reference< css::text::XTextRange > getRangeByPosition(const css::uno::Reference< css::text::XText > &rText, sal_Int32 _position)
get a range in a xText by creating a cursor that iterates over the text.
virtual void SAL_CALL Activate() override
virtual void SAL_CALL Close(const css::uno::Any &bSaveChanges, const css::uno::Any &aFileName, const css::uno::Any &bRouteWorkbook) override
css::uno::Type const & get()
int nCount
URL aURL
uno::Reference< uno::XComponentContext > mxContext
std::deque< AttacherIndex_Impl > aIndex
Sequence< OUString > aServiceNames
OUString sName
sal_Int32 nIndex
OUString aName
tools::SvRef< SvBaseLink > xSink
#define SAL_INFO(area, stream)
Reference< XComponentContext > getProcessComponentContext()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
int i
index
SwDocShell * getDocShell(const uno::Reference< frame::XModel > &xModel)
uno::Reference< style::XStyle > getCurrentPageStyle(const uno::Reference< frame::XModel > &xModel)
uno::Reference< style::XStyle > getDefaultParagraphStyle(const uno::Reference< frame::XModel > &xModel)
VBAHELPER_DLLPUBLIC void dispatchRequests(const css::uno::Reference< css::frame::XModel > &xModel, const OUString &aUrl)
args
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
#define ERRCODE_BASIC_METHOD_FAILED
bool hasValue()
Reference< XModel > xModel
unsigned char sal_Bool
Method
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Writer_SwVbaDocument_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
cppu::ImplInheritanceHelper< VbaDocumentBase, ooo::vba::word::XDocument, ooo::vba::XSinkCaller > SwVbaDocument_BASE
Definition: vbadocument.hxx:31