From ea19790828f026570c23b2f69047ab3f02ddc0d2 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 15 Feb 2012 07:11:41 -0500 Subject: [PATCH] st-widget: Implement a proper allocate Since an StWidget now has children, it needs to allocate those children properly. Defer to the currently installed layout manager, like Clutter does. Now that we have something that allocates children in St, to prevent double allocations, we use clutter_actor_set_allocation rather than chaining up to StWidget::allocate. https://bugzilla.gnome.org/show_bug.cgi?id=670034 --- src/shell-generic-container.c | 2 +- src/shell-slicer.c | 4 +--- src/shell-stack.c | 2 +- src/st/st-bin.c | 3 +-- src/st/st-box-layout.c | 3 +-- src/st/st-entry.c | 4 +--- src/st/st-icon.c | 2 +- src/st/st-label.c | 6 ++---- src/st/st-scroll-bar.c | 3 +-- src/st/st-scroll-view.c | 13 +------------ src/st/st-table.c | 2 +- src/st/st-widget.c | 27 +++++++++++++++++++++++++++ 12 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/shell-generic-container.c b/src/shell-generic-container.c index bed22b29c..4766d9f0d 100644 --- a/src/shell-generic-container.c +++ b/src/shell-generic-container.c @@ -66,7 +66,7 @@ shell_generic_container_allocate (ClutterActor *self, StThemeNode *theme_node; ClutterActorBox content_box; - CLUTTER_ACTOR_CLASS (shell_generic_container_parent_class)->allocate (self, box, flags); + clutter_actor_set_allocation (self, box, flags); theme_node = st_widget_get_theme_node (ST_WIDGET (self)); st_theme_node_get_content_box (theme_node, box, &content_box); diff --git a/src/shell-slicer.c b/src/shell-slicer.c index 986214e9b..1d3f3ecdf 100644 --- a/src/shell-slicer.c +++ b/src/shell-slicer.c @@ -81,9 +81,7 @@ shell_slicer_allocate (ClutterActor *self, { ClutterActor *child; - /* Chain up directly to ClutterActor to set actor->allocation. We explicitly skip our parent class - * StBin here because we want to override the allocate function. */ - CLUTTER_ACTOR_CLASS (g_type_class_peek (clutter_actor_get_type ()))->allocate (self, box, flags); + clutter_actor_set_allocation (self, box, flags); child = st_bin_get_child (ST_BIN (self)); if (child) diff --git a/src/shell-stack.c b/src/shell-stack.c index 439aa8313..76ed475c9 100644 --- a/src/shell-stack.c +++ b/src/shell-stack.c @@ -29,7 +29,7 @@ shell_stack_allocate (ClutterActor *self, ClutterActorBox content_box; GList *children, *iter; - CLUTTER_ACTOR_CLASS (shell_stack_parent_class)->allocate (self, box, flags); + clutter_actor_set_allocation (self, box, flags); st_theme_node_get_content_box (theme_node, box, &content_box); diff --git a/src/st/st-bin.c b/src/st/st-bin.c index 0ca1a9272..8e86ac6cc 100644 --- a/src/st/st-bin.c +++ b/src/st/st-bin.c @@ -111,8 +111,7 @@ st_bin_allocate (ClutterActor *self, { StBinPrivate *priv = ST_BIN (self)->priv; - CLUTTER_ACTOR_CLASS (st_bin_parent_class)->allocate (self, box, - flags); + clutter_actor_set_allocation (self, box, flags); if (priv->child) { diff --git a/src/st/st-box-layout.c b/src/st/st-box-layout.c index c57b7e0b5..dd44ccb0c 100644 --- a/src/st/st-box-layout.c +++ b/src/st/st-box-layout.c @@ -628,8 +628,7 @@ st_box_layout_allocate (ClutterActor *actor, gboolean flip = (st_widget_get_direction (ST_WIDGET (actor)) == ST_TEXT_DIRECTION_RTL) && (!priv->is_vertical); - CLUTTER_ACTOR_CLASS (st_box_layout_parent_class)->allocate (actor, box, - flags); + clutter_actor_set_allocation (actor, box, flags); children = st_container_get_children_list (ST_CONTAINER (actor)); if (children == NULL) diff --git a/src/st/st-entry.c b/src/st/st-entry.c index a4e5dba6c..95eaf4d89 100644 --- a/src/st/st-entry.c +++ b/src/st/st-entry.c @@ -382,13 +382,11 @@ st_entry_allocate (ClutterActor *actor, { StEntryPrivate *priv = ST_ENTRY_PRIV (actor); StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor)); - ClutterActorClass *parent_class; ClutterActorBox content_box, child_box, icon_box; gfloat icon_w, icon_h; gfloat entry_h, min_h, pref_h, avail_h; - parent_class = CLUTTER_ACTOR_CLASS (st_entry_parent_class); - parent_class->allocate (actor, box, flags); + clutter_actor_set_allocation (actor, box, flags); st_theme_node_get_content_box (theme_node, box, &content_box); diff --git a/src/st/st-icon.c b/src/st/st-icon.c index 45c212242..4ff35355b 100644 --- a/src/st/st-icon.c +++ b/src/st/st-icon.c @@ -232,7 +232,7 @@ st_icon_allocate (ClutterActor *actor, StIconPrivate *priv = ST_ICON (actor)->priv; StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor)); - CLUTTER_ACTOR_CLASS (st_icon_parent_class)->allocate (actor, box, flags); + clutter_actor_set_allocation (actor, box, flags); if (priv->icon_texture) { diff --git a/src/st/st-label.c b/src/st/st-label.c index 594b5d8e0..0d00ba767 100644 --- a/src/st/st-label.c +++ b/src/st/st-label.c @@ -172,13 +172,11 @@ st_label_allocate (ClutterActor *actor, { StLabelPrivate *priv = ST_LABEL (actor)->priv; StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor)); - ClutterActorClass *parent_class; ClutterActorBox content_box; - st_theme_node_get_content_box (theme_node, box, &content_box); + clutter_actor_set_allocation (actor, box, flags); - parent_class = CLUTTER_ACTOR_CLASS (st_label_parent_class); - parent_class->allocate (actor, box, flags); + st_theme_node_get_content_box (theme_node, box, &content_box); clutter_actor_allocate (priv->label, &content_box, flags); } diff --git a/src/st/st-scroll-bar.c b/src/st/st-scroll-bar.c index fb6b171ea..0309a8cf8 100644 --- a/src/st/st-scroll-bar.c +++ b/src/st/st-scroll-bar.c @@ -368,8 +368,7 @@ st_scroll_bar_allocate (ClutterActor *actor, { StScrollBar *bar = ST_SCROLL_BAR (actor); - /* Chain up */ - CLUTTER_ACTOR_CLASS (st_scroll_bar_parent_class)->allocate (actor, box, flags); + clutter_actor_set_allocation (actor, box, flags); scroll_bar_allocate_children (bar, box, flags); } diff --git a/src/st/st-scroll-view.c b/src/st/st-scroll-view.c index 3dd932700..34da25357 100644 --- a/src/st/st-scroll-view.c +++ b/src/st/st-scroll-view.c @@ -492,24 +492,13 @@ st_scroll_view_allocate (ClutterActor *actor, ClutterAllocationFlags flags) { ClutterActorBox content_box, child_box; - ClutterActorClass *parent_parent_class; gfloat avail_width, avail_height, sb_width, sb_height; gboolean hscrollbar_visible, vscrollbar_visible; StScrollViewPrivate *priv = ST_SCROLL_VIEW (actor)->priv; StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor)); - /* Chain up to the parent's parent class - * - * We do this because we do not want StBin to allocate the child, as we - * give it a different allocation later, depending on whether the scrollbars - * are visible - */ - parent_parent_class - = g_type_class_peek_parent (st_scroll_view_parent_class); - - CLUTTER_ACTOR_CLASS (parent_parent_class)-> - allocate (actor, box, flags); + clutter_actor_set_allocation (actor, box, flags); st_theme_node_get_content_box (theme_node, box, &content_box); diff --git a/src/st/st-table.c b/src/st/st-table.c index 9b1db4d9a..d253a7ee2 100644 --- a/src/st/st-table.c +++ b/src/st/st-table.c @@ -717,7 +717,7 @@ st_table_allocate (ClutterActor *self, StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (self)); ClutterActorBox content_box; - CLUTTER_ACTOR_CLASS (st_table_parent_class)->allocate (self, box, flags); + clutter_actor_set_allocation (self, box, flags); if (priv->n_cols < 1 || priv->n_rows < 1) return; diff --git a/src/st/st-widget.c b/src/st/st-widget.c index 7abdfd596..3d0b64a64 100644 --- a/src/st/st-widget.c +++ b/src/st/st-widget.c @@ -329,6 +329,32 @@ st_widget_get_preferred_height (ClutterActor *self, st_theme_node_adjust_preferred_height (theme_node, min_height_p, natural_height_p); } +static void +st_widget_allocate (ClutterActor *actor, + const ClutterActorBox *box, + ClutterAllocationFlags flags) +{ + StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor)); + ClutterActorBox content_box; + + /* Note that we can't just chain up to clutter_actor_real_allocate -- + * Clutter does some dirty tricks for backwards compatibility. + * Clutter also passes the actor's allocation directly to the layout + * manager, meaning that we can't modify it for children only. + */ + + clutter_actor_set_allocation (actor, box, flags); + + st_theme_node_get_content_box (theme_node, box, &content_box); + + /* If we've chained up to here, we want to allocate the children using the + * currently installed layout manager */ + clutter_layout_manager_allocate (clutter_actor_get_layout_manager (actor), + CLUTTER_CONTAINER (actor), + &content_box, + flags); +} + /** * st_widget_paint_background: * @widget: The #StWidget @@ -713,6 +739,7 @@ st_widget_class_init (StWidgetClass *klass) actor_class->get_preferred_width = st_widget_get_preferred_width; actor_class->get_preferred_height = st_widget_get_preferred_height; + actor_class->allocate = st_widget_allocate; actor_class->paint = st_widget_paint; actor_class->get_paint_volume = st_widget_get_paint_volume; actor_class->parent_set = st_widget_parent_set;