* Copyright (C) 1998 Tim Janik
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Library General Public
+ * 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.
*/
+
+/*
+ * Modified by the GTK+ Team and others 1997-2001. See the AUTHORS
+ * file for a list of people on the GTK+ Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#include "config.h"
#include <string.h>
-#include <ctype.h>
-#include "gtkmain.h"
-#include "gtksignal.h"
-#include "gtkaccellabel.h"
+#include "gtkaccellabel.h"
+#include "gtkaccelmap.h"
+#include "gtkmain.h"
+#include "gtkprivate.h"
+#include "gtkintl.h"
+#include "gtkalias.h"
+#include <gdk/gdkkeysyms.h>
enum {
- ARG_0,
- ARG_ACCEL_WIDGET,
+ PROP_0,
+ PROP_ACCEL_CLOSURE,
+ PROP_ACCEL_WIDGET
};
-static void gtk_accel_label_class_init (GtkAccelLabelClass *klass);
-static void gtk_accel_label_init (GtkAccelLabel *accel_label);
-static void gtk_accel_label_set_arg (GtkObject *object,
- GtkArg *arg,
- guint arg_id);
-static void gtk_accel_label_get_arg (GtkObject *object,
- GtkArg *arg,
- guint arg_id);
-static void gtk_accel_label_destroy (GtkObject *object);
-static void gtk_accel_label_finalize (GtkObject *object);
-static void gtk_accel_label_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
-static gint gtk_accel_label_expose_event (GtkWidget *widget,
- GdkEventExpose *event);
-
-static GtkAccelLabelClass *accel_label_class = NULL;
-static GtkLabelClass *parent_class = NULL;
-
-
-GtkType
-gtk_accel_label_get_type (void)
-{
- static GtkType accel_label_type = 0;
-
- if (!accel_label_type)
- {
- GtkTypeInfo accel_label_info =
- {
- "GtkAccelLabel",
- sizeof (GtkAccelLabel),
- sizeof (GtkAccelLabelClass),
- (GtkClassInitFunc) gtk_accel_label_class_init,
- (GtkObjectInitFunc) gtk_accel_label_init,
- /* reserved_1 */ NULL,
- /* reserved_2 */ NULL,
- (GtkClassInitFunc) NULL,
- };
-
- accel_label_type = gtk_type_unique (gtk_label_get_type (), &accel_label_info);
- }
-
- return accel_label_type;
-}
+static void gtk_accel_label_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gtk_accel_label_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void gtk_accel_label_destroy (GtkObject *object);
+static void gtk_accel_label_finalize (GObject *object);
+static void gtk_accel_label_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static gboolean gtk_accel_label_expose_event (GtkWidget *widget,
+ GdkEventExpose *event);
+static const gchar *gtk_accel_label_get_string (GtkAccelLabel *accel_label);
+
+
+G_DEFINE_TYPE (GtkAccelLabel, gtk_accel_label, GTK_TYPE_LABEL)
static void
gtk_accel_label_class_init (GtkAccelLabelClass *class)
{
- GtkObjectClass *object_class;
- GtkWidgetClass *widget_class;
- GtkMiscClass *misc_class;
- GtkLabelClass *label_class;
-
- accel_label_class = class;
- object_class = (GtkObjectClass*) class;
- widget_class = (GtkWidgetClass*) class;
- misc_class = (GtkMiscClass*) class;
- label_class = (GtkLabelClass*) class;
+ GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+ GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
- parent_class = gtk_type_class (gtk_label_get_type ());
+ gobject_class->finalize = gtk_accel_label_finalize;
+ gobject_class->set_property = gtk_accel_label_set_property;
+ gobject_class->get_property = gtk_accel_label_get_property;
- gtk_object_add_arg_type ("GtkAccelLabel::accel_widget", GTK_TYPE_WIDGET, GTK_ARG_READWRITE, ARG_ACCEL_WIDGET);
-
- object_class->set_arg = gtk_accel_label_set_arg;
- object_class->get_arg = gtk_accel_label_get_arg;
object_class->destroy = gtk_accel_label_destroy;
- object_class->finalize = gtk_accel_label_finalize;
-
+
widget_class->size_request = gtk_accel_label_size_request;
widget_class->expose_event = gtk_accel_label_expose_event;
class->signal_quote1 = g_strdup ("<:");
class->signal_quote2 = g_strdup (":>");
- class->mod_name_shift = g_strdup ("Shft");
- class->mod_name_control = g_strdup ("Ctl");
- class->mod_name_alt = g_strdup ("Alt");
+
+#ifndef GDK_WINDOWING_QUARTZ
+ /* This is the text that should appear next to menu accelerators
+ * that use the shift key. If the text on this key isn't typically
+ * translated on keyboards used for your language, don't translate
+ * this.
+ *
+ * Don't include the prefix "keyboard label|" in the translation.
+ */
+ class->mod_name_shift = g_strdup (Q_("keyboard label|Shift"));
+ /* This is the text that should appear next to menu accelerators
+ * that use the control key. If the text on this key isn't typically
+ * translated on keyboards used for your language, don't translate
+ * this.
+ *
+ * Don't include the prefix "keyboard label|" in the translation.
+ */
+ class->mod_name_control = g_strdup (Q_("keyboard label|Ctrl"));
+ /* This is the text that should appear next to menu accelerators
+ * that use the alt key. If the text on this key isn't typically
+ * translated on keyboards used for your language, don't translate
+ * this.
+ *
+ * Don't include the prefix "keyboard label|" in the translation.
+ */
+ class->mod_name_alt = g_strdup (Q_("keyboard label|Alt"));
class->mod_separator = g_strdup ("+");
+#else /* GDK_WINDOWING_QUARTZ */
+
+ /* U+21E7 UPWARDS WHITE ARROW */
+ class->mod_name_shift = g_strdup ("\xe2\x87\xa7");
+ /* U+2303 UP ARROWHEAD */
+ class->mod_name_control = g_strdup ("\xe2\x8c\x83");
+ /* U+2325 OPTION KEY */
+ class->mod_name_alt = g_strdup ("\xe2\x8c\xa5");
+ class->mod_separator = g_strdup ("");
+
+#endif /* GDK_WINDOWING_QUARTZ */
+
class->accel_seperator = g_strdup (" / ");
class->latin1_to_char = TRUE;
+
+ g_object_class_install_property (gobject_class,
+ PROP_ACCEL_CLOSURE,
+ g_param_spec_boxed ("accel-closure",
+ P_("Accelerator Closure"),
+ P_("The closure to be monitored for accelerator changes"),
+ G_TYPE_CLOSURE,
+ GTK_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class,
+ PROP_ACCEL_WIDGET,
+ g_param_spec_object ("accel-widget",
+ P_("Accelerator Widget"),
+ P_("The widget to be monitored for accelerator changes"),
+ GTK_TYPE_WIDGET,
+ GTK_PARAM_READWRITE));
}
static void
-gtk_accel_label_set_arg (GtkObject *object,
- GtkArg *arg,
- guint arg_id)
+gtk_accel_label_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GtkAccelLabel *accel_label;
accel_label = GTK_ACCEL_LABEL (object);
- switch (arg_id)
+ switch (prop_id)
{
- case ARG_ACCEL_WIDGET:
- gtk_accel_label_set_accel_widget (accel_label, (GtkWidget*) GTK_VALUE_OBJECT (*arg));
+ case PROP_ACCEL_CLOSURE:
+ gtk_accel_label_set_accel_closure (accel_label, g_value_get_boxed (value));
+ break;
+ case PROP_ACCEL_WIDGET:
+ gtk_accel_label_set_accel_widget (accel_label, g_value_get_object (value));
break;
default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
-gtk_accel_label_get_arg (GtkObject *object,
- GtkArg *arg,
- guint arg_id)
+gtk_accel_label_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GtkAccelLabel *accel_label;
accel_label = GTK_ACCEL_LABEL (object);
- switch (arg_id)
+ switch (prop_id)
{
- case ARG_ACCEL_WIDGET:
- GTK_VALUE_OBJECT (*arg) = (GtkObject*) accel_label->accel_widget;
+ case PROP_ACCEL_CLOSURE:
+ g_value_set_boxed (value, accel_label->accel_closure);
+ break;
+ case PROP_ACCEL_WIDGET:
+ g_value_set_object (value, accel_label->accel_widget);
break;
default:
- arg->type = GTK_TYPE_INVALID;
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_accel_label_init (GtkAccelLabel *accel_label)
{
- accel_label->queue_id = 0;
accel_label->accel_padding = 3;
accel_label->accel_widget = NULL;
+ accel_label->accel_closure = NULL;
+ accel_label->accel_group = NULL;
accel_label->accel_string = NULL;
-
- gtk_accel_label_refetch (accel_label);
}
GtkWidget*
g_return_val_if_fail (string != NULL, NULL);
- accel_label = gtk_type_new (GTK_TYPE_ACCEL_LABEL);
+ accel_label = g_object_new (GTK_TYPE_ACCEL_LABEL, NULL);
- gtk_label_set (GTK_LABEL (accel_label), string);
+ gtk_label_set_text (GTK_LABEL (accel_label), string);
return GTK_WIDGET (accel_label);
}
static void
gtk_accel_label_destroy (GtkObject *object)
{
- GtkAccelLabel *accel_label;
-
- g_return_if_fail (object != NULL);
- g_return_if_fail (GTK_IS_ACCEL_LABEL (object));
-
- accel_label = GTK_ACCEL_LABEL (object);
+ GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
gtk_accel_label_set_accel_widget (accel_label, NULL);
+ gtk_accel_label_set_accel_closure (accel_label, NULL);
- GTK_OBJECT_CLASS (parent_class)->destroy (object);
+ GTK_OBJECT_CLASS (gtk_accel_label_parent_class)->destroy (object);
}
static void
-gtk_accel_label_finalize (GtkObject *object)
+gtk_accel_label_finalize (GObject *object)
{
- GtkAccelLabel *accel_label;
-
- g_return_if_fail (object != NULL);
- g_return_if_fail (GTK_IS_ACCEL_LABEL (object));
-
- accel_label = GTK_ACCEL_LABEL (object);
-
+ GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
+
g_free (accel_label->accel_string);
- GTK_OBJECT_CLASS (parent_class)->finalize (object);
+ G_OBJECT_CLASS (gtk_accel_label_parent_class)->finalize (object);
+}
+
+/**
+ * gtk_accel_label_get_accel_widget:
+ * @accel_label: a #GtkAccelLabel
+ *
+ * Fetches the widget monitored by this accelerator label. See
+ * gtk_accel_label_set_accel_widget().
+ *
+ * Return value: the object monitored by the accelerator label,
+ * or %NULL.
+ **/
+GtkWidget*
+gtk_accel_label_get_accel_widget (GtkAccelLabel *accel_label)
+{
+ g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), NULL);
+
+ return accel_label->accel_widget;
}
guint
-gtk_accel_label_accelerator_width (GtkAccelLabel *accel_label)
+gtk_accel_label_get_accel_width (GtkAccelLabel *accel_label)
{
- g_return_val_if_fail (accel_label != NULL, 0);
g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), 0);
- return accel_label->accel_padding + accel_label->accel_string_width;
+ return (accel_label->accel_string_width +
+ (accel_label->accel_string_width ? accel_label->accel_padding : 0));
}
static void
gtk_accel_label_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
- GtkAccelLabel *accel_label;
+ GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
+ PangoLayout *layout;
+ gint width;
- g_return_if_fail (widget != NULL);
- g_return_if_fail (GTK_IS_ACCEL_LABEL (widget));
- g_return_if_fail (requisition != NULL);
-
- accel_label = GTK_ACCEL_LABEL (widget);
-
- if (GTK_WIDGET_CLASS (parent_class)->size_request)
- GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
+ if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->size_request)
+ GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->size_request (widget, requisition);
+
+ layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
+ pango_layout_get_pixel_size (layout, &width, NULL);
+ accel_label->accel_string_width = width;
- accel_label->accel_string_width = gdk_string_width (GTK_WIDGET (accel_label)->style->font,
- accel_label->accel_string);
+ g_object_unref (layout);
}
static gint
+get_first_baseline (PangoLayout *layout)
+{
+ PangoLayoutIter *iter;
+ gint result;
+
+ iter = pango_layout_get_iter (layout);
+ result = pango_layout_iter_get_baseline (iter);
+ pango_layout_iter_free (iter);
+
+ return PANGO_PIXELS (result);
+}
+
+static gboolean
gtk_accel_label_expose_event (GtkWidget *widget,
GdkEventExpose *event)
{
- GtkMisc *misc;
- GtkAccelLabel *accel_label;
-
- g_return_val_if_fail (widget != NULL, FALSE);
- g_return_val_if_fail (GTK_IS_ACCEL_LABEL (widget), FALSE);
- g_return_val_if_fail (event != NULL, FALSE);
-
- accel_label = GTK_ACCEL_LABEL (widget);
- misc = GTK_MISC (accel_label);
-
+ GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
+ GtkMisc *misc = GTK_MISC (accel_label);
+ GtkTextDirection direction;
+
+ direction = gtk_widget_get_direction (widget);
+
if (GTK_WIDGET_DRAWABLE (accel_label))
{
guint ac_width;
- ac_width = gtk_accel_label_accelerator_width (accel_label);
+ ac_width = gtk_accel_label_get_accel_width (accel_label);
if (widget->allocation.width >= widget->requisition.width + ac_width)
{
- guint x;
- guint y;
+ PangoLayout *label_layout;
+ PangoLayout *accel_layout;
+ GtkLabel *label = GTK_LABEL (widget);
+
+ gint x;
+ gint y;
+ label_layout = gtk_label_get_layout (GTK_LABEL (accel_label));
+
+ if (direction == GTK_TEXT_DIR_RTL)
+ widget->allocation.x += ac_width;
widget->allocation.width -= ac_width;
- if (GTK_WIDGET_CLASS (parent_class)->expose_event)
- GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
- widget->allocation.width += ac_width;
-
- x = widget->allocation.x + widget->allocation.width - misc->xpad - ac_width;
+ if (gtk_label_get_ellipsize (label))
+ pango_layout_set_width (label_layout,
+ pango_layout_get_width (label_layout)
+ - ac_width * PANGO_SCALE);
- y = (widget->allocation.y * (1.0 - misc->yalign) +
- (widget->allocation.y + widget->allocation.height -
- (widget->requisition.height - misc->ypad * 2)) *
- misc->yalign + widget->style->font->ascent) + 1.5;
-
- if (GTK_WIDGET_STATE (accel_label) == GTK_STATE_INSENSITIVE)
- gdk_draw_string (widget->window,
- widget->style->font,
- widget->style->white_gc,
- x + 1,
- y + 1,
- accel_label->accel_string);
+ if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
+ GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
+ if (direction == GTK_TEXT_DIR_RTL)
+ widget->allocation.x -= ac_width;
+ widget->allocation.width += ac_width;
+ if (gtk_label_get_ellipsize (label))
+ pango_layout_set_width (label_layout,
+ pango_layout_get_width (label_layout)
+ + ac_width * PANGO_SCALE);
- gdk_draw_string (widget->window,
- widget->style->font,
- widget->style->fg_gc[GTK_WIDGET_STATE (accel_label)],
- x,
- y,
- accel_label->accel_string);
+ if (direction == GTK_TEXT_DIR_RTL)
+ x = widget->allocation.x + misc->xpad;
+ else
+ x = widget->allocation.x + widget->allocation.width - misc->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);
+
+ gtk_paint_layout (widget->style,
+ widget->window,
+ GTK_WIDGET_STATE (widget),
+ FALSE,
+ &event->area,
+ widget,
+ "accellabel",
+ x, y,
+ accel_layout);
+
+ g_object_unref (accel_layout);
}
else
{
- if (GTK_WIDGET_CLASS (parent_class)->expose_event)
- GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
+ if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
+ GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
}
}
- return TRUE;
+ return FALSE;
}
static void
-gtk_accel_label_queue_refetch (GtkAccelLabel *accel_label)
+refetch_widget_accel_closure (GtkAccelLabel *accel_label)
{
- g_return_if_fail (accel_label != NULL);
+ GClosure *closure = NULL;
+ GList *clist, *list;
+
g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
-
- if (accel_label->queue_id == 0)
- accel_label->queue_id = gtk_idle_add_priority (GTK_PRIORITY_HIGH - 2,
- (GtkFunction) gtk_accel_label_refetch,
- accel_label);
+ g_return_if_fail (GTK_IS_WIDGET (accel_label->accel_widget));
+
+ clist = gtk_widget_list_accel_closures (accel_label->accel_widget);
+ for (list = clist; list; list = list->next)
+ {
+ /* we just take the first closure used */
+ closure = list->data;
+ break;
+ }
+ g_list_free (clist);
+ gtk_accel_label_set_accel_closure (accel_label, closure);
}
+/**
+ * gtk_accel_label_set_accel_widget:
+ * @accel_label: a #GtkAccelLabel
+ * @accel_widget: the widget to be monitored.
+ *
+ * Sets the widget to be monitored by this accelerator label.
+ **/
void
gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
- GtkWidget *accel_widget)
+ GtkWidget *accel_widget)
{
- g_return_if_fail (accel_label != NULL);
g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
- if (accel_widget != NULL)
+ if (accel_widget)
g_return_if_fail (GTK_IS_WIDGET (accel_widget));
-
+
if (accel_widget != accel_label->accel_widget)
{
if (accel_label->accel_widget)
{
- gtk_signal_disconnect_by_func (GTK_OBJECT (accel_label->accel_widget),
- GTK_SIGNAL_FUNC (gtk_accel_label_queue_refetch),
- accel_label);
- gtk_widget_unref (accel_label->accel_widget);
- }
- if (accel_label->queue_id)
- {
- gtk_idle_remove (accel_label->queue_id);
- accel_label->queue_id = 0;
+ gtk_accel_label_set_accel_closure (accel_label, NULL);
+ g_signal_handlers_disconnect_by_func (accel_label->accel_widget,
+ refetch_widget_accel_closure,
+ accel_label);
+ g_object_unref (accel_label->accel_widget);
}
accel_label->accel_widget = accel_widget;
if (accel_label->accel_widget)
{
- gtk_widget_ref (accel_label->accel_widget);
- gtk_signal_connect_object_after (GTK_OBJECT (accel_label->accel_widget),
- "add-accelerator",
- GTK_SIGNAL_FUNC (gtk_accel_label_queue_refetch),
- GTK_OBJECT (accel_label));
- gtk_signal_connect_object_after (GTK_OBJECT (accel_label->accel_widget),
- "remove-accelerator",
- GTK_SIGNAL_FUNC (gtk_accel_label_queue_refetch),
- GTK_OBJECT (accel_label));
+ g_object_ref (accel_label->accel_widget);
+ g_signal_connect_object (accel_label->accel_widget, "accel_closures_changed",
+ G_CALLBACK (refetch_widget_accel_closure),
+ accel_label, G_CONNECT_SWAPPED);
+ refetch_widget_accel_closure (accel_label);
}
+ g_object_notify (G_OBJECT (accel_label), "accel-widget");
}
}
-gboolean
-gtk_accel_label_refetch (GtkAccelLabel *accel_label)
+static void
+gtk_accel_label_reset (GtkAccelLabel *accel_label)
+{
+ if (accel_label->accel_string)
+ {
+ g_free (accel_label->accel_string);
+ accel_label->accel_string = NULL;
+ }
+
+ gtk_widget_queue_resize (GTK_WIDGET (accel_label));
+}
+
+static void
+check_accel_changed (GtkAccelGroup *accel_group,
+ guint keyval,
+ GdkModifierType modifier,
+ GClosure *accel_closure,
+ GtkAccelLabel *accel_label)
{
- GtkAccelLabelClass *class;
+ if (accel_closure == accel_label->accel_closure)
+ gtk_accel_label_reset (accel_label);
+}
- g_return_val_if_fail (accel_label != NULL, FALSE);
- g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
+/**
+ * gtk_accel_label_set_accel_closure:
+ * @accel_label: a #GtkAccelLabel
+ * @accel_closure: the closure to monitor for accelerator changes.
+ *
+ * Sets the closure to be monitored by this accelerator label. The closure
+ * must be connected to an accelerator group; see gtk_accel_group_connect().
+ **/
+void
+gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,
+ GClosure *accel_closure)
+{
+ g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
+ if (accel_closure)
+ g_return_if_fail (gtk_accel_group_from_accel_closure (accel_closure) != NULL);
- class = GTK_ACCEL_LABEL_CLASS (GTK_OBJECT (accel_label)->klass);
+ if (accel_closure != accel_label->accel_closure)
+ {
+ if (accel_label->accel_closure)
+ {
+ g_signal_handlers_disconnect_by_func (accel_label->accel_group,
+ check_accel_changed,
+ accel_label);
+ accel_label->accel_group = NULL;
+ g_closure_unref (accel_label->accel_closure);
+ }
+ accel_label->accel_closure = accel_closure;
+ if (accel_label->accel_closure)
+ {
+ g_closure_ref (accel_label->accel_closure);
+ accel_label->accel_group = gtk_accel_group_from_accel_closure (accel_closure);
+ g_signal_connect_object (accel_label->accel_group, "accel_changed",
+ G_CALLBACK (check_accel_changed),
+ accel_label, 0);
+ }
+ gtk_accel_label_reset (accel_label);
+ g_object_notify (G_OBJECT (accel_label), "accel-closure");
+ }
+}
+
+static gboolean
+find_accel (GtkAccelKey *key,
+ GClosure *closure,
+ gpointer data)
+{
+ return data == (gpointer) closure;
+}
+
+static const gchar *
+gtk_accel_label_get_string (GtkAccelLabel *accel_label)
+{
+ if (!accel_label->accel_string)
+ gtk_accel_label_refetch (accel_label);
- g_free (accel_label->accel_string);
- accel_label->accel_string = NULL;
+ return accel_label->accel_string;
+}
+
+/* Underscores in key names are better displayed as spaces
+ * E.g., Page_Up should be "Page Up"
+ */
+static void
+substitute_underscores (char *str)
+{
+ char *p;
+
+ for (p = str; *p; p++)
+ if (*p == '_')
+ *p = ' ';
+}
+
+/* On Mac, if the key has symbolic representation (e.g. arrow keys),
+ * append it to gstring and return TRUE; otherwise return FALSE.
+ * See http://docs.info.apple.com/article.html?path=Mac/10.5/en/cdb_symbs.html
+ * for the list of special keys. */
+static gboolean
+append_keyval_symbol (guint accelerator_key,
+ GString *gstring)
+{
+#ifdef GDK_WINDOWING_QUARTZ
+ switch (accelerator_key)
+ {
+ case GDK_Return:
+ /* U+21A9 LEFTWARDS ARROW WITH HOOK */
+ g_string_append (gstring, "\xe2\x86\xa9");
+ return TRUE;
+
+ case GDK_ISO_Enter:
+ /* U+2324 UP ARROWHEAD BETWEEN TWO HORIZONTAL BARS */
+ g_string_append (gstring, "\xe2\x8c\xa4");
+ return TRUE;
+
+ case GDK_Left:
+ /* U+2190 LEFTWARDS ARROW */
+ g_string_append (gstring, "\xe2\x86\x90");
+ return TRUE;
+
+ case GDK_Up:
+ /* U+2191 UPWARDS ARROW */
+ g_string_append (gstring, "\xe2\x86\x91");
+ return TRUE;
+
+ case GDK_Right:
+ /* U+2192 RIGHTWARDS ARROW */
+ g_string_append (gstring, "\xe2\x86\x92");
+ return TRUE;
+
+ case GDK_Down:
+ /* U+2193 DOWNWARDS ARROW */
+ g_string_append (gstring, "\xe2\x86\x93");
+ return TRUE;
+
+ case GDK_Page_Up:
+ /* U+21DE UPWARDS ARROW WITH DOUBLE STROKE */
+ g_string_append (gstring, "\xe2\x87\x9e");
+ return TRUE;
+
+ case GDK_Page_Down:
+ /* U+21DF DOWNWARDS ARROW WITH DOUBLE STROKE */
+ g_string_append (gstring, "\xe2\x87\x9f");
+ return TRUE;
+
+ case GDK_Home:
+ /* U+2196 NORTH WEST ARROW */
+ g_string_append (gstring, "\xe2\x86\x96");
+ return TRUE;
+
+ case GDK_End:
+ /* U+2198 SOUTH EAST ARROW */
+ g_string_append (gstring, "\xe2\x86\x98");
+ return TRUE;
+
+ case GDK_Escape:
+ /* U+238B BROKEN CIRCLE WITH NORTHWEST ARROW */
+ g_string_append (gstring, "\xe2\x8e\x8b");
+ return TRUE;
+
+ case GDK_BackSpace:
+ /* U+232B ERASE TO THE LEFT */
+ g_string_append (gstring, "\xe2\x8c\xab");
+ return TRUE;
+
+ case GDK_Delete:
+ /* U+2326 ERASE TO THE RIGHT */
+ g_string_append (gstring, "\xe2\x8c\xa6");
+ return TRUE;
+
+ default:
+ return FALSE;
+ }
+#else /* !GDK_WINDOWING_QUARTZ */
+ return FALSE;
+#endif
+}
+
+gchar *
+_gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
+ guint accelerator_key,
+ GdkModifierType accelerator_mods)
+{
+ GString *gstring;
+ gboolean seen_mod = FALSE;
+ gunichar ch;
- if (accel_label->accel_widget)
+ gstring = g_string_new ("");
+
+ if (accelerator_mods & GDK_SHIFT_MASK)
{
- GtkAccelEntry *entry = NULL;
- GSList *slist;
-
- slist = gtk_accel_group_entries_from_object (GTK_OBJECT (accel_label->accel_widget));
- for (; slist; slist = slist->next)
+ g_string_append (gstring, klass->mod_name_shift);
+ seen_mod = TRUE;
+ }
+ if (accelerator_mods & GDK_CONTROL_MASK)
+ {
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+ g_string_append (gstring, klass->mod_name_control);
+ seen_mod = TRUE;
+ }
+ if (accelerator_mods & GDK_MOD1_MASK)
+ {
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+ g_string_append (gstring, klass->mod_name_alt);
+ seen_mod = TRUE;
+ }
+ if (accelerator_mods & GDK_MOD2_MASK)
+ {
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+
+ g_string_append (gstring, "Mod2");
+ seen_mod = TRUE;
+ }
+ if (accelerator_mods & GDK_MOD3_MASK)
+ {
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+
+ g_string_append (gstring, "Mod3");
+ seen_mod = TRUE;
+ }
+ if (accelerator_mods & GDK_MOD4_MASK)
+ {
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+
+ g_string_append (gstring, "Mod4");
+ seen_mod = TRUE;
+ }
+ if (accelerator_mods & GDK_MOD5_MASK)
+ {
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+
+ g_string_append (gstring, "Mod5");
+ seen_mod = TRUE;
+ }
+ if (accelerator_mods & GDK_SUPER_MASK)
+ {
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+
+ /* This is the text that should appear next to menu accelerators
+ * that use the super key. If the text on this key isn't typically
+ * translated on keyboards used for your language, don't translate
+ * this.
+ * And do not translate the part before the |.
+ */
+ g_string_append (gstring, Q_("keyboard label|Super"));
+ seen_mod = TRUE;
+ }
+ if (accelerator_mods & GDK_HYPER_MASK)
+ {
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+
+ /* This is the text that should appear next to menu accelerators
+ * that use the hyper key. If the text on this key isn't typically
+ * translated on keyboards used for your language, don't translate
+ * this.
+ * And do not translate the part before the |.
+ */
+ g_string_append (gstring, Q_("keyboard label|Hyper"));
+ seen_mod = TRUE;
+ }
+ if (accelerator_mods & GDK_META_MASK)
+ {
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+
+#ifndef GDK_WINDOWING_QUARTZ
+ /* This is the text that should appear next to menu accelerators
+ * that use the meta key. If the text on this key isn't typically
+ * translated on keyboards used for your language, don't translate
+ * this.
+ * And do not translate the part before the |.
+ */
+ g_string_append (gstring, Q_("keyboard label|Meta"));
+#else
+ /* Command key symbol U+2318 PLACE OF INTEREST SIGN */
+ g_string_append (gstring, "\xe2\x8c\x98");
+#endif
+ seen_mod = TRUE;
+ }
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+
+ ch = gdk_keyval_to_unicode (accelerator_key);
+ if (ch && (g_unichar_isgraph (ch) || ch == ' ') &&
+ (ch < 0x80 || klass->latin1_to_char))
+ {
+ switch (ch)
{
- entry = slist->data;
- if (entry->accel_flags & GTK_ACCEL_VISIBLE)
- {
- GString *gstring;
- gboolean had_mod;
-
- gstring = g_string_new (accel_label->accel_string);
- if (gstring->len)
- g_string_append (gstring, class->accel_seperator);
- else
- g_string_append (gstring, " ");
+ case ' ':
+ /* do not translate the part before the | */
+ g_string_append (gstring, Q_("keyboard label|Space"));
+ break;
+ case '\\':
+ /* do not translate the part before the | */
+ g_string_append (gstring, Q_("keyboard label|Backslash"));
+ break;
+ default:
+ g_string_append_unichar (gstring, g_unichar_toupper (ch));
+ break;
+ }
+ }
+ else if (!append_keyval_symbol (accelerator_key, gstring))
+ {
+ gchar *tmp;
- if (entry->accel_flags & GTK_ACCEL_SIGNAL_VISIBLE)
- {
- g_string_append (gstring, class->signal_quote1);
- g_string_append (gstring, gtk_signal_name (entry->signal_id));
- g_string_append (gstring, class->signal_quote2);
- }
-
- had_mod = FALSE;
- if (entry->accelerator_mods & GDK_SHIFT_MASK)
- {
- g_string_append (gstring, class->mod_name_shift);
- had_mod = TRUE;
- }
- if (entry->accelerator_mods & GDK_CONTROL_MASK)
- {
- if (had_mod)
- g_string_append (gstring, class->mod_separator);
- g_string_append (gstring, class->mod_name_control);
- had_mod = TRUE;
- }
- if (entry->accelerator_mods & GDK_MOD1_MASK)
- {
- if (had_mod)
- g_string_append (gstring, class->mod_separator);
- g_string_append (gstring, class->mod_name_alt);
- had_mod = TRUE;
- }
+ tmp = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
+ if (tmp != NULL)
+ {
+ if (tmp[0] != 0 && tmp[1] == 0)
+ g_string_append_c (gstring, g_ascii_toupper (tmp[0]));
+ else
+ {
+ gchar msg[128];
+ gchar *str;
- if (had_mod)
- g_string_append (gstring, class->mod_separator);
- if (entry->accelerator_key < 0x80 ||
- (entry->accelerator_key > 0x80 &&
- entry->accelerator_key <= 0xff &&
- class->latin1_to_char))
- {
- switch (entry->accelerator_key)
- {
- case ' ':
- g_string_append (gstring, "Space");
- break;
- case '\\':
- g_string_append (gstring, "Backslash");
- break;
- default:
- g_string_append_c (gstring, toupper (entry->accelerator_key));
- break;
- }
- }
- else
+ strcpy (msg, "keyboard label|");
+ g_strlcat (msg, tmp, 128);
+ str = _(msg);
+ if (str == msg)
{
- gchar *tmp;
-
- tmp = gtk_accelerator_name (entry->accelerator_key, 0);
- if (tmp[0] != 0 && tmp[1] == 0)
- tmp[0] = toupper (tmp[0]);
g_string_append (gstring, tmp);
- g_free (tmp);
+ substitute_underscores (gstring->str);
}
-
- g_free (accel_label->accel_string);
- accel_label->accel_string = gstring->str;
- g_string_free (gstring, FALSE);
+ else
+ g_string_append (gstring, str);
}
}
}
- if (!accel_label->accel_string)
- accel_label->accel_string = g_strdup ("");
+ return g_string_free (gstring, FALSE);
+}
+
+gboolean
+gtk_accel_label_refetch (GtkAccelLabel *accel_label)
+{
+ gboolean enable_accels;
+
+ g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
+
+ if (accel_label->accel_string)
+ {
+ g_free (accel_label->accel_string);
+ accel_label->accel_string = NULL;
+ }
+
+ g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)),
+ "gtk-enable-accels", &enable_accels,
+ NULL);
- if (accel_label->queue_id)
+ if (enable_accels && accel_label->accel_closure)
{
- gtk_idle_remove (accel_label->queue_id);
- accel_label->queue_id = 0;
+ GtkAccelKey *key = gtk_accel_group_find (accel_label->accel_group, find_accel, accel_label->accel_closure);
+
+ if (key && key->accel_flags & GTK_ACCEL_VISIBLE)
+ {
+ GtkAccelLabelClass *klass;
+ gchar *tmp;
+
+ klass = GTK_ACCEL_LABEL_GET_CLASS (accel_label);
+ tmp = _gtk_accel_label_class_get_accelerator_label (klass,
+ key->accel_key,
+ key->accel_mods);
+ accel_label->accel_string = g_strconcat (" ", tmp, NULL);
+ g_free (tmp);
+ }
+ if (!accel_label->accel_string)
+ accel_label->accel_string = g_strdup ("-/-");
}
+
+ if (!accel_label->accel_string)
+ accel_label->accel_string = g_strdup ("");
gtk_widget_queue_resize (GTK_WIDGET (accel_label));
return FALSE;
}
+
+#define __GTK_ACCEL_LABEL_C__
+#include "gtkaliasdef.c"