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