a3129ee83c283a9cbfbac46c95172e84378e30b8
[framework/uifw/ecore.git] / src / lib / ecore_win32 / ecore_win32_window.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4
5 #ifdef HAVE_CONFIG_H
6 # include <config.h>
7 #endif
8
9 #include <stdlib.h>
10 #include <stdio.h>   /* for printf */
11
12 #define WIN32_LEAN_AND_MEAN
13 #include <windows.h>
14 #undef WIN32_LEAN_AND_MEAN
15
16 #include "Ecore_Win32.h"
17 #include "ecore_win32_private.h"
18
19
20 /***** Private declarations *****/
21
22
23 typedef enum _Ecore_Win32_Window_Z_Order Ecore_Win32_Window_Z_Order;
24 enum _Ecore_Win32_Window_Z_Order
25 {
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
30 };
31
32 static Ecore_Win32_Window *ecore_win32_window_internal_new(Ecore_Win32_Window *parent,
33                                                            int                 x,
34                                                            int                 y,
35                                                            int                 width,
36                                                            int                 height,
37                                                            DWORD               style);
38
39
40 /***** API *****/
41
42 Ecore_Win32_Window *
43 ecore_win32_window_new(Ecore_Win32_Window *parent,
44                        int                 x,
45                        int                 y,
46                        int                 width,
47                        int                 height)
48 {
49    return ecore_win32_window_internal_new(parent,
50                                           x, y,
51                                           width, height,
52                                           WS_OVERLAPPEDWINDOW | WS_SIZEBOX);
53 }
54
55 /* simulate X11 override windows */
56 Ecore_Win32_Window *
57 ecore_win32_window_override_new(Ecore_Win32_Window *parent,
58                                 int                 x,
59                                 int                 y,
60                                 int                 width,
61                                 int                 height)
62 {
63    return ecore_win32_window_internal_new(parent,
64                                           x, y,
65                                           width, height,
66                                           WS_POPUP);
67 }
68
69 void
70 ecore_win32_window_del(Ecore_Win32_Window *window)
71 {
72    if (!window) return;
73
74    DestroyWindow(((struct _Ecore_Win32_Window *)window)->window);
75    free(window);
76    printf ("ecore_win32_window_del\n");
77 }
78
79 void *
80 ecore_win32_window_hwnd_get(Ecore_Win32_Window *window)
81 {
82    if (!window) return NULL;
83
84    return ((struct _Ecore_Win32_Window *)window)->window;
85 }
86
87 /*
88 void
89 ecore_win32_window_configure(Ecore_Win32_Window        *window,
90                              Ecore_Win32_Window_Z_Order order,
91                              int                        x,
92                              int                        y,
93                              int                        width,
94                              int                        height)
95 {
96   HWND w;
97
98   switch (order)
99     {
100     case ECORE_WIN32_WINDOW_Z_ORDER_BOTTOM:
101       w = HWND_BOTTOM;
102       break;
103     case ECORE_WIN32_WINDOW_Z_ORDER_NOTOPMOST:
104       w = HWND_NOTOPMOST;
105       break;
106     case ECORE_WIN32_WINDOW_Z_ORDER_TOP:
107       w = HWND_TOP;
108       break;
109     case ECORE_WIN32_WINDOW_Z_ORDER_TOPMOST:
110       w = HWND_TOPMOST;
111       break;
112     default:
113       return;
114     }
115   SetWindowPos((struct _Ecore_Win32_Window *)window->window, w, x, y, width, height, ???);
116 }
117 */
118
119 void
120 ecore_win32_window_move(Ecore_Win32_Window *window,
121                         int                 x,
122                         int                 y)
123 {
124    RECT rect;
125    HWND w;
126
127    if (!window) return;
128
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))
132      return;
133
134    MoveWindow(w, x, y,
135               rect.right - rect.left,
136               rect.bottom - rect.top,
137               TRUE);
138 }
139
140 void
141 ecore_win32_window_resize(Ecore_Win32_Window *window,
142                           int                 width,
143                           int                 height)
144 {
145    RECT                        rect;
146    struct _Ecore_Win32_Window *w;
147    DWORD                       style;
148    int                         x;
149    int                         y;
150
151    if (!window) return;
152
153    w = (struct _Ecore_Win32_Window *)window;
154    if (!GetWindowRect(w->window, &rect)) return;
155
156    printf ("ecore_win32_window_resize 0 : %p (%d %d) (%d %d) (%d %d)\n",
157            w,
158            w->min_width,
159            w->min_height,
160            w->max_width,
161            w->max_height,
162            width,
163            height);
164
165    x = rect.left;
166    y = rect.top;
167    rect.left = 0;
168    rect.top = 0;
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); */
176    rect.right = width;
177    rect.bottom = height;
178    style = GetWindowLong(w->window, GWL_STYLE);
179    if (!AdjustWindowRect(&rect, style, FALSE))
180      return;
181
182    if (!MoveWindow(w->window, x, y,
183                    rect.right - rect.left,
184                    rect.bottom - rect.top,
185                    FALSE))
186      {
187        printf (" MEEERDE !!!\n");
188      }
189    printf ("ecore_win32_window_resize 4 : %d %d\n", width, height);
190 }
191
192 void
193 ecore_win32_window_move_resize(Ecore_Win32_Window *window,
194                                int                 x,
195                                int                 y,
196                                int                 width,
197                                int                 height)
198 {
199    RECT                        rect;
200    struct _Ecore_Win32_Window *w;
201    DWORD                       style;
202
203    if (!window) return;
204
205    printf ("ecore_win32_window_move_resize 0 : %p  %d %d\n", window, width, height);
206    w = ((struct _Ecore_Win32_Window *)window);
207    rect.left = 0;
208    rect.top = 0;
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);
214    rect.right = width;
215    rect.bottom = height;
216    style = GetWindowLong(w->window, GWL_STYLE);
217    if (!AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_SIZEBOX, FALSE))
218      return;
219
220    MoveWindow(w->window, x, y,
221               rect.right - rect.left,
222               rect.bottom - rect.top,
223               TRUE);
224 }
225
226 void
227 ecore_win32_window_geometry_get(Ecore_Win32_Window *window,
228                                 int                *x,
229                                 int                *y,
230                                 int                *width,
231                                 int                *height)
232 {
233    RECT rect;
234    int  w;
235    int  h;
236
237    printf ("ecore_win32_window_geometry_get %p\n", window);
238    if (!window)
239      {
240         if (x) *x = 0;
241         if (y) *y = 0;
242         if (width) *width = GetSystemMetrics(SM_CXSCREEN);
243         if (height) *height = GetSystemMetrics(SM_CYSCREEN);
244
245         return;
246      }
247
248    if (!GetClientRect(((struct _Ecore_Win32_Window *)window)->window,
249                       &rect))
250      {
251         if (x) *x = 0;
252         if (y) *y = 0;
253         if (width) *width = 0;
254         if (height) *height = 0;
255
256         return;
257      }
258
259    w = rect.right - rect.left;
260    h = rect.bottom - rect.top;
261
262    if (!GetWindowRect(((struct _Ecore_Win32_Window *)window)->window,
263                       &rect))
264      {
265         if (x) *x = 0;
266         if (y) *y = 0;
267         if (width) *width = 0;
268         if (height) *height = 0;
269
270         return;
271      }
272
273    if (x) *x = rect.left;
274    if (y) *y = rect.top;
275    if (width) *width = w;
276    if (height) *height = h;
277 }
278
279 void
280 ecore_win32_window_size_get(Ecore_Win32_Window *window,
281                             int                *width,
282                             int                *height)
283 {
284    RECT rect;
285
286    printf ("ecore_win32_window_size_get %p\n", window);
287    if (!window)
288      {
289         if (width) *width = GetSystemMetrics(SM_CXSCREEN);
290         if (height) *height = GetSystemMetrics(SM_CYSCREEN);
291
292         return;
293      }
294
295    if (!GetClientRect(((struct _Ecore_Win32_Window *)window)->window,
296                       &rect))
297      {
298         if (width) *width = 0;
299         if (height) *height = 0;
300      }
301
302    if (width) *width = rect.right - rect.left;
303    if (height) *height = rect.bottom - rect.top;
304 }
305
306 void
307 ecore_win32_window_size_min_set(Ecore_Win32_Window *window,
308                                 unsigned int        min_width,
309                                 unsigned int        min_height)
310 {
311    struct _Ecore_Win32_Window *w;
312
313    if (!window) return;
314
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;
319 }
320
321 void
322 ecore_win32_window_size_min_get(Ecore_Win32_Window *window,
323                                 unsigned int       *min_width,
324                                 unsigned int       *min_height)
325 {
326    struct _Ecore_Win32_Window *w;
327
328    if (!window) return;
329
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;
334 }
335
336 void
337 ecore_win32_window_size_max_set(Ecore_Win32_Window *window,
338                                 unsigned int        max_width,
339                                 unsigned int        max_height)
340 {
341    struct _Ecore_Win32_Window *w;
342
343    if (!window) return;
344
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;
349 }
350
351 void
352 ecore_win32_window_size_max_get(Ecore_Win32_Window *window,
353                                 unsigned int       *max_width,
354                                 unsigned int       *max_height)
355 {
356    struct _Ecore_Win32_Window *w;
357
358    if (!window) return;
359
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;
364 }
365
366 void
367 ecore_win32_window_size_base_set(Ecore_Win32_Window *window,
368                                  unsigned int        base_width,
369                                  unsigned int        base_height)
370 {
371    struct _Ecore_Win32_Window *w;
372
373    printf ("ecore_win32_window_size_base_set : %p  %d %d\n", window, base_width, base_height);
374    if (!window) return;
375
376    w = (struct _Ecore_Win32_Window *)window;
377    w->base_width = base_width;
378    w->base_height = base_height;
379 }
380
381 void
382 ecore_win32_window_size_base_get(Ecore_Win32_Window *window,
383                                  unsigned int       *base_width,
384                                  unsigned int       *base_height)
385 {
386    struct _Ecore_Win32_Window *w;
387
388    if (!window) return;
389
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;
394 }
395
396 void
397 ecore_win32_window_size_step_set(Ecore_Win32_Window *window,
398                                  unsigned int        step_width,
399                                  unsigned int        step_height)
400 {
401    struct _Ecore_Win32_Window *w;
402
403    printf ("ecore_win32_window_size_step_set : %p  %d %d\n", window, step_width, step_height);
404    if (!window) return;
405
406    w = (struct _Ecore_Win32_Window *)window;
407    w->step_width = step_width;
408    w->step_height = step_height;
409 }
410
411 void
412 ecore_win32_window_size_step_get(Ecore_Win32_Window *window,
413                                  unsigned int       *step_width,
414                                  unsigned int       *step_height)
415 {
416    struct _Ecore_Win32_Window *w;
417
418    if (!window) return;
419
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;
424 }
425
426 /* TODO: ecore_win32_window_shaped_set */
427
428 void
429 ecore_win32_window_show(Ecore_Win32_Window *window)
430 {
431    if (!window) return;
432
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);
436 }
437
438 /* FIXME: seems to block the taskbar */
439 void
440 ecore_win32_window_hide(Ecore_Win32_Window *window)
441 {
442    if (!window) return;
443
444    printf (" ** ecore_win32_window_hide  %p\n", window);
445    ShowWindow(((struct _Ecore_Win32_Window *)window)->window, SW_HIDE);
446 }
447
448 void
449 ecore_win32_window_raise(Ecore_Win32_Window *window)
450 {
451    if (!window) return;
452
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);
457 }
458
459 void
460 ecore_win32_window_lower(Ecore_Win32_Window *window)
461 {
462    if (!window) return;
463
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);
468 }
469
470 void
471 ecore_win32_window_title_set(Ecore_Win32_Window *window,
472                              const char         *title)
473 {
474    if (!window) return;
475
476    if (!title || !title[0]) return;
477
478    SetWindowText(((struct _Ecore_Win32_Window *)window)->window, title);
479 }
480
481 void
482 ecore_win32_window_focus_set(Ecore_Win32_Window *window)
483 {
484    if (!window) return;
485
486    SetFocus(((struct _Ecore_Win32_Window *)window)->window);
487 }
488
489 void
490 ecore_win32_window_iconified_set(Ecore_Win32_Window *window,
491                                  int                 on)
492 {
493    struct _Ecore_Win32_Window *ew;
494
495    if (!window) return;
496
497    ew = (struct _Ecore_Win32_Window *)window;
498    if (((ew->iconified) && (on)) ||
499        ((!ew->iconified) && (!on)))
500      return;
501
502    if (on)
503      {
504         ShowWindow(ew->window,
505                    SW_MINIMIZE);
506      }
507    else
508      {
509         ShowWindow(ew->window,
510                    SW_RESTORE);
511      }
512    ew->iconified = on;
513 }
514
515 void
516 ecore_win32_window_borderless_set(Ecore_Win32_Window *window,
517                                   int                 on)
518 {
519    RECT                        rect;
520    DWORD                       style;
521    struct _Ecore_Win32_Window *ew;
522    HWND                        w;
523
524    if (!window) return;
525
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)))
530      return;
531
532    w = ew->window;
533
534    style = GetWindowLong(w, GWL_STYLE);
535    if (on)
536      {
537         if (!GetClientRect(w, &rect)) return;
538         SetWindowLong(w, GWL_STYLE, style & ~WS_CAPTION);
539      }
540    else
541      {
542         if (!GetWindowRect(w, &rect)) return;
543         style |= WS_CAPTION;
544         AdjustWindowRect (&rect, style, FALSE);
545         SetWindowLong(w, GWL_STYLE, style);
546      }
547    SetWindowPos(w, HWND_TOPMOST,
548                 rect.left, rect.top,
549                 rect.right - rect.left, rect.bottom - rect.top,
550                 SWP_NOMOVE | SWP_FRAMECHANGED);
551    ew->borderless = on;
552 }
553
554 void
555 ecore_win32_window_fullscreen_set(Ecore_Win32_Window *window,
556                                   int                 on)
557 {
558    struct _Ecore_Win32_Window *ew;
559    HWND                        w;
560    int                         width;
561    int                         height;
562
563    if (!window) return;
564
565    ew = (struct _Ecore_Win32_Window *)window;
566    if (((ew->fullscreen) && (on)) ||
567        ((!ew->fullscreen) && (!on)))
568      return;
569
570    ew->fullscreen = on;
571    w = ew->window;
572
573    if (on)
574      {
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))
581           return;
582         SetWindowPos(w, HWND_TOP, 0, 0, width, height,
583                      SWP_NOCOPYBITS | SWP_SHOWWINDOW);
584      }
585    else
586      {
587         if (!SetWindowLong(w, GWL_STYLE, ew->style))
588           return;
589         SetWindowPos(w, HWND_NOTOPMOST,
590                      ew->rect.left,
591                      ew->rect.top,
592                      ew->rect.right - ew->rect.left,
593                      ew->rect.bottom - ew->rect.top,
594                      SWP_NOCOPYBITS | SWP_SHOWWINDOW);
595      }
596 }
597
598 void
599 ecore_win32_window_cursor_set(Ecore_Win32_Window *window,
600                               Ecore_Win32_Cursor *cursor)
601 {
602    SetClassLong(((struct _Ecore_Win32_Window *)window)->window,
603                 GCL_HCURSOR, (LONG)cursor);
604 }
605
606 void
607 ecore_win32_window_state_set(Ecore_Win32_Window       *window,
608                              Ecore_Win32_Window_State *state,
609                              unsigned int              num)
610 {
611    unsigned int i;
612
613    if (!num)
614      return;
615
616    for (i = 0; i < num; i++)
617      {
618         switch (state[i])
619           {
620           case ECORE_WIN32_WINDOW_STATE_ICONIFIED:
621             ((struct _Ecore_Win32_Window *)window)->state.iconified = 1;
622             break;
623           case ECORE_WIN32_WINDOW_STATE_MODAL:
624             ((struct _Ecore_Win32_Window *)window)->state.modal = 1;
625             break;
626           case ECORE_WIN32_WINDOW_STATE_STICKY:
627             ((struct _Ecore_Win32_Window *)window)->state.sticky = 1;
628             break;
629           case ECORE_WIN32_WINDOW_STATE_MAXIMIZED_VERT:
630             ((struct _Ecore_Win32_Window *)window)->state.maximized_vert = 1;
631             break;
632           case ECORE_WIN32_WINDOW_STATE_MAXIMIZED_HORZ:
633             ((struct _Ecore_Win32_Window *)window)->state.maximized_horz = 1;
634             break;
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;
638             break;
639           case ECORE_WIN32_WINDOW_STATE_SHADED:
640             ((struct _Ecore_Win32_Window *)window)->state.shaded = 1;
641             break;
642           case ECORE_WIN32_WINDOW_STATE_HIDDEN:
643             ((struct _Ecore_Win32_Window *)window)->state.hidden = 1;
644             break;
645           case ECORE_WIN32_WINDOW_STATE_FULLSCREEN:
646             ((struct _Ecore_Win32_Window *)window)->state.fullscreen = 1;
647             break;
648           case ECORE_WIN32_WINDOW_STATE_ABOVE:
649             ((struct _Ecore_Win32_Window *)window)->state.above = 1;
650             break;
651           case ECORE_WIN32_WINDOW_STATE_BELOW:
652             ((struct _Ecore_Win32_Window *)window)->state.below = 1;
653             break;
654           case ECORE_WIN32_WINDOW_STATE_DEMANDS_ATTENTION:
655             ((struct _Ecore_Win32_Window *)window)->state.demands_attention = 1;
656             break;
657           case ECORE_WIN32_WINDOW_STATE_UNKNOWN:
658             /* nothing to be done */
659             break;
660           }
661      }
662 }
663
664 void
665 ecore_win32_window_state_request_send(Ecore_Win32_Window      *window,
666                                       Ecore_Win32_Window_State state,
667                                       unsigned int             set)
668 {
669   if (!window)
670     return;
671
672    switch (state)
673      {
674      case ECORE_WIN32_WINDOW_STATE_ICONIFIED:
675        if (((struct _Ecore_Win32_Window *)window)->state.iconified)
676          ecore_win32_window_iconified_set(window, set);
677        break;
678      case ECORE_WIN32_WINDOW_STATE_MODAL:
679        ((struct _Ecore_Win32_Window *)window)->state.modal = 1;
680        break;
681      case ECORE_WIN32_WINDOW_STATE_STICKY:
682        ((struct _Ecore_Win32_Window *)window)->state.sticky = 1;
683        break;
684      case ECORE_WIN32_WINDOW_STATE_MAXIMIZED_VERT:
685        if (((struct _Ecore_Win32_Window *)window)->state.maximized_vert)
686          {
687             RECT rect;
688             int  y;
689             int  height;
690
691             if (!SystemParametersInfo(SPI_GETWORKAREA, 0,
692                                       &rect, 0))
693               break;
694             y = rect.top;
695             height = rect.bottom - rect.top;
696
697             if (!GetClientRect(((struct _Ecore_Win32_Window *)window)->window,
698                                &rect))
699               break;
700
701             MoveWindow(window, rect.left, y,
702                        rect.right - rect.left,
703                        height,
704                        TRUE);
705          }
706        break;
707      case ECORE_WIN32_WINDOW_STATE_MAXIMIZED_HORZ:
708        if (((struct _Ecore_Win32_Window *)window)->state.maximized_horz)
709          {
710             RECT rect;
711
712             if (!GetClientRect(((struct _Ecore_Win32_Window *)window)->window,
713                                &rect))
714               break;
715
716             MoveWindow(window, 0, rect.top,
717                        GetSystemMetrics(SM_CXSCREEN),
718                        rect.bottom - rect.top,
719                        TRUE);
720          }
721        break;
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)
725          {
726             RECT rect;
727
728             if (!SystemParametersInfo(SPI_GETWORKAREA, 0,
729                                       &rect, 0))
730               break;
731
732             MoveWindow(window, 0, 0,
733                        GetSystemMetrics(SM_CXSCREEN),
734                        rect.bottom - rect.top,
735                        TRUE);
736          }
737        break;
738      case ECORE_WIN32_WINDOW_STATE_SHADED:
739        ((struct _Ecore_Win32_Window *)window)->state.shaded = 1;
740        break;
741      case ECORE_WIN32_WINDOW_STATE_HIDDEN:
742        ((struct _Ecore_Win32_Window *)window)->state.hidden = 1;
743        break;
744      case ECORE_WIN32_WINDOW_STATE_FULLSCREEN:
745        if (((struct _Ecore_Win32_Window *)window)->state.fullscreen)
746          ecore_win32_window_fullscreen_set(window, set);
747        break;
748      case ECORE_WIN32_WINDOW_STATE_ABOVE:
749        if (((struct _Ecore_Win32_Window *)window)->state.above)
750          SetWindowPos(((struct _Ecore_Win32_Window *)window)->window,
751                       HWND_TOP,
752                       0, 0,
753                       0, 0,
754                       SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
755        break;
756      case ECORE_WIN32_WINDOW_STATE_BELOW:
757        if (((struct _Ecore_Win32_Window *)window)->state.below)
758          SetWindowPos(((struct _Ecore_Win32_Window *)window)->window,
759                       HWND_BOTTOM,
760                       0, 0,
761                       0, 0,
762                       SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
763        break;
764      case ECORE_WIN32_WINDOW_STATE_DEMANDS_ATTENTION:
765        ((struct _Ecore_Win32_Window *)window)->state.demands_attention = 1;
766        break;
767      case ECORE_WIN32_WINDOW_STATE_UNKNOWN:
768        /* nothing to be done */
769        break;
770      }
771 }
772
773 void
774 ecore_win32_window_type_set(Ecore_Win32_Window      *window,
775                             Ecore_Win32_Window_Type  type)
776 {
777    switch (type)
778      {
779      case ECORE_WIN32_WINDOW_TYPE_DESKTOP:
780        ((struct _Ecore_Win32_Window *)window)->type.desktop = 1;
781        break;
782      case ECORE_WIN32_WINDOW_TYPE_DOCK:
783        ((struct _Ecore_Win32_Window *)window)->type.dock = 1;
784        break;
785      case ECORE_WIN32_WINDOW_TYPE_TOOLBAR:
786        ((struct _Ecore_Win32_Window *)window)->type.toolbar = 1;
787        break;
788      case ECORE_WIN32_WINDOW_TYPE_MENU:
789        ((struct _Ecore_Win32_Window *)window)->type.menu = 1;
790        break;
791      case ECORE_WIN32_WINDOW_TYPE_UTILITY:
792        ((struct _Ecore_Win32_Window *)window)->type.utility = 1;
793        break;
794      case ECORE_WIN32_WINDOW_TYPE_SPLASH:
795        ((struct _Ecore_Win32_Window *)window)->type.splash = 1;
796        break;
797      case ECORE_WIN32_WINDOW_TYPE_DIALOG:
798        ((struct _Ecore_Win32_Window *)window)->type.dialog = 1;
799        break;
800      case ECORE_WIN32_WINDOW_TYPE_NORMAL:
801        ((struct _Ecore_Win32_Window *)window)->type.normal = 1;
802        break;
803      case ECORE_WIN32_WINDOW_TYPE_UNKNOWN:
804        ((struct _Ecore_Win32_Window *)window)->type.normal = 1;
805        break;
806      }
807 }
808
809
810 /***** Private functions definitions *****/
811
812 static Ecore_Win32_Window *
813 ecore_win32_window_internal_new(Ecore_Win32_Window *parent,
814                                 int                 x,
815                                 int                 y,
816                                 int                 width,
817                                 int                 height,
818                                 DWORD               style)
819 {
820    RECT                        rect;
821    struct _Ecore_Win32_Window *w;
822    int                         minimal_width;
823    int                         minimal_height;
824
825    w = (struct _Ecore_Win32_Window *)calloc(1, sizeof(struct _Ecore_Win32_Window));
826    if (!w)
827      return NULL;
828
829    printf (" *** ecore_win32_window_new : %p  %d %d %d\n",
830            w,
831            width, height, GetSystemMetrics(SM_CXMIN));
832    rect.left = 0;
833    rect.top = 0;
834    rect.right = width;
835    rect.bottom = height;
836    if (!AdjustWindowRect(&rect, style, FALSE))
837      {
838         free(w);
839         return NULL;
840      }
841    printf (" * ecore : new debut : %ld %d %d\n",
842            rect.right - rect.left, GetSystemMetrics(SM_CXMIN), GetSystemMetrics(SM_CYMIN));
843
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)) */
848 /*      { */
849 /*         fprintf (stderr, "[Ecore] [Win32] ERROR !!\n"); */
850 /*         fprintf (stderr, "                Wrong size %ld\n", rect.right - rect.left); */
851 /*         free(w); */
852 /*         return NULL; */
853 /*      } */
854    if ((rect.right - rect.left) < minimal_width)
855      {
856        rect.right = rect.left + minimal_width;
857      }
858
859    w->window = CreateWindow(ECORE_WIN32_WINDOW_CLASS, "",
860                             style,
861                             x, y,
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);
866    if (!w->window)
867      {
868         free(w);
869         return NULL;
870      }
871
872    SetLastError(0);
873    if (!SetWindowLong(w->window, GWL_USERDATA, (LONG)w) && (GetLastError() != 0))
874      {
875         DestroyWindow(w->window);
876         free(w);
877         return NULL;
878      }
879
880    w->min_width   = 0;
881    w->min_height  = 0;
882    w->max_width   = 32767;
883    w->max_height  = 32767;
884    w->base_width  = -1;
885    w->base_height = -1;
886    w->step_width  = -1;
887    w->step_height = -1;
888
889    w->state.iconified         = 0;
890    w->state.modal             = 0;
891    w->state.sticky            = 0;
892    w->state.maximized_vert    = 0;
893    w->state.maximized_horz    = 0;
894    w->state.shaded            = 0;
895    w->state.hidden            = 0;
896    w->state.fullscreen        = 0;
897    w->state.above             = 0;
898    w->state.below             = 0;
899    w->state.demands_attention = 0;
900
901    w->type.desktop = 0;
902    w->type.dock    = 0;
903    w->type.toolbar = 0;
904    w->type.menu    = 0;
905    w->type.utility = 0;
906    w->type.splash  = 0;
907    w->type.dialog  = 0;
908    w->type.normal  = 0;
909
910    w->pointer_is_in = 0;
911    w->borderless    = 0;
912    w->iconified     = 0;
913    w->fullscreen    = 0;
914
915    printf (" *** ecore_win32_window_new fin : (%d %d) (%d %d)\n",
916            w->min_width,
917            w->min_height,
918            w->max_width,
919            w->max_height);
920
921    return w;
922 }