[gtk+/wip/baedert/drawing: 23/147] colorswatch: Remove gadget usage



commit ed010b1d101a6ca5847666461f7e7c35e5d5de25
Author: Timm Bäder <mail baedert org>
Date:   Thu May 4 09:45:05 2017 +0200

    colorswatch: Remove gadget usage

 gtk/gtkcolorswatch.c |  111 ++++++++++++++------------------------------------
 1 files changed, 31 insertions(+), 80 deletions(-)
---
diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c
index d3465b3..17e7e25 100644
--- a/gtk/gtkcolorswatch.c
+++ b/gtk/gtkcolorswatch.c
@@ -62,7 +62,6 @@ struct _GtkColorSwatchPrivate
 
   GtkGesture *long_press_gesture;
   GtkGesture *multipress_gesture;
-  GtkCssGadget *gadget;
   GtkCssGadget *overlay_gadget;
 
   GtkWidget *popover;
@@ -88,29 +87,14 @@ static guint signals[LAST_SIGNAL];
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkColorSwatch, gtk_color_swatch, GTK_TYPE_WIDGET)
 
+#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
 static void
 swatch_snapshot (GtkWidget   *widget,
                  GtkSnapshot *snapshot)
 {
-  gtk_css_gadget_snapshot (GTK_COLOR_SWATCH (widget)->priv->gadget, snapshot);
-}
-
-#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
-
-static gboolean
-gtk_color_swatch_render (GtkCssGadget *gadget,
-                         GtkSnapshot  *snapshot,
-                         int           x,
-                         int           y,
-                         int           width,
-                         int           height,
-                         gpointer      data)
-{
-  GtkWidget *widget;
   GtkColorSwatch *swatch;
   GtkStyleContext *context;
 
-  widget = gtk_css_gadget_get_owner (gadget);
   swatch = GTK_COLOR_SWATCH (widget);
   context = gtk_widget_get_style_context (widget);
 
@@ -122,7 +106,8 @@ gtk_color_swatch_render (GtkCssGadget *gadget,
       GskRoundedRect content_box;
 
       gtk_widget_get_allocation (widget, &allocation);
-      gtk_css_gadget_get_border_allocation (gadget, &border_allocation, NULL);
+      /* TODO: This should be the border allocation */
+      gtk_widget_get_allocation (widget, &border_allocation);
 
       border_allocation.x -= allocation.x;
       border_allocation.y -= allocation.y;
@@ -180,10 +165,9 @@ gtk_color_swatch_render (GtkCssGadget *gadget,
     }
 
   gtk_css_gadget_snapshot (swatch->priv->overlay_gadget, snapshot);
-
-  return gtk_widget_has_visible_focus (widget);
 }
 
+
 static void
 drag_set_color_icon (GdkDragContext *context,
                      const GdkRGBA  *color)
@@ -274,39 +258,6 @@ swatch_drag_data_received (GtkWidget        *widget,
   gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (widget), &color);
 }
 
-static void
-gtk_color_swatch_measure (GtkCssGadget   *gadget,
-                          GtkOrientation  orientation,
-                          int             for_size,
-                          int            *minimum,
-                          int            *natural,
-                          int            *minimum_baseline,
-                          int            *natural_baseline,
-                          gpointer        unused)
-{
-  GtkWidget *widget;
-  GtkColorSwatch *swatch;
-  gint w, h, min;
-
-  widget = gtk_css_gadget_get_owner (gadget);
-  swatch = GTK_COLOR_SWATCH (widget);
-
-  gtk_css_gadget_get_preferred_size (swatch->priv->overlay_gadget,
-                                     orientation,
-                                     -1,
-                                     minimum, natural,
-                                     NULL, NULL);
-
-  gtk_widget_get_size_request (widget, &w, &h);
-  if (orientation == GTK_ORIENTATION_HORIZONTAL)
-    min = w < 0 ? 48 : w;
-  else
-    min = h < 0 ? 32 : h;
-
-  *minimum = MAX (*minimum, min);
-  *natural = MAX (*natural, min);
-}
-
 static gboolean
 swatch_key_press (GtkWidget   *widget,
                   GdkEventKey *event)
@@ -501,14 +452,9 @@ swatch_size_allocate (GtkWidget     *widget,
                       GtkAllocation *allocation)
 {
   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
-  GtkAllocation clip, clip2;
+  GtkAllocation clip = *allocation, clip2 = *allocation;
 
-  gtk_widget_set_allocation (widget, allocation);
 
-  gtk_css_gadget_allocate (swatch->priv->gadget,
-                           allocation,
-                           gtk_widget_get_allocated_baseline (widget),
-                           &clip);
   gtk_css_gadget_allocate (swatch->priv->overlay_gadget,
                            allocation,
                            gtk_widget_get_allocated_baseline (widget),
@@ -520,19 +466,19 @@ swatch_size_allocate (GtkWidget     *widget,
 
   if (gtk_widget_get_realized (widget))
     {
-      GtkAllocation border_allocation;
-      gtk_css_gadget_get_border_allocation(swatch->priv->gadget, &border_allocation, NULL);
+      GtkAllocation widget_allocation;
+      gtk_widget_get_allocation (widget, &widget_allocation);
       gdk_window_move_resize (swatch->priv->event_window,
-                              border_allocation.x,
-                              border_allocation.y,
-                              border_allocation.width,
-                              border_allocation.height);
+                              widget_allocation.x,
+                              widget_allocation.y,
+                              widget_allocation.width,
+                              widget_allocation.height);
     }
 
 }
 
 static void
-gtk_color_swatch_measure_ (GtkWidget *widget,
+gtk_color_swatch_measure (GtkWidget *widget,
                           GtkOrientation  orientation,
                           int             for_size,
                           int            *minimum,
@@ -540,11 +486,25 @@ gtk_color_swatch_measure_ (GtkWidget *widget,
                           int            *minimum_baseline,
                           int            *natural_baseline)
 {
-  gtk_css_gadget_get_preferred_size (GTK_COLOR_SWATCH (widget)->priv->gadget,
+  GtkColorSwatch *swatch;
+  gint w, h, min;
+
+  swatch = GTK_COLOR_SWATCH (widget);
+
+  gtk_css_gadget_get_preferred_size (swatch->priv->overlay_gadget,
                                      orientation,
-                                     for_size,
+                                     -1,
                                      minimum, natural,
-                                     minimum_baseline, natural_baseline);
+                                     NULL, NULL);
+
+  gtk_widget_get_size_request (widget, &w, &h);
+  if (orientation == GTK_ORIENTATION_HORIZONTAL)
+    min = w < 0 ? 48 : w;
+  else
+    min = h < 0 ? 32 : h;
+
+  *minimum = MAX (*minimum, min);
+  *natural = MAX (*natural, min);
 }
 
 
@@ -575,7 +535,6 @@ swatch_state_flags_changed (GtkWidget     *widget,
 {
   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
 
-  gtk_css_gadget_set_state (swatch->priv->gadget, gtk_widget_get_state_flags (widget));
   gtk_css_gadget_set_state (swatch->priv->overlay_gadget, gtk_widget_get_state_flags (widget));
 
   update_icon (swatch);
@@ -643,7 +602,6 @@ swatch_finalize (GObject *object)
   GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
 
   g_free (swatch->priv->icon);
-  g_clear_object (&swatch->priv->gadget);
   g_clear_object (&swatch->priv->overlay_gadget);
 
   G_OBJECT_CLASS (gtk_color_swatch_parent_class)->finalize (object);
@@ -677,7 +635,7 @@ gtk_color_swatch_class_init (GtkColorSwatchClass *class)
   object_class->finalize = swatch_finalize;
   object_class->dispose = swatch_dispose;
 
-  widget_class->measure = gtk_color_swatch_measure_;
+  widget_class->measure = gtk_color_swatch_measure;
   widget_class->snapshot = swatch_snapshot;
   widget_class->drag_begin = swatch_drag_begin;
   widget_class->drag_data_get = swatch_drag_data_get;
@@ -746,14 +704,7 @@ gtk_color_swatch_init (GtkColorSwatch *swatch)
                     G_CALLBACK (tap_action), swatch);
 
   widget_node = gtk_widget_get_css_node (GTK_WIDGET (swatch));
-  swatch->priv->gadget = gtk_css_custom_gadget_new_for_node (widget_node,
-                                                             GTK_WIDGET (swatch),
-                                                             gtk_color_swatch_measure,
-                                                             NULL,
-                                                             gtk_color_swatch_render,
-                                                             NULL,
-                                                             NULL);
-  gtk_css_gadget_add_class (swatch->priv->gadget, "activatable");
+  gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (swatch)), "activatable");
 
   swatch->priv->overlay_gadget = gtk_icon_helper_new_named ("overlay", GTK_WIDGET (swatch));
   _gtk_icon_helper_set_force_scale_pixbuf (GTK_ICON_HELPER (swatch->priv->overlay_gadget), TRUE);


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