コード例 #1
0
ファイル: nimf-m17n.c プロジェクト: cogniti/nimf
static void
nimf_m17n_open_im (NimfM17n *m17n)
{
  g_debug (G_STRLOC ": %s", G_STRFUNC);

  gchar **strv;

  m17n->preedit = g_strdup ("");
  m17n->preedit_attrs[0] = nimf_preedit_attr_new (NIMF_PREEDIT_ATTR_UNDERLINE, 0, 0);
  m17n->preedit_attrs[0]->type = NIMF_PREEDIT_ATTR_UNDERLINE;
  m17n->preedit_attrs[0]->start_index = 0;
  m17n->preedit_attrs[0]->end_index   = 0;
  m17n->preedit_attrs[1] = NULL;

  M17N_INIT();

  strv = g_strsplit (m17n->method, ":", 2);

  if (g_strv_length (strv) > 1)
  {
    m17n->im = minput_open_im (msymbol (strv[0]), msymbol (strv[1]), NULL);

    if (m17n->im)
    {
      mplist_put (m17n->im->driver.callback_list,
                  Minput_get_surrounding_text, on_get_surrounding_text);
      mplist_put (m17n->im->driver.callback_list,
                  Minput_delete_surrounding_text, on_delete_surrounding_text);
      m17n->ic = minput_create_ic (m17n->im, m17n);
      m17n->converter = mconv_buffer_converter (Mcoding_utf_8, NULL, 0);
    }
  }

  g_strfreev (strv);

  g_return_if_fail (m17n->im != NULL);
}
コード例 #2
0
ファイル: engine.c プロジェクト: Nomad280279/ibus-m17n
static GObject*
ibus_m17n_engine_constructor (GType                   type,
                              guint                   n_construct_params,
                              GObjectConstructParam  *construct_params)
{
    IBusM17NEngine *m17n;
    GObjectClass *object_class;
    IBusM17NEngineClass *klass;

    m17n = (IBusM17NEngine *) G_OBJECT_CLASS (parent_class)->constructor (type,
                                                       n_construct_params,
                                                       construct_params);

    object_class = G_OBJECT_GET_CLASS (m17n);
    klass = (IBusM17NEngineClass *) object_class;
    if (klass->im == NULL) {
        const gchar *engine_name;
        gchar *lang = NULL, *name = NULL;

        engine_name = ibus_engine_get_name ((IBusEngine *) m17n);
        if (!ibus_m17n_scan_engine_name (engine_name, &lang, &name)) {
            g_free (lang);
            g_free (name);
            return NULL;
        }

        klass->im = minput_open_im (msymbol (lang), msymbol (name), NULL);
        g_free (lang);
        g_free (name);

        if (klass->im == NULL) {
            g_warning ("Can not find m17n keymap %s", engine_name);
            g_object_unref (m17n);
            return NULL;
        }

        mplist_put (klass->im->driver.callback_list, Minput_preedit_start, ibus_m17n_engine_callback);
        mplist_put (klass->im->driver.callback_list, Minput_preedit_draw, ibus_m17n_engine_callback);
        mplist_put (klass->im->driver.callback_list, Minput_preedit_done, ibus_m17n_engine_callback);
        mplist_put (klass->im->driver.callback_list, Minput_status_start, ibus_m17n_engine_callback);
        mplist_put (klass->im->driver.callback_list, Minput_status_draw, ibus_m17n_engine_callback);
        mplist_put (klass->im->driver.callback_list, Minput_status_done, ibus_m17n_engine_callback);
        mplist_put (klass->im->driver.callback_list, Minput_candidates_start, ibus_m17n_engine_callback);
        mplist_put (klass->im->driver.callback_list, Minput_candidates_draw, ibus_m17n_engine_callback);
        mplist_put (klass->im->driver.callback_list, Minput_candidates_done, ibus_m17n_engine_callback);
        mplist_put (klass->im->driver.callback_list, Minput_set_spot, ibus_m17n_engine_callback);
        mplist_put (klass->im->driver.callback_list, Minput_toggle, ibus_m17n_engine_callback);
        /*
          Does not set reset callback, uses the default callback in m17n.
          mplist_put (klass->im->driver.callback_list, Minput_reset, ibus_m17n_engine_callback);
        */
        mplist_put (klass->im->driver.callback_list, Minput_get_surrounding_text, ibus_m17n_engine_callback);
        mplist_put (klass->im->driver.callback_list, Minput_delete_surrounding_text, ibus_m17n_engine_callback);
    }

    m17n->context = minput_create_ic (klass->im, m17n);

    return (GObject *) m17n;
}