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