Merge branch 'button-box-orientable-584598'

This commit is contained in:
Davyd Madeley 2009-06-15 09:48:14 +08:00
commit 0532056349
5 changed files with 469 additions and 385 deletions

View File

@ -26,6 +26,7 @@
#include "config.h"
#include "gtkbbox.h"
#include "gtkorientable.h"
#include "gtkprivate.h"
#include "gtkintl.h"
#include "gtkalias.h"
@ -48,6 +49,10 @@ static void gtk_button_box_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gtk_button_box_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void gtk_button_box_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void gtk_button_box_set_child_property (GtkContainer *container,
GtkWidget *child,
guint property_id,
@ -80,6 +85,9 @@ gtk_button_box_class_init (GtkButtonBoxClass *class)
gobject_class->set_property = gtk_button_box_set_property;
gobject_class->get_property = gtk_button_box_get_property;
widget_class->size_request = gtk_button_box_size_request;
widget_class->size_allocate = gtk_button_box_size_allocate;
container_class->set_child_property = gtk_button_box_set_child_property;
container_class->get_child_property = gtk_button_box_get_child_property;
@ -471,5 +479,346 @@ _gtk_button_box_child_requisition (GtkWidget *widget,
*height = needed_height;
}
/* this is a kludge function to support the deprecated
* gtk_[vh]button_box_set_layout_default() just in case anyone is still
* using it (why?)
*/
static GtkButtonBoxStyle
gtk_button_box_kludge_get_layout_default (GtkButtonBox *widget)
{
GtkOrientation orientation;
orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (widget));
if (orientation == GTK_ORIENTATION_HORIZONTAL)
return gtk_hbutton_box_get_layout_default ();
else
return gtk_vbutton_box_get_layout_default ();
}
static void
gtk_button_box_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
GtkBox *box;
GtkButtonBox *bbox;
gint nvis_children;
gint child_width;
gint child_height;
gint spacing;
GtkButtonBoxStyle layout;
GtkOrientation orientation;
box = GTK_BOX (widget);
bbox = GTK_BUTTON_BOX (widget);
orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (widget));
spacing = box->spacing;
layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
? bbox->layout_style : gtk_button_box_kludge_get_layout_default (GTK_BUTTON_BOX (widget));
_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:
if (orientation == GTK_ORIENTATION_HORIZONTAL)
requisition->width =
nvis_children*child_width + ((nvis_children+1)*spacing);
else
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:
if (orientation == GTK_ORIENTATION_HORIZONTAL)
requisition->width =
nvis_children*child_width + ((nvis_children-1)*spacing);
else
requisition->height =
nvis_children*child_height + ((nvis_children-1)*spacing);
break;
default:
g_assert_not_reached ();
break;
}
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
requisition->height = child_height;
}
else
{
requisition->width = child_width;
}
}
requisition->width += GTK_CONTAINER (box)->border_width * 2;
requisition->height += GTK_CONTAINER (box)->border_width * 2;
}
static void
gtk_button_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_x = 0;
gint secondary_y = 0;
gint width;
gint height;
gint childspace;
gint childspacing = 0;
GtkButtonBoxStyle layout;
gint spacing;
GtkOrientation orientation;
orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (widget));
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 : gtk_button_box_kludge_get_layout_default (GTK_BUTTON_BOX (widget));
_gtk_button_box_child_requisition (widget,
&nvis_children,
&n_secondaries,
&child_width,
&child_height);
widget->allocation = *allocation;
if (orientation == GTK_ORIENTATION_HORIZONTAL)
width = allocation->width - GTK_CONTAINER (box)->border_width*2;
else
height = allocation->height - GTK_CONTAINER (box)->border_width*2;
switch (layout)
{
case GTK_BUTTONBOX_SPREAD:
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
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));
}
else
{
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 (orientation == GTK_ORIENTATION_HORIZONTAL)
{
if (nvis_children >= 2)
{
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 */
childspacing = width;
x = secondary_x = allocation->x
+ (allocation->width - child_width) / 2;
}
}
else
{
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:
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
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;
}
else
{
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:
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
childspacing = spacing;
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;
}
else
{
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:
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
childspacing = spacing;
x = allocation->x +
(allocation->width
- (child_width * (nvis_children - n_secondaries)
+ spacing * (nvis_children - n_secondaries - 1)))/2
+ (n_secondaries * child_width + n_secondaries * spacing)/2;
secondary_x = allocation->x + GTK_CONTAINER (box)->border_width;
}
else
{
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;
}
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
y = allocation->y + (allocation->height - child_height) / 2;
childspace = child_width + childspacing;
}
else
{
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;
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
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);
}
else
{
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_BUTTON_BOX_C__
#include "gtkaliasdef.c"

View File

@ -26,15 +26,11 @@
#include "config.h"
#include "gtkhbbox.h"
#include "gtkorientable.h"
#include "gtkintl.h"
#include "gtkalias.h"
static void gtk_hbutton_box_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void gtk_hbutton_box_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static gint default_spacing = 30;
static gint default_layout_style = GTK_BUTTONBOX_EDGE;
@ -43,18 +39,13 @@ G_DEFINE_TYPE (GtkHButtonBox, gtk_hbutton_box, GTK_TYPE_BUTTON_BOX)
static void
gtk_hbutton_box_class_init (GtkHButtonBoxClass *class)
{
GtkWidgetClass *widget_class;
widget_class = (GtkWidgetClass*) class;
widget_class->size_request = gtk_hbutton_box_size_request;
widget_class->size_allocate = gtk_hbutton_box_size_allocate;
}
static void
gtk_hbutton_box_init (GtkHButtonBox *hbutton_box)
{
/* button_box_init has done everything already */
gtk_orientable_set_orientation (GTK_ORIENTABLE (hbutton_box),
GTK_ORIENTATION_HORIZONTAL);
}
GtkWidget*
@ -105,186 +96,5 @@ gtk_hbutton_box_get_layout_default (void)
return default_layout_style;
}
static void
gtk_hbutton_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->width =
nvis_children*child_width + ((nvis_children+1)*spacing);
break;
case GTK_BUTTONBOX_EDGE:
case GTK_BUTTONBOX_START:
case GTK_BUTTONBOX_END:
case GTK_BUTTONBOX_CENTER:
requisition->width = nvis_children*child_width + ((nvis_children-1)*spacing);
break;
default:
g_assert_not_reached();
break;
}
requisition->height = child_height;
}
requisition->width += GTK_CONTAINER (box)->border_width * 2;
requisition->height += GTK_CONTAINER (box)->border_width * 2;
}
static void
gtk_hbutton_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 secondary_x = 0;
gint y = 0;
gint width;
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;
width = allocation->width - GTK_CONTAINER (box)->border_width*2;
switch (layout)
{
case GTK_BUTTONBOX_SPREAD:
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;
secondary_x = x + ((nvis_children - n_secondaries) * (child_width + childspacing));
}
else
{
/* one or zero children, just center */
childspacing = width;
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 - n_secondaries)
- spacing * (nvis_children - n_secondaries - 1)
- GTK_CONTAINER (box)->border_width;
secondary_x = allocation->x + GTK_CONTAINER (box)->border_width;
break;
case GTK_BUTTONBOX_CENTER:
childspacing = spacing;
x = allocation->x +
(allocation->width
- (child_width * (nvis_children - n_secondaries)
+ spacing * (nvis_children - n_secondaries - 1)))/2
+ (n_secondaries * child_width + n_secondaries * spacing)/2;
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;
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.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);
}
}
}
#define __GTK_HBUTTON_BOX_C__
#include "gtkaliasdef.c"

View File

@ -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"

View File

@ -55,6 +55,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testmultiscreen \
testnotebookdnd \
testnouiprint \
testorientable \
testprint \
testrgb \
testrecentchooser \
@ -133,6 +134,7 @@ testmultidisplay_DEPENDENCIES = $(TEST_DEPS)
testmultiscreen_DEPENDENCIES = $(TEST_DEPS)
testnotebookdnd_DEPENDENCIES = $(TEST_DEPS)
testnouiprint_DEPENDENCIES = $(TEST_DEPS)
testorientable_DEPENDENCIES = $(TEST_DEPS)
testprint_DEPENDENCIES = $(TEST_DEPS)
testrecentchooser_DEPENDENCIES = $(TEST_DEPS)
testrecentchoosermenu_DEPENDENCIES = $(TEST_DEPS)
@ -191,6 +193,7 @@ testmultidisplay_LDADD = $(LDADDS)
testmultiscreen_LDADD = $(LDADDS)
testnotebookdnd_LDADD = $(LDADDS)
testnouiprint_LDADD = $(LDADDS)
testorientable_LDADD = $(LDADDS)
testprint_LDADD = $(LDADDS)
testrecentchooser_LDADD = $(LDADDS)
testrecentchoosermenu_LDADD = $(LDADDS)

111
tests/testorientable.c Normal file
View File

@ -0,0 +1,111 @@
/* testorientable.c
* Copyright (C) 2004 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <gtk/gtk.h>
static void
orient_toggled (GtkToggleButton *button, gpointer user_data)
{
GList *orientables = (GList *) user_data, *ptr;
gboolean state = gtk_toggle_button_get_active (button);
GtkOrientation orientation;
if (state)
{
orientation = GTK_ORIENTATION_VERTICAL;
gtk_button_set_label (GTK_BUTTON (button), "Vertical");
}
else
{
orientation = GTK_ORIENTATION_HORIZONTAL;
gtk_button_set_label (GTK_BUTTON (button), "Horizontal");
}
for (ptr = orientables; ptr; ptr = ptr->next)
{
GtkOrientable *orientable = GTK_ORIENTABLE (ptr->data);
gtk_orientable_set_orientation (orientable, orientation);
}
}
int
main (int argc, char **argv)
{
GtkWidget *window;
GtkWidget *table;
GtkWidget *box, *button;
GList *orientables = NULL;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
table = gtk_table_new (2, 3, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 12);
gtk_table_set_col_spacings (GTK_TABLE (table), 12);
/* GtkBox */
box = gtk_hbox_new (6, FALSE);
orientables = g_list_prepend (orientables, box);
gtk_table_attach_defaults (GTK_TABLE (table), box, 0, 1, 1, 2);
gtk_box_pack_start (GTK_BOX (box),
gtk_button_new_with_label ("GtkBox 1"),
TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (box),
gtk_button_new_with_label ("GtkBox 2"),
TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (box),
gtk_button_new_with_label ("GtkBox 3"),
TRUE, TRUE, 0);
/* GtkButtonBox */
box = gtk_hbutton_box_new ();
orientables = g_list_prepend (orientables, box);
gtk_table_attach_defaults (GTK_TABLE (table), box, 1, 2, 1, 2);
gtk_box_pack_start (GTK_BOX (box),
gtk_button_new_with_label ("GtkButtonBox 1"),
TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (box),
gtk_button_new_with_label ("GtkButtonBox 2"),
TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (box),
gtk_button_new_with_label ("GtkButtonBox 3"),
TRUE, TRUE, 0);
/* GtkSeparator */
box = gtk_hseparator_new ();
orientables = g_list_prepend (orientables, box);
gtk_table_attach_defaults (GTK_TABLE (table), box, 2, 3, 1, 2);
button = gtk_toggle_button_new_with_label ("Horizontal");
gtk_table_attach (GTK_TABLE (table), button, 0, 1, 0, 1,
GTK_FILL, GTK_FILL, 0, 0);
g_signal_connect (button, "toggled",
G_CALLBACK (orient_toggled), orientables);
gtk_container_add (GTK_CONTAINER (window), table);
gtk_widget_show_all (window);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
gtk_main ();
return 0;
}