6 #include <stdio.h> /* for printf */
8 #define WIN32_LEAN_AND_MEAN
10 #undef WIN32_LEAN_AND_MEAN
15 #include <Ecore_Input.h>
17 #include "Ecore_Win32.h"
18 #include "ecore_win32_private.h"
21 /***** Private declarations *****/
24 static Ecore_Win32_Window *_ecore_win32_mouse_down_last_window = NULL;
25 static Ecore_Win32_Window *_ecore_win32_mouse_down_last_last_window = NULL;
26 static long _ecore_win32_mouse_down_last_time = 0 ;
27 static long _ecore_win32_mouse_down_last_last_time = 0 ;
28 static int _ecore_win32_mouse_down_did_triple = 0;
29 static int _ecore_win32_mouse_up_count = 0;
31 static void _ecore_win32_event_free_key_down(void *data,
34 static void _ecore_win32_event_free_key_up(void *data,
37 static int _ecore_win32_event_keystroke_get(int key,
43 static int _ecore_win32_event_char_get(int key,
49 /***** Global functions definitions *****/
52 _ecore_win32_event_handle_key_press(Ecore_Win32_Callback_Data *msg,
59 e = (Ecore_Event_Key *)calloc(1, sizeof(Ecore_Event_Key));
64 if (!_ecore_win32_event_keystroke_get(LOWORD(msg->window_param),
65 msg->data_param & 0x01000000,
77 if (!_ecore_win32_event_char_get(LOWORD(msg->window_param),
88 e->window = (Ecore_Window)GetWindowLongPtr(msg->window, GWL_USERDATA);
94 e->event_window = e->window;
95 e->timestamp = msg->time;
97 _ecore_win32_event_last_time = e->timestamp;
99 ecore_event_add(ECORE_EVENT_KEY_DOWN, e, _ecore_win32_event_free_key_down, NULL);
103 _ecore_win32_event_handle_key_release(Ecore_Win32_Callback_Data *msg,
110 e = (Ecore_Event_Key *)calloc(1, sizeof(Ecore_Event_Key));
115 if (!_ecore_win32_event_keystroke_get(LOWORD(msg->window_param),
116 msg->data_param & 0x01000000,
117 (char **)&e->keyname,
119 (char **)&e->string))
128 if (!_ecore_win32_event_char_get(LOWORD(msg->window_param),
129 (char **)&e->keyname,
131 (char **)&e->string))
139 e->window = (Ecore_Window)GetWindowLongPtr(msg->window, GWL_USERDATA);
145 e->event_window = e->window;
146 e->timestamp = msg->time;
148 _ecore_win32_event_last_time = e->timestamp;
150 ecore_event_add(ECORE_EVENT_KEY_UP, e, _ecore_win32_event_free_key_up, NULL);
154 _ecore_win32_event_handle_button_press(Ecore_Win32_Callback_Data *msg,
157 Ecore_Win32_Window *window;
159 INF("mouse button pressed");
161 window = (Ecore_Win32_Window *)GetWindowLongPtr(msg->window, GWL_USERDATA);
165 Ecore_Event_Mouse_Wheel *e;
167 e = (Ecore_Event_Mouse_Wheel *)calloc(1, sizeof(Ecore_Event_Mouse_Wheel));
170 e->window = (Ecore_Window)window;
171 e->event_window = e->window;
173 /* wheel delta is positive or negative, never 0 */
174 e->z = GET_WHEEL_DELTA_WPARAM(msg->window_param) > 0 ? -1 : 1;
175 e->x = GET_X_LPARAM(msg->data_param);
176 e->y = GET_Y_LPARAM(msg->data_param);
177 e->timestamp = msg->time;
179 _ecore_win32_event_last_time = e->timestamp;
180 _ecore_win32_event_last_window = (Ecore_Win32_Window *)e->window;
182 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, e, NULL, NULL);
187 Ecore_Event_Mouse_Move *e;
189 e = (Ecore_Event_Mouse_Move *)calloc(1, sizeof(Ecore_Event_Mouse_Move));
192 e->window = (Ecore_Window)window;
193 e->event_window = e->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;
219 e->event_window = e->window;
221 e->x = GET_X_LPARAM(msg->data_param);
222 e->y = GET_Y_LPARAM(msg->data_param);
223 e->timestamp = msg->time;
225 if (((e->timestamp - _ecore_win32_mouse_down_last_time) <= (unsigned long)(1000 * _ecore_win32_double_click_time)) &&
226 (e->window == (Ecore_Window)_ecore_win32_mouse_down_last_window))
229 if (((e->timestamp - _ecore_win32_mouse_down_last_last_time) <= (unsigned long)(2 * 1000 * _ecore_win32_double_click_time)) &&
230 (e->window == (Ecore_Window)_ecore_win32_mouse_down_last_window) &&
231 (e->window == (Ecore_Window)_ecore_win32_mouse_down_last_last_window))
234 _ecore_win32_mouse_down_did_triple = 1;
237 _ecore_win32_mouse_down_did_triple = 0;
239 if (!e->double_click && !e->triple_click)
240 _ecore_win32_mouse_up_count = 0;
242 _ecore_win32_event_last_time = e->timestamp;
243 _ecore_win32_event_last_window = (Ecore_Win32_Window *)e->window;
245 if (!_ecore_win32_mouse_down_did_triple)
247 _ecore_win32_mouse_down_last_last_window = _ecore_win32_mouse_down_last_window;
248 _ecore_win32_mouse_down_last_window = (Ecore_Win32_Window *)e->window;
249 _ecore_win32_mouse_down_last_last_time = _ecore_win32_mouse_down_last_time;
250 _ecore_win32_mouse_down_last_time = e->timestamp;
253 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, e, NULL, NULL);
259 _ecore_win32_event_handle_button_release(Ecore_Win32_Callback_Data *msg,
262 Ecore_Win32_Window *window;
264 INF("mouse button released");
266 window = (void *)GetWindowLongPtr(msg->window, GWL_USERDATA);
269 Ecore_Event_Mouse_Move *e;
271 e = (Ecore_Event_Mouse_Move *)calloc(1, sizeof(Ecore_Event_Mouse_Move));
274 e->window = (Ecore_Window)window;
275 e->event_window = e->window;
276 e->x = GET_X_LPARAM(msg->data_param);
277 e->y = GET_Y_LPARAM(msg->data_param);
278 e->timestamp = msg->time;
280 _ecore_win32_event_last_time = e->timestamp;
281 _ecore_win32_event_last_window = (Ecore_Win32_Window *)e->window;
283 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, e, NULL, NULL);
287 Ecore_Event_Mouse_Button *e;
289 e = (Ecore_Event_Mouse_Button *)calloc(1, sizeof(Ecore_Event_Mouse_Button));
292 e->window = (Ecore_Window)window;
293 e->event_window = e->window;
295 e->x = GET_X_LPARAM(msg->data_param);
296 e->y = GET_Y_LPARAM(msg->data_param);
297 e->timestamp = msg->time;
299 _ecore_win32_mouse_up_count++;
301 if ((_ecore_win32_mouse_up_count >= 2) &&
302 ((e->timestamp - _ecore_win32_mouse_down_last_time) <= (unsigned long)(1000 * _ecore_win32_double_click_time)) &&
303 (e->window == (Ecore_Window)_ecore_win32_mouse_down_last_window))
306 if ((_ecore_win32_mouse_up_count >= 3) &&
307 ((e->timestamp - _ecore_win32_mouse_down_last_last_time) <= (unsigned long)(2 * 1000 * _ecore_win32_double_click_time)) &&
308 (e->window == (Ecore_Window)_ecore_win32_mouse_down_last_window) &&
309 (e->window == (Ecore_Window)_ecore_win32_mouse_down_last_last_window))
312 _ecore_win32_event_last_time = e->timestamp;
313 _ecore_win32_event_last_window = (Ecore_Win32_Window *)e->window;
315 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, e, NULL, NULL);
320 _ecore_win32_event_handle_motion_notify(Ecore_Win32_Callback_Data *msg)
322 Ecore_Event_Mouse_Move *e;
326 e = (Ecore_Event_Mouse_Move *)calloc(1, sizeof(Ecore_Event_Mouse_Move));
329 e->window = (Ecore_Window)GetWindowLongPtr(msg->window, GWL_USERDATA);
330 e->event_window = e->window;
331 e->x = GET_X_LPARAM(msg->data_param);
332 e->y = GET_Y_LPARAM(msg->data_param);
333 e->timestamp = msg->time;
335 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, e, NULL, NULL);
339 _ecore_win32_event_handle_enter_notify(Ecore_Win32_Callback_Data *msg)
342 Ecore_Event_Mouse_Move *e;
346 e = (Ecore_Event_Mouse_Move *)calloc(1, sizeof(Ecore_Event_Mouse_Move));
349 e->window = (Ecore_Window)GetWindowLongPtr(msg->window, GWL_USERDATA);
350 e->event_window = e->window;
353 e->timestamp = msg->time;
355 _ecore_win32_event_last_time = e->timestamp;
356 _ecore_win32_event_last_window = (Ecore_Win32_Window *)e->window;
358 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, e, NULL, NULL);
362 Ecore_Win32_Event_Mouse_In *e;
364 e = (Ecore_Win32_Event_Mouse_In *)calloc(1, sizeof(Ecore_Win32_Event_Mouse_In));
367 e->window = (void *)GetWindowLongPtr(msg->window, GWL_USERDATA);
370 e->time = msg->time ;
372 _ecore_win32_event_last_time = e->time;
374 ecore_event_add(ECORE_WIN32_EVENT_MOUSE_IN, e, NULL, NULL);
379 _ecore_win32_event_handle_leave_notify(Ecore_Win32_Callback_Data *msg)
382 Ecore_Event_Mouse_Move *e;
386 e = (Ecore_Event_Mouse_Move *)calloc(1, sizeof(Ecore_Event_Mouse_Move));
389 e->window = (Ecore_Window)GetWindowLongPtr(msg->window, GWL_USERDATA);
390 e->event_window = e->window;
393 e->timestamp = msg->time;
395 _ecore_win32_event_last_time = e->timestamp;
396 _ecore_win32_event_last_window = (Ecore_Win32_Window *)e->window;
398 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, e, NULL, NULL);
402 Ecore_Win32_Event_Mouse_Out *e;
404 e = (Ecore_Win32_Event_Mouse_Out *)calloc(1, sizeof(Ecore_Win32_Event_Mouse_Out));
407 e->window = (void *)GetWindowLongPtr(msg->window, GWL_USERDATA);
412 _ecore_win32_event_last_time = e->time;
414 ecore_event_add(ECORE_WIN32_EVENT_MOUSE_OUT, e, NULL, NULL);
419 _ecore_win32_event_handle_focus_in(Ecore_Win32_Callback_Data *msg)
421 Ecore_Win32_Event_Window_Focus_In *e;
425 e = (Ecore_Win32_Event_Window_Focus_In *)calloc(1, sizeof(Ecore_Win32_Event_Window_Focus_In));
428 e->window = (void *)GetWindowLongPtr(msg->window, GWL_USERDATA);
430 e->time = _ecore_win32_event_last_time;
431 _ecore_win32_event_last_time = e->time;
433 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_FOCUS_IN, e, NULL, NULL);
437 _ecore_win32_event_handle_focus_out(Ecore_Win32_Callback_Data *msg)
439 Ecore_Win32_Event_Window_Focus_Out *e;
443 e = (Ecore_Win32_Event_Window_Focus_Out *)calloc(1, sizeof(Ecore_Win32_Event_Window_Focus_Out));
446 e->window = (void *)GetWindowLongPtr(msg->window, GWL_USERDATA);
448 e->time = _ecore_win32_event_last_time;
449 _ecore_win32_event_last_time = e->time;
451 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_FOCUS_OUT, e, NULL, NULL);
455 _ecore_win32_event_handle_expose(Ecore_Win32_Callback_Data *msg)
457 Ecore_Win32_Event_Window_Damage *e;
459 INF("window expose");
461 e = (Ecore_Win32_Event_Window_Damage *)calloc(1, sizeof(Ecore_Win32_Event_Window_Damage));
464 e->window = (void *)GetWindowLongPtr(msg->window, GWL_USERDATA);
466 e->x = msg->update.left;
467 e->y = msg->update.top;
468 e->width = msg->update.right - msg->update.left;
469 e->height = msg->update.bottom - msg->update.top;
471 e->time = _ecore_win32_event_last_time;
473 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_DAMAGE, e, NULL, NULL);
477 _ecore_win32_event_handle_create_notify(Ecore_Win32_Callback_Data *msg)
479 Ecore_Win32_Event_Window_Create *e;
481 INF("window create notify");
483 e = calloc(1, sizeof(Ecore_Win32_Event_Window_Create));
486 e->window = (void *)GetWindowLongPtr(msg->window, GWL_USERDATA);
488 e->time = _ecore_win32_event_last_time;
490 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_CREATE, e, NULL, NULL);
494 _ecore_win32_event_handle_destroy_notify(Ecore_Win32_Callback_Data *msg)
496 Ecore_Win32_Event_Window_Destroy *e;
498 INF("window destroy notify");
500 e = calloc(1, sizeof(Ecore_Win32_Event_Window_Destroy));
503 e->window = (void *)GetWindowLongPtr(msg->window, GWL_USERDATA);
505 e->time = _ecore_win32_event_last_time;
506 if (e->window == _ecore_win32_event_last_window) _ecore_win32_event_last_window = NULL;
508 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_DESTROY, e, NULL, NULL);
512 _ecore_win32_event_handle_map_notify(Ecore_Win32_Callback_Data *msg)
514 Ecore_Win32_Event_Window_Show *e;
516 INF("window map notify");
518 e = calloc(1, sizeof(Ecore_Win32_Event_Window_Show));
521 e->window = (void *)GetWindowLongPtr(msg->window, GWL_USERDATA);
523 e->time = _ecore_win32_event_last_time;
525 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_SHOW, e, NULL, NULL);
529 _ecore_win32_event_handle_unmap_notify(Ecore_Win32_Callback_Data *msg)
531 Ecore_Win32_Event_Window_Hide *e;
533 INF("window unmap notify");
535 e = calloc(1, sizeof(Ecore_Win32_Event_Window_Hide));
538 e->window = (void *)GetWindowLongPtr(msg->window, GWL_USERDATA);
540 e->time = _ecore_win32_event_last_time;
542 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_HIDE, e, NULL, NULL);
546 _ecore_win32_event_handle_configure_notify(Ecore_Win32_Callback_Data *msg)
549 Ecore_Win32_Event_Window_Configure *e;
550 WINDOWPOS *window_pos;
552 INF("window configure notify");
554 e = calloc(1, sizeof(Ecore_Win32_Event_Window_Configure));
557 window_pos = (WINDOWPOS *)msg->data_param;
558 wi.cbSize = sizeof(WINDOWINFO);
559 if (!GetWindowInfo(window_pos->hwnd, &wi))
565 e->window = (void *)GetWindowLongPtr(msg->window, GWL_USERDATA);
566 e->abovewin = (void *)GetWindowLongPtr(window_pos->hwndInsertAfter, GWL_USERDATA);
567 e->x = wi.rcClient.left;
568 e->y = wi.rcClient.top;
569 e->width = wi.rcClient.right - wi.rcClient.left;
570 e->height = wi.rcClient.bottom - wi.rcClient.top;
571 e->time = _ecore_win32_event_last_time;
573 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_CONFIGURE, e, NULL, NULL);
577 _ecore_win32_event_handle_resize(Ecore_Win32_Callback_Data *msg)
580 Ecore_Win32_Event_Window_Resize *e;
582 INF("window resize");
584 if (!GetClientRect(msg->window, &rect))
587 e = calloc(1, sizeof(Ecore_Win32_Event_Window_Resize));
590 e->window = (void *)GetWindowLongPtr(msg->window, GWL_USERDATA);
591 e->width = rect.right - rect.left;
592 e->height = rect.bottom - rect.top;
593 e->time = _ecore_win32_event_last_time;
595 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_RESIZE, e, NULL, NULL);
599 _ecore_win32_event_handle_delete_request(Ecore_Win32_Callback_Data *msg)
601 Ecore_Win32_Event_Window_Delete_Request *e;
603 INF("window delete request");
605 e = calloc(1, sizeof(Ecore_Win32_Event_Window_Delete_Request));
608 e->window = (void *)GetWindowLongPtr(msg->window, GWL_USERDATA);
609 e->time = _ecore_win32_event_last_time;
611 ecore_event_add(ECORE_WIN32_EVENT_WINDOW_DELETE_REQUEST, e, NULL, NULL);
615 /***** Private functions definitions *****/
618 _ecore_win32_event_free_key_down(void *data __UNUSED__,
624 if (e->keyname) free((char *)e->keyname);
625 if (e->key) free((char *)e->key);
626 if (e->string) free((char *)e->string);
631 _ecore_win32_event_free_key_up(void *data __UNUSED__,
637 if (e->keyname) free((char *)e->keyname);
638 if (e->key) free((char *)e->key);
639 if (e->string) free((char *)e->string);
644 _ecore_win32_event_keystroke_get(int key,
927 /* other non keystroke characters */
930 *keyname = strdup(kn);
931 if (!*keyname) return 0;
932 *keysymbol = strdup(ks);
939 *keycompose = strdup(kc);
953 _ecore_win32_event_char_get(int key,
969 strncpy(kn, "BackSpace", 32);
970 strncpy(ks, "BackSpace", 32);
971 strncpy(kc, "BackSpace", 32);
974 strncpy(kn, "Tab", 32);
975 strncpy(ks, "ISO_Left_Tab", 32);
976 strncpy(kc, "Tab", 32);
979 /* Line feed (Shift + Enter) */
980 strncpy(kn, "LineFeed", 32);
981 strncpy(ks, "LineFeed", 32);
982 strncpy(kc, "LineFeed", 32);
985 strncpy(kn, "Return", 32);
986 strncpy(ks, "Return", 32);
987 strncpy(kc, "Return", 32);
990 strncpy(kn, "Escape", 32);
991 strncpy(ks, "Escape", 32);
992 strncpy(kc, "Escape", 32);
995 strncpy(kn, "space", 32);
996 strncpy(ks, "space", 32);
997 strncpy(kc, "space", 32);
1000 /* displayable characters */
1001 printf (" * key : %d\n", key);
1010 *keyname = strdup(kn);
1011 if (!*keyname) return 0;
1012 *keysymbol = strdup(ks);
1019 *keycompose = strdup(kc);