[gtk+/wip/matthiasc/gadget: 4/34] separator: port to gadgets



commit 8ecd5eb2a25c89c8c81550f227414a0221ff6239
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Nov 26 22:32:41 2015 -0500

    separator: port to gadgets
    
    As part of this, stop using custom rendering code for wide
    and non-wide separators.

 gtk/gtkseparator.c                       |  118 +++++++++++++++--------------
 gtk/gtkwidget.c                          |   11 ++-
 gtk/theme/Adwaita/_common.scss           |    4 +-
 gtk/theme/Adwaita/gtk-contained-dark.css |    4 +-
 gtk/theme/Adwaita/gtk-contained.css      |    4 +-
 5 files changed, 78 insertions(+), 63 deletions(-)
---
diff --git a/gtk/gtkseparator.c b/gtk/gtkseparator.c
index c8f2a08..ca26992 100644
--- a/gtk/gtkseparator.c
+++ b/gtk/gtkseparator.c
@@ -30,6 +30,8 @@
 #include "gtkintl.h"
 #include "gtkprivate.h"
 #include "gtkrender.h"
+#include "gtkwidgetprivate.h"
+#include "gtkcsscustomgadgetprivate.h"
 
 /**
  * SECTION:gtkseparator
@@ -51,6 +53,7 @@
 struct _GtkSeparatorPrivate
 {
   GtkOrientation orientation;
+  GtkCssGadget *gadget;
 };
 
 
@@ -111,18 +114,28 @@ gtk_separator_get_property (GObject    *object,
     }
 }
 
+
 static void
-gtk_separator_get_preferred_size (GtkWidget      *widget,
-                                  GtkOrientation  orientation,
-                                  gint           *minimum,
-                                  gint           *natural)
+gtk_separator_get_content_size (GtkCssGadget   *gadget,
+                                GtkOrientation  orientation,
+                                gint            for_size,
+                                gint           *minimum,
+                                gint           *natural,
+                                gint           *minimum_baseline,
+                                gint           *natural_baseline,
+                                gpointer        data)
 {
-  GtkSeparator *separator = GTK_SEPARATOR (widget);
-  GtkSeparatorPrivate *private = separator->priv;
+  GtkWidget *widget;
+  GtkSeparator *separator;
+  GtkSeparatorPrivate *private;
   gboolean wide_sep;
   gint     sep_width;
   gint     sep_height;
 
+  widget = gtk_css_gadget_get_owner (gadget);
+  separator = GTK_SEPARATOR (widget);
+  private = separator->priv;
+
   gtk_widget_style_get (widget,
                         "wide-separators",  &wide_sep,
                         "separator-width",  &sep_width,
@@ -130,17 +143,11 @@ gtk_separator_get_preferred_size (GtkWidget      *widget,
                         NULL);
 
   if (orientation == private->orientation)
-    {
-      *minimum = *natural = 1;
-    }
+    *minimum = *natural = 1;
   else if (orientation == GTK_ORIENTATION_VERTICAL)
-    {
-      *minimum = *natural = wide_sep ? sep_height : 1;
-    }
+    *minimum = *natural = wide_sep ? sep_height : 1;
   else
-    {
-      *minimum = *natural = wide_sep ? sep_width : 1;
-    }
+    *minimum = *natural = wide_sep ? sep_width : 1;
 }
 
 static void
@@ -148,7 +155,11 @@ gtk_separator_get_preferred_width (GtkWidget *widget,
                                    gint      *minimum,
                                    gint      *natural)
 {
-  gtk_separator_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum, natural);
+  gtk_css_gadget_get_preferred_size (GTK_SEPARATOR (widget)->priv->gadget,
+                                     GTK_ORIENTATION_HORIZONTAL,
+                                     -1,
+                                     minimum, natural,
+                                     NULL, NULL);
 }
 
 static void
@@ -156,53 +167,34 @@ gtk_separator_get_preferred_height (GtkWidget *widget,
                                     gint      *minimum,
                                     gint      *natural)
 {
-  gtk_separator_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum, natural);
+  gtk_css_gadget_get_preferred_size (GTK_SEPARATOR (widget)->priv->gadget,
+                                     GTK_ORIENTATION_VERTICAL,
+                                     -1,
+                                     minimum, natural,
+                                     NULL, NULL);
 }
 
-static gboolean
-gtk_separator_draw (GtkWidget *widget,
-                    cairo_t   *cr)
+static void
+gtk_separator_size_allocate (GtkWidget     *widget,
+                             GtkAllocation *allocation)
 {
-  GtkSeparator *separator = GTK_SEPARATOR (widget);
-  GtkSeparatorPrivate *private = separator->priv;
-  GtkStyleContext *context;
-  gboolean wide_separators;
-  gint separator_width;
-  gint separator_height;
-  int width, height;
+  GtkAllocation clip;
 
-  gtk_widget_style_get (widget,
-                        "wide-separators",  &wide_separators,
-                        "separator-width",  &separator_width,
-                        "separator-height", &separator_height,
-                        NULL);
+  gtk_widget_set_allocation (widget, allocation);
 
-  context = gtk_widget_get_style_context (widget);
-  width = gtk_widget_get_allocated_width (widget);
-  height = gtk_widget_get_allocated_height (widget);
+  gtk_css_gadget_allocate (GTK_SEPARATOR (widget)->priv->gadget,
+                           allocation,
+                           gtk_widget_get_allocated_baseline (widget),
+                           &clip);
 
-  if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
-    {
-      if (wide_separators)
-        gtk_render_frame (context, cr,
-                          0, (height - separator_height) / 2,
-                          width, separator_height);
-      else
-        gtk_render_line (context, cr,
-                         0, height / 2,
-                         width - 1, height / 2);
-    }
-  else
-    {
-      if (wide_separators)
-        gtk_render_frame (context, cr,
-                          (width - separator_width) / 2, 0,
-                          separator_width, height);
-      else
-        gtk_render_line (context, cr,
-                         width / 2, 0,
-                         width / 2, height - 1);
-    }
+  gtk_widget_set_clip (widget, &clip);
+}
+
+static gboolean
+gtk_separator_draw (GtkWidget *widget,
+                    cairo_t   *cr)
+{
+  gtk_css_gadget_draw (GTK_SEPARATOR (widget)->priv->gadget, cr);
 
   return FALSE;
 }
@@ -210,12 +202,23 @@ gtk_separator_draw (GtkWidget *widget,
 static void
 gtk_separator_init (GtkSeparator *separator)
 {
+  GtkCssNode *widget_node;
+
   separator->priv = gtk_separator_get_instance_private (separator);
   separator->priv->orientation = GTK_ORIENTATION_HORIZONTAL;
 
   gtk_widget_set_has_window (GTK_WIDGET (separator), FALSE);
 
   _gtk_orientable_set_style_classes (GTK_ORIENTABLE (separator));
+
+  widget_node = gtk_widget_get_css_node (GTK_WIDGET (separator));
+  separator->priv->gadget = gtk_css_custom_gadget_new_for_node (widget_node,
+                                                                GTK_WIDGET (separator),
+                                                                gtk_separator_get_content_size,
+                                                                NULL,
+                                                                NULL,
+                                                                NULL,
+                                                                NULL);
 }
 
 static void
@@ -229,6 +232,7 @@ gtk_separator_class_init (GtkSeparatorClass *class)
 
   widget_class->get_preferred_width = gtk_separator_get_preferred_width;
   widget_class->get_preferred_height = gtk_separator_get_preferred_height;
+  widget_class->size_allocate = gtk_separator_size_allocate;
 
   widget_class->draw = gtk_separator_draw;
 
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 0bf08a0..59708bb 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -3566,13 +3566,14 @@ G_GNUC_END_IGNORE_DEPRECATIONS
    * configurable width and should be drawn using a box instead of a line.
    *
    * Since: 2.10
+   * Deprecated: 3.20: Use the standard min-width and min-height CSS properties instead.
    */
   gtk_widget_class_install_style_property (klass,
                                            g_param_spec_boolean ("wide-separators",
                                                                  P_("Wide Separators"),
                                                                  P_("Whether separators have configurable 
width and should be drawn using a box instead of a line"),
                                                                  FALSE,
-                                                                 GTK_PARAM_READABLE));
+                                                                 GTK_PARAM_READABLE|G_PARAM_DEPRECATED));
 
   /**
    * GtkWidget:separator-width:
@@ -3581,13 +3582,15 @@ G_GNUC_END_IGNORE_DEPRECATIONS
    * This property only takes effect if the "wide-separators" style property is %TRUE.
    *
    * Since: 2.10
+   *
+   * Deprecated: 3.20: Use the standard min-width and min-height CSS properties instead.
    */
   gtk_widget_class_install_style_property (klass,
                                            g_param_spec_int ("separator-width",
                                                              P_("Separator Width"),
                                                              P_("The width of separators if wide-separators 
is TRUE"),
                                                              0, G_MAXINT, 0,
-                                                             GTK_PARAM_READABLE));
+                                                             GTK_PARAM_READABLE|G_PARAM_DEPRECATED));
 
   /**
    * GtkWidget:separator-height:
@@ -3596,13 +3599,15 @@ G_GNUC_END_IGNORE_DEPRECATIONS
    * This property only takes effect if the "wide-separators" style property is %TRUE.
    *
    * Since: 2.10
+   *
+   * Deprecated: 3.20: Use the standard min-width and min-height CSS properties instead.
    */
   gtk_widget_class_install_style_property (klass,
                                            g_param_spec_int ("separator-height",
                                                              P_("Separator Height"),
                                                              P_("The height of separators if 
\"wide-separators\" is TRUE"),
                                                              0, G_MAXINT, 0,
-                                                             GTK_PARAM_READABLE));
+                                                             GTK_PARAM_READABLE|G_PARAM_DEPRECATED));
 
   /**
    * GtkWidget:scroll-arrow-hlength:
diff --git a/gtk/theme/Adwaita/_common.scss b/gtk/theme/Adwaita/_common.scss
index 59c452d..8de9e9c 100644
--- a/gtk/theme/Adwaita/_common.scss
+++ b/gtk/theme/Adwaita/_common.scss
@@ -2553,7 +2553,9 @@ scrolledwindow {
 separator {
   // always disable separators
   // -GtkWidget-wide-separators: true;
-  color: transparentize(black, 0.9);
+  background: transparentize(black, 0.9);
+  min-width: 1px;
+  min-height: 1px;
 
   // Font and File button separators
   button.file &.vertical,
diff --git a/gtk/theme/Adwaita/gtk-contained-dark.css b/gtk/theme/Adwaita/gtk-contained-dark.css
index 7414d8c..52ce6be 100644
--- a/gtk/theme/Adwaita/gtk-contained-dark.css
+++ b/gtk/theme/Adwaita/gtk-contained-dark.css
@@ -3625,7 +3625,9 @@ scrolledwindow junction {
     background-color: #323737; }
 
 separator {
-  color: rgba(0, 0, 0, 0.1); }
+  background: rgba(0, 0, 0, 0.1);
+  min-width: 1px;
+  min-height: 1px; }
   button.file separator.vertical, button.font separator.vertical {
     -GtkWidget-wide-separators: true; }
 
diff --git a/gtk/theme/Adwaita/gtk-contained.css b/gtk/theme/Adwaita/gtk-contained.css
index 28b9589..ef83a14 100644
--- a/gtk/theme/Adwaita/gtk-contained.css
+++ b/gtk/theme/Adwaita/gtk-contained.css
@@ -3787,7 +3787,9 @@ scrolledwindow junction {
     background-color: #e1e1df; }
 
 separator {
-  color: rgba(0, 0, 0, 0.1); }
+  background: rgba(0, 0, 0, 0.1);
+  min-width: 1px;
+  min-height: 1px; }
   button.file separator.vertical, button.font separator.vertical {
     -GtkWidget-wide-separators: true; }
 


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