diff options
author | Davyd Madeley <davyd@madeley.id.au> | 2009-06-02 20:01:19 +0800 |
---|---|---|
committer | Davyd Madeley <davyd@madeley.id.au> | 2009-06-15 09:14:17 +0800 |
commit | 2901695dfd83c30256baabe007f2e137322f01da (patch) | |
tree | 1a3e9cb58df8dba67ea276872fd79e1e7e813dc3 /gtk/gtkvbbox.c | |
parent | 1fe7308dd1797c10cefd2b775e547bf97d0ed275 (diff) | |
download | gtk+-2901695dfd83c30256baabe007f2e137322f01da.tar.gz |
Support GtkOrientable for GtkButtonBox
Edit: Update for coding style
Diffstat (limited to 'gtk/gtkvbbox.c')
-rw-r--r-- | gtk/gtkvbbox.c | 195 |
1 files changed, 3 insertions, 192 deletions
diff --git a/gtk/gtkvbbox.c b/gtk/gtkvbbox.c index e42db03b36..5198e46a30 100644 --- a/gtk/gtkvbbox.c +++ b/gtk/gtkvbbox.c @@ -26,15 +26,11 @@ #include "config.h" #include "gtkvbbox.h" +#include "gtkorientable.h" #include "gtkintl.h" #include "gtkalias.h" -static void gtk_vbutton_box_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void gtk_vbutton_box_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - static gint default_spacing = 10; static GtkButtonBoxStyle default_layout_style = GTK_BUTTONBOX_EDGE; @@ -43,18 +39,13 @@ G_DEFINE_TYPE (GtkVButtonBox, gtk_vbutton_box, GTK_TYPE_BUTTON_BOX) static void gtk_vbutton_box_class_init (GtkVButtonBoxClass *class) { - GtkWidgetClass *widget_class; - - widget_class = (GtkWidgetClass*) class; - - widget_class->size_request = gtk_vbutton_box_size_request; - widget_class->size_allocate = gtk_vbutton_box_size_allocate; } static void gtk_vbutton_box_init (GtkVButtonBox *vbutton_box) { - /* button_box_init has done everything allready */ + gtk_orientable_set_orientation (GTK_ORIENTABLE (vbutton_box), + GTK_ORIENTATION_VERTICAL); } GtkWidget* @@ -107,185 +98,5 @@ gtk_vbutton_box_get_layout_default (void) return default_layout_style; } - - - -static void -gtk_vbutton_box_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - GtkBox *box; - GtkButtonBox *bbox; - gint nvis_children; - gint child_width; - gint child_height; - gint spacing; - GtkButtonBoxStyle layout; - - box = GTK_BOX (widget); - bbox = GTK_BUTTON_BOX (widget); - - spacing = box->spacing; - layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE - ? bbox->layout_style : default_layout_style; - - _gtk_button_box_child_requisition (widget, - &nvis_children, - NULL, - &child_width, - &child_height); - - if (nvis_children == 0) - { - requisition->width = 0; - requisition->height = 0; - } - else - { - switch (layout) - { - case GTK_BUTTONBOX_SPREAD: - requisition->height = - nvis_children*child_height + ((nvis_children+1)*spacing); - break; - case GTK_BUTTONBOX_EDGE: - case GTK_BUTTONBOX_START: - case GTK_BUTTONBOX_END: - case GTK_BUTTONBOX_CENTER: - requisition->height = - nvis_children*child_height + ((nvis_children-1)*spacing); - break; - default: - g_assert_not_reached(); - break; - } - - requisition->width = child_width; - } - - requisition->width += GTK_CONTAINER (box)->border_width * 2; - requisition->height += GTK_CONTAINER (box)->border_width * 2; -} - - - -static void -gtk_vbutton_box_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - GtkBox *base_box; - GtkButtonBox *box; - GtkBoxChild *child; - 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; - GtkButtonBoxStyle layout; - gint spacing; - - base_box = GTK_BOX (widget); - box = GTK_BUTTON_BOX (widget); - spacing = base_box->spacing; - layout = box->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE - ? box->layout_style : default_layout_style; - _gtk_button_box_child_requisition (widget, - &nvis_children, - &n_secondaries, - &child_width, - &child_height); - widget->allocation = *allocation; - height = allocation->height - GTK_CONTAINER (box)->border_width*2; - switch (layout) - { - case GTK_BUTTONBOX_SPREAD: - 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); - 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 = 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 - n_secondaries) - - spacing * (nvis_children - n_secondaries - 1) - - GTK_CONTAINER (box)->border_width; - secondary_y = allocation->y + GTK_CONTAINER (box)->border_width; - break; - case GTK_BUTTONBOX_CENTER: - childspacing = spacing; - y = allocation->y + - (allocation->height - - (child_height * (nvis_children - n_secondaries) - + spacing * (nvis_children - n_secondaries - 1)))/2 - + (n_secondaries * child_height + n_secondaries * spacing)/2; - secondary_y = allocation->y + GTK_CONTAINER (box)->border_width; - break; - default: - g_assert_not_reached(); - break; - } - - - x = allocation->x + (allocation->width - child_width) / 2; - childspace = child_height + childspacing; - - children = GTK_BOX (box)->children; - - while (children) - { - child = children->data; - children = children->next; - - if (GTK_WIDGET_VISIBLE (child->widget)) - { - child_allocation.width = child_width; - child_allocation.height = child_height; - child_allocation.x = x; - - if (child->is_secondary) - { - child_allocation.y = secondary_y; - secondary_y += childspace; - } - else - { - child_allocation.y = y; - y += childspace; - } - - gtk_widget_size_allocate (child->widget, &child_allocation); - } - } -} - #define __GTK_VBBOX_C__ #include "gtkaliasdef.c" |