Elm: Add wayland_shm engine for Elm. Add config entries for the
[framework/uifw/elementary.git] / src / lib / elm_win.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 typedef struct _Elm_Win Elm_Win;
5
6 struct _Elm_Win
7 {
8    Ecore_Evas *ee;
9    Evas *evas;
10    Evas_Object *parent, *win_obj, *img_obj, *frame_obj;
11    Eina_List *subobjs;
12 #ifdef HAVE_ELEMENTARY_X
13    Ecore_X_Window xwin;
14    Ecore_Event_Handler *client_message_handler;
15 #endif
16    Ecore_Job *deferred_resize_job;
17    Ecore_Job *deferred_child_eval_job;
18
19    Elm_Win_Type type;
20    Elm_Win_Keyboard_Mode kbdmode;
21    struct {
22       const char *info;
23       Ecore_Timer *timer;
24       int repeat_count;
25       int shot_counter;
26    } shot;
27    Eina_Bool autodel : 1;
28    Eina_Bool constrain : 1;
29    int *autodel_clear, rot;
30    int show_count;
31    struct {
32       int x, y;
33    } screen;
34
35    struct {
36       Evas_Object *top;
37
38       struct {
39          Evas_Object *target;
40          Eina_Bool visible : 1;
41          Eina_Bool handled : 1;
42       } cur, prev;
43
44       const char *style;
45       Ecore_Job *reconf_job;
46
47       Eina_Bool enabled : 1;
48       Eina_Bool changed_theme : 1;
49       Eina_Bool top_animate : 1;
50       Eina_Bool geometry_changed : 1;
51    } focus_highlight;
52 };
53
54 static const char *widtype = NULL;
55 static void _elm_win_obj_callback_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
56 static void _elm_win_obj_callback_img_obj_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
57 static void _elm_win_obj_callback_parent_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
58 static void _elm_win_obj_intercept_move(void *data, Evas_Object *obj, Evas_Coord x, Evas_Coord y);
59 static void _elm_win_obj_intercept_show(void *data, Evas_Object *obj);
60 static void _elm_win_move(Ecore_Evas *ee);
61 static void _elm_win_resize(Ecore_Evas *ee);
62 static void _elm_win_delete_request(Ecore_Evas *ee);
63 static void _elm_win_resize_job(void *data);
64 #ifdef HAVE_ELEMENTARY_X
65 static void _elm_win_xwin_update(Elm_Win *win);
66 #endif
67 static void _elm_win_eval_subobjs(Evas_Object *obj);
68 static void _elm_win_subobj_callback_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
69 static void _elm_win_subobj_callback_changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
70 static void _elm_win_focus_highlight_init(Elm_Win *win);
71 static void _elm_win_focus_highlight_shutdown(Elm_Win *win);
72 static void _elm_win_focus_highlight_visible_set(Elm_Win *win, Eina_Bool visible);
73 static void _elm_win_focus_highlight_reconfigure_job_start(Elm_Win *win);
74 static void _elm_win_focus_highlight_reconfigure_job_stop(Elm_Win *win);
75 static void _elm_win_focus_highlight_anim_end(void *data, Evas_Object *obj, const char *emission, const char *source);
76 static void _elm_win_focus_highlight_reconfigure(Elm_Win *win);
77
78 static const char SIG_DELETE_REQUEST[] = "delete,request";
79 static const char SIG_FOCUS_OUT[] = "focus,out";
80 static const char SIG_FOCUS_IN[] = "focus,in";
81 static const char SIG_MOVED[] = "moved";
82 static const char SIG_THEME_CHANGED[] = "theme,changed";
83
84 static const Evas_Smart_Cb_Description _signals[] = {
85    {SIG_DELETE_REQUEST, ""},
86    {SIG_FOCUS_OUT, ""},
87    {SIG_FOCUS_IN, ""},
88    {SIG_MOVED, ""},
89    {NULL, NULL}
90 };
91
92
93
94 Eina_List *_elm_win_list = NULL;
95 int _elm_win_deferred_free = 0;
96
97 // exmaple shot spec (wait 0.1 sec then save as my-window.png):
98 // ELM_ENGINE="shot:delay=0.1:file=my-window.png"
99
100 static double
101 _shot_delay_get(Elm_Win *win)
102 {
103    char *p, *pd;
104    char *d = strdup(win->shot.info);
105
106    if (!d) return 0.5;
107    for (p = (char *)win->shot.info; *p; p++)
108      {
109         if (!strncmp(p, "delay=", 6))
110           {
111              double v;
112
113              for (pd = d, p += 6; (*p) && (*p != ':'); p++, pd++)
114                {
115                   *pd = *p;
116                }
117              *pd = 0;
118              v = atof(d);
119              free(d);
120              return v;
121           }
122      }
123    free(d);
124    return 0.5;
125 }
126
127 static char *
128 _shot_file_get(Elm_Win *win)
129 {
130    char *p;
131    char *tmp = strdup(win->shot.info);
132    char *repname = NULL;
133
134    if (!tmp) return NULL;
135
136    for (p = (char *)win->shot.info; *p; p++)
137      {
138         if (!strncmp(p, "file=", 5))
139           {
140              strcpy(tmp, p + 5);
141              if (!win->shot.repeat_count) return tmp;
142              else
143                {
144                   char *dotptr = strrchr(tmp, '.');
145                   if (dotptr)
146                     {
147                        repname = malloc(sizeof(char)*(strlen(tmp) + 16));
148                        strncpy(repname, tmp, dotptr - tmp);
149                        sprintf(repname + (dotptr - tmp), "%03i",
150                                win->shot.shot_counter + 1);
151                        strcat(repname, dotptr);
152                        free(tmp);
153                        return repname;
154                     }
155                }
156           }
157      }
158    free(tmp);
159    if (!win->shot.repeat_count) return strdup("out.png");
160    else
161      {
162         repname = malloc(sizeof(char) * 24);
163         sprintf(repname, "out%03i.png", win->shot.shot_counter + 1);
164         return repname;
165      }
166 }
167
168 static int
169 _shot_repeat_count_get(Elm_Win *win)
170 {
171
172    char *p, *pd;
173    char *d = strdup(win->shot.info);
174
175    if (!d) return 0;
176    for (p = (char *)win->shot.info; *p; p++)
177      {
178         if (!strncmp(p, "repeat=", 7))
179           {
180              int v;
181
182              for (pd = d, p += 7; (*p) && (*p != ':'); p++, pd++)
183                {
184                   *pd = *p;
185                }
186              *pd = 0;
187              v = atoi(d);
188              if (v < 0) v = 0;
189              if (v > 1000) v = 999;
190              free(d);
191              return v;
192           }
193      }
194    free(d);
195    return 0;
196 }
197
198 static char *
199 _shot_key_get(Elm_Win *win __UNUSED__)
200 {
201    return NULL;
202 }
203
204 static char *
205 _shot_flags_get(Elm_Win *win __UNUSED__)
206 {
207    return NULL;
208 }
209
210 static void
211 _shot_do(Elm_Win *win)
212 {
213    Ecore_Evas *ee;
214    Evas_Object *o;
215    unsigned int *pixels;
216    int w, h;
217    char *file, *key, *flags;
218
219    ecore_evas_manual_render(win->ee);
220    pixels = (void *)ecore_evas_buffer_pixels_get(win->ee);
221    if (!pixels) return;
222    ecore_evas_geometry_get(win->ee, NULL, NULL, &w, &h);
223    if ((w < 1) || (h < 1)) return;
224    file = _shot_file_get(win);
225    if (!file) return;
226    key = _shot_key_get(win);
227    flags = _shot_flags_get(win);
228    ee = ecore_evas_buffer_new(1, 1);
229    o = evas_object_image_add(ecore_evas_get(ee));
230    evas_object_image_alpha_set(o, ecore_evas_alpha_get(win->ee));
231    evas_object_image_size_set(o, w, h);
232    evas_object_image_data_set(o, pixels);
233    if (!evas_object_image_save(o, file, key, flags))
234      {
235         ERR("Cannot save window to '%s' (key '%s', flags '%s')",
236             file, key, flags);
237      }
238    free(file);
239    if (key) free(key);
240    if (flags) free(flags);
241    ecore_evas_free(ee);
242    if (win->shot.repeat_count) win->shot.shot_counter++;
243 }
244
245 static Eina_Bool
246 _shot_delay(void *data)
247 {
248    Elm_Win *win = data;
249    _shot_do(win);
250    if (win->shot.repeat_count)
251      {
252         int remainshot = (win->shot.repeat_count - win->shot.shot_counter);
253         if (remainshot > 0) return EINA_TRUE;
254      }
255    win->shot.timer = NULL;
256    elm_exit();
257    return EINA_FALSE;
258 }
259
260 static void
261 _shot_init(Elm_Win *win)
262 {
263    if (!win->shot.info) return;
264    win->shot.repeat_count = _shot_repeat_count_get(win);
265    win->shot.shot_counter = 0;
266 }
267
268 static void
269 _shot_handle(Elm_Win *win)
270 {
271    if (!win->shot.info) return;
272    win->shot.timer = ecore_timer_add(_shot_delay_get(win), _shot_delay, win);
273 }
274
275 static void
276 _elm_win_move(Ecore_Evas *ee)
277 {
278    Evas_Object *obj = ecore_evas_object_associate_get(ee);
279    Elm_Win *win;
280    int x, y;
281
282    if (!obj) return;
283    win = elm_widget_data_get(obj);
284    if (!win) return;
285    ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
286    win->screen.x = x;
287    win->screen.y = y;
288    evas_object_smart_callback_call(win->win_obj, SIG_MOVED, NULL);
289 }
290
291 static void
292 _elm_win_resize(Ecore_Evas *ee)
293 {
294    Evas_Object *obj = ecore_evas_object_associate_get(ee);
295    Elm_Win *win;
296
297    if (!obj) return;
298    win = elm_widget_data_get(obj);
299    if (!win) return;
300    if (win->deferred_resize_job) ecore_job_del(win->deferred_resize_job);
301    win->deferred_resize_job = ecore_job_add(_elm_win_resize_job, win);
302 }
303
304 static void
305 _elm_win_focus_in(Ecore_Evas *ee)
306 {
307    Evas_Object *obj = ecore_evas_object_associate_get(ee);
308    Elm_Win *win;
309
310    if (!obj) return;
311    win = elm_widget_data_get(obj);
312    if (!win) return;
313    _elm_widget_top_win_focused_set(win->win_obj, EINA_TRUE);
314    if (win->show_count == 1)
315      {
316         elm_widget_focus_steal(win->win_obj);
317         win->show_count++;
318      }
319    else
320      elm_widget_focus_restore(win->win_obj);
321    evas_object_smart_callback_call(win->win_obj, SIG_FOCUS_IN, NULL);
322    win->focus_highlight.cur.visible = EINA_TRUE;
323    _elm_win_focus_highlight_reconfigure_job_start(win);
324    if (win->frame_obj)
325      {
326         edje_object_signal_emit(win->frame_obj, "elm,action,focus", "elm");
327      }
328    else if (win->img_obj)
329      {
330         /* do nothing */
331      }
332 }
333
334 static void
335 _elm_win_focus_out(Ecore_Evas *ee)
336 {
337    Evas_Object *obj = ecore_evas_object_associate_get(ee);
338    Elm_Win *win;
339
340    if (!obj) return;
341    win = elm_widget_data_get(obj);
342    if (!win) return;
343    elm_object_focus_set(win->win_obj, EINA_FALSE);
344    _elm_widget_top_win_focused_set(win->win_obj, EINA_FALSE);
345    evas_object_smart_callback_call(win->win_obj, SIG_FOCUS_OUT, NULL);
346    win->focus_highlight.cur.visible = EINA_FALSE;
347    _elm_win_focus_highlight_reconfigure_job_start(win);
348    if (win->frame_obj)
349      {
350         edje_object_signal_emit(win->frame_obj, "elm,action,unfocus", "elm");
351      }
352    else if (win->img_obj)
353      {
354         /* do nothing */
355      }
356 }
357
358 static Eina_Bool
359 _elm_win_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
360 {
361    Elm_Win *wd = elm_widget_data_get(obj);
362    const Eina_List *items;
363    void *(*list_data_get) (const Eina_List *list);
364
365    if (!wd)
366      return EINA_FALSE;
367
368    /* Focus chain */
369    if (wd->subobjs)
370      {
371         if (!(items = elm_widget_focus_custom_chain_get(obj)))
372           {
373              items = wd->subobjs;
374              if (!items)
375                return EINA_FALSE;
376           }
377         list_data_get = eina_list_data_get;
378
379         elm_widget_focus_list_next_get(obj, items, list_data_get, dir, next);
380
381         if (*next)
382           return EINA_TRUE;
383      }
384
385    *next = (Evas_Object *)obj;
386    return EINA_FALSE;
387 }
388
389 static void
390 _elm_win_on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
391 {
392    Elm_Win *win = elm_widget_data_get(obj);
393    if (!win) return;
394
395    if (win->img_obj)
396       evas_object_focus_set(win->img_obj, elm_widget_focus_get(obj));
397    else
398       evas_object_focus_set(obj, elm_widget_focus_get(obj));
399 }
400
401 static Eina_Bool
402 _elm_win_event_cb(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
403 {
404    if (type == EVAS_CALLBACK_KEY_DOWN)
405      {
406         Evas_Event_Key_Down *ev = event_info;
407         if (!strcmp(ev->keyname, "Tab"))
408           {
409              if (evas_key_modifier_is_set(ev->modifiers, "Shift"))
410                elm_widget_focus_cycle(obj, ELM_FOCUS_PREVIOUS);
411              else
412                elm_widget_focus_cycle(obj, ELM_FOCUS_NEXT);
413              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
414              return EINA_TRUE;
415           }
416         else if ((!strcmp(ev->keyname, "Left")) ||
417                  (!strcmp(ev->keyname, "KP_Left")))
418           {
419              //TODO : woohyun jung
420           }
421         else if ((!strcmp(ev->keyname, "Right")) ||
422                  (!strcmp(ev->keyname, "KP_Right")))
423           {
424              //TODO : woohyun jung
425           }
426         else if ((!strcmp(ev->keyname, "Up")) ||
427                  (!strcmp(ev->keyname, "KP_Up")))
428           {
429              //TODO : woohyun jung
430           }
431         else if ((!strcmp(ev->keyname, "Down")) ||
432                  (!strcmp(ev->keyname, "KP_Down")))
433           {
434              //TODO : woohyun jung
435           }
436      }
437
438    return EINA_FALSE;
439 }
440
441 static void
442 _deferred_ecore_evas_free(void *data)
443 {
444    ecore_evas_free(data);
445    _elm_win_deferred_free--;
446 }
447
448 static void
449 _elm_win_obj_callback_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
450 {
451    Elm_Win *win = data;
452
453    if (!win->show_count) win->show_count++;
454    if (win->shot.info) _shot_handle(win);
455 }
456
457 static void
458 _elm_win_obj_callback_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
459 {
460    Elm_Win *win = data;
461
462    if (win->frame_obj)
463      {
464         evas_object_hide(win->frame_obj);
465      }
466    else if (win->img_obj)
467      {
468         evas_object_hide(win->img_obj);
469      }
470 }
471
472 static void
473 _elm_win_obj_callback_del(void *data, Evas *e, Evas_Object *obj, void *event_info __UNUSED__)
474 {
475    Elm_Win *win = data;
476    Evas_Object *child;
477
478    if (win->parent)
479      {
480         evas_object_event_callback_del_full(win->parent, EVAS_CALLBACK_DEL,
481                                             _elm_win_obj_callback_parent_del, win);
482         win->parent = NULL;
483      }
484    if (win->autodel_clear) *(win->autodel_clear) = -1;
485    _elm_win_list = eina_list_remove(_elm_win_list, win->win_obj);
486    while (win->subobjs) elm_win_resize_object_del(obj, win->subobjs->data);
487    if (win->ee)
488      {
489         ecore_evas_callback_delete_request_set(win->ee, NULL);
490         ecore_evas_callback_resize_set(win->ee, NULL);
491      }
492    if (win->deferred_resize_job) ecore_job_del(win->deferred_resize_job);
493    if (win->deferred_child_eval_job) ecore_job_del(win->deferred_child_eval_job);
494    if (win->shot.info) eina_stringshare_del(win->shot.info);
495    if (win->shot.timer) ecore_timer_del(win->shot.timer);
496    evas_object_event_callback_del_full(win->win_obj, EVAS_CALLBACK_DEL,
497                                        _elm_win_obj_callback_del, win);
498    while (((child = evas_object_bottom_get(win->evas))) &&
499           (child != obj))
500      {
501         evas_object_del(child);
502      }
503    while (((child = evas_object_top_get(win->evas))) &&
504           (child != obj))
505      {
506         evas_object_del(child);
507      }
508 #ifdef HAVE_ELEMENTARY_X
509    if (win->client_message_handler)
510      ecore_event_handler_del(win->client_message_handler);
511 #endif
512    // FIXME: Why are we flushing edje on every window destroy ??
513    //   edje_file_cache_flush();
514    //   edje_collection_cache_flush();
515    //   evas_image_cache_flush(win->evas);
516    //   evas_font_cache_flush(win->evas);
517    // FIXME: we are in the del handler for the object and delete the canvas
518    // that lives under it from the handler... nasty. deferring doesn't help either
519
520    if (win->img_obj)
521      {
522         win->img_obj = NULL;
523      }
524    else
525      {
526         if (win->ee)
527           {
528              ecore_job_add(_deferred_ecore_evas_free, win->ee);
529              _elm_win_deferred_free++;
530           }
531      }
532
533    _elm_win_focus_highlight_shutdown(win);
534    eina_stringshare_del(win->focus_highlight.style);
535
536    free(win);
537
538    if ((!_elm_win_list) &&
539        (elm_policy_get(ELM_POLICY_QUIT) == ELM_POLICY_QUIT_LAST_WINDOW_CLOSED))
540      {
541         edje_file_cache_flush();
542         edje_collection_cache_flush();
543         evas_image_cache_flush(e);
544         evas_font_cache_flush(e);
545         elm_exit();
546      }
547 }
548
549 static void
550 _elm_win_obj_callback_img_obj_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
551 {
552    Elm_Win *win = data;
553    if (!win->img_obj) return;
554    evas_object_event_callback_del_full
555       (win->img_obj, EVAS_CALLBACK_DEL, _elm_win_obj_callback_img_obj_del, win);
556    evas_object_del(win->img_obj);
557 }
558
559 static void
560 _elm_win_obj_callback_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
561 {
562    Elm_Win *win = data;
563    if (obj == win->parent) win->parent = NULL;
564 }
565
566 static void
567 _elm_win_obj_intercept_move(void *data, Evas_Object *obj, Evas_Coord x, Evas_Coord y)
568 {
569    Elm_Win *win = data;
570
571    if (win->img_obj)
572      {
573         if ((x != win->screen.x) || (y != win->screen.y))
574           {
575              win->screen.x = x;
576              win->screen.y = y;
577              evas_object_smart_callback_call(win->win_obj, SIG_MOVED, NULL);
578           }
579      }
580    else
581      {
582         evas_object_move(obj, x, y);
583      }
584 }
585
586 static void
587 _elm_win_obj_intercept_show(void *data, Evas_Object *obj)
588 {
589    Elm_Win *win = data;
590    // this is called to make sure all smart containers have calculated their
591    // sizes BEFORE we show the window to make sure it initially appears at
592    // our desired size (ie min size is known first)
593    evas_smart_objects_calculate(evas_object_evas_get(obj));
594    if (win->frame_obj)
595      {
596         evas_object_show(win->frame_obj);
597      }
598    else if (win->img_obj)
599      {
600         evas_object_show(win->img_obj);
601      }
602    evas_object_show(obj);
603 }
604
605 static void
606 _elm_win_obj_callback_move(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
607 {
608    Elm_Win *win = data;
609
610    if (ecore_evas_override_get(win->ee))
611      {
612         Evas_Coord x, y;
613
614         evas_object_geometry_get(obj, &x, &y, NULL, NULL);
615         win->screen.x = x;
616         win->screen.y = y;
617         evas_object_smart_callback_call(win->win_obj, SIG_MOVED, NULL);
618      }
619    if (win->frame_obj)
620      {
621         Evas_Coord x, y;
622
623         evas_object_geometry_get(obj, &x, &y, NULL, NULL);
624         win->screen.x = x;
625         win->screen.y = y;
626      }
627    else if (win->img_obj)
628      {
629         Evas_Coord x, y;
630
631         evas_object_geometry_get(obj, &x, &y, NULL, NULL);
632         win->screen.x = x;
633         win->screen.y = y;
634 //        evas_object_move(win->img_obj, x, y);
635      }
636 }
637
638 static void
639 _elm_win_obj_callback_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
640 {
641    Elm_Win *win = data;
642
643    if (win->frame_obj)
644      {
645      }
646    else if (win->img_obj)
647      {
648         Evas_Coord w = 1, h = 1;
649
650         evas_object_geometry_get(obj, NULL, NULL, &w, &h);
651         if (win->constrain)
652           {
653              int sw, sh;
654              ecore_evas_screen_geometry_get(win->ee, NULL, NULL, &sw, &sh);
655              w = MIN(w, sw);
656              h = MIN(h, sh);
657           }
658         if (w < 1) w = 1;
659         if (h < 1) h = 1;
660         evas_object_image_size_set(win->img_obj, w, h);
661      }
662 }
663
664 static void
665 _elm_win_delete_request(Ecore_Evas *ee)
666 {
667    Evas_Object *obj = ecore_evas_object_associate_get(ee);
668    Elm_Win *win;
669    if (strcmp(elm_widget_type_get(obj), "win")) return;
670
671    win = elm_widget_data_get(obj);
672    if (!win) return;
673    int autodel = win->autodel;
674    win->autodel_clear = &autodel;
675    evas_object_ref(win->win_obj);
676    evas_object_smart_callback_call(win->win_obj, SIG_DELETE_REQUEST, NULL);
677    // FIXME: if above callback deletes - then the below will be invalid
678    if (autodel) evas_object_del(win->win_obj);
679    else win->autodel_clear = NULL;
680    evas_object_unref(win->win_obj);
681 }
682
683 static void
684 _elm_win_resize_job(void *data)
685 {
686    Elm_Win *win = data;
687    const Eina_List *l;
688    Evas_Object *obj;
689    int w, h;
690
691    win->deferred_resize_job = NULL;
692    ecore_evas_request_geometry_get(win->ee, NULL, NULL, &w, &h);
693    if (win->constrain)
694      {
695         int sw, sh;
696         ecore_evas_screen_geometry_get(win->ee, NULL, NULL, &sw, &sh);
697         w = MIN(w, sw);
698         h = MIN(h, sh);
699      }
700    if (win->frame_obj)
701      {
702         evas_object_resize(win->frame_obj, w, h);
703      }
704    else if (win->img_obj)
705      {
706      }
707    evas_object_resize(win->win_obj, w, h);
708    EINA_LIST_FOREACH(win->subobjs, l, obj)
709      {
710         evas_object_move(obj, 0, 0);
711         evas_object_resize(obj, w, h);
712      }
713 }
714
715 #ifdef HAVE_ELEMENTARY_X
716 static void
717 _elm_win_xwindow_get(Elm_Win *win)
718 {
719    win->xwin = 0;
720
721 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
722    if (ENGINE_COMPARE(ELM_SOFTWARE_X11))
723      {
724        if (win->ee) win->xwin = ecore_evas_software_x11_window_get(win->ee);
725      }
726    else if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
727             ENGINE_COMPARE(ELM_SOFTWARE_FB) ||
728             ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE) ||
729             ENGINE_COMPARE(ELM_SOFTWARE_SDL) ||
730             ENGINE_COMPARE(ELM_SOFTWARE_16_SDL) ||
731             ENGINE_COMPARE(ELM_OPENGL_SDL) ||
732             ENGINE_COMPARE(ELM_OPENGL_COCOA))
733      {
734      }
735    else if (ENGINE_COMPARE(ELM_SOFTWARE_16_X11))
736      {
737         if (win->ee) win->xwin = ecore_evas_software_x11_16_window_get(win->ee);
738      }
739    else if (ENGINE_COMPARE(ELM_SOFTWARE_8_X11))
740      {
741         if (win->ee) win->xwin = ecore_evas_software_x11_8_window_get(win->ee);
742      }
743 /* killed
744    else if (ENGINE_COMPARE(ELM_XRENDER_X11))
745      {
746         if (win->ee) win->xwin = ecore_evas_xrender_x11_window_get(win->ee);
747      }
748  */
749    else if (ENGINE_COMPARE(ELM_OPENGL_X11))
750      {
751         if (win->ee) win->xwin = ecore_evas_gl_x11_window_get(win->ee);
752      }
753    else if (ENGINE_COMPARE(ELM_SOFTWARE_WIN32))
754      {
755         if (win->ee) win->xwin = (long)ecore_evas_win32_window_get(win->ee);
756      }
757 #undef ENGINE_COMPARE
758 }
759 #endif
760
761 #ifdef HAVE_ELEMENTARY_X
762 static void
763 _elm_win_xwin_update(Elm_Win *win)
764 {
765    _elm_win_xwindow_get(win);
766    if (win->parent)
767      {
768         Elm_Win *win2;
769
770         win2 = elm_widget_data_get(win->parent);
771         if (win2)
772           {
773              if (win->xwin)
774                ecore_x_icccm_transient_for_set(win->xwin, win2->xwin);
775           }
776      }
777
778    if (!win->xwin) return; /* nothing more to do */
779
780    switch (win->type)
781      {
782       case ELM_WIN_BASIC:
783          ecore_x_netwm_window_type_set(win->xwin, ECORE_X_WINDOW_TYPE_NORMAL);
784          break;
785       case ELM_WIN_DIALOG_BASIC:
786          ecore_x_netwm_window_type_set(win->xwin, ECORE_X_WINDOW_TYPE_DIALOG);
787          break;
788       case ELM_WIN_DESKTOP:
789          ecore_x_netwm_window_type_set(win->xwin, ECORE_X_WINDOW_TYPE_DESKTOP);
790          break;
791       case ELM_WIN_DOCK:
792          ecore_x_netwm_window_type_set(win->xwin, ECORE_X_WINDOW_TYPE_DOCK);
793          break;
794       case ELM_WIN_TOOLBAR:
795          ecore_x_netwm_window_type_set(win->xwin, ECORE_X_WINDOW_TYPE_TOOLBAR);
796          break;
797       case ELM_WIN_MENU:
798          ecore_x_netwm_window_type_set(win->xwin, ECORE_X_WINDOW_TYPE_MENU);
799          break;
800       case ELM_WIN_UTILITY:
801          ecore_x_netwm_window_type_set(win->xwin, ECORE_X_WINDOW_TYPE_UTILITY);
802          break;
803       case ELM_WIN_SPLASH:
804          ecore_x_netwm_window_type_set(win->xwin, ECORE_X_WINDOW_TYPE_SPLASH);
805          break;
806       case ELM_WIN_DROPDOWN_MENU:
807          ecore_x_netwm_window_type_set(win->xwin, ECORE_X_WINDOW_TYPE_DROPDOWN_MENU);
808          break;
809       case ELM_WIN_POPUP_MENU:
810          ecore_x_netwm_window_type_set(win->xwin, ECORE_X_WINDOW_TYPE_POPUP_MENU);
811          break;
812       case ELM_WIN_TOOLTIP:
813          ecore_x_netwm_window_type_set(win->xwin, ECORE_X_WINDOW_TYPE_TOOLTIP);
814          break;
815       case ELM_WIN_NOTIFICATION:
816          ecore_x_netwm_window_type_set(win->xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
817          break;
818       case ELM_WIN_COMBO:
819          ecore_x_netwm_window_type_set(win->xwin, ECORE_X_WINDOW_TYPE_COMBO);
820          break;
821       case ELM_WIN_DND:
822          ecore_x_netwm_window_type_set(win->xwin, ECORE_X_WINDOW_TYPE_DND);
823          break;
824       default:
825          break;
826      }
827    ecore_x_e_virtual_keyboard_state_set
828       (win->xwin, (Ecore_X_Virtual_Keyboard_State)win->kbdmode);
829 }
830 #endif
831
832 static void
833 _elm_win_eval_subobjs(Evas_Object *obj)
834 {
835    const Eina_List *l;
836    const Evas_Object *child;
837
838    Elm_Win *win = elm_widget_data_get(obj);
839    Evas_Coord w, h, minw = -1, minh = -1, maxw = -1, maxh = -1;
840    int xx = 1, xy = 1;
841    double wx, wy;
842
843    EINA_LIST_FOREACH(win->subobjs, l, child)
844      {
845         evas_object_size_hint_weight_get(child, &wx, &wy);
846         if (wx == 0.0) xx = 0;
847         if (wy == 0.0) xy = 0;
848
849         evas_object_size_hint_min_get(child, &w, &h);
850         if (w < 1) w = 1;
851         if (h < 1) h = 1;
852         if (w > minw) minw = w;
853         if (h > minh) minh = h;
854
855         evas_object_size_hint_max_get(child, &w, &h);
856         if (w < 1) w = -1;
857         if (h < 1) h = -1;
858         if (maxw == -1) maxw = w;
859         else if ((w > 0) && (w < maxw)) maxw = w;
860         if (maxh == -1) maxh = h;
861         else if ((h > 0) && (h < maxh)) maxh = h;
862      }
863    if (!xx) maxw = minw;
864    else maxw = 32767;
865    if (!xy) maxh = minh;
866    else maxh = 32767;
867    evas_object_size_hint_min_set(obj, minw, minh);
868    evas_object_size_hint_max_set(obj, maxw, maxh);
869    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
870    if (w < minw) w = minw;
871    if (h < minh) h = minh;
872    if ((maxw >= 0) && (w > maxw)) w = maxw;
873    if ((maxh >= 0) && (h > maxh)) h = maxh;
874    evas_object_resize(obj, w, h);
875 }
876
877 static void
878 _elm_win_subobj_callback_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
879 {
880    Elm_Win *win = elm_widget_data_get(data);
881    win->subobjs = eina_list_remove(win->subobjs, obj);
882    _elm_win_eval_subobjs(win->win_obj);
883 }
884
885 static void
886 _elm_win_subobj_callback_changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
887 {
888    _elm_win_eval_subobjs(data);
889 }
890
891 void
892 _elm_win_shutdown(void)
893 {
894    while (_elm_win_list)
895      evas_object_del(_elm_win_list->data);
896 }
897
898 void
899 _elm_win_rescale(Elm_Theme *th, Eina_Bool use_theme)
900 {
901    const Eina_List *l;
902    Evas_Object *obj;
903
904    if (!use_theme)
905      {
906         EINA_LIST_FOREACH(_elm_win_list, l, obj)
907           elm_widget_theme(obj);
908      }
909    else
910      {
911         EINA_LIST_FOREACH(_elm_win_list, l, obj)
912           elm_widget_theme_specific(obj, th, EINA_FALSE);
913      }
914 }
915
916 void
917 _elm_win_translate(void)
918 {
919    const Eina_List *l;
920    Evas_Object *obj;
921
922    EINA_LIST_FOREACH(_elm_win_list, l, obj)
923       elm_widget_translate(obj);
924 }
925
926 #ifdef HAVE_ELEMENTARY_X
927 static Eina_Bool
928 _elm_win_client_message(void *data, int type __UNUSED__, void *event)
929 {
930    Elm_Win *win = data;
931    Ecore_X_Event_Client_Message *e = event;
932
933    if (e->format != 32) return ECORE_CALLBACK_PASS_ON;
934    if (e->message_type == ECORE_X_ATOM_E_COMP_FLUSH)
935      {
936         if ((unsigned)e->data.l[0] == win->xwin)
937           {
938              Evas *evas = evas_object_evas_get(win->win_obj);
939              if (evas)
940                {
941                   edje_file_cache_flush();
942                   edje_collection_cache_flush();
943                   evas_image_cache_flush(evas);
944                   evas_font_cache_flush(evas);
945                }
946           }
947      }
948    else if (e->message_type == ECORE_X_ATOM_E_COMP_DUMP)
949      {
950         if ((unsigned)e->data.l[0] == win->xwin)
951           {
952              Evas *evas = evas_object_evas_get(win->win_obj);
953              if (evas)
954                {
955                   edje_file_cache_flush();
956                   edje_collection_cache_flush();
957                   evas_image_cache_flush(evas);
958                   evas_font_cache_flush(evas);
959                   evas_render_dump(evas);
960                }
961           }
962      }
963    return ECORE_CALLBACK_PASS_ON;
964 }
965 #endif
966
967 static void
968 _elm_win_focus_target_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
969 {
970    Elm_Win *win = data;
971
972    win->focus_highlight.geometry_changed = EINA_TRUE;
973    _elm_win_focus_highlight_reconfigure_job_start(win);
974 }
975
976 static void
977 _elm_win_focus_target_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
978 {
979    Elm_Win *win = data;
980
981    win->focus_highlight.geometry_changed = EINA_TRUE;
982    _elm_win_focus_highlight_reconfigure_job_start(win);
983 }
984
985 static void
986 _elm_win_focus_target_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
987 {
988    Elm_Win *win = data;
989
990    win->focus_highlight.cur.target = NULL;
991
992    _elm_win_focus_highlight_reconfigure_job_start(win);
993 }
994
995 static void
996 _elm_win_focus_target_callbacks_add(Elm_Win *win)
997 {
998    Evas_Object *obj = win->focus_highlight.cur.target;
999
1000    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
1001                                   _elm_win_focus_target_move, win);
1002    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
1003                                   _elm_win_focus_target_resize, win);
1004    evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
1005                                   _elm_win_focus_target_del, win);
1006 }
1007
1008 static void
1009 _elm_win_focus_target_callbacks_del(Elm_Win *win)
1010 {
1011    Evas_Object *obj = win->focus_highlight.cur.target;
1012
1013    evas_object_event_callback_del_full(obj, EVAS_CALLBACK_MOVE,
1014                                        _elm_win_focus_target_move, win);
1015    evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE,
1016                                        _elm_win_focus_target_resize, win);
1017    evas_object_event_callback_del_full(obj, EVAS_CALLBACK_DEL,
1018                                        _elm_win_focus_target_del, win);
1019 }
1020
1021 static Evas_Object *
1022 _elm_win_focus_target_get(Evas_Object *obj)
1023 {
1024    Evas_Object *o = obj;
1025
1026    do
1027      {
1028         if (elm_widget_is(o))
1029           {
1030              if (!elm_widget_highlight_ignore_get(o))
1031                break;
1032              o = elm_widget_parent_get(o);
1033              if (!o)
1034                o = evas_object_smart_parent_get(o);
1035           }
1036         else
1037           {
1038              o = elm_widget_parent_widget_get(o);
1039              if (!o)
1040                o = evas_object_smart_parent_get(o);
1041           }
1042      }
1043    while (o);
1044
1045    return o;
1046 }
1047
1048 static void
1049 _elm_win_object_focus_in(void *data, Evas *e __UNUSED__, void *event_info)
1050 {
1051    Evas_Object *obj = event_info, *target;
1052    Elm_Win *win = data;
1053
1054    if (win->focus_highlight.cur.target == obj)
1055      return;
1056
1057    target = _elm_win_focus_target_get(obj);
1058    win->focus_highlight.cur.target = target;
1059    if (elm_widget_highlight_in_theme_get(target))
1060      win->focus_highlight.cur.handled = EINA_TRUE;
1061    else
1062      _elm_win_focus_target_callbacks_add(win);
1063
1064    _elm_win_focus_highlight_reconfigure_job_start(win);
1065 }
1066
1067 static void
1068 _elm_win_object_focus_out(void *data, Evas *e __UNUSED__, void *event_info __UNUSED__)
1069 {
1070    Elm_Win *win = data;
1071
1072    if (!win->focus_highlight.cur.target)
1073      return;
1074
1075    if (!win->focus_highlight.cur.handled)
1076      _elm_win_focus_target_callbacks_del(win);
1077    win->focus_highlight.cur.target = NULL;
1078    win->focus_highlight.cur.handled = EINA_FALSE;
1079
1080    _elm_win_focus_highlight_reconfigure_job_start(win);
1081 }
1082
1083 static void
1084 _elm_win_focus_highlight_hide(void *data __UNUSED__, Evas_Object *obj, const char *emission __UNUSED__, const char *source __UNUSED__)
1085 {
1086    evas_object_hide(obj);
1087 }
1088
1089 static void
1090 _elm_win_focus_highlight_init(Elm_Win *win)
1091 {
1092    evas_event_callback_add(win->evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
1093                            _elm_win_object_focus_in, win);
1094    evas_event_callback_add(win->evas,
1095                            EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_OUT,
1096                            _elm_win_object_focus_out, win);
1097
1098    win->focus_highlight.cur.target = evas_focus_get(win->evas);
1099
1100    win->focus_highlight.top = edje_object_add(win->evas);
1101    win->focus_highlight.changed_theme = EINA_TRUE;
1102    edje_object_signal_callback_add(win->focus_highlight.top,
1103                                    "elm,action,focus,hide,end", "",
1104                                    _elm_win_focus_highlight_hide, NULL);
1105    edje_object_signal_callback_add(win->focus_highlight.top,
1106                                    "elm,action,focus,anim,end", "",
1107                                    _elm_win_focus_highlight_anim_end, win);
1108    _elm_win_focus_highlight_reconfigure_job_start(win);
1109 }
1110
1111 static void
1112 _elm_win_focus_highlight_shutdown(Elm_Win *win)
1113 {
1114    _elm_win_focus_highlight_reconfigure_job_stop(win);
1115    if (win->focus_highlight.cur.target)
1116      {
1117         _elm_win_focus_target_callbacks_del(win);
1118         win->focus_highlight.cur.target = NULL;
1119      }
1120    if (win->focus_highlight.top)
1121      {
1122         evas_object_del(win->focus_highlight.top);
1123         win->focus_highlight.top = NULL;
1124      }
1125
1126    evas_event_callback_del_full(win->evas,
1127                                 EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
1128                                 _elm_win_object_focus_in, win);
1129    evas_event_callback_del_full(win->evas,
1130                                 EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_OUT,
1131                                 _elm_win_object_focus_out, win);
1132 }
1133
1134 static void
1135 _elm_win_focus_highlight_visible_set(Elm_Win *win, Eina_Bool visible)
1136 {
1137    Evas_Object *top;
1138
1139    top = win->focus_highlight.top;
1140    if (visible)
1141      {
1142         if (top)
1143           {
1144              evas_object_show(top);
1145              edje_object_signal_emit(top, "elm,action,focus,show", "elm");
1146           }
1147      }
1148    else
1149      {
1150         if (top)
1151           edje_object_signal_emit(top, "elm,action,focus,hide", "elm");
1152      }
1153 }
1154
1155 static void
1156 _elm_win_focus_highlight_reconfigure_job(void *data)
1157 {
1158    _elm_win_focus_highlight_reconfigure((Elm_Win *)data);
1159 }
1160
1161 static void
1162 _elm_win_focus_highlight_reconfigure_job_start(Elm_Win *win)
1163 {
1164    if (win->focus_highlight.reconf_job)
1165      ecore_job_del(win->focus_highlight.reconf_job);
1166    win->focus_highlight.reconf_job = ecore_job_add(
1167       _elm_win_focus_highlight_reconfigure_job, win);
1168 }
1169
1170 static void
1171 _elm_win_focus_highlight_reconfigure_job_stop(Elm_Win *win)
1172 {
1173    if (win->focus_highlight.reconf_job)
1174      ecore_job_del(win->focus_highlight.reconf_job);
1175    win->focus_highlight.reconf_job = NULL;
1176 }
1177
1178 static void
1179 _elm_win_focus_highlight_simple_setup(Elm_Win *win, Evas_Object *obj)
1180 {
1181    Evas_Object *clip, *target = win->focus_highlight.cur.target;
1182    Evas_Coord x, y, w, h;
1183
1184    clip = evas_object_clip_get(target);
1185    evas_object_geometry_get(target, &x, &y, &w, &h);
1186
1187    evas_object_move(obj, x, y);
1188    evas_object_resize(obj, w, h);
1189    evas_object_clip_set(obj, clip);
1190 }
1191
1192 static void
1193 _elm_win_focus_highlight_anim_setup(Elm_Win *win, Evas_Object *obj)
1194 {
1195    Evas_Coord tx, ty, tw, th;
1196    Evas_Coord w, h, px, py, pw, ph;
1197    Edje_Message_Int_Set *m;
1198    Evas_Object *previous = win->focus_highlight.prev.target;
1199    Evas_Object *target = win->focus_highlight.cur.target;
1200
1201    evas_object_geometry_get(win->win_obj, NULL, NULL, &w, &h);
1202    evas_object_geometry_get(target, &tx, &ty, &tw, &th);
1203    evas_object_geometry_get(previous, &px, &py, &pw, &ph);
1204    evas_object_move(obj, 0, 0);
1205    evas_object_resize(obj, tw, th);
1206    evas_object_clip_unset(obj);
1207
1208    m = alloca(sizeof(*m) + (sizeof(int) * 8));
1209    m->count = 8;
1210    m->val[0] = px;
1211    m->val[1] = py;
1212    m->val[2] = pw;
1213    m->val[3] = ph;
1214    m->val[4] = tx;
1215    m->val[5] = ty;
1216    m->val[6] = tw;
1217    m->val[7] = th;
1218    edje_object_message_send(obj, EDJE_MESSAGE_INT_SET, 1, m);
1219 }
1220
1221 static void
1222 _elm_win_focus_highlight_anim_end(void *data, Evas_Object *obj, const char *emission __UNUSED__, const char *source __UNUSED__)
1223 {
1224    Elm_Win *win = data;
1225    _elm_win_focus_highlight_simple_setup(win, obj);
1226 }
1227
1228 static void
1229 _elm_win_focus_highlight_reconfigure(Elm_Win *win)
1230 {
1231    Evas_Object *target = win->focus_highlight.cur.target;
1232    Evas_Object *previous = win->focus_highlight.prev.target;
1233    Evas_Object *top = win->focus_highlight.top;
1234    Eina_Bool visible_changed;
1235    Eina_Bool common_visible;
1236    const char *sig = NULL;
1237
1238    _elm_win_focus_highlight_reconfigure_job_stop(win);
1239
1240    visible_changed = (win->focus_highlight.cur.visible !=
1241                       win->focus_highlight.prev.visible);
1242
1243    if ((target == previous) && (!visible_changed) &&
1244        (!win->focus_highlight.geometry_changed))
1245      return;
1246
1247    if ((previous) && (win->focus_highlight.prev.handled))
1248      elm_widget_signal_emit(previous, "elm,action,focus_highlight,hide", "elm");
1249
1250    if (!target)
1251      common_visible = EINA_FALSE;
1252    else if (win->focus_highlight.cur.handled)
1253      {
1254         common_visible = EINA_FALSE;
1255         if (win->focus_highlight.cur.visible)
1256           sig = "elm,action,focus_highlight,show";
1257         else
1258           sig = "elm,action,focus_highlight,hide";
1259      }
1260    else
1261      common_visible = win->focus_highlight.cur.visible;
1262
1263    _elm_win_focus_highlight_visible_set(win, common_visible);
1264    if (sig)
1265      elm_widget_signal_emit(target, sig, "elm");
1266
1267    if ((!target) || (!common_visible) || (win->focus_highlight.cur.handled))
1268      goto the_end;
1269
1270    if (win->focus_highlight.changed_theme)
1271      {
1272         const char *str;
1273         if (win->focus_highlight.style)
1274           str = win->focus_highlight.style;
1275         else
1276           str = "default";
1277         _elm_theme_object_set(win->win_obj, top, "focus_highlight", "top",
1278                               str);
1279         win->focus_highlight.changed_theme = EINA_FALSE;
1280
1281         if (_elm_config->focus_highlight_animate)
1282           {
1283              str = edje_object_data_get(win->focus_highlight.top, "animate");
1284              win->focus_highlight.top_animate = ((str) && (!strcmp(str, "on")));
1285           }
1286      }
1287
1288    if ((win->focus_highlight.top_animate) && (previous) &&
1289        (!win->focus_highlight.prev.handled))
1290      _elm_win_focus_highlight_anim_setup(win, top);
1291    else
1292      _elm_win_focus_highlight_simple_setup(win, top);
1293    evas_object_raise(top);
1294
1295 the_end:
1296    win->focus_highlight.geometry_changed = EINA_FALSE;
1297    win->focus_highlight.prev = win->focus_highlight.cur;
1298 }
1299
1300 #ifdef ELM_DEBUG
1301 static void
1302 _debug_key_down(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info)
1303 {
1304    Evas_Event_Key_Down *ev = event_info;
1305
1306    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1307      return;
1308
1309
1310    if ((strcmp(ev->keyname, "F12")) ||
1311        (!evas_key_modifier_is_set(ev->modifiers, "Control")))
1312      return;
1313
1314    printf("Tree graph generated.\n");
1315    elm_object_tree_dot_dump(obj, "./dump.dot");
1316 }
1317 #endif
1318
1319 static void
1320 _win_img_hide(void        *data,
1321               Evas        *e __UNUSED__,
1322               Evas_Object *obj __UNUSED__,
1323               void        *event_info __UNUSED__)
1324 {
1325    Elm_Win *win = data;
1326
1327    elm_widget_focus_hide_handle(win->win_obj);
1328 }
1329
1330 static void
1331 _win_img_mouse_up(void        *data,
1332                   Evas        *e __UNUSED__,
1333                   Evas_Object *obj __UNUSED__,
1334                   void        *event_info)
1335 {
1336    Elm_Win *win = data;
1337    Evas_Event_Mouse_Up *ev = event_info;
1338    if (!(ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD))
1339       elm_widget_focus_mouse_up_handle(win->win_obj);
1340 }
1341
1342 static void
1343 _win_img_focus_in(void        *data,
1344                   Evas        *e __UNUSED__,
1345                   Evas_Object *obj __UNUSED__,
1346                   void        *event_info __UNUSED__)
1347 {
1348    Elm_Win *win = data;
1349    elm_widget_focus_steal(win->win_obj);
1350 }
1351
1352 static void
1353 _win_img_focus_out(void        *data,
1354                    Evas        *e __UNUSED__,
1355                    Evas_Object *obj __UNUSED__,
1356                    void        *event_info __UNUSED__)
1357 {
1358    Elm_Win *win = data;
1359    elm_widget_focused_object_clear(win->win_obj);
1360 }
1361
1362 static void
1363 _win_inlined_image_set(Elm_Win *win)
1364 {
1365    evas_object_image_alpha_set(win->img_obj, EINA_FALSE);
1366    evas_object_image_filled_set(win->img_obj, EINA_TRUE);
1367    evas_object_event_callback_add(win->img_obj, EVAS_CALLBACK_DEL,
1368                                   _elm_win_obj_callback_img_obj_del, win);
1369
1370    evas_object_event_callback_add(win->img_obj, EVAS_CALLBACK_HIDE,
1371                                   _win_img_hide, win);
1372    evas_object_event_callback_add(win->img_obj, EVAS_CALLBACK_MOUSE_UP,
1373                                   _win_img_mouse_up, win);
1374    evas_object_event_callback_add(win->img_obj, EVAS_CALLBACK_FOCUS_IN,
1375                                   _win_img_focus_in, win);
1376    evas_object_event_callback_add(win->img_obj, EVAS_CALLBACK_FOCUS_OUT,
1377                                   _win_img_focus_out, win);
1378 }
1379
1380 static void
1381 _subobj_del(Elm_Win *win, Evas_Object *obj, Evas_Object *subobj)
1382 {
1383    evas_object_event_callback_del_full(subobj,
1384                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1385                                        _elm_win_subobj_callback_changed_size_hints,
1386                                        obj);
1387    evas_object_event_callback_del_full(subobj, EVAS_CALLBACK_DEL,
1388                                        _elm_win_subobj_callback_del, obj);
1389    win->subobjs = eina_list_remove(win->subobjs, subobj);
1390    _elm_win_eval_subobjs(obj);
1391 }
1392
1393 EAPI Evas_Object *
1394 elm_win_add(Evas_Object *parent, const char *name, Elm_Win_Type type)
1395 {
1396    Elm_Win *win;
1397    const Eina_List *l;
1398    const char *fontpath;
1399
1400    win = ELM_NEW(Elm_Win);
1401
1402 #define FALLBACK_TRY(engine)                                            \
1403    if (!win->ee)                                                        \
1404       do {                                                              \
1405          CRITICAL(engine " engine creation failed. Trying default.");   \
1406          win->ee = ecore_evas_new(NULL, 0, 0, 1, 1, NULL);              \
1407          if (win->ee)                                                   \
1408             elm_engine_set(ecore_evas_engine_name_get(win->ee));        \
1409    } while (0)
1410 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
1411
1412    switch (type)
1413      {
1414       case ELM_WIN_INLINED_IMAGE:
1415         if (!parent) break;
1416         {
1417            Evas *e = evas_object_evas_get(parent);
1418            Ecore_Evas *ee;
1419            if (!e) break;
1420            ee = ecore_evas_ecore_evas_get(e);
1421            if (!ee) break;
1422            win->img_obj = ecore_evas_object_image_new(ee);
1423            if (!win->img_obj) break;
1424            win->ee = ecore_evas_object_ecore_evas_get(win->img_obj);
1425            if (win->ee)
1426              {
1427                 _win_inlined_image_set(win);
1428                 break;
1429              }
1430            evas_object_del(win->img_obj);
1431            win->img_obj = NULL;
1432         }
1433         break;
1434       default:
1435         if (ENGINE_COMPARE(ELM_SOFTWARE_X11))
1436           {
1437              win->ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
1438 #ifdef HAVE_ELEMENTARY_X
1439              win->client_message_handler = ecore_event_handler_add
1440                 (ECORE_X_EVENT_CLIENT_MESSAGE, _elm_win_client_message, win);
1441 #endif
1442              FALLBACK_TRY("Sofware X11");
1443           }
1444         else if (ENGINE_COMPARE(ELM_SOFTWARE_FB))
1445           {
1446              win->ee = ecore_evas_fb_new(NULL, 0, 1, 1);
1447              FALLBACK_TRY("Sofware FB");
1448           }
1449         else if (ENGINE_COMPARE(ELM_SOFTWARE_DIRECTFB))
1450           {
1451              win->ee = ecore_evas_directfb_new(NULL, 1, 0, 0, 1, 1);
1452              FALLBACK_TRY("Sofware DirectFB");
1453           }
1454         else if (ENGINE_COMPARE(ELM_SOFTWARE_16_X11))
1455           {
1456              win->ee = ecore_evas_software_x11_16_new(NULL, 0, 0, 0, 1, 1);
1457              FALLBACK_TRY("Sofware-16");
1458 #ifdef HAVE_ELEMENTARY_X
1459              win->client_message_handler = ecore_event_handler_add
1460                 (ECORE_X_EVENT_CLIENT_MESSAGE, _elm_win_client_message, win);
1461 #endif
1462      }
1463         else if (ENGINE_COMPARE(ELM_SOFTWARE_8_X11))
1464           {
1465              win->ee = ecore_evas_software_x11_8_new(NULL, 0, 0, 0, 1, 1);
1466              FALLBACK_TRY("Sofware-8");
1467 #ifdef HAVE_ELEMENTARY_X
1468              win->client_message_handler = ecore_event_handler_add
1469                 (ECORE_X_EVENT_CLIENT_MESSAGE, _elm_win_client_message, win);
1470 #endif
1471           }
1472 /* killed
1473         else if (ENGINE_COMPARE(ELM_XRENDER_X11))
1474           {
1475              win->ee = ecore_evas_xrender_x11_new(NULL, 0, 0, 0, 1, 1);
1476              FALLBACK_TRY("XRender");
1477 #ifdef HAVE_ELEMENTARY_X
1478              win->client_message_handler = ecore_event_handler_add
1479                 (ECORE_X_EVENT_CLIENT_MESSAGE, _elm_win_client_message, win);
1480 #endif
1481           }
1482  */
1483         else if (ENGINE_COMPARE(ELM_OPENGL_X11))
1484           {
1485              int opt[10];
1486              int opt_i = 0;
1487
1488              if (_elm_config->vsync)
1489                {
1490                   opt[opt_i] = ECORE_EVAS_GL_X11_OPT_VSYNC;
1491                   opt_i++;
1492                   opt[opt_i] = 1;
1493                   opt_i++;
1494                }
1495              if (opt_i > 0)
1496                 win->ee = ecore_evas_gl_x11_options_new(NULL, 0, 0, 0, 1, 1, opt);
1497              else
1498                 win->ee = ecore_evas_gl_x11_new(NULL, 0, 0, 0, 1, 1);
1499              FALLBACK_TRY("OpenGL");
1500 #ifdef HAVE_ELEMENTARY_X
1501              win->client_message_handler = ecore_event_handler_add
1502                 (ECORE_X_EVENT_CLIENT_MESSAGE, _elm_win_client_message, win);
1503 #endif
1504           }
1505         else if (ENGINE_COMPARE(ELM_SOFTWARE_WIN32))
1506           {
1507              win->ee = ecore_evas_software_gdi_new(NULL, 0, 0, 1, 1);
1508              FALLBACK_TRY("Sofware Win32");
1509           }
1510         else if (ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE))
1511           {
1512              win->ee = ecore_evas_software_wince_gdi_new(NULL, 0, 0, 1, 1);
1513              FALLBACK_TRY("Sofware-16-WinCE");
1514           }
1515         else if (ENGINE_COMPARE(ELM_SOFTWARE_PSL1GHT))
1516           {
1517              win->ee = ecore_evas_psl1ght_new(NULL, 1, 1);
1518              FALLBACK_TRY("PSL1GHT");
1519           }
1520         else if (ENGINE_COMPARE(ELM_SOFTWARE_SDL))
1521           {
1522              win->ee = ecore_evas_sdl_new(NULL, 0, 0, 0, 0, 0, 1);
1523              FALLBACK_TRY("Sofware SDL");
1524           }
1525         else if (ENGINE_COMPARE(ELM_SOFTWARE_16_SDL))
1526           {
1527              win->ee = ecore_evas_sdl16_new(NULL, 0, 0, 0, 0, 0, 1);
1528              FALLBACK_TRY("Sofware-16-SDL");
1529           }
1530         else if (ENGINE_COMPARE(ELM_OPENGL_SDL))
1531           {
1532              win->ee = ecore_evas_gl_sdl_new(NULL, 1, 1, 0, 0);
1533              FALLBACK_TRY("OpenGL SDL");
1534           }
1535         else if (ENGINE_COMPARE(ELM_OPENGL_COCOA))
1536           {
1537              win->ee = ecore_evas_cocoa_new(NULL, 1, 1, 0, 0);
1538              FALLBACK_TRY("OpenGL Cocoa");
1539           }
1540         else if (ENGINE_COMPARE(ELM_BUFFER))
1541           {
1542              win->ee = ecore_evas_buffer_new(1, 1);
1543           }
1544         else if (ENGINE_COMPARE(ELM_EWS))
1545           {
1546              win->ee = ecore_evas_ews_new(0, 0, 1, 1);
1547           }
1548         else if (ENGINE_COMPARE(ELM_WAYLAND_SHM)) 
1549           {
1550              win->ee = ecore_evas_wayland_shm_new(NULL, 0, 0, 1, 1, 0);
1551              win->evas = ecore_evas_get(win->ee);
1552              evas_output_framespace_set(win->evas, 0, 22, 0, 26);
1553
1554              win->frame_obj = edje_object_add(win->evas);
1555              _elm_theme_set(NULL, win->frame_obj, "border", "base", "default");
1556              evas_object_is_frame_object_set(win->frame_obj, EINA_TRUE);
1557              evas_object_move(win->frame_obj, 0, 0);
1558              evas_object_resize(win->frame_obj, 1, 1);
1559           }
1560         else if (!strncmp(_elm_config->engine, "shot:", 5))
1561           {
1562              win->ee = ecore_evas_buffer_new(1, 1);
1563              ecore_evas_manual_render_set(win->ee, EINA_TRUE);
1564              win->shot.info = eina_stringshare_add(_elm_config->engine + 5);
1565              _shot_init(win);
1566           }
1567 #undef FALLBACK_TRY
1568         break;
1569      }
1570
1571    if (!win->ee)
1572      {
1573         ERR("Cannot create window.");
1574         free(win);
1575         return NULL;
1576      }
1577 #ifdef HAVE_ELEMENTARY_X
1578    _elm_win_xwindow_get(win);
1579 #endif
1580    if ((_elm_config->bgpixmap) && (!_elm_config->compositing))
1581      ecore_evas_avoid_damage_set(win->ee, ECORE_EVAS_AVOID_DAMAGE_EXPOSE);
1582    // bg pixmap done by x - has other issues like can be redrawn by x before it
1583    // is filled/ready by app
1584    //     ecore_evas_avoid_damage_set(win->ee, ECORE_EVAS_AVOID_DAMAGE_BUILT_IN);
1585
1586    win->type = type;
1587    win->parent = parent;
1588    if (win->parent)
1589      evas_object_event_callback_add(win->parent, EVAS_CALLBACK_DEL,
1590                                     _elm_win_obj_callback_parent_del, win);
1591
1592    win->evas = ecore_evas_get(win->ee);
1593    win->win_obj = elm_widget_add(win->evas);
1594    elm_widget_type_set(win->win_obj, "win");
1595    ELM_SET_WIDTYPE(widtype, "win");
1596    elm_widget_data_set(win->win_obj, win);
1597    elm_widget_event_hook_set(win->win_obj, _elm_win_event_cb);
1598    elm_widget_on_focus_hook_set(win->win_obj, _elm_win_on_focus_hook, NULL);
1599    elm_widget_can_focus_set(win->win_obj, EINA_TRUE);
1600    elm_widget_highlight_ignore_set(win->win_obj, EINA_TRUE);
1601    elm_widget_focus_next_hook_set(win->win_obj, _elm_win_focus_next_hook);
1602    evas_object_color_set(win->win_obj, 0, 0, 0, 0);
1603    evas_object_move(win->win_obj, 0, 0);
1604    evas_object_resize(win->win_obj, 1, 1);
1605    evas_object_layer_set(win->win_obj, 50);
1606    evas_object_pass_events_set(win->win_obj, EINA_TRUE);
1607
1608    if (win->frame_obj) 
1609      {
1610 //        evas_object_clip_set(win->win_obj, win->frame_obj);
1611         evas_object_stack_below(win->frame_obj, win->win_obj);
1612      }
1613
1614    if (type == ELM_WIN_INLINED_IMAGE)
1615      elm_widget_parent2_set(win->win_obj, parent);
1616    ecore_evas_object_associate(win->ee, win->win_obj,
1617                                ECORE_EVAS_OBJECT_ASSOCIATE_BASE |
1618                                ECORE_EVAS_OBJECT_ASSOCIATE_STACK |
1619                                ECORE_EVAS_OBJECT_ASSOCIATE_LAYER);
1620    evas_object_event_callback_add(win->win_obj, EVAS_CALLBACK_SHOW,
1621                                   _elm_win_obj_callback_show, win);
1622    evas_object_event_callback_add(win->win_obj, EVAS_CALLBACK_HIDE,
1623                                   _elm_win_obj_callback_hide, win);
1624    evas_object_event_callback_add(win->win_obj, EVAS_CALLBACK_DEL,
1625                                   _elm_win_obj_callback_del, win);
1626    evas_object_event_callback_add(win->win_obj, EVAS_CALLBACK_MOVE,
1627                                   _elm_win_obj_callback_move, win);
1628    evas_object_event_callback_add(win->win_obj, EVAS_CALLBACK_RESIZE,
1629                                   _elm_win_obj_callback_resize, win);
1630    if (win->img_obj)
1631      evas_object_intercept_move_callback_add(win->win_obj,
1632                                              _elm_win_obj_intercept_move, win);
1633    evas_object_intercept_show_callback_add(win->win_obj,
1634                                            _elm_win_obj_intercept_show, win);
1635
1636    evas_object_smart_callback_add(win->win_obj, "sub-object-del", (Evas_Smart_Cb)_subobj_del, win);
1637    ecore_evas_name_class_set(win->ee, name, _elm_appname);
1638    ecore_evas_callback_delete_request_set(win->ee, _elm_win_delete_request);
1639    ecore_evas_callback_resize_set(win->ee, _elm_win_resize);
1640    ecore_evas_callback_focus_in_set(win->ee, _elm_win_focus_in);
1641    ecore_evas_callback_focus_out_set(win->ee, _elm_win_focus_out);
1642    ecore_evas_callback_move_set(win->ee, _elm_win_move);
1643    evas_image_cache_set(win->evas, (_elm_config->image_cache * 1024));
1644    evas_font_cache_set(win->evas, (_elm_config->font_cache * 1024));
1645    EINA_LIST_FOREACH(_elm_config->font_dirs, l, fontpath)
1646      evas_font_path_append(win->evas, fontpath);
1647    if (!_elm_config->font_hinting)
1648      evas_font_hinting_set(win->evas, EVAS_FONT_HINTING_NONE);
1649    else if (_elm_config->font_hinting == 1)
1650      evas_font_hinting_set(win->evas, EVAS_FONT_HINTING_AUTO);
1651    else if (_elm_config->font_hinting == 2)
1652      evas_font_hinting_set(win->evas, EVAS_FONT_HINTING_BYTECODE);
1653
1654 #ifdef HAVE_ELEMENTARY_X
1655    _elm_win_xwin_update(win);
1656 #endif
1657
1658    _elm_win_list = eina_list_append(_elm_win_list, win->win_obj);
1659
1660    if (ENGINE_COMPARE(ELM_SOFTWARE_FB))
1661      {
1662         ecore_evas_fullscreen_set(win->ee, 1);
1663      }
1664 #undef ENGINE_COMPARE
1665
1666    if (_elm_config->focus_highlight_enable)
1667      elm_win_focus_highlight_enabled_set(win->win_obj, EINA_TRUE);
1668
1669 #ifdef ELM_DEBUG
1670    Evas_Modifier_Mask mask = evas_key_modifier_mask_get(win->evas, "Control");
1671    evas_object_event_callback_add(win->win_obj, EVAS_CALLBACK_KEY_DOWN,
1672                                   _debug_key_down, win);
1673
1674    Eina_Bool ret = evas_object_key_grab(win->win_obj, "F12", mask, 0,
1675                                         EINA_TRUE);
1676    printf("Ctrl+F12 key combination exclusive for dot tree generation\n");
1677 #endif
1678
1679    evas_object_smart_callbacks_descriptions_set(win->win_obj, _signals);
1680
1681    return win->win_obj;
1682 }
1683
1684 EAPI Evas_Object *
1685 elm_win_util_standard_add(const char *name, const char *title)
1686 {
1687    Evas_Object *win, *bg;
1688
1689    win = elm_win_add(NULL, name, ELM_WIN_BASIC);
1690    if (!win) return NULL;
1691    elm_win_title_set(win, title);
1692    bg = elm_bg_add(win);
1693    if (!bg)
1694      {
1695         evas_object_del(win);
1696         return NULL;
1697      }
1698    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1699    elm_win_resize_object_add(win, bg);
1700    evas_object_show(bg);
1701    return win;
1702 }
1703
1704 EAPI void
1705 elm_win_resize_object_add(Evas_Object *obj, Evas_Object *subobj)
1706 {
1707    Evas_Coord w, h;
1708    Elm_Win *win;
1709    ELM_CHECK_WIDTYPE(obj, widtype);
1710    win = elm_widget_data_get(obj);
1711    if (!win) return;
1712    if (eina_list_data_find(win->subobjs, subobj)) return;
1713    win->subobjs = eina_list_append(win->subobjs, subobj);
1714    elm_widget_sub_object_add(obj, subobj);
1715    evas_object_event_callback_add(subobj, EVAS_CALLBACK_DEL,
1716                                   _elm_win_subobj_callback_del, obj);
1717    evas_object_event_callback_add(subobj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1718                                   _elm_win_subobj_callback_changed_size_hints,
1719                                   obj);
1720    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
1721    evas_object_move(subobj, 0, 0);
1722    evas_object_resize(subobj, w, h);
1723    _elm_win_eval_subobjs(obj);
1724 }
1725
1726 EAPI void
1727 elm_win_resize_object_del(Evas_Object *obj, Evas_Object *subobj)
1728 {
1729    Elm_Win *win;
1730    ELM_CHECK_WIDTYPE(obj, widtype);
1731    win = elm_widget_data_get(obj);
1732    if (!win) return;
1733    evas_object_event_callback_del_full(subobj,
1734                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1735                                        _elm_win_subobj_callback_changed_size_hints,
1736                                        obj);
1737    evas_object_event_callback_del_full(subobj, EVAS_CALLBACK_DEL,
1738                                        _elm_win_subobj_callback_del, obj);
1739    win->subobjs = eina_list_remove(win->subobjs, subobj);
1740    elm_widget_sub_object_del(obj, subobj);
1741    _elm_win_eval_subobjs(obj);
1742 }
1743
1744 EAPI void
1745 elm_win_title_set(Evas_Object *obj, const char *title)
1746 {
1747    Elm_Win *win;
1748    ELM_CHECK_WIDTYPE(obj, widtype);
1749    win = elm_widget_data_get(obj);
1750    if (!win) return;
1751    ecore_evas_title_set(win->ee, title);
1752    if (win->frame_obj)
1753      edje_object_part_text_set(win->frame_obj, "elm.text.title", title);
1754 }
1755
1756 EAPI const char *
1757 elm_win_title_get(const Evas_Object *obj)
1758 {
1759    Elm_Win *win;
1760    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1761    win = elm_widget_data_get(obj);
1762    if (!win) return NULL;
1763    return ecore_evas_title_get(win->ee);
1764 }
1765
1766 EAPI void
1767 elm_win_autodel_set(Evas_Object *obj, Eina_Bool autodel)
1768 {
1769    Elm_Win *win;
1770    ELM_CHECK_WIDTYPE(obj, widtype);
1771    win = elm_widget_data_get(obj);
1772    if (!win) return;
1773    win->autodel = autodel;
1774 }
1775
1776 EAPI Eina_Bool
1777 elm_win_autodel_get(const Evas_Object *obj)
1778 {
1779    Elm_Win *win;
1780    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1781    win = elm_widget_data_get(obj);
1782    if (!win) return EINA_FALSE;
1783    return win->autodel;
1784 }
1785
1786 EAPI void
1787 elm_win_activate(Evas_Object *obj)
1788 {
1789    Elm_Win *win;
1790    ELM_CHECK_WIDTYPE(obj, widtype);
1791    win = elm_widget_data_get(obj);
1792    if (!win) return;
1793    ecore_evas_activate(win->ee);
1794 }
1795
1796 EAPI void
1797 elm_win_lower(Evas_Object *obj)
1798 {
1799    Elm_Win *win;
1800    ELM_CHECK_WIDTYPE(obj, widtype);
1801    win = elm_widget_data_get(obj);
1802    if (!win) return;
1803    ecore_evas_lower(win->ee);
1804 }
1805
1806 EAPI void
1807 elm_win_raise(Evas_Object *obj)
1808 {
1809    Elm_Win *win;
1810    ELM_CHECK_WIDTYPE(obj, widtype);
1811    win = elm_widget_data_get(obj);
1812    if (!win) return;
1813    ecore_evas_raise(win->ee);
1814 }
1815
1816 EAPI void
1817 elm_win_center(Evas_Object *obj, Eina_Bool h, Eina_Bool v)
1818 {
1819    Elm_Win *win;
1820    int win_w, win_h, screen_w, screen_h, nx, ny;
1821    ELM_CHECK_WIDTYPE(obj, widtype);
1822    win = elm_widget_data_get(obj);
1823    if (!win) return;
1824    ecore_evas_screen_geometry_get(win->ee, NULL, NULL, &screen_w, &screen_h);
1825    if ((!screen_w) || (!screen_h)) return;
1826    evas_object_geometry_get(obj, NULL, NULL, &win_w, &win_h);
1827    if ((!win_w) || (!win_h)) return;
1828    if (h) nx = win_w >= screen_w ? 0 : (screen_w / 2) - (win_w / 2);
1829    else nx = win->screen.x;
1830    if (v) ny = win_h >= screen_h ? 0 : (screen_h / 2) - (win_h / 2);
1831    else ny = win->screen.y;
1832    if (nx < 0) nx = 0;
1833    if (ny < 0) ny = 0;
1834    evas_object_move(obj, nx, ny);
1835 }
1836
1837 EAPI void
1838 elm_win_borderless_set(Evas_Object *obj, Eina_Bool borderless)
1839 {
1840    Elm_Win *win;
1841    ELM_CHECK_WIDTYPE(obj, widtype);
1842    win = elm_widget_data_get(obj);
1843    if (!win) return;
1844    ecore_evas_borderless_set(win->ee, borderless);
1845 #ifdef HAVE_ELEMENTARY_X
1846    _elm_win_xwin_update(win);
1847 #endif
1848 }
1849
1850 EAPI Eina_Bool
1851 elm_win_borderless_get(const Evas_Object *obj)
1852 {
1853    Elm_Win *win;
1854    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1855    win = elm_widget_data_get(obj);
1856    if (!win) return EINA_FALSE;
1857    return ecore_evas_borderless_get(win->ee);
1858 }
1859
1860 EAPI void
1861 elm_win_shaped_set(Evas_Object *obj, Eina_Bool shaped)
1862 {
1863    Elm_Win *win;
1864    ELM_CHECK_WIDTYPE(obj, widtype);
1865    win = elm_widget_data_get(obj);
1866    if (!win) return;
1867    ecore_evas_shaped_set(win->ee, shaped);
1868 #ifdef HAVE_ELEMENTARY_X
1869    _elm_win_xwin_update(win);
1870 #endif
1871 }
1872
1873 EAPI Eina_Bool
1874 elm_win_shaped_get(const Evas_Object *obj)
1875 {
1876    Elm_Win *win;
1877    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1878    win = elm_widget_data_get(obj);
1879    if (!win) return EINA_FALSE;
1880    return ecore_evas_shaped_get(win->ee);
1881 }
1882
1883 EAPI void
1884 elm_win_alpha_set(Evas_Object *obj, Eina_Bool alpha)
1885 {
1886    Elm_Win *win;
1887    ELM_CHECK_WIDTYPE(obj, widtype);
1888    win = elm_widget_data_get(obj);
1889    if (!win) return;
1890    if (win->frame_obj)
1891      {
1892      }
1893    else if (win->img_obj)
1894      {
1895         evas_object_image_alpha_set(win->img_obj, alpha);
1896         ecore_evas_alpha_set(win->ee, alpha);
1897      }
1898    else
1899      {
1900 #ifdef HAVE_ELEMENTARY_X
1901         if (win->xwin)
1902           {
1903              if (alpha)
1904                {
1905                   if (!_elm_config->compositing)
1906                      elm_win_shaped_set(obj, alpha);
1907                   else
1908                      ecore_evas_alpha_set(win->ee, alpha);
1909                }
1910              else
1911                 ecore_evas_alpha_set(win->ee, alpha);
1912              _elm_win_xwin_update(win);
1913           }
1914         else
1915 #endif
1916            ecore_evas_alpha_set(win->ee, alpha);
1917      }
1918 }
1919
1920 EAPI Eina_Bool
1921 elm_win_alpha_get(const Evas_Object *obj)
1922 {
1923    Elm_Win *win;
1924    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1925    win = elm_widget_data_get(obj);
1926    if (!win) return EINA_FALSE;
1927    if (win->frame_obj)
1928      {
1929      }
1930    else if (win->img_obj)
1931      {
1932         return evas_object_image_alpha_get(win->img_obj);
1933      }
1934    return ecore_evas_alpha_get(win->ee);
1935 }
1936
1937 EAPI void
1938 elm_win_transparent_set(Evas_Object *obj, Eina_Bool transparent)
1939 {
1940    Elm_Win *win;
1941    ELM_CHECK_WIDTYPE(obj, widtype);
1942    win = elm_widget_data_get(obj);
1943    if (!win) return;
1944
1945    if (win->frame_obj)
1946      {
1947      }
1948    else if (win->img_obj)
1949      {
1950         evas_object_image_alpha_set(win->img_obj, transparent);
1951      }
1952    else
1953      {
1954 #ifdef HAVE_ELEMENTARY_X
1955         if (win->xwin)
1956           {
1957              ecore_evas_transparent_set(win->ee, transparent);
1958              _elm_win_xwin_update(win);
1959           }
1960         else
1961 #endif
1962            ecore_evas_transparent_set(win->ee, transparent);
1963      }
1964 }
1965
1966 EAPI Eina_Bool
1967 elm_win_transparent_get(const Evas_Object *obj)
1968 {
1969    Elm_Win *win;
1970    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1971    win = elm_widget_data_get(obj);
1972    if (!win) return EINA_FALSE;
1973
1974    return ecore_evas_transparent_get(win->ee);
1975 }
1976
1977 EAPI void
1978 elm_win_override_set(Evas_Object *obj, Eina_Bool override)
1979 {
1980    Elm_Win *win;
1981    ELM_CHECK_WIDTYPE(obj, widtype);
1982    win = elm_widget_data_get(obj);
1983    if (!win) return;
1984    ecore_evas_override_set(win->ee, override);
1985 #ifdef HAVE_ELEMENTARY_X
1986    _elm_win_xwin_update(win);
1987 #endif
1988 }
1989
1990 EAPI Eina_Bool
1991 elm_win_override_get(const Evas_Object *obj)
1992 {
1993    Elm_Win *win;
1994    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1995    win = elm_widget_data_get(obj);
1996    if (!win) return EINA_FALSE;
1997    return ecore_evas_override_get(win->ee);
1998 }
1999
2000 EAPI void
2001 elm_win_fullscreen_set(Evas_Object *obj, Eina_Bool fullscreen)
2002 {
2003    Elm_Win *win;
2004    ELM_CHECK_WIDTYPE(obj, widtype);
2005    win = elm_widget_data_get(obj);
2006    if (!win) return;
2007
2008    // YYY: handle if win->img_obj
2009 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
2010    if (ENGINE_COMPARE(ELM_SOFTWARE_FB) ||
2011        ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE))
2012      {
2013         // these engines... can ONLY be fullscreen
2014         return;
2015      }
2016    else
2017      {
2018         ecore_evas_fullscreen_set(win->ee, fullscreen);
2019 #ifdef HAVE_ELEMENTARY_X
2020         _elm_win_xwin_update(win);
2021 #endif
2022      }
2023 #undef ENGINE_COMPARE
2024 }
2025
2026 EAPI Eina_Bool
2027 elm_win_fullscreen_get(const Evas_Object *obj)
2028 {
2029    Elm_Win *win;
2030    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2031    win = elm_widget_data_get(obj);
2032    if (!win) return EINA_FALSE;
2033
2034 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
2035    if (ENGINE_COMPARE(ELM_SOFTWARE_FB) ||
2036        ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE))
2037      {
2038         // these engines... can ONLY be fullscreen
2039         return EINA_TRUE;
2040      }
2041    else
2042      {
2043         return ecore_evas_fullscreen_get(win->ee);
2044      }
2045 #undef ENGINE_COMPARE
2046 }
2047
2048 EAPI void
2049 elm_win_maximized_set(Evas_Object *obj, Eina_Bool maximized)
2050 {
2051    Elm_Win *win;
2052    ELM_CHECK_WIDTYPE(obj, widtype);
2053    win = elm_widget_data_get(obj);
2054    if (!win) return;
2055    // YYY: handle if win->img_obj
2056    ecore_evas_maximized_set(win->ee, maximized);
2057 #ifdef HAVE_ELEMENTARY_X
2058    _elm_win_xwin_update(win);
2059 #endif
2060 }
2061
2062 EAPI Eina_Bool
2063 elm_win_maximized_get(const Evas_Object *obj)
2064 {
2065    Elm_Win *win;
2066    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2067    win = elm_widget_data_get(obj);
2068    if (!win) return EINA_FALSE;
2069    return ecore_evas_maximized_get(win->ee);
2070 }
2071
2072 EAPI void
2073 elm_win_iconified_set(Evas_Object *obj, Eina_Bool iconified)
2074 {
2075    Elm_Win *win;
2076    ELM_CHECK_WIDTYPE(obj, widtype);
2077    win = elm_widget_data_get(obj);
2078    if (!win) return;
2079    ecore_evas_iconified_set(win->ee, iconified);
2080 #ifdef HAVE_ELEMENTARY_X
2081    _elm_win_xwin_update(win);
2082 #endif
2083 }
2084
2085 EAPI Eina_Bool
2086 elm_win_iconified_get(const Evas_Object *obj)
2087 {
2088    Elm_Win *win;
2089    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2090    win = elm_widget_data_get(obj);
2091    if (!win) return EINA_FALSE;
2092    return ecore_evas_iconified_get(win->ee);
2093 }
2094
2095 EAPI void
2096 elm_win_layer_set(Evas_Object *obj, int layer)
2097 {
2098    Elm_Win *win;
2099    ELM_CHECK_WIDTYPE(obj, widtype);
2100    win = elm_widget_data_get(obj);
2101    if (!win) return;
2102    ecore_evas_layer_set(win->ee, layer);
2103 #ifdef HAVE_ELEMENTARY_X
2104    _elm_win_xwin_update(win);
2105 #endif
2106 }
2107
2108 EAPI int
2109 elm_win_layer_get(const Evas_Object *obj)
2110 {
2111    Elm_Win *win;
2112    ELM_CHECK_WIDTYPE(obj, widtype) -1;
2113    win = elm_widget_data_get(obj);
2114    if (!win) return -1;
2115    return ecore_evas_layer_get(win->ee);
2116 }
2117
2118 EAPI void
2119 elm_win_rotation_set(Evas_Object *obj, int rotation)
2120 {
2121    Elm_Win *win;
2122    ELM_CHECK_WIDTYPE(obj, widtype);
2123    win = elm_widget_data_get(obj);
2124    if (!win) return;
2125    if (win->rot == rotation) return;
2126    win->rot = rotation;
2127    ecore_evas_rotation_set(win->ee, rotation);
2128    evas_object_size_hint_min_set(obj, -1, -1);
2129    evas_object_size_hint_max_set(obj, -1, -1);
2130    _elm_win_eval_subobjs(obj);
2131 #ifdef HAVE_ELEMENTARY_X
2132    _elm_win_xwin_update(win);
2133 #endif
2134 }
2135
2136 EAPI void
2137 elm_win_rotation_with_resize_set(Evas_Object *obj, int rotation)
2138 {
2139    Elm_Win *win;
2140    ELM_CHECK_WIDTYPE(obj, widtype);
2141    win = elm_widget_data_get(obj);
2142    if (!win) return;
2143    if (win->rot == rotation) return;
2144    win->rot = rotation;
2145    ecore_evas_rotation_with_resize_set(win->ee, rotation);
2146    evas_object_size_hint_min_set(obj, -1, -1);
2147    evas_object_size_hint_max_set(obj, -1, -1);
2148    _elm_win_eval_subobjs(obj);
2149 #ifdef HAVE_ELEMENTARY_X
2150    _elm_win_xwin_update(win);
2151 #endif
2152 }
2153
2154 EAPI int
2155 elm_win_rotation_get(const Evas_Object *obj)
2156 {
2157    Elm_Win *win;
2158    ELM_CHECK_WIDTYPE(obj, widtype) -1;
2159    win = elm_widget_data_get(obj);
2160    if (!win) return -1;
2161    return win->rot;
2162 }
2163
2164 EAPI void
2165 elm_win_sticky_set(Evas_Object *obj, Eina_Bool sticky)
2166 {
2167    Elm_Win *win;
2168    ELM_CHECK_WIDTYPE(obj, widtype);
2169    win = elm_widget_data_get(obj);
2170    if (!win) return;
2171    ecore_evas_sticky_set(win->ee, sticky);
2172 #ifdef HAVE_ELEMENTARY_X
2173    _elm_win_xwin_update(win);
2174 #endif
2175 }
2176
2177 EAPI Eina_Bool
2178 elm_win_sticky_get(const Evas_Object *obj)
2179 {
2180    Elm_Win *win;
2181    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2182    win = elm_widget_data_get(obj);
2183    if (!win) return EINA_FALSE;
2184    return ecore_evas_sticky_get(win->ee);
2185 }
2186
2187 EAPI void
2188 elm_win_keyboard_mode_set(Evas_Object *obj, Elm_Win_Keyboard_Mode mode)
2189 {
2190    Elm_Win *win;
2191    ELM_CHECK_WIDTYPE(obj, widtype);
2192    win = elm_widget_data_get(obj);
2193    if (!win) return;
2194    if (mode == win->kbdmode) return;
2195 #ifdef HAVE_ELEMENTARY_X
2196    _elm_win_xwindow_get(win);
2197 #endif
2198    win->kbdmode = mode;
2199 #ifdef HAVE_ELEMENTARY_X
2200    if (win->xwin)
2201      ecore_x_e_virtual_keyboard_state_set
2202         (win->xwin, (Ecore_X_Virtual_Keyboard_State)win->kbdmode);
2203 #endif
2204 }
2205
2206 EAPI Elm_Win_Keyboard_Mode
2207 elm_win_keyboard_mode_get(const Evas_Object *obj)
2208 {
2209    Elm_Win *win;
2210    ELM_CHECK_WIDTYPE(obj, widtype) ELM_WIN_KEYBOARD_UNKNOWN;
2211    win = elm_widget_data_get(obj);
2212    if (!win) return ELM_WIN_KEYBOARD_UNKNOWN;
2213    return win->kbdmode;
2214 }
2215
2216 EAPI void
2217 elm_win_keyboard_win_set(Evas_Object *obj, Eina_Bool is_keyboard)
2218 {
2219    Elm_Win *win;
2220    ELM_CHECK_WIDTYPE(obj, widtype);
2221    win = elm_widget_data_get(obj);
2222    if (!win) return;
2223 #ifdef HAVE_ELEMENTARY_X
2224    _elm_win_xwindow_get(win);
2225    if (win->xwin)
2226      ecore_x_e_virtual_keyboard_set(win->xwin, is_keyboard);
2227 #else
2228    (void) is_keyboard;
2229 #endif
2230 }
2231
2232 EAPI Eina_Bool
2233 elm_win_keyboard_win_get(const Evas_Object *obj)
2234 {
2235    Elm_Win *win;
2236    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2237    win = elm_widget_data_get(obj);
2238    if (!win) return EINA_FALSE;
2239 #ifdef HAVE_ELEMENTARY_X
2240    _elm_win_xwindow_get(win);
2241    if (win->xwin)
2242      return ecore_x_e_virtual_keyboard_get(win->xwin);
2243 #endif
2244    return EINA_FALSE;
2245 }
2246
2247 EAPI void
2248 elm_win_screen_position_get(const Evas_Object *obj, int *x, int *y)
2249 {
2250    Elm_Win *win;
2251    ELM_CHECK_WIDTYPE(obj, widtype);
2252    win = elm_widget_data_get(obj);
2253    if (!win) return;
2254    if (x) *x = win->screen.x;
2255    if (y) *y = win->screen.y;
2256 }
2257
2258 EAPI Eina_Bool
2259 elm_win_focus_get(const Evas_Object *obj)
2260 {
2261    Elm_Win *win;
2262    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2263    win = elm_widget_data_get(obj);
2264    if (!win) return EINA_FALSE;
2265    return ecore_evas_focus_get(win->ee);
2266 }
2267
2268 EAPI void
2269 elm_win_screen_constrain_set(Evas_Object *obj, Eina_Bool constrain)
2270 {
2271    Elm_Win *win;
2272    ELM_CHECK_WIDTYPE(obj, widtype);
2273    win = elm_widget_data_get(obj);
2274    if (!win) return;
2275    win->constrain = !!constrain;
2276 }
2277
2278 EAPI Eina_Bool
2279 elm_win_screen_constrain_get(Evas_Object *obj)
2280 {
2281    Elm_Win *win;
2282    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2283    win = elm_widget_data_get(obj);
2284    if (!win) return EINA_FALSE;
2285    return win->constrain;
2286 }
2287
2288 EAPI void
2289 elm_win_screen_size_get(const Evas_Object *obj, int *x, int *y, int *w, int *h)
2290 {
2291    Elm_Win *win;
2292    ELM_CHECK_WIDTYPE(obj, widtype);
2293    win = elm_widget_data_get(obj);
2294    if (!win) return;
2295    ecore_evas_screen_geometry_get(win->ee, x, y, w, h);
2296 }
2297
2298 EAPI void
2299 elm_win_conformant_set(Evas_Object *obj, Eina_Bool conformant)
2300 {
2301    Elm_Win *win;
2302    ELM_CHECK_WIDTYPE(obj, widtype);
2303    win = elm_widget_data_get(obj);
2304    if (!win) return;
2305 #ifdef HAVE_ELEMENTARY_X
2306    _elm_win_xwindow_get(win);
2307    if (win->xwin)
2308      ecore_x_e_illume_conformant_set(win->xwin, conformant);
2309 #else
2310    (void) conformant;
2311 #endif
2312 }
2313
2314 EAPI Eina_Bool
2315 elm_win_conformant_get(const Evas_Object *obj)
2316 {
2317    Elm_Win *win;
2318    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2319    win = elm_widget_data_get(obj);
2320    if (!win) return EINA_FALSE;
2321 #ifdef HAVE_ELEMENTARY_X
2322    _elm_win_xwindow_get(win);
2323    if (win->xwin)
2324      return ecore_x_e_illume_conformant_get(win->xwin);
2325 #endif
2326    return EINA_FALSE;
2327 }
2328
2329 EAPI void
2330 elm_win_quickpanel_set(Evas_Object *obj, Eina_Bool quickpanel)
2331 {
2332    Elm_Win *win;
2333    ELM_CHECK_WIDTYPE(obj, widtype);
2334    win = elm_widget_data_get(obj);
2335    if (!win) return;
2336 #ifdef HAVE_ELEMENTARY_X
2337    _elm_win_xwindow_get(win);
2338    if (win->xwin)
2339      {
2340         ecore_x_e_illume_quickpanel_set(win->xwin, quickpanel);
2341         if (quickpanel)
2342           {
2343              Ecore_X_Window_State states[2];
2344
2345              states[0] = ECORE_X_WINDOW_STATE_SKIP_TASKBAR;
2346              states[1] = ECORE_X_WINDOW_STATE_SKIP_PAGER;
2347              ecore_x_netwm_window_state_set(win->xwin, states, 2);
2348              ecore_x_icccm_hints_set(win->xwin, 0, 0, 0, 0, 0, 0, 0);
2349           }
2350      }
2351 #else
2352    (void) quickpanel;
2353 #endif
2354 }
2355
2356 EAPI Eina_Bool
2357 elm_win_quickpanel_get(const Evas_Object *obj)
2358 {
2359    Elm_Win *win;
2360    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2361    win = elm_widget_data_get(obj);
2362    if (!win) return EINA_FALSE;
2363 #ifdef HAVE_ELEMENTARY_X
2364    _elm_win_xwindow_get(win);
2365    if (win->xwin)
2366      return ecore_x_e_illume_quickpanel_get(win->xwin);
2367 #endif
2368    return EINA_FALSE;
2369 }
2370
2371 EAPI void
2372 elm_win_quickpanel_priority_major_set(Evas_Object *obj, int priority)
2373 {
2374    Elm_Win *win;
2375    ELM_CHECK_WIDTYPE(obj, widtype);
2376    win = elm_widget_data_get(obj);
2377    if (!win) return;
2378 #ifdef HAVE_ELEMENTARY_X
2379    _elm_win_xwindow_get(win);
2380    if (win->xwin)
2381      ecore_x_e_illume_quickpanel_priority_major_set(win->xwin, priority);
2382 #else
2383    (void) priority;
2384 #endif
2385 }
2386
2387 EAPI int
2388 elm_win_quickpanel_priority_major_get(const Evas_Object *obj)
2389 {
2390    Elm_Win *win;
2391    ELM_CHECK_WIDTYPE(obj, widtype) -1;
2392    win = elm_widget_data_get(obj);
2393    if (!win) return -1;
2394 #ifdef HAVE_ELEMENTARY_X
2395    _elm_win_xwindow_get(win);
2396    if (win->xwin)
2397      return ecore_x_e_illume_quickpanel_priority_major_get(win->xwin);
2398 #endif
2399    return -1;
2400 }
2401
2402 EAPI void
2403 elm_win_quickpanel_priority_minor_set(Evas_Object *obj, int priority)
2404 {
2405    Elm_Win *win;
2406    ELM_CHECK_WIDTYPE(obj, widtype);
2407    win = elm_widget_data_get(obj);
2408    if (!win) return;
2409 #ifdef HAVE_ELEMENTARY_X
2410    _elm_win_xwindow_get(win);
2411    if (win->xwin)
2412      ecore_x_e_illume_quickpanel_priority_minor_set(win->xwin, priority);
2413 #else
2414    (void) priority;
2415 #endif
2416 }
2417
2418 EAPI int
2419 elm_win_quickpanel_priority_minor_get(const Evas_Object *obj)
2420 {
2421    Elm_Win *win;
2422    ELM_CHECK_WIDTYPE(obj, widtype) -1;
2423    win = elm_widget_data_get(obj);
2424    if (!win) return -1;
2425 #ifdef HAVE_ELEMENTARY_X
2426    _elm_win_xwindow_get(win);
2427    if (win->xwin)
2428      return ecore_x_e_illume_quickpanel_priority_minor_get(win->xwin);
2429 #endif
2430    return -1;
2431 }
2432
2433 EAPI void
2434 elm_win_quickpanel_zone_set(Evas_Object *obj, int zone)
2435 {
2436    Elm_Win *win;
2437    ELM_CHECK_WIDTYPE(obj, widtype);
2438    win = elm_widget_data_get(obj);
2439    if (!win) return;
2440 #ifdef HAVE_ELEMENTARY_X
2441    _elm_win_xwindow_get(win);
2442    if (win->xwin)
2443      ecore_x_e_illume_quickpanel_zone_set(win->xwin, zone);
2444 #else
2445    (void) zone;
2446 #endif
2447 }
2448
2449 EAPI int
2450 elm_win_quickpanel_zone_get(const Evas_Object *obj)
2451 {
2452    Elm_Win *win;
2453    ELM_CHECK_WIDTYPE(obj, widtype) 0;
2454    win = elm_widget_data_get(obj);
2455    if (!win) return 0;
2456 #ifdef HAVE_ELEMENTARY_X
2457    _elm_win_xwindow_get(win);
2458    if (win->xwin)
2459      return ecore_x_e_illume_quickpanel_zone_get(win->xwin);
2460 #endif
2461    return 0;
2462 }
2463
2464 EAPI void
2465 elm_win_prop_focus_skip_set(Evas_Object *obj, Eina_Bool skip)
2466 {
2467    Elm_Win *win;
2468    ELM_CHECK_WIDTYPE(obj, widtype);
2469    win = elm_widget_data_get(obj);
2470    if (!win) return;
2471 #ifdef HAVE_ELEMENTARY_X
2472    _elm_win_xwindow_get(win);
2473    if (skip)
2474      {
2475         if (win->xwin)
2476           {
2477              Ecore_X_Window_State states[2];
2478
2479              ecore_x_icccm_hints_set(win->xwin, 0, 0, 0, 0, 0, 0, 0);
2480              states[0] = ECORE_X_WINDOW_STATE_SKIP_TASKBAR;
2481              states[1] = ECORE_X_WINDOW_STATE_SKIP_PAGER;
2482              ecore_x_netwm_window_state_set(win->xwin, states, 2);
2483           }
2484      }
2485 #else
2486    (void) skip;
2487 #endif
2488 }
2489
2490 EAPI void
2491 elm_win_illume_command_send(Evas_Object *obj, Elm_Illume_Command command, void *params __UNUSED__)
2492 {
2493    Elm_Win *win;
2494    ELM_CHECK_WIDTYPE(obj, widtype);
2495    win = elm_widget_data_get(obj);
2496    if (!win) return;
2497 #ifdef HAVE_ELEMENTARY_X
2498    _elm_win_xwindow_get(win);
2499    if (win->xwin)
2500      {
2501         switch (command)
2502           {
2503            case ELM_ILLUME_COMMAND_FOCUS_BACK:
2504               ecore_x_e_illume_focus_back_send(win->xwin);
2505               break;
2506            case ELM_ILLUME_COMMAND_FOCUS_FORWARD:
2507               ecore_x_e_illume_focus_forward_send(win->xwin);
2508               break;
2509            case ELM_ILLUME_COMMAND_FOCUS_HOME:
2510               ecore_x_e_illume_focus_home_send(win->xwin);
2511               break;
2512            case ELM_ILLUME_COMMAND_CLOSE:
2513               ecore_x_e_illume_close_send(win->xwin);
2514               break;
2515            default:
2516               break;
2517           }
2518      }
2519 #else
2520    (void) command;
2521 #endif
2522 }
2523
2524 EAPI Evas_Object *
2525 elm_win_inlined_image_object_get(Evas_Object *obj)
2526 {
2527    Elm_Win *win;
2528    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2529    win = elm_widget_data_get(obj);
2530    if (!win) return NULL;
2531    return win->img_obj;
2532 }
2533
2534 EAPI void
2535 elm_win_focus_highlight_enabled_set(Evas_Object *obj, Eina_Bool enabled)
2536 {
2537    Elm_Win *win;
2538
2539    ELM_CHECK_WIDTYPE(obj, widtype);
2540
2541    win = elm_widget_data_get(obj);
2542    enabled = !!enabled;
2543    if (win->focus_highlight.enabled == enabled)
2544      return;
2545
2546    win->focus_highlight.enabled = enabled;
2547
2548    if (win->focus_highlight.enabled)
2549      _elm_win_focus_highlight_init(win);
2550    else
2551      _elm_win_focus_highlight_shutdown(win);
2552 }
2553
2554 EAPI Eina_Bool
2555 elm_win_focus_highlight_enabled_get(const Evas_Object *obj)
2556 {
2557    Elm_Win *win;
2558
2559    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2560
2561    win = elm_widget_data_get(obj);
2562    return win->focus_highlight.enabled;
2563 }
2564
2565 EAPI void
2566 elm_win_focus_highlight_style_set(Evas_Object *obj, const char *style)
2567 {
2568    Elm_Win *win;
2569
2570    ELM_CHECK_WIDTYPE(obj, widtype);
2571
2572    win = elm_widget_data_get(obj);
2573    eina_stringshare_replace(&win->focus_highlight.style, style);
2574    win->focus_highlight.changed_theme = EINA_TRUE;
2575    _elm_win_focus_highlight_reconfigure_job_start(win);
2576 }
2577
2578 EAPI const char *
2579 elm_win_focus_highlight_style_get(const Evas_Object *obj)
2580 {
2581    Elm_Win *win;
2582
2583    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2584
2585    win = elm_widget_data_get(obj);
2586    return win->focus_highlight.style;
2587 }
2588
2589 typedef struct _Widget_Data Widget_Data;
2590
2591 struct _Widget_Data
2592 {
2593    Evas_Object *frm;
2594    Evas_Object *content;
2595 };
2596
2597 static void _del_hook(Evas_Object *obj);
2598 static void _theme_hook(Evas_Object *obj);
2599 static void _sizing_eval(Evas_Object *obj);
2600 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
2601 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
2602
2603 static const char *widtype2 = NULL;
2604
2605 static void
2606 _del_hook(Evas_Object *obj)
2607 {
2608    Widget_Data *wd = elm_widget_data_get(obj);
2609    if (!wd) return;
2610    free(wd);
2611 }
2612
2613 static void
2614 _theme_hook(Evas_Object *obj)
2615 {
2616    Widget_Data *wd = elm_widget_data_get(obj);
2617    _elm_theme_object_set(obj, wd->frm, "win", "inwin", elm_widget_style_get(obj));
2618    if (wd->content)
2619      edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
2620    _sizing_eval(obj);
2621
2622    evas_object_smart_callback_call(obj, SIG_THEME_CHANGED, NULL);
2623 }
2624
2625 static Eina_Bool
2626 _elm_inwin_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
2627 {
2628    Widget_Data *wd = elm_widget_data_get(obj);
2629
2630    if (!wd)
2631      return EINA_FALSE;
2632
2633    /* Try Focus cycle in subitem */
2634    if (wd->content)
2635      {
2636         elm_widget_focus_next_get(wd->content, dir, next);
2637         if (*next)
2638           return EINA_TRUE;
2639      }
2640
2641    *next = (Evas_Object *)obj;
2642    return EINA_FALSE;
2643 }
2644
2645 static void
2646 _sizing_eval(Evas_Object *obj)
2647 {
2648    Widget_Data *wd = elm_widget_data_get(obj);
2649    Evas_Coord minw = -1, minh = -1;
2650
2651    evas_object_size_hint_min_get(wd->content, &minw, &minh);
2652    edje_object_size_min_calc(wd->frm, &minw, &minh);
2653    evas_object_size_hint_min_set(obj, minw, minh);
2654    evas_object_size_hint_max_set(obj, -1, -1);
2655 }
2656
2657 static void
2658 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2659 {
2660    _sizing_eval(data);
2661 }
2662
2663 static void
2664 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
2665 {
2666    Widget_Data *wd = elm_widget_data_get(obj);
2667    Evas_Object *sub = event_info;
2668    if (sub == wd->content)
2669      {
2670         evas_object_event_callback_del_full
2671            (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
2672         wd->content = NULL;
2673         _sizing_eval(obj);
2674      }
2675 }
2676
2677 EAPI Evas_Object *
2678 elm_win_inwin_add(Evas_Object *obj)
2679 {
2680    Evas_Object *obj2;
2681    Widget_Data *wd;
2682    Elm_Win *win;
2683
2684    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2685    win = elm_widget_data_get(obj);
2686    if (!win) return NULL;
2687    wd = ELM_NEW(Widget_Data);
2688    obj2 = elm_widget_add(win->evas);
2689    elm_widget_type_set(obj2, "inwin");
2690    ELM_SET_WIDTYPE(widtype2, "inwin");
2691    elm_widget_sub_object_add(obj, obj2);
2692    evas_object_size_hint_weight_set(obj2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2693    evas_object_size_hint_align_set(obj2, EVAS_HINT_FILL, EVAS_HINT_FILL);
2694    elm_win_resize_object_add(obj, obj2);
2695
2696    elm_widget_data_set(obj2, wd);
2697    elm_widget_del_hook_set(obj2, _del_hook);
2698    elm_widget_theme_hook_set(obj2, _theme_hook);
2699    elm_widget_focus_next_hook_set(obj2, _elm_inwin_focus_next_hook);
2700    elm_widget_can_focus_set(obj2, EINA_TRUE);
2701    elm_widget_highlight_ignore_set(obj2, EINA_TRUE);
2702
2703    wd->frm = edje_object_add(win->evas);
2704    _elm_theme_object_set(obj, wd->frm, "win", "inwin", "default");
2705    elm_widget_resize_object_set(obj2, wd->frm);
2706
2707    evas_object_smart_callback_add(obj2, "sub-object-del", _sub_del, obj2);
2708
2709    _sizing_eval(obj2);
2710    return obj2;
2711 }
2712
2713 EAPI void
2714 elm_win_inwin_activate(Evas_Object *obj)
2715 {
2716    ELM_CHECK_WIDTYPE(obj, widtype2);
2717    Widget_Data *wd = elm_widget_data_get(obj);
2718    if (!wd) return;
2719    evas_object_raise(obj);
2720    evas_object_show(obj);
2721    edje_object_signal_emit(wd->frm, "elm,action,show", "elm");
2722    elm_object_focus_set(obj, EINA_TRUE);
2723 }
2724
2725 EAPI void
2726 elm_win_inwin_content_set(Evas_Object *obj, Evas_Object *content)
2727 {
2728    ELM_CHECK_WIDTYPE(obj, widtype2);
2729    Widget_Data *wd = elm_widget_data_get(obj);
2730    if (!wd) return;
2731    if (wd->content == content) return;
2732    if (wd->content) evas_object_del(wd->content);
2733    wd->content = content;
2734    if (content)
2735      {
2736         elm_widget_sub_object_add(obj, content);
2737         evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2738                                        _changed_size_hints, obj);
2739         edje_object_part_swallow(wd->frm, "elm.swallow.content", content);
2740      }
2741    _sizing_eval(obj);
2742 }
2743
2744 EAPI Evas_Object *
2745 elm_win_inwin_content_get(const Evas_Object *obj)
2746 {
2747    ELM_CHECK_WIDTYPE(obj, widtype2) NULL;
2748    Widget_Data *wd = elm_widget_data_get(obj);
2749    if (!wd) return NULL;
2750    return wd->content;
2751 }
2752
2753 EAPI Evas_Object *
2754 elm_win_inwin_content_unset(Evas_Object *obj)
2755 {
2756    ELM_CHECK_WIDTYPE(obj, widtype2) NULL;
2757    Widget_Data *wd = elm_widget_data_get(obj);
2758    if (!wd) return NULL;
2759    if (!wd->content) return NULL;
2760    Evas_Object *content = wd->content;
2761    elm_widget_sub_object_del(obj, wd->content);
2762    evas_object_event_callback_del_full(wd->content,
2763                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2764                                        _changed_size_hints, obj);
2765    edje_object_part_unswallow(wd->frm, wd->content);
2766    wd->content = NULL;
2767    return content;
2768 }
2769
2770 /* windowing spcific calls - shall we do this differently? */
2771
2772 static Ecore_X_Window
2773 _elm_ee_win_get(const Evas_Object *obj)
2774 {
2775    if (!obj) return 0;
2776 #ifdef HAVE_ELEMENTARY_X
2777    Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
2778    if (ee) return (Ecore_X_Window)ecore_evas_window_get(ee);
2779 #endif
2780    return 0;
2781 }
2782
2783 EAPI Ecore_X_Window
2784 elm_win_xwindow_get(const Evas_Object *obj)
2785 {
2786    Elm_Win *win;
2787    const char *type;
2788
2789    if (!obj) return 0;
2790    type = elm_widget_type_get(obj);
2791    if ((!type) || (type != widtype)) return _elm_ee_win_get(obj);
2792    win = elm_widget_data_get(obj);
2793    if (!win) return 0;
2794 #ifdef HAVE_ELEMENTARY_X
2795    if (win->xwin) return win->xwin;
2796    if (win->parent) return elm_win_xwindow_get(win->parent);
2797 #endif
2798    return 0;
2799 }