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