chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx |   18 
++++------
 chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx       |    5 ++
 chart2/source/controller/chartapiwrapper/DiagramWrapper.hxx       |    5 ++
 chart2/source/controller/inc/ChartDocumentWrapper.hxx             |    3 +
 chart2/source/inc/DisposeHelper.hxx                               |    9 +++++
 5 files changed, 28 insertions(+), 12 deletions(-)

New commits:
commit f976823a66858d3ecc749544be50fdda0c8c40f6
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Sep 12 15:39:44 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Sep 12 19:28:23 2024 +0200

    use more concrete UNO class in chart2
    
    Change-Id: Ifbdcf39f6f621dc63746a8c389a19c52aab847b9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173264
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins

diff --git a/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx 
b/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx
index 7c832ed0d781..f7825b714855 100644
--- a/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx
+++ b/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx
@@ -709,20 +709,18 @@ Reference< XDiagram > SAL_CALL 
ChartDocumentWrapper::getDiagram()
     return m_xDiagram;
 }
 
-void SAL_CALL ChartDocumentWrapper::setDiagram( const Reference< XDiagram >& 
xDiagram )
+void SAL_CALL ChartDocumentWrapper::setDiagram( const Reference< XDiagram >& 
_xDiagram )
 {
-    uno::Reference< util::XRefreshable > xAddIn( xDiagram, uno::UNO_QUERY );
-    if( xAddIn.is() )
-    {
-        setAddIn( xAddIn );
-    }
-    else if( xDiagram.is() && xDiagram != m_xDiagram )
+    if (!_xDiagram.is())
+        return;
+    auto xDiagram = dynamic_cast<DiagramWrapper*>(_xDiagram.get());
+    assert(xDiagram);
+    if( xDiagram != m_xDiagram )
     {
         // set new wrapped diagram at new chart.  This requires the old
         // diagram given as parameter to implement the new interface.  If
         // this is not possible throw an exception
-        Reference< chart2::XDiagramProvider > xNewDiaProvider( xDiagram, 
uno::UNO_QUERY_THROW );
-        Reference< chart2::XDiagram > xNewDia( xNewDiaProvider->getDiagram());
+        rtl::Reference< ::chart::Diagram > xNewDia( 
xDiagram->getUnderlyingDiagram());
 
         try
         {
@@ -1354,7 +1352,7 @@ void ChartDocumentWrapper::_disposing( const 
lang::EventObject& rSource )
         m_xLegend.clear();
     else if( rSource.Source == m_xChartData )
         m_xChartData.clear();
-    else if( rSource.Source == m_xDiagram )
+    else if( rSource.Source == cppu::getXWeak(m_xDiagram.get()) )
         m_xDiagram.clear();
     else if( rSource.Source == m_xArea )
         m_xArea.clear();
diff --git a/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx 
b/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx
index 1623eecb2364..1b9da6491134 100644
--- a/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx
+++ b/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx
@@ -1845,6 +1845,11 @@ Reference< chart2::XDiagram > SAL_CALL 
DiagramWrapper::getDiagram()
     return m_spChart2ModelContact->getDiagram();
 }
 
+rtl::Reference< ::chart::Diagram > DiagramWrapper::getUnderlyingDiagram()
+{
+    return m_spChart2ModelContact->getDiagram();
+}
+
 void SAL_CALL DiagramWrapper::setDiagram(
     const Reference< chart2::XDiagram >& /*xDiagram*/ )
 {
diff --git a/chart2/source/controller/chartapiwrapper/DiagramWrapper.hxx 
b/chart2/source/controller/chartapiwrapper/DiagramWrapper.hxx
index 3a3a8383de05..2e00c0941e58 100644
--- a/chart2/source/controller/chartapiwrapper/DiagramWrapper.hxx
+++ b/chart2/source/controller/chartapiwrapper/DiagramWrapper.hxx
@@ -33,12 +33,13 @@
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <com/sun/star/lang/XComponent.hpp>
 #include <com/sun/star/chart/XSecondAxisTitleSupplier.hpp>
-
 #include <com/sun/star/chart/X3DDefaultSetter.hpp>
+#include <rtl/ref.hxx>
 #include <memory>
 
 namespace com::sun::star::chart2 { class XDiagram; }
 namespace com::sun::star::lang { class XEventListener; }
+namespace chart { class Diagram; }
 
 namespace chart::wrapper
 {
@@ -178,6 +179,8 @@ public:
     virtual css::uno::Reference< css::chart2::XDiagram > SAL_CALL getDiagram() 
override;
     virtual void SAL_CALL setDiagram( const css::uno::Reference< 
css::chart2::XDiagram >& xDiagram ) override;
 
+    rtl::Reference< ::chart::Diagram > getUnderlyingDiagram();
+
 protected:
     // ____ WrappedPropertySet ____
     virtual const css::uno::Sequence< css::beans::Property >& 
getPropertySequence() override;
diff --git a/chart2/source/controller/inc/ChartDocumentWrapper.hxx 
b/chart2/source/controller/inc/ChartDocumentWrapper.hxx
index a5bded3c8fb7..008296b6a358 100644
--- a/chart2/source/controller/inc/ChartDocumentWrapper.hxx
+++ b/chart2/source/controller/inc/ChartDocumentWrapper.hxx
@@ -37,6 +37,7 @@ namespace chart { class ChartView; }
 namespace chart::wrapper
 {
 
+class DiagramWrapper;
 class Chart2ModelContact;
 
 class ChartDocumentWrapper_Base : public ::cppu::ImplInheritanceHelper
@@ -155,7 +156,7 @@ private: //member
     css::uno::Reference< css::drawing::XShape >   m_xSubTitle;
     css::uno::Reference< css::drawing::XShape >   m_xLegend;
     css::uno::Reference< css::chart::XChartData > m_xChartData;
-    css::uno::Reference< css::chart::XDiagram >   m_xDiagram;
+    rtl::Reference< DiagramWrapper >   m_xDiagram;
     css::uno::Reference< css::beans::XPropertySet > m_xArea;
 
     css::uno::Reference< css::util::XRefreshable > m_xAddIn;
diff --git a/chart2/source/inc/DisposeHelper.hxx 
b/chart2/source/inc/DisposeHelper.hxx
index 58dc2d5c55ba..e39c88760dcc 100644
--- a/chart2/source/inc/DisposeHelper.hxx
+++ b/chart2/source/inc/DisposeHelper.hxx
@@ -36,6 +36,15 @@ template <class T> void 
DisposeAndClear(css::uno::Reference<T>& rInterface)
     rInterface.clear();
 }
 
+template <class T> void DisposeAndClear(rtl::Reference<T>& rInterface)
+{
+    if (rInterface)
+    {
+        rInterface->dispose();
+        rInterface.clear();
+    }
+}
+
 template <class Container> void DisposeAllElements(Container& rContainer)
 {
     for (const auto& rElement : rContainer)

Reply via email to