[gtk+] snapshot: Convert GtkButton and subclasses



commit ab47479045a6437c07f7b05b4208623fca870c5e
Author: Benjamin Otte <otte redhat com>
Date:   Mon Nov 14 21:55:03 2016 +0100

    snapshot: Convert GtkButton and subclasses

 gtk/gtkbutton.c      |   43 +++++++++++++++++++---------
 gtk/gtkcheckbutton.c |   19 +++++-------
 gtk/gtkmodelbutton.c |   76 +++++++++++++++++++++++++++----------------------
 3 files changed, 79 insertions(+), 59 deletions(-)
---
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index f63a725..78e94d6 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -125,8 +125,7 @@ static void gtk_button_map (GtkWidget * widget);
 static void gtk_button_unmap (GtkWidget * widget);
 static void gtk_button_size_allocate (GtkWidget * widget,
                                      GtkAllocation * allocation);
-static GskRenderNode *gtk_button_get_render_node (GtkWidget   *widget,
-                                                  GskRenderer *renderer);
+static void gtk_button_snapshot (GtkWidget * widget, GtkSnapshot *snapshot);
 static gint gtk_button_grab_broken (GtkWidget * widget,
                                    GdkEventGrabBroken * event);
 static gint gtk_button_key_release (GtkWidget * widget, GdkEventKey * event);
@@ -170,6 +169,13 @@ static void     gtk_button_allocate (GtkCssGadget        *gadget,
                                      GtkAllocation       *out_clip,
                                      gpointer             data);
 static void gtk_button_set_child_type (GtkButton *button, guint child_type);
+static gboolean gtk_button_render   (GtkCssGadget        *gadget,
+                                     GtkSnapshot         *snapshot,
+                                     int                  x,
+                                     int                  y,
+                                     int                  width,
+                                     int                  height,
+                                     gpointer             data);
 
 static GParamSpec *props[LAST_PROP] = { NULL, };
 static guint button_signals[LAST_SIGNAL] = { 0 };
@@ -224,7 +230,7 @@ gtk_button_class_init (GtkButtonClass *klass)
   widget_class->map = gtk_button_map;
   widget_class->unmap = gtk_button_unmap;
   widget_class->size_allocate = gtk_button_size_allocate;
-  widget_class->get_render_node = gtk_button_get_render_node;
+  widget_class->snapshot = gtk_button_snapshot;
   widget_class->grab_broken_event = gtk_button_grab_broken;
   widget_class->key_release_event = gtk_button_key_release;
   widget_class->enter_notify_event = gtk_button_enter_notify;
@@ -474,7 +480,7 @@ gtk_button_init (GtkButton *button)
                                                      gtk_button_measure,
                                                      gtk_button_allocate,
                                                      NULL,
-                                                     NULL,
+                                                     gtk_button_render,
                                                      NULL,
                                                      NULL);
 
@@ -886,20 +892,29 @@ gtk_button_allocate (GtkCssGadget        *gadget,
   gtk_container_get_children_clip (GTK_CONTAINER (widget), out_clip);
 }
 
-static GskRenderNode *
-gtk_button_get_render_node (GtkWidget   *widget,
-                            GskRenderer *renderer)
+static void
+gtk_button_snapshot (GtkWidget   *widget,
+                     GtkSnapshot *snapshot)
 {
-  GskRenderNode *res = gtk_css_gadget_get_render_node (GTK_BUTTON (widget)->priv->gadget,
-                                                       renderer,
-                                                       gtk_widget_has_visible_focus (widget));
+  gtk_css_gadget_snapshot (GTK_BUTTON (widget)->priv->gadget, snapshot);
+}
 
-  if (res == NULL)
-    return NULL;
+static gboolean
+gtk_button_render (GtkCssGadget *gadget,
+                   GtkSnapshot  *snapshot,
+                   int           x,
+                   int           y,
+                   int           width,
+                   int           height,
+                   gpointer      data)
+{
+  GtkWidget *widget;
+
+  widget = gtk_css_gadget_get_owner (gadget);
 
-  gtk_container_propagate_render_node (GTK_CONTAINER (widget), renderer, res);
+  GTK_WIDGET_CLASS (gtk_button_parent_class)->snapshot (widget, snapshot);
 
-  return res;
+  return gtk_widget_has_visible_focus (widget);
 }
 
 static void
diff --git a/gtk/gtkcheckbutton.c b/gtk/gtkcheckbutton.c
index 5d0d8af..167095a 100644
--- a/gtk/gtkcheckbutton.c
+++ b/gtk/gtkcheckbutton.c
@@ -80,9 +80,8 @@
 
 static void gtk_check_button_size_allocate       (GtkWidget           *widget,
                                                  GtkAllocation       *allocation);
-static GskRenderNode *gtk_check_button_get_render_node (GtkWidget   *widget,
-                                                        GskRenderer *renderer);
-
+static void gtk_check_button_snapshot            (GtkWidget           *widget,
+                                                 GtkSnapshot         *snapshot);
 
 typedef struct {
   GtkCssGadget *gadget;
@@ -210,7 +209,7 @@ gtk_check_button_class_init (GtkCheckButtonClass *class)
 
   widget_class->measure = gtk_check_button_measure;
   widget_class->size_allocate = gtk_check_button_size_allocate;
-  widget_class->get_render_node = gtk_check_button_get_render_node;
+  widget_class->snapshot = gtk_check_button_snapshot;
   widget_class->state_flags_changed = gtk_check_button_state_flags_changed;
   widget_class->direction_changed = gtk_check_button_direction_changed;
 
@@ -382,18 +381,16 @@ gtk_check_button_size_allocate (GtkWidget     *widget,
     }
 }
 
-static GskRenderNode *
-gtk_check_button_get_render_node (GtkWidget   *widget,
-                                  GskRenderer *renderer)
+static void
+gtk_check_button_snapshot (GtkWidget   *widget,
+                           GtkSnapshot *snapshot)
 {
   GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (GTK_CHECK_BUTTON (widget));
 
   if (!gtk_toggle_button_get_mode (GTK_TOGGLE_BUTTON (widget)))
-    return GTK_WIDGET_CLASS (gtk_check_button_parent_class)->get_render_node (widget, renderer);
+    GTK_WIDGET_CLASS (gtk_check_button_parent_class)->snapshot (widget, snapshot);
   else
-    return gtk_css_gadget_get_render_node (priv->gadget,
-                                           renderer,
-                                           gtk_widget_has_visible_focus (widget));
+    gtk_css_gadget_snapshot (priv->gadget, snapshot);
 }
 
 GtkCssNode *
diff --git a/gtk/gtkmodelbutton.c b/gtk/gtkmodelbutton.c
index 443abc1..4c98da5 100644
--- a/gtk/gtkmodelbutton.c
+++ b/gtk/gtkmodelbutton.c
@@ -900,6 +900,46 @@ gtk_model_button_allocate (GtkCssGadget        *gadget,
 }
 
 static void
+gtk_model_button_snapshot (GtkWidget   *widget,
+                           GtkSnapshot *snapshot)
+{
+  GtkCssGadget *gadget;
+
+  if (GTK_MODEL_BUTTON (widget)->iconic)
+    gadget = GTK_BUTTON (widget)->priv->gadget;
+  else
+    gadget = GTK_MODEL_BUTTON (widget)->gadget;
+
+  gtk_css_gadget_snapshot (gadget, snapshot);
+}
+
+static gboolean
+gtk_model_button_render (GtkCssGadget *gadget,
+                         GtkSnapshot  *snapshot,
+                         int           x,
+                         int           y,
+                         int           width,
+                         int           height,
+                         gpointer      data)
+{
+  GtkWidget *widget;
+  GtkModelButton *button;
+  GtkWidget *child;
+
+  widget = gtk_css_gadget_get_owner (gadget);
+  button = GTK_MODEL_BUTTON (widget);
+
+  if (gtk_css_node_get_visible (gtk_css_gadget_get_node (button->indicator_gadget)))
+    gtk_css_gadget_snapshot (button->indicator_gadget, snapshot);
+
+  child = gtk_bin_get_child (GTK_BIN (widget));
+  if (child)
+    gtk_container_snapshot_child (GTK_CONTAINER (widget), child, snapshot);
+
+  return gtk_widget_has_visible_focus (widget);
+}
+
+static void
 gtk_model_button_destroy (GtkWidget *widget)
 {
   GtkModelButton *model_button = GTK_MODEL_BUTTON (widget);
@@ -943,38 +983,6 @@ gtk_model_button_finalize (GObject *object)
   G_OBJECT_CLASS (gtk_model_button_parent_class)->finalize (object);
 }
 
-static GskRenderNode *
-gtk_model_button_get_render_node (GtkWidget *widget, GskRenderer *renderer)
-{
-  GtkCssGadget  *button_gadget;
-  GskRenderNode *button_node;
-  GskRenderNode *indicator_node;
-
-  if (GTK_MODEL_BUTTON (widget)->iconic)
-    button_gadget = GTK_BUTTON (widget)->priv->gadget;
-  else
-    button_gadget = GTK_MODEL_BUTTON (widget)->gadget;
-
-  button_node = gtk_css_gadget_get_render_node (button_gadget, renderer,
-                                                gtk_widget_has_visible_focus (widget));
-
-  if (button_node == NULL)
-    return NULL;
-
-  indicator_node = gtk_css_gadget_get_render_node (GTK_MODEL_BUTTON (widget)->indicator_gadget,
-                                                   renderer, FALSE);
-
-  if (indicator_node != NULL)
-    {
-      gsk_render_node_append_child (button_node, indicator_node);
-      gsk_render_node_unref (indicator_node);
-    }
-
-  gtk_container_propagate_render_node (GTK_CONTAINER (widget), renderer, button_node);
-
-  return button_node;
-}
-
 static void
 gtk_model_button_class_init (GtkModelButtonClass *class)
 {
@@ -988,10 +996,10 @@ gtk_model_button_class_init (GtkModelButtonClass *class)
 
   widget_class->measure = gtk_model_button_measure_;
   widget_class->size_allocate = gtk_model_button_size_allocate;
+  widget_class->snapshot = gtk_model_button_snapshot;
   widget_class->destroy = gtk_model_button_destroy;
   widget_class->state_flags_changed = gtk_model_button_state_flags_changed;
   widget_class->direction_changed = gtk_model_button_direction_changed;
-  widget_class->get_render_node = gtk_model_button_get_render_node;
 
   button_class->clicked = gtk_model_button_clicked;
 
@@ -1147,7 +1155,7 @@ gtk_model_button_init (GtkModelButton *button)
                                                        gtk_model_button_measure,
                                                        gtk_model_button_allocate,
                                                        NULL,
-                                                       NULL,
+                                                       gtk_model_button_render,
                                                        NULL,
                                                        NULL);
   button->indicator_gadget = gtk_builtin_icon_new ("check",


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