GNOME Bugzilla – Bug 63495
Bidi control menu for textviewer and entry
Last modified: 2011-02-04 16:09:32 UTC
The following patch adds another submenu to the textview and the entry right button MenuShell. This submenu contains Bidi Control characters. Selecting an entry from the menu, inserts the unicode character into the buffer. diff -P -N -X /home/dov/etc/diff-exclude -u -r gtk+-1.3.10.org/gtk/Makefile.am gtk+-1.3.10/gtk/Makefile.am --- gtk+-1.3.10.org/gtk/Makefile.am Tue Oct 23 11:01:33 2001 +++ gtk+-1.3.10/gtk/Makefile.am Tue Oct 30 23:33:02 2001 @@ -199,6 +199,7 @@ gtktreedatalist.h \ gtktreeprivate.h \ gtkwindow-decorate.h \ + gtkbidicontrol.h \ @STRIP_END@ # GTK+ C sources to build the library from gtk_c_sources = @STRIP_BEGIN@ \ @@ -209,6 +210,7 @@ gtkalignment.c \ gtkarrow.c \ gtkaspectframe.c \ + gtkbidicontrol.c \ gtkbin.c \ gtkbindings.c \ gtkbbox.c \ diff -P -N -X /home/dov/etc/diff-exclude -u -r gtk+-1.3.10.org/gtk/gtkbidicontrol.c gtk+-1.3.10/gtk/gtkbidicontrol.c --- gtk+-1.3.10.org/gtk/gtkbidicontrol.c Wed Dec 31 19:00:00 1969 +++ gtk+-1.3.10/gtk/gtkbidicontrol.c Wed Oct 31 22:32:42 2001 @@ -0,0 +1,109 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2000 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <string.h> +#include <locale.h> + +#include "gtkintl.h" +#include "gtksignal.h" +#include "gtkwidget.h" +#include "gtkmenuitem.h" +#include "gtkmenushell.h" +#include "gdk/gdkkeysyms.h" + +#define UNI_MASK 0x01000000 + +typedef struct { + char *label; + gunichar ch; +} bidi_chars_t; + +bidi_chars_t bidi_chars[] = { + { N_("Left-to-Right Mark (LRM)"), 0x200E }, + { N_("Right-to-Left Mark (RLM)"), 0x200F }, + { N_("Left-to-Right Embed (LRE)"), 0x202A }, + { N_("Right-to-Left Embed (RLE)"), 0x202B }, + { N_("Left-to-Right Override (LRO)"), 0x202D }, + { N_("Right-to-Left Override (RLO)"), 0x202E }, + { N_("Pop Directional Formatting (PDF)"), 0x202C }, + { N_("Zero Width Space (ZWS)"), 0x200B }, + { N_("Zero Width Nonjoiner (ZWNJ)"), 0x200C }, + { N_("Zero Width Joiner (ZWN)"), 0x200D } }; +static int num_bidi_chars = sizeof(bidi_chars)/sizeof(bidi_chars_t); + +static void +activate_cb (GtkWidget *menuitem, + GtkWidget *widget) +{ + bidi_chars_t *bidi_ch = (bidi_chars_t*)gtk_object_get_data (GTK_OBJECT (menuitem), "uni-char"); + GdkEventKey key_event; + + /* Send the character to the widget */ + key_event.type = GDK_KEY_PRESS; + key_event.window = widget->window; + key_event.send_event = TRUE; /* ?? */ + key_event.time = 0; + key_event.state = 0; + key_event.keyval = UNI_MASK | bidi_ch->ch; /* Like U1234 in xkb. */ + key_event.length = 0; /* Do I need this */ + key_event.string = NULL; /* and this??? */ + + gdk_window_ref (widget->window); + gtk_widget_event(widget, (GdkEvent *)&key_event); + gdk_window_unref (widget->window); +} + +/** + * gtk_bidi_control_append_menuitems: + * @text_viewer: a #GtkTextViewer + * @menushell: a #GtkMenuShell + * + * Add menuitems for various bidi control characters to a menu; + * the menuitems, when selected, will input the character into + * the text viewer. + **/ +void +gtk_bidi_control_append_menuitems (GtkWidget *widget, + GtkMenuShell *menushell) +{ + int i; + GtkWidget *menuitem; + + menuitem = gtk_menu_item_new_with_label (_("Bidi Control Characters")); + gtk_widget_show (menuitem); + gtk_menu_shell_append (menushell, menuitem); + + menuitem = gtk_separator_menu_item_new (); + gtk_widget_show (menuitem); + gtk_menu_shell_append (menushell, menuitem); + + for (i=0; i < num_bidi_chars; i++) + { + menuitem = gtk_menu_item_new_with_label (bidi_chars[i].label); + gtk_object_set_data (GTK_OBJECT (menuitem), "uni-char", + (bidi_chars_t*)&bidi_chars[i]); + + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + G_CALLBACK (activate_cb), widget); + + gtk_widget_show (menuitem); + gtk_menu_shell_append (menushell, menuitem); + } +} + diff -P -N -X /home/dov/etc/diff-exclude -u -r gtk+-1.3.10.org/gtk/gtkbidicontrol.h gtk+-1.3.10/gtk/gtkbidicontrol.h --- gtk+-1.3.10.org/gtk/gtkbidicontrol.h Wed Dec 31 19:00:00 1969 +++ gtk+-1.3.10/gtk/gtkbidicontrol.h Tue Oct 30 23:33:24 2001 @@ -0,0 +1,39 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2000 Red Hat Software + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GTK_BIDI_CONTROL_H__ +#define __GTK_BIDI_CONTROL_H__ + +#include <gtk/gtktextview.h> +#include <gtk/gtkmenushell.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +void +gtk_bidi_control_append_menuitems (GtkWidget *widget, + GtkMenuShell *menushell); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + + +#endif /* __GTK_BIDI_CONTROL_H__ */ + diff -P -N -X /home/dov/etc/diff-exclude -u -r gtk+-1.3.10.org/gtk/gtkentry.c gtk+-1.3.10/gtk/gtkentry.c --- gtk+-1.3.10.org/gtk/gtkentry.c Wed Oct 24 10:11:34 2001 +++ gtk+-1.3.10/gtk/gtkentry.c Wed Oct 31 00:31:04 2001 @@ -36,6 +36,7 @@ #include "gtkentry.h" #include "gtkimagemenuitem.h" #include "gtkimmulticontext.h" +#include "gtkbidicontrol.h" #include "gtkintl.h" #include "gtkmain.h" #include "gtkmenu.h" @@ -3809,6 +3810,21 @@ gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (entry->im_context), GTK_MENU_SHELL (submenu)); + + /* Bidi control characters */ + menuitem = gtk_separator_menu_item_new (); + gtk_widget_show (menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem); + + menuitem = gtk_menu_item_new_with_label (_("BiDi Control")); + gtk_widget_show (menuitem); + submenu = gtk_menu_new (); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu); + gtk_menu_shell_append (GTK_MENU_SHELL (entry->popup_menu), menuitem); + + gtk_bidi_control_append_menuitems(GTK_WIDGET(entry), + GTK_MENU_SHELL(submenu)); + /* End BiDi */ gtk_signal_emit (GTK_OBJECT (entry), signals[POPULATE_POPUP], diff -P -N -X /home/dov/etc/diff-exclude -u -r gtk+-1.3.10.org/gtk/gtktextview.c gtk+-1.3.10/gtk/gtktextview.c --- gtk+-1.3.10.org/gtk/gtktextview.c Thu Oct 25 16:35:27 2001 +++ gtk+-1.3.10/gtk/gtktextview.c Wed Oct 31 00:31:35 2001 @@ -41,6 +41,7 @@ #include "gtktextdisplay.h" #include "gtktextview.h" #include "gtkimmulticontext.h" +#include "gtkbidicontrol.h" #include "gdk/gdkkeysyms.h" #include <string.h> @@ -3264,7 +3265,7 @@ GtkTextView *text_view = GTK_TEXT_VIEW (widget); GtkTextMark *insert; GtkTextIter iter; - + if (text_view->layout == NULL || get_buffer (text_view) == NULL) return FALSE; @@ -5569,6 +5570,21 @@ gtk_im_multicontext_append_menuitems (GTK_IM_MULTICONTEXT (text_view->im_context), GTK_MENU_SHELL (submenu)); + /* Bidi control characters */ + menuitem = gtk_separator_menu_item_new (); + gtk_widget_show (menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem); + + menuitem = gtk_menu_item_new_with_label (_("BiDi Control")); + gtk_widget_show (menuitem); + submenu = gtk_menu_new (); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu); + gtk_menu_shell_append (GTK_MENU_SHELL (text_view->popup_menu), menuitem); + + gtk_bidi_control_append_menuitems(GTK_WIDGET(text_view), + GTK_MENU_SHELL(submenu)); + /* End BiDi */ + gtk_signal_emit (GTK_OBJECT (text_view), signals[POPULATE_POPUP], text_view->popup_menu);
This will need to be private API in 2.0 I believe. There must be a way to keep this and the input method menu out of the right-click menu for locales that don't use them; I don't think Windows XP has this stuff in English/Latin locales, does it?
This patch has been incorporated in gtk+-1.3.12 .