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