summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.van.berkom@gmail.com>2010-09-08 00:25:47 +0200
committerJavier Jardón <jjardon@gnome.org>2010-09-08 18:50:24 +0200
commit993400742041418637e1b09b462e311665ce00fb (patch)
tree1dbafa241869741844e5d98a1e3be563430521fe /gtk
parent4e6a665e613fc7c65874bc5a121c7b87fe65b3e2 (diff)
downloadgtk+-993400742041418637e1b09b462e311665ce00fb.tar.gz
Completely removed requisition cache from GtkWidget instance structure.
Since we have a new mechanism for requesting sizes: GtkSizeRequestIface; it makes no sense to maintain this cache on the GtkWidget structure... removing the requisition cache however does not break the old "size-request" signal which is there for backwards compatability reasons. In any case widget->requisition should not have been accessed, gtk_widget_get_child_requisition() would have been the correct way to consult the cache. This commit also deprecates the newly added gtk_widget_get_requisition() API and makes it fallback on gtk_size_request_get_size().
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkarrow.c57
-rw-r--r--gtk/gtkcontainer.c1
-rw-r--r--gtk/gtkfontsel.c9
-rw-r--r--gtk/gtkhandlebox.c8
-rw-r--r--gtk/gtkiconview.c8
-rw-r--r--gtk/gtkimage.c28
-rw-r--r--gtk/gtkmenu.c5
-rw-r--r--gtk/gtkmisc.c8
-rw-r--r--gtk/gtkpathbar.c2
-rw-r--r--gtk/gtkprivate.h6
-rw-r--r--gtk/gtkruler.c4
-rw-r--r--gtk/gtkseparator.c4
-rw-r--r--gtk/gtksizegroup.c1
-rw-r--r--gtk/gtksizerequest.c28
-rw-r--r--gtk/gtkspinbutton.c56
-rw-r--r--gtk/gtktextview.c3
-rw-r--r--gtk/gtktreeview.c13
-rw-r--r--gtk/gtkwidget.c36
-rw-r--r--gtk/gtkwidget.h4
19 files changed, 167 insertions, 114 deletions
diff --git a/gtk/gtkarrow.c b/gtk/gtkarrow.c
index ed1d69c9a1..70abcc1ff8 100644
--- a/gtk/gtkarrow.c
+++ b/gtk/gtkarrow.c
@@ -47,6 +47,7 @@
#include "config.h"
#include <math.h>
#include "gtkarrow.h"
+#include "gtksizerequest.h"
#include "gtkprivate.h"
#include "gtkintl.h"
@@ -76,8 +77,17 @@ static void gtk_arrow_get_property (GObject *object,
static gboolean gtk_arrow_expose (GtkWidget *widget,
GdkEventExpose *event);
+static void gtk_arrow_size_request_init (GtkSizeRequestIface *iface);
+static void gtk_arrow_get_width (GtkSizeRequest *widget,
+ gint *minimum_size,
+ gint *natural_size);
+static void gtk_arrow_get_height (GtkSizeRequest *widget,
+ gint *minimum_size,
+ gint *natural_size);
-G_DEFINE_TYPE (GtkArrow, gtk_arrow, GTK_TYPE_MISC)
+G_DEFINE_TYPE_WITH_CODE (GtkArrow, gtk_arrow, GTK_TYPE_MISC,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_SIZE_REQUEST,
+ gtk_arrow_size_request_init))
static void
@@ -176,7 +186,6 @@ static void
gtk_arrow_init (GtkArrow *arrow)
{
GtkArrowPrivate *priv;
- gint xpad, ypad;
arrow->priv = G_TYPE_INSTANCE_GET_PRIVATE (arrow,
GTK_TYPE_ARROW,
@@ -185,14 +194,50 @@ gtk_arrow_init (GtkArrow *arrow)
gtk_widget_set_has_window (GTK_WIDGET (arrow), FALSE);
- gtk_misc_get_padding (GTK_MISC (arrow), &xpad, &ypad);
- GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + xpad * 2;
- GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + ypad * 2;
-
priv->arrow_type = GTK_ARROW_RIGHT;
priv->shadow_type = GTK_SHADOW_OUT;
}
+static void
+gtk_arrow_size_request_init (GtkSizeRequestIface *iface)
+{
+ iface->get_width = gtk_arrow_get_width;
+ iface->get_height = gtk_arrow_get_height;
+}
+
+static void
+gtk_arrow_get_width (GtkSizeRequest *widget,
+ gint *minimum_size,
+ gint *natural_size)
+{
+ gint xpad;
+
+ gtk_misc_get_padding (GTK_MISC (widget), &xpad, NULL);
+
+ if (minimum_size)
+ *minimum_size = MIN_ARROW_SIZE + xpad * 2;
+
+ if (natural_size)
+ *natural_size = MIN_ARROW_SIZE + xpad * 2;
+}
+
+static void
+gtk_arrow_get_height (GtkSizeRequest *widget,
+ gint *minimum_size,
+ gint *natural_size)
+{
+ gint ypad;
+
+ gtk_misc_get_padding (GTK_MISC (widget), NULL, &ypad);
+
+ if (minimum_size)
+ *minimum_size = MIN_ARROW_SIZE + ypad * 2;
+
+ if (natural_size)
+ *natural_size = MIN_ARROW_SIZE + ypad * 2;
+}
+
+
/**
* gtk_arrow_new:
* @arrow_type: a valid #GtkArrowType.
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 66b8c37bfc..3599fe0cb8 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -1408,7 +1408,6 @@ _gtk_container_queue_resize (GtkContainer *container)
while (TRUE)
{
GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
- GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
diff --git a/gtk/gtkfontsel.c b/gtk/gtkfontsel.c
index 24331b557c..50812d5bc2 100644
--- a/gtk/gtkfontsel.c
+++ b/gtk/gtkfontsel.c
@@ -58,8 +58,9 @@
#include "gtkscrolledwindow.h"
#include "gtkintl.h"
#include "gtkaccessible.h"
-#include "gtkprivate.h"
#include "gtkbuildable.h"
+#include "gtksizerequest.h"
+#include "gtkprivate.h"
struct _GtkFontSelectionPrivate
{
@@ -1168,7 +1169,7 @@ gtk_font_selection_update_preview (GtkFontSelection *fontsel)
GtkFontSelectionPrivate *priv = fontsel->priv;
GtkRcStyle *rc_style;
gint new_height;
- GtkRequisition old_requisition;
+ GtkRequisition old_requisition, new_requisition;
GtkWidget *preview_entry = priv->preview_entry;
const gchar *text;
@@ -1180,10 +1181,10 @@ gtk_font_selection_update_preview (GtkFontSelection *fontsel)
gtk_widget_modify_style (preview_entry, rc_style);
g_object_unref (rc_style);
- gtk_widget_size_request (preview_entry, NULL);
+ gtk_size_request_get_size (GTK_SIZE_REQUEST (preview_entry), &new_requisition, NULL);
/* We don't ever want to be over MAX_PREVIEW_HEIGHT pixels high. */
- new_height = CLAMP (preview_entry->requisition.height, INITIAL_PREVIEW_HEIGHT, MAX_PREVIEW_HEIGHT);
+ new_height = CLAMP (new_requisition.height, INITIAL_PREVIEW_HEIGHT, MAX_PREVIEW_HEIGHT);
if (new_height > old_requisition.height || new_height < old_requisition.height - 30)
gtk_widget_set_size_request (preview_entry, -1, new_height);
diff --git a/gtk/gtkhandlebox.c b/gtk/gtkhandlebox.c
index 3769b69568..add2d3b97a 100644
--- a/gtk/gtkhandlebox.c
+++ b/gtk/gtkhandlebox.c
@@ -32,6 +32,7 @@
#include "gtkmain.h"
#include "gtkmarshalers.h"
#include "gtkwindow.h"
+#include "gtksizerequest.h"
#include "gtkprivate.h"
#include "gtkintl.h"
@@ -406,6 +407,7 @@ gtk_handle_box_realize (GtkWidget *widget)
GtkHandleBoxPrivate *priv = hb->priv;
GtkWidget *child;
GdkWindowAttr attributes;
+ GtkRequisition requisition;
gint attributes_mask;
gtk_widget_set_realized (widget, TRUE);
@@ -443,10 +445,12 @@ gtk_handle_box_realize (GtkWidget *widget)
if (child)
gtk_widget_set_parent_window (child, priv->bin_window);
+ gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &requisition, NULL);
+
attributes.x = 0;
attributes.y = 0;
- attributes.width = widget->requisition.width;
- attributes.height = widget->requisition.height;
+ attributes.width = requisition.width;
+ attributes.height = requisition.height;
attributes.window_type = GDK_WINDOW_TOPLEVEL;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c
index 9e9ed3deef..c3f9254b40 100644
--- a/gtk/gtkiconview.c
+++ b/gtk/gtkiconview.c
@@ -39,6 +39,7 @@
#include "gtkentry.h"
#include "gtkcombobox.h"
#include "gtktextbuffer.h"
+#include "gtksizerequest.h"
#include "gtktreednd.h"
#include "gtkprivate.h"
@@ -2803,6 +2804,7 @@ gtk_icon_view_layout (GtkIconView *icon_view)
gint y = 0, maximum_width = 0;
GList *icons;
GtkWidget *widget;
+ GtkRequisition requisition;
gint row;
gint item_width;
@@ -2862,8 +2864,10 @@ gtk_icon_view_layout (GtkIconView *icon_view)
gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
icon_view->priv->height);
- if (icon_view->priv->width != widget->requisition.width ||
- icon_view->priv->height != widget->requisition.height)
+ gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &requisition, NULL);
+
+ if (icon_view->priv->width != requisition.width ||
+ icon_view->priv->height != requisition.height)
gtk_widget_queue_resize_no_redraw (widget);
if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index 004a36df57..2989b7214f 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -33,6 +33,7 @@
#include "gtkiconfactory.h"
#include "gtkstock.h"
#include "gtkicontheme.h"
+#include "gtksizerequest.h"
#include "gtkintl.h"
#include "gtkprivate.h"
@@ -150,6 +151,8 @@ struct _GtkImagePrivate
* only used with GTK_IMAGE_GICON, GTK_IMAGE_ICON_NAME */
gint pixel_size;
guint need_calc_size : 1;
+ gint required_width;
+ gint required_height;
};
@@ -1820,9 +1823,9 @@ gtk_image_expose (GtkWidget *widget,
xalign = 1.0 - xalign;
x = floor (widget->allocation.x + xpad
- + ((widget->allocation.width - widget->requisition.width) * xalign));
+ + ((widget->allocation.width - priv->required_width) * xalign));
y = floor (widget->allocation.y + ypad
- + ((widget->allocation.height - widget->requisition.height) * yalign));
+ + ((widget->allocation.height - priv->required_height) * yalign));
mask_x = x;
mask_y = y;
@@ -2230,7 +2233,7 @@ gtk_image_calc_size (GtkImage *image)
/* We update stock/icon set on every size request, because
* the theme could have affected the size; for other kinds of
- * image, we just update the requisition when the image data
+ * image, we just update the required width/height when the image data
* is set.
*/
switch (priv->storage_type)
@@ -2272,8 +2275,8 @@ gtk_image_calc_size (GtkImage *image)
gtk_misc_get_padding (GTK_MISC (image), &xpad, &ypad);
- widget->requisition.width = gdk_pixbuf_get_width (pixbuf) + xpad * 2;
- widget->requisition.height = gdk_pixbuf_get_height (pixbuf) + ypad * 2;
+ priv->required_width = gdk_pixbuf_get_width (pixbuf) + xpad * 2;
+ priv->required_height = gdk_pixbuf_get_height (pixbuf) + ypad * 2;
g_object_unref (pixbuf);
}
@@ -2284,13 +2287,15 @@ gtk_image_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
GtkImage *image;
+ GtkImagePrivate *priv;
image = GTK_IMAGE (widget);
+ priv = image->priv;
gtk_image_calc_size (image);
- /* Chain up to default that simply reads current requisition */
- GTK_WIDGET_CLASS (gtk_image_parent_class)->size_request (widget, requisition);
+ requisition->width = priv->required_width;
+ requisition->height = priv->required_height;
}
static void
@@ -2326,13 +2331,14 @@ gtk_image_update_size (GtkImage *image,
gint image_width,
gint image_height)
{
- GtkWidget *widget = GTK_WIDGET (image);
- gint xpad, ypad;
+ GtkWidget *widget = GTK_WIDGET (image);
+ GtkImagePrivate *priv = image->priv;
+ gint xpad, ypad;
gtk_misc_get_padding (GTK_MISC (image), &xpad, &ypad);
- widget->requisition.width = image_width + xpad * 2;
- widget->requisition.height = image_height + ypad * 2;
+ priv->required_width = image_width + xpad * 2;
+ priv->required_height = image_height + ypad * 2;
if (gtk_widget_get_visible (widget))
gtk_widget_queue_resize (widget);
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 17716f2b62..8e433f9797 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -2047,8 +2047,9 @@ gtk_menu_set_tearoff_hints (GtkMenu *menu,
if (gtk_widget_get_visible (menu->tearoff_scrollbar))
{
- gtk_widget_size_request (menu->tearoff_scrollbar, NULL);
- width += menu->tearoff_scrollbar->requisition.width;
+ GtkRequisition requisition;
+ gtk_widget_size_request (menu->tearoff_scrollbar, &requisition);
+ width += requisition.width;
}
geometry_hints.min_width = width;
diff --git a/gtk/gtkmisc.c b/gtk/gtkmisc.c
index 94d3052b61..1f5a9557bc 100644
--- a/gtk/gtkmisc.c
+++ b/gtk/gtkmisc.c
@@ -268,7 +268,6 @@ gtk_misc_set_padding (GtkMisc *misc,
gint ypad)
{
GtkMiscPrivate *priv;
- GtkRequisition *requisition;
g_return_if_fail (GTK_IS_MISC (misc));
@@ -288,16 +287,9 @@ gtk_misc_set_padding (GtkMisc *misc,
if (ypad != priv->ypad)
g_object_notify (G_OBJECT (misc), "ypad");
- requisition = &(GTK_WIDGET (misc)->requisition);
- requisition->width -= priv->xpad * 2;
- requisition->height -= priv->ypad * 2;
-
priv->xpad = xpad;
priv->ypad = ypad;
- requisition->width += priv->xpad * 2;
- requisition->height += priv->ypad * 2;
-
if (gtk_widget_is_drawable (GTK_WIDGET (misc)))
gtk_widget_queue_resize (GTK_WIDGET (misc));
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index 3c36f3814d..84379127ad 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -355,8 +355,6 @@ gtk_path_bar_size_request (GtkWidget *widget,
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
requisition->width += border_width * 2;
requisition->height += border_width * 2;
-
- widget->requisition = *requisition;
}
static void
diff --git a/gtk/gtkprivate.h b/gtk/gtkprivate.h
index 8db5c48518..e4505420fc 100644
--- a/gtk/gtkprivate.h
+++ b/gtk/gtkprivate.h
@@ -47,9 +47,8 @@ typedef enum
PRIVATE_GTK_CHILD_VISIBLE = 1 << 10, /* If widget should be mapped when parent is mapped */
PRIVATE_GTK_REDRAW_ON_ALLOC = 1 << 11, /* If we should queue a draw on the entire widget when it is reallocated */
PRIVATE_GTK_ALLOC_NEEDED = 1 << 12, /* If we we should allocate even if the allocation is the same */
- PRIVATE_GTK_REQUEST_NEEDED = 1 << 13, /* Whether we need to call gtk_widget_size_request */
- PRIVATE_GTK_WIDTH_REQUEST_NEEDED = 1 << 14, /* Whether we need to call gtk_extended_layout_get_desired_width */
- PRIVATE_GTK_HEIGHT_REQUEST_NEEDED = 1 << 15 /* Whether we need to call gtk_extended_layout_get_desired_height */
+ PRIVATE_GTK_WIDTH_REQUEST_NEEDED = 1 << 13, /* Whether we need to call gtk_extended_layout_get_desired_width */
+ PRIVATE_GTK_HEIGHT_REQUEST_NEEDED = 1 << 14 /* Whether we need to call gtk_extended_layout_get_desired_height */
} GtkPrivateFlags;
/* Macros for extracting a widgets private_flags from GtkWidget.
@@ -67,7 +66,6 @@ typedef enum
#define GTK_WIDGET_CHILD_VISIBLE(obj) ((GTK_PRIVATE_FLAGS (obj) & PRIVATE_GTK_CHILD_VISIBLE) != 0)
#define GTK_WIDGET_REDRAW_ON_ALLOC(obj) ((GTK_PRIVATE_FLAGS (obj) & PRIVATE_GTK_REDRAW_ON_ALLOC) != 0)
#define GTK_WIDGET_ALLOC_NEEDED(obj) ((GTK_PRIVATE_FLAGS (obj) & PRIVATE_GTK_ALLOC_NEEDED) != 0)
-#define GTK_WIDGET_REQUEST_NEEDED(obj) ((GTK_PRIVATE_FLAGS (obj) & PRIVATE_GTK_REQUEST_NEEDED) != 0)
#define GTK_WIDGET_WIDTH_REQUEST_NEEDED(obj) ((GTK_PRIVATE_FLAGS (obj) & PRIVATE_GTK_WIDTH_REQUEST_NEEDED) != 0)
#define GTK_WIDGET_HEIGHT_REQUEST_NEEDED(obj) ((GTK_PRIVATE_FLAGS (obj) & PRIVATE_GTK_HEIGHT_REQUEST_NEEDED) != 0)
diff --git a/gtk/gtkruler.c b/gtk/gtkruler.c
index eff3bfe824..95aba88dea 100644
--- a/gtk/gtkruler.c
+++ b/gtk/gtkruler.c
@@ -189,7 +189,6 @@ gtk_ruler_class_init (GtkRulerClass *class)
static void
gtk_ruler_init (GtkRuler *ruler)
{
- GtkWidget *widget = GTK_WIDGET (ruler);
GtkRulerPrivate *priv;
ruler->priv = G_TYPE_INSTANCE_GET_PRIVATE (ruler,
@@ -199,9 +198,6 @@ gtk_ruler_init (GtkRuler *ruler)
priv->orientation = GTK_ORIENTATION_HORIZONTAL;
- widget->requisition.width = widget->style->xthickness * 2 + 1;
- widget->requisition.height = widget->style->ythickness * 2 + RULER_WIDTH;
-
priv->backing_store = NULL;
priv->xsrc = 0;
priv->ysrc = 0;
diff --git a/gtk/gtkseparator.c b/gtk/gtkseparator.c
index 43f9ae5c9b..927bfef9eb 100644
--- a/gtk/gtkseparator.c
+++ b/gtk/gtkseparator.c
@@ -95,7 +95,6 @@ gtk_separator_class_init (GtkSeparatorClass *class)
static void
gtk_separator_init (GtkSeparator *separator)
{
- GtkWidget *widget = GTK_WIDGET (separator);
GtkSeparatorPrivate *private;
separator->priv = G_TYPE_INSTANCE_GET_PRIVATE (separator,
@@ -106,9 +105,6 @@ gtk_separator_init (GtkSeparator *separator)
gtk_widget_set_has_window (GTK_WIDGET (separator), FALSE);
private->orientation = GTK_ORIENTATION_HORIZONTAL;
-
- widget->requisition.width = 1;
- widget->requisition.height = widget->style->ythickness;
}
static void
diff --git a/gtk/gtksizegroup.c b/gtk/gtksizegroup.c
index 87f5c48584..59ddc6e985 100644
--- a/gtk/gtksizegroup.c
+++ b/gtk/gtksizegroup.c
@@ -187,7 +187,6 @@ real_queue_resize (GtkWidget *widget)
GtkWidget *parent;
GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
- GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
diff --git a/gtk/gtksizerequest.c b/gtk/gtksizerequest.c
index 77f99c40d8..4af24144f5 100644
--- a/gtk/gtksizerequest.c
+++ b/gtk/gtksizerequest.c
@@ -196,18 +196,14 @@ get_cache (GtkSizeRequest *widget,
return cache;
}
-
static void
-do_size_request (GtkWidget *widget)
+do_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
{
- if (GTK_WIDGET_REQUEST_NEEDED (widget))
- {
- gtk_widget_ensure_style (widget);
- GTK_PRIVATE_UNSET_FLAG (widget, GTK_REQUEST_NEEDED);
- g_signal_emit_by_name (widget,
- "size-request",
- &widget->requisition);
- }
+ /* Now we dont bother caching the deprecated "size-request" returns,
+ * just unconditionally invoke here just in case we run into legacy stuff */
+ gtk_widget_ensure_style (widget);
+ g_signal_emit_by_name (widget, "size-request", requisition);
}
static void
@@ -255,15 +251,16 @@ compute_size_for_orientation (GtkSizeRequest *request,
if (!found_in_cache)
{
+ GtkRequisition requisition = { 0, 0 };
gint min_size = 0, nat_size = 0;
gint group_size, requisition_size;
/* Unconditional size request runs but is often unhandled. */
- do_size_request (widget);
+ do_size_request (widget, &requisition);
if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
{
- requisition_size = widget->requisition.width;
+ requisition_size = requisition.width;
if (for_size < 0)
GTK_SIZE_REQUEST_GET_IFACE (request)->get_width (request, &min_size, &nat_size);
@@ -273,7 +270,7 @@ compute_size_for_orientation (GtkSizeRequest *request,
}
else
{
- requisition_size = widget->requisition.height;
+ requisition_size = requisition.height;
if (for_size < 0)
GTK_SIZE_REQUEST_GET_IFACE (request)->get_height (request, &min_size, &nat_size);
@@ -288,9 +285,8 @@ compute_size_for_orientation (GtkSizeRequest *request,
G_OBJECT_TYPE_NAME (request), request, min_size, nat_size);
}
- /* Support for dangling "size-request" signals and forward derived
- * classes that will not default to a ->get_width() that
- * returns the values in the ->requisition cache.
+ /* Support for dangling "size-request" signal implementations on
+ * legacy widgets
*/
min_size = MAX (min_size, requisition_size);
nat_size = MAX (nat_size, requisition_size);
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index 649b0daf6b..5cc2ba0246 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -40,6 +40,7 @@
#include "gtkmain.h"
#include "gtkmarshalers.h"
#include "gtksettings.h"
+#include "gtksizerequest.h"
#include "gtkprivate.h"
#include "gtkintl.h"
@@ -582,12 +583,15 @@ gtk_spin_button_realize (GtkWidget *widget)
GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
GtkSpinButtonPrivate *priv = spin_button->priv;
GdkWindowAttr attributes;
+ GtkRequisition requisition;
gint attributes_mask;
gboolean return_val;
gint arrow_size;
arrow_size = spin_button_get_arrow_size (spin_button);
+ gtk_size_request_get_size (GTK_SIZE_REQUEST (spin_button), &requisition, NULL);
+
gtk_widget_set_events (widget, gtk_widget_get_events (widget) |
GDK_KEY_RELEASE_MASK);
GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->realize (widget);
@@ -605,10 +609,9 @@ gtk_spin_button_realize (GtkWidget *widget)
attributes.x = (widget->allocation.width - arrow_size -
2 * widget->style->xthickness);
- attributes.y = (widget->allocation.height -
- widget->requisition.height) / 2;
+ attributes.y = (widget->allocation.height - requisition.height) / 2;
attributes.width = arrow_size + 2 * widget->style->xthickness;
- attributes.height = widget->requisition.height;
+ attributes.height = requisition.height;
priv->panel = gdk_window_new (widget->window,
&attributes, attributes_mask);
@@ -736,6 +739,7 @@ gtk_spin_button_size_allocate (GtkWidget *widget,
{
GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
GtkSpinButtonPrivate *priv = spin->priv;
+ GtkRequisition requisition;
GtkAllocation panel_allocation;
gint arrow_size;
gint panel_width;
@@ -743,6 +747,8 @@ gtk_spin_button_size_allocate (GtkWidget *widget,
arrow_size = spin_button_get_arrow_size (spin);
panel_width = arrow_size + 2 * widget->style->xthickness;
+ gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &requisition, NULL);
+
widget->allocation = *allocation;
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
@@ -751,7 +757,7 @@ gtk_spin_button_size_allocate (GtkWidget *widget,
panel_allocation.x = allocation->width - panel_width;
panel_allocation.width = panel_width;
- panel_allocation.height = MIN (widget->requisition.height, allocation->height);
+ panel_allocation.height = MIN (requisition.height, allocation->height);
panel_allocation.y = 0;
@@ -858,21 +864,25 @@ gtk_spin_button_draw_arrow (GtkSpinButton *spin_button,
if (gtk_widget_is_drawable (widget))
{
+ GtkRequisition requisition;
+
width = spin_button_get_arrow_size (spin_button) + 2 * widget->style->xthickness;
+ gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &requisition, NULL);
+
if (arrow_type == GTK_ARROW_UP)
{
x = 0;
y = 0;
- height = widget->requisition.height / 2;
+ height = requisition.height / 2;
}
else
{
x = 0;
- y = widget->requisition.height / 2;
+ y = requisition.height / 2;
- height = (widget->requisition.height + 1) / 2;
+ height = (requisition.height + 1) / 2;
}
if (spin_button_at_limit (spin_button, arrow_type))
@@ -909,7 +919,7 @@ gtk_spin_button_draw_arrow (GtkSpinButton *spin_button,
(arrow_type == GTK_ARROW_UP)? "spinbutton_up" : "spinbutton_down",
x, y, width, height);
- height = widget->requisition.height;
+ height = requisition.height;
if (arrow_type == GTK_ARROW_DOWN)
{
@@ -953,6 +963,7 @@ gtk_spin_button_enter_notify (GtkWidget *widget,
{
GtkSpinButton *spin = GTK_SPIN_BUTTON (widget);
GtkSpinButtonPrivate *priv = spin->priv;
+ GtkRequisition requisition;
if (event->window == priv->panel)
{
@@ -963,7 +974,9 @@ gtk_spin_button_enter_notify (GtkWidget *widget,
device = gdk_event_get_device ((GdkEvent *) event);
gdk_window_get_device_position (priv->panel, device, &x, &y, NULL);
- if (y <= widget->requisition.height / 2)
+ gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &requisition, NULL);
+
+ if (y <= requisition.height / 2)
priv->in_child = GTK_ARROW_UP;
else
priv->in_child = GTK_ARROW_DOWN;
@@ -1132,6 +1145,8 @@ gtk_spin_button_button_press (GtkWidget *widget,
{
if (event->window == priv->panel)
{
+ GtkRequisition requisition;
+
if (!gtk_widget_has_focus (widget))
gtk_widget_grab_focus (widget);
priv->button = event->button;
@@ -1139,7 +1154,9 @@ gtk_spin_button_button_press (GtkWidget *widget,
if (GTK_ENTRY (widget)->editable)
gtk_spin_button_update (spin);
- if (event->y <= widget->requisition.height / 2)
+ gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &requisition, NULL);
+
+ if (event->y <= requisition.height / 2)
{
if (event->button == 1)
start_spinning (spin, GTK_ARROW_UP, priv->adjustment->step_increment);
@@ -1183,12 +1200,16 @@ gtk_spin_button_button_release (GtkWidget *widget,
if (event->button == 3)
{
+ GtkRequisition requisition;
+
+ gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &requisition, NULL);
+
if (event->y >= 0 && event->x >= 0 &&
- event->y <= widget->requisition.height &&
+ event->y <= requisition.height &&
event->x <= arrow_size + 2 * widget->style->xthickness)
{
if (click_child == GTK_ARROW_UP &&
- event->y <= widget->requisition.height / 2)
+ event->y <= requisition.height / 2)
{
gdouble diff;
@@ -1197,7 +1218,7 @@ gtk_spin_button_button_release (GtkWidget *widget,
gtk_spin_button_real_spin (spin, diff);
}
else if (click_child == GTK_ARROW_DOWN &&
- event->y > widget->requisition.height / 2)
+ event->y > requisition.height / 2)
{
gdouble diff;
@@ -1228,16 +1249,19 @@ gtk_spin_button_motion_notify (GtkWidget *widget,
if (event->window == priv->panel)
{
gint y = event->y;
+ GtkRequisition requisition;
gdk_event_request_motions (event);
-
- if (y <= widget->requisition.height / 2 &&
+
+ gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &requisition, NULL);
+
+ if (y <= requisition.height / 2 &&
priv->in_child == GTK_ARROW_DOWN)
{
priv->in_child = GTK_ARROW_UP;
gtk_widget_queue_draw (GTK_WIDGET (spin));
}
- else if (y > widget->requisition.height / 2 &&
+ else if (y > requisition.height / 2 &&
priv->in_child == GTK_ARROW_UP)
{
priv->in_child = GTK_ARROW_DOWN;
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 050aebbb25..e79dec917a 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -40,6 +40,7 @@
#include "gtkseparatormenuitem.h"
#include "gtksettings.h"
#include "gtkstock.h"
+#include "gtksizerequest.h"
#include "gtktextbufferrichtext.h"
#include "gtktextdisplay.h"
#include "gtktextview.h"
@@ -3933,7 +3934,7 @@ changed_handler (GtkTextLayout *layout,
GtkRequisition old_req;
GtkRequisition new_req;
- old_req = widget->requisition;
+ gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &old_req, NULL);
/* Use this instead of gtk_widget_size_request wrapper
* to avoid the optimization which just returns widget->requisition
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index a9da909b36..8e370bcc21 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -43,6 +43,7 @@
#include "gtkframe.h"
#include "gtktreemodelsort.h"
#include "gtktooltip.h"
+#include "gtksizerequest.h"
#include "gtkprivate.h"
#define GTK_TREE_VIEW_PRIORITY_VALIDATE (GDK_PRIORITY_REDRAW + 5)
@@ -5323,8 +5324,11 @@ gtk_tree_view_key_press (GtkWidget *widget,
if (event->keyval == (rtl ? GDK_Right : GDK_Left)
|| event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
{
+ GtkRequisition button_req;
gint old_width = column->resized_width;
+ gtk_size_request_get_size (GTK_SIZE_REQUEST (column->button), &button_req, NULL);
+
column->resized_width = MAX (column->resized_width,
column->width);
column->resized_width -= 2;
@@ -5332,7 +5336,7 @@ gtk_tree_view_key_press (GtkWidget *widget,
column->resized_width = 0;
if (column->min_width == -1)
- column->resized_width = MAX (column->button->requisition.width,
+ column->resized_width = MAX (button_req.width,
column->resized_width);
else
column->resized_width = MAX (column->min_width,
@@ -10486,6 +10490,7 @@ gtk_tree_view_new_column_width (GtkTreeView *tree_view,
gint *x)
{
GtkTreeViewColumn *column;
+ GtkRequisition button_req;
gint width;
gboolean rtl;
@@ -10498,8 +10503,10 @@ gtk_tree_view_new_column_width (GtkTreeView *tree_view,
/* Clamp down the value */
if (column->min_width == -1)
- width = MAX (column->button->requisition.width,
- width);
+ {
+ gtk_size_request_get_size (GTK_SIZE_REQUEST (column->button), &button_req, NULL);
+ width = MAX (button_req.width, width);
+ }
else
width = MAX (column->min_width,
width);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 6f34ec1b39..628dc9207f 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -2856,8 +2856,6 @@ gtk_widget_init (GtkWidget *widget)
widget->state = GTK_STATE_NORMAL;
widget->saved_state = GTK_STATE_NORMAL;
widget->name = NULL;
- widget->requisition.width = 0;
- widget->requisition.height = 0;
widget->allocation.x = -1;
widget->allocation.y = -1;
widget->allocation.width = 1;
@@ -2871,7 +2869,6 @@ gtk_widget_init (GtkWidget *widget)
gtk_widget_set_double_buffered (widget, TRUE);
GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
- GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
@@ -3783,12 +3780,6 @@ gtk_widget_size_request (GtkWidget *widget,
{
g_return_if_fail (GTK_IS_WIDGET (widget));
-#ifdef G_ENABLE_DEBUG
- if (requisition == &widget->requisition)
- g_warning ("gtk_widget_size_request() called on child widget with request equal\n"
- "to widget->requisition. gtk_widget_set_usize() may not work properly.");
-#endif /* G_ENABLE_DEBUG */
-
gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
}
@@ -3927,7 +3918,8 @@ gtk_widget_size_allocate (GtkWidget *widget,
#endif /* G_ENABLE_DEBUG */
alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
- if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
+ if (!GTK_WIDGET_WIDTH_REQUEST_NEEDED (widget) &&
+ !GTK_WIDGET_HEIGHT_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
old_allocation = widget->allocation;
@@ -8887,8 +8879,8 @@ static void
gtk_widget_real_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
- requisition->width = widget->requisition.width;
- requisition->height = widget->requisition.height;
+ requisition->width = 0;
+ requisition->height = 0;
}
/**
@@ -10809,14 +10801,11 @@ gtk_widget_real_get_width (GtkSizeRequest *widget,
gint *minimum_size,
gint *natural_size)
{
- /* Set the initial values so that unimplemented classes will fall back
- * on the "size-request" collected values (see gtksizegroup.c:do_size_request()).
- */
if (minimum_size)
- *minimum_size = GTK_WIDGET (widget)->requisition.width;
+ *minimum_size = 0;
if (natural_size)
- *natural_size = GTK_WIDGET (widget)->requisition.width;
+ *natural_size = 0;
}
static void
@@ -10824,14 +10813,11 @@ gtk_widget_real_get_height (GtkSizeRequest *widget,
gint *minimum_size,
gint *natural_size)
{
- /* Set the initial values so that unimplemented classes will fall back
- * on the "size-request" collected values (see gtksizegroup.c:do_size_request()).
- */
if (minimum_size)
- *minimum_size = GTK_WIDGET (widget)->requisition.height;
+ *minimum_size = 0;
if (natural_size)
- *natural_size = GTK_WIDGET (widget)->requisition.height;
+ *natural_size = 0;
}
static void
@@ -11373,6 +11359,10 @@ gtk_widget_set_allocation (GtkWidget *widget,
* Normally, gtk_widget_size_request() should be used.
*
* Since: 2.20
+ *
+ * Deprecated: 3.0: The #GtkRequisition cache on the widget was
+ * removed, If you need to cache sizes across requests and allocations,
+ * add an explicit cache to the widget in question instead.
*/
void
gtk_widget_get_requisition (GtkWidget *widget,
@@ -11381,7 +11371,7 @@ gtk_widget_get_requisition (GtkWidget *widget,
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (requisition != NULL);
- *requisition = widget->requisition;
+ gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
}
/**
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 4b35ca3b2d..e07ebd5193 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -294,10 +294,6 @@ struct _GtkWidget
*/
GtkStyle *GSEAL (style);
- /* The widget's desired size.
- */
- GtkRequisition GSEAL (requisition);
-
/* The widget's allocated size.
*/
GtkAllocation GSEAL (allocation);