svx/source/inc/StylesPreviewToolBoxControl.hxx      |    2 -
 svx/source/inc/StylesPreviewWindow.hxx              |   15 ++++++------
 svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx |    7 -----
 svx/source/tbxctrls/StylesPreviewWindow.cxx         |   24 +++++++++++++-------
 4 files changed, 25 insertions(+), 23 deletions(-)

New commits:
commit 42ee261d01983c94d8be60fccae37ae5af53bf5e
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Thu Jul 6 16:29:02 2023 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Wed Jul 12 02:21:48 2023 +0200

    tdf#125504 StylesPreviewWindow: don't use disposed DispatchProvider
    
    .uno:StylesPreview in the notebookbar was doing nothing
    because the view switching from print preview caused
    the saved XDispatchProvider to become disposed.
    
    Thanks to Maxim, my patch is completely re-written.
    I think I have implemented the method he has suggested.
    
    Change-Id: Iae01116c742bc27ed2c14d983e7347d39c9acaf6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154148
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>
    Reviewed-by: Maxim Monastirsky <momonas...@gmail.com>

diff --git a/svx/source/inc/StylesPreviewToolBoxControl.hxx 
b/svx/source/inc/StylesPreviewToolBoxControl.hxx
index d8d12a0f20a8..f1f943dfffbe 100644
--- a/svx/source/inc/StylesPreviewToolBoxControl.hxx
+++ b/svx/source/inc/StylesPreviewToolBoxControl.hxx
@@ -32,8 +32,6 @@ class StylesPreviewToolBoxControl final
     VclPtr<StylesPreviewWindow_Impl> m_xVclBox;
     std::unique_ptr<StylesPreviewWindow_Base> m_xWeldBox;
 
-    css::uno::Reference<css::frame::XDispatchProvider> m_xDispatchProvider;
-
     std::vector<std::pair<OUString, OUString>> m_aDefaultStyles;
 
 public:
diff --git a/svx/source/inc/StylesPreviewWindow.hxx 
b/svx/source/inc/StylesPreviewWindow.hxx
index 1e9b01a6df1b..76b385c084d2 100644
--- a/svx/source/inc/StylesPreviewWindow.hxx
+++ b/svx/source/inc/StylesPreviewWindow.hxx
@@ -23,6 +23,7 @@
 #include <vcl/InterimItemWindow.hxx>
 #include <svl/style.hxx>
 #include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
 #include <sfx2/sfxstatuslistener.hxx>
 
 class StylesPreviewWindow_Base;
@@ -95,7 +96,7 @@ class StylesPreviewWindow_Base
 protected:
     static constexpr unsigned STYLES_COUNT = 6;
 
-    css::uno::Reference<css::frame::XDispatchProvider> m_xDispatchProvider;
+    css::uno::Reference<css::frame::XFrame> m_xFrame;
 
     std::unique_ptr<weld::IconView> m_xStylesView;
 
@@ -115,9 +116,9 @@ protected:
     DECL_LINK(DoJsonProperty, const weld::json_prop_query&, bool);
 
 public:
-    StylesPreviewWindow_Base(
-        weld::Builder& xBuilder, std::vector<std::pair<OUString, OUString>>&& 
aDefaultStyles,
-        const css::uno::Reference<css::frame::XDispatchProvider>& 
xDispatchProvider);
+    StylesPreviewWindow_Base(weld::Builder& xBuilder,
+                             std::vector<std::pair<OUString, OUString>>&& 
aDefaultStyles,
+                             const css::uno::Reference<css::frame::XFrame>& 
xFrame);
     ~StylesPreviewWindow_Base();
 
     void Select(const OUString& rStyleName);
@@ -134,9 +135,9 @@ private:
 class StylesPreviewWindow_Impl final : public InterimItemWindow, public 
StylesPreviewWindow_Base
 {
 public:
-    StylesPreviewWindow_Impl(
-        vcl::Window* pParent, std::vector<std::pair<OUString, OUString>>&& 
aDefaultStyles,
-        const css::uno::Reference<css::frame::XDispatchProvider>& 
xDispatchProvider);
+    StylesPreviewWindow_Impl(vcl::Window* pParent,
+                             std::vector<std::pair<OUString, OUString>>&& 
aDefaultStyles,
+                             const css::uno::Reference<css::frame::XFrame>& 
xFrame);
     ~StylesPreviewWindow_Impl();
 
     void dispose();
diff --git a/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx 
b/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx
index 64e6ed7822fe..d26063d5447e 100644
--- a/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx
+++ b/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx
@@ -35,12 +35,7 @@ StylesPreviewToolBoxControl::initialize(const 
css::uno::Sequence<css::uno::Any>&
     svt::ToolboxController::initialize(rArguments);
 
     if (m_xFrame.is())
-    {
         InitializeStyles(m_xFrame->getController()->getModel());
-
-        m_xDispatchProvider = 
css::uno::Reference<css::frame::XDispatchProvider>(
-            m_xFrame->getController(), css::uno::UNO_QUERY);
-    }
 }
 
 void SAL_CALL StylesPreviewToolBoxControl::dispose()
@@ -156,7 +151,7 @@ StylesPreviewToolBoxControl::createItemWindow(const 
css::uno::Reference<css::awt
             SolarMutexGuard aSolarMutexGuard;
 
             m_xVclBox = VclPtr<StylesPreviewWindow_Impl>::Create(
-                pParent, std::vector(m_aDefaultStyles), m_xDispatchProvider);
+                pParent, std::vector(m_aDefaultStyles), m_xFrame);
             xItemWindow = VCLUnoHelper::GetInterface(m_xVclBox);
         }
     }
diff --git a/svx/source/tbxctrls/StylesPreviewWindow.cxx 
b/svx/source/tbxctrls/StylesPreviewWindow.cxx
index c5215cba4a6d..27e992c92059 100644
--- a/svx/source/tbxctrls/StylesPreviewWindow.cxx
+++ b/svx/source/tbxctrls/StylesPreviewWindow.cxx
@@ -208,7 +208,9 @@ bool StylesPreviewWindow_Base::Command(const CommandEvent& 
rEvent)
     {
         css::uno::Sequence<css::beans::PropertyValue> aArgs(0);
 
-        SfxToolBoxControl::Dispatch(m_xDispatchProvider,
+        const css::uno::Reference<css::frame::XDispatchProvider> 
xProvider(m_xFrame,
+                                                                           
css::uno::UNO_QUERY);
+        SfxToolBoxControl::Dispatch(xProvider,
                                     rIdent == "update" ? 
OUString(".uno:StyleUpdateByExample")
                                                        : 
OUString(".uno:EditStyle"),
                                     aArgs);
@@ -442,8 +444,8 @@ void StyleItemController::DrawText(vcl::RenderContext& 
rRenderContext)
 
 StylesPreviewWindow_Base::StylesPreviewWindow_Base(
     weld::Builder& xBuilder, std::vector<std::pair<OUString, OUString>>&& 
aDefaultStyles,
-    const css::uno::Reference<css::frame::XDispatchProvider>& 
xDispatchProvider)
-    : m_xDispatchProvider(xDispatchProvider)
+    const css::uno::Reference<css::frame::XFrame>& xFrame)
+    : m_xFrame(xFrame)
     , m_xStylesView(xBuilder.weld_icon_view("stylesview"))
     , m_aUpdateTask(*this)
     , m_aDefaultStyles(std::move(aDefaultStyles))
@@ -456,7 +458,9 @@ StylesPreviewWindow_Base::StylesPreviewWindow_Base(
     m_xStylesView->connect_get_property_tree_elem(
         LINK(this, StylesPreviewWindow_Base, DoJsonProperty));
 
-    m_xStatusListener = new StyleStatusListener(this, xDispatchProvider);
+    const css::uno::Reference<css::frame::XDispatchProvider> 
xProvider(m_xFrame,
+                                                                       
css::uno::UNO_QUERY);
+    m_xStatusListener = new StyleStatusListener(this, xProvider);
 
     m_pStylePoolChangeListener.reset(new StylePoolChangeListener(this));
 
@@ -471,7 +475,9 @@ IMPL_LINK(StylesPreviewWindow_Base, Selected, 
weld::IconView&, rIconView, void)
         comphelper::makePropertyValue("Template", sStyleName),
         comphelper::makePropertyValue("Family", 
sal_Int16(SfxStyleFamily::Para))
     };
-    SfxToolBoxControl::Dispatch(m_xDispatchProvider, ".uno:StyleApply", aArgs);
+    const css::uno::Reference<css::frame::XDispatchProvider> 
xProvider(m_xFrame,
+                                                                       
css::uno::UNO_QUERY);
+    SfxToolBoxControl::Dispatch(xProvider, ".uno:StyleApply", aArgs);
 }
 
 IMPL_LINK(StylesPreviewWindow_Base, DoubleClick, weld::IconView&, rIconView, 
bool)
@@ -482,7 +488,9 @@ IMPL_LINK(StylesPreviewWindow_Base, DoubleClick, 
weld::IconView&, rIconView, boo
         comphelper::makePropertyValue("Param", sStyleName),
         comphelper::makePropertyValue("Family", 
sal_Int16(SfxStyleFamily::Para))
     };
-    SfxToolBoxControl::Dispatch(m_xDispatchProvider, ".uno:EditStyle", aArgs);
+    const css::uno::Reference<css::frame::XDispatchProvider> 
xProvider(m_xFrame,
+                                                                       
css::uno::UNO_QUERY);
+    SfxToolBoxControl::Dispatch(xProvider, ".uno:EditStyle", aArgs);
 
     return true;
 }
@@ -651,10 +659,10 @@ void StylesPreviewWindow_Base::UpdateStylesList()
 
 StylesPreviewWindow_Impl::StylesPreviewWindow_Impl(
     vcl::Window* pParent, std::vector<std::pair<OUString, OUString>>&& 
aDefaultStyles,
-    const css::uno::Reference<css::frame::XDispatchProvider>& 
xDispatchProvider)
+    const css::uno::Reference<css::frame::XFrame>& xFrame)
     : InterimItemWindow(pParent, "svx/ui/stylespreview.ui", "ApplyStyleBox", 
true,
                         reinterpret_cast<sal_uInt64>(SfxViewShell::Current()))
-    , StylesPreviewWindow_Base(*m_xBuilder, std::move(aDefaultStyles), 
xDispatchProvider)
+    , StylesPreviewWindow_Base(*m_xBuilder, std::move(aDefaultStyles), xFrame)
 {
     SetOptimalSize();
 }

Reply via email to