mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-25 13:11:13 +00:00
accellabel: Remove gtk_widget_is_drawable() check from draw vfunc
This commit is contained in:
parent
41e6da4075
commit
c34c05217c
@ -383,85 +383,80 @@ gtk_accel_label_draw (GtkWidget *widget,
|
|||||||
GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
|
GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
|
||||||
GtkMisc *misc = GTK_MISC (accel_label);
|
GtkMisc *misc = GTK_MISC (accel_label);
|
||||||
GtkTextDirection direction;
|
GtkTextDirection direction;
|
||||||
|
guint ac_width;
|
||||||
|
GtkAllocation allocation;
|
||||||
|
GtkRequisition requisition;
|
||||||
|
|
||||||
direction = gtk_widget_get_direction (widget);
|
direction = gtk_widget_get_direction (widget);
|
||||||
|
ac_width = gtk_accel_label_get_accel_width (accel_label);
|
||||||
|
gtk_widget_get_allocation (widget, &allocation);
|
||||||
|
gtk_widget_get_preferred_size (widget, &requisition, NULL);
|
||||||
|
|
||||||
if (gtk_widget_is_drawable (widget))
|
if (allocation.width >= requisition.width + ac_width)
|
||||||
{
|
{
|
||||||
guint ac_width;
|
PangoLayout *label_layout;
|
||||||
GtkAllocation allocation;
|
PangoLayout *accel_layout;
|
||||||
GtkRequisition requisition;
|
GtkLabel *label = GTK_LABEL (widget);
|
||||||
|
|
||||||
ac_width = gtk_accel_label_get_accel_width (accel_label);
|
gint x;
|
||||||
gtk_widget_get_allocation (widget, &allocation);
|
gint y;
|
||||||
gtk_widget_get_preferred_size (widget, &requisition, NULL);
|
gint xpad;
|
||||||
|
|
||||||
if (allocation.width >= requisition.width + ac_width)
|
label_layout = gtk_label_get_layout (GTK_LABEL (accel_label));
|
||||||
{
|
|
||||||
PangoLayout *label_layout;
|
|
||||||
PangoLayout *accel_layout;
|
|
||||||
GtkLabel *label = GTK_LABEL (widget);
|
|
||||||
|
|
||||||
gint x;
|
cairo_save (cr);
|
||||||
gint y;
|
|
||||||
gint xpad;
|
|
||||||
|
|
||||||
label_layout = gtk_label_get_layout (GTK_LABEL (accel_label));
|
/* XXX: Mad hack: We modify the label's width so it renders
|
||||||
|
* properly in its draw function that we chain to. */
|
||||||
|
if (direction == GTK_TEXT_DIR_RTL)
|
||||||
|
cairo_translate (cr, ac_width, 0);
|
||||||
|
if (gtk_label_get_ellipsize (label))
|
||||||
|
pango_layout_set_width (label_layout,
|
||||||
|
pango_layout_get_width (label_layout)
|
||||||
|
- ac_width * PANGO_SCALE);
|
||||||
|
|
||||||
|
allocation.width -= ac_width;
|
||||||
|
gtk_widget_set_allocation (widget, &allocation);
|
||||||
|
if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw)
|
||||||
|
GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw (widget,
|
||||||
|
cr);
|
||||||
|
allocation.width += ac_width;
|
||||||
|
gtk_widget_set_allocation (widget, &allocation);
|
||||||
|
if (gtk_label_get_ellipsize (label))
|
||||||
|
pango_layout_set_width (label_layout,
|
||||||
|
pango_layout_get_width (label_layout)
|
||||||
|
+ ac_width * PANGO_SCALE);
|
||||||
|
|
||||||
cairo_save (cr);
|
cairo_restore (cr);
|
||||||
|
|
||||||
/* XXX: Mad hack: We modify the label's width so it renders
|
gtk_misc_get_padding (misc, &xpad, NULL);
|
||||||
* properly in its draw function that we chain to. */
|
|
||||||
if (direction == GTK_TEXT_DIR_RTL)
|
|
||||||
cairo_translate (cr, ac_width, 0);
|
|
||||||
if (gtk_label_get_ellipsize (label))
|
|
||||||
pango_layout_set_width (label_layout,
|
|
||||||
pango_layout_get_width (label_layout)
|
|
||||||
- ac_width * PANGO_SCALE);
|
|
||||||
|
|
||||||
allocation.width -= ac_width;
|
|
||||||
gtk_widget_set_allocation (widget, &allocation);
|
|
||||||
if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw)
|
|
||||||
GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw (widget,
|
|
||||||
cr);
|
|
||||||
allocation.width += ac_width;
|
|
||||||
gtk_widget_set_allocation (widget, &allocation);
|
|
||||||
if (gtk_label_get_ellipsize (label))
|
|
||||||
pango_layout_set_width (label_layout,
|
|
||||||
pango_layout_get_width (label_layout)
|
|
||||||
+ ac_width * PANGO_SCALE);
|
|
||||||
|
|
||||||
cairo_restore (cr);
|
if (direction == GTK_TEXT_DIR_RTL)
|
||||||
|
x = xpad;
|
||||||
gtk_misc_get_padding (misc, &xpad, NULL);
|
|
||||||
|
|
||||||
if (direction == GTK_TEXT_DIR_RTL)
|
|
||||||
x = xpad;
|
|
||||||
else
|
|
||||||
x = gtk_widget_get_allocated_width (widget) - xpad - ac_width;
|
|
||||||
|
|
||||||
gtk_label_get_layout_offsets (GTK_LABEL (accel_label), NULL, &y);
|
|
||||||
|
|
||||||
accel_layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
|
|
||||||
|
|
||||||
y += get_first_baseline (label_layout) - get_first_baseline (accel_layout) - allocation.y;
|
|
||||||
|
|
||||||
gtk_paint_layout (gtk_widget_get_style (widget),
|
|
||||||
cr,
|
|
||||||
gtk_widget_get_state (widget),
|
|
||||||
FALSE,
|
|
||||||
widget,
|
|
||||||
"accellabel",
|
|
||||||
x, y,
|
|
||||||
accel_layout);
|
|
||||||
|
|
||||||
g_object_unref (accel_layout);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
x = gtk_widget_get_allocated_width (widget) - xpad - ac_width;
|
||||||
if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw)
|
|
||||||
GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw (widget, cr);
|
gtk_label_get_layout_offsets (GTK_LABEL (accel_label), NULL, &y);
|
||||||
}
|
|
||||||
|
accel_layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
|
||||||
|
|
||||||
|
y += get_first_baseline (label_layout) - get_first_baseline (accel_layout) - allocation.y;
|
||||||
|
|
||||||
|
gtk_paint_layout (gtk_widget_get_style (widget),
|
||||||
|
cr,
|
||||||
|
gtk_widget_get_state (widget),
|
||||||
|
FALSE,
|
||||||
|
widget,
|
||||||
|
"accellabel",
|
||||||
|
x, y,
|
||||||
|
accel_layout);
|
||||||
|
|
||||||
|
g_object_unref (accel_layout);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw)
|
||||||
|
GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw (widget, cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
Loading…
Reference in New Issue
Block a user