2d377116bfe137552c64f72f7c91b3a805d99950
[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 GType type_mim = 0;
17
18 static gboolean
19 mim_filter_keypress(GtkIMContext *context,
20                     GdkEventKey *event)
21 {
22     if (event->type == GDK_KEY_RELEASE)
23         return FALSE;
24
25     return TRUE;
26 }
27
28 static void
29 mim_set_client_window(GtkIMContext *context,
30                       GdkWindow *window)
31 {
32     if (window == NULL) {
33         /*TODO: create new client window */
34         //mim_mui_create_window();
35     }
36 }
37
38 static void
39 mim_reset(GtkIMContext *context)
40 {
41 }
42
43 static void
44 mim_class_init(GtkIMContextClass *clazz)
45 {
46     clazz->filter_keypress = mim_filter_keypress;
47     clazz->reset = mim_reset;
48     clazz->set_client_window = mim_set_client_window;
49 }
50
51 static void
52 mim_init(GtkIMContext *im_context)
53 {
54 }
55
56 static void
57 mim_register_type(GTypeModule *module)
58 {
59     static const GTypeInfo object_info =
60     {
61         sizeof(GtkIMContextClass),
62         (GBaseInitFunc) NULL,
63         (GBaseFinalizeFunc) NULL,
64         (GClassInitFunc) mim_class_init,
65         NULL, /* class_finalize */
66         NULL, /* class_data */
67         sizeof(GtkIMContext),
68         0,
69         (GInstanceInitFunc) mim_init,
70     };
71
72     type_mim = g_type_module_register_type(module,
73                                            GTK_TYPE_IM_CONTEXT,
74                                            "GtkIMContextYiddishNoah",
75                                            &object_info,
76                                            0);
77 }
78
79 static const
80 GtkIMContextInfo mim_info =
81 {
82     "mim", /* ID */
83     N_("MiM"), /* Human readable name */
84     GETTEXT_PACKAGE, /* Translation domain */
85     LOCALEDIR, /* Dir for bindtextdomain */
86     "zh_CN", /* Languages for which this module is the default */
87 };
88
89 static const
90 GtkIMContextInfo *info_list[] =
91 {
92     &mim_info,
93 };
94
95 void
96 im_module_init(GTypeModule *module)
97 {
98     g_debug("mim-immodule imported!");
99     mim_register_type(module);
100     /*TODO: Mask off the accelerators, except the CTRL (need for CTRL
101      * ^SPACE) */
102 }
103
104 void
105 im_module_exit()
106 {
107     g_debug("mim-immodule released!");
108 }
109
110 void
111 im_module_list(const GtkIMContextInfo ***contexts,
112                gint *n_contexts)
113 {
114     *contexts = info_list;
115     *n_contexts = G_N_ELEMENTS(info_list);
116 }
117
118 GtkIMContext *
119 im_module_create(const gchar *context_id)
120 {
121     if (strcmp(context_id, "mim") == 0)
122         return GTK_IM_CONTEXT(g_object_new(type_mim, NULL));
123     else
124         return NULL;
125 }
126