1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2 -*- */
2 /* IM-JA Japanese Input Method Module for GTK-2.0
3  *
4  * Copyright (C) 2003 Botond Botyanszki <boti@rocketmail.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 
23 
24 #ifndef _IM_JA_H_
25 #define _IM_JA_H_
26 
27 #include <gtk/gtk.h>
28 #include <gconf/gconf-client.h>
29 
30 #ifdef IMJA_TARGET_XIM
31 # include "xim/xim-ic-types.h"
32 #endif
33 
34 #define BUFFERSIZE 1024
35 
36 #ifdef IMJA_TARGET_GTK
37 extern GType type_im_ja_context;
38 # define TYPE_IM_JA_CONTEXT              type_im_ja_context
39 #else /* XIM */
40 # define TYPE_IM_JA_CONTEXT              (im_ja_context_get_type())
41 #endif
42 
43 #define IM_JA_CONTEXT(obj)              (GTK_CHECK_CAST ((obj), TYPE_IM_JA_CONTEXT, IMJAContext))
44 
45 #define IM_JA_CONTEXT_CLASS(klass)      (GTK_CHECK_CLASS_CAST ((klass), TYPE_IM_JA_CONTEXT, IMJAContextClass))
46 #define IS_IM_JA_CONTEXT(obj)           (GTK_CHECK_TYPE ((obj), TYPE_IM_JA_CONTEXT))
47 #define IS_IM_JA_CONTEXT_CLASS(klass)   (GTK_CHECK_CLASS_TYPE ((klass), TYPE_IM_JA_CONTEXT))
48 #define IM_JA_CONTEXT_GET_CLASS(obj)    (GTK_CHECK_GET_CLASS ((obj), TYPE_IM_JA_CONTEXT, IMJAContextClass))
49 
50 /* Status widget types */
51 enum {
52   STATUS_BELOW_CURSOR,
53   STATUS_WINDOW_BOTTOM_LEFT,
54   STATUS_FIXED_COORD,
55   STATUS_DISABLED
56 };
57 
58 /* Candwin styles */
59 enum {
60 	CANDWIN_STYLE_MENU,
61 	CANDWIN_STYLE_TABLE
62 };
63 
64 /* Conversion engines */
65 enum {
66   CONV_ENGINE_CANNA,
67   CONV_ENGINE_WNN,
68   CONV_ENGINE_KANJIPAD,
69   CONV_ENGINE_ANTHY,
70   CONV_ENGINE_SKK,
71   CONV_ENGINE_NONE
72 };
73 
74 enum {
75   IM_JA_DIRECT_INPUT,
76   IM_JA_HIRAGANA_INPUT,
77   IM_JA_KATAKANA_INPUT,
78   IM_JA_HALFKATA_INPUT,
79   IM_JA_ZENKAKU_INPUT,
80   IM_JA_KANJIPAD_INPUT,
81 
82   IM_JA_INPUT_METHODS_TOTAL
83 };
84 
85 /* Keys */
86 enum {
87   START_CONFIGURATOR,
88   NEXT_INPUT_MODE,
89   PREV_INPUT_MODE,
90   DIRECT_INPUT_MODE,
91   HIRAGANA_INPUT_MODE,
92   KATAKANA_INPUT_MODE,
93   HALFKATA_INPUT_MODE,
94   ZENKAKU_INPUT_MODE,
95   CANNA_INPUT_MODE, /* deprecated */
96   WNN_INPUT_MODE,   /* deprecated */
97   KANJIPAD_INPUT_MODE,
98   UNCONVERT,
99   CONVERT,
100   PREV_CANDIDATE,
101   NEXT_CANDIDATE,
102   LIST_CANDIDATES,
103   PREV_BUNSETSU,
104   NEXT_BUNSETSU,
105   EXPAND_BUNSETSU,
106   SHRINK_BUNSETSU,
107   TOGGLE_PREEDIT_WINDOW,
108   COMMIT_PREEDIT,
109   SYMBOL_INPUT,
110   UNICODE_INPUT,
111   JIS_CODE_INPUT,
112 	RADICAL_INPUT,
113   HOTKEYS_TOTAL
114 };
115 
116 typedef struct _IMJAContext IMJAContext;
117 typedef struct _IMJAContextClass IMJAContextClass;
118 
119 #include "statuswin.h"
120 #include "preeditwin.h"
121 #include "candwin.h"
122 
123 #ifndef DISABLE_WNN
124 # include "wnn/wnn.h"
125 #endif
126 
127 #ifndef DISABLE_ANTHY
128 # include "anthy/anthy.h"
129 #endif
130 
131 #ifndef DISABLE_SKK
132 # include "skk/skkconv.h"
133 #endif
134 
135 struct _IMJAContextClass {
136 #ifdef IMJA_TARGET_GTK
137   GtkIMContextClass parent_class;
138 #else /* IMJA_TARGET_XIM */
139 	GObjectClass parent;
140 #endif
141 };
142 
143 struct _IMJAContext {
144 #ifdef IMJA_TARGET_GTK
145   GtkIMContext parent_object;
146 #else
147 	GObject parent;
148 #endif
149 
150 #ifdef IMJA_TARGET_XIM
151 	CARD16              id;               /* ic id */
152 	CARD16              connect_id;       /* connect id */
153 	INT32               input_style;      /* input style */
154 	Window              client_window;    /* client window */
155 	Window              focus_window;     /* focus window */
156 	char*               resource_name;    /* resource name */
157 	char*               resource_class;   /* resource class */
158 	StatusAttributes    status_attr;      /* status attributes */
159 	PreeditAttributes   preedit;          /* preedit attributes */
160 	IMJAXimConnect *connect;
161 	IMJAContext *next;
162 
163 	gchar *prev_preedit_buf;
164 #endif
165 #ifdef IMJA_TARGET_IIIMF
166 	void *iml_session;
167 #endif
168 
169 	gboolean finalized;
170 
171 #ifdef IMJA_TARGET_GTK
172   GdkWindow *client_gdk;
173   GtkWidget *client_gtk;
174   GdkWindow *toplevel_gdk;
175   GtkWidget *toplevel_gtk;
176 	gulong popup_signal_h;
177 	GtkWindowGroup *modal_grp;
178 #endif
179 
180   GtkWidget *kanjipad;
181 	StatusWin *status_win;
182 	PreeditWin *preedit_win;
183 	CandidateWin *candidate_win;
184 
185   gint candwin_pos_offset_x;
186   gint candwin_pos_offset_y;
187   gint preedit_win_pos_offset_x;
188   gint preedit_win_pos_offset_y;
189 	gint cursor_pos_offset_x;
190 	gint cursor_pos_offset_y;
191   gboolean update_candwin_pos;
192   gboolean update_preedit_pos;
193 
194 	GdkColor original_colors[2]; /* original client window widget style: fg and bg */
195 
196   GList *candidate_list;
197 
198 	gboolean show_first;
199   gboolean preedit_win_on;
200 	gint candwin_style;
201 
202   /* Preedit string */
203   gchar *preedit_buf;
204   gchar *preedit_insert;
205   gint preedit_reverse_start;
206   gint preedit_reverse_end;
207 
208   gint cursor_ndx;
209   gint cursor_char_pos; /* used by anthy and wnn */
210 
211   gint cand_stat;
212   gboolean show_candidates;
213 	gboolean has_focus;
214 
215 #ifndef DISABLE_WNN
216   wnnStat wnn_stat;
217 #endif
218 #ifndef DISABLE_ANTHY
219 	AnthyContext anthy_context;
220 #endif
221 #ifndef DISABLE_CANNA
222   void *canna_rk_ctx;
223 #endif
224 #ifndef DISABLE_SKK
225 	SKKContext *skk_ctx;
226 #endif
227 
228   gint input_method;
229 	gint conv_engine;
230 	gboolean conv_engine_initialized;
231 	GtkIMContext *simple_context;
232 
233 	/* conversion engine functions */
234 	void (*im_ja_conv_engine_reset_context) (IMJAContext *context);
235 	gboolean (*im_ja_conv_engine_filter_keypress) (IMJAContext *context, GdkEventKey *key);
236 	void (*im_ja_conv_engine_shutdown) (IMJAContext *context);
237 	void (*im_ja_conv_engine_select_candidate) (IMJAContext *context, gint selected);
238 	/*void (*im_ja_conv_engine_change_candidate) (IMJAContext *context, gint selected);*/
239 	void (*im_ja_conv_engine_update_preedit) (IMJAContext *context);
240 	void (*im_ja_conv_engine_commit) (IMJAContext *context);
241 
242 };
243 
244 /* Function prototypes */
245 IMJAContext *im_ja_context_new();
246 void im_ja_context_class_finalize(GObject *obj);
247 #ifndef IMJA_TARGET_GTK
248 GType im_ja_context_get_type(void);
249 #endif
250 void im_ja_context_init(IMJAContext *context);
251 void im_ja_next_input_method(IMJAContext *context);
252 void im_ja_prev_input_method(IMJAContext *context);
253 gboolean im_ja_set_input_method(IMJAContext *context, gint input_method);
254 void im_ja_context_reset(IMJAContext *context);
255 void im_ja_on_reset(IMJAContext *context);
256 void im_ja_set_preedit_string(IMJAContext *context, gchar *str, gint reverse_start, gint reverse_end);
257 void im_ja_free_candidate_list(IMJAContext *context);
258 void im_ja_input_utf8(IMJAContext *context, gchar *strg);
259 gboolean im_ja_init_conversion_engine(IMJAContext *cn);
260 void im_ja_cursor_location_changed(IMJAContext *context, gint x, gint y);
261 gboolean im_ja_filter_keypress(IMJAContext *context, GdkEventKey *key);
262 void im_ja_lost_focus(IMJAContext *context);
263 void im_ja_got_focus(IMJAContext *context);
264 void im_ja_run_configurator();
265 void im_ja_input_method_changed_cb(GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data);
266 void im_ja_set_use_preedit(IMJAContext *context, gboolean use_preedit);
267 gint im_ja_get_cursor_pos_chars(IMJAContext *context);
268 gint im_ja_get_cursor_pos_bytes(IMJAContext *context);
269 void im_ja_context_destroy(IMJAContext *context);
270 void im_ja_center_on_client_win(IMJAContext *context, GtkWindow *window);
271 void im_ja_move_within_rect(IMJAContext *cn, gint *target_x, gint *target_y, GdkRectangle *rect);
272 /*gboolean im_ja_is_cursor_over_window(GtkWidget *window);*/
273 void im_ja_join_modal_window(IMJAContext *cn, GtkWidget *window);
274 
275 #endif
276