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