X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkcontainer.c;h=ce16fe4df42e224471754b0886415b08b200e474;hb=50065b7ba07fe08f5c71e42101fedf5b6e810982;hp=88f79b394e30e63b52920255411d83d9424f2e4b;hpb=9d0febc9a64a5bfb0fcfc3a88de4757f6c1ff090;p=~andy%2Fgtk diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c index 88f79b394..ce16fe4df 100644 --- a/gtk/gtkcontainer.c +++ b/gtk/gtkcontainer.c @@ -34,6 +34,7 @@ #include #include +#include "gtkadjustment.h" #include "gtkbuildable.h" #include "gtkbuilderprivate.h" #include "gtktypebuiltins.h" @@ -41,10 +42,13 @@ #include "gtkmain.h" #include "gtkmarshalers.h" #include "gtksizerequest.h" +#include "gtksizerequestcacheprivate.h" #include "gtkwidgetprivate.h" #include "gtkwindow.h" #include "gtkassistant.h" #include "gtkintl.h" +#include "gtkstylecontextprivate.h" +#include "gtkwidgetpath.h" #include "a11y/gtkcontaineraccessible.h" /** @@ -232,11 +236,15 @@ struct _GtkContainerPrivate { GtkWidget *focus_child; + guint resize_handler; + GdkFrameClock *resize_clock; + guint border_width : 16; guint has_focus_chain : 1; - guint need_resize : 1; guint reallocate_redraws : 1; + guint resize_pending : 1; + guint restyle_pending : 1; guint resize_mode : 2; guint request_mode : 2; }; @@ -339,7 +347,6 @@ static const gchar vadjustment_key[] = "gtk-vadjustment"; static guint vadjustment_key_id = 0; static const gchar hadjustment_key[] = "gtk-hadjustment"; static guint hadjustment_key_id = 0; -static GSList *container_resize_queue = NULL; static guint container_signals[LAST_SIGNAL] = { 0 }; static GtkWidgetClass *parent_class = NULL; extern GParamSpecPool *_gtk_widget_child_property_pool; @@ -1339,7 +1346,6 @@ gtk_container_init (GtkContainer *container) priv->focus_child = NULL; priv->border_width = 0; - priv->need_resize = FALSE; priv->resize_mode = GTK_RESIZE_PARENT; priv->reallocate_redraws = FALSE; } @@ -1350,9 +1356,12 @@ gtk_container_destroy (GtkWidget *widget) GtkContainer *container = GTK_CONTAINER (widget); GtkContainerPrivate *priv = container->priv; - if (_gtk_widget_get_resize_pending (GTK_WIDGET (container))) + if (priv->resize_pending) _gtk_container_dequeue_resize_handler (container); + if (priv->restyle_pending) + priv->restyle_pending = FALSE; + if (priv->focus_child) { g_object_unref (priv->focus_child); @@ -1541,10 +1550,9 @@ void _gtk_container_dequeue_resize_handler (GtkContainer *container) { g_return_if_fail (GTK_IS_CONTAINER (container)); - g_return_if_fail (_gtk_widget_get_resize_pending (GTK_WIDGET (container))); + g_return_if_fail (container->priv->resize_pending); - container_resize_queue = g_slist_remove (container_resize_queue, container); - _gtk_widget_set_resize_pending (GTK_WIDGET (container), FALSE); + container->priv->resize_pending = FALSE; } /** @@ -1620,115 +1628,166 @@ gtk_container_set_reallocate_redraws (GtkContainer *container, container->priv->reallocate_redraws = needs_redraws ? TRUE : FALSE; } -static GtkContainer* -gtk_container_get_resize_container (GtkContainer *container) -{ - GtkWidget *parent; - GtkWidget *widget = GTK_WIDGET (container); - - while ((parent = gtk_widget_get_parent (widget))) +static void +gtk_container_idle_sizer (GdkFrameClock *clock, + GtkContainer *container) +{ + /* 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 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. + */ + if (container->priv->restyle_pending) { - widget = parent; - if (GTK_IS_RESIZE_CONTAINER (widget)) - break; - } + GtkBitmask *empty; + gint64 current_time; - return GTK_IS_RESIZE_CONTAINER (widget) ? (GtkContainer*) widget : NULL; -} + empty = _gtk_bitmask_new (); + current_time = g_get_monotonic_time (); + + container->priv->restyle_pending = FALSE; + _gtk_style_context_validate (gtk_widget_get_style_context (GTK_WIDGET (container)), + current_time, + 0, + empty); + + _gtk_bitmask_free (empty); + } -static gboolean -gtk_container_idle_sizer (gpointer data) -{ /* 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) + if (container->priv->resize_pending) { - GSList *slist; - GtkWidget *widget; - - slist = container_resize_queue; - container_resize_queue = slist->next; - widget = slist->data; - g_slist_free_1 (slist); + container->priv->resize_pending = FALSE; + gtk_container_check_resize (container); + } - _gtk_widget_set_resize_pending (widget, FALSE); - gtk_container_check_resize (GTK_CONTAINER (widget)); + if (!container->priv->restyle_pending && !container->priv->resize_pending) + { + _gtk_container_stop_idle_sizer (container); + } + else + { + gdk_frame_clock_request_phase (clock, + GDK_FRAME_CLOCK_PHASE_LAYOUT); } +} - gdk_window_process_all_updates (); +static void +gtk_container_start_idle_sizer (GtkContainer *container) +{ + GdkFrameClock *clock; - return FALSE; + if (container->priv->resize_handler != 0) + return; + + clock = gtk_widget_get_frame_clock (GTK_WIDGET (container)); + if (clock == NULL) + return; + + container->priv->resize_clock = clock; + container->priv->resize_handler = g_signal_connect (clock, "layout", + G_CALLBACK (gtk_container_idle_sizer), container); + gdk_frame_clock_request_phase (clock, + GDK_FRAME_CLOCK_PHASE_LAYOUT); +} + +void +_gtk_container_stop_idle_sizer (GtkContainer *container) +{ + if (container->priv->resize_handler == 0) + return; + + g_signal_handler_disconnect (container->priv->resize_clock, + container->priv->resize_handler); + container->priv->resize_handler = 0; + container->priv->resize_clock = NULL; +} + +static void +gtk_container_queue_resize_handler (GtkContainer *container) +{ + GtkWidget *widget; + + g_return_if_fail (GTK_IS_RESIZE_CONTAINER (container)); + + widget = GTK_WIDGET (container); + + if (gtk_widget_get_visible (widget) && + (gtk_widget_is_toplevel (widget) || + gtk_widget_get_realized (widget))) + { + switch (container->priv->resize_mode) + { + case GTK_RESIZE_QUEUE: + if (!container->priv->resize_pending) + { + container->priv->resize_pending = TRUE; + gtk_container_start_idle_sizer (container); + } + break; + + case GTK_RESIZE_IMMEDIATE: + gtk_container_check_resize (container); + break; + + case GTK_RESIZE_PARENT: + default: + g_assert_not_reached (); + break; + } + } } static void _gtk_container_queue_resize_internal (GtkContainer *container, gboolean invalidate_only) { - GtkContainer *resize_container; - GtkWidget *parent; GtkWidget *widget; g_return_if_fail (GTK_IS_CONTAINER (container)); widget = GTK_WIDGET (container); - resize_container = gtk_container_get_resize_container (container); - - while (TRUE) + 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 ((resize_container && widget == GTK_WIDGET (resize_container)) || - !(parent = gtk_widget_get_parent (widget))) + if (GTK_IS_RESIZE_CONTAINER (widget)) break; - widget = parent; + widget = gtk_widget_get_parent (widget); } + while (widget); - if (resize_container && !invalidate_only) - { - if (gtk_widget_get_visible (GTK_WIDGET (resize_container)) && - (gtk_widget_is_toplevel (GTK_WIDGET (resize_container)) || - gtk_widget_get_realized (GTK_WIDGET (resize_container)))) - { - switch (resize_container->priv->resize_mode) - { - case GTK_RESIZE_QUEUE: - if (!_gtk_widget_get_resize_pending (GTK_WIDGET (resize_container))) - { - _gtk_widget_set_resize_pending (GTK_WIDGET (resize_container), TRUE); - if (container_resize_queue == NULL) - gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE, - gtk_container_idle_sizer, - NULL, NULL); - container_resize_queue = g_slist_prepend (container_resize_queue, resize_container); - } - break; + if (widget && !invalidate_only) + gtk_container_queue_resize_handler (GTK_CONTAINER (widget)); +} - case GTK_RESIZE_IMMEDIATE: - gtk_container_check_resize (resize_container); - break; +void +_gtk_container_queue_restyle (GtkContainer *container) +{ + GtkContainerPrivate *priv; - case GTK_RESIZE_PARENT: - g_assert_not_reached (); - break; - } - } - else - { - /* we need to let hidden resize containers know that something - * changed while they where hidden (currently only evaluated by - * toplevels). - */ - resize_container->priv->need_resize = TRUE; - } - } + g_return_if_fail (GTK_CONTAINER (container)); + + priv = container->priv; + + if (priv->restyle_pending) + return; + + gtk_container_start_idle_sizer (container); + priv->restyle_pending = TRUE; } /** @@ -1761,6 +1820,13 @@ _gtk_container_resize_invalidate (GtkContainer *container) _gtk_container_queue_resize_internal (container, TRUE); } +void +_gtk_container_maybe_start_idle_sizer (GtkContainer *container) +{ + if (container->priv->restyle_pending || container->priv->resize_pending) + gtk_container_start_idle_sizer (container); +} + void gtk_container_check_resize (GtkContainer *container) { @@ -1864,32 +1930,11 @@ gtk_container_adjust_size_allocation (GtkWidget *widget, 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; @@ -1935,27 +1980,17 @@ count_request_modes (GtkWidget *widget, 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; } /** @@ -2321,7 +2356,7 @@ gtk_container_real_get_path_for_child (GtkContainer *container, GList *classes; context = gtk_widget_get_style_context (GTK_WIDGET (container)); - path = gtk_widget_path_copy (gtk_widget_get_path (GTK_WIDGET (container))); + path = _gtk_widget_create_path (GTK_WIDGET (container)); /* Copy any permanent classes to the path */ classes = gtk_style_context_list_classes (context); @@ -3342,19 +3377,6 @@ gtk_container_propagate_draw (GtkContainer *container, cairo_restore (cr); } -gboolean -_gtk_container_get_need_resize (GtkContainer *container) -{ - return container->priv->need_resize; -} - -void -_gtk_container_set_need_resize (GtkContainer *container, - gboolean need_resize) -{ - container->priv->need_resize = need_resize; -} - gboolean _gtk_container_get_reallocate_redraws (GtkContainer *container) {