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