| 1 |
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ |
| 2 |
/* vim:set et ts=4: */ |
| 3 |
/* ibus - The Input Bus |
| 4 |
* Copyright (C) 2008-2010 Peng Huang <[email protected]> |
| 5 |
* Copyright (C) 2008-2020 Red Hat, Inc. |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2.1 of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public |
| 18 |
* License along with this library; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 20 |
* USA |
| 21 |
*/ |
| 22 |
|
| 23 |
#include <gtk/gtk.h> |
| 24 |
#include <gtk/gtkimmodule.h> |
| 25 |
#include <ibus.h> |
| 26 |
#include "ibusimcontext.h" |
| 27 |
|
| 28 |
#define IBUS_LOCALDIR "" |
| 29 |
static const GtkIMContextInfo ibus_im_info = { |
| 30 |
"ibus", |
| 31 |
"IBus (Intelligent Input Bus)", |
| 32 |
"ibus", |
| 33 |
IBUS_LOCALDIR, |
| 34 |
"ja:ko:zh:*" |
| 35 |
}; |
| 36 |
|
| 37 |
static const GtkIMContextInfo *info_list[] = { |
| 38 |
&ibus_im_info |
| 39 |
}; |
| 40 |
|
| 41 |
G_MODULE_EXPORT const gchar* |
| 42 |
g_module_check_init (GModule *module) |
| 43 |
{ |
| 44 |
return NULL; |
| 45 |
} |
| 46 |
|
| 47 |
G_MODULE_EXPORT void |
| 48 |
im_module_init (GTypeModule *type_module) |
| 49 |
{ |
| 50 |
/* make module resident */ |
| 51 |
g_type_module_use (type_module); |
| 52 |
ibus_init (); |
| 53 |
ibus_im_context_register_type (type_module); |
| 54 |
} |
| 55 |
|
| 56 |
G_MODULE_EXPORT void |
| 57 |
im_module_exit (void) |
| 58 |
{ |
| 59 |
} |
| 60 |
|
| 61 |
G_MODULE_EXPORT GtkIMContext * |
| 62 |
im_module_create (const gchar *context_id) |
| 63 |
{ |
| 64 |
if (g_strcmp0 (context_id, "ibus") == 0) { |
| 65 |
IBusIMContext *context; |
| 66 |
context = ibus_im_context_new (); |
| 67 |
return (GtkIMContext *) context; |
| 68 |
} |
| 69 |
return NULL; |
| 70 |
} |
| 71 |
|
| 72 |
G_MODULE_EXPORT void |
| 73 |
im_module_list (const GtkIMContextInfo ***contexts, |
| 74 |
gint *n_contexts) |
| 75 |
{ |
| 76 |
*contexts = info_list; |
| 77 |
*n_contexts = G_N_ELEMENTS (info_list); |
| 78 |
} |
| 79 |
|
| 80 |
G_MODULE_EXPORT const char * |
| 81 |
im_get_context_id (int *argc, |
| 82 |
char ***argv) |
| 83 |
{ |
| 84 |
GtkIMContext *context; |
| 85 |
char *preedit_string = NULL; |
| 86 |
PangoAttrList *preedit_attrs = NULL; |
| 87 |
const char *context_id; |
| 88 |
|
| 89 |
gtk_init (argc, argv); |
| 90 |
context = gtk_im_multicontext_new (); |
| 91 |
gtk_im_context_get_preedit_string (context, |
| 92 |
&preedit_string, |
| 93 |
&preedit_attrs, |
| 94 |
0); |
| 95 |
context_id = gtk_im_multicontext_get_context_id ( |
| 96 |
GTK_IM_MULTICONTEXT (context)); |
| 97 |
return context_id; |
| 98 |
} |
| 99 |
|