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