diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-09-08 09:30:35 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-09-21 20:10:06 +0200 |
commit | af90b8089405d6f042207f5639e750f08798ae92 (patch) | |
tree | 0af8401f534cbce9a11e64c1819ef84413ddd912 /vcl | |
parent | 416c11d189a18a08c28135b8aa5e0f12cd51dcd6 (diff) |
weld infobars
note: "pushed" status listener case dropped. Doesn't seem to be an expectation
for it to something in infobars, and there doesn't seem to be a working case
anyway.
Change-Id: I7869cc05de9918f0dd70e28b0087205db6c9506c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101945
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/app/weldutils.cxx | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/vcl/source/app/weldutils.cxx b/vcl/source/app/weldutils.cxx index ee074df63d93..237645076330 100644 --- a/vcl/source/app/weldutils.cxx +++ b/vcl/source/app/weldutils.cxx @@ -7,6 +7,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <com/sun/star/util/URLTransformer.hpp> +#include <com/sun/star/frame/Desktop.hpp> +#include <comphelper/processfactory.hxx> #include <svl/zforlist.hxx> #include <svl/zformat.hxx> #include <vcl/builderpage.hxx> @@ -488,6 +491,61 @@ int GetMinimumEditHeight() std::unique_ptr<weld::Entry> xEntry(xBuilder->weld_entry("name_entry")); return xEntry->get_preferred_size().Height(); } + +WidgetStatusListener::WidgetStatusListener(weld::Widget* widget, const OUString& aCommand) + : mWidget(widget) +{ + css::uno::Reference<css::uno::XComponentContext> xContext + = ::comphelper::getProcessComponentContext(); + css::uno::Reference<css::frame::XDesktop2> xDesktop = css::frame::Desktop::create(xContext); + + css::uno::Reference<css::frame::XFrame> xFrame(xDesktop->getActiveFrame()); + if (!xFrame.is()) + xFrame = xDesktop; + + mxFrame = xFrame; + + maCommandURL.Complete = aCommand; + css::uno::Reference<css::util::XURLTransformer> xParser + = css::util::URLTransformer::create(xContext); + xParser->parseStrict(maCommandURL); +} + +void WidgetStatusListener::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 = xDispatchProvider->queryDispatch(maCommandURL, "", 0); + if (mxDispatch.is()) + mxDispatch->addStatusListener(this, maCommandURL); +} + +void WidgetStatusListener::statusChanged(const css::frame::FeatureStateEvent& rEvent) +{ + mWidget->set_sensitive(rEvent.IsEnabled); +} + +void WidgetStatusListener::disposing(const css::lang::EventObject& /*Source*/) +{ + mxDispatch.clear(); +} + +void WidgetStatusListener::dispose() +{ + if (mxDispatch.is()) + { + mxDispatch->removeStatusListener(this, maCommandURL); + mxDispatch.clear(); + } + mxFrame.clear(); + mWidget = nullptr; +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |