38#include <com/sun/star/text/XBookmarksSupplier.hpp>
39#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
40#include <com/sun/star/document/XDocumentProperties.hpp>
41#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
42#include <com/sun/star/drawing/XControlShape.hpp>
43#include <com/sun/star/form/XFormsSupplier.hpp>
44#include <com/sun/star/frame/XStorable.hpp>
45#include <com/sun/star/document/XRedlinesSupplier.hpp>
46#include <com/sun/star/util/thePathSettings.hpp>
47#include <ooo/vba/XControlProvider.hpp>
48#include <ooo/vba/word/WdProtectionType.hpp>
49#include <ooo/vba/word/WdSaveFormat.hpp>
50#include <ooo/vba/word/XDocumentOutgoing.hpp>
68#include <osl/file.hxx>
76class SwVbaDocumentOutgoingConnectionPoint :
public cppu::WeakImplHelper<XConnectionPoint>
85 sal_uInt32 SAL_CALL Advise(
const uno::Reference< XSink >& Sink )
override;
86 void SAL_CALL Unadvise( sal_uInt32 Cookie )
override;
123 if (nNumber < 1 || nNumber >
mvSinks.size())
126 mvSinks[nNumber-1] = uno::Reference< XSink >();
129uno::Reference< word::XRange > SAL_CALL
132 uno::Reference< text::XTextRange > xStart =
mxTextDocument->getText()->getStart();
133 uno::Reference< text::XTextRange > xEnd;
137uno::Reference< word::XRange > SAL_CALL
143 sal_Int32 nStart = 0;
148 uno::Reference< text::XTextRange > xStart;
149 uno::Reference< text::XTextRange > xEnd;
152 throw uno::RuntimeException();
177 if( !xStart.is() && !xEnd.is() )
185 catch(
const uno::Exception&)
197 if (
index.hasValue() )
206 if (
index.hasValue() )
214 uno::Reference< text::XBookmarksSupplier > xBookmarksSupplier( getModel(),uno::UNO_QUERY_THROW );
215 uno::Reference<container::XIndexAccess > xBookmarks( xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY_THROW );
217 if ( rIndex.getValueTypeClass() == uno::TypeClass_VOID )
220 return xBookmarksVba->Item( rIndex,
uno::Any() );
225 uno::Reference<XCollection> xContentControls(
227 if (
index.hasValue())
233 catch (lang::IndexOutOfBoundsException&)
238 if (
index.getValueTypeClass() == css::uno::TypeClass_LONG)
242 return xContentControls->Item(
uno::Any(
static_cast<double>(nLong)),
uno::Any());
254 return uno::Any(uno::Reference<XCollection>(
262 return uno::Any(uno::Reference<XCollection>(
270 mxModel->getCurrentController());
276 uno::Reference< css::document::XDocumentPropertiesSupplier > xDocumentPropertiesSupplier( getModel(),uno::UNO_QUERY_THROW );
277 uno::Reference< css::document::XDocumentProperties > xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties();
278 uno::Reference< beans::XPropertyAccess > xUserDefined( xDocumentProperties->getUserDefinedProperties(), uno::UNO_QUERY_THROW );
281 if ( rIndex.getValueTypeClass() == uno::TypeClass_VOID )
284 return xVariables->Item( rIndex,
uno::Any() );
291 if (
index.hasValue() )
300 if (
index.hasValue() )
309 if (
index.hasValue() )
317 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( getModel(), uno::UNO_QUERY_THROW );
318 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
322 if (
index.hasValue() )
339 if (
index.hasValue() )
348 if (
index.hasValue() )
356 if (
index.hasValue())
371 return "SwVbaDocument";
377 uno::Reference< word::XTemplate > xTemplate;
378 uno::Reference<css::document::XDocumentPropertiesSupplier>
const xDocPropSupp(
379 getModel(), uno::UNO_QUERY_THROW);
380 uno::Reference< css::document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_SET_THROW );
381 OUString sTemplateUrl = xDocProps->getTemplateURL();
391 if( !( _attachedtemplate >>= sTemplate ) )
393 throw uno::RuntimeException();
398 bool bIsURL = aObj.
GetProtocol() != INetProtocol::NotValid;
402 osl::FileBase::getFileURLFromSystemPath( sTemplate,
aURL );
404 uno::Reference<css::document::XDocumentPropertiesSupplier>
const xDocPropSupp(
405 getModel(), uno::UNO_QUERY_THROW );
406 uno::Reference< css::document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_SET_THROW );
407 xDocProps->setTemplateURL(
aURL );
429 return word::WdProtectionType::wdNoProtection;
451 bool IsAutoHyphenation =
false;
453 xParaProps->getPropertyValue(
"ParaIsHyphenation") >>= IsAutoHyphenation;
454 return IsAutoHyphenation;
461 xParaProps->setPropertyValue(
"ParaIsHyphenation",
uno::Any( _autohyphenation ) );
478 sal_Int16 nHyphensLimit = 0;
480 xParaProps->getPropertyValue(
"ParaHyphenationMaxHyphens") >>= nHyphensLimit;
481 return nHyphensLimit;
486 sal_Int16 nHyphensLimit =
static_cast< sal_Int16
>( _consecutivehyphenslimit );
488 xParaProps->setPropertyValue(
"ParaHyphenationMaxHyphens",
uno::Any( nHyphensLimit ) );
502void SAL_CALL
SwVbaDocument::PrintOut(
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& )
520 uno::Reference< css::document::XRedlinesSupplier > xRedlinesSupp(
mxTextDocument, uno::UNO_QUERY_THROW );
521 uno::Reference< container::XIndexAccess > xRedlines( xRedlinesSupp->getRedlines(), uno::UNO_QUERY_THROW );
523 if (
index.hasValue() )
531 uno::Reference< text::XTextFramesSupplier > xTextFramesSupp(
mxTextDocument, uno::UNO_QUERY_THROW );
532 uno::Reference< container::XIndexAccess > xFrames( xTextFramesSupp->getTextFrames(), uno::UNO_QUERY_THROW );
534 if (
index.hasValue() )
540SwVbaDocument::SaveAs2000(
const uno::Any& FileName,
const uno::Any& FileFormat,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& )
542 SAL_INFO(
"sw.vba",
"Document.SaveAs2000(FileName:=" << FileName <<
",FileFormat:=" << FileFormat <<
")");
546 FileName >>= sFileName;
548 osl::FileBase::getFileURLFromSystemPath( sFileName, sURL );
556 sURL = getModel()->getURL();
558 if ( sURL.isEmpty() )
564 xPathSettings->getPropertyValue(
"Work" ) >>= sPathUrl;
567 sal_Int32
nIndex = sPathUrl.lastIndexOf(
';' );
570 sPathUrl = sPathUrl.copy(
nIndex + 1 );
573 aURL.SetURL( sPathUrl );
578 aURL.Append( sFileName );
584 sal_Int32 nFileFormat = word::WdSaveFormat::wdFormatDocument;
585 FileFormat >>= nFileFormat;
589 setFilterPropsFromFormat( nFileFormat, storeProps );
591 uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
592 xStor->storeAsURL( sURL, storeProps );
596SwVbaDocument::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& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& )
598 return SaveAs2000( FileName, FileFormat, LockComments,
Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter );
611 FileName >>= sFileName;
613 osl::FileBase::getFileURLFromSystemPath( sFileName, sURL );
616 OUString(
"writer_png_Export")) };
618 uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
619 xStor->storeToURL( sURL, storeProps );
625 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(
mxTextDocument, uno::UNO_QUERY_THROW );
626 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
628 sal_Int32
nCount = xIndexAccess->getCount();
633 uno::Reference< drawing::XControlShape > xControlShape( aUnoObj, uno::UNO_QUERY );
634 if( xControlShape.is() )
636 uno::Reference< container::XNamed > xNamed( xControlShape->getControl(), uno::UNO_QUERY_THROW );
637 if(
sName == xNamed->getName() )
646uno::Reference< beans::XIntrospectionAccess > SAL_CALL
649 return uno::Reference< beans::XIntrospectionAccess >();
653SwVbaDocument::invoke(
const OUString& aFunctionName,
const uno::Sequence< uno::Any >& , uno::Sequence< ::sal_Int16 >& , uno::Sequence< uno::Any >& )
655 SAL_INFO(
"sw.vba",
"** will barf " << aFunctionName );
656 throw uno::RuntimeException();
662 throw uno::RuntimeException();
667 uno::Reference< drawing::XControlShape > xControlShape(
getControlShape( aPropertyName ), uno::UNO_QUERY_THROW );
669 uno::Reference<lang::XMultiComponentFactory > xServiceManager(
mxContext->getServiceManager(), uno::UNO_SET_THROW );
670 uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext(
"ooo.vba.ControlProvider",
mxContext ), uno::UNO_QUERY_THROW );
671 uno::Reference< msforms::XControl > xControl( xControlProvider->createControl( xControlShape, getModel() ) );
684 uno::Reference< container::XNameAccess > xFormControls(
getFormControls() );
685 if ( xFormControls.is() )
686 return xFormControls->hasByName(
aName );
690uno::Reference< container::XNameAccess >
693 uno::Reference< container::XNameAccess > xFormControls;
696 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(
mxTextDocument, uno::UNO_QUERY_THROW );
697 uno::Reference< form::XFormsSupplier > xFormSupplier( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
698 uno::Reference< container::XIndexAccess > xIndexAccess( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
702 xFormControls.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW );
704 catch(
const uno::Exception&)
707 return xFormControls;
715 return "{82154424-0FBF-11d4-8313-005004526AB4}";
723 return "{82154428-0FBF-11D4-8313-005004526AB4}";
731 "{82154429-0FBF-11D4-8313-005004526AB4}"
749uno::Reference<XConnectionPoint> SAL_CALL
752 uno::Reference<XConnectionPoint> xCP(
new SwVbaDocumentOutgoingConnectionPoint(
this));
758SwVbaDocumentOutgoingConnectionPoint::SwVbaDocumentOutgoingConnectionPoint(
SwVbaDocument* pDoc ) :
766SwVbaDocumentOutgoingConnectionPoint::Advise(
const uno::Reference< XSink >& Sink )
768 return mpDoc->AddSink(Sink);
772SwVbaDocumentOutgoingConnectionPoint::Unadvise( sal_uInt32 Cookie )
774 mpDoc->RemoveSink( Cookie );
777uno::Sequence< OUString >
782 "ooo.vba.word.Document"
787extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
789 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const& args)
css::uno::Reference< css::frame::XModel2 > mxModel
unotools::WeakReference< AnimationNode > mxParent
INetProtocol GetProtocol() const
bool SetURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
void RegisterAutomationDocumentObject(css::uno::Reference< ooo::vba::word::XDocument > const &xDocument)
void RegisterAutomationDocumentEventsCaller(css::uno::Reference< ooo::vba::XSinkCaller > const &xCaller)
SwDoc * GetDoc()
returns Doc. But be careful!
void SetVbaEventProcessor()
css::uno::Any SAL_CALL ContentControls(const css::uno::Any &index) override
virtual ::sal_Int32 SAL_CALL getProtectionType() override
std::vector< css::uno::Reference< ooo::vba::XSink > > mvSinks
virtual void SAL_CALL SaveAs2000(const css::uno::Any &FileName, const css::uno::Any &FileFormat, const css::uno::Any &LockComments, const css::uno::Any &Password, const css::uno::Any &AddToRecentFiles, const css::uno::Any &WritePassword, const css::uno::Any &ReadOnlyRecommended, const css::uno::Any &EmbedTrueTypeFonts, const css::uno::Any &SaveNativePictureFormat, const css::uno::Any &SaveFormsData, const css::uno::Any &SaveAsAOCELetter) override
void RemoveSink(sal_uInt32 nNumber)
virtual css::uno::Reference< ooo::vba::word::XMailMerge > SAL_CALL getMailMerge() override
virtual ov::TypeAndIID SAL_CALL GetConnectionPoint() override
virtual css::uno::Any SAL_CALL invoke(const OUString &aFunctionName, const css::uno::Sequence< css::uno::Any > &aParams, css::uno::Sequence< ::sal_Int16 > &aOutParamIndex, css::uno::Sequence< css::uno::Any > &aOutParam) override
virtual void SAL_CALL setAutoHyphenation(sal_Bool _autohyphenation) override
css::uno::Any SAL_CALL SelectContentControlsByTag(const css::uno::Any &index) override
virtual css::uno::Any SAL_CALL getValue(const OUString &aPropertyName) override
css::uno::Reference< ov::word::XWindow > SAL_CALL getActiveWindow() override
virtual css::uno::Any SAL_CALL Frames(const css::uno::Any &aIndex) override
virtual css::uno::Any SAL_CALL Shapes(const css::uno::Any &aIndex) override
virtual void SAL_CALL ClosePrintPreview() override
virtual void SAL_CALL Activate() override
virtual void SAL_CALL setProtectionType(::sal_Int32 _protectiontype) override
virtual sal_Bool SAL_CALL hasMethod(const OUString &aName) override
virtual void SAL_CALL Select() override
virtual void SAL_CALL Protect(::sal_Int32 Type, const css::uno::Any &NOReset, const css::uno::Any &Password, const css::uno::Any &UseIRM, const css::uno::Any &EnforceStyleLock) override
css::uno::Any getControlShape(std::u16string_view sName)
virtual css::uno::Any SAL_CALL Sections(const css::uno::Any &aIndex) override
virtual css::uno::Any SAL_CALL BuiltInDocumentProperties(const css::uno::Any &index) override
virtual void SAL_CALL Close(const css::uno::Any &SaveChanges, const css::uno::Any &OriginalFormat, const css::uno::Any &RouteDocument) override
virtual css::uno::Reference< ov::XConnectionPoint > SAL_CALL FindConnectionPoint() override
virtual css::uno::Reference< ooo::vba::word::XRange > SAL_CALL getContent() override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual void SAL_CALL setValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual ~SwVbaDocument() override
virtual void SAL_CALL setAttachedTemplate(const css::uno::Any &_attachedtemplate) override
virtual void SAL_CALL SaveAs(const css::uno::Any &FileName, const css::uno::Any &FileFormat, const css::uno::Any &LockComments, const css::uno::Any &Password, const css::uno::Any &AddToRecentFiles, const css::uno::Any &WritePassword, const css::uno::Any &ReadOnlyRecommended, const css::uno::Any &EmbedTrueTypeFonts, const css::uno::Any &SaveNativePictureFormat, const css::uno::Any &SaveFormsData, const css::uno::Any &SaveAsAOCELetter, const css::uno::Any &Encoding, const css::uno::Any &InsertLineBreaks, const css::uno::Any &AllowSubstitutions, const css::uno::Any &LineEnding, const css::uno::Any &AddBiDiMarks) override
virtual css::uno::Any SAL_CALL Fields(const css::uno::Any &aIndex) override
virtual OUString SAL_CALL getIID() override
virtual css::uno::Any SAL_CALL CustomDocumentProperties(const css::uno::Any &index) override
virtual void SAL_CALL setUpdateStylesOnOpen(sal_Bool _updatestylesonopen) override
css::uno::Reference< css::text::XTextDocument > mxTextDocument
virtual css::uno::Any SAL_CALL TablesOfContents(const css::uno::Any &aIndex) override
virtual sal_Bool SAL_CALL hasProperty(const OUString &aName) override
virtual css::uno::Any SAL_CALL Paragraphs(const css::uno::Any &rIndex) override
virtual void SAL_CALL setHyphenationZone(::sal_Int32 _hyphenationzone) override
virtual OUString getServiceImplName() override
virtual css::uno::Reference< css::beans::XIntrospectionAccess > SAL_CALL getIntrospection() override
virtual void SAL_CALL PrintOut(const css::uno::Any &Background, const css::uno::Any &Append, const css::uno::Any &Range, const css::uno::Any &OutputFileName, const css::uno::Any &From, const css::uno::Any &To, const css::uno::Any &Item, const css::uno::Any &Copies, const css::uno::Any &Pages, const css::uno::Any &PageType, const css::uno::Any &PrintToFile, const css::uno::Any &Collate, const css::uno::Any &FileName, const css::uno::Any &ActivePrinterMacGX, const css::uno::Any &ManualDuplexPrint, const css::uno::Any &PrintZoomColumn, const css::uno::Any &PrintZoomRow, const css::uno::Any &PrintZoomPaperWidth, const css::uno::Any &PrintZoomPaperHeight) override
virtual void SAL_CALL CallSinks(const OUString &Method, css::uno::Sequence< css::uno::Any > &Arguments) override
virtual css::uno::Any SAL_CALL Styles(const css::uno::Any &rIndex) override
virtual css::uno::Any SAL_CALL FormFields(const css::uno::Any &aIndex) override
sal_uInt32 AddSink(const css::uno::Reference< ooo::vba::XSink > &xSink)
SwVbaDocument(const css::uno::Reference< ooo::vba::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &m_xContext, css::uno::Reference< css::frame::XModel > const &xModel)
css::uno::Any SAL_CALL SelectContentControlsByTitle(const css::uno::Any &index) override
virtual void SAL_CALL SavePreviewPngAs(const css::uno::Any &FileName) override
virtual css::uno::Any SAL_CALL getAttachedTemplate() override
css::uno::Reference< css::container::XNameAccess > getFormControls() const
virtual css::uno::Any SAL_CALL Revisions(const css::uno::Any &aIndex) override
virtual css::uno::Any SAL_CALL Tables(const css::uno::Any &aIndex) override
virtual css::uno::Any SAL_CALL PageSetup() override
virtual ::sal_Int32 SAL_CALL getConsecutiveHyphensLimit() override
virtual void SAL_CALL setConsecutiveHyphensLimit(::sal_Int32 _consecutivehyphenslimit) override
virtual css::uno::Any SAL_CALL Bookmarks(const css::uno::Any &rIndex) override
virtual OUString SAL_CALL GetIIDForClassItselfNotCoclass() override
virtual ::sal_Int32 SAL_CALL getHyphenationZone() override
virtual sal_Bool SAL_CALL getUpdateStylesOnOpen() override
virtual css::uno::Reference< ooo::vba::word::XRange > SAL_CALL Range(const css::uno::Any &rStart, const css::uno::Any &rEnd) override
virtual void SAL_CALL PrintPreview() override
virtual css::uno::Any SAL_CALL Variables(const css::uno::Any &rIndex) override
virtual sal_Bool SAL_CALL getAutoHyphenation() override
static rtl::Reference< SwVbaMailMerge > const & get(const css::uno::Reference< ooo::vba::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext)
static css::uno::Reference< css::text::XTextRange > getRangeByPosition(const css::uno::Reference< css::text::XText > &rText, sal_Int32 _position)
get a range in a xText by creating a cursor that iterates over the text.
virtual void SAL_CALL Activate() override
virtual void SAL_CALL Close(const css::uno::Any &bSaveChanges, const css::uno::Any &aFileName, const css::uno::Any &bRouteWorkbook) override
css::uno::Type const & get()
std::deque< AttacherIndex_Impl > aIndex
Sequence< OUString > aServiceNames
tools::SvRef< SvBaseLink > xSink
#define SAL_INFO(area, stream)
Reference< XComponentContext > getProcessComponentContext()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
SwDocShell * getDocShell(const uno::Reference< frame::XModel > &xModel)
uno::Reference< style::XStyle > getCurrentPageStyle(const uno::Reference< frame::XModel > &xModel)
uno::Reference< style::XStyle > getDefaultParagraphStyle(const uno::Reference< frame::XModel > &xModel)
VBAHELPER_DLLPUBLIC void dispatchRequests(const css::uno::Reference< css::frame::XModel > &xModel, const OUString &aUrl)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
#define ERRCODE_BASIC_METHOD_FAILED
Reference< XModel > xModel
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Writer_SwVbaDocument_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
cppu::ImplInheritanceHelper< VbaDocumentBase, ooo::vba::word::XDocument, ooo::vba::XSinkCaller > SwVbaDocument_BASE