diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-03-23 09:41:42 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-03-24 16:07:57 +0100 |
commit | a541c989f07fd7cf908915a9f005d32aca6cd953 (patch) | |
tree | 1bb548ac3976a6f18172a7fde1ae29a1862e8daa /vcl | |
parent | fe1c13d4ba288e45acdba5bc01b0ef81da08f125 (diff) |
hook up focus events
Change-Id: I9f5835e86550bd3d728936e5525262697e01e5fc
Reviewed-on: https://gerrit.libreoffice.org/51786
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/app/salvtables.cxx | 32 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 34 |
2 files changed, 66 insertions, 0 deletions
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); } |