Make the widgets work reasonably when they don't have children -- draw the

Thu Oct 17 16:13:28 2002  Owen Taylor  <otaylor@redhat.com>

        * 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.
This commit is contained in:
Owen Taylor 2002-10-17 20:20:52 +00:00 committed by Owen Taylor
parent a9d26e1478
commit de89785a28
9 changed files with 168 additions and 52 deletions

View File

@ -1,3 +1,14 @@
Thu Oct 17 16:13:28 2002 Owen Taylor <otaylor@redhat.com>
* 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 <sandmann@daimi.au.dk> Thu Oct 17 22:09:05 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into * gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into

View File

@ -1,3 +1,14 @@
Thu Oct 17 16:13:28 2002 Owen Taylor <otaylor@redhat.com>
* 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 <sandmann@daimi.au.dk> Thu Oct 17 22:09:05 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into * gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into

View File

@ -1,3 +1,14 @@
Thu Oct 17 16:13:28 2002 Owen Taylor <otaylor@redhat.com>
* 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 <sandmann@daimi.au.dk> Thu Oct 17 22:09:05 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into * gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into

View File

@ -1,3 +1,14 @@
Thu Oct 17 16:13:28 2002 Owen Taylor <otaylor@redhat.com>
* 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 <sandmann@daimi.au.dk> Thu Oct 17 22:09:05 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into * gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into

View File

@ -1,3 +1,14 @@
Thu Oct 17 16:13:28 2002 Owen Taylor <otaylor@redhat.com>
* 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 <sandmann@daimi.au.dk> Thu Oct 17 22:09:05 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into * gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into

View File

@ -1,3 +1,14 @@
Thu Oct 17 16:13:28 2002 Owen Taylor <otaylor@redhat.com>
* 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 <sandmann@daimi.au.dk> Thu Oct 17 22:09:05 2002 Soeren Sandmann <sandmann@daimi.au.dk>
* gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into * gtk/gtkmenu.c (gtk_menu_scroll_to): Take arrows into

View File

@ -177,18 +177,15 @@ gtk_check_button_paint (GtkWidget *widget,
border_width = GTK_CONTAINER (widget)->border_width; border_width = GTK_CONTAINER (widget)->border_width;
if (GTK_WIDGET_HAS_FOCUS (widget)) if (GTK_WIDGET_HAS_FOCUS (widget))
{ {
if (interior_focus) GtkWidget *child = GTK_BIN (widget)->child;
{
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),
if (child && GTK_WIDGET_VISIBLE (child)) NULL, widget, "checkbutton",
gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget), child->allocation.x - focus_width - focus_pad,
NULL, widget, "checkbutton", child->allocation.y - focus_width - focus_pad,
child->allocation.x - focus_width - focus_pad, child->allocation.width + 2 * (focus_width + focus_pad),
child->allocation.y - focus_width - focus_pad, child->allocation.height + 2 * (focus_width + focus_pad));
child->allocation.width + 2 * (focus_width + focus_pad),
child->allocation.height + 2 * (focus_width + focus_pad));
}
else else
gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget), gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
NULL, widget, "checkbutton", NULL, widget, "checkbutton",
@ -245,14 +242,14 @@ gtk_check_button_size_request (GtkWidget *widget,
gtk_widget_size_request (child, &child_requisition); gtk_widget_size_request (child, &child_requisition);
requisition->width += child_requisition.width; requisition->width += child_requisition.width + indicator_spacing;
requisition->height += child_requisition.height; requisition->height += child_requisition.height;
} }
_gtk_check_button_get_props (GTK_CHECK_BUTTON (widget), _gtk_check_button_get_props (GTK_CHECK_BUTTON (widget),
&indicator_size, &indicator_spacing); &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; temp = indicator_size + indicator_spacing * 2;
requisition->height = MAX (requisition->height, temp) + 2 * (focus_width + focus_pad); 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) GdkRectangle *area)
{ {
GtkWidget *widget; GtkWidget *widget;
GtkWidget *child;
GtkButton *button; GtkButton *button;
GtkToggleButton *toggle_button; GtkToggleButton *toggle_button;
GtkStateType state_type; 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; x = widget->allocation.x + indicator_spacing + GTK_CONTAINER (widget)->border_width;
y = widget->allocation.y + (widget->allocation.height - indicator_size) / 2; 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; x += focus_width + focus_pad;
if (toggle_button->inconsistent) if (toggle_button->inconsistent)

View File

@ -599,6 +599,7 @@ gtk_radio_button_draw_indicator (GtkCheckButton *check_button,
GdkRectangle *area) GdkRectangle *area)
{ {
GtkWidget *widget; GtkWidget *widget;
GtkWidget *child;
GtkButton *button; GtkButton *button;
GtkToggleButton *toggle_button; GtkToggleButton *toggle_button;
GtkStateType state_type; 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; x = widget->allocation.x + indicator_spacing + GTK_CONTAINER (widget)->border_width;
y = widget->allocation.y + (widget->allocation.height - indicator_size) / 2; 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; x += focus_width + focus_pad;
if (toggle_button->inconsistent) if (toggle_button->inconsistent)

View File

@ -568,6 +568,62 @@ create_toggle_buttons (GtkWidget *widget)
gtk_widget_destroy (window); 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 * GtkCheckButton
*/ */
@ -580,23 +636,28 @@ create_check_buttons (GtkWidget *widget)
GtkWidget *box2; GtkWidget *box2;
GtkWidget *button; GtkWidget *button;
GtkWidget *separator; GtkWidget *separator;
GtkWidget *table;
if (!window) 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_window_set_screen (GTK_WINDOW (window),
gtk_widget_get_screen (widget)); gtk_widget_get_screen (widget));
g_signal_connect (window, "destroy", g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), G_CALLBACK (gtk_widget_destroyed),
&window); &window);
g_signal_connect (window, "response",
G_CALLBACK (gtk_widget_destroy),
NULL);
gtk_window_set_title (GTK_WINDOW (window), "GtkCheckButton"); box1 = GTK_DIALOG (window)->vbox;
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
box1 = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), box1);
box2 = gtk_vbox_new (FALSE, 10); box2 = gtk_vbox_new (FALSE, 10);
gtk_container_set_border_width (GTK_CONTAINER (box2), 10); gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0); 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"); button = gtk_check_button_new_with_label ("inconsistent");
gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button), TRUE); gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button), TRUE);
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
separator = gtk_hseparator_new (); separator = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
box2 = gtk_vbox_new (FALSE, 10); table = create_widget_grid (GTK_TYPE_CHECK_BUTTON);
gtk_container_set_border_width (GTK_CONTAINER (box2), 10); gtk_container_set_border_width (GTK_CONTAINER (table), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box1), table, TRUE, 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);
} }
if (!GTK_WIDGET_VISIBLE (window)) if (!GTK_WIDGET_VISIBLE (window))
@ -648,10 +701,15 @@ create_radio_buttons (GtkWidget *widget)
GtkWidget *box2; GtkWidget *box2;
GtkWidget *button; GtkWidget *button;
GtkWidget *separator; GtkWidget *separator;
GtkWidget *table;
if (!window) 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_window_set_screen (GTK_WINDOW (window),
gtk_widget_get_screen (widget)); gtk_widget_get_screen (widget));
@ -659,12 +717,11 @@ create_radio_buttons (GtkWidget *widget)
g_signal_connect (window, "destroy", g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), G_CALLBACK (gtk_widget_destroyed),
&window); &window);
g_signal_connect (window, "response",
G_CALLBACK (gtk_widget_destroy),
NULL);
gtk_window_set_title (GTK_WINDOW (window), "radio buttons"); box1 = GTK_DIALOG (window)->vbox;
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
box1 = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), box1);
box2 = gtk_vbox_new (FALSE, 10); box2 = gtk_vbox_new (FALSE, 10);
gtk_container_set_border_width (GTK_CONTAINER (box2), 10); gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
@ -717,17 +774,9 @@ create_radio_buttons (GtkWidget *widget)
separator = gtk_hseparator_new (); separator = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
box2 = gtk_vbox_new (FALSE, 10); table = create_widget_grid (GTK_TYPE_RADIO_BUTTON);
gtk_container_set_border_width (GTK_CONTAINER (box2), 10); gtk_container_set_border_width (GTK_CONTAINER (table), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box1), table, TRUE, 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);
} }
if (!GTK_WIDGET_VISIBLE (window)) if (!GTK_WIDGET_VISIBLE (window))