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