Blame gtk/gtkbox.c

Packit 98cdb6
/* GTK - The GIMP Toolkit
Packit 98cdb6
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
Packit 98cdb6
 *
Packit 98cdb6
 * This library is free software; you can redistribute it and/or
Packit 98cdb6
 * modify it under the terms of the GNU Lesser General Public
Packit 98cdb6
 * License as published by the Free Software Foundation; either
Packit 98cdb6
 * version 2 of the License, or (at your option) any later version.
Packit 98cdb6
 *
Packit 98cdb6
 * This library is distributed in the hope that it will be useful,
Packit 98cdb6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 98cdb6
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 98cdb6
 * Lesser General Public License for more details.
Packit 98cdb6
 *
Packit 98cdb6
 * You should have received a copy of the GNU Lesser General Public
Packit 98cdb6
 * License along with this library; if not, write to the
Packit 98cdb6
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 98cdb6
 * Boston, MA 02111-1307, USA.
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
/*
Packit 98cdb6
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
Packit 98cdb6
 * file for a list of people on the GTK+ Team.  See the ChangeLog
Packit 98cdb6
 * files for a list of changes.  These files are distributed with
Packit 98cdb6
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
#include "config.h"
Packit 98cdb6
Packit 98cdb6
#include "gtkbox.h"
Packit 98cdb6
#include "gtkorientable.h"
Packit 98cdb6
#include "gtkprivate.h"
Packit 98cdb6
#include "gtkintl.h"
Packit 98cdb6
#include "gtkalias.h"
Packit 98cdb6
Packit 98cdb6
enum {
Packit 98cdb6
  PROP_0,
Packit 98cdb6
  PROP_ORIENTATION,
Packit 98cdb6
  PROP_SPACING,
Packit 98cdb6
  PROP_HOMOGENEOUS
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
enum {
Packit 98cdb6
  CHILD_PROP_0,
Packit 98cdb6
  CHILD_PROP_EXPAND,
Packit 98cdb6
  CHILD_PROP_FILL,
Packit 98cdb6
  CHILD_PROP_PADDING,
Packit 98cdb6
  CHILD_PROP_PACK_TYPE,
Packit 98cdb6
  CHILD_PROP_POSITION
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
typedef struct _GtkBoxPrivate GtkBoxPrivate;
Packit 98cdb6
Packit 98cdb6
struct _GtkBoxPrivate
Packit 98cdb6
{
Packit 98cdb6
  GtkOrientation orientation;
Packit 98cdb6
  guint          default_expand : 1;
Packit 98cdb6
  guint          spacing_set    : 1;
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
#define GTK_BOX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_BOX, GtkBoxPrivate))
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
static void gtk_box_set_property       (GObject        *object,
Packit 98cdb6
                                        guint           prop_id,
Packit 98cdb6
                                        const GValue   *value,
Packit 98cdb6
                                        GParamSpec     *pspec);
Packit 98cdb6
static void gtk_box_get_property       (GObject        *object,
Packit 98cdb6
                                        guint           prop_id,
Packit 98cdb6
                                        GValue         *value,
Packit 98cdb6
                                        GParamSpec     *pspec);
Packit 98cdb6
Packit 98cdb6
static void gtk_box_size_request       (GtkWidget      *widget,
Packit 98cdb6
                                        GtkRequisition *requisition);
Packit 98cdb6
static void gtk_box_size_allocate      (GtkWidget      *widget,
Packit 98cdb6
                                        GtkAllocation  *allocation);
Packit 98cdb6
Packit 98cdb6
static void gtk_box_add                (GtkContainer   *container,
Packit 98cdb6
                                        GtkWidget      *widget);
Packit 98cdb6
static void gtk_box_remove             (GtkContainer   *container,
Packit 98cdb6
                                        GtkWidget      *widget);
Packit 98cdb6
static void gtk_box_forall             (GtkContainer   *container,
Packit 98cdb6
                                        gboolean        include_internals,
Packit 98cdb6
                                        GtkCallback     callback,
Packit 98cdb6
                                        gpointer        callback_data);
Packit 98cdb6
static void gtk_box_set_child_property (GtkContainer   *container,
Packit 98cdb6
                                        GtkWidget      *child,
Packit 98cdb6
                                        guint           property_id,
Packit 98cdb6
                                        const GValue   *value,
Packit 98cdb6
                                        GParamSpec     *pspec);
Packit 98cdb6
static void gtk_box_get_child_property (GtkContainer   *container,
Packit 98cdb6
                                        GtkWidget      *child,
Packit 98cdb6
                                        guint           property_id,
Packit 98cdb6
                                        GValue         *value,
Packit 98cdb6
                                        GParamSpec     *pspec);
Packit 98cdb6
static GType gtk_box_child_type        (GtkContainer   *container);
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkBox, gtk_box, GTK_TYPE_CONTAINER,
Packit 98cdb6
                                  G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
Packit 98cdb6
                                                         NULL));
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_box_class_init (GtkBoxClass *class)
Packit 98cdb6
{
Packit 98cdb6
  GObjectClass *object_class = G_OBJECT_CLASS (class);
Packit 98cdb6
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
Packit 98cdb6
  GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
Packit 98cdb6
Packit 98cdb6
  object_class->set_property = gtk_box_set_property;
Packit 98cdb6
  object_class->get_property = gtk_box_get_property;
Packit 98cdb6
Packit 98cdb6
  widget_class->size_request = gtk_box_size_request;
Packit 98cdb6
  widget_class->size_allocate = gtk_box_size_allocate;
Packit 98cdb6
Packit 98cdb6
  container_class->add = gtk_box_add;
Packit 98cdb6
  container_class->remove = gtk_box_remove;
Packit 98cdb6
  container_class->forall = gtk_box_forall;
Packit 98cdb6
  container_class->child_type = gtk_box_child_type;
Packit 98cdb6
  container_class->set_child_property = gtk_box_set_child_property;
Packit 98cdb6
  container_class->get_child_property = gtk_box_get_child_property;
Packit 98cdb6
Packit 98cdb6
  g_object_class_override_property (object_class,
Packit 98cdb6
                                    PROP_ORIENTATION,
Packit 98cdb6
                                    "orientation");
Packit 98cdb6
Packit 98cdb6
  g_object_class_install_property (object_class,
Packit 98cdb6
                                   PROP_SPACING,
Packit 98cdb6
                                   g_param_spec_int ("spacing",
Packit 98cdb6
                                                     P_("Spacing"),
Packit 98cdb6
                                                     P_("The amount of space between children"),
Packit 98cdb6
                                                     0,
Packit 98cdb6
                                                     G_MAXINT,
Packit 98cdb6
                                                     0,
Packit 98cdb6
                                                     GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
  g_object_class_install_property (object_class,
Packit 98cdb6
                                   PROP_HOMOGENEOUS,
Packit 98cdb6
                                   g_param_spec_boolean ("homogeneous",
Packit 98cdb6
							 P_("Homogeneous"),
Packit 98cdb6
							 P_("Whether the children should all be the same size"),
Packit 98cdb6
							 FALSE,
Packit 98cdb6
							 GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
  gtk_container_class_install_child_property (container_class,
Packit 98cdb6
					      CHILD_PROP_EXPAND,
Packit 98cdb6
					      g_param_spec_boolean ("expand", 
Packit 98cdb6
								    P_("Expand"), 
Packit 98cdb6
								    P_("Whether the child should receive extra space when the parent grows"),
Packit 98cdb6
								    TRUE,
Packit 98cdb6
								    GTK_PARAM_READWRITE));
Packit 98cdb6
  gtk_container_class_install_child_property (container_class,
Packit 98cdb6
					      CHILD_PROP_FILL,
Packit 98cdb6
					      g_param_spec_boolean ("fill", 
Packit 98cdb6
								    P_("Fill"), 
Packit 98cdb6
								    P_("Whether extra space given to the child should be allocated to the child or used as padding"),
Packit 98cdb6
								    TRUE,
Packit 98cdb6
								    GTK_PARAM_READWRITE));
Packit 98cdb6
  gtk_container_class_install_child_property (container_class,
Packit 98cdb6
					      CHILD_PROP_PADDING,
Packit 98cdb6
					      g_param_spec_uint ("padding", 
Packit 98cdb6
								 P_("Padding"), 
Packit 98cdb6
								 P_("Extra space to put between the child and its neighbors, in pixels"),
Packit 98cdb6
								 0, G_MAXINT, 0,
Packit 98cdb6
								 GTK_PARAM_READWRITE));
Packit 98cdb6
  gtk_container_class_install_child_property (container_class,
Packit 98cdb6
					      CHILD_PROP_PACK_TYPE,
Packit 98cdb6
					      g_param_spec_enum ("pack-type", 
Packit 98cdb6
								 P_("Pack type"), 
Packit 98cdb6
								 P_("A GtkPackType indicating whether the child is packed with reference to the start or end of the parent"),
Packit 98cdb6
								 GTK_TYPE_PACK_TYPE, GTK_PACK_START,
Packit 98cdb6
								 GTK_PARAM_READWRITE));
Packit 98cdb6
  gtk_container_class_install_child_property (container_class,
Packit 98cdb6
					      CHILD_PROP_POSITION,
Packit 98cdb6
					      g_param_spec_int ("position", 
Packit 98cdb6
								P_("Position"), 
Packit 98cdb6
								P_("The index of the child in the parent"),
Packit 98cdb6
								-1, G_MAXINT, 0,
Packit 98cdb6
								GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
  g_type_class_add_private (object_class, sizeof (GtkBoxPrivate));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_box_init (GtkBox *box)
Packit 98cdb6
{
Packit 98cdb6
  GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
Packit 98cdb6
Packit 98cdb6
  gtk_widget_set_has_window (GTK_WIDGET (box), FALSE);
Packit 98cdb6
  gtk_widget_set_redraw_on_allocate (GTK_WIDGET (box), FALSE);
Packit 98cdb6
Packit 98cdb6
  box->children = NULL;
Packit 98cdb6
  box->spacing = 0;
Packit 98cdb6
  box->homogeneous = FALSE;
Packit 98cdb6
Packit 98cdb6
  private->orientation = GTK_ORIENTATION_HORIZONTAL;
Packit 98cdb6
  private->default_expand = FALSE;
Packit 98cdb6
  private->spacing_set = FALSE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_box_set_property (GObject      *object,
Packit 98cdb6
                      guint         prop_id,
Packit 98cdb6
                      const GValue *value,
Packit 98cdb6
                      GParamSpec   *pspec)
Packit 98cdb6
{
Packit 98cdb6
  GtkBox *box = GTK_BOX (object);
Packit 98cdb6
  GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
Packit 98cdb6
Packit 98cdb6
  switch (prop_id)
Packit 98cdb6
    {
Packit 98cdb6
    case PROP_ORIENTATION:
Packit 98cdb6
      private->orientation = g_value_get_enum (value);
Packit 98cdb6
      gtk_widget_queue_resize (GTK_WIDGET (box));
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_SPACING:
Packit 98cdb6
      gtk_box_set_spacing (box, g_value_get_int (value));
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_HOMOGENEOUS:
Packit 98cdb6
      gtk_box_set_homogeneous (box, g_value_get_boolean (value));
Packit 98cdb6
      break;
Packit 98cdb6
    default:
Packit 98cdb6
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit 98cdb6
      break;
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_box_get_property (GObject    *object,
Packit 98cdb6
                      guint       prop_id,
Packit 98cdb6
                      GValue     *value,
Packit 98cdb6
                      GParamSpec *pspec)
Packit 98cdb6
{
Packit 98cdb6
  GtkBox *box = GTK_BOX (object);
Packit 98cdb6
  GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
Packit 98cdb6
Packit 98cdb6
  switch (prop_id)
Packit 98cdb6
    {
Packit 98cdb6
    case PROP_ORIENTATION:
Packit 98cdb6
      g_value_set_enum (value, private->orientation);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_SPACING:
Packit 98cdb6
      g_value_set_int (value, box->spacing);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_HOMOGENEOUS:
Packit 98cdb6
      g_value_set_boolean (value, box->homogeneous);
Packit 98cdb6
      break;
Packit 98cdb6
    default:
Packit 98cdb6
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit 98cdb6
      break;
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_box_size_request (GtkWidget      *widget,
Packit 98cdb6
                      GtkRequisition *requisition)
Packit 98cdb6
{
Packit 98cdb6
  GtkBox *box = GTK_BOX (widget);
Packit 98cdb6
  GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
Packit 98cdb6
  GtkBoxChild *child;
Packit 98cdb6
  GList *children;
Packit 98cdb6
  gint nvis_children;
Packit 98cdb6
  gint width;
Packit 98cdb6
  gint height;
Packit 98cdb6
Packit 98cdb6
  requisition->width = 0;
Packit 98cdb6
  requisition->height = 0;
Packit 98cdb6
  nvis_children = 0;
Packit 98cdb6
Packit 98cdb6
  children = box->children;
Packit 98cdb6
  while (children)
Packit 98cdb6
    {
Packit 98cdb6
      child = children->data;
Packit 98cdb6
      children = children->next;
Packit 98cdb6
Packit 98cdb6
      if (gtk_widget_get_visible (child->widget))
Packit 98cdb6
	{
Packit 98cdb6
	  GtkRequisition child_requisition;
Packit 98cdb6
Packit 98cdb6
	  gtk_widget_size_request (child->widget, &child_requisition);
Packit 98cdb6
Packit 98cdb6
	  if (box->homogeneous)
Packit 98cdb6
	    {
Packit 98cdb6
	      width = child_requisition.width + child->padding * 2;
Packit 98cdb6
	      height = child_requisition.height + child->padding * 2;
Packit 98cdb6
Packit 98cdb6
              if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
Packit 98cdb6
                requisition->width = MAX (requisition->width, width);
Packit 98cdb6
              else
Packit 98cdb6
                requisition->height = MAX (requisition->height, height);
Packit 98cdb6
	    }
Packit 98cdb6
	  else
Packit 98cdb6
	    {
Packit 98cdb6
              if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
Packit 98cdb6
                requisition->width += child_requisition.width + child->padding * 2;
Packit 98cdb6
              else
Packit 98cdb6
                requisition->height += child_requisition.height + child->padding * 2;
Packit 98cdb6
	    }
Packit 98cdb6
Packit 98cdb6
          if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
Packit 98cdb6
            requisition->height = MAX (requisition->height, child_requisition.height);
Packit 98cdb6
          else
Packit 98cdb6
            requisition->width = MAX (requisition->width, child_requisition.width);
Packit 98cdb6
Packit 98cdb6
	  nvis_children += 1;
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (nvis_children > 0)
Packit 98cdb6
    {
Packit 98cdb6
      if (box->homogeneous)
Packit 98cdb6
        {
Packit 98cdb6
          if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
Packit 98cdb6
            requisition->width *= nvis_children;
Packit 98cdb6
          else
Packit 98cdb6
            requisition->height *= nvis_children;
Packit 98cdb6
        }
Packit 98cdb6
Packit 98cdb6
      if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
Packit 98cdb6
        requisition->width += (nvis_children - 1) * box->spacing;
Packit 98cdb6
      else
Packit 98cdb6
        requisition->height += (nvis_children - 1) * box->spacing;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  requisition->width += GTK_CONTAINER (box)->border_width * 2;
Packit 98cdb6
  requisition->height += GTK_CONTAINER (box)->border_width * 2;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_box_size_allocate (GtkWidget     *widget,
Packit 98cdb6
                       GtkAllocation *allocation)
Packit 98cdb6
{
Packit 98cdb6
  GtkBox *box = GTK_BOX (widget);
Packit 98cdb6
  GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (box);
Packit 98cdb6
  GtkBoxChild *child;
Packit 98cdb6
  GList *children;
Packit 98cdb6
  GtkAllocation child_allocation;
Packit 98cdb6
  gint nvis_children = 0;
Packit 98cdb6
  gint nexpand_children = 0;
Packit 98cdb6
  gint child_width = 0;
Packit 98cdb6
  gint child_height = 0;
Packit 98cdb6
  gint width = 0;
Packit 98cdb6
  gint height = 0;
Packit 98cdb6
  gint extra = 0;
Packit 98cdb6
  gint x = 0;
Packit 98cdb6
  gint y = 0;
Packit 98cdb6
  GtkTextDirection direction;
Packit 98cdb6
Packit 98cdb6
  widget->allocation = *allocation;
Packit 98cdb6
Packit 98cdb6
  direction = gtk_widget_get_direction (widget);
Packit 98cdb6
Packit 98cdb6
  for (children = box->children; children; children = children->next)
Packit 98cdb6
    {
Packit 98cdb6
      child = children->data;
Packit 98cdb6
Packit 98cdb6
      if (gtk_widget_get_visible (child->widget))
Packit 98cdb6
	{
Packit 98cdb6
	  nvis_children += 1;
Packit 98cdb6
	  if (child->expand)
Packit 98cdb6
	    nexpand_children += 1;
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (nvis_children > 0)
Packit 98cdb6
    {
Packit 98cdb6
      if (box->homogeneous)
Packit 98cdb6
	{
Packit 98cdb6
          if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
Packit 98cdb6
            {
Packit 98cdb6
              width = (allocation->width -
Packit 98cdb6
                       GTK_CONTAINER (box)->border_width * 2 -
Packit 98cdb6
                       (nvis_children - 1) * box->spacing);
Packit 98cdb6
              extra = width / nvis_children;
Packit 98cdb6
            }
Packit 98cdb6
          else
Packit 98cdb6
            {
Packit 98cdb6
              height = (allocation->height -
Packit 98cdb6
                        GTK_CONTAINER (box)->border_width * 2 -
Packit 98cdb6
                        (nvis_children - 1) * box->spacing);
Packit 98cdb6
              extra = height / nvis_children;
Packit 98cdb6
            }
Packit 98cdb6
	}
Packit 98cdb6
      else if (nexpand_children > 0)
Packit 98cdb6
	{
Packit 98cdb6
          if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
Packit 98cdb6
            {
Packit 98cdb6
              width = (gint) allocation->width - (gint) widget->requisition.width;
Packit 98cdb6
              extra = width / nexpand_children;
Packit 98cdb6
            }
Packit 98cdb6
          else
Packit 98cdb6
            {
Packit 98cdb6
              height = (gint) allocation->height - (gint) widget->requisition.height;
Packit 98cdb6
              extra = height / nexpand_children;
Packit 98cdb6
            }
Packit 98cdb6
	}
Packit 98cdb6
Packit 98cdb6
      if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
Packit 98cdb6
        {
Packit 98cdb6
          x = allocation->x + GTK_CONTAINER (box)->border_width;
Packit 98cdb6
          child_allocation.y = allocation->y + GTK_CONTAINER (box)->border_width;
Packit 98cdb6
          child_allocation.height = MAX (1, (gint) allocation->height - (gint) GTK_CONTAINER (box)->border_width * 2);
Packit 98cdb6
        }
Packit 98cdb6
      else
Packit 98cdb6
        {
Packit 98cdb6
          y = allocation->y + GTK_CONTAINER (box)->border_width;
Packit 98cdb6
          child_allocation.x = allocation->x + GTK_CONTAINER (box)->border_width;
Packit 98cdb6
          child_allocation.width = MAX (1, (gint) allocation->width - (gint) GTK_CONTAINER (box)->border_width * 2);
Packit 98cdb6
        }
Packit 98cdb6
Packit 98cdb6
      children = box->children;
Packit 98cdb6
      while (children)
Packit 98cdb6
	{
Packit 98cdb6
	  child = children->data;
Packit 98cdb6
	  children = children->next;
Packit 98cdb6
Packit 98cdb6
	  if ((child->pack == GTK_PACK_START) && gtk_widget_get_visible (child->widget))
Packit 98cdb6
	    {
Packit 98cdb6
	      if (box->homogeneous)
Packit 98cdb6
		{
Packit 98cdb6
		  if (nvis_children == 1)
Packit 98cdb6
                    {
Packit 98cdb6
                      child_width = width;
Packit 98cdb6
                      child_height = height;
Packit 98cdb6
                    }
Packit 98cdb6
		  else
Packit 98cdb6
                    {
Packit 98cdb6
                      child_width = extra;
Packit 98cdb6
                      child_height = extra;
Packit 98cdb6
                    }
Packit 98cdb6
Packit 98cdb6
		  nvis_children -= 1;
Packit 98cdb6
		  width -= extra;
Packit 98cdb6
                  height -= extra;
Packit 98cdb6
		}
Packit 98cdb6
	      else
Packit 98cdb6
		{
Packit 98cdb6
		  GtkRequisition child_requisition;
Packit 98cdb6
Packit 98cdb6
		  gtk_widget_get_child_requisition (child->widget, &child_requisition);
Packit 98cdb6
Packit 98cdb6
		  child_width = child_requisition.width + child->padding * 2;
Packit 98cdb6
		  child_height = child_requisition.height + child->padding * 2;
Packit 98cdb6
Packit 98cdb6
		  if (child->expand)
Packit 98cdb6
		    {
Packit 98cdb6
		      if (nexpand_children == 1)
Packit 98cdb6
                        {
Packit 98cdb6
                          child_width += width;
Packit 98cdb6
                          child_height += height;
Packit 98cdb6
                        }
Packit 98cdb6
		      else
Packit 98cdb6
                        {
Packit 98cdb6
                          child_width += extra;
Packit 98cdb6
                          child_height += extra;
Packit 98cdb6
                        }
Packit 98cdb6
Packit 98cdb6
		      nexpand_children -= 1;
Packit 98cdb6
		      width -= extra;
Packit 98cdb6
                      height -= extra;
Packit 98cdb6
		    }
Packit 98cdb6
		}
Packit 98cdb6
Packit 98cdb6
	      if (child->fill)
Packit 98cdb6
		{
Packit 98cdb6
                  if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
Packit 98cdb6
                    {
Packit 98cdb6
                      child_allocation.width = MAX (1, (gint) child_width - (gint) child->padding * 2);
Packit 98cdb6
                      child_allocation.x = x + child->padding;
Packit 98cdb6
                    }
Packit 98cdb6
                  else
Packit 98cdb6
                    {
Packit 98cdb6
                      child_allocation.height = MAX (1, child_height - (gint)child->padding * 2);
Packit 98cdb6
                      child_allocation.y = y + child->padding;
Packit 98cdb6
                    }
Packit 98cdb6
		}
Packit 98cdb6
	      else
Packit 98cdb6
		{
Packit 98cdb6
		  GtkRequisition child_requisition;
Packit 98cdb6
Packit 98cdb6
		  gtk_widget_get_child_requisition (child->widget, &child_requisition);
Packit 98cdb6
                  if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
Packit 98cdb6
                    {
Packit 98cdb6
                      child_allocation.width = child_requisition.width;
Packit 98cdb6
                      child_allocation.x = x + (child_width - child_allocation.width) / 2;
Packit 98cdb6
                    }
Packit 98cdb6
                  else
Packit 98cdb6
                    {
Packit 98cdb6
                      child_allocation.height = child_requisition.height;
Packit 98cdb6
                      child_allocation.y = y + (child_height - child_allocation.height) / 2;
Packit 98cdb6
                    }
Packit 98cdb6
		}
Packit 98cdb6
Packit 98cdb6
	      if (direction == GTK_TEXT_DIR_RTL &&
Packit 98cdb6
                  private->orientation == GTK_ORIENTATION_HORIZONTAL)
Packit 98cdb6
                {
Packit 98cdb6
                  child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width;
Packit 98cdb6
                }
Packit 98cdb6
Packit 98cdb6
	      gtk_widget_size_allocate (child->widget, &child_allocation);
Packit 98cdb6
Packit 98cdb6
	      x += child_width + box->spacing;
Packit 98cdb6
	      y += child_height + box->spacing;
Packit 98cdb6
	    }
Packit 98cdb6
	}
Packit 98cdb6
Packit 98cdb6
      x = allocation->x + allocation->width - GTK_CONTAINER (box)->border_width;
Packit 98cdb6
      y = allocation->y + allocation->height - GTK_CONTAINER (box)->border_width;
Packit 98cdb6
Packit 98cdb6
      children = box->children;
Packit 98cdb6
      while (children)
Packit 98cdb6
	{
Packit 98cdb6
	  child = children->data;
Packit 98cdb6
	  children = children->next;
Packit 98cdb6
Packit 98cdb6
	  if ((child->pack == GTK_PACK_END) && gtk_widget_get_visible (child->widget))
Packit 98cdb6
	    {
Packit 98cdb6
	      GtkRequisition child_requisition;
Packit 98cdb6
Packit 98cdb6
	      gtk_widget_get_child_requisition (child->widget, &child_requisition);
Packit 98cdb6
Packit 98cdb6
              if (box->homogeneous)
Packit 98cdb6
                {
Packit 98cdb6
                  if (nvis_children == 1)
Packit 98cdb6
                    {
Packit 98cdb6
                      child_width = width;
Packit 98cdb6
                      child_height = height;
Packit 98cdb6
                    }
Packit 98cdb6
                  else
Packit 98cdb6
                    {
Packit 98cdb6
                      child_width = extra;
Packit 98cdb6
                      child_height = extra;
Packit 98cdb6
                   }
Packit 98cdb6
Packit 98cdb6
                  nvis_children -= 1;
Packit 98cdb6
                  width -= extra;
Packit 98cdb6
                  height -= extra;
Packit 98cdb6
                }
Packit 98cdb6
              else
Packit 98cdb6
                {
Packit 98cdb6
		  child_width = child_requisition.width + child->padding * 2;
Packit 98cdb6
		  child_height = child_requisition.height + child->padding * 2;
Packit 98cdb6
Packit 98cdb6
                  if (child->expand)
Packit 98cdb6
                    {
Packit 98cdb6
                      if (nexpand_children == 1)
Packit 98cdb6
                        {
Packit 98cdb6
                          child_width += width;
Packit 98cdb6
                          child_height += height;
Packit 98cdb6
                         }
Packit 98cdb6
                      else
Packit 98cdb6
                        {
Packit 98cdb6
                          child_width += extra;
Packit 98cdb6
                          child_height += extra;
Packit 98cdb6
                        }
Packit 98cdb6
Packit 98cdb6
                      nexpand_children -= 1;
Packit 98cdb6
                      width -= extra;
Packit 98cdb6
                      height -= extra;
Packit 98cdb6
                    }
Packit 98cdb6
                }
Packit 98cdb6
Packit 98cdb6
              if (child->fill)
Packit 98cdb6
                {
Packit 98cdb6
                  if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
Packit 98cdb6
                    {
Packit 98cdb6
                      child_allocation.width = MAX (1, (gint)child_width - (gint)child->padding * 2);
Packit 98cdb6
                      child_allocation.x = x + child->padding - child_width;
Packit 98cdb6
                    }
Packit 98cdb6
                  else
Packit 98cdb6
                    {
Packit 98cdb6
                      child_allocation.height = MAX (1, child_height - (gint)child->padding * 2);
Packit 98cdb6
                      child_allocation.y = y + child->padding - child_height;
Packit 98cdb6
                     }
Packit 98cdb6
                }
Packit 98cdb6
              else
Packit 98cdb6
                {
Packit 98cdb6
                  if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
Packit 98cdb6
                    {
Packit 98cdb6
                      child_allocation.width = child_requisition.width;
Packit 98cdb6
                      child_allocation.x = x + (child_width - child_allocation.width) / 2 - child_width;
Packit 98cdb6
                    }
Packit 98cdb6
                  else
Packit 98cdb6
                    {
Packit 98cdb6
                      child_allocation.height = child_requisition.height;
Packit 98cdb6
                      child_allocation.y = y + (child_height - child_allocation.height) / 2 - child_height;
Packit 98cdb6
                    }
Packit 98cdb6
                }
Packit 98cdb6
Packit 98cdb6
	      if (direction == GTK_TEXT_DIR_RTL &&
Packit 98cdb6
                  private->orientation == GTK_ORIENTATION_HORIZONTAL)
Packit 98cdb6
                {
Packit 98cdb6
                  child_allocation.x = allocation->x + allocation->width - (child_allocation.x - allocation->x) - child_allocation.width;
Packit 98cdb6
                }
Packit 98cdb6
Packit 98cdb6
              gtk_widget_size_allocate (child->widget, &child_allocation);
Packit 98cdb6
Packit 98cdb6
              x -= (child_width + box->spacing);
Packit 98cdb6
              y -= (child_height + box->spacing);
Packit 98cdb6
	    }
Packit 98cdb6
	}
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static GType
Packit 98cdb6
gtk_box_child_type (GtkContainer   *container)
Packit 98cdb6
{
Packit 98cdb6
  return GTK_TYPE_WIDGET;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_box_set_child_property (GtkContainer *container,
Packit 98cdb6
                            GtkWidget    *child,
Packit 98cdb6
                            guint         property_id,
Packit 98cdb6
                            const GValue *value,
Packit 98cdb6
                            GParamSpec   *pspec)
Packit 98cdb6
{
Packit 98cdb6
  gboolean expand = 0;
Packit 98cdb6
  gboolean fill = 0;
Packit 98cdb6
  guint padding = 0;
Packit 98cdb6
  GtkPackType pack_type = 0;
Packit 98cdb6
Packit 98cdb6
  if (property_id != CHILD_PROP_POSITION)
Packit 98cdb6
    gtk_box_query_child_packing (GTK_BOX (container),
Packit 98cdb6
				 child,
Packit 98cdb6
				 &expand,
Packit 98cdb6
				 &fill,
Packit 98cdb6
				 &padding,
Packit 98cdb6
				 &pack_type);
Packit 98cdb6
  switch (property_id)
Packit 98cdb6
    {
Packit 98cdb6
    case CHILD_PROP_EXPAND:
Packit 98cdb6
      gtk_box_set_child_packing (GTK_BOX (container),
Packit 98cdb6
				 child,
Packit 98cdb6
				 g_value_get_boolean (value),
Packit 98cdb6
				 fill,
Packit 98cdb6
				 padding,
Packit 98cdb6
				 pack_type);
Packit 98cdb6
      break;
Packit 98cdb6
    case CHILD_PROP_FILL:
Packit 98cdb6
      gtk_box_set_child_packing (GTK_BOX (container),
Packit 98cdb6
				 child,
Packit 98cdb6
				 expand,
Packit 98cdb6
				 g_value_get_boolean (value),
Packit 98cdb6
				 padding,
Packit 98cdb6
				 pack_type);
Packit 98cdb6
      break;
Packit 98cdb6
    case CHILD_PROP_PADDING:
Packit 98cdb6
      gtk_box_set_child_packing (GTK_BOX (container),
Packit 98cdb6
				 child,
Packit 98cdb6
				 expand,
Packit 98cdb6
				 fill,
Packit 98cdb6
				 g_value_get_uint (value),
Packit 98cdb6
				 pack_type);
Packit 98cdb6
      break;
Packit 98cdb6
    case CHILD_PROP_PACK_TYPE:
Packit 98cdb6
      gtk_box_set_child_packing (GTK_BOX (container),
Packit 98cdb6
				 child,
Packit 98cdb6
				 expand,
Packit 98cdb6
				 fill,
Packit 98cdb6
				 padding,
Packit 98cdb6
				 g_value_get_enum (value));
Packit 98cdb6
      break;
Packit 98cdb6
    case CHILD_PROP_POSITION:
Packit 98cdb6
      gtk_box_reorder_child (GTK_BOX (container),
Packit 98cdb6
			     child,
Packit 98cdb6
			     g_value_get_int (value));
Packit 98cdb6
      break;
Packit 98cdb6
    default:
Packit 98cdb6
      GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
Packit 98cdb6
      break;
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_box_get_child_property (GtkContainer *container,
Packit 98cdb6
			    GtkWidget    *child,
Packit 98cdb6
			    guint         property_id,
Packit 98cdb6
			    GValue       *value,
Packit 98cdb6
			    GParamSpec   *pspec)
Packit 98cdb6
{
Packit 98cdb6
  gboolean expand = 0;
Packit 98cdb6
  gboolean fill = 0;
Packit 98cdb6
  guint padding = 0;
Packit 98cdb6
  GtkPackType pack_type = 0;
Packit 98cdb6
  GList *list;
Packit 98cdb6
Packit 98cdb6
  if (property_id != CHILD_PROP_POSITION)
Packit 98cdb6
    gtk_box_query_child_packing (GTK_BOX (container),
Packit 98cdb6
				 child,
Packit 98cdb6
				 &expand,
Packit 98cdb6
				 &fill,
Packit 98cdb6
				 &padding,
Packit 98cdb6
				 &pack_type);
Packit 98cdb6
  switch (property_id)
Packit 98cdb6
    {
Packit 98cdb6
      guint i;
Packit 98cdb6
    case CHILD_PROP_EXPAND:
Packit 98cdb6
      g_value_set_boolean (value, expand);
Packit 98cdb6
      break;
Packit 98cdb6
    case CHILD_PROP_FILL:
Packit 98cdb6
      g_value_set_boolean (value, fill);
Packit 98cdb6
      break;
Packit 98cdb6
    case CHILD_PROP_PADDING:
Packit 98cdb6
      g_value_set_uint (value, padding);
Packit 98cdb6
      break;
Packit 98cdb6
    case CHILD_PROP_PACK_TYPE:
Packit 98cdb6
      g_value_set_enum (value, pack_type);
Packit 98cdb6
      break;
Packit 98cdb6
    case CHILD_PROP_POSITION:
Packit 98cdb6
      i = 0;
Packit 98cdb6
      for (list = GTK_BOX (container)->children; list; list = list->next)
Packit 98cdb6
	{
Packit 98cdb6
	  GtkBoxChild *child_entry;
Packit 98cdb6
Packit 98cdb6
	  child_entry = list->data;
Packit 98cdb6
	  if (child_entry->widget == child)
Packit 98cdb6
	    break;
Packit 98cdb6
	  i++;
Packit 98cdb6
	}
Packit 98cdb6
      g_value_set_int (value, list ? i : -1);
Packit 98cdb6
      break;
Packit 98cdb6
    default:
Packit 98cdb6
      GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
Packit 98cdb6
      break;
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_box_pack (GtkBox      *box,
Packit 98cdb6
              GtkWidget   *child,
Packit 98cdb6
              gboolean     expand,
Packit 98cdb6
              gboolean     fill,
Packit 98cdb6
              guint        padding,
Packit 98cdb6
              GtkPackType  pack_type)
Packit 98cdb6
{
Packit 98cdb6
  GtkBoxChild *child_info;
Packit 98cdb6
Packit 98cdb6
  g_return_if_fail (GTK_IS_BOX (box));
Packit 98cdb6
  g_return_if_fail (GTK_IS_WIDGET (child));
Packit 98cdb6
  g_return_if_fail (child->parent == NULL);
Packit 98cdb6
Packit 98cdb6
  child_info = g_new (GtkBoxChild, 1);
Packit 98cdb6
  child_info->widget = child;
Packit 98cdb6
  child_info->padding = padding;
Packit 98cdb6
  child_info->expand = expand ? TRUE : FALSE;
Packit 98cdb6
  child_info->fill = fill ? TRUE : FALSE;
Packit 98cdb6
  child_info->pack = pack_type;
Packit 98cdb6
  child_info->is_secondary = FALSE;
Packit 98cdb6
Packit 98cdb6
  box->children = g_list_append (box->children, child_info);
Packit 98cdb6
Packit 98cdb6
  gtk_widget_freeze_child_notify (child);
Packit 98cdb6
Packit 98cdb6
  gtk_widget_set_parent (child, GTK_WIDGET (box));
Packit 98cdb6
  
Packit 98cdb6
  gtk_widget_child_notify (child, "expand");
Packit 98cdb6
  gtk_widget_child_notify (child, "fill");
Packit 98cdb6
  gtk_widget_child_notify (child, "padding");
Packit 98cdb6
  gtk_widget_child_notify (child, "pack-type");
Packit 98cdb6
  gtk_widget_child_notify (child, "position");
Packit 98cdb6
  gtk_widget_thaw_child_notify (child);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_box_new:
Packit 98cdb6
 * @orientation: the box' orientation.
Packit 98cdb6
 * @homogeneous: %TRUE if all children are to be given equal space allocations.
Packit 98cdb6
 * @spacing: the number of pixels to place by default between children.
Packit 98cdb6
 *
Packit 98cdb6
 * Creates a new #GtkHBox.
Packit 98cdb6
 *
Packit 98cdb6
 * Return value: a new #GtkHBox.
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.16
Packit 98cdb6
 **/
Packit 98cdb6
GtkWidget*
Packit 98cdb6
_gtk_box_new (GtkOrientation orientation,
Packit 98cdb6
              gboolean       homogeneous,
Packit 98cdb6
              gint           spacing)
Packit 98cdb6
{
Packit 98cdb6
  return g_object_new (GTK_TYPE_BOX,
Packit 98cdb6
                       "orientation", orientation,
Packit 98cdb6
                       "spacing",     spacing,
Packit 98cdb6
                       "homogeneous", homogeneous ? TRUE : FALSE,
Packit 98cdb6
                       NULL);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_box_pack_start:
Packit 98cdb6
 * @box: a #GtkBox
Packit 98cdb6
 * @child: the #GtkWidget to be added to @box
Packit 98cdb6
 * @expand: %TRUE if the new child is to be given extra space allocated to
Packit 98cdb6
 * @box.  The extra space will be divided evenly between all children of
Packit 98cdb6
 * @box that use this option
Packit 98cdb6
 * @fill: %TRUE if space given to @child by the @expand option is
Packit 98cdb6
 *   actually allocated to @child, rather than just padding it.  This
Packit 98cdb6
 *   parameter has no effect if @expand is set to %FALSE.  A child is
Packit 98cdb6
 *   always allocated the full height of a #GtkHBox and the full width 
Packit 98cdb6
 *   of a #GtkVBox. This option affects the other dimension
Packit 98cdb6
 * @padding: extra space in pixels to put between this child and its
Packit 98cdb6
 *   neighbors, over and above the global amount specified by
Packit 98cdb6
 *   #GtkBox:spacing property.  If @child is a widget at one of the 
Packit 98cdb6
 *   reference ends of @box, then @padding pixels are also put between 
Packit 98cdb6
 *   @child and the reference edge of @box
Packit 98cdb6
 *
Packit 98cdb6
 * Adds @child to @box, packed with reference to the start of @box.
Packit 98cdb6
 * The @child is packed after any other child packed with reference 
Packit 98cdb6
 * to the start of @box.
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gtk_box_pack_start (GtkBox    *box,
Packit 98cdb6
		    GtkWidget *child,
Packit 98cdb6
		    gboolean   expand,
Packit 98cdb6
		    gboolean   fill,
Packit 98cdb6
		    guint      padding)
Packit 98cdb6
{
Packit 98cdb6
  gtk_box_pack (box, child, expand, fill, padding, GTK_PACK_START);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_box_pack_end:
Packit 98cdb6
 * @box: a #GtkBox
Packit 98cdb6
 * @child: the #GtkWidget to be added to @box
Packit 98cdb6
 * @expand: %TRUE if the new child is to be given extra space allocated 
Packit 98cdb6
 *   to @box. The extra space will be divided evenly between all children 
Packit 98cdb6
 *   of @box that use this option
Packit 98cdb6
 * @fill: %TRUE if space given to @child by the @expand option is
Packit 98cdb6
 *   actually allocated to @child, rather than just padding it.  This
Packit 98cdb6
 *   parameter has no effect if @expand is set to %FALSE.  A child is
Packit 98cdb6
 *   always allocated the full height of a #GtkHBox and the full width 
Packit 98cdb6
 *   of a #GtkVBox.  This option affects the other dimension
Packit 98cdb6
 * @padding: extra space in pixels to put between this child and its
Packit 98cdb6
 *   neighbors, over and above the global amount specified by
Packit 98cdb6
 *   #GtkBox:spacing property.  If @child is a widget at one of the 
Packit 98cdb6
 *   reference ends of @box, then @padding pixels are also put between 
Packit 98cdb6
 *   @child and the reference edge of @box
Packit 98cdb6
 *
Packit 98cdb6
 * Adds @child to @box, packed with reference to the end of @box.  
Packit 98cdb6
 * The @child is packed after (away from end of) any other child 
Packit 98cdb6
 * packed with reference to the end of @box.
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gtk_box_pack_end (GtkBox    *box,
Packit 98cdb6
		  GtkWidget *child,
Packit 98cdb6
		  gboolean   expand,
Packit 98cdb6
		  gboolean   fill,
Packit 98cdb6
		  guint      padding)
Packit 98cdb6
{
Packit 98cdb6
  gtk_box_pack (box, child, expand, fill, padding, GTK_PACK_END);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_box_pack_start_defaults:
Packit 98cdb6
 * @box: a #GtkBox
Packit 98cdb6
 * @widget: the #GtkWidget to be added to @box
Packit 98cdb6
 *
Packit 98cdb6
 * Adds @widget to @box, packed with reference to the start of @box.
Packit 98cdb6
 * The child is packed after any other child packed with reference 
Packit 98cdb6
 * to the start of @box. 
Packit 98cdb6
 * 
Packit 98cdb6
 * Parameters for how to pack the child @widget, #GtkBox:expand, 
Packit 98cdb6
 * #GtkBox:fill and #GtkBox:padding, are given their default
Packit 98cdb6
 * values, %TRUE, %TRUE, and 0, respectively.
Packit 98cdb6
 *
Packit 98cdb6
 * Deprecated: 2.14: Use gtk_box_pack_start()
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gtk_box_pack_start_defaults (GtkBox    *box,
Packit 98cdb6
			     GtkWidget *child)
Packit 98cdb6
{
Packit 98cdb6
  gtk_box_pack_start (box, child, TRUE, TRUE, 0);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_box_pack_end_defaults:
Packit 98cdb6
 * @box: a #GtkBox
Packit 98cdb6
 * @widget: the #GtkWidget to be added to @box
Packit 98cdb6
 *
Packit 98cdb6
 * Adds @widget to @box, packed with reference to the end of @box.
Packit 98cdb6
 * The child is packed after any other child packed with reference 
Packit 98cdb6
 * to the start of @box. 
Packit 98cdb6
 * 
Packit 98cdb6
 * Parameters for how to pack the child @widget, #GtkBox:expand, 
Packit 98cdb6
 * #GtkBox:fill and #GtkBox:padding, are given their default
Packit 98cdb6
 * values, %TRUE, %TRUE, and 0, respectively.
Packit 98cdb6
 *
Packit 98cdb6
 * Deprecated: 2.14: Use gtk_box_pack_end()
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gtk_box_pack_end_defaults (GtkBox    *box,
Packit 98cdb6
			   GtkWidget *child)
Packit 98cdb6
{
Packit 98cdb6
  gtk_box_pack_end (box, child, TRUE, TRUE, 0);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_box_set_homogeneous:
Packit 98cdb6
 * @box: a #GtkBox
Packit 98cdb6
 * @homogeneous: a boolean value, %TRUE to create equal allotments,
Packit 98cdb6
 *   %FALSE for variable allotments
Packit 98cdb6
 * 
Packit 98cdb6
 * Sets the #GtkBox:homogeneous property of @box, controlling 
Packit 98cdb6
 * whether or not all children of @box are given equal space 
Packit 98cdb6
 * in the box.
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gtk_box_set_homogeneous (GtkBox  *box,
Packit 98cdb6
			 gboolean homogeneous)
Packit 98cdb6
{
Packit 98cdb6
  g_return_if_fail (GTK_IS_BOX (box));
Packit 98cdb6
Packit 98cdb6
  if ((homogeneous ? TRUE : FALSE) != box->homogeneous)
Packit 98cdb6
    {
Packit 98cdb6
      box->homogeneous = homogeneous ? TRUE : FALSE;
Packit 98cdb6
      g_object_notify (G_OBJECT (box), "homogeneous");
Packit 98cdb6
      gtk_widget_queue_resize (GTK_WIDGET (box));
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_box_get_homogeneous:
Packit 98cdb6
 * @box: a #GtkBox
Packit 98cdb6
 *
Packit 98cdb6
 * Returns whether the box is homogeneous (all children are the
Packit 98cdb6
 * same size). See gtk_box_set_homogeneous().
Packit 98cdb6
 *
Packit 98cdb6
 * Return value: %TRUE if the box is homogeneous.
Packit 98cdb6
 **/
Packit 98cdb6
gboolean
Packit 98cdb6
gtk_box_get_homogeneous (GtkBox *box)
Packit 98cdb6
{
Packit 98cdb6
  g_return_val_if_fail (GTK_IS_BOX (box), FALSE);
Packit 98cdb6
Packit 98cdb6
  return box->homogeneous;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_box_set_spacing:
Packit 98cdb6
 * @box: a #GtkBox
Packit 98cdb6
 * @spacing: the number of pixels to put between children
Packit 98cdb6
 *
Packit 98cdb6
 * Sets the #GtkBox:spacing property of @box, which is the 
Packit 98cdb6
 * number of pixels to place between children of @box.
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gtk_box_set_spacing (GtkBox *box,
Packit 98cdb6
		     gint    spacing)
Packit 98cdb6
{
Packit 98cdb6
  g_return_if_fail (GTK_IS_BOX (box));
Packit 98cdb6
Packit 98cdb6
  if (spacing != box->spacing)
Packit 98cdb6
    {
Packit 98cdb6
      box->spacing = spacing;
Packit 98cdb6
      _gtk_box_set_spacing_set (box, TRUE);
Packit 98cdb6
Packit 98cdb6
      g_object_notify (G_OBJECT (box), "spacing");
Packit 98cdb6
Packit 98cdb6
      gtk_widget_queue_resize (GTK_WIDGET (box));
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_box_get_spacing:
Packit 98cdb6
 * @box: a #GtkBox
Packit 98cdb6
 * 
Packit 98cdb6
 * Gets the value set by gtk_box_set_spacing().
Packit 98cdb6
 * 
Packit 98cdb6
 * Return value: spacing between children
Packit 98cdb6
 **/
Packit 98cdb6
gint
Packit 98cdb6
gtk_box_get_spacing (GtkBox *box)
Packit 98cdb6
{
Packit 98cdb6
  g_return_val_if_fail (GTK_IS_BOX (box), 0);
Packit 98cdb6
Packit 98cdb6
  return box->spacing;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
void
Packit 98cdb6
_gtk_box_set_spacing_set (GtkBox  *box,
Packit 98cdb6
                          gboolean spacing_set)
Packit 98cdb6
{
Packit 98cdb6
  GtkBoxPrivate *private;
Packit 98cdb6
Packit 98cdb6
  g_return_if_fail (GTK_IS_BOX (box));
Packit 98cdb6
Packit 98cdb6
  private = GTK_BOX_GET_PRIVATE (box);
Packit 98cdb6
Packit 98cdb6
  private->spacing_set = spacing_set ? TRUE : FALSE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
gboolean
Packit 98cdb6
_gtk_box_get_spacing_set (GtkBox *box)
Packit 98cdb6
{
Packit 98cdb6
  GtkBoxPrivate *private;
Packit 98cdb6
Packit 98cdb6
  g_return_val_if_fail (GTK_IS_BOX (box), FALSE);
Packit 98cdb6
Packit 98cdb6
  private = GTK_BOX_GET_PRIVATE (box);
Packit 98cdb6
Packit 98cdb6
  return private->spacing_set;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_box_reorder_child:
Packit 98cdb6
 * @box: a #GtkBox
Packit 98cdb6
 * @child: the #GtkWidget to move
Packit 98cdb6
 * @position: the new position for @child in the list of children 
Packit 98cdb6
 *   of @box, starting from 0. If negative, indicates the end of 
Packit 98cdb6
 *   the list
Packit 98cdb6
 *
Packit 98cdb6
 * Moves @child to a new @position in the list of @box children.  
Packit 98cdb6
 * The list is the <structfield>children</structfield> field of
Packit 98cdb6
 * #GtkBox-struct, and contains both widgets packed #GTK_PACK_START 
Packit 98cdb6
 * as well as widgets packed #GTK_PACK_END, in the order that these 
Packit 98cdb6
 * widgets were added to @box.
Packit 98cdb6
 * 
Packit 98cdb6
 * A widget's position in the @box children list determines where 
Packit 98cdb6
 * the widget is packed into @box.  A child widget at some position 
Packit 98cdb6
 * in the list will be packed just after all other widgets of the 
Packit 98cdb6
 * same packing type that appear earlier in the list.
Packit 98cdb6
 */ 
Packit 98cdb6
void
Packit 98cdb6
gtk_box_reorder_child (GtkBox    *box,
Packit 98cdb6
		       GtkWidget *child,
Packit 98cdb6
		       gint       position)
Packit 98cdb6
{
Packit 98cdb6
  GList *old_link;
Packit 98cdb6
  GList *new_link;
Packit 98cdb6
  GtkBoxChild *child_info = NULL;
Packit 98cdb6
  gint old_position;
Packit 98cdb6
Packit 98cdb6
  g_return_if_fail (GTK_IS_BOX (box));
Packit 98cdb6
  g_return_if_fail (GTK_IS_WIDGET (child));
Packit 98cdb6
Packit 98cdb6
  old_link = box->children;
Packit 98cdb6
  old_position = 0;
Packit 98cdb6
  while (old_link)
Packit 98cdb6
    {
Packit 98cdb6
      child_info = old_link->data;
Packit 98cdb6
      if (child_info->widget == child)
Packit 98cdb6
	break;
Packit 98cdb6
Packit 98cdb6
      old_link = old_link->next;
Packit 98cdb6
      old_position++;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  g_return_if_fail (old_link != NULL);
Packit 98cdb6
Packit 98cdb6
  if (position == old_position)
Packit 98cdb6
    return;
Packit 98cdb6
Packit 98cdb6
  box->children = g_list_delete_link (box->children, old_link);
Packit 98cdb6
Packit 98cdb6
  if (position < 0)
Packit 98cdb6
    new_link = NULL;
Packit 98cdb6
  else
Packit 98cdb6
    new_link = g_list_nth (box->children, position);
Packit 98cdb6
Packit 98cdb6
  box->children = g_list_insert_before (box->children, new_link, child_info);
Packit 98cdb6
Packit 98cdb6
  gtk_widget_child_notify (child, "position");
Packit 98cdb6
  if (gtk_widget_get_visible (child)
Packit 98cdb6
      && gtk_widget_get_visible (GTK_WIDGET (box)))
Packit 98cdb6
    gtk_widget_queue_resize (child);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_box_query_child_packing:
Packit 98cdb6
 * @box: a #GtkBox
Packit 98cdb6
 * @child: the #GtkWidget of the child to query
Packit 98cdb6
 * @expand: pointer to return location for #GtkBox:expand child property 
Packit 98cdb6
 * @fill: pointer to return location for #GtkBox:fill child property 
Packit 98cdb6
 * @padding: pointer to return location for #GtkBox:padding child property 
Packit 98cdb6
 * @pack_type: pointer to return location for #GtkBox:pack-type child property 
Packit 98cdb6
 * 
Packit 98cdb6
 * Obtains information about how @child is packed into @box.
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gtk_box_query_child_packing (GtkBox      *box,
Packit 98cdb6
			     GtkWidget   *child,
Packit 98cdb6
			     gboolean    *expand,
Packit 98cdb6
			     gboolean    *fill,
Packit 98cdb6
			     guint       *padding,
Packit 98cdb6
			     GtkPackType *pack_type)
Packit 98cdb6
{
Packit 98cdb6
  GList *list;
Packit 98cdb6
  GtkBoxChild *child_info = NULL;
Packit 98cdb6
Packit 98cdb6
  g_return_if_fail (GTK_IS_BOX (box));
Packit 98cdb6
  g_return_if_fail (GTK_IS_WIDGET (child));
Packit 98cdb6
Packit 98cdb6
  list = box->children;
Packit 98cdb6
  while (list)
Packit 98cdb6
    {
Packit 98cdb6
      child_info = list->data;
Packit 98cdb6
      if (child_info->widget == child)
Packit 98cdb6
	break;
Packit 98cdb6
Packit 98cdb6
      list = list->next;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  if (list)
Packit 98cdb6
    {
Packit 98cdb6
      if (expand)
Packit 98cdb6
	*expand = child_info->expand;
Packit 98cdb6
      if (fill)
Packit 98cdb6
	*fill = child_info->fill;
Packit 98cdb6
      if (padding)
Packit 98cdb6
	*padding = child_info->padding;
Packit 98cdb6
      if (pack_type)
Packit 98cdb6
	*pack_type = child_info->pack;
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_box_set_child_packing:
Packit 98cdb6
 * @box: a #GtkBox
Packit 98cdb6
 * @child: the #GtkWidget of the child to set
Packit 98cdb6
 * @expand: the new value of the #GtkBox:expand child property 
Packit 98cdb6
 * @fill: the new value of the #GtkBox:fill child property
Packit 98cdb6
 * @padding: the new value of the #GtkBox:padding child property
Packit 98cdb6
 * @pack_type: the new value of the #GtkBox:pack-type child property
Packit 98cdb6
 *
Packit 98cdb6
 * Sets the way @child is packed into @box.
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gtk_box_set_child_packing (GtkBox      *box,
Packit 98cdb6
			   GtkWidget   *child,
Packit 98cdb6
			   gboolean     expand,
Packit 98cdb6
			   gboolean     fill,
Packit 98cdb6
			   guint        padding,
Packit 98cdb6
			   GtkPackType  pack_type)
Packit 98cdb6
{
Packit 98cdb6
  GList *list;
Packit 98cdb6
  GtkBoxChild *child_info = NULL;
Packit 98cdb6
Packit 98cdb6
  g_return_if_fail (GTK_IS_BOX (box));
Packit 98cdb6
  g_return_if_fail (GTK_IS_WIDGET (child));
Packit 98cdb6
Packit 98cdb6
  list = box->children;
Packit 98cdb6
  while (list)
Packit 98cdb6
    {
Packit 98cdb6
      child_info = list->data;
Packit 98cdb6
      if (child_info->widget == child)
Packit 98cdb6
	break;
Packit 98cdb6
Packit 98cdb6
      list = list->next;
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  gtk_widget_freeze_child_notify (child);
Packit 98cdb6
  if (list)
Packit 98cdb6
    {
Packit 98cdb6
      child_info->expand = expand != FALSE;
Packit 98cdb6
      gtk_widget_child_notify (child, "expand");
Packit 98cdb6
      child_info->fill = fill != FALSE;
Packit 98cdb6
      gtk_widget_child_notify (child, "fill");
Packit 98cdb6
      child_info->padding = padding;
Packit 98cdb6
      gtk_widget_child_notify (child, "padding");
Packit 98cdb6
      if (pack_type == GTK_PACK_END)
Packit 98cdb6
	child_info->pack = GTK_PACK_END;
Packit 98cdb6
      else
Packit 98cdb6
	child_info->pack = GTK_PACK_START;
Packit 98cdb6
      gtk_widget_child_notify (child, "pack-type");
Packit 98cdb6
Packit 98cdb6
      if (gtk_widget_get_visible (child)
Packit 98cdb6
          && gtk_widget_get_visible (GTK_WIDGET (box)))
Packit 98cdb6
	gtk_widget_queue_resize (child);
Packit 98cdb6
    }
Packit 98cdb6
  gtk_widget_thaw_child_notify (child);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
void
Packit 98cdb6
_gtk_box_set_old_defaults (GtkBox *box)
Packit 98cdb6
{
Packit 98cdb6
  GtkBoxPrivate *private;
Packit 98cdb6
Packit 98cdb6
  g_return_if_fail (GTK_IS_BOX (box));
Packit 98cdb6
Packit 98cdb6
  private = GTK_BOX_GET_PRIVATE (box);
Packit 98cdb6
Packit 98cdb6
  private->default_expand = TRUE;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_box_add (GtkContainer *container,
Packit 98cdb6
	     GtkWidget    *widget)
Packit 98cdb6
{
Packit 98cdb6
  GtkBoxPrivate *private = GTK_BOX_GET_PRIVATE (container);
Packit 98cdb6
Packit 98cdb6
  gtk_box_pack_start (GTK_BOX (container), widget,
Packit 98cdb6
                      private->default_expand,
Packit 98cdb6
                      private->default_expand,
Packit 98cdb6
                      0);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_box_remove (GtkContainer *container,
Packit 98cdb6
		GtkWidget    *widget)
Packit 98cdb6
{
Packit 98cdb6
  GtkBox *box = GTK_BOX (container);
Packit 98cdb6
  GtkBoxChild *child;
Packit 98cdb6
  GList *children;
Packit 98cdb6
Packit 98cdb6
  children = box->children;
Packit 98cdb6
  while (children)
Packit 98cdb6
    {
Packit 98cdb6
      child = children->data;
Packit 98cdb6
Packit 98cdb6
      if (child->widget == widget)
Packit 98cdb6
	{
Packit 98cdb6
	  gboolean was_visible;
Packit 98cdb6
Packit 98cdb6
	  was_visible = gtk_widget_get_visible (widget);
Packit 98cdb6
	  gtk_widget_unparent (widget);
Packit 98cdb6
Packit 98cdb6
	  box->children = g_list_remove_link (box->children, children);
Packit 98cdb6
	  g_list_free (children);
Packit 98cdb6
	  g_free (child);
Packit 98cdb6
Packit 98cdb6
	  /* queue resize regardless of gtk_widget_get_visible (container),
Packit 98cdb6
	   * since that's what is needed by toplevels.
Packit 98cdb6
	   */
Packit 98cdb6
	  if (was_visible)
Packit 98cdb6
	    gtk_widget_queue_resize (GTK_WIDGET (container));
Packit 98cdb6
Packit 98cdb6
	  break;
Packit 98cdb6
	}
Packit 98cdb6
Packit 98cdb6
      children = children->next;
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_box_forall (GtkContainer *container,
Packit 98cdb6
		gboolean      include_internals,
Packit 98cdb6
		GtkCallback   callback,
Packit 98cdb6
		gpointer      callback_data)
Packit 98cdb6
{
Packit 98cdb6
  GtkBox *box = GTK_BOX (container);
Packit 98cdb6
  GtkBoxChild *child;
Packit 98cdb6
  GList *children;
Packit 98cdb6
Packit 98cdb6
  children = box->children;
Packit 98cdb6
  while (children)
Packit 98cdb6
    {
Packit 98cdb6
      child = children->data;
Packit 98cdb6
      children = children->next;
Packit 98cdb6
Packit 98cdb6
      if (child->pack == GTK_PACK_START)
Packit 98cdb6
	(* callback) (child->widget, callback_data);
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  children = g_list_last (box->children);
Packit 98cdb6
  while (children)
Packit 98cdb6
    {
Packit 98cdb6
      child = children->data;
Packit 98cdb6
      children = children->prev;
Packit 98cdb6
Packit 98cdb6
      if (child->pack == GTK_PACK_END)
Packit 98cdb6
	(* callback) (child->widget, callback_data);
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
#define __GTK_BOX_C__
Packit 98cdb6
#include "gtkaliasdef.c"