[gtk/wip/matthiasc/focus2: 5/41] root: Add focus
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/focus2: 5/41] root: Add focus
- Date: Tue, 5 Mar 2019 03:55:22 +0000 (UTC)
commit 505deb570a9747b07bd653464b91eb5dac1e0e8b
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Mar 2 08:45:13 2019 -0500
root: Add focus
Add a getter and a setter for the focus widget.
The default implementations do nothing.
gtk/gtkroot.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkroot.h | 10 ++++++++++
2 files changed, 69 insertions(+)
---
diff --git a/gtk/gtkroot.c b/gtk/gtkroot.c
index ad93f8791a..3552a85474 100644
--- a/gtk/gtkroot.c
+++ b/gtk/gtkroot.c
@@ -59,12 +59,26 @@ gtk_root_default_get_surface_transform (GtkRoot *self,
*y = 0;
}
+static void
+gtk_root_default_set_focus (GtkRoot *self,
+ GtkWidget *focus)
+{
+}
+
+static GtkWidget *
+gtk_root_default_get_focus (GtkRoot *self)
+{
+ return NULL;
+}
+
static void
gtk_root_default_init (GtkRootInterface *iface)
{
iface->get_display = gtk_root_default_get_display;
iface->get_renderer = gtk_root_default_get_renderer;
iface->get_surface_transform = gtk_root_default_get_surface_transform;
+ iface->set_focus = gtk_root_default_set_focus;
+ iface->get_focus = gtk_root_default_get_focus;
}
GdkDisplay *
@@ -124,3 +138,48 @@ gtk_root_get_for_surface (GdkSurface *surface)
return NULL;
}
+
+/**
+ * gtk_root_set_focus:
+ * @self: a #GtkRoot
+ * @focus: (allow-none): widget to be the new focus widget, or %NULL
+ * to unset the focus widget
+ *
+ * If @focus is not the current focus widget, and is focusable, sets
+ * it as the focus widget for the root. If @focus is %NULL, unsets
+ * the focus widget for the root.
+ *
+ * To set the focus to a particular widget in the root, it is usually
+ * more convenient to use gtk_widget_grab_focus() instead of this function.
+ */
+void
+gtk_root_set_focus (GtkRoot *self,
+ GtkWidget *focus)
+{
+ g_return_if_fail (GTK_IS_ROOT (self));
+ g_return_if_fail (focus == NULL || GTK_IS_WIDGET (focus));
+
+ GTK_ROOT_GET_IFACE (self)->set_focus (self, focus);
+}
+
+/**
+ * gtk_root_get_focus:
+ * @self: a #GtkRoot
+ *
+ * Retrieves the current focused widget within the root.
+ *
+ * Note that this is the widget that would have the focus
+ * if the root is active; if the root is not focused then
+ * `gtk_widget_has_focus (widget)` will be %FALSE for the
+ * widget.
+ *
+ * Returns: (nullable) (transfer none): the currently focused widget,
+ * or %NULL if there is none.
+ */
+GtkWidget *
+gtk_root_get_focus (GtkRoot *self)
+{
+ g_return_val_if_fail (GTK_IS_ROOT (self), NULL);
+
+ return GTK_ROOT_GET_IFACE (self)->get_focus (self);
+}
diff --git a/gtk/gtkroot.h b/gtk/gtkroot.h
index 45e777ba68..fe4d980d2e 100644
--- a/gtk/gtkroot.h
+++ b/gtk/gtkroot.h
@@ -51,11 +51,21 @@ struct _GtkRootInterface
void (* get_surface_transform) (GtkRoot *root,
int *x,
int *y);
+
+ void (* set_focus) (GtkRoot *self,
+ GtkWidget *focus);
+ GtkWidget * (* get_focus) (GtkRoot *self);
};
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_root_get_for_surface (GdkSurface *surface);
+GDK_AVAILABLE_IN_ALL
+void gtk_root_set_focus (GtkRoot *self,
+ GtkWidget *focus);
+GDK_AVAILABLE_IN_ALL
+GtkWidget * gtk_root_get_focus (GtkRoot *self);
+
G_END_DECLS
#endif /* __GTK_ROOT_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]