include/vcl/weld.hxx | 10 ++++++++++ vcl/source/app/salvtables.cxx | 32 ++++++++++++++++++++++++++++++++ vcl/unx/gtk3/gtk3gtkinst.cxx | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+)
New commits: commit a541c989f07fd7cf908915a9f005d32aca6cd953 Author: Caolán McNamara <caol...@redhat.com> Date: Fri Mar 23 09:41:42 2018 +0000 hook up focus events Change-Id: I9f5835e86550bd3d728936e5525262697e01e5fc Reviewed-on: https://gerrit.libreoffice.org/51786 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index 0cdf21d06ed4..d6234273b703 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -24,6 +24,13 @@ class DialogController; class VCL_DLLPUBLIC Widget { +protected: + Link<Widget&, void> m_aFocusInHdl; + Link<Widget&, void> m_aFocusOutHdl; + + void signal_focus_in() { return m_aFocusInHdl.Call(*this); } + void signal_focus_out() { return m_aFocusOutHdl.Call(*this); } + public: virtual void set_sensitive(bool sensitive) = 0; virtual bool get_sensitive() const = 0; @@ -59,6 +66,9 @@ public: virtual void set_accessible_name(const OUString& rName) = 0; + virtual void connect_focus_in(const Link<Widget&, void>& rLink) = 0; + virtual void connect_focus_out(const Link<Widget&, void>& rLink) = 0; + virtual Container* weld_parent() const = 0; virtual ~Widget() {} diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 47e0037c81c9..9cfe42eb9376 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -179,6 +179,10 @@ class SalInstanceWidget : public virtual weld::Widget { private: VclPtr<vcl::Window> m_xWidget; + + DECL_LINK(FocusInHdl, Control&, void); + DECL_LINK(FocusOutHdl, Control&, void); + bool m_bTakeOwnership; public: @@ -305,10 +309,28 @@ public: m_xWidget->SetAccessibleName(rName); } + virtual void connect_focus_in(const Link<Widget&, void>& rLink) override + { + assert(!m_aFocusInHdl.IsSet()); + dynamic_cast<Control&>(*m_xWidget).SetGetFocusHdl(LINK(this, SalInstanceWidget, FocusInHdl)); + m_aFocusInHdl = rLink; + } + + virtual void connect_focus_out(const Link<Widget&, void>& rLink) override + { + assert(!m_aFocusOutHdl.IsSet()); + dynamic_cast<Control&>(*m_xWidget).SetLoseFocusHdl(LINK(this, SalInstanceWidget, FocusOutHdl)); + m_aFocusOutHdl = rLink; + } + virtual weld::Container* weld_parent() const override; virtual ~SalInstanceWidget() override { + if (m_aFocusInHdl.IsSet()) + dynamic_cast<Control&>(*m_xWidget).SetGetFocusHdl(Link<Control&,void>()); + if (m_aFocusOutHdl.IsSet()) + dynamic_cast<Control&>(*m_xWidget).SetLoseFocusHdl(Link<Control&,void>()); if (m_bTakeOwnership) m_xWidget.disposeAndClear(); } @@ -324,6 +346,16 @@ public: } }; +IMPL_LINK_NOARG(SalInstanceWidget, FocusInHdl, Control&, void) +{ + signal_focus_in(); +} + +IMPL_LINK_NOARG(SalInstanceWidget, FocusOutHdl, Control&, void) +{ + signal_focus_out(); +} + class SalInstanceContainer : public SalInstanceWidget, public virtual weld::Container { private: diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 6d1c3eebb7e9..947d1cc2f1da 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -1178,11 +1178,27 @@ protected: GtkWidget* m_pWidget; private: bool m_bTakeOwnership; + gulong m_nFocusInSignalId; + gulong m_nFocusOutSignalId; + + static void signalFocusIn(GtkWidget*, GdkEvent*, gpointer widget) + { + GtkInstanceWidget* pThis = static_cast<GtkInstanceWidget*>(widget); + pThis->signal_focus_in(); + } + + static void signalFocusOut(GtkWidget*, GdkEvent*, gpointer widget) + { + GtkInstanceWidget* pThis = static_cast<GtkInstanceWidget*>(widget); + pThis->signal_focus_out(); + } public: GtkInstanceWidget(GtkWidget* pWidget, bool bTakeOwnership) : m_pWidget(pWidget) , m_bTakeOwnership(bTakeOwnership) + , m_nFocusInSignalId(0) + , m_nFocusOutSignalId(0) { } @@ -1348,8 +1364,26 @@ public: return GTK_WINDOW(gtk_widget_get_toplevel(m_pWidget)); } + virtual void connect_focus_in(const Link<Widget&, void>& rLink) override + { + assert(!m_aFocusInHdl.IsSet()); + m_nFocusInSignalId = g_signal_connect(m_pWidget, "focus-in-event", G_CALLBACK(signalFocusIn), this); + m_aFocusInHdl = rLink; + } + + virtual void connect_focus_out(const Link<Widget&, void>& rLink) override + { + assert(!m_aFocusOutHdl.IsSet()); + m_nFocusOutSignalId = g_signal_connect(m_pWidget, "focus-out-event", G_CALLBACK(signalFocusOut), this); + m_aFocusOutHdl = rLink; + } + virtual ~GtkInstanceWidget() override { + if (m_nFocusInSignalId) + g_signal_handler_disconnect(m_pWidget, m_nFocusInSignalId); + if (m_nFocusOutSignalId) + g_signal_handler_disconnect(m_pWidget, m_nFocusOutSignalId); if (m_bTakeOwnership) gtk_widget_destroy(m_pWidget); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits