X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkalignment.c;h=ddd627ce86695a64dc262cfbc7bb0ec8809ad5a8;hb=3b2182e711ace4a2d6843848208224cd7525d530;hp=2e3a8bb566b5b81ad5606473f134c5e63dfac250;hpb=091335fcb47fb94727c247f70247a7c4a83cdb9b;p=~andy%2Fgtk
diff --git a/gtk/gtkalignment.c b/gtk/gtkalignment.c
index 2e3a8bb56..ddd627ce8 100644
--- a/gtk/gtkalignment.c
+++ b/gtk/gtkalignment.c
@@ -12,9 +12,7 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see .
*/
/*
@@ -41,6 +39,14 @@
* area. The values range from 0 (top or left) to 1 (bottom or right).
* Of course, if the scale settings are both set to 1, the alignment settings
* have no effect.
+ *
+ *
+ *
+ * Note that the desired effect can in most cases be achieved by using the
+ * #GtkWidget:halign, #GtkWidget:valign and #GtkWidget:margin properties
+ * on the child widget, so #GtkAlignment should not be used in new code.
+ *
+ *
*/
#include "config.h"
@@ -50,7 +56,7 @@
#include "gtkintl.h"
-struct _GtkAlignmentPriv
+struct _GtkAlignmentPrivate
{
gfloat xalign;
gfloat yalign;
@@ -88,17 +94,22 @@ static void gtk_alignment_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
-static void gtk_alignment_size_request_init (GtkSizeRequestIface *iface);
-static void gtk_alignment_get_width (GtkSizeRequest *widget,
- gint *minimum_size,
- gint *natural_size);
-static void gtk_alignment_get_height (GtkSizeRequest *widget,
- gint *minimum_size,
- gint *natural_size);
-
-G_DEFINE_TYPE_WITH_CODE (GtkAlignment, gtk_alignment, GTK_TYPE_BIN,
- G_IMPLEMENT_INTERFACE (GTK_TYPE_SIZE_REQUEST,
- gtk_alignment_size_request_init))
+static void gtk_alignment_get_preferred_width (GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size);
+static void gtk_alignment_get_preferred_height (GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size);
+static void gtk_alignment_get_preferred_width_for_height (GtkWidget *widget,
+ gint for_size,
+ gint *minimum_size,
+ gint *natural_size);
+static void gtk_alignment_get_preferred_height_for_width (GtkWidget *widget,
+ gint for_size,
+ gint *minimum_size,
+ gint *natural_size);
+
+G_DEFINE_TYPE (GtkAlignment, gtk_alignment, GTK_TYPE_BIN)
static void
gtk_alignment_class_init (GtkAlignmentClass *class)
@@ -112,7 +123,11 @@ gtk_alignment_class_init (GtkAlignmentClass *class)
gobject_class->set_property = gtk_alignment_set_property;
gobject_class->get_property = gtk_alignment_get_property;
- widget_class->size_allocate = gtk_alignment_size_allocate;
+ widget_class->size_allocate = gtk_alignment_size_allocate;
+ widget_class->get_preferred_width = gtk_alignment_get_preferred_width;
+ widget_class->get_preferred_height = gtk_alignment_get_preferred_height;
+ widget_class->get_preferred_width_for_height = gtk_alignment_get_preferred_width_for_height;
+ widget_class->get_preferred_height_for_width = gtk_alignment_get_preferred_height_for_width;
g_object_class_install_property (gobject_class,
PROP_XALIGN,
@@ -221,17 +236,17 @@ gtk_alignment_class_init (GtkAlignmentClass *class)
0,
GTK_PARAM_READWRITE));
- g_type_class_add_private (gobject_class, sizeof (GtkAlignmentPriv));
+ g_type_class_add_private (gobject_class, sizeof (GtkAlignmentPrivate));
}
static void
gtk_alignment_init (GtkAlignment *alignment)
{
- GtkAlignmentPriv *priv;
+ GtkAlignmentPrivate *priv;
alignment->priv = G_TYPE_INSTANCE_GET_PRIVATE (alignment,
GTK_TYPE_ALIGNMENT,
- GtkAlignmentPriv);
+ GtkAlignmentPrivate);
priv = alignment->priv;
gtk_widget_set_has_window (GTK_WIDGET (alignment), FALSE);
@@ -274,7 +289,7 @@ gtk_alignment_new (gfloat xalign,
gfloat yscale)
{
GtkAlignment *alignment;
- GtkAlignmentPriv *priv;
+ GtkAlignmentPrivate *priv;
alignment = g_object_new (GTK_TYPE_ALIGNMENT, NULL);
@@ -295,7 +310,7 @@ gtk_alignment_set_property (GObject *object,
GParamSpec *pspec)
{
GtkAlignment *alignment = GTK_ALIGNMENT (object);
- GtkAlignmentPriv *priv = alignment->priv;
+ GtkAlignmentPrivate *priv = alignment->priv;
switch (prop_id)
{
@@ -371,7 +386,7 @@ gtk_alignment_get_property (GObject *object,
GParamSpec *pspec)
{
GtkAlignment *alignment = GTK_ALIGNMENT (object);
- GtkAlignmentPriv *priv = alignment->priv;
+ GtkAlignmentPrivate *priv = alignment->priv;
switch (prop_id)
{
@@ -432,7 +447,7 @@ gtk_alignment_set (GtkAlignment *alignment,
gfloat xscale,
gfloat yscale)
{
- GtkAlignmentPriv *priv;
+ GtkAlignmentPrivate *priv;
GtkWidget *child;
g_return_if_fail (GTK_IS_ALIGNMENT (alignment));
@@ -485,10 +500,10 @@ gtk_alignment_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkAlignment *alignment = GTK_ALIGNMENT (widget);
- GtkAlignmentPriv *priv = alignment->priv;
+ GtkAlignmentPrivate *priv = alignment->priv;
GtkBin *bin;
GtkAllocation child_allocation;
- GtkWidget *bin_child;
+ GtkWidget *child;
gint width, height;
guint border_width;
gint padding_horizontal, padding_vertical;
@@ -499,10 +514,9 @@ gtk_alignment_size_allocate (GtkWidget *widget,
gtk_widget_set_allocation (widget, allocation);
bin = GTK_BIN (widget);
- bin_child = gtk_bin_get_child (bin);
- if (bin_child && gtk_widget_get_visible (bin_child))
+ child = gtk_bin_get_child (bin);
+ if (child && gtk_widget_get_visible (child))
{
- GtkSizeRequest *child = GTK_SIZE_REQUEST (bin_child);
gint child_nat_width;
gint child_nat_height;
gint child_width, child_height;
@@ -515,23 +529,23 @@ gtk_alignment_size_allocate (GtkWidget *widget,
width = MAX (1, allocation->width - padding_horizontal - 2 * border_width);
height = MAX (1, allocation->height - padding_vertical - 2 * border_width);
- if (gtk_size_request_get_request_mode (child) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
+ if (gtk_widget_get_request_mode (child) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
{
- gtk_size_request_get_width (child, NULL, &child_nat_width);
+ gtk_widget_get_preferred_width (child, NULL, &child_nat_width);
child_width = MIN (width, child_nat_width);
- gtk_size_request_get_height_for_width (child, child_width, NULL, &child_nat_height);
+ gtk_widget_get_preferred_height_for_width (child, child_width, NULL, &child_nat_height);
child_height = MIN (height, child_nat_height);
}
else
{
- gtk_size_request_get_height (child, NULL, &child_nat_height);
+ gtk_widget_get_preferred_height (child, NULL, &child_nat_height);
child_height = MIN (height, child_nat_height);
- gtk_size_request_get_width_for_height (child, child_height, NULL, &child_nat_width);
+ gtk_widget_get_preferred_width_for_height (child, child_height, NULL, &child_nat_width);
child_width = MIN (width, child_nat_width);
}
@@ -557,26 +571,20 @@ gtk_alignment_size_allocate (GtkWidget *widget,
child_allocation.y = priv->yalign * (height - child_allocation.height) + allocation->y + border_width + priv->padding_top;
- gtk_widget_size_allocate (bin_child, &child_allocation);
+ gtk_widget_size_allocate (child, &child_allocation);
}
}
static void
-gtk_alignment_size_request_init (GtkSizeRequestIface *iface)
-{
- iface->get_width = gtk_alignment_get_width;
- iface->get_height = gtk_alignment_get_height;
-}
-
-static void
-gtk_alignment_get_size (GtkSizeRequest *widget,
- GtkOrientation orientation,
- gint *minimum_size,
- gint *natural_size)
+gtk_alignment_get_preferred_size (GtkWidget *widget,
+ GtkOrientation orientation,
+ gint for_size,
+ gint *minimum_size,
+ gint *natural_size)
{
GtkAlignment *alignment = GTK_ALIGNMENT (widget);
- GtkAlignmentPriv *priv = alignment->priv;
+ GtkAlignmentPrivate *priv = alignment->priv;
GtkWidget *child;
guint minimum, natural;
@@ -590,14 +598,44 @@ gtk_alignment_get_size (GtkSizeRequest *widget,
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
minimum += (priv->padding_left + priv->padding_right);
- gtk_size_request_get_width (GTK_SIZE_REQUEST (child),
- &child_min, &child_nat);
+
+ if (for_size < 0)
+ gtk_widget_get_preferred_width (child, &child_min, &child_nat);
+ else
+ {
+ gint min_height;
+
+ gtk_widget_get_preferred_height (child, &min_height, NULL);
+
+ for_size -= (priv->padding_top + priv->padding_bottom);
+
+ if (for_size > min_height)
+ for_size = (min_height * (1.0 - priv->yscale) +
+ for_size * priv->yscale);
+
+ gtk_widget_get_preferred_width_for_height (child, for_size, &child_min, &child_nat);
+ }
}
else
{
minimum += (priv->padding_top + priv->padding_bottom);
- gtk_size_request_get_height (GTK_SIZE_REQUEST (child),
- &child_min, &child_nat);
+
+ if (for_size < 0)
+ gtk_widget_get_preferred_height (child, &child_min, &child_nat);
+ else
+ {
+ gint min_width;
+
+ gtk_widget_get_preferred_width (child, &min_width, NULL);
+
+ for_size -= (priv->padding_left + priv->padding_right);
+
+ if (for_size > min_width)
+ for_size = (min_width * (1.0 - priv->xscale) +
+ for_size * priv->xscale);
+
+ gtk_widget_get_preferred_height_for_width (child, for_size, &child_min, &child_nat);
+ }
}
natural = minimum;
@@ -614,19 +652,38 @@ gtk_alignment_get_size (GtkSizeRequest *widget,
}
static void
-gtk_alignment_get_width (GtkSizeRequest *widget,
- gint *minimum_size,
- gint *natural_size)
+gtk_alignment_get_preferred_width (GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size)
+{
+ gtk_alignment_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, -1, minimum_size, natural_size);
+}
+
+static void
+gtk_alignment_get_preferred_height (GtkWidget *widget,
+ gint *minimum_size,
+ gint *natural_size)
{
- gtk_alignment_get_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
+ gtk_alignment_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, -1, minimum_size, natural_size);
+}
+
+
+static void
+gtk_alignment_get_preferred_width_for_height (GtkWidget *widget,
+ gint for_size,
+ gint *minimum_size,
+ gint *natural_size)
+{
+ gtk_alignment_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, for_size, minimum_size, natural_size);
}
static void
-gtk_alignment_get_height (GtkSizeRequest *widget,
- gint *minimum_size,
- gint *natural_size)
+gtk_alignment_get_preferred_height_for_width (GtkWidget *widget,
+ gint for_size,
+ gint *minimum_size,
+ gint *natural_size)
{
- gtk_alignment_get_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
+ gtk_alignment_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, for_size, minimum_size, natural_size);
}
/**
@@ -651,7 +708,7 @@ gtk_alignment_set_padding (GtkAlignment *alignment,
guint padding_left,
guint padding_right)
{
- GtkAlignmentPriv *priv;
+ GtkAlignmentPrivate *priv;
GtkWidget *child;
g_return_if_fail (GTK_IS_ALIGNMENT (alignment));
@@ -694,10 +751,14 @@ gtk_alignment_set_padding (GtkAlignment *alignment,
/**
* gtk_alignment_get_padding:
* @alignment: a #GtkAlignment
- * @padding_top: (allow-none): location to store the padding for the top of the widget, or %NULL
- * @padding_bottom: (allow-none): location to store the padding for the bottom of the widget, or %NULL
- * @padding_left: (allow-none): location to store the padding for the left of the widget, or %NULL
- * @padding_right: (allow-none): location to store the padding for the right of the widget, or %NULL
+ * @padding_top: (out) (allow-none): location to store the padding for
+ * the top of the widget, or %NULL
+ * @padding_bottom: (out) (allow-none): location to store the padding
+ * for the bottom of the widget, or %NULL
+ * @padding_left: (out) (allow-none): location to store the padding
+ * for the left of the widget, or %NULL
+ * @padding_right: (out) (allow-none): location to store the padding
+ * for the right of the widget, or %NULL
*
* Gets the padding on the different sides of the widget.
* See gtk_alignment_set_padding ().
@@ -711,7 +772,7 @@ gtk_alignment_get_padding (GtkAlignment *alignment,
guint *padding_left,
guint *padding_right)
{
- GtkAlignmentPriv *priv;
+ GtkAlignmentPrivate *priv;
g_return_if_fail (GTK_IS_ALIGNMENT (alignment));