diff options
author | Jan Holesovsky <kendy@collabora.com> | 2014-09-24 09:06:18 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2014-09-24 09:13:08 +0200 |
commit | 0a56da5b110d6a3329ed7ebf296856f839e9980c (patch) | |
tree | ea7645d507624c85653038f5b2d7b721335e806e /vcl | |
parent | 0bcd32da2efd287bbab51e335b382ec27e023644 (diff) |
vcl button: Allow automatic handling of UNO commands (like .uno:Something).
Change-Id: I71c00286dde2e5a01a7a592305c1790f1ed63a93
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/control/button.cxx | 51 | ||||
-rw-r--r-- | vcl/source/window/builder.cxx | 2 |
2 files changed, 53 insertions, 0 deletions
diff --git a/vcl/source/control/button.cxx b/vcl/source/control/button.cxx index cef9d0dce18d..1ee4014fb6fc 100644 --- a/vcl/source/control/button.cxx +++ b/vcl/source/control/button.cxx @@ -41,6 +41,16 @@ #include <window.h> #include <controldata.hxx> +#include <comphelper/processfactory.hxx> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/frame/XDispatch.hpp> +#include <com/sun/star/frame/XDispatchProvider.hpp> +#include <com/sun/star/util/URL.hpp> +#include <com/sun/star/util/URLTransformer.hpp> + +using namespace css; + #define PUSHBUTTON_VIEW_STYLE (WB_3DLOOK | \ WB_LEFT | WB_CENTER | WB_RIGHT | \ WB_TOP | WB_VCENTER | WB_BOTTOM | \ @@ -94,6 +104,12 @@ Button::~Button() delete mpButtonData; } +void Button::SetCommandHandler(const OUString& aCommand) +{ + maCommand = aCommand; + SetClickHdl(Link(NULL, dispatchCommandHandler)); +} + void Button::Click() { ImplCallEventListenersAndHandler( VCLEVENT_BUTTON_CLICK, maClickHdl, this ); @@ -583,6 +599,41 @@ bool Button::set_property(const OString &rKey, const OString &rValue) return true; } +long Button::dispatchCommandHandler(void *, void *pCaller) +{ + const Button *pButton = reinterpret_cast<Button*>(pCaller); + if (pButton == NULL) + return 0; + + // Target where we will execute the .uno: command + uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext(); + uno::Reference<frame::XDesktop2> xDesktop = frame::Desktop::create(xContext); + + uno::Reference<frame::XFrame> xFrame(xDesktop->getActiveFrame()); + if (!xFrame.is()) + xFrame = uno::Reference<frame::XFrame>(xDesktop, uno::UNO_QUERY); + + uno::Reference<frame::XDispatchProvider> xDispatchProvider(xFrame, uno::UNO_QUERY); + if (!xDispatchProvider.is()) + return 0; + + util::URL aCommandURL; + aCommandURL.Complete = pButton->maCommand; + uno::Reference<util::XURLTransformer> xParser = util::URLTransformer::create(xContext); + xParser->parseStrict(aCommandURL); + + uno::Reference<frame::XDispatch> xDisp = xDispatchProvider->queryDispatch(aCommandURL, OUString(), 0); + if (!xDisp.is()) + return 0; + + // And do the work... + xDisp->dispatch(aCommandURL, uno::Sequence<beans::PropertyValue>()); + + return 1; +} + + + void PushButton::ImplInitPushButtonData() { mpWindowImpl->mbPushButton = true; diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index e0c71e923530..a66ad77bbe36 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -833,6 +833,8 @@ namespace Image aImage(VclBuilder::getCommandImage(aCommand, /* bLarge = */ false, xContext, rFrame, aModuleId)); pButton->SetModeImage(aImage); + + pButton->SetCommandHandler(aCommand); } Button* extractStockAndBuildPushButton(vcl::Window *pParent, VclBuilder::stringmap &rMap) |