diff --git a/ChangeLog b/ChangeLog index 0d9b2f1a9a..33336e8378 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Thu Oct 17 16:13:28 2002 Owen Taylor + + * gtk/gtkcheckbutton.c gtk/gtkradiobutton.c: Make + the widgets work reasonably when they don't have + children -- draw the focus around the indicator, + and position the indicator symmetrically. + (#74830, Dave Camp) + + * tests/testgtk.c: Add no-child portions to check and radio + button tests. + Thu Oct 17 22:09:05 2002 Soeren Sandmann * gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 0d9b2f1a9a..33336e8378 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,14 @@ +Thu Oct 17 16:13:28 2002 Owen Taylor + + * gtk/gtkcheckbutton.c gtk/gtkradiobutton.c: Make + the widgets work reasonably when they don't have + children -- draw the focus around the indicator, + and position the indicator symmetrically. + (#74830, Dave Camp) + + * tests/testgtk.c: Add no-child portions to check and radio + button tests. + Thu Oct 17 22:09:05 2002 Soeren Sandmann * gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 0d9b2f1a9a..33336e8378 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,14 @@ +Thu Oct 17 16:13:28 2002 Owen Taylor + + * gtk/gtkcheckbutton.c gtk/gtkradiobutton.c: Make + the widgets work reasonably when they don't have + children -- draw the focus around the indicator, + and position the indicator symmetrically. + (#74830, Dave Camp) + + * tests/testgtk.c: Add no-child portions to check and radio + button tests. + Thu Oct 17 22:09:05 2002 Soeren Sandmann * gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 0d9b2f1a9a..33336e8378 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,14 @@ +Thu Oct 17 16:13:28 2002 Owen Taylor + + * gtk/gtkcheckbutton.c gtk/gtkradiobutton.c: Make + the widgets work reasonably when they don't have + children -- draw the focus around the indicator, + and position the indicator symmetrically. + (#74830, Dave Camp) + + * tests/testgtk.c: Add no-child portions to check and radio + button tests. + Thu Oct 17 22:09:05 2002 Soeren Sandmann * gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 0d9b2f1a9a..33336e8378 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,14 @@ +Thu Oct 17 16:13:28 2002 Owen Taylor + + * gtk/gtkcheckbutton.c gtk/gtkradiobutton.c: Make + the widgets work reasonably when they don't have + children -- draw the focus around the indicator, + and position the indicator symmetrically. + (#74830, Dave Camp) + + * tests/testgtk.c: Add no-child portions to check and radio + button tests. + Thu Oct 17 22:09:05 2002 Soeren Sandmann * gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 0d9b2f1a9a..33336e8378 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,14 @@ +Thu Oct 17 16:13:28 2002 Owen Taylor + + * gtk/gtkcheckbutton.c gtk/gtkradiobutton.c: Make + the widgets work reasonably when they don't have + children -- draw the focus around the indicator, + and position the indicator symmetrically. + (#74830, Dave Camp) + + * tests/testgtk.c: Add no-child portions to check and radio + button tests. + Thu Oct 17 22:09:05 2002 Soeren Sandmann * gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into diff --git a/gtk/gtkcheckbutton.c b/gtk/gtkcheckbutton.c index 1fa1c1f832..963cb6ea99 100644 --- a/gtk/gtkcheckbutton.c +++ b/gtk/gtkcheckbutton.c @@ -177,18 +177,15 @@ gtk_check_button_paint (GtkWidget *widget, border_width = GTK_CONTAINER (widget)->border_width; if (GTK_WIDGET_HAS_FOCUS (widget)) { - if (interior_focus) - { - GtkWidget *child = GTK_BIN (widget)->child; - - if (child && GTK_WIDGET_VISIBLE (child)) - gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget), - NULL, widget, "checkbutton", - child->allocation.x - focus_width - focus_pad, - child->allocation.y - focus_width - focus_pad, - child->allocation.width + 2 * (focus_width + focus_pad), - child->allocation.height + 2 * (focus_width + focus_pad)); - } + GtkWidget *child = GTK_BIN (widget)->child; + + if (interior_focus && child && GTK_WIDGET_VISIBLE (child)) + gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget), + NULL, widget, "checkbutton", + child->allocation.x - focus_width - focus_pad, + child->allocation.y - focus_width - focus_pad, + child->allocation.width + 2 * (focus_width + focus_pad), + child->allocation.height + 2 * (focus_width + focus_pad)); else gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget), NULL, widget, "checkbutton", @@ -245,14 +242,14 @@ gtk_check_button_size_request (GtkWidget *widget, gtk_widget_size_request (child, &child_requisition); - requisition->width += child_requisition.width; + requisition->width += child_requisition.width + indicator_spacing; requisition->height += child_requisition.height; } _gtk_check_button_get_props (GTK_CHECK_BUTTON (widget), &indicator_size, &indicator_spacing); - requisition->width += (indicator_size + indicator_spacing * 3 + 2 * (focus_width + focus_pad)); + requisition->width += (indicator_size + indicator_spacing * 2 + 2 * (focus_width + focus_pad)); temp = indicator_size + indicator_spacing * 2; requisition->height = MAX (requisition->height, temp) + 2 * (focus_width + focus_pad); @@ -376,6 +373,7 @@ gtk_real_check_button_draw_indicator (GtkCheckButton *check_button, GdkRectangle *area) { GtkWidget *widget; + GtkWidget *child; GtkButton *button; GtkToggleButton *toggle_button; GtkStateType state_type; @@ -402,7 +400,8 @@ gtk_real_check_button_draw_indicator (GtkCheckButton *check_button, x = widget->allocation.x + indicator_spacing + GTK_CONTAINER (widget)->border_width; y = widget->allocation.y + (widget->allocation.height - indicator_size) / 2; - if (!interior_focus) + child = GTK_BIN (check_button)->child; + if (!interior_focus || !(child && GTK_WIDGET_VISIBLE (child))) x += focus_width + focus_pad; if (toggle_button->inconsistent) diff --git a/gtk/gtkradiobutton.c b/gtk/gtkradiobutton.c index 57f1b178a0..f7feaf0e7c 100644 --- a/gtk/gtkradiobutton.c +++ b/gtk/gtkradiobutton.c @@ -599,6 +599,7 @@ gtk_radio_button_draw_indicator (GtkCheckButton *check_button, GdkRectangle *area) { GtkWidget *widget; + GtkWidget *child; GtkButton *button; GtkToggleButton *toggle_button; GtkStateType state_type; @@ -626,7 +627,8 @@ gtk_radio_button_draw_indicator (GtkCheckButton *check_button, x = widget->allocation.x + indicator_spacing + GTK_CONTAINER (widget)->border_width; y = widget->allocation.y + (widget->allocation.height - indicator_size) / 2; - if (!interior_focus) + child = GTK_BIN (check_button)->child; + if (!interior_focus || !(child && GTK_WIDGET_VISIBLE (child))) x += focus_width + focus_pad; if (toggle_button->inconsistent) diff --git a/tests/testgtk.c b/tests/testgtk.c index 8b3d158777..490631c72f 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -568,6 +568,62 @@ create_toggle_buttons (GtkWidget *widget) gtk_widget_destroy (window); } +static GtkWidget * +create_widget_grid (GType widget_type) +{ + GtkWidget *table; + GtkWidget *group_widget = NULL; + gint i, j; + + table = gtk_table_new (FALSE, 3, 3); + + for (i = 0; i < 5; i++) + { + for (j = 0; j < 5; j++) + { + GtkWidget *widget; + char *tmp; + + if (i == 0 && j == 0) + { + widget = NULL; + } + else if (i == 0) + { + tmp = g_strdup_printf ("%d", j); + widget = gtk_label_new (tmp); + g_free (tmp); + } + else if (j == 0) + { + tmp = g_strdup_printf ("%c", 'A' + i - 1); + widget = gtk_label_new (tmp); + g_free (tmp); + } + else + { + widget = g_object_new (widget_type, NULL); + + if (g_type_is_a (widget_type, GTK_TYPE_RADIO_BUTTON)) + { + if (!group_widget) + group_widget = widget; + else + g_object_set (widget, "group", group_widget, NULL); + } + } + + if (widget) + gtk_table_attach (GTK_TABLE (table), widget, + i, i + 1, j, j + 1, + 0, 0, + 0, 0); + } + } + + return table; +} + /* * GtkCheckButton */ @@ -580,23 +636,28 @@ create_check_buttons (GtkWidget *widget) GtkWidget *box2; GtkWidget *button; GtkWidget *separator; + GtkWidget *table; if (!window) { - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + window = gtk_dialog_new_with_buttons ("Check Buttons", + NULL, 0, + GTK_STOCK_CLOSE, + GTK_RESPONSE_NONE, + NULL); + gtk_window_set_screen (GTK_WINDOW (window), gtk_widget_get_screen (widget)); g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window); + g_signal_connect (window, "response", + G_CALLBACK (gtk_widget_destroy), + NULL); - gtk_window_set_title (GTK_WINDOW (window), "GtkCheckButton"); - gtk_container_set_border_width (GTK_CONTAINER (window), 0); - - box1 = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (window), box1); - + box1 = GTK_DIALOG (window)->vbox; + box2 = gtk_vbox_new (FALSE, 10); gtk_container_set_border_width (GTK_CONTAINER (box2), 10); gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); @@ -613,21 +674,13 @@ create_check_buttons (GtkWidget *widget) button = gtk_check_button_new_with_label ("inconsistent"); gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button), TRUE); gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); - + separator = gtk_hseparator_new (); gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); - box2 = gtk_vbox_new (FALSE, 10); - gtk_container_set_border_width (GTK_CONTAINER (box2), 10); - gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); - - button = gtk_button_new_with_label ("close"); - g_signal_connect_swapped (button, "clicked", - G_CALLBACK (gtk_widget_destroy), - window); - gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); - GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); - gtk_widget_grab_default (button); + table = create_widget_grid (GTK_TYPE_CHECK_BUTTON); + gtk_container_set_border_width (GTK_CONTAINER (table), 10); + gtk_box_pack_start (GTK_BOX (box1), table, TRUE, TRUE, 0); } if (!GTK_WIDGET_VISIBLE (window)) @@ -648,10 +701,15 @@ create_radio_buttons (GtkWidget *widget) GtkWidget *box2; GtkWidget *button; GtkWidget *separator; + GtkWidget *table; if (!window) { - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + window = gtk_dialog_new_with_buttons ("Radio Buttons", + NULL, 0, + GTK_STOCK_CLOSE, + GTK_RESPONSE_NONE, + NULL); gtk_window_set_screen (GTK_WINDOW (window), gtk_widget_get_screen (widget)); @@ -659,12 +717,11 @@ create_radio_buttons (GtkWidget *widget) g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window); + g_signal_connect (window, "response", + G_CALLBACK (gtk_widget_destroy), + NULL); - gtk_window_set_title (GTK_WINDOW (window), "radio buttons"); - gtk_container_set_border_width (GTK_CONTAINER (window), 0); - - box1 = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (window), box1); + box1 = GTK_DIALOG (window)->vbox; box2 = gtk_vbox_new (FALSE, 10); gtk_container_set_border_width (GTK_CONTAINER (box2), 10); @@ -717,17 +774,9 @@ create_radio_buttons (GtkWidget *widget) separator = gtk_hseparator_new (); gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); - box2 = gtk_vbox_new (FALSE, 10); - gtk_container_set_border_width (GTK_CONTAINER (box2), 10); - gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); - - button = gtk_button_new_with_label ("close"); - g_signal_connect_swapped (button, "clicked", - G_CALLBACK (gtk_widget_destroy), - window); - gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); - GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); - gtk_widget_grab_default (button); + table = create_widget_grid (GTK_TYPE_RADIO_BUTTON); + gtk_container_set_border_width (GTK_CONTAINER (table), 10); + gtk_box_pack_start (GTK_BOX (box1), table, TRUE, TRUE, 0); } if (!GTK_WIDGET_VISIBLE (window))