tests: Fix testgtk

An assorted collection of fixes.
This commit is contained in:
Alexander Mikhaylenko 2020-05-11 18:11:48 +05:00
parent 99704248b7
commit 4277eeee1b
2 changed files with 140 additions and 64 deletions

View File

@ -126,6 +126,7 @@ build_alpha_widgets (void)
GtkWidget *entry; GtkWidget *entry;
grid = gtk_grid_new (); grid = gtk_grid_new ();
gtk_widget_set_vexpand (grid, TRUE);
radio_button = gtk_radio_button_new_with_label (NULL, "Red"); radio_button = gtk_radio_button_new_with_label (NULL, "Red");
gtk_widget_set_hexpand (radio_button, TRUE); gtk_widget_set_hexpand (radio_button, TRUE);
@ -211,12 +212,15 @@ create_alpha_window (GtkWidget *widget)
content_area = gtk_dialog_get_content_area (GTK_DIALOG (window)); content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
gtk_widget_set_margin_top (vbox, 12);
gtk_widget_set_margin_bottom (vbox, 12);
gtk_widget_set_margin_start (vbox, 12);
gtk_widget_set_margin_end (vbox, 12);
gtk_widget_set_vexpand (vbox, TRUE);
gtk_container_add (GTK_CONTAINER (content_area), vbox); gtk_container_add (GTK_CONTAINER (content_area), vbox);
label = gtk_label_new (NULL); label = gtk_label_new (NULL);
gtk_container_add (GTK_CONTAINER (vbox), label); gtk_widget_set_vexpand (label, TRUE);
label = gtk_label_new (NULL);
gtk_container_add (GTK_CONTAINER (vbox), label); gtk_container_add (GTK_CONTAINER (vbox), label);
display = gtk_widget_get_display (window); display = gtk_widget_get_display (window);
on_composited_changed (display, NULL, GTK_LABEL (label)); on_composited_changed (display, NULL, GTK_LABEL (label));
@ -284,6 +288,10 @@ create_buttons (GtkWidget *widget)
grid = gtk_grid_new (); grid = gtk_grid_new ();
gtk_grid_set_row_spacing (GTK_GRID (grid), 5); gtk_grid_set_row_spacing (GTK_GRID (grid), 5);
gtk_grid_set_column_spacing (GTK_GRID (grid), 5); gtk_grid_set_column_spacing (GTK_GRID (grid), 5);
gtk_widget_set_margin_top (grid, 10);
gtk_widget_set_margin_bottom (grid, 10);
gtk_widget_set_margin_start (grid, 10);
gtk_widget_set_margin_end (grid, 10);
gtk_container_add (GTK_CONTAINER (box1), grid); gtk_container_add (GTK_CONTAINER (box1), grid);
button[0] = gtk_button_new_with_label ("button1"); button[0] = gtk_button_new_with_label ("button1");
@ -315,6 +323,10 @@ create_buttons (GtkWidget *widget)
gtk_container_add (GTK_CONTAINER (box1), box2); gtk_container_add (GTK_CONTAINER (box1), box2);
button[9] = gtk_button_new_with_label ("close"); button[9] = gtk_button_new_with_label ("close");
gtk_widget_set_margin_top (button[9], 10);
gtk_widget_set_margin_bottom (button[9], 10);
gtk_widget_set_margin_start (button[9], 10);
gtk_widget_set_margin_end (button[9], 10);
g_signal_connect_swapped (button[9], "clicked", g_signal_connect_swapped (button[9], "clicked",
G_CALLBACK (gtk_widget_destroy), G_CALLBACK (gtk_widget_destroy),
window); window);
@ -476,6 +488,11 @@ create_check_buttons (GtkWidget *widget)
box1 = gtk_dialog_get_content_area (GTK_DIALOG (window)); box1 = gtk_dialog_get_content_area (GTK_DIALOG (window));
box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10); box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
gtk_widget_set_hexpand (box2, TRUE);
gtk_widget_set_margin_start (box2, 10);
gtk_widget_set_margin_end (box2, 10);
gtk_widget_set_margin_top (box2, 10);
gtk_widget_set_margin_bottom (box2, 10);
gtk_container_add (GTK_CONTAINER (box1), box2); gtk_container_add (GTK_CONTAINER (box1), box2);
button = gtk_check_button_new_with_mnemonic ("_button1"); button = gtk_check_button_new_with_mnemonic ("_button1");
@ -492,10 +509,11 @@ create_check_buttons (GtkWidget *widget)
gtk_container_add (GTK_CONTAINER (box2), button); gtk_container_add (GTK_CONTAINER (box2), button);
separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL); separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
gtk_container_add (GTK_CONTAINER (box1), separator); gtk_container_add (GTK_CONTAINER (box2), separator);
table = create_widget_grid (GTK_TYPE_CHECK_BUTTON); table = create_widget_grid (GTK_TYPE_CHECK_BUTTON);
gtk_container_add (GTK_CONTAINER (box1), table); gtk_widget_set_vexpand (table, TRUE);
gtk_container_add (GTK_CONTAINER (box2), table);
} }
if (!gtk_widget_get_visible (window)) if (!gtk_widget_get_visible (window))
@ -1179,6 +1197,8 @@ create_rotated_text (GtkWidget *widget)
content_area = gtk_dialog_get_content_area (GTK_DIALOG (window)); content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
drawing_area = gtk_drawing_area_new (); drawing_area = gtk_drawing_area_new ();
gtk_widget_set_hexpand (drawing_area, TRUE);
gtk_widget_set_vexpand (drawing_area, TRUE);
gtk_container_add (GTK_CONTAINER (content_area), drawing_area); gtk_container_add (GTK_CONTAINER (content_area), drawing_area);
tile_pixbuf = gdk_pixbuf_new_from_file ("marble.xpm", NULL); tile_pixbuf = gdk_pixbuf_new_from_file ("marble.xpm", NULL);
@ -1190,8 +1210,6 @@ create_rotated_text (GtkWidget *widget)
g_signal_connect (drawing_area, "unrealize", g_signal_connect (drawing_area, "unrealize",
G_CALLBACK (on_rotated_text_unrealize), NULL); G_CALLBACK (on_rotated_text_unrealize), NULL);
gtk_widget_show (gtk_button_get_child (GTK_BUTTON (window)));
gtk_drawing_area_set_content_width (GTK_DRAWING_AREA (drawing_area), DEFAULT_TEXT_RADIUS * 2); gtk_drawing_area_set_content_width (GTK_DRAWING_AREA (drawing_area), DEFAULT_TEXT_RADIUS * 2);
gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (drawing_area), DEFAULT_TEXT_RADIUS * 2); gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (drawing_area), DEFAULT_TEXT_RADIUS * 2);
} }
@ -1603,7 +1621,7 @@ create_listbox (GtkWidget *widget)
static GtkWidget * static GtkWidget *
accel_button_new (const gchar *text, accel_button_new (const gchar *text,
const gchar *accel) const gchar *accel)
{ {
guint keyval; guint keyval;
GdkModifierType modifiers; GdkModifierType modifiers;
@ -1624,7 +1642,6 @@ accel_button_new (const gchar *text,
shortcut = gtk_shortcut_new (gtk_keyval_trigger_new (keyval, modifiers), shortcut = gtk_shortcut_new (gtk_keyval_trigger_new (keyval, modifiers),
g_object_ref (gtk_activate_action_get ())); g_object_ref (gtk_activate_action_get ()));
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut); gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
g_object_unref (shortcut);
gtk_widget_add_controller (button, controller); gtk_widget_add_controller (button, controller);
label = gtk_accel_label_new (text); label = gtk_accel_label_new (text);
@ -1642,6 +1659,7 @@ create_key_lookup (GtkWidget *widget)
if (!window) if (!window)
{ {
GtkWidget *box;
GtkWidget *button; GtkWidget *button;
GtkWidget *content_area; GtkWidget *content_area;
@ -1658,34 +1676,37 @@ create_key_lookup (GtkWidget *widget)
content_area = gtk_dialog_get_content_area (GTK_DIALOG (window)); content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_hexpand (box, TRUE);
gtk_widget_set_vexpand (box, TRUE);
gtk_container_add (GTK_CONTAINER (content_area), box);
button = gtk_button_new_with_mnemonic ("Button 1 (_a)"); button = gtk_button_new_with_mnemonic ("Button 1 (_a)");
gtk_container_add (GTK_CONTAINER (content_area), button); gtk_container_add (GTK_CONTAINER (box), button);
button = gtk_button_new_with_mnemonic ("Button 2 (_A)"); button = gtk_button_new_with_mnemonic ("Button 2 (_A)");
gtk_container_add (GTK_CONTAINER (content_area), button); gtk_container_add (GTK_CONTAINER (box), button);
button = gtk_button_new_with_mnemonic ("Button 3 (_\321\204)"); button = gtk_button_new_with_mnemonic ("Button 3 (_\321\204)");
gtk_container_add (GTK_CONTAINER (content_area), button); gtk_container_add (GTK_CONTAINER (box), button);
button = gtk_button_new_with_mnemonic ("Button 4 (_\320\244)"); button = gtk_button_new_with_mnemonic ("Button 4 (_\320\244)");
gtk_container_add (GTK_CONTAINER (content_area), button); gtk_container_add (GTK_CONTAINER (box), button);
button = gtk_button_new_with_mnemonic ("Button 6 (_b)"); button = gtk_button_new_with_mnemonic ("Button 6 (_b)");
gtk_container_add (GTK_CONTAINER (content_area), button); gtk_container_add (GTK_CONTAINER (box), button);
button = accel_button_new ("Button 7", "<Alt><Shift>b"); button = accel_button_new ("Button 7", "<Alt><Shift>b");
gtk_container_add (GTK_CONTAINER (content_area), button); gtk_container_add (GTK_CONTAINER (box), button);
button = accel_button_new ("Button 8", "<Alt>d"); button = accel_button_new ("Button 8", "<Alt>d");
gtk_container_add (GTK_CONTAINER (content_area), button); gtk_container_add (GTK_CONTAINER (box), button);
button = accel_button_new ("Button 9", "<Alt>Cyrillic_ve"); button = accel_button_new ("Button 9", "<Alt>Cyrillic_ve");
gtk_container_add (GTK_CONTAINER (content_area), button); gtk_container_add (GTK_CONTAINER (box), button);
button = gtk_button_new_with_mnemonic ("Button 10 (_1)"); button = gtk_button_new_with_mnemonic ("Button 10 (_1)");
gtk_container_add (GTK_CONTAINER (content_area), button); gtk_container_add (GTK_CONTAINER (box), button);
button = gtk_button_new_with_mnemonic ("Button 11 (_!)"); button = gtk_button_new_with_mnemonic ("Button 11 (_!)");
gtk_container_add (GTK_CONTAINER (content_area), button); gtk_container_add (GTK_CONTAINER (box), button);
button = accel_button_new ("Button 12", "<Super>a"); button = accel_button_new ("Button 12", "<Super>a");
gtk_container_add (GTK_CONTAINER (content_area), button); gtk_container_add (GTK_CONTAINER (box), button);
button = accel_button_new ("Button 13", "<Hyper>a"); button = accel_button_new ("Button 13", "<Hyper>a");
gtk_container_add (GTK_CONTAINER (content_area), button); gtk_container_add (GTK_CONTAINER (box), button);
button = accel_button_new ("Button 14", "<Meta>a"); button = accel_button_new ("Button 14", "<Meta>a");
gtk_container_add (GTK_CONTAINER (content_area), button); gtk_container_add (GTK_CONTAINER (box), button);
button = accel_button_new ("Button 15", "<Shift><Mod4>b");
gtk_container_add (GTK_CONTAINER (content_area), button);
window_ptr = &window; window_ptr = &window;
g_object_add_weak_pointer (G_OBJECT (window), window_ptr); g_object_add_weak_pointer (G_OBJECT (window), window_ptr);
@ -1914,8 +1935,8 @@ scrolled_windows_remove (GtkWidget *dialog, gint response, GtkWidget *scrollwin)
if (sw_parent) if (sw_parent)
{ {
g_object_ref (scrollwin); g_object_ref (scrollwin);
gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (scrollwin)), scrollwin); gtk_window_set_child (GTK_WINDOW (gtk_widget_get_parent (scrollwin)), NULL);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw_parent), scrollwin); gtk_container_add (GTK_CONTAINER (sw_parent), scrollwin);
g_object_unref (scrollwin); g_object_unref (scrollwin);
@ -1937,7 +1958,7 @@ scrolled_windows_remove (GtkWidget *dialog, gint response, GtkWidget *scrollwin)
g_object_ref (scrollwin); g_object_ref (scrollwin);
gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (scrollwin)), scrollwin); gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (scrollwin)), scrollwin);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw_float_parent), scrollwin); gtk_window_set_child (GTK_WINDOW (sw_float_parent), scrollwin);
g_object_unref (scrollwin); g_object_unref (scrollwin);
@ -2134,6 +2155,10 @@ create_entry (GtkWidget *widget)
box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10); box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
gtk_widget_set_margin_top (box2, 10);
gtk_widget_set_margin_bottom (box2, 10);
gtk_widget_set_margin_start (box2, 10);
gtk_widget_set_margin_end (box2, 10);
gtk_container_add (GTK_CONTAINER (box1), box2); gtk_container_add (GTK_CONTAINER (box1), box2);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
@ -2142,6 +2167,7 @@ create_entry (GtkWidget *widget)
entry = gtk_entry_new (); entry = gtk_entry_new ();
gtk_editable_set_text (GTK_EDITABLE (entry), "hello world \330\247\331\204\330\263\331\204\330\247\331\205 \330\271\331\204\331\212\331\203\331\205"); gtk_editable_set_text (GTK_EDITABLE (entry), "hello world \330\247\331\204\330\263\331\204\330\247\331\205 \330\271\331\204\331\212\331\203\331\205");
gtk_editable_select_region (GTK_EDITABLE (entry), 0, 5); gtk_editable_select_region (GTK_EDITABLE (entry), 0, 5);
gtk_widget_set_hexpand (entry, TRUE);
gtk_container_add (GTK_CONTAINER (hbox), entry); gtk_container_add (GTK_CONTAINER (hbox), entry);
cb = GTK_COMBO_BOX_TEXT (gtk_combo_box_text_new_with_entry ()); cb = GTK_COMBO_BOX_TEXT (gtk_combo_box_text_new_with_entry ());
@ -2158,12 +2184,12 @@ create_entry (GtkWidget *widget)
gtk_combo_box_text_append_text (cb, "item8 item8 item8"); gtk_combo_box_text_append_text (cb, "item8 item8 item8");
gtk_combo_box_text_append_text (cb, "item9 item9"); gtk_combo_box_text_append_text (cb, "item9 item9");
cb_entry = gtk_button_get_child (GTK_BUTTON (cb)); cb_entry = gtk_combo_box_get_child (GTK_COMBO_BOX (cb));
gtk_editable_set_text (GTK_EDITABLE (cb_entry), "hello world \n\n\n foo"); gtk_editable_set_text (GTK_EDITABLE (cb_entry), "hello world \n\n\n foo");
gtk_editable_select_region (GTK_EDITABLE (cb_entry), 0, -1); gtk_editable_select_region (GTK_EDITABLE (cb_entry), 0, -1);
gtk_container_add (GTK_CONTAINER (box2), GTK_WIDGET (cb)); gtk_container_add (GTK_CONTAINER (box2), GTK_WIDGET (cb));
sensitive_check = gtk_check_button_new_with_label("Sensitive"); sensitive_check = gtk_check_button_new_with_label ("Sensitive");
gtk_container_add (GTK_CONTAINER (box2), sensitive_check); gtk_container_add (GTK_CONTAINER (box2), sensitive_check);
g_signal_connect (sensitive_check, "toggled", g_signal_connect (sensitive_check, "toggled",
G_CALLBACK (entry_toggle_sensitive), entry); G_CALLBACK (entry_toggle_sensitive), entry);
@ -2189,6 +2215,10 @@ create_entry (GtkWidget *widget)
gtk_container_add (GTK_CONTAINER (box1), separator); gtk_container_add (GTK_CONTAINER (box1), separator);
box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10); box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
gtk_widget_set_margin_top (box2, 10);
gtk_widget_set_margin_bottom (box2, 10);
gtk_widget_set_margin_start (box2, 10);
gtk_widget_set_margin_end (box2, 10);
gtk_container_add (GTK_CONTAINER (box1), box2); gtk_container_add (GTK_CONTAINER (box1), box2);
button = gtk_button_new_with_label ("close"); button = gtk_button_new_with_label ("close");
@ -2274,6 +2304,7 @@ create_size_group_window (GdkDisplay *display,
{ {
GtkWidget *content_area; GtkWidget *content_area;
GtkWidget *window; GtkWidget *window;
GtkWidget *vbox;
GtkWidget *grid; GtkWidget *grid;
GtkWidget *main_button; GtkWidget *main_button;
GtkWidget *button; GtkWidget *button;
@ -2300,8 +2331,11 @@ create_size_group_window (GdkDisplay *display,
content_area = gtk_dialog_get_content_area (GTK_DIALOG (window)); content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (content_area), vbox);
grid = gtk_grid_new (); grid = gtk_grid_new ();
gtk_container_add (GTK_CONTAINER (content_area), grid); gtk_container_add (GTK_CONTAINER (vbox), grid);
gtk_grid_set_row_spacing (GTK_GRID (grid), 5); gtk_grid_set_row_spacing (GTK_GRID (grid), 5);
gtk_grid_set_column_spacing (GTK_GRID (grid), 5); gtk_grid_set_column_spacing (GTK_GRID (grid), 5);
@ -2362,16 +2396,18 @@ create_size_group_window (GdkDisplay *display,
g_object_unref (vgroup2); g_object_unref (vgroup2);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
gtk_container_add (GTK_CONTAINER (content_area), hbox); gtk_container_add (GTK_CONTAINER (vbox), hbox);
spin_button = gtk_spin_button_new_with_range (1, 100, 1); spin_button = gtk_spin_button_new_with_range (1, 100, 1);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_button), SIZE_GROUP_INITIAL_SIZE); gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_button), SIZE_GROUP_INITIAL_SIZE);
gtk_widget_set_hexpand (spin_button, TRUE);
gtk_container_add (GTK_CONTAINER (hbox), spin_button); gtk_container_add (GTK_CONTAINER (hbox), spin_button);
g_signal_connect (spin_button, "value_changed", g_signal_connect (spin_button, "value_changed",
G_CALLBACK (size_group_hsize_changed), main_button); G_CALLBACK (size_group_hsize_changed), main_button);
spin_button = gtk_spin_button_new_with_range (1, 100, 1); spin_button = gtk_spin_button_new_with_range (1, 100, 1);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_button), SIZE_GROUP_INITIAL_SIZE); gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_button), SIZE_GROUP_INITIAL_SIZE);
gtk_widget_set_hexpand (spin_button, TRUE);
gtk_container_add (GTK_CONTAINER (hbox), spin_button); gtk_container_add (GTK_CONTAINER (hbox), spin_button);
g_signal_connect (spin_button, "value_changed", g_signal_connect (spin_button, "value_changed",
G_CALLBACK (size_group_vsize_changed), main_button); G_CALLBACK (size_group_vsize_changed), main_button);
@ -2635,6 +2671,7 @@ create_spins (GtkWidget *widget)
gtk_container_add (GTK_CONTAINER (vbox), hbox); gtk_container_add (GTK_CONTAINER (vbox), hbox);
vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_hexpand (vbox2, TRUE);
gtk_container_add (GTK_CONTAINER (hbox), vbox2); gtk_container_add (GTK_CONTAINER (hbox), vbox2);
label = gtk_label_new ("Time :"); label = gtk_label_new ("Time :");
@ -2654,6 +2691,7 @@ create_spins (GtkWidget *widget)
gtk_container_add (GTK_CONTAINER (vbox2), spinner); gtk_container_add (GTK_CONTAINER (vbox2), spinner);
vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_hexpand (vbox2, TRUE);
gtk_container_add (GTK_CONTAINER (hbox), vbox2); gtk_container_add (GTK_CONTAINER (hbox), vbox2);
label = gtk_label_new ("Month :"); label = gtk_label_new ("Month :");
@ -2679,6 +2717,7 @@ create_spins (GtkWidget *widget)
gtk_container_add (GTK_CONTAINER (vbox2), spinner); gtk_container_add (GTK_CONTAINER (vbox2), spinner);
vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_hexpand (vbox2, TRUE);
gtk_container_add (GTK_CONTAINER (hbox), vbox2); gtk_container_add (GTK_CONTAINER (hbox), vbox2);
label = gtk_label_new ("Hex :"); label = gtk_label_new ("Hex :");
@ -2762,6 +2801,7 @@ create_spins (GtkWidget *widget)
gtk_container_add (GTK_CONTAINER (vbox), hbox); gtk_container_add (GTK_CONTAINER (vbox), hbox);
button = gtk_button_new_with_label ("Value as Int"); button = gtk_button_new_with_label ("Value as Int");
gtk_widget_set_hexpand (button, TRUE);
g_object_set_data (G_OBJECT (button), "user_data", val_label); g_object_set_data (G_OBJECT (button), "user_data", val_label);
g_signal_connect (button, "clicked", g_signal_connect (button, "clicked",
G_CALLBACK (get_value), G_CALLBACK (get_value),
@ -2769,6 +2809,7 @@ create_spins (GtkWidget *widget)
gtk_container_add (GTK_CONTAINER (hbox), button); gtk_container_add (GTK_CONTAINER (hbox), button);
button = gtk_button_new_with_label ("Value as Float"); button = gtk_button_new_with_label ("Value as Float");
gtk_widget_set_hexpand (button, TRUE);
g_object_set_data (G_OBJECT (button), "user_data", val_label); g_object_set_data (G_OBJECT (button), "user_data", val_label);
g_signal_connect (button, "clicked", g_signal_connect (button, "clicked",
G_CALLBACK (get_value), G_CALLBACK (get_value),
@ -2782,11 +2823,13 @@ create_spins (GtkWidget *widget)
gtk_container_add (GTK_CONTAINER (main_vbox), frame); gtk_container_add (GTK_CONTAINER (main_vbox), frame);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_frame_set_child (GTK_FRAME (frame), vbox); gtk_frame_set_child (GTK_FRAME (frame), hbox);
val_label = gtk_label_new ("0.0"); val_label = gtk_label_new ("0.0");
gtk_widget_set_hexpand (val_label, TRUE);
spinner = gtk_spin_button_new_with_range (0.0, 10.0, 0.009); spinner = gtk_spin_button_new_with_range (0.0, 10.0, 0.009);
gtk_widget_set_hexpand (spinner, TRUE);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinner), 0.0); gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinner), 0.0);
g_signal_connect (spinner, "value_changed", g_signal_connect (spinner, "value_changed",
G_CALLBACK (get_spin_value), val_label); G_CALLBACK (get_spin_value), val_label);
@ -2797,6 +2840,7 @@ create_spins (GtkWidget *widget)
gtk_container_add (GTK_CONTAINER (main_vbox), hbox); gtk_container_add (GTK_CONTAINER (main_vbox), hbox);
button = gtk_button_new_with_label ("Close"); button = gtk_button_new_with_label ("Close");
gtk_widget_set_hexpand (button, TRUE);
g_signal_connect_swapped (button, "clicked", g_signal_connect_swapped (button, "clicked",
G_CALLBACK (gtk_widget_destroy), G_CALLBACK (gtk_widget_destroy),
window); window);
@ -3084,6 +3128,10 @@ create_cursors (GtkWidget *widget)
if (cursor_demo) if (cursor_demo)
{ {
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_widget_set_margin_top (hbox, 5);
gtk_widget_set_margin_bottom (hbox, 5);
gtk_widget_set_margin_start (hbox, 5);
gtk_widget_set_margin_end (hbox, 5);
gtk_container_add (GTK_CONTAINER (vbox), hbox); gtk_container_add (GTK_CONTAINER (vbox), hbox);
label = gtk_label_new ("Cursor Theme:"); label = gtk_label_new ("Cursor Theme:");
@ -3097,6 +3145,7 @@ create_cursors (GtkWidget *widget)
size = gtk_spin_button_new_with_range (1.0, 128.0, 1.0); size = gtk_spin_button_new_with_range (1.0, 128.0, 1.0);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (size), 24.0); gtk_spin_button_set_value (GTK_SPIN_BUTTON (size), 24.0);
gtk_widget_set_hexpand (size, TRUE);
gtk_container_add (GTK_CONTAINER (hbox), size); gtk_container_add (GTK_CONTAINER (hbox), size);
g_signal_connect (entry, "changed", g_signal_connect (entry, "changed",
@ -3106,6 +3155,10 @@ create_cursors (GtkWidget *widget)
} }
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_widget_set_margin_top (hbox, 5);
gtk_widget_set_margin_bottom (hbox, 5);
gtk_widget_set_margin_start (hbox, 5);
gtk_widget_set_margin_end (hbox, 5);
gtk_container_add (GTK_CONTAINER (vbox), hbox); gtk_container_add (GTK_CONTAINER (vbox), hbox);
label = gtk_label_new ("Cursor Name:"); label = gtk_label_new ("Cursor Name:");
@ -3120,6 +3173,7 @@ create_cursors (GtkWidget *widget)
gtk_entry_completion_set_text_column (completion, 0); gtk_entry_completion_set_text_column (completion, 0);
gtk_entry_set_completion (GTK_ENTRY (entry), completion); gtk_entry_set_completion (GTK_ENTRY (entry), completion);
g_object_unref (model); g_object_unref (model);
gtk_widget_set_hexpand (entry, TRUE);
gtk_container_add (GTK_CONTAINER (hbox), entry); gtk_container_add (GTK_CONTAINER (hbox), entry);
frame = frame =
@ -3148,9 +3202,14 @@ create_cursors (GtkWidget *widget)
gtk_container_add (GTK_CONTAINER (main_vbox), any); gtk_container_add (GTK_CONTAINER (main_vbox), any);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_margin_top (hbox, 10);
gtk_widget_set_margin_bottom (hbox, 10);
gtk_widget_set_margin_start (hbox, 10);
gtk_widget_set_margin_end (hbox, 10);
gtk_container_add (GTK_CONTAINER (main_vbox), hbox); gtk_container_add (GTK_CONTAINER (main_vbox), hbox);
button = gtk_button_new_with_label ("Close"); button = gtk_button_new_with_label ("Close");
gtk_widget_set_hexpand (button, TRUE);
g_signal_connect_swapped (button, "clicked", g_signal_connect_swapped (button, "clicked",
G_CALLBACK (gtk_widget_destroy), G_CALLBACK (gtk_widget_destroy),
window); window);
@ -3190,6 +3249,10 @@ create_color_selection (GtkWidget *widget)
gtk_window_set_title (GTK_WINDOW (window), "GtkColorButton"); gtk_window_set_title (GTK_WINDOW (window), "GtkColorButton");
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
gtk_widget_set_margin_top (hbox, 5);
gtk_widget_set_margin_bottom (hbox, 5);
gtk_widget_set_margin_start (hbox, 5);
gtk_widget_set_margin_end (hbox, 5);
gtk_window_set_child (GTK_WINDOW (window), hbox); gtk_window_set_child (GTK_WINDOW (window), hbox);
label = gtk_label_new ("Pick a color"); label = gtk_label_new ("Pick a color");
@ -3367,6 +3430,10 @@ create_font_selection (GtkWidget *widget)
gtk_window_set_title (GTK_WINDOW (window), "GtkFontButton"); gtk_window_set_title (GTK_WINDOW (window), "GtkFontButton");
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
gtk_widget_set_margin_top (hbox, 8);
gtk_widget_set_margin_bottom (hbox, 8);
gtk_widget_set_margin_start (hbox, 8);
gtk_widget_set_margin_end (hbox, 8);
gtk_window_set_child (GTK_WINDOW (window), hbox); gtk_window_set_child (GTK_WINDOW (window), hbox);
label = gtk_label_new ("Pick a font"); label = gtk_label_new ("Pick a font");
@ -3568,7 +3635,7 @@ create_display_screen (GtkWidget *widget)
combo_dpy = gtk_combo_box_text_new_with_entry (); combo_dpy = gtk_combo_box_text_new_with_entry ();
gtk_widget_set_hexpand (combo_dpy, TRUE); gtk_widget_set_hexpand (combo_dpy, TRUE);
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_dpy), "diabolo:0.0"); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_dpy), "diabolo:0.0");
gtk_editable_set_text (GTK_EDITABLE (gtk_button_get_child (GTK_BUTTON (combo_dpy))), gtk_editable_set_text (GTK_EDITABLE (gtk_combo_box_get_child (GTK_COMBO_BOX (combo_dpy))),
"<hostname>:<X Server Num>.<Screen Num>"); "<hostname>:<X Server Num>.<Screen Num>");
gtk_grid_attach (GTK_GRID (grid), label_dpy, 0, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), label_dpy, 0, 0, 1, 1);
@ -3576,9 +3643,9 @@ create_display_screen (GtkWidget *widget)
bbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); bbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_halign (bbox, GTK_ALIGN_END); gtk_widget_set_halign (bbox, GTK_ALIGN_END);
applyb = gtk_button_new_with_label ("_Apply"); applyb = gtk_button_new_with_mnemonic ("_Apply");
cancelb = gtk_button_new_with_label ("_Cancel"); cancelb = gtk_button_new_with_mnemonic ("_Cancel");
gtk_container_add (GTK_CONTAINER (vbox), bbox); gtk_container_add (GTK_CONTAINER (vbox), bbox);
gtk_container_add (GTK_CONTAINER (bbox), applyb); gtk_container_add (GTK_CONTAINER (bbox), applyb);
@ -3586,7 +3653,7 @@ create_display_screen (GtkWidget *widget)
scr_dpy_data = g_new0 (ScreenDisplaySelection, 1); scr_dpy_data = g_new0 (ScreenDisplaySelection, 1);
scr_dpy_data->entry = gtk_button_get_child (GTK_BUTTON (combo_dpy)); scr_dpy_data->entry = gtk_combo_box_get_child (GTK_COMBO_BOX (combo_dpy));
scr_dpy_data->toplevel = GTK_WIDGET (gtk_widget_get_root (widget)); scr_dpy_data->toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
scr_dpy_data->dialog_window = window; scr_dpy_data->dialog_window = window;
@ -3661,10 +3728,9 @@ create_range_controls (GtkWidget *widget)
scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, GTK_ADJUSTMENT (adjustment)); scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, GTK_ADJUSTMENT (adjustment));
gtk_scale_set_draw_value (GTK_SCALE (scale), TRUE); gtk_scale_set_draw_value (GTK_SCALE (scale), TRUE);
g_signal_connect (scale, gtk_scale_set_format_value_func (GTK_SCALE (scale),
"format_value", (GtkScaleFormatValueFunc) reformat_value,
G_CALLBACK (reformat_value), NULL, NULL);
NULL);
gtk_container_add (GTK_CONTAINER (box2), scale); gtk_container_add (GTK_CONTAINER (box2), scale);
gtk_widget_show (scale); gtk_widget_show (scale);
@ -3687,10 +3753,9 @@ create_range_controls (GtkWidget *widget)
scale = gtk_scale_new (GTK_ORIENTATION_VERTICAL, GTK_ADJUSTMENT (adjustment)); scale = gtk_scale_new (GTK_ORIENTATION_VERTICAL, GTK_ADJUSTMENT (adjustment));
gtk_scale_set_draw_value (GTK_SCALE (scale), TRUE); gtk_scale_set_draw_value (GTK_SCALE (scale), TRUE);
g_signal_connect (scale, gtk_scale_set_format_value_func (GTK_SCALE (scale),
"format_value", (GtkScaleFormatValueFunc) reformat_value,
G_CALLBACK (reformat_value), NULL, NULL);
NULL);
gtk_container_add (GTK_CONTAINER (hbox), scale); gtk_container_add (GTK_CONTAINER (hbox), scale);
gtk_widget_show (scale); gtk_widget_show (scale);
@ -3847,7 +3912,7 @@ create_pages (GtkNotebook *notebook, gint start, gint end)
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_box_set_homogeneous (GTK_BOX (vbox), TRUE); gtk_box_set_homogeneous (GTK_BOX (vbox), TRUE);
gtk_container_add (GTK_CONTAINER (child), vbox); gtk_frame_set_child (GTK_FRAME (child), vbox);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE); gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
@ -4021,8 +4086,9 @@ create_notebook (GtkWidget *widget)
sample_notebook = gtk_notebook_new (); sample_notebook = gtk_notebook_new ();
g_signal_connect (sample_notebook, "switch_page", g_signal_connect (sample_notebook, "switch_page",
G_CALLBACK (page_switch), NULL); G_CALLBACK (page_switch), NULL);
gtk_notebook_set_tab_pos (GTK_NOTEBOOK (sample_notebook), GTK_POS_TOP); gtk_notebook_set_tab_pos (GTK_NOTEBOOK (sample_notebook), GTK_POS_TOP);
gtk_widget_set_vexpand (sample_notebook, TRUE);
gtk_container_add (GTK_CONTAINER (box1), sample_notebook); gtk_container_add (GTK_CONTAINER (box1), sample_notebook);
gtk_widget_realize (sample_notebook); gtk_widget_realize (sample_notebook);
@ -4760,9 +4826,10 @@ tracking_label (GtkWidget *window)
gtk_container_add (GTK_CONTAINER (hbox), label); gtk_container_add (GTK_CONTAINER (hbox), label);
g_object_set_data (G_OBJECT (label), "title", (gpointer)gtk_window_get_title (GTK_WINDOW (window))); g_object_set_data (G_OBJECT (label), "title", (gpointer)gtk_window_get_title (GTK_WINDOW (window)));
g_signal_connect (gtk_native_get_surface (GTK_NATIVE (window)), "notify::state", g_signal_connect_object (gtk_native_get_surface (GTK_NATIVE (window)), "notify::state",
G_CALLBACK (surface_state_callback), G_CALLBACK (surface_state_callback),
label); label,
0);
button = gtk_button_new_with_label ("Unminimize"); button = gtk_button_new_with_label ("Unminimize");
g_signal_connect_object (button, g_signal_connect_object (button,
@ -4898,7 +4965,7 @@ create_surface_states (GtkWidget *widget)
G_CALLBACK (gtk_widget_destroyed), G_CALLBACK (gtk_widget_destroyed),
&window); &window);
gtk_window_set_title (GTK_WINDOW (window), "Window states"); gtk_window_set_title (GTK_WINDOW (window), "Surface states");
box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_window_set_child (GTK_WINDOW (window), box1); gtk_window_set_child (GTK_WINDOW (window), box1);
@ -4915,7 +4982,7 @@ create_surface_states (GtkWidget *widget)
gtk_window_minimize (GTK_WINDOW (iconified)); gtk_window_minimize (GTK_WINDOW (iconified));
gtk_window_set_title (GTK_WINDOW (iconified), "Minimized initially"); gtk_window_set_title (GTK_WINDOW (iconified), "Minimized initially");
controls = get_state_controls (iconified); controls = get_state_controls (iconified);
gtk_container_add (GTK_CONTAINER (iconified), controls); gtk_window_set_child (GTK_WINDOW (iconified), controls);
normal = gtk_window_new (); normal = gtk_window_new ();
@ -4929,7 +4996,7 @@ create_surface_states (GtkWidget *widget)
gtk_window_set_title (GTK_WINDOW (normal), "Unminimized initially"); gtk_window_set_title (GTK_WINDOW (normal), "Unminimized initially");
controls = get_state_controls (normal); controls = get_state_controls (normal);
gtk_container_add (GTK_CONTAINER (normal), controls); gtk_window_set_child (GTK_WINDOW (normal), controls);
gtk_widget_realize (iconified); gtk_widget_realize (iconified);
gtk_widget_realize (normal); gtk_widget_realize (normal);
@ -5059,7 +5126,7 @@ window_controls (GtkWidget *window)
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_container_add (GTK_CONTAINER (control_window), vbox); gtk_window_set_child (GTK_WINDOW (control_window), vbox);
label = gtk_label_new ("<no size>"); label = gtk_label_new ("<no size>");
gtk_container_add (GTK_CONTAINER (vbox), label); gtk_container_add (GTK_CONTAINER (vbox), label);
@ -5165,8 +5232,8 @@ create_window_sizing (GtkWidget *widget)
gtk_widget_get_display (widget)); gtk_widget_get_display (widget));
label = gtk_label_new (NULL); label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), "<span foreground=\"purple\"><big>Window being resized</big></span>\nBlah blah blah blah\nblah blah blah\nblah blah blah blah blah"); gtk_label_set_markup (GTK_LABEL (label), "<span foreground=\"purple\"><big>Window being resized</big></span>\nBlah blah blah blah\nblah blah blah\nblah blah blah blah blah");
gtk_container_add (GTK_CONTAINER (target_window), label); gtk_window_set_child (GTK_WINDOW (target_window), label);
gtk_widget_show (label); gtk_widget_show (target_window);
g_signal_connect (target_window, "destroy", g_signal_connect (target_window, "destroy",
G_CALLBACK (gtk_widget_destroyed), G_CALLBACK (gtk_widget_destroyed),
@ -5984,12 +6051,12 @@ struct {
{ "size groups", create_size_groups }, { "size groups", create_size_groups },
{ "spinbutton", create_spins }, { "spinbutton", create_spins },
{ "statusbar", create_statusbar }, { "statusbar", create_statusbar },
{ "surface states", create_surface_states },
{ "test timeout", create_timeout_test }, { "test timeout", create_timeout_test },
{ "toggle buttons", create_toggle_buttons }, { "toggle buttons", create_toggle_buttons },
{ "tooltips", create_tooltips }, { "tooltips", create_tooltips },
{ "WM hints", create_wmhints }, { "WM hints", create_wmhints },
{ "window sizing", create_window_sizing }, { "window sizing", create_window_sizing }
{ "window states", create_surface_states }
}; };
int nbuttons = sizeof (buttons) / sizeof (buttons[0]); int nbuttons = sizeof (buttons) / sizeof (buttons[0]);
@ -6043,6 +6110,10 @@ create_main_window (void)
gtk_widget_set_name (label, "testgtk-version-label"); gtk_widget_set_name (label, "testgtk-version-label");
scrolled_window = gtk_scrolled_window_new (NULL, NULL); scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_set_margin_top (scrolled_window, 10);
gtk_widget_set_margin_bottom (scrolled_window, 10);
gtk_widget_set_margin_start (scrolled_window, 10);
gtk_widget_set_margin_end (scrolled_window, 10);
gtk_widget_set_vexpand (scrolled_window, TRUE); gtk_widget_set_vexpand (scrolled_window, TRUE);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_NEVER, GTK_POLICY_NEVER,
@ -6050,6 +6121,10 @@ create_main_window (void)
gtk_container_add (GTK_CONTAINER (box1), scrolled_window); gtk_container_add (GTK_CONTAINER (box1), scrolled_window);
box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_margin_top (box2, 10);
gtk_widget_set_margin_bottom (box2, 10);
gtk_widget_set_margin_start (box2, 10);
gtk_widget_set_margin_end (box2, 10);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled_window), box2); gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled_window), box2);
gtk_viewport_set_scroll_to_focus (GTK_VIEWPORT (gtk_widget_get_parent (box2)), TRUE); gtk_viewport_set_scroll_to_focus (GTK_VIEWPORT (gtk_widget_get_parent (box2)), TRUE);
gtk_widget_show (box2); gtk_widget_show (box2);
@ -6070,14 +6145,15 @@ create_main_window (void)
separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL); separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
gtk_container_add (GTK_CONTAINER (box1), separator); gtk_container_add (GTK_CONTAINER (box1), separator);
box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
gtk_container_add (GTK_CONTAINER (box1), box2);
button = gtk_button_new_with_mnemonic ("_Close"); button = gtk_button_new_with_mnemonic ("_Close");
gtk_widget_set_margin_top (button, 10);
gtk_widget_set_margin_bottom (button, 10);
gtk_widget_set_margin_start (button, 10);
gtk_widget_set_margin_end (button, 10);
g_signal_connect (button, "clicked", g_signal_connect (button, "clicked",
G_CALLBACK (do_exit), G_CALLBACK (do_exit),
window); window);
gtk_container_add (GTK_CONTAINER (box2), button); gtk_container_add (GTK_CONTAINER (box1), button);
gtk_window_set_default_widget (GTK_WINDOW (window), button); gtk_window_set_default_widget (GTK_WINDOW (window), button);
gtk_widget_show (window); gtk_widget_show (window);

View File

@ -11,11 +11,11 @@ label:selected {
} }
label:hover { label:hover {
background-color: mix (#a0a0a0, rgb (75%, 200, 0%), 0.9); background-color: mix(#a0a0a0, rgb(75%, 78%, 0%), 0.9);
} }
/* override testgtk2, introduce the green color in the button list */ /* override testgtk2, introduce the green color in the button list */
#main_window scrolledwindow button:hover { #main_window scrolledwindow button:hover {
background-color: rgb (0%, 75%, 0); background-color: rgb(0%, 75%, 0%);
} }