svn update: 48958 (latest:48959)
[framework/uifw/ecore.git] / src / lib / ecore_imf / Ecore_IMF.h
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4
5 #ifndef _ECORE_IMF_H
6 #define _ECORE_IMF_H
7
8 #include <Eina.h>
9
10 #ifdef EAPI
11 # undef EAPI
12 #endif
13
14 #ifdef _WIN32
15 # ifdef EFL_ECORE_IMF_BUILD
16 #  ifdef DLL_EXPORT
17 #   define EAPI __declspec(dllexport)
18 #  else
19 #   define EAPI
20 #  endif /* ! DLL_EXPORT */
21 # else
22 #  define EAPI __declspec(dllimport)
23 # endif /* ! EFL_ECORE_IMF_BUILD */
24 #else
25 # ifdef __GNUC__
26 #  if __GNUC__ >= 4
27 #   define EAPI __attribute__ ((visibility("default")))
28 #  else
29 #   define EAPI
30 #  endif
31 # else
32 #  define EAPI
33 # endif
34 #endif /* ! _WIN32 */
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40    /* Events sent by the Input Method */
41    typedef struct _Ecore_IMF_Event_Preedit_Start      Ecore_IMF_Event_Preedit_Start;
42    typedef struct _Ecore_IMF_Event_Preedit_End        Ecore_IMF_Event_Preedit_End;
43    typedef struct _Ecore_IMF_Event_Preedit_Changed    Ecore_IMF_Event_Preedit_Changed;
44    typedef struct _Ecore_IMF_Event_Commit             Ecore_IMF_Event_Commit;
45    typedef struct _Ecore_IMF_Event_Delete_Surrounding Ecore_IMF_Event_Delete_Surrounding;
46
47    /* Events to filter */
48    typedef struct _Ecore_IMF_Event_Mouse_Down         Ecore_IMF_Event_Mouse_Down;
49    typedef struct _Ecore_IMF_Event_Mouse_Up           Ecore_IMF_Event_Mouse_Up;
50    typedef struct _Ecore_IMF_Event_Mouse_In           Ecore_IMF_Event_Mouse_In;
51    typedef struct _Ecore_IMF_Event_Mouse_Out          Ecore_IMF_Event_Mouse_Out;
52    typedef struct _Ecore_IMF_Event_Mouse_Move         Ecore_IMF_Event_Mouse_Move;
53    typedef struct _Ecore_IMF_Event_Mouse_Wheel        Ecore_IMF_Event_Mouse_Wheel;
54    typedef struct _Ecore_IMF_Event_Key_Down           Ecore_IMF_Event_Key_Down;
55    typedef struct _Ecore_IMF_Event_Key_Up             Ecore_IMF_Event_Key_Up;
56    typedef union  _Ecore_IMF_Event                    Ecore_IMF_Event;
57
58    typedef struct _Ecore_IMF_Context                  Ecore_IMF_Context;                  /**< An Input Method Context */
59    typedef struct _Ecore_IMF_Context_Class            Ecore_IMF_Context_Class;            /**< An Input Method Context class */
60    typedef struct _Ecore_IMF_Context_Info             Ecore_IMF_Context_Info;             /**< An Input Method Context info */
61
62    EAPI extern int ECORE_IMF_EVENT_PREEDIT_START;
63    EAPI extern int ECORE_IMF_EVENT_PREEDIT_END;
64    EAPI extern int ECORE_IMF_EVENT_PREEDIT_CHANGED;
65    EAPI extern int ECORE_IMF_EVENT_COMMIT;
66    EAPI extern int ECORE_IMF_EVENT_DELETE_SURROUNDING;
67
68    typedef enum
69      {
70         ECORE_IMF_EVENT_MOUSE_DOWN,
71         ECORE_IMF_EVENT_MOUSE_UP,
72         ECORE_IMF_EVENT_MOUSE_IN,
73         ECORE_IMF_EVENT_MOUSE_OUT,
74         ECORE_IMF_EVENT_MOUSE_MOVE,
75         ECORE_IMF_EVENT_MOUSE_WHEEL,
76         ECORE_IMF_EVENT_KEY_DOWN,
77         ECORE_IMF_EVENT_KEY_UP
78      } Ecore_IMF_Event_Type;
79
80    typedef enum
81      {
82         ECORE_IMF_KEYBOARD_MODIFIER_NONE  = 0,      /**< No active modifiers */
83         ECORE_IMF_KEYBOARD_MODIFIER_CTRL  = 1 << 0, /**< "Control" is pressed */
84         ECORE_IMF_KEYBOARD_MODIFIER_ALT   = 1 << 1, /**< "Alt" is pressed */
85         ECORE_IMF_KEYBOARD_MODIFIER_SHIFT = 1 << 2, /**< "Shift" is pressed */
86         ECORE_IMF_KEYBOARD_MODIFIER_WIN   = 1 << 3  /**< "Win" (between "Ctrl" and "Alt") is pressed */
87      } Ecore_IMF_Keyboard_Modifiers;
88
89    typedef enum
90      {
91         ECORE_IMF_KEYBOARD_LOCK_NONE      = 0,      /**< No locks are active */
92         ECORE_IMF_KEYBOARD_LOCK_NUM       = 1 << 0, /**< "Num" lock is active */
93         ECORE_IMF_KEYBOARD_LOCK_CAPS      = 1 << 1, /**< "Caps" lock is active */
94         ECORE_IMF_KEYBOARD_LOCK_SCROLL    = 1 << 2  /**< "Scroll" lock is active */
95      } Ecore_IMF_Keyboard_Locks;
96
97    typedef enum
98      {
99         ECORE_IMF_MOUSE_NONE              = 0,      /**< A single click */
100         ECORE_IMF_MOUSE_DOUBLE_CLICK      = 1 << 0, /**< A double click */
101         ECORE_IMF_MOUSE_TRIPLE_CLICK      = 1 << 1  /**< A triple click */
102      } Ecore_IMF_Mouse_Flags;
103
104    typedef enum
105      {
106         ECORE_IMF_INPUT_MODE_ALPHA        = 1 << 0,
107         ECORE_IMF_INPUT_MODE_NUMERIC      = 1 << 1,
108         ECORE_IMF_INPUT_MODE_SPECIAL      = 1 << 2,
109         ECORE_IMF_INPUT_MODE_HEXA         = 1 << 3,
110         ECORE_IMF_INPUT_MODE_TELE         = 1 << 4,
111         ECORE_IMF_INPUT_MODE_FULL         = (ECORE_IMF_INPUT_MODE_ALPHA | ECORE_IMF_INPUT_MODE_NUMERIC | ECORE_IMF_INPUT_MODE_SPECIAL),
112         ECORE_IMF_INPUT_MODE_INVISIBLE    = 1 << 29,
113         ECORE_IMF_INPUT_MODE_AUTOCAP      = 1 << 30
114      } Ecore_IMF_Input_Mode;
115
116    struct _Ecore_IMF_Event_Preedit_Start
117      {
118         Ecore_IMF_Context *ctx;
119      };
120
121    struct _Ecore_IMF_Event_Preedit_End
122      {
123         Ecore_IMF_Context *ctx;
124      };
125
126    struct _Ecore_IMF_Event_Preedit_Changed
127      {
128         Ecore_IMF_Context *ctx;
129      };
130
131    struct _Ecore_IMF_Event_Commit
132      {
133         Ecore_IMF_Context *ctx;
134         char *str;
135      };
136
137    struct _Ecore_IMF_Event_Delete_Surrounding
138      {
139         Ecore_IMF_Context *ctx;
140         int offset;
141         int n_chars;
142      };
143
144    struct _Ecore_IMF_Event_Mouse_Down
145      {
146         int button;                             /**< The button which has been pressed */
147         struct {
148              int x, y;
149         } output;
150         struct {
151              int x, y;
152         } canvas;
153         Ecore_IMF_Keyboard_Modifiers modifiers; /**< The keyboard modifiers active when the event has been emitted */
154         Ecore_IMF_Keyboard_Locks     locks;     /**< The keyboard locks active when the event has been emitted */
155         Ecore_IMF_Mouse_Flags        flags;     /**< The flags corresponding the mouse click (single, double or triple click) */
156         unsigned int                 timestamp; /**< The timestamp when the event occured */
157      };
158
159    struct _Ecore_IMF_Event_Mouse_Up
160      {
161         int button;                             /**< The button which has been pressed */
162         struct {
163              int x, y;
164         } output;
165         struct {
166              int x, y;
167         } canvas;
168         Ecore_IMF_Keyboard_Modifiers modifiers; /**< The keyboard modifiers active when the event has been emitted */
169         Ecore_IMF_Keyboard_Locks     locks;     /**< The keyboard locks active when the event has been emitted */
170         Ecore_IMF_Mouse_Flags        flags;     /**< The flags corresponding the mouse click (single, double or triple click) */
171         unsigned int                 timestamp; /**< The timestamp when the event occured */
172      };
173
174    struct _Ecore_IMF_Event_Mouse_In
175      {
176         int buttons;
177         struct {
178              int x, y;
179         } output;
180         struct {
181              int x, y;
182         } canvas;
183         Ecore_IMF_Keyboard_Modifiers modifiers; /**< The keyboard modifiers active when the event has been emitted */
184         Ecore_IMF_Keyboard_Locks     locks;     /**< The keyboard locks active when the event has been emitted */
185         unsigned int                 timestamp; /**< The timestamp when the event occured */
186      };
187
188    struct _Ecore_IMF_Event_Mouse_Out
189      {
190         int buttons;
191         struct {
192              int x, y;
193         } output;
194         struct {
195              int x, y;
196         } canvas;
197         Ecore_IMF_Keyboard_Modifiers modifiers; /**< The keyboard modifiers active when the event has been emitted */
198         Ecore_IMF_Keyboard_Locks     locks;     /**< The keyboard locks active when the event has been emitted */
199         unsigned int                 timestamp; /**< The timestamp when the event occured */
200      };
201
202    struct _Ecore_IMF_Event_Mouse_Move
203      {
204         int buttons;
205         struct {
206              struct {
207                   int x, y;
208              } output;
209              struct {
210                   int x, y;
211              } canvas;
212         } cur, prev;
213         Ecore_IMF_Keyboard_Modifiers modifiers; /**< The keyboard modifiers active when the event has been emitted */
214         Ecore_IMF_Keyboard_Locks     locks;     /**< The keyboard locks active when the event has been emitted */
215         unsigned int                 timestamp; /**< The timestamp when the event occured */
216      };
217
218    struct _Ecore_IMF_Event_Mouse_Wheel
219      {
220         int direction;                         /* 0 = default up/down wheel */
221         int z;                                 /* ...,-2,-1 = down, 1,2,... = up */
222         struct {
223              int x, y;
224         } output;
225         struct {
226              int x, y;
227         } canvas;
228         Ecore_IMF_Keyboard_Modifiers modifiers; /**< The keyboard modifiers active when the event has been emitted */
229         Ecore_IMF_Keyboard_Locks     locks;     /**< The keyboard locks active when the event has been emitted */
230         unsigned int                 timestamp; /**< The timestamp when the event occured */
231      };
232
233    struct _Ecore_IMF_Event_Key_Down
234      {
235         const char                  *keyname;   /**< The string name of the key pressed */
236         Ecore_IMF_Keyboard_Modifiers modifiers; /**< The keyboard modifiers active when the event has been emitted */
237         Ecore_IMF_Keyboard_Locks     locks;     /**< The keyboard locks active when the event has been emitted */
238         const char                  *key;       /**< The logical key : (eg shift+1 == exclamation) */
239         const char                  *string;    /**< A UTF8 string if this keystroke has produced a visible string to be ADDED */
240         const char                  *compose;   /**< A UTF8 string if this keystroke has modified a string in the middle of being composed - this string replaces the previous one */
241         unsigned int                 timestamp; /**< The timestamp when the event occured */
242    };
243
244    struct _Ecore_IMF_Event_Key_Up
245      {
246         const char                  *keyname;   /**< The string name of the key pressed */
247         Ecore_IMF_Keyboard_Modifiers modifiers; /**< The keyboard modifiers active when the event has been emitted */
248         Ecore_IMF_Keyboard_Locks     locks;     /**< The keyboard locks active when the event has been emitted */
249         const char                  *key;       /**< The logical key : (eg shift+1 == exclamation) */
250         const char                  *string;    /**< A UTF8 string if this keystroke has produced a visible string to be ADDED */
251         const char                  *compose;   /**< A UTF8 string if this keystroke has modified a string in the middle of being composed - this string replaces the previous one */
252         unsigned int                 timestamp; /**< The timestamp when the event occured */
253      };
254
255    union _Ecore_IMF_Event
256      {
257         Ecore_IMF_Event_Mouse_Down mouse_down;
258         Ecore_IMF_Event_Mouse_Up mouse_up;
259         Ecore_IMF_Event_Mouse_In mouse_in;
260         Ecore_IMF_Event_Mouse_Out mouse_out;
261         Ecore_IMF_Event_Mouse_Move mouse_move;
262         Ecore_IMF_Event_Mouse_Wheel mouse_wheel;
263         Ecore_IMF_Event_Key_Down key_down;
264         Ecore_IMF_Event_Key_Up key_up;
265      };
266
267    struct _Ecore_IMF_Context_Class
268      {
269         void (*add)                 (Ecore_IMF_Context *ctx);
270         void (*del)                 (Ecore_IMF_Context *ctx);
271         void (*client_window_set)   (Ecore_IMF_Context *ctx, void *window);
272         void (*client_canvas_set)   (Ecore_IMF_Context *ctx, void *canvas);
273         void (*show)                (Ecore_IMF_Context *ctx);
274         void (*hide)                (Ecore_IMF_Context *ctx);
275         void (*preedit_string_get)  (Ecore_IMF_Context *ctx, char **str, int *cursor_pos);
276         void (*focus_in)            (Ecore_IMF_Context *ctx);
277         void (*focus_out)           (Ecore_IMF_Context *ctx);
278         void (*reset)               (Ecore_IMF_Context *ctx);
279         void (*cursor_position_set) (Ecore_IMF_Context *ctx, int cursor_pos);
280         void (*use_preedit_set)     (Ecore_IMF_Context *ctx, int use_preedit);
281         void (*input_mode_set)      (Ecore_IMF_Context *ctx, Ecore_IMF_Input_Mode input_mode);
282         int  (*filter_event)        (Ecore_IMF_Context *ctx, Ecore_IMF_Event_Type type, Ecore_IMF_Event *event);
283      };
284
285    struct _Ecore_IMF_Context_Info
286      {
287         const char *id;              /* ID */
288         const char *description;     /* Human readable description */
289         const char *default_locales; /* Languages for which this context is the default, separated by : */
290         const char *canvas_type;     /* The canvas type used by the input method. Eg.: evas */
291         int         canvas_required; /* Whether the canvas usage is required for this input method */
292      };
293
294    EAPI int                           ecore_imf_init(void);
295    EAPI int                           ecore_imf_shutdown(void);
296
297    EAPI void                          ecore_imf_module_register(const Ecore_IMF_Context_Info *info, Ecore_IMF_Context *(*imf_module_create)(void), Ecore_IMF_Context *(*imf_module_exit)(void));
298
299    EAPI Eina_List                    *ecore_imf_context_available_ids_get(void);
300    EAPI Eina_List                    *ecore_imf_context_available_ids_by_canvas_type_get(const char *canvas_type);
301    EAPI const char                   *ecore_imf_context_default_id_get(void);
302    EAPI const char                   *ecore_imf_context_default_id_by_canvas_type_get(const char *canvas_type);
303    EAPI const Ecore_IMF_Context_Info *ecore_imf_context_info_by_id_get(const char *id);
304
305    EAPI Ecore_IMF_Context            *ecore_imf_context_add(const char *id);
306    EAPI const Ecore_IMF_Context_Info *ecore_imf_context_info_get(Ecore_IMF_Context *ctx);
307    EAPI void                          ecore_imf_context_del(Ecore_IMF_Context *ctx);
308    EAPI void                          ecore_imf_context_client_window_set(Ecore_IMF_Context *ctx, void *window);
309    EAPI void                          ecore_imf_context_client_canvas_set(Ecore_IMF_Context *ctx, void *canvas);
310    EAPI void                          ecore_imf_context_show(Ecore_IMF_Context *ctx);
311    EAPI void                          ecore_imf_context_hide(Ecore_IMF_Context *ctx);
312    EAPI void                          ecore_imf_context_preedit_string_get(Ecore_IMF_Context *ctx, char **str, int *cursor_pos);
313    EAPI void                          ecore_imf_context_focus_in(Ecore_IMF_Context *ctx);
314    EAPI void                          ecore_imf_context_focus_out(Ecore_IMF_Context *ctx);
315    EAPI void                          ecore_imf_context_reset(Ecore_IMF_Context *ctx);
316    EAPI void                          ecore_imf_context_cursor_position_set(Ecore_IMF_Context *ctx, int cursor_pos);
317    EAPI void                          ecore_imf_context_use_preedit_set(Ecore_IMF_Context *ctx, int use_preedit);
318    EAPI void                          ecore_imf_context_retrieve_surrounding_callback_set(Ecore_IMF_Context *ctx, int (*func)(void *data, Ecore_IMF_Context *ctx, char **text, int *cursor_pos), const void *data);
319    EAPI void                          ecore_imf_context_input_mode_set(Ecore_IMF_Context *ctx, Ecore_IMF_Input_Mode input_mode);
320    EAPI Ecore_IMF_Input_Mode          ecore_imf_context_input_mode_get(Ecore_IMF_Context *ctx);
321    EAPI int                           ecore_imf_context_filter_event(Ecore_IMF_Context *ctx, Ecore_IMF_Event_Type type, Ecore_IMF_Event *event);
322
323    /* plugin specific functions */
324    EAPI Ecore_IMF_Context            *ecore_imf_context_new(const Ecore_IMF_Context_Class *ctxc);
325    EAPI void                          ecore_imf_context_data_set(Ecore_IMF_Context *ctx, void *data);
326    EAPI void                         *ecore_imf_context_data_get(Ecore_IMF_Context *ctx);
327    EAPI int                           ecore_imf_context_surrounding_get(Ecore_IMF_Context *ctx, char **text, int *cursor_pos);
328    EAPI void                          ecore_imf_context_preedit_start_event_add(Ecore_IMF_Context *ctx);
329    EAPI void                          ecore_imf_context_preedit_end_event_add(Ecore_IMF_Context *ctx);
330    EAPI void                          ecore_imf_context_preedit_changed_event_add(Ecore_IMF_Context *ctx);
331    EAPI void                          ecore_imf_context_commit_event_add(Ecore_IMF_Context *ctx, const char *str);
332    EAPI void                          ecore_imf_context_delete_surrounding_event_add(Ecore_IMF_Context *ctx, int offset, int n_chars);
333
334    /* The following entry points must be exported by each input method module
335     */
336
337    /*
338     * int                imf_module_init   (const Ecore_IMF_Context_Info **info);
339     * void               imf_module_exit   (void);
340     * Ecore_IMF_Context *imf_module_create (void);
341     */
342
343 #ifdef __cplusplus
344 }
345 #endif
346
347 #endif