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