Blame gtk/gtkalignment.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
/**
Packit 98cdb6
 * SECTION:gtkalignment
Packit 98cdb6
 * @Short_description: A widget which controls the alignment and size of its child
Packit 98cdb6
 * @Title: GtkAlignment
Packit 98cdb6
 *
Packit 98cdb6
 * The #GtkAlignment widget controls the alignment and size of its child widget.
Packit 98cdb6
 * It has four settings: xscale, yscale, xalign, and yalign.
Packit 98cdb6
 *
Packit 98cdb6
 * The scale settings are used to specify how much the child widget should
Packit 98cdb6
 * expand to fill the space allocated to the #GtkAlignment.
Packit 98cdb6
 * The values can range from 0 (meaning the child doesn't expand at all) to
Packit 98cdb6
 * 1 (meaning the child expands to fill all of the available space).
Packit 98cdb6
 *
Packit 98cdb6
 * The align settings are used to place the child widget within the available
Packit 98cdb6
 * area. The values range from 0 (top or left) to 1 (bottom or right).
Packit 98cdb6
 * Of course, if the scale settings are both set to 1, the alignment settings
Packit 98cdb6
 * have no effect.
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
#include "config.h"
Packit 98cdb6
#include "gtkalignment.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
Packit 98cdb6
  PROP_XALIGN,
Packit 98cdb6
  PROP_YALIGN,
Packit 98cdb6
  PROP_XSCALE,
Packit 98cdb6
  PROP_YSCALE,
Packit 98cdb6
Packit 98cdb6
  PROP_TOP_PADDING,
Packit 98cdb6
  PROP_BOTTOM_PADDING,
Packit 98cdb6
  PROP_LEFT_PADDING,
Packit 98cdb6
  PROP_RIGHT_PADDING
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
#define GTK_ALIGNMENT_GET_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_ALIGNMENT, GtkAlignmentPrivate))
Packit 98cdb6
Packit 98cdb6
struct _GtkAlignmentPrivate
Packit 98cdb6
{
Packit 98cdb6
  guint padding_top;
Packit 98cdb6
  guint padding_bottom;
Packit 98cdb6
  guint padding_left;
Packit 98cdb6
  guint padding_right;
Packit 98cdb6
};
Packit 98cdb6
Packit 98cdb6
static void gtk_alignment_size_request  (GtkWidget         *widget,
Packit 98cdb6
					 GtkRequisition    *requisition);
Packit 98cdb6
static void gtk_alignment_size_allocate (GtkWidget         *widget,
Packit 98cdb6
					 GtkAllocation     *allocation);
Packit 98cdb6
static void gtk_alignment_set_property (GObject         *object,
Packit 98cdb6
                                        guint            prop_id,
Packit 98cdb6
                                        const GValue    *value,
Packit 98cdb6
                                        GParamSpec      *pspec);
Packit 98cdb6
static void gtk_alignment_get_property (GObject         *object,
Packit 98cdb6
                                        guint            prop_id,
Packit 98cdb6
                                        GValue          *value,
Packit 98cdb6
                                        GParamSpec      *pspec);
Packit 98cdb6
Packit 98cdb6
G_DEFINE_TYPE (GtkAlignment, gtk_alignment, GTK_TYPE_BIN)
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_alignment_class_init (GtkAlignmentClass *class)
Packit 98cdb6
{
Packit 98cdb6
  GObjectClass *gobject_class;
Packit 98cdb6
  GtkWidgetClass *widget_class;
Packit 98cdb6
Packit 98cdb6
  gobject_class = (GObjectClass*) class;
Packit 98cdb6
  widget_class = (GtkWidgetClass*) class;
Packit 98cdb6
  
Packit 98cdb6
  gobject_class->set_property = gtk_alignment_set_property;
Packit 98cdb6
  gobject_class->get_property = gtk_alignment_get_property;
Packit 98cdb6
Packit 98cdb6
  widget_class->size_request = gtk_alignment_size_request;
Packit 98cdb6
  widget_class->size_allocate = gtk_alignment_size_allocate;
Packit 98cdb6
Packit 98cdb6
  g_object_class_install_property (gobject_class,
Packit 98cdb6
                                   PROP_XALIGN,
Packit 98cdb6
                                   g_param_spec_float("xalign",
Packit 98cdb6
                                                      P_("Horizontal alignment"),
Packit 98cdb6
                                                      P_("Horizontal position of child in available space. 0.0 is left aligned, 1.0 is right aligned"),
Packit 98cdb6
                                                      0.0,
Packit 98cdb6
                                                      1.0,
Packit 98cdb6
                                                      0.5,
Packit 98cdb6
                                                      GTK_PARAM_READWRITE));
Packit 98cdb6
   
Packit 98cdb6
  g_object_class_install_property (gobject_class,
Packit 98cdb6
                                   PROP_YALIGN,
Packit 98cdb6
                                   g_param_spec_float("yalign",
Packit 98cdb6
                                                      P_("Vertical alignment"),
Packit 98cdb6
                                                      P_("Vertical position of child in available space. 0.0 is top aligned, 1.0 is bottom aligned"),
Packit 98cdb6
                                                      0.0,
Packit 98cdb6
                                                      1.0,
Packit 98cdb6
						      0.5,
Packit 98cdb6
                                                      GTK_PARAM_READWRITE));
Packit 98cdb6
  g_object_class_install_property (gobject_class,
Packit 98cdb6
                                   PROP_XSCALE,
Packit 98cdb6
                                   g_param_spec_float("xscale",
Packit 98cdb6
                                                      P_("Horizontal scale"),
Packit 98cdb6
                                                      P_("If available horizontal space is bigger than needed for the child, how much of it to use for the child. 0.0 means none, 1.0 means all"),
Packit 98cdb6
                                                      0.0,
Packit 98cdb6
                                                      1.0,
Packit 98cdb6
                                                      1.0,
Packit 98cdb6
                                                      GTK_PARAM_READWRITE));
Packit 98cdb6
  g_object_class_install_property (gobject_class,
Packit 98cdb6
                                   PROP_YSCALE,
Packit 98cdb6
                                   g_param_spec_float("yscale",
Packit 98cdb6
                                                      P_("Vertical scale"),
Packit 98cdb6
                                                      P_("If available vertical space is bigger than needed for the child, how much of it to use for the child. 0.0 means none, 1.0 means all"),
Packit 98cdb6
                                                      0.0,
Packit 98cdb6
                                                      1.0,
Packit 98cdb6
                                                      1.0,
Packit 98cdb6
                                                      GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * GtkAlignment:top-padding:
Packit 98cdb6
 *
Packit 98cdb6
 * The padding to insert at the top of the widget.
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.4
Packit 98cdb6
 */
Packit 98cdb6
  g_object_class_install_property (gobject_class,
Packit 98cdb6
                                   PROP_TOP_PADDING,
Packit 98cdb6
                                   g_param_spec_uint("top-padding",
Packit 98cdb6
                                                      P_("Top Padding"),
Packit 98cdb6
                                                      P_("The padding to insert at the top of the widget."),
Packit 98cdb6
                                                      0,
Packit 98cdb6
                                                      G_MAXINT,
Packit 98cdb6
                                                      0,
Packit 98cdb6
                                                      GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * GtkAlignment:bottom-padding:
Packit 98cdb6
 *
Packit 98cdb6
 * The padding to insert at the bottom of the widget.
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.4
Packit 98cdb6
 */
Packit 98cdb6
  g_object_class_install_property (gobject_class,
Packit 98cdb6
                                   PROP_BOTTOM_PADDING,
Packit 98cdb6
                                   g_param_spec_uint("bottom-padding",
Packit 98cdb6
                                                      P_("Bottom Padding"),
Packit 98cdb6
                                                      P_("The padding to insert at the bottom of the widget."),
Packit 98cdb6
                                                      0,
Packit 98cdb6
                                                      G_MAXINT,
Packit 98cdb6
                                                      0,
Packit 98cdb6
                                                      GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * GtkAlignment:left-padding:
Packit 98cdb6
 *
Packit 98cdb6
 * The padding to insert at the left of the widget.
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.4
Packit 98cdb6
 */
Packit 98cdb6
  g_object_class_install_property (gobject_class,
Packit 98cdb6
                                   PROP_LEFT_PADDING,
Packit 98cdb6
                                   g_param_spec_uint("left-padding",
Packit 98cdb6
                                                      P_("Left Padding"),
Packit 98cdb6
                                                      P_("The padding to insert at the left of the widget."),
Packit 98cdb6
                                                      0,
Packit 98cdb6
                                                      G_MAXINT,
Packit 98cdb6
                                                      0,
Packit 98cdb6
                                                      GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * GtkAlignment:right-padding:
Packit 98cdb6
 *
Packit 98cdb6
 * The padding to insert at the right of the widget.
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.4
Packit 98cdb6
 */
Packit 98cdb6
  g_object_class_install_property (gobject_class,
Packit 98cdb6
                                   PROP_RIGHT_PADDING,
Packit 98cdb6
                                   g_param_spec_uint("right-padding",
Packit 98cdb6
                                                      P_("Right Padding"),
Packit 98cdb6
                                                      P_("The padding to insert at the right of the widget."),
Packit 98cdb6
                                                      0,
Packit 98cdb6
                                                      G_MAXINT,
Packit 98cdb6
                                                      0,
Packit 98cdb6
                                                      GTK_PARAM_READWRITE));
Packit 98cdb6
Packit 98cdb6
  g_type_class_add_private (gobject_class, sizeof (GtkAlignmentPrivate));  
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_alignment_init (GtkAlignment *alignment)
Packit 98cdb6
{
Packit 98cdb6
  GtkAlignmentPrivate *priv;
Packit 98cdb6
  
Packit 98cdb6
  gtk_widget_set_has_window (GTK_WIDGET (alignment), FALSE);
Packit 98cdb6
  gtk_widget_set_redraw_on_allocate (GTK_WIDGET (alignment), FALSE);
Packit 98cdb6
Packit 98cdb6
  alignment->xalign = 0.5;
Packit 98cdb6
  alignment->yalign = 0.5;
Packit 98cdb6
  alignment->xscale = 1.0;
Packit 98cdb6
  alignment->yscale = 1.0;
Packit 98cdb6
Packit 98cdb6
  /* Initialize padding with default values: */
Packit 98cdb6
  priv = GTK_ALIGNMENT_GET_PRIVATE (alignment);
Packit 98cdb6
  priv->padding_top = 0;
Packit 98cdb6
  priv->padding_bottom = 0;
Packit 98cdb6
  priv->padding_left = 0;
Packit 98cdb6
  priv->padding_right = 0;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_alignment_new:
Packit 98cdb6
 * @xalign: the horizontal alignment of the child widget, from 0 (left) to 1
Packit 98cdb6
 *  (right).
Packit 98cdb6
 * @yalign: the vertical alignment of the child widget, from 0 (top) to 1
Packit 98cdb6
 *  (bottom).
Packit 98cdb6
 * @xscale: the amount that the child widget expands horizontally to fill up
Packit 98cdb6
 *  unused space, from 0 to 1.
Packit 98cdb6
 *  A value of 0 indicates that the child widget should never expand.
Packit 98cdb6
 *  A value of 1 indicates that the child widget will expand to fill all of the
Packit 98cdb6
 *  space allocated for the #GtkAlignment.
Packit 98cdb6
 * @yscale: the amount that the child widget expands vertically to fill up
Packit 98cdb6
 *  unused space, from 0 to 1. The values are similar to @xscale.
Packit 98cdb6
 *
Packit 98cdb6
 * Creates a new #GtkAlignment.
Packit 98cdb6
 *
Packit 98cdb6
 * Returns: the new #GtkAlignment.
Packit 98cdb6
 */
Packit 98cdb6
GtkWidget*
Packit 98cdb6
gtk_alignment_new (gfloat xalign,
Packit 98cdb6
		   gfloat yalign,
Packit 98cdb6
		   gfloat xscale,
Packit 98cdb6
		   gfloat yscale)
Packit 98cdb6
{
Packit 98cdb6
  GtkAlignment *alignment;
Packit 98cdb6
Packit 98cdb6
  alignment = g_object_new (GTK_TYPE_ALIGNMENT, NULL);
Packit 98cdb6
Packit 98cdb6
  alignment->xalign = CLAMP (xalign, 0.0, 1.0);
Packit 98cdb6
  alignment->yalign = CLAMP (yalign, 0.0, 1.0);
Packit 98cdb6
  alignment->xscale = CLAMP (xscale, 0.0, 1.0);
Packit 98cdb6
  alignment->yscale = CLAMP (yscale, 0.0, 1.0);
Packit 98cdb6
Packit 98cdb6
  return GTK_WIDGET (alignment);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_alignment_set_property (GObject         *object,
Packit 98cdb6
			    guint            prop_id,
Packit 98cdb6
			    const GValue    *value,
Packit 98cdb6
			    GParamSpec      *pspec)
Packit 98cdb6
{
Packit 98cdb6
  GtkAlignment *alignment;
Packit 98cdb6
  GtkAlignmentPrivate *priv;
Packit 98cdb6
  
Packit 98cdb6
  alignment = GTK_ALIGNMENT (object);
Packit 98cdb6
  priv = GTK_ALIGNMENT_GET_PRIVATE (alignment);
Packit 98cdb6
  
Packit 98cdb6
  switch (prop_id)
Packit 98cdb6
    {
Packit 98cdb6
    case PROP_XALIGN:
Packit 98cdb6
      gtk_alignment_set (alignment,
Packit 98cdb6
			 g_value_get_float (value),
Packit 98cdb6
			 alignment->yalign,
Packit 98cdb6
			 alignment->xscale,
Packit 98cdb6
			 alignment->yscale);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_YALIGN:
Packit 98cdb6
      gtk_alignment_set (alignment,
Packit 98cdb6
			 alignment->xalign,
Packit 98cdb6
			 g_value_get_float (value),
Packit 98cdb6
			 alignment->xscale,
Packit 98cdb6
			 alignment->yscale);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_XSCALE:
Packit 98cdb6
      gtk_alignment_set (alignment,
Packit 98cdb6
			 alignment->xalign,
Packit 98cdb6
			 alignment->yalign,
Packit 98cdb6
			 g_value_get_float (value),
Packit 98cdb6
			 alignment->yscale);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_YSCALE:
Packit 98cdb6
      gtk_alignment_set (alignment,
Packit 98cdb6
			 alignment->xalign,
Packit 98cdb6
			 alignment->yalign,
Packit 98cdb6
			 alignment->xscale,
Packit 98cdb6
			 g_value_get_float (value));
Packit 98cdb6
      break;
Packit 98cdb6
      
Packit 98cdb6
    /* Padding: */
Packit 98cdb6
    case PROP_TOP_PADDING:
Packit 98cdb6
      gtk_alignment_set_padding (alignment,
Packit 98cdb6
			 g_value_get_uint (value),
Packit 98cdb6
			 priv->padding_bottom,
Packit 98cdb6
			 priv->padding_left,
Packit 98cdb6
			 priv->padding_right);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_BOTTOM_PADDING:
Packit 98cdb6
      gtk_alignment_set_padding (alignment,
Packit 98cdb6
			 priv->padding_top,
Packit 98cdb6
			 g_value_get_uint (value),
Packit 98cdb6
			 priv->padding_left,
Packit 98cdb6
			 priv->padding_right);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_LEFT_PADDING:
Packit 98cdb6
      gtk_alignment_set_padding (alignment,
Packit 98cdb6
			 priv->padding_top,
Packit 98cdb6
			 priv->padding_bottom,
Packit 98cdb6
			 g_value_get_uint (value),
Packit 98cdb6
			 priv->padding_right);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_RIGHT_PADDING:
Packit 98cdb6
      gtk_alignment_set_padding (alignment,
Packit 98cdb6
			 priv->padding_top,
Packit 98cdb6
			 priv->padding_bottom,
Packit 98cdb6
			 priv->padding_left,
Packit 98cdb6
			 g_value_get_uint (value));
Packit 98cdb6
      break;
Packit 98cdb6
    
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_alignment_get_property (GObject         *object,
Packit 98cdb6
			    guint            prop_id,
Packit 98cdb6
			    GValue          *value,
Packit 98cdb6
			    GParamSpec      *pspec)
Packit 98cdb6
{
Packit 98cdb6
  GtkAlignment *alignment;
Packit 98cdb6
  GtkAlignmentPrivate *priv;
Packit 98cdb6
Packit 98cdb6
  alignment = GTK_ALIGNMENT (object);
Packit 98cdb6
  priv = GTK_ALIGNMENT_GET_PRIVATE (alignment);
Packit 98cdb6
   
Packit 98cdb6
  switch (prop_id)
Packit 98cdb6
    {
Packit 98cdb6
    case PROP_XALIGN:
Packit 98cdb6
      g_value_set_float(value, alignment->xalign);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_YALIGN:
Packit 98cdb6
      g_value_set_float(value, alignment->yalign);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_XSCALE:
Packit 98cdb6
      g_value_set_float(value, alignment->xscale);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_YSCALE:
Packit 98cdb6
      g_value_set_float(value, alignment->yscale);
Packit 98cdb6
      break;
Packit 98cdb6
Packit 98cdb6
    /* Padding: */
Packit 98cdb6
    case PROP_TOP_PADDING:
Packit 98cdb6
      g_value_set_uint (value, priv->padding_top);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_BOTTOM_PADDING:
Packit 98cdb6
      g_value_set_uint (value, priv->padding_bottom);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_LEFT_PADDING:
Packit 98cdb6
      g_value_set_uint (value, priv->padding_left);
Packit 98cdb6
      break;
Packit 98cdb6
    case PROP_RIGHT_PADDING:
Packit 98cdb6
      g_value_set_uint (value, priv->padding_right);
Packit 98cdb6
      break;
Packit 98cdb6
      
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
/**
Packit 98cdb6
 * gtk_alignment_set:
Packit 98cdb6
 * @alignment: a #GtkAlignment.
Packit 98cdb6
 * @xalign: the horizontal alignment of the child widget, from 0 (left) to 1
Packit 98cdb6
 *  (right).
Packit 98cdb6
 * @yalign: the vertical alignment of the child widget, from 0 (top) to 1
Packit 98cdb6
 *  (bottom).
Packit 98cdb6
 * @xscale: the amount that the child widget expands horizontally to fill up
Packit 98cdb6
 *  unused space, from 0 to 1.
Packit 98cdb6
 *  A value of 0 indicates that the child widget should never expand.
Packit 98cdb6
 *  A value of 1 indicates that the child widget will expand to fill all of the
Packit 98cdb6
 *  space allocated for the #GtkAlignment.
Packit 98cdb6
 * @yscale: the amount that the child widget expands vertically to fill up
Packit 98cdb6
 *  unused space, from 0 to 1. The values are similar to @xscale.
Packit 98cdb6
 *
Packit 98cdb6
 * Sets the #GtkAlignment values.
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gtk_alignment_set (GtkAlignment *alignment,
Packit 98cdb6
		   gfloat        xalign,
Packit 98cdb6
		   gfloat        yalign,
Packit 98cdb6
		   gfloat        xscale,
Packit 98cdb6
		   gfloat        yscale)
Packit 98cdb6
{
Packit 98cdb6
  g_return_if_fail (GTK_IS_ALIGNMENT (alignment));
Packit 98cdb6
Packit 98cdb6
  xalign = CLAMP (xalign, 0.0, 1.0);
Packit 98cdb6
  yalign = CLAMP (yalign, 0.0, 1.0);
Packit 98cdb6
  xscale = CLAMP (xscale, 0.0, 1.0);
Packit 98cdb6
  yscale = CLAMP (yscale, 0.0, 1.0);
Packit 98cdb6
Packit 98cdb6
  if (   (alignment->xalign != xalign)
Packit 98cdb6
      || (alignment->yalign != yalign)
Packit 98cdb6
      || (alignment->xscale != xscale)
Packit 98cdb6
      || (alignment->yscale != yscale))
Packit 98cdb6
    {
Packit 98cdb6
      g_object_freeze_notify (G_OBJECT (alignment));
Packit 98cdb6
      if (alignment->xalign != xalign)
Packit 98cdb6
        {
Packit 98cdb6
           alignment->xalign = xalign;
Packit 98cdb6
           g_object_notify (G_OBJECT (alignment), "xalign");
Packit 98cdb6
        }
Packit 98cdb6
      if (alignment->yalign != yalign)
Packit 98cdb6
        {
Packit 98cdb6
           alignment->yalign = yalign;
Packit 98cdb6
           g_object_notify (G_OBJECT (alignment), "yalign");
Packit 98cdb6
        }
Packit 98cdb6
      if (alignment->xscale != xscale)
Packit 98cdb6
        {
Packit 98cdb6
           alignment->xscale = xscale;
Packit 98cdb6
           g_object_notify (G_OBJECT (alignment), "xscale");
Packit 98cdb6
        }
Packit 98cdb6
      if (alignment->yscale != yscale)
Packit 98cdb6
        {
Packit 98cdb6
           alignment->yscale = yscale;
Packit 98cdb6
           g_object_notify (G_OBJECT (alignment), "yscale");
Packit 98cdb6
        }
Packit 98cdb6
      g_object_thaw_notify (G_OBJECT (alignment));
Packit 98cdb6
Packit 98cdb6
      if (GTK_BIN (alignment)->child)
Packit 98cdb6
        gtk_widget_queue_resize (GTK_BIN (alignment)->child);
Packit 98cdb6
      gtk_widget_queue_draw (GTK_WIDGET (alignment));
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_alignment_size_request (GtkWidget      *widget,
Packit 98cdb6
			    GtkRequisition *requisition)
Packit 98cdb6
{
Packit 98cdb6
  GtkBin *bin;
Packit 98cdb6
  GtkAlignmentPrivate *priv;
Packit 98cdb6
Packit 98cdb6
  bin = GTK_BIN (widget);
Packit 98cdb6
  priv = GTK_ALIGNMENT_GET_PRIVATE (widget);
Packit 98cdb6
Packit 98cdb6
  requisition->width = GTK_CONTAINER (widget)->border_width * 2;
Packit 98cdb6
  requisition->height = GTK_CONTAINER (widget)->border_width * 2;
Packit 98cdb6
Packit 98cdb6
  if (bin->child && gtk_widget_get_visible (bin->child))
Packit 98cdb6
    {
Packit 98cdb6
      GtkRequisition child_requisition;
Packit 98cdb6
      
Packit 98cdb6
      gtk_widget_size_request (bin->child, &child_requisition);
Packit 98cdb6
Packit 98cdb6
      requisition->width += child_requisition.width;
Packit 98cdb6
      requisition->height += child_requisition.height;
Packit 98cdb6
Packit 98cdb6
      /* Request extra space for the padding: */
Packit 98cdb6
      requisition->width += (priv->padding_left + priv->padding_right);
Packit 98cdb6
      requisition->height += (priv->padding_top + priv->padding_bottom);
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static void
Packit 98cdb6
gtk_alignment_size_allocate (GtkWidget     *widget,
Packit 98cdb6
			     GtkAllocation *allocation)
Packit 98cdb6
{
Packit 98cdb6
  GtkAlignment *alignment;
Packit 98cdb6
  GtkBin *bin;
Packit 98cdb6
  GtkAllocation child_allocation;
Packit 98cdb6
  GtkRequisition child_requisition;
Packit 98cdb6
  gint width, height;
Packit 98cdb6
  gint border_width;
Packit 98cdb6
  gint padding_horizontal, padding_vertical;
Packit 98cdb6
  GtkAlignmentPrivate *priv;
Packit 98cdb6
Packit 98cdb6
  padding_horizontal = 0;
Packit 98cdb6
  padding_vertical = 0;
Packit 98cdb6
Packit 98cdb6
  widget->allocation = *allocation;
Packit 98cdb6
  alignment = GTK_ALIGNMENT (widget);
Packit 98cdb6
  bin = GTK_BIN (widget);
Packit 98cdb6
  
Packit 98cdb6
  if (bin->child && gtk_widget_get_visible (bin->child))
Packit 98cdb6
    {
Packit 98cdb6
      gtk_widget_get_child_requisition (bin->child, &child_requisition);
Packit 98cdb6
Packit 98cdb6
      border_width = GTK_CONTAINER (alignment)->border_width;
Packit 98cdb6
Packit 98cdb6
      priv = GTK_ALIGNMENT_GET_PRIVATE (widget);
Packit 98cdb6
      padding_horizontal = priv->padding_left + priv->padding_right;
Packit 98cdb6
      padding_vertical = priv->padding_top + priv->padding_bottom;
Packit 98cdb6
Packit 98cdb6
      width  = MAX (1, allocation->width - padding_horizontal - 2 * border_width);
Packit 98cdb6
      height = MAX (1, allocation->height - padding_vertical - 2 * border_width);
Packit 98cdb6
    
Packit 98cdb6
      if (width > child_requisition.width)
Packit 98cdb6
	child_allocation.width = (child_requisition.width *
Packit 98cdb6
				  (1.0 - alignment->xscale) +
Packit 98cdb6
				  width * alignment->xscale);
Packit 98cdb6
      else
Packit 98cdb6
	child_allocation.width = width;
Packit 98cdb6
      
Packit 98cdb6
      if (height > child_requisition.height)
Packit 98cdb6
	child_allocation.height = (child_requisition.height *
Packit 98cdb6
				   (1.0 - alignment->yscale) +
Packit 98cdb6
				   height * alignment->yscale);
Packit 98cdb6
      else
Packit 98cdb6
	child_allocation.height = height;
Packit 98cdb6
Packit 98cdb6
      if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
Packit 98cdb6
	child_allocation.x = (1.0 - alignment->xalign) * (width - child_allocation.width) + allocation->x + border_width + priv->padding_right;
Packit 98cdb6
      else 
Packit 98cdb6
	child_allocation.x = alignment->xalign * (width - child_allocation.width) + allocation->x + border_width + priv->padding_left;
Packit 98cdb6
Packit 98cdb6
      child_allocation.y = alignment->yalign * (height - child_allocation.height) + allocation->y + border_width + priv->padding_top;
Packit 98cdb6
Packit 98cdb6
      gtk_widget_size_allocate (bin->child, &child_allocation);
Packit 98cdb6
    }
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_alignment_set_padding:
Packit 98cdb6
 * @alignment: a #GtkAlignment
Packit 98cdb6
 * @padding_top: the padding at the top of the widget
Packit 98cdb6
 * @padding_bottom: the padding at the bottom of the widget
Packit 98cdb6
 * @padding_left: the padding at the left of the widget
Packit 98cdb6
 * @padding_right: the padding at the right of the widget.
Packit 98cdb6
 *
Packit 98cdb6
 * Sets the padding on the different sides of the widget.
Packit 98cdb6
 * The padding adds blank space to the sides of the widget. For instance,
Packit 98cdb6
 * this can be used to indent the child widget towards the right by adding
Packit 98cdb6
 * padding on the left.
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.4
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gtk_alignment_set_padding (GtkAlignment    *alignment,
Packit 98cdb6
			   guint            padding_top,
Packit 98cdb6
			   guint            padding_bottom,
Packit 98cdb6
			   guint            padding_left,
Packit 98cdb6
			   guint            padding_right)
Packit 98cdb6
{
Packit 98cdb6
  GtkAlignmentPrivate *priv;
Packit 98cdb6
  
Packit 98cdb6
  g_return_if_fail (GTK_IS_ALIGNMENT (alignment));
Packit 98cdb6
Packit 98cdb6
  priv = GTK_ALIGNMENT_GET_PRIVATE (alignment);
Packit 98cdb6
Packit 98cdb6
  g_object_freeze_notify (G_OBJECT (alignment));
Packit 98cdb6
Packit 98cdb6
  if (priv->padding_top != padding_top)
Packit 98cdb6
    {
Packit 98cdb6
      priv->padding_top = padding_top;
Packit 98cdb6
      g_object_notify (G_OBJECT (alignment), "top-padding");
Packit 98cdb6
    }
Packit 98cdb6
  if (priv->padding_bottom != padding_bottom)
Packit 98cdb6
    {
Packit 98cdb6
      priv->padding_bottom = padding_bottom;
Packit 98cdb6
      g_object_notify (G_OBJECT (alignment), "bottom-padding");
Packit 98cdb6
    }
Packit 98cdb6
  if (priv->padding_left != padding_left)
Packit 98cdb6
    {
Packit 98cdb6
      priv->padding_left = padding_left;
Packit 98cdb6
      g_object_notify (G_OBJECT (alignment), "left-padding");
Packit 98cdb6
    }
Packit 98cdb6
  if (priv->padding_right != padding_right)
Packit 98cdb6
    {
Packit 98cdb6
      priv->padding_right = padding_right;
Packit 98cdb6
      g_object_notify (G_OBJECT (alignment), "right-padding");
Packit 98cdb6
    }
Packit 98cdb6
Packit 98cdb6
  g_object_thaw_notify (G_OBJECT (alignment));
Packit 98cdb6
  
Packit 98cdb6
  /* Make sure that the widget and children are redrawn with the new setting: */
Packit 98cdb6
  if (GTK_BIN (alignment)->child)
Packit 98cdb6
    gtk_widget_queue_resize (GTK_BIN (alignment)->child);
Packit 98cdb6
Packit 98cdb6
  gtk_widget_queue_draw (GTK_WIDGET (alignment));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gtk_alignment_get_padding:
Packit 98cdb6
 * @alignment: a #GtkAlignment
Packit 98cdb6
 * @padding_top: (out) (allow-none): location to store the padding for
Packit 98cdb6
 *     the top of the widget, or %NULL
Packit 98cdb6
 * @padding_bottom: (out) (allow-none): location to store the padding
Packit 98cdb6
 *     for the bottom of the widget, or %NULL
Packit 98cdb6
 * @padding_left: (out) (allow-none): location to store the padding
Packit 98cdb6
 *     for the left of the widget, or %NULL
Packit 98cdb6
 * @padding_right: (out) (allow-none): location to store the padding
Packit 98cdb6
 *     for the right of the widget, or %NULL
Packit 98cdb6
 *
Packit 98cdb6
 * Gets the padding on the different sides of the widget.
Packit 98cdb6
 * See gtk_alignment_set_padding ().
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.4
Packit 98cdb6
 */
Packit 98cdb6
void
Packit 98cdb6
gtk_alignment_get_padding (GtkAlignment    *alignment,
Packit 98cdb6
			   guint           *padding_top,
Packit 98cdb6
			   guint           *padding_bottom,
Packit 98cdb6
			   guint           *padding_left,
Packit 98cdb6
			   guint           *padding_right)
Packit 98cdb6
{
Packit 98cdb6
  GtkAlignmentPrivate *priv;
Packit 98cdb6
 
Packit 98cdb6
  g_return_if_fail (GTK_IS_ALIGNMENT (alignment));
Packit 98cdb6
Packit 98cdb6
  priv = GTK_ALIGNMENT_GET_PRIVATE (alignment);
Packit 98cdb6
  if(padding_top)
Packit 98cdb6
    *padding_top = priv->padding_top;
Packit 98cdb6
  if(padding_bottom)
Packit 98cdb6
    *padding_bottom = priv->padding_bottom;
Packit 98cdb6
  if(padding_left)
Packit 98cdb6
    *padding_left = priv->padding_left;
Packit 98cdb6
  if(padding_right)
Packit 98cdb6
    *padding_right = priv->padding_right;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
#define __GTK_ALIGNMENT_C__
Packit 98cdb6
#include "gtkaliasdef.c"