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