[gtk+/wip/otte/gtk4: 46/127] label,image: Remove GtkMisc usage



commit d87e130c6f5482383f8677351d68785546500f5a
Author: Timm Bäder <mail baedert org>
Date:   Sun Oct 2 18:19:59 2016 +0200

    label,image: Remove GtkMisc usage

 gtk/gtkimage.c |   39 ++++-------------------------------
 gtk/gtkimage.h |    6 ++--
 gtk/gtklabel.c |   60 ++++++-------------------------------------------------
 gtk/gtklabel.h |    6 ++--
 4 files changed, 18 insertions(+), 93 deletions(-)
---
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index 7e0443f..e0e7581 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -71,10 +71,6 @@
  * The image file may contain an animation, if so the #GtkImage will
  * display an animation (#GdkPixbufAnimation) instead of a static image.
  *
- * #GtkImage is a subclass of #GtkMisc, which implies that you can
- * align it (center, left, right) and add padding to it, using
- * #GtkMisc methods.
- *
  * #GtkImage is a “no window” widget (has no #GdkWindow of its own),
  * so by default does not receive events. If you want to receive events
  * on the image, such as button clicks, place the image inside a
@@ -118,13 +114,6 @@
  *   }
  * ]|
  *
- * When handling events on the event box, keep in mind that coordinates
- * in the image may be different from event box coordinates due to
- * the alignment and padding settings on the image (see #GtkMisc).
- * The simplest way to solve this is to set the alignment to 0.0
- * (left/top), and set the padding to zero. Then the origin of
- * the image will be the same as the origin of the event box.
- *
  * Sometimes an application will want to avoid depending on external data
  * files, such as image files. GTK+ comes with a program to avoid this,
  * called “gdk-pixbuf-csource”. This library
@@ -224,9 +213,7 @@ enum
 
 static GParamSpec *image_props[NUM_PROPERTIES] = { NULL, };
 
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-G_DEFINE_TYPE_WITH_PRIVATE (GtkImage, gtk_image, GTK_TYPE_MISC)
-G_GNUC_END_IGNORE_DEPRECATIONS
+G_DEFINE_TYPE_WITH_PRIVATE (GtkImage, gtk_image, GTK_TYPE_WIDGET)
 
 static void
 gtk_image_class_init (GtkImageClass *class)
@@ -1675,19 +1662,12 @@ gtk_image_get_content_size (GtkCssGadget   *gadget,
   GtkWidget *widget;
   gint width, height;
   float baseline_align;
-  gint xpad, ypad;
 
   widget = gtk_css_gadget_get_owner (gadget);
 
   _gtk_icon_helper_get_size (GTK_IMAGE (widget)->priv->icon_helper,
                              &width, &height);
 
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-  gtk_misc_get_padding (GTK_MISC (widget), &xpad, &ypad);
-  width += 2 * xpad;
-  height += 2 * ypad;
-G_GNUC_END_IGNORE_DEPRECATIONS
-
   if (orientation == GTK_ORIENTATION_HORIZONTAL)
     {
       *minimum = *natural = width;
@@ -1727,8 +1707,6 @@ gtk_image_render_contents (GtkCssGadget *gadget,
   GtkImage *image;
   GtkImagePrivate *priv;
   gint w, h, baseline;
-  gfloat xalign, yalign;
-  gint xpad, ypad;
 
   widget = gtk_css_gadget_get_owner (gadget);
   image = GTK_IMAGE (widget);
@@ -1736,21 +1714,14 @@ gtk_image_render_contents (GtkCssGadget *gadget,
 
   _gtk_icon_helper_get_size (priv->icon_helper, &w, &h);
 
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-  gtk_misc_get_alignment (GTK_MISC (image), &xalign, &yalign);
-  gtk_misc_get_padding (GTK_MISC (image), &xpad, &ypad);
-G_GNUC_END_IGNORE_DEPRECATIONS
-
-  if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
-    xalign = 1.0 - xalign;
-
   baseline = gtk_widget_get_allocated_baseline (widget);
 
-  x += floor ((width - 2 * xpad - w) * xalign + xpad);
   if (baseline == -1)
-    y += floor ((height - 2 * ypad - h) * yalign + ypad);
+    y += floor(height - h) / 2;
   else
-    y += CLAMP (baseline - h * gtk_image_get_baseline_align (image), ypad, height - 2 * ypad - h);
+    y += CLAMP (baseline - h * gtk_image_get_baseline_align (image), 0, height - h);
+
+  x += (width - w) / 2;
 
   if (gtk_image_get_storage_type (image) == GTK_IMAGE_ANIMATION)
     {
diff --git a/gtk/gtkimage.h b/gtk/gtkimage.h
index 68b9a6d..0dbe53a 100644
--- a/gtk/gtkimage.h
+++ b/gtk/gtkimage.h
@@ -31,7 +31,7 @@
 #endif
 
 #include <gio/gio.h>
-#include <gtk/deprecated/gtkmisc.h>
+#include <gtk/gtkwidget.h>
 
 
 G_BEGIN_DECLS
@@ -90,7 +90,7 @@ typedef enum
  */
 struct _GtkImage
 {
-  GtkMisc misc;
+  GtkWidget parent_instance;
 
   /*< private >*/
   GtkImagePrivate *priv;
@@ -98,7 +98,7 @@ struct _GtkImage
 
 struct _GtkImageClass
 {
-  GtkMiscClass parent_class;
+  GtkWidgetClass parent_class;
 
   /* Padding for future expansion */
   void (*_gtk_reserved1) (void);
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 4937189..02ed9f7 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -588,7 +588,7 @@ static gboolean gtk_label_render  (GtkCssGadget   *gadget,
 static GtkBuildableIface *buildable_parent_iface = NULL;
 
 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-G_DEFINE_TYPE_WITH_CODE (GtkLabel, gtk_label, GTK_TYPE_MISC,
+G_DEFINE_TYPE_WITH_CODE (GtkLabel, gtk_label, GTK_TYPE_WIDGET,
                          G_ADD_PRIVATE (GtkLabel)
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
                                                 gtk_label_buildable_interface_init))
@@ -3392,17 +3392,13 @@ gtk_label_update_layout_width (GtkLabel *label)
   if (priv->ellipsize || priv->wrap)
     {
       GtkAllocation allocation;
-      int xpad, ypad;
       PangoRectangle logical;
       gint width, height;
 
       gtk_css_gadget_get_content_allocation (priv->gadget, &allocation, NULL);
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-      gtk_misc_get_padding (GTK_MISC (label), &xpad, &ypad);
-G_GNUC_END_IGNORE_DEPRECATIONS
 
-      width = allocation.width - 2 * xpad;
-      height = allocation.height - 2 * ypad;
+      width = allocation.width;
+      height = allocation.height;
 
       if (priv->have_transform)
         {
@@ -3754,14 +3750,9 @@ gtk_label_get_preferred_size (GtkWidget      *widget,
 {
   GtkLabel      *label = GTK_LABEL (widget);
   GtkLabelPrivate  *priv = label->priv;
-  gint xpad, ypad;
   PangoRectangle widest_rect;
   PangoRectangle smallest_rect;
 
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-  gtk_misc_get_padding (GTK_MISC (label), &xpad, &ypad);
-G_GNUC_END_IGNORE_DEPRECATIONS
-
   gtk_label_get_preferred_layout_size (label, &smallest_rect, &widest_rect);
 
   /* Now that we have minimum and natural sizes in pango extents, apply a possible transform */
@@ -3824,9 +3815,6 @@ G_GNUC_END_IGNORE_DEPRECATIONS
           *natural_size = widest_rect.width;
         }
 
-      *minimum_size += xpad * 2;
-      *natural_size += xpad * 2;
-
       if (minimum_baseline)
         *minimum_baseline = -1;
 
@@ -3865,9 +3853,6 @@ G_GNUC_END_IGNORE_DEPRECATIONS
           *minimum_size = MIN (smallest_rect.height, widest_rect.height);
           *natural_size = MAX (smallest_rect.height, widest_rect.height);
         }
-
-      *minimum_size += ypad * 2;
-      *natural_size += ypad * 2;
     }
 }
 
@@ -3884,41 +3869,18 @@ gtk_label_measure (GtkCssGadget   *gadget,
   GtkWidget *widget;
   GtkLabel *label;
   GtkLabelPrivate *priv;
-  gint xpad, ypad;
 
   widget = gtk_css_gadget_get_owner (gadget);
   label = GTK_LABEL (widget);
   priv = label->priv;
 
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-  gtk_misc_get_padding (GTK_MISC (label), &xpad, &ypad);
-G_GNUC_END_IGNORE_DEPRECATIONS
-
   if ((orientation == GTK_ORIENTATION_VERTICAL && for_size != -1 && priv->wrap && (priv->angle == 0 || 
priv->angle == 180 || priv->angle == 360)) ||
       (orientation == GTK_ORIENTATION_HORIZONTAL && priv->wrap && (priv->angle == 90 || priv->angle == 270)))
     {
-      gint size;
-
       if (priv->wrap)
         gtk_label_clear_layout (label);
 
-      if (orientation == GTK_ORIENTATION_HORIZONTAL)
-        size = MAX (1, for_size) - 2 * ypad;
-      else
-        size = MAX (1, for_size) - 2 * xpad;
-
-      get_size_for_allocation (label, size, minimum, natural, minimum_baseline, natural_baseline);
-
-      if (orientation == GTK_ORIENTATION_HORIZONTAL)
-        {
-          *minimum += 2 * xpad;
-          *natural += 2 * xpad;
-        }
-      else
-        {
-          *minimum += 2 * ypad;
-          *natural += 2 * ypad;
-        }
+      get_size_for_allocation (label, for_size, minimum, natural, minimum_baseline, natural_baseline);
     }
   else
     gtk_label_get_preferred_size (widget, orientation, minimum, natural, minimum_baseline, natural_baseline);
@@ -3997,7 +3959,6 @@ get_layout_location (GtkLabel  *label,
   GtkAllocation allocation;
   GtkWidget *widget;
   GtkLabelPrivate *priv;
-  gint xpad, ypad;
   gint req_width, x, y;
   gint req_height;
   gfloat xalign, yalign;
@@ -4010,10 +3971,6 @@ get_layout_location (GtkLabel  *label,
   xalign = priv->xalign;
   yalign = priv->yalign;
 
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-  gtk_misc_get_padding (GTK_MISC (label), &xpad, &ypad);
-G_GNUC_END_IGNORE_DEPRECATIONS
-
   if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
     xalign = 1.0 - xalign;
 
@@ -4031,14 +3988,11 @@ G_GNUC_END_IGNORE_DEPRECATIONS
   req_width  = logical.width;
   req_height = logical.height;
 
-  req_width  += 2 * xpad;
-  req_height += 2 * ypad;
-
   gtk_css_gadget_get_content_allocation (priv->gadget,
                                          &allocation,
                                          &baseline);
 
-  x = floor (allocation.x + xpad + xalign * (allocation.width - req_width) - logical.x);
+  x = floor (allocation.x + xalign * (allocation.width - req_width) - logical.x);
 
   baseline_offset = 0;
   if (baseline != -1 && !priv->have_transform)
@@ -4062,9 +4016,9 @@ G_GNUC_END_IGNORE_DEPRECATIONS
    *   middle".  You want to read the first line, at least, to get some context.
    */
   if (pango_layout_get_line_count (priv->layout) == 1)
-    y = floor (allocation.y + ypad + (allocation.height - req_height) * yalign) - logical.y + 
baseline_offset;
+    y = floor (allocation.y + (allocation.height - req_height) * yalign) - logical.y + baseline_offset;
   else
-    y = floor (allocation.y + ypad + MAX ((allocation.height - req_height) * yalign, 0)) - logical.y + 
baseline_offset;
+    y = floor (allocation.y + MAX ((allocation.height - req_height) * yalign, 0)) - logical.y + 
baseline_offset;
 
   if (xp)
     *xp = x;
diff --git a/gtk/gtklabel.h b/gtk/gtklabel.h
index 14d0a44..928bc50 100644
--- a/gtk/gtklabel.h
+++ b/gtk/gtklabel.h
@@ -29,9 +29,9 @@
 #error "Only <gtk/gtk.h> can be included directly."
 #endif
 
-#include <gtk/deprecated/gtkmisc.h>
 #include <gtk/gtkwindow.h>
 #include <gtk/gtkmenu.h>
+#include <gtk/gtkwidget.h>
 
 G_BEGIN_DECLS
 
@@ -51,7 +51,7 @@ typedef struct _GtkLabelSelectionInfo GtkLabelSelectionInfo;
 
 struct _GtkLabel
 {
-  GtkMisc misc;
+  GtkWidget parent_instance;
 
   /*< private >*/
   GtkLabelPrivate *priv;
@@ -59,7 +59,7 @@ struct _GtkLabel
 
 struct _GtkLabelClass
 {
-  GtkMiscClass parent_class;
+  GtkWidgetClass parent_class;
 
   void (* move_cursor)     (GtkLabel       *label,
                            GtkMovementStep step,


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