]> Pileus Git - ~andy/gtk/blob - gtk/gtktextutil.c
Fix use of uninitialized variable.
[~andy/gtk] / gtk / gtktextutil.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include "gtktextutil.h"
28 #include "gtkintl.h"
29 #include "gtkmenuitem.h"
30
31 typedef struct _GtkUnicodeMenuEntry GtkUnicodeMenuEntry;
32 typedef struct _GtkTextUtilCallbackInfo GtkTextUtilCallbackInfo;
33
34 struct _GtkUnicodeMenuEntry {
35   const char *label;
36   gunichar ch;
37 };
38
39 struct _GtkTextUtilCallbackInfo
40 {
41   GtkTextUtilCharChosenFunc func;
42   gpointer data;
43 };
44
45 static const 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_("ZWJ Zero width _joiner"), 0x200D },
55   { N_("ZWNJ Zero width _non-joiner"), 0x200C }
56 };
57
58 static void
59 activate_cb (GtkWidget *menu_item,
60              gpointer   data)
61 {
62   GtkUnicodeMenuEntry *entry;
63   GtkTextUtilCallbackInfo *info = data;
64   char buf[7];
65   
66   entry = g_object_get_data (G_OBJECT (menu_item), "gtk-unicode-menu-entry");
67
68   buf[g_unichar_to_utf8 (entry->ch, buf)] = '\0';
69   
70   (* info->func) (buf, info->data);
71 }
72
73 /**
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
78  * 
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.
82  *
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.
87  **/
88 void
89 _gtk_text_util_append_special_char_menuitems (GtkMenuShell              *menushell,
90                                               GtkTextUtilCharChosenFunc  func,
91                                               gpointer                   data)
92 {
93   int i;
94   
95   for (i = 0; i < G_N_ELEMENTS (bidi_menu_entries); i++)
96     {
97       GtkWidget *menuitem;
98       GtkTextUtilCallbackInfo *info;
99
100       /* wasteful to have a bunch of copies, but simplifies mem management */
101       info = g_new (GtkTextUtilCallbackInfo, 1);
102       info->func = func;
103       info->data = data;
104       
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                          (gpointer)&bidi_menu_entries[i]);
108       
109       g_signal_connect_data (menuitem, "activate",
110                              G_CALLBACK (activate_cb),
111                              info, (GClosureNotify) g_free, 0);
112       
113       gtk_widget_show (menuitem);
114       gtk_menu_shell_append (menushell, menuitem);
115     }
116 }
117