6 #include <stdio.h> /* for printf */
8 #define WIN32_LEAN_AND_MEAN
10 #undef WIN32_LEAN_AND_MEAN
14 #include <Ecore_Input.h>
16 #include "Ecore_WinCE.h"
17 #include "ecore_wince_private.h"
20 /***** Global declarations *****/
22 double _ecore_wince_double_click_time = 0.25;
23 long _ecore_wince_event_last_time = 0;
24 Ecore_WinCE_Window *_ecore_wince_event_last_window = NULL;
25 HINSTANCE _ecore_wince_instance = NULL;
26 int _ecore_wince_log_dom_global = -1;
28 int ECORE_WINCE_EVENT_MOUSE_IN = 0;
29 int ECORE_WINCE_EVENT_MOUSE_OUT = 0;
30 int ECORE_WINCE_EVENT_WINDOW_FOCUS_IN = 0;
31 int ECORE_WINCE_EVENT_WINDOW_FOCUS_OUT = 0;
32 int ECORE_WINCE_EVENT_WINDOW_DAMAGE = 0;
33 int ECORE_WINCE_EVENT_WINDOW_CREATE = 0;
34 int ECORE_WINCE_EVENT_WINDOW_DESTROY = 0;
35 int ECORE_WINCE_EVENT_WINDOW_SHOW = 0;
36 int ECORE_WINCE_EVENT_WINDOW_HIDE = 0;
37 int ECORE_WINCE_EVENT_WINDOW_DELETE_REQUEST = 0;
40 /***** Private declarations *****/
42 static int _ecore_wince_init_count = 0;
44 LRESULT CALLBACK _ecore_wince_window_procedure(HWND window,
49 static void _ecore_wince_error_print_cb(const Eina_Log_Domain *d,
66 if (++_ecore_wince_init_count != 1)
67 return _ecore_wince_init_count;
70 return --_ecore_wince_init_count;
72 eina_log_print_cb_set(_ecore_wince_error_print_cb, NULL);
73 _ecore_wince_log_dom_global = eina_log_domain_register("ecore_wince", ECORE_WINCE_DEFAULT_LOG_COLOR);
74 if (_ecore_wince_log_dom_global < 0)
76 EINA_LOG_ERR("Ecore_WinCE: Could not register log domain");
80 if (!ecore_event_init())
82 ERR("Ecore_WinCE: Could not init ecore_event");
83 goto unregister_log_domain;
86 _ecore_wince_instance = GetModuleHandle(NULL);
87 if (!_ecore_wince_instance)
89 ERR("GetModuleHandle() failed");
90 goto shutdown_ecore_event;
93 memset (&wc, 0, sizeof (wc));
94 wc.style = CS_HREDRAW | CS_VREDRAW;
95 wc.lpfnWndProc = _ecore_wince_window_procedure;
98 wc.hInstance = _ecore_wince_instance;
100 wc.hCursor = LoadCursor (NULL, IDC_ARROW);
101 wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
102 wc.lpszMenuName = NULL;
103 wc.lpszClassName = ECORE_WINCE_WINDOW_CLASS;
105 if(!RegisterClass(&wc))
107 ERR("RegisterClass() failed");
111 if (!ECORE_WINCE_EVENT_MOUSE_IN)
113 ECORE_WINCE_EVENT_MOUSE_IN = ecore_event_type_new();
114 ECORE_WINCE_EVENT_MOUSE_OUT = ecore_event_type_new();
115 ECORE_WINCE_EVENT_WINDOW_FOCUS_IN = ecore_event_type_new();
116 ECORE_WINCE_EVENT_WINDOW_FOCUS_OUT = ecore_event_type_new();
117 ECORE_WINCE_EVENT_WINDOW_DAMAGE = ecore_event_type_new();
118 ECORE_WINCE_EVENT_WINDOW_CREATE = ecore_event_type_new();
119 ECORE_WINCE_EVENT_WINDOW_DESTROY = ecore_event_type_new();
120 ECORE_WINCE_EVENT_WINDOW_SHOW = ecore_event_type_new();
121 ECORE_WINCE_EVENT_WINDOW_HIDE = ecore_event_type_new();
122 ECORE_WINCE_EVENT_WINDOW_DELETE_REQUEST = ecore_event_type_new();
125 return _ecore_wince_init_count;
128 FreeLibrary(_ecore_wince_instance);
129 shutdown_ecore_event:
130 ecore_event_shutdown();
131 unregister_log_domain:
132 eina_log_domain_unregister(_ecore_wince_log_dom_global);
136 return --_ecore_wince_init_count;
140 ecore_wince_shutdown()
144 if (--_ecore_wince_init_count != 0)
145 return _ecore_wince_init_count;
147 /* force task bar to be shown (in case the application exits */
148 /* while being fullscreen) */
149 task_bar = FindWindow(L"HHTaskBar", NULL);
152 ShowWindow(task_bar, SW_SHOW);
153 EnableWindow(task_bar, TRUE);
156 if (!UnregisterClass(ECORE_WINCE_WINDOW_CLASS, _ecore_wince_instance))
157 ERR("UnregisterClass() failed");
159 if (!FreeLibrary(_ecore_wince_instance))
160 ERR("FreeLibrary() failed");
162 _ecore_wince_instance = NULL;
164 ecore_event_shutdown();
165 eina_log_domain_unregister(_ecore_wince_log_dom_global);
166 _ecore_wince_log_dom_global = -1;
169 return _ecore_wince_init_count;
173 * Sets the timeout for a double and triple clicks to be flagged.
175 * This sets the time between clicks before the double_click flag is
176 * set in a button down event. If 3 clicks occur within double this
177 * time, the triple_click flag is also set.
179 * @param t The time in seconds
182 ecore_wince_double_click_time_set(double t)
184 if (t < 0.0) t = 0.0;
185 _ecore_wince_double_click_time = t;
189 * Retrieves the double and triple click flag timeout.
191 * See @ref ecore_wince_double_click_time_set for more information.
193 * @return The timeout for double clicks in seconds.
196 ecore_wince_double_click_time_get(void)
198 return _ecore_wince_double_click_time;
202 * Return the last event time
205 ecore_wince_current_time_get(void)
207 return _ecore_wince_event_last_time;
211 /***** Private functions definitions *****/
214 _ecore_wince_window_procedure(HWND window,
219 Ecore_WinCE_Callback_Data *data;
223 data = (Ecore_WinCE_Callback_Data *)malloc(sizeof(Ecore_WinCE_Callback_Data));
224 if (!data) return DefWindowProc(window, message, window_param, data_param);
226 data->window = window;
227 data->message = message;
228 data->window_param = window_param;
229 data->data_param = data_param;
230 data->time = GetTickCount();
231 coord = GetMessagePos();
232 pt = MAKEPOINTS(coord);
236 switch (data->message)
238 /* Keyboard input notifications */
240 _ecore_wince_event_handle_key_press(data, 0);
243 _ecore_wince_event_handle_key_press(data, 1);
247 _ecore_wince_event_handle_key_press(data, 1);
251 _ecore_wince_event_handle_key_release(data, 1);
254 _ecore_wince_event_handle_focus_in(data);
257 _ecore_wince_event_handle_focus_out(data);
259 /* Mouse input notifications */
261 _ecore_wince_event_handle_button_press(data, 1);
264 _ecore_wince_event_handle_button_release(data, 1);
269 struct _Ecore_WinCE_Window *w = NULL;
271 w = (struct _Ecore_WinCE_Window *)GetWindowLong(window, GWL_USERDATA);
273 if (GetClientRect(window, &rect))
277 INF("mouse in window");
279 pt.x = LOWORD(data_param);
280 pt.y = HIWORD(data_param);
281 if (!PtInRect(&rect, pt))
283 if (w->pointer_is_in)
285 w->pointer_is_in = 0;
286 _ecore_wince_event_handle_leave_notify(data);
291 if (!w->pointer_is_in)
293 w->pointer_is_in = 1;
294 _ecore_wince_event_handle_enter_notify(data);
300 ERR("GetClientRect() failed");
302 _ecore_wince_event_handle_motion_notify(data);
306 /* Window notifications */
308 _ecore_wince_event_handle_create_notify(data);
311 _ecore_wince_event_handle_destroy_notify(data);
314 if ((data->data_param == SW_OTHERUNZOOM) ||
315 (data->data_param == SW_OTHERUNZOOM))
318 if (data->window_param)
319 _ecore_wince_event_handle_map_notify(data);
321 _ecore_wince_event_handle_unmap_notify(data);
325 _ecore_wince_event_handle_delete_request(data);
327 /* GDI notifications */
332 if (BeginPaint(window, &paint))
334 data->update = paint.rcPaint;
335 _ecore_wince_event_handle_expose(data);
336 EndPaint(window, &paint);
341 return DefWindowProc(window, message, window_param, data_param);
348 _ecore_wince_error_print_cb(const Eina_Log_Domain *d __UNUSED__,
349 Eina_Log_Level level __UNUSED__,
350 const char *file __UNUSED__,
354 void *data __UNUSED__,
357 fprintf(stderr, "[%s:%d] ", fnc, line);
358 vfprintf(stderr, fmt, args);