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