Comment fix
[mim] / src / ui / mim-immodule.c
index 1391e26..a9746f4 100644 (file)
@@ -1,11 +1,33 @@
-/*
- * GTK+ MiM input module 
- */
-
+/*********************************************************************
+**
+**  Copyright (C) 2009  MiM
+**
+**          Contact: Handspring <xhealer@gmail.com>
+**
+**          AUTHOR:
+**
+**  This file is part of MiM Pinyin.
+**
+**  This is free software: you can redistribute it and/or modify
+**  it under the terms of the GNU General Public License as published by
+**  the Free Software Foundation, either version 3 of the License, or
+**  (at your option) any later version.
+**
+**  This 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 General Public License for more details.
+**
+**  You should have received a copy of the GNU General Public License
+**  along with Sigil.  If not, see <http://www.gnu.org/licenses/>.
+**
+*********************************************************************/
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-
+/*
+ * GTK+ MiM input module 
+ */
 #include <gtk/gtkimcontext.h>
 #include <gtk/gtkimmodule.h>
 #include <gdk/gdkkeysyms.h>
 
 #include "im-extra-intl.h"
 
-
 GType type_mim = 0;
 
-/* is this a character that could appear in a mim word */
 static gboolean
-is_mim_word_character (gunichar uc)
+mim_filter_keypress(GtkIMContext *context,
+                    GdkEventKey *event)
 {
-  return (((uc >= 0x0590 && uc <= 0x5ff) || (uc >= 0xfb1d && uc <= 0xfb4f))
-          && g_unichar_isdefined (uc) && ! g_unichar_ispunct (uc));
+    if (event->type == GDK_KEY_RELEASE)
+        return FALSE;
 
-}
-
-
-static gboolean
-at_initial_position (GtkIMContext *context)
-{
-  gchar *text;
-  gchar *prevp;
-  gint cursor_index;
-  gunichar uc;
-
-  if (! gtk_im_context_get_surrounding (context, &text, &cursor_index))
-    return FALSE;
-
-  prevp = g_utf8_find_prev_char (text, text + cursor_index);
-  if (prevp == NULL)
-    return TRUE;
-
-  uc = g_utf8_get_char_validated (prevp, text + cursor_index - prevp);
-  g_return_val_if_fail (uc != (gunichar)(-1) && uc != (gunichar)(-2), 
-                        FALSE);
-
-  if (is_mim_word_character (uc))
-    return FALSE;
-  else
     return TRUE;
 }
 
 static void
-mim_reset (GtkIMContext *context)
+mim_set_client_window(GtkIMContext *context,
+                      GdkWindow *window)
 {
+    if (window == NULL) {
+        /*TODO: create new client window */
+        //mim_mui_create_window();
+    }
 }
 
-static gboolean
-mim_filter_keypress (GtkIMContext *context,
-                         GdkEventKey  *event)
+static void
+mim_reset(GtkIMContext *context)
 {
-  gboolean is_initial;
-  gint i;
-
-  if (event->type == GDK_KEY_RELEASE)
-    return FALSE;
-
-  /* don't filter key events with accelerator modifiers held down */
-  if (event->state 
-      & (gtk_accelerator_get_default_mod_mask () & ~GDK_SHIFT_MASK))
-    return FALSE;
-
-  is_initial = at_initial_position (context);
-  return TRUE;
 }
 
-
 static void
-mim_class_init (GtkIMContextClass *clazz)
+mim_class_init(GtkIMContextClass *clazz)
 {
-  clazz->filter_keypress = mim_filter_keypress;
-  clazz->reset = mim_reset;
+    clazz->filter_keypress = mim_filter_keypress;
+    clazz->reset = mim_reset;
+    clazz->set_client_window = mim_set_client_window;
 }
 
 static void
-mim_init (GtkIMContext *im_context)
+mim_init(GtkIMContext *im_context)
 {
 }
 
-
 static void
-mim_register_type (GTypeModule *module)
+mim_register_type(GTypeModule *module)
 {
-  static const GTypeInfo object_info =
-  {
-    sizeof (GtkIMContextClass),
-    (GBaseInitFunc) NULL,
-    (GBaseFinalizeFunc) NULL,
-    (GClassInitFunc) mim_class_init,
-    NULL,           /* class_finalize */
-    NULL,           /* class_data */
-    sizeof (GtkIMContext),
-    0,
-    (GInstanceInitFunc) mim_init,
-  };
-
-  type_mim = 
-    g_type_module_register_type (module,
-                                 GTK_TYPE_IM_CONTEXT,
-                                 "GtkIMContextYiddishNoah",
-                                 &object_info, 0);
+    static const GTypeInfo object_info =
+    {
+        sizeof(GtkIMContextClass),
+        (GBaseInitFunc) NULL,
+        (GBaseFinalizeFunc) NULL,
+        (GClassInitFunc) mim_class_init,
+        NULL, /* class_finalize */
+        NULL, /* class_data */
+        sizeof(GtkIMContext),
+        0,
+        (GInstanceInitFunc) mim_init,
+    };
+
+    type_mim = g_type_module_register_type(module,
+                                           GTK_TYPE_IM_CONTEXT,
+                                           "GtkIMContextYiddishNoah",
+                                           &object_info,
+                                           0);
 }
 
-
-static const GtkIMContextInfo mim_info =
+static const
+GtkIMContextInfo mim_info =
 {
-  "mim",              /* ID */
-  N_("MiM"),          /* Human readable name */
-  GETTEXT_PACKAGE,    /* Translation domain */
-  LOCALEDIR,          /* Dir for bindtextdomain */
-  "zh_CN",            /* Languages for which this module is the default */
+    "mim", /* ID */
+    N_("MiM"), /* Human readable name */
+    GETTEXT_PACKAGE, /* Translation domain */
+    LOCALEDIR, /* Dir for bindtextdomain */
+    "zh_CN", /* Languages for which this module is the default */
 };
 
-
-static const GtkIMContextInfo *info_list[] = 
+static const
+GtkIMContextInfo *info_list[] =
 {
-  &mim_info,
+    &mim_info,
 };
 
-
 void
-im_module_init (GTypeModule *module)
+im_module_init(GTypeModule *module)
 {
-  g_debug("mim-immodule imported!");
-  mim_register_type (module);
+    g_debug("mim-immodule imported!");
+    mim_register_type(module);
+    /*TODO: Mask off the accelerators, except the CTRL (need for CTRL
+     * ^SPACE) */
 }
 
 void
-im_module_exit ()
+im_module_exit()
 {
-  g_debug("mim-immodule released!");
+    g_debug("mim-immodule released!");
 }
 
-void 
-im_module_list (const GtkIMContextInfo ***contexts, gint *n_contexts)
+void
+im_module_list(const GtkIMContextInfo ***contexts,
+               gint *n_contexts)
 {
-  *contexts = info_list;
-  *n_contexts = G_N_ELEMENTS (info_list);
+    *contexts = info_list;
+    *n_contexts = G_N_ELEMENTS(info_list);
 }
 
-
 GtkIMContext *
-im_module_create (const gchar *context_id)
+im_module_create(const gchar *context_id)
 {
-  if (strcmp (context_id, "mim-n") == 0)
-    return GTK_IM_CONTEXT (g_object_new (type_mim, NULL));
-  else
-    return NULL;
+    if (strcmp(context_id, "mim") == 0)
+        return GTK_IM_CONTEXT(g_object_new(type_mim, NULL));
+    else
+        return NULL;
 }
 
-
-