Commit 0b6c3f54 authored by Owen Taylor's avatar Owen Taylor Committed by Owen Taylor

Patch from Gregory Merchan to add gtk_button_box_set_secondary(), which

Thu Jul  5 21:53:46 2001  Owen Taylor  <otaylor@redhat.com>

	* gtk/gtkbbox.[ch] gtk/gtkbox.[ch] gtk/gtk[hv]bbox.c:
	Patch from Gregory Merchan to add
	gtk_button_box_set_secondary(), which separates
	the child into a separate group from the normal
	buttons. (#56331)

	* gtk/gtkdialog.c: Make help buttons secondary by
	default.

	* gtk/gtkbbox.c: Added a child property "secondary".

	* gtk/testgtk.c: Turn on the help button for the
	color selector to check that it properly appears
	as secondary.
parent d69aa7e9
Thu Jul 5 21:53:46 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkbbox.[ch] gtk/gtkbox.[ch] gtk/gtk[hv]bbox.c:
Patch from Gregory Merchan to add
gtk_button_box_set_secondary(), which separates
the child into a separate group from the normal
buttons. (#56331)
* gtk/gtkdialog.c: Make help buttons secondary by
default.
* gtk/gtkbbox.c: Added a child property "secondary".
* gtk/testgtk.c: Turn on the help button for the
color selector to check that it properly appears
as secondary.
Mon Jul 2 01:09:37 2001 Owen Taylor <otaylor@redhat.com>
* gdk/gdkwindow.[ch] gdk/gdkinternals.h gdk/x11/gdkwindow-x11.c
......
Thu Jul 5 21:53:46 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkbbox.[ch] gtk/gtkbox.[ch] gtk/gtk[hv]bbox.c:
Patch from Gregory Merchan to add
gtk_button_box_set_secondary(), which separates
the child into a separate group from the normal
buttons. (#56331)
* gtk/gtkdialog.c: Make help buttons secondary by
default.
* gtk/gtkbbox.c: Added a child property "secondary".
* gtk/testgtk.c: Turn on the help button for the
color selector to check that it properly appears
as secondary.
Mon Jul 2 01:09:37 2001 Owen Taylor <otaylor@redhat.com>
* gdk/gdkwindow.[ch] gdk/gdkinternals.h gdk/x11/gdkwindow-x11.c
......
Thu Jul 5 21:53:46 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkbbox.[ch] gtk/gtkbox.[ch] gtk/gtk[hv]bbox.c:
Patch from Gregory Merchan to add
gtk_button_box_set_secondary(), which separates
the child into a separate group from the normal
buttons. (#56331)
* gtk/gtkdialog.c: Make help buttons secondary by
default.
* gtk/gtkbbox.c: Added a child property "secondary".
* gtk/testgtk.c: Turn on the help button for the
color selector to check that it properly appears
as secondary.
Mon Jul 2 01:09:37 2001 Owen Taylor <otaylor@redhat.com>
* gdk/gdkwindow.[ch] gdk/gdkinternals.h gdk/x11/gdkwindow-x11.c
......
Thu Jul 5 21:53:46 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkbbox.[ch] gtk/gtkbox.[ch] gtk/gtk[hv]bbox.c:
Patch from Gregory Merchan to add
gtk_button_box_set_secondary(), which separates
the child into a separate group from the normal
buttons. (#56331)
* gtk/gtkdialog.c: Make help buttons secondary by
default.
* gtk/gtkbbox.c: Added a child property "secondary".
* gtk/testgtk.c: Turn on the help button for the
color selector to check that it properly appears
as secondary.
Mon Jul 2 01:09:37 2001 Owen Taylor <otaylor@redhat.com>
* gdk/gdkwindow.[ch] gdk/gdkinternals.h gdk/x11/gdkwindow-x11.c
......
Thu Jul 5 21:53:46 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkbbox.[ch] gtk/gtkbox.[ch] gtk/gtk[hv]bbox.c:
Patch from Gregory Merchan to add
gtk_button_box_set_secondary(), which separates
the child into a separate group from the normal
buttons. (#56331)
* gtk/gtkdialog.c: Make help buttons secondary by
default.
* gtk/gtkbbox.c: Added a child property "secondary".
* gtk/testgtk.c: Turn on the help button for the
color selector to check that it properly appears
as secondary.
Mon Jul 2 01:09:37 2001 Owen Taylor <otaylor@redhat.com>
* gdk/gdkwindow.[ch] gdk/gdkinternals.h gdk/x11/gdkwindow-x11.c
......
Thu Jul 5 21:53:46 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkbbox.[ch] gtk/gtkbox.[ch] gtk/gtk[hv]bbox.c:
Patch from Gregory Merchan to add
gtk_button_box_set_secondary(), which separates
the child into a separate group from the normal
buttons. (#56331)
* gtk/gtkdialog.c: Make help buttons secondary by
default.
* gtk/gtkbbox.c: Added a child property "secondary".
* gtk/testgtk.c: Turn on the help button for the
color selector to check that it properly appears
as secondary.
Mon Jul 2 01:09:37 2001 Owen Taylor <otaylor@redhat.com>
* gdk/gdkwindow.[ch] gdk/gdkinternals.h gdk/x11/gdkwindow-x11.c
......
Thu Jul 5 21:53:46 2001 Owen Taylor <otaylor@redhat.com>
* gtk/gtkbbox.[ch] gtk/gtkbox.[ch] gtk/gtk[hv]bbox.c:
Patch from Gregory Merchan to add
gtk_button_box_set_secondary(), which separates
the child into a separate group from the normal
buttons. (#56331)
* gtk/gtkdialog.c: Make help buttons secondary by
default.
* gtk/gtkbbox.c: Added a child property "secondary".
* gtk/testgtk.c: Turn on the help button for the
color selector to check that it properly appears
as secondary.
Mon Jul 2 01:09:37 2001 Owen Taylor <otaylor@redhat.com>
* gdk/gdkwindow.[ch] gdk/gdkinternals.h gdk/x11/gdkwindow-x11.c
......
......@@ -190,6 +190,7 @@ the start (top/left) or end (bottom/right) of the GtkBox.</entry>
@expand:
@fill:
@pack:
@is_secondary:
<!-- ##### FUNCTION gtk_box_pack_start ##### -->
<para>
......
......@@ -33,16 +33,31 @@ enum {
PROP_LAST
};
static void gtk_button_box_class_init (GtkButtonBoxClass *klass);
static void gtk_button_box_init (GtkButtonBox *box);
static void gtk_button_box_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_button_box_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
enum {
CHILD_PROP_0,
CHILD_PROP_SECONDARY
};
static void gtk_button_box_class_init (GtkButtonBoxClass *klass);
static void gtk_button_box_init (GtkButtonBox *box);
static void gtk_button_box_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_button_box_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gtk_button_box_set_child_property (GtkContainer *container,
GtkWidget *child,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_button_box_get_child_property (GtkContainer *container,
GtkWidget *child,
guint property_id,
GValue *value,
GParamSpec *pspec);
#define DEFAULT_CHILD_MIN_WIDTH 85
#define DEFAULT_CHILD_MIN_HEIGHT 27
......@@ -79,12 +94,17 @@ gtk_button_box_class_init (GtkButtonBoxClass *class)
{
GtkWidgetClass *widget_class;
GObjectClass *gobject_class;
GtkContainerClass *container_class;
gobject_class = G_OBJECT_CLASS (class);
widget_class = (GtkWidgetClass*) class;
container_class = (GtkContainerClass*) class;
gobject_class->set_property = gtk_button_box_set_property;
gobject_class->get_property = gtk_button_box_get_property;
container_class->set_child_property = gtk_button_box_set_child_property;
container_class->get_child_property = gtk_button_box_get_child_property;
/* FIXME we need to override the "spacing" property on GtkBox once
* libgobject allows that.
......@@ -133,6 +153,14 @@ gtk_button_box_class_init (GtkButtonBoxClass *class)
GTK_TYPE_BUTTON_BOX_STYLE,
GTK_BUTTONBOX_DEFAULT_STYLE,
G_PARAM_READWRITE));
gtk_container_class_install_child_property (container_class,
CHILD_PROP_SECONDARY,
g_param_spec_boolean ("secondary",
_("Secondary"),
_("If TRUE, the child appears in a secondary group of children, suitable for, e.g., help buttons."),
FALSE,
G_PARAM_READWRITE));
}
static void
......@@ -181,7 +209,57 @@ gtk_button_box_get_property (GObject *object,
}
}
static void
gtk_button_box_set_child_property (GtkContainer *container,
GtkWidget *child,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
switch (property_id)
{
case CHILD_PROP_SECONDARY:
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (container), child,
g_value_get_boolean (value));
break;
default:
GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
break;
}
}
static void
gtk_button_box_get_child_property (GtkContainer *container,
GtkWidget *child,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GList *list;
GtkBoxChild *child_info = NULL;
list = GTK_BOX (container)->children;
while (list)
{
child_info = list->data;
if (child_info->widget == child)
break;
list = list->next;
}
g_assert (list != NULL);
switch (property_id)
{
case CHILD_PROP_SECONDARY:
g_value_set_boolean (value, child_info->is_secondary);
break;
default:
GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
break;
}
}
/* set per widget values for spacing, child size and child internal padding */
......@@ -229,26 +307,79 @@ void gtk_button_box_get_child_ipadding (GtkButtonBox *widget,
*ipad_y = widget->child_ipad_y;
}
GtkButtonBoxStyle gtk_button_box_get_layout (GtkButtonBox *widget)
GtkButtonBoxStyle
gtk_button_box_get_layout (GtkButtonBox *widget)
{
g_return_val_if_fail (GTK_IS_BUTTON_BOX (widget), GTK_BUTTONBOX_SPREAD);
return widget->layout_style;
}
/**
* gtk_button_box_set_child_secondary
* @widget: a #GtkButtonBox
* @child: a child of @widget
* @is_secondary: if %TRUE, the @child appears in a secondary group of the
* button box.
*
* Sets whether @child should appear in a secondary group of children.
* A typical use of a secondary child is the help button in a dialog.
*
* This group appears after the other children if the style
* is %GTK_BUTTONBOX_START, %GTK_BUTTONBOX_SPREAD or
* %GTK_BUTTONBOX_EDGE, and before the the other children if the style
* is %GTK_BUTTONBOX_END. For horizontal button boxes, the definition
* of before/after depends on direction of the widget. (See
* gtk_widget_set_direction()) If the style is %GTK_BUTTONBOX_START,
* or %GTK_BUTTONBOX_START, then the secondary children are aligned at
* the other end of the button box from the main children. For the
* other styles, they appear immediately next to the main children.
**/
void
gtk_button_box_set_child_secondary (GtkButtonBox *widget,
GtkWidget *child,
gboolean is_secondary)
{
GList *list;
g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
g_return_if_fail (GTK_IS_WIDGET (child));
g_return_if_fail (child->parent == GTK_WIDGET (widget));
list = GTK_BOX (widget)->children;
while (list)
{
GtkBoxChild *child_info = list->data;
if (child_info->widget == child)
{
child_info->is_secondary = is_secondary;
break;
}
list = list->next;
}
gtk_widget_child_notify (child, "secondary");
if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (child))
gtk_widget_queue_resize (child);
}
/* Ask children how much space they require and round up
to match minimum size and internal padding.
Returns the size each single child should have. */
void
_gtk_button_box_child_requisition (GtkWidget *widget,
int *nvis_children,
int *width,
int *height)
int *nvis_children,
int *nvis_secondaries,
int *width,
int *height)
{
GtkButtonBox *bbox;
GtkBoxChild *child;
GList *children;
gint nchildren;
gint nsecondaries;
gint needed_width;
gint needed_height;
GtkRequisition child_requisition;
......@@ -289,6 +420,7 @@ _gtk_button_box_child_requisition (GtkWidget *widget,
? bbox->child_ipad_y : ipad_y_default;
nchildren = 0;
nsecondaries = 0;
children = GTK_BOX(bbox)->children;
needed_width = child_min_width;
needed_height = child_min_height;
......@@ -304,14 +436,22 @@ _gtk_button_box_child_requisition (GtkWidget *widget,
{
nchildren += 1;
gtk_widget_size_request (child->widget, &child_requisition);
if (child_requisition.width + ipad_w > needed_width)
needed_width = child_requisition.width + ipad_w;
needed_width = child_requisition.width + ipad_w;
if (child_requisition.height + ipad_h > needed_height)
needed_height = child_requisition.height + ipad_h;
needed_height = child_requisition.height + ipad_h;
if (child->is_secondary)
nsecondaries++;
}
}
*nvis_children = nchildren;
*width = needed_width;
*height = needed_height;
if (nvis_children)
*nvis_children = nchildren;
if (nvis_secondaries)
*nvis_secondaries = nsecondaries;
if (width)
*width = needed_width;
if (height)
*height = needed_height;
}
......@@ -66,28 +66,37 @@ struct _GtkButtonBoxClass
GtkType gtk_button_box_get_type (void) G_GNUC_CONST;
GtkButtonBoxStyle gtk_button_box_get_layout (GtkButtonBox *widget);
void gtk_button_box_set_layout (GtkButtonBox *widget,
GtkButtonBoxStyle layout_style);
GtkButtonBoxStyle gtk_button_box_get_layout (GtkButtonBox *widget);
void gtk_button_box_set_layout (GtkButtonBox *widget,
GtkButtonBoxStyle layout_style);
void gtk_button_box_set_child_secondary (GtkButtonBox *widget,
GtkWidget *child,
gboolean is_secondary);
#ifndef GTK_DISABLE_DEPRECATED
#define gtk_button_box_set_spacing gtk_box_set_spacing
#define gtk_button_box_get_spacing gtk_box_get_spacing
void gtk_button_box_set_child_size (GtkButtonBox *widget,
gint min_width, gint min_height);
void gtk_button_box_set_child_ipadding (GtkButtonBox *widget, gint ipad_x, gint ipad_y);
void gtk_button_box_get_child_size (GtkButtonBox *widget,
gint *min_width, gint *min_height);
void gtk_button_box_get_child_ipadding (GtkButtonBox *widget, gint *ipad_x, gint *ipad_y);
void gtk_button_box_set_child_size (GtkButtonBox *widget,
gint min_width,
gint min_height);
void gtk_button_box_set_child_ipadding (GtkButtonBox *widget,
gint ipad_x,
gint ipad_y);
void gtk_button_box_get_child_size (GtkButtonBox *widget,
gint *min_width,
gint *min_height);
void gtk_button_box_get_child_ipadding (GtkButtonBox *widget,
gint *ipad_x,
gint *ipad_y);
#endif
/* Internal method - do not use. */
void _gtk_button_box_child_requisition (GtkWidget *widget,
int *nvis_children,
int *width,
int *height);
int *nvis_children,
int *nvis_secondaries,
int *width,
int *height);
#ifdef __cplusplus
}
#endif /* __cplusplus */
......
......@@ -371,6 +371,7 @@ gtk_box_pack_start (GtkBox *box,
child_info->expand = expand ? TRUE : FALSE;
child_info->fill = fill ? TRUE : FALSE;
child_info->pack = GTK_PACK_START;
child_info->is_secondary = FALSE;
box->children = g_list_append (box->children, child_info);
......@@ -416,6 +417,7 @@ gtk_box_pack_end (GtkBox *box,
child_info->expand = expand ? TRUE : FALSE;
child_info->fill = fill ? TRUE : FALSE;
child_info->pack = GTK_PACK_END;
child_info->is_secondary = FALSE;
box->children = g_list_append (box->children, child_info);
......
......@@ -70,6 +70,7 @@ struct _GtkBoxChild
guint expand : 1;
guint fill : 1;
guint pack : 1;
guint is_secondary : 1;
};
......
......@@ -514,7 +514,10 @@ gtk_dialog_add_action_widget (GtkDialog *dialog,
gtk_box_pack_end (GTK_BOX (dialog->action_area),
child,
FALSE, TRUE, 0);
FALSE, TRUE, 0);
if (response_id == GTK_RESPONSE_HELP)
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (dialog->action_area), child, TRUE);
}
/**
......
......@@ -150,6 +150,7 @@ gtk_hbutton_box_size_request (GtkWidget *widget,
_gtk_button_box_child_requisition (widget,
&nvis_children,
NULL,
&child_width,
&child_height);
......@@ -196,9 +197,11 @@ gtk_hbutton_box_size_allocate (GtkWidget *widget,
GList *children;
GtkAllocation child_allocation;
gint nvis_children;
gint n_secondaries;
gint child_width;
gint child_height;
gint x = 0;
gint secondary_x = 0;
gint y = 0;
gint width;
gint childspace;
......@@ -218,6 +221,7 @@ gtk_hbutton_box_size_allocate (GtkWidget *widget,
? box->layout_style : default_layout_style;
_gtk_button_box_child_requisition (widget,
&nvis_children,
&n_secondaries,
&child_width,
&child_height);
widget->allocation = *allocation;
......@@ -225,39 +229,46 @@ gtk_hbutton_box_size_allocate (GtkWidget *widget,
switch (layout)
{
case GTK_BUTTONBOX_SPREAD:
childspacing = (width - (nvis_children*child_width)) / (nvis_children+1);
childspacing = (width - (nvis_children * child_width)) / (nvis_children + 1);
x = allocation->x + GTK_CONTAINER (box)->border_width + childspacing;
secondary_x = x + ((nvis_children - n_secondaries) * (child_width + childspacing));
break;
case GTK_BUTTONBOX_EDGE:
if (nvis_children >= 2)
{
childspacing =
(width - (nvis_children*child_width)) / (nvis_children-1);
x = allocation->x + GTK_CONTAINER (box)->border_width;
}
{
childspacing = (width - (nvis_children * child_width)) / (nvis_children - 1);
x = allocation->x + GTK_CONTAINER (box)->border_width;
secondary_x = x + ((nvis_children - n_secondaries) * (child_width + childspacing));
}
else
{
/* one or zero children, just center */
/* one or zero children, just center */
childspacing = width;
x = allocation->x + (allocation->width - child_width) / 2;
x = secondary_x = allocation->x + (allocation->width - child_width) / 2;
}
break;
case GTK_BUTTONBOX_START:
childspacing = spacing;
x = allocation->x + GTK_CONTAINER (box)->border_width;
secondary_x = allocation->x + allocation->width
- child_width * n_secondaries
- spacing * (n_secondaries - 1)
- GTK_CONTAINER (box)->border_width;
break;
case GTK_BUTTONBOX_END:
childspacing = spacing;
x = allocation->x + allocation->width - child_width * nvis_children
- spacing *(nvis_children-1)
- GTK_CONTAINER (box)->border_width;
x = allocation->x + allocation->width
- child_width * (nvis_children - n_secondaries)
- spacing * (nvis_children - n_secondaries - 1)
- GTK_CONTAINER (box)->border_width;
secondary_x = allocation->x + GTK_CONTAINER (box)->border_width;
break;
default:
g_assert_not_reached();
break;
}
y = allocation->y + (allocation->height - child_height) / 2;
childspace = child_width + childspacing;
......@@ -272,16 +283,23 @@ gtk_hbutton_box_size_allocate (GtkWidget *widget,
{
child_allocation.width = child_width;
child_allocation.height = child_height;
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
child_allocation.x = x;
else
child_allocation.x = allocation->x + allocation->width - (x - allocation->x + child_width);
child_allocation.y = y;
if (child->is_secondary)
{
child_allocation.x = secondary_x;
secondary_x += childspace;
}
else
{
child_allocation.x = x;
x += childspace;
}
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
child_allocation.x = (allocation->x + allocation->width) - (child_allocation.x + child_width - allocation->x);
gtk_widget_size_allocate (child->widget, &child_allocation);
x += childspace;
}
}
}
......
......@@ -152,6 +152,7 @@ gtk_vbutton_box_size_request (GtkWidget *widget,
_gtk_button_box_child_requisition (widget,
&nvis_children,
NULL,
&child_width,
&child_height);
......@@ -199,10 +200,12 @@ gtk_vbutton_box_size_allocate (GtkWidget *widget,
GList *children;
GtkAllocation child_allocation;
gint nvis_children;
gint n_secondaries;
gint child_width;
gint child_height;
gint x = 0;
gint y = 0;
gint secondary_y = 0;
gint height;
gint childspace;
gint childspacing = 0;
......@@ -221,6 +224,7 @@ gtk_vbutton_box_size_allocate (GtkWidget *widget,
? box->layout_style : default_layout_style;
_gtk_button_box_child_requisition (widget,
&nvis_children,
&n_secondaries,
&child_width,
&child_height);
widget->allocation = *allocation;
......@@ -228,32 +232,39 @@ gtk_vbutton_box_size_allocate (GtkWidget *widget,
switch (layout)
{
case GTK_BUTTONBOX_SPREAD:
childspacing = (height - (nvis_children*child_height)) / (nvis_children+1);
childspacing = (height - (nvis_children * child_height)) / (nvis_children + 1);
y = allocation->y + GTK_CONTAINER (box)->border_width + childspacing;
secondary_y = y + ((nvis_children - n_secondaries) * (child_height + childspacing));
break;
case GTK_BUTTONBOX_EDGE:
if (nvis_children >= 2)
{
childspacing =
(height - (nvis_children*child_height)) / (nvis_children-1);
childspacing = (height - (nvis_children*child_height)) / (nvis_children-1);
y = allocation->y + GTK_CONTAINER (box)->border_width;
secondary_y = y + ((nvis_children - n_secondaries) * (child_height + childspacing));
}
else
{
/* one or zero children, just center */
childspacing = height;
y = allocation->y + (allocation->height - child_height) / 2;
/* one or zero children, just center */
childspacing = height;
y = secondary_y = allocation->y + (allocation->height - child_height) / 2;
}
break;
case GTK_BUTTONBOX_START:
childspacing = spacing;
y = allocation->y + GTK_CONTAINER (box)->border_width;
secondary_y = allocation->y + allocation->height
- child_height * n_secondaries
- spacing * (n_secondaries - 1)
- GTK_CONTAINER (box)->border_width;
break;
case GTK_BUTTONBOX_END:
childspacing = spacing;
y = allocation->y + allocation->height - child_height * nvis_children
- spacing * (nvis_children-1)
- GTK_CONTAINER (box)->border_width;
y = allocation->y + allocation->height
- child_height * (nvis_children - n_secondaries)
- spacing * (nvis_children - n_secondaries - 1)
- GTK_CONTAINER (box)->border_width;
secondary_y = allocation->y + GTK_CONTAINER (box)->border_width;
break;
default:
g_assert_not_reached();
......@@ -276,9 +287,19 @@ gtk_vbutton_box_size_allocate (GtkWidget *widget,
child_allocation.width = child_width;
child_allocation.height = child_height;
child_allocation.x = x;
child_allocation.y = y;
if (child->is_secondary)
{
child_allocation.y = secondary_y;
secondary_y += childspace;
}