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 /* OLE IID for Drag'n Drop */
28 # include <basetyps.h>
29 DEFINE_OLEGUID(IID_IEnumFORMATETC, 0x00000103L, 0, 0);
30 DEFINE_OLEGUID(IID_IDataObject, 0x0000010EL, 0, 0);
31 DEFINE_OLEGUID(IID_IDropSource, 0x00000121L, 0, 0);
32 DEFINE_OLEGUID(IID_IDropTarget, 0x00000122L, 0, 0);
33 DEFINE_OLEGUID(IID_IUnknown, 0x00000000L, 0, 0);
36 /***** Global declarations *****/
38 HINSTANCE _ecore_win32_instance = NULL;
39 double _ecore_win32_double_click_time = 0.25;
40 long _ecore_win32_event_last_time = 0;
41 Ecore_Win32_Window *_ecore_win32_event_last_window = NULL;
42 int _ecore_win32_log_dom_global = -1;
44 int ECORE_WIN32_EVENT_MOUSE_IN = 0;
45 int ECORE_WIN32_EVENT_MOUSE_OUT = 0;
46 int ECORE_WIN32_EVENT_WINDOW_FOCUS_IN = 0;
47 int ECORE_WIN32_EVENT_WINDOW_FOCUS_OUT = 0;
48 int ECORE_WIN32_EVENT_WINDOW_DAMAGE = 0;
49 int ECORE_WIN32_EVENT_WINDOW_CREATE = 0;
50 int ECORE_WIN32_EVENT_WINDOW_DESTROY = 0;
51 int ECORE_WIN32_EVENT_WINDOW_SHOW = 0;
52 int ECORE_WIN32_EVENT_WINDOW_HIDE = 0;
53 int ECORE_WIN32_EVENT_WINDOW_CONFIGURE = 0;
54 int ECORE_WIN32_EVENT_WINDOW_RESIZE = 0;
55 int ECORE_WIN32_EVENT_WINDOW_DELETE_REQUEST = 0;
58 /***** Private declarations *****/
60 static int _ecore_win32_init_count = 0;
62 LRESULT CALLBACK _ecore_win32_window_procedure(HWND window,
67 static void _ecore_win32_error_print_cb(const Eina_Log_Domain *d,
85 if (++_ecore_win32_init_count != 1)
86 return _ecore_win32_init_count;
89 return --_ecore_win32_init_count;
91 eina_log_print_cb_set(_ecore_win32_error_print_cb, NULL);
92 _ecore_win32_log_dom_global = eina_log_domain_register("ecore_win32", ECORE_WIN32_DEFAULT_LOG_COLOR);
93 if (_ecore_win32_log_dom_global < 0)
95 EINA_LOG_ERR("Ecore_Win32: Could not register log domain");
99 if (!ecore_event_init())
101 ERR("Ecore_Win32: Could not init ecore_event");
102 goto unregister_log_domain;
105 _ecore_win32_instance = GetModuleHandle(NULL);
106 if (!_ecore_win32_instance)
108 ERR("GetModuleHandle() failed");
109 goto shutdown_ecore_event;
112 memset (&wc, 0, sizeof (WNDCLASS));
113 wc.style = CS_HREDRAW | CS_VREDRAW;
114 wc.lpfnWndProc = _ecore_win32_window_procedure;
117 wc.hInstance = _ecore_win32_instance;
118 wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
119 wc.hCursor = LoadCursor (NULL, IDC_ARROW);
120 wc.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
121 wc.lpszMenuName = NULL;
122 wc.lpszClassName = ECORE_WIN32_WINDOW_CLASS;
124 if(!RegisterClass(&wc))
126 ERR("RegisterClass() failed");
130 if (!ecore_win32_dnd_init())
132 ERR("ecore_win32_dnd_init() failed");
133 goto unregister_class;
136 if (!ECORE_WIN32_EVENT_MOUSE_IN)
138 ECORE_WIN32_EVENT_MOUSE_IN = ecore_event_type_new();
139 ECORE_WIN32_EVENT_MOUSE_OUT = ecore_event_type_new();
140 ECORE_WIN32_EVENT_WINDOW_FOCUS_IN = ecore_event_type_new();
141 ECORE_WIN32_EVENT_WINDOW_FOCUS_OUT = ecore_event_type_new();
142 ECORE_WIN32_EVENT_WINDOW_DAMAGE = ecore_event_type_new();
143 ECORE_WIN32_EVENT_WINDOW_CREATE = ecore_event_type_new();
144 ECORE_WIN32_EVENT_WINDOW_DESTROY = ecore_event_type_new();
145 ECORE_WIN32_EVENT_WINDOW_SHOW = ecore_event_type_new();
146 ECORE_WIN32_EVENT_WINDOW_HIDE = ecore_event_type_new();
147 ECORE_WIN32_EVENT_WINDOW_CONFIGURE = ecore_event_type_new();
148 ECORE_WIN32_EVENT_WINDOW_RESIZE = ecore_event_type_new();
149 ECORE_WIN32_EVENT_WINDOW_DELETE_REQUEST = ecore_event_type_new();
152 return _ecore_win32_init_count;
155 UnregisterClass(ECORE_WIN32_WINDOW_CLASS, _ecore_win32_instance);
157 FreeLibrary(_ecore_win32_instance);
158 shutdown_ecore_event:
159 ecore_event_shutdown();
160 unregister_log_domain:
161 eina_log_domain_unregister(_ecore_win32_log_dom_global);
165 return --_ecore_win32_init_count;
169 ecore_win32_shutdown()
171 if (--_ecore_win32_init_count != 0)
172 return _ecore_win32_init_count;
174 ecore_win32_dnd_shutdown();
176 if (!UnregisterClass(ECORE_WIN32_WINDOW_CLASS, _ecore_win32_instance))
177 INF("UnregisterClass() failed");
179 if (!FreeLibrary(_ecore_win32_instance))
180 INF("FreeLibrary() failed");
182 _ecore_win32_instance = NULL;
184 ecore_event_shutdown();
185 eina_log_domain_unregister(_ecore_win32_log_dom_global);
186 _ecore_win32_log_dom_global = -1;
189 return _ecore_win32_init_count;
193 ecore_win32_screen_depth_get()
198 INF("getting screen depth");
203 ERR("GetDC() failed");
207 depth = GetDeviceCaps(dc, BITSPIXEL);
208 if (!ReleaseDC(NULL, dc))
210 ERR("ReleaseDC() failed (device context not released)");
217 * Sets the timeout for a double and triple clicks to be flagged.
219 * This sets the time between clicks before the double_click flag is
220 * set in a button down event. If 3 clicks occur within double this
221 * time, the triple_click flag is also set.
223 * @param t The time in seconds
226 ecore_win32_double_click_time_set(double t)
228 if (t < 0.0) t = 0.0;
229 _ecore_win32_double_click_time = t;
233 * Retrieves the double and triple click flag timeout.
235 * See @ref ecore_win32_double_click_time_set for more information.
237 * @return The timeout for double clicks in seconds.
240 ecore_win32_double_click_time_get(void)
242 return _ecore_win32_double_click_time;
246 * Return the last event time
249 ecore_win32_current_time_get(void)
251 return _ecore_win32_event_last_time;
255 /***** Private functions definitions *****/
259 _ecore_win32_window_procedure(HWND window,
264 Ecore_Win32_Callback_Data *data;
268 data = (Ecore_Win32_Callback_Data *)malloc(sizeof(Ecore_Win32_Callback_Data));
269 if (!data) return DefWindowProc(window, message, window_param, data_param);
271 data->window = window;
272 data->message = message;
273 data->window_param = window_param;
274 data->data_param = data_param;
275 data->time = GetMessageTime();
276 coord = GetMessagePos();
277 pt = MAKEPOINTS(coord);
281 switch (data->message)
283 /* Keyboard input notifications */
285 _ecore_win32_event_handle_key_press(data, 1);
288 _ecore_win32_event_handle_key_press(data, 0);
291 _ecore_win32_event_handle_key_release(data, 1);
294 _ecore_win32_event_handle_focus_in(data);
297 _ecore_win32_event_handle_focus_out(data);
299 /* Mouse input notifications */
301 _ecore_win32_event_handle_button_press(data, 1);
304 _ecore_win32_event_handle_button_press(data, 2);
307 _ecore_win32_event_handle_button_press(data, 3);
310 _ecore_win32_event_handle_button_release(data, 1);
313 _ecore_win32_event_handle_button_release(data, 2);
316 _ecore_win32_event_handle_button_release(data, 3);
321 struct _Ecore_Win32_Window *w = NULL;
323 w = (struct _Ecore_Win32_Window *)GetWindowLong(window, GWL_USERDATA);
325 if (GetClientRect(window, &rect))
329 INF("mouse in window");
331 pt.x = GET_X_LPARAM(data_param);
332 pt.y = GET_Y_LPARAM(data_param);
333 if (!PtInRect(&rect, pt))
335 if (w->pointer_is_in)
337 w->pointer_is_in = 0;
338 _ecore_win32_event_handle_leave_notify(data);
343 if (!w->pointer_is_in)
345 w->pointer_is_in = 1;
346 _ecore_win32_event_handle_enter_notify(data);
352 ERR("GetClientRect() failed");
354 _ecore_win32_event_handle_motion_notify(data);
359 _ecore_win32_event_handle_button_press(data, 4);
361 /* Window notifications */
363 _ecore_win32_event_handle_create_notify(data);
366 _ecore_win32_event_handle_destroy_notify(data);
369 if ((data->data_param == SW_OTHERUNZOOM) ||
370 (data->data_param == SW_OTHERUNZOOM))
373 if (data->window_param)
374 _ecore_win32_event_handle_map_notify(data);
376 _ecore_win32_event_handle_unmap_notify(data);
380 _ecore_win32_event_handle_delete_request(data);
383 printf (" * ecore message : moving\n");
386 printf (" * ecore message : moved\n");
389 printf (" * ecore message : sizing\n");
390 _ecore_win32_event_handle_resize(data);
391 _ecore_win32_event_handle_configure_notify(data);
394 printf (" * ecore message : sized\n");
396 /* case WM_WINDOWPOSCHANGING: */
399 /* GetClientRect(window, &rect); */
400 /* printf (" *** ecore message : WINDOWPOSCHANGING %ld %ld\n", */
401 /* rect.right - rect.left, rect.bottom - rect.top); */
403 /* _ecore_win32_event_handle_configure_notify(data); */
405 case WM_WINDOWPOSCHANGED:
406 _ecore_win32_event_handle_configure_notify(data);
408 case WM_ENTERSIZEMOVE :
409 printf (" * ecore message : WM_ENTERSIZEMOVE \n");
411 case WM_EXITSIZEMOVE:
412 printf (" * ecore message : WM_EXITSIZEMOVE\n");
414 /* GDI notifications */
419 if (GetUpdateRect(window, &rect, FALSE))
424 hdc = BeginPaint(window, &ps);
426 _ecore_win32_event_handle_expose(data);
427 EndPaint(window, &ps);
432 printf (" * ecore message : WM_SETREDRAW\n");
435 printf (" * ecore message : WM_SYNCPAINT\n");
438 return DefWindowProc(window, message, window_param, data_param);
443 _ecore_win32_error_print_cb(const Eina_Log_Domain *d __UNUSED__,
444 Eina_Log_Level level __UNUSED__,
445 const char *file __UNUSED__,
449 void *data __UNUSED__,
452 fprintf(stderr, "[%s:%d] ", fnc, line);
453 vfprintf(stderr, fmt, args);