diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2015-12-04 16:28:27 +0100 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2015-12-07 11:29:42 +0000 |
commit | c5fe98905deac6de4f9e76a17097ce83fe381ac3 (patch) | |
tree | 06fd82303f00a8e64e0498c817944b98fc2ec36d | |
parent | ebe80ac6713b67b1801ede3d1e9038cb2c93cb11 (diff) |
Make buttonstatuslistener a generic listener for any widgets
Change-Id: I966b06e1169f8a06d08be811f78e98a2e3d7580c
Reviewed-on: https://gerrit.libreoffice.org/20401
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
-rw-r--r-- | include/vcl/button.hxx | 4 | ||||
-rw-r--r-- | include/vcl/buttonstatuslistener.hxx | 45 | ||||
-rw-r--r-- | include/vcl/vclstatuslistener.hxx (renamed from vcl/source/control/buttonstatuslistener.cxx) | 52 | ||||
-rw-r--r-- | vcl/Library_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/source/control/button.cxx | 12 |
5 files changed, 51 insertions, 63 deletions
diff --git a/include/vcl/button.hxx b/include/vcl/button.hxx index 93d5b99e8b03..81c79a2b1de8 100644 --- a/include/vcl/button.hxx +++ b/include/vcl/button.hxx @@ -94,7 +94,7 @@ public: virtual bool set_property(const OString &rKey, const OString &rValue) override; /// Sets the button state according to the FeatureStateEvent emitted by an Uno state change. - virtual void SetStateUno(const css::frame::FeatureStateEvent& rEvent); + void statusChanged(const css::frame::FeatureStateEvent& rEvent); protected: @@ -187,7 +187,7 @@ public: void SetState( TriState eState ); TriState GetState() const { return meState; } - virtual void SetStateUno(const css::frame::FeatureStateEvent& rEvent) override; + void statusChanged(const css::frame::FeatureStateEvent& rEvent); void Check( bool bCheck = true ); bool IsChecked() const; diff --git a/include/vcl/buttonstatuslistener.hxx b/include/vcl/buttonstatuslistener.hxx deleted file mode 100644 index 772189591114..000000000000 --- a/include/vcl/buttonstatuslistener.hxx +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#ifndef INCLUDED_VCL_BUTTONSTATUSLISTENER_HXX -#define INCLUDED_VCL_BUTTONSTATUSLISTENER_HXX - -#include <cppuhelper/implbase.hxx> -#include <vcl/button.hxx> - -#include <com/sun/star/util/URL.hpp> -#include <com/sun/star/frame/XStatusListener.hpp> -#include <com/sun/star/frame/XDispatch.hpp> - - -class VCL_DLLPUBLIC ButtonStatusListener : public cppu::WeakImplHelper < css::frame::XStatusListener> -{ -public: - ButtonStatusListener(Button* button, const rtl::OUString& aCommand); - -private: - VclPtr<Button> mButton; /** The button on which actions are performed */ - - /** Dispatcher. Need to keep a reference to it as long as this StatusListener exists. */ - css::uno::Reference<css::frame::XDispatch> mxDispatch; - css::util::URL maCommandURL; - -public: - virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& rEvent) - throw(css::uno::RuntimeException, std::exception) override; - - virtual void SAL_CALL disposing(const css::lang::EventObject& /*Source*/) - throw( css::uno::RuntimeException, std::exception ) override; - - void dispose(); -}; - -#endif // INCLUDED_VCL_BUTTONSTATUSLISTENER_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file diff --git a/vcl/source/control/buttonstatuslistener.cxx b/include/vcl/vclstatuslistener.hxx index bad5452daacf..186d4491406d 100644 --- a/vcl/source/control/buttonstatuslistener.cxx +++ b/include/vcl/vclstatuslistener.hxx @@ -7,18 +7,46 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <vcl/buttonstatuslistener.hxx> +#ifndef INCLUDED_VCL_VCLSTATUSLISTENER_HXX +#define INCLUDED_VCL_VCLSTATUSLISTENER_HXX + +#include <cppuhelper/implbase.hxx> #include <comphelper/processfactory.hxx> +#include <vcl/dllapi.h> +#include <vcl/vclptr.hxx> #include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/frame/XStatusListener.hpp> #include <com/sun/star/frame/XDispatch.hpp> #include <com/sun/star/frame/XDispatchProvider.hpp> -#include <com/sun/star/frame/XStatusListener.hpp> #include <com/sun/star/util/URL.hpp> #include <com/sun/star/util/URLTransformer.hpp> -ButtonStatusListener::ButtonStatusListener(Button* button, const rtl::OUString& aCommand) { - mButton = button; +template <class T> class VCL_DLLPUBLIC VclStatusListener : public cppu::WeakImplHelper < css::frame::XStatusListener> +{ +public: + VclStatusListener<T>(T* widget, const rtl::OUString& aCommand); + +private: + VclPtr<T> mWidget; /** The widget on which actions are performed */ + + /** Dispatcher. Need to keep a reference to it as long as this StatusListener exists. */ + css::uno::Reference<css::frame::XDispatch> mxDispatch; + css::util::URL maCommandURL; + +public: + void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& rEvent) + throw(css::uno::RuntimeException, std::exception) override; + + void SAL_CALL disposing(const css::lang::EventObject& /*Source*/) + throw( css::uno::RuntimeException, std::exception ) override; + + void dispose(); +}; + +template<class T> +VclStatusListener<T>::VclStatusListener(T* widget, const rtl::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); @@ -42,25 +70,31 @@ ButtonStatusListener::ButtonStatusListener(Button* button, const rtl::OUString& mxDispatch->addStatusListener(this, maCommandURL); } -void ButtonStatusListener::statusChanged(const css::frame::FeatureStateEvent& rEvent) +template<class T> +void VclStatusListener<T>::statusChanged(const css::frame::FeatureStateEvent& rEvent) throw(css::uno::RuntimeException, std::exception) { - mButton->SetStateUno(rEvent); + mWidget->statusChanged(rEvent); } -void ButtonStatusListener::disposing(const css::lang::EventObject& /*Source*/) +template<class T> +void VclStatusListener<T>::disposing(const css::lang::EventObject& /*Source*/) throw( css::uno::RuntimeException, std::exception ) { mxDispatch.clear(); } -void ButtonStatusListener::dispose() +template<class T> +void VclStatusListener<T>::dispose() { if (mxDispatch.is()) { mxDispatch->removeStatusListener(this, maCommandURL); mxDispatch.clear(); } - mButton.clear(); + mWidget.clear(); } + +#endif // INCLUDED_VCL_VCLSTATUSLISTENER_HXX + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 8e55cdcdbf11..87570d64916d 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -205,7 +205,6 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/window/winproc \ vcl/source/window/wrkwin \ vcl/source/control/button \ - vcl/source/control/buttonstatuslistener \ vcl/source/control/combobox \ vcl/source/control/ctrl \ vcl/source/control/edit \ diff --git a/vcl/source/control/button.cxx b/vcl/source/control/button.cxx index b3390a37cf19..d831794b0c54 100644 --- a/vcl/source/control/button.cxx +++ b/vcl/source/control/button.cxx @@ -32,10 +32,10 @@ #include <vcl/dialog.hxx> #include <vcl/fixed.hxx> #include <vcl/button.hxx> -#include <vcl/buttonstatuslistener.hxx> #include <vcl/salnativewidgets.hxx> #include <vcl/edit.hxx> #include <vcl/layout.hxx> +#include <vcl/vclstatuslistener.hxx> #include <svids.hrc> #include <svdata.hxx> @@ -82,7 +82,7 @@ public: SymbolAlign meSymbolAlign; /** StatusListener. Updates the button as the slot state changes */ - rtl::Reference<ButtonStatusListener> mpStatusListener; + rtl::Reference<VclStatusListener<Button>> mpStatusListener; }; ImplCommonButtonData::ImplCommonButtonData() : maFocusRect(), mnSeparatorX(0), mnButtonState(DrawButtonFlags::NONE), @@ -117,7 +117,7 @@ void Button::SetCommandHandler(const OUString& aCommand) maCommand = aCommand; SetClickHdl( LINK( this, Button, dispatchCommandHandler) ); - mpButtonData->mpStatusListener = new ButtonStatusListener(this, aCommand); + mpButtonData->mpStatusListener = new VclStatusListener<Button>(this, aCommand); } void Button::Click() @@ -617,7 +617,7 @@ bool Button::set_property(const OString &rKey, const OString &rValue) return true; } -void Button::SetStateUno(const css::frame::FeatureStateEvent& rEvent) +void Button::statusChanged(const css::frame::FeatureStateEvent& rEvent) { Enable(rEvent.IsEnabled); } @@ -1606,9 +1606,9 @@ void PushButton::SetState( TriState eState ) } } -void PushButton::SetStateUno(const css::frame::FeatureStateEvent& rEvent) +void PushButton::statusChanged(const css::frame::FeatureStateEvent& rEvent) { - Button::SetStateUno(rEvent); + Button::statusChanged(rEvent); if (rEvent.State.has<bool>()) SetPressed(rEvent.State.get<bool>()); } |