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/.
27 #include "gtktextutil.h"
29 #include "gtkmenuitem.h"
31 typedef struct _GtkUnicodeMenuEntry GtkUnicodeMenuEntry;
32 typedef struct _GtkTextUtilCallbackInfo GtkTextUtilCallbackInfo;
34 struct _GtkUnicodeMenuEntry {
39 struct _GtkTextUtilCallbackInfo
41 GtkTextUtilCharChosenFunc func;
45 GtkUnicodeMenuEntry bidi_menu_entries[] = {
46 { N_("LRM _Left-to-right mark"), 0x200E },
47 { N_("RLM _Right-to-left mark"), 0x200F },
48 { N_("LRE Left-to-right _embedding"), 0x202A },
49 { N_("RLE Right-to-left e_mbedding"), 0x202B },
50 { N_("LRO Left-to-right _override"), 0x202D },
51 { N_("RLO Right-to-left o_verride"), 0x202E },
52 { N_("PDF _Pop directional formatting"), 0x202C },
53 { N_("ZWS _Zero width space"), 0x200B },
54 { N_("ZWN Zero width _joiner"), 0x200D },
55 { N_("ZWNJ Zero width _non-joiner"), 0x200C }
59 activate_cb (GtkWidget *menu_item,
62 GtkUnicodeMenuEntry *entry;
63 GtkTextUtilCallbackInfo *info = data;
66 entry = g_object_get_data (G_OBJECT (menu_item), "gtk-unicode-menu-entry");
68 buf[g_unichar_to_utf8 (entry->ch, buf)] = '\0';
70 (* info->func) (buf, info->data);
74 * _gtk_text_util_append_special_char_menuitems
75 * @menushell: a #GtkMenuShell
76 * @callback: call this when an item is chosen
77 * @data: data for callback
79 * Add menuitems for various bidi control characters to a menu;
80 * the menuitems, when selected, will call the given function
81 * with the chosen character.
83 * This function is private/internal in GTK 2.0, the functionality may
84 * become public sometime, but it probably needs more thought first.
85 * e.g. maybe there should be a way to just get the list of items,
86 * instead of requiring the menu items to be created.
89 _gtk_text_util_append_special_char_menuitems (GtkMenuShell *menushell,
90 GtkTextUtilCharChosenFunc func,
95 for (i = 0; i < G_N_ELEMENTS (bidi_menu_entries); i++)
98 GtkTextUtilCallbackInfo *info;
100 /* wasteful to have a bunch of copies, but simplifies mem management */
101 info = g_new (GtkTextUtilCallbackInfo, 1);
105 menuitem = gtk_menu_item_new_with_mnemonic (_(bidi_menu_entries[i].label));
106 g_object_set_data (G_OBJECT (menuitem), "gtk-unicode-menu-entry",
107 &bidi_menu_entries[i]);
109 g_signal_connect_data (G_OBJECT (menuitem), "activate",
110 G_CALLBACK (activate_cb),
111 info, (GClosureNotify) g_free, 0);
113 gtk_widget_show (menuitem);
114 gtk_menu_shell_append (menushell, menuitem);