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