forms/source/inc/InterfaceContainer.hxx   |    9 +++-
 forms/source/misc/InterfaceContainer.cxx  |   13 ++++++
 include/oox/shape/ShapeContextHandler.hxx |   30 +++++++++------
 oox/source/shape/ShapeContextHandler.cxx  |   60 ++++++++++++------------------
 4 files changed, 62 insertions(+), 50 deletions(-)

New commits:
commit f9785ea595fd8e911f6370e836fa579225b9e571
Author:     Stephan Bergmann <[email protected]>
AuthorDate: Tue Dec 20 19:05:30 2022 +0100
Commit:     Stephan Bergmann <[email protected]>
CommitDate: Wed Dec 21 06:43:15 2022 +0000

    loplugin:unocast (frm::OInterfaceContainer)
    
    (See the upcoming commit introducing that loplugin:unocast on why such
    dynamic_casts from UNO types are dangerous.)
    
    Change-Id: Ie8f6fbe25dfffc082033a4bc967d738143746506
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144635
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <[email protected]>

diff --git a/forms/source/inc/InterfaceContainer.hxx 
b/forms/source/inc/InterfaceContainer.hxx
index 66135a02e48e..b42229ddc16c 100644
--- a/forms/source/inc/InterfaceContainer.hxx
+++ b/forms/source/inc/InterfaceContainer.hxx
@@ -22,6 +22,7 @@
 #include <comphelper/uno3.hxx>
 #include <com/sun/star/container/XNameContainer.hpp>
 #include <com/sun/star/lang/EventObject.hpp>
+#include <com/sun/star/lang/XUnoTunnel.hpp>
 #include <com/sun/star/container/XEnumerationAccess.hpp>
 #include <com/sun/star/io/XPersistObject.hpp>
 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
@@ -37,7 +38,7 @@
 #include <comphelper/interfacecontainer3.hxx>
 #include <cppuhelper/component.hxx>
 #include <cppuhelper/implbase1.hxx>
-#include <cppuhelper/implbase8.hxx>
+#include <cppuhelper/implbase9.hxx>
 #include <unordered_map>
 
 namespace com::sun::star::uno { class XComponentContext; }
@@ -72,7 +73,7 @@ typedef std::unordered_multimap< OUString, 
css::uno::Reference<css::uno::XInterf
 // OInterfaceContainer
 // implements a container for form components
 
-typedef ::cppu::ImplHelper8 <   css::container::XNameContainer
+typedef ::cppu::ImplHelper9 <   css::container::XNameContainer
                             ,   css::container::XIndexContainer
                             ,   css::container::XContainer
                             ,   css::container::XEnumerationAccess
@@ -80,6 +81,7 @@ typedef ::cppu::ImplHelper8 <   css::container::XNameContainer
                             ,   css::beans::XPropertyChangeListener
                             ,   css::io::XPersistObject
                             ,   css::util::XCloneable
+                            ,   css::lang::XUnoTunnel
                             > OInterfaceContainer_BASE;
 
 class OInterfaceContainer : public OInterfaceContainer_BASE
@@ -173,6 +175,9 @@ public:
     virtual void SAL_CALL addScriptListener( const css::uno::Reference< 
css::script::XScriptListener >& xListener ) override;
     virtual void SAL_CALL removeScriptListener( const css::uno::Reference< 
css::script::XScriptListener >& Listener ) override;
 
+    sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const & 
aIdentifier) override;
+    static css::uno::Sequence<sal_Int8> const & getUnoTunnelId();
+
 protected:
     // helper
     virtual void SAL_CALL disposing();
diff --git a/forms/source/misc/InterfaceContainer.cxx 
b/forms/source/misc/InterfaceContainer.cxx
index f7278117899c..e7d7b43672c2 100644
--- a/forms/source/misc/InterfaceContainer.cxx
+++ b/forms/source/misc/InterfaceContainer.cxx
@@ -41,6 +41,7 @@
 #include <comphelper/eventattachermgr.hxx>
 #include <comphelper/property.hxx>
 #include <comphelper/sequence.hxx>
+#include <comphelper/servicehelper.hxx>
 #include <comphelper/types.hxx>
 #include <cppuhelper/exc_hlp.hxx>
 #include <o3tl/safeint.hxx>
@@ -834,7 +835,7 @@ void OInterfaceContainer::implInsert(sal_Int32 _nIndex, 
const Reference< XProper
     if ( bHandleVbaEvents )
     {
         Reference< XEventAttacherManager > xMgr ( 
pElementMetaData->xInterface, UNO_QUERY );
-        OInterfaceContainer* pIfcMgr = xMgr.is() ? 
dynamic_cast<OInterfaceContainer*>(xMgr.get()) : nullptr;
+        OInterfaceContainer* pIfcMgr = xMgr.is() ? 
comphelper::getFromUnoTunnel<OInterfaceContainer>(xMgr) : nullptr;
         if (pIfcMgr)
         {
             sal_Int32 nLen = pIfcMgr->getCount();
@@ -1236,6 +1237,16 @@ void SAL_CALL OInterfaceContainer::removeScriptListener( 
const Reference< XScrip
 }
 
 
+sal_Int64 OInterfaceContainer::getSomething(css::uno::Sequence<sal_Int8> const 
& aIdentifier) {
+    return comphelper::getSomethingImpl(aIdentifier, this);
+}
+
+css::uno::Sequence<sal_Int8> const & OInterfaceContainer::getUnoTunnelId() {
+    static comphelper::UnoIdInit const id;
+    return id.getSeq();
+}
+
+
 //= OFormComponents
 
 
commit bc661b966fd82808a94e8684d62007c3f254d778
Author:     Stephan Bergmann <[email protected]>
AuthorDate: Tue Dec 20 21:31:24 2022 +0100
Commit:     Stephan Bergmann <[email protected]>
CommitDate: Wed Dec 21 06:43:03 2022 +0000

    Use rtl::Reference to avoid some dynamic_casts
    
    (And some of those dynamic_casts could apparently never evaluate to null, 
and
    the corresponding checks have thus been dropped as being redundant.)
    
    Change-Id: I351d1c9f2894c5a88429ce3c7495f12145664743
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144636
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <[email protected]>

diff --git a/include/oox/shape/ShapeContextHandler.hxx 
b/include/oox/shape/ShapeContextHandler.hxx
index 42e884f27daa..7887770286b8 100644
--- a/include/oox/shape/ShapeContextHandler.hxx
+++ b/include/oox/shape/ShapeContextHandler.hxx
@@ -25,14 +25,20 @@
 #include <oox/drawingml/graphicshapecontext.hxx>
 #include <oox/core/fragmenthandler2.hxx>
 #include <oox/core/xmlfilterbase.hxx>
+#include <rtl/ref.hxx>
 #include <com/sun/star/document/XDocumentProperties.hpp>
 #include <com/sun/star/graphic/XGraphicMapper.hpp>
 #include <com/sun/star/drawing/XDrawPage.hpp>
 #include <com/sun/star/frame/XModel.hpp>
 
+namespace oox::vml { class DrawingFragment; }
+
 namespace oox::shape {
 
+class LockedCanvasContext;
 class ShapeFilterBase;
+class WpgContext;
+class WpsContext;
 
 class ShapeFragmentHandler final : public core::FragmentHandler2
 {
@@ -128,14 +134,14 @@ private:
 
     typedef rtl::Reference<drawingml::GraphicShapeContext>
     GraphicShapeContextPtr;
-    css::uno::Reference<XFastContextHandler> mxDrawingFragmentHandler;
+    rtl::Reference<vml::DrawingFragment> mxDrawingFragmentHandler;
     css::uno::Reference<XFastContextHandler> mxGraphicShapeContext;
-    css::uno::Reference<XFastContextHandler> mxDiagramShapeContext;
-    css::uno::Reference<XFastContextHandler> mxLockedCanvasContext;
-    css::uno::Reference<XFastContextHandler> mxWpsContext;
+    rtl::Reference<drawingml::DiagramGraphicDataContext> mxDiagramShapeContext;
+    rtl::Reference<LockedCanvasContext> mxLockedCanvasContext;
+    rtl::Reference<WpsContext> mxWpsContext;
     css::uno::Reference<css::drawing::XShape> mxSavedShape;
-    css::uno::Reference<XFastContextHandler> mxWpgContext;
-    css::uno::Reference<XFastContextHandler> mxChartShapeContext;
+    rtl::Reference<WpgContext> mxWpgContext;
+    rtl::Reference<drawingml::ChartGraphicDataContext> mxChartShapeContext;
     css::uno::Reference<css::document::XDocumentProperties> 
mxDocumentProperties;
     css::uno::Sequence<css::beans::PropertyValue> maMediaDescriptor;
 
@@ -145,12 +151,12 @@ private:
     OUString msRelationFragmentPath;
 
     css::uno::Reference<XFastContextHandler> const & 
getGraphicShapeContext(::sal_Int32 Element);
-    css::uno::Reference<XFastContextHandler> const & 
getChartShapeContext(::sal_Int32 Element);
-    css::uno::Reference<XFastContextHandler> const & getDrawingShapeContext();
-    css::uno::Reference<XFastContextHandler> const & getDiagramShapeContext();
-    css::uno::Reference<XFastContextHandler> const & 
getLockedCanvasContext(sal_Int32 nElement);
-    css::uno::Reference<XFastContextHandler> const & getWpsContext(sal_Int32 
nStartElement, sal_Int32 nElement);
-    css::uno::Reference<XFastContextHandler> const & getWpgContext(sal_Int32 
nElement);
+    css::uno::Reference<XFastContextHandler> getChartShapeContext(::sal_Int32 
Element);
+    css::uno::Reference<XFastContextHandler> getDrawingShapeContext();
+    css::uno::Reference<XFastContextHandler> getDiagramShapeContext();
+    css::uno::Reference<XFastContextHandler> getLockedCanvasContext(sal_Int32 
nElement);
+    css::uno::Reference<XFastContextHandler> getWpsContext(sal_Int32 
nStartElement, sal_Int32 nElement);
+    css::uno::Reference<XFastContextHandler> getWpgContext(sal_Int32 nElement);
     css::uno::Reference<XFastContextHandler> getContextHandler(sal_Int32 
nElement = 0);
 
     void applyFontRefColor(const oox::drawingml::ShapePtr& pShape,
diff --git a/oox/source/shape/ShapeContextHandler.cxx 
b/oox/source/shape/ShapeContextHandler.cxx
index 91201fea45f4..662c3d4c0863 100644
--- a/oox/source/shape/ShapeContextHandler.cxx
+++ b/oox/source/shape/ShapeContextHandler.cxx
@@ -55,7 +55,7 @@ ShapeContextHandler::~ShapeContextHandler()
 {
 }
 
-uno::Reference<xml::sax::XFastContextHandler> const & 
ShapeContextHandler::getLockedCanvasContext(sal_Int32 nElement)
+uno::Reference<xml::sax::XFastContextHandler> 
ShapeContextHandler::getLockedCanvasContext(sal_Int32 nElement)
 {
     if (!mxLockedCanvasContext.is())
     {
@@ -64,20 +64,20 @@ uno::Reference<xml::sax::XFastContextHandler> const & 
ShapeContextHandler::getLo
         switch (nElement & 0xffff)
         {
             case XML_lockedCanvas:
-                
mxLockedCanvasContext.set(static_cast<oox::core::ContextHandler*>(new 
LockedCanvasContext(*rFragmentHandler)));
+                mxLockedCanvasContext.set(new 
LockedCanvasContext(*rFragmentHandler));
                 break;
             default:
                 break;
         }
     }
 
-    return mxLockedCanvasContext;
+    return static_cast<ContextHandler *>(mxLockedCanvasContext.get());
 }
 
 /*
  * This method creates new ChartGraphicDataContext Object.
  */
-uno::Reference<xml::sax::XFastContextHandler> const & 
ShapeContextHandler::getChartShapeContext(sal_Int32 nElement)
+uno::Reference<xml::sax::XFastContextHandler> 
ShapeContextHandler::getChartShapeContext(sal_Int32 nElement)
 {
     if (!mxChartShapeContext.is())
     {
@@ -99,7 +99,7 @@ uno::Reference<xml::sax::XFastContextHandler> const & 
ShapeContextHandler::getCh
     return mxChartShapeContext;
 }
 
-uno::Reference<xml::sax::XFastContextHandler> const & 
ShapeContextHandler::getWpsContext(sal_Int32 nStartElement, sal_Int32 nElement)
+uno::Reference<xml::sax::XFastContextHandler> 
ShapeContextHandler::getWpsContext(sal_Int32 nStartElement, sal_Int32 nElement)
 {
     if (!mxWpsContext.is())
     {
@@ -130,7 +130,7 @@ uno::Reference<xml::sax::XFastContextHandler> const & 
ShapeContextHandler::getWp
     return mxWpsContext;
 }
 
-uno::Reference<xml::sax::XFastContextHandler> const & 
ShapeContextHandler::getWpgContext(sal_Int32 nElement)
+uno::Reference<xml::sax::XFastContextHandler> 
ShapeContextHandler::getWpgContext(sal_Int32 nElement)
 {
     if (!mxWpgContext.is())
     {
@@ -140,9 +140,8 @@ uno::Reference<xml::sax::XFastContextHandler> const & 
ShapeContextHandler::getWp
         {
             case XML_wgp:
             {
-                rtl::Reference<WpgContext> rContext = new 
WpgContext(*rFragmentHandler, oox::drawingml::ShapePtr());
-                rContext->setFullWPGSupport(m_bFullWPGSUpport);
-                
mxWpgContext.set(static_cast<oox::core::ContextHandler*>(rContext.get()));
+                mxWpgContext.set(new WpgContext(*rFragmentHandler, 
oox::drawingml::ShapePtr()));
+                mxWpgContext->setFullWPGSupport(m_bFullWPGSUpport);
                 break;
             }
             default:
@@ -150,7 +149,7 @@ uno::Reference<xml::sax::XFastContextHandler> const & 
ShapeContextHandler::getWp
         }
     }
 
-    return mxWpgContext;
+    return static_cast<ContextHandler *>(mxWpgContext.get());
 }
 
 uno::Reference<xml::sax::XFastContextHandler> const &
@@ -181,34 +180,32 @@ ShapeContextHandler::getGraphicShapeContext(::sal_Int32 
Element )
     return mxGraphicShapeContext;
 }
 
-uno::Reference<xml::sax::XFastContextHandler> const &
+uno::Reference<xml::sax::XFastContextHandler>
 ShapeContextHandler::getDrawingShapeContext()
 {
     if (!mxDrawingFragmentHandler.is())
     {
         mpDrawing = std::make_shared<oox::vml::Drawing>( *mxShapeFilterBase, 
mxDrawPage, oox::vml::VMLDRAWING_WORD );
         mxDrawingFragmentHandler.set
-          (static_cast<ContextHandler *>
            (new oox::vml::DrawingFragment
-            ( *mxShapeFilterBase, msRelationFragmentPath, *mpDrawing )));
+            ( *mxShapeFilterBase, msRelationFragmentPath, *mpDrawing ));
     }
     else
     {
         // Reset the handler if fragment path has changed
-        OUString sHandlerFragmentPath = 
dynamic_cast<ContextHandler&>(*mxDrawingFragmentHandler).getFragmentPath();
+        OUString sHandlerFragmentPath = 
mxDrawingFragmentHandler->getFragmentPath();
         if ( msRelationFragmentPath != sHandlerFragmentPath )
         {
             mxDrawingFragmentHandler.clear();
             mxDrawingFragmentHandler.set
-              (static_cast<ContextHandler *>
                (new oox::vml::DrawingFragment
-                ( *mxShapeFilterBase, msRelationFragmentPath, *mpDrawing )));
+                ( *mxShapeFilterBase, msRelationFragmentPath, *mpDrawing ));
         }
     }
-    return mxDrawingFragmentHandler;
+    return static_cast<ContextHandler *>(mxDrawingFragmentHandler.get());
 }
 
-uno::Reference<xml::sax::XFastContextHandler> const &
+uno::Reference<xml::sax::XFastContextHandler>
 ShapeContextHandler::getDiagramShapeContext()
 {
     if (!mxDiagramShapeContext.is())
@@ -419,10 +416,7 @@ ShapeContextHandler::getShape()
                 // Prerendered diagram output is available, then use that, and 
throw away the original result.
                 for (auto const& extDrawing : mpShape->getExtDrawings())
                 {
-                    DiagramGraphicDataContext* pDiagramGraphicDataContext = 
dynamic_cast<DiagramGraphicDataContext*>(mxDiagramShapeContext.get());
-                    if (!pDiagramGraphicDataContext)
-                        break;
-                    OUString 
aFragmentPath(pDiagramGraphicDataContext->getFragmentPathFromRelId(extDrawing));
+                    OUString 
aFragmentPath(mxDiagramShapeContext->getFragmentPathFromRelId(extDrawing));
                     oox::drawingml::ShapePtr pShapePtr = 
std::make_shared<Shape>( "com.sun.star.drawing.GroupShape" );
                     pShapePtr->setDiagramType();
                     mxShapeFilterBase->importFragment(new 
ShapeDrawingFragmentHandler(*mxShapeFilterBase, aFragmentPath, pShapePtr));
@@ -453,7 +447,7 @@ ShapeContextHandler::getShape()
         }
         else if (mxLockedCanvasContext.is())
         {
-            ShapePtr pShape = 
dynamic_cast<LockedCanvasContext&>(*mxLockedCanvasContext).getShape();
+            ShapePtr pShape = mxLockedCanvasContext->getShape();
             if (pShape)
             {
                 basegfx::B2DHomMatrix aMatrix;
@@ -467,21 +461,17 @@ ShapeContextHandler::getShape()
         //Only in case it is set then only the below block of code for 
ChartShapeContext should be executed.
         else if (mxChartShapeContext.is() && (NMSP_dmlChart == getNamespace( 
getStartToken() )))
         {
-            ChartGraphicDataContext* pChartGraphicDataContext = 
dynamic_cast<ChartGraphicDataContext*>(mxChartShapeContext.get());
-            if (pChartGraphicDataContext)
-            {
-                basegfx::B2DHomMatrix aMatrix;
-                oox::drawingml::ShapePtr xShapePtr( 
pChartGraphicDataContext->getShape());
-                // See SwXTextDocument::createInstance(), ODF import uses the 
same hack.
-                
xShapePtr->setServiceName("com.sun.star.drawing.temporaryForXMLImportOLE2Shape");
-                xShapePtr->addShape( *mxShapeFilterBase, mpThemePtr.get(), 
xShapes, aMatrix, xShapePtr->getFillProperties() );
-                xResult = xShapePtr->getXShape();
-            }
+            basegfx::B2DHomMatrix aMatrix;
+            oox::drawingml::ShapePtr xShapePtr( 
mxChartShapeContext->getShape());
+            // See SwXTextDocument::createInstance(), ODF import uses the same 
hack.
+            
xShapePtr->setServiceName("com.sun.star.drawing.temporaryForXMLImportOLE2Shape");
+            xShapePtr->addShape( *mxShapeFilterBase, mpThemePtr.get(), 
xShapes, aMatrix, xShapePtr->getFillProperties() );
+            xResult = xShapePtr->getXShape();
             mxChartShapeContext.clear();
         }
         else if (mxWpsContext.is())
         {
-            ShapePtr pShape = 
dynamic_cast<WpsContext&>(*mxWpsContext).getShape();
+            ShapePtr pShape = mxWpsContext->getShape();
             if (pShape)
             {
                 basegfx::B2DHomMatrix aMatrix;
@@ -494,7 +484,7 @@ ShapeContextHandler::getShape()
         }
         else if (mxWpgContext.is())
         {
-            ShapePtr pShape = 
dynamic_cast<WpgContext&>(*mxWpgContext).getShape();
+            ShapePtr pShape = mxWpgContext->getShape();
             if (pShape)
             {
                 basegfx::B2DHomMatrix aMatrix;

Reply via email to