Initialize Tizen 2.3
[framework/uifw/ecore.git] / mobile / src / lib / ecore_evas / ecore_evas_wince.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_SOFTWARE_16_WINCE
10 # define WIN32_LEAN_AND_MEAN
11 # include <windows.h>
12 # undef WIN32_LEAN_AND_MEAN
13 # include <Ecore_WinCE.h>
14 # include <ecore_wince_private.h>
15 #endif /* BUILD_ECORE_EVAS_SOFTWARE_16_WINCE */
16
17 #include "ecore_evas_private.h"
18 #include "Ecore_Evas.h"
19
20 #ifdef BUILD_ECORE_EVAS_SOFTWARE_16_WINCE
21
22 #define ECORE_EVAS_EVENT_COUNT 9
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_wince_event_mouse_in(void *data __UNUSED__, int type __UNUSED__, void *event);
29
30 static Eina_Bool _ecore_evas_wince_event_mouse_out(void *data __UNUSED__, int type __UNUSED__, void *event);
31
32 static Eina_Bool _ecore_evas_wince_event_window_focus_in(void *data __UNUSED__, int type __UNUSED__, void *event);
33
34 static Eina_Bool _ecore_evas_wince_event_window_focus_out(void *data __UNUSED__, int type __UNUSED__, void *event);
35
36 static Eina_Bool _ecore_evas_wince_event_window_damage(void *data __UNUSED__, int type __UNUSED__, void *event);
37
38 static Eina_Bool _ecore_evas_wince_event_window_destroy(void *data __UNUSED__, int type __UNUSED__, void *event);
39
40 static Eina_Bool _ecore_evas_wince_event_window_show(void *data __UNUSED__, int type __UNUSED__, void *event);
41
42 static Eina_Bool _ecore_evas_wince_event_window_hide(void *data __UNUSED__, int type __UNUSED__, void *event);
43
44 static Eina_Bool _ecore_evas_wince_event_window_delete_request(void *data __UNUSED__, int type __UNUSED__, void *event);
45
46 /* Private functions */
47
48 static int
49 _ecore_evas_wince_render(Ecore_Evas *ee)
50 {
51    int rend = 0;
52    Eina_List *updates = NULL;
53    Eina_List *ll;
54    Ecore_Evas *ee2;
55
56    EINA_LIST_FOREACH(ee->sub_ecore_evas, ll, ee2)
57      {
58         if (ee2->func.fn_pre_render) ee2->func.fn_pre_render(ee2);
59         if (ee2->engine.func->fn_render)
60           rend |= ee2->engine.func->fn_render(ee2);
61         if (ee2->func.fn_post_render) ee2->func.fn_post_render(ee2);
62      }
63
64    if (ee->func.fn_pre_render) ee->func.fn_pre_render(ee);
65    if (ee->prop.avoid_damage)
66      {
67         updates = evas_render_updates(ee->evas);
68         if (updates) evas_render_updates_free(updates);
69      }
70    else if ((ee->visible) ||
71             ((ee->should_be_visible) && (ee->prop.fullscreen)) ||
72             ((ee->should_be_visible) && (ee->prop.override)))
73      {
74         if (ee->shaped)
75           {
76              updates = evas_render_updates(ee->evas);
77              if (updates) evas_render_updates_free(updates);
78           }
79         else
80           {
81              updates = evas_render_updates(ee->evas);
82              if (updates) evas_render_updates_free(updates);
83           }
84      }
85    else
86      evas_norender(ee->evas);
87    if (updates) rend = 1;
88    if (ee->func.fn_post_render) ee->func.fn_post_render(ee);
89    return rend;
90 }
91
92 static int
93 _ecore_evas_wince_init(void)
94 {
95    _ecore_evas_init_count++;
96    if (_ecore_evas_init_count > 1)
97      return _ecore_evas_init_count;
98
99    ecore_evas_event_handlers[0]  = ecore_event_handler_add(ECORE_WINCE_EVENT_MOUSE_IN, _ecore_evas_wince_event_mouse_in, NULL);
100    ecore_evas_event_handlers[1]  = ecore_event_handler_add(ECORE_WINCE_EVENT_MOUSE_OUT, _ecore_evas_wince_event_mouse_out, NULL);
101    ecore_evas_event_handlers[2]  = ecore_event_handler_add(ECORE_WINCE_EVENT_WINDOW_FOCUS_IN, _ecore_evas_wince_event_window_focus_in, NULL);
102    ecore_evas_event_handlers[3]  = ecore_event_handler_add(ECORE_WINCE_EVENT_WINDOW_FOCUS_OUT, _ecore_evas_wince_event_window_focus_out, NULL);
103    ecore_evas_event_handlers[4]  = ecore_event_handler_add(ECORE_WINCE_EVENT_WINDOW_DAMAGE, _ecore_evas_wince_event_window_damage, NULL);
104    ecore_evas_event_handlers[5]  = ecore_event_handler_add(ECORE_WINCE_EVENT_WINDOW_DESTROY, _ecore_evas_wince_event_window_destroy, NULL);
105    ecore_evas_event_handlers[6]  = ecore_event_handler_add(ECORE_WINCE_EVENT_WINDOW_SHOW, _ecore_evas_wince_event_window_show, NULL);
106    ecore_evas_event_handlers[7]  = ecore_event_handler_add(ECORE_WINCE_EVENT_WINDOW_HIDE, _ecore_evas_wince_event_window_hide, NULL);
107    ecore_evas_event_handlers[8]  = ecore_event_handler_add(ECORE_WINCE_EVENT_WINDOW_DELETE_REQUEST, _ecore_evas_wince_event_window_delete_request, NULL);
108
109    ecore_event_evas_init();
110    return _ecore_evas_init_count;
111 }
112
113 int
114 _ecore_evas_wince_shutdown(void)
115 {
116    _ecore_evas_init_count--;
117    if (_ecore_evas_init_count == 0)
118      {
119         int i;
120
121         for (i = 0; i < ECORE_EVAS_EVENT_COUNT; i++)
122           ecore_event_handler_del(ecore_evas_event_handlers[i]);
123         ecore_event_evas_shutdown();
124      }
125
126    if (_ecore_evas_init_count < 0) _ecore_evas_init_count = 0;
127
128    return _ecore_evas_init_count;
129 }
130
131 static Eina_Bool
132 _ecore_evas_wince_event_mouse_in(void *data __UNUSED__, int type __UNUSED__, void *event)
133 {
134    Ecore_Evas                 *ee;
135    Ecore_WinCE_Event_Mouse_In *e;
136
137    INF("mouse in");
138
139    e = event;
140    ee = ecore_event_window_match((Ecore_Window)e->window);
141    if ((!ee) || (ee->ignore_events)) return 1; /* pass on event */
142    if (e->window != (Ecore_WinCE_Window *)ee->prop.window) return 1;
143
144    if (ee->func.fn_mouse_in) ee->func.fn_mouse_in(ee);
145    /* FIXME to do */
146 /*    _ecore_evas_x_modifier_locks_update(ee, e->modifiers); */
147    evas_event_feed_mouse_in(ee->evas, e->time, NULL);
148    _ecore_evas_mouse_move_process(ee, e->x, e->y, e->time);
149
150    return 1;
151 }
152
153 static Eina_Bool
154 _ecore_evas_wince_event_mouse_out(void *data __UNUSED__, int type __UNUSED__, void *event)
155 {
156    Ecore_Evas                  *ee;
157    Ecore_WinCE_Event_Mouse_Out *e;
158
159    INF("mouse out");
160
161    e = event;
162    ee = ecore_event_window_match((Ecore_Window)e->window);
163    if ((!ee) || (ee->ignore_events)) return 1; /* pass on event */
164    if (e->window != (Ecore_WinCE_Window *)ee->prop.window) return 1;
165
166    /* FIXME to do */
167 /*    _ecore_evas_x_modifier_locks_update(ee, e->modifiers); */
168    _ecore_evas_mouse_move_process(ee, e->x, e->y, e->time);
169
170    evas_event_feed_mouse_out(ee->evas, e->time, NULL);
171    if (ee->func.fn_mouse_out) ee->func.fn_mouse_out(ee);
172    if (ee->prop.cursor.object) evas_object_hide(ee->prop.cursor.object);
173
174    return 1;
175 }
176
177 static Eina_Bool
178 _ecore_evas_wince_event_window_focus_in(void *data __UNUSED__, int type __UNUSED__, void *event)
179 {
180    Ecore_Evas *ee;
181    Ecore_WinCE_Event_Window_Focus_In *e;
182
183    e = event;
184    ee = ecore_event_window_match(e->window);
185    if ((!ee) || (ee->ignore_events)) return ECORE_CALLBACK_PASS_ON;
186    if (e->window != ee->prop.window) return ECORE_CALLBACK_PASS_ON;
187
188    ee->prop.focused = 1;
189    evas_focus_in(ee->evas);
190    if (ee->func.fn_focus_in) ee->func.fn_focus_in(ee);
191    return ECORE_CALLBACK_PASS_ON;
192 }
193
194 static Eina_Bool
195 _ecore_evas_wince_event_window_focus_out(void *data __UNUSED__, int type __UNUSED__, void *event)
196 {
197    Ecore_Evas *ee;
198    Ecore_WinCE_Event_Window_Focus_Out *e;
199
200    e = event;
201    ee = ecore_event_window_match(e->window);
202    if ((!ee) || (ee->ignore_events)) return ECORE_CALLBACK_PASS_ON;
203    if (e->window != ee->prop.window) return ECORE_CALLBACK_PASS_ON;
204
205    evas_focus_out(ee->evas);
206    ee->prop.focused = 0;
207    if (ee->func.fn_focus_out) ee->func.fn_focus_out(ee);
208    return ECORE_CALLBACK_PASS_ON;
209 }
210
211 static Eina_Bool
212 _ecore_evas_wince_event_window_damage(void *data __UNUSED__, int type __UNUSED__, void *event)
213 {
214    Ecore_Evas                      *ee;
215    Ecore_WinCE_Event_Window_Damage *e;
216
217    INF("window damage");
218
219    e = event;
220    ee = ecore_event_window_match((Ecore_Window)e->window);
221    if (!ee) return 1; /* pass on event */
222    if (e->window != (Ecore_WinCE_Window *)ee->prop.window) return 1;
223
224    if (ee->prop.avoid_damage)
225      {
226 #warning [ECORE] [WINCE] No Region code
227      }
228    else
229      {
230         if (ee->rotation == 0)
231           evas_damage_rectangle_add(ee->evas,
232                                     e->x,
233                                     e->y,
234                                     e->width,
235                                     e->height);
236         else if (ee->rotation == 90)
237           evas_damage_rectangle_add(ee->evas,
238                                     ee->h - e->y - e->height,
239                                     e->x,
240                                     e->height,
241                                     e->width);
242         else if (ee->rotation == 180)
243           evas_damage_rectangle_add(ee->evas,
244                                     ee->w - e->x - e->width,
245                                     ee->h - e->y - e->height,
246                                     e->width,
247                                     e->height);
248         else if (ee->rotation == 270)
249           evas_damage_rectangle_add(ee->evas,
250                                     e->y,
251                                     ee->w - e->x - e->width,
252                                     e->height,
253                                     e->width);
254      }
255
256    return 1;
257 }
258
259 static Eina_Bool
260 _ecore_evas_wince_event_window_destroy(void *data __UNUSED__, int type __UNUSED__, void *event)
261 {
262    Ecore_Evas                       *ee;
263    Ecore_WinCE_Event_Window_Destroy *e;
264
265    INF("window destroy");
266
267    e = event;
268    ee = ecore_event_window_match((Ecore_Window)e->window);
269    if (!ee) return 1; /* pass on event */
270    if (e->window != (Ecore_WinCE_Window *)ee->prop.window) return 1;
271    if (ee->func.fn_destroy) ee->func.fn_destroy(ee);
272    ecore_evas_free(ee);
273
274    return 1;
275 }
276
277 static Eina_Bool
278 _ecore_evas_wince_event_window_show(void *data __UNUSED__, int type __UNUSED__, void *event)
279 {
280    Ecore_Evas                    *ee;
281    Ecore_WinCE_Event_Window_Show *e;
282
283    INF("window show");
284
285    e = event;
286    ee = ecore_event_window_match((Ecore_Window)e->window);
287    if (!ee) return 1; /* pass on event */
288    if (e->window != (Ecore_WinCE_Window *)ee->prop.window) return 1;
289    if (ee->visible) return 0; /* dont pass it on */
290    ee->visible = 1;
291    if (ee->func.fn_show) ee->func.fn_show(ee);
292
293    return 1;
294 }
295
296 static Eina_Bool
297 _ecore_evas_wince_event_window_hide(void *data __UNUSED__, int type __UNUSED__, void *event)
298 {
299    Ecore_Evas                    *ee;
300    Ecore_WinCE_Event_Window_Hide *e;
301
302    INF("window hide");
303
304    e = event;
305    ee = ecore_event_window_match((Ecore_Window)e->window);
306    if (!ee) return 1; /* pass on event */
307    if (e->window != (Ecore_WinCE_Window *)ee->prop.window) return 1;
308    if (!ee->visible) return 0; /* dont pass it on */
309    ee->visible = 0;
310    if (ee->func.fn_hide) ee->func.fn_hide(ee);
311
312    return 1;
313 }
314
315 static Eina_Bool
316 _ecore_evas_wince_event_window_delete_request(void *data __UNUSED__, int type __UNUSED__, void *event)
317 {
318    Ecore_Evas                              *ee;
319    Ecore_WinCE_Event_Window_Delete_Request *e;
320
321    INF("window delete request");
322
323    e = event;
324    ee = ecore_event_window_match((Ecore_Window)e->window);
325    if (!ee) return 1; /* pass on event */
326    if (e->window != (Ecore_WinCE_Window *)ee->prop.window) return 1;
327    if (ee->func.fn_delete_request) ee->func.fn_delete_request(ee);
328
329    return 1;
330 }
331
332
333 /* Ecore_Evas interface */
334
335 static void
336 _ecore_evas_wince_free(Ecore_Evas *ee)
337 {
338    INF("ecore evas free");
339
340    ecore_wince_window_free((Ecore_WinCE_Window *)ee->prop.window);
341    ecore_event_window_unregister(ee->prop.window);
342    _ecore_evas_wince_shutdown();
343    ecore_wince_shutdown();
344 }
345
346 static void
347 _ecore_evas_wince_callback_delete_request_set(Ecore_Evas *ee,
348                                               Ecore_Evas_Event_Cb func)
349 {
350    ee->func.fn_delete_request = func;
351 }
352
353 static void
354 _ecore_evas_wince_move(Ecore_Evas *ee, int x, int y)
355 {
356   INF("ecore evas move (%dx%d)", x, y);
357    ee->req.x = x;
358    ee->req.y = y;
359
360    if ((x != ee->x) || (y != ee->y))
361      {
362         ee->x = x;
363         ee->y = y;
364         ecore_wince_window_move((Ecore_WinCE_Window *)ee->prop.window, x, y);
365         if (ee->func.fn_move) ee->func.fn_move(ee);
366      }
367 }
368
369 static void
370 _ecore_evas_wince_resize(Ecore_Evas *ee, int width, int height)
371 {
372    INF("ecore evas resize (%dx%d)", width, height);
373    ee->req.w = width;
374    ee->req.h = height;
375
376    if ((ee->w != width) || (ee->h != height))
377      {
378         ee->w = width;
379         ee->h = height;
380         ecore_wince_window_resize((Ecore_WinCE_Window *)ee->prop.window, width, height);
381         if ((ee->rotation == 90) || (ee->rotation == 270))
382           {
383              evas_output_size_set(ee->evas, ee->h, ee->w);
384              evas_output_viewport_set(ee->evas, 0, 0, ee->h, ee->w);
385           }
386         else
387           {
388              evas_output_size_set(ee->evas, ee->w, ee->h);
389              evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
390           }
391         /* FIXME: damage and shape */
392
393         if (ee->func.fn_resize) ee->func.fn_resize(ee);
394      }
395 }
396
397 static void
398 _ecore_evas_wince_move_resize(Ecore_Evas *ee, int x, int y, int width, int height)
399 {
400    INF("ecore evas resize (%dx%d %dx%d)", x, y, width, height);
401    ee->req.x = x;
402    ee->req.y = y;
403    ee->req.w = width;
404    ee->req.h = height;
405
406    if ((ee->w != width) || (ee->h != height) || (x != ee->x) || (y != ee->y))
407      {
408         int change_size = 0;
409         int change_pos = 0;
410
411         if ((ee->w != width) || (ee->h != height)) change_size = 1;
412         if ((x != ee->x) || (y != ee->y)) change_pos = 1;
413
414         ee->x = x;
415         ee->y = y;
416         ee->w = width;
417         ee->h = height;
418         ecore_wince_window_move_resize((Ecore_WinCE_Window *)ee->prop.window, x, y, width, height);
419         if ((ee->rotation == 90) || (ee->rotation == 270))
420           {
421              evas_output_size_set(ee->evas, ee->h, ee->w);
422              evas_output_viewport_set(ee->evas, 0, 0, ee->h, ee->w);
423           }
424         else
425           {
426              evas_output_size_set(ee->evas, ee->w, ee->h);
427              evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
428           }
429         /* FIXME: damage and shape */
430         if (change_pos)
431           {
432              if (ee->func.fn_move) ee->func.fn_move(ee);
433           }
434         if (change_size)
435           {
436              if (ee->func.fn_resize) ee->func.fn_resize(ee);
437           }
438      }
439 }
440
441 /* static void */
442 /* _ecore_evas_wince_rotation_set(Ecore_Evas *ee, int rotation) */
443 /* { */
444 /*    int rot_dif; */
445
446 /*    if (ee->rotation == rotation) return; */
447 /*    rot_dif = ee->rotation - rotation; */
448 /*    if (rot_dif < 0) rot_dif = -rot_dif; */
449 /*    if (!strcmp(ee->driver, "software_ddraw")) */
450 /*      { */
451 /*        Evas_Engine_Info_Software_16_WinCE *einfo; */
452
453 /*        einfo = (Evas_Engine_Info_Software_16_WinCE *)evas_engine_info_get(ee->evas); */
454 /*        if (!einfo) return; */
455 /*        if (rot_dif != 180) */
456 /*          { */
457 /*             int minw, minh, maxw, maxh, basew, baseh, stepw, steph; */
458
459 /*             einfo->info.rotation = rotation; */
460 /*             evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo); */
461 /*             if (!ee->prop.fullscreen) */
462 /*               { */
463 /*                  ecore_wince_window_resize(ee->prop.window, ee->h, ee->w); */
464 /*                  ee->expecting_resize.w = ee->h; */
465 /*                  ee->expecting_resize.h = ee->w; */
466 /*               } */
467 /*             else */
468 /*               { */
469 /*                  int w, h; */
470
471 /*                  ecore_wince_window_size_get(ee->prop.window, &w, &h); */
472 /*                  ecore_wince_window_resize(ee->prop.window, h, w); */
473 /*                  if ((rotation == 0) || (rotation == 180)) */
474 /*                    { */
475 /*                       evas_output_size_set(ee->evas, ee->w, ee->h); */
476 /*                       evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h); */
477 /*                    } */
478 /*                  else */
479 /*                    { */
480 /*                       evas_output_size_set(ee->evas, ee->h, ee->w); */
481 /*                       evas_output_viewport_set(ee->evas, 0, 0, ee->h, ee->w); */
482 /*                    } */
483 /*                  if (ee->func.fn_resize) ee->func.fn_resize(ee); */
484 /*               } */
485 /*             ecore_evas_size_min_get(ee, &minw, &minh); */
486 /*             ecore_evas_size_max_get(ee, &maxw, &maxh); */
487 /*             ecore_evas_size_base_get(ee, &basew, &baseh); */
488 /*             ecore_evas_size_step_get(ee, &stepw, &steph); */
489 /*             ee->rotation = rotation; */
490 /*             ecore_evas_size_min_set(ee, minh, minw); */
491 /*             ecore_evas_size_max_set(ee, maxh, maxw); */
492 /*             ecore_evas_size_base_set(ee, baseh, basew); */
493 /*             ecore_evas_size_step_set(ee, steph, stepw); */
494 /*             _ecore_evas_wince_mouse_move_process(ee, ee->mouse.x, ee->mouse.y, */
495 /*                                                   ecore_wince_current_time_get()); */
496 /*          } */
497 /*        else */
498 /*          { */
499 /*             einfo->info.rotation = rotation; */
500 /*             evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo); */
501 /*             ee->rotation = rotation; */
502 /*             _ecore_evas_wince_mouse_move_process(ee, ee->mouse.x, ee->mouse.y, */
503 /*                                                   ecore_wince_current_time_get()); */
504 /*             if (ee->func.fn_resize) ee->func.fn_resize(ee); */
505 /*          } */
506 /*        if ((ee->rotation == 90) || (ee->rotation == 270)) */
507 /*          evas_damage_rectangle_add(ee->evas, 0, 0, ee->h, ee->w); */
508 /*        else */
509 /*          evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h); */
510 /*      } */
511 /* } */
512
513 static void
514 _ecore_evas_wince_show(Ecore_Evas *ee)
515 {
516    INF("ecore evas show");
517
518    ee->should_be_visible = 1;
519    if (ee->prop.avoid_damage)
520      _ecore_evas_wince_render(ee);
521    ecore_wince_window_show((Ecore_WinCE_Window *)ee->prop.window);
522 /*    if (ee->prop.fullscreen) */
523 /*      ecore_wince_window_focus(ee->prop.window); */
524 }
525
526 static void
527 _ecore_evas_wince_hide(Ecore_Evas *ee)
528 {
529    INF("ecore evas hide");
530
531    ecore_wince_window_hide((Ecore_WinCE_Window *)ee->prop.window);
532    ee->should_be_visible = 0;
533 }
534
535 /* static void */
536 /* _ecore_evas_wince_raise(Ecore_Evas *ee) */
537 /* { */
538 /*    if (!ee->prop.fullscreen) */
539 /*      ecore_wince_window_raise(ee->prop.window); */
540 /*    else */
541 /*      ecore_wince_window_raise(ee->prop.window); */
542 /* } */
543
544 /* static void */
545 /* _ecore_evas_wince_lower(Ecore_Evas *ee) */
546 /* { */
547 /*    if (!ee->prop.fullscreen) */
548 /*      ecore_wince_window_lower(ee->prop.window); */
549 /*    else */
550 /*      ecore_wince_window_lower(ee->prop.window); */
551 /* } */
552
553 static void
554 _ecore_evas_wince_title_set(Ecore_Evas *ee, const char *title)
555 {
556    INF("ecore evas title set");
557
558    if (ee->prop.title) free(ee->prop.title);
559    ee->prop.title = NULL;
560    if (title) ee->prop.title = strdup(title);
561    ecore_wince_window_title_set((Ecore_WinCE_Window *)ee->prop.window, ee->prop.title);
562 }
563
564 /* static void */
565 /* _ecore_evas_wince_size_min_set(Ecore_Evas *ee, int width, int height) */
566 /* { */
567 /*    if (width < 0) width = 0; */
568 /*    if (height < 0) height = 0; */
569 /*    if ((ee->prop.min.w == width) && (ee->prop.min.h == height)) return; */
570 /*    ee->prop.min.w = width; */
571 /*    ee->prop.min.h = height; */
572 /*    ecore_wince_window_size_min_set(ee->prop.window, width, height); */
573 /* } */
574
575 /* static void */
576 /* _ecore_evas_wince_size_max_set(Ecore_Evas *ee, int width, int height) */
577 /* { */
578 /*    if (width < 0) width = 0; */
579 /*    if (height < 0) height = 0; */
580 /*    if ((ee->prop.max.w == width) && (ee->prop.max.h == height)) return; */
581 /*    ee->prop.max.w = width; */
582 /*    ee->prop.max.h = height; */
583 /*    ecore_wince_window_size_max_set(ee->prop.window, width, height); */
584 /* } */
585
586 /* static void */
587 /* _ecore_evas_wince_size_base_set(Ecore_Evas *ee, int width, int height) */
588 /* { */
589 /*    if (width < 0) width = 0; */
590 /*    if (height < 0) height = 0; */
591 /*    if ((ee->prop.base.w == width) && (ee->prop.base.h == height)) return; */
592 /*    ee->prop.base.w = width; */
593 /*    ee->prop.base.h = height; */
594 /*    ecore_wince_window_size_base_set(ee->prop.window, width, height); */
595 /* } */
596
597 /* static void */
598 /* _ecore_evas_wince_size_step_set(Ecore_Evas *ee, int width, int height) */
599 /* { */
600 /*    if (width < 1) width = 1; */
601 /*    if (height < 1) height = 1; */
602 /*    if ((ee->prop.step.w == width) && (ee->prop.step.h == height)) return; */
603 /*    ee->prop.step.w = width; */
604 /*    ee->prop.step.h = height; */
605 /*    ecore_wince_window_size_step_set(ee->prop.window, width, height); */
606 /* } */
607
608 static void
609 _ecore_evas_wince_cursor_set(Ecore_Evas *ee, Evas_Object *obj, int layer, int hot_x, int hot_y)
610 {
611 #if 0
612    int x, y;
613
614    if (ee->prop.cursor.object) evas_object_del(ee->prop.cursor.object);
615
616    if (obj == NULL)
617      {
618         ee->prop.cursor.object = NULL;
619         ee->prop.cursor.layer = 0;
620         ee->prop.cursor.hot.x = 0;
621         ee->prop.cursor.hot.y = 0;
622         ecore_wince_window_cursor_show(ee->prop.window, 1);
623         return;
624      }
625
626    ee->prop.cursor.object = obj;
627    ee->prop.cursor.layer = layer;
628    ee->prop.cursor.hot.x = hot_x;
629    ee->prop.cursor.hot.y = hot_y;
630
631    ecore_wince_window_cursor_show(ee->prop.window, 0);
632
633    evas_pointer_output_xy_get(ee->evas, &x, &y);
634    evas_object_layer_set(ee->prop.cursor.object, ee->prop.cursor.layer);
635    evas_object_move(ee->prop.cursor.object,
636                     x - ee->prop.cursor.hot.x,
637                     y - ee->prop.cursor.hot.y);
638    evas_object_pass_events_set(ee->prop.cursor.object, 1);
639    if (evas_pointer_inside_get(ee->evas))
640      evas_object_show(ee->prop.cursor.object);
641 #endif
642 }
643
644 static void
645 _ecore_evas_wince_focus_set(Ecore_Evas *ee, int on __UNUSED__)
646 {
647    ecore_wince_window_focus(ee->prop.window);
648 }
649
650 /* static void */
651 /* _ecore_evas_wince_iconified_set(Ecore_Evas *ee, int on) */
652 /* { */
653 /* /\*    if (((ee->prop.borderless) && (on)) || *\/ */
654 /* /\*        ((!ee->prop.borderless) && (!on))) return; *\/ */
655 /*    ee->prop.iconified = on; */
656 /*    ecore_wince_window_iconified_set(ee->prop.window, ee->prop.iconified); */
657 /* } */
658
659 /* static void */
660 /* _ecore_evas_wince_borderless_set(Ecore_Evas *ee, int on) */
661 /* { */
662 /*    if (((ee->prop.borderless) && (on)) || */
663 /*        ((!ee->prop.borderless) && (!on))) return; */
664 /*    ee->prop.borderless = on; */
665 /*    ecore_wince_window_borderless_set(ee->prop.window, ee->prop.borderless); */
666 /* } */
667
668 static void
669 _ecore_evas_wince_fullscreen_set(Ecore_Evas *ee, int on)
670 {
671    Evas_Engine_Info_Software_16_WinCE *einfo;
672    struct _Ecore_WinCE_Window         *window;
673
674    INF("ecore evas fullscreen set");
675
676    if ((ee->engine.wince.state.fullscreen && on) ||
677       (!ee->engine.wince.state.fullscreen && !on))
678      return;
679
680    ee->engine.wince.state.fullscreen = on;
681    ee->prop.fullscreen = on;
682
683    window = (struct _Ecore_WinCE_Window *)ee->prop.window;
684
685    if (on != 0)
686    {
687 /*       ecore_win32_window_shape_set(ee->engine.win32.window, 0, 0, NULL); */
688       ecore_wince_window_fullscreen_set((Ecore_WinCE_Window *)ee->prop.window, on);
689       ee->w = GetSystemMetrics(SM_CXSCREEN);
690       ee->h = GetSystemMetrics(SM_CYSCREEN);
691       ee->req.w = ee->w;
692       ee->req.h = ee->h;
693       evas_output_size_set(ee->evas, ee->w, ee->h);
694       evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
695    }
696    else
697    {
698       int w;
699       int h;
700
701       ecore_wince_window_fullscreen_set((Ecore_WinCE_Window *)ee->prop.window, on);
702       ecore_wince_window_size_get((Ecore_WinCE_Window *)ee->prop.window, &w, &h);
703       ee->w = w;
704       ee->h = h;
705       ee->req.w = ee->w;
706       ee->req.h = ee->h;
707       evas_output_size_set(ee->evas, ee->w, ee->h);
708       evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h);
709 /*       ecore_win32_window_shape_set(window, */
710 /*                                    window->shape.width, */
711 /*                                    window->shape.height, */
712 /*                                    window->shape.mask); */
713    }
714
715    einfo = (Evas_Engine_Info_Software_16_WinCE *)evas_engine_info_get(ecore_evas_get(ee));
716    if (einfo)
717      {
718         einfo->info.fullscreen = !!on;
719 /*         einfo->info.layered = window->shape.layered; */
720         if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo))
721           {
722              ERR("evas_engine_info_set() for engine '%s' failed.", ee->driver);
723           }
724      }
725 }
726
727 static void
728 _ecore_evas_wince_screen_dpi_get(const Ecore_Evas *ee, int *xdpi, int *ydpi)
729 {
730    HDC dc;
731
732    dc = GetDC(NULL);
733    if (!dc)
734      {
735         if (xdpi) *xdpi = 0;
736         if (ydpi) *ydpi = 0;
737         return;
738      }
739
740    if (xdpi) *xdpi = GetDeviceCaps(dc, LOGPIXELSX);
741    if (ydpi) *ydpi = GetDeviceCaps(dc, LOGPIXELSY);
742
743    ReleaseDC(NULL, dc);
744 }
745
746 static Ecore_Evas_Engine_Func _ecore_wince_engine_func =
747 {
748    _ecore_evas_wince_free,
749    NULL,
750    NULL,
751    NULL,
752    NULL,
753    _ecore_evas_wince_callback_delete_request_set,
754    NULL,
755    NULL,
756    NULL,
757    NULL,
758    NULL,
759    NULL,
760    NULL,
761    NULL,
762    NULL,
763    _ecore_evas_wince_move,
764    NULL,
765    _ecore_evas_wince_resize,
766    _ecore_evas_wince_move_resize,
767    NULL, //_ecore_evas_wince_rotation_set,
768    NULL, /* _ecore_evas_x_shaped_set */
769    _ecore_evas_wince_show,
770    _ecore_evas_wince_hide,
771    NULL, //_ecore_evas_wince_raise,
772    NULL, //_ecore_evas_wince_lower,
773    NULL, //_ecore_evas_wince_activate,
774    _ecore_evas_wince_title_set,
775    NULL, /* _ecore_evas_x_name_class_set */
776    NULL, //_ecore_evas_wince_size_min_set,
777    NULL, //_ecore_evas_wince_size_max_set,
778    NULL, //_ecore_evas_wince_size_base_set,
779    NULL, //_ecore_evas_wince_size_step_set,
780    _ecore_evas_wince_cursor_set,
781    NULL, /* _ecore_evas_x_layer_set */
782    _ecore_evas_wince_focus_set,
783    NULL, //_ecore_evas_wince_iconified_set,
784    NULL, //_ecore_evas_wince_borderless_set,
785    NULL, /* _ecore_evas_x_override_set */
786    NULL,
787    _ecore_evas_wince_fullscreen_set,
788    NULL, /* _ecore_evas_x_avoid_damage_set */
789    NULL, /* _ecore_evas_x_withdrawn_set */
790    NULL, /* _ecore_evas_x_sticky_set */
791    NULL, /* _ecore_evas_x_ignore_events_set */
792    NULL, /* _ecore_evas_x_alpha_set */
793    NULL, //transparent
794    NULL, // profiles_set
795
796    NULL,
797    NULL,
798    NULL,
799    NULL,
800    NULL,
801    NULL,
802
803    NULL, // render
804    NULL, // screen_geometry_get
805    _ecore_evas_wince_screen_dpi_get,
806
807    NULL, // wm_rot_preferred_rotation_set
808    NULL  // wm_rot_available_rotations_set
809 };
810
811 /* API */
812
813 static Ecore_Evas *
814 ecore_evas_software_wince_new_internal(int                 backend,
815                                        Ecore_WinCE_Window *parent,
816                                        int                 x,
817                                        int                 y,
818                                        int                 width,
819                                        int                 height,
820                                        int                 fullscreen)
821 {
822    Evas_Engine_Info_Software_16_WinCE *einfo;
823    Ecore_Evas                         *ee;
824    int                                 rmethod;
825
826    rmethod = evas_render_method_lookup("software_16_wince");
827    if (!rmethod)
828      return NULL;
829
830    if (!ecore_wince_init())
831      return NULL;
832
833    ee = calloc(1, sizeof(Ecore_Evas));
834    if (!ee)
835      {
836         ecore_wince_shutdown();
837         return NULL;
838      }
839
840    ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
841
842    if (!_ecore_evas_wince_init())
843      {
844         free(ee);
845         ecore_wince_shutdown();
846         return NULL;
847      }
848
849    ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_wince_engine_func;
850
851    ee->driver = "software_16_wince";
852
853    if (width < 1) width = 1;
854    if (height < 1) height = 1;
855    ee->x = x;
856    ee->y = y;
857    ee->w = width;
858    ee->h = height;
859    ee->req.x = ee->x;
860    ee->req.y = ee->y;
861    ee->req.w = ee->w;
862    ee->req.h = ee->h;
863
864    ee->prop.max.w = 32767;
865    ee->prop.max.h = 32767;
866    ee->prop.layer = 4;
867    ee->prop.request_pos = 0;
868    ee->prop.sticky = 0;
869    /* FIXME: sticky to add */
870
871    ee->prop.window = (Ecore_Window)ecore_wince_window_new((Ecore_WinCE_Window *)parent, x, y, width, height);
872    if (!ee->prop.window)
873      {
874         _ecore_evas_wince_shutdown();
875         free(ee);
876         ecore_wince_shutdown();
877         return NULL;
878      }
879
880    ecore_wince_window_fullscreen_set((Ecore_WinCE_Window *)ee->prop.window, fullscreen);
881
882    /* init evas here */
883    ee->evas = evas_new();
884    evas_data_attach_set(ee->evas, ee);
885    evas_output_method_set(ee->evas, rmethod);
886    evas_output_size_set(ee->evas, width, height);
887    evas_output_viewport_set(ee->evas, 0, 0, width, height);
888
889    einfo = (Evas_Engine_Info_Software_16_WinCE *)evas_engine_info_get(ee->evas);
890    if (einfo)
891      {
892         /* FIXME: REDRAW_DEBUG missing for now */
893         einfo->info.window = ((struct _Ecore_WinCE_Window *)ee->prop.window)->window;
894         einfo->info.width = width;
895         einfo->info.height = height;
896         einfo->info.backend = backend;
897         einfo->info.rotation = 0;
898         einfo->info.fullscreen = fullscreen;
899         if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo))
900           {
901              ERR("evas_engine_info_set() for engine '%s' failed.", ee->driver);
902              _ecore_evas_wince_shutdown();
903              free(ee);
904              ecore_wince_shutdown();
905              return NULL;
906           }
907
908         ecore_wince_window_backend_set((Ecore_WinCE_Window *)ee->prop.window, backend);
909         ecore_wince_window_suspend_cb_set((Ecore_WinCE_Window *)ee->prop.window, einfo->func.suspend);
910         ecore_wince_window_resume_cb_set((Ecore_WinCE_Window *)ee->prop.window, einfo->func.resume);
911      }
912    else
913      {
914         ERR("evas_engine_info_set() init engine '%s' failed.", ee->driver);
915         _ecore_evas_wince_shutdown();
916         free(ee);
917         ecore_wince_shutdown();
918         return NULL;
919      }
920
921    ee->engine.func->fn_render = _ecore_evas_wince_render;
922    _ecore_evas_register(ee);
923    ecore_event_window_register(ee->prop.window, ee, ee->evas,
924                                (Ecore_Event_Mouse_Move_Cb)_ecore_evas_mouse_move_process,
925                                (Ecore_Event_Multi_Move_Cb)_ecore_evas_mouse_multi_move_process,
926                                (Ecore_Event_Multi_Down_Cb)_ecore_evas_mouse_multi_down_process,
927                                (Ecore_Event_Multi_Up_Cb)_ecore_evas_mouse_multi_up_process);
928    evas_focus_in(ee->evas);
929
930    return ee;
931 }
932
933 #else
934
935 static Ecore_Evas *
936 ecore_evas_software_wince_new_internal(int                 backend __UNUSED__,
937                                        Ecore_WinCE_Window *parent __UNUSED__,
938                                        int                 x __UNUSED__,
939                                        int                 y __UNUSED__,
940                                        int                 width __UNUSED__,
941                                        int                 height __UNUSED__,
942                                        int                 fullscreen __UNUSED__)
943 {
944    return NULL;
945 }
946
947 #endif /* BUILD_ECORE_EVAS_SOFTWARE_16_WINCE */
948
949
950 EAPI Ecore_Evas *
951 ecore_evas_software_wince_new(Ecore_WinCE_Window *parent,
952                               int                 x,
953                               int                 y,
954                               int                 width,
955                               int                 height)
956 {
957    return ecore_evas_software_wince_new_internal(0, parent, x, y, width, height, 1);
958 }
959
960 EAPI Ecore_Evas *
961 ecore_evas_software_wince_fb_new(Ecore_WinCE_Window *parent,
962                                  int                 x,
963                                  int                 y,
964                                  int                 width,
965                                  int                 height)
966 {
967    return ecore_evas_software_wince_new_internal(1, parent, x, y, width, height, 1);
968 }
969
970 EAPI Ecore_Evas *
971 ecore_evas_software_wince_gapi_new(Ecore_WinCE_Window *parent,
972                                    int                 x,
973                                    int                 y,
974                                    int                 width,
975                                    int                 height)
976 {
977    return ecore_evas_software_wince_new_internal(2, parent, x, y, width, height, 1);
978 }
979
980 EAPI Ecore_Evas *
981 ecore_evas_software_wince_ddraw_new(Ecore_WinCE_Window *parent,
982                                     int                 x,
983                                     int                 y,
984                                     int                 width,
985                                     int                 height)
986 {
987    return ecore_evas_software_wince_new_internal(3, parent, x, y, width, height, 1);
988 }
989
990 EAPI Ecore_Evas *
991 ecore_evas_software_wince_gdi_new(Ecore_WinCE_Window *parent,
992                                   int                 x,
993                                   int                 y,
994                                   int                 width,
995                                   int                 height)
996 {
997    return ecore_evas_software_wince_new_internal(4, parent, x, y, width, height, 0);
998 }
999
1000 #ifdef BUILD_ECORE_EVAS_SOFTWARE_16_WINCE
1001
1002 EAPI Ecore_WinCE_Window *
1003 ecore_evas_software_wince_window_get(const Ecore_Evas *ee)
1004 {
1005    return (Ecore_WinCE_Window *) ecore_evas_window_get(ee);
1006 }
1007
1008 #else
1009
1010 EAPI Ecore_WinCE_Window *
1011 ecore_evas_software_wince_window_get(const Ecore_Evas *ee __UNUSED__)
1012 {
1013    return NULL;
1014 }
1015
1016 #endif /* ! BUILD_ECORE_EVAS_SOFTWARE_16_WINCE */