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