summaryrefslogtreecommitdiff
path: root/src/lib/ecore_win32/ecore_win32_window.c
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-12-02 22:35:45 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-12-02 22:35:45 +0000
commit7d6010b12c47a20e492da808e3192c3f87dab619 (patch)
tree26c6fd189e046a76560c0bc740b85f4d767ae399 /src/lib/ecore_win32/ecore_win32_window.c
parent53fc441d5475155965d92da89502fe4634a561b2 (diff)
merge: add escape ecore, fix several bugs
SVN revision: 79995
Diffstat (limited to 'src/lib/ecore_win32/ecore_win32_window.c')
-rw-r--r--src/lib/ecore_win32/ecore_win32_window.c1418
1 files changed, 1418 insertions, 0 deletions
diff --git a/src/lib/ecore_win32/ecore_win32_window.c b/src/lib/ecore_win32/ecore_win32_window.c
new file mode 100644
index 0000000..36f8a86
--- /dev/null
+++ b/src/lib/ecore_win32/ecore_win32_window.c
@@ -0,0 +1,1418 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdlib.h>
6#include <stdio.h> /* for printf */
7
8#define WIN32_LEAN_AND_MEAN
9#include <windows.h>
10#undef WIN32_LEAN_AND_MEAN
11
12#include <Eina.h>
13
14#include "Ecore_Win32.h"
15#include "ecore_win32_private.h"
16
17/*============================================================================*
18 * Local *
19 *============================================================================*/
20
21/**
22 * @cond LOCAL
23 */
24
25
26typedef enum _Ecore_Win32_Window_Z_Order Ecore_Win32_Window_Z_Order;
27enum _Ecore_Win32_Window_Z_Order
28{
29 ECORE_WIN32_WINDOW_Z_ORDER_BOTTOM,
30 ECORE_WIN32_WINDOW_Z_ORDER_NOTOPMOST,
31 ECORE_WIN32_WINDOW_Z_ORDER_TOP,
32 ECORE_WIN32_WINDOW_Z_ORDER_TOPMOST
33};
34
35static Ecore_Win32_Window *
36ecore_win32_window_internal_new(Ecore_Win32_Window *parent,
37 int x,
38 int y,
39 int width,
40 int height,
41 DWORD style)
42{
43 RECT rect;
44 Ecore_Win32_Window *w;
45 int minimal_width;
46 int minimal_height;
47
48 w = (Ecore_Win32_Window *)calloc(1, sizeof(Ecore_Win32_Window));
49 if (!w)
50 {
51 ERR("malloc() failed");
52 return NULL;
53 }
54
55 rect.left = 0;
56 rect.top = 0;
57 rect.right = width;
58 rect.bottom = height;
59 if (!AdjustWindowRectEx(&rect, style, FALSE, 0))
60 {
61 ERR("AdjustWindowRect() failed");
62 free(w);
63 return NULL;
64 }
65
66 minimal_width = GetSystemMetrics(SM_CXMIN);
67 minimal_height = GetSystemMetrics(SM_CYMIN);
68/* if (((rect.right - rect.left) < minimal_width) || */
69/* ((rect.bottom - rect.top) < minimal_height)) */
70/* { */
71/* fprintf (stderr, "[Ecore] [Win32] ERROR !!\n"); */
72/* fprintf (stderr, " Wrong size %ld\n", rect.right - rect.left); */
73/* free(w); */
74/* return NULL; */
75/* } */
76 if ((rect.right - rect.left) < minimal_width)
77 {
78 rect.right = rect.left + minimal_width;
79 }
80
81 w->window = CreateWindowEx(0,
82 ECORE_WIN32_WINDOW_CLASS, "",
83 style,
84 x, y,
85 rect.right - rect.left,
86 rect.bottom - rect.top,
87 parent ? parent->window : NULL,
88 NULL, _ecore_win32_instance, NULL);
89 if (!w->window)
90 {
91 ERR("CreateWindowEx() failed");
92 free(w);
93 return NULL;
94 }
95
96 SetLastError(0);
97 if (!SetWindowLongPtr(w->window, GWLP_USERDATA, (LONG_PTR)w) &&
98 (GetLastError() != 0))
99 {
100 ERR("SetWindowLongPtr() failed");
101 DestroyWindow(w->window);
102 free(w);
103 return NULL;
104 }
105
106 w->min_width = 0;
107 w->min_height = 0;
108 w->max_width = 32767;
109 w->max_height = 32767;
110 w->base_width = -1;
111 w->base_height = -1;
112 w->step_width = 1;
113 w->step_height = 1;
114
115 w->state.iconified = 0;
116 w->state.modal = 0;
117 w->state.sticky = 0;
118 w->state.maximized_vert = 0;
119 w->state.maximized_horz = 0;
120 w->state.shaded = 0;
121 w->state.hidden = 0;
122 w->state.fullscreen = 0;
123 w->state.above = 0;
124 w->state.below = 0;
125 w->state.demands_attention = 0;
126
127 w->type.desktop = 0;
128 w->type.dock = 0;
129 w->type.toolbar = 0;
130 w->type.menu = 0;
131 w->type.utility = 0;
132 w->type.splash = 0;
133 w->type.dialog = 0;
134 w->type.normal = 0;
135
136 w->pointer_is_in = 0;
137 w->borderless = 0;
138 w->iconified = 0;
139 w->fullscreen = 0;
140
141 return w;
142}
143
144/**
145 * @endcond
146 */
147
148
149/*============================================================================*
150 * Global *
151 *============================================================================*/
152
153/*============================================================================*
154 * API *
155 *============================================================================*/
156
157/**
158 * @addtogroup Ecore_Win32_Group Ecore_Win32 library
159 *
160 * @{
161 */
162
163/**
164 * @brief Creates a new window.
165 *
166 * @param parent The parent window.
167 * @param x The x coordinate of the top-left corner of the window.
168 * @param y The y coordinate of the top-left corner of the window.
169 * @param width The width of the window.
170 * @param height The height of hte window.
171 * @return A newly allocated window.
172 *
173 * This function creates a new window which parent is @p parent. @p width and
174 * @p height are the size of the window content (the client part),
175 * without the border and title bar. @p x and @p y are the system
176 * coordinates of the top left cerner of the window (that is, of the
177 * title bar). This function returns a newly created window on
178 * success, and @c NULL on failure.
179 */
180EAPI Ecore_Win32_Window *
181ecore_win32_window_new(Ecore_Win32_Window *parent,
182 int x,
183 int y,
184 int width,
185 int height)
186{
187 INF("creating window with border");
188
189 return ecore_win32_window_internal_new(parent,
190 x, y,
191 width, height,
192 WS_OVERLAPPEDWINDOW | WS_SIZEBOX);
193}
194
195/**
196 * @brief Creates a new borderless window.
197 *
198 * @param parent The parent window.
199 * @param x The x coordinate of the top-left corner of the window.
200 * @param y The y coordinate of the top-left corner of the window.
201 * @param width The width of the window.
202 * @param height The height of hte window.
203 * @return A newly allocated window.
204 *
205 * This function is the same than ecore_win32_window_override_new()
206 * but the returned window is borderless.
207 */
208EAPI Ecore_Win32_Window *
209ecore_win32_window_override_new(Ecore_Win32_Window *parent,
210 int x,
211 int y,
212 int width,
213 int height)
214{
215 INF("creating window without border");
216
217 return ecore_win32_window_internal_new(parent,
218 x, y,
219 width, height,
220 WS_POPUP & ~(WS_CAPTION | WS_THICKFRAME));
221}
222
223/**
224 * @brief Free the given window.
225 *
226 * @param window The window to free.
227 *
228 * This function frees @p window. If @p window is @c NULL, this
229 * function does nothing.
230 */
231EAPI void
232ecore_win32_window_free(Ecore_Win32_Window *window)
233{
234 if (!window) return;
235
236 INF("destroying window");
237
238 if (window->shape.mask)
239 free(window->shape.mask);
240
241 DestroyWindow(window->window);
242 free(window);
243}
244
245/**
246 * @brief Return the window HANDLE associated to the given window.
247 *
248 * @param window The window to retrieve the HANDLE from.
249 *
250 * This function returns the window HANDLE associated to @p window. If
251 * @p window is @c NULL, this function returns @c NULL.
252 *
253 * @note The returned value is of type HWND.
254 */
255EAPI void *
256ecore_win32_window_hwnd_get(Ecore_Win32_Window *window)
257{
258 if (!window) return NULL;
259
260 return window->window;
261}
262
263/*
264void
265ecore_win32_window_configure(Ecore_Win32_Window *window,
266 Ecore_Win32_Window_Z_Order order,
267 int x,
268 int y,
269 int width,
270 int height)
271{
272 HWND w;
273
274 switch (order)
275 {
276 case ECORE_WIN32_WINDOW_Z_ORDER_BOTTOM:
277 w = HWND_BOTTOM;
278 break;
279 case ECORE_WIN32_WINDOW_Z_ORDER_NOTOPMOST:
280 w = HWND_NOTOPMOST;
281 break;
282 case ECORE_WIN32_WINDOW_Z_ORDER_TOP:
283 w = HWND_TOP;
284 break;
285 case ECORE_WIN32_WINDOW_Z_ORDER_TOPMOST:
286 w = HWND_TOPMOST;
287 break;
288 default:
289 return;
290 }
291 SetWindowPos((Ecore_Win32_Window *)window->window, w, x, y, width, height, ???);
292}
293*/
294
295/**
296 * @brief Move the given window to a given position.
297 *
298 * @param window The window to move.
299 * @param x The x coordinate of the destination position.
300 * @param y The y coordinate of the destination position.
301 *
302 * This function move @p window to the new position of coordinates @p x
303 * and @p y. If @p window is @c NULL, or if it is fullscreen, or on
304 * error, this function does nothing.
305 */
306EAPI void
307ecore_win32_window_move(Ecore_Win32_Window *window,
308 int x,
309 int y)
310{
311 RECT rect;
312
313 /* FIXME: on fullscreen, should not move it */
314 if (!window) return;
315
316 INF("moving window (%dx%d)", x, y);
317
318 if (!GetWindowRect(window->window, &rect))
319 {
320 ERR("GetWindowRect() failed");
321 return;
322 }
323
324 if (!MoveWindow(window->window, x, y,
325 rect.right - rect.left,
326 rect.bottom - rect.top,
327 TRUE))
328 {
329 ERR("MoveWindow() failed");
330 }
331}
332
333/**
334 * @brief Resize the given window to a given size.
335 *
336 * @param window The window to resize.
337 * @param width The new width.
338 * @param height The new height.
339 *
340 * This function resize @p window to the new @p width and @p height.
341 * If @p window is @c NULL, or if it is fullscreen, or on error, this
342 * function does nothing.
343 */
344EAPI void
345ecore_win32_window_resize(Ecore_Win32_Window *window,
346 int width,
347 int height)
348{
349 RECT rect;
350 DWORD style;
351 int x;
352 int y;
353 int minimal_width;
354 int minimal_height;
355
356 /* FIXME: on fullscreen, should not resize it */
357 if (!window) return;
358
359 INF("resizing window (%dx%d)", width, height);
360
361 minimal_width = MAX(GetSystemMetrics(SM_CXMIN), (int)window->min_width);
362 minimal_height = MAX(GetSystemMetrics(SM_CYMIN), (int)window->min_height);
363
364 if (!GetWindowRect(window->window, &rect))
365 {
366 ERR("GetWindowRect() failed");
367 return;
368 }
369
370 x = rect.left;
371 y = rect.top;
372 rect.left = 0;
373 rect.top = 0;
374 if (width < minimal_width) width = minimal_width;
375 if (width > (int)window->max_width) width = window->max_width;
376 if (height < minimal_height) height = minimal_height;
377 if (height > (int)window->max_height) height = window->max_height;
378 rect.right = width;
379 rect.bottom = height;
380 if (!(style = GetWindowLong(window->window, GWL_STYLE)))
381 {
382 ERR("GetWindowLong() failed");
383 return;
384 }
385 if (!AdjustWindowRect(&rect, style, FALSE))
386 {
387 ERR("AdjustWindowRect() failed");
388 return;
389 }
390
391 if (!MoveWindow(window->window, x, y,
392 rect.right - rect.left,
393 rect.bottom - rect.top,
394 TRUE))
395 {
396 ERR("MoveWindow() failed");
397 }
398}
399
400/**
401 * @brief Move and resize the given window to a given position and size.
402 *
403 * @param window The window to move and resize.
404 * @param x The x coordinate of the destination position.
405 * @param y The x coordinate of the destination position.
406 * @param width The new width.
407 * @param height The new height.
408 *
409 * This function resize @p window to the new position of coordinates @p x
410 * and @p y and the new @p width and @p height. If @p window is @c NULL,
411 * or if it is fullscreen, or on error, this function does nothing.
412 */
413EAPI void
414ecore_win32_window_move_resize(Ecore_Win32_Window *window,
415 int x,
416 int y,
417 int width,
418 int height)
419{
420 RECT rect;
421 DWORD style;
422 int minimal_width;
423 int minimal_height;
424
425 /* FIXME: on fullscreen, should not move/resize it */
426 if (!window) return;
427
428 INF("moving and resizing window (%dx%d %dx%d)", x, y, width, height);
429
430 minimal_width = MAX(GetSystemMetrics(SM_CXMIN), (int)window->min_width);
431 minimal_height = MAX(GetSystemMetrics(SM_CYMIN), (int)window->min_height);
432
433 rect.left = 0;
434 rect.top = 0;
435 if (width < minimal_width) width = minimal_width;
436 if (width > (int)window->max_width) width = window->max_width;
437 if (height < minimal_height) height = minimal_height;
438 if (height > (int)window->max_height) height = window->max_height;
439 rect.right = width;
440 rect.bottom = height;
441 if (!(style = GetWindowLong(window->window, GWL_STYLE)))
442 {
443 ERR("GetWindowLong() failed");
444 return;
445 }
446 if (!AdjustWindowRect(&rect, style, FALSE))
447 {
448 ERR("AdjustWindowRect() failed");
449 return;
450 }
451
452 if (!MoveWindow(window->window, x, y,
453 rect.right - rect.left,
454 rect.bottom - rect.top,
455 TRUE))
456 {
457 ERR("MoveWindow() failed");
458 }
459}
460
461/**
462 * @brief Get the geometry of the given window.
463 *
464 * @param window The window to retrieve the geometry from.
465 * @param x The x coordinate of the position.
466 * @param y The x coordinate of the position.
467 * @param width The width.
468 * @param height The height.
469 *
470 * This function retrieves the position and size of @p window. @p x,
471 * @p y, @p width and @p height can be buffers that will be filled with
472 * the corresponding values. If one of them is @c NULL, nothing will
473 * be done for that parameter. If @p window is @c NULL, and if the
474 * buffers are not @c NULL, they will be filled with respectively 0,
475 * 0, the size of the screen and the height of the screen.
476 */
477EAPI void
478ecore_win32_window_geometry_get(Ecore_Win32_Window *window,
479 int *x,
480 int *y,
481 int *width,
482 int *height)
483{
484 RECT rect;
485 int w;
486 int h;
487
488 INF("getting window geometry");
489
490 if (!window)
491 {
492 if (x) *x = 0;
493 if (y) *y = 0;
494 if (width) *width = GetSystemMetrics(SM_CXSCREEN);
495 if (height) *height = GetSystemMetrics(SM_CYSCREEN);
496
497 return;
498 }
499
500 if (!GetClientRect(window->window, &rect))
501 {
502 ERR("GetClientRect() failed");
503
504 if (x) *x = 0;
505 if (y) *y = 0;
506 if (width) *width = 0;
507 if (height) *height = 0;
508
509 return;
510 }
511
512 w = rect.right - rect.left;
513 h = rect.bottom - rect.top;
514
515 if (!GetWindowRect(window->window, &rect))
516 {
517 ERR("GetWindowRect() failed");
518
519 if (x) *x = 0;
520 if (y) *y = 0;
521 if (width) *width = 0;
522 if (height) *height = 0;
523
524 return;
525 }
526
527 if (x) *x = rect.left;
528 if (y) *y = rect.top;
529 if (width) *width = w;
530 if (height) *height = h;
531}
532
533/**
534 * @brief Get the size of the given window.
535 *
536 * @param window The window to retrieve the size from.
537 * @param width The width.
538 * @param height The height.
539 *
540 * This function retrieves the size of @p window. @p width and
541 * @p height can be buffers that will be filled with the corresponding
542 * values. If one of them is @c NULL, nothing will be done for that
543 * parameter. If @p window is @c NULL, and if the buffers are not
544 * @c NULL, they will be filled with respectively the size of the screen
545 * and the height of the screen.
546 */
547EAPI void
548ecore_win32_window_size_get(Ecore_Win32_Window *window,
549 int *width,
550 int *height)
551{
552 RECT rect;
553
554 INF("getting window size");
555
556 if (!window)
557 {
558 if (width) *width = GetSystemMetrics(SM_CXSCREEN);
559 if (height) *height = GetSystemMetrics(SM_CYSCREEN);
560
561 return;
562 }
563
564 if (!GetClientRect(window->window, &rect))
565 {
566 ERR("GetClientRect() failed");
567
568 if (width) *width = 0;
569 if (height) *height = 0;
570 }
571
572 if (width) *width = rect.right - rect.left;
573 if (height) *height = rect.bottom - rect.top;
574}
575
576/**
577 * @brief Set the minimum size of the given window.
578 *
579 * @param window The window.
580 * @param min_width The minimal width.
581 * @param min_height The minimal height.
582 *
583 * This function sets the minimum size of @p window to @p min_width
584 * and *p min_height. If @p window is @c NULL, this functions does
585 * nothing.
586 */
587EAPI void
588ecore_win32_window_size_min_set(Ecore_Win32_Window *window,
589 unsigned int min_width,
590 unsigned int min_height)
591{
592 if (!window) return;
593
594 printf ("ecore_win32_window_size_min_set : %p %d %d\n", window, min_width, min_height);
595 window->min_width = min_width;
596 window->min_height = min_height;
597}
598
599/**
600 * @brief Get the minimum size of the given window.
601 *
602 * @param window The window.
603 * @param min_width The minimal width.
604 * @param min_height The minimal height.
605 *
606 * This function fills the minimum size of @p window in the buffers
607 * @p min_width and *p min_height. They both can be @c NULL. If
608 * @p window is @c NULL, this functions does nothing.
609 */
610EAPI void
611ecore_win32_window_size_min_get(Ecore_Win32_Window *window,
612 unsigned int *min_width,
613 unsigned int *min_height)
614{
615 if (!window) return;
616
617 printf ("ecore_win32_window_size_min_get : %p %d %d\n", window, window->min_width, window->min_height);
618 if (min_width) *min_width = window->min_width;
619 if (min_height) *min_height = window->min_height;
620}
621
622/**
623 * @brief Set the maximum size of the given window.
624 *
625 * @param window The window.
626 * @param max_width The maximal width.
627 * @param max_height The maximal height.
628 *
629 * This function sets the maximum size of @p window to @p max_width
630 * and *p max_height. If @p window is @c NULL, this functions does
631 * nothing.
632 */
633EAPI void
634ecore_win32_window_size_max_set(Ecore_Win32_Window *window,
635 unsigned int max_width,
636 unsigned int max_height)
637{
638 if (!window) return;
639
640 printf ("ecore_win32_window_size_max_set : %p %d %d\n", window, max_width, max_height);
641 window->max_width = max_width;
642 window->max_height = max_height;
643}
644
645/**
646 * @brief Get the maximum size of the given window.
647 *
648 * @param window The window.
649 * @param max_width The maximal width.
650 * @param max_height The maximal height.
651 *
652 * This function fills the maximum size of @p window in the buffers
653 * @p max_width and *p max_height. They both can be @c NULL. If
654 * @p window is @c NULL, this functions does nothing.
655 */
656EAPI void
657ecore_win32_window_size_max_get(Ecore_Win32_Window *window,
658 unsigned int *max_width,
659 unsigned int *max_height)
660{
661 if (!window) return;
662
663 printf ("ecore_win32_window_size_max_get : %p %d %d\n", window, window->max_width, window->max_height);
664 if (max_width) *max_width = window->max_width;
665 if (max_height) *max_height = window->max_height;
666}
667
668/**
669 * @brief Set the base size of the given window.
670 *
671 * @param window The window.
672 * @param base_width The base width.
673 * @param base_height The base height.
674 *
675 * This function sets the base size of @p window to @p base_width
676 * and *p base_height. If @p window is @c NULL, this functions does
677 * nothing.
678 */
679EAPI void
680ecore_win32_window_size_base_set(Ecore_Win32_Window *window,
681 unsigned int base_width,
682 unsigned int base_height)
683{
684 printf ("ecore_win32_window_size_base_set : %p %d %d\n", window, base_width, base_height);
685 if (!window) return;
686
687 window->base_width = base_width;
688 window->base_height = base_height;
689}
690
691/**
692 * @brief Get the base size of the given window.
693 *
694 * @param window The window.
695 * @param base_width The base width.
696 * @param base_height The bas height.
697 *
698 * This function fills the base size of @p window in the buffers
699 * @p base_width and *p base_height. They both can be @c NULL. If
700 * @p window is @c NULL, this functions does nothing.
701 */
702EAPI void
703ecore_win32_window_size_base_get(Ecore_Win32_Window *window,
704 unsigned int *base_width,
705 unsigned int *base_height)
706{
707 if (!window) return;
708
709 printf ("ecore_win32_window_size_base_get : %p %d %d\n", window, window->base_width, window->base_height);
710 if (base_width) *base_width = window->base_width;
711 if (base_height) *base_height = window->base_height;
712}
713
714/**
715 * @brief Set the step size of the given window.
716 *
717 * @param window The window.
718 * @param step_width The step width.
719 * @param step_height The step height.
720 *
721 * This function sets the step size of @p window to @p step_width
722 * and *p step_height. If @p window is @c NULL, this functions does
723 * nothing.
724 */
725EAPI void
726ecore_win32_window_size_step_set(Ecore_Win32_Window *window,
727 unsigned int step_width,
728 unsigned int step_height)
729{
730 printf ("ecore_win32_window_size_step_set : %p %d %d\n", window, step_width, step_height);
731 if (!window) return;
732
733 window->step_width = step_width;
734 window->step_height = step_height;
735}
736
737/**
738 * @brief Get the step size of the given window.
739 *
740 * @param window The window.
741 * @param step_width The step width.
742 * @param step_height The bas height.
743 *
744 * This function fills the step size of @p window in the buffers
745 * @p step_width and *p step_height. They both can be @c NULL. If
746 * @p window is @c NULL, this functions does nothing.
747 */
748EAPI void
749ecore_win32_window_size_step_get(Ecore_Win32_Window *window,
750 unsigned int *step_width,
751 unsigned int *step_height)
752{
753 if (!window) return;
754
755 printf ("ecore_win32_window_size_step_get : %p %d %d\n", window, window->step_width, window->step_height);
756 if (step_width) *step_width = window->step_width;
757 if (step_height) *step_height = window->step_height;
758}
759
760/**
761 * @brief Show the given window.
762 *
763 * @param window The window to show.
764 *
765 * This function shows @p window. If @p window is @c NULL, or on
766 * error, this function does nothing.
767 */
768EAPI void
769ecore_win32_window_show(Ecore_Win32_Window *window)
770{
771 if (!window) return;
772
773 INF("showing window");
774
775 ShowWindow(window->window, SW_SHOWNORMAL);
776 if (!UpdateWindow(window->window))
777 {
778 ERR("UpdateWindow() failed");
779 }
780}
781
782/* FIXME: seems to block the taskbar */
783/**
784 * @brief Hide the given window.
785 *
786 * @param window The window to show.
787 *
788 * This function hides @p window. If @p window is @c NULL, or on
789 * error, this function does nothing.
790 */
791EAPI void
792ecore_win32_window_hide(Ecore_Win32_Window *window)
793{
794 if (!window) return;
795
796 INF("hiding window");
797
798 ShowWindow(window->window, SW_HIDE);
799}
800
801/**
802 * @brief Place the given window at the top of the Z order.
803 *
804 * @param window The window to place at the top.
805 *
806 * This function places @p window at the top of the Z order. If
807 * @p window is @c NULL, this function does nothing.
808 */
809EAPI void
810ecore_win32_window_raise(Ecore_Win32_Window *window)
811{
812 if (!window) return;
813
814 INF("raising window");
815
816 if (!SetWindowPos(window->window,
817 HWND_TOP, 0, 0, 0, 0,
818 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE))
819 {
820 ERR("SetWindowPos() failed");
821 }
822}
823
824/**
825 * @brief Place the given window at the bottom of the Z order.
826 *
827 * @param window The window to place at the bottom.
828 *
829 * This function places @p window at the bottom of the Z order. If
830 * @p window is @c NULL, this function does nothing.
831 */
832EAPI void
833ecore_win32_window_lower(Ecore_Win32_Window *window)
834{
835 if (!window) return;
836
837 INF("lowering window");
838
839 if (!SetWindowPos(window->window,
840 HWND_BOTTOM, 0, 0, 0, 0,
841 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE))
842 {
843 ERR("SetWindowPos() failed");
844 }
845}
846
847/**
848 * @brief Set the title of the given window.
849 *
850 * @param window The window to set the title.
851 * @param title The new title.
852 *
853 * This function sets the title of @p window to @p title. If @p window
854 * is @c NULL, or if @p title is @c NULL or empty, or on error, this
855 * function does nothing.
856 */
857EAPI void
858ecore_win32_window_title_set(Ecore_Win32_Window *window,
859 const char *title)
860{
861 if (!window) return;
862
863 if (!title || !title[0]) return;
864
865 INF("setting window title");
866
867 if (!SetWindowText(window->window, title))
868 {
869 ERR("SetWindowText() failed");
870 }
871}
872
873/**
874 * @brief Set the focus to the given window.
875 *
876 * @param window The window to give focus to.
877 *
878 * This function gives the focus to @p window. If @p window is
879 * @c NULL, this function does nothing.
880 */
881EAPI void
882ecore_win32_window_focus(Ecore_Win32_Window *window)
883{
884 if (!window) return;
885
886 INF("focusing window");
887
888 if (!SetFocus(window->window))
889 {
890 ERR("SetFocus() failed");
891 }
892}
893
894/**
895 * @brief Get the current focused window.
896 *
897 * @return The window that has focus.
898 *
899 * This function returns the window that has focus. If the calling
900 * thread's message queue does not have an associated window with the
901 * keyboard focus, the return value is @c NULL.
902 *
903 * @note Even if the returned value is @c NULL, another thread's queue
904 * may be associated with a window that has the keyboard focus.
905 *
906 * @note The returned value is of type HWND.
907 */
908EAPI void *
909ecore_win32_window_focus_get(void)
910{
911 HWND focused;
912
913 INF("getting focused window");
914
915 focused = GetFocus();
916 if (!focused)
917 {
918 ERR("GetFocus() failed");
919 return NULL;
920 }
921
922 return focused;
923}
924
925/**
926 * @brief Iconify or restore the given window.
927 *
928 * @param window The window.
929 * @param on @c EINA_TRUE to iconify the window, @c EINA_FALSE to restore it.
930 *
931 * This function iconify or restore @p window. If @p on is set to @c EINA_TRUE,
932 * the window will be iconified, if it is set to @c EINA_FALSE, it will be
933 * restored. If @p window is @c NULL or if the state does not change (like
934 * iconifying the window while it is already iconified), this function does
935 * nothing.
936 */
937EAPI void
938ecore_win32_window_iconified_set(Ecore_Win32_Window *window,
939 Eina_Bool on)
940{
941 if (!window) return;
942
943 if (((window->iconified) && (on)) ||
944 ((!window->iconified) && (!on)))
945 return;
946
947 INF("iconifying window: %s", on ? "yes" : "no");
948
949 ShowWindow(window->window, on ? SW_MINIMIZE : SW_RESTORE);
950 window->iconified = on;
951}
952
953/**
954 * @brief Remove or restore the border of the given window.
955 *
956 * @param window The window.
957 * @param on @c EINA_TRUE to remove the border, @c EINA_FALSE to restore it.
958 *
959 * This function remove or restore the border of @p window. If @p on is set to
960 * @c EINA_TRUE, the window will have no border, if it is set to @c EINA_FALSE,
961 * it will have a border. If @p window is @c NULL or if the state does not
962 * change (like setting to borderless while the window has no border), this
963 * function does nothing.
964 */
965EAPI void
966ecore_win32_window_borderless_set(Ecore_Win32_Window *window,
967 Eina_Bool on)
968{
969 RECT rect;
970 DWORD style;
971
972 if (!window) return;
973
974 if (((window->borderless) && (on)) ||
975 ((!window->borderless) && (!on)))
976 return;
977
978 INF("setting window without border: %s", on ? "yes" : "no");
979
980 style = GetWindowLong(window->window, GWL_STYLE);
981 if (on)
982 {
983 if (!GetClientRect(window->window, &rect))
984 {
985 ERR("GetClientRect() failed");
986 return;
987 }
988 SetLastError(0);
989 if (!SetWindowLongPtr(window->window, GWL_STYLE, style & ~(WS_CAPTION | WS_THICKFRAME)) &&
990 (GetLastError() != 0))
991 {
992 ERR("SetWindowLongPtr() failed");
993 return;
994 }
995 }
996 else
997 {
998 if (!GetWindowRect(window->window, &rect))
999 {
1000 ERR("GetWindowRect() failed");
1001 return;
1002 }
1003 style |= WS_CAPTION | WS_THICKFRAME;
1004 if (!AdjustWindowRect (&rect, style, FALSE))
1005 {
1006 ERR("AdjustWindowRect() failed");
1007 return;
1008 }
1009 SetLastError(0);
1010 if (!SetWindowLongPtr(window->window, GWL_STYLE, style) &&
1011 (GetLastError() != 0))
1012 {
1013 ERR("SetWindowLongPtr() failed");
1014 return;
1015 }
1016 }
1017 if (!SetWindowPos(window->window, HWND_TOPMOST,
1018 rect.left, rect.top,
1019 rect.right - rect.left, rect.bottom - rect.top,
1020 SWP_NOMOVE | SWP_FRAMECHANGED))
1021 {
1022 ERR("SetWindowPos() failed");
1023 return;
1024 }
1025
1026 window->borderless = on;
1027}
1028
1029/**
1030 * @brief Set the given window to fullscreen.
1031 *
1032 * @param window The window.
1033 * @param on @c EINA_TRUE for fullscreen mode, @c EINA_FALSE for windowed mode.
1034 *
1035 * This function set @p window to fullscreen or windowed mode. If @p on is set
1036 * to @c EINA_TRUE, the window will be fullscreen, if it is set to
1037 * @c EINA_FALSE, it will be windowed. If @p window is @c NULL or if the state
1038 * does not change (like setting to fullscreen while the window is already
1039 * fullscreen), this function does nothing.
1040 */
1041EAPI void
1042ecore_win32_window_fullscreen_set(Ecore_Win32_Window *window,
1043 Eina_Bool on)
1044{
1045 if (!window) return;
1046
1047 if (((window->fullscreen) && (on)) ||
1048 ((!window->fullscreen) && (!on)))
1049 return;
1050
1051 INF("setting fullscreen: %s", on ? "yes" : "no");
1052
1053 window->fullscreen = !!on;
1054
1055 if (on)
1056 {
1057 DWORD style;
1058
1059 if (!GetWindowRect(window->window, &window->rect))
1060 {
1061 ERR("GetWindowRect() failed");
1062 return;
1063 }
1064 if (!(window->style = GetWindowLong(window->window, GWL_STYLE)))
1065 {
1066 ERR("GetWindowLong() failed");
1067 return;
1068 }
1069 style = window->style & ~WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX;
1070 style |= WS_VISIBLE | WS_POPUP;
1071 SetLastError(0);
1072 if (!SetWindowLongPtr(window->window, GWL_STYLE, style) &&
1073 (GetLastError() != 0))
1074 {
1075 ERR("SetWindowLongPtr() failed");
1076 return;
1077 }
1078 SetLastError(0);
1079 if (!SetWindowLongPtr(window->window, GWL_EXSTYLE, WS_EX_TOPMOST) &&
1080 (GetLastError() != 0))
1081 {
1082 ERR("SetWindowLongPtr() failed");
1083 return;
1084 }
1085 if (!SetWindowPos(window->window, HWND_TOPMOST, 0, 0,
1086 GetSystemMetrics (SM_CXSCREEN),
1087 GetSystemMetrics (SM_CYSCREEN),
1088 SWP_NOCOPYBITS | SWP_SHOWWINDOW))
1089 {
1090 ERR("SetWindowPos() failed");
1091 return;
1092 }
1093 }
1094 else
1095 {
1096 SetLastError(0);
1097 if (!SetWindowLongPtr(window->window, GWL_STYLE, window->style) &&
1098 (GetLastError() != 0))
1099 {
1100 ERR("SetWindowLongPtr() failed");
1101 return;
1102 }
1103 SetLastError(0);
1104 if (!SetWindowLongPtr(window->window, GWL_EXSTYLE, 0) &&
1105 (GetLastError() != 0))
1106 {
1107 ERR("SetWindowLongPtr() failed");
1108 return;
1109 }
1110 if (!SetWindowPos(window->window, HWND_NOTOPMOST,
1111 window->rect.left,
1112 window->rect.top,
1113 window->rect.right - window->rect.left,
1114 window->rect.bottom - window->rect.top,
1115 SWP_NOCOPYBITS | SWP_SHOWWINDOW))
1116 {
1117 ERR("SetWindowPos() failed");
1118 return;
1119 }
1120 }
1121}
1122
1123/**
1124 * @brief Set the given cursor to the given window.
1125 *
1126 * @param window The window to modify the cursor.
1127 * @param cursor The new cursor.
1128 *
1129 * This function sets @p cursor to @p window. @p cursor must have been
1130 * obtained by ecore_win32_cursor_new() or
1131 * ecore_win32_cursor_shaped_new(). If @p window or @p cursor is
1132 * @c NULL, the function does nothing.
1133 */
1134EAPI void
1135ecore_win32_window_cursor_set(Ecore_Win32_Window *window,
1136 Ecore_Win32_Cursor *cursor)
1137{
1138 INF("setting cursor");
1139
1140 if (!window || !cursor)
1141 return;
1142
1143 if (!SetClassLongPtr(window->window,
1144 GCLP_HCURSOR, (LONG_PTR)cursor))
1145 {
1146 ERR("SetClassLong() failed");
1147 }
1148}
1149
1150/**
1151 * @brief Set the state of the given window.
1152 *
1153 * @param window The window to modify the state.
1154 * @param state An array of the new states.
1155 * @param num The number of states in the array.
1156 *
1157 * This function set the state of @p window. @p state is an array of
1158 * states of size @p num. If @p window or @p state are @c NULL, or if
1159 * @p num is less or equal than 0, the function does nothing.
1160 */
1161EAPI void
1162ecore_win32_window_state_set(Ecore_Win32_Window *window,
1163 Ecore_Win32_Window_State *state,
1164 unsigned int num)
1165{
1166 unsigned int i;
1167
1168 if (!window || !state || (num <= 0))
1169 return;
1170
1171 INF("setting cursor state");
1172
1173 for (i = 0; i < num; i++)
1174 {
1175 switch (state[i])
1176 {
1177 case ECORE_WIN32_WINDOW_STATE_ICONIFIED:
1178 window->state.iconified = 1;
1179 break;
1180 case ECORE_WIN32_WINDOW_STATE_MODAL:
1181 window->state.modal = 1;
1182 break;
1183 case ECORE_WIN32_WINDOW_STATE_STICKY:
1184 window->state.sticky = 1;
1185 break;
1186 case ECORE_WIN32_WINDOW_STATE_MAXIMIZED_VERT:
1187 window->state.maximized_vert = 1;
1188 break;
1189 case ECORE_WIN32_WINDOW_STATE_MAXIMIZED_HORZ:
1190 window->state.maximized_horz = 1;
1191 break;
1192 case ECORE_WIN32_WINDOW_STATE_MAXIMIZED:
1193 window->state.maximized_horz = 1;
1194 window->state.maximized_vert = 1;
1195 break;
1196 case ECORE_WIN32_WINDOW_STATE_SHADED:
1197 window->state.shaded = 1;
1198 break;
1199 case ECORE_WIN32_WINDOW_STATE_HIDDEN:
1200 window->state.hidden = 1;
1201 break;
1202 case ECORE_WIN32_WINDOW_STATE_FULLSCREEN:
1203 window->state.fullscreen = 1;
1204 break;
1205 case ECORE_WIN32_WINDOW_STATE_ABOVE:
1206 window->state.above = 1;
1207 break;
1208 case ECORE_WIN32_WINDOW_STATE_BELOW:
1209 window->state.below = 1;
1210 break;
1211 case ECORE_WIN32_WINDOW_STATE_DEMANDS_ATTENTION:
1212 window->state.demands_attention = 1;
1213 break;
1214 case ECORE_WIN32_WINDOW_STATE_UNKNOWN:
1215 /* nothing to be done */
1216 break;
1217 }
1218 }
1219}
1220
1221/**
1222 * @brief Apply the modification of the state to the given window.
1223 *
1224 * @param window The window.
1225 * @param state The state to apply changes.
1226 * @param set The value of the state change.
1227 *
1228 * This function applies the modification of the state @p state of
1229 * @p window. @p set is used only for
1230 * #ECORE_WIN32_WINDOW_STATE_ICONIFIED and
1231 * #ECORE_WIN32_WINDOW_STATE_FULLSCREEN. If @p window is @c NULL, the
1232 * function does nothing.
1233 */
1234EAPI void
1235ecore_win32_window_state_request_send(Ecore_Win32_Window *window,
1236 Ecore_Win32_Window_State state,
1237 unsigned int set)
1238{
1239 if (!window) return;
1240
1241 INF("sending cursor state");
1242
1243 switch (state)
1244 {
1245 case ECORE_WIN32_WINDOW_STATE_ICONIFIED:
1246 if (window->state.iconified)
1247 ecore_win32_window_iconified_set(window, set);
1248 break;
1249 case ECORE_WIN32_WINDOW_STATE_MODAL:
1250 window->state.modal = 1;
1251 break;
1252 case ECORE_WIN32_WINDOW_STATE_STICKY:
1253 window->state.sticky = 1;
1254 break;
1255 case ECORE_WIN32_WINDOW_STATE_MAXIMIZED_VERT:
1256 if (window->state.maximized_vert)
1257 {
1258 RECT rect;
1259 int y;
1260 int height;
1261
1262 if (!SystemParametersInfo(SPI_GETWORKAREA, 0,
1263 &rect, 0))
1264 {
1265 ERR("SystemParametersInfo() failed");
1266 break;
1267 }
1268 y = rect.top;
1269 height = rect.bottom - rect.top;
1270
1271 if (!GetClientRect(window->window, &rect))
1272 {
1273 ERR("GetClientRect() failed");
1274 break;
1275 }
1276
1277 if (!MoveWindow(window->window, rect.left, y,
1278 rect.right - rect.left,
1279 height,
1280 TRUE))
1281 {
1282 ERR("MoveWindow() failed");
1283 }
1284 }
1285 break;
1286 case ECORE_WIN32_WINDOW_STATE_MAXIMIZED_HORZ:
1287 if (window->state.maximized_horz)
1288 {
1289 RECT rect;
1290
1291 if (!GetClientRect(window->window, &rect))
1292 {
1293 ERR("GetClientRect() failed");
1294 break;
1295 }
1296
1297 if (!MoveWindow(window->window, 0, rect.top,
1298 GetSystemMetrics(SM_CXSCREEN),
1299 rect.bottom - rect.top,
1300 TRUE))
1301 {
1302 ERR("MoveWindow() failed");
1303 }
1304 }
1305 break;
1306 case ECORE_WIN32_WINDOW_STATE_MAXIMIZED:
1307 if (window->state.maximized_vert && window->state.maximized_horz)
1308 {
1309 RECT rect;
1310
1311 if (!SystemParametersInfo(SPI_GETWORKAREA, 0,
1312 &rect, 0))
1313 {
1314 ERR("SystemParametersInfo() failed");
1315 break;
1316 }
1317
1318 if (!MoveWindow(window->window, 0, 0,
1319 GetSystemMetrics(SM_CXSCREEN),
1320 rect.bottom - rect.top,
1321 TRUE))
1322 {
1323 ERR("MoveWindow() failed");
1324 }
1325 }
1326 break;
1327 case ECORE_WIN32_WINDOW_STATE_SHADED:
1328 window->state.shaded = 1;
1329 break;
1330 case ECORE_WIN32_WINDOW_STATE_HIDDEN:
1331 window->state.hidden = 1;
1332 break;
1333 case ECORE_WIN32_WINDOW_STATE_FULLSCREEN:
1334 if (window->state.fullscreen)
1335 ecore_win32_window_fullscreen_set(window, set);
1336 break;
1337 case ECORE_WIN32_WINDOW_STATE_ABOVE:
1338 if (window->state.above)
1339 if (!SetWindowPos(window->window, HWND_TOP,
1340 0, 0,
1341 0, 0,
1342 SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW))
1343 {
1344 ERR("SetWindowPos() failed");
1345 }
1346 break;
1347 case ECORE_WIN32_WINDOW_STATE_BELOW:
1348 if (window->state.below)
1349 if (!SetWindowPos(window->window, HWND_BOTTOM,
1350 0, 0,
1351 0, 0,
1352 SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW))
1353 {
1354 ERR("SetWindowPos() failed");
1355 }
1356 break;
1357 case ECORE_WIN32_WINDOW_STATE_DEMANDS_ATTENTION:
1358 window->state.demands_attention = 1;
1359 break;
1360 case ECORE_WIN32_WINDOW_STATE_UNKNOWN:
1361 /* nothing to be done */
1362 break;
1363 }
1364}
1365
1366/**
1367 * @brief Set the type of the given window.
1368 *
1369 * @param window The window to modify the type.
1370 * @param type The nwindow types.
1371 *
1372 * This function set the type of @p window to @p type. If
1373 * @p window is @c NULL, the function does nothing.
1374 */
1375EAPI void
1376ecore_win32_window_type_set(Ecore_Win32_Window *window,
1377 Ecore_Win32_Window_Type type)
1378{
1379 if (!window)
1380 return;
1381
1382 INF("setting window type");
1383
1384 switch (type)
1385 {
1386 case ECORE_WIN32_WINDOW_TYPE_DESKTOP:
1387 window->type.desktop = 1;
1388 break;
1389 case ECORE_WIN32_WINDOW_TYPE_DOCK:
1390 window->type.dock = 1;
1391 break;
1392 case ECORE_WIN32_WINDOW_TYPE_TOOLBAR:
1393 window->type.toolbar = 1;
1394 break;
1395 case ECORE_WIN32_WINDOW_TYPE_MENU:
1396 window->type.menu = 1;
1397 break;
1398 case ECORE_WIN32_WINDOW_TYPE_UTILITY:
1399 window->type.utility = 1;
1400 break;
1401 case ECORE_WIN32_WINDOW_TYPE_SPLASH:
1402 window->type.splash = 1;
1403 break;
1404 case ECORE_WIN32_WINDOW_TYPE_DIALOG:
1405 window->type.dialog = 1;
1406 break;
1407 case ECORE_WIN32_WINDOW_TYPE_NORMAL:
1408 window->type.normal = 1;
1409 break;
1410 case ECORE_WIN32_WINDOW_TYPE_UNKNOWN:
1411 window->type.normal = 1;
1412 break;
1413 }
1414}
1415
1416/**
1417 * @}
1418 */