[Libreoffice-commits] core.git: framework/inc framework/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Wed Jul 7 10:09:23 UTC 2021


 framework/inc/helper/tagwindowasmodified.hxx    |    8 +-
 framework/source/helper/tagwindowasmodified.cxx |   96 +++++++-----------------
 2 files changed, 36 insertions(+), 68 deletions(-)

New commits:
commit 3e942e40a6c175e4e42a16be83191bc5e01f43b9
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Jul 6 18:53:35 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Jul 7 12:08:47 2021 +0200

    tdf#132740 improve TagWindowAsModified
    
    makes a small difference
    
    (*) Use strong ref instead of weak ref, because weak ref is expensive to
    access
    (*) to make that work, fix dispose()
    (*) cache the vcl::Window to avoid expensive VCLUnoHelper::GetWindow
    
    Change-Id: Ida7a060d729633a0feb326697509d90052bca1f8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118533
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/framework/inc/helper/tagwindowasmodified.hxx b/framework/inc/helper/tagwindowasmodified.hxx
index ee06ed6d6e44..1528c63c5b18 100644
--- a/framework/inc/helper/tagwindowasmodified.hxx
+++ b/framework/inc/helper/tagwindowasmodified.hxx
@@ -23,9 +23,11 @@
 #include <com/sun/star/frame/XFrame.hpp>
 #include <com/sun/star/util/XModifyListener.hpp>
 #include <com/sun/star/frame/XFrameActionListener.hpp>
+#include <com/sun/star/util/XModifiable.hpp>
 
 #include <cppuhelper/implbase.hxx>
 #include <cppuhelper/weakref.hxx>
+#include <vcl/window.hxx>
 
 namespace framework{
 
@@ -51,13 +53,13 @@ class TagWindowAsModified final : public  ::cppu::WeakImplHelper<
     private:
 
         /// reference to the frame, where we listen for new loaded documents for updating our own xModel reference
-        css::uno::WeakReference< css::frame::XFrame > m_xFrame;
+        css::uno::Reference< css::frame::XFrame > m_xFrame;
 
         /// reference to the frame container window, where we must set the tag
-        css::uno::WeakReference< css::awt::XWindow > m_xWindow;
+        VclPtr<vcl::Window> m_xWindow;
 
         /// we list on the model for modify events
-        css::uno::WeakReference< css::frame::XModel > m_xModel;
+        css::uno::Reference< css::util::XModifiable > m_xModel;
 
     // interface
 
diff --git a/framework/source/helper/tagwindowasmodified.cxx b/framework/source/helper/tagwindowasmodified.cxx
index 93f2ace64c99..33a722a725eb 100644
--- a/framework/source/helper/tagwindowasmodified.cxx
+++ b/framework/source/helper/tagwindowasmodified.cxx
@@ -22,7 +22,6 @@
 #include <com/sun/star/awt/XWindow.hpp>
 
 #include <com/sun/star/util/XModifyBroadcaster.hpp>
-#include <com/sun/star/util/XModifiable.hpp>
 #include <com/sun/star/frame/FrameAction.hpp>
 
 #include <toolkit/helper/vclunohelper.hxx>
@@ -47,52 +46,31 @@ void SAL_CALL TagWindowAsModified::initialize(const css::uno::Sequence< css::uno
     if (lArguments.hasElements())
         lArguments[0] >>= xFrame;
 
-    if ( ! xFrame.is ())
+    if (!xFrame)
         return;
 
-    {
-        SolarMutexGuard g;
-        m_xFrame = xFrame;
-    }
-
+    m_xFrame = xFrame;
     xFrame->addFrameActionListener(this);
     impl_update (xFrame);
 }
 
 void SAL_CALL TagWindowAsModified::modified(const css::lang::EventObject& aEvent)
 {
-    css::uno::Reference< css::util::XModifiable > xModel;
-    css::uno::Reference< css::awt::XWindow >      xWindow;
-    {
-        SolarMutexGuard g;
-        xModel.set(m_xModel.get (), css::uno::UNO_QUERY);
-        xWindow.set(m_xWindow.get(), css::uno::UNO_QUERY);
-        if (
-            ( ! xModel.is  ()       ) ||
-            ( ! xWindow.is ()       ) ||
-            (aEvent.Source != xModel)
-        )
-            return;
-    }
+    if (!m_xModel || !m_xWindow || aEvent.Source != m_xModel)
+        return;
 
-    bool bModified = xModel->isModified ();
+    bool bModified = m_xModel->isModified ();
 
     // SYNCHRONIZED ->
     SolarMutexGuard aSolarGuard;
 
-    VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xWindow);
-    if ( ! pWindow)
-        return;
-
-    bool bSystemWindow = pWindow->IsSystemWindow();
-    bool bWorkWindow   = (pWindow->GetType() == WindowType::WORKWINDOW);
-    if (!bSystemWindow && !bWorkWindow)
+    if (m_xWindow->isDisposed())
         return;
 
     if (bModified)
-        pWindow->SetExtendedStyle(WindowExtendedStyle::DocModified);
+        m_xWindow->SetExtendedStyle(WindowExtendedStyle::DocModified);
     else
-        pWindow->SetExtendedStyle(WindowExtendedStyle::NONE);
+        m_xWindow->SetExtendedStyle(WindowExtendedStyle::NONE);
     // <- SYNCHRONIZED
 }
 
@@ -104,43 +82,26 @@ void SAL_CALL TagWindowAsModified::frameAction(const css::frame::FrameActionEven
        )
         return;
 
-    css::uno::Reference< css::frame::XFrame > xFrame;
-    {
-        SolarMutexGuard g;
-        xFrame.set(m_xFrame.get(), css::uno::UNO_QUERY);
-        if (
-            ( ! xFrame.is ()        ) ||
-            (aEvent.Source != xFrame)
-        )
-            return;
-    }
+    if ( aEvent.Source != m_xFrame )
+        return;
 
-    impl_update (xFrame);
+    impl_update (m_xFrame);
 }
 
 void SAL_CALL TagWindowAsModified::disposing(const css::lang::EventObject& aEvent)
 {
     SolarMutexGuard g;
 
-    css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
-    if (xFrame.is())
-        xFrame->addFrameActionListener(this);
-
-    if (
-        (xFrame.is ()           ) &&
-        (aEvent.Source == xFrame)
-       )
+    if (m_xFrame && aEvent.Source == m_xFrame)
     {
+        m_xFrame->removeFrameActionListener(this);
         m_xFrame.clear();
         return;
     }
 
-    css::uno::Reference< css::frame::XModel > xModel(m_xModel.get(), css::uno::UNO_QUERY);
-    if (
-        (xModel.is ()           ) &&
-        (aEvent.Source == xModel)
-       )
+    if (m_xModel && aEvent.Source == m_xModel)
     {
+        m_xModel->removeModifyListener(this);
         m_xModel.clear();
         return;
     }
@@ -148,32 +109,37 @@ void SAL_CALL TagWindowAsModified::disposing(const css::lang::EventObject& aEven
 
 void TagWindowAsModified::impl_update (const css::uno::Reference< css::frame::XFrame >& xFrame)
 {
-    if ( ! xFrame.is ())
+    if (!xFrame)
         return;
 
     css::uno::Reference< css::awt::XWindow >       xWindow     = xFrame->getContainerWindow ();
     css::uno::Reference< css::frame::XController > xController = xFrame->getController ();
-    css::uno::Reference< css::frame::XModel >      xModel;
+    css::uno::Reference< css::util::XModifiable >  xModel;
     if (xController.is ())
-        xModel = xController->getModel ();
+        xModel = css::uno::Reference< css::util::XModifiable >(xController->getModel(), css::uno::UNO_QUERY);
 
-    if (
-        ( ! xWindow.is ()) ||
-        ( ! xModel.is  ())
-       )
+    if (!xWindow || !xModel)
         return;
 
     {
         SolarMutexGuard g;
+
+        VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xWindow);
+        bool bSystemWindow = pWindow->IsSystemWindow();
+        bool bWorkWindow   = (pWindow->GetType() == WindowType::WORKWINDOW);
+        if (!bSystemWindow && !bWorkWindow)
+            return;
+
+        if (m_xModel)
+            m_xModel->removeModifyListener (this);
+
         // Note: frame was set as member outside ! we have to refresh connections
         // regarding window and model only here.
-        m_xWindow = xWindow;
+        m_xWindow = pWindow;
         m_xModel  = xModel;
     }
 
-    css::uno::Reference< css::util::XModifyBroadcaster > xModifiable(xModel, css::uno::UNO_QUERY);
-    if (xModifiable.is ())
-        xModifiable->addModifyListener (this);
+    m_xModel->addModifyListener (this);
 }
 
 } // namespace framework


More information about the Libreoffice-commits mailing list