[gtk+] entry: Make code do what it's meant to do



commit c5905b13b97012fc9e9424718bdce34e0989f512
Author: Benjamin Otte <otte redhat com>
Date:   Fri Mar 13 18:04:51 2015 +0100

    entry: Make code do what it's meant to do
    
    With the 3.0 transition, this code went from just querying the entry's
    height request to doing a full size request.
    Then it got code to revert the features that a full size request does.
    And then it grew code that manually computed the baseline.
    
    Avoid this and just do what happened back in the days: Do a regular
    height request.
    
    This changes the semantics of the get_frame_size() vfunc wrt its
    behavior towards subclasses overwriting the get_height() vfuncs, but I'm
    happy to live with that.

 gtk/gtkentry.c      |   22 +++++-----------------
 gtk/gtkspinbutton.c |   32 --------------------------------
 2 files changed, 5 insertions(+), 49 deletions(-)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index c0b9d43..a8f54c1 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -3584,13 +3584,11 @@ gtk_entry_get_text_area_size (GtkEntry *entry,
 {
   GtkWidget *widget = GTK_WIDGET (entry);
   GtkAllocation allocation;
-  GtkRequisition requisition;
-  gint req_height;
+  gint req_height, unused;
   gint frame_height;
   GtkBorder borders;
 
-  gtk_widget_get_preferred_size (widget, &requisition, NULL);
-  req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom 
(widget);
+  gtk_entry_get_preferred_height_and_baseline_for_width (widget, -1, &req_height, &unused, NULL, NULL);
 
   gtk_widget_get_allocation (widget, &allocation);
   _gtk_entry_get_borders (entry, &borders);
@@ -3640,16 +3638,11 @@ gtk_entry_get_frame_size (GtkEntry *entry,
 {
   GtkEntryPrivate *priv = entry->priv;
   GtkAllocation allocation;
-  GtkRequisition requisition;
   GtkWidget *widget = GTK_WIDGET (entry);
-  gint area_height, y_pos;
   gint baseline;
-  gint req_height;
-  GtkBorder borders;
-
-  gtk_widget_get_preferred_size (widget, &requisition, NULL);
+  gint req_height, req_baseline, unused;
 
-  req_height = requisition.height - gtk_widget_get_margin_top (widget) - gtk_widget_get_margin_bottom 
(widget);
+  gtk_entry_get_preferred_height_and_baseline_for_width (widget, -1, &req_height, &unused, &req_baseline, 
&unused);
 
   gtk_widget_get_allocation (widget, &allocation);
   baseline = gtk_widget_get_allocated_baseline (widget);
@@ -3666,12 +3659,7 @@ gtk_entry_get_frame_size (GtkEntry *entry,
           if (baseline == -1)
             *y = (allocation.height - req_height) / 2;
           else
-            {
-              _gtk_entry_get_borders (entry, &borders);
-              area_height = req_height - borders.top - borders.bottom;
-              y_pos = ((area_height * PANGO_SCALE - priv->ascent - priv->descent) / 2 + priv->ascent) / 
PANGO_SCALE;
-              *y = baseline - y_pos - borders.top;
-            }
+            *y = baseline - req_baseline;
         }
 
       *y += allocation.y;
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index 6408abf..2d8f98d 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -263,11 +263,6 @@ static void gtk_spin_button_get_text_area_size (GtkEntry *entry,
                                                 gint     *y,
                                                 gint     *width,
                                                 gint     *height);
-static void gtk_spin_button_get_frame_size (GtkEntry *entry,
-                                            gint     *x,
-                                            gint     *y,
-                                            gint     *width,
-                                            gint     *height);
 static void gtk_spin_button_unset_adjustment (GtkSpinButton *spin_button);
 static void gtk_spin_button_set_orientation (GtkSpinButton     *spin_button,
                                              GtkOrientation     orientation);
@@ -335,7 +330,6 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class)
 
   entry_class->activate = gtk_spin_button_activate;
   entry_class->get_text_area_size = gtk_spin_button_get_text_area_size;
-  entry_class->get_frame_size = gtk_spin_button_get_frame_size;
 
   class->input = NULL;
   class->output = NULL;
@@ -1859,32 +1853,6 @@ gtk_spin_button_activate (GtkEntry *entry)
 }
 
 static void
-gtk_spin_button_get_frame_size (GtkEntry *entry,
-                                gint     *x,
-                                gint     *y,
-                                gint     *width,
-                                gint     *height)
-{
-  GtkSpinButtonPrivate *priv = GTK_SPIN_BUTTON (entry)->priv;
-  gint up_panel_width, up_panel_height;
-  gint down_panel_width, down_panel_height;
-
-  gtk_spin_button_panel_get_size (GTK_SPIN_BUTTON (entry), priv->up_panel, &up_panel_width, 
&up_panel_height);
-  gtk_spin_button_panel_get_size (GTK_SPIN_BUTTON (entry), priv->down_panel, &down_panel_width, 
&down_panel_height);
-
-  GTK_ENTRY_CLASS (gtk_spin_button_parent_class)->get_frame_size (entry, x, y, width, height);
-
-  if (priv->orientation == GTK_ORIENTATION_VERTICAL)
-    {
-      if (y)
-        *y += up_panel_height;
-
-      if (height)
-        *height -= up_panel_height + down_panel_height;
-    }
-}
-
-static void
 gtk_spin_button_get_text_area_size (GtkEntry *entry,
                                     gint     *x,
                                     gint     *y,


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