summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Monastirsky <momonasmon@gmail.com>2017-02-19 15:15:54 +0200
committerMaxim Monastirsky <momonasmon@gmail.com>2017-02-21 01:40:29 +0200
commit5ccea065247dffe1c29923619b39d63b2e1c5911 (patch)
tree886bb47564ffcc1c2d8780c4dd26828e01f10add
parentb6994cb75fb7e34574d933dff58fcec3bb1ab922 (diff)
VclStatusListener: Listener needs to be acquire'd first
because as soon as we're wrapped somewhere with a temp. uno/rtl::Reference, its destruction will lead to our own destruction while we're still in ctor. Typical situation is when the broadcaster rejects our listening request. Change-Id: I7fd282e53095ab9939f803df9564c9767263b1f8
-rw-r--r--include/vcl/vclstatuslistener.hxx21
-rw-r--r--vcl/source/control/button.cxx1
-rw-r--r--vcl/source/window/toolbox.cxx1
3 files changed, 16 insertions, 7 deletions
diff --git a/include/vcl/vclstatuslistener.hxx b/include/vcl/vclstatuslistener.hxx
index c18d2acbed14..42894dd5e98b 100644
--- a/include/vcl/vclstatuslistener.hxx
+++ b/include/vcl/vclstatuslistener.hxx
@@ -41,6 +41,8 @@ public:
const css::uno::Reference<css::frame::XFrame>& getFrame() { return mxFrame; }
+ void startListening();
+
void dispose();
};
@@ -57,19 +59,24 @@ VclStatusListener<T>::VclStatusListener(T* widget, const rtl::OUString& aCommand
mxFrame = xFrame;
- css::uno::Reference<css::frame::XDispatchProvider> xDispatchProvider(xFrame, css::uno::UNO_QUERY);
- if (!xDispatchProvider.is())
- return;
-
maCommandURL.Complete = aCommand;
css::uno::Reference<css::util::XURLTransformer> xParser = css::util::URLTransformer::create(xContext);
xParser->parseStrict(maCommandURL);
+}
- mxDispatch = xDispatchProvider->queryDispatch(maCommandURL, "", 0);
- if (!mxDispatch.is())
+template<class T>
+void VclStatusListener<T>::startListening()
+{
+ if (mxDispatch.is())
+ mxDispatch->removeStatusListener(this, maCommandURL);
+
+ css::uno::Reference<css::frame::XDispatchProvider> xDispatchProvider(mxFrame, css::uno::UNO_QUERY);
+ if (!xDispatchProvider.is())
return;
- mxDispatch->addStatusListener(this, maCommandURL);
+ mxDispatch = xDispatchProvider->queryDispatch(maCommandURL, "", 0);
+ if (mxDispatch.is())
+ mxDispatch->addStatusListener(this, maCommandURL);
}
template<class T>
diff --git a/vcl/source/control/button.cxx b/vcl/source/control/button.cxx
index e565639c7763..e94df630f4db 100644
--- a/vcl/source/control/button.cxx
+++ b/vcl/source/control/button.cxx
@@ -115,6 +115,7 @@ void Button::SetCommandHandler(const OUString& aCommand)
SetClickHdl( LINK( this, Button, dispatchCommandHandler) );
mpButtonData->mpStatusListener = new VclStatusListener<Button>(this, aCommand);
+ mpButtonData->mpStatusListener->startListening();
}
void Button::Click()
diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx
index dfee6f2a5265..549074890b50 100644
--- a/vcl/source/window/toolbox.cxx
+++ b/vcl/source/window/toolbox.cxx
@@ -1401,6 +1401,7 @@ void ToolBox::ImplInitToolBoxData()
mnActivateCount = 0;
mnImagesRotationAngle = 0;
mpStatusListener = new VclStatusListener<ToolBox>(this, ".uno:ImageOrientation");
+ mpStatusListener->startListening();
mpIdle = new Idle("vcl::ToolBox maIdle update");
mpIdle->SetPriority( TaskPriority::RESIZE );