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 return xContentControls->Item(index, uno::Any());
229
230 return uno::Any(xContentControls);
231}
232
234{
235 OUString sTag;
236 index >>= sTag;
237 return uno::Any(uno::Reference<XCollection>(
238 new SwVbaContentControls(this, mxContext, mxTextDocument, sTag, "")));
239}
240
242{
243 OUString sTitle;
244 index >>= sTitle;
245 return uno::Any(uno::Reference<XCollection>(
246 new SwVbaContentControls(this, mxContext, mxTextDocument, "", sTitle)));
247}
248
249uno::Reference<word::XWindow> SwVbaDocument::getActiveWindow()
250{
251 // copied from vbaapplication which has a #FIXME so far can't determine Parent
252 return new SwVbaWindow(uno::Reference< XHelperInterface >(), mxContext, mxModel,
253 mxModel->getCurrentController());
254}
255
256uno::Any SAL_CALL
258{
259 uno::Reference< css::document::XDocumentPropertiesSupplier > xDocumentPropertiesSupplier( getModel(),uno::UNO_QUERY_THROW );
260 uno::Reference< css::document::XDocumentProperties > xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties();
261 uno::Reference< beans::XPropertyAccess > xUserDefined( xDocumentProperties->getUserDefinedProperties(), uno::UNO_QUERY_THROW );
262
263 uno::Reference< XCollection > xVariables( new SwVbaVariables( this, mxContext, xUserDefined ) );
264 if ( rIndex.getValueTypeClass() == uno::TypeClass_VOID )
265 return uno::Any( xVariables );
266
267 return xVariables->Item( rIndex, uno::Any() );
268}
269
270uno::Any SAL_CALL
272{
273 uno::Reference< XCollection > xCol( new SwVbaParagraphs( mxParent, mxContext, mxTextDocument ) );
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 SwVbaStyles( 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< XCollection > xCol( new SwVbaFields( mxParent, mxContext, getModel() ) );
292 if ( index.hasValue() )
293 return xCol->Item( index, uno::Any() );
294 return uno::Any( xCol );
295}
296
297uno::Any SAL_CALL
299{
300 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( getModel(), uno::UNO_QUERY_THROW );
301 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
302 uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
303 uno::Reference< XCollection > xCol( new ScVbaShapes( this, mxContext, xIndexAccess, xModel ) );
304
305 if ( index.hasValue() )
306 return xCol->Item( index, uno::Any() );
307 return uno::Any( xCol );
308}
309
310void SAL_CALL
312{
313 auto xRange = getContent();
314 if ( xRange )
315 xRange->Select();
316}
317
318uno::Any SAL_CALL
320{
321 uno::Reference< XCollection > xCol( new SwVbaSections( mxParent, mxContext, getModel() ) );
322 if ( index.hasValue() )
323 return xCol->Item( index, uno::Any() );
324 return uno::Any( xCol );
325}
326
327uno::Any SAL_CALL
329{
330 uno::Reference< XCollection > xCol( new SwVbaTablesOfContents( this, mxContext, mxTextDocument ) );
331 if ( index.hasValue() )
332 return xCol->Item( index, uno::Any() );
333 return uno::Any( xCol );
334}
335
337{
338 uno::Reference<XCollection> xCol(new SwVbaFormFields(this, mxContext, mxTextDocument));
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< beans::XPropertySet > xPageProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW );
348 return uno::Any( uno::Reference< word::XPageSetup >( new SwVbaPageSetup( this, mxContext, mxModel, xPageProps ) ) );
349}
350
351OUString
353{
354 return "SwVbaDocument";
355}
356
357uno::Any SAL_CALL
359{
360 uno::Reference< word::XTemplate > xTemplate;
361 uno::Reference<css::document::XDocumentPropertiesSupplier> const xDocPropSupp(
362 getModel(), uno::UNO_QUERY_THROW);
363 uno::Reference< css::document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_SET_THROW );
364 OUString sTemplateUrl = xDocProps->getTemplateURL();
365
366 xTemplate = new SwVbaTemplate( this, mxContext, sTemplateUrl );
367 return uno::Any( xTemplate );
368}
369
370void SAL_CALL
371SwVbaDocument::setAttachedTemplate( const css::uno::Any& _attachedtemplate )
372{
373 OUString sTemplate;
374 if( !( _attachedtemplate >>= sTemplate ) )
375 {
376 throw uno::RuntimeException();
377 }
378 OUString aURL;
379 INetURLObject aObj;
380 aObj.SetURL( sTemplate );
381 bool bIsURL = aObj.GetProtocol() != INetProtocol::NotValid;
382 if ( bIsURL )
383 aURL = sTemplate;
384 else
385 osl::FileBase::getFileURLFromSystemPath( sTemplate, aURL );
386
387 uno::Reference<css::document::XDocumentPropertiesSupplier> const xDocPropSupp(
388 getModel(), uno::UNO_QUERY_THROW );
389 uno::Reference< css::document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_SET_THROW );
390 xDocProps->setTemplateURL( aURL );
391}
392
393uno::Any SAL_CALL
394SwVbaDocument::Tables( const css::uno::Any& aIndex )
395{
396 uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
397 uno::Reference< XCollection > xColl( new SwVbaTables( mxParent, mxContext, xModel ) );
398
399 if ( aIndex.hasValue() )
400 return xColl->Item( aIndex, uno::Any() );
401 return uno::Any( xColl );
402}
403
405{
407}
408
410{
411 //TODO
412 return word::WdProtectionType::wdNoProtection;
413}
414
415void SAL_CALL SwVbaDocument::setProtectionType( ::sal_Int32 /*_protectiontype*/ )
416{
417 //TODO
418}
419
421{
422 //TODO
423 return false;
424}
425
426void SAL_CALL SwVbaDocument::setUpdateStylesOnOpen( sal_Bool /*_updatestylesonopen*/ )
427{
428 //TODO
429}
430
432{
433 // check this property only in default paragraph style
434 bool IsAutoHyphenation = false;
435 uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
436 xParaProps->getPropertyValue("ParaIsHyphenation") >>= IsAutoHyphenation;
437 return IsAutoHyphenation;
438}
439
440void SAL_CALL SwVbaDocument::setAutoHyphenation( sal_Bool _autohyphenation )
441{
442 //TODO
443 uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
444 xParaProps->setPropertyValue("ParaIsHyphenation", uno::Any( _autohyphenation ) );
445}
446
448{
449 //TODO
450 return 0;
451}
452
453void SAL_CALL SwVbaDocument::setHyphenationZone( ::sal_Int32 /*_hyphenationzone*/ )
454{
455 //TODO
456}
457
459{
460 //TODO
461 sal_Int16 nHyphensLimit = 0;
462 uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
463 xParaProps->getPropertyValue("ParaHyphenationMaxHyphens") >>= nHyphensLimit;
464 return nHyphensLimit;
465}
466
467void SAL_CALL SwVbaDocument::setConsecutiveHyphensLimit( ::sal_Int32 _consecutivehyphenslimit )
468{
469 sal_Int16 nHyphensLimit = static_cast< sal_Int16 >( _consecutivehyphenslimit );
470 uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
471 xParaProps->setPropertyValue("ParaHyphenationMaxHyphens", uno::Any( nHyphensLimit ) );
472}
473
474uno::Reference< ooo::vba::word::XMailMerge > SAL_CALL SwVbaDocument::getMailMerge()
475{
477}
478
479void SAL_CALL SwVbaDocument::Protect( ::sal_Int32 /*Type*/, const uno::Any& /*NOReset*/, const uno::Any& /*Password*/, const uno::Any& /*UseIRM*/, const uno::Any& /*EnforceStyleLock*/ )
480{
481 // Seems not support in Writer
482 // VbaDocumentBase::Protect( Password );
483}
484
485void 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*/ )
486{
487 //TODO
488}
489
491{
492 dispatchRequests( mxModel,".uno:PrintPreview" );
493}
494
496{
497 dispatchRequests( mxModel,".uno:ClosePreview" );
498}
499
500uno::Any SAL_CALL
502{
503 uno::Reference< css::document::XRedlinesSupplier > xRedlinesSupp( mxTextDocument, uno::UNO_QUERY_THROW );
504 uno::Reference< container::XIndexAccess > xRedlines( xRedlinesSupp->getRedlines(), uno::UNO_QUERY_THROW );
505 uno::Reference< XCollection > xCol( new SwVbaRevisions( this, mxContext, getModel(), xRedlines ) );
506 if ( index.hasValue() )
507 return xCol->Item( index, uno::Any() );
508 return uno::Any( xCol );
509}
510
511uno::Any SAL_CALL
513{
514 uno::Reference< text::XTextFramesSupplier > xTextFramesSupp( mxTextDocument, uno::UNO_QUERY_THROW );
515 uno::Reference< container::XIndexAccess > xFrames( xTextFramesSupp->getTextFrames(), uno::UNO_QUERY_THROW );
516 uno::Reference< XCollection > xCol( new SwVbaFrames( this, mxContext, xFrames, getModel() ) );
517 if ( index.hasValue() )
518 return xCol->Item( index, uno::Any() );
519 return uno::Any( xCol );
520}
521
522void SAL_CALL
523SwVbaDocument::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*/ )
524{
525 SAL_INFO("sw.vba", "Document.SaveAs2000(FileName:=" << FileName << ",FileFormat:=" << FileFormat << ")");
526
527 // Based on ScVbaWorkbook::SaveAs.
528 OUString sFileName;
529 FileName >>= sFileName;
530 OUString sURL;
531 osl::FileBase::getFileURLFromSystemPath( sFileName, sURL );
532
533 // Detect if there is no path then we need to use the current folder.
534 INetURLObject aURL( sURL );
535 sURL = aURL.GetMainURL( INetURLObject::DecodeMechanism::ToIUri );
536 if( sURL.isEmpty() )
537 {
538 // Need to add cur dir ( of this document ) or else the 'Work' dir
539 sURL = getModel()->getURL();
540
541 if ( sURL.isEmpty() )
542 {
543 // Not path available from 'this' document. Need to add the 'document'/work directory then.
544 // Based on SwVbaOptions::getValueEvent()
545 uno::Reference< util::XPathSettings > xPathSettings = util::thePathSettings::get( comphelper::getProcessComponentContext() );
546 OUString sPathUrl;
547 xPathSettings->getPropertyValue( "Work" ) >>= sPathUrl;
548 // Path could be a multipath, Microsoft doesn't support this feature in Word currently.
549 // Only the last path is from interest.
550 sal_Int32 nIndex = sPathUrl.lastIndexOf( ';' );
551 if( nIndex != -1 )
552 {
553 sPathUrl = sPathUrl.copy( nIndex + 1 );
554 }
555
556 aURL.SetURL( sPathUrl );
557 }
558 else
559 {
560 aURL.SetURL( sURL );
561 aURL.Append( sFileName );
562 }
563 sURL = aURL.GetMainURL( INetURLObject::DecodeMechanism::ToIUri );
564
565 }
566
567 sal_Int32 nFileFormat = word::WdSaveFormat::wdFormatDocument;
568 FileFormat >>= nFileFormat;
569
570 uno::Sequence storeProps{ comphelper::makePropertyValue("FilterName", uno::Any()) };
571
572 setFilterPropsFromFormat( nFileFormat, storeProps );
573
574 uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
575 xStor->storeAsURL( sURL, storeProps );
576}
577
578void SAL_CALL
579SwVbaDocument::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*/ )
580{
581 return SaveAs2000( FileName, FileFormat, LockComments, Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter );
582}
583
584void SAL_CALL
585SwVbaDocument::Close( const uno::Any& SaveChanges, const uno::Any& /*OriginalFormat*/, const uno::Any& /*RouteDocument*/ )
586{
587 VbaDocumentBase::Close( SaveChanges, uno::Any(), uno::Any() );
588}
589
590void SAL_CALL
592{
593 OUString sFileName;
594 FileName >>= sFileName;
595 OUString sURL;
596 osl::FileBase::getFileURLFromSystemPath( sFileName, sURL );
597
598 uno::Sequence storeProps{ comphelper::makePropertyValue("FilterName",
599 OUString("writer_png_Export")) };
600
601 uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
602 xStor->storeToURL( sURL, storeProps );
603}
604
606SwVbaDocument::getControlShape( std::u16string_view sName )
607{
608 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxTextDocument, uno::UNO_QUERY_THROW );
609 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
610
611 sal_Int32 nCount = xIndexAccess->getCount();
612 for( int index = 0; index < nCount; index++ )
613 {
614 uno::Any aUnoObj = xIndexAccess->getByIndex( index );
615 // It seems there are some drawing objects that can not query into Control shapes?
616 uno::Reference< drawing::XControlShape > xControlShape( aUnoObj, uno::UNO_QUERY );
617 if( xControlShape.is() )
618 {
619 uno::Reference< container::XNamed > xNamed( xControlShape->getControl(), uno::UNO_QUERY_THROW );
620 if( sName == xNamed->getName() )
621 {
622 return aUnoObj;
623 }
624 }
625 }
626 return uno::Any();
627}
628
629uno::Reference< beans::XIntrospectionAccess > SAL_CALL
631{
632 return uno::Reference< beans::XIntrospectionAccess >();
633}
634
635uno::Any SAL_CALL
636SwVbaDocument::invoke( const OUString& aFunctionName, const uno::Sequence< uno::Any >& /*aParams*/, uno::Sequence< ::sal_Int16 >& /*aOutParamIndex*/, uno::Sequence< uno::Any >& /*aOutParam*/ )
637{
638 SAL_INFO("sw.vba", "** will barf " << aFunctionName );
639 throw uno::RuntimeException(); // unsupported operation
640}
641
642void SAL_CALL
643SwVbaDocument::setValue( const OUString& /*aPropertyName*/, const uno::Any& /*aValue*/ )
644{
645 throw uno::RuntimeException(); // unsupported operation
646}
647uno::Any SAL_CALL
648SwVbaDocument::getValue( const OUString& aPropertyName )
649{
650 uno::Reference< drawing::XControlShape > xControlShape( getControlShape( aPropertyName ), uno::UNO_QUERY_THROW );
651
652 uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW );
653 uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext("ooo.vba.ControlProvider", mxContext ), uno::UNO_QUERY_THROW );
654 uno::Reference< msforms::XControl > xControl( xControlProvider->createControl( xControlShape, getModel() ) );
655 return uno::Any( xControl );
656}
657
658sal_Bool SAL_CALL
659SwVbaDocument::hasMethod( const OUString& /*aName*/ )
660{
661 return false;
662}
663
664sal_Bool SAL_CALL
665SwVbaDocument::hasProperty( const OUString& aName )
666{
667 uno::Reference< container::XNameAccess > xFormControls( getFormControls() );
668 if ( xFormControls.is() )
669 return xFormControls->hasByName( aName );
670 return false;
671}
672
673uno::Reference< container::XNameAccess >
675{
676 uno::Reference< container::XNameAccess > xFormControls;
677 try
678 {
679 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxTextDocument, uno::UNO_QUERY_THROW );
680 uno::Reference< form::XFormsSupplier > xFormSupplier( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
681 uno::Reference< container::XIndexAccess > xIndexAccess( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
682 // get the www-standard container ( maybe we should access the
683 // 'www-standard' by name rather than index, this seems an
684 // implementation detail
685 xFormControls.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW );
686 }
687 catch(const uno::Exception&)
688 {
689 }
690 return xFormControls;
691}
692
693// XInterfaceWithIID
694
695OUString SAL_CALL
697{
698 return "{82154424-0FBF-11d4-8313-005004526AB4}";
699}
700
701// XConnectable
702
703OUString SAL_CALL
705{
706 return "{82154428-0FBF-11D4-8313-005004526AB4}";
707}
708
709TypeAndIID SAL_CALL
711{
712 TypeAndIID aResult =
714 "{82154429-0FBF-11D4-8313-005004526AB4}"
715 };
716
717 return aResult;
718}
719
720// XSinkCaller
721
722void SAL_CALL
723SwVbaDocument::CallSinks( const OUString& Method, uno::Sequence< uno::Any >& Arguments )
724{
725 for (auto& i : mvSinks)
726 {
727 if (i.is())
728 i->Call(Method, Arguments);
729 }
730}
731
732uno::Reference<XConnectionPoint> SAL_CALL
734{
735 uno::Reference<XConnectionPoint> xCP(new SwVbaDocumentOutgoingConnectionPoint(this));
736 return xCP;
737}
738
739// SwVbaApplicationOutgoingConnectionPoint
740
741SwVbaDocumentOutgoingConnectionPoint::SwVbaDocumentOutgoingConnectionPoint( SwVbaDocument* pDoc ) :
742 mpDoc(pDoc)
743{
744}
745
746// XConnectionPoint
747
748sal_uInt32 SAL_CALL
749SwVbaDocumentOutgoingConnectionPoint::Advise( const uno::Reference< XSink >& Sink )
750{
751 return mpDoc->AddSink(Sink);
752}
753
754void SAL_CALL
755SwVbaDocumentOutgoingConnectionPoint::Unadvise( sal_uInt32 Cookie )
756{
757 mpDoc->RemoveSink( Cookie );
758}
759
760uno::Sequence< OUString >
762{
763 static uno::Sequence< OUString > const aServiceNames
764 {
765 "ooo.vba.word.Document"
766 };
767 return aServiceNames;
768}
769
770extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
772 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
773{
774 return cppu::acquire(new SwVbaDocument(args, context));
775}
776
777
778/* 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: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:1837
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
sal_Int32 nIndex
OUString aName
tools::SvRef< SvBaseLink > xSink
#define SAL_INFO(area, stream)
const char * sName
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