]> Pileus Git - ~andy/gtk/blob - gtk/gtktextutil.c
Make PLT-reduction work with gcc4, and don't include everything in
[~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 <config.h>
28 #include "gtktextutil.h"
29 #include "gtkintl.h"
30 #include "gtkmenuitem.h"
31 #include "gtkalias.h"
32
33 typedef struct _GtkUnicodeMenuEntry GtkUnicodeMenuEntry;
34 typedef struct _GtkTextUtilCallbackInfo GtkTextUtilCallbackInfo;
35
36 struct _GtkUnicodeMenuEntry {
37   const char *label;
38   gunichar ch;
39 };
40
41 struct _GtkTextUtilCallbackInfo
42 {
43   GtkTextUtilCharChosenFunc func;
44   gpointer data;
45 };
46
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 }
58 };
59
60 static void
61 activate_cb (GtkWidget *menu_item,
62              gpointer   data)
63 {
64   GtkUnicodeMenuEntry *entry;
65   GtkTextUtilCallbackInfo *info = data;
66   char buf[7];
67   
68   entry = g_object_get_data (G_OBJECT (menu_item), "gtk-unicode-menu-entry");
69
70   buf[g_unichar_to_utf8 (entry->ch, buf)] = '\0';
71   
72   (* info->func) (buf, info->data);
73 }
74
75 /**
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
80  * 
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.
84  *
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.
89  **/
90 void
91 _gtk_text_util_append_special_char_menuitems (GtkMenuShell              *menushell,
92                                               GtkTextUtilCharChosenFunc  func,
93                                               gpointer                   data)
94 {
95   int i;
96   
97   for (i = 0; i < G_N_ELEMENTS (bidi_menu_entries); i++)
98     {
99       GtkWidget *menuitem;
100       GtkTextUtilCallbackInfo *info;
101
102       /* wasteful to have a bunch of copies, but simplifies mem management */
103       info = g_new (GtkTextUtilCallbackInfo, 1);
104       info->func = func;
105       info->data = data;
106       
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]);
110       
111       g_signal_connect_data (menuitem, "activate",
112                              G_CALLBACK (activate_cb),
113                              info, (GClosureNotify) g_free, 0);
114       
115       gtk_widget_show (menuitem);
116       gtk_menu_shell_append (menushell, menuitem);
117     }
118 }
119