diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-08-30 18:21:48 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-08-30 21:23:25 -0400 |
commit | 1b6f73401960cbacf8c76f9c7411836a1ab286fd (patch) | |
tree | cfda7bc995253a138f87fe8e14464601e9e6b18a /tests | |
parent | cd284da79427ad5eea2ddd902ae5f7370dde5980 (diff) | |
download | gtk+-1b6f73401960cbacf8c76f9c7411836a1ab286fd.tar.gz |
tests: Stop using radio buttons
Use grouped check buttons.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testappchooser.c | 12 | ||||
-rw-r--r-- | tests/testassistant.c | 27 | ||||
-rw-r--r-- | tests/testbaseline.c | 11 | ||||
-rw-r--r-- | tests/testentryicons.c | 22 | ||||
-rw-r--r-- | tests/testgtk.c | 60 |
5 files changed, 73 insertions, 59 deletions
diff --git a/tests/testappchooser.c b/tests/testappchooser.c index f5abdde70c..a3418dd34b 100644 --- a/tests/testappchooser.c +++ b/tests/testappchooser.c @@ -81,9 +81,9 @@ prepare_dialog (void) gboolean use_file = FALSE; char *content_type = NULL; - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_file))) + if (gtk_check_button_get_active (GTK_CHECK_BUTTON (radio_file))) use_file = TRUE; - else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_content))) + else if (gtk_check_button_get_active (GTK_CHECK_BUTTON (radio_content))) use_file = FALSE; if (use_file) @@ -208,9 +208,11 @@ main (int argc, char **argv) g_signal_connect (file_l, "clicked", G_CALLBACK (button_clicked), NULL); - radio_file = gtk_radio_button_new_with_label (NULL, "Use GFile"); - radio_content = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio_file), - "Use content type"); + radio_file = gtk_check_button_new_with_label ("Use GFile"); + radio_content = gtk_check_button_new_with_label ("Use content type"); + gtk_check_button_set_group (GTK_CHECK_BUTTON (radio_content), GTK_CHECK_BUTTON (radio_file)); + gtk_check_button_set_group (GTK_CHECK_BUTTON (radio_file), GTK_CHECK_BUTTON (radio_content)); + gtk_check_button_set_active (GTK_CHECK_BUTTON (radio_file), TRUE); gtk_grid_attach (GTK_GRID (grid), radio_file, 0, 1, 1, 1); diff --git a/tests/testassistant.c b/tests/testassistant.c index e85396cda1..d1a9ae2d4a 100644 --- a/tests/testassistant.c +++ b/tests/testassistant.c @@ -41,7 +41,7 @@ complete_cb (GtkWidget *check, PageData *pdata = data; gboolean complete; - complete = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)); + complete = gtk_check_button_get_active (GTK_CHECK_BUTTON (check)); gtk_assistant_set_page_complete (pdata->assistant, pdata->page, @@ -64,7 +64,7 @@ add_completion_test_page (GtkWidget *assistant, gtk_box_append (GTK_BOX (page), gtk_label_new (text)); gtk_box_append (GTK_BOX (page), check); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), complete); + gtk_check_button_set_active (GTK_CHECK_BUTTON (check), complete); pdata = g_new (PageData, 1); pdata->assistant = GTK_ASSISTANT (assistant); @@ -231,7 +231,7 @@ visible_cb (GtkWidget *check, GtkWidget *page = data; gboolean visible; - visible = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)); + visible = gtk_check_button_get_active (GTK_CHECK_BUTTON (check)); g_object_set (G_OBJECT (page), "visible", visible, NULL); } @@ -268,7 +268,7 @@ create_generous_assistant (GtkWidget *widget) next = add_completion_test_page (assistant, "More Content", TRUE, TRUE); check = gtk_check_button_new_with_label ("Next page visible"); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE); + gtk_check_button_set_active (GTK_CHECK_BUTTON (check), TRUE); g_signal_connect (G_OBJECT (check), "toggled", G_CALLBACK (visible_cb), next); gtk_box_append (GTK_BOX (page), check); @@ -295,9 +295,9 @@ create_generous_assistant (GtkWidget *widget) gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Summary"); gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_SUMMARY); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page), - gtk_assistant_get_page_complete (GTK_ASSISTANT (assistant), - page)); + gtk_check_button_set_active (GTK_CHECK_BUTTON (page), + gtk_assistant_get_page_complete (GTK_ASSISTANT (assistant), + page)); pdata = g_new (PageData, 1); pdata->assistant = GTK_ASSISTANT (assistant); @@ -348,7 +348,7 @@ create_nonlinear_assistant (GtkWidget *widget) if (!assistant) { - GtkWidget *page, *button; + GtkWidget *page, *button, *group; assistant = gtk_assistant_new (); gtk_window_set_default_size (GTK_WINDOW (assistant), 400, 300); @@ -368,13 +368,14 @@ create_nonlinear_assistant (GtkWidget *widget) page = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - button = gtk_radio_button_new_with_label (NULL, "branch A"); + button = gtk_check_button_new_with_label ("branch A"); gtk_box_append (GTK_BOX (page), button); g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (select_branch), GINT_TO_POINTER ('A')); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); + gtk_check_button_set_active (GTK_CHECK_BUTTON (button), TRUE); + group = button; - button = gtk_radio_button_new_with_label (gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)), - "branch B"); + button = gtk_check_button_new_with_label ("branch B"); + gtk_check_button_set_group (GTK_CHECK_BUTTON (button), GTK_CHECK_BUTTON (group)); gtk_box_append (GTK_BOX (page), button); g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (select_branch), GINT_TO_POINTER ('B')); @@ -427,7 +428,7 @@ looping_assistant_forward_page (int current_page, gpointer data) assistant = (GtkAssistant*) data; page = gtk_assistant_get_nth_page (assistant, current_page); - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (page))) + if (gtk_check_button_get_active (GTK_CHECK_BUTTON (page))) return 0; else return 4; diff --git a/tests/testbaseline.c b/tests/testbaseline.c index 32915a6972..f81c937951 100644 --- a/tests/testbaseline.c +++ b/tests/testbaseline.c @@ -87,6 +87,7 @@ main (int argc, int i, j; GtkCssProvider *provider; gboolean done = FALSE; + GtkWidget *group = NULL; gtk_init (); @@ -225,10 +226,18 @@ main (int argc, gtk_widget_set_valign (button, GTK_ALIGN_BASELINE); gtk_box_append (GTK_BOX (hbox), button); - button = gtk_radio_button_new_with_label (NULL, "│Xyj,Ö"); + button = gtk_check_button_new_with_label ("│Xyj,Ö"); if (j == 0) gtk_widget_set_valign (button, GTK_ALIGN_BASELINE); gtk_box_append (GTK_BOX (hbox), button); + if (group == NULL) + { + group = button; + gtk_check_button_set_active (GTK_CHECK_BUTTON (button), TRUE); + } + else + gtk_check_button_set_group (GTK_CHECK_BUTTON (button), + GTK_CHECK_BUTTON (group)); } diff --git a/tests/testentryicons.c b/tests/testentryicons.c index cc875a5ee9..7c91901acf 100644 --- a/tests/testentryicons.c +++ b/tests/testentryicons.c @@ -12,7 +12,7 @@ static void set_blank (GtkWidget *button, GtkEntry *entry) { - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) + if (gtk_check_button_get_active (GTK_CHECK_BUTTON (button))) gtk_entry_set_icon_from_icon_name (entry, GTK_ENTRY_ICON_SECONDARY, NULL); } @@ -20,7 +20,7 @@ static void set_icon_name (GtkWidget *button, GtkEntry *entry) { - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) + if (gtk_check_button_get_active (GTK_CHECK_BUTTON (button))) gtk_entry_set_icon_from_icon_name (entry, GTK_ENTRY_ICON_SECONDARY, "media-floppy"); } @@ -30,7 +30,7 @@ set_gicon (GtkWidget *button, { GIcon *icon; - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) + if (gtk_check_button_get_active (GTK_CHECK_BUTTON (button))) { icon = g_themed_icon_new ("gtk-yes"); gtk_entry_set_icon_from_gicon (entry, GTK_ENTRY_ICON_SECONDARY, icon); @@ -44,7 +44,7 @@ set_texture (GtkWidget *button, { GdkTexture *texture; - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) + if (gtk_check_button_get_active (GTK_CHECK_BUTTON (button))) { texture = gdk_texture_new_from_resource ("/org/gtk/libgtk/inspector/logo.png"); gtk_entry_set_icon_from_paintable (entry, GTK_ENTRY_ICON_SECONDARY, GDK_PAINTABLE (texture)); @@ -238,23 +238,23 @@ main (int argc, char **argv) gtk_widget_set_vexpand (GTK_WIDGET (box), TRUE); gtk_grid_attach (GTK_GRID (grid), box, 0, 5, 3, 1); - button1 = gtk_radio_button_new_with_label (NULL, "Blank"); + button1 = gtk_check_button_new_with_label ("Blank"); gtk_widget_set_valign (button1, GTK_ALIGN_START); g_signal_connect (button1, "toggled", G_CALLBACK (set_blank), entry); gtk_box_append (GTK_BOX (box), button1); - button2 = gtk_radio_button_new_with_label (NULL, "Icon Name"); + button2 = gtk_check_button_new_with_label ("Icon Name"); gtk_widget_set_valign (button2, GTK_ALIGN_START); - gtk_radio_button_join_group (GTK_RADIO_BUTTON (button2), GTK_RADIO_BUTTON (button1)); + gtk_check_button_set_group (GTK_CHECK_BUTTON (button2), GTK_CHECK_BUTTON (button1)); g_signal_connect (button2, "toggled", G_CALLBACK (set_icon_name), entry); gtk_box_append (GTK_BOX (box), button2); - button3 = gtk_radio_button_new_with_label (NULL, "GIcon"); + button3 = gtk_check_button_new_with_label ("GIcon"); gtk_widget_set_valign (button3, GTK_ALIGN_START); - gtk_radio_button_join_group (GTK_RADIO_BUTTON (button3), GTK_RADIO_BUTTON (button1)); + gtk_check_button_set_group (GTK_CHECK_BUTTON (button3), GTK_CHECK_BUTTON (button1)); g_signal_connect (button3, "toggled", G_CALLBACK (set_gicon), entry); gtk_box_append (GTK_BOX (box), button3); - button4 = gtk_radio_button_new_with_label (NULL, "Texture"); + button4 = gtk_check_button_new_with_label ("Texture"); gtk_widget_set_valign (button4, GTK_ALIGN_START); - gtk_radio_button_join_group (GTK_RADIO_BUTTON (button4), GTK_RADIO_BUTTON (button1)); + gtk_check_button_set_group (GTK_CHECK_BUTTON (button4), GTK_CHECK_BUTTON (button1)); g_signal_connect (button4, "toggled", G_CALLBACK (set_texture), entry); gtk_box_append (GTK_BOX (box), button4); diff --git a/tests/testgtk.c b/tests/testgtk.c index 49d20714f1..890e7ff0d6 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -124,21 +124,26 @@ build_alpha_widgets (void) GtkWidget *hbox; GtkWidget *label; GtkWidget *entry; + GtkWidget *group; grid = gtk_grid_new (); gtk_widget_set_vexpand (grid, TRUE); - radio_button = gtk_radio_button_new_with_label (NULL, "Red"); + radio_button = gtk_check_button_new_with_label ("Red"); gtk_widget_set_hexpand (radio_button, TRUE); gtk_grid_attach (GTK_GRID (grid), radio_button, 0, 0, 1, 1); + group = radio_button; - radio_button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio_button), "Green"); + radio_button = gtk_check_button_new_with_label ("Green"); gtk_widget_set_hexpand (radio_button, TRUE); gtk_grid_attach (GTK_GRID (grid), radio_button, 0, 1, 1, 1); + gtk_check_button_set_group (GTK_CHECK_BUTTON (radio_button), GTK_CHECK_BUTTON (group)); - radio_button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio_button), "Blue"), + radio_button = gtk_check_button_new_with_label ("Blue"), gtk_widget_set_hexpand (radio_button, TRUE); gtk_grid_attach (GTK_GRID (grid), radio_button, 0, 2, 1, 1); + gtk_check_button_set_group (GTK_CHECK_BUTTON (radio_button), GTK_CHECK_BUTTON (group)); + gtk_check_button_set_active (GTK_CHECK_BUTTON (group), TRUE); check_button = gtk_check_button_new_with_label ("Sedentary"), gtk_widget_set_hexpand (check_button, TRUE); @@ -391,7 +396,7 @@ create_toggle_buttons (GtkWidget *widget) } static GtkWidget * -create_widget_grid (GType widget_type) +create_widget_grid (gboolean group) { GtkWidget *grid; GtkWidget *group_widget = NULL; @@ -424,14 +429,13 @@ create_widget_grid (GType widget_type) } else { - widget = g_object_new (widget_type, NULL); - - if (g_type_is_a (widget_type, GTK_TYPE_RADIO_BUTTON)) + widget = gtk_check_button_new (); + if (group) { if (!group_widget) group_widget = widget; else - g_object_set (widget, "group", group_widget, NULL); + gtk_check_button_set_group (GTK_CHECK_BUTTON (widget), GTK_CHECK_BUTTON (group_widget)); } } @@ -498,7 +502,7 @@ create_check_buttons (GtkWidget *widget) separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL); gtk_box_append (GTK_BOX (box1), separator); - table = create_widget_grid (GTK_TYPE_CHECK_BUTTON); + table = create_widget_grid (FALSE); gtk_widget_set_vexpand (table, TRUE); gtk_box_append (GTK_BOX (box2), table); } @@ -522,6 +526,7 @@ create_radio_buttons (GtkWidget *widget) GtkWidget *button; GtkWidget *separator; GtkWidget *table; + GtkWidget *group; if (!window) { @@ -543,23 +548,21 @@ create_radio_buttons (GtkWidget *widget) box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10); gtk_box_append (GTK_BOX (box1), box2); - button = gtk_radio_button_new_with_label (NULL, "button1"); + button = gtk_check_button_new_with_label ("button1"); gtk_box_append (GTK_BOX (box2), button); + group = button; - button = gtk_radio_button_new_with_label ( - gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)), - "button2"); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); + button = gtk_check_button_new_with_label ("button2"); + gtk_check_button_set_active (GTK_CHECK_BUTTON (button), TRUE); + gtk_check_button_set_group (GTK_CHECK_BUTTON (button), GTK_CHECK_BUTTON (group)); gtk_box_append (GTK_BOX (box2), button); - button = gtk_radio_button_new_with_label ( - gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)), - "button3"); + button = gtk_check_button_new_with_label ("button3"); + gtk_check_button_set_group (GTK_CHECK_BUTTON (button), GTK_CHECK_BUTTON (group)); gtk_box_append (GTK_BOX (box2), button); - button = gtk_radio_button_new_with_label ( - gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)), - "inconsistent"); + button = gtk_check_button_new_with_label ("inconsistent"); + gtk_check_button_set_group (GTK_CHECK_BUTTON (button), GTK_CHECK_BUTTON (group)); gtk_check_button_set_inconsistent (GTK_CHECK_BUTTON (button), TRUE); gtk_box_append (GTK_BOX (box2), button); @@ -569,24 +572,23 @@ create_radio_buttons (GtkWidget *widget) box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10); gtk_box_append (GTK_BOX (box1), box2); - button = gtk_radio_button_new_with_label (NULL, "button4"); + button = gtk_check_button_new_with_label ("button4"); gtk_box_append (GTK_BOX (box2), button); + group = button; - button = gtk_radio_button_new_with_label ( - gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)), - "button5"); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); + button = gtk_check_button_new_with_label ("button5"); + gtk_check_button_set_active (GTK_CHECK_BUTTON (button), TRUE); + gtk_check_button_set_group (GTK_CHECK_BUTTON (button), GTK_CHECK_BUTTON (group)); gtk_box_append (GTK_BOX (box2), button); - button = gtk_radio_button_new_with_label ( - gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)), - "button6"); + button = gtk_check_button_new_with_label ("button6"); + gtk_check_button_set_group (GTK_CHECK_BUTTON (button), GTK_CHECK_BUTTON (group)); gtk_box_append (GTK_BOX (box2), button); separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL); gtk_box_append (GTK_BOX (box1), separator); - table = create_widget_grid (GTK_TYPE_RADIO_BUTTON); + table = create_widget_grid (TRUE); gtk_box_append (GTK_BOX (box1), table); } |