#include "gtkmain.h"
#include "gtkmarshalers.h"
#include "gtksizerequest.h"
+#include "gtksizerequestcacheprivate.h"
#include "gtkwidgetprivate.h"
#include "gtkwindow.h"
#include "gtkassistant.h"
guint has_focus_chain : 1;
guint reallocate_redraws : 1;
guint resize_pending : 1;
+ guint restyle_pending : 1;
guint resize_mode : 2;
guint request_mode : 2;
};
static const gchar hadjustment_key[] = "gtk-hadjustment";
static guint hadjustment_key_id = 0;
static GSList *container_resize_queue = NULL;
+static GSList *container_restyle_queue = NULL;
static guint container_signals[LAST_SIGNAL] = { 0 };
static GtkWidgetClass *parent_class = NULL;
extern GParamSpecPool *_gtk_widget_child_property_pool;
if (priv->resize_pending)
_gtk_container_dequeue_resize_handler (container);
+ if (priv->restyle_pending)
+ {
+ container_restyle_queue = g_slist_remove (container_restyle_queue, container);
+ priv->restyle_pending = FALSE;
+ }
if (priv->focus_child)
{
GSList *slist;
gint64 current_time;
- /* we may be invoked with a container_resize_queue of NULL, because
- * queue_resize could have been adding an extra idle function while
- * the queue still got processed. we better just ignore such case
- * than trying to explicitely work around them with some extra flags,
- * since it doesn't cause any actual harm.
- */
-
/* We validate the style contexts in a single loop before even trying
* to handle resizes instead of doing validations inline.
* This is mostly necessary for compatibility reasons with old code,
- * because size_allocate functions often change styles and so could
- * cause infinite loops in this function.
+ * because both style_updated and size_allocate functions often change
+ * styles and so could cause infinite loops in this function.
+ *
+ * It's important to note that even an invalid style context returns
+ * sane values. So the result of an invalid style context will never be
+ * a program crash, but only a wrong layout or rendering.
*/
current_time = g_get_monotonic_time ();
- for (slist = container_resize_queue; slist; slist = slist->next)
+ slist = container_restyle_queue;
+ container_restyle_queue = NULL;
+ while (slist)
{
- _gtk_style_context_validate (gtk_widget_get_style_context (slist->data),
+ GSList *next = slist->next;
+ GtkContainer *container = slist->data;
+ GtkBitmask *empty;
+
+ empty = _gtk_bitmask_new ();
+
+ container->priv->restyle_pending = FALSE;
+ _gtk_style_context_validate (gtk_widget_get_style_context (GTK_WIDGET (container)),
current_time,
- 0);
+ 0,
+ empty);
+
+ g_slist_free_1 (slist);
+ slist = next;
+ _gtk_bitmask_free (empty);
}
+ /* we may be invoked with a container_resize_queue of NULL, because
+ * queue_resize could have been adding an extra idle function while
+ * the queue still got processed. we better just ignore such case
+ * than trying to explicitely work around them with some extra flags,
+ * since it doesn't cause any actual harm.
+ */
while (container_resize_queue)
{
GtkContainer *container;
gdk_window_process_all_updates ();
- return FALSE;
+ return container_resize_queue != NULL || container_restyle_queue != NULL;
}
-void
-_gtk_container_queue_resize_handler (GtkContainer *container)
+static void
+gtk_container_start_idle_sizer (GtkContainer *container)
+{
+ /* already started */
+ if (container_resize_queue != NULL ||
+ container_restyle_queue != NULL)
+ return;
+
+ gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE,
+ gtk_container_idle_sizer,
+ NULL, NULL);
+}
+
+static void
+gtk_container_queue_resize_handler (GtkContainer *container)
{
GtkWidget *widget;
if (!container->priv->resize_pending)
{
container->priv->resize_pending = TRUE;
- if (container_resize_queue == NULL)
- gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE,
- gtk_container_idle_sizer,
- NULL, NULL);
+ gtk_container_start_idle_sizer (container);
container_resize_queue = g_slist_prepend (container_resize_queue, container);
}
break;
case GTK_RESIZE_IMMEDIATE:
- _gtk_style_context_validate (gtk_widget_get_style_context (widget),
- g_get_monotonic_time (),
- 0);
gtk_container_check_resize (container);
+ break;
case GTK_RESIZE_PARENT:
default:
do
{
_gtk_widget_set_alloc_needed (widget, TRUE);
- _gtk_widget_set_width_request_needed (widget, TRUE);
- _gtk_widget_set_height_request_needed (widget, TRUE);
+ _gtk_size_request_cache_clear (_gtk_widget_peek_request_cache (widget));
if (GTK_IS_RESIZE_CONTAINER (widget))
break;
while (widget);
if (widget && !invalidate_only)
- _gtk_container_queue_resize_handler (GTK_CONTAINER (widget));
+ gtk_container_queue_resize_handler (GTK_CONTAINER (widget));
+}
+
+void
+_gtk_container_queue_restyle (GtkContainer *container)
+{
+ GtkContainerPrivate *priv;
+
+ g_return_if_fail (GTK_CONTAINER (container));
+
+ priv = container->priv;
+
+ if (priv->restyle_pending)
+ return;
+
+ gtk_container_start_idle_sizer (container);
+
+ container_restyle_queue = g_slist_prepend (container_restyle_queue, container);
+ priv->restyle_pending = TRUE;
}
/**
container = GTK_CONTAINER (widget);
- if (!GTK_CONTAINER_GET_CLASS (widget)->_handle_border_width)
+ if (GTK_CONTAINER_GET_CLASS (widget)->_handle_border_width)
{
- parent_class->adjust_size_allocation (widget, orientation,
- minimum_size, natural_size, allocated_pos,
- allocated_size);
- return;
- }
-
- border_width = container->priv->border_width;
-
- *allocated_size -= border_width * 2;
-
- /* If we get a pathological too-small allocation to hold
- * even the border width, leave all allocation to the actual
- * widget, and leave x,y unchanged. (GtkWidget's min size is
- * 1x1 if you're wondering why <1 and not <0)
- *
- * As long as we have space, set x,y properly.
- */
+ border_width = container->priv->border_width;
- if (*allocated_size < 1)
- {
- *allocated_size += border_width * 2;
- }
- else
- {
+ *allocated_size -= border_width * 2;
*allocated_pos += border_width;
*minimum_size -= border_width * 2;
*natural_size -= border_width * 2;
static GtkSizeRequestMode
gtk_container_get_request_mode (GtkWidget *widget)
{
- GtkContainer *container = GTK_CONTAINER (widget);
- GtkContainerPrivate *priv = container->priv;
-
- /* Recalculate the request mode of the children by majority
- * vote whenever the internal content changes */
- if (_gtk_widget_get_width_request_needed (widget) ||
- _gtk_widget_get_height_request_needed (widget))
- {
- RequestModeCount count = { 0, 0 };
+ GtkContainer *container = GTK_CONTAINER (widget);
+ RequestModeCount count = { 0, 0 };
- gtk_container_forall (container, (GtkCallback)count_request_modes, &count);
+ gtk_container_forall (container, (GtkCallback)count_request_modes, &count);
- if (!count.hfw && !count.wfh)
- priv->request_mode = GTK_SIZE_REQUEST_CONSTANT_SIZE;
- else
- priv->request_mode = count.wfh > count.hfw ?
- GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT :
- GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
- }
-
- return priv->request_mode;
+ if (!count.hfw && !count.wfh)
+ return GTK_SIZE_REQUEST_CONSTANT_SIZE;
+ else
+ return count.wfh > count.hfw ?
+ GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT :
+ GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
}
/**