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"
20 /*============================================================================*
22 *============================================================================*/
28 /* OLE IID for Drag'n Drop */
31 # include <basetyps.h>
32 DEFINE_OLEGUID(IID_IEnumFORMATETC, 0x00000103L, 0, 0);
33 DEFINE_OLEGUID(IID_IDataObject, 0x0000010EL, 0, 0);
34 DEFINE_OLEGUID(IID_IDropSource, 0x00000121L, 0, 0);
35 DEFINE_OLEGUID(IID_IDropTarget, 0x00000122L, 0, 0);
36 DEFINE_OLEGUID(IID_IUnknown, 0x00000000L, 0, 0);
38 static int _ecore_win32_init_count = 0;
41 _ecore_win32_window_procedure(HWND window,
46 Ecore_Win32_Callback_Data *data;
50 data = (Ecore_Win32_Callback_Data *)malloc(sizeof(Ecore_Win32_Callback_Data));
51 if (!data) return DefWindowProc(window, message, window_param, data_param);
53 data->window = window;
54 data->message = message;
55 data->window_param = window_param;
56 data->data_param = data_param;
57 data->time = GetMessageTime();
58 coord = GetMessagePos();
59 pt = MAKEPOINTS(coord);
63 switch (data->message)
65 /* Keyboard input notifications */
67 _ecore_win32_event_handle_key_press(data, 1);
70 _ecore_win32_event_handle_key_press(data, 0);
73 _ecore_win32_event_handle_key_release(data, 1);
76 _ecore_win32_event_handle_focus_in(data);
79 _ecore_win32_event_handle_focus_out(data);
81 /* Mouse input notifications */
83 _ecore_win32_event_handle_button_press(data, 1);
86 _ecore_win32_event_handle_button_press(data, 2);
89 _ecore_win32_event_handle_button_press(data, 3);
92 _ecore_win32_event_handle_button_release(data, 1);
95 _ecore_win32_event_handle_button_release(data, 2);
98 _ecore_win32_event_handle_button_release(data, 3);
103 struct _Ecore_Win32_Window *w = NULL;
105 w = (struct _Ecore_Win32_Window *)GetWindowLong(window, GWL_USERDATA);
107 if (GetClientRect(window, &rect))
111 INF("mouse in window");
113 pt.x = GET_X_LPARAM(data_param);
114 pt.y = GET_Y_LPARAM(data_param);
115 if (!PtInRect(&rect, pt))
117 if (w->pointer_is_in)
119 w->pointer_is_in = 0;
120 _ecore_win32_event_handle_leave_notify(data);
125 if (!w->pointer_is_in)
127 w->pointer_is_in = 1;
128 _ecore_win32_event_handle_enter_notify(data);
134 ERR("GetClientRect() failed");
136 _ecore_win32_event_handle_motion_notify(data);
141 _ecore_win32_event_handle_button_press(data, 4);
143 /* Window notifications */
145 _ecore_win32_event_handle_create_notify(data);
148 _ecore_win32_event_handle_destroy_notify(data);
151 if ((data->data_param == SW_OTHERUNZOOM) ||
152 (data->data_param == SW_OTHERZOOM))
155 if (data->window_param)
156 _ecore_win32_event_handle_map_notify(data);
158 _ecore_win32_event_handle_unmap_notify(data);
162 _ecore_win32_event_handle_delete_request(data);
165 printf (" * ecore message : moving\n");
168 printf (" * ecore message : moved\n");
171 printf (" * ecore message : sizing\n");
172 _ecore_win32_event_handle_resize(data);
173 _ecore_win32_event_handle_configure_notify(data);
176 printf (" * ecore message : sized\n");
178 /* case WM_WINDOWPOSCHANGING: */
181 /* GetClientRect(window, &rect); */
182 /* printf (" *** ecore message : WINDOWPOSCHANGING %ld %ld\n", */
183 /* rect.right - rect.left, rect.bottom - rect.top); */
185 /* _ecore_win32_event_handle_configure_notify(data); */
187 case WM_WINDOWPOSCHANGED:
188 _ecore_win32_event_handle_configure_notify(data);
190 case WM_ENTERSIZEMOVE :
191 printf (" * ecore message : WM_ENTERSIZEMOVE \n");
193 case WM_EXITSIZEMOVE:
194 printf (" * ecore message : WM_EXITSIZEMOVE\n");
196 /* GDI notifications */
201 if (GetUpdateRect(window, &rect, FALSE))
206 hdc = BeginPaint(window, &ps);
208 _ecore_win32_event_handle_expose(data);
209 EndPaint(window, &ps);
214 printf (" * ecore message : WM_SETREDRAW\n");
217 printf (" * ecore message : WM_SYNCPAINT\n");
220 return DefWindowProc(window, message, window_param, data_param);
229 /*============================================================================*
231 *============================================================================*/
234 HINSTANCE _ecore_win32_instance = NULL;
235 double _ecore_win32_double_click_time = 0.25;
236 long _ecore_win32_event_last_time = 0;
237 Ecore_Win32_Window *_ecore_win32_event_last_window = NULL;
238 int _ecore_win32_log_dom_global = -1;
240 int ECORE_WIN32_EVENT_MOUSE_IN = 0;
241 int ECORE_WIN32_EVENT_MOUSE_OUT = 0;
242 int ECORE_WIN32_EVENT_WINDOW_FOCUS_IN = 0;
243 int ECORE_WIN32_EVENT_WINDOW_FOCUS_OUT = 0;
244 int ECORE_WIN32_EVENT_WINDOW_DAMAGE = 0;
245 int ECORE_WIN32_EVENT_WINDOW_CREATE = 0;
246 int ECORE_WIN32_EVENT_WINDOW_DESTROY = 0;
247 int ECORE_WIN32_EVENT_WINDOW_SHOW = 0;
248 int ECORE_WIN32_EVENT_WINDOW_HIDE = 0;
249 int ECORE_WIN32_EVENT_WINDOW_CONFIGURE = 0;
250 int ECORE_WIN32_EVENT_WINDOW_RESIZE = 0;
251 int ECORE_WIN32_EVENT_WINDOW_DELETE_REQUEST = 0;
253 /*============================================================================*
255 *============================================================================*/
258 * @addtogroup Ecore_Win32_Group Ecore_Win32 library
260 * Ecore_Win32 is a library that wraps Windows graphic functions
261 * and integrate them nicely into the Ecore main loop.
267 * @brief Initialize the Ecore_Win32 library.
269 * @return 1 or greater on success, 0 on error.
271 * This function sets up the Windows graphic system. It returns 0 on
272 * failure, otherwise it returns the number of times it has already been
275 * When Ecore_Win32 is not used anymore, call ecore_win32_shutdown()
276 * to shut down the Ecore_Win32 library.
283 if (++_ecore_win32_init_count != 1)
284 return _ecore_win32_init_count;
287 return --_ecore_win32_init_count;
289 _ecore_win32_log_dom_global = eina_log_domain_register
290 ("ecore_win32", ECORE_WIN32_DEFAULT_LOG_COLOR);
291 if (_ecore_win32_log_dom_global < 0)
293 EINA_LOG_ERR("Ecore_Win32: Could not register log domain");
297 if (!ecore_event_init())
299 ERR("Ecore_Win32: Could not init ecore_event");
300 goto unregister_log_domain;
303 _ecore_win32_instance = GetModuleHandle(NULL);
304 if (!_ecore_win32_instance)
306 ERR("GetModuleHandle() failed");
307 goto shutdown_ecore_event;
310 memset (&wc, 0, sizeof (WNDCLASS));
311 wc.style = CS_HREDRAW | CS_VREDRAW;
312 wc.lpfnWndProc = _ecore_win32_window_procedure;
315 wc.hInstance = _ecore_win32_instance;
316 wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
317 wc.hCursor = LoadCursor (NULL, IDC_ARROW);
318 wc.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
319 wc.lpszMenuName = NULL;
320 wc.lpszClassName = ECORE_WIN32_WINDOW_CLASS;
322 if(!RegisterClass(&wc))
324 ERR("RegisterClass() failed");
328 if (!ecore_win32_dnd_init())
330 ERR("ecore_win32_dnd_init() failed");
331 goto unregister_class;
334 if (!ECORE_WIN32_EVENT_MOUSE_IN)
336 ECORE_WIN32_EVENT_MOUSE_IN = ecore_event_type_new();
337 ECORE_WIN32_EVENT_MOUSE_OUT = ecore_event_type_new();
338 ECORE_WIN32_EVENT_WINDOW_FOCUS_IN = ecore_event_type_new();
339 ECORE_WIN32_EVENT_WINDOW_FOCUS_OUT = ecore_event_type_new();
340 ECORE_WIN32_EVENT_WINDOW_DAMAGE = ecore_event_type_new();
341 ECORE_WIN32_EVENT_WINDOW_CREATE = ecore_event_type_new();
342 ECORE_WIN32_EVENT_WINDOW_DESTROY = ecore_event_type_new();
343 ECORE_WIN32_EVENT_WINDOW_SHOW = ecore_event_type_new();
344 ECORE_WIN32_EVENT_WINDOW_HIDE = ecore_event_type_new();
345 ECORE_WIN32_EVENT_WINDOW_CONFIGURE = ecore_event_type_new();
346 ECORE_WIN32_EVENT_WINDOW_RESIZE = ecore_event_type_new();
347 ECORE_WIN32_EVENT_WINDOW_DELETE_REQUEST = ecore_event_type_new();
350 return _ecore_win32_init_count;
353 UnregisterClass(ECORE_WIN32_WINDOW_CLASS, _ecore_win32_instance);
355 FreeLibrary(_ecore_win32_instance);
356 shutdown_ecore_event:
357 ecore_event_shutdown();
358 unregister_log_domain:
359 eina_log_domain_unregister(_ecore_win32_log_dom_global);
363 return --_ecore_win32_init_count;
367 * @brief Shut down the Ecore_Win32 library.
369 * @return 0 when the library is completely shut down, 1 or
372 * This function shuts down the Ecore_Win32 library. It returns 0 when it has
373 * been called the same number of times than ecore_win32_init(). In that case
374 * it shuts down all the Windows graphic system.
377 ecore_win32_shutdown()
379 if (--_ecore_win32_init_count != 0)
380 return _ecore_win32_init_count;
382 ecore_win32_dnd_shutdown();
384 if (!UnregisterClass(ECORE_WIN32_WINDOW_CLASS, _ecore_win32_instance))
385 INF("UnregisterClass() failed");
387 if (!FreeLibrary(_ecore_win32_instance))
388 INF("FreeLibrary() failed");
390 _ecore_win32_instance = NULL;
392 ecore_event_shutdown();
393 eina_log_domain_unregister(_ecore_win32_log_dom_global);
394 _ecore_win32_log_dom_global = -1;
397 return _ecore_win32_init_count;
401 * @brief Retrieve the depth of the screen.
403 * @return The depth of the screen.
405 * This function returns the depth of the screen. If an error occurs,
409 ecore_win32_screen_depth_get()
414 INF("getting screen depth");
419 ERR("GetDC() failed");
423 depth = GetDeviceCaps(dc, BITSPIXEL);
424 if (!ReleaseDC(NULL, dc))
426 ERR("ReleaseDC() failed (device context not released)");
433 * @brief Sets the timeout for a double and triple clicks to be flagged.
435 * @param t The time in seconds.
437 * This function sets the time @p t between clicks before the
438 * double_click flag is set in a button down event. If 3 clicks occur
439 * within double this time, the triple_click flag is also set.
442 ecore_win32_double_click_time_set(double t)
444 if (t < 0.0) t = 0.0;
445 _ecore_win32_double_click_time = t;
449 * @brief Retrieve the double and triple click flag timeout.
451 * @return The timeout for double clicks in seconds.
453 * This function returns the double clicks in seconds. If
454 * ecore_win32_double_click_time_set() has not been called, the
455 * default value is returned. See ecore_win32_double_click_time_set()
456 * for more informations.
459 ecore_win32_double_click_time_get(void)
461 return _ecore_win32_double_click_time;
465 * @brief Return the last event time.
467 * @return The last envent time.
469 * This function returns the last event time.
472 ecore_win32_current_time_get(void)
474 return _ecore_win32_event_last_time;