Use accessor functions to access GtkMisc

This commit is contained in:
Javier Jardón 2010-07-02 17:49:18 +02:00
parent e2b8112fd8
commit 978a031b76
4 changed files with 95 additions and 57 deletions

View File

@ -176,6 +176,7 @@ static void
gtk_arrow_init (GtkArrow *arrow)
{
GtkArrowPriv *priv;
gint xpad, ypad;
arrow->priv = G_TYPE_INSTANCE_GET_PRIVATE (arrow,
GTK_TYPE_ARROW,
@ -184,8 +185,9 @@ gtk_arrow_init (GtkArrow *arrow)
gtk_widget_set_has_window (GTK_WIDGET (arrow), FALSE);
GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
gtk_misc_get_padding (GTK_MISC (arrow), &xpad, &ypad);
GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + xpad * 2;
GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + ypad * 2;
priv->arrow_type = GTK_ARROW_RIGHT;
priv->shadow_type = GTK_SHADOW_OUT;
@ -276,32 +278,34 @@ gtk_arrow_expose (GtkWidget *widget,
gint width, height;
gint x, y;
gint extent;
gfloat xalign;
gint xpad, ypad;
gfloat xalign, yalign;
GtkArrowType effective_arrow_type;
gfloat arrow_scaling;
gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL);
width = widget->allocation.width - misc->xpad * 2;
height = widget->allocation.height - misc->ypad * 2;
gtk_misc_get_padding (misc, &xpad, &ypad);
gtk_misc_get_alignment (misc, &xalign, &yalign);
width = widget->allocation.width - xpad * 2;
height = widget->allocation.height - ypad * 2;
extent = MIN (width, height) * arrow_scaling;
effective_arrow_type = priv->arrow_type;
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
xalign = misc->xalign;
else
{
xalign = 1.0 - misc->xalign;
if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
{
xalign = 1.0 - xalign;
if (priv->arrow_type == GTK_ARROW_LEFT)
effective_arrow_type = GTK_ARROW_RIGHT;
else if (priv->arrow_type == GTK_ARROW_RIGHT)
effective_arrow_type = GTK_ARROW_LEFT;
}
x = floor (widget->allocation.x + misc->xpad
x = floor (widget->allocation.x + xpad
+ ((widget->allocation.width - extent) * xalign));
y = floor (widget->allocation.y + misc->ypad
+ ((widget->allocation.height - extent) * misc->yalign));
y = floor (widget->allocation.y + ypad
+ ((widget->allocation.height - extent) * yalign));
shadow_type = priv->shadow_type;

View File

@ -1933,8 +1933,9 @@ gtk_image_expose (GtkWidget *widget,
{
GtkMisc *misc;
GdkRectangle area, image_bound;
gfloat xalign;
gint x, y, mask_x, mask_y;
gint xpad, ypad;
gfloat xalign, yalign;
GdkBitmap *mask;
GdkPixbuf *pixbuf;
GtkStateType state;
@ -1954,15 +1955,16 @@ gtk_image_expose (GtkWidget *widget,
if (!gdk_rectangle_intersect (&area, &widget->allocation, &area))
return FALSE;
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
xalign = misc->xalign;
else
xalign = 1.0 - misc->xalign;
gtk_misc_get_alignment (misc, &xalign, &yalign);
gtk_misc_get_padding (misc, &xpad, &ypad);
x = floor (widget->allocation.x + misc->xpad
if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
xalign = 1.0 - xalign;
x = floor (widget->allocation.x + xpad
+ ((widget->allocation.width - widget->requisition.width) * xalign));
y = floor (widget->allocation.y + misc->ypad
+ ((widget->allocation.height - widget->requisition.height) * misc->yalign));
y = floor (widget->allocation.y + ypad
+ ((widget->allocation.height - widget->requisition.height) * yalign));
mask_x = x;
mask_y = y;
@ -2447,8 +2449,12 @@ gtk_image_calc_size (GtkImage *image)
if (pixbuf)
{
widget->requisition.width = gdk_pixbuf_get_width (pixbuf) + GTK_MISC (image)->xpad * 2;
widget->requisition.height = gdk_pixbuf_get_height (pixbuf) + GTK_MISC (image)->ypad * 2;
gint xpad, ypad;
gtk_misc_get_padding (GTK_MISC (image), &xpad, &ypad);
widget->requisition.width = gdk_pixbuf_get_width (pixbuf) + xpad * 2;
widget->requisition.height = gdk_pixbuf_get_height (pixbuf) + ypad * 2;
g_object_unref (pixbuf);
}
@ -2502,9 +2508,12 @@ gtk_image_update_size (GtkImage *image,
gint image_height)
{
GtkWidget *widget = GTK_WIDGET (image);
gint xpad, ypad;
widget->requisition.width = image_width + GTK_MISC (image)->xpad * 2;
widget->requisition.height = image_height + GTK_MISC (image)->ypad * 2;
gtk_misc_get_padding (GTK_MISC (image), &xpad, &ypad);
widget->requisition.width = image_width + xpad * 2;
widget->requisition.height = image_height + ypad * 2;
if (gtk_widget_get_visible (widget))
gtk_widget_queue_resize (widget);

View File

@ -3252,10 +3252,13 @@ gtk_label_ensure_layout (GtkLabel *label, gboolean guess_wrap_width)
else if (guess_wrap_width == FALSE &&
widget->allocation.width > 1 && widget->allocation.height > 1)
{
gint xpad, ypad;
gtk_misc_get_padding (GTK_MISC (label), &xpad, &ypad);
if (angle == 90 || angle == 270)
width = widget->allocation.height - label->misc.ypad * 2;
width = widget->allocation.height - ypad * 2;
else
width = widget->allocation.width - label->misc.xpad * 2;
width = widget->allocation.width - xpad * 2;
pango_layout_set_wrap (priv->layout, priv->wrap_mode);
pango_layout_set_width (priv->layout, MAX (width, 1) * PANGO_SCALE);
@ -3417,6 +3420,7 @@ gtk_label_get_size (GtkSizeRequest *widget,
PangoRectangle required_rect;
PangoRectangle natural_rect;
gdouble angle;
gint xpad, ypad;
/* "width-chars" Hard-coded minimum width:
* - minimum size should be MAX (width-chars, strlen ("..."));
@ -3485,6 +3489,8 @@ gtk_label_get_size (GtkSizeRequest *widget,
natural_rect.width = PANGO_PIXELS_CEIL (natural_rect.width);
natural_rect.height = PANGO_PIXELS_CEIL (natural_rect.height);
gtk_misc_get_padding (GTK_MISC (label), &xpad, &ypad);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
/* Note, we cant use get_size_for_allocation() when rotating
@ -3509,8 +3515,8 @@ gtk_label_get_size (GtkSizeRequest *widget,
*natural_size = natural_rect.width;
}
*minimum_size += label->misc.xpad * 2;
*natural_size += label->misc.xpad * 2;
*minimum_size += xpad * 2;
*natural_size += xpad * 2;
}
else /* GTK_ORIENTATION_VERTICAL */
{
@ -3537,8 +3543,8 @@ gtk_label_get_size (GtkSizeRequest *widget,
*natural_size = natural_rect.height;
}
*minimum_size += label->misc.ypad * 2;
*natural_size += label->misc.ypad * 2;
*minimum_size += ypad * 2;
*natural_size += ypad * 2;
}
/* Restore real allocated size of layout; sometimes size-requests
@ -3581,18 +3587,22 @@ gtk_label_get_width_for_height (GtkSizeRequest *widget,
if (priv->wrap && (angle == 90 || angle == 270))
{
gint xpad, ypad;
gtk_misc_get_padding (GTK_MISC (label), &xpad, &ypad);
if (priv->wrap)
gtk_label_clear_layout (label);
get_size_for_allocation (label, GTK_ORIENTATION_VERTICAL,
MAX (1, height - (label->misc.ypad * 2)),
MAX (1, height - (ypad * 2)),
minimum_width, natural_width);
if (minimum_width)
*minimum_width += label->misc.xpad * 2;
*minimum_width += xpad * 2;
if (natural_width)
*natural_width += label->misc.xpad * 2;
*natural_width += xpad * 2;
}
else
GTK_SIZE_REQUEST_GET_IFACE (widget)->get_width (widget, minimum_width, natural_width);
@ -3610,18 +3620,22 @@ gtk_label_get_height_for_width (GtkSizeRequest *widget,
if (priv->wrap && (angle == 0 || angle == 180 || angle == 360))
{
gint xpad, ypad;
gtk_misc_get_padding (GTK_MISC (label), &xpad, &ypad);
if (priv->wrap)
gtk_label_clear_layout (label);
get_size_for_allocation (label, GTK_ORIENTATION_HORIZONTAL,
MAX (1, width - label->misc.xpad * 2),
MAX (1, width - xpad * 2),
minimum_height, natural_height);
if (minimum_height)
*minimum_height += label->misc.ypad * 2;
*minimum_height += ypad * 2;
if (natural_height)
*natural_height += label->misc.ypad * 2;
*natural_height += ypad * 2;
}
else
GTK_SIZE_REQUEST_GET_IFACE (widget)->get_height (widget, minimum_height, natural_height);
@ -3650,10 +3664,13 @@ gtk_label_size_allocate (GtkWidget *widget,
{
PangoRectangle logical;
PangoRectangle bounds;
gint xpad, ypad;
gtk_misc_get_padding (GTK_MISC (label), &xpad, &ypad);
bounds.x = bounds.y = 0;
bounds.width = allocation->width - label->misc.xpad * 2;
bounds.height = allocation->height - label->misc.ypad * 2;
bounds.width = allocation->width - xpad * 2;
bounds.height = allocation->height - ypad * 2;
pango_layout_set_width (priv->layout, -1);
pango_layout_get_pixel_extents (priv->layout, NULL, &logical);
@ -3814,9 +3831,10 @@ get_layout_location (GtkLabel *label,
GtkMisc *misc;
GtkWidget *widget;
GtkLabelPriv *priv;
gfloat xalign;
gint req_width, x, y;
gint req_height;
gint xpad, ypad;
gfloat xalign, yalign;
PangoRectangle logical;
gdouble angle;
@ -3825,10 +3843,11 @@ get_layout_location (GtkLabel *label,
priv = label->priv;
angle = gtk_label_get_angle (label);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
xalign = misc->xalign;
else
xalign = 1.0 - misc->xalign;
gtk_misc_get_alignment (misc, &xalign, &yalign);
gtk_misc_get_padding (misc, &xpad, &ypad);
if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
xalign = 1.0 - xalign;
pango_layout_get_extents (priv->layout, NULL, &logical);
@ -3856,16 +3875,16 @@ get_layout_location (GtkLabel *label,
req_width = logical.width;
req_height = logical.height;
req_width += 2 * misc->xpad;
req_height += 2 * misc->ypad;
req_width += 2 * xpad;
req_height += 2 * ypad;
x = floor (widget->allocation.x + (gint)misc->xpad +
xalign * (widget->allocation.width - req_width));
x = floor (widget->allocation.x + xpad +
xalign * (widget->allocation.width - req_width));
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
x = MAX (x, widget->allocation.x + misc->xpad);
x = MAX (x, widget->allocation.x + xpad);
else
x = MIN (x, widget->allocation.x + widget->allocation.width - misc->xpad);
x = MIN (x, widget->allocation.x + widget->allocation.width - xpad);
@ -3884,12 +3903,15 @@ get_layout_location (GtkLabel *label,
* middle". You want to read the first line, at least, to get some context.
*/
if (pango_layout_get_line_count (priv->layout) == 1)
y = floor (widget->allocation.y + (gint)misc->ypad
+ (widget->allocation.height - req_height) * misc->yalign);
{
y = floor (widget->allocation.y + ypad
+ (widget->allocation.height - req_height) * yalign);
}
else
y = floor (widget->allocation.y + (gint)misc->ypad
+ MAX (((widget->allocation.height - req_height) * misc->yalign),
0));
{
y = floor (widget->allocation.y + ypad
+ MAX ((widget->allocation.height - req_height) * yalign, 0));
}
if (xp)
*xp = x;

View File

@ -1659,6 +1659,7 @@ gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
GtkStatusIconPrivate *priv = status_icon->priv;
GtkOrientation orientation;
gint size;
gint xpad, ypad;
orientation = _gtk_tray_icon_get_orientation (GTK_TRAY_ICON (priv->tray_icon));
@ -1667,8 +1668,10 @@ gtk_status_icon_size_allocate (GtkStatusIcon *status_icon,
else
size = allocation->width;
priv->image_width = allocation->width - GTK_MISC (priv->image)->xpad * 2;
priv->image_height = allocation->height - GTK_MISC (priv->image)->ypad * 2;
gtk_misc_get_padding (GTK_MISC (priv->image), &xpad, &ypad);
priv->image_width = allocation->width - xpad * 2;
priv->image_height = allocation->height - ypad * 2;
if (priv->size != size)
{