X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkalignment.c;h=ddd627ce86695a64dc262cfbc7bb0ec8809ad5a8;hb=02e915273845b21af223e7e5e2425569afcf1b83;hp=9a85a91a1b503c0e197843771de59ca060d72ae8;hpb=6b4992d647aaa1d67f5c61b0a8f0c202e770c918;p=~andy%2Fgtk diff --git a/gtk/gtkalignment.c b/gtk/gtkalignment.c index 9a85a91a1..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 . */ /* @@ -42,9 +40,13 @@ * 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. + * on the child widget, so #GtkAlignment should not be used in new code. + * + * */ #include "config.h" @@ -92,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) @@ -116,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, @@ -492,7 +503,7 @@ gtk_alignment_size_allocate (GtkWidget *widget, 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; @@ -503,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; @@ -519,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); } @@ -561,23 +571,17 @@ 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); GtkAlignmentPrivate *priv = alignment->priv; @@ -594,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; @@ -618,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); } /** @@ -698,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 ().