1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2001. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include "gtktextutil.h"
30 #include "gtkmenuitem.h"
33 typedef struct _GtkUnicodeMenuEntry GtkUnicodeMenuEntry;
34 typedef struct _GtkTextUtilCallbackInfo GtkTextUtilCallbackInfo;
36 struct _GtkUnicodeMenuEntry {
41 struct _GtkTextUtilCallbackInfo
43 GtkTextUtilCharChosenFunc func;
47 static const GtkUnicodeMenuEntry bidi_menu_entries[] = {
48 { N_("LRM _Left-to-right mark"), 0x200E },
49 { N_("RLM _Right-to-left mark"), 0x200F },
50 { N_("LRE Left-to-right _embedding"), 0x202A },
51 { N_("RLE Right-to-left e_mbedding"), 0x202B },
52 { N_("LRO Left-to-right _override"), 0x202D },
53 { N_("RLO Right-to-left o_verride"), 0x202E },
54 { N_("PDF _Pop directional formatting"), 0x202C },
55 { N_("ZWS _Zero width space"), 0x200B },
56 { N_("ZWJ Zero width _joiner"), 0x200D },
57 { N_("ZWNJ Zero width _non-joiner"), 0x200C }
61 activate_cb (GtkWidget *menu_item,
64 GtkUnicodeMenuEntry *entry;
65 GtkTextUtilCallbackInfo *info = data;
68 entry = g_object_get_data (G_OBJECT (menu_item), "gtk-unicode-menu-entry");
70 buf[g_unichar_to_utf8 (entry->ch, buf)] = '\0';
72 (* info->func) (buf, info->data);
76 * _gtk_text_util_append_special_char_menuitems
77 * @menushell: a #GtkMenuShell
78 * @callback: call this when an item is chosen
79 * @data: data for callback
81 * Add menuitems for various bidi control characters to a menu;
82 * the menuitems, when selected, will call the given function
83 * with the chosen character.
85 * This function is private/internal in GTK 2.0, the functionality may
86 * become public sometime, but it probably needs more thought first.
87 * e.g. maybe there should be a way to just get the list of items,
88 * instead of requiring the menu items to be created.
91 _gtk_text_util_append_special_char_menuitems (GtkMenuShell *menushell,
92 GtkTextUtilCharChosenFunc func,
97 for (i = 0; i < G_N_ELEMENTS (bidi_menu_entries); i++)
100 GtkTextUtilCallbackInfo *info;
102 /* wasteful to have a bunch of copies, but simplifies mem management */
103 info = g_new (GtkTextUtilCallbackInfo, 1);
107 menuitem = gtk_menu_item_new_with_mnemonic (_(bidi_menu_entries[i].label));
108 g_object_set_data (G_OBJECT (menuitem), "gtk-unicode-menu-entry",
109 (gpointer)&bidi_menu_entries[i]);
111 g_signal_connect_data (menuitem, "activate",
112 G_CALLBACK (activate_cb),
113 info, (GClosureNotify) g_free, 0);
115 gtk_widget_show (menuitem);
116 gtk_menu_shell_append (menushell, menuitem);