gtk+ r21596 - in trunk: . gtk
- From: mitch svn gnome org
- To: svn-commits-list gnome org
- Subject: gtk+ r21596 - in trunk: . gtk
- Date: Tue, 7 Oct 2008 07:44:07 +0000 (UTC)
Author: mitch
Date: Tue Oct 7 07:44:06 2008
New Revision: 21596
URL: http://svn.gnome.org/viewvc/gtk+?rev=21596&view=rev
Log:
2008-10-07 Michael Natterer <mitch imendio com>
Bug 553573 â Add orientation API to GtkBox
* gtk/gtkbox.[hh]: implement the GtkOrientable interface and
swallow all code from GtkHBox and GtkVBox. Add gtk_box_new()
which takes a GtkOrientation argument. Also move the newly
added "spacing_set" boolean from struct GtkBox to the new
private struct.
* gtk/gtkhbox.[ch]
* gtk/gtkvbox.[ch]: remove all code except the constructor and
call gtk_orientable_set_orientation() in init().
* gtk/gtk.symbols: add gtk_box_new().
Modified:
trunk/ChangeLog
trunk/gtk/gtk.symbols
trunk/gtk/gtkbox.c
trunk/gtk/gtkbox.h
trunk/gtk/gtkhbox.c
trunk/gtk/gtkhbox.h
trunk/gtk/gtkvbox.c
trunk/gtk/gtkvbox.h
Modified: trunk/gtk/gtk.symbols
==============================================================================
--- trunk/gtk/gtk.symbols (original)
+++ trunk/gtk/gtk.symbols Tue Oct 7 07:44:06 2008
@@ -427,6 +427,7 @@
gtk_box_get_homogeneous
gtk_box_get_spacing
gtk_box_get_type G_GNUC_CONST
+gtk_box_new
gtk_box_pack_end
gtk_box_pack_start
#ifndef GTK_DISABLE_DEPRECATED
Modified: trunk/gtk/gtkbox.c
==============================================================================
--- trunk/gtk/gtkbox.c (original)
+++ trunk/gtk/gtkbox.c Tue Oct 7 07:44:06 2008
@@ -21,17 +21,20 @@
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
+
#include "gtkbox.h"
+#include "gtkorientable.h"
#include "gtkprivate.h"
#include "gtkintl.h"
#include "gtkalias.h"
enum {
PROP_0,
+ PROP_ORIENTATION,
PROP_SPACING,
PROP_HOMOGENEOUS
};
@@ -45,6 +48,19 @@
CHILD_PROP_POSITION
};
+
+typedef struct _GtkBoxPrivate GtkBoxPrivate;
+
+struct _GtkBoxPrivate
+{
+ GtkOrientation orientation;
+ guint default_expand : 1;
+ guint spacing_set : 1;
+};
+
+#define GTK_BOX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_BOX, GtkBoxPrivate))
+
+
static void gtk_box_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -53,6 +69,12 @@
guint prop_id,
GValue *value,
GParamSpec *pspec);
+
+static void gtk_box_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static void gtk_box_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+
static void gtk_box_add (GtkContainer *container,
GtkWidget *widget);
static void gtk_box_remove (GtkContainer *container,
@@ -72,19 +94,26 @@
GValue *value,
GParamSpec *pspec);
static GType gtk_box_child_type (GtkContainer *container);
-
-G_DEFINE_ABSTRACT_TYPE (GtkBox, gtk_box, GTK_TYPE_CONTAINER)
+
+G_DEFINE_TYPE_WITH_CODE (GtkBox, gtk_box, GTK_TYPE_CONTAINER,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
+ NULL))
+
static void
gtk_box_class_init (GtkBoxClass *class)
{
- GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
- gobject_class->set_property = gtk_box_set_property;
- gobject_class->get_property = gtk_box_get_property;
-
+ object_class->set_property = gtk_box_set_property;
+ object_class->get_property = gtk_box_get_property;
+
+ widget_class->size_request = gtk_box_size_request;
+ widget_class->size_allocate = gtk_box_size_allocate;
+
container_class->add = gtk_box_add;
container_class->remove = gtk_box_remove;
container_class->forall = gtk_box_forall;
@@ -92,7 +121,11 @@
container_class->set_child_property = gtk_box_set_child_property;
container_class->get_child_property = gtk_box_get_child_property;
- g_object_class_install_property (gobject_class,
+ g_object_class_override_property (object_class,
+ PROP_ORIENTATION,
+ "orientation");
+
+ g_object_class_install_property (object_class,
PROP_SPACING,
g_param_spec_int ("spacing",
P_("Spacing"),
@@ -102,7 +135,7 @@
0,
GTK_PARAM_READWRITE));
- g_object_class_install_property (gobject_class,
+ g_object_class_install_property (object_class,
PROP_HOMOGENEOUS,
g_param_spec_boolean ("homogeneous",
P_("Homogeneous"),
@@ -145,32 +178,42 @@
P_("The index of the child in the parent"),
-1, G_MAXINT, 0,
GTK_PARAM_READWRITE));
+
+ g_type_class_add_private (object_class, sizeof (GtkBoxPrivate));
}
static void
gtk_box_init (GtkBox *box)
{
+ GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
+
GTK_WIDGET_SET_FLAGS (box, GTK_NO_WINDOW);
gtk_widget_set_redraw_on_allocate (GTK_WIDGET (box), FALSE);
-
+
box->children = NULL;
box->spacing = 0;
- box->spacing_set = FALSE;
box->homogeneous = FALSE;
+
+ private->orientation = GTK_ORIENTATION_HORIZONTAL;
+ private->default_expand = FALSE;
+ private->spacing_set = FALSE;
}
-static void
-gtk_box_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+static void
+gtk_box_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- GtkBox *box;
-
- box = GTK_BOX (object);
+ GtkBox *box = GTK_BOX (object);
+ GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
switch (prop_id)
{
+ case PROP_ORIENTATION:
+ private->orientation = g_value_get_enum (value);
+ gtk_widget_queue_resize (GTK_WIDGET (box));
+ break;
case PROP_SPACING:
gtk_box_set_spacing (box, g_value_get_int (value));
break;
@@ -183,17 +226,20 @@
}
}
-static void gtk_box_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+static void
+gtk_box_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- GtkBox *box;
-
- box = GTK_BOX (object);
+ GtkBox *box = GTK_BOX (object);
+ GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
switch (prop_id)
{
+ case PROP_ORIENTATION:
+ g_value_set_enum (value, private->orientation);
+ break;
case PROP_SPACING:
g_value_set_int (value, box->spacing);
break;
@@ -206,6 +252,357 @@
}
}
+static void
+gtk_box_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ GtkBox *box = GTK_BOX (widget);
+ GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
+ GtkBoxChild *child;
+ GList *children;
+ gint nvis_children;
+ gint width;
+ gint height;
+
+ requisition->width = 0;
+ requisition->height = 0;
+ nvis_children = 0;
+
+ children = box->children;
+ while (children)
+ {
+ child = children->data;
+ children = children->next;
+
+ if (GTK_WIDGET_VISIBLE (child->widget))
+ {
+ GtkRequisition child_requisition;
+
+ gtk_widget_size_request (child->widget, &child_requisition);
+
+ if (box->homogeneous)
+ {
+ width = child_requisition.width + child->padding * 2;
+ height = child_requisition.height + child->padding * 2;
+
+ if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
+ requisition->width = MAX (requisition->width, width);
+ else
+ requisition->height = MAX (requisition->height, height);
+ }
+ else
+ {
+ if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
+ requisition->width += child_requisition.width + child->padding * 2;
+ else
+ requisition->height += child_requisition.height + child->padding * 2;
+ }
+
+ if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
+ requisition->height = MAX (requisition->height, child_requisition.height);
+ else
+ requisition->width = MAX (requisition->width, child_requisition.width);
+
+ nvis_children += 1;
+ }
+ }
+
+ if (nvis_children > 0)
+ {
+ if (box->homogeneous)
+ {
+ if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
+ requisition->width *= nvis_children;
+ else
+ requisition->height *= nvis_children;
+ }
+
+ if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
+ requisition->width += (nvis_children - 1) * box->spacing;
+ else
+ requisition->height += (nvis_children - 1) * box->spacing;
+ }
+
+ requisition->width += GTK_CONTAINER (box)->border_width * 2;
+ requisition->height += GTK_CONTAINER (box)->border_width * 2;
+}
+
+static void
+gtk_box_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ GtkBox *box = GTK_BOX (widget);
+ GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
+ GtkBoxChild *child;
+ GList *children;
+ GtkAllocation child_allocation;
+ gint nvis_children = 0;
+ gint nexpand_children = 0;
+ gint child_width = 0;
+ gint child_height = 0;
+ gint width = 0;
+ gint height = 0;
+ gint extra = 0;
+ gint x = 0;
+ gint y = 0;
+ GtkTextDirection direction;
+
+ widget->allocation = *allocation;
+
+ direction = gtk_widget_get_direction (widget);
+
+ for (children = box->children; children; children = children->next)
+ {
+ child = children->data;
+
+ if (GTK_WIDGET_VISIBLE (child->widget))
+ {
+ nvis_children += 1;
+ if (child->expand)
+ nexpand_children += 1;
+ }
+ }
+
+ if (nvis_children > 0)
+ {
+ if (box->homogeneous)
+ {
+ if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ width = (allocation->width -
+ GTK_CONTAINER (box)->border_width * 2 -
+ (nvis_children - 1) * box->spacing);
+ extra = width / nvis_children;
+ }
+ else
+ {
+ height = (allocation->height -
+ GTK_CONTAINER (box)->border_width * 2 -
+ (nvis_children - 1) * box->spacing);
+ extra = height / nvis_children;
+ }
+ }
+ else if (nexpand_children > 0)
+ {
+ if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ width = (gint) allocation->width - (gint) widget->requisition.width;
+ extra = width / nexpand_children;
+ }
+ else
+ {
+ height = (gint) allocation->height - (gint) widget->requisition.height;
+ extra = height / nexpand_children;
+ }
+ }
+
+ if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ x = allocation->x + GTK_CONTAINER (box)->border_width;
+ child_allocation.y = allocation->y + GTK_CONTAINER (box)->border_width;
+ child_allocation.height = MAX (1, (gint) allocation->height - (gint) GTK_CONTAINER (box)->border_width * 2);
+ }
+ else
+ {
+ y = allocation->y + GTK_CONTAINER (box)->border_width;
+ child_allocation.x = allocation->x + GTK_CONTAINER (box)->border_width;
+ child_allocation.width = MAX (1, (gint) allocation->width - (gint) GTK_CONTAINER (box)->border_width * 2);
+ }
+
+ children = box->children;
+ while (children)
+ {
+ child = children->data;
+ children = children->next;
+
+ if ((child->pack == GTK_PACK_START) && GTK_WIDGET_VISIBLE (child->widget))
+ {
+ if (box->homogeneous)
+ {
+ if (nvis_children == 1)
+ {
+ child_width = width;
+ child_height = height;
+ }
+ else
+ {
+ child_width = extra;
+ child_height = extra;
+ }
+
+ nvis_children -= 1;
+ width -= extra;
+ height -= extra;
+ }
+ else
+ {
+ GtkRequisition child_requisition;
+
+ gtk_widget_get_child_requisition (child->widget, &child_requisition);
+
+ child_width = child_requisition.width + child->padding * 2;
+ child_height = child_requisition.height + child->padding * 2;
+
+ if (child->expand)
+ {
+ if (nexpand_children == 1)
+ {
+ child_width += width;
+ child_height += height;
+ }
+ else
+ {
+ child_width += extra;
+ child_height += extra;
+ }
+
+ nexpand_children -= 1;
+ width -= extra;
+ height -= extra;
+ }
+ }
+
+ if (child->fill)
+ {
+ if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ child_allocation.width = MAX (1, (gint) child_width - (gint) child->padding * 2);
+ child_allocation.x = x + child->padding;
+ }
+ else
+ {
+ child_allocation.height = MAX (1, child_height - (gint)child->padding * 2);
+ child_allocation.y = y + child->padding;
+ }
+ }
+ else
+ {
+ GtkRequisition child_requisition;
+
+ gtk_widget_get_child_requisition (child->widget, &child_requisition);
+ if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ child_allocation.width = child_requisition.width;
+ child_allocation.x = x + (child_width - child_allocation.width) / 2;
+ }
+ else
+ {
+ child_allocation.height = child_requisition.height;
+ child_allocation.y = y + (child_height - child_allocation.height) / 2;
+ }
+ }
+
+ if (direction == GTK_TEXT_DIR_RTL &&
+ private->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width;
+ }
+
+ gtk_widget_size_allocate (child->widget, &child_allocation);
+
+ x += child_width + box->spacing;
+ y += child_height + box->spacing;
+ }
+ }
+
+ x = allocation->x + allocation->width - GTK_CONTAINER (box)->border_width;
+ y = allocation->y + allocation->height - GTK_CONTAINER (box)->border_width;
+
+ children = box->children;
+ while (children)
+ {
+ child = children->data;
+ children = children->next;
+
+ if ((child->pack == GTK_PACK_END) && GTK_WIDGET_VISIBLE (child->widget))
+ {
+ GtkRequisition child_requisition;
+
+ gtk_widget_get_child_requisition (child->widget, &child_requisition);
+
+ if (box->homogeneous)
+ {
+ if (nvis_children == 1)
+ {
+ child_width = width;
+ child_height = height;
+ }
+ else
+ {
+ child_width = extra;
+ child_height = extra;
+ }
+
+ nvis_children -= 1;
+ width -= extra;
+ height -= extra;
+ }
+ else
+ {
+ child_width = child_requisition.width + child->padding * 2;
+ child_height = child_requisition.height + child->padding * 2;
+
+ if (child->expand)
+ {
+ if (nexpand_children == 1)
+ {
+ child_width += width;
+ child_height += height;
+ }
+ else
+ {
+ child_width += extra;
+ child_height += extra;
+ }
+
+ nexpand_children -= 1;
+ width -= extra;
+ height -= extra;
+ }
+ }
+
+ if (child->fill)
+ {
+ if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ child_allocation.width = MAX (1, (gint)child_width - (gint)child->padding * 2);
+ child_allocation.x = x + child->padding - child_width;
+ }
+ else
+ {
+ child_allocation.height = MAX (1, child_height - (gint)child->padding * 2);
+ child_allocation.y = y + child->padding - child_height;
+ }
+ }
+ else
+ {
+ if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ child_allocation.width = child_requisition.width;
+ child_allocation.x = x + (child_width - child_allocation.width) / 2 - child_width;
+ }
+ else
+ {
+ child_allocation.height = child_requisition.height;
+ child_allocation.y = y + (child_height - child_allocation.height) / 2 - child_height;
+ }
+ }
+
+ if (direction == GTK_TEXT_DIR_RTL &&
+ private->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width;
+ }
+
+ gtk_widget_size_allocate (child->widget, &child_allocation);
+
+ x -= (child_width + box->spacing);
+ y -= (child_height + box->spacing);
+ }
+ }
+ }
+}
+
static GType
gtk_box_child_type (GtkContainer *container)
{
@@ -367,6 +764,30 @@
}
/**
+ * gtk_box_new:
+ * @orientation: the box' orientation.
+ * @homogeneous: %TRUE if all children are to be given equal space allocations.
+ * @spacing: the number of pixels to place by default between children.
+ *
+ * Creates a new #GtkHBox.
+ *
+ * Return value: a new #GtkHBox.
+ *
+ * Since: 2.16
+ **/
+GtkWidget *
+gtk_box_new (GtkOrientation orientation,
+ gboolean homogeneous,
+ gint spacing)
+{
+ return g_object_new (GTK_TYPE_BOX,
+ "orientation", orientation,
+ "spacing", spacing,
+ "homogeneous", homogeneous ? TRUE : FALSE,
+ NULL);
+}
+
+/**
* gtk_box_pack_start:
* @box: a #GtkBox
* @child: the #GtkWidget to be added to @box
@@ -532,7 +953,7 @@
if (spacing != box->spacing)
{
box->spacing = spacing;
- box->spacing_set = TRUE;
+ _gtk_box_set_spacing_set (box, TRUE);
g_object_notify (G_OBJECT (box), "spacing");
@@ -560,17 +981,25 @@
_gtk_box_set_spacing_set (GtkBox *box,
gboolean spacing_set)
{
+ GtkBoxPrivate *private;
+
g_return_if_fail (GTK_IS_BOX (box));
- box->spacing_set = spacing_set;
+ private = GTK_BOX_GET_PRIVATE (box);
+
+ private->spacing_set = spacing_set ? TRUE : FALSE;
}
gboolean
_gtk_box_get_spacing_set (GtkBox *box)
{
+ GtkBoxPrivate *private;
+
g_return_val_if_fail (GTK_IS_BOX (box), FALSE);
- return box->spacing_set;
+ private = GTK_BOX_GET_PRIVATE (box);
+
+ return private->spacing_set;
}
/**
@@ -740,11 +1169,28 @@
gtk_widget_thaw_child_notify (child);
}
+void
+_gtk_box_set_default_expand (GtkBox *box)
+{
+ GtkBoxPrivate *private;
+
+ g_return_if_fail (GTK_IS_BOX (box));
+
+ private = GTK_BOX_GET_PRIVATE (box);
+
+ private->default_expand = TRUE;
+}
+
static void
gtk_box_add (GtkContainer *container,
GtkWidget *widget)
{
- gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
+ GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (container);
+
+ gtk_box_pack_start (GTK_BOX (container), widget,
+ private->default_expand,
+ private->default_expand,
+ 0);
}
static void
Modified: trunk/gtk/gtkbox.h
==============================================================================
--- trunk/gtk/gtkbox.h (original)
+++ trunk/gtk/gtkbox.h Tue Oct 7 07:44:06 2008
@@ -59,7 +59,6 @@
GList *GSEAL (children);
gint16 GSEAL (spacing);
guint GSEAL (homogeneous) : 1;
- guint GSEAL (spacing_set) : 1;
};
struct _GtkBoxClass
@@ -78,50 +77,59 @@
};
-GType gtk_box_get_type (void) G_GNUC_CONST;
-void gtk_box_pack_start (GtkBox *box,
- GtkWidget *child,
- gboolean expand,
- gboolean fill,
- guint padding);
-void gtk_box_pack_end (GtkBox *box,
- GtkWidget *child,
- gboolean expand,
- gboolean fill,
- guint padding);
+GType gtk_box_get_type (void) G_GNUC_CONST;
+GtkWidget * gtk_box_new (GtkOrientation orientation,
+ gboolean homogeneous,
+ gint spacing);
+
+void gtk_box_pack_start (GtkBox *box,
+ GtkWidget *child,
+ gboolean expand,
+ gboolean fill,
+ guint padding);
+void gtk_box_pack_end (GtkBox *box,
+ GtkWidget *child,
+ gboolean expand,
+ gboolean fill,
+ guint padding);
+
#ifndef GTK_DISABLE_DEPRECATED
-void gtk_box_pack_start_defaults (GtkBox *box,
- GtkWidget *widget);
-void gtk_box_pack_end_defaults (GtkBox *box,
- GtkWidget *widget);
+void gtk_box_pack_start_defaults (GtkBox *box,
+ GtkWidget *widget);
+void gtk_box_pack_end_defaults (GtkBox *box,
+ GtkWidget *widget);
#endif
-void gtk_box_set_homogeneous (GtkBox *box,
- gboolean homogeneous);
-gboolean gtk_box_get_homogeneous (GtkBox *box);
-void gtk_box_set_spacing (GtkBox *box,
- gint spacing);
-gint gtk_box_get_spacing (GtkBox *box);
-void gtk_box_reorder_child (GtkBox *box,
- GtkWidget *child,
- gint position);
-void gtk_box_query_child_packing (GtkBox *box,
- GtkWidget *child,
- gboolean *expand,
- gboolean *fill,
- guint *padding,
- GtkPackType *pack_type);
-void gtk_box_set_child_packing (GtkBox *box,
- GtkWidget *child,
- gboolean expand,
- gboolean fill,
- guint padding,
- GtkPackType pack_type);
-gboolean _gtk_box_get_spacing_set (GtkBox* box);
-void _gtk_box_set_spacing_set (GtkBox *box,
- gboolean spacing_set);
+void gtk_box_set_homogeneous (GtkBox *box,
+ gboolean homogeneous);
+gboolean gtk_box_get_homogeneous (GtkBox *box);
+void gtk_box_set_spacing (GtkBox *box,
+ gint spacing);
+gint gtk_box_get_spacing (GtkBox *box);
+
+void gtk_box_reorder_child (GtkBox *box,
+ GtkWidget *child,
+ gint position);
+
+void gtk_box_query_child_packing (GtkBox *box,
+ GtkWidget *child,
+ gboolean *expand,
+ gboolean *fill,
+ guint *padding,
+ GtkPackType *pack_type);
+void gtk_box_set_child_packing (GtkBox *box,
+ GtkWidget *child,
+ gboolean expand,
+ gboolean fill,
+ guint padding,
+ GtkPackType pack_type);
+
+/* internal API */
+void _gtk_box_set_default_expand (GtkBox *box);
+gboolean _gtk_box_get_spacing_set (GtkBox *box);
+void _gtk_box_set_spacing_set (GtkBox *box,
+ gboolean spacing_set);
G_END_DECLS
-
#endif /* __GTK_BOX_H__ */
Modified: trunk/gtk/gtkhbox.c
==============================================================================
--- trunk/gtk/gtkhbox.c (original)
+++ trunk/gtk/gtkhbox.c Tue Oct 7 07:44:06 2008
@@ -21,290 +21,39 @@
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
+
#include "gtkhbox.h"
-#include "gtkintl.h"
+#include "gtkorientable.h"
#include "gtkalias.h"
-
-static void gtk_hbox_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
-static void gtk_hbox_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-
-
G_DEFINE_TYPE (GtkHBox, gtk_hbox, GTK_TYPE_BOX)
static void
gtk_hbox_class_init (GtkHBoxClass *class)
{
- GtkWidgetClass *widget_class;
-
- widget_class = (GtkWidgetClass*) class;
-
- widget_class->size_request = gtk_hbox_size_request;
- widget_class->size_allocate = gtk_hbox_size_allocate;
}
static void
gtk_hbox_init (GtkHBox *hbox)
{
-}
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (hbox),
+ GTK_ORIENTATION_HORIZONTAL);
-GtkWidget*
-gtk_hbox_new (gboolean homogeneous,
- gint spacing)
-{
- GtkHBox *hbox;
-
- hbox = g_object_new (GTK_TYPE_HBOX, NULL);
-
- GTK_BOX (hbox)->spacing = spacing;
- GTK_BOX (hbox)->homogeneous = homogeneous ? TRUE : FALSE;
-
- return GTK_WIDGET (hbox);
+ _gtk_box_set_default_expand (GTK_BOX (hbox));
}
-
-static void
-gtk_hbox_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
-{
- GtkBox *box;
- GtkBoxChild *child;
- GList *children;
- gint nvis_children;
- gint width;
-
- box = GTK_BOX (widget);
- requisition->width = 0;
- requisition->height = 0;
- nvis_children = 0;
-
- children = box->children;
- while (children)
- {
- child = children->data;
- children = children->next;
-
- if (GTK_WIDGET_VISIBLE (child->widget))
- {
- GtkRequisition child_requisition;
-
- gtk_widget_size_request (child->widget, &child_requisition);
-
- if (box->homogeneous)
- {
- width = child_requisition.width + child->padding * 2;
- requisition->width = MAX (requisition->width, width);
- }
- else
- {
- requisition->width += child_requisition.width + child->padding * 2;
- }
-
- requisition->height = MAX (requisition->height, child_requisition.height);
-
- nvis_children += 1;
- }
- }
-
- if (nvis_children > 0)
- {
- if (box->homogeneous)
- requisition->width *= nvis_children;
- requisition->width += (nvis_children - 1) * box->spacing;
- }
-
- requisition->width += GTK_CONTAINER (box)->border_width * 2;
- requisition->height += GTK_CONTAINER (box)->border_width * 2;
-}
-
-static void
-gtk_hbox_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
+GtkWidget *
+gtk_hbox_new (gboolean homogeneous,
+ gint spacing)
{
- GtkBox *box;
- GtkBoxChild *child;
- GList *children;
- GtkAllocation child_allocation;
- gint nvis_children;
- gint nexpand_children;
- gint child_width;
- gint width;
- gint extra;
- gint x;
- GtkTextDirection direction;
-
- box = GTK_BOX (widget);
- widget->allocation = *allocation;
-
- direction = gtk_widget_get_direction (widget);
-
- nvis_children = 0;
- nexpand_children = 0;
- children = box->children;
-
- while (children)
- {
- child = children->data;
- children = children->next;
-
- if (GTK_WIDGET_VISIBLE (child->widget))
- {
- nvis_children += 1;
- if (child->expand)
- nexpand_children += 1;
- }
- }
-
- if (nvis_children > 0)
- {
- if (box->homogeneous)
- {
- width = (allocation->width -
- GTK_CONTAINER (box)->border_width * 2 -
- (nvis_children - 1) * box->spacing);
- extra = width / nvis_children;
- }
- else if (nexpand_children > 0)
- {
- width = (gint) allocation->width - (gint) widget->requisition.width;
- extra = width / nexpand_children;
- }
- else
- {
- width = 0;
- extra = 0;
- }
-
- x = allocation->x + GTK_CONTAINER (box)->border_width;
- child_allocation.y = allocation->y + GTK_CONTAINER (box)->border_width;
- child_allocation.height = MAX (1, (gint) allocation->height - (gint) GTK_CONTAINER (box)->border_width * 2);
-
- children = box->children;
- while (children)
- {
- child = children->data;
- children = children->next;
-
- if ((child->pack == GTK_PACK_START) && GTK_WIDGET_VISIBLE (child->widget))
- {
- if (box->homogeneous)
- {
- if (nvis_children == 1)
- child_width = width;
- else
- child_width = extra;
-
- nvis_children -= 1;
- width -= extra;
- }
- else
- {
- GtkRequisition child_requisition;
-
- gtk_widget_get_child_requisition (child->widget, &child_requisition);
-
- child_width = child_requisition.width + child->padding * 2;
-
- if (child->expand)
- {
- if (nexpand_children == 1)
- child_width += width;
- else
- child_width += extra;
-
- nexpand_children -= 1;
- width -= extra;
- }
- }
-
- if (child->fill)
- {
- child_allocation.width = MAX (1, (gint) child_width - (gint) child->padding * 2);
- child_allocation.x = x + child->padding;
- }
- else
- {
- GtkRequisition child_requisition;
-
- gtk_widget_get_child_requisition (child->widget, &child_requisition);
- child_allocation.width = child_requisition.width;
- child_allocation.x = x + (child_width - child_allocation.width) / 2;
- }
-
- if (direction == GTK_TEXT_DIR_RTL)
- child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width;
-
- gtk_widget_size_allocate (child->widget, &child_allocation);
-
- x += child_width + box->spacing;
- }
- }
-
- x = allocation->x + allocation->width - GTK_CONTAINER (box)->border_width;
-
- children = box->children;
- while (children)
- {
- child = children->data;
- children = children->next;
-
- if ((child->pack == GTK_PACK_END) && GTK_WIDGET_VISIBLE (child->widget))
- {
- GtkRequisition child_requisition;
- gtk_widget_get_child_requisition (child->widget, &child_requisition);
-
- if (box->homogeneous)
- {
- if (nvis_children == 1)
- child_width = width;
- else
- child_width = extra;
-
- nvis_children -= 1;
- width -= extra;
- }
- else
- {
- child_width = child_requisition.width + child->padding * 2;
-
- if (child->expand)
- {
- if (nexpand_children == 1)
- child_width += width;
- else
- child_width += extra;
-
- nexpand_children -= 1;
- width -= extra;
- }
- }
-
- if (child->fill)
- {
- child_allocation.width = MAX (1, (gint)child_width - (gint)child->padding * 2);
- child_allocation.x = x + child->padding - child_width;
- }
- else
- {
- child_allocation.width = child_requisition.width;
- child_allocation.x = x + (child_width - child_allocation.width) / 2 - child_width;
- }
-
- if (direction == GTK_TEXT_DIR_RTL)
- child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width;
-
- gtk_widget_size_allocate (child->widget, &child_allocation);
-
- x -= (child_width + box->spacing);
- }
- }
- }
+ return g_object_new (GTK_TYPE_HBOX,
+ "spacing", spacing,
+ "homogeneous", homogeneous ? TRUE : FALSE,
+ NULL);
}
#define __GTK_HBOX_C__
Modified: trunk/gtk/gtkhbox.h
==============================================================================
--- trunk/gtk/gtkhbox.h (original)
+++ trunk/gtk/gtkhbox.h Tue Oct 7 07:44:06 2008
@@ -60,10 +60,9 @@
};
-GType gtk_hbox_get_type (void) G_GNUC_CONST;
-GtkWidget* gtk_hbox_new (gboolean homogeneous,
- gint spacing);
-
+GType gtk_hbox_get_type (void) G_GNUC_CONST;
+GtkWidget * gtk_hbox_new (gboolean homogeneous,
+ gint spacing);
G_END_DECLS
Modified: trunk/gtk/gtkvbox.c
==============================================================================
--- trunk/gtk/gtkvbox.c (original)
+++ trunk/gtk/gtkvbox.c Tue Oct 7 07:44:06 2008
@@ -21,278 +21,39 @@
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
+
+#include "gtkorientable.h"
#include "gtkvbox.h"
-#include "gtkintl.h"
#include "gtkalias.h"
-
-static void gtk_vbox_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
-static void gtk_vbox_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-
G_DEFINE_TYPE (GtkVBox, gtk_vbox, GTK_TYPE_BOX)
static void
gtk_vbox_class_init (GtkVBoxClass *class)
{
- GtkWidgetClass *widget_class;
-
- widget_class = (GtkWidgetClass*) class;
-
- widget_class->size_request = gtk_vbox_size_request;
- widget_class->size_allocate = gtk_vbox_size_allocate;
}
static void
gtk_vbox_init (GtkVBox *vbox)
{
-}
-
-GtkWidget*
-gtk_vbox_new (gboolean homogeneous,
- gint spacing)
-{
- GtkVBox *vbox;
-
- vbox = g_object_new (GTK_TYPE_VBOX, NULL);
-
- GTK_BOX (vbox)->spacing = spacing;
- GTK_BOX (vbox)->homogeneous = homogeneous ? TRUE : FALSE;
-
- return GTK_WIDGET (vbox);
-}
-
-
-static void
-gtk_vbox_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
-{
- GtkBox *box;
- GtkBoxChild *child;
- GtkRequisition child_requisition;
- GList *children;
- gint nvis_children;
- gint height;
-
- box = GTK_BOX (widget);
- requisition->width = 0;
- requisition->height = 0;
- nvis_children = 0;
-
- children = box->children;
- while (children)
- {
- child = children->data;
- children = children->next;
-
- if (GTK_WIDGET_VISIBLE (child->widget))
- {
- gtk_widget_size_request (child->widget, &child_requisition);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (vbox),
+ GTK_ORIENTATION_VERTICAL);
- if (box->homogeneous)
- {
- height = child_requisition.height + child->padding * 2;
- requisition->height = MAX (requisition->height, height);
- }
- else
- {
- requisition->height += child_requisition.height + child->padding * 2;
- }
-
- requisition->width = MAX (requisition->width, child_requisition.width);
-
- nvis_children += 1;
- }
- }
-
- if (nvis_children > 0)
- {
- if (box->homogeneous)
- requisition->height *= nvis_children;
- requisition->height += (nvis_children - 1) * box->spacing;
- }
-
- requisition->width += GTK_CONTAINER (box)->border_width * 2;
- requisition->height += GTK_CONTAINER (box)->border_width * 2;
+ _gtk_box_set_default_expand (GTK_BOX (vbox));
}
-static void
-gtk_vbox_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
+GtkWidget *
+gtk_vbox_new (gboolean homogeneous,
+ gint spacing)
{
- GtkBox *box;
- GtkBoxChild *child;
- GList *children;
- GtkAllocation child_allocation;
- gint nvis_children;
- gint nexpand_children;
- gint child_height;
- gint height;
- gint extra;
- gint y;
-
- box = GTK_BOX (widget);
- widget->allocation = *allocation;
-
- nvis_children = 0;
- nexpand_children = 0;
- children = box->children;
-
- while (children)
- {
- child = children->data;
- children = children->next;
-
- if (GTK_WIDGET_VISIBLE (child->widget))
- {
- nvis_children += 1;
- if (child->expand)
- nexpand_children += 1;
- }
- }
-
- if (nvis_children > 0)
- {
- if (box->homogeneous)
- {
- height = (allocation->height -
- GTK_CONTAINER (box)->border_width * 2 -
- (nvis_children - 1) * box->spacing);
- extra = height / nvis_children;
- }
- else if (nexpand_children > 0)
- {
- height = (gint) allocation->height - (gint) widget->requisition.height;
- extra = height / nexpand_children;
- }
- else
- {
- height = 0;
- extra = 0;
- }
-
- y = allocation->y + GTK_CONTAINER (box)->border_width;
- child_allocation.x = allocation->x + GTK_CONTAINER (box)->border_width;
- child_allocation.width = MAX (1, (gint) allocation->width - (gint) GTK_CONTAINER (box)->border_width * 2);
-
- children = box->children;
- while (children)
- {
- child = children->data;
- children = children->next;
-
- if ((child->pack == GTK_PACK_START) && GTK_WIDGET_VISIBLE (child->widget))
- {
- if (box->homogeneous)
- {
- if (nvis_children == 1)
- child_height = height;
- else
- child_height = extra;
-
- nvis_children -= 1;
- height -= extra;
- }
- else
- {
- GtkRequisition child_requisition;
-
- gtk_widget_get_child_requisition (child->widget, &child_requisition);
- child_height = child_requisition.height + child->padding * 2;
-
- if (child->expand)
- {
- if (nexpand_children == 1)
- child_height += height;
- else
- child_height += extra;
-
- nexpand_children -= 1;
- height -= extra;
- }
- }
-
- if (child->fill)
- {
- child_allocation.height = MAX (1, child_height - (gint)child->padding * 2);
- child_allocation.y = y + child->padding;
- }
- else
- {
- GtkRequisition child_requisition;
-
- gtk_widget_get_child_requisition (child->widget, &child_requisition);
- child_allocation.height = child_requisition.height;
- child_allocation.y = y + (child_height - child_allocation.height) / 2;
- }
-
- gtk_widget_size_allocate (child->widget, &child_allocation);
-
- y += child_height + box->spacing;
- }
- }
-
- y = allocation->y + allocation->height - GTK_CONTAINER (box)->border_width;
-
- children = box->children;
- while (children)
- {
- child = children->data;
- children = children->next;
-
- if ((child->pack == GTK_PACK_END) && GTK_WIDGET_VISIBLE (child->widget))
- {
- GtkRequisition child_requisition;
- gtk_widget_get_child_requisition (child->widget, &child_requisition);
-
- if (box->homogeneous)
- {
- if (nvis_children == 1)
- child_height = height;
- else
- child_height = extra;
-
- nvis_children -= 1;
- height -= extra;
- }
- else
- {
- child_height = child_requisition.height + child->padding * 2;
-
- if (child->expand)
- {
- if (nexpand_children == 1)
- child_height += height;
- else
- child_height += extra;
-
- nexpand_children -= 1;
- height -= extra;
- }
- }
-
- if (child->fill)
- {
- child_allocation.height = MAX (1, child_height - (gint)child->padding * 2);
- child_allocation.y = y + child->padding - child_height;
- }
- else
- {
- child_allocation.height = child_requisition.height;
- child_allocation.y = y + (child_height - child_allocation.height) / 2 - child_height;
- }
-
- gtk_widget_size_allocate (child->widget, &child_allocation);
-
- y -= (child_height + box->spacing);
- }
- }
- }
+ return g_object_new (GTK_TYPE_VBOX,
+ "spacing", spacing,
+ "homogeneous", homogeneous ? TRUE : FALSE,
+ NULL);
}
#define __GTK_VBOX_C__
Modified: trunk/gtk/gtkvbox.h
==============================================================================
--- trunk/gtk/gtkvbox.h (original)
+++ trunk/gtk/gtkvbox.h Tue Oct 7 07:44:06 2008
@@ -38,7 +38,6 @@
G_BEGIN_DECLS
-
#define GTK_TYPE_VBOX (gtk_vbox_get_type ())
#define GTK_VBOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_VBOX, GtkVBox))
#define GTK_VBOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_VBOX, GtkVBoxClass))
@@ -61,12 +60,10 @@
};
-GType gtk_vbox_get_type (void) G_GNUC_CONST;
-GtkWidget* gtk_vbox_new (gboolean homogeneous,
- gint spacing);
-
+GType gtk_vbox_get_type (void) G_GNUC_CONST;
+GtkWidget * gtk_vbox_new (gboolean homogeneous,
+ gint spacing);
G_END_DECLS
-
#endif /* __GTK_VBOX_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]