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