[gtk/wip/matthiasc/focus2] gizmo: Make it possible to override focus



commit 115c7b6dba8a0d7c2f4c9524c4d8cada2f715eaf
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Mar 11 15:35:13 2019 -0400

    gizmo: Make it possible to override focus
    
    This will be used in GtkNotebook.

 gtk/gtkgizmo.c        | 25 +++++++++++++++++++++++++
 gtk/gtkgizmoprivate.h | 11 ++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkgizmo.c b/gtk/gtkgizmo.c
index 305e0b524e..b3272578a9 100644
--- a/gtk/gtkgizmo.c
+++ b/gtk/gtkgizmo.c
@@ -46,6 +46,19 @@ gtk_gizmo_snapshot (GtkWidget   *widget,
     GTK_WIDGET_CLASS (gtk_gizmo_parent_class)->snapshot (widget, snapshot);
 }
 
+static GtkWidget *
+gtk_gizmo_next_focus_child (GtkWidget        *widget,
+                            GtkWidget        *child,
+                            GtkDirectionType  direction)
+{
+  GtkGizmo *self = GTK_GIZMO (widget);
+
+  if (self->focus_func)
+    return self->focus_func (self, child, direction);
+  else
+    return GTK_WIDGET_CLASS (gtk_gizmo_parent_class)->next_focus_child (widget, child, direction);
+}
+
 static void
 gtk_gizmo_finalize (GObject *object)
 {
@@ -76,6 +89,7 @@ gtk_gizmo_class_init (GtkGizmoClass *klass)
   widget_class->measure = gtk_gizmo_measure;
   widget_class->size_allocate = gtk_gizmo_size_allocate;
   widget_class->snapshot = gtk_gizmo_snapshot;
+  widget_class->next_focus_child = gtk_gizmo_next_focus_child;
 }
 
 static void
@@ -89,6 +103,16 @@ gtk_gizmo_new (const char              *css_name,
                GtkGizmoMeasureFunc  measure_func,
                GtkGizmoAllocateFunc allocate_func,
                GtkGizmoSnapshotFunc snapshot_func)
+{
+  return gtk_gizmo_new_with_focus (css_name, measure_func, allocate_func, snapshot_func, NULL);
+}
+
+GtkWidget *
+gtk_gizmo_new_with_focus (const char              *css_name,
+                          GtkGizmoMeasureFunc  measure_func,
+                          GtkGizmoAllocateFunc allocate_func,
+                          GtkGizmoSnapshotFunc snapshot_func,
+                          GtkGizmoFocusFunc    focus_func)
 {
   GtkGizmo *gizmo = GTK_GIZMO (g_object_new (GTK_TYPE_GIZMO,
                                              "css-name", css_name,
@@ -97,6 +121,7 @@ gtk_gizmo_new (const char              *css_name,
   gizmo->measure_func  = measure_func;
   gizmo->allocate_func = allocate_func;
   gizmo->snapshot_func = snapshot_func;
+  gizmo->focus_func    = focus_func;
 
   return GTK_WIDGET (gizmo);
 }
diff --git a/gtk/gtkgizmoprivate.h b/gtk/gtkgizmoprivate.h
index c65a430351..d1e879d632 100644
--- a/gtk/gtkgizmoprivate.h
+++ b/gtk/gtkgizmoprivate.h
@@ -27,7 +27,9 @@ typedef void    (* GtkGizmoAllocateFunc)  (GtkGizmo *gizmo,
                                            int       baseline);
 typedef void    (* GtkGizmoSnapshotFunc)  (GtkGizmo    *gizmo,
                                            GtkSnapshot *snapshot);
-
+typedef GtkWidget * (* GtkGizmoFocusFunc) (GtkGizmo         *gizmo,
+                                           GtkWidget        *child,
+                                           GtkDirectionType  direction);
 
 struct _GtkGizmo
 {
@@ -36,6 +38,7 @@ struct _GtkGizmo
   GtkGizmoMeasureFunc  measure_func;
   GtkGizmoAllocateFunc allocate_func;
   GtkGizmoSnapshotFunc snapshot_func;
+  GtkGizmoFocusFunc    focus_func;
 };
 
 struct _GtkGizmoClass
@@ -50,5 +53,11 @@ GtkWidget *gtk_gizmo_new (const char          *css_name,
                           GtkGizmoAllocateFunc allocate_func,
                           GtkGizmoSnapshotFunc snapshot_func);
 
+GtkWidget *gtk_gizmo_new_with_focus (const char          *css_name,
+                                     GtkGizmoMeasureFunc  measure_func,
+                                     GtkGizmoAllocateFunc allocate_func,
+                                     GtkGizmoSnapshotFunc snapshot_func,
+                                     GtkGizmoFocusFunc    focus_func);
+
 
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]