sizegroup: a resize asked for in a size group finds the groups of widgets by a flag and marks the visited ones in a set instead of object data, and does not go through the same widgets a second time when all groups are of both modes
This commit is contained in:
parent
3776f89ea4
commit
3af8f826d6
2 changed files with 79 additions and 68 deletions
|
|
@ -74,6 +74,7 @@ gpointer _gtk_memdup2 (gconstpointer mem,
|
|||
typedef enum
|
||||
{
|
||||
PRIVATE_GTK_USER_STYLE = 1 << 0,
|
||||
PRIVATE_GTK_IN_SIZE_GROUP = 1 << 1, /* If the widget is in a size group */
|
||||
PRIVATE_GTK_RESIZE_PENDING = 1 << 2,
|
||||
PRIVATE_GTK_HAS_POINTER = 1 << 3, /* If the pointer is above a window belonging to the widget */
|
||||
PRIVATE_GTK_SHADOWED = 1 << 4, /* If there is a grab in effect shadowing the widget */
|
||||
|
|
|
|||
|
|
@ -68,12 +68,16 @@ static void gtk_size_group_buildable_custom_finished (GtkBuildable *buildable,
|
|||
static GQuark size_groups_quark;
|
||||
static const gchar size_groups_tag[] = "gtk-size-groups";
|
||||
|
||||
static GQuark visited_quark;
|
||||
static const gchar visited_tag[] = "gtk-size-group-visited";
|
||||
|
||||
/* most widgets are in no group: a flag says so, without looking for
|
||||
* the groups in the data of the widget, for each widget and each of
|
||||
* its parents at every resize asked for */
|
||||
static GSList *
|
||||
get_size_groups (GtkWidget *widget)
|
||||
{
|
||||
if (!(GTK_PRIVATE_FLAGS (widget) & PRIVATE_GTK_IN_SIZE_GROUP))
|
||||
return NULL;
|
||||
|
||||
return g_object_get_qdata (G_OBJECT (widget), size_groups_quark);
|
||||
}
|
||||
|
||||
|
|
@ -82,24 +86,38 @@ set_size_groups (GtkWidget *widget,
|
|||
GSList *groups)
|
||||
{
|
||||
g_object_set_qdata (G_OBJECT (widget), size_groups_quark, groups);
|
||||
|
||||
if (groups)
|
||||
GTK_PRIVATE_SET_FLAG (widget, GTK_IN_SIZE_GROUP);
|
||||
else
|
||||
GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_SIZE_GROUP);
|
||||
}
|
||||
|
||||
/* The widgets and groups of a closure being built are marked in a set,
|
||||
* not with data on each object: setting and reading object data takes
|
||||
* a lock and a search of all data of the object each time, for every
|
||||
* widget of a group at every resize asked for by one of them */
|
||||
static GHashTable *visited_set;
|
||||
|
||||
static void
|
||||
mark_visited (gpointer object)
|
||||
{
|
||||
g_object_set_qdata (object, visited_quark, "visited");
|
||||
if (!visited_set)
|
||||
visited_set = g_hash_table_new (NULL, NULL);
|
||||
g_hash_table_insert (visited_set, object, object);
|
||||
}
|
||||
|
||||
static void
|
||||
mark_unvisited (gpointer object)
|
||||
{
|
||||
g_object_set_qdata (object, visited_quark, NULL);
|
||||
if (visited_set)
|
||||
g_hash_table_remove (visited_set, object);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_visited (gpointer object)
|
||||
{
|
||||
return g_object_get_qdata (object, visited_quark) != NULL;
|
||||
return visited_set && g_hash_table_lookup (visited_set, object) != NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -176,18 +194,68 @@ reset_group_sizes (GSList *groups)
|
|||
}
|
||||
}
|
||||
|
||||
static void queue_resize_on_widget (GtkWidget *widget,
|
||||
gboolean check_siblings);
|
||||
|
||||
/* Resets the groups of the closure of @parent in @mode and asks for a
|
||||
* new size of all its widgets; returns whether all groups of all these
|
||||
* widgets are of both modes, when the closure in the other mode is the
|
||||
* same and needs no second round */
|
||||
static gboolean
|
||||
queue_resize_on_closure (GtkWidget *widget,
|
||||
GtkWidget *parent,
|
||||
GtkSizeGroupMode mode)
|
||||
{
|
||||
GSList *groups = NULL;
|
||||
GSList *widgets = NULL;
|
||||
GSList *tmp_list;
|
||||
gboolean all_both = TRUE;
|
||||
|
||||
add_widget_to_closure (parent, mode, &groups, &widgets);
|
||||
g_slist_foreach (widgets, (GFunc)mark_unvisited, NULL);
|
||||
g_slist_foreach (groups, (GFunc)mark_unvisited, NULL);
|
||||
|
||||
reset_group_sizes (groups);
|
||||
|
||||
tmp_list = widgets;
|
||||
while (tmp_list)
|
||||
{
|
||||
GSList *g;
|
||||
|
||||
for (g = get_size_groups (tmp_list->data); g; g = g->next)
|
||||
if (((GtkSizeGroup *) g->data)->mode != GTK_SIZE_GROUP_BOTH)
|
||||
all_both = FALSE;
|
||||
|
||||
if (tmp_list->data == parent)
|
||||
{
|
||||
if (widget == parent)
|
||||
real_queue_resize (parent);
|
||||
}
|
||||
else if (tmp_list->data == widget)
|
||||
{
|
||||
g_warning ("A container and its child are part of this SizeGroup");
|
||||
}
|
||||
else
|
||||
queue_resize_on_widget (tmp_list->data, FALSE);
|
||||
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
|
||||
g_slist_free (widgets);
|
||||
g_slist_free (groups);
|
||||
|
||||
return all_both;
|
||||
}
|
||||
|
||||
static void
|
||||
queue_resize_on_widget (GtkWidget *widget,
|
||||
gboolean check_siblings)
|
||||
{
|
||||
GtkWidget *parent = widget;
|
||||
GSList *tmp_list;
|
||||
|
||||
while (parent)
|
||||
{
|
||||
GSList *widget_groups;
|
||||
GSList *groups;
|
||||
GSList *widgets;
|
||||
|
||||
if (widget == parent && !check_siblings)
|
||||
{
|
||||
|
|
@ -206,65 +274,8 @@ queue_resize_on_widget (GtkWidget *widget,
|
|||
continue;
|
||||
}
|
||||
|
||||
groups = NULL;
|
||||
widgets = NULL;
|
||||
|
||||
add_widget_to_closure (parent, GTK_SIZE_GROUP_HORIZONTAL, &groups, &widgets);
|
||||
g_slist_foreach (widgets, (GFunc)mark_unvisited, NULL);
|
||||
g_slist_foreach (groups, (GFunc)mark_unvisited, NULL);
|
||||
|
||||
reset_group_sizes (groups);
|
||||
|
||||
tmp_list = widgets;
|
||||
while (tmp_list)
|
||||
{
|
||||
if (tmp_list->data == parent)
|
||||
{
|
||||
if (widget == parent)
|
||||
real_queue_resize (parent);
|
||||
}
|
||||
else if (tmp_list->data == widget)
|
||||
{
|
||||
g_warning ("A container and its child are part of this SizeGroup");
|
||||
}
|
||||
else
|
||||
queue_resize_on_widget (tmp_list->data, FALSE);
|
||||
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
|
||||
g_slist_free (widgets);
|
||||
g_slist_free (groups);
|
||||
|
||||
groups = NULL;
|
||||
widgets = NULL;
|
||||
|
||||
add_widget_to_closure (parent, GTK_SIZE_GROUP_VERTICAL, &groups, &widgets);
|
||||
g_slist_foreach (widgets, (GFunc)mark_unvisited, NULL);
|
||||
g_slist_foreach (groups, (GFunc)mark_unvisited, NULL);
|
||||
|
||||
reset_group_sizes (groups);
|
||||
|
||||
tmp_list = widgets;
|
||||
while (tmp_list)
|
||||
{
|
||||
if (tmp_list->data == parent)
|
||||
{
|
||||
if (widget == parent)
|
||||
real_queue_resize (parent);
|
||||
}
|
||||
else if (tmp_list->data == widget)
|
||||
{
|
||||
g_warning ("A container and its child are part of this SizeGroup");
|
||||
}
|
||||
else
|
||||
queue_resize_on_widget (tmp_list->data, FALSE);
|
||||
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
|
||||
g_slist_free (widgets);
|
||||
g_slist_free (groups);
|
||||
if (!queue_resize_on_closure (widget, parent, GTK_SIZE_GROUP_HORIZONTAL))
|
||||
queue_resize_on_closure (widget, parent, GTK_SIZE_GROUP_VERTICAL);
|
||||
|
||||
parent = parent->parent;
|
||||
}
|
||||
|
|
@ -283,7 +294,6 @@ initialize_size_group_quarks (void)
|
|||
if (!size_groups_quark)
|
||||
{
|
||||
size_groups_quark = g_quark_from_static_string (size_groups_tag);
|
||||
visited_quark = g_quark_from_static_string (visited_tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue