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
18 #include "Ecore_Win32.h"
19 #include "ecore_win32_private.h"
22 /***** Global declarations *****/
24 HINSTANCE _ecore_win32_instance = NULL;
25 double _ecore_win32_double_click_time = 0.25;
26 double _ecore_win32_event_last_time = 0.0;
27 Ecore_Win32_Window *_ecore_win32_event_last_window = NULL;
29 int ECORE_WIN32_EVENT_KEY_DOWN = 0;
30 int ECORE_WIN32_EVENT_KEY_UP = 0;
31 int ECORE_WIN32_EVENT_MOUSE_BUTTON_DOWN = 0;
32 int ECORE_WIN32_EVENT_MOUSE_BUTTON_UP = 0;
33 int ECORE_WIN32_EVENT_MOUSE_MOVE = 0;
34 int ECORE_WIN32_EVENT_MOUSE_IN = 0;
35 int ECORE_WIN32_EVENT_MOUSE_OUT = 0;
36 int ECORE_WIN32_EVENT_MOUSE_WHEEL = 0;
37 int ECORE_WIN32_EVENT_WINDOW_FOCUS_IN = 0;
38 int ECORE_WIN32_EVENT_WINDOW_FOCUS_OUT = 0;
39 int ECORE_WIN32_EVENT_WINDOW_DAMAGE = 0;
40 int ECORE_WIN32_EVENT_WINDOW_CREATE = 0;
41 int ECORE_WIN32_EVENT_WINDOW_DESTROY = 0;
42 int ECORE_WIN32_EVENT_WINDOW_SHOW = 0;
43 int ECORE_WIN32_EVENT_WINDOW_HIDE = 0;
44 int ECORE_WIN32_EVENT_WINDOW_CONFIGURE = 0;
45 int ECORE_WIN32_EVENT_WINDOW_RESIZE = 0;
46 int ECORE_WIN32_EVENT_WINDOW_DELETE_REQUEST = 0;
49 /***** Private declarations *****/
51 static int _ecore_win32_init_count = 0;
53 LRESULT CALLBACK _ecore_win32_window_procedure(HWND window,
67 if (_ecore_win32_init_count > 0)
69 _ecore_win32_init_count++;
70 return _ecore_win32_init_count;
73 printf (" *** ecore_win32_init\n");
74 _ecore_win32_instance = GetModuleHandle(NULL);
75 if (!_ecore_win32_instance)
78 memset (&wc, 0, sizeof (WNDCLASS));
79 wc.style = CS_HREDRAW | CS_VREDRAW;
80 wc.lpfnWndProc = _ecore_win32_window_procedure;
83 wc.hInstance = _ecore_win32_instance;
84 wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
85 wc.hCursor = LoadCursor (NULL, IDC_ARROW);
86 wc.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
87 wc.lpszMenuName = NULL;
88 wc.lpszClassName = ECORE_WIN32_WINDOW_CLASS;
90 if(!RegisterClass(&wc))
92 FreeLibrary(_ecore_win32_instance);
96 if (!ECORE_WIN32_EVENT_KEY_DOWN)
98 ECORE_WIN32_EVENT_KEY_DOWN = ecore_event_type_new();
99 ECORE_WIN32_EVENT_KEY_UP = ecore_event_type_new();
100 ECORE_WIN32_EVENT_MOUSE_BUTTON_DOWN = ecore_event_type_new();
101 ECORE_WIN32_EVENT_MOUSE_BUTTON_UP = ecore_event_type_new();
102 ECORE_WIN32_EVENT_MOUSE_MOVE = ecore_event_type_new();
103 ECORE_WIN32_EVENT_MOUSE_IN = ecore_event_type_new();
104 ECORE_WIN32_EVENT_MOUSE_OUT = ecore_event_type_new();
105 ECORE_WIN32_EVENT_MOUSE_WHEEL = ecore_event_type_new();
106 ECORE_WIN32_EVENT_WINDOW_FOCUS_IN = ecore_event_type_new();
107 ECORE_WIN32_EVENT_WINDOW_FOCUS_OUT = ecore_event_type_new();
108 ECORE_WIN32_EVENT_WINDOW_DAMAGE = ecore_event_type_new();
109 ECORE_WIN32_EVENT_WINDOW_CREATE = ecore_event_type_new();
110 ECORE_WIN32_EVENT_WINDOW_DESTROY = ecore_event_type_new();
111 ECORE_WIN32_EVENT_WINDOW_SHOW = ecore_event_type_new();
112 ECORE_WIN32_EVENT_WINDOW_HIDE = ecore_event_type_new();
113 ECORE_WIN32_EVENT_WINDOW_CONFIGURE = ecore_event_type_new();
114 ECORE_WIN32_EVENT_WINDOW_RESIZE = ecore_event_type_new();
115 ECORE_WIN32_EVENT_WINDOW_DELETE_REQUEST = ecore_event_type_new();
118 _ecore_win32_init_count++;
120 return _ecore_win32_init_count;
124 ecore_win32_shutdown()
126 _ecore_win32_init_count++;
127 if (_ecore_win32_init_count > 0) return _ecore_win32_init_count;
128 if (!_ecore_win32_instance) return _ecore_win32_init_count;
130 UnregisterClass(ECORE_WIN32_WINDOW_CLASS, _ecore_win32_instance);
131 FreeLibrary(_ecore_win32_instance);
132 _ecore_win32_instance = NULL;
134 if (_ecore_win32_init_count < 0) _ecore_win32_init_count = 0;
136 return _ecore_win32_init_count;
140 ecore_win32_screen_depth_get()
149 depth = GetDeviceCaps(dc, BITSPIXEL);
156 * Sets the timeout for a double and triple clicks to be flagged.
158 * This sets the time between clicks before the double_click flag is
159 * set in a button down event. If 3 clicks occur within double this
160 * time, the triple_click flag is also set.
162 * @param t The time in seconds
165 ecore_win32_double_click_time_set(double t)
167 if (t < 0.0) t = 0.0;
168 _ecore_win32_double_click_time = t;
172 * Retrieves the double and triple click flag timeout.
174 * See @ref ecore_win32_double_click_time_set for more information.
176 * @return The timeout for double clicks in seconds.
179 ecore_win32_double_click_time_get(void)
181 return _ecore_win32_double_click_time;
185 * Return the last event time
188 ecore_win32_current_time_get(void)
190 return _ecore_win32_event_last_time;
194 /***** Private functions definitions *****/
198 _ecore_win32_window_procedure(HWND window,
203 Ecore_Win32_Callback_Data *data;
207 data = (Ecore_Win32_Callback_Data *)malloc(sizeof(Ecore_Win32_Callback_Data));
208 if (!data) return DefWindowProc(window, message, window_param, data_param);
210 data->window = window;
211 data->message = message;
212 data->window_param = window_param;
213 data->data_param = data_param;
214 data->time = GetMessageTime();
215 coord = GetMessagePos();
216 pt = MAKEPOINTS(coord);
220 switch (data->message)
222 /* Keyboard input notifications */
224 printf (" * ecore message : keystroke down\n");
225 _ecore_win32_event_handle_key_press(data, 1);
228 _ecore_win32_event_handle_key_press(data, 0);
231 printf (" * ecore message : keystroke up\n");
232 _ecore_win32_event_handle_key_release(data, 1);
235 printf (" * ecore message : focus in\n");
236 _ecore_win32_event_handle_focus_in(data);
239 printf (" * ecore message : focus out\n");
240 _ecore_win32_event_handle_focus_out(data);
242 /* Mouse input notifications */
244 printf (" * ecore message : lbuttondown\n");
245 _ecore_win32_event_handle_button_press(data, 1);
248 printf (" * ecore message : mbuttondown\n");
249 _ecore_win32_event_handle_button_press(data, 2);
252 printf (" * ecore message : rbuttondown\n");
253 _ecore_win32_event_handle_button_press(data, 3);
256 printf (" * ecore message : lbuttonup\n");
257 _ecore_win32_event_handle_button_release(data, 1);
260 printf (" * ecore message : mbuttonup\n");
261 _ecore_win32_event_handle_button_release(data, 2);
264 printf (" * ecore message : rbuttonup\n");
265 _ecore_win32_event_handle_button_release(data, 3);
270 struct _Ecore_Win32_Window *w = NULL;
272 w = (struct _Ecore_Win32_Window *)GetWindowLong(window, GWL_USERDATA);
274 if (GetClientRect(window, &rect))
278 pt.x = GET_X_LPARAM(data_param);
279 pt.y = GET_Y_LPARAM(data_param);
280 if (!PtInRect(&rect, pt))
282 if (w->pointer_is_in)
284 w->pointer_is_in = 0;
285 _ecore_win32_event_handle_leave_notify(data);
290 if (!w->pointer_is_in)
292 w->pointer_is_in = 1;
293 _ecore_win32_event_handle_enter_notify(data);
298 _ecore_win32_event_handle_motion_notify(data);
303 printf (" * ecore message : mouse wheel\n");
304 _ecore_win32_event_handle_button_press(data, 4);
306 /* Window notifications */
310 GetClientRect(window, &rect);
311 printf (" *** ecore message : create %ld %ld\n",
312 rect.right - rect.left, rect.bottom - rect.top);
314 _ecore_win32_event_handle_create_notify(data);
317 printf (" * ecore message : destroy\n");
318 _ecore_win32_event_handle_destroy_notify(data);
323 GetClientRect(window, &rect);
324 printf (" *** ecore message : show %ld %ld\n",
325 rect.right - rect.left, rect.bottom - rect.top);
327 if ((data->data_param == SW_OTHERUNZOOM) ||
328 (data->data_param == SW_OTHERUNZOOM))
331 if (data->window_param)
332 _ecore_win32_event_handle_map_notify(data);
334 _ecore_win32_event_handle_unmap_notify(data);
338 printf (" * ecore message : close\n");
339 _ecore_win32_event_handle_delete_request(data);
342 printf (" * ecore message : moving\n");
345 printf (" * ecore message : moved\n");
348 printf (" * ecore message : sizing\n");
349 _ecore_win32_event_handle_resize(data);
350 _ecore_win32_event_handle_configure_notify(data);
353 printf (" * ecore message : sized\n");
355 /* case WM_WINDOWPOSCHANGING: */
358 /* GetClientRect(window, &rect); */
359 /* printf (" *** ecore message : WINDOWPOSCHANGING %ld %ld\n", */
360 /* rect.right - rect.left, rect.bottom - rect.top); */
362 /* _ecore_win32_event_handle_configure_notify(data); */
364 case WM_WINDOWPOSCHANGED:
367 GetClientRect(window, &rect);
368 printf (" *** ecore message : WINDOWPOSCHANGED %ld %ld\n",
369 rect.right - rect.left, rect.bottom - rect.top);
371 _ecore_win32_event_handle_configure_notify(data);
373 case WM_ENTERSIZEMOVE :
374 printf (" * ecore message : WM_ENTERSIZEMOVE \n");
376 case WM_EXITSIZEMOVE:
377 printf (" * ecore message : WM_EXITSIZEMOVE\n");
379 /* GDI notifications */
384 printf (" * ecore message : paint\n");
385 if (GetUpdateRect(window, &rect, FALSE))
390 hdc = BeginPaint(window, &ps);
392 _ecore_win32_event_handle_expose(data);
393 EndPaint(window, &ps);
394 printf (" * %ld %ld %ld %ld\n",
397 rect.right - rect.left,
398 rect.bottom - rect.top);
403 printf (" * ecore message : WM_SETREDRAW\n");
406 printf (" * ecore message : WM_SYNCPAINT\n");
409 return DefWindowProc(window, message, window_param, data_param);