aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/lib/ecore_imf_evas/ecore_imf_evas.c
blob: 62ba4c86868f9fa74235ceba5f5cd738f6a30db3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "Ecore_IMF_Evas.h"

/**
 * @defgroup Ecore_IMF_Evas_Group Ecore Input Method Context Evas Helper Functions
 *
 * Helper functions to make it easy to use Evas with Ecore_IMF.
 */

static const char *_ecore_imf_evas_event_empty = "";

/* Converts the Evas modifiers to Ecore_IMF keyboard modifiers */
static void
_ecore_imf_evas_event_modifiers_wrap(Evas_Modifier *evas_modifiers,
                                     Ecore_IMF_Keyboard_Modifiers *imf_keyboard_modifiers)
{
   if (!evas_modifiers || !imf_keyboard_modifiers)
     return;

   *imf_keyboard_modifiers = ECORE_IMF_KEYBOARD_MODIFIER_NONE;
   if (evas_key_modifier_is_set(evas_modifiers, "Control"))
     *imf_keyboard_modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
   if (evas_key_modifier_is_set(evas_modifiers, "Alt"))
     *imf_keyboard_modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
   if (evas_key_modifier_is_set(evas_modifiers, "Shift"))
     *imf_keyboard_modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT;
   if (evas_key_modifier_is_set(evas_modifiers, "Super") || evas_key_modifier_is_set(evas_modifiers, "Hyper"))
     *imf_keyboard_modifiers |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
}

/* Converts the Evas locks to Ecore_IMF keyboard locks */
static void
_ecore_imf_evas_event_locks_wrap(Evas_Lock *evas_locks,
                                 Ecore_IMF_Keyboard_Locks *imf_keyboard_locks)
{
   if (!evas_locks || !imf_keyboard_locks)
     return;

   *imf_keyboard_locks = ECORE_IMF_KEYBOARD_LOCK_NONE;
   if (evas_key_lock_is_set(evas_locks, "Num_Lock"))
     *imf_keyboard_locks |= ECORE_IMF_KEYBOARD_LOCK_NUM;
   if (evas_key_lock_is_set(evas_locks, "Caps_Lock"))
     *imf_keyboard_locks |= ECORE_IMF_KEYBOARD_LOCK_CAPS;
   if (evas_key_lock_is_set(evas_locks, "Scroll_Lock"))
     *imf_keyboard_locks |= ECORE_IMF_KEYBOARD_LOCK_SCROLL;
}

/* Converts the Evas mouse flags to Ecore_IMF mouse flags */
static void
_ecore_imf_evas_event_mouse_flags_wrap(Evas_Button_Flags evas_flags,
                                       Ecore_IMF_Mouse_Flags *imf_flags)
{
   if (!imf_flags)
     return;

   *imf_flags = ECORE_IMF_MOUSE_NONE;
   if (evas_flags & EVAS_BUTTON_DOUBLE_CLICK)
     *imf_flags |= ECORE_IMF_MOUSE_DOUBLE_CLICK;
   if (evas_flags & EVAS_BUTTON_TRIPLE_CLICK)
     *imf_flags |= ECORE_IMF_MOUSE_TRIPLE_CLICK;
}

/**
 * Converts a "mouse_in" event from Evas to the corresponding event of Ecore_IMF.
 *
 * @param evas_event The received Evas event.
 * @param imf_event The location to store the converted Ecore_IMF event.
 * @ingroup Ecore_IMF_Evas_Group
 */
EAPI void
ecore_imf_evas_event_mouse_in_wrap(Evas_Event_Mouse_In *evas_event,
                                   Ecore_IMF_Event_Mouse_In *imf_event)
{
   if (!evas_event || !imf_event)
     return;

   imf_event->buttons = evas_event->buttons;
   imf_event->output.x = evas_event->output.x;
   imf_event->output.y = evas_event->output.y;
   imf_event->canvas.x = evas_event->canvas.x;
   imf_event->canvas.y = evas_event->canvas.y;
   imf_event->timestamp = evas_event->timestamp;
   _ecore_imf_evas_event_modifiers_wrap(evas_event->modifiers, &imf_event->modifiers);
   _ecore_imf_evas_event_locks_wrap(evas_event->locks, &imf_event->locks);
}

/**
 * Converts a "mouse_out" event from Evas to the corresponding event of Ecore_IMF.
 *
 * @param evas_event The received Evas event.
 * @param imf_event The location to store the converted Ecore_IMF event.
 * @ingroup Ecore_IMF_Evas_Group
 */
EAPI void
ecore_imf_evas_event_mouse_out_wrap(Evas_Event_Mouse_Out *evas_event,
                                    Ecore_IMF_Event_Mouse_Out *imf_event)
{
   if (!evas_event || !imf_event)
     return;

   imf_event->buttons = evas_event->buttons;
   imf_event->output.x = evas_event->output.x;
   imf_event->output.y = evas_event->output.y;
   imf_event->canvas.x = evas_event->canvas.x;
   imf_event->canvas.y = evas_event->canvas.y;
   imf_event->timestamp = evas_event->timestamp;
   _ecore_imf_evas_event_modifiers_wrap(evas_event->modifiers, &imf_event->modifiers);
   _ecore_imf_evas_event_locks_wrap(evas_event->locks, &imf_event->locks);
}

/**
 * Converts a "mouse_move" event from Evas to the corresponding event of Ecore_IMF.
 *
 * @param evas_event The received Evas event.
 * @param imf_event The location to store the converted Ecore_IMF event.
 * @ingroup Ecore_IMF_Evas_Group
 */
EAPI void
ecore_imf_evas_event_mouse_move_wrap(Evas_Event_Mouse_Move *evas_event,
                                     Ecore_IMF_Event_Mouse_Move *imf_event)
{
   if (!evas_event || !imf_event)
     return;

   imf_event->buttons = evas_event->buttons;
   imf_event->cur.output.x = evas_event->cur.output.x;
   imf_event->cur.output.y = evas_event->cur.output.y;
   imf_event->prev.output.x = evas_event->prev.output.x;
   imf_event->prev.output.y = evas_event->prev.output.y;
   imf_event->cur.canvas.x = evas_event->cur.canvas.x;
   imf_event->cur.canvas.y = evas_event->cur.canvas.y;
   imf_event->prev.canvas.x = evas_event->prev.canvas.x;
   imf_event->prev.canvas.y = evas_event->prev.canvas.y;
   imf_event->timestamp = evas_event->timestamp;
   _ecore_imf_evas_event_modifiers_wrap(evas_event->modifiers, &imf_event->modifiers);
   _ecore_imf_evas_event_locks_wrap(evas_event->locks, &imf_event->locks);
}

/**
 * Converts a "mouse_down" event from Evas to the corresponding event of Ecore_IMF.
 *
 * @param evas_event The received Evas event.
 * @param imf_event The location to store the converted Ecore_IMF event.
 * @ingroup Ecore_IMF_Evas_Group
 */
EAPI void
ecore_imf_evas_event_mouse_down_wrap(Evas_Event_Mouse_Down *evas_event,
                                     Ecore_IMF_Event_Mouse_Down *imf_event)
{
   if (!evas_event || !imf_event)
      return;

   imf_event->button = evas_event->button;
   imf_event->output.x = evas_event->output.x;
   imf_event->output.y = evas_event->output.y;
   imf_event->canvas.x = evas_event->canvas.x;
   imf_event->canvas.y = evas_event->canvas.y;
   imf_event->timestamp = evas_event->timestamp;
   _ecore_imf_evas_event_modifiers_wrap(evas_event->modifiers, &imf_event->modifiers);
   _ecore_imf_evas_event_locks_wrap(evas_event->locks, &imf_event->locks);
   _ecore_imf_evas_event_mouse_flags_wrap(evas_event->flags, &imf_event->flags);
}

/**
 * Converts a "mouse_up" event from Evas to the corresponding event of Ecore_IMF.
 *
 * @param evas_event The received Evas event.
 * @param imf_event The location to store the converted Ecore_IMF event.
 * @ingroup Ecore_IMF_Evas_Group
 */
EAPI void
ecore_imf_evas_event_mouse_up_wrap(Evas_Event_Mouse_Up *evas_event,
                                   Ecore_IMF_Event_Mouse_Up *imf_event)
{
   if (!evas_event || !imf_event)
     return;

   imf_event->button = evas_event->button;
   imf_event->output.x = evas_event->output.x;
   imf_event->output.y = evas_event->output.y;
   imf_event->canvas.x = evas_event->canvas.x;
   imf_event->canvas.y = evas_event->canvas.y;
   imf_event->timestamp = evas_event->timestamp;
   _ecore_imf_evas_event_modifiers_wrap(evas_event->modifiers, &imf_event->modifiers);
   _ecore_imf_evas_event_locks_wrap(evas_event->locks, &imf_event->locks);
   _ecore_imf_evas_event_mouse_flags_wrap(evas_event->flags, &imf_event->flags);
}

/**
 * Converts a "mouse_wheel" event from Evas to the corresponding event of Ecore_IMF.
 *
 * @param evas_event The received Evas event.
 * @param imf_event The location to store the converted Ecore_IMF event.
 * @ingroup Ecore_IMF_Evas_Group
 */
EAPI void
ecore_imf_evas_event_mouse_wheel_wrap(Evas_Event_Mouse_Wheel *evas_event,
                                      Ecore_IMF_Event_Mouse_Wheel *imf_event)
{
   if (!evas_event || !imf_event)
     return;

   imf_event->direction = evas_event->direction;
   imf_event->z = evas_event->z;
   imf_event->output.x = evas_event->output.x;
   imf_event->output.y = evas_event->output.y;
   imf_event->canvas.x = evas_event->canvas.x;
   imf_event->canvas.y = evas_event->canvas.y;
   imf_event->timestamp = evas_event->timestamp;
   _ecore_imf_evas_event_modifiers_wrap(evas_event->modifiers, &imf_event->modifiers);
   _ecore_imf_evas_event_locks_wrap(evas_event->locks, &imf_event->locks);
   imf_event->timestamp = evas_event->timestamp;
}

/**
 * Converts a "key_down" event from Evas to the corresponding event of Ecore_IMF.
 *
 * @param evas_event The received Evas event.
 * @param imf_event The location to store the converted Ecore_IMF event.
 * @ingroup Ecore_IMF_Evas_Group
 *
 * Example
 * @code
 * static void
 * _key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
 * {
 *    Evas_Event_Key_Down *ev = event_info;
 *    if (!ev->keyname) return;
 *
 *    if (imf_context)
 *      {
 *         Ecore_IMF_Event_Key_Down ecore_ev;
 *         ecore_imf_evas_event_key_down_wrap(ev, &ecore_ev);
 *         if (ecore_imf_context_filter_event(imf_context,
 *                                            ECORE_IMF_EVENT_KEY_DOWN,
 *                                            (Ecore_IMF_Event *)&ecore_ev))
 *           return;
 *      }
 * }
 *
 * evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_DOWN, _key_down_cb, data);
 * @endcode
 */
EAPI void
ecore_imf_evas_event_key_down_wrap(Evas_Event_Key_Down *evas_event,
                                   Ecore_IMF_Event_Key_Down *imf_event)
{
   if (!evas_event || !imf_event)
     return;

   imf_event->keyname = evas_event->keyname ? evas_event->keyname : _ecore_imf_evas_event_empty;
   imf_event->key = evas_event->key ? evas_event->key : _ecore_imf_evas_event_empty;
   imf_event->string = evas_event->string ? evas_event->string : _ecore_imf_evas_event_empty;
   imf_event->compose = evas_event->compose ? evas_event->compose : _ecore_imf_evas_event_empty;
   imf_event->timestamp = evas_event->timestamp;
   _ecore_imf_evas_event_modifiers_wrap(evas_event->modifiers, &imf_event->modifiers);
   _ecore_imf_evas_event_locks_wrap(evas_event->locks, &imf_event->locks);
}

/**
 * Converts a "key_up" event from Evas to the corresponding event of Ecore_IMF.
 *
 * @param evas_event The received Evas event.
 * @param imf_event The location to store the converted Ecore_IMF event.
 * @ingroup Ecore_IMF_Evas_Group
 *
 * Example
 * @code
 * static void
 * _key_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
 * {
 *    Evas_Event_Key_Up *ev = event_info;
 *    if (!ev->keyname) return;
 *
 *    if (imf_context)
 *      {
 *         Ecore_IMF_Event_Key_Up ecore_ev;
 *         ecore_imf_evas_event_key_up_wrap(ev, &ecore_ev);
 *         if (ecore_imf_context_filter_event(imf_context,
 *                                            ECORE_IMF_EVENT_KEY_UP,
 *                                            (Ecore_IMF_Event *)&ecore_ev))
 *           return;
 *      }
 * }
 *
 * evas_object_event_callback_add(obj, EVAS_CALLBACK_KEY_UP, _key_up_cb, data);
 * @endcode
 */
EAPI void
ecore_imf_evas_event_key_up_wrap(Evas_Event_Key_Up *evas_event,
                                 Ecore_IMF_Event_Key_Up *imf_event)
{
   imf_event->keyname = evas_event->keyname ? evas_event->keyname : _ecore_imf_evas_event_empty;
   imf_event->key = evas_event->key ? evas_event->key : _ecore_imf_evas_event_empty;
   imf_event->string = evas_event->string ? evas_event->string : _ecore_imf_evas_event_empty;
   imf_event->compose = evas_event->compose ? evas_event->compose : _ecore_imf_evas_event_empty;
   imf_event->timestamp = evas_event->timestamp;
   _ecore_imf_evas_event_modifiers_wrap(evas_event->modifiers, &imf_event->modifiers);
   _ecore_imf_evas_event_locks_wrap(evas_event->locks, &imf_event->locks);
}