summaryrefslogtreecommitdiff
path: root/gtk/gtkaccellabel.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2016-01-17 14:08:22 -0500
committerMatthias Clasen <mclasen@redhat.com>2016-01-17 14:08:22 -0500
commit9e2a1685c5d9c519212eee3c6bc4cde1025ee377 (patch)
tree287637bcc36449ef76a5ac87d95ea2111cdfb703 /gtk/gtkaccellabel.c
parentd28959c6dbea441c6c2f5dd2690123cf684eb96a (diff)
downloadgtk+-9e2a1685c5d9c519212eee3c6bc4cde1025ee377.tar.gz
accel label: Fix RTL handling
The 'mad hack' that GtkAccelLabel used to affect the GtkLabel draw function broke with the introduction of gadgets, since the positioning is no longer relative to the widgets' allocation at the time of the call, but rather to the gadgets allocation. Instead of coming up with an even madder hack to keep this working, give the GtkLabel draw function knowledge about accel labels. https://bugzilla.gnome.org/show_bug.cgi?id=760663
Diffstat (limited to 'gtk/gtkaccellabel.c')
-rw-r--r--gtk/gtkaccellabel.c52
1 files changed, 12 insertions, 40 deletions
diff --git a/gtk/gtkaccellabel.c b/gtk/gtkaccellabel.c
index 35938293e2..e9d88cb6e3 100644
--- a/gtk/gtkaccellabel.c
+++ b/gtk/gtkaccellabel.c
@@ -50,13 +50,13 @@
* accelerator key on the right of the label text, e.g. “Ctl+S”.
* It is commonly used in menus to show the keyboard short-cuts for commands.
*
- * The accelerator key to display is not set explicitly.
- * Instead, the #GtkAccelLabel displays the accelerators which have been added to
- * a particular widget. This widget is set by calling
- * gtk_accel_label_set_accel_widget().
+ * The accelerator key to display is typically not set explicitly (although it
+ * can be, with gtk_accel_label_set_accel()). Instead, the #GtkAccelLabel displays
+ * the accelerators which have been added to a particular widget. This widget is
+ * set by calling gtk_accel_label_set_accel_widget().
*
- * For example, a #GtkMenuItem widget may have an accelerator added to emit the
- * “activate” signal when the “Ctl+S” key combination is pressed.
+ * For example, a #GtkMenuItem widget may have an accelerator added to emit
+ * the “activate” signal when the “Ctl+S” key combination is pressed.
* A #GtkAccelLabel is created and added to the #GtkMenuItem, and
* gtk_accel_label_set_accel_widget() is called with the #GtkMenuItem as the
* second argument. The #GtkAccelLabel will now display “Ctl+S” after its label.
@@ -449,12 +449,12 @@ gtk_accel_label_draw (GtkWidget *widget,
cairo_t *cr)
{
GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
- GtkTextDirection direction;
guint ac_width;
GtkAllocation allocation;
GtkRequisition requisition;
- direction = gtk_widget_get_direction (widget);
+ GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw (widget, cr);
+
ac_width = gtk_accel_label_get_accel_width (accel_label);
gtk_widget_get_allocation (widget, &allocation);
gtk_widget_get_preferred_size (widget, NULL, &requisition);
@@ -465,45 +465,21 @@ gtk_accel_label_draw (GtkWidget *widget,
PangoLayout *label_layout;
PangoLayout *accel_layout;
GtkLabel *label = GTK_LABEL (widget);
-
gint x;
gint y;
context = gtk_widget_get_style_context (widget);
- label_layout = gtk_label_get_layout (GTK_LABEL (accel_label));
- cairo_save (cr);
+ label_layout = gtk_label_get_layout (GTK_LABEL (accel_label));
+ accel_layout = gtk_accel_label_get_accel_layout (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);
- 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)
+ if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
x = 0;
else
x = gtk_widget_get_allocated_width (widget) - ac_width;
gtk_label_get_layout_offsets (GTK_LABEL (accel_label), NULL, &y);
- accel_layout = gtk_accel_label_get_accel_layout (accel_label);
y += get_first_baseline (label_layout) - get_first_baseline (accel_layout) - allocation.y;
gtk_style_context_save_to_node (context, accel_label->priv->accel_node);
@@ -512,11 +488,7 @@ gtk_accel_label_draw (GtkWidget *widget,
g_object_unref (accel_layout);
}
- else
- {
- GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw (widget, cr);
- }
-
+
return FALSE;
}