From 0a56da5b110d6a3329ed7ebf296856f839e9980c Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Wed, 24 Sep 2014 09:06:18 +0200 Subject: vcl button: Allow automatic handling of UNO commands (like .uno:Something). Change-Id: I71c00286dde2e5a01a7a592305c1790f1ed63a93 --- vcl/source/control/button.cxx | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'vcl/source/control') 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 #include +#include + +#include +#include +#include +#include +#include + +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(pCaller); + if (pButton == NULL) + return 0; + + // Target where we will execute the .uno: command + uno::Reference xContext = ::comphelper::getProcessComponentContext(); + uno::Reference xDesktop = frame::Desktop::create(xContext); + + uno::Reference xFrame(xDesktop->getActiveFrame()); + if (!xFrame.is()) + xFrame = uno::Reference(xDesktop, uno::UNO_QUERY); + + uno::Reference xDispatchProvider(xFrame, uno::UNO_QUERY); + if (!xDispatchProvider.is()) + return 0; + + util::URL aCommandURL; + aCommandURL.Complete = pButton->maCommand; + uno::Reference xParser = util::URLTransformer::create(xContext); + xParser->parseStrict(aCommandURL); + + uno::Reference xDisp = xDispatchProvider->queryDispatch(aCommandURL, OUString(), 0); + if (!xDisp.is()) + return 0; + + // And do the work... + xDisp->dispatch(aCommandURL, uno::Sequence()); + + return 1; +} + + + void PushButton::ImplInitPushButtonData() { mpWindowImpl->mbPushButton = true; -- cgit