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())
237 return uno::Any(uno::Reference<XCollection>(
245 return uno::Any(uno::Reference<XCollection>(
253 mxModel->getCurrentController());
259 uno::Reference< css::document::XDocumentPropertiesSupplier > xDocumentPropertiesSupplier( getModel(),uno::UNO_QUERY_THROW );
260 uno::Reference< css::document::XDocumentProperties > xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties();
261 uno::Reference< beans::XPropertyAccess > xUserDefined( xDocumentProperties->getUserDefinedProperties(), uno::UNO_QUERY_THROW );
264 if ( rIndex.getValueTypeClass() == uno::TypeClass_VOID )
267 return xVariables->Item( rIndex,
uno::Any() );
274 if (
index.hasValue() )
283 if (
index.hasValue() )
292 if (
index.hasValue() )
300 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( getModel(), uno::UNO_QUERY_THROW );
301 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
305 if (
index.hasValue() )
322 if (
index.hasValue() )
331 if (
index.hasValue() )
339 if (
index.hasValue())
354 return "SwVbaDocument";
360 uno::Reference< word::XTemplate > xTemplate;
361 uno::Reference<css::document::XDocumentPropertiesSupplier>
const xDocPropSupp(
362 getModel(), uno::UNO_QUERY_THROW);
363 uno::Reference< css::document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_SET_THROW );
364 OUString sTemplateUrl = xDocProps->getTemplateURL();
374 if( !( _attachedtemplate >>= sTemplate ) )
376 throw uno::RuntimeException();
381 bool bIsURL = aObj.
GetProtocol() != INetProtocol::NotValid;
385 osl::FileBase::getFileURLFromSystemPath( sTemplate,
aURL );
387 uno::Reference<css::document::XDocumentPropertiesSupplier>
const xDocPropSupp(
388 getModel(), uno::UNO_QUERY_THROW );
389 uno::Reference< css::document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_SET_THROW );
390 xDocProps->setTemplateURL(
aURL );
412 return word::WdProtectionType::wdNoProtection;
434 bool IsAutoHyphenation =
false;
436 xParaProps->getPropertyValue(
"ParaIsHyphenation") >>= IsAutoHyphenation;
437 return IsAutoHyphenation;
444 xParaProps->setPropertyValue(
"ParaIsHyphenation",
uno::Any( _autohyphenation ) );
461 sal_Int16 nHyphensLimit = 0;
463 xParaProps->getPropertyValue(
"ParaHyphenationMaxHyphens") >>= nHyphensLimit;
464 return nHyphensLimit;
469 sal_Int16 nHyphensLimit =
static_cast< sal_Int16
>( _consecutivehyphenslimit );
471 xParaProps->setPropertyValue(
"ParaHyphenationMaxHyphens",
uno::Any( nHyphensLimit ) );
485void 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& )
503 uno::Reference< css::document::XRedlinesSupplier > xRedlinesSupp(
mxTextDocument, uno::UNO_QUERY_THROW );
504 uno::Reference< container::XIndexAccess > xRedlines( xRedlinesSupp->getRedlines(), uno::UNO_QUERY_THROW );
506 if (
index.hasValue() )
514 uno::Reference< text::XTextFramesSupplier > xTextFramesSupp(
mxTextDocument, uno::UNO_QUERY_THROW );
515 uno::Reference< container::XIndexAccess > xFrames( xTextFramesSupp->getTextFrames(), uno::UNO_QUERY_THROW );
517 if (
index.hasValue() )
523SwVbaDocument::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& )
525 SAL_INFO(
"sw.vba",
"Document.SaveAs2000(FileName:=" << FileName <<
",FileFormat:=" << FileFormat <<
")");
529 FileName >>= sFileName;
531 osl::FileBase::getFileURLFromSystemPath( sFileName, sURL );
539 sURL = getModel()->getURL();
541 if ( sURL.isEmpty() )
547 xPathSettings->getPropertyValue(
"Work" ) >>= sPathUrl;
550 sal_Int32
nIndex = sPathUrl.lastIndexOf(
';' );
553 sPathUrl = sPathUrl.copy(
nIndex + 1 );
556 aURL.SetURL( sPathUrl );
561 aURL.Append( sFileName );
567 sal_Int32 nFileFormat = word::WdSaveFormat::wdFormatDocument;
568 FileFormat >>= nFileFormat;
572 setFilterPropsFromFormat( nFileFormat, storeProps );
574 uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
575 xStor->storeAsURL( sURL, storeProps );
579SwVbaDocument::SaveAs(
const uno::Any& FileName,
const uno::Any& FileFormat,
const uno::Any& LockComments,
const uno::Any& Password,
const uno::Any& AddToRecentFiles,
const uno::Any& WritePassword,
const uno::Any& ReadOnlyRecommended,
const uno::Any& EmbedTrueTypeFonts,
const uno::Any& SaveNativePictureFormat,
const uno::Any& SaveFormsData,
const uno::Any& SaveAsAOCELetter,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& ,
const uno::Any& )
581 return SaveAs2000( FileName, FileFormat, LockComments,
Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter );
594 FileName >>= sFileName;
596 osl::FileBase::getFileURLFromSystemPath( sFileName, sURL );
599 OUString(
"writer_png_Export")) };
601 uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
602 xStor->storeToURL( sURL, storeProps );
608 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(
mxTextDocument, uno::UNO_QUERY_THROW );
609 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
611 sal_Int32
nCount = xIndexAccess->getCount();
616 uno::Reference< drawing::XControlShape > xControlShape( aUnoObj, uno::UNO_QUERY );
617 if( xControlShape.is() )
619 uno::Reference< container::XNamed > xNamed( xControlShape->getControl(), uno::UNO_QUERY_THROW );
620 if(
sName == xNamed->getName() )
629uno::Reference< beans::XIntrospectionAccess > SAL_CALL
632 return uno::Reference< beans::XIntrospectionAccess >();
636SwVbaDocument::invoke(
const OUString& aFunctionName,
const uno::Sequence< uno::Any >& , uno::Sequence< ::sal_Int16 >& , uno::Sequence< uno::Any >& )
638 SAL_INFO(
"sw.vba",
"** will barf " << aFunctionName );
639 throw uno::RuntimeException();
645 throw uno::RuntimeException();
650 uno::Reference< drawing::XControlShape > xControlShape(
getControlShape( aPropertyName ), uno::UNO_QUERY_THROW );
652 uno::Reference<lang::XMultiComponentFactory > xServiceManager(
mxContext->getServiceManager(), uno::UNO_SET_THROW );
653 uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext(
"ooo.vba.ControlProvider",
mxContext ), uno::UNO_QUERY_THROW );
654 uno::Reference< msforms::XControl > xControl( xControlProvider->createControl( xControlShape, getModel() ) );
667 uno::Reference< container::XNameAccess > xFormControls(
getFormControls() );
668 if ( xFormControls.is() )
669 return xFormControls->hasByName(
aName );
673uno::Reference< container::XNameAccess >
676 uno::Reference< container::XNameAccess > xFormControls;
679 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(
mxTextDocument, uno::UNO_QUERY_THROW );
680 uno::Reference< form::XFormsSupplier > xFormSupplier( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
681 uno::Reference< container::XIndexAccess > xIndexAccess( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
685 xFormControls.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW );
687 catch(
const uno::Exception&)
690 return xFormControls;
698 return "{82154424-0FBF-11d4-8313-005004526AB4}";
706 return "{82154428-0FBF-11D4-8313-005004526AB4}";
714 "{82154429-0FBF-11D4-8313-005004526AB4}"
732uno::Reference<XConnectionPoint> SAL_CALL
735 uno::Reference<XConnectionPoint> xCP(
new SwVbaDocumentOutgoingConnectionPoint(
this));
741SwVbaDocumentOutgoingConnectionPoint::SwVbaDocumentOutgoingConnectionPoint(
SwVbaDocument* pDoc ) :
749SwVbaDocumentOutgoingConnectionPoint::Advise(
const uno::Reference< XSink >& Sink )
751 return mpDoc->AddSink(Sink);
755SwVbaDocumentOutgoingConnectionPoint::Unadvise( sal_uInt32 Cookie )
757 mpDoc->RemoveSink( Cookie );
760uno::Sequence< OUString >
765 "ooo.vba.word.Document"
770extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
772 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