~canonical-dx-team/ubuntu/maverick/gtk+2.0/menuproxy

« back to all changes in this revision

Viewing changes to gtk/gtkaccellabel.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-04 12:24:25 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20070504122425-0m8midgzrp40y8w2
Tags: 2.10.12-1ubuntu1
* Sync with Debian
* New upstream version:
  Fixed bugs:
  - 379414 file chooser warnings when changing path in the entry
  - 418585 GtkFileChooserDefault sizing code is not DPI independent
  - 419568 Crash in search if start with special letter
  - 435062 build dies with icon cache validation
  - 379399 Segfault to call gtk_print_operation_run twice.
  - 387889 cups backend has problems when there are too many printers
  - 418531 invalid read to gtkicontheme.c gtk_icon_theme_lookup_icon...
  - 423916 crash in color scheme code
  - 424042 Segmentation fault while quickly pressing Alt+arrows
  - 415260 Protect against negative indices when setting values in G...
  - 419171 XGetVisualInfo() may not set nxvisuals
  - 128852 Gdk cursors don't look good on win32
  - 344657 Ctrl-H doesn't toggle "Show Hidden Files" setting
  - 345345 PrintOperation::paginate is not emitted for class handler
  - 347567 GtkPrintOperation::end-print is not emitted if it's cance...
  - 369112 gtk_ui_manager_add_ui should accept unnamed separator
  - 392015 Selected menu item invisible on Windows Vista
  - 399253 MS-Windows Theme Bottom Tab placement rendering glitches
  - 399425 gtk_input_dialog_fill_axes() adds child to gtkscrolledwin...
  - 403251 [patch] little memory leak in GtkPrintJob
  - 403267 [patch] memory leak in GtkPageSetupUnixDialog
  - 403470 MS-Windows Theme tab placement other than on top leaks a ...
  - 404506 Windows system fonts that have multi-byte font names cann...
  - 405089 Incorrect window placement for GtkEventBox private window
  - 405515 Minor leak in gtkfilesystemmodel.c
  - 405539 gdk_pixbuf_save() for PNG saver can return FALSE without ...
  - 415681 gdk_window_clear_area includes an extra line and column o...
  - 418219 GtkRecentChooser should apply filter before sorting and c...
  - 418403 Scroll to printer after selecting it from settings
  - 421985 _gtk_print_operation_platform_backend_launch_preview
  - 421990 gtk_print_job_get_surface
  - 421993 gtk_print_operation_init
  - 423064 Conditional jump or move depends on uninitialised value(s...
  - 423722 Fix printing header in gtk-demo
  - 424168 gtk_print_operation_run on async preview
  - 425655 Don't install gtk+-unix-print-2.0.pc on non-UNIX platforms
  - 425786 GDK segfaults if XineramaQueryScreens fails
  - 428665 Lpr Backend gets stuck in infinite loop during gtk_enumer...
  - 429902 GtkPrintOperation leaks cairo contextes
  - 431997 First delay of GdkPixbufAnimationIter is wrong
  - 433242 Inconsistent scroll arrow position calculations
  - 433972 Placing gtk.Expander inside a gtk.TextView() changes gtk....
  - 434261 _gtk_toolbar_elide_underscores incorrectly handles some s...
  - 383354 ctrl-L should make 'Location' entry disappear
  - 418673 gtk_recent_manager_add_item
  - 429732 gtk_accel_group_finalize accesses invalid memory
  - 435028 WM_CLIENT_LEADER is wrong on the leader_window
  - 431067 Background of the header window is not updated
  - 338843 add recent files support inside the ui manager
  - 148535 add drop shadow to menus, tooltips, etc. under Windows XP
* debian/control.in:
  - Conflicts on ubuntulooks (<= 0.9.11-1)
* debian/patches/15_default-fallback-icon-theme.patch:
  - patch from Debian, fallback on gnome icon theme

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GTK - The GIMP Toolkit
 
2
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 
3
 *
 
4
 * GtkAccelLabel: GtkLabel with accelerator monitoring facilities.
 
5
 * Copyright (C) 1998 Tim Janik
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2 of the License, or (at your option) any later version.
 
11
 *
 
12
 * This library is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Lesser General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Lesser General Public
 
18
 * License along with this library; if not, write to the
 
19
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
20
 * Boston, MA 02111-1307, USA.
 
21
 */
 
22
 
 
23
/*
 
24
 * Modified by the GTK+ Team and others 1997-2001.  See the AUTHORS
 
25
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 
26
 * files for a list of changes.  These files are distributed with
 
27
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 
28
 */
 
29
 
 
30
#include <config.h>
 
31
#include <string.h>
 
32
 
 
33
#include "gtkaccellabel.h"
 
34
#include "gtkaccelmap.h"
 
35
#include "gtkmain.h"
 
36
#include "gtkprivate.h"
 
37
#include "gtkintl.h"
 
38
#include "gtkalias.h"
 
39
 
 
40
enum {
 
41
  PROP_0,
 
42
  PROP_ACCEL_CLOSURE,
 
43
  PROP_ACCEL_WIDGET
 
44
};
 
45
 
 
46
static void         gtk_accel_label_set_property (GObject            *object,
 
47
                                                  guint               prop_id,
 
48
                                                  const GValue       *value,
 
49
                                                  GParamSpec         *pspec);
 
50
static void         gtk_accel_label_get_property (GObject            *object,
 
51
                                                  guint               prop_id,
 
52
                                                  GValue             *value,
 
53
                                                  GParamSpec         *pspec);
 
54
static void         gtk_accel_label_destroy      (GtkObject          *object);
 
55
static void         gtk_accel_label_finalize     (GObject            *object);
 
56
static void         gtk_accel_label_size_request (GtkWidget          *widget,
 
57
                                                  GtkRequisition     *requisition);
 
58
static gboolean     gtk_accel_label_expose_event (GtkWidget          *widget,
 
59
                                                  GdkEventExpose     *event);
 
60
static const gchar *gtk_accel_label_get_string   (GtkAccelLabel      *accel_label);
 
61
 
 
62
 
 
63
G_DEFINE_TYPE (GtkAccelLabel, gtk_accel_label, GTK_TYPE_LABEL)
 
64
 
 
65
static void
 
66
gtk_accel_label_class_init (GtkAccelLabelClass *class)
 
67
{
 
68
  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
 
69
  GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
 
70
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
 
71
  
 
72
  gobject_class->finalize = gtk_accel_label_finalize;
 
73
  gobject_class->set_property = gtk_accel_label_set_property;
 
74
  gobject_class->get_property = gtk_accel_label_get_property;
 
75
  
 
76
  object_class->destroy = gtk_accel_label_destroy;
 
77
   
 
78
  widget_class->size_request = gtk_accel_label_size_request;
 
79
  widget_class->expose_event = gtk_accel_label_expose_event;
 
80
 
 
81
  class->signal_quote1 = g_strdup ("<:");
 
82
  class->signal_quote2 = g_strdup (":>");
 
83
  /* This is the text that should appear next to menu accelerators
 
84
   * that use the shift key. If the text on this key isn't typically
 
85
   * translated on keyboards used for your language, don't translate
 
86
   * this.
 
87
   * And do not translate the part before the |.
 
88
   */
 
89
  class->mod_name_shift = g_strdup (Q_("keyboard label|Shift"));
 
90
  /* This is the text that should appear next to menu accelerators
 
91
   * that use the control key. If the text on this key isn't typically
 
92
   * translated on keyboards used for your language, don't translate
 
93
   * this.
 
94
   * And do not translate the part before the |.
 
95
   */
 
96
  class->mod_name_control = g_strdup (Q_("keyboard label|Ctrl"));
 
97
  /* This is the text that should appear next to menu accelerators
 
98
   * that use the alt key. If the text on this key isn't typically
 
99
   * translated on keyboards used for your language, don't translate
 
100
   * this.
 
101
   * And do not translate the part before the |.
 
102
   */
 
103
  class->mod_name_alt = g_strdup (Q_("keyboard label|Alt"));
 
104
  class->mod_separator = g_strdup ("+");
 
105
  class->accel_seperator = g_strdup (" / ");
 
106
  class->latin1_to_char = TRUE;
 
107
  
 
108
  g_object_class_install_property (gobject_class,
 
109
                                   PROP_ACCEL_CLOSURE,
 
110
                                   g_param_spec_boxed ("accel-closure",
 
111
                                                       P_("Accelerator Closure"),
 
112
                                                       P_("The closure to be monitored for accelerator changes"),
 
113
                                                       G_TYPE_CLOSURE,
 
114
                                                       GTK_PARAM_READWRITE));
 
115
  g_object_class_install_property (gobject_class,
 
116
                                   PROP_ACCEL_WIDGET,
 
117
                                   g_param_spec_object ("accel-widget",
 
118
                                                        P_("Accelerator Widget"),
 
119
                                                        P_("The widget to be monitored for accelerator changes"),
 
120
                                                        GTK_TYPE_WIDGET,
 
121
                                                        GTK_PARAM_READWRITE));
 
122
}
 
123
 
 
124
static void
 
125
gtk_accel_label_set_property (GObject      *object,
 
126
                              guint         prop_id,
 
127
                              const GValue *value,
 
128
                              GParamSpec   *pspec)
 
129
{
 
130
  GtkAccelLabel  *accel_label;
 
131
 
 
132
  accel_label = GTK_ACCEL_LABEL (object);
 
133
 
 
134
  switch (prop_id)
 
135
    {
 
136
    case PROP_ACCEL_CLOSURE:
 
137
      gtk_accel_label_set_accel_closure (accel_label, g_value_get_boxed (value));
 
138
      break;
 
139
    case PROP_ACCEL_WIDGET:
 
140
      gtk_accel_label_set_accel_widget (accel_label, g_value_get_object (value));
 
141
      break;
 
142
    default:
 
143
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
144
      break;
 
145
    }
 
146
}
 
147
 
 
148
static void
 
149
gtk_accel_label_get_property (GObject    *object,
 
150
                              guint       prop_id,
 
151
                              GValue     *value,
 
152
                              GParamSpec *pspec)
 
153
{
 
154
  GtkAccelLabel  *accel_label;
 
155
 
 
156
  accel_label = GTK_ACCEL_LABEL (object);
 
157
 
 
158
  switch (prop_id)
 
159
    {
 
160
    case PROP_ACCEL_CLOSURE:
 
161
      g_value_set_boxed (value, accel_label->accel_closure);
 
162
      break;
 
163
    case PROP_ACCEL_WIDGET:
 
164
      g_value_set_object (value, accel_label->accel_widget);
 
165
      break;
 
166
    default:
 
167
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
168
      break;
 
169
    }
 
170
}
 
171
 
 
172
static void
 
173
gtk_accel_label_init (GtkAccelLabel *accel_label)
 
174
{
 
175
  accel_label->accel_padding = 3;
 
176
  accel_label->accel_widget = NULL;
 
177
  accel_label->accel_closure = NULL;
 
178
  accel_label->accel_group = NULL;
 
179
  accel_label->accel_string = NULL;
 
180
}
 
181
 
 
182
GtkWidget*
 
183
gtk_accel_label_new (const gchar *string)
 
184
{
 
185
  GtkAccelLabel *accel_label;
 
186
  
 
187
  g_return_val_if_fail (string != NULL, NULL);
 
188
  
 
189
  accel_label = g_object_new (GTK_TYPE_ACCEL_LABEL, NULL);
 
190
  
 
191
  gtk_label_set_text (GTK_LABEL (accel_label), string);
 
192
  
 
193
  return GTK_WIDGET (accel_label);
 
194
}
 
195
 
 
196
static void
 
197
gtk_accel_label_destroy (GtkObject *object)
 
198
{
 
199
  GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
 
200
 
 
201
  gtk_accel_label_set_accel_widget (accel_label, NULL);
 
202
  gtk_accel_label_set_accel_closure (accel_label, NULL);
 
203
  
 
204
  GTK_OBJECT_CLASS (gtk_accel_label_parent_class)->destroy (object);
 
205
}
 
206
 
 
207
static void
 
208
gtk_accel_label_finalize (GObject *object)
 
209
{
 
210
  GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
 
211
 
 
212
  g_free (accel_label->accel_string);
 
213
  
 
214
  G_OBJECT_CLASS (gtk_accel_label_parent_class)->finalize (object);
 
215
}
 
216
 
 
217
/**
 
218
 * gtk_accel_label_get_accel_widget:
 
219
 * @accel_label: a #GtkAccelLabel
 
220
 *
 
221
 * Fetches the widget monitored by this accelerator label. See
 
222
 * gtk_accel_label_set_accel_widget().
 
223
 *
 
224
 * Return value: the object monitored by the accelerator label,
 
225
 *               or %NULL.
 
226
 **/
 
227
GtkWidget*
 
228
gtk_accel_label_get_accel_widget (GtkAccelLabel *accel_label)
 
229
{
 
230
  g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), NULL);
 
231
 
 
232
  return accel_label->accel_widget;
 
233
}
 
234
 
 
235
guint
 
236
gtk_accel_label_get_accel_width (GtkAccelLabel *accel_label)
 
237
{
 
238
  g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), 0);
 
239
  
 
240
  return (accel_label->accel_string_width +
 
241
          (accel_label->accel_string_width ? accel_label->accel_padding : 0));
 
242
}
 
243
 
 
244
static void
 
245
gtk_accel_label_size_request (GtkWidget      *widget,
 
246
                              GtkRequisition *requisition)
 
247
{
 
248
  GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
 
249
  PangoLayout *layout;
 
250
  gint width;
 
251
  
 
252
  if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->size_request)
 
253
    GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->size_request (widget, requisition);
 
254
 
 
255
  layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
 
256
  pango_layout_get_pixel_size (layout, &width, NULL);
 
257
  accel_label->accel_string_width = width;
 
258
  
 
259
  g_object_unref (layout);
 
260
}
 
261
 
 
262
static gint
 
263
get_first_baseline (PangoLayout *layout)
 
264
{
 
265
  PangoLayoutIter *iter;
 
266
  gint result;
 
267
 
 
268
  iter = pango_layout_get_iter (layout);
 
269
  result = pango_layout_iter_get_baseline (iter);
 
270
  pango_layout_iter_free (iter);
 
271
 
 
272
  return PANGO_PIXELS (result);
 
273
}
 
274
 
 
275
static gboolean 
 
276
gtk_accel_label_expose_event (GtkWidget      *widget,
 
277
                              GdkEventExpose *event)
 
278
{
 
279
  GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
 
280
  GtkMisc *misc = GTK_MISC (accel_label);
 
281
  GtkTextDirection direction;
 
282
 
 
283
  direction = gtk_widget_get_direction (widget);
 
284
 
 
285
  if (GTK_WIDGET_DRAWABLE (accel_label))
 
286
    {
 
287
      guint ac_width;
 
288
      
 
289
      ac_width = gtk_accel_label_get_accel_width (accel_label);
 
290
      
 
291
      if (widget->allocation.width >= widget->requisition.width + ac_width)
 
292
        {
 
293
          PangoLayout *label_layout;
 
294
          PangoLayout *accel_layout;
 
295
          GtkLabel *label = GTK_LABEL (widget);
 
296
 
 
297
          gint x;
 
298
          gint y;
 
299
          
 
300
          label_layout = gtk_label_get_layout (GTK_LABEL (accel_label));
 
301
 
 
302
          if (direction == GTK_TEXT_DIR_RTL)
 
303
            widget->allocation.x += ac_width;
 
304
          widget->allocation.width -= ac_width;
 
305
          if (gtk_label_get_ellipsize (label))
 
306
            pango_layout_set_width (label_layout,
 
307
                                    pango_layout_get_width (label_layout) 
 
308
                                    - ac_width * PANGO_SCALE);
 
309
          
 
310
          if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
 
311
            GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
 
312
          if (direction == GTK_TEXT_DIR_RTL)
 
313
            widget->allocation.x -= ac_width;
 
314
          widget->allocation.width += ac_width;
 
315
          if (gtk_label_get_ellipsize (label))
 
316
            pango_layout_set_width (label_layout,
 
317
                                    pango_layout_get_width (label_layout) 
 
318
                                    + ac_width * PANGO_SCALE);
 
319
          
 
320
          if (direction == GTK_TEXT_DIR_RTL)
 
321
            x = widget->allocation.x + misc->xpad;
 
322
          else
 
323
            x = widget->allocation.x + widget->allocation.width - misc->xpad - ac_width;
 
324
 
 
325
          gtk_label_get_layout_offsets (GTK_LABEL (accel_label), NULL, &y);
 
326
 
 
327
          accel_layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
 
328
 
 
329
          y += get_first_baseline (label_layout) - get_first_baseline (accel_layout);
 
330
 
 
331
          gtk_paint_layout (widget->style,
 
332
                            widget->window,
 
333
                            GTK_WIDGET_STATE (widget),
 
334
                            FALSE,
 
335
                            &event->area,
 
336
                            widget,
 
337
                            "accellabel",
 
338
                            x, y,
 
339
                            accel_layout);                            
 
340
 
 
341
          g_object_unref (accel_layout);
 
342
        }
 
343
      else
 
344
        {
 
345
          if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
 
346
            GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
 
347
        }
 
348
    }
 
349
  
 
350
  return FALSE;
 
351
}
 
352
 
 
353
static void
 
354
refetch_widget_accel_closure (GtkAccelLabel *accel_label)
 
355
{
 
356
  GClosure *closure = NULL;
 
357
  GList *clist, *list;
 
358
  
 
359
  g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
 
360
  g_return_if_fail (GTK_IS_WIDGET (accel_label->accel_widget));
 
361
  
 
362
  clist = gtk_widget_list_accel_closures (accel_label->accel_widget);
 
363
  for (list = clist; list; list = list->next)
 
364
    {
 
365
      /* we just take the first closure used */
 
366
      closure = list->data;
 
367
      break;
 
368
    }
 
369
  g_list_free (clist);
 
370
  gtk_accel_label_set_accel_closure (accel_label, closure);
 
371
}
 
372
 
 
373
/**
 
374
 * gtk_accel_label_set_accel_widget:
 
375
 * @accel_label: a #GtkAccelLabel
 
376
 * @accel_widget: the widget to be monitored.
 
377
 *
 
378
 * Sets the widget to be monitored by this accelerator label. 
 
379
 **/
 
380
void
 
381
gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
 
382
                                  GtkWidget     *accel_widget)
 
383
{
 
384
  g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
 
385
  if (accel_widget)
 
386
    g_return_if_fail (GTK_IS_WIDGET (accel_widget));
 
387
    
 
388
  if (accel_widget != accel_label->accel_widget)
 
389
    {
 
390
      if (accel_label->accel_widget)
 
391
        {
 
392
          gtk_accel_label_set_accel_closure (accel_label, NULL);
 
393
          g_signal_handlers_disconnect_by_func (accel_label->accel_widget,
 
394
                                                refetch_widget_accel_closure,
 
395
                                                accel_label);
 
396
          g_object_unref (accel_label->accel_widget);
 
397
        }
 
398
      accel_label->accel_widget = accel_widget;
 
399
      if (accel_label->accel_widget)
 
400
        {
 
401
          g_object_ref (accel_label->accel_widget);
 
402
          g_signal_connect_object (accel_label->accel_widget, "accel_closures_changed",
 
403
                                   G_CALLBACK (refetch_widget_accel_closure),
 
404
                                   accel_label, G_CONNECT_SWAPPED);
 
405
          refetch_widget_accel_closure (accel_label);
 
406
        }
 
407
      g_object_notify (G_OBJECT (accel_label), "accel-widget");
 
408
    }
 
409
}
 
410
 
 
411
static void
 
412
gtk_accel_label_reset (GtkAccelLabel *accel_label)
 
413
{
 
414
  if (accel_label->accel_string)
 
415
    {
 
416
      g_free (accel_label->accel_string);
 
417
      accel_label->accel_string = NULL;
 
418
    }
 
419
  
 
420
  gtk_widget_queue_resize (GTK_WIDGET (accel_label));
 
421
}
 
422
 
 
423
static void
 
424
check_accel_changed (GtkAccelGroup  *accel_group,
 
425
                     guint           keyval,
 
426
                     GdkModifierType modifier,
 
427
                     GClosure       *accel_closure,
 
428
                     GtkAccelLabel  *accel_label)
 
429
{
 
430
  if (accel_closure == accel_label->accel_closure)
 
431
    gtk_accel_label_reset (accel_label);
 
432
}
 
433
 
 
434
/**
 
435
 * gtk_accel_label_set_accel_closure:
 
436
 * @accel_label: a #GtkAccelLabel
 
437
 * @accel_closure: the closure to monitor for accelerator changes.
 
438
 *
 
439
 * Sets the closure to be monitored by this accelerator label. The closure
 
440
 * must be connected to an accelerator group; see gtk_accel_group_connect().
 
441
 **/
 
442
void
 
443
gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,
 
444
                                   GClosure      *accel_closure)
 
445
{
 
446
  g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
 
447
  if (accel_closure)
 
448
    g_return_if_fail (gtk_accel_group_from_accel_closure (accel_closure) != NULL);
 
449
 
 
450
  if (accel_closure != accel_label->accel_closure)
 
451
    {
 
452
      if (accel_label->accel_closure)
 
453
        {
 
454
          g_signal_handlers_disconnect_by_func (accel_label->accel_group,
 
455
                                                check_accel_changed,
 
456
                                                accel_label);
 
457
          accel_label->accel_group = NULL;
 
458
          g_closure_unref (accel_label->accel_closure);
 
459
        }
 
460
      accel_label->accel_closure = accel_closure;
 
461
      if (accel_label->accel_closure)
 
462
        {
 
463
          g_closure_ref (accel_label->accel_closure);
 
464
          accel_label->accel_group = gtk_accel_group_from_accel_closure (accel_closure);
 
465
          g_signal_connect_object (accel_label->accel_group, "accel_changed",
 
466
                                   G_CALLBACK (check_accel_changed),
 
467
                                   accel_label, 0);
 
468
        }
 
469
      gtk_accel_label_reset (accel_label);
 
470
      g_object_notify (G_OBJECT (accel_label), "accel-closure");
 
471
    }
 
472
}
 
473
 
 
474
static gboolean
 
475
find_accel (GtkAccelKey *key,
 
476
            GClosure    *closure,
 
477
            gpointer     data)
 
478
{
 
479
  return data == (gpointer) closure;
 
480
}
 
481
 
 
482
static const gchar *
 
483
gtk_accel_label_get_string (GtkAccelLabel *accel_label)
 
484
{
 
485
  if (!accel_label->accel_string)
 
486
    gtk_accel_label_refetch (accel_label);
 
487
  
 
488
  return accel_label->accel_string;
 
489
}
 
490
 
 
491
/* Underscores in key names are better displayed as spaces
 
492
 * E.g., Page_Up should be "Page Up"
 
493
 */
 
494
static void
 
495
substitute_underscores (char *str)
 
496
{
 
497
  char *p;
 
498
 
 
499
  for (p = str; *p; p++)
 
500
    if (*p == '_')
 
501
      *p = ' ';
 
502
}
 
503
 
 
504
gchar *
 
505
_gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
 
506
                                              guint               accelerator_key,
 
507
                                              GdkModifierType     accelerator_mods)
 
508
{
 
509
  GString *gstring;
 
510
  gboolean seen_mod = FALSE;
 
511
  gunichar ch;
 
512
  
 
513
  gstring = g_string_new ("");
 
514
  
 
515
  if (accelerator_mods & GDK_SHIFT_MASK)
 
516
    {
 
517
      g_string_append (gstring, klass->mod_name_shift);
 
518
      seen_mod = TRUE;
 
519
    }
 
520
  if (accelerator_mods & GDK_CONTROL_MASK)
 
521
    {
 
522
      if (seen_mod)
 
523
        g_string_append (gstring, klass->mod_separator);
 
524
      g_string_append (gstring, klass->mod_name_control);
 
525
      seen_mod = TRUE;
 
526
    }
 
527
  if (accelerator_mods & GDK_MOD1_MASK)
 
528
    {
 
529
      if (seen_mod)
 
530
        g_string_append (gstring, klass->mod_separator);
 
531
      g_string_append (gstring, klass->mod_name_alt);
 
532
      seen_mod = TRUE;
 
533
    }
 
534
  if (accelerator_mods & GDK_MOD2_MASK)
 
535
    {
 
536
      if (seen_mod)
 
537
        g_string_append (gstring, klass->mod_separator);
 
538
 
 
539
      g_string_append (gstring, "Mod2");
 
540
      seen_mod = TRUE;
 
541
    }
 
542
  if (accelerator_mods & GDK_MOD3_MASK)
 
543
    {
 
544
      if (seen_mod)
 
545
        g_string_append (gstring, klass->mod_separator);
 
546
 
 
547
      g_string_append (gstring, "Mod3");
 
548
      seen_mod = TRUE;
 
549
    }
 
550
  if (accelerator_mods & GDK_MOD4_MASK)
 
551
    {
 
552
      if (seen_mod)
 
553
        g_string_append (gstring, klass->mod_separator);
 
554
 
 
555
      g_string_append (gstring, "Mod4");
 
556
      seen_mod = TRUE;
 
557
    }
 
558
  if (accelerator_mods & GDK_MOD5_MASK)
 
559
    {
 
560
      if (seen_mod)
 
561
        g_string_append (gstring, klass->mod_separator);
 
562
 
 
563
      g_string_append (gstring, "Mod5");
 
564
      seen_mod = TRUE;
 
565
    }
 
566
  if (accelerator_mods & GDK_SUPER_MASK)
 
567
    {
 
568
      if (seen_mod)
 
569
        g_string_append (gstring, klass->mod_separator);
 
570
 
 
571
      /* This is the text that should appear next to menu accelerators
 
572
       * that use the super key. If the text on this key isn't typically
 
573
       * translated on keyboards used for your language, don't translate
 
574
       * this.
 
575
       * And do not translate the part before the |.
 
576
       */
 
577
      g_string_append (gstring, Q_("keyboard label|Super"));
 
578
      seen_mod = TRUE;
 
579
    }
 
580
  if (accelerator_mods & GDK_HYPER_MASK)
 
581
    {
 
582
      if (seen_mod)
 
583
        g_string_append (gstring, klass->mod_separator);
 
584
 
 
585
      /* This is the text that should appear next to menu accelerators
 
586
       * that use the hyper key. If the text on this key isn't typically
 
587
       * translated on keyboards used for your language, don't translate
 
588
       * this.
 
589
       * And do not translate the part before the |.
 
590
       */
 
591
      g_string_append (gstring, Q_("keyboard label|Hyper"));
 
592
      seen_mod = TRUE;
 
593
    }
 
594
  if (accelerator_mods & GDK_META_MASK)
 
595
    {
 
596
      if (seen_mod)
 
597
        g_string_append (gstring, klass->mod_separator);
 
598
 
 
599
      /* This is the text that should appear next to menu accelerators
 
600
       * that use the meta key. If the text on this key isn't typically
 
601
       * translated on keyboards used for your language, don't translate
 
602
       * this.
 
603
       * And do not translate the part before the |.
 
604
       */
 
605
      g_string_append (gstring, Q_("keyboard label|Meta"));
 
606
      seen_mod = TRUE;
 
607
    }
 
608
  if (seen_mod)
 
609
    g_string_append (gstring, klass->mod_separator);
 
610
  
 
611
  ch = gdk_keyval_to_unicode (accelerator_key);
 
612
  if (ch && (g_unichar_isgraph (ch) || ch == ' ') &&
 
613
      (ch < 0x80 || klass->latin1_to_char))
 
614
    {
 
615
      switch (ch)
 
616
        {
 
617
        case ' ':
 
618
          /* do not translate the part before the | */
 
619
          g_string_append (gstring, Q_("keyboard label|Space"));
 
620
          break;
 
621
        case '\\':
 
622
          /* do not translate the part before the | */
 
623
          g_string_append (gstring, Q_("keyboard label|Backslash"));
 
624
          break;
 
625
        default:
 
626
          g_string_append_unichar (gstring, g_unichar_toupper (ch));
 
627
          break;
 
628
        }
 
629
    }
 
630
  else
 
631
    {
 
632
      gchar *tmp;
 
633
 
 
634
      tmp = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
 
635
      if (tmp != NULL)
 
636
        {
 
637
          if (tmp[0] != 0 && tmp[1] == 0)
 
638
            g_string_append_c (gstring, g_ascii_toupper (tmp[0]));
 
639
          else
 
640
            {
 
641
              gchar msg[128];
 
642
              gchar *str;
 
643
              
 
644
              strcpy (msg, "keyboard label|");
 
645
              g_strlcat (msg, tmp, 128);
 
646
              str = dgettext (GETTEXT_PACKAGE, msg);
 
647
              if (str == msg)
 
648
                {
 
649
                  g_string_append (gstring, tmp);
 
650
                  substitute_underscores (gstring->str);
 
651
                }
 
652
              else
 
653
                g_string_append (gstring, str);
 
654
            }
 
655
        }
 
656
    }
 
657
 
 
658
  return g_string_free (gstring, FALSE);
 
659
}
 
660
 
 
661
gboolean
 
662
gtk_accel_label_refetch (GtkAccelLabel *accel_label)
 
663
{
 
664
  g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
 
665
 
 
666
  if (accel_label->accel_string)
 
667
    {
 
668
      g_free (accel_label->accel_string);
 
669
      accel_label->accel_string = NULL;
 
670
    }
 
671
 
 
672
  if (accel_label->accel_closure)
 
673
    {
 
674
      GtkAccelKey *key = gtk_accel_group_find (accel_label->accel_group, find_accel, accel_label->accel_closure);
 
675
 
 
676
      if (key && key->accel_flags & GTK_ACCEL_VISIBLE)
 
677
        {
 
678
          GtkAccelLabelClass *klass;
 
679
          gchar *tmp;
 
680
 
 
681
          klass = GTK_ACCEL_LABEL_GET_CLASS (accel_label);
 
682
          tmp = _gtk_accel_label_class_get_accelerator_label (klass,
 
683
                                                              key->accel_key,
 
684
                                                              key->accel_mods);
 
685
          accel_label->accel_string = g_strconcat ("   ", tmp, NULL);
 
686
          g_free (tmp);
 
687
        }
 
688
      if (!accel_label->accel_string)
 
689
        accel_label->accel_string = g_strdup ("-/-");
 
690
    }
 
691
  
 
692
  if (!accel_label->accel_string)
 
693
    accel_label->accel_string = g_strdup ("");
 
694
 
 
695
  gtk_widget_queue_resize (GTK_WIDGET (accel_label));
 
696
 
 
697
  return FALSE;
 
698
}
 
699
 
 
700
#define __GTK_ACCEL_LABEL_C__
 
701
#include "gtkaliasdef.c"