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