1 /* ImHangul - Gtk+ 2.0 Input Method Module for Hangul
2  * Copyright (C) 2002 Choe Hwanjin
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22 
23 #include <string.h>
24 
25 #include <gtk/gtk.h>
26 #include <gtk/gtkimmodule.h>
27 
28 #include "gettext.h"
29 #include "gtkimcontexthangul.h"
30 
31 /* hangul keyboard list */
32 #define IM_HANGUL_CONTEXT_NAME_LIST 	    \
33     N_("Hangul Dubeolsik")		    \
34     N_("Hangul Dubeolsik Yetgeul")	    \
35     N_("Hangul Sebeolsik Dubeol Layout")    \
36     N_("Hangul Sebeolsik 390")		    \
37     N_("Hangul Sebeolsik Final")	    \
38     N_("Hangul Sebeolsik Noshift")	    \
39     N_("Hangul Sebeolsik Yetgeul")	    \
40     N_("Hangul Romaja")			    \
41     N_("Hangul Ahnmatae")
42 
43 /* xgettext 에서 ASCII 가 아닌 문자열이라고 워닝 나는 것을 방지하기 위해서
44  * 주석을 아래쪽에 단다.
45  *
46  * 키보드 이름의 번역을 위해서 여기에 사용하지 않는 매크로로 키보드 이름을
47  * 리스팅 한다.
48  * GTK+는 im_module_list() 함수로 지원하는 context 리스트를 얻은후 나중에
49  * 메뉴에 보여 줄때에는 그 스트링에 해당하는 번역 스트링을 각 모듈에서 지정한
50  * mo 파일에서 로딩을 시도한다. 따라서 키보드 이름에 해당하는 번역 스트링을
51  * imhangul의 mo 파일이 가지고 있어야 한다. 그러므로 imhangul이 libhangul의
52  * 키보드 리스트를 동적으로 얻는다 하더라도, po 파일에 추가할 스트링은
53  * 여기에 하드코딩할 수밖에 없다.
54  * 아래에 리스팅한 키보드 이름은 번역되어 나타나겠지만, 없는 것들은 번역이
55  * 안된상태로 메뉴에 나타나게 될 것이다.
56  */
57 
58 static GtkIMContext *im_hangul_new (const char *libhangul_id);
59 
60 /* 임의로 지원가능한 키보드 갯수를 16개로 잡는다. */
61 static gchar context_ids[16][16];
62 static gchar context_names[16][64];
63 static GtkIMContextInfo info_array[16];
64 static const GtkIMContextInfo *info_list[16];
65 
66 void
im_module_init(GTypeModule * type_module)67 im_module_init (GTypeModule *type_module)
68 {
69   gtk_im_context_hangul_register_type (type_module);
70   im_hangul_init();
71 }
72 
73 void
im_module_exit(void)74 im_module_exit (void)
75 {
76   im_hangul_finalize ();
77 }
78 
79 void
im_module_list(const GtkIMContextInfo *** contexts,int * n_contexts)80 im_module_list (const GtkIMContextInfo ***contexts,
81 		int *n_contexts)
82 {
83     int i;
84     int n;
85 
86     n = hangul_ic_get_n_keyboards();
87 
88     /* 일단 현재로서는 info_array 개수를 벗어난 것은 리스팅 하지 않는다. */
89     if (n > G_N_ELEMENTS(info_array))
90 	n = G_N_ELEMENTS(info_array);
91 
92     for (i = 0; i < n; ++i) {
93 	const char* id;
94 	const char* name;
95 	id = hangul_ic_get_keyboard_id(i);
96 	name = hangul_ic_get_keyboard_name(i);
97 	g_snprintf(context_ids[i], sizeof(context_ids[i]), "hangul%s", id);
98 	g_snprintf(context_names[i], sizeof(context_names[i]),
99 		    "Hangul %s", name);
100 	info_array[i].context_id = context_ids[i];
101 	info_array[i].context_name = context_names[i];
102 	info_array[i].domain = GETTEXT_PACKAGE;
103 	info_array[i].domain_dirname = IM_HANGUL_LOCALEDIR;
104 	if (strcmp(id, DEFAULT_KEYBOARD_ID) == 0)
105 	    info_array[i].default_locales = "ko";
106 	else
107 	    info_array[i].default_locales = "";
108 	info_list[i] = &info_array[i];
109     }
110 
111     *contexts = info_list;
112     *n_contexts = n;
113 }
114 
115 GtkIMContext *
im_module_create(const gchar * context_id)116 im_module_create (const gchar *context_id)
117 {
118     if (strncmp(context_id, "hangul", 6) == 0) {
119 	const char *id = context_id + 6;
120 	return im_hangul_new(id);
121     }
122 
123     g_warning("imhangul:unknown context id: %s", context_id);
124     g_assert_not_reached();
125 
126     return NULL;
127 }
128 
129 static GtkIMContext *
im_hangul_new(const char * libhangul_id)130 im_hangul_new (const char *libhangul_id)
131 {
132   GtkIMContext *context = gtk_im_context_hangul_new ();
133   GtkIMContextHangul *hcontext = GTK_IM_CONTEXT_HANGUL (context);
134 
135   gtk_im_context_hangul_select_keyboard(hcontext, libhangul_id);
136 
137   return context;
138 }
139 
140 /* vim: set sw=2 : */
141