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