2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
10 #include <stdio.h> /* for printf */
12 #define WIN32_LEAN_AND_MEAN
14 #undef WIN32_LEAN_AND_MEAN
19 #include <Ecore_Input.h>
21 #include "Ecore_Win32.h"
22 #include "ecore_win32_private.h"
25 /***** Private declarations *****/
28 static Ecore_Win32_Window *_ecore_win32_mouse_down_last_window = NULL;
29 static Ecore_Win32_Window *_ecore_win32_mouse_down_last_last_window = NULL;
30 static long _ecore_win32_mouse_down_last_time = 0 ;
31 static long _ecore_win32_mouse_down_last_last_time = 0 ;
32 static int _ecore_win32_mouse_down_did_triple = 0;
33 static int _ecore_win32_mouse_up_count = 0;
35 static void _ecore_win32_event_free_key_down(void *data,
38 static void _ecore_win32_event_free_key_up(void *data,
41 static int _ecore_win32_event_keystroke_get(int key,
47 static int _ecore_win32_event_char_get(int key,
53 /***** Global functions definitions *****/
56 _ecore_win32_event_handle_key_press(Ecore_Win32_Callback_Data *msg,
63 e = (Ecore_Event_Key *)malloc(sizeof(Ecore_Event_Key));
68 if (!_ecore_win32_event_keystroke_get(LOWORD(msg->window_param),
69 msg->data_param & 0x01000000,
81 if (!_ecore_win32_event_char_get(LOWORD(msg->window_param),
92 e->window = (Ecore_Window)GetWindowLong(msg->window, GWL_USERDATA);
98 e->timestamp = msg->time;
100 _ecore_win32_event_last_time = e->timestamp;
102 ecore_event_add(ECORE_EVENT_KEY_DOWN, e, _ecore_win32_event_free_key_down, NULL);
106 _ecore_win32_event_handle_key_release(Ecore_Win32_Callback_Data *msg,
113 e = (Ecore_Event_Key *)calloc(1, sizeof(Ecore_Event_Key));
118 if (!_ecore_win32_event_keystroke_get(LOWORD(msg->window_param),
119 msg->data_param & 0x01000000,
120 (char **)&e->keyname,
122 (char **)&e->string))
131 if (!_ecore_win32_event_char_get(LOWORD(msg->window_param),
132 (char **)&e->keyname,
134 (char **)&e->string))
142 e->window = (Ecore_Window)GetWindowLong(msg->window, GWL_USERDATA);
148 e->timestamp = msg->time;
150 _ecore_win32_event_last_time = e->timestamp;
152 ecore_event_add(ECORE_EVENT_KEY_UP, e, _ecore_win32_event_free_key_up, NULL);
156 _ecore_win32_event_handle_button_press(Ecore_Win32_Callback_Data *msg,
159 Ecore_Win32_Window *window;
161 INF("mouse button pressed");
163 window = (Ecore_Win32_Window *)GetWindowLong(msg->window, GWL_USERDATA);
167 Ecore_Event_Mouse_Wheel *e;
169 e = (Ecore_Event_Mouse_Wheel *)calloc(1, sizeof(Ecore_Event_Mouse_Wheel));
172 e->window = (Ecore_Window)window;
174 /* wheel delta is positive or negative, never 0 */
175 e->z = GET_WHEEL_DELTA_WPARAM(msg->window_param) > 0 ? -1 : 1;
176 e->x = GET_X_LPARAM(msg->data_param);
177 e->y = GET_Y_LPARAM(msg->data_param);
178 e->timestamp = msg->time;
180 _ecore_win32_event_last_time = e->timestamp;
181 _ecore_win32_event_last_window = (Ecore_Win32_Window *)e->window;
183 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, e, NULL, NULL);
188 Ecore_Event_Mouse_Move *e;
190 e = (Ecore_Event_Mouse_Move *)calloc(1, sizeof(Ecore_Event_Mouse_Move));
193 e->window = (Ecore_Window)window;
194 e->x = GET_X_LPARAM(msg->data_param);
195 e->y = GET_Y_LPARAM(msg->data_param);
196 e->timestamp = msg->time;
198 _ecore_win32_event_last_time = e->timestamp;
199 _ecore_win32_event_last_window = (Ecore_Win32_Window *)e->window;
201 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, e, NULL, NULL);
205 Ecore_Event_Mouse_Button *e;
207 if (_ecore_win32_mouse_down_did_triple)
209 _ecore_win32_mouse_down_last_window = NULL;
210 _ecore_win32_mouse_down_last_last_window = NULL;
211 _ecore_win32_mouse_down_last_time = 0;
212 _ecore_win32_mouse_down_last_last_time = 0;
215 e = (Ecore_Event_Mouse_Button *)calloc(1, sizeof(Ecore_Event_Mouse_Button));
218 e->window = (Ecore_Window)window;
220 e->x = GET_X_LPARAM(msg->data_param);
221 e->y = GET_Y_LPARAM(msg->data_param);
222 e->timestamp = msg->time;
224 if (((e->timestamp - _ecore_win32_mouse_down_last_time) <= (long)(1000 * _ecore_win32_double_click_time)) &&
225 (e->window == (Ecore_Window)_ecore_win32_mouse_down_last_window))
228 if (((e->timestamp - _ecore_win32_mouse_down_last_last_time) <= (long)(2 * 1000 * _ecore_win32_double_click_time)) &&
229 (e->window == (Ecore_Window)_ecore_win32_mouse_down_last_window) &&
230 (e->window == (Ecore_Window)_ecore_win32_mouse_down_last_last_window))
233 _ecore_win32_mouse_down_did_triple = 1;
236 _ecore_win32_mouse_down_did_triple = 0;
238 if (!e->double_click && !e->triple_click)
239 _ecore_win32_mouse_up_count = 0;
241 _ecore_win32_event_last_time = e->timestamp;
242 _ecore_win32_event_last_window = (Ecore_Win32_Window *)e->window;
244 if (!_ecore_win32_mouse_down_did_triple)
246 _ecore_win32_mouse_down_last_last_window = _ecore_win32_mouse_down_last_window;
247 _ecore_win32_mouse_down_last_window = (Ecore_Win32_Window *)e->window;
248 _ecore_win32_mouse_down_last_last_time = _ecore_win32_mouse_down_last_time;
249 _ecore_win32_mouse_down_last_time = e->timestamp;
252 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, e, NULL, NULL);
258 _ecore_win32_event_handle_button_release(Ecore_Win32_Callback_Data *msg,
261 Ecore_Win32_Window *window;
263 INF("mouse button released");
265 window = (void *)GetWindowLong(msg->window, GWL_USERDATA);
268 Ecore_Event_Mouse_Move *e;
270 e = (Ecore_Event_Mouse_Move *)calloc(1, sizeof(Ecore_Event_Mouse_Move));
273 e->window = (Ecore_Window)window;
274 e->x = GET_X_LPARAM(msg->data_param);
275 e->y = GET_Y_LPARAM(msg->data_param);
276 e->timestamp = msg->time;
278 _ecore_win32_event_last_time = e->timestamp;
279 _ecore_win32_event_last_window = (Ecore_Win32_Window *)e->window;
281 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, e, NULL, NULL);
285 Ecore_Event_Mouse_Button *e;
287 e = (Ecore_Event_Mouse_Button *)calloc(1, sizeof(Ecore_Event_Mouse_Button));
290 e->window = (Ecore_Window)window;
292 e->x = GET_X_LPARAM(msg->data_param);
293 e->y = GET_Y_LPARAM(msg->data_param);
294 e->timestamp = msg->time;
296 _ecore_win32_mouse_up_count++;
298 if ((_ecore_win32_mouse_up_count >= 2) &&
299 ((e->timestamp - _ecore_win32_mouse_down_last_time) <= (long)(1000 * _ecore_win32_double_click_time)) &&
300 (e->window == (Ecore_Window)_ecore_win32_mouse_down_last_window))
303 if ((_ecore_win32_mouse_up_count >= 3) &&
304 ((e->timestamp - _ecore_win32_mouse_down_last_last_time) <= (long)(2 * 1000 * _ecore_win32_double_click_time)) &&
305 (e->window == (Ecore_Window)_ecore_win32_mouse_down_last_window) &&
306 (e->window == (Ecore_Window)_ecore_win32_mouse_down_last_last_window))
309 _ecore_win32_event_last_time = e->timestamp;
310 _ecore_win32_event_last_window = (Ecore_Win32_Window *)e->window;
312 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, e, NULL, NULL);
317 _ecore_win32_event_handle_motion_notify(Ecore_Win32_Callback_Data *msg)
319 Ecore_Event_Mouse_Move *e;
323 e = (Ecore_Event_Mouse_Move *)calloc(1, sizeof(Ecore_Event_Mouse_Move));
326 e->window = (Ecore_Window)GetWindowLong(msg->window, GWL_USERDATA);
327 e->x = GET_X_LPARAM(msg->data_param);
328 e->y = GET_Y_LPARAM(msg->data_param);
329 e->timestamp = msg->time;
331 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, e, NULL, NULL);
335 _ecore_win32_event_handle_enter_notify(Ecore_Win32_Callback_Data *msg)
338 Ecore_Event_Mouse_Move *e;
342 e = (Ecore_Event_Mouse_Move *)calloc(1, sizeof(Ecore_Event_Mouse_Move));
345 e->window = (Ecore_Window)GetWindowLong(msg->window, GWL_USERDATA);
348 e->timestamp = msg->time;
350 _ecore_win32_event_last_time = e->timestamp;
351 _ecore_win32_event_last_window = (Ecore_Win32_Window *)e->window;
353 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, e, NULL, NULL);
357 Ecore_Win32_Event_Mouse_In *e;
359 e = (Ecore_Win32_Event_Mouse_In *)calloc(1, sizeof(Ecore_Win32_Event_Mouse_In));
362 e->window = (void *)GetWindowLong(msg->window, GWL_USERDATA);
365 e->time = msg->time ;
367 _ecore_win32_event_last_time = e->time;
369 ecore_event_add(ECORE_WIN32_EVENT_MOUSE_IN, e, NULL, NULL);
374 _ecore_win32_event_handle_leave_notify(Ecore_Win32_Callback_Data *msg)
377 Ecore_Event_Mouse_Move *e;
381 e = (Ecore_Event_Mouse_Move *)calloc(1, sizeof(Ecore_Event_Mouse_Move));
384 e->window = (Ecore_Window)GetWindowLong(msg->window, GWL_USERDATA);
387 e->timestamp = msg->time;
389 _ecore_win32_event_last_time = e->timestamp;
390 _ecore_win32_event_last_window = (Ecore_Win32_Window *)e->window;
392 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, e, NULL, NULL);
396 Ecore_Win32_Event_Mouse_Out *e;
398 e = (Ecore_Win32_Event_Mouse_Out *)calloc(1, sizeof(Ecore_Win32_Event_Mouse_Out));
401 e->window = (void *)GetWindowLong(msg->window, GWL_USERDATA);
406 _ecore_win32_event_last_time = e->time;
408 ecore_event_add(ECORE_WIN32_EVENT_MOUSE_OUT, e, NULL, NULL);
413 _ecore_win32_event_handle_focus_in(Ecore_Win32_Callback_Data *msg)
415 Ecore_Win32_Event_Window_Focus_In *e;
419 e = (Ecore_Win32_Event_Window_Focus_In *)calloc(1, sizeof(Ecore_Win32_Event_Window_Focus_In));
422 e->window = (void *)GetWindowLong(msg->window, GWL_USERDATA);
424 e->time = _ecore_win32_event_last_time;
425 _ecore_win32_event_last_time = e->time;
427 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_FOCUS_IN, e, NULL, NULL);
431 _ecore_win32_event_handle_focus_out(Ecore_Win32_Callback_Data *msg)
433 Ecore_Win32_Event_Window_Focus_Out *e;
437 e = (Ecore_Win32_Event_Window_Focus_Out *)calloc(1, sizeof(Ecore_Win32_Event_Window_Focus_Out));
440 e->window = (void *)GetWindowLong(msg->window, GWL_USERDATA);
442 e->time = _ecore_win32_event_last_time;
443 _ecore_win32_event_last_time = e->time;
445 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_FOCUS_OUT, e, NULL, NULL);
449 _ecore_win32_event_handle_expose(Ecore_Win32_Callback_Data *msg)
451 Ecore_Win32_Event_Window_Damage *e;
453 INF("window expose");
455 e = (Ecore_Win32_Event_Window_Damage *)calloc(1, sizeof(Ecore_Win32_Event_Window_Damage));
458 e->window = (void *)GetWindowLong(msg->window, GWL_USERDATA);
460 e->x = msg->update.left;
461 e->y = msg->update.top;
462 e->width = msg->update.right - msg->update.left;
463 e->height = msg->update.bottom - msg->update.top;
465 e->time = _ecore_win32_event_last_time;
467 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_DAMAGE, e, NULL, NULL);
471 _ecore_win32_event_handle_create_notify(Ecore_Win32_Callback_Data *msg)
473 Ecore_Win32_Event_Window_Create *e;
475 INF("window create notify");
477 e = calloc(1, sizeof(Ecore_Win32_Event_Window_Create));
480 e->window = (void *)GetWindowLong(msg->window, GWL_USERDATA);
482 e->time = _ecore_win32_event_last_time;
484 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_CREATE, e, NULL, NULL);
488 _ecore_win32_event_handle_destroy_notify(Ecore_Win32_Callback_Data *msg)
490 Ecore_Win32_Event_Window_Destroy *e;
492 INF("window destroy notify");
494 e = calloc(1, sizeof(Ecore_Win32_Event_Window_Destroy));
497 e->window = (void *)GetWindowLong(msg->window, GWL_USERDATA);
499 e->time = _ecore_win32_event_last_time;
500 if (e->window == _ecore_win32_event_last_window) _ecore_win32_event_last_window = NULL;
502 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_DESTROY, e, NULL, NULL);
506 _ecore_win32_event_handle_map_notify(Ecore_Win32_Callback_Data *msg)
508 Ecore_Win32_Event_Window_Show *e;
510 INF("window map notify");
512 e = calloc(1, sizeof(Ecore_Win32_Event_Window_Show));
515 e->window = (void *)GetWindowLong(msg->window, GWL_USERDATA);
517 e->time = _ecore_win32_event_last_time;
519 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_SHOW, e, NULL, NULL);
523 _ecore_win32_event_handle_unmap_notify(Ecore_Win32_Callback_Data *msg)
525 Ecore_Win32_Event_Window_Hide *e;
527 INF("window unmap notify");
529 e = calloc(1, sizeof(Ecore_Win32_Event_Window_Hide));
532 e->window = (void *)GetWindowLong(msg->window, GWL_USERDATA);
534 e->time = _ecore_win32_event_last_time;
536 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_HIDE, e, NULL, NULL);
540 _ecore_win32_event_handle_configure_notify(Ecore_Win32_Callback_Data *msg)
543 Ecore_Win32_Event_Window_Configure *e;
544 WINDOWPOS *window_pos;
546 INF("window configure notify");
548 e = calloc(1, sizeof(Ecore_Win32_Event_Window_Configure));
551 window_pos = (WINDOWPOS *)msg->data_param;
552 wi.cbSize = sizeof(WINDOWINFO);
553 if (!GetWindowInfo(window_pos->hwnd, &wi))
559 e->window = (void *)GetWindowLong(msg->window, GWL_USERDATA);
560 e->abovewin = (void *)GetWindowLong(window_pos->hwndInsertAfter, GWL_USERDATA);
561 e->x = wi.rcClient.left;
562 e->y = wi.rcClient.top;
563 e->width = wi.rcClient.right - wi.rcClient.left;
564 e->height = wi.rcClient.bottom - wi.rcClient.top;
565 e->time = _ecore_win32_event_last_time;
567 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_CONFIGURE, e, NULL, NULL);
571 _ecore_win32_event_handle_resize(Ecore_Win32_Callback_Data *msg)
574 Ecore_Win32_Event_Window_Resize *e;
576 INF("window resize");
578 if (!GetClientRect(msg->window, &rect))
581 e = calloc(1, sizeof(Ecore_Win32_Event_Window_Resize));
584 e->window = (void *)GetWindowLong(msg->window, GWL_USERDATA);
585 e->width = rect.right - rect.left;
586 e->height = rect.bottom - rect.top;
587 e->time = _ecore_win32_event_last_time;
589 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_RESIZE, e, NULL, NULL);
593 _ecore_win32_event_handle_delete_request(Ecore_Win32_Callback_Data *msg)
595 Ecore_Win32_Event_Window_Delete_Request *e;
597 INF("window delete request");
599 e = calloc(1, sizeof(Ecore_Win32_Event_Window_Delete_Request));
602 e->window = (void *)GetWindowLong(msg->window, GWL_USERDATA);
603 e->time = _ecore_win32_event_last_time;
605 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_DELETE_REQUEST, e, NULL, NULL);
609 /***** Private functions definitions *****/
612 _ecore_win32_event_free_key_down(void *data __UNUSED__,
618 if (e->keyname) free((char *)e->keyname);
619 if (e->key) free((char *)e->key);
620 if (e->string) free((char *)e->string);
625 _ecore_win32_event_free_key_up(void *data __UNUSED__,
631 if (e->keyname) free((char *)e->keyname);
632 if (e->key) free((char *)e->key);
633 if (e->string) free((char *)e->string);
638 _ecore_win32_event_keystroke_get(int key,
916 /* other non keystroke characters */
919 *keyname = strdup(kn);
920 if (!*keyname) return 0;
921 *keysymbol = strdup(ks);
928 *keycompose = strdup(kc);
942 _ecore_win32_event_char_get(int key,
958 strncpy(kn, "BackSpace", 32);
959 strncpy(ks, "BackSpace", 32);
960 strncpy(kc, "BackSpace", 32);
963 strncpy(kn, "Tab", 32);
964 strncpy(ks, "ISO_Left_Tab", 32);
965 strncpy(kc, "Tab", 32);
968 /* Line feed (Shift + Enter) */
969 strncpy(kn, "LineFeed", 32);
970 strncpy(ks, "LineFeed", 32);
971 strncpy(kc, "LineFeed", 32);
974 strncpy(kn, "Return", 32);
975 strncpy(ks, "Return", 32);
976 strncpy(kc, "Return", 32);
979 strncpy(kn, "Escape", 32);
980 strncpy(ks, "Escape", 32);
981 strncpy(kc, "Escape", 32);
984 /* displayable characters */
985 printf (" * key : %d\n", key);
994 *keyname = strdup(kn);
995 if (!*keyname) return 0;
996 *keysymbol = strdup(ks);
1003 *keycompose = strdup(kc);