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