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"
35
36#include <com/sun/star/text/XBookmarksSupplier.hpp>
37#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
38#include <com/sun/star/document/XDocumentProperties.hpp>
39#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
40#include <com/sun/star/drawing/XControlShape.hpp>
41#include <com/sun/star/form/XFormsSupplier.hpp>
42#include <com/sun/star/frame/XStorable.hpp>
43#include <com/sun/star/document/XRedlinesSupplier.hpp>
44#include <com/sun/star/util/thePathSettings.hpp>
45#include <ooo/vba/XControlProvider.hpp>
46#include <ooo/vba/word/WdProtectionType.hpp>
47#include <ooo/vba/word/WdSaveFormat.hpp>
48#include <ooo/vba/word/XDocumentOutgoing.hpp>
49
50#include "wordvbahelper.hxx"
51#include <doc.hxx>
52#include <docsh.hxx>
53#include "vbatemplate.hxx"
54#include "vbaparagraph.hxx"
55#include "vbastyles.hxx"
56#include "vbatables.hxx"
57#include "vbafield.hxx"
58#include "vbapagesetup.hxx"
59#include "vbasections.hxx"
63#include "vbarevisions.hxx"
64#include "vbaframes.hxx"
65#include <basic/sberrors.hxx>
66#include <osl/file.hxx>
67#include <tools/urlobj.hxx>
68
69using namespace ::ooo::vba;
70using namespace ::com::sun::star;
71
72namespace {
73
74class SwVbaDocumentOutgoingConnectionPoint : public cppu::WeakImplHelper<XConnectionPoint>
75{
76private:
77 SwVbaDocument* mpDoc;
78
79public:
80 SwVbaDocumentOutgoingConnectionPoint( SwVbaDocument* pDoc );
81
82 // XConnectionPoint
83 sal_uInt32 SAL_CALL Advise(const uno::Reference< XSink >& Sink ) override;
84 void SAL_CALL Unadvise( sal_uInt32 Cookie ) override;
85};
86
87}
88
89SwVbaDocument::SwVbaDocument( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< frame::XModel > const & xModel ): SwVbaDocument_BASE( xParent, xContext, xModel )
90{
91 Initialize();
92}
93SwVbaDocument::SwVbaDocument( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& xContext ) : SwVbaDocument_BASE( aArgs, xContext )
94{
95 Initialize();
96}
97
99{
100}
101
103{
104 mxTextDocument.set( getModel(), uno::UNO_QUERY_THROW );
107 rDocSh.GetDoc()->SetVbaEventProcessor();
108}
109
110sal_uInt32
111SwVbaDocument::AddSink( const uno::Reference< XSink >& xSink )
112{
113 word::getDocShell( mxModel )->RegisterAutomationDocumentEventsCaller( uno::Reference< XSinkCaller >(this) );
114 mvSinks.push_back(xSink);
115 return mvSinks.size();
116}
117
118void
119SwVbaDocument::RemoveSink( sal_uInt32 nNumber )
120{
121 if (nNumber < 1 || nNumber > mvSinks.size())
122 return;
123
124 mvSinks[nNumber-1] = uno::Reference< XSink >();
125}
126
127uno::Reference< word::XRange > SAL_CALL
129{
130 uno::Reference< text::XTextRange > xStart = mxTextDocument->getText()->getStart();
131 uno::Reference< text::XTextRange > xEnd;
132 return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, xStart, xEnd ) );
133}
134
135uno::Reference< word::XRange > SAL_CALL
136SwVbaDocument::Range( const uno::Any& rStart, const uno::Any& rEnd )
137{
138 if( !rStart.hasValue() && !rEnd.hasValue() )
139 return getContent();
140
141 sal_Int32 nStart = 0;
142 sal_Int32 nEnd = 0;
143 rStart >>= nStart;
144 rEnd >>= nEnd;
145
146 uno::Reference< text::XTextRange > xStart;
147 uno::Reference< text::XTextRange > xEnd;
148
149 if( nStart > nEnd)
150 throw uno::RuntimeException();
151
152 if( nEnd != 0)
153 {
154 if( nEnd == nStart )
155 {
156 xStart = mxTextDocument->getText()->getEnd();
157 xEnd = mxTextDocument->getText()->getEnd();
158 }
159 else
160 {
161 xEnd = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nEnd );
162
163 if( nStart != 0 )
164 xStart = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nStart );
165 else
166 xStart = mxTextDocument->getText()->getStart();
167 }
168 }
169 else
170 {
171 xStart = mxTextDocument->getText()->getEnd();
172 xEnd = mxTextDocument->getText()->getEnd();
173 }
174
175 if( !xStart.is() && !xEnd.is() )
176 {
177 try
178 {
179 // FIXME
180 xStart = mxTextDocument->getText()->getStart();
181 xEnd = mxTextDocument->getText()->getEnd();
182 }
183 catch(const uno::Exception&)
184 {
185 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
186 }
187 }
188 return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, xStart, xEnd ) );
189}
190
191uno::Any SAL_CALL
193{
194 uno::Reference< XCollection > xCol( new SwVbaBuiltinDocumentProperties( mxParent, mxContext, getModel() ) );
195 if ( index.hasValue() )
196 return xCol->Item( index, uno::Any() );
197 return uno::Any( xCol );
198}
199
200uno::Any SAL_CALL
202{
203 uno::Reference< XCollection > xCol( new SwVbaCustomDocumentProperties( mxParent, mxContext, getModel() ) );
204 if ( index.hasValue() )
205 return xCol->Item( index, uno::Any() );
206 return uno::Any( xCol );
207}
208
209uno::Any SAL_CALL
211{
212 uno::Reference< text::XBookmarksSupplier > xBookmarksSupplier( getModel(),uno::UNO_QUERY_THROW );
213 uno::Reference<container::XIndexAccess > xBookmarks( xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY_THROW );
214 uno::Reference< XCollection > xBookmarksVba( new SwVbaBookmarks( this, mxContext, xBookmarks, getModel() ) );
215 if ( rIndex.getValueTypeClass() == uno::TypeClass_VOID )
216 return uno::Any( xBookmarksVba );
217
218 return xBookmarksVba->Item( rIndex, uno::Any() );
219}
220
222{
223 uno::Reference<XCollection> xContentControls(
224 new SwVbaContentControls(this, mxContext, mxTextDocument, "", ""));
225 if (index.hasValue())
226 return xContentControls->Item(index, uno::Any());
227
228 return uno::Any(xContentControls);
229}
230
232{
233 OUString sTag;
234 index >>= sTag;
235 return uno::Any(uno::Reference<XCollection>(
236 new SwVbaContentControls(this, mxContext, mxTextDocument, sTag, "")));
237}
238
240{
241 OUString sTitle;
242 index >>= sTitle;
243 return uno::Any(uno::Reference<XCollection>(
244 new SwVbaContentControls(this, mxContext, mxTextDocument, "", sTitle)));
245}
246
247uno::Any SAL_CALL
249{
250 uno::Reference< css::document::XDocumentPropertiesSupplier > xDocumentPropertiesSupplier( getModel(),uno::UNO_QUERY_THROW );
251 uno::Reference< css::document::XDocumentProperties > xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties();
252 uno::Reference< beans::XPropertyAccess > xUserDefined( xDocumentProperties->getUserDefinedProperties(), uno::UNO_QUERY_THROW );
253
254 uno::Reference< XCollection > xVariables( new SwVbaVariables( this, mxContext, xUserDefined ) );
255 if ( rIndex.getValueTypeClass() == uno::TypeClass_VOID )
256 return uno::Any( xVariables );
257
258 return xVariables->Item( rIndex, uno::Any() );
259}
260
261uno::Any SAL_CALL
263{
264 uno::Reference< XCollection > xCol( new SwVbaParagraphs( mxParent, mxContext, mxTextDocument ) );
265 if ( index.hasValue() )
266 return xCol->Item( index, uno::Any() );
267 return uno::Any( xCol );
268}
269
270uno::Any SAL_CALL
272{
273 uno::Reference< XCollection > xCol( new SwVbaStyles( mxParent, mxContext, getModel() ) );
274 if ( index.hasValue() )
275 return xCol->Item( index, uno::Any() );
276 return uno::Any( xCol );
277}
278
279uno::Any SAL_CALL
281{
282 uno::Reference< XCollection > xCol( new SwVbaFields( mxParent, mxContext, getModel() ) );
283 if ( index.hasValue() )
284 return xCol->Item( index, uno::Any() );
285 return uno::Any( xCol );
286}
287
288uno::Any SAL_CALL
290{
291 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( getModel(), uno::UNO_QUERY_THROW );
292 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
293 uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
294 uno::Reference< XCollection > xCol( new ScVbaShapes( this, mxContext, xIndexAccess, xModel ) );
295
296 if ( index.hasValue() )
297 return xCol->Item( index, uno::Any() );
298 return uno::Any( xCol );
299}
300
301void SAL_CALL
303{
304 auto xRange = getContent();
305 if ( xRange )
306 xRange->Select();
307}
308
309uno::Any SAL_CALL
311{
312 uno::Reference< XCollection > xCol( new SwVbaSections( mxParent, mxContext, getModel() ) );
313 if ( index.hasValue() )
314 return xCol->Item( index, uno::Any() );
315 return uno::Any( xCol );
316}
317
318uno::Any SAL_CALL
320{
321 uno::Reference< XCollection > xCol( new SwVbaTablesOfContents( this, mxContext, mxTextDocument ) );
322 if ( index.hasValue() )
323 return xCol->Item( index, uno::Any() );
324 return uno::Any( xCol );
325}
326
328{
329 uno::Reference<XCollection> xCol(new SwVbaFormFields(this, mxContext, mxModel));
330 if (index.hasValue())
331 return xCol->Item(index, uno::Any());
332 return uno::Any(xCol);
333}
334
335uno::Any SAL_CALL
337{
338 uno::Reference< beans::XPropertySet > xPageProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW );
339 return uno::Any( uno::Reference< word::XPageSetup >( new SwVbaPageSetup( this, mxContext, mxModel, xPageProps ) ) );
340}
341
342OUString
344{
345 return "SwVbaDocument";
346}
347
348uno::Any SAL_CALL
350{
351 uno::Reference< word::XTemplate > xTemplate;
352 uno::Reference<css::document::XDocumentPropertiesSupplier> const xDocPropSupp(
353 getModel(), uno::UNO_QUERY_THROW);
354 uno::Reference< css::document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_SET_THROW );
355 OUString sTemplateUrl = xDocProps->getTemplateURL();
356
357 xTemplate = new SwVbaTemplate( this, mxContext, sTemplateUrl );
358 return uno::Any( xTemplate );
359}
360
361void SAL_CALL
362SwVbaDocument::setAttachedTemplate( const css::uno::Any& _attachedtemplate )
363{
364 OUString sTemplate;
365 if( !( _attachedtemplate >>= sTemplate ) )
366 {
367 throw uno::RuntimeException();
368 }
369 OUString aURL;
370 INetURLObject aObj;
371 aObj.SetURL( sTemplate );
372 bool bIsURL = aObj.GetProtocol() != INetProtocol::NotValid;
373 if ( bIsURL )
374 aURL = sTemplate;
375 else
376 osl::FileBase::getFileURLFromSystemPath( sTemplate, aURL );
377
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 xDocProps->setTemplateURL( aURL );
382}
383
384uno::Any SAL_CALL
385SwVbaDocument::Tables( const css::uno::Any& aIndex )
386{
387 uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
388 uno::Reference< XCollection > xColl( new SwVbaTables( mxParent, mxContext, xModel ) );
389
390 if ( aIndex.hasValue() )
391 return xColl->Item( aIndex, uno::Any() );
392 return uno::Any( xColl );
393}
394
396{
398}
399
401{
402 //TODO
403 return word::WdProtectionType::wdNoProtection;
404}
405
406void SAL_CALL SwVbaDocument::setProtectionType( ::sal_Int32 /*_protectiontype*/ )
407{
408 //TODO
409}
410
412{
413 //TODO
414 return false;
415}
416
417void SAL_CALL SwVbaDocument::setUpdateStylesOnOpen( sal_Bool /*_updatestylesonopen*/ )
418{
419 //TODO
420}
421
423{
424 // check this property only in default paragraph style
425 bool IsAutoHyphenation = false;
426 uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
427 xParaProps->getPropertyValue("ParaIsHyphenation") >>= IsAutoHyphenation;
428 return IsAutoHyphenation;
429}
430
431void SAL_CALL SwVbaDocument::setAutoHyphenation( sal_Bool _autohyphenation )
432{
433 //TODO
434 uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
435 xParaProps->setPropertyValue("ParaIsHyphenation", uno::Any( _autohyphenation ) );
436}
437
439{
440 //TODO
441 return 0;
442}
443
444void SAL_CALL SwVbaDocument::setHyphenationZone( ::sal_Int32 /*_hyphenationzone*/ )
445{
446 //TODO
447}
448
450{
451 //TODO
452 sal_Int16 nHyphensLimit = 0;
453 uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
454 xParaProps->getPropertyValue("ParaHyphenationMaxHyphens") >>= nHyphensLimit;
455 return nHyphensLimit;
456}
457
458void SAL_CALL SwVbaDocument::setConsecutiveHyphensLimit( ::sal_Int32 _consecutivehyphenslimit )
459{
460 sal_Int16 nHyphensLimit = static_cast< sal_Int16 >( _consecutivehyphenslimit );
461 uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
462 xParaProps->setPropertyValue("ParaHyphenationMaxHyphens", uno::Any( nHyphensLimit ) );
463}
464
465uno::Reference< ooo::vba::word::XMailMerge > SAL_CALL SwVbaDocument::getMailMerge()
466{
468}
469
470void SAL_CALL SwVbaDocument::Protect( ::sal_Int32 /*Type*/, const uno::Any& /*NOReset*/, const uno::Any& /*Password*/, const uno::Any& /*UseIRM*/, const uno::Any& /*EnforceStyleLock*/ )
471{
472 // Seems not support in Writer
473 // VbaDocumentBase::Protect( Password );
474}
475
476void 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*/ )
477{
478 //TODO
479}
480
482{
483 dispatchRequests( mxModel,".uno:PrintPreview" );
484}
485
487{
488 dispatchRequests( mxModel,".uno:ClosePreview" );
489}
490
491uno::Any SAL_CALL
493{
494 uno::Reference< css::document::XRedlinesSupplier > xRedlinesSupp( mxTextDocument, uno::UNO_QUERY_THROW );
495 uno::Reference< container::XIndexAccess > xRedlines( xRedlinesSupp->getRedlines(), uno::UNO_QUERY_THROW );
496 uno::Reference< XCollection > xCol( new SwVbaRevisions( this, mxContext, getModel(), xRedlines ) );
497 if ( index.hasValue() )
498 return xCol->Item( index, uno::Any() );
499 return uno::Any( xCol );
500}
501
502uno::Any SAL_CALL
504{
505 uno::Reference< text::XTextFramesSupplier > xTextFramesSupp( mxTextDocument, uno::UNO_QUERY_THROW );
506 uno::Reference< container::XIndexAccess > xFrames( xTextFramesSupp->getTextFrames(), uno::UNO_QUERY_THROW );
507 uno::Reference< XCollection > xCol( new SwVbaFrames( this, mxContext, xFrames, getModel() ) );
508 if ( index.hasValue() )
509 return xCol->Item( index, uno::Any() );
510 return uno::Any( xCol );
511}
512
513void SAL_CALL
514SwVbaDocument::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*/ )
515{
516 SAL_INFO("sw.vba", "Document.SaveAs2000(FileName:=" << FileName << ",FileFormat:=" << FileFormat << ")");
517
518 // Based on ScVbaWorkbook::SaveAs.
519 OUString sFileName;
520 FileName >>= sFileName;
521 OUString sURL;
522 osl::FileBase::getFileURLFromSystemPath( sFileName, sURL );
523
524 // Detect if there is no path then we need to use the current folder.
525 INetURLObject aURL( sURL );
526 sURL = aURL.GetMainURL( INetURLObject::DecodeMechanism::ToIUri );
527 if( sURL.isEmpty() )
528 {
529 // Need to add cur dir ( of this document ) or else the 'Work' dir
530 sURL = getModel()->getURL();
531
532 if ( sURL.isEmpty() )
533 {
534 // Not path available from 'this' document. Need to add the 'document'/work directory then.
535 // Based on SwVbaOptions::getValueEvent()
536 uno::Reference< util::XPathSettings > xPathSettings = util::thePathSettings::get( comphelper::getProcessComponentContext() );
537 OUString sPathUrl;
538 xPathSettings->getPropertyValue( "Work" ) >>= sPathUrl;
539 // Path could be a multipath, Microsoft doesn't support this feature in Word currently.
540 // Only the last path is from interest.
541 sal_Int32 nIndex = sPathUrl.lastIndexOf( ';' );
542 if( nIndex != -1 )
543 {
544 sPathUrl = sPathUrl.copy( nIndex + 1 );
545 }
546
547 aURL.SetURL( sPathUrl );
548 }
549 else
550 {
551 aURL.SetURL( sURL );
552 aURL.Append( sFileName );
553 }
554 sURL = aURL.GetMainURL( INetURLObject::DecodeMechanism::ToIUri );
555
556 }
557
558 sal_Int32 nFileFormat = word::WdSaveFormat::wdFormatDocument;
559 FileFormat >>= nFileFormat;
560
561 uno::Sequence storeProps{ comphelper::makePropertyValue("FilterName", uno::Any()) };
562
563 setFilterPropsFromFormat( nFileFormat, storeProps );
564
565 uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
566 xStor->storeAsURL( sURL, storeProps );
567}
568
569void SAL_CALL
570SwVbaDocument::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*/ )
571{
572 return SaveAs2000( FileName, FileFormat, LockComments, Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter );
573}
574
575void SAL_CALL
576SwVbaDocument::Close( const uno::Any& SaveChanges, const uno::Any& /*OriginalFormat*/, const uno::Any& /*RouteDocument*/ )
577{
578 VbaDocumentBase::Close( SaveChanges, uno::Any(), uno::Any() );
579}
580
581void SAL_CALL
583{
584 OUString sFileName;
585 FileName >>= sFileName;
586 OUString sURL;
587 osl::FileBase::getFileURLFromSystemPath( sFileName, sURL );
588
589 uno::Sequence storeProps{ comphelper::makePropertyValue("FilterName",
590 OUString("writer_png_Export")) };
591
592 uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
593 xStor->storeToURL( sURL, storeProps );
594}
595
597SwVbaDocument::getControlShape( std::u16string_view sName )
598{
599 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxTextDocument, uno::UNO_QUERY_THROW );
600 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
601
602 sal_Int32 nCount = xIndexAccess->getCount();
603 for( int index = 0; index < nCount; index++ )
604 {
605 uno::Any aUnoObj = xIndexAccess->getByIndex( index );
606 // It seems there are some drawing objects that can not query into Control shapes?
607 uno::Reference< drawing::XControlShape > xControlShape( aUnoObj, uno::UNO_QUERY );
608 if( xControlShape.is() )
609 {
610 uno::Reference< container::XNamed > xNamed( xControlShape->getControl(), uno::UNO_QUERY_THROW );
611 if( sName == xNamed->getName() )
612 {
613 return aUnoObj;
614 }
615 }
616 }
617 return uno::Any();
618}
619
620uno::Reference< beans::XIntrospectionAccess > SAL_CALL
622{
623 return uno::Reference< beans::XIntrospectionAccess >();
624}
625
626uno::Any SAL_CALL
627SwVbaDocument::invoke( const OUString& aFunctionName, const uno::Sequence< uno::Any >& /*aParams*/, uno::Sequence< ::sal_Int16 >& /*aOutParamIndex*/, uno::Sequence< uno::Any >& /*aOutParam*/ )
628{
629 SAL_INFO("sw.vba", "** will barf " << aFunctionName );
630 throw uno::RuntimeException(); // unsupported operation
631}
632
633void SAL_CALL
634SwVbaDocument::setValue( const OUString& /*aPropertyName*/, const uno::Any& /*aValue*/ )
635{
636 throw uno::RuntimeException(); // unsupported operation
637}
638uno::Any SAL_CALL
639SwVbaDocument::getValue( const OUString& aPropertyName )
640{
641 uno::Reference< drawing::XControlShape > xControlShape( getControlShape( aPropertyName ), uno::UNO_QUERY_THROW );
642
643 uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW );
644 uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext("ooo.vba.ControlProvider", mxContext ), uno::UNO_QUERY_THROW );
645 uno::Reference< msforms::XControl > xControl( xControlProvider->createControl( xControlShape, getModel() ) );
646 return uno::Any( xControl );
647}
648
649sal_Bool SAL_CALL
650SwVbaDocument::hasMethod( const OUString& /*aName*/ )
651{
652 return false;
653}
654
655sal_Bool SAL_CALL
656SwVbaDocument::hasProperty( const OUString& aName )
657{
658 uno::Reference< container::XNameAccess > xFormControls( getFormControls() );
659 if ( xFormControls.is() )
660 return xFormControls->hasByName( aName );
661 return false;
662}
663
664uno::Reference< container::XNameAccess >
666{
667 uno::Reference< container::XNameAccess > xFormControls;
668 try
669 {
670 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxTextDocument, uno::UNO_QUERY_THROW );
671 uno::Reference< form::XFormsSupplier > xFormSupplier( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
672 uno::Reference< container::XIndexAccess > xIndexAccess( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
673 // get the www-standard container ( maybe we should access the
674 // 'www-standard' by name rather than index, this seems an
675 // implementation detail
676 xFormControls.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW );
677 }
678 catch(const uno::Exception&)
679 {
680 }
681 return xFormControls;
682}
683
684// XInterfaceWithIID
685
686OUString SAL_CALL
688{
689 return "{82154424-0FBF-11d4-8313-005004526AB4}";
690}
691
692// XConnectable
693
694OUString SAL_CALL
696{
697 return "{82154428-0FBF-11D4-8313-005004526AB4}";
698}
699
700TypeAndIID SAL_CALL
702{
703 TypeAndIID aResult =
704 { word::XDocumentOutgoing::static_type(),
705 "{82154429-0FBF-11D4-8313-005004526AB4}"
706 };
707
708 return aResult;
709}
710
711// XSinkCaller
712
713void SAL_CALL
714SwVbaDocument::CallSinks( const OUString& Method, uno::Sequence< uno::Any >& Arguments )
715{
716 for (auto& i : mvSinks)
717 {
718 if (i.is())
719 i->Call(Method, Arguments);
720 }
721}
722
723uno::Reference<XConnectionPoint> SAL_CALL
725{
726 uno::Reference<XConnectionPoint> xCP(new SwVbaDocumentOutgoingConnectionPoint(this));
727 return xCP;
728}
729
730// SwVbaApplicationOutgoingConnectionPoint
731
732SwVbaDocumentOutgoingConnectionPoint::SwVbaDocumentOutgoingConnectionPoint( SwVbaDocument* pDoc ) :
733 mpDoc(pDoc)
734{
735}
736
737// XConnectionPoint
738
739sal_uInt32 SAL_CALL
740SwVbaDocumentOutgoingConnectionPoint::Advise( const uno::Reference< XSink >& Sink )
741{
742 return mpDoc->AddSink(Sink);
743}
744
745void SAL_CALL
746SwVbaDocumentOutgoingConnectionPoint::Unadvise( sal_uInt32 Cookie )
747{
748 mpDoc->RemoveSink( Cookie );
749}
750
751uno::Sequence< OUString >
753{
754 static uno::Sequence< OUString > const aServiceNames
755 {
756 "ooo.vba.word.Document"
757 };
758 return aServiceNames;
759}
760
761extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
763 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
764{
765 return cppu::acquire(new SwVbaDocument(args, context));
766}
767
768
769/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::frame::XModel2 > mxModel
WeakReference< XInterface > 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:1428
void RegisterAutomationDocumentEventsCaller(css::uno::Reference< ooo::vba::XSinkCaller > const &xCaller)
Definition: docsh.cxx:1417
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:204
void SetVbaEventProcessor()
Definition: doc.cxx:1807
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
css::uno::Any SAL_CALL SelectContentControlsByTag(const css::uno::Any &index) override
virtual void SAL_CALL setAutoHyphenation(sal_Bool _autohyphenation) override
virtual css::uno::Any SAL_CALL getValue(const OUString &aPropertyName) 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 SAL_CALL ContentControls(const css::uno::Any &index) 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
Definition: vbadocument.cxx:98
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)
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
css::uno::Any SAL_CALL SelectContentControlsByTitle(const css::uno::Any &index) 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
int nCount
URL aURL
uno::Reference< uno::XComponentContext > mxContext
std::deque< AttacherIndex_Impl > aIndex
Sequence< OUString > aServiceNames
sal_Int32 nIndex
OUString aName
tools::SvRef< SvBaseLink > xSink
#define SAL_INFO(area, stream)
const char * sName
ScModelObj * getModel(const ScDocShell &rDocShell)
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