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