[gtk] eventcontrollerkey: Add getters for the properties
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk] eventcontrollerkey: Add getters for the properties
- Date: Mon, 7 Oct 2019 02:55:35 +0000 (UTC)
commit 578dc9e70bb5f4d25900ea1eb6e03c3b7e31afd6
Author: Benjamin Otte <otte redhat com>
Date: Thu Oct 3 22:13:54 2019 +0200
eventcontrollerkey: Add getters for the properties
...and use them.
docs/reference/gtk/gtk4-sections.txt | 2 ++
gtk/gtkeventcontrollerkey.c | 32 ++++++++++++++++++++++++++
gtk/gtkeventcontrollerkey.h | 10 ++++++--
gtk/gtkpopovermenu.c | 16 +++++--------
gtk/gtktreeview.c | 3 ++-
testsuite/gtk/focus.c | 44 +++++++++++++-----------------------
6 files changed, 66 insertions(+), 41 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 87948ae035..71bb48caf5 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -6729,6 +6729,8 @@ gtk_event_controller_key_forward
gtk_event_controller_key_get_group
gtk_event_controller_key_get_focus_origin
gtk_event_controller_key_get_focus_target
+gtk_event_controller_key_contains_focus
+gtk_event_controller_key_is_focus
<SUBSECTION Standard>
GTK_TYPE_EVENT_CONTROLLER_KEY
diff --git a/gtk/gtkeventcontrollerkey.c b/gtk/gtkeventcontrollerkey.c
index fd209ea1df..d11f68b441 100644
--- a/gtk/gtkeventcontrollerkey.c
+++ b/gtk/gtkeventcontrollerkey.c
@@ -596,3 +596,35 @@ gtk_event_controller_key_get_focus_target (GtkEventControllerKey *controller)
else
return (GtkWidget *)gdk_event_get_related_target (controller->current_event);
}
+
+/**
+ * gtk_event_controller_key_contains_focus:
+ * @self: a #GtkEventControllerKey
+ *
+ * Returns the value of the GtkEventControllerKey:contains-focus property.
+ *
+ * Returns: %TRUE if focus is within @self or one of its children
+ */
+gboolean
+gtk_event_controller_key_contains_focus (GtkEventControllerKey *self)
+{
+ g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_KEY (self), FALSE);
+
+ return self->contains_focus;
+}
+
+/**
+ * gtk_event_controller_key_is_focus:
+ * @self: a #GtkEventControllerKey
+ *
+ * Returns the value of the GtkEventControllerKey:is-focus property.
+ *
+ * Returns: %TRUE if focus is within @self but not one of its children
+ */
+gboolean
+gtk_event_controller_key_is_focus (GtkEventControllerKey *self)
+{
+ g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_KEY (self), FALSE);
+
+ return self->is_focus;
+}
diff --git a/gtk/gtkeventcontrollerkey.h b/gtk/gtkeventcontrollerkey.h
index b036bde7ec..755947d255 100644
--- a/gtk/gtkeventcontrollerkey.h
+++ b/gtk/gtkeventcontrollerkey.h
@@ -59,9 +59,15 @@ GDK_AVAILABLE_IN_ALL
guint gtk_event_controller_key_get_group (GtkEventControllerKey *controller);
GDK_AVAILABLE_IN_ALL
-GtkWidget * gtk_event_controller_key_get_focus_origin (GtkEventControllerKey *controller);
+GtkWidget * gtk_event_controller_key_get_focus_origin (GtkEventControllerKey *controller);
GDK_AVAILABLE_IN_ALL
-GtkWidget * gtk_event_controller_key_get_focus_target (GtkEventControllerKey *controller);
+GtkWidget * gtk_event_controller_key_get_focus_target (GtkEventControllerKey *controller);
+
+GDK_AVAILABLE_IN_ALL
+gboolean gtk_event_controller_key_contains_focus (GtkEventControllerKey *self);
+GDK_AVAILABLE_IN_ALL
+gboolean gtk_event_controller_key_is_focus (GtkEventControllerKey *self);
+
G_END_DECLS
diff --git a/gtk/gtkpopovermenu.c b/gtk/gtkpopovermenu.c
index 98b52058bc..02ee7706cb 100644
--- a/gtk/gtkpopovermenu.c
+++ b/gtk/gtkpopovermenu.c
@@ -210,19 +210,15 @@ visible_submenu_changed (GObject *object,
}
static void
-focus_out (GtkEventController *controller,
- GdkCrossingMode mode,
- GdkNotifyType detail,
- GtkPopoverMenu *menu)
+focus_out (GtkEventControllerKey *controller,
+ GdkCrossingMode mode,
+ GdkNotifyType detail,
+ GtkPopoverMenu *menu)
{
- gboolean contains_focus;
-
- g_object_get (controller, "contains-focus", &contains_focus, NULL);
-
- if (!contains_focus)
+ if (!gtk_event_controller_key_contains_focus (controller))
{
if (menu->parent_menu &&
- GTK_POPOVER_MENU (menu->parent_menu)->open_submenu == (GtkWidget*)menu)
+ GTK_POPOVER_MENU (menu->parent_menu)->open_submenu == (GtkWidget*) menu)
GTK_POPOVER_MENU (menu->parent_menu)->open_submenu = NULL;
gtk_popover_popdown (GTK_POPOVER (menu));
}
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index f7ec1b3f5f..9c2354450e 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -5619,7 +5619,8 @@ gtk_tree_view_key_controller_focus_out (GtkEventControllerKey *key,
/* destroy interactive search dialog */
if (tree_view->priv->search_window &&
- !is_focus && !contains_focus)
+ !gtk_event_controller_key_is_focus (key) &&
+ !gtk_event_controller_key_contains_focus (key))
gtk_tree_view_search_window_hide (tree_view->priv->search_window, tree_view,
gtk_get_current_event_device ());
}
diff --git a/testsuite/gtk/focus.c b/testsuite/gtk/focus.c
index 3086cc771c..a8f11e15de 100644
--- a/testsuite/gtk/focus.c
+++ b/testsuite/gtk/focus.c
@@ -26,47 +26,35 @@ detail_to_string (GdkNotifyType detail)
}
static void
-focus_in (GtkEventController *controller,
- GdkCrossingMode mode,
- GdkNotifyType detail,
- GString *s)
+focus_in (GtkEventControllerKey *key,
+ GdkCrossingMode mode,
+ GdkNotifyType detail,
+ GString *s)
{
- GtkWidget *widget = gtk_event_controller_get_widget (controller);
- gboolean is_focus;
- gboolean contains_focus;
-
- g_object_get (controller,
- "is-focus", &is_focus,
- "contains-focus", &contains_focus,
- NULL);
+ GtkWidget *widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (key));
+
g_string_append_printf (s, "%s: focus-in %s %s is-focus: %d contains-focus: %d\n",
widget_name (widget),
mode_to_string (mode),
detail_to_string (detail),
- is_focus,
- contains_focus);
+ gtk_event_controller_key_is_focus (key),
+ gtk_event_controller_key_contains_focus (key));
}
static void
-focus_out (GtkEventController *controller,
- GdkCrossingMode mode,
- GdkNotifyType detail,
- GString *s)
+focus_out (GtkEventControllerKey *key,
+ GdkCrossingMode mode,
+ GdkNotifyType detail,
+ GString *s)
{
- GtkWidget *widget = gtk_event_controller_get_widget (controller);
- gboolean is_focus;
- gboolean contains_focus;
-
- g_object_get (controller,
- "is-focus", &is_focus,
- "contains-focus", &contains_focus,
- NULL);
+ GtkWidget *widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (key));
+
g_string_append_printf (s, "%s: focus-out %s %s is-focus: %d contains-focus: %d\n",
widget_name (widget),
mode_to_string (mode),
detail_to_string (detail),
- is_focus,
- contains_focus);
+ gtk_event_controller_key_is_focus (key),
+ gtk_event_controller_key_contains_focus (key));
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]