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