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