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 /* OLE IID for Drag'n Drop */
24 # include <basetyps.h>
25 DEFINE_OLEGUID(IID_IEnumFORMATETC, 0x00000103L, 0, 0);
26 DEFINE_OLEGUID(IID_IDataObject, 0x0000010EL, 0, 0);
27 DEFINE_OLEGUID(IID_IDropSource, 0x00000121L, 0, 0);
28 DEFINE_OLEGUID(IID_IDropTarget, 0x00000122L, 0, 0);
29 DEFINE_OLEGUID(IID_IUnknown, 0x00000000L, 0, 0);
32 /***** Global declarations *****/
34 HINSTANCE _ecore_win32_instance = NULL;
35 double _ecore_win32_double_click_time = 0.25;
36 long _ecore_win32_event_last_time = 0;
37 Ecore_Win32_Window *_ecore_win32_event_last_window = NULL;
38 int _ecore_win32_log_dom_global = -1;
40 int ECORE_WIN32_EVENT_MOUSE_IN = 0;
41 int ECORE_WIN32_EVENT_MOUSE_OUT = 0;
42 int ECORE_WIN32_EVENT_WINDOW_FOCUS_IN = 0;
43 int ECORE_WIN32_EVENT_WINDOW_FOCUS_OUT = 0;
44 int ECORE_WIN32_EVENT_WINDOW_DAMAGE = 0;
45 int ECORE_WIN32_EVENT_WINDOW_CREATE = 0;
46 int ECORE_WIN32_EVENT_WINDOW_DESTROY = 0;
47 int ECORE_WIN32_EVENT_WINDOW_SHOW = 0;
48 int ECORE_WIN32_EVENT_WINDOW_HIDE = 0;
49 int ECORE_WIN32_EVENT_WINDOW_CONFIGURE = 0;
50 int ECORE_WIN32_EVENT_WINDOW_RESIZE = 0;
51 int ECORE_WIN32_EVENT_WINDOW_DELETE_REQUEST = 0;
54 /***** Private declarations *****/
56 static int _ecore_win32_init_count = 0;
58 LRESULT CALLBACK _ecore_win32_window_procedure(HWND window,
63 static void _ecore_win32_error_print_cb(const Eina_Log_Domain *d,
81 if (++_ecore_win32_init_count != 1)
82 return _ecore_win32_init_count;
85 return --_ecore_win32_init_count;
87 eina_log_print_cb_set(_ecore_win32_error_print_cb, NULL);
88 _ecore_win32_log_dom_global = eina_log_domain_register("ecore_win32", ECORE_WIN32_DEFAULT_LOG_COLOR);
89 if (_ecore_win32_log_dom_global < 0)
91 EINA_LOG_ERR("Ecore_Win32: Could not register log domain");
95 if (!ecore_event_init())
97 ERR("Ecore_Win32: Could not init ecore_event");
98 goto unregister_log_domain;
101 _ecore_win32_instance = GetModuleHandle(NULL);
102 if (!_ecore_win32_instance)
104 ERR("GetModuleHandle() failed");
105 goto shutdown_ecore_event;
108 memset (&wc, 0, sizeof (WNDCLASS));
109 wc.style = CS_HREDRAW | CS_VREDRAW;
110 wc.lpfnWndProc = _ecore_win32_window_procedure;
113 wc.hInstance = _ecore_win32_instance;
114 wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
115 wc.hCursor = LoadCursor (NULL, IDC_ARROW);
116 wc.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
117 wc.lpszMenuName = NULL;
118 wc.lpszClassName = ECORE_WIN32_WINDOW_CLASS;
120 if(!RegisterClass(&wc))
122 ERR("RegisterClass() failed");
126 if (!ecore_win32_dnd_init())
128 ERR("ecore_win32_dnd_init() failed");
129 goto unregister_class;
132 if (!ECORE_WIN32_EVENT_MOUSE_IN)
134 ECORE_WIN32_EVENT_MOUSE_IN = ecore_event_type_new();
135 ECORE_WIN32_EVENT_MOUSE_OUT = ecore_event_type_new();
136 ECORE_WIN32_EVENT_WINDOW_FOCUS_IN = ecore_event_type_new();
137 ECORE_WIN32_EVENT_WINDOW_FOCUS_OUT = ecore_event_type_new();
138 ECORE_WIN32_EVENT_WINDOW_DAMAGE = ecore_event_type_new();
139 ECORE_WIN32_EVENT_WINDOW_CREATE = ecore_event_type_new();
140 ECORE_WIN32_EVENT_WINDOW_DESTROY = ecore_event_type_new();
141 ECORE_WIN32_EVENT_WINDOW_SHOW = ecore_event_type_new();
142 ECORE_WIN32_EVENT_WINDOW_HIDE = ecore_event_type_new();
143 ECORE_WIN32_EVENT_WINDOW_CONFIGURE = ecore_event_type_new();
144 ECORE_WIN32_EVENT_WINDOW_RESIZE = ecore_event_type_new();
145 ECORE_WIN32_EVENT_WINDOW_DELETE_REQUEST = ecore_event_type_new();
148 return _ecore_win32_init_count;
151 UnregisterClass(ECORE_WIN32_WINDOW_CLASS, _ecore_win32_instance);
153 FreeLibrary(_ecore_win32_instance);
154 shutdown_ecore_event:
155 ecore_event_shutdown();
156 unregister_log_domain:
157 eina_log_domain_unregister(_ecore_win32_log_dom_global);
161 return --_ecore_win32_init_count;
165 ecore_win32_shutdown()
167 if (--_ecore_win32_init_count != 0)
168 return _ecore_win32_init_count;
170 ecore_win32_dnd_shutdown();
172 if (!UnregisterClass(ECORE_WIN32_WINDOW_CLASS, _ecore_win32_instance))
173 INF("UnregisterClass() failed");
175 if (!FreeLibrary(_ecore_win32_instance))
176 INF("FreeLibrary() failed");
178 _ecore_win32_instance = NULL;
180 ecore_event_shutdown();
181 eina_log_domain_unregister(_ecore_win32_log_dom_global);
182 _ecore_win32_log_dom_global = -1;
185 return _ecore_win32_init_count;
189 ecore_win32_screen_depth_get()
194 INF("getting screen depth");
199 ERR("GetDC() failed");
203 depth = GetDeviceCaps(dc, BITSPIXEL);
204 if (!ReleaseDC(NULL, dc))
206 ERR("ReleaseDC() failed (device context not released)");
213 * Sets the timeout for a double and triple clicks to be flagged.
215 * This sets the time between clicks before the double_click flag is
216 * set in a button down event. If 3 clicks occur within double this
217 * time, the triple_click flag is also set.
219 * @param t The time in seconds
222 ecore_win32_double_click_time_set(double t)
224 if (t < 0.0) t = 0.0;
225 _ecore_win32_double_click_time = t;
229 * Retrieves the double and triple click flag timeout.
231 * See @ref ecore_win32_double_click_time_set for more information.
233 * @return The timeout for double clicks in seconds.
236 ecore_win32_double_click_time_get(void)
238 return _ecore_win32_double_click_time;
242 * Return the last event time
245 ecore_win32_current_time_get(void)
247 return _ecore_win32_event_last_time;
251 /***** Private functions definitions *****/
255 _ecore_win32_window_procedure(HWND window,
260 Ecore_Win32_Callback_Data *data;
264 data = (Ecore_Win32_Callback_Data *)malloc(sizeof(Ecore_Win32_Callback_Data));
265 if (!data) return DefWindowProc(window, message, window_param, data_param);
267 data->window = window;
268 data->message = message;
269 data->window_param = window_param;
270 data->data_param = data_param;
271 data->time = GetMessageTime();
272 coord = GetMessagePos();
273 pt = MAKEPOINTS(coord);
277 switch (data->message)
279 /* Keyboard input notifications */
281 _ecore_win32_event_handle_key_press(data, 1);
284 _ecore_win32_event_handle_key_press(data, 0);
287 _ecore_win32_event_handle_key_release(data, 1);
290 _ecore_win32_event_handle_focus_in(data);
293 _ecore_win32_event_handle_focus_out(data);
295 /* Mouse input notifications */
297 _ecore_win32_event_handle_button_press(data, 1);
300 _ecore_win32_event_handle_button_press(data, 2);
303 _ecore_win32_event_handle_button_press(data, 3);
306 _ecore_win32_event_handle_button_release(data, 1);
309 _ecore_win32_event_handle_button_release(data, 2);
312 _ecore_win32_event_handle_button_release(data, 3);
317 struct _Ecore_Win32_Window *w = NULL;
319 w = (struct _Ecore_Win32_Window *)GetWindowLong(window, GWL_USERDATA);
321 if (GetClientRect(window, &rect))
325 INF("mouse in window");
327 pt.x = GET_X_LPARAM(data_param);
328 pt.y = GET_Y_LPARAM(data_param);
329 if (!PtInRect(&rect, pt))
331 if (w->pointer_is_in)
333 w->pointer_is_in = 0;
334 _ecore_win32_event_handle_leave_notify(data);
339 if (!w->pointer_is_in)
341 w->pointer_is_in = 1;
342 _ecore_win32_event_handle_enter_notify(data);
348 ERR("GetClientRect() failed");
350 _ecore_win32_event_handle_motion_notify(data);
355 _ecore_win32_event_handle_button_press(data, 4);
357 /* Window notifications */
359 _ecore_win32_event_handle_create_notify(data);
362 _ecore_win32_event_handle_destroy_notify(data);
365 if ((data->data_param == SW_OTHERUNZOOM) ||
366 (data->data_param == SW_OTHERUNZOOM))
369 if (data->window_param)
370 _ecore_win32_event_handle_map_notify(data);
372 _ecore_win32_event_handle_unmap_notify(data);
376 _ecore_win32_event_handle_delete_request(data);
379 printf (" * ecore message : moving\n");
382 printf (" * ecore message : moved\n");
385 printf (" * ecore message : sizing\n");
386 _ecore_win32_event_handle_resize(data);
387 _ecore_win32_event_handle_configure_notify(data);
390 printf (" * ecore message : sized\n");
392 /* case WM_WINDOWPOSCHANGING: */
395 /* GetClientRect(window, &rect); */
396 /* printf (" *** ecore message : WINDOWPOSCHANGING %ld %ld\n", */
397 /* rect.right - rect.left, rect.bottom - rect.top); */
399 /* _ecore_win32_event_handle_configure_notify(data); */
401 case WM_WINDOWPOSCHANGED:
402 _ecore_win32_event_handle_configure_notify(data);
404 case WM_ENTERSIZEMOVE :
405 printf (" * ecore message : WM_ENTERSIZEMOVE \n");
407 case WM_EXITSIZEMOVE:
408 printf (" * ecore message : WM_EXITSIZEMOVE\n");
410 /* GDI notifications */
415 if (GetUpdateRect(window, &rect, FALSE))
420 hdc = BeginPaint(window, &ps);
422 _ecore_win32_event_handle_expose(data);
423 EndPaint(window, &ps);
428 printf (" * ecore message : WM_SETREDRAW\n");
431 printf (" * ecore message : WM_SYNCPAINT\n");
434 return DefWindowProc(window, message, window_param, data_param);
439 _ecore_win32_error_print_cb(const Eina_Log_Domain *d __UNUSED__,
440 Eina_Log_Level level __UNUSED__,
441 const char *file __UNUSED__,
445 void *data __UNUSED__,
448 fprintf(stderr, "[%s:%d] ", fnc, line);
449 vfprintf(stderr, fmt, args);