[Libreoffice-commits] core.git: include/vcl vcl/Library_vcl.mk vcl/source
Samuel Mehrbrodt
Samuel.Mehrbrodt at cib.de
Mon Dec 7 03:30:05 PST 2015
include/vcl/button.hxx | 4 -
include/vcl/buttonstatuslistener.hxx | 45 ------------
include/vcl/vclstatuslistener.hxx | 100 ++++++++++++++++++++++++++++
vcl/Library_vcl.mk | 1
vcl/source/control/button.cxx | 12 +--
vcl/source/control/buttonstatuslistener.cxx | 66 ------------------
6 files changed, 108 insertions(+), 120 deletions(-)
New commits:
commit c5fe98905deac6de4f9e76a17097ce83fe381ac3
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date: Fri Dec 4 16:28:27 2015 +0100
Make buttonstatuslistener a generic listener for any widgets
Change-Id: I966b06e1169f8a06d08be811f78e98a2e3d7580c
Reviewed-on: https://gerrit.libreoffice.org/20401
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
diff --git a/include/vcl/button.hxx b/include/vcl/button.hxx
index 93d5b99..81c79a2 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 7721895..0000000
--- 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
similarity index 56%
rename from vcl/source/control/buttonstatuslistener.cxx
rename to include/vcl/vclstatuslistener.hxx
index bad5452..186d449 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 8e55cdc..87570d6 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 b3390a3..d831794 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>());
}
More information about the Libreoffice-commits
mailing list