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