summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2024-04-24 15:02:18 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-04-28 22:26:33 +0200
commit7ee095d7e075ebc12183378c65fe64e5c0fc1ba4 (patch)
tree3ae521370715527d035fe8a23714428d4c21d1b2
parent24ac1b2eea24c6aab04ecde88e692f352fda2b62 (diff)
use more concrete UNO classes in writerfilter (SwXTextGraphicObject)
Change-Id: I27c96bd3c18d24398f773319fa41bed8a8da9eee Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166802 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sw/inc/unoframe.hxx5
-rw-r--r--sw/inc/unotxdoc.hxx2
-rw-r--r--sw/source/uibase/uno/unotxdoc.cxx7
-rw-r--r--sw/source/writerfilter/dmapper/GraphicImport.cxx83
-rw-r--r--sw/source/writerfilter/dmapper/GraphicImport.hxx9
5 files changed, 57 insertions, 49 deletions
diff --git a/sw/inc/unoframe.hxx b/sw/inc/unoframe.hxx
index 705e52e40440..33648faf7bde 100644
--- a/sw/inc/unoframe.hxx
+++ b/sw/inc/unoframe.hxx
@@ -19,6 +19,7 @@
#ifndef INCLUDED_SW_INC_UNOFRAME_HXX
#define INCLUDED_SW_INC_UNOFRAME_HXX
+#include "swdllapi.h"
#include <com/sun/star/beans/XPropertyState.hpp>
#include <com/sun/star/container/XNamed.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
@@ -103,7 +104,7 @@ public:
//XPropertySet
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
- virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
+ SW_DLLPUBLIC virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
@@ -236,7 +237,7 @@ typedef cppu::ImplInheritanceHelper
css::document::XEventsSupplier
>
SwXTextGraphicObjectBaseClass;
-class SwXTextGraphicObject final : public SwXTextGraphicObjectBaseClass
+class SW_DLLPUBLIC SwXTextGraphicObject final : public SwXTextGraphicObjectBaseClass
{
friend class SwXFrame; // just for CreateXFrame
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index 59fab6827acb..d84561244258 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -112,6 +112,7 @@ class SwXTextSection;
class SwXTextField;
class SwXLineBreak;
class SwXTextFrame;
+class SwXTextGraphicObject;
namespace com::sun::star::container { class XNameContainer; }
namespace com::sun::star::frame { class XController; }
namespace com::sun::star::lang { struct Locale; }
@@ -522,6 +523,7 @@ public:
SW_DLLPUBLIC rtl::Reference<SwXTextField> createFieldAnnotation();
SW_DLLPUBLIC rtl::Reference<SwXLineBreak> createLineBreak();
SW_DLLPUBLIC rtl::Reference<SwXTextFrame> createTextFrame();
+ SW_DLLPUBLIC rtl::Reference<SwXTextGraphicObject> createTextGraphicObject();
};
class SwXLinkTargetSupplier final : public cppu::WeakImplHelper
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 3d36312afecc..2fa09ab06e70 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -1713,6 +1713,13 @@ rtl::Reference< SwXTextFrame > SwXTextDocument::createTextFrame()
return SwXTextFrame::CreateXTextFrame(GetDocOrThrow(), nullptr);
}
+rtl::Reference< SwXTextGraphicObject > SwXTextDocument::createTextGraphicObject()
+{
+ SolarMutexGuard aGuard;
+ ThrowIfInvalid();
+ return SwXTextGraphicObject::CreateXTextGraphicObject(GetDocOrThrow(), nullptr);
+}
+
Reference< XInterface > SwXTextDocument::createInstance(const OUString& rServiceName)
{
return create(rServiceName, nullptr);
diff --git a/sw/source/writerfilter/dmapper/GraphicImport.cxx b/sw/source/writerfilter/dmapper/GraphicImport.cxx
index 2df2569530a1..0320c671c47f 100644
--- a/sw/source/writerfilter/dmapper/GraphicImport.cxx
+++ b/sw/source/writerfilter/dmapper/GraphicImport.cxx
@@ -82,6 +82,8 @@
#include <o3tl/unit_conversion.hxx>
#include <oox/export/drawingml.hxx>
#include <utility>
+#include <unoframe.hxx>
+#include <unotxdoc.hxx>
using namespace css;
@@ -467,7 +469,7 @@ public:
};
GraphicImport::GraphicImport(uno::Reference<uno::XComponentContext> xComponentContext,
- uno::Reference<lang::XMultiServiceFactory> xTextFactory,
+ rtl::Reference<SwXTextDocument> xTextDoc,
DomainMapper& rDMapper,
GraphicImportType & rImportType,
std::pair<OUString, OUString>& rPositionOffsets,
@@ -478,7 +480,7 @@ GraphicImport::GraphicImport(uno::Reference<uno::XComponentContext> xComponentCo
, LoggedStream("GraphicImport")
, m_pImpl(new GraphicImport_Impl(rImportType, rDMapper, rPositionOffsets, rAligns, rPositivePercentages))
, m_xComponentContext(std::move(xComponentContext))
-, m_xTextFactory(std::move(xTextFactory))
+, m_xTextDoc(std::move(xTextDoc))
{
}
@@ -873,12 +875,10 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
if ( !bUseShape )
{
// Define the object size
- uno::Reference< beans::XPropertySet > xGraphProps( m_xGraphicObject,
- uno::UNO_QUERY );
awt::Size aSize = xShape->getSize( );
- xGraphProps->setPropertyValue("Height",
+ m_xGraphicObject->setPropertyValue("Height",
uno::Any( aSize.Height ) );
- xGraphProps->setPropertyValue("Width",
+ m_xGraphicObject->setPropertyValue("Width",
uno::Any( aSize.Width ) );
text::GraphicCrop aGraphicCrop( 0, 0, 0, 0 );
@@ -886,12 +886,12 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
uno::Any aAny = xSourceGraphProps->getPropertyValue("GraphicCrop");
if (m_pImpl->m_oCrop)
{ // RTF: RTFValue from resolvePict()
- xGraphProps->setPropertyValue("GraphicCrop",
+ m_xGraphicObject->setPropertyValue("GraphicCrop",
uno::Any(*m_pImpl->m_oCrop));
}
else if (aAny >>= aGraphicCrop)
{ // DOCX: imported in oox BlipFillContext
- xGraphProps->setPropertyValue("GraphicCrop",
+ m_xGraphicObject->setPropertyValue("GraphicCrop",
uno::Any( aGraphicCrop ) );
}
@@ -1771,23 +1771,20 @@ void GraphicImport::lcl_entry(const writerfilter::Reference<Properties>::Pointer
{
}
-uno::Reference<text::XTextContent> GraphicImport::createGraphicObject(uno::Reference<graphic::XGraphic> const & rxGraphic,
+rtl::Reference<SwXTextGraphicObject> GraphicImport::createGraphicObject(uno::Reference<graphic::XGraphic> const & rxGraphic,
uno::Reference<beans::XPropertySet> const & xShapeProps)
{
- uno::Reference<text::XTextContent> xGraphicObject;
+ rtl::Reference<SwXTextGraphicObject> xGraphicObject;
try
{
if (rxGraphic.is())
{
- uno::Reference< beans::XPropertySet > xGraphicObjectProperties(
- m_xTextFactory->createInstance("com.sun.star.text.TextGraphicObject"),
- uno::UNO_QUERY_THROW);
- xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_GRAPHIC), uno::Any(rxGraphic));
- xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_ANCHOR_TYPE),
+ xGraphicObject = m_xTextDoc->createTextGraphicObject();
+ xGraphicObject->setPropertyValue(getPropertyName(PROP_GRAPHIC), uno::Any(rxGraphic));
+ xGraphicObject->setPropertyValue(getPropertyName(PROP_ANCHOR_TYPE),
uno::Any( m_pImpl->m_rGraphicImportType == IMPORT_AS_DETECTED_ANCHOR ?
text::TextContentAnchorType_AT_CHARACTER :
text::TextContentAnchorType_AS_CHARACTER ));
- xGraphicObject.set( xGraphicObjectProperties, uno::UNO_QUERY_THROW );
//shapes have only one border
table::BorderLine2 aBorderLine;
@@ -1816,7 +1813,7 @@ uno::Reference<text::XTextContent> GraphicImport::createGraphicObject(uno::Refer
};
for(PropertyIds const & rBorderProp : aBorderProps)
- xGraphicObjectProperties->setPropertyValue(getPropertyName(rBorderProp), uno::Any(aBorderLine));
+ xGraphicObject->setPropertyValue(getPropertyName(rBorderProp), uno::Any(aBorderLine));
// setting graphic object shadow properties
if (m_pImpl->m_bShadow)
@@ -1847,18 +1844,18 @@ uno::Reference<text::XTextContent> GraphicImport::createGraphicObject(uno::Refer
aShadow.Location = table::ShadowLocation_TOP_LEFT;
}
- xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_SHADOW_FORMAT), uno::Any(aShadow));
+ xGraphicObject->setPropertyValue(getPropertyName(PROP_SHADOW_FORMAT), uno::Any(aShadow));
}
// setting properties for all types
if( m_pImpl->m_bPositionProtected )
- xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_POSITION_PROTECTED ),
+ xGraphicObject->setPropertyValue(getPropertyName( PROP_POSITION_PROTECTED ),
uno::Any(true));
if( m_pImpl->m_bSizeProtected )
- xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_SIZE_PROTECTED ),
+ xGraphicObject->setPropertyValue(getPropertyName( PROP_SIZE_PROTECTED ),
uno::Any(true));
- xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_DECORATIVE), uno::Any(m_pImpl->m_bDecorative));
+ xGraphicObject->setPropertyValue(getPropertyName(PROP_DECORATIVE), uno::Any(m_pImpl->m_bDecorative));
sal_Int32 nWidth = - m_pImpl->m_nLeftPosition;
if (m_pImpl->m_rGraphicImportType == IMPORT_AS_DETECTED_ANCHOR)
{
@@ -1923,41 +1920,41 @@ uno::Reference<text::XTextContent> GraphicImport::createGraphicObject(uno::Refer
m_pImpl->m_nTopPosition *= -1;
}
- m_pImpl->applyPosition(xGraphicObjectProperties);
- m_pImpl->applyRelativePosition(xGraphicObjectProperties);
+ m_pImpl->applyPosition(xGraphicObject);
+ m_pImpl->applyRelativePosition(xGraphicObject);
if( !m_pImpl->m_bOpaque )
{
- xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_OPAQUE ), uno::Any(m_pImpl->m_bOpaque));
+ xGraphicObject->setPropertyValue(getPropertyName( PROP_OPAQUE ), uno::Any(m_pImpl->m_bOpaque));
}
- xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_SURROUND ),
+ xGraphicObject->setPropertyValue(getPropertyName( PROP_SURROUND ),
uno::Any(static_cast<sal_Int32>(m_pImpl->m_nWrap)));
if( m_pImpl->m_rDomainMapper.IsInTable())
- xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_FOLLOW_TEXT_FLOW ),
+ xGraphicObject->setPropertyValue(getPropertyName( PROP_FOLLOW_TEXT_FLOW ),
uno::Any(m_pImpl->m_bLayoutInCell));
- xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_ALLOW_OVERLAP),
+ xGraphicObject->setPropertyValue(getPropertyName(PROP_ALLOW_OVERLAP),
uno::Any(m_pImpl->m_bAllowOverlap));
- xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_SURROUND_CONTOUR ),
+ xGraphicObject->setPropertyValue(getPropertyName( PROP_SURROUND_CONTOUR ),
uno::Any(m_pImpl->m_bContour));
- xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_CONTOUR_OUTSIDE ),
+ xGraphicObject->setPropertyValue(getPropertyName( PROP_CONTOUR_OUTSIDE ),
uno::Any(m_pImpl->m_bContourOutside));
- m_pImpl->applyMargins(xGraphicObjectProperties);
+ m_pImpl->applyMargins(xGraphicObject);
}
- xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_ADJUST_CONTRAST ),
+ xGraphicObject->setPropertyValue(getPropertyName( PROP_ADJUST_CONTRAST ),
uno::Any(static_cast<sal_Int16>(m_pImpl->m_nContrast)));
- xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_ADJUST_LUMINANCE ),
+ xGraphicObject->setPropertyValue(getPropertyName( PROP_ADJUST_LUMINANCE ),
uno::Any(static_cast<sal_Int16>(m_pImpl->m_nBrightness)));
if(m_pImpl->m_eColorMode != drawing::ColorMode_STANDARD)
{
- xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_GRAPHIC_COLOR_MODE ),
+ xGraphicObject->setPropertyValue(getPropertyName( PROP_GRAPHIC_COLOR_MODE ),
uno::Any(m_pImpl->m_eColorMode));
}
- xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_BACK_COLOR ),
+ xGraphicObject->setPropertyValue(getPropertyName( PROP_BACK_COLOR ),
uno::Any( GraphicImport_Impl::nFillColor ));
- m_pImpl->applyZOrder(xGraphicObjectProperties);
+ m_pImpl->applyZOrder(xGraphicObject);
//there seems to be no way to detect the original size via _real_ API
uno::Reference< beans::XPropertySet > xGraphicProperties(rxGraphic, uno::UNO_QUERY_THROW);
@@ -1994,12 +1991,12 @@ uno::Reference<text::XTextContent> GraphicImport::createGraphicObject(uno::Refer
if (pCorrected)
{
aContourPolyPolygon <<= pCorrected->getPointSequenceSequence();
- xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_CONTOUR_POLY_POLYGON),
+ xGraphicObject->setPropertyValue(getPropertyName(PROP_CONTOUR_POLY_POLYGON),
aContourPolyPolygon);
// We should bring it to front, even if wp:anchor's behindDoc="1",
// because otherwise paragraph background (if set) overlaps the graphic
// TODO: if paragraph's background becomes bottommost, then remove this hack
- xGraphicObjectProperties->setPropertyValue("Opaque", uno::Any(true));
+ xGraphicObject->setPropertyValue("Opaque", uno::Any(true));
}
}
@@ -2008,11 +2005,11 @@ uno::Reference<text::XTextContent> GraphicImport::createGraphicObject(uno::Refer
|| m_pImpl->m_rGraphicImportType == IMPORT_AS_DETECTED_ANCHOR)
{
if( m_pImpl->getXSize() && m_pImpl->getYSize() )
- xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_SIZE),
+ xGraphicObject->setPropertyValue(getPropertyName(PROP_SIZE),
uno::Any( awt::Size( m_pImpl->getXSize(), m_pImpl->getYSize() )));
- m_pImpl->applyMargins(xGraphicObjectProperties);
- m_pImpl->applyName(xGraphicObjectProperties);
- m_pImpl->applyHyperlink(xGraphicObjectProperties, false);
+ m_pImpl->applyMargins(xGraphicObject);
+ m_pImpl->applyName(xGraphicObject);
+ m_pImpl->applyHyperlink(xGraphicObject, false);
}
// Handle horizontal flip.
@@ -2020,9 +2017,9 @@ uno::Reference<text::XTextContent> GraphicImport::createGraphicObject(uno::Refer
xShapeProps->getPropertyValue("IsMirrored") >>= bMirrored;
if (bMirrored)
{
- xGraphicObjectProperties->setPropertyValue("HoriMirroredOnEvenPages",
+ xGraphicObject->setPropertyValue("HoriMirroredOnEvenPages",
uno::Any(true));
- xGraphicObjectProperties->setPropertyValue("HoriMirroredOnOddPages",
+ xGraphicObject->setPropertyValue("HoriMirroredOnOddPages",
uno::Any(true));
}
}
diff --git a/sw/source/writerfilter/dmapper/GraphicImport.hxx b/sw/source/writerfilter/dmapper/GraphicImport.hxx
index dae19ce85c03..2ae7b83dd08a 100644
--- a/sw/source/writerfilter/dmapper/GraphicImport.hxx
+++ b/sw/source/writerfilter/dmapper/GraphicImport.hxx
@@ -27,6 +27,7 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
+class SwXTextGraphicObject;
namespace com::sun::star {
namespace uno
{
@@ -67,14 +68,14 @@ class GraphicImport : public LoggedProperties, public LoggedTable
std::unique_ptr<GraphicImport_Impl> m_pImpl;
css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
- css::uno::Reference<css::lang::XMultiServiceFactory> m_xTextFactory;
+ rtl::Reference<SwXTextDocument> m_xTextDoc;
- css::uno::Reference<css::text::XTextContent> m_xGraphicObject;
+ rtl::Reference<SwXTextGraphicObject> m_xGraphicObject;
css::uno::Reference<css::drawing::XShape> m_xShape;
void ProcessShapeOptions(Value const & val);
- css::uno::Reference<css::text::XTextContent>
+ rtl::Reference<SwXTextGraphicObject>
createGraphicObject(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic,
css::uno::Reference<css::beans::XPropertySet> const & xShapeProps);
@@ -82,7 +83,7 @@ class GraphicImport : public LoggedProperties, public LoggedTable
public:
explicit GraphicImport( css::uno::Reference<css::uno::XComponentContext> xComponentContext,
- css::uno::Reference<css::lang::XMultiServiceFactory> xTextFactory,
+ rtl::Reference<SwXTextDocument> xTextDoc,
DomainMapper& rDomainMapper,
GraphicImportType & rGraphicImportType,
std::pair<OUString, OUString>& rPositionOffsets,