svn update: 48958 (latest:48959)
[framework/uifw/ecore.git] / src / lib / ecore_evas / ecore_evas_win32.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> /* for NULL */
10
11 #include <Ecore.h>
12 #include "ecore_private.h"
13 #ifdef BUILD_ECORE_EVAS_WIN32
14 # define WIN32_LEAN_AND_MEAN
15 # include <windows.h>
16 # undef WIN32_LEAN_AND_MEAN
17 # include <Ecore_Win32.h>
18 # include <ecore_win32_private.h>
19 #endif /* BUILD_ECORE_EVAS_WIN32 */
20
21 #include "ecore_evas_private.h"
22 #include "Ecore_Evas.h"
23
24 #ifdef BUILD_ECORE_EVAS_WIN32
25
26 #define ECORE_EVAS_EVENT_COUNT 8
27
28 static int _ecore_evas_init_count = 0;
29
30 static Ecore_Event_Handler *ecore_evas_event_handlers[ECORE_EVAS_EVENT_COUNT];
31
32 static int _ecore_evas_win32_event_mouse_in(void *data __UNUSED__, int type __UNUSED__, void *event);
33
34 static int _ecore_evas_win32_event_mouse_out(void *data __UNUSED__, int type __UNUSED__, void *event);
35
36 static int _ecore_evas_win32_event_window_damage(void *data __UNUSED__, int type __UNUSED__, void *event);
37
38 static int _ecore_evas_win32_event_window_destroy(void *data __UNUSED__, int type __UNUSED__, void *event);
39
40 static int _ecore_evas_win32_event_window_show(void *data __UNUSED__, int type __UNUSED__, void *event);
41
42 static int _ecore_evas_win32_event_window_hide(void *data __UNUSED__, int type __UNUSED__, void *event);
43
44 static int _ecore_evas_win32_event_window_configure(void *data __UNUSED__, int type __UNUSED__, void *event);
45
46 static int _ecore_evas_win32_event_window_delete_request(void *data __UNUSED__, int type __UNUSED__, void *event);
47
48 /* Private functions */
49
50 static int
51 _ecore_evas_win32_render(Ecore_Evas *ee)
52 {
53    int rend = 0;
54    Eina_List *updates = NULL;
55 #ifdef BUILD_ECORE_EVAS_SOFTWARE_BUFFER
56    Eina_List *ll;
57    Ecore_Evas *ee2;
58
59    EINA_LIST_FOREACH(ee->sub_ecore_evas, ll, ee2)
60      {
61         if (ee2->func.fn_pre_render) ee2->func.fn_pre_render(ee2);
62         rend |= _ecore_evas_buffer_render(ee2);
63         if (ee2->func.fn_post_render) ee2->func.fn_post_render(ee2);
64      }
65 #endif
66    if (ee->func.fn_pre_render) ee->func.fn_pre_render(ee);
67    if (ee->prop.avoid_damage)
68      {
69         updates = evas_render_updates(ee->evas);
70         if (updates) evas_render_updates_free(updates);
71      }
72    else if ((ee->visible) ||
73             ((ee->should_be_visible) && (ee->prop.fullscreen)) ||
74             ((ee->should_be_visible) && (ee->prop.override)))
75      {
76         if (ee->shaped)
77           {
78              updates = evas_render_updates(ee->evas);
79              if (updates) evas_render_updates_free(updates);
80           }
81         else
82           {
83              updates = evas_render_updates(ee->evas);
84              if (updates) evas_render_updates_free(updates);
85           }
86      }
87    else
88      evas_norender(ee->evas);
89    if (updates) rend = 1;
90    if (ee->func.fn_post_render) ee->func.fn_post_render(ee);
91    return rend;
92 }
93
94 static int
95 _ecore_evas_win32_init(void)
96 {
97    _ecore_evas_init_count++;
98    if (_ecore_evas_init_count > 1)
99      return _ecore_evas_init_count;
100    
101    ecore_evas_event_handlers[0]  = ecore_event_handler_add(ECORE_WIN32_EVENT_MOUSE_IN, _ecore_evas_win32_event_mouse_in, NULL);
102    ecore_evas_event_handlers[1]  = ecore_event_handler_add(ECORE_WIN32_EVENT_MOUSE_OUT, _ecore_evas_win32_event_mouse_out, NULL);
103    ecore_evas_event_handlers[2]  = ecore_event_handler_add(ECORE_WIN32_EVENT_WINDOW_DAMAGE, _ecore_evas_win32_event_window_damage, NULL);
104    ecore_evas_event_handlers[3]  = ecore_event_handler_add(ECORE_WIN32_EVENT_WINDOW_DESTROY, _ecore_evas_win32_event_window_destroy, NULL);
105    ecore_evas_event_handlers[4]  = ecore_event_handler_add(ECORE_WIN32_EVENT_WINDOW_SHOW, _ecore_evas_win32_event_window_show, NULL);
106    ecore_evas_event_handlers[5]  = ecore_event_handler_add(ECORE_WIN32_EVENT_WINDOW_HIDE, _ecore_evas_win32_event_window_hide, NULL);
107    ecore_evas_event_handlers[6]  = ecore_event_handler_add(ECORE_WIN32_EVENT_WINDOW_CONFIGURE, _ecore_evas_win32_event_window_configure, NULL);
108    ecore_evas_event_handlers[7]  = ecore_event_handler_add(ECORE_WIN32_EVENT_WINDOW_DELETE_REQUEST, _ecore_evas_win32_event_window_delete_request, NULL);
109
110    ecore_event_evas_init();
111    return _ecore_evas_init_count;
112 }
113
114 int
115 _ecore_evas_win32_shutdown(void)
116 {
117    _ecore_evas_init_count--;
118    if (_ecore_evas_init_count == 0)
119      {
120         int i;
121
122         for (i = 0; i < ECORE_EVAS_EVENT_COUNT; i++)
123           ecore_event_handler_del(ecore_evas_event_handlers[i]);
124         ecore_event_evas_shutdown();
125      }
126
127    if (_ecore_evas_init_count < 0) _ecore_evas_init_count = 0;
128
129    return _ecore_evas_init_count;
130 }
131
132 static int
133 _ecore_evas_win32_event_mouse_in(void *data __UNUSED__, int type __UNUSED__, void *event)
134 {
135    Ecore_Evas                 *ee;
136    Ecore_Win32_Event_Mouse_In *e;
137
138    INF("mouse in");
139
140    e = event;
141    ee = ecore_event_window_match((Ecore_Window)e->window);
142    if ((!ee) || (ee->ignore_events)) return 1; /* pass on event */
143    if ((Ecore_Window)e->window != ee->prop.window) return 1;
144
145    if (ee->func.fn_mouse_in) ee->func.fn_mouse_in(ee);
146    /* FIXME to do */
147 /*    _ecore_evas_x_modifier_locks_update(ee, e->modifiers); */
148    evas_event_feed_mouse_in(ee->evas, e->time, NULL);
149    evas_focus_in(ee->evas);
150    _ecore_evas_mouse_move_process(ee, e->x, e->y, e->time);
151
152    return 1;
153 }
154
155 static int
156 _ecore_evas_win32_event_mouse_out(void *data __UNUSED__, int type __UNUSED__, void *event)
157 {
158    Ecore_Evas                  *ee;
159    Ecore_Win32_Event_Mouse_Out *e;
160
161    INF("mouse out");
162
163    e = event;
164    ee = ecore_event_window_match((Ecore_Window)e->window);
165    if ((!ee) || (ee->ignore_events)) return 1; /* pass on event */
166    if ((Ecore_Window)e->window != ee->prop.window) return 1;
167
168    /* FIXME to do */
169 /*    _ecore_evas_x_modifier_locks_update(ee, e->modifiers); */
170    _ecore_evas_mouse_move_process(ee, e->x, e->y, e->time);
171
172    evas_event_feed_mouse_out(ee->evas, e->time, NULL);
173    if (ee->func.fn_mouse_out) ee->func.fn_mouse_out(ee);
174    if (ee->prop.cursor.object) evas_object_hide(ee->prop.cursor.object);
175
176    return 1;
177 }
178
179 static int
180 _ecore_evas_win32_event_window_damage(void *data __UNUSED__, int type __UNUSED__, void *event)
181 {
182    Ecore_Evas                      *ee;
183    Ecore_Win32_Event_Window_Damage *e;
184
185    INF("window damage");
186
187    e = event;
188    ee = ecore_event_window_match((Ecore_Window)e->window);
189    if (!ee) return 1; /* pass on event */
190    if ((Ecore_Window)e->window != ee->prop.window) return 1;
191
192    if (ee->prop.avoid_damage)
193      {
194 #ifdef _MSC_VER
195 # pragma message ("[ECORE] [WIN32] No Region code")
196 #else
197 # warning [ECORE] [WIN32] No Region code
198 #endif /* ! _MSC_VER */
199      }
200    else
201      {
202         if (ee->rotation == 0)
203           evas_damage_rectangle_add(ee->evas,
204                                     e->x,
205                                     e->y,
206                                     e->width,
207                                     e->height);
208         else if (ee->rotation == 90)
209           evas_damage_rectangle_add(ee->evas,
210                                     ee->h - e->y - e->height,
211                                     e->x,
212                                     e->height,
213                                     e->width);
214         else if (ee->rotation == 180)
215           evas_damage_rectangle_add(ee->evas,
216                                     ee->w - e->x - e->width,
217                                     ee->h - e->y - e->height,
218                                     e->width,
219                                     e->height);
220         else if (ee->rotation == 270)
221           evas_damage_rectangle_add(ee->evas,
222                                     e->y,
223                                     ee->w - e->x - e->width,
224                                     e->height,
225                                     e->width);
226      }
227
228    return 1;
229 }
230
231 static int
232 _ecore_evas_win32_event_window_destroy(void *data __UNUSED__, int type __UNUSED__, void *event)
233 {
234    Ecore_Evas                       *ee;
235    Ecore_Win32_Event_Window_Destroy *e;
236
237    INF("window destroy");
238
239    e = event;
240    ee = ecore_event_window_match((Ecore_Window)e->window);
241    if (!ee) return 1; /* pass on event */
242    if ((Ecore_Window)e->window != ee->prop.window) return 1;
243    if (ee->func.fn_destroy) ee->func.fn_destroy(ee);
244    ecore_evas_free(ee);
245
246    return 1;
247 }
248
249 static int
250 _ecore_evas_win32_event_window_show(void *data __UNUSED__, int type __UNUSED__, void *event)
251 {
252    Ecore_Evas                    *ee;
253    Ecore_Win32_Event_Window_Show *e;
254
255    INF("window show");
256
257    e = event;
258    ee = ecore_event_window_match((Ecore_Window)e->window);
259    if (!ee) return 1; /* pass on event */
260    if ((Ecore_Window)e->window != ee->prop.window) return 1;
261    if (ee->visible) return 0; /* dont pass it on */
262    ee->visible = 1;
263    if (ee->func.fn_show) ee->func.fn_show(ee);
264
265    return 1;
266 }
267
268 static int
269 _ecore_evas_win32_event_window_hide(void *data __UNUSED__, int type __UNUSED__, void *event)
270 {
271    Ecore_Evas                    *ee;
272    Ecore_Win32_Event_Window_Hide *e;
273
274    INF("window hide");
275
276    e = event;
277    ee = ecore_event_window_match((Ecore_Window)e->window);
278    if (!ee) return 1; /* pass on event */
279    if ((Ecore_Window)e->window != ee->prop.window) return 1;
280    if (!ee->visible) return 0; /* dont pass it on */
281    ee->visible = 0;
282    if (ee->func.fn_hide) ee->func.fn_hide(ee);
283
284    return 1;
285 }
286
287 static int
288 _ecore_evas_win32_event_window_configure(void *data __UNUSED__, int type __UNUSED__, void *event)
289 {
290    Ecore_Evas                         *ee;
291    Ecore_Win32_Event_Window_Configure *e;
292
293    INF("window configure");
294
295    e = event;
296    ee = ecore_event_window_match((Ecore_Window)e->window);
297    if (!ee) return 1; /* pass on event */
298    if ((Ecore_Window)e->window != ee->prop.window) return 1;
299
300    if ((ee->x != e->x) || (ee->y != e->y))
301      {
302         ee->x = e->x;
303         ee->y = e->y;
304         if (ee->func.fn_move) ee->func.fn_move(ee);
305      }
306
307    if ((ee->w != e->width) || (ee->h != e->height))
308      {
309         ee->w = e->width;
310         ee->h = e->height;
311         if ((ee->rotation == 90) || (ee->rotation == 270))
312           {
313              evas_output_size_set(ee->evas, ee->h, ee->w);
314              evas_output_viewport_set(ee->evas, 0, 0, ee->h, ee->w);
315           }
316         else
317           {
318              evas_output_size_set(ee->evas, ee->w, ee->h);
319              evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
320           }
321         if (ee->prop.avoid_damage)
322           {
323              ecore_evas_avoid_damage_set(ee, 0);
324              ecore_evas_avoid_damage_set(ee, 1);
325           }
326         /* FIXME: to do... */
327 /*        if (ee->shaped) */
328 /*          _ecore_evas_x_resize_shape(ee); */
329         if ((ee->expecting_resize.w > 0) &&
330             (ee->expecting_resize.h > 0))
331           {
332              if ((ee->expecting_resize.w == ee->w) &&
333                  (ee->expecting_resize.h == ee->h))
334                _ecore_evas_mouse_move_process(ee, ee->mouse.x, ee->mouse.y,
335                                               ecore_win32_current_time_get());
336              ee->expecting_resize.w = 0;
337              ee->expecting_resize.h = 0;
338           }
339         if (ee->func.fn_resize) ee->func.fn_resize(ee);
340      }
341
342    return 1;
343 }
344
345 static int
346 _ecore_evas_win32_event_window_delete_request(void *data __UNUSED__, int type __UNUSED__, void *event)
347 {
348    Ecore_Evas                              *ee;
349    Ecore_Win32_Event_Window_Delete_Request *e;
350
351    INF("window delete request");
352
353    e = event;
354    ee = ecore_event_window_match((Ecore_Window)e->window);
355    if (!ee) return 1; /* pass on event */
356    if ((Ecore_Window)e->window != ee->prop.window) return 1;
357    if (ee->func.fn_delete_request) ee->func.fn_delete_request(ee);
358
359    INF(" * ee event delete\n");
360    return 1;
361 }
362
363
364 /* Ecore_Evas interface */
365
366 static void
367 _ecore_evas_win32_free(Ecore_Evas *ee)
368 {
369    INF("ecore evas free");
370
371    ecore_win32_window_free((struct _Ecore_Win32_Window *)ee->prop.window);
372    ecore_event_window_unregister(ee->prop.window);
373    _ecore_evas_win32_shutdown();
374    ecore_win32_shutdown();
375 }
376
377 static void
378 _ecore_evas_win32_callback_delete_request_set(Ecore_Evas *ee,
379                                               void (*func) (Ecore_Evas *ee))
380 {
381    ee->func.fn_delete_request = func;
382 }
383
384 static void
385 _ecore_evas_win32_move(Ecore_Evas *ee, int x, int y)
386 {
387   INF("ecore evas move (%dx%d)", x, y);
388
389    if ((x != ee->x) || (y != ee->y))
390      {
391         ee->x = x;
392         ee->y = y;
393         ecore_win32_window_move((struct _Ecore_Win32_Window *)ee->prop.window,
394                                 x, y);
395         if (ee->func.fn_move) ee->func.fn_move(ee);
396      }
397 }
398
399 static void
400 _ecore_evas_win32_resize(Ecore_Evas *ee, int width, int height)
401 {
402    INF("ecore evas resize (%dx%d)", width, height);
403
404    if ((ee->w != width) || (ee->h != height))
405      {
406         ee->w = width;
407         ee->h = height;
408         ecore_win32_window_resize((struct _Ecore_Win32_Window *)ee->prop.window,
409                                   width, height);
410         if ((ee->rotation == 90) || (ee->rotation == 270))
411           {
412              evas_output_size_set(ee->evas, ee->h, ee->w);
413              evas_output_viewport_set(ee->evas, 0, 0, ee->h, ee->w);
414           }
415         else
416           {
417              evas_output_size_set(ee->evas, ee->w, ee->h);
418              evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
419           }
420         /* FIXME: damage and shape */
421
422         if (ee->func.fn_resize) ee->func.fn_resize(ee);
423      }
424 }
425
426 static void
427 _ecore_evas_win32_move_resize(Ecore_Evas *ee, int x, int y, int width, int height)
428 {
429    INF("ecore evas resize (%dx%d %dx%d)", x, y, width, height);
430
431    if ((ee->w != width) || (ee->h != height) || (x != ee->x) || (y != ee->y))
432      {
433         int change_size = 0;
434         int change_pos = 0;
435
436         if ((ee->w != width) || (ee->h != height)) change_size = 1;
437         if ((x != ee->x) || (y != ee->y)) change_pos = 1;
438
439         ee->x = x;
440         ee->y = y;
441         ee->w = width;
442         ee->h = height;
443         ecore_win32_window_move_resize((struct _Ecore_Win32_Window *)ee->prop.window,
444                                        x, y, width, height);
445         if ((ee->rotation == 90) || (ee->rotation == 270))
446           {
447              evas_output_size_set(ee->evas, ee->h, ee->w);
448              evas_output_viewport_set(ee->evas, 0, 0, ee->h, ee->w);
449           }
450         else
451           {
452              evas_output_size_set(ee->evas, ee->w, ee->h);
453              evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
454           }
455         /* FIXME: damage and shape */
456         if (change_pos)
457           {
458              if (ee->func.fn_move) ee->func.fn_move(ee);
459           }
460         if (change_size)
461           {
462              if (ee->func.fn_resize) ee->func.fn_resize(ee);
463           }
464      }
465 }
466
467 static void
468 _ecore_evas_win32_rotation_set_internal(Ecore_Evas *ee, int rotation)
469 {
470    int rot_dif;
471
472    rot_dif = ee->rotation - rotation;
473    if (rot_dif < 0) rot_dif = -rot_dif;
474
475    if (rot_dif != 180)
476      {
477         int minw, minh, maxw, maxh, basew, baseh, stepw, steph;
478
479         if (!ee->prop.fullscreen)
480           {
481              ecore_win32_window_resize((struct _Ecore_Win32_Window *)ee->prop.window,
482                                        ee->h, ee->w);
483              ee->expecting_resize.w = ee->h;
484              ee->expecting_resize.h = ee->w;
485           }
486         else
487           {
488              int w, h;
489
490              ecore_win32_window_size_get((struct _Ecore_Win32_Window *)ee->prop.window,
491                                          &w, &h);
492              ecore_win32_window_resize((struct _Ecore_Win32_Window *)ee->prop.window,
493                                        h, w);
494              if ((rotation == 0) || (rotation == 180))
495                {
496                   evas_output_size_set(ee->evas, ee->w, ee->h);
497                   evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
498                }
499              else
500                {
501                   evas_output_size_set(ee->evas, ee->h, ee->w);
502                   evas_output_viewport_set(ee->evas, 0, 0, ee->h, ee->w);
503                }
504              if (ee->func.fn_resize) ee->func.fn_resize(ee);
505           }
506         ecore_evas_size_min_get(ee, &minw, &minh);
507         ecore_evas_size_max_get(ee, &maxw, &maxh);
508         ecore_evas_size_base_get(ee, &basew, &baseh);
509         ecore_evas_size_step_get(ee, &stepw, &steph);
510         ee->rotation = rotation;
511         ecore_evas_size_min_set(ee, minh, minw);
512         ecore_evas_size_max_set(ee, maxh, maxw);
513         ecore_evas_size_base_set(ee, baseh, basew);
514         ecore_evas_size_step_set(ee, steph, stepw);
515         _ecore_evas_mouse_move_process(ee, ee->mouse.x, ee->mouse.y,
516                                        ecore_win32_current_time_get());
517      }
518    else
519      {
520         ee->rotation = rotation;
521         _ecore_evas_mouse_move_process(ee, ee->mouse.x, ee->mouse.y,
522                                        ecore_win32_current_time_get());
523         if (ee->func.fn_resize) ee->func.fn_resize(ee);
524      }
525
526    if ((ee->rotation == 90) || (ee->rotation == 270))
527      evas_damage_rectangle_add(ee->evas, 0, 0, ee->h, ee->w);
528    else
529      evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h);
530 }
531
532 static void
533 _ecore_evas_win32_rotation_set(Ecore_Evas *ee, int rotation, int resize)
534 {
535    INF("ecore evas rotation: %s", rotation ? "yes" : "no");
536
537    if (ee->rotation == rotation) return;
538
539 #ifdef BUILD_ECORE_EVAS_SOFTWARE_GDI
540    if (!strcmp(ee->driver, "software_gdi"))
541      {
542         Evas_Engine_Info_Software_Gdi *einfo;
543
544         einfo = (Evas_Engine_Info_Software_Gdi *)evas_engine_info_get(ee->evas);
545         if (!einfo) return;
546         einfo->info.rotation = rotation;
547         evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
548         _ecore_evas_win32_rotation_set_internal(ee, rotation);
549      }
550 #endif /* BUILD_ECORE_EVAS_SOFTWARE_GDI */
551
552 #ifdef BUILD_ECORE_EVAS_SOFTWARE_DDRAW
553    if (!strcmp(ee->driver, "software_ddraw"))
554      {
555         Evas_Engine_Info_Software_DDraw *einfo;
556
557         einfo = (Evas_Engine_Info_Software_DDraw *)evas_engine_info_get(ee->evas);
558         if (!einfo) return;
559         einfo->info.rotation = rotation;
560         evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
561         _ecore_evas_win32_rotation_set_internal(ee, rotation);
562      }
563 #endif /* BUILD_ECORE_EVAS_SOFTWARE_DDRAW */
564 }
565
566 static void
567 _ecore_evas_win32_show(Ecore_Evas *ee)
568 {
569    INF("ecore evas show");
570
571    ee->should_be_visible = 1;
572    if (ee->prop.avoid_damage)
573      _ecore_evas_win32_render(ee);
574    ecore_win32_window_show((struct _Ecore_Win32_Window *)ee->prop.window);
575 /*    if (ee->prop.fullscreen) */
576 /*      ecore_win32_window_focus(ee->prop.window); */
577 }
578
579 static void
580 _ecore_evas_win32_hide(Ecore_Evas *ee)
581 {
582    INF("ecore evas hide");
583
584    ecore_win32_window_hide((struct _Ecore_Win32_Window *)ee->prop.window);
585    ee->should_be_visible = 0;
586 }
587
588 static void
589 _ecore_evas_win32_raise(Ecore_Evas *ee)
590 {
591    INF("ecore evas raise");
592
593    if (!ee->prop.fullscreen)
594      ecore_win32_window_raise((struct _Ecore_Win32_Window *)ee->prop.window);
595    else
596      ecore_win32_window_raise((struct _Ecore_Win32_Window *)ee->prop.window);
597 }
598
599 static void
600 _ecore_evas_win32_lower(Ecore_Evas *ee)
601 {
602    INF("ecore evas lower");
603
604    if (!ee->prop.fullscreen)
605      ecore_win32_window_lower((struct _Ecore_Win32_Window *)ee->prop.window);
606    else
607      ecore_win32_window_lower((struct _Ecore_Win32_Window *)ee->prop.window);
608 }
609
610 static void
611 _ecore_evas_win32_activate(Ecore_Evas *ee)
612 {
613    INF("ecore evas activate");
614
615    ecore_win32_window_focus_set((struct _Ecore_Win32_Window *)ee->prop.window);
616 }
617
618 static void
619 _ecore_evas_win32_title_set(Ecore_Evas *ee, const char *title)
620 {
621    INF("ecore evas title set");
622
623    if (ee->prop.title) free(ee->prop.title);
624    ee->prop.title = NULL;
625    if (title) ee->prop.title = strdup(title);
626    ecore_win32_window_title_set((struct _Ecore_Win32_Window *)ee->prop.window,
627                                 ee->prop.title);
628 }
629
630 static void
631 _ecore_evas_win32_size_min_set(Ecore_Evas *ee, int width, int height)
632 {
633    if (width < 0) width = 0;
634    if (height < 0) height = 0;
635    if ((ee->prop.min.w == width) && (ee->prop.min.h == height)) return;
636    ee->prop.min.w = width;
637    ee->prop.min.h = height;
638    ecore_win32_window_size_min_set((struct _Ecore_Win32_Window *)ee->prop.window,
639                                    width, height);
640 }
641
642 static void
643 _ecore_evas_win32_size_max_set(Ecore_Evas *ee, int width, int height)
644 {
645    if (width < 0) width = 0;
646    if (height < 0) height = 0;
647    if ((ee->prop.max.w == width) && (ee->prop.max.h == height)) return;
648    ee->prop.max.w = width;
649    ee->prop.max.h = height;
650    ecore_win32_window_size_max_set((struct _Ecore_Win32_Window *)ee->prop.window,
651                                    width, height);
652 }
653
654 static void
655 _ecore_evas_win32_size_base_set(Ecore_Evas *ee, int width, int height)
656 {
657    if (width < 0) width = 0;
658    if (height < 0) height = 0;
659    if ((ee->prop.base.w == width) && (ee->prop.base.h == height)) return;
660    ee->prop.base.w = width;
661    ee->prop.base.h = height;
662    ecore_win32_window_size_base_set((struct _Ecore_Win32_Window *)ee->prop.window,
663                                     width, height);
664 }
665
666 static void
667 _ecore_evas_win32_size_step_set(Ecore_Evas *ee, int width, int height)
668 {
669    if (width < 1) width = 1;
670    if (height < 1) height = 1;
671    if ((ee->prop.step.w == width) && (ee->prop.step.h == height)) return;
672    ee->prop.step.w = width;
673    ee->prop.step.h = height;
674    ecore_win32_window_size_step_set((struct _Ecore_Win32_Window *)ee->prop.window,
675                                     width, height);
676 }
677
678 static void
679 _ecore_evas_win32_cursor_set(Ecore_Evas *ee, Evas_Object *obj, int layer, int hot_x, int hot_y)
680 {
681 #if 0
682    int x, y;
683
684    if (ee->prop.cursor.object) evas_object_del(ee->prop.cursor.object);
685
686    if (obj == NULL)
687      {
688         ee->prop.cursor.object = NULL;
689         ee->prop.cursor.layer = 0;
690         ee->prop.cursor.hot.x = 0;
691         ee->prop.cursor.hot.y = 0;
692         ecore_win32_window_cursor_show(ee->prop.window, 1);
693         return;
694      }
695
696    ee->prop.cursor.object = obj;
697    ee->prop.cursor.layer = layer;
698    ee->prop.cursor.hot.x = hot_x;
699    ee->prop.cursor.hot.y = hot_y;
700
701    ecore_win32_window_cursor_show(ee->prop.window, 0);
702
703    evas_pointer_output_xy_get(ee->evas, &x, &y);
704    evas_object_layer_set(ee->prop.cursor.object, ee->prop.cursor.layer);
705    evas_object_move(ee->prop.cursor.object,
706                     x - ee->prop.cursor.hot.x,
707                     y - ee->prop.cursor.hot.y);
708    evas_object_pass_events_set(ee->prop.cursor.object, 1);
709    if (evas_pointer_inside_get(ee->evas))
710      evas_object_show(ee->prop.cursor.object);
711 #endif
712 }
713
714 static void
715 _ecore_evas_win32_focus_set(Ecore_Evas *ee, int on __UNUSED__)
716 {
717    ecore_win32_window_focus_set((struct _Ecore_Win32_Window *)ee->prop.window);
718 }
719
720 static void
721 _ecore_evas_win32_iconified_set(Ecore_Evas *ee, int on)
722 {
723 /*    if (((ee->prop.borderless) && (on)) || */
724 /*        ((!ee->prop.borderless) && (!on))) return; */
725    ee->prop.iconified = on;
726    ecore_win32_window_iconified_set((struct _Ecore_Win32_Window *)ee->prop.window,
727                                     ee->prop.iconified);
728 }
729
730 static void
731 _ecore_evas_win32_borderless_set(Ecore_Evas *ee, int on)
732 {
733    if (((ee->prop.borderless) && (on)) ||
734        ((!ee->prop.borderless) && (!on))) return;
735    ee->prop.borderless = on;
736    ecore_win32_window_borderless_set((struct _Ecore_Win32_Window *)ee->prop.window,
737                                      ee->prop.borderless);
738 }
739
740 static void
741 _ecore_evas_win32_fullscreen_set(Ecore_Evas *ee, int on)
742 {
743    struct _Ecore_Win32_Window *window;
744
745    INF("ecore evas fullscreen set");
746
747    if ((ee->engine.win32.state.fullscreen && on) ||
748       (!ee->engine.win32.state.fullscreen && !on))
749      return;
750
751    ee->engine.win32.state.fullscreen = on;
752    ee->prop.fullscreen = on;
753
754    window = (struct _Ecore_Win32_Window *)ee->prop.window;
755
756    if (on != 0)
757    {
758       ecore_win32_window_shape_set((struct _Ecore_Win32_Window *)ee->prop.window,
759                                    0, 0, NULL);
760       ecore_win32_window_fullscreen_set((struct _Ecore_Win32_Window *)ee->prop.window,
761                                         on);
762    }
763    else
764    {
765       ecore_win32_window_fullscreen_set(window, on);
766       ecore_win32_window_shape_set(window,
767                                    window->shape.width,
768                                    window->shape.height,
769                                    window->shape.mask);
770    }
771
772    /* Nothing to be done for the GDI backend at the evas level */
773
774 #ifdef BUILD_ECORE_EVAS_SOFTWRE_DDRAW
775    if (strcmp(ee->driver, "software_ddraw") == 0)
776      {
777         Evas_Engine_Info_Software_DDraw *einfo;
778
779         einfo = (Evas_Engine_Info_Software_DDraw *)evas_engine_info_get(ecore_evas_get(ee));
780         if (einfo != NULL)
781           {
782              einfo->info.fullscreen = !!on;
783 /*           einfo->info.layered = window->shape.layered; */
784              evas_engine_info_set(ecore_evas_get(ee), (Evas_Engine_Info *)einfo);
785           }
786      }
787 #endif /* BUILD_ECORE_EVAS_SOFTWARE_DDRAW */
788
789 #ifdef BUILD_ECORE_EVAS_DIRECT3D
790    if (strcmp(ee->driver, "direct3d") == 0)
791      {
792         Evas_Engine_Info_Direct3D *einfo;
793
794         einfo = (Evas_Engine_Info_Direct3D *)evas_engine_info_get(ecore_evas_get(ee));
795         if (einfo != NULL)
796           {
797              einfo->info.fullscreen = !!on;
798              einfo->info.layered = window->shape.layered;
799              evas_engine_info_set(ecore_evas_get(ee), (Evas_Engine_Info *)einfo);
800           }
801      }
802 #endif /* BUILD_ECORE_EVAS_DIRECT3D */
803 }
804
805
806 static Ecore_Evas_Engine_Func _ecore_win32_engine_func =
807 {
808    _ecore_evas_win32_free,
809      NULL,
810      NULL,
811      NULL,
812      NULL,
813      _ecore_evas_win32_callback_delete_request_set,
814      NULL,
815      NULL,
816      NULL,
817      NULL,
818      NULL,
819      NULL,
820      NULL,
821      NULL,
822      NULL,
823      _ecore_evas_win32_move,
824      NULL,
825      _ecore_evas_win32_resize,
826      _ecore_evas_win32_move_resize,
827      _ecore_evas_win32_rotation_set,
828      NULL, /* _ecore_evas_x_shaped_set */
829      _ecore_evas_win32_show,
830      _ecore_evas_win32_hide,
831      _ecore_evas_win32_raise,
832      _ecore_evas_win32_lower,
833      _ecore_evas_win32_activate,
834      _ecore_evas_win32_title_set,
835      NULL, /* _ecore_evas_x_name_class_set */
836      _ecore_evas_win32_size_min_set,
837      _ecore_evas_win32_size_max_set,
838      _ecore_evas_win32_size_base_set,
839      _ecore_evas_win32_size_step_set,
840      _ecore_evas_win32_cursor_set,
841      NULL, /* _ecore_evas_x_layer_set */
842      _ecore_evas_win32_focus_set,
843      _ecore_evas_win32_iconified_set,
844      _ecore_evas_win32_borderless_set,
845      NULL, /* _ecore_evas_x_override_set */
846      NULL,
847      _ecore_evas_win32_fullscreen_set,
848      NULL, /* _ecore_evas_x_avoid_damage_set */
849      NULL, /* _ecore_evas_x_withdrawn_set */
850      NULL, /* _ecore_evas_x_sticky_set */
851      NULL, /* _ecore_evas_x_ignore_events_set */
852      NULL,  /* _ecore_evas_x_alpha_set */
853      NULL, //transparent
854      
855      NULL // render
856 };
857
858 #endif /* BUILD_ECORE_EVAS_WIN32 */
859
860 /* API */
861
862 #ifdef BUILD_ECORE_EVAS_SOFTWARE_GDI
863 static int
864 _ecore_evas_engine_software_gdi_init(Ecore_Evas *ee)
865 {
866    Evas_Engine_Info_Software_Gdi *einfo;
867    const char                    *driver;
868    int                            rmethod;
869
870    driver = "software_gdi";
871
872    rmethod = evas_render_method_lookup(driver);
873    if (!rmethod)
874      return 0;
875
876    ee->driver = driver;
877    evas_output_method_set(ee->evas, rmethod);
878
879    einfo = (Evas_Engine_Info_Software_Gdi *)evas_engine_info_get(ee->evas);
880    if (einfo)
881      {
882         /* FIXME: REDRAW_DEBUG missing for now */
883         einfo->info.window = ((struct _Ecore_Win32_Window *)ee->prop.window)->window;
884         einfo->info.mask = NULL;
885         einfo->info.depth = ecore_win32_screen_depth_get();
886         einfo->info.rotation = 0;
887         einfo->info.fullscreen = 0;
888         evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
889      }
890
891    return 1;
892 }
893 #endif /* BUILD_ECORE_EVAS_SOFTWARE_GDI */
894
895 #ifdef BUILD_ECORE_EVAS_SOFTWARE_DDRAW
896 static int
897 _ecore_evas_engine_software_ddraw_init(Ecore_Evas *ee)
898 {
899    Evas_Engine_Info_Software_DDraw *einfo;
900    const char                      *driver;
901    int                              rmethod;
902
903    driver = "software_ddraw";
904
905    rmethod = evas_render_method_lookup(driver);
906    if (!rmethod)
907      return 0;
908
909    ee->driver = driver;
910    evas_output_method_set(ee->evas, rmethod);
911
912    einfo = (Evas_Engine_Info_Software_DDraw *)evas_engine_info_get(ee->evas);
913    if (einfo)
914      {
915         /* FIXME: REDRAW_DEBUG missing for now */
916         einfo->info.window = ((struct _Ecore_Win32_Window *)ee->prop.window)->window;
917         einfo->info.depth = ecore_win32_screen_depth_get();
918         einfo->info.rotation = 0;
919         evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
920      }
921
922    return 1;
923 }
924 #endif /* BUILD_ECORE_EVAS_SOFTWARE_DDRAW */
925
926 #ifdef BUILD_ECORE_EVAS_DIRECT3D
927 static int
928 _ecore_evas_engine_direct3d_init(Ecore_Evas *ee)
929 {
930    Evas_Engine_Info_Direct3D *einfo;
931    const char                *driver;
932    int                        rmethod;
933
934    driver = "direct3d";
935
936    rmethod = evas_render_method_lookup(driver);
937    if (!rmethod)
938      return 0;
939
940    ee->driver = driver;
941    evas_output_method_set(ee->evas, rmethod);
942
943    einfo = (Evas_Engine_Info_Direct3D *)evas_engine_info_get(ee->evas);
944    if (einfo)
945      {
946         /* FIXME: REDRAW_DEBUG missing for now */
947         einfo->info.window = ((struct _Ecore_Win32_Window *)ee->prop.window)->window;
948         einfo->info.depth = ecore_win32_screen_depth_get();
949         einfo->info.rotation = 0;
950         evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
951      }
952
953    return 1;
954 }
955 #endif /* BUILD_ECORE_EVAS_DIRECT3D */
956
957 #ifdef BUILD_ECORE_EVAS_OPENGL_GLEW
958 static int
959 _ecore_evas_engine_opengl_glew_init(Ecore_Evas *ee)
960 {
961    Evas_Engine_Info_GL_Glew *einfo;
962    const char               *driver;
963    int                       rmethod;
964
965    driver = "gl_glew";
966
967    rmethod = evas_render_method_lookup(driver);
968    if (!rmethod)
969      return 0;
970
971    ee->driver = driver;
972    evas_output_method_set(ee->evas, rmethod);
973
974    einfo = (Evas_Engine_Info_GL_Glew *)evas_engine_info_get(ee->evas);
975    if (einfo)
976      {
977         /* FIXME: REDRAW_DEBUG missing for now */
978         einfo->info.window = ((struct _Ecore_Win32_Window *)ee->prop.window)->window;
979         einfo->info.depth = ecore_win32_screen_depth_get();
980         evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
981      }
982
983    return 1;
984 }
985 #endif /* BUILD_ECORE_EVAS_OPENGL_GLEW */
986
987 #ifdef BUILD_ECORE_EVAS_SOFTWARE_16_DDRAW
988 static int
989 _ecore_evas_engine_software_16_ddraw_init(Ecore_Evas *ee)
990 {
991    Evas_Engine_Info_Software_DDraw *einfo;
992    const char                      *driver;
993    int                              rmethod;
994
995    driver = "software_16_ddraw";
996
997    rmethod = evas_render_method_lookup(driver);
998    if (!rmethod)
999      return 0;
1000
1001    ee->driver = driver;
1002    evas_output_method_set(ee->evas, rmethod);
1003
1004    if (ecore_win32_screen_depth_get() != 16)
1005      return 0;
1006
1007    einfo = (Evas_Engine_Info_Software_16_DDraw *)evas_engine_info_get(ee->evas);
1008    if (einfo)
1009      {
1010         /* FIXME: REDRAW_DEBUG missing for now */
1011         einfo->info.window = ((struct _Ecore_Win32_Window *)ee->prop.window)->window;
1012         einfo->info.depth = ecore_win32_screen_depth_get();
1013         einfo->info.rotation = 0;
1014         evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
1015      }
1016
1017    return 1;
1018 }
1019 #endif /* BUILD_ECORE_EVAS_SOFTWARE_16_DDRAW */
1020
1021 #ifdef BUILD_ECORE_EVAS_WIN32
1022 static Ecore_Evas *
1023 _ecore_evas_win32_new_internal(int (*_ecore_evas_engine_init)(Ecore_Evas *ee),
1024                                Ecore_Win32_Window *parent,
1025                                int                 x,
1026                                int                 y,
1027                                int                 width,
1028                                int                 height)
1029 {
1030    Ecore_Evas *ee;
1031
1032    if (!ecore_win32_init())
1033      return NULL;
1034
1035    ee = calloc(1, sizeof(Ecore_Evas));
1036    if (!ee)
1037      return NULL;
1038
1039    ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
1040
1041    _ecore_evas_win32_init();
1042
1043    ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_win32_engine_func;
1044
1045    if (width < 1) width = 1;
1046    if (height < 1) height = 1;
1047    ee->x = x;
1048    ee->y = y;
1049    ee->w = width;
1050    ee->h = height;
1051
1052    ee->prop.max.w = 32767;
1053    ee->prop.max.h = 32767;
1054    ee->prop.layer = 4;
1055    ee->prop.request_pos = 0;
1056    ee->prop.sticky = 0;
1057    /* FIXME: sticky to add */
1058    ee->prop.window = 0;
1059
1060    /* init evas here */
1061    ee->evas = evas_new();
1062    evas_data_attach_set(ee->evas, ee);
1063    evas_output_size_set(ee->evas, width, height);
1064    evas_output_viewport_set(ee->evas, 0, 0, width, height);
1065
1066    ee->engine.win32.parent = parent;
1067    ee->prop.window = (Ecore_Window)ecore_win32_window_new(parent, x, y, width, height);
1068    if (!ee->prop.window)
1069      {
1070         _ecore_evas_win32_shutdown();
1071         free(ee);
1072         return NULL;
1073      }
1074
1075    if (!_ecore_evas_engine_init(ee))
1076      {
1077         _ecore_evas_win32_shutdown();
1078         free(ee);
1079         return NULL;
1080      }
1081
1082    ee->engine.func->fn_render = _ecore_evas_win32_render;
1083    _ecore_evas_register(ee);
1084    ecore_event_window_register(ee->prop.window, ee, ee->evas, _ecore_evas_mouse_move_process);
1085    
1086    return ee;
1087 }
1088
1089 #endif /* BUILD_ECORE_EVAS_WIN32 */
1090
1091 #ifdef BUILD_ECORE_EVAS_SOFTWARE_GDI
1092
1093 EAPI Ecore_Evas *
1094 ecore_evas_software_gdi_new(Ecore_Win32_Window *parent,
1095                             int                 x,
1096                             int                 y,
1097                             int                 width,
1098                             int                 height)
1099 {
1100    return _ecore_evas_win32_new_internal(_ecore_evas_engine_software_gdi_init,
1101                                          parent,
1102                                          x,
1103                                          y,
1104                                          width,
1105                                          height);
1106 }
1107
1108 #else
1109
1110 EAPI Ecore_Evas *
1111 ecore_evas_software_gdi_new(Ecore_Win32_Window *parent __UNUSED__,
1112                             int                 x __UNUSED__,
1113                             int                 y __UNUSED__,
1114                             int                 width __UNUSED__,
1115                             int                 height __UNUSED__)
1116 {
1117    return NULL;
1118 }
1119
1120 #endif /* ! BUILD_ECORE_EVAS_SOFTWARE_GDI */
1121
1122 #ifdef BUILD_ECORE_EVAS_SOFTWARE_DDRAW
1123
1124 EAPI Ecore_Evas *
1125 ecore_evas_software_ddraw_new(Ecore_Win32_Window *parent,
1126                               int                 x,
1127                               int                 y,
1128                               int                 width,
1129                               int                 height)
1130 {
1131    return _ecore_evas_win32_new_internal(_ecore_evas_engine_software_ddraw_init,
1132                                          parent,
1133                                          x,
1134                                          y,
1135                                          width,
1136                                          height);
1137 }
1138
1139 #else
1140
1141 EAPI Ecore_Evas *
1142 ecore_evas_software_ddraw_new(Ecore_Win32_Window *parent __UNUSED__,
1143                               int                 x __UNUSED__,
1144                               int                 y __UNUSED__,
1145                               int                 width __UNUSED__,
1146                               int                 height __UNUSED__)
1147 {
1148    return NULL;
1149 }
1150
1151 #endif /* ! BUILD_ECORE_EVAS_SOFTWARE_DDRAW */
1152
1153
1154 #ifdef BUILD_ECORE_EVAS_SOFTWARE_16_DDRAW
1155
1156 EAPI Ecore_Evas *
1157 ecore_evas_software_16_ddraw_new(Ecore_Win32_Window *parent,
1158                                  int                 x,
1159                                  int                 y,
1160                                  int                 width,
1161                                  int                 height)
1162 {
1163    return _ecore_evas_win32_new_internal(_ecore_evas_engine_software_16_ddraw_init,
1164                                          parent,
1165                                          x,
1166                                          y,
1167                                          width,
1168                                          height);
1169 }
1170
1171 #else
1172
1173 EAPI Ecore_Evas *
1174 ecore_evas_software_16_ddraw_new(Ecore_Win32_Window *parent __UNUSED__,
1175                                  int                 x __UNUSED__,
1176                                  int                 y __UNUSED__,
1177                                  int                 width __UNUSED__,
1178                                  int                 height __UNUSED__)
1179 {
1180    return NULL;
1181 }
1182
1183 #endif /* ! BUILD_ECORE_EVAS_SOFTWARE_16_DDRAW */
1184
1185
1186 #ifdef BUILD_ECORE_EVAS_DIRECT3D
1187
1188 EAPI Ecore_Evas *
1189 ecore_evas_direct3d_new(Ecore_Win32_Window *parent,
1190                         int                 x,
1191                         int                 y,
1192                         int                 width,
1193                         int                 height)
1194 {
1195    return _ecore_evas_win32_new_internal(_ecore_evas_engine_direct3d_init,
1196                                          parent,
1197                                          x,
1198                                          y,
1199                                          width,
1200                                          height);
1201 }
1202
1203 #else
1204
1205 EAPI Ecore_Evas *
1206 ecore_evas_direct3d_new(Ecore_Win32_Window *parent __UNUSED__,
1207                         int                 x __UNUSED__,
1208                         int                 y __UNUSED__,
1209                         int                 width __UNUSED__,
1210                         int                 height __UNUSED__)
1211 {
1212    return NULL;
1213 }
1214
1215 #endif /* ! BUILD_ECORE_EVAS_DIRECT3D */
1216
1217
1218 #ifdef BUILD_ECORE_EVAS_OPENGL_GLEW
1219
1220 EAPI Ecore_Evas *
1221 ecore_evas_gl_glew_new(Ecore_Win32_Window *parent,
1222                        int                 x,
1223                        int                 y,
1224                        int                 width,
1225                        int                 height)
1226 {
1227    return _ecore_evas_win32_new_internal(_ecore_evas_engine_opengl_glew_init,
1228                                          parent,
1229                                          x,
1230                                          y,
1231                                          width,
1232                                          height);
1233 }
1234
1235 #else
1236
1237 EAPI Ecore_Evas *
1238 ecore_evas_gl_glew_new(Ecore_Win32_Window *parent __UNUSED__,
1239                        int                 x __UNUSED__,
1240                        int                 y __UNUSED__,
1241                        int                 width __UNUSED__,
1242                        int                 height __UNUSED__)
1243 {
1244    return NULL;
1245 }
1246
1247 #endif /* BUILD_ECORE_EVAS_OPENGL_GLEW */
1248
1249
1250 #ifdef BUILD_ECORE_EVAS_WIN32
1251
1252 EAPI Ecore_Win32_Window *
1253 ecore_evas_win32_window_get(const Ecore_Evas *ee)
1254 {
1255    return (Ecore_Win32_Window *) ecore_evas_window_get(ee);
1256 }
1257
1258 #else
1259
1260 EAPI Ecore_Win32_Window *
1261 ecore_evas_win32_window_get(const Ecore_Evas *ee __UNUSED__)
1262 {
1263    return NULL;
1264 }
1265
1266 #endif /* BUILD_ECORE_EVAS_WIN32 */