Remove compose sequence from source, since MiM (Chinese input) need no such ways
[mim] / src / ui / mim-immodule.c
1 /*
2  * GTK+ MiM input module 
3  */
4
5 #ifdef HAVE_CONFIG_H
6 # include <config.h>
7 #endif
8
9 #include <gtk/gtkimcontext.h>
10 #include <gtk/gtkimmodule.h>
11 #include <gdk/gdkkeysyms.h>
12 #include <string.h>
13
14 #include "im-extra-intl.h"
15
16
17 GType type_mim = 0;
18
19 /* is this a character that could appear in a mim word */
20 static gboolean
21 is_mim_word_character (gunichar uc)
22 {
23   return (((uc >= 0x0590 && uc <= 0x5ff) || (uc >= 0xfb1d && uc <= 0xfb4f))
24           && g_unichar_isdefined (uc) && ! g_unichar_ispunct (uc));
25
26 }
27
28
29 static gboolean
30 at_initial_position (GtkIMContext *context)
31 {
32   gchar *text;
33   gchar *prevp;
34   gint cursor_index;
35   gunichar uc;
36
37   if (! gtk_im_context_get_surrounding (context, &text, &cursor_index))
38     return FALSE;
39
40   prevp = g_utf8_find_prev_char (text, text + cursor_index);
41   if (prevp == NULL)
42     return TRUE;
43
44   uc = g_utf8_get_char_validated (prevp, text + cursor_index - prevp);
45   g_return_val_if_fail (uc != (gunichar)(-1) && uc != (gunichar)(-2), 
46                         FALSE);
47
48   if (is_mim_word_character (uc))
49     return FALSE;
50   else
51     return TRUE;
52 }
53
54 static void
55 mim_reset (GtkIMContext *context)
56 {
57 }
58
59 static gboolean
60 mim_filter_keypress (GtkIMContext *context,
61                          GdkEventKey  *event)
62 {
63   gboolean is_initial;
64   gint i;
65
66   if (event->type == GDK_KEY_RELEASE)
67     return FALSE;
68
69   /* don't filter key events with accelerator modifiers held down */
70   if (event->state 
71       & (gtk_accelerator_get_default_mod_mask () & ~GDK_SHIFT_MASK))
72     return FALSE;
73
74   is_initial = at_initial_position (context);
75   return TRUE;
76 }
77
78
79 static void
80 mim_class_init (GtkIMContextClass *clazz)
81 {
82   clazz->filter_keypress = mim_filter_keypress;
83   clazz->reset = mim_reset;
84 }
85
86 static void
87 mim_init (GtkIMContext *im_context)
88 {
89 }
90
91
92 static void
93 mim_register_type (GTypeModule *module)
94 {
95   static const GTypeInfo object_info =
96   {
97     sizeof (GtkIMContextClass),
98     (GBaseInitFunc) NULL,
99     (GBaseFinalizeFunc) NULL,
100     (GClassInitFunc) mim_class_init,
101     NULL,           /* class_finalize */
102     NULL,           /* class_data */
103     sizeof (GtkIMContext),
104     0,
105     (GInstanceInitFunc) mim_init,
106   };
107
108   type_mim = 
109     g_type_module_register_type (module,
110                                  GTK_TYPE_IM_CONTEXT,
111                                  "GtkIMContextYiddishNoah",
112                                  &object_info, 0);
113 }
114
115
116 static const GtkIMContextInfo mim_info =
117 {
118   "mim",              /* ID */
119   N_("MiM"),          /* Human readable name */
120   GETTEXT_PACKAGE,    /* Translation domain */
121   LOCALEDIR,          /* Dir for bindtextdomain */
122   "zh_CN",            /* Languages for which this module is the default */
123 };
124
125
126 static const GtkIMContextInfo *info_list[] = 
127 {
128   &mim_info,
129 };
130
131
132 void
133 im_module_init (GTypeModule *module)
134 {
135   g_debug("mim-immodule imported!");
136   mim_register_type (module);
137 }
138
139 void
140 im_module_exit ()
141 {
142   g_debug("mim-immodule released!");
143 }
144
145 void 
146 im_module_list (const GtkIMContextInfo ***contexts, gint *n_contexts)
147 {
148   *contexts = info_list;
149   *n_contexts = G_N_ELEMENTS (info_list);
150 }
151
152
153 GtkIMContext *
154 im_module_create (const gchar *context_id)
155 {
156   if (strcmp (context_id, "mim-n") == 0)
157     return GTK_IM_CONTEXT (g_object_new (type_mim, NULL));
158   else
159     return NULL;
160 }
161
162
163