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
16 #include "Ecore_Win32.h"
17 #include "ecore_win32_private.h"
20 /***** Private declarations *****/
23 typedef enum _Ecore_Win32_Window_Z_Order Ecore_Win32_Window_Z_Order;
24 enum _Ecore_Win32_Window_Z_Order
26 ECORE_WIN32_WINDOW_Z_ORDER_BOTTOM,
27 ECORE_WIN32_WINDOW_Z_ORDER_NOTOPMOST,
28 ECORE_WIN32_WINDOW_Z_ORDER_TOP,
29 ECORE_WIN32_WINDOW_Z_ORDER_TOPMOST
32 static Ecore_Win32_Window *ecore_win32_window_internal_new(Ecore_Win32_Window *parent,
43 ecore_win32_window_new(Ecore_Win32_Window *parent,
49 return ecore_win32_window_internal_new(parent,
52 WS_OVERLAPPEDWINDOW | WS_SIZEBOX);
55 /* simulate X11 override windows */
57 ecore_win32_window_override_new(Ecore_Win32_Window *parent,
63 return ecore_win32_window_internal_new(parent,
70 ecore_win32_window_del(Ecore_Win32_Window *window)
74 DestroyWindow(((struct _Ecore_Win32_Window *)window)->window);
76 printf ("ecore_win32_window_del\n");
80 ecore_win32_window_hwnd_get(Ecore_Win32_Window *window)
82 if (!window) return NULL;
84 return ((struct _Ecore_Win32_Window *)window)->window;
89 ecore_win32_window_configure(Ecore_Win32_Window *window,
90 Ecore_Win32_Window_Z_Order order,
100 case ECORE_WIN32_WINDOW_Z_ORDER_BOTTOM:
103 case ECORE_WIN32_WINDOW_Z_ORDER_NOTOPMOST:
106 case ECORE_WIN32_WINDOW_Z_ORDER_TOP:
109 case ECORE_WIN32_WINDOW_Z_ORDER_TOPMOST:
115 SetWindowPos((struct _Ecore_Win32_Window *)window->window, w, x, y, width, height, ???);
120 ecore_win32_window_move(Ecore_Win32_Window *window,
129 printf ("ecore_win32_window_move %p : %d %d\n", window, x, y);
130 w = ((struct _Ecore_Win32_Window *)window)->window;
131 if (!GetWindowRect(w, &rect))
135 rect.right - rect.left,
136 rect.bottom - rect.top,
141 ecore_win32_window_resize(Ecore_Win32_Window *window,
146 struct _Ecore_Win32_Window *w;
153 w = (struct _Ecore_Win32_Window *)window;
154 if (!GetWindowRect(w->window, &rect)) return;
156 printf ("ecore_win32_window_resize 0 : %p (%d %d) (%d %d) (%d %d)\n",
169 /* if (width < w->min_width) width = w->min_width; */
170 /* if (width > w->max_width) width = w->max_width; */
171 /* printf ("ecore_win32_window_resize 1 : %d %d %d\n", w->min_height, w->max_height, height); */
172 /* if (height < w->min_height) height = w->min_height; */
173 /* printf ("ecore_win32_window_resize 2 : %d %d\n", w->max_height, height); */
174 /* if (height > w->max_height) height = w->max_height; */
175 /* printf ("ecore_win32_window_resize 3 : %d %d\n", w->max_height, height); */
177 rect.bottom = height;
178 style = GetWindowLong(w->window, GWL_STYLE);
179 if (!AdjustWindowRect(&rect, style, FALSE))
182 if (!MoveWindow(w->window, x, y,
183 rect.right - rect.left,
184 rect.bottom - rect.top,
187 printf (" MEEERDE !!!\n");
189 printf ("ecore_win32_window_resize 4 : %d %d\n", width, height);
193 ecore_win32_window_move_resize(Ecore_Win32_Window *window,
200 struct _Ecore_Win32_Window *w;
205 printf ("ecore_win32_window_move_resize 0 : %p %d %d\n", window, width, height);
206 w = ((struct _Ecore_Win32_Window *)window);
209 if ((unsigned int)width < w->min_width) width = w->min_width;
210 if ((unsigned int)width > w->max_width) width = w->max_width;
211 if ((unsigned int)height < w->min_height) height = w->min_height;
212 if ((unsigned int)height > w->max_height) height = w->max_height;
213 printf ("ecore_win32_window_move_resize 1 : %d %d\n", width, height);
215 rect.bottom = height;
216 style = GetWindowLong(w->window, GWL_STYLE);
217 if (!AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_SIZEBOX, FALSE))
220 MoveWindow(w->window, x, y,
221 rect.right - rect.left,
222 rect.bottom - rect.top,
227 ecore_win32_window_geometry_get(Ecore_Win32_Window *window,
237 printf ("ecore_win32_window_geometry_get %p\n", window);
242 if (width) *width = GetSystemMetrics(SM_CXSCREEN);
243 if (height) *height = GetSystemMetrics(SM_CYSCREEN);
248 if (!GetClientRect(((struct _Ecore_Win32_Window *)window)->window,
253 if (width) *width = 0;
254 if (height) *height = 0;
259 w = rect.right - rect.left;
260 h = rect.bottom - rect.top;
262 if (!GetWindowRect(((struct _Ecore_Win32_Window *)window)->window,
267 if (width) *width = 0;
268 if (height) *height = 0;
273 if (x) *x = rect.left;
274 if (y) *y = rect.top;
275 if (width) *width = w;
276 if (height) *height = h;
280 ecore_win32_window_size_get(Ecore_Win32_Window *window,
286 printf ("ecore_win32_window_size_get %p\n", window);
289 if (width) *width = GetSystemMetrics(SM_CXSCREEN);
290 if (height) *height = GetSystemMetrics(SM_CYSCREEN);
295 if (!GetClientRect(((struct _Ecore_Win32_Window *)window)->window,
298 if (width) *width = 0;
299 if (height) *height = 0;
302 if (width) *width = rect.right - rect.left;
303 if (height) *height = rect.bottom - rect.top;
307 ecore_win32_window_size_min_set(Ecore_Win32_Window *window,
308 unsigned int min_width,
309 unsigned int min_height)
311 struct _Ecore_Win32_Window *w;
315 printf ("ecore_win32_window_size_min_set : %p %d %d\n", window, min_width, min_height);
316 w = (struct _Ecore_Win32_Window *)window;
317 w->min_width = min_width;
318 w->min_height = min_height;
322 ecore_win32_window_size_min_get(Ecore_Win32_Window *window,
323 unsigned int *min_width,
324 unsigned int *min_height)
326 struct _Ecore_Win32_Window *w;
330 w = (struct _Ecore_Win32_Window *)window;
331 printf ("ecore_win32_window_size_min_get : %p %d %d\n", window, w->min_width, w->min_height);
332 if (min_width) *min_width = w->min_width;
333 if (min_height) *min_height = w->min_height;
337 ecore_win32_window_size_max_set(Ecore_Win32_Window *window,
338 unsigned int max_width,
339 unsigned int max_height)
341 struct _Ecore_Win32_Window *w;
345 printf ("ecore_win32_window_size_max_set : %p %d %d\n", window, max_width, max_height);
346 w = (struct _Ecore_Win32_Window *)window;
347 w->max_width = max_width;
348 w->max_height = max_height;
352 ecore_win32_window_size_max_get(Ecore_Win32_Window *window,
353 unsigned int *max_width,
354 unsigned int *max_height)
356 struct _Ecore_Win32_Window *w;
360 w = (struct _Ecore_Win32_Window *)window;
361 printf ("ecore_win32_window_size_max_get : %p %d %d\n", window, w->max_width, w->max_height);
362 if (max_width) *max_width = w->max_width;
363 if (max_height) *max_height = w->max_height;
367 ecore_win32_window_size_base_set(Ecore_Win32_Window *window,
368 unsigned int base_width,
369 unsigned int base_height)
371 struct _Ecore_Win32_Window *w;
373 printf ("ecore_win32_window_size_base_set : %p %d %d\n", window, base_width, base_height);
376 w = (struct _Ecore_Win32_Window *)window;
377 w->base_width = base_width;
378 w->base_height = base_height;
382 ecore_win32_window_size_base_get(Ecore_Win32_Window *window,
383 unsigned int *base_width,
384 unsigned int *base_height)
386 struct _Ecore_Win32_Window *w;
390 w = (struct _Ecore_Win32_Window *)window;
391 printf ("ecore_win32_window_size_base_get : %p %d %d\n", window, w->base_width, w->base_height);
392 if (base_width) *base_width = w->base_width;
393 if (base_height) *base_height = w->base_height;
397 ecore_win32_window_size_step_set(Ecore_Win32_Window *window,
398 unsigned int step_width,
399 unsigned int step_height)
401 struct _Ecore_Win32_Window *w;
403 printf ("ecore_win32_window_size_step_set : %p %d %d\n", window, step_width, step_height);
406 w = (struct _Ecore_Win32_Window *)window;
407 w->step_width = step_width;
408 w->step_height = step_height;
412 ecore_win32_window_size_step_get(Ecore_Win32_Window *window,
413 unsigned int *step_width,
414 unsigned int *step_height)
416 struct _Ecore_Win32_Window *w;
420 w = (struct _Ecore_Win32_Window *)window;
421 printf ("ecore_win32_window_size_step_get : %p %d %d\n", window, w->step_width, w->step_height);
422 if (step_width) *step_width = w->step_width;
423 if (step_height) *step_height = w->step_height;
426 /* TODO: ecore_win32_window_shaped_set */
429 ecore_win32_window_show(Ecore_Win32_Window *window)
433 printf (" ** ecore_win32_window_show %p\n", window);
434 ShowWindow(((struct _Ecore_Win32_Window *)window)->window, SW_SHOWNORMAL);
435 UpdateWindow(((struct _Ecore_Win32_Window *)window)->window);
438 /* FIXME: seems to block the taskbar */
440 ecore_win32_window_hide(Ecore_Win32_Window *window)
444 printf (" ** ecore_win32_window_hide %p\n", window);
445 ShowWindow(((struct _Ecore_Win32_Window *)window)->window, SW_HIDE);
449 ecore_win32_window_raise(Ecore_Win32_Window *window)
453 printf (" ** ecore_win32_window_raise %p\n", window);
454 SetWindowPos(((struct _Ecore_Win32_Window *)window)->window,
455 HWND_TOP, 0, 0, 0, 0,
456 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
460 ecore_win32_window_lower(Ecore_Win32_Window *window)
464 printf (" ** ecore_win32_window_lower %p\n", window);
465 SetWindowPos(((struct _Ecore_Win32_Window *)window)->window,
466 HWND_BOTTOM, 0, 0, 0, 0,
467 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
471 ecore_win32_window_title_set(Ecore_Win32_Window *window,
476 if (!title || !title[0]) return;
478 SetWindowText(((struct _Ecore_Win32_Window *)window)->window, title);
482 ecore_win32_window_focus_set(Ecore_Win32_Window *window)
486 SetFocus(((struct _Ecore_Win32_Window *)window)->window);
490 ecore_win32_window_iconified_set(Ecore_Win32_Window *window,
493 struct _Ecore_Win32_Window *ew;
497 ew = (struct _Ecore_Win32_Window *)window;
498 if (((ew->iconified) && (on)) ||
499 ((!ew->iconified) && (!on)))
504 ShowWindow(ew->window,
509 ShowWindow(ew->window,
516 ecore_win32_window_borderless_set(Ecore_Win32_Window *window,
521 struct _Ecore_Win32_Window *ew;
526 printf (" ** ecore_win32_window_borderless_set %p %d\n", window, on);
527 ew = (struct _Ecore_Win32_Window *)window;
528 if (((ew->borderless) && (on)) ||
529 ((!ew->borderless) && (!on)))
534 style = GetWindowLong(w, GWL_STYLE);
537 if (!GetClientRect(w, &rect)) return;
538 SetWindowLong(w, GWL_STYLE, style & ~WS_CAPTION);
542 if (!GetWindowRect(w, &rect)) return;
544 AdjustWindowRect (&rect, style, FALSE);
545 SetWindowLong(w, GWL_STYLE, style);
547 SetWindowPos(w, HWND_TOPMOST,
549 rect.right - rect.left, rect.bottom - rect.top,
550 SWP_NOMOVE | SWP_FRAMECHANGED);
555 ecore_win32_window_fullscreen_set(Ecore_Win32_Window *window,
558 struct _Ecore_Win32_Window *ew;
565 ew = (struct _Ecore_Win32_Window *)window;
566 if (((ew->fullscreen) && (on)) ||
567 ((!ew->fullscreen) && (!on)))
575 if (!GetWindowRect(w, &ew->rect)) return;
576 ew->style = GetWindowLong(w, GWL_STYLE);
577 width = GetSystemMetrics (SM_CXSCREEN);
578 height = GetSystemMetrics (SM_CYSCREEN);
579 if (!SetWindowLong(w, GWL_STYLE,
580 (ew->style & ~WS_OVERLAPPEDWINDOW) | WS_POPUP))
582 SetWindowPos(w, HWND_TOP, 0, 0, width, height,
583 SWP_NOCOPYBITS | SWP_SHOWWINDOW);
587 if (!SetWindowLong(w, GWL_STYLE, ew->style))
589 SetWindowPos(w, HWND_NOTOPMOST,
592 ew->rect.right - ew->rect.left,
593 ew->rect.bottom - ew->rect.top,
594 SWP_NOCOPYBITS | SWP_SHOWWINDOW);
599 ecore_win32_window_cursor_set(Ecore_Win32_Window *window,
600 Ecore_Win32_Cursor *cursor)
602 SetClassLong(((struct _Ecore_Win32_Window *)window)->window,
603 GCL_HCURSOR, (LONG)cursor);
607 ecore_win32_window_state_set(Ecore_Win32_Window *window,
608 Ecore_Win32_Window_State *state,
616 for (i = 0; i < num; i++)
620 case ECORE_WIN32_WINDOW_STATE_ICONIFIED:
621 ((struct _Ecore_Win32_Window *)window)->state.iconified = 1;
623 case ECORE_WIN32_WINDOW_STATE_MODAL:
624 ((struct _Ecore_Win32_Window *)window)->state.modal = 1;
626 case ECORE_WIN32_WINDOW_STATE_STICKY:
627 ((struct _Ecore_Win32_Window *)window)->state.sticky = 1;
629 case ECORE_WIN32_WINDOW_STATE_MAXIMIZED_VERT:
630 ((struct _Ecore_Win32_Window *)window)->state.maximized_vert = 1;
632 case ECORE_WIN32_WINDOW_STATE_MAXIMIZED_HORZ:
633 ((struct _Ecore_Win32_Window *)window)->state.maximized_horz = 1;
635 case ECORE_WIN32_WINDOW_STATE_MAXIMIZED:
636 ((struct _Ecore_Win32_Window *)window)->state.maximized_horz = 1;
637 ((struct _Ecore_Win32_Window *)window)->state.maximized_vert = 1;
639 case ECORE_WIN32_WINDOW_STATE_SHADED:
640 ((struct _Ecore_Win32_Window *)window)->state.shaded = 1;
642 case ECORE_WIN32_WINDOW_STATE_HIDDEN:
643 ((struct _Ecore_Win32_Window *)window)->state.hidden = 1;
645 case ECORE_WIN32_WINDOW_STATE_FULLSCREEN:
646 ((struct _Ecore_Win32_Window *)window)->state.fullscreen = 1;
648 case ECORE_WIN32_WINDOW_STATE_ABOVE:
649 ((struct _Ecore_Win32_Window *)window)->state.above = 1;
651 case ECORE_WIN32_WINDOW_STATE_BELOW:
652 ((struct _Ecore_Win32_Window *)window)->state.below = 1;
654 case ECORE_WIN32_WINDOW_STATE_DEMANDS_ATTENTION:
655 ((struct _Ecore_Win32_Window *)window)->state.demands_attention = 1;
657 case ECORE_WIN32_WINDOW_STATE_UNKNOWN:
658 /* nothing to be done */
665 ecore_win32_window_state_request_send(Ecore_Win32_Window *window,
666 Ecore_Win32_Window_State state,
674 case ECORE_WIN32_WINDOW_STATE_ICONIFIED:
675 if (((struct _Ecore_Win32_Window *)window)->state.iconified)
676 ecore_win32_window_iconified_set(window, set);
678 case ECORE_WIN32_WINDOW_STATE_MODAL:
679 ((struct _Ecore_Win32_Window *)window)->state.modal = 1;
681 case ECORE_WIN32_WINDOW_STATE_STICKY:
682 ((struct _Ecore_Win32_Window *)window)->state.sticky = 1;
684 case ECORE_WIN32_WINDOW_STATE_MAXIMIZED_VERT:
685 if (((struct _Ecore_Win32_Window *)window)->state.maximized_vert)
691 if (!SystemParametersInfo(SPI_GETWORKAREA, 0,
695 height = rect.bottom - rect.top;
697 if (!GetClientRect(((struct _Ecore_Win32_Window *)window)->window,
701 MoveWindow(window, rect.left, y,
702 rect.right - rect.left,
707 case ECORE_WIN32_WINDOW_STATE_MAXIMIZED_HORZ:
708 if (((struct _Ecore_Win32_Window *)window)->state.maximized_horz)
712 if (!GetClientRect(((struct _Ecore_Win32_Window *)window)->window,
716 MoveWindow(window, 0, rect.top,
717 GetSystemMetrics(SM_CXSCREEN),
718 rect.bottom - rect.top,
722 case ECORE_WIN32_WINDOW_STATE_MAXIMIZED:
723 if (((struct _Ecore_Win32_Window *)window)->state.maximized_vert &&
724 ((struct _Ecore_Win32_Window *)window)->state.maximized_horz)
728 if (!SystemParametersInfo(SPI_GETWORKAREA, 0,
732 MoveWindow(window, 0, 0,
733 GetSystemMetrics(SM_CXSCREEN),
734 rect.bottom - rect.top,
738 case ECORE_WIN32_WINDOW_STATE_SHADED:
739 ((struct _Ecore_Win32_Window *)window)->state.shaded = 1;
741 case ECORE_WIN32_WINDOW_STATE_HIDDEN:
742 ((struct _Ecore_Win32_Window *)window)->state.hidden = 1;
744 case ECORE_WIN32_WINDOW_STATE_FULLSCREEN:
745 if (((struct _Ecore_Win32_Window *)window)->state.fullscreen)
746 ecore_win32_window_fullscreen_set(window, set);
748 case ECORE_WIN32_WINDOW_STATE_ABOVE:
749 if (((struct _Ecore_Win32_Window *)window)->state.above)
750 SetWindowPos(((struct _Ecore_Win32_Window *)window)->window,
754 SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
756 case ECORE_WIN32_WINDOW_STATE_BELOW:
757 if (((struct _Ecore_Win32_Window *)window)->state.below)
758 SetWindowPos(((struct _Ecore_Win32_Window *)window)->window,
762 SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
764 case ECORE_WIN32_WINDOW_STATE_DEMANDS_ATTENTION:
765 ((struct _Ecore_Win32_Window *)window)->state.demands_attention = 1;
767 case ECORE_WIN32_WINDOW_STATE_UNKNOWN:
768 /* nothing to be done */
774 ecore_win32_window_type_set(Ecore_Win32_Window *window,
775 Ecore_Win32_Window_Type type)
779 case ECORE_WIN32_WINDOW_TYPE_DESKTOP:
780 ((struct _Ecore_Win32_Window *)window)->type.desktop = 1;
782 case ECORE_WIN32_WINDOW_TYPE_DOCK:
783 ((struct _Ecore_Win32_Window *)window)->type.dock = 1;
785 case ECORE_WIN32_WINDOW_TYPE_TOOLBAR:
786 ((struct _Ecore_Win32_Window *)window)->type.toolbar = 1;
788 case ECORE_WIN32_WINDOW_TYPE_MENU:
789 ((struct _Ecore_Win32_Window *)window)->type.menu = 1;
791 case ECORE_WIN32_WINDOW_TYPE_UTILITY:
792 ((struct _Ecore_Win32_Window *)window)->type.utility = 1;
794 case ECORE_WIN32_WINDOW_TYPE_SPLASH:
795 ((struct _Ecore_Win32_Window *)window)->type.splash = 1;
797 case ECORE_WIN32_WINDOW_TYPE_DIALOG:
798 ((struct _Ecore_Win32_Window *)window)->type.dialog = 1;
800 case ECORE_WIN32_WINDOW_TYPE_NORMAL:
801 ((struct _Ecore_Win32_Window *)window)->type.normal = 1;
803 case ECORE_WIN32_WINDOW_TYPE_UNKNOWN:
804 ((struct _Ecore_Win32_Window *)window)->type.normal = 1;
810 /***** Private functions definitions *****/
812 static Ecore_Win32_Window *
813 ecore_win32_window_internal_new(Ecore_Win32_Window *parent,
821 struct _Ecore_Win32_Window *w;
825 w = (struct _Ecore_Win32_Window *)calloc(1, sizeof(struct _Ecore_Win32_Window));
829 printf (" *** ecore_win32_window_new : %p %d %d %d\n",
831 width, height, GetSystemMetrics(SM_CXMIN));
835 rect.bottom = height;
836 if (!AdjustWindowRect(&rect, style, FALSE))
841 printf (" * ecore : new debut : %ld %d %d\n",
842 rect.right - rect.left, GetSystemMetrics(SM_CXMIN), GetSystemMetrics(SM_CYMIN));
844 minimal_width = GetSystemMetrics(SM_CXMIN);
845 minimal_height = GetSystemMetrics(SM_CYMIN);
846 /* if (((rect.right - rect.left) < minimal_width) || */
847 /* ((rect.bottom - rect.top) < minimal_height)) */
849 /* fprintf (stderr, "[Ecore] [Win32] ERROR !!\n"); */
850 /* fprintf (stderr, " Wrong size %ld\n", rect.right - rect.left); */
854 if ((rect.right - rect.left) < minimal_width)
856 rect.right = rect.left + minimal_width;
859 w->window = CreateWindow(ECORE_WIN32_WINDOW_CLASS, "",
862 rect.right - rect.left,
863 rect.bottom - rect.top,
864 parent ? ((struct _Ecore_Win32_Window *)parent)->window : NULL,
865 NULL, _ecore_win32_instance, NULL);
873 if (!SetWindowLong(w->window, GWL_USERDATA, (LONG)w) && (GetLastError() != 0))
875 DestroyWindow(w->window);
882 w->max_width = 32767;
883 w->max_height = 32767;
889 w->state.iconified = 0;
892 w->state.maximized_vert = 0;
893 w->state.maximized_horz = 0;
896 w->state.fullscreen = 0;
899 w->state.demands_attention = 0;
910 w->pointer_is_in = 0;
915 printf (" *** ecore_win32_window_new fin : (%d %d) (%d %d)\n",