forked from AuroraMiddleware/gtk
gtk: GtkToolbar returns invalid paths when adding tool items
* Calculate siblings_path on demand, so that it's always correct and doesn't get out of sync with the toolbar state. https://bugzilla.gnome.org/show_bug.cgi?id=662177
This commit is contained in:
parent
febc29852b
commit
385b7a3031
@ -121,8 +121,6 @@ struct _GtkToolbarPrivate
|
|||||||
|
|
||||||
GTimer *timer;
|
GTimer *timer;
|
||||||
|
|
||||||
GtkWidgetPath *sibling_path;
|
|
||||||
|
|
||||||
gulong settings_connection;
|
gulong settings_connection;
|
||||||
|
|
||||||
gint idle_id;
|
gint idle_id;
|
||||||
@ -3163,9 +3161,6 @@ gtk_toolbar_finalize (GObject *object)
|
|||||||
GtkToolbar *toolbar = GTK_TOOLBAR (object);
|
GtkToolbar *toolbar = GTK_TOOLBAR (object);
|
||||||
GtkToolbarPrivate *priv = toolbar->priv;
|
GtkToolbarPrivate *priv = toolbar->priv;
|
||||||
|
|
||||||
if (priv->sibling_path != NULL)
|
|
||||||
gtk_widget_path_unref (priv->sibling_path);
|
|
||||||
|
|
||||||
g_list_free_full (priv->content, (GDestroyNotify)toolbar_content_free);
|
g_list_free_full (priv->content, (GDestroyNotify)toolbar_content_free);
|
||||||
|
|
||||||
g_timer_destroy (priv->timer);
|
g_timer_destroy (priv->timer);
|
||||||
@ -3308,7 +3303,7 @@ toolbar_content_new_tool_item (GtkToolbar *toolbar,
|
|||||||
content->is_placeholder = is_placeholder;
|
content->is_placeholder = is_placeholder;
|
||||||
|
|
||||||
priv->content = g_list_insert (priv->content, content, pos);
|
priv->content = g_list_insert (priv->content, content, pos);
|
||||||
|
|
||||||
gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
|
gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
|
||||||
gtk_toolbar_invalidate_order (toolbar);
|
gtk_toolbar_invalidate_order (toolbar);
|
||||||
|
|
||||||
@ -3938,37 +3933,34 @@ gtk_toolbar_get_path_for_child (GtkContainer *container,
|
|||||||
GtkWidgetPath *path;
|
GtkWidgetPath *path;
|
||||||
GtkToolbar *toolbar;
|
GtkToolbar *toolbar;
|
||||||
GtkToolbarPrivate *priv;
|
GtkToolbarPrivate *priv;
|
||||||
|
GtkWidgetPath *sibling_path;
|
||||||
gint vis_index;
|
gint vis_index;
|
||||||
|
GList *children;
|
||||||
|
|
||||||
toolbar = GTK_TOOLBAR (container);
|
toolbar = GTK_TOOLBAR (container);
|
||||||
priv = toolbar->priv;
|
priv = toolbar->priv;
|
||||||
|
|
||||||
if (priv->sibling_path == NULL)
|
/* build a path for all the visible children;
|
||||||
{
|
* get_children works in visible order
|
||||||
GList *children;
|
*/
|
||||||
|
sibling_path = gtk_widget_path_new ();
|
||||||
|
children = _gtk_container_get_all_children (container);
|
||||||
|
|
||||||
/* build a path for all the visible children;
|
if (priv->orientation != GTK_ORIENTATION_HORIZONTAL ||
|
||||||
* get_children works in visible order
|
gtk_widget_get_direction (GTK_WIDGET (toolbar)) != GTK_TEXT_DIR_RTL)
|
||||||
*/
|
children = g_list_reverse (children);
|
||||||
priv->sibling_path = gtk_widget_path_new ();
|
|
||||||
children = _gtk_container_get_all_children (container);
|
|
||||||
|
|
||||||
if (priv->orientation != GTK_ORIENTATION_HORIZONTAL ||
|
g_list_foreach (children, add_widget_to_path, sibling_path);
|
||||||
gtk_widget_get_direction (GTK_WIDGET (toolbar)) != GTK_TEXT_DIR_RTL)
|
g_list_free (children);
|
||||||
children = g_list_reverse (children);
|
|
||||||
|
|
||||||
g_list_foreach (children, add_widget_to_path, priv->sibling_path);
|
|
||||||
g_list_free (children);
|
|
||||||
}
|
|
||||||
|
|
||||||
path = gtk_widget_path_copy (gtk_widget_get_path (GTK_WIDGET (container)));
|
path = gtk_widget_path_copy (gtk_widget_get_path (GTK_WIDGET (container)));
|
||||||
if (gtk_widget_get_visible (child))
|
if (gtk_widget_get_visible (child))
|
||||||
{
|
{
|
||||||
vis_index = gtk_toolbar_get_visible_position (toolbar, child);
|
vis_index = gtk_toolbar_get_visible_position (toolbar, child);
|
||||||
|
|
||||||
if (vis_index < gtk_widget_path_length (priv->sibling_path))
|
if (vis_index < gtk_widget_path_length (sibling_path))
|
||||||
gtk_widget_path_append_with_siblings (path,
|
gtk_widget_path_append_with_siblings (path,
|
||||||
priv->sibling_path,
|
sibling_path,
|
||||||
vis_index);
|
vis_index);
|
||||||
else
|
else
|
||||||
gtk_widget_path_append_for_widget (path, child);
|
gtk_widget_path_append_for_widget (path, child);
|
||||||
@ -3976,23 +3968,16 @@ gtk_toolbar_get_path_for_child (GtkContainer *container,
|
|||||||
else
|
else
|
||||||
gtk_widget_path_append_for_widget (path, child);
|
gtk_widget_path_append_for_widget (path, child);
|
||||||
|
|
||||||
|
gtk_widget_path_unref (sibling_path);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_toolbar_invalidate_order (GtkToolbar *toolbar)
|
gtk_toolbar_invalidate_order (GtkToolbar *toolbar)
|
||||||
{
|
{
|
||||||
GtkToolbarPrivate *priv = toolbar->priv;
|
gtk_container_forall (GTK_CONTAINER (toolbar),
|
||||||
|
(GtkCallback) gtk_widget_reset_style,
|
||||||
if (priv->sibling_path != NULL)
|
NULL);
|
||||||
{
|
|
||||||
gtk_widget_path_unref (priv->sibling_path);
|
|
||||||
priv->sibling_path = NULL;
|
|
||||||
|
|
||||||
gtk_container_forall (GTK_CONTAINER (toolbar),
|
|
||||||
(GtkCallback) gtk_widget_reset_style,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user