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