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