Use accessor functions to access GtkToolbar
This commit is contained in:
parent
83c20d4b32
commit
374d5094a3
@ -31,6 +31,7 @@ struct _Info
|
|||||||
static void
|
static void
|
||||||
add_random (GtkToolbar *toolbar, gint n)
|
add_random (GtkToolbar *toolbar, gint n)
|
||||||
{
|
{
|
||||||
|
gint n_items;
|
||||||
gint position;
|
gint position;
|
||||||
gchar *label = g_strdup_printf ("Button %d", n);
|
gchar *label = g_strdup_printf ("Button %d", n);
|
||||||
|
|
||||||
@ -40,10 +41,11 @@ add_random (GtkToolbar *toolbar, gint n)
|
|||||||
g_free (label);
|
g_free (label);
|
||||||
gtk_widget_show_all (GTK_WIDGET (toolitem));
|
gtk_widget_show_all (GTK_WIDGET (toolitem));
|
||||||
|
|
||||||
if (g_list_length (toolbar->children) == 0)
|
n_items = gtk_toolbar_get_n_items (toolbar);
|
||||||
|
if (n_items == 0)
|
||||||
position = 0;
|
position = 0;
|
||||||
else
|
else
|
||||||
position = g_random_int_range (0, g_list_length (toolbar->children));
|
position = g_random_int_range (0, n_items);
|
||||||
|
|
||||||
gtk_toolbar_insert (toolbar, toolitem, position);
|
gtk_toolbar_insert (toolbar, toolitem, position);
|
||||||
}
|
}
|
||||||
@ -51,17 +53,21 @@ add_random (GtkToolbar *toolbar, gint n)
|
|||||||
static void
|
static void
|
||||||
remove_random (GtkToolbar *toolbar)
|
remove_random (GtkToolbar *toolbar)
|
||||||
{
|
{
|
||||||
GtkWidget *child;
|
GtkToolItem *tool_item;
|
||||||
|
gint n_items;
|
||||||
gint position;
|
gint position;
|
||||||
|
|
||||||
if (!toolbar->children)
|
n_items = gtk_toolbar_get_n_items (toolbar);
|
||||||
|
|
||||||
|
if (n_items == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
position = g_random_int_range (0, g_list_length (toolbar->children));
|
position = g_random_int_range (0, n_items);
|
||||||
|
|
||||||
child = g_list_nth_data (toolbar->children, position);
|
tool_item = gtk_toolbar_get_nth_item (toolbar, position);
|
||||||
|
|
||||||
gtk_container_remove (GTK_CONTAINER (toolbar), child);
|
gtk_container_remove (GTK_CONTAINER (toolbar),
|
||||||
|
GTK_WIDGET (tool_item));
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -75,7 +81,8 @@ stress_test_old_api (gpointer data)
|
|||||||
|
|
||||||
Info *info = data;
|
Info *info = data;
|
||||||
Action action;
|
Action action;
|
||||||
|
gint n_items;
|
||||||
|
|
||||||
if (info->counter++ == 200)
|
if (info->counter++ == 200)
|
||||||
{
|
{
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
@ -90,12 +97,13 @@ stress_test_old_api (gpointer data)
|
|||||||
gtk_widget_show (GTK_WIDGET (info->toolbar));
|
gtk_widget_show (GTK_WIDGET (info->toolbar));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!info->toolbar->children)
|
n_items = gtk_toolbar_get_n_items (info->toolbar);
|
||||||
|
if (n_items == 0)
|
||||||
{
|
{
|
||||||
add_random (info->toolbar, info->counter);
|
add_random (info->toolbar, info->counter);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else if (g_list_length (info->toolbar->children) > 50)
|
else if (n_items > 50)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 25; i++)
|
for (i = 0; i < 25; i++)
|
||||||
|
@ -562,7 +562,7 @@ main (gint argc, gchar **argv)
|
|||||||
for (i = 0; i < G_N_ELEMENTS (toolbar_styles); i++)
|
for (i = 0; i < G_N_ELEMENTS (toolbar_styles); i++)
|
||||||
gtk_combo_box_append_text (GTK_COMBO_BOX (option_menu), toolbar_styles[i]);
|
gtk_combo_box_append_text (GTK_COMBO_BOX (option_menu), toolbar_styles[i]);
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX (option_menu),
|
gtk_combo_box_set_active (GTK_COMBO_BOX (option_menu),
|
||||||
GTK_TOOLBAR (toolbar)->style);
|
gtk_toolbar_get_style (GTK_TOOLBAR (toolbar)));
|
||||||
gtk_box_pack_start (GTK_BOX (hbox2), option_menu, FALSE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (hbox2), option_menu, FALSE, FALSE, 0);
|
||||||
g_signal_connect (option_menu, "changed",
|
g_signal_connect (option_menu, "changed",
|
||||||
G_CALLBACK (change_toolbar_style), toolbar);
|
G_CALLBACK (change_toolbar_style), toolbar);
|
||||||
|
Loading…
Reference in New Issue
Block a user