ae9bc2beb39dcbf85d8bd2c338aadeb8215a0771
[framework/uifw/elementary.git] / src / lib / elm_win.c
1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
3 #include "elm_priv.h"
4
5 static const char WIN_SMART_NAME[] = "elm_win";
6
7 static const Elm_Win_Trap *trap = NULL;
8
9 #define TRAP(sd, name, ...)                                             \
10   do                                                                    \
11     {                                                                   \
12        if ((!trap) || (!trap->name) ||                                  \
13            ((trap->name) &&                                             \
14             (trap->name(sd->trap_data, sd->base.obj, ## __VA_ARGS__)))) \
15          ecore_evas_##name(sd->ee, ##__VA_ARGS__);                      \
16     }                                                                   \
17   while (0)
18
19 #define ELM_WIN_DATA_GET(o, sd) \
20   Elm_Win_Smart_Data * sd = evas_object_smart_data_get(o)
21
22 #define ELM_WIN_DATA_GET_OR_RETURN(o, ptr)           \
23   ELM_WIN_DATA_GET(o, ptr);                          \
24   if (!ptr)                                          \
25     {                                                \
26        CRITICAL("No widget data for object %p (%s)", \
27                 o, evas_object_type_get(o));         \
28        return;                                       \
29     }
30
31 #define ELM_WIN_DATA_GET_OR_RETURN_VAL(o, ptr, val)  \
32   ELM_WIN_DATA_GET(o, ptr);                          \
33   if (!ptr)                                          \
34     {                                                \
35        CRITICAL("No widget data for object %p (%s)", \
36                 o, evas_object_type_get(o));         \
37        return val;                                   \
38     }
39
40 #define ELM_WIN_CHECK(obj)                                             \
41   if (!obj || !elm_widget_type_check((obj), WIN_SMART_NAME, __func__)) \
42     return
43
44 #define ENGINE_GET() (_elm_preferred_engine ? _elm_preferred_engine : (_elm_config->engine ? _elm_config->engine : ""))
45 #define ENGINE_COMPARE(name) (!strcmp(ENGINE_GET(), name))
46 #define EE_ENGINE_COMPARE(ee, name) (!strcmp(ecore_evas_engine_name_get(ee), name))
47
48 typedef struct _Elm_Win_Smart_Data Elm_Win_Smart_Data;
49
50 struct _Elm_Win_Smart_Data
51 {
52    Elm_Widget_Smart_Data base; /* base widget smart data as
53                                 * first member obligatory, as
54                                 * we're inheriting from it */
55
56    Ecore_Evas           *ee;
57    Evas                 *evas;
58    Evas_Object          *parent; /* parent *window* object*/
59    // TIZEN ONLY (20130422) : For automating default focused UI.
60    Evas_Object          *obj;
61    //
62    Evas_Object          *img_obj, *frame_obj;
63    Eina_List            *resize_objs; /* a window may have
64                                        * *multiple* resize
65                                        * objects */
66 #ifdef HAVE_ELEMENTARY_X
67    struct
68    {
69       Ecore_X_Window       xwin;
70       Ecore_Event_Handler *client_message_handler;
71       Ecore_Event_Handler *property_handler;
72       // TIZEN ONLY (20130422) : For automating default focused UI.
73       Ecore_Event_Handler *mouse_down_handler;
74       Ecore_Event_Handler *key_down_handler;
75       //
76    } x;
77 #endif
78
79 #ifdef HAVE_ELEMENTARY_WAYLAND
80    struct
81    {
82       Ecore_Wl_Window *win;
83    } wl;
84 #endif
85
86    Ecore_Job                     *deferred_resize_job;
87    Ecore_Job                     *deferred_child_eval_job;
88
89    Elm_Win_Type                   type;
90    Elm_Win_Keyboard_Mode          kbdmode;
91    Elm_Win_Indicator_Mode         indmode;
92    Elm_Win_Indicator_Opacity_Mode ind_o_mode;
93    Elm_Win_Indicator_Type_Mode ind_t_mode;
94    struct
95    {
96       const char  *info;
97       Ecore_Timer *timer;
98       int          repeat_count;
99       int          shot_counter;
100    } shot;
101    int                            resize_location;
102    int                           *autodel_clear, rot;
103    struct
104    {
105       int x, y;
106    } screen;
107    struct
108    {
109       Ecore_Evas  *ee;
110       Evas        *evas;
111       Evas_Object *obj, *hot_obj;
112       int          hot_x, hot_y;
113    } pointer;
114    struct
115    {
116       Evas_Object *top;
117
118       struct
119       {
120          Evas_Object *target;
121          Eina_Bool    visible : 1;
122          Eina_Bool    handled : 1;
123       } cur, prev;
124
125       const char  *style;
126       Ecore_Job   *reconf_job;
127
128       Eina_Bool    enabled : 1;
129       Eina_Bool    changed_theme : 1;
130       Eina_Bool    top_animate : 1;
131       Eina_Bool    geometry_changed : 1;
132    } focus_highlight;
133    struct
134    {
135       const char  *name;
136       Ecore_Timer *timer;
137       Eina_List   *names;
138    } profile;
139    struct
140    {
141       int          preferred_rot; // specified by app
142       int         *rots;          // available rotations
143       unsigned int count;         // number of elements in available rotations
144       Eina_Bool    wm_supported : 1;
145       Eina_Bool    use : 1;
146    } wm_rot;
147
148    Evas_Object *icon;
149    const char  *title;
150    const char  *icon_name;
151    const char  *role;
152
153    void *trap_data;
154
155    double       aspect;
156    int          size_base_w, size_base_h;
157    int          size_step_w, size_step_h;
158    int          norender;
159    Eina_Bool    urgent : 1;
160    Eina_Bool    modal : 1;
161    Eina_Bool    demand_attention : 1;
162    Eina_Bool    autodel : 1;
163    Eina_Bool    constrain : 1;
164    Eina_Bool    resizing : 1;
165    Eina_Bool    iconified : 1;
166    Eina_Bool    withdrawn : 1;
167    Eina_Bool    sticky : 1;
168    Eina_Bool    fullscreen : 1;
169    Eina_Bool    maximized : 1;
170    Eina_Bool    skip_focus : 1;
171    Eina_Bool    floating : 1;
172    // TIZEN ONLY (20130422) : For automating default focused UI.
173    Eina_Bool    keyboard_attached : 1;
174    Eina_Bool    first_key_down : 1;
175    //
176 };
177
178 static const char SIG_DELETE_REQUEST[] = "delete,request";
179 static const char SIG_FOCUS_OUT[] = "focus,out";
180 static const char SIG_FOCUS_IN[] = "focus,in";
181 static const char SIG_MOVED[] = "moved";
182 static const char SIG_WITHDRAWN[] = "withdrawn";
183 static const char SIG_ICONIFIED[] = "iconified";
184 static const char SIG_NORMAL[] = "normal";
185 static const char SIG_STICK[] = "stick";
186 static const char SIG_UNSTICK[] = "unstick";
187 static const char SIG_FULLSCREEN[] = "fullscreen";
188 static const char SIG_UNFULLSCREEN[] = "unfullscreen";
189 static const char SIG_MAXIMIZED[] = "maximized";
190 static const char SIG_UNMAXIMIZED[] = "unmaximized";
191 static const char SIG_IOERR[] = "ioerr";
192 static const char SIG_INDICATOR_PROP_CHANGED[] = "indicator,prop,changed";
193 static const char SIG_ROTATION_CHANGED[] = "rotation,changed";
194 static const char SIG_PROFILE_CHANGED[] = "profile,changed";
195 static const char SIG_WM_ROTATION_CHANGED[] = "wm,rotation,changed";
196
197 static const Evas_Smart_Cb_Description _smart_callbacks[] = {
198    {SIG_DELETE_REQUEST, ""},
199    {SIG_FOCUS_OUT, ""},
200    {SIG_FOCUS_IN, ""},
201    {SIG_MOVED, ""},
202    {SIG_WITHDRAWN, ""},
203    {SIG_ICONIFIED, ""},
204    {SIG_NORMAL, ""},
205    {SIG_STICK, ""},
206    {SIG_UNSTICK, ""},
207    {SIG_FULLSCREEN, ""},
208    {SIG_UNFULLSCREEN, ""},
209    {SIG_MAXIMIZED, ""},
210    {SIG_UNMAXIMIZED, ""},
211    {SIG_IOERR, ""},
212    {SIG_INDICATOR_PROP_CHANGED, ""},
213    {SIG_ROTATION_CHANGED, ""},
214    {SIG_PROFILE_CHANGED, ""},
215    {SIG_WM_ROTATION_CHANGED, ""},
216    {NULL, NULL}
217 };
218
219 EVAS_SMART_SUBCLASS_NEW
220   (WIN_SMART_NAME, _elm_win, Elm_Widget_Smart_Class,
221   Elm_Widget_Smart_Class, elm_widget_smart_class_get, _smart_callbacks);
222
223 Eina_List *_elm_win_list = NULL;
224 int _elm_win_deferred_free = 0;
225
226 static int _elm_win_count = 0;
227
228 static Eina_Bool _elm_win_auto_throttled = EINA_FALSE;
229
230 static Ecore_Job *_elm_win_state_eval_job = NULL;
231
232 static void _elm_win_resize_objects_eval(Evas_Object *obj);
233
234 #ifdef HAVE_ELEMENTARY_X
235 static void _elm_win_xwin_update(Elm_Win_Smart_Data *sd);
236 static void _elm_win_xwin_type_set(Elm_Win_Smart_Data *sd);
237 // TIZEN ONLY (20130422) : For automating default focused UI.
238 static Ecore_X_Atom keyboard_exist = 0;
239 //
240 #endif
241
242 static void
243 _elm_win_obj_intercept_show(void *data, Evas_Object *obj)
244 {
245    Elm_Win_Smart_Data *sd = data;
246    // this is called to make sure all smart containers have calculated their
247    // sizes BEFORE we show the window to make sure it initially appears at
248    // our desired size (ie min size is known first)
249    evas_smart_objects_calculate(evas_object_evas_get(obj));
250    if (sd->frame_obj)
251      {
252         evas_object_show(sd->frame_obj);
253      }
254    else if (sd->img_obj)
255      {
256         evas_object_show(sd->img_obj);
257      }
258    if (sd->pointer.obj)
259      {
260         ecore_evas_show(sd->pointer.ee);
261         evas_object_show(sd->pointer.obj);
262         /* ecore_evas_wayland_pointer_set(win->pointer.ee, 10, 10); */
263      }
264    evas_object_show(obj);
265 }
266
267
268 static void
269 _elm_win_state_eval(void *data __UNUSED__)
270 {
271    Eina_List *l;
272    Evas_Object *obj;
273    int _elm_win_count_shown = 0;
274    int _elm_win_count_iconified = 0;
275    int _elm_win_count_withdrawn = 0;
276
277    _elm_win_state_eval_job = NULL;
278
279    if (_elm_config->auto_norender_withdrawn)
280      {
281         EINA_LIST_FOREACH(_elm_win_list, l, obj)
282           {
283              if ((elm_win_withdrawn_get(obj)) ||
284                  ((elm_win_iconified_get(obj) &&
285                    (_elm_config->auto_norender_iconified_same_as_withdrawn))))
286                {
287                   if (!evas_object_data_get(obj, "__win_auto_norender"))
288                     {
289                        Evas *evas = evas_object_evas_get(obj);
290
291                        elm_win_norender_push(obj);
292                        evas_object_data_set(obj, "__win_auto_norender", obj);
293
294                        if (_elm_config->auto_flush_withdrawn)
295                          {
296                             edje_file_cache_flush();
297                             edje_collection_cache_flush();
298                             evas_image_cache_flush(evas);
299                             evas_font_cache_flush(evas);
300                          }
301                        if (_elm_config->auto_dump_withdrawn)
302                          {
303                             evas_render_dump(evas);
304                          }
305                     }
306                }
307              else
308                {
309                   if (evas_object_data_get(obj, "__win_auto_norender"))
310                     {
311                        elm_win_norender_pop(obj);
312                        evas_object_data_del(obj, "__win_auto_norender");
313                     }
314                }
315           }
316      }
317    if (((_elm_config->auto_throttle) &&
318         (elm_policy_get(ELM_POLICY_THROTTLE) != ELM_POLICY_THROTTLE_NEVER)) ||
319         (elm_policy_get(ELM_POLICY_THROTTLE) == ELM_POLICY_THROTTLE_HIDDEN_ALWAYS))
320      {
321         if (_elm_win_count == 0)
322           {
323              if (_elm_win_auto_throttled)
324                {
325                   ecore_throttle_adjust(-_elm_config->auto_throttle_amount);
326                   _elm_win_auto_throttled = EINA_FALSE;
327                }
328           }
329         else
330           {
331              EINA_LIST_FOREACH(_elm_win_list, l, obj)
332                {
333                   if (elm_win_withdrawn_get(obj))
334                     _elm_win_count_withdrawn++;
335                   else if (elm_win_iconified_get(obj))
336                     _elm_win_count_iconified++;
337                   else if (evas_object_visible_get(obj))
338                     _elm_win_count_shown++;
339                }
340              if (_elm_win_count_shown <= 0)
341                {
342                   if (!_elm_win_auto_throttled)
343                     {
344                        ecore_throttle_adjust(_elm_config->auto_throttle_amount);
345                        _elm_win_auto_throttled = EINA_TRUE;
346                     }
347                }
348              else
349                {
350                   if (_elm_win_auto_throttled)
351                     {
352                        ecore_throttle_adjust(-_elm_config->auto_throttle_amount);
353                        _elm_win_auto_throttled = EINA_FALSE;
354                     }
355                }
356           }
357      }
358 }
359
360 static void
361 _elm_win_state_eval_queue(void)
362 {
363    if (_elm_win_state_eval_job) ecore_job_del(_elm_win_state_eval_job);
364    _elm_win_state_eval_job = ecore_job_add(_elm_win_state_eval, NULL);
365 }
366
367 // example shot spec (wait 0.1 sec then save as my-window.png):
368 // ELM_ENGINE="shot:delay=0.1:file=my-window.png"
369
370 static double
371 _shot_delay_get(Elm_Win_Smart_Data *sd)
372 {
373    char *p, *pd;
374    char *d = strdup(sd->shot.info);
375
376    if (!d) return 0.5;
377    for (p = (char *)sd->shot.info; *p; p++)
378      {
379         if (!strncmp(p, "delay=", 6))
380           {
381              double v;
382
383              for (pd = d, p += 6; (*p) && (*p != ':'); p++, pd++)
384                {
385                   *pd = *p;
386                }
387              *pd = 0;
388              v = _elm_atof(d);
389              free(d);
390              return v;
391           }
392      }
393    free(d);
394
395    return 0.5;
396 }
397
398 static char *
399 _shot_file_get(Elm_Win_Smart_Data *sd)
400 {
401    char *p;
402    char *tmp = strdup(sd->shot.info);
403    char *repname = NULL;
404
405    if (!tmp) return NULL;
406
407    for (p = (char *)sd->shot.info; *p; p++)
408      {
409         if (!strncmp(p, "file=", 5))
410           {
411              strcpy(tmp, p + 5);
412              if (!sd->shot.repeat_count) return tmp;
413              else
414                {
415                   char *dotptr = strrchr(tmp, '.');
416                   if (dotptr)
417                     {
418                        size_t size = sizeof(char) * (strlen(tmp) + 16);
419                        repname = malloc(size);
420                        strncpy(repname, tmp, dotptr - tmp);
421                        snprintf(repname + (dotptr - tmp), size -
422                                 (dotptr - tmp), "%03i",
423                                 sd->shot.shot_counter + 1);
424                        strcat(repname, dotptr);
425                        free(tmp);
426                        return repname;
427                     }
428                }
429           }
430      }
431    free(tmp);
432    if (!sd->shot.repeat_count) return strdup("out.png");
433
434    repname = malloc(sizeof(char) * 24);
435    snprintf(repname, sizeof(char) * 24, "out%03i.png",
436             sd->shot.shot_counter + 1);
437
438    return repname;
439 }
440
441 static int
442 _shot_repeat_count_get(Elm_Win_Smart_Data *sd)
443 {
444    char *p, *pd;
445    char *d = strdup(sd->shot.info);
446
447    if (!d) return 0;
448    for (p = (char *)sd->shot.info; *p; p++)
449      {
450         if (!strncmp(p, "repeat=", 7))
451           {
452              int v;
453
454              for (pd = d, p += 7; (*p) && (*p != ':'); p++, pd++)
455                {
456                   *pd = *p;
457                }
458              *pd = 0;
459              v = atoi(d);
460              if (v < 0) v = 0;
461              if (v > 1000) v = 999;
462              free(d);
463              return v;
464           }
465      }
466    free(d);
467
468    return 0;
469 }
470
471 static char *
472 _shot_key_get(Elm_Win_Smart_Data *sd __UNUSED__)
473 {
474    return NULL;
475 }
476
477 static char *
478 _shot_flags_get(Elm_Win_Smart_Data *sd __UNUSED__)
479 {
480    return NULL;
481 }
482
483 static void
484 _shot_do(Elm_Win_Smart_Data *sd)
485 {
486    Ecore_Evas *ee;
487    Evas_Object *o;
488    unsigned int *pixels;
489    int w, h;
490    char *file, *key, *flags;
491
492    ecore_evas_manual_render(sd->ee);
493    pixels = (void *)ecore_evas_buffer_pixels_get(sd->ee);
494    if (!pixels) return;
495
496    ecore_evas_geometry_get(sd->ee, NULL, NULL, &w, &h);
497    if ((w < 1) || (h < 1)) return;
498
499    file = _shot_file_get(sd);
500    if (!file) return;
501
502    key = _shot_key_get(sd);
503    flags = _shot_flags_get(sd);
504    ee = ecore_evas_buffer_new(1, 1);
505    o = evas_object_image_add(ecore_evas_get(ee));
506    evas_object_image_alpha_set(o, ecore_evas_alpha_get(sd->ee));
507    evas_object_image_size_set(o, w, h);
508    evas_object_image_data_set(o, pixels);
509    if (!evas_object_image_save(o, file, key, flags))
510      {
511         ERR("Cannot save window to '%s' (key '%s', flags '%s')",
512             file, key, flags);
513      }
514    free(file);
515    if (key) free(key);
516    if (flags) free(flags);
517    ecore_evas_free(ee);
518    if (sd->shot.repeat_count) sd->shot.shot_counter++;
519 }
520
521 static Eina_Bool
522 _shot_delay(void *data)
523 {
524    Elm_Win_Smart_Data *sd = data;
525
526    _shot_do(sd);
527    if (sd->shot.repeat_count)
528      {
529         int remainshot = (sd->shot.repeat_count - sd->shot.shot_counter);
530         if (remainshot > 0) return EINA_TRUE;
531      }
532    sd->shot.timer = NULL;
533    elm_exit();
534
535    return EINA_FALSE;
536 }
537
538 static void
539 _shot_init(Elm_Win_Smart_Data *sd)
540 {
541    if (!sd->shot.info) return;
542
543    sd->shot.repeat_count = _shot_repeat_count_get(sd);
544    sd->shot.shot_counter = 0;
545 }
546
547 static void
548 _shot_handle(Elm_Win_Smart_Data *sd)
549 {
550    if (!sd->shot.info) return;
551
552    if (!sd->shot.timer)
553      sd->shot.timer = ecore_timer_add(_shot_delay_get(sd), _shot_delay, sd);
554 }
555
556 /* elm-win specific associate, does the trap while ecore_evas_object_associate()
557  * does not.
558  */
559 static Elm_Win_Smart_Data *
560 _elm_win_associate_get(const Ecore_Evas *ee)
561 {
562    return ecore_evas_data_get(ee, "elm_win");
563 }
564
565 /* Interceptors Callbacks */
566 static void
567 _elm_win_obj_intercept_raise(void *data, Evas_Object *obj __UNUSED__)
568 {
569    Elm_Win_Smart_Data *sd = data;
570    TRAP(sd, raise);
571 }
572
573 static void
574 _elm_win_obj_intercept_lower(void *data, Evas_Object *obj __UNUSED__)
575 {
576    Elm_Win_Smart_Data *sd = data;
577    TRAP(sd, lower);
578 }
579
580 static void
581 _elm_win_obj_intercept_stack_above(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Object *above __UNUSED__)
582 {
583    INF("TODO: %s", __FUNCTION__);
584 }
585
586 static void
587 _elm_win_obj_intercept_stack_below(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Object *below __UNUSED__)
588 {
589    INF("TODO: %s", __FUNCTION__);
590 }
591
592 static void
593 _elm_win_obj_intercept_layer_set(void *data, Evas_Object *obj __UNUSED__, int l)
594 {
595    Elm_Win_Smart_Data *sd = data;
596    TRAP(sd, layer_set, l);
597 }
598
599 static void
600 _ecore_evas_move_(void *data, Evas_Object *obj __UNUSED__, int a, int b)
601 {
602    printf("[%s][%d] a=%d, b=%d\n", __FUNCTION__, __LINE__, a, b);
603    Elm_Win_Smart_Data *sd = data;
604    TRAP(sd, move, a, b);
605 }
606
607 /* Event Callbacks */
608
609 static void
610 _elm_win_obj_callback_changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
611 {
612    Elm_Win_Smart_Data *sd = data;
613    Evas_Coord w, h;
614
615    evas_object_size_hint_min_get(obj, &w, &h);
616    TRAP(sd, size_min_set, w, h);
617
618    evas_object_size_hint_max_get(obj, &w, &h);
619    if (w < 1) w = -1;
620    if (h < 1) h = -1;
621    TRAP(sd, size_max_set, w, h);
622 }
623 /* end of elm-win specific associate */
624
625
626 static void
627 _elm_win_move(Ecore_Evas *ee)
628 {
629    Elm_Win_Smart_Data *sd = _elm_win_associate_get(ee);
630    int x, y;
631
632    EINA_SAFETY_ON_NULL_RETURN(sd);
633
634    ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
635    sd->screen.x = x;
636    sd->screen.y = y;
637    evas_object_smart_callback_call(ELM_WIDGET_DATA(sd)->obj, SIG_MOVED, NULL);
638 }
639
640 static void
641 _elm_win_resize_job(void *data)
642 {
643    Elm_Win_Smart_Data *sd = data;
644    const Eina_List *l;
645    Evas_Object *obj;
646    int w, h;
647
648    sd->deferred_resize_job = NULL;
649    ecore_evas_request_geometry_get(sd->ee, NULL, NULL, &w, &h);
650    if (sd->constrain)
651      {
652         int sw, sh;
653         ecore_evas_screen_geometry_get(sd->ee, NULL, NULL, &sw, &sh);
654         w = MIN(w, sw);
655         h = MIN(h, sh);
656      }
657
658    if (sd->frame_obj)
659      {
660         int fw, fh;
661
662         evas_output_framespace_get(sd->evas, NULL, NULL, &fw, &fh);
663         evas_object_resize(sd->frame_obj, w + fw, h + fh);
664      }
665
666    /* if (sd->img_obj) */
667    /*   { */
668    /*   } */
669
670    evas_object_resize(ELM_WIDGET_DATA(sd)->obj, w, h);
671    EINA_LIST_FOREACH(sd->resize_objs, l, obj)
672      {
673         evas_object_move(obj, 0, 0);
674         evas_object_resize(obj, w, h);
675      }
676 }
677
678 static void
679 _elm_win_resize(Ecore_Evas *ee)
680 {
681    Elm_Win_Smart_Data *sd = _elm_win_associate_get(ee);
682    EINA_SAFETY_ON_NULL_RETURN(sd);
683
684    if (sd->deferred_resize_job) ecore_job_del(sd->deferred_resize_job);
685    sd->deferred_resize_job = ecore_job_add(_elm_win_resize_job, sd);
686 }
687
688 static void
689 _elm_win_mouse_in(Ecore_Evas *ee)
690 {
691    Elm_Win_Smart_Data *sd = _elm_win_associate_get(ee);
692    EINA_SAFETY_ON_NULL_RETURN(sd);
693
694    if (sd->resizing) sd->resizing = EINA_FALSE;
695 }
696
697 static void
698 _elm_win_focus_highlight_reconfigure_job_stop(Elm_Win_Smart_Data *sd)
699 {
700    if (sd->focus_highlight.reconf_job)
701      ecore_job_del(sd->focus_highlight.reconf_job);
702    sd->focus_highlight.reconf_job = NULL;
703 }
704
705 static void
706 _elm_win_focus_highlight_visible_set(Elm_Win_Smart_Data *sd,
707                                      Eina_Bool visible)
708 {
709    Evas_Object *top;
710
711    top = sd->focus_highlight.top;
712    if (visible)
713      {
714         if (top)
715           {
716              evas_object_show(top);
717              edje_object_signal_emit(top, "elm,action,focus,show", "elm");
718           }
719      }
720    else
721      {
722         if (top)
723           edje_object_signal_emit(top, "elm,action,focus,hide", "elm");
724      }
725 }
726
727 static void
728 _elm_win_focus_highlight_anim_setup(Elm_Win_Smart_Data *sd,
729                                     Evas_Object *obj)
730 {
731    Evas_Coord tx, ty, tw, th;
732    Evas_Coord w, h, px, py, pw, ph;
733    Edje_Message_Int_Set *m;
734    Evas_Object *previous = sd->focus_highlight.prev.target;
735    Evas_Object *target = sd->focus_highlight.cur.target;
736
737    evas_object_geometry_get(ELM_WIDGET_DATA(sd)->obj, NULL, NULL, &w, &h);
738    evas_object_geometry_get(target, &tx, &ty, &tw, &th);
739    evas_object_geometry_get(previous, &px, &py, &pw, &ph);
740    evas_object_move(obj, tx, ty);
741    evas_object_resize(obj, tw, th);
742    evas_object_clip_unset(obj);
743
744    m = alloca(sizeof(*m) + (sizeof(int) * 8));
745    m->count = 8;
746    m->val[0] = px - tx;
747    m->val[1] = py - ty;
748    m->val[2] = pw;
749    m->val[3] = ph;
750    m->val[4] = 0;
751    m->val[5] = 0;
752    m->val[6] = tw;
753    m->val[7] = th;
754    edje_object_message_send(obj, EDJE_MESSAGE_INT_SET, 1, m);
755 }
756
757 static void
758 _elm_win_focus_highlight_simple_setup(Elm_Win_Smart_Data *sd,
759                                       Evas_Object *obj)
760 {
761    Evas_Object *clip, *target = sd->focus_highlight.cur.target;
762    Evas_Coord x, y, w, h;
763
764    clip = evas_object_clip_get(target);
765    evas_object_geometry_get(target, &x, &y, &w, &h);
766
767    evas_object_move(obj, x, y);
768    evas_object_resize(obj, w, h);
769    evas_object_clip_set(obj, clip);
770 }
771
772 static void
773 _elm_win_focus_highlight_reconfigure(Elm_Win_Smart_Data *sd)
774 {
775    Evas_Object *target = sd->focus_highlight.cur.target;
776    Evas_Object *previous = sd->focus_highlight.prev.target;
777    Evas_Object *top = sd->focus_highlight.top;
778    Eina_Bool visible_changed;
779    Eina_Bool common_visible;
780    const char *sig = NULL;
781
782    _elm_win_focus_highlight_reconfigure_job_stop(sd);
783
784    visible_changed = (sd->focus_highlight.cur.visible !=
785                       sd->focus_highlight.prev.visible);
786
787    if ((target == previous) && (!visible_changed) &&
788        (!sd->focus_highlight.geometry_changed))
789      return;
790
791    if ((previous) && (sd->focus_highlight.prev.handled))
792      elm_widget_signal_emit
793        (previous, "elm,action,focus_highlight,hide", "elm");
794
795    if (!target)
796      common_visible = EINA_FALSE;
797    else if (sd->focus_highlight.cur.handled)
798      {
799         common_visible = EINA_FALSE;
800         if (sd->focus_highlight.cur.visible)
801           sig = "elm,action,focus_highlight,show";
802         else
803           sig = "elm,action,focus_highlight,hide";
804      }
805    else
806      common_visible = sd->focus_highlight.cur.visible;
807
808    _elm_win_focus_highlight_visible_set(sd, common_visible);
809    if (sig)
810      elm_widget_signal_emit(target, sig, "elm");
811
812    if ((!target) || (!common_visible) || (sd->focus_highlight.cur.handled))
813      goto the_end;
814
815    if (sd->focus_highlight.changed_theme)
816      {
817         const char *str;
818         if (sd->focus_highlight.style)
819           str = sd->focus_highlight.style;
820         else
821           str = "default";
822         elm_widget_theme_object_set
823           (ELM_WIDGET_DATA(sd)->obj, top, "focus_highlight", "top", str);
824         sd->focus_highlight.changed_theme = EINA_FALSE;
825
826         if (_elm_config->focus_highlight_animate)
827           {
828              str = edje_object_data_get(sd->focus_highlight.top, "animate");
829              sd->focus_highlight.top_animate = ((str) && (!strcmp(str, "on")));
830           }
831      }
832
833    if ((sd->focus_highlight.top_animate) && (previous) &&
834        (!sd->focus_highlight.prev.handled))
835      _elm_win_focus_highlight_anim_setup(sd, top);
836    else
837      _elm_win_focus_highlight_simple_setup(sd, top);
838    evas_object_raise(top);
839
840 the_end:
841    sd->focus_highlight.geometry_changed = EINA_FALSE;
842    sd->focus_highlight.prev = sd->focus_highlight.cur;
843 }
844
845 static void
846 _elm_win_focus_highlight_reconfigure_job(void *data)
847 {
848    _elm_win_focus_highlight_reconfigure((Elm_Win_Smart_Data *)data);
849 }
850
851 static void
852 _elm_win_focus_highlight_reconfigure_job_start(Elm_Win_Smart_Data *sd)
853 {
854    if (sd->focus_highlight.reconf_job)
855      ecore_job_del(sd->focus_highlight.reconf_job);
856
857    sd->focus_highlight.reconf_job = ecore_job_add(
858        _elm_win_focus_highlight_reconfigure_job, sd);
859 }
860
861 static void
862 _elm_win_focus_in(Ecore_Evas *ee)
863 {
864    Elm_Win_Smart_Data *sd = _elm_win_associate_get(ee);
865    Evas_Object *obj;
866    unsigned int order = 0;
867    Evas_Object *access_highlight;
868
869    EINA_SAFETY_ON_NULL_RETURN(sd);
870
871    obj = ELM_WIDGET_DATA(sd)->obj;
872
873    _elm_widget_top_win_focused_set(obj, EINA_TRUE);
874    if (!elm_widget_focus_order_get(obj)
875        || (obj == elm_widget_newest_focus_order_get(obj, &order, EINA_TRUE)))
876      {
877         elm_widget_focus_steal(obj);
878      }
879    else
880      elm_widget_focus_restore(obj);
881    evas_object_smart_callback_call(obj, SIG_FOCUS_IN, NULL);
882    // TIZEN_ONLY (20130713) : For supporting Focused UI of TIZEN.
883    /*
884    sd->focus_highlight.cur.visible = EINA_TRUE;
885    _elm_win_focus_highlight_reconfigure_job_start(sd);
886    */
887    if (sd->frame_obj)
888      {
889         edje_object_signal_emit(sd->frame_obj, "elm,action,focus", "elm");
890      }
891
892    /* access */
893    if (_elm_config->access_mode)
894      {
895         access_highlight = evas_object_name_find(evas_object_evas_get(obj),
896                                                  "_elm_access_disp");
897         if (!access_highlight) return;
898
899         evas_object_show(access_highlight);
900         _elm_access_highlight_object_read(obj);
901      }
902    /* do nothing */
903    /* else if (sd->img_obj) */
904    /*   { */
905    /*   } */
906 }
907
908 static void
909 _elm_win_focus_out(Ecore_Evas *ee)
910 {
911    Elm_Win_Smart_Data *sd = _elm_win_associate_get(ee);
912    Evas_Object *obj;
913    Evas_Object *access_highlight;
914
915    EINA_SAFETY_ON_NULL_RETURN(sd);
916
917    obj = ELM_WIDGET_DATA(sd)->obj;
918
919    elm_object_focus_set(obj, EINA_FALSE);
920    _elm_widget_top_win_focused_set(obj, EINA_FALSE);
921    evas_object_smart_callback_call(obj, SIG_FOCUS_OUT, NULL);
922    sd->focus_highlight.cur.visible = EINA_FALSE;
923    // TIZEN_ONLY (20130713) : For supporting Focused UI of TIZEN.
924    elm_win_focus_highlight_enabled_set(obj, EINA_FALSE);
925    //
926    _elm_win_focus_highlight_reconfigure_job_start(sd);
927    if (sd->frame_obj)
928      {
929         edje_object_signal_emit(sd->frame_obj, "elm,action,unfocus", "elm");
930      }
931
932    /* access */
933    if (_elm_config->access_mode)
934      {
935         access_highlight = evas_object_name_find(evas_object_evas_get(obj),
936                                                  "_elm_access_disp");
937         if (access_highlight) evas_object_hide(access_highlight);
938      }
939
940    /* do nothing */
941    /* if (sd->img_obj) */
942    /*   { */
943    /*   } */
944 }
945
946 static void
947 _elm_win_profile_update(Ecore_Evas *ee)
948 {
949    Elm_Win_Smart_Data *sd = _elm_win_associate_get(ee);
950    Evas_Object *obj;
951
952    EINA_SAFETY_ON_NULL_RETURN(sd);
953
954    obj = ELM_WIDGET_DATA(sd)->obj;
955    if (!obj) return;
956
957    if (sd->profile.timer)
958      {
959         ecore_timer_del(sd->profile.timer);
960         sd->profile.timer = NULL;
961      }
962
963    /* It should be replaced per-window ELM profile later. */
964    _elm_config_profile_set(sd->profile.name);
965
966    evas_object_smart_callback_call(obj, SIG_PROFILE_CHANGED, NULL);
967 }
968
969 static Eina_Bool
970 _elm_win_profile_change_delay(void *data)
971 {
972    Elm_Win_Smart_Data *sd = data;
973    const char *profile;
974    Eina_Bool changed = EINA_FALSE;
975
976    profile = eina_list_nth(sd->profile.names, 0);
977    if (profile)
978      {
979         if (sd->profile.name)
980           {
981              if (strcmp(sd->profile.name, profile))
982                {
983                   eina_stringshare_replace(&(sd->profile.name), profile);
984                   changed = EINA_TRUE;
985                }
986           }
987         else
988           {
989              sd->profile.name = eina_stringshare_add(profile);
990              changed = EINA_TRUE;
991           }
992      }
993    sd->profile.timer = NULL;
994    if (changed) _elm_win_profile_update(sd->ee);
995    return EINA_FALSE;
996 }
997
998 static void
999 _elm_win_state_change(Ecore_Evas *ee)
1000 {
1001    Elm_Win_Smart_Data *sd = _elm_win_associate_get(ee);
1002    Evas_Object *obj;
1003    Eina_Bool ch_withdrawn = EINA_FALSE;
1004    Eina_Bool ch_sticky = EINA_FALSE;
1005    Eina_Bool ch_iconified = EINA_FALSE;
1006    Eina_Bool ch_fullscreen = EINA_FALSE;
1007    Eina_Bool ch_maximized = EINA_FALSE;
1008    Eina_Bool ch_profile = EINA_FALSE;
1009    Eina_Bool ch_wm_rotation = EINA_FALSE;
1010    const char *profile;
1011
1012    EINA_SAFETY_ON_NULL_RETURN(sd);
1013
1014    obj = ELM_WIDGET_DATA(sd)->obj;
1015
1016    if (sd->withdrawn != ecore_evas_withdrawn_get(sd->ee))
1017      {
1018         sd->withdrawn = ecore_evas_withdrawn_get(sd->ee);
1019         ch_withdrawn = EINA_TRUE;
1020      }
1021    if (sd->sticky != ecore_evas_sticky_get(sd->ee))
1022      {
1023         sd->sticky = ecore_evas_sticky_get(sd->ee);
1024         ch_sticky = EINA_TRUE;
1025      }
1026    if (sd->iconified != ecore_evas_iconified_get(sd->ee))
1027      {
1028         sd->iconified = ecore_evas_iconified_get(sd->ee);
1029         ch_iconified = EINA_TRUE;
1030      }
1031    if (sd->fullscreen != ecore_evas_fullscreen_get(sd->ee))
1032      {
1033         sd->fullscreen = ecore_evas_fullscreen_get(sd->ee);
1034         ch_fullscreen = EINA_TRUE;
1035      }
1036    if (sd->maximized != ecore_evas_maximized_get(sd->ee))
1037      {
1038         sd->maximized = ecore_evas_maximized_get(sd->ee);
1039         ch_maximized = EINA_TRUE;
1040      }
1041    profile = ecore_evas_profile_get(sd->ee);
1042    if ((profile) &&
1043        _elm_config_profile_exists(profile))
1044      {
1045         if (sd->profile.name)
1046           {
1047              if (strcmp(sd->profile.name, profile))
1048                {
1049                   eina_stringshare_replace(&(sd->profile.name), profile);
1050                   ch_profile = EINA_TRUE;
1051                }
1052           }
1053         else
1054           {
1055              sd->profile.name = eina_stringshare_add(profile);
1056              ch_profile = EINA_TRUE;
1057           }
1058      }
1059    if (sd->wm_rot.use)
1060      {
1061         if (sd->rot != ecore_evas_rotation_get(sd->ee))
1062           {
1063              sd->rot = ecore_evas_rotation_get(sd->ee);
1064              ch_wm_rotation = EINA_TRUE;
1065           }
1066      }
1067
1068    _elm_win_state_eval_queue();
1069
1070    if ((ch_withdrawn) || (ch_iconified))
1071      {
1072         if (sd->withdrawn)
1073           evas_object_smart_callback_call(obj, SIG_WITHDRAWN, NULL);
1074         else if (sd->iconified)
1075           evas_object_smart_callback_call(obj, SIG_ICONIFIED, NULL);
1076         else
1077           evas_object_smart_callback_call(obj, SIG_NORMAL, NULL);
1078      }
1079    if (ch_sticky)
1080      {
1081         if (sd->sticky)
1082           evas_object_smart_callback_call(obj, SIG_STICK, NULL);
1083         else
1084           evas_object_smart_callback_call(obj, SIG_UNSTICK, NULL);
1085      }
1086    if (ch_fullscreen)
1087      {
1088         if (sd->fullscreen)
1089           evas_object_smart_callback_call(obj, SIG_FULLSCREEN, NULL);
1090         else
1091           evas_object_smart_callback_call(obj, SIG_UNFULLSCREEN, NULL);
1092      }
1093    if (ch_maximized)
1094      {
1095         if (sd->maximized)
1096           evas_object_smart_callback_call(obj, SIG_MAXIMIZED, NULL);
1097         else
1098           evas_object_smart_callback_call(obj, SIG_UNMAXIMIZED, NULL);
1099      }
1100    if (ch_profile)
1101      {
1102         _elm_win_profile_update(ee);
1103      }
1104    if (ch_wm_rotation)
1105      {
1106         evas_object_size_hint_min_set(obj, -1, -1);
1107         evas_object_size_hint_max_set(obj, -1, -1);
1108         _elm_win_resize_objects_eval(obj);
1109 #ifdef HAVE_ELEMENTARY_X
1110         _elm_win_xwin_update(sd);
1111 #endif
1112         elm_widget_orientation_set(obj, sd->rot);
1113         evas_object_smart_callback_call(obj, SIG_ROTATION_CHANGED, NULL);
1114         evas_object_smart_callback_call(obj, SIG_WM_ROTATION_CHANGED, NULL);
1115      }
1116 }
1117
1118 static Eina_Bool
1119 _elm_win_smart_focus_next(const Evas_Object *obj,
1120                           Elm_Focus_Direction dir,
1121                           Evas_Object **next)
1122 {
1123    Eina_Bool ret;
1124    ELM_WIN_DATA_GET(obj, sd);
1125
1126    const Eina_List *items;
1127    void *(*list_data_get)(const Eina_List *list);
1128
1129    /* Focus chain */
1130    if (ELM_WIDGET_DATA(sd)->subobjs)
1131      {
1132         if (!(items = elm_widget_focus_custom_chain_get(obj)))
1133           {
1134              items = ELM_WIDGET_DATA(sd)->subobjs;
1135              if (!items)
1136                return EINA_FALSE;
1137           }
1138         list_data_get = eina_list_data_get;
1139
1140         ret = elm_widget_focus_list_next_get(obj, items, list_data_get, dir, next);
1141
1142         /* the result is used on the auto read mode. it would meet end of the
1143            widget tree if it return EINA_FALSE. stop the auto read if ret is EINA_FALSE */
1144         if (_elm_config->access_mode && *next)
1145           return ret;
1146
1147         if (*next)
1148           return EINA_TRUE;
1149      }
1150    *next = (Evas_Object *)obj;
1151    return EINA_FALSE;
1152 }
1153
1154 static Eina_Bool
1155 _elm_win_smart_focus_direction(const Evas_Object *obj,
1156                                const Evas_Object *base,
1157                                double degree,
1158                                Evas_Object **direction,
1159                                double *weight)
1160 {
1161    const Eina_List *items;
1162    void *(*list_data_get)(const Eina_List *list);
1163
1164    ELM_WIN_DATA_GET(obj, sd);
1165
1166    /* Focus chain */
1167    if (ELM_WIDGET_DATA(sd)->subobjs)
1168      {
1169         if (!(items = elm_widget_focus_custom_chain_get(obj)))
1170           items = ELM_WIDGET_DATA(sd)->subobjs;
1171
1172         list_data_get = eina_list_data_get;
1173
1174         return elm_widget_focus_list_direction_get
1175                  (obj, base, items, list_data_get, degree, direction, weight);
1176      }
1177
1178    return EINA_FALSE;
1179 }
1180
1181 static Eina_Bool
1182 _elm_win_smart_on_focus(Evas_Object *obj)
1183 {
1184    ELM_WIN_DATA_GET(obj, sd);
1185
1186    if (sd->img_obj)
1187      evas_object_focus_set(sd->img_obj, elm_widget_focus_get(obj));
1188    else
1189      evas_object_focus_set(obj, elm_widget_focus_get(obj));
1190
1191    return EINA_TRUE;
1192 }
1193
1194 static Eina_Bool
1195 _elm_win_smart_event(Evas_Object *obj,
1196                      Evas_Object *src __UNUSED__,
1197                      Evas_Callback_Type type,
1198                      void *event_info __UNUSED__)
1199 {
1200    Evas_Event_Key_Down *ev = event_info;
1201    Evas_Object *current_focused;
1202
1203    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
1204
1205    if (type != EVAS_CALLBACK_KEY_DOWN)
1206      return EINA_FALSE;
1207
1208    // TIZEN_ONLY (20130713) : For supporting Focused UI of TIZEN.
1209    if (!elm_win_focus_highlight_enabled_get(obj))
1210      return EINA_FALSE;
1211    ////
1212
1213    current_focused = elm_widget_focused_object_get(obj);
1214    if ((!strcmp(ev->keyname, "Tab")) ||
1215        (!strcmp(ev->keyname, "ISO_Left_Tab")))
1216      {
1217         if (evas_key_modifier_is_set(ev->modifiers, "Shift"))
1218           elm_widget_focus_cycle(obj, ELM_FOCUS_PREVIOUS);
1219         else
1220           elm_widget_focus_cycle(obj, ELM_FOCUS_NEXT);
1221
1222         goto success;
1223      }
1224    else if ((!strcmp(ev->keyname, "Left")) ||
1225             ((!strcmp(ev->keyname, "KP_Left")) && (!ev->string)))
1226      {
1227         if (current_focused == obj)
1228           elm_widget_focus_cycle(obj, ELM_FOCUS_NEXT);
1229         else
1230           elm_widget_focus_direction_go(obj, 270.0);
1231
1232         goto success;
1233      }
1234    else if ((!strcmp(ev->keyname, "Right")) ||
1235             ((!strcmp(ev->keyname, "KP_Right")) && (!ev->string)))
1236      {
1237         if (current_focused == obj)
1238           elm_widget_focus_cycle(obj, ELM_FOCUS_NEXT);
1239         else
1240           elm_widget_focus_direction_go(obj, 90.0);
1241
1242         goto success;
1243      }
1244    else if ((!strcmp(ev->keyname, "Up")) ||
1245             ((!strcmp(ev->keyname, "KP_Up")) && (!ev->string)))
1246      {
1247         if (current_focused == obj)
1248           elm_widget_focus_cycle(obj, ELM_FOCUS_NEXT);
1249         else
1250           elm_widget_focus_direction_go(obj, 0.0);
1251
1252         goto success;
1253      }
1254    else if ((!strcmp(ev->keyname, "Down")) ||
1255             ((!strcmp(ev->keyname, "KP_Down")) && (!ev->string)))
1256      {
1257         if (current_focused == obj)
1258           elm_widget_focus_cycle(obj, ELM_FOCUS_NEXT);
1259         else
1260           elm_widget_focus_direction_go(obj, 180.0);
1261
1262         goto success;
1263      }
1264
1265    return EINA_FALSE;
1266
1267 success:
1268    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1269    return EINA_TRUE;
1270 }
1271
1272 static void
1273 _deferred_ecore_evas_free(void *data)
1274 {
1275    ecore_evas_free(data);
1276    _elm_win_deferred_free--;
1277 }
1278
1279
1280
1281 static void
1282 _elm_win_smart_show(Evas_Object *obj)
1283 {
1284    ELM_WIN_DATA_GET(obj, sd);
1285
1286    if (!evas_object_visible_get(obj))
1287      _elm_win_state_eval_queue();
1288    _elm_win_parent_sc->base.show(obj);
1289
1290    TRAP(sd, show);
1291
1292    if (sd->shot.info) _shot_handle(sd);
1293 }
1294
1295 static void
1296 _elm_win_smart_hide(Evas_Object *obj)
1297 {
1298    ELM_WIN_DATA_GET(obj, sd);
1299
1300    if (evas_object_visible_get(obj))
1301      _elm_win_state_eval_queue();
1302    _elm_win_parent_sc->base.hide(obj);
1303
1304    TRAP(sd, hide);
1305
1306    if (sd->frame_obj)
1307      {
1308         evas_object_hide(sd->frame_obj);
1309      }
1310    if (sd->img_obj)
1311      {
1312         evas_object_hide(sd->img_obj);
1313      }
1314    if (sd->pointer.obj)
1315      {
1316         evas_object_hide(sd->pointer.obj);
1317         ecore_evas_hide(sd->pointer.ee);
1318      }
1319 }
1320
1321 static void
1322 _elm_win_on_parent_del(void *data,
1323                        Evas *e __UNUSED__,
1324                        Evas_Object *obj,
1325                        void *event_info __UNUSED__)
1326 {
1327    Elm_Win_Smart_Data *sd = data;
1328
1329    if (obj == sd->parent) sd->parent = NULL;
1330 }
1331
1332 static void
1333 _elm_win_focus_target_move(void *data,
1334                            Evas *e __UNUSED__,
1335                            Evas_Object *obj __UNUSED__,
1336                            void *event_info __UNUSED__)
1337 {
1338    Elm_Win_Smart_Data *sd = data;
1339
1340    sd->focus_highlight.geometry_changed = EINA_TRUE;
1341    _elm_win_focus_highlight_reconfigure_job_start(sd);
1342 }
1343
1344 static void
1345 _elm_win_focus_target_resize(void *data,
1346                              Evas *e __UNUSED__,
1347                              Evas_Object *obj __UNUSED__,
1348                              void *event_info __UNUSED__)
1349 {
1350    Elm_Win_Smart_Data *sd = data;
1351
1352    sd->focus_highlight.geometry_changed = EINA_TRUE;
1353    _elm_win_focus_highlight_reconfigure_job_start(sd);
1354 }
1355
1356 static void
1357 _elm_win_focus_target_del(void *data,
1358                           Evas *e __UNUSED__,
1359                           Evas_Object *obj __UNUSED__,
1360                           void *event_info __UNUSED__)
1361 {
1362    Elm_Win_Smart_Data *sd = data;
1363
1364    sd->focus_highlight.cur.target = NULL;
1365
1366    _elm_win_focus_highlight_reconfigure_job_start(sd);
1367 }
1368
1369 static Evas_Object *
1370 _elm_win_focus_target_get(Evas_Object *obj)
1371 {
1372    Evas_Object *o = obj;
1373
1374    do
1375      {
1376         if (elm_widget_is(o))
1377           {
1378              if (!elm_widget_highlight_ignore_get(o))
1379                break;
1380              o = elm_widget_parent_get(o);
1381              if (!o)
1382                o = evas_object_smart_parent_get(o);
1383           }
1384         else
1385           {
1386              o = elm_widget_parent_widget_get(o);
1387              if (!o)
1388                o = evas_object_smart_parent_get(o);
1389           }
1390      }
1391    while (o);
1392
1393    return o;
1394 }
1395
1396 static void
1397 _elm_win_focus_target_callbacks_add(Elm_Win_Smart_Data *sd)
1398 {
1399    Evas_Object *obj = sd->focus_highlight.cur.target;
1400
1401    evas_object_event_callback_add
1402      (obj, EVAS_CALLBACK_MOVE, _elm_win_focus_target_move, sd);
1403    evas_object_event_callback_add
1404      (obj, EVAS_CALLBACK_RESIZE, _elm_win_focus_target_resize, sd);
1405    evas_object_event_callback_add
1406      (obj, EVAS_CALLBACK_DEL, _elm_win_focus_target_del, sd);
1407 }
1408
1409 static void
1410 _elm_win_focus_target_callbacks_del(Elm_Win_Smart_Data *sd)
1411 {
1412    Evas_Object *obj = sd->focus_highlight.cur.target;
1413
1414    evas_object_event_callback_del_full
1415      (obj, EVAS_CALLBACK_MOVE, _elm_win_focus_target_move, sd);
1416    evas_object_event_callback_del_full
1417      (obj, EVAS_CALLBACK_RESIZE, _elm_win_focus_target_resize, sd);
1418    evas_object_event_callback_del_full
1419      (obj, EVAS_CALLBACK_DEL, _elm_win_focus_target_del, sd);
1420 }
1421
1422 static void
1423 _elm_win_object_focus_in(void *data,
1424                          Evas *e __UNUSED__,
1425                          void *event_info)
1426 {
1427    Evas_Object *obj = event_info, *target;
1428    Elm_Win_Smart_Data *sd = data;
1429
1430    if (sd->focus_highlight.cur.target == obj)
1431      return;
1432
1433    target = _elm_win_focus_target_get(obj);
1434    sd->focus_highlight.cur.target = target;
1435    if (elm_widget_highlight_in_theme_get(target))
1436      sd->focus_highlight.cur.handled = EINA_TRUE;
1437    else
1438      _elm_win_focus_target_callbacks_add(sd);
1439
1440    _elm_win_focus_highlight_reconfigure_job_start(sd);
1441 }
1442
1443 static void
1444 _elm_win_object_focus_out(void *data,
1445                           Evas *e __UNUSED__,
1446                           void *event_info __UNUSED__)
1447 {
1448    Elm_Win_Smart_Data *sd = data;
1449
1450    if (!sd->focus_highlight.cur.target)
1451      return;
1452
1453    if (!sd->focus_highlight.cur.handled)
1454      _elm_win_focus_target_callbacks_del(sd);
1455
1456    sd->focus_highlight.cur.target = NULL;
1457    sd->focus_highlight.cur.handled = EINA_FALSE;
1458
1459    _elm_win_focus_highlight_reconfigure_job_start(sd);
1460 }
1461
1462 static void
1463 _elm_win_focus_highlight_shutdown(Elm_Win_Smart_Data *sd)
1464 {
1465    _elm_win_focus_highlight_reconfigure_job_stop(sd);
1466    if (sd->focus_highlight.cur.target)
1467      {
1468         elm_widget_signal_emit(sd->focus_highlight.cur.target,
1469                                "elm,action,focus_highlight,hide", "elm");
1470         _elm_win_focus_target_callbacks_del(sd);
1471         sd->focus_highlight.cur.target = NULL;
1472      }
1473    if (sd->focus_highlight.top)
1474      {
1475         evas_object_del(sd->focus_highlight.top);
1476         sd->focus_highlight.top = NULL;
1477      }
1478
1479    evas_event_callback_del_full
1480      (sd->evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
1481      _elm_win_object_focus_in, sd);
1482    evas_event_callback_del_full
1483      (sd->evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_OUT,
1484      _elm_win_object_focus_out, sd);
1485 }
1486
1487 static void
1488 _elm_win_on_img_obj_del(void *data,
1489                         Evas *e __UNUSED__,
1490                         Evas_Object *obj __UNUSED__,
1491                         void *event_info __UNUSED__)
1492 {
1493    Elm_Win_Smart_Data *sd = data;
1494    sd->img_obj = NULL;
1495 }
1496
1497 static void
1498 _elm_win_resize_objects_eval(Evas_Object *obj)
1499 {
1500    const Eina_List *l;
1501    const Evas_Object *child;
1502
1503    ELM_WIN_DATA_GET(obj, sd);
1504    Evas_Coord w, h, minw = -1, minh = -1, maxw = -1, maxh = -1;
1505    int xx = 1, xy = 1;
1506    double wx, wy;
1507
1508    EINA_LIST_FOREACH(sd->resize_objs, l, child)
1509      {
1510         evas_object_size_hint_weight_get(child, &wx, &wy);
1511         if (wx == 0.0) xx = 0;
1512         if (wy == 0.0) xy = 0;
1513
1514         evas_object_size_hint_min_get(child, &w, &h);
1515         if (w < 1) w = 1;
1516         if (h < 1) h = 1;
1517         if (w > minw) minw = w;
1518         if (h > minh) minh = h;
1519
1520         evas_object_size_hint_max_get(child, &w, &h);
1521         if (w < 1) w = -1;
1522         if (h < 1) h = -1;
1523         if (maxw == -1) maxw = w;
1524         else if ((w > 0) && (w < maxw))
1525           maxw = w;
1526         if (maxh == -1) maxh = h;
1527         else if ((h > 0) && (h < maxh))
1528           maxh = h;
1529      }
1530    if (!xx) maxw = minw;
1531    else maxw = 32767;
1532    if (!xy) maxh = minh;
1533    else maxh = 32767;
1534    evas_object_size_hint_min_set(obj, minw, minh);
1535    evas_object_size_hint_max_set(obj, maxw, maxh);
1536    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
1537    if (w < minw) w = minw;
1538    if (h < minh) h = minh;
1539    if ((maxw >= 0) && (w > maxw)) w = maxw;
1540    if ((maxh >= 0) && (h > maxh)) h = maxh;
1541    evas_object_resize(obj, w, h);
1542 }
1543
1544 static void
1545 _elm_win_on_resize_obj_del(void *data,
1546                            Evas *e __UNUSED__,
1547                            Evas_Object *obj __UNUSED__,
1548                            void *event_info __UNUSED__)
1549 {
1550    ELM_WIN_DATA_GET(data, sd);
1551
1552    sd->resize_objs = eina_list_remove(sd->resize_objs, obj);
1553
1554    _elm_win_resize_objects_eval(data);
1555 }
1556
1557 static void
1558 _elm_win_on_resize_obj_changed_size_hints(void *data,
1559                                           Evas *e __UNUSED__,
1560                                           Evas_Object *obj __UNUSED__,
1561                                           void *event_info __UNUSED__)
1562 {
1563    _elm_win_resize_objects_eval(data);
1564 }
1565
1566 static void
1567 _elm_win_smart_del(Evas_Object *obj)
1568 {
1569    const char *str;
1570    const Eina_List *l;
1571    Evas_Object *child = NULL;
1572
1573    ELM_WIN_DATA_GET(obj, sd);
1574
1575    // TIZEN ONLY (20130422) : For automating default focused UI.
1576    if (sd->obj) sd->obj = NULL;
1577    //
1578
1579    /* NB: child deletion handled by parent's smart del */
1580
1581    if ((trap) && (trap->del))
1582      trap->del(sd->trap_data, obj);
1583
1584    if (sd->parent)
1585      {
1586         evas_object_event_callback_del_full
1587           (sd->parent, EVAS_CALLBACK_DEL, _elm_win_on_parent_del, sd);
1588         sd->parent = NULL;
1589      }
1590
1591    EINA_LIST_FOREACH(sd->resize_objs, l, child)
1592      {
1593         evas_object_event_callback_del_full
1594            (child, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1595             _elm_win_on_resize_obj_changed_size_hints, obj);
1596         evas_object_event_callback_del_full
1597            (child, EVAS_CALLBACK_DEL, _elm_win_on_resize_obj_del, obj);
1598      }
1599
1600    if (sd->autodel_clear) *(sd->autodel_clear) = -1;
1601
1602    _elm_win_list = eina_list_remove(_elm_win_list, obj);
1603    _elm_win_count--;
1604    _elm_win_state_eval_queue();
1605
1606    if (sd->ee)
1607      {
1608         ecore_evas_callback_delete_request_set(sd->ee, NULL);
1609         ecore_evas_callback_resize_set(sd->ee, NULL);
1610      }
1611    if (sd->deferred_resize_job) ecore_job_del(sd->deferred_resize_job);
1612    if (sd->deferred_child_eval_job) ecore_job_del(sd->deferred_child_eval_job);
1613    if (sd->shot.info) eina_stringshare_del(sd->shot.info);
1614    if (sd->shot.timer) ecore_timer_del(sd->shot.timer);
1615
1616 #ifdef HAVE_ELEMENTARY_X
1617    if (sd->x.client_message_handler)
1618      ecore_event_handler_del(sd->x.client_message_handler);
1619    if (sd->x.property_handler)
1620      ecore_event_handler_del(sd->x.property_handler);
1621    // TIZEN ONLY (20130422) : For automating default focused UI.
1622    if (sd->x.mouse_down_handler)
1623      ecore_event_handler_del(sd->x.mouse_down_handler);
1624    if (sd->x.key_down_handler)
1625      ecore_event_handler_del(sd->x.key_down_handler);
1626    //
1627 #endif
1628
1629    if (sd->img_obj)
1630      {
1631         evas_object_event_callback_del_full
1632            (sd->img_obj, EVAS_CALLBACK_DEL, _elm_win_on_img_obj_del, sd);
1633         sd->img_obj = NULL;
1634      }
1635    else
1636      {
1637         if (sd->ee)
1638           {
1639              ecore_job_add(_deferred_ecore_evas_free, sd->ee);
1640              _elm_win_deferred_free++;
1641           }
1642      }
1643
1644    _elm_win_focus_highlight_shutdown(sd);
1645    eina_stringshare_del(sd->focus_highlight.style);
1646
1647    if (sd->title) eina_stringshare_del(sd->title);
1648    if (sd->icon_name) eina_stringshare_del(sd->icon_name);
1649    if (sd->role) eina_stringshare_del(sd->role);
1650    if (sd->icon) evas_object_del(sd->icon);
1651
1652    EINA_LIST_FREE(sd->profile.names, str) eina_stringshare_del(str);
1653    if (sd->profile.name) eina_stringshare_del(sd->profile.name);
1654    if (sd->profile.timer) ecore_timer_del(sd->profile.timer);
1655
1656    if (sd->wm_rot.rots) free(sd->wm_rot.rots);
1657    sd->wm_rot.rots = NULL;
1658
1659    /* Don't let callback in the air that point to sd */
1660    ecore_evas_callback_delete_request_set(sd->ee, NULL);
1661    ecore_evas_callback_resize_set(sd->ee, NULL);
1662    ecore_evas_callback_mouse_in_set(sd->ee, NULL);
1663    ecore_evas_callback_focus_in_set(sd->ee, NULL);
1664    ecore_evas_callback_focus_out_set(sd->ee, NULL);
1665    ecore_evas_callback_move_set(sd->ee, NULL);
1666    ecore_evas_callback_state_change_set(sd->ee, NULL);
1667
1668    _elm_win_parent_sc->base.del(obj); /* handles freeing sd */
1669
1670    if ((!_elm_win_list) &&
1671        (elm_policy_get(ELM_POLICY_QUIT) == ELM_POLICY_QUIT_LAST_WINDOW_CLOSED))
1672      {
1673         edje_file_cache_flush();
1674         edje_collection_cache_flush();
1675         evas_image_cache_flush(evas_object_evas_get(obj));
1676         evas_font_cache_flush(evas_object_evas_get(obj));
1677         elm_exit();
1678      }
1679 }
1680
1681
1682 static void
1683 _elm_win_smart_move(Evas_Object *obj,
1684                     Evas_Coord x,
1685                     Evas_Coord y)
1686 {
1687    ELM_WIN_DATA_GET(obj, sd);
1688
1689    if (sd->img_obj)
1690      {
1691         if ((x != sd->screen.x) || (y != sd->screen.y))
1692           {
1693              sd->screen.x = x;
1694              sd->screen.y = y;
1695              evas_object_smart_callback_call(obj, SIG_MOVED, NULL);
1696           }
1697         return;
1698      }
1699    else
1700      {
1701         TRAP(sd, move, x, y);
1702         if (!ecore_evas_override_get(sd->ee))  return;
1703      }
1704
1705    _elm_win_parent_sc->base.move(obj, x, y);
1706
1707    if (ecore_evas_override_get(sd->ee))
1708      {
1709         sd->screen.x = x;
1710         sd->screen.y = y;
1711         evas_object_smart_callback_call(obj, SIG_MOVED, NULL);
1712      }
1713    if (sd->frame_obj)
1714      {
1715         /* FIXME: We should update ecore_wl_window_location here !! */
1716         sd->screen.x = x;
1717         sd->screen.y = y;
1718      }
1719    if (sd->img_obj)
1720      {
1721         sd->screen.x = x;
1722         sd->screen.y = y;
1723      }
1724 }
1725
1726 static void
1727 _elm_win_smart_resize(Evas_Object *obj,
1728                       Evas_Coord w,
1729                       Evas_Coord h)
1730 {
1731    ELM_WIN_DATA_GET(obj, sd);
1732
1733    _elm_win_parent_sc->base.resize(obj, w, h);
1734
1735    if (sd->img_obj)
1736      {
1737         if (sd->constrain)
1738           {
1739              int sw, sh;
1740
1741              ecore_evas_screen_geometry_get(sd->ee, NULL, NULL, &sw, &sh);
1742              w = MIN(w, sw);
1743              h = MIN(h, sh);
1744           }
1745         if (w < 1) w = 1;
1746         if (h < 1) h = 1;
1747
1748         evas_object_image_size_set(sd->img_obj, w, h);
1749      }
1750
1751    TRAP(sd, resize, w, h);
1752 }
1753
1754 static void
1755 _elm_win_delete_request(Ecore_Evas *ee)
1756 {
1757    Elm_Win_Smart_Data *sd = _elm_win_associate_get(ee);
1758    Evas_Object *obj;
1759
1760    EINA_SAFETY_ON_NULL_RETURN(sd);
1761
1762    obj = ELM_WIDGET_DATA(sd)->obj;
1763
1764    int autodel = sd->autodel;
1765    sd->autodel_clear = &autodel;
1766    evas_object_ref(obj);
1767    evas_object_smart_callback_call(obj, SIG_DELETE_REQUEST, NULL);
1768    // FIXME: if above callback deletes - then the below will be invalid
1769    if (autodel) evas_object_del(obj);
1770    else sd->autodel_clear = NULL;
1771    evas_object_unref(obj);
1772 }
1773
1774 Ecore_X_Window
1775 _elm_ee_xwin_get(const Ecore_Evas *ee)
1776 {
1777 #ifdef HAVE_ELEMENTARY_X
1778    Ecore_X_Window xwin = 0;
1779
1780    if (!ee) return 0;
1781    if (EE_ENGINE_COMPARE(ee, ELM_SOFTWARE_X11))
1782      {
1783         if (ee) xwin = ecore_evas_software_x11_window_get(ee);
1784      }
1785    else if (EE_ENGINE_COMPARE(ee, ELM_SOFTWARE_FB) ||
1786             EE_ENGINE_COMPARE(ee, ELM_SOFTWARE_16_WINCE) ||
1787             EE_ENGINE_COMPARE(ee, ELM_SOFTWARE_SDL) ||
1788             EE_ENGINE_COMPARE(ee, ELM_SOFTWARE_16_SDL) ||
1789             EE_ENGINE_COMPARE(ee, ELM_OPENGL_SDL) ||
1790             EE_ENGINE_COMPARE(ee, ELM_OPENGL_COCOA))
1791      {
1792      }
1793    else if (EE_ENGINE_COMPARE(ee, ELM_SOFTWARE_16_X11))
1794      {
1795         if (ee) xwin = ecore_evas_software_x11_16_window_get(ee);
1796      }
1797    else if (EE_ENGINE_COMPARE(ee, ELM_SOFTWARE_8_X11))
1798      {
1799         if (ee) xwin = ecore_evas_software_x11_8_window_get(ee);
1800      }
1801    else if (EE_ENGINE_COMPARE(ee, ELM_OPENGL_X11))
1802      {
1803         if (ee) xwin = ecore_evas_gl_x11_window_get(ee);
1804      }
1805    else if (EE_ENGINE_COMPARE(ee, ELM_SOFTWARE_WIN32))
1806      {
1807         if (ee) xwin = (long)ecore_evas_win32_window_get(ee);
1808      }
1809    return xwin;
1810
1811 #endif
1812    return 0;
1813 }
1814
1815 #ifdef HAVE_ELEMENTARY_X
1816 static void
1817 _elm_win_xwindow_get(Elm_Win_Smart_Data *sd)
1818 {
1819    sd->x.xwin = _elm_ee_xwin_get(sd->ee);
1820 }
1821
1822 #endif
1823
1824 #ifdef HAVE_ELEMENTARY_X
1825 static void
1826 _elm_win_xwin_update(Elm_Win_Smart_Data *sd)
1827 {
1828    const char *s;
1829
1830    _elm_win_xwindow_get(sd);
1831    if (sd->parent)
1832      {
1833         ELM_WIN_DATA_GET(sd->parent, sdp);
1834         if (sdp)
1835           {
1836              if (sd->x.xwin)
1837                ecore_x_icccm_transient_for_set(sd->x.xwin, sdp->x.xwin);
1838           }
1839      }
1840
1841    if (!sd->x.xwin) return;  /* nothing more to do */
1842
1843    s = sd->title;
1844    if (!s) s = _elm_appname;
1845    if (!s) s = "";
1846    if (sd->icon_name) s = sd->icon_name;
1847    ecore_x_icccm_icon_name_set(sd->x.xwin, s);
1848    ecore_x_netwm_icon_name_set(sd->x.xwin, s);
1849
1850    s = sd->role;
1851    if (s) ecore_x_icccm_window_role_set(sd->x.xwin, s);
1852
1853    // set window icon
1854    if (sd->icon)
1855      {
1856         void *data;
1857
1858         data = evas_object_image_data_get(sd->icon, EINA_FALSE);
1859         if (data)
1860           {
1861              Ecore_X_Icon ic;
1862              int w = 0, h = 0, stride, x, y;
1863              unsigned char *p;
1864              unsigned int *p2;
1865
1866              evas_object_image_size_get(sd->icon, &w, &h);
1867              stride = evas_object_image_stride_get(sd->icon);
1868              if ((w > 0) && (h > 0) &&
1869                  (stride >= (int)(w * sizeof(unsigned int))))
1870                {
1871                   ic.width = w;
1872                   ic.height = h;
1873                   ic.data = malloc(w * h * sizeof(unsigned int));
1874
1875                   if (ic.data)
1876                     {
1877                        p = (unsigned char *)data;
1878                        p2 = (unsigned int *)ic.data;
1879                        for (y = 0; y < h; y++)
1880                          {
1881                             for (x = 0; x < w; x++)
1882                               {
1883                                  *p2 = *((unsigned int *)p);
1884                                  p += sizeof(unsigned int);
1885                                  p2++;
1886                               }
1887                             p += (stride - (w * sizeof(unsigned int)));
1888                          }
1889                        ecore_x_netwm_icons_set(sd->x.xwin, &ic, 1);
1890                        free(ic.data);
1891                     }
1892                }
1893              evas_object_image_data_set(sd->icon, data);
1894           }
1895      }
1896
1897    ecore_x_e_virtual_keyboard_state_set
1898      (sd->x.xwin, (Ecore_X_Virtual_Keyboard_State)sd->kbdmode);
1899    if (sd->indmode == ELM_WIN_INDICATOR_SHOW)
1900      ecore_x_e_illume_indicator_state_set
1901        (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_STATE_ON);
1902    else if (sd->indmode == ELM_WIN_INDICATOR_HIDE)
1903      ecore_x_e_illume_indicator_state_set
1904        (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_STATE_OFF);
1905 }
1906
1907 static void
1908 _elm_win_xwin_type_set(Elm_Win_Smart_Data *sd)
1909 {
1910    _elm_win_xwindow_get(sd);
1911    if (!sd->x.xwin) return;  /* nothing more to do */
1912
1913    switch (sd->type)
1914      {
1915       case ELM_WIN_BASIC:
1916         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_NORMAL);
1917         break;
1918
1919       case ELM_WIN_DIALOG_BASIC:
1920         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_DIALOG);
1921         break;
1922
1923       case ELM_WIN_DESKTOP:
1924         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_DESKTOP);
1925         break;
1926
1927       case ELM_WIN_DOCK:
1928         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_DOCK);
1929         break;
1930
1931       case ELM_WIN_TOOLBAR:
1932         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_TOOLBAR);
1933         break;
1934
1935       case ELM_WIN_MENU:
1936         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_MENU);
1937         break;
1938
1939       case ELM_WIN_UTILITY:
1940         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_UTILITY);
1941         break;
1942
1943       case ELM_WIN_SPLASH:
1944         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_SPLASH);
1945         break;
1946
1947       case ELM_WIN_DROPDOWN_MENU:
1948         ecore_x_netwm_window_type_set
1949           (sd->x.xwin, ECORE_X_WINDOW_TYPE_DROPDOWN_MENU);
1950         break;
1951
1952       case ELM_WIN_POPUP_MENU:
1953         ecore_x_netwm_window_type_set
1954           (sd->x.xwin, ECORE_X_WINDOW_TYPE_POPUP_MENU);
1955         break;
1956
1957       case ELM_WIN_TOOLTIP:
1958         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_TOOLTIP);
1959         break;
1960
1961       case ELM_WIN_NOTIFICATION:
1962         ecore_x_netwm_window_type_set
1963           (sd->x.xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
1964         break;
1965
1966       case ELM_WIN_COMBO:
1967         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_COMBO);
1968         break;
1969
1970       case ELM_WIN_DND:
1971         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_DND);
1972         break;
1973
1974       default:
1975         break;
1976      }
1977
1978    return;
1979 }
1980 #endif
1981
1982
1983 void
1984 _elm_win_shutdown(void)
1985 {
1986    while (_elm_win_list) evas_object_del(_elm_win_list->data);
1987    if (_elm_win_state_eval_job)
1988      {
1989         ecore_job_del(_elm_win_state_eval_job);
1990         _elm_win_state_eval_job = NULL;
1991      }
1992 }
1993
1994 void
1995 _elm_win_rescale(Elm_Theme *th,
1996                  Eina_Bool use_theme)
1997 {
1998    const Eina_List *l;
1999    Evas_Object *obj;
2000
2001    if (!use_theme)
2002      {
2003         EINA_LIST_FOREACH(_elm_win_list, l, obj)
2004           elm_widget_theme(obj);
2005      }
2006    else
2007      {
2008         EINA_LIST_FOREACH(_elm_win_list, l, obj)
2009           elm_widget_theme_specific(obj, th, EINA_FALSE);
2010      }
2011 }
2012
2013 void
2014 _elm_win_access(Eina_Bool is_access)
2015 {
2016    Evas *evas;
2017    const Eina_List *l;
2018    Evas_Object *obj;
2019
2020    EINA_LIST_FOREACH(_elm_win_list, l, obj)
2021      {
2022         elm_widget_access(obj, is_access);
2023         if (!is_access)
2024           {
2025              evas = evas_object_evas_get(obj);
2026             if (evas) _elm_access_object_hilight_disable(evas);
2027           }
2028      }
2029 }
2030
2031 void
2032 _elm_win_translate(void)
2033 {
2034    const Eina_List *l;
2035    Evas_Object *obj;
2036
2037    EINA_LIST_FOREACH(_elm_win_list, l, obj)
2038      elm_widget_translate(obj);
2039 }
2040
2041 #ifdef HAVE_ELEMENTARY_X
2042 static Eina_Bool
2043 _elm_win_client_message(void *data,
2044                         int type __UNUSED__,
2045                         void *event)
2046 {
2047    Elm_Access_Action_Info *a;
2048    Elm_Win_Smart_Data *sd = data;
2049    Ecore_X_Event_Client_Message *e = event;
2050
2051    if (e->format != 32) return ECORE_CALLBACK_PASS_ON;
2052    if (e->message_type == ECORE_X_ATOM_E_COMP_FLUSH)
2053      {
2054         if ((unsigned int)e->data.l[0] == sd->x.xwin)
2055           {
2056              Evas *evas = evas_object_evas_get(ELM_WIDGET_DATA(sd)->obj);
2057              if (evas)
2058                {
2059                   edje_file_cache_flush();
2060                   edje_collection_cache_flush();
2061                   evas_image_cache_flush(evas);
2062                   evas_font_cache_flush(evas);
2063                }
2064           }
2065      }
2066    else if (e->message_type == ECORE_X_ATOM_E_COMP_DUMP)
2067      {
2068         if ((unsigned int)e->data.l[0] == sd->x.xwin)
2069           {
2070              Evas *evas = evas_object_evas_get(ELM_WIDGET_DATA(sd)->obj);
2071              if (evas)
2072                {
2073                   edje_file_cache_flush();
2074                   edje_collection_cache_flush();
2075                   evas_image_cache_flush(evas);
2076                   evas_font_cache_flush(evas);
2077                   evas_render_dump(evas);
2078                }
2079           }
2080      }
2081    else if (e->message_type == ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL)
2082      {
2083         if ((unsigned int)e->data.l[0] == sd->x.xwin)
2084           {
2085              if ((unsigned int)e->data.l[1] ==
2086                  ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_NEXT)
2087                {
2088                   // XXX: call right access func
2089                }
2090              else if ((unsigned int)e->data.l[1] ==
2091                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_PREV)
2092                {
2093                   // XXX: call right access func
2094                }
2095              else if ((unsigned int)e->data.l[1] ==
2096                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ACTIVATE)
2097                {
2098                   _elm_access_highlight_object_activate
2099                     (ELM_WIDGET_DATA(sd)->obj, ELM_ACTIVATE_DEFAULT);
2100                }
2101              else if ((unsigned int)e->data.l[1] ==
2102                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ)
2103                {
2104                   /* there would be better way to read highlight object */
2105                   Evas *evas;
2106                   evas = evas_object_evas_get(ELM_WIDGET_DATA(sd)->obj);
2107                   if (!evas) return ECORE_CALLBACK_PASS_ON;
2108
2109                   a = calloc(1, sizeof(Elm_Access_Action_Info));
2110                   if (!a) return ECORE_CALLBACK_PASS_ON;
2111
2112                   a->x = e->data.l[2];
2113                   a->y = e->data.l[3];
2114                   elm_access_action(ELM_WIDGET_DATA(sd)->obj, ELM_ACCESS_ACTION_HIGHLIGHT, a);
2115                   free(a);
2116                }
2117              else if ((unsigned int)e->data.l[1] ==
2118                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_NEXT)
2119                {
2120                   _elm_access_highlight_cycle(ELM_WIDGET_DATA(sd)->obj, ELM_FOCUS_NEXT);
2121                }
2122              else if ((unsigned int)e->data.l[1] ==
2123                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_PREV)
2124                {
2125                   _elm_access_highlight_cycle(ELM_WIDGET_DATA(sd)->obj, ELM_FOCUS_PREVIOUS);
2126                }
2127              else if ((unsigned int)e->data.l[1] ==
2128                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_UP)
2129                {
2130                   _elm_access_highlight_object_activate
2131                     (ELM_WIDGET_DATA(sd)->obj, ELM_ACTIVATE_UP);
2132                }
2133              else if ((unsigned int)e->data.l[1] ==
2134                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DOWN)
2135                {
2136                   _elm_access_highlight_object_activate
2137                     (ELM_WIDGET_DATA(sd)->obj, ELM_ACTIVATE_DOWN);
2138                }
2139              else if ((unsigned int)e->data.l[1] ==
2140                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_SCROLL)
2141                {
2142                   a = calloc(1, sizeof(Elm_Access_Action_Info));
2143                   if (!a) return ECORE_CALLBACK_PASS_ON;
2144
2145                   a->mouse_type = e->data.l[2];
2146                   a->x = e->data.l[3];
2147                   a->y = e->data.l[4];
2148                   elm_access_action(ELM_WIDGET_DATA(sd)->obj,
2149                                     ELM_ACCESS_ACTION_SCROLL, a);
2150                   free(a);
2151                }
2152              else if ((unsigned int)e->data.l[1] ==
2153                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_MOUSE)
2154                {
2155                   a = calloc(1, sizeof(Elm_Access_Action_Info));
2156                   if (!a) return ECORE_CALLBACK_PASS_ON;
2157
2158                   a->mouse_type = e->data.l[2];
2159                   a->x = e->data.l[3];
2160                   a->y = e->data.l[4];
2161                   elm_access_action(ELM_WIDGET_DATA(sd)->obj,
2162                                     ELM_ACCESS_ACTION_MOUSE, a);
2163                   free(a);
2164                }
2165           }
2166      }
2167    return ECORE_CALLBACK_PASS_ON;
2168 }
2169
2170 static Eina_Bool
2171 _elm_win_property_change(void *data,
2172                          int type __UNUSED__,
2173                          void *event)
2174 {
2175    Elm_Win_Smart_Data *sd = data;
2176    Ecore_X_Event_Window_Property *e = event;
2177
2178    if (e->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_STATE)
2179      {
2180         if (e->win == sd->x.xwin)
2181           {
2182              sd->indmode = ecore_x_e_illume_indicator_state_get(e->win);
2183              evas_object_smart_callback_call(ELM_WIDGET_DATA(sd)->obj, SIG_INDICATOR_PROP_CHANGED, NULL);
2184           }
2185      }
2186    if (e->atom == ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE)
2187      {
2188         if (e->win == sd->x.xwin)
2189           {
2190              sd->kbdmode = ecore_x_e_virtual_keyboard_state_get(e->win);
2191           }
2192      }
2193
2194    // TIZEN ONLY (20130422) : For automating default focused UI.
2195    if (e->atom == keyboard_exist)
2196      {
2197         Ecore_X_Window rootwin_xid = 0;
2198         unsigned int val = 0;
2199
2200         rootwin_xid = ecore_x_window_root_first_get();
2201         if (rootwin_xid)
2202           ecore_x_window_prop_card32_get(rootwin_xid, keyboard_exist, &val, 1);
2203
2204         if (val != 0)
2205           {
2206              sd->keyboard_attached = EINA_TRUE;
2207              elm_win_focus_highlight_enabled_set(sd->obj, EINA_TRUE);
2208           }
2209         else
2210           {
2211              sd->keyboard_attached = EINA_FALSE;
2212              elm_win_focus_highlight_enabled_set(sd->obj, EINA_FALSE);
2213           }
2214      }
2215    //////////////////////
2216
2217    return ECORE_CALLBACK_PASS_ON;
2218 }
2219
2220 // TIZEN ONLY (20130422) : For automating default focused UI.
2221 static Eina_Bool
2222 _elm_win_mouse_button_down(void *data,
2223                            int type __UNUSED__,
2224                            void *event __UNUSED__)
2225 {
2226    Elm_Win_Smart_Data *sd = data;
2227    if (!sd) return ECORE_CALLBACK_PASS_ON;
2228
2229    if (sd->keyboard_attached)
2230      elm_win_focus_highlight_enabled_set(sd->obj, EINA_FALSE);
2231
2232    return ECORE_CALLBACK_PASS_ON;
2233 }
2234
2235 static Eina_Bool
2236 _elm_win_key_down(void *data,
2237                   int type __UNUSED__,
2238                   void *event __UNUSED__)
2239 {
2240    Elm_Win_Smart_Data *sd = data;
2241
2242    if (!sd) return ECORE_CALLBACK_PASS_ON;
2243
2244    if (!sd->first_key_down)
2245      {
2246         Ecore_X_Window rootwin_xid = 0;
2247         unsigned int val = 0;
2248
2249         rootwin_xid = ecore_x_window_root_first_get();
2250         if (rootwin_xid)
2251           ecore_x_window_prop_card32_get(rootwin_xid, keyboard_exist, &val, 1);
2252         if (val != 0)
2253           {
2254              sd->keyboard_attached = EINA_TRUE;
2255              sd->focus_highlight.cur.visible = EINA_TRUE;
2256              elm_win_focus_highlight_enabled_set(sd->obj, EINA_TRUE);
2257           }
2258         sd->first_key_down = EINA_TRUE;
2259      }
2260    else if (sd->keyboard_attached)
2261      {
2262         sd->focus_highlight.cur.visible = EINA_TRUE;
2263         elm_win_focus_highlight_enabled_set(sd->obj, EINA_TRUE);
2264      }
2265
2266    return ECORE_CALLBACK_PASS_ON;
2267 }
2268 ///////////////////////////
2269 #endif
2270
2271 static void
2272 _elm_win_focus_highlight_hide(void *data __UNUSED__,
2273                               Evas_Object *obj,
2274                               const char *emission __UNUSED__,
2275                               const char *source __UNUSED__)
2276 {
2277    evas_object_hide(obj);
2278 }
2279
2280 static void
2281 _elm_win_focus_highlight_anim_end(void *data,
2282                                   Evas_Object *obj,
2283                                   const char *emission __UNUSED__,
2284                                   const char *source __UNUSED__)
2285 {
2286    Elm_Win_Smart_Data *sd = data;
2287
2288    _elm_win_focus_highlight_simple_setup(sd, obj);
2289 }
2290
2291 static void
2292 _elm_win_focus_highlight_init(Elm_Win_Smart_Data *sd)
2293 {
2294    evas_event_callback_add(sd->evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
2295                            _elm_win_object_focus_in, sd);
2296    evas_event_callback_add(sd->evas,
2297                            EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_OUT,
2298                            _elm_win_object_focus_out, sd);
2299
2300    // TIZEN_ONLY (20130713) : For supporting Focused UI of TIZEN.
2301    //sd->focus_highlight.cur.target = evas_focus_get(sd->evas);
2302    sd->focus_highlight.cur.target = _elm_win_focus_target_get(evas_focus_get(sd->evas));
2303    if (elm_widget_highlight_in_theme_get(sd->focus_highlight.cur.target))
2304      sd->focus_highlight.cur.handled = EINA_TRUE;
2305    //////
2306
2307    sd->focus_highlight.top = edje_object_add(sd->evas);
2308    sd->focus_highlight.changed_theme = EINA_TRUE;
2309    edje_object_signal_callback_add(sd->focus_highlight.top,
2310                                    "elm,action,focus,hide,end", "",
2311                                    _elm_win_focus_highlight_hide, NULL);
2312    edje_object_signal_callback_add(sd->focus_highlight.top,
2313                                    "elm,action,focus,anim,end", "",
2314                                    _elm_win_focus_highlight_anim_end, sd);
2315    _elm_win_focus_highlight_reconfigure_job_start(sd);
2316 }
2317
2318 static void
2319 _elm_win_frame_cb_move_start(void *data,
2320                              Evas_Object *obj __UNUSED__,
2321                              const char *sig __UNUSED__,
2322                              const char *source __UNUSED__)
2323 {
2324    Elm_Win_Smart_Data *sd;
2325
2326    if (!(sd = data)) return;
2327    /* FIXME: Change mouse pointer */
2328
2329    /* NB: Wayland handles moving surfaces by itself so we cannot
2330     * specify a specific x/y we want. Instead, we will pass in the
2331     * existing x/y values so they can be recorded as 'previous'
2332     * position. The new position will get updated automatically when
2333     * the move is finished */
2334
2335    ecore_evas_wayland_move(sd->ee, sd->screen.x, sd->screen.y);
2336 }
2337
2338 static void
2339 _elm_win_frame_cb_resize_show(void *data,
2340                               Evas_Object *obj __UNUSED__,
2341                               const char *sig __UNUSED__,
2342                               const char *source)
2343 {
2344    Elm_Win_Smart_Data *sd;
2345
2346    if (!(sd = data)) return;
2347    if (sd->resizing) return;
2348
2349 #ifdef HAVE_ELEMENTARY_WAYLAND
2350    if (!strcmp(source, "elm.event.resize.t"))
2351      ecore_wl_window_cursor_from_name_set(sd->wl.win, ELM_CURSOR_TOP_SIDE);
2352    else if (!strcmp(source, "elm.event.resize.b"))
2353      ecore_wl_window_cursor_from_name_set(sd->wl.win, ELM_CURSOR_BOTTOM_SIDE);
2354    else if (!strcmp(source, "elm.event.resize.l"))
2355      ecore_wl_window_cursor_from_name_set(sd->wl.win, ELM_CURSOR_LEFT_SIDE);
2356    else if (!strcmp(source, "elm.event.resize.r"))
2357      ecore_wl_window_cursor_from_name_set(sd->wl.win, ELM_CURSOR_RIGHT_SIDE);
2358    else if (!strcmp(source, "elm.event.resize.tl"))
2359      ecore_wl_window_cursor_from_name_set(sd->wl.win,
2360                                           ELM_CURSOR_TOP_LEFT_CORNER);
2361    else if (!strcmp(source, "elm.event.resize.tr"))
2362      ecore_wl_window_cursor_from_name_set(sd->wl.win,
2363                                           ELM_CURSOR_TOP_RIGHT_CORNER);
2364    else if (!strcmp(source, "elm.event.resize.bl"))
2365      ecore_wl_window_cursor_from_name_set(sd->wl.win,
2366                                           ELM_CURSOR_BOTTOM_LEFT_CORNER);
2367    else if (!strcmp(source, "elm.event.resize.br"))
2368      ecore_wl_window_cursor_from_name_set(sd->wl.win,
2369                                           ELM_CURSOR_BOTTOM_RIGHT_CORNER);
2370    else
2371      ecore_wl_window_cursor_default_restore(sd->wl.win);
2372 #else
2373    (void)source;
2374 #endif
2375 }
2376
2377 static void
2378 _elm_win_frame_cb_resize_hide(void *data,
2379                               Evas_Object *obj __UNUSED__,
2380                               const char *sig __UNUSED__,
2381                               const char *source __UNUSED__)
2382 {
2383    Elm_Win_Smart_Data *sd;
2384
2385    if (!(sd = data)) return;
2386    if (sd->resizing) return;
2387
2388 #ifdef HAVE_ELEMENTARY_WAYLAND
2389    ecore_wl_window_cursor_default_restore(sd->wl.win);
2390 #endif
2391 }
2392
2393 static void
2394 _elm_win_frame_cb_resize_start(void *data,
2395                                Evas_Object *obj __UNUSED__,
2396                                const char *sig __UNUSED__,
2397                                const char *source)
2398 {
2399    Elm_Win_Smart_Data *sd;
2400
2401    if (!(sd = data)) return;
2402    if (sd->resizing) return;
2403
2404    sd->resizing = EINA_TRUE;
2405
2406    if (!strcmp(source, "elm.event.resize.t"))
2407      sd->resize_location = 1;
2408    else if (!strcmp(source, "elm.event.resize.b"))
2409      sd->resize_location = 2;
2410    else if (!strcmp(source, "elm.event.resize.l"))
2411      sd->resize_location = 4;
2412    else if (!strcmp(source, "elm.event.resize.r"))
2413      sd->resize_location = 8;
2414    else if (!strcmp(source, "elm.event.resize.tl"))
2415      sd->resize_location = 5;
2416    else if (!strcmp(source, "elm.event.resize.tr"))
2417      sd->resize_location = 9;
2418    else if (!strcmp(source, "elm.event.resize.bl"))
2419      sd->resize_location = 6;
2420    else if (!strcmp(source, "elm.event.resize.br"))
2421      sd->resize_location = 10;
2422    else
2423      sd->resize_location = 0;
2424
2425    if (sd->resize_location > 0)
2426      ecore_evas_wayland_resize(sd->ee, sd->resize_location);
2427 }
2428
2429 static void
2430 _elm_win_frame_cb_minimize(void *data,
2431                            Evas_Object *obj __UNUSED__,
2432                            const char *sig __UNUSED__,
2433                            const char *source __UNUSED__)
2434 {
2435    Elm_Win_Smart_Data *sd;
2436
2437    if (!(sd = data)) return;
2438 // sd->iconified = EINA_TRUE;
2439    TRAP(sd, iconified_set, EINA_TRUE);
2440 }
2441
2442 static void
2443 _elm_win_frame_cb_maximize(void *data,
2444                            Evas_Object *obj __UNUSED__,
2445                            const char *sig __UNUSED__,
2446                            const char *source __UNUSED__)
2447 {
2448    Elm_Win_Smart_Data *sd;
2449
2450    if (!(sd = data)) return;
2451    if (sd->maximized) sd->maximized = EINA_FALSE;
2452    else sd->maximized = EINA_TRUE;
2453    TRAP(sd, maximized_set, sd->maximized);
2454 }
2455
2456 static void
2457 _elm_win_frame_cb_close(void *data,
2458                         Evas_Object *obj __UNUSED__,
2459                         const char *sig __UNUSED__,
2460                         const char *source __UNUSED__)
2461 {
2462    Elm_Win_Smart_Data *sd;
2463    Evas_Object *win;
2464
2465    /* FIXME: After the current freeze, this should be handled differently.
2466     *
2467     * Ideally, we would want to mimic the X11 backend and use something
2468     * like ECORE_WL_EVENT_WINDOW_DELETE and handle the delete_request
2469     * inside of ecore_evas. That would be the 'proper' way, but since we are
2470     * in a freeze right now, I cannot add a new event value, or a new
2471     * event structure to ecore_wayland.
2472     *
2473     * So yes, this is a temporary 'stop-gap' solution which will be fixed
2474     * when the freeze is over, but it does fix a trac bug for now, and in a
2475     * way which does not break API or the freeze. - dh
2476     */
2477
2478    if (!(sd = data)) return;
2479
2480    win = ELM_WIDGET_DATA(sd)->obj;
2481
2482    int autodel = sd->autodel;
2483    sd->autodel_clear = &autodel;
2484    evas_object_ref(win);
2485    evas_object_smart_callback_call(win, SIG_DELETE_REQUEST, NULL);
2486    // FIXME: if above callback deletes - then the below will be invalid
2487    if (autodel) evas_object_del(win);
2488    else sd->autodel_clear = NULL;
2489    evas_object_unref(win);
2490 }
2491
2492 static void
2493 _elm_win_frame_add(Elm_Win_Smart_Data *sd,
2494                    const char *style)
2495 {
2496    evas_output_framespace_set(sd->evas, 0, 22, 0, 26);
2497
2498    sd->frame_obj = edje_object_add(sd->evas);
2499    elm_widget_theme_object_set
2500      (ELM_WIDGET_DATA(sd)->obj, sd->frame_obj, "border", "base", style);
2501
2502    evas_object_is_frame_object_set(sd->frame_obj, EINA_TRUE);
2503    evas_object_move(sd->frame_obj, 0, 0);
2504    evas_object_resize(sd->frame_obj, 1, 1);
2505
2506    edje_object_signal_callback_add
2507      (sd->frame_obj, "elm,action,move,start", "elm",
2508      _elm_win_frame_cb_move_start, sd);
2509    edje_object_signal_callback_add
2510      (sd->frame_obj, "elm,action,resize,show", "*",
2511      _elm_win_frame_cb_resize_show, sd);
2512    edje_object_signal_callback_add
2513      (sd->frame_obj, "elm,action,resize,hide", "*",
2514      _elm_win_frame_cb_resize_hide, sd);
2515    edje_object_signal_callback_add
2516      (sd->frame_obj, "elm,action,resize,start", "*",
2517      _elm_win_frame_cb_resize_start, sd);
2518    edje_object_signal_callback_add
2519      (sd->frame_obj, "elm,action,minimize", "elm",
2520      _elm_win_frame_cb_minimize, sd);
2521    edje_object_signal_callback_add
2522      (sd->frame_obj, "elm,action,maximize", "elm",
2523      _elm_win_frame_cb_maximize, sd);
2524    edje_object_signal_callback_add
2525      (sd->frame_obj, "elm,action,close", "elm", _elm_win_frame_cb_close, sd);
2526
2527    if (sd->title)
2528      {
2529         edje_object_part_text_escaped_set
2530           (sd->frame_obj, "elm.text.title", sd->title);
2531      }
2532 }
2533
2534 static void
2535 _elm_win_frame_del(Elm_Win_Smart_Data *sd)
2536 {
2537    if (sd->frame_obj)
2538      {
2539         edje_object_signal_callback_del
2540           (sd->frame_obj, "elm,action,move,start", "elm",
2541               _elm_win_frame_cb_move_start);
2542         edje_object_signal_callback_del
2543           (sd->frame_obj, "elm,action,resize,show", "*",
2544               _elm_win_frame_cb_resize_show);
2545         edje_object_signal_callback_del
2546           (sd->frame_obj, "elm,action,resize,hide", "*",
2547               _elm_win_frame_cb_resize_hide);
2548         edje_object_signal_callback_del
2549           (sd->frame_obj, "elm,action,resize,start", "*",
2550               _elm_win_frame_cb_resize_start);
2551         edje_object_signal_callback_del
2552           (sd->frame_obj, "elm,action,minimize", "elm",
2553               _elm_win_frame_cb_minimize);
2554         edje_object_signal_callback_del
2555           (sd->frame_obj, "elm,action,maximize", "elm",
2556               _elm_win_frame_cb_maximize);
2557         edje_object_signal_callback_del
2558           (sd->frame_obj, "elm,action,close", "elm",
2559               _elm_win_frame_cb_close);
2560
2561         evas_object_del(sd->frame_obj);
2562         sd->frame_obj = NULL;
2563      }
2564
2565    evas_output_framespace_set(sd->evas, 0, 0, 0, 0);
2566 }
2567
2568 #ifdef ELM_DEBUG
2569 static void
2570 _debug_key_down(void *data __UNUSED__,
2571                 Evas *e __UNUSED__,
2572                 Evas_Object *obj,
2573                 void *event_info)
2574 {
2575    Evas_Event_Key_Down *ev = event_info;
2576
2577    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
2578      return;
2579
2580    if ((strcmp(ev->keyname, "F12")) ||
2581        (!evas_key_modifier_is_set(ev->modifiers, "Control")))
2582      return;
2583
2584    printf("Tree graph generated.\n");
2585    elm_object_tree_dot_dump(obj, "./dump.dot");
2586 }
2587
2588 #endif
2589
2590 static void
2591 _win_img_hide(void *data,
2592               Evas *e __UNUSED__,
2593               Evas_Object *obj __UNUSED__,
2594               void *event_info __UNUSED__)
2595 {
2596    Elm_Win_Smart_Data *sd = data;
2597
2598    elm_widget_focus_hide_handle(ELM_WIDGET_DATA(sd)->obj);
2599 }
2600
2601 static void
2602 _win_img_mouse_up(void *data,
2603                   Evas *e __UNUSED__,
2604                   Evas_Object *obj __UNUSED__,
2605                   void *event_info)
2606 {
2607    Elm_Win_Smart_Data *sd = data;
2608    Evas_Event_Mouse_Up *ev = event_info;
2609    if (!(ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD))
2610      elm_widget_focus_mouse_up_handle(ELM_WIDGET_DATA(sd)->obj);
2611 }
2612
2613 static void
2614 _win_img_focus_in(void *data,
2615                   Evas *e __UNUSED__,
2616                   Evas_Object *obj __UNUSED__,
2617                   void *event_info __UNUSED__)
2618 {
2619    Elm_Win_Smart_Data *sd = data;
2620    elm_widget_focus_steal(ELM_WIDGET_DATA(sd)->obj);
2621 }
2622
2623 static void
2624 _win_img_focus_out(void *data,
2625                    Evas *e __UNUSED__,
2626                    Evas_Object *obj __UNUSED__,
2627                    void *event_info __UNUSED__)
2628 {
2629    Elm_Win_Smart_Data *sd = data;
2630    elm_widget_focused_object_clear(ELM_WIDGET_DATA(sd)->obj);
2631 }
2632
2633 static void
2634 _win_inlined_image_set(Elm_Win_Smart_Data *sd)
2635 {
2636    evas_object_image_alpha_set(sd->img_obj, EINA_FALSE);
2637    evas_object_image_filled_set(sd->img_obj, EINA_TRUE);
2638
2639    evas_object_event_callback_add
2640      (sd->img_obj, EVAS_CALLBACK_DEL, _elm_win_on_img_obj_del, sd);
2641    evas_object_event_callback_add
2642      (sd->img_obj, EVAS_CALLBACK_HIDE, _win_img_hide, sd);
2643    evas_object_event_callback_add
2644      (sd->img_obj, EVAS_CALLBACK_MOUSE_UP, _win_img_mouse_up, sd);
2645    evas_object_event_callback_add
2646      (sd->img_obj, EVAS_CALLBACK_FOCUS_IN, _win_img_focus_in, sd);
2647    evas_object_event_callback_add
2648      (sd->img_obj, EVAS_CALLBACK_FOCUS_OUT, _win_img_focus_out, sd);
2649 }
2650
2651 static void
2652 _elm_win_on_icon_del(void *data,
2653                      Evas *e __UNUSED__,
2654                      Evas_Object *obj,
2655                      void *event_info __UNUSED__)
2656 {
2657    Elm_Win_Smart_Data *sd = data;
2658
2659    if (sd->icon == obj) sd->icon = NULL;
2660 }
2661
2662 static void
2663 _elm_win_smart_add(Evas_Object *obj)
2664 {
2665    EVAS_SMART_DATA_ALLOC(obj, Elm_Win_Smart_Data);
2666
2667    _elm_win_parent_sc->base.add(obj);
2668
2669    elm_widget_can_focus_set(obj, EINA_TRUE);
2670
2671    elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2672 }
2673
2674 static void
2675 _elm_win_smart_set_user(Elm_Widget_Smart_Class *sc)
2676 {
2677    sc->base.add = _elm_win_smart_add;
2678    sc->base.del = _elm_win_smart_del;
2679    sc->base.show = _elm_win_smart_show;
2680    sc->base.hide = _elm_win_smart_hide;
2681    sc->base.move = _elm_win_smart_move;
2682    sc->base.resize = _elm_win_smart_resize;
2683
2684    sc->focus_next = _elm_win_smart_focus_next;
2685    sc->focus_direction = _elm_win_smart_focus_direction;
2686    sc->on_focus = _elm_win_smart_on_focus;
2687    sc->event = _elm_win_smart_event;
2688 }
2689
2690 #ifdef HAVE_ELEMENTARY_X
2691 static void
2692 _elm_x_io_err(void *data __UNUSED__)
2693 {
2694    Eina_List *l;
2695    Evas_Object *obj;
2696
2697    EINA_LIST_FOREACH(_elm_win_list, l, obj)
2698      evas_object_smart_callback_call(obj, SIG_IOERR, NULL);
2699    elm_exit();
2700 }
2701 #endif
2702
2703 static void
2704 _elm_win_cb_hide(void *data __UNUSED__,
2705                  Evas *e __UNUSED__,
2706                  Evas_Object *obj __UNUSED__,
2707                  void *event_info __UNUSED__)
2708 {
2709    _elm_win_state_eval_queue();
2710 }
2711
2712 static void
2713 _elm_win_cb_show(void *data __UNUSED__,
2714                  Evas *e __UNUSED__,
2715                  Evas_Object *obj __UNUSED__,
2716                  void *event_info __UNUSED__)
2717 {
2718    _elm_win_state_eval_queue();
2719 }
2720
2721 EAPI Evas_Object *
2722 elm_win_add(Evas_Object *parent,
2723             const char *name,
2724             Elm_Win_Type type)
2725 {
2726    Evas *e;
2727    Evas_Object *obj;
2728    const Eina_List *l;
2729    const char *fontpath, *fallback = NULL;
2730
2731    Elm_Win_Smart_Data tmp_sd;
2732
2733    /* just to store some data while trying out to create a canvas */
2734    memset(&tmp_sd, 0, sizeof(Elm_Win_Smart_Data));
2735
2736 #define FALLBACK_TRY(engine)                                      \
2737   if (!tmp_sd.ee) {                                               \
2738      CRITICAL(engine " engine creation failed. Trying default."); \
2739      tmp_sd.ee = ecore_evas_new(NULL, 0, 0, 1, 1, NULL);          \
2740      if (tmp_sd.ee)                                               \
2741        elm_config_preferred_engine_set(ecore_evas_engine_name_get(tmp_sd.ee)); \
2742   } while (0)
2743 #define FALLBACK_STORE(engine)                               \
2744    if (tmp_sd.ee)                                            \
2745    {                                                         \
2746       CRITICAL(engine "Fallback to %s successful.", engine); \
2747       fallback = engine;                                     \
2748    }
2749
2750    switch (type)
2751      {
2752       case ELM_WIN_INLINED_IMAGE:
2753         if (!parent) break;
2754         {
2755            e = evas_object_evas_get(parent);
2756            Ecore_Evas *ee;
2757
2758            if (!e) break;
2759
2760            ee = ecore_evas_ecore_evas_get(e);
2761            if (!ee) break;
2762
2763            tmp_sd.img_obj = ecore_evas_object_image_new(ee);
2764            if (!tmp_sd.img_obj) break;
2765
2766            tmp_sd.ee = ecore_evas_object_ecore_evas_get(tmp_sd.img_obj);
2767            if (!tmp_sd.ee)
2768              {
2769                 evas_object_del(tmp_sd.img_obj);
2770                 tmp_sd.img_obj = NULL;
2771              }
2772         }
2773         break;
2774
2775       case ELM_WIN_SOCKET_IMAGE:
2776         tmp_sd.ee = ecore_evas_extn_socket_new(1, 1);
2777         break;
2778
2779       default:
2780         if (ENGINE_COMPARE(ELM_SOFTWARE_X11))
2781           {
2782              tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2783              FALLBACK_TRY("Software X11");
2784              if (!tmp_sd.ee)
2785                {
2786                   tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2787                   FALLBACK_STORE("Software FB");
2788                }
2789           }
2790         else if (ENGINE_COMPARE(ELM_SOFTWARE_FB))
2791           {
2792              tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2793              FALLBACK_TRY("Software FB");
2794              if (!tmp_sd.ee)
2795                {
2796                   tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2797                   FALLBACK_STORE("Software X11");
2798                }
2799           }
2800         else if (ENGINE_COMPARE(ELM_SOFTWARE_DIRECTFB))
2801           {
2802              tmp_sd.ee = ecore_evas_directfb_new(NULL, 1, 0, 0, 1, 1);
2803              FALLBACK_TRY("Software DirectFB");
2804              if (!tmp_sd.ee)
2805                {
2806                   tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2807                   FALLBACK_STORE("Software X11");
2808                   if (!tmp_sd.ee)
2809                     {
2810                        tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2811                        FALLBACK_STORE("Software FB");
2812                     }
2813                }
2814           }
2815         else if (ENGINE_COMPARE(ELM_SOFTWARE_16_X11))
2816           {
2817              tmp_sd.ee = ecore_evas_software_x11_16_new(NULL, 0, 0, 0, 1, 1);
2818              FALLBACK_TRY("Software-16");
2819              if (!tmp_sd.ee)
2820                {
2821                   tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2822                   FALLBACK_STORE("Software X11");
2823                   if (!tmp_sd.ee)
2824                     {
2825                        tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2826                        FALLBACK_STORE("Software FB");
2827                     }
2828                }
2829           }
2830         else if (ENGINE_COMPARE(ELM_SOFTWARE_8_X11))
2831           {
2832              tmp_sd.ee = ecore_evas_software_x11_8_new(NULL, 0, 0, 0, 1, 1);
2833              FALLBACK_TRY("Software-8");
2834              if (!tmp_sd.ee)
2835                {
2836                   tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2837                   FALLBACK_STORE("Software X11");
2838                   if (!tmp_sd.ee)
2839                     {
2840                        tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2841                        FALLBACK_STORE("Software FB");
2842                     }
2843                }
2844           }
2845         else if (ENGINE_COMPARE(ELM_OPENGL_X11))
2846           {
2847              int opt[10];
2848              int opt_i = 0;
2849
2850              if (_elm_config->vsync)
2851                {
2852                   opt[opt_i] = ECORE_EVAS_GL_X11_OPT_VSYNC;
2853                   opt_i++;
2854                   opt[opt_i] = 1;
2855                   opt_i++;
2856                                   opt[opt_i] = 0;
2857                }
2858              if (opt_i > 0)
2859                tmp_sd.ee = ecore_evas_gl_x11_options_new
2860                    (NULL, 0, 0, 0, 1, 1, opt);
2861              else
2862                tmp_sd.ee = ecore_evas_gl_x11_new(NULL, 0, 0, 0, 1, 1);
2863              FALLBACK_TRY("OpenGL");
2864              if (!tmp_sd.ee)
2865                {
2866                   tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2867                   FALLBACK_STORE("Software X11");
2868                   if (!tmp_sd.ee)
2869                     {
2870                        tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2871                        FALLBACK_STORE("Software FB");
2872                     }
2873                }
2874           }
2875         else if (ENGINE_COMPARE(ELM_SOFTWARE_WIN32))
2876           {
2877              tmp_sd.ee = ecore_evas_software_gdi_new(NULL, 0, 0, 1, 1);
2878              FALLBACK_TRY("Software Win32");
2879           }
2880         else if (ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE))
2881           {
2882              tmp_sd.ee = ecore_evas_software_wince_gdi_new(NULL, 0, 0, 1, 1);
2883              FALLBACK_TRY("Software-16-WinCE");
2884           }
2885         else if (ENGINE_COMPARE(ELM_SOFTWARE_PSL1GHT))
2886           {
2887              tmp_sd.ee = ecore_evas_psl1ght_new(NULL, 1, 1);
2888              FALLBACK_TRY("PSL1GHT");
2889           }
2890         else if (ENGINE_COMPARE(ELM_SOFTWARE_SDL))
2891           {
2892              tmp_sd.ee = ecore_evas_sdl_new(NULL, 0, 0, 0, 0, 0, 1);
2893              FALLBACK_TRY("Software SDL");
2894              if (!tmp_sd.ee)
2895                {
2896                   tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2897                   FALLBACK_STORE("Software X11");
2898                   if (!tmp_sd.ee)
2899                     {
2900                        tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2901                        FALLBACK_STORE("Software FB");
2902                     }
2903                }
2904           }
2905         else if (ENGINE_COMPARE(ELM_SOFTWARE_16_SDL))
2906           {
2907              tmp_sd.ee = ecore_evas_sdl16_new(NULL, 0, 0, 0, 0, 0, 1);
2908              FALLBACK_TRY("Software-16-SDL");
2909              if (!tmp_sd.ee)
2910                {
2911                   tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2912                   FALLBACK_STORE("Software X11");
2913                   if (!tmp_sd.ee)
2914                     {
2915                        tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2916                        FALLBACK_STORE("Software FB");
2917                     }
2918                }
2919           }
2920         else if (ENGINE_COMPARE(ELM_OPENGL_SDL))
2921           {
2922              tmp_sd.ee = ecore_evas_gl_sdl_new(NULL, 1, 1, 0, 0);
2923              FALLBACK_TRY("OpenGL SDL");
2924              if (!tmp_sd.ee)
2925                {
2926                   tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
2927                   FALLBACK_STORE("Software X11");
2928                   if (!tmp_sd.ee)
2929                     {
2930                        tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
2931                        FALLBACK_STORE("Software FB");
2932                     }
2933                }
2934           }
2935         else if (ENGINE_COMPARE(ELM_OPENGL_COCOA))
2936           {
2937              tmp_sd.ee = ecore_evas_cocoa_new(NULL, 1, 1, 0, 0);
2938              FALLBACK_TRY("OpenGL Cocoa");
2939           }
2940         else if (ENGINE_COMPARE(ELM_BUFFER))
2941           {
2942              tmp_sd.ee = ecore_evas_buffer_new(1, 1);
2943           }
2944         else if (ENGINE_COMPARE(ELM_EWS))
2945           {
2946              tmp_sd.ee = ecore_evas_ews_new(0, 0, 1, 1);
2947           }
2948         else if (ENGINE_COMPARE(ELM_WAYLAND_SHM))
2949           {
2950              tmp_sd.ee = ecore_evas_wayland_shm_new(NULL, 0, 0, 0, 1, 1, 0);
2951           }
2952         else if (ENGINE_COMPARE(ELM_WAYLAND_EGL))
2953           {
2954              tmp_sd.ee = ecore_evas_wayland_egl_new(NULL, 0, 0, 0, 1, 1, 0);
2955           }
2956         else if (!strncmp(ENGINE_GET(), "shot:", 5))
2957           {
2958              tmp_sd.ee = ecore_evas_buffer_new(1, 1);
2959              ecore_evas_manual_render_set(tmp_sd.ee, EINA_TRUE);
2960              tmp_sd.shot.info = eina_stringshare_add
2961                  (ENGINE_GET() + 5);
2962           }
2963 #undef FALLBACK_TRY
2964         break;
2965      }
2966
2967    if (!tmp_sd.ee)
2968      {
2969         ERR("Cannot create window.");
2970         return NULL;
2971      }
2972
2973    obj = evas_object_smart_add
2974        (ecore_evas_get(tmp_sd.ee), _elm_win_smart_class_new());
2975
2976    ELM_WIN_DATA_GET(obj, sd);
2977
2978    // TIZEN ONLY (20130422) : For automating default focused UI.
2979    sd->obj = obj;
2980    sd->keyboard_attached = EINA_FALSE;
2981    sd->first_key_down = EINA_FALSE;
2982    //
2983
2984    /* copying possibly altered fields back */
2985 #define SD_CPY(_field)             \
2986   do                               \
2987     {                              \
2988        sd->_field = tmp_sd._field; \
2989     } while (0)
2990
2991    SD_CPY(ee);
2992    SD_CPY(img_obj);
2993    SD_CPY(shot.info);
2994 #undef SD_CPY
2995
2996    if ((trap) && (trap->add))
2997      sd->trap_data = trap->add(obj);
2998
2999    /* complementary actions, which depend on final smart data
3000     * pointer */
3001    if (type == ELM_WIN_INLINED_IMAGE)
3002      _win_inlined_image_set(sd);
3003
3004 #ifdef HAVE_ELEMENTARY_X
3005     else if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
3006             ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
3007             ENGINE_COMPARE(ELM_SOFTWARE_8_X11) ||
3008             ENGINE_COMPARE(ELM_OPENGL_X11))
3009      {
3010         // TIZEN ONLY (20130422) : For automating default focused UI.
3011         keyboard_exist = ecore_x_atom_get("X External Keyboard Exist");
3012
3013         sd->x.mouse_down_handler = ecore_event_handler_add
3014             (ECORE_EVENT_MOUSE_BUTTON_DOWN, _elm_win_mouse_button_down, sd);
3015         sd->x.key_down_handler = ecore_event_handler_add
3016             (ECORE_EVENT_KEY_DOWN, _elm_win_key_down, sd);
3017         /////////////
3018         sd->x.client_message_handler = ecore_event_handler_add
3019             (ECORE_X_EVENT_CLIENT_MESSAGE, _elm_win_client_message, sd);
3020         sd->x.property_handler = ecore_event_handler_add
3021             (ECORE_X_EVENT_WINDOW_PROPERTY, _elm_win_property_change, sd);
3022      }
3023 #endif
3024
3025    else if (!strncmp(ENGINE_GET(), "shot:", 5))
3026      _shot_init(sd);
3027
3028    sd->kbdmode = ELM_WIN_KEYBOARD_UNKNOWN;
3029    sd->indmode = ELM_WIN_INDICATOR_UNKNOWN;
3030
3031 #ifdef HAVE_ELEMENTARY_X
3032    _elm_win_xwindow_get(sd);
3033    if (sd->x.xwin)
3034      {
3035         ecore_x_io_error_handler_set(_elm_x_io_err, NULL);
3036      }
3037 #endif
3038
3039 #ifdef HAVE_ELEMENTARY_WAYLAND
3040    sd->wl.win = ecore_evas_wayland_window_get(sd->ee);
3041 #endif
3042
3043    if ((_elm_config->bgpixmap)
3044 #ifdef HAVE_ELEMENTARY_X
3045        &&
3046        (((sd->x.xwin) && (!ecore_x_screen_is_composited(0))) ||
3047            (!sd->x.xwin))
3048 #endif
3049       )
3050      TRAP(sd, avoid_damage_set, ECORE_EVAS_AVOID_DAMAGE_EXPOSE);
3051    // bg pixmap done by x - has other issues like can be redrawn by x before it
3052    // is filled/ready by app
3053    //     TRAP(sd, avoid_damage_set, ECORE_EVAS_AVOID_DAMAGE_BUILT_IN);
3054
3055    sd->type = type;
3056    sd->parent = parent;
3057
3058    if (sd->parent)
3059      evas_object_event_callback_add
3060        (sd->parent, EVAS_CALLBACK_DEL, _elm_win_on_parent_del, sd);
3061
3062    sd->evas = ecore_evas_get(sd->ee);
3063
3064    evas_object_color_set(obj, 0, 0, 0, 0);
3065    evas_object_move(obj, 0, 0);
3066    evas_object_resize(obj, 1, 1);
3067    evas_object_layer_set(obj, 50);
3068    evas_object_pass_events_set(obj, EINA_TRUE);
3069
3070    if (type == ELM_WIN_INLINED_IMAGE)
3071      elm_widget_parent2_set(obj, parent);
3072
3073    /* use own version of ecore_evas_object_associate() that does TRAP() */
3074    ecore_evas_data_set(sd->ee, "elm_win", sd);
3075
3076    evas_object_event_callback_add
3077      (obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
3078       _elm_win_obj_callback_changed_size_hints, sd);
3079
3080    evas_object_intercept_raise_callback_add
3081      (obj, _elm_win_obj_intercept_raise, sd);
3082    evas_object_intercept_lower_callback_add
3083      (obj, _elm_win_obj_intercept_lower, sd);
3084    evas_object_intercept_stack_above_callback_add
3085      (obj, _elm_win_obj_intercept_stack_above, sd);
3086    evas_object_intercept_stack_below_callback_add
3087      (obj, _elm_win_obj_intercept_stack_below, sd);
3088    evas_object_intercept_layer_set_callback_add
3089      (obj, _elm_win_obj_intercept_layer_set, sd);
3090    evas_object_intercept_show_callback_add
3091      (obj, _elm_win_obj_intercept_show, sd);
3092    evas_object_intercept_move_callback_add
3093      (obj, _ecore_evas_move_, sd);
3094
3095    TRAP(sd, name_class_set, name, _elm_appname);
3096    ecore_evas_callback_delete_request_set(sd->ee, _elm_win_delete_request);
3097    ecore_evas_callback_resize_set(sd->ee, _elm_win_resize);
3098    ecore_evas_callback_mouse_in_set(sd->ee, _elm_win_mouse_in);
3099    ecore_evas_callback_focus_in_set(sd->ee, _elm_win_focus_in);
3100    ecore_evas_callback_focus_out_set(sd->ee, _elm_win_focus_out);
3101    ecore_evas_callback_move_set(sd->ee, _elm_win_move);
3102    ecore_evas_callback_state_change_set(sd->ee, _elm_win_state_change);
3103    evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _elm_win_cb_hide, sd);
3104    evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _elm_win_cb_show, sd);
3105
3106    evas_image_cache_set(sd->evas, (_elm_config->image_cache * 1024));
3107    evas_font_cache_set(sd->evas, (_elm_config->font_cache * 1024));
3108
3109    EINA_LIST_FOREACH(_elm_config->font_dirs, l, fontpath)
3110      evas_font_path_append(sd->evas, fontpath);
3111
3112    if (!_elm_config->font_hinting)
3113      evas_font_hinting_set(sd->evas, EVAS_FONT_HINTING_NONE);
3114    else if (_elm_config->font_hinting == 1)
3115      evas_font_hinting_set(sd->evas, EVAS_FONT_HINTING_AUTO);
3116    else if (_elm_config->font_hinting == 2)
3117      evas_font_hinting_set(sd->evas, EVAS_FONT_HINTING_BYTECODE);
3118
3119 #ifdef HAVE_ELEMENTARY_X
3120    _elm_win_xwin_type_set(sd);
3121    _elm_win_xwin_update(sd);
3122 #endif
3123
3124    _elm_win_list = eina_list_append(_elm_win_list, obj);
3125    _elm_win_count++;
3126
3127    if (((fallback) && (!strcmp(fallback, "Software FB"))) ||
3128        ((!fallback) && (ENGINE_COMPARE(ELM_SOFTWARE_FB))))
3129      {
3130         TRAP(sd, fullscreen_set, 1);
3131      }
3132    else if ((type != ELM_WIN_INLINED_IMAGE) &&
3133             (ENGINE_COMPARE(ELM_WAYLAND_SHM) ||
3134              ENGINE_COMPARE(ELM_WAYLAND_EGL)))
3135      _elm_win_frame_add(sd, "default");
3136
3137    if (_elm_config->focus_highlight_enable)
3138      elm_win_focus_highlight_enabled_set(obj, EINA_TRUE);
3139
3140 #ifdef ELM_DEBUG
3141    Evas_Modifier_Mask mask = evas_key_modifier_mask_get(sd->evas, "Control");
3142    evas_object_event_callback_add
3143      (obj, EVAS_CALLBACK_KEY_DOWN, _debug_key_down, sd);
3144
3145    if (evas_object_key_grab(obj, "F12", mask, 0, EINA_TRUE))
3146      INF("Ctrl+F12 key combination exclusive for dot tree generation\n");
3147    else
3148      ERR("failed to grab F12 key to elm widgets (dot) tree generation");
3149 #endif
3150
3151    if ((_elm_config->softcursor_mode == ELM_SOFTCURSOR_MODE_ON) ||
3152        ((_elm_config->softcursor_mode == ELM_SOFTCURSOR_MODE_AUTO) &&
3153            (((fallback) && (!strcmp(fallback, "Software FB"))) ||
3154                ((!fallback) && (ENGINE_COMPARE(ELM_SOFTWARE_FB))))))
3155      {
3156         Evas_Object *o;
3157         Evas_Coord mw = 1, mh = 1, hx = 0, hy = 0;
3158
3159         sd->pointer.obj = o = edje_object_add(ecore_evas_get(tmp_sd.ee));
3160         _elm_theme_object_set(obj, o, "pointer", "base", "default");
3161         edje_object_size_min_calc(o, &mw, &mh);
3162         evas_object_resize(o, mw, mh);
3163         edje_object_part_geometry_get(o, "elm.swallow.hotspot",
3164                                       &hx, &hy, NULL, NULL);
3165         sd->pointer.hot_x = hx;
3166         sd->pointer.hot_y = hy;
3167         evas_object_show(o);
3168         ecore_evas_object_cursor_set(tmp_sd.ee, o, EVAS_LAYER_MAX, hx, hy);
3169      }
3170    else if (_elm_config->softcursor_mode == ELM_SOFTCURSOR_MODE_OFF)
3171      {
3172         // do nothing
3173      }
3174
3175    sd->wm_rot.wm_supported = ecore_evas_wm_rotation_supported_get(sd->ee);
3176    sd->wm_rot.preferred_rot = -1; // it means that elm_win doesn't use preferred rotation.
3177
3178    return obj;
3179 }
3180
3181 EAPI Evas_Object *
3182 elm_win_util_standard_add(const char *name,
3183                           const char *title)
3184 {
3185    Evas_Object *win, *bg;
3186
3187    win = elm_win_add(NULL, name, ELM_WIN_BASIC);
3188    if (!win) return NULL;
3189
3190    elm_win_title_set(win, title);
3191    bg = elm_bg_add(win);
3192    if (!bg)
3193      {
3194         evas_object_del(win);
3195         return NULL;
3196      }
3197    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3198    elm_win_resize_object_add(win, bg);
3199    evas_object_show(bg);
3200
3201    return win;
3202 }
3203
3204 EAPI void
3205 elm_win_resize_object_add(Evas_Object *obj,
3206                           Evas_Object *subobj)
3207 {
3208    Evas_Coord w, h;
3209
3210    ELM_WIN_CHECK(obj);
3211    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3212
3213    if (eina_list_data_find(sd->resize_objs, subobj)) return;
3214
3215    if (!ELM_WIDGET_DATA(sd)->api->sub_object_add(obj, subobj))
3216      ERR("could not add %p as sub object of %p", subobj, obj);
3217
3218    sd->resize_objs = eina_list_append(sd->resize_objs, subobj);
3219
3220    evas_object_event_callback_add
3221      (subobj, EVAS_CALLBACK_DEL, _elm_win_on_resize_obj_del, obj);
3222    evas_object_event_callback_add
3223      (subobj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
3224      _elm_win_on_resize_obj_changed_size_hints, obj);
3225
3226    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
3227    evas_object_move(subobj, 0, 0);
3228    evas_object_resize(subobj, w, h);
3229
3230    _elm_win_resize_objects_eval(obj);
3231 }
3232
3233 EAPI void
3234 elm_win_resize_object_del(Evas_Object *obj,
3235                           Evas_Object *subobj)
3236 {
3237    ELM_WIN_CHECK(obj);
3238    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3239
3240    if (!ELM_WIDGET_DATA(sd)->api->sub_object_del(obj, subobj))
3241      ERR("could not remove sub object %p from %p", subobj, obj);
3242
3243    sd->resize_objs = eina_list_remove(sd->resize_objs, subobj);
3244
3245    evas_object_event_callback_del_full
3246      (subobj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
3247      _elm_win_on_resize_obj_changed_size_hints, obj);
3248    evas_object_event_callback_del_full
3249      (subobj, EVAS_CALLBACK_DEL, _elm_win_on_resize_obj_del, obj);
3250
3251    _elm_win_resize_objects_eval(obj);
3252 }
3253
3254 EAPI void
3255 elm_win_title_set(Evas_Object *obj,
3256                   const char *title)
3257 {
3258    ELM_WIN_CHECK(obj);
3259    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3260
3261    if (!title) return;
3262    eina_stringshare_replace(&(sd->title), title);
3263    TRAP(sd, title_set, sd->title);
3264    if (sd->frame_obj)
3265      edje_object_part_text_escaped_set
3266        (sd->frame_obj, "elm.text.title", sd->title);
3267 }
3268
3269 EAPI const char *
3270 elm_win_title_get(const Evas_Object *obj)
3271 {
3272    ELM_WIN_CHECK(obj) NULL;
3273    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
3274
3275    return sd->title;
3276 }
3277
3278 EAPI void
3279 elm_win_icon_name_set(Evas_Object *obj,
3280                       const char *icon_name)
3281 {
3282    ELM_WIN_CHECK(obj);
3283    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3284
3285    if (!icon_name) return;
3286    eina_stringshare_replace(&(sd->icon_name), icon_name);
3287 #ifdef HAVE_ELEMENTARY_X
3288    _elm_win_xwin_update(sd);
3289 #endif
3290 }
3291
3292 EAPI const char *
3293 elm_win_icon_name_get(const Evas_Object *obj)
3294 {
3295    ELM_WIN_CHECK(obj) NULL;
3296    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
3297
3298    return sd->icon_name;
3299 }
3300
3301 EAPI void
3302 elm_win_role_set(Evas_Object *obj, const char *role)
3303 {
3304    ELM_WIN_CHECK(obj);
3305    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3306
3307    if (!role) return;
3308    eina_stringshare_replace(&(sd->role), role);
3309 #ifdef HAVE_ELEMENTARY_X
3310    _elm_win_xwin_update(sd);
3311 #endif
3312 }
3313
3314 EAPI const char *
3315 elm_win_role_get(const Evas_Object *obj)
3316 {
3317    ELM_WIN_CHECK(obj) NULL;
3318    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
3319
3320    return sd->role;
3321 }
3322
3323 EAPI void
3324 elm_win_icon_object_set(Evas_Object *obj,
3325                         Evas_Object *icon)
3326 {
3327    ELM_WIN_CHECK(obj);
3328    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3329
3330    if (sd->icon)
3331      evas_object_event_callback_del_full
3332        (sd->icon, EVAS_CALLBACK_DEL, _elm_win_on_icon_del, sd);
3333    sd->icon = icon;
3334    if (sd->icon)
3335      evas_object_event_callback_add
3336        (sd->icon, EVAS_CALLBACK_DEL, _elm_win_on_icon_del, sd);
3337 #ifdef HAVE_ELEMENTARY_X
3338    _elm_win_xwin_update(sd);
3339 #endif
3340 }
3341
3342 EAPI const Evas_Object *
3343 elm_win_icon_object_get(const Evas_Object *obj)
3344 {
3345    ELM_WIN_CHECK(obj) NULL;
3346    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
3347
3348    return sd->icon;
3349 }
3350
3351 EAPI void
3352 elm_win_autodel_set(Evas_Object *obj,
3353                     Eina_Bool autodel)
3354 {
3355    ELM_WIN_CHECK(obj);
3356    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3357
3358    sd->autodel = autodel;
3359 }
3360
3361 EAPI Eina_Bool
3362 elm_win_autodel_get(const Evas_Object *obj)
3363 {
3364    ELM_WIN_CHECK(obj) EINA_FALSE;
3365    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3366
3367    return sd->autodel;
3368 }
3369
3370 EAPI void
3371 elm_win_activate(Evas_Object *obj)
3372 {
3373    ELM_WIN_CHECK(obj);
3374    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3375
3376    TRAP(sd, activate);
3377 }
3378
3379 EAPI void
3380 elm_win_lower(Evas_Object *obj)
3381 {
3382    ELM_WIN_CHECK(obj);
3383    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3384
3385    TRAP(sd, lower);
3386 }
3387
3388 EAPI void
3389 elm_win_raise(Evas_Object *obj)
3390 {
3391    ELM_WIN_CHECK(obj);
3392    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3393
3394    TRAP(sd, raise);
3395 }
3396
3397 EAPI void
3398 elm_win_center(Evas_Object *obj,
3399                Eina_Bool h,
3400                Eina_Bool v)
3401 {
3402    int win_w, win_h, screen_w, screen_h, nx, ny;
3403
3404    ELM_WIN_CHECK(obj);
3405    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3406
3407    if ((trap) && (trap->center) && (!trap->center(sd->trap_data, obj)))
3408      return;
3409
3410    ecore_evas_screen_geometry_get(sd->ee, NULL, NULL, &screen_w, &screen_h);
3411    if ((!screen_w) || (!screen_h)) return;
3412
3413    evas_object_geometry_get(obj, NULL, NULL, &win_w, &win_h);
3414    if ((!win_w) || (!win_h)) return;
3415
3416    if (h) nx = win_w >= screen_w ? 0 : (screen_w / 2) - (win_w / 2);
3417    else nx = sd->screen.x;
3418    if (v) ny = win_h >= screen_h ? 0 : (screen_h / 2) - (win_h / 2);
3419    else ny = sd->screen.y;
3420    if (nx < 0) nx = 0;
3421    if (ny < 0) ny = 0;
3422
3423    evas_object_move(obj, nx, ny);
3424 }
3425
3426 EAPI void
3427 elm_win_borderless_set(Evas_Object *obj,
3428                        Eina_Bool borderless)
3429 {
3430    ELM_WIN_CHECK(obj);
3431    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3432
3433    TRAP(sd, borderless_set, borderless);
3434 #ifdef HAVE_ELEMENTARY_X
3435    _elm_win_xwin_update(sd);
3436 #endif
3437 }
3438
3439 EAPI Eina_Bool
3440 elm_win_borderless_get(const Evas_Object *obj)
3441 {
3442    ELM_WIN_CHECK(obj) EINA_FALSE;
3443    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3444
3445    return ecore_evas_borderless_get(sd->ee);
3446 }
3447
3448 EAPI void
3449 elm_win_shaped_set(Evas_Object *obj,
3450                    Eina_Bool shaped)
3451 {
3452    ELM_WIN_CHECK(obj);
3453    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3454
3455    TRAP(sd, shaped_set, shaped);
3456 #ifdef HAVE_ELEMENTARY_X
3457    _elm_win_xwin_update(sd);
3458 #endif
3459 }
3460
3461 EAPI Eina_Bool
3462 elm_win_shaped_get(const Evas_Object *obj)
3463 {
3464    ELM_WIN_CHECK(obj) EINA_FALSE;
3465    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3466
3467    return ecore_evas_shaped_get(sd->ee);
3468 }
3469
3470 EAPI void
3471 elm_win_alpha_set(Evas_Object *obj,
3472                   Eina_Bool alpha)
3473 {
3474    ELM_WIN_CHECK(obj);
3475    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3476
3477    if (sd->img_obj)
3478      {
3479         evas_object_image_alpha_set(sd->img_obj, alpha);
3480         ecore_evas_alpha_set(sd->ee, alpha);
3481      }
3482    else
3483      {
3484 #ifdef HAVE_ELEMENTARY_X
3485         if (sd->x.xwin)
3486           {
3487              if (alpha)
3488                {
3489                   if (!ecore_x_screen_is_composited(0))
3490                     elm_win_shaped_set(obj, alpha);
3491                   else
3492                     TRAP(sd, alpha_set, alpha);
3493                }
3494              else
3495                TRAP(sd, alpha_set, alpha);
3496              _elm_win_xwin_type_set(sd);
3497              _elm_win_xwin_update(sd);
3498           }
3499         else
3500 #endif
3501           TRAP(sd, alpha_set, alpha);
3502      }
3503 }
3504
3505 EAPI Eina_Bool
3506 elm_win_alpha_get(const Evas_Object *obj)
3507 {
3508    ELM_WIN_CHECK(obj) EINA_FALSE;
3509    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3510
3511    if (sd->img_obj)
3512      {
3513         return evas_object_image_alpha_get(sd->img_obj);
3514      }
3515
3516    return ecore_evas_alpha_get(sd->ee);
3517 }
3518
3519 EAPI void
3520 elm_win_override_set(Evas_Object *obj,
3521                      Eina_Bool override)
3522 {
3523    ELM_WIN_CHECK(obj);
3524    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3525
3526    TRAP(sd, override_set, override);
3527 #ifdef HAVE_ELEMENTARY_X
3528    _elm_win_xwin_update(sd);
3529 #endif
3530 }
3531
3532 EAPI Eina_Bool
3533 elm_win_override_get(const Evas_Object *obj)
3534 {
3535    ELM_WIN_CHECK(obj) EINA_FALSE;
3536    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3537
3538    return ecore_evas_override_get(sd->ee);
3539 }
3540
3541 EAPI void
3542 elm_win_fullscreen_set(Evas_Object *obj,
3543                        Eina_Bool fullscreen)
3544 {
3545    ELM_WIN_CHECK(obj);
3546    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3547    // YYY: handle if sd->img_obj
3548    if (ENGINE_COMPARE(ELM_SOFTWARE_FB) ||
3549        ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE))
3550      {
3551         // these engines... can ONLY be fullscreen
3552         return;
3553      }
3554    else
3555      {
3556 //        sd->fullscreen = fullscreen;
3557
3558         if (fullscreen)
3559           {
3560              if (ENGINE_COMPARE(ELM_WAYLAND_SHM) ||
3561                  ENGINE_COMPARE(ELM_WAYLAND_EGL))
3562                _elm_win_frame_del(sd);
3563           }
3564         else
3565           {
3566              if (ENGINE_COMPARE(ELM_WAYLAND_SHM) ||
3567                  ENGINE_COMPARE(ELM_WAYLAND_EGL))
3568                _elm_win_frame_add(sd, "default");
3569
3570              evas_object_show(sd->frame_obj);
3571           }
3572
3573         TRAP(sd, fullscreen_set, fullscreen);
3574 #ifdef HAVE_ELEMENTARY_X
3575         _elm_win_xwin_update(sd);
3576 #endif
3577      }
3578 }
3579
3580 EAPI Eina_Bool
3581 elm_win_fullscreen_get(const Evas_Object *obj)
3582 {
3583    ELM_WIN_CHECK(obj) EINA_FALSE;
3584    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3585
3586    if (ENGINE_COMPARE(ELM_SOFTWARE_FB) ||
3587        ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE))
3588      {
3589         // these engines... can ONLY be fullscreen
3590         return EINA_TRUE;
3591      }
3592    else
3593      {
3594         return sd->fullscreen;
3595      }
3596 }
3597
3598 EAPI void
3599 elm_win_maximized_set(Evas_Object *obj,
3600                       Eina_Bool maximized)
3601 {
3602    ELM_WIN_CHECK(obj);
3603    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3604
3605 //   sd->maximized = maximized;
3606    // YYY: handle if sd->img_obj
3607    TRAP(sd, maximized_set, maximized);
3608 #ifdef HAVE_ELEMENTARY_X
3609    _elm_win_xwin_update(sd);
3610 #endif
3611 }
3612
3613 EAPI Eina_Bool
3614 elm_win_maximized_get(const Evas_Object *obj)
3615 {
3616    ELM_WIN_CHECK(obj) EINA_FALSE;
3617    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3618
3619    return sd->maximized;
3620 }
3621
3622 EAPI void
3623 elm_win_iconified_set(Evas_Object *obj,
3624                       Eina_Bool iconified)
3625 {
3626    ELM_WIN_CHECK(obj);
3627    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3628
3629 //   sd->iconified = iconified;
3630    TRAP(sd, iconified_set, iconified);
3631 #ifdef HAVE_ELEMENTARY_X
3632    _elm_win_xwin_update(sd);
3633 #endif
3634 }
3635
3636 EAPI Eina_Bool
3637 elm_win_iconified_get(const Evas_Object *obj)
3638 {
3639    ELM_WIN_CHECK(obj) EINA_FALSE;
3640    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3641
3642    return sd->iconified;
3643 }
3644
3645 EAPI void
3646 elm_win_withdrawn_set(Evas_Object *obj,
3647                       Eina_Bool withdrawn)
3648 {
3649    ELM_WIN_CHECK(obj);
3650    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3651
3652 //   sd->withdrawn = withdrawn;
3653    TRAP(sd, withdrawn_set, withdrawn);
3654 #ifdef HAVE_ELEMENTARY_X
3655    _elm_win_xwin_update(sd);
3656 #endif
3657 }
3658
3659 EAPI Eina_Bool
3660 elm_win_withdrawn_get(const Evas_Object *obj)
3661 {
3662    ELM_WIN_CHECK(obj) EINA_FALSE;
3663    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3664
3665    return sd->withdrawn;
3666 }
3667
3668 EAPI void
3669 elm_win_profiles_set(Evas_Object  *obj,
3670                      const char  **profiles,
3671                      unsigned int  num_profiles)
3672 {
3673    char **profiles_int;
3674    const char *str;
3675    unsigned int i, num;
3676    Eina_List *l;
3677
3678    ELM_WIN_CHECK(obj);
3679    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3680
3681    if (!profiles) return;
3682
3683    if (sd->profile.timer) ecore_timer_del(sd->profile.timer);
3684    sd->profile.timer = ecore_timer_add(0.1, _elm_win_profile_change_delay, sd);
3685    EINA_LIST_FREE(sd->profile.names, str) eina_stringshare_del(str);
3686
3687    for (i = 0; i < num_profiles; i++)
3688      {
3689         if ((profiles[i]) &&
3690             _elm_config_profile_exists(profiles[i]))
3691           {
3692              str = eina_stringshare_add(profiles[i]);
3693              sd->profile.names = eina_list_append(sd->profile.names, str);
3694           }
3695      }
3696
3697    num = eina_list_count(sd->profile.names);
3698    profiles_int = alloca(num * sizeof(char *));
3699
3700    if (profiles_int)
3701      {
3702         i = 0;
3703         EINA_LIST_FOREACH(sd->profile.names, l, str)
3704           {
3705              if (str)
3706                profiles_int[i] = strdup(str);
3707              else
3708                profiles_int[i] = NULL;
3709              i++;
3710           }
3711         ecore_evas_profiles_set(sd->ee, (const char **)profiles_int, i);
3712         for (i = 0; i < num; i++)
3713           {
3714              if (profiles_int[i]) free(profiles_int[i]);
3715           }
3716      }
3717    else
3718      ecore_evas_profiles_set(sd->ee, profiles, num_profiles);
3719 }
3720
3721 EAPI const char *
3722 elm_win_profile_get(const Evas_Object *obj)
3723 {
3724    ELM_WIN_CHECK(obj) NULL;
3725    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
3726
3727    return sd->profile.name;
3728 }
3729
3730 EAPI void
3731 elm_win_urgent_set(Evas_Object *obj,
3732                    Eina_Bool urgent)
3733 {
3734    ELM_WIN_CHECK(obj);
3735    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3736
3737    sd->urgent = urgent;
3738    TRAP(sd, urgent_set, urgent);
3739 #ifdef HAVE_ELEMENTARY_X
3740    _elm_win_xwin_update(sd);
3741 #endif
3742 }
3743
3744 EAPI Eina_Bool
3745 elm_win_urgent_get(const Evas_Object *obj)
3746 {
3747    ELM_WIN_CHECK(obj) EINA_FALSE;
3748    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3749
3750    return sd->urgent;
3751 }
3752
3753 EAPI void
3754 elm_win_demand_attention_set(Evas_Object *obj,
3755                              Eina_Bool demand_attention)
3756 {
3757    ELM_WIN_CHECK(obj);
3758    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3759
3760    sd->demand_attention = demand_attention;
3761    TRAP(sd, demand_attention_set, demand_attention);
3762 #ifdef HAVE_ELEMENTARY_X
3763    _elm_win_xwin_update(sd);
3764 #endif
3765 }
3766
3767 EAPI Eina_Bool
3768 elm_win_demand_attention_get(const Evas_Object *obj)
3769 {
3770    ELM_WIN_CHECK(obj) EINA_FALSE;
3771    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3772
3773    return sd->demand_attention;
3774 }
3775
3776 EAPI void
3777 elm_win_modal_set(Evas_Object *obj,
3778                   Eina_Bool modal)
3779 {
3780    ELM_WIN_CHECK(obj);
3781    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3782
3783    sd->modal = modal;
3784    TRAP(sd, modal_set, modal);
3785 #ifdef HAVE_ELEMENTARY_X
3786    _elm_win_xwin_update(sd);
3787 #endif
3788 }
3789
3790 EAPI Eina_Bool
3791 elm_win_modal_get(const Evas_Object *obj)
3792 {
3793    ELM_WIN_CHECK(obj) EINA_FALSE;
3794    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3795
3796    return sd->modal;
3797 }
3798
3799 EAPI void
3800 elm_win_aspect_set(Evas_Object *obj,
3801                    double aspect)
3802 {
3803    ELM_WIN_CHECK(obj);
3804    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3805
3806    sd->aspect = aspect;
3807    TRAP(sd, aspect_set, aspect);
3808 #ifdef HAVE_ELEMENTARY_X
3809    _elm_win_xwin_update(sd);
3810 #endif
3811 }
3812
3813 EAPI double
3814 elm_win_aspect_get(const Evas_Object *obj)
3815 {
3816    ELM_WIN_CHECK(obj) 0.0;
3817    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, 0.0);
3818
3819    return sd->aspect;
3820 }
3821
3822 EAPI void
3823 elm_win_size_base_set(Evas_Object *obj, int w, int h)
3824 {
3825    ELM_WIN_CHECK(obj);
3826    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3827    sd->size_base_w = w;
3828    sd->size_base_h = h;
3829    TRAP(sd, size_base_set, w, h);
3830 #ifdef HAVE_ELEMENTARY_X
3831    _elm_win_xwin_update(sd);
3832 #endif
3833 }
3834
3835 EAPI void
3836 elm_win_size_base_get(Evas_Object *obj, int *w, int *h)
3837 {
3838    ELM_WIN_CHECK(obj);
3839    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3840    if (w) *w = sd->size_base_w;
3841    if (w) *h = sd->size_base_h;
3842 }
3843
3844 EAPI void
3845 elm_win_size_step_set(Evas_Object *obj, int w, int h)
3846 {
3847    ELM_WIN_CHECK(obj);
3848    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3849    sd->size_step_w = w;
3850    sd->size_step_h = h;
3851    TRAP(sd, size_step_set, w, h);
3852 #ifdef HAVE_ELEMENTARY_X
3853    _elm_win_xwin_update(sd);
3854 #endif
3855 }
3856
3857 EAPI void
3858 elm_win_size_step_get(Evas_Object *obj, int *w, int *h)
3859 {
3860    ELM_WIN_CHECK(obj);
3861    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3862    if (w) *w = sd->size_step_w;
3863    if (w) *h = sd->size_step_h;
3864 }
3865
3866 EAPI void
3867 elm_win_layer_set(Evas_Object *obj,
3868                   int layer)
3869 {
3870    ELM_WIN_CHECK(obj);
3871    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3872
3873    TRAP(sd, layer_set, layer);
3874 #ifdef HAVE_ELEMENTARY_X
3875    _elm_win_xwin_update(sd);
3876 #endif
3877 }
3878
3879 EAPI int
3880 elm_win_layer_get(const Evas_Object *obj)
3881 {
3882    ELM_WIN_CHECK(obj) - 1;
3883    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
3884
3885    return ecore_evas_layer_get(sd->ee);
3886 }
3887
3888 EAPI void
3889 elm_win_norender_push(Evas_Object *obj)
3890 {
3891    ELM_WIN_CHECK(obj);
3892    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3893
3894    sd->norender++;
3895    if (sd->norender == 1) ecore_evas_manual_render_set(sd->ee, EINA_TRUE);
3896 }
3897
3898 EAPI void
3899 elm_win_norender_pop(Evas_Object *obj)
3900 {
3901    ELM_WIN_CHECK(obj);
3902    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3903
3904    if (sd->norender <= 0) return;
3905    sd->norender--;
3906    if (sd->norender == 0) ecore_evas_manual_render_set(sd->ee, EINA_FALSE);
3907 }
3908
3909 EAPI int
3910 elm_win_norender_get(Evas_Object *obj)
3911 {
3912    ELM_WIN_CHECK(obj) - 1;
3913    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
3914    return sd->norender;
3915 }
3916
3917 EAPI void
3918 elm_win_render(Evas_Object *obj)
3919 {
3920    ELM_WIN_CHECK(obj);
3921    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3922    ecore_evas_manual_render(sd->ee);
3923 }
3924
3925 static int
3926 _win_rotation_degree_check(int rotation)
3927 {
3928    if ((rotation > 360) || (rotation < 0))
3929      {
3930         WRN("Rotation degree should be 0 ~ 360 (passed degree: %d)", rotation);
3931         rotation %= 360;
3932         if (rotation < 0) rotation += 360;
3933      }
3934    return rotation;
3935 }
3936
3937 static void
3938 _win_rotate(Evas_Object *obj, Elm_Win_Smart_Data *sd, int rotation, Eina_Bool resize)
3939 {
3940    rotation = _win_rotation_degree_check(rotation);
3941    if (sd->rot == rotation) return;
3942    sd->rot = rotation;
3943    if (resize) TRAP(sd, rotation_with_resize_set, rotation);
3944    else TRAP(sd, rotation_set, rotation);
3945    evas_object_size_hint_min_set(obj, -1, -1);
3946    evas_object_size_hint_max_set(obj, -1, -1);
3947    _elm_win_resize_objects_eval(obj);
3948 #ifdef HAVE_ELEMENTARY_X
3949    _elm_win_xwin_update(sd);
3950 #endif
3951    elm_widget_orientation_set(obj, rotation);
3952    evas_object_smart_callback_call(obj, SIG_ROTATION_CHANGED, NULL);
3953 }
3954
3955 EAPI void
3956 elm_win_rotation_set(Evas_Object *obj,
3957                      int rotation)
3958 {
3959    ELM_WIN_CHECK(obj);
3960    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3961    _win_rotate(obj, sd, rotation, EINA_FALSE);
3962 }
3963
3964 EAPI void
3965 elm_win_rotation_with_resize_set(Evas_Object *obj,
3966                                  int rotation)
3967 {
3968    ELM_WIN_CHECK(obj);
3969    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
3970    _win_rotate(obj, sd, rotation, EINA_TRUE);
3971 }
3972
3973 EAPI int
3974 elm_win_rotation_get(const Evas_Object *obj)
3975 {
3976    ELM_WIN_CHECK(obj) - 1;
3977    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
3978
3979    return sd->rot;
3980 }
3981
3982 EAPI Eina_Bool
3983 elm_win_wm_rotation_supported_get(const Evas_Object *obj)
3984 {
3985    ELM_WIN_CHECK(obj) EINA_FALSE;
3986    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
3987    return sd->wm_rot.wm_supported;
3988 }
3989
3990 /* This will unset a preferred rotation, if given preferred rotation is '-1'.
3991  */
3992 EAPI void
3993 elm_win_wm_rotation_preferred_rotation_set(Evas_Object *obj,
3994                                            const int rotation)
3995 {
3996    int rot;
3997
3998    ELM_WIN_CHECK(obj);
3999    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4000
4001    if (!sd->wm_rot.use)
4002      sd->wm_rot.use = EINA_TRUE;
4003
4004    // '-1' means that elm_win doesn't use preferred rotation.
4005    if (rotation == -1)
4006      rot = -1;
4007    else
4008      rot = _win_rotation_degree_check(rotation);
4009
4010    if (sd->wm_rot.preferred_rot == rot) return;
4011    sd->wm_rot.preferred_rot = rot;
4012
4013    ecore_evas_wm_rotation_preferred_rotation_set(sd->ee, rot);
4014 }
4015
4016 EAPI int
4017 elm_win_wm_rotation_preferred_rotation_get(const Evas_Object *obj)
4018 {
4019    ELM_WIN_CHECK(obj) -1;
4020    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
4021    if (!sd->wm_rot.use) return -1;
4022    return sd->wm_rot.preferred_rot;
4023 }
4024
4025 EAPI void
4026 elm_win_wm_rotation_available_rotations_set(Evas_Object *obj,
4027                                             const int   *rotations,
4028                                             unsigned int count)
4029 {
4030    unsigned int i;
4031    int r;
4032
4033    ELM_WIN_CHECK(obj);
4034    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4035
4036    if (!sd->wm_rot.use)
4037      sd->wm_rot.use = EINA_TRUE;
4038
4039    if (sd->wm_rot.rots) free(sd->wm_rot.rots);
4040
4041    sd->wm_rot.rots = NULL;
4042    sd->wm_rot.count = 0;
4043
4044    if (count > 0)
4045      {
4046         sd->wm_rot.rots = calloc(count, sizeof(int));
4047         if (!sd->wm_rot.rots) return;
4048         for (i = 0; i < count; i++)
4049           {
4050              r = _win_rotation_degree_check(rotations[i]);
4051              sd->wm_rot.rots[i] = r;
4052           }
4053      }
4054
4055    sd->wm_rot.count = count;
4056
4057    ecore_evas_wm_rotation_available_rotations_set(sd->ee,
4058                                                   sd->wm_rot.rots,
4059                                                   sd->wm_rot.count);
4060 }
4061
4062 EAPI Eina_Bool
4063 elm_win_wm_rotation_available_rotations_get(const Evas_Object *obj,
4064                                             int              **rotations,
4065                                             unsigned int      *count)
4066 {
4067    ELM_WIN_CHECK(obj) EINA_FALSE;
4068    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4069    if (!sd->wm_rot.use) return EINA_FALSE;
4070
4071    if (sd->wm_rot.count > 0)
4072      {
4073         if ((rotations) && (*rotations))
4074           {
4075              *rotations = calloc(sd->wm_rot.count, sizeof(int));
4076              if (*rotations)
4077                {
4078                   memcpy(*rotations,
4079                          sd->wm_rot.rots,
4080                          sizeof(int) * sd->wm_rot.count);
4081                }
4082           }
4083      }
4084
4085    if (count) *count = sd->wm_rot.count;
4086
4087    return EINA_TRUE;
4088 }
4089
4090 EAPI void
4091 elm_win_sticky_set(Evas_Object *obj,
4092                    Eina_Bool sticky)
4093 {
4094    ELM_WIN_CHECK(obj);
4095    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4096
4097 //   sd->sticky = sticky;
4098    TRAP(sd, sticky_set, sticky);
4099 #ifdef HAVE_ELEMENTARY_X
4100    _elm_win_xwin_update(sd);
4101 #endif
4102 }
4103
4104 EAPI Eina_Bool
4105 elm_win_sticky_get(const Evas_Object *obj)
4106 {
4107    ELM_WIN_CHECK(obj) EINA_FALSE;
4108    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4109
4110    return sd->sticky;
4111 }
4112
4113 EAPI void
4114 elm_win_keyboard_mode_set(Evas_Object *obj,
4115                           Elm_Win_Keyboard_Mode mode)
4116 {
4117    ELM_WIN_CHECK(obj);
4118    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4119
4120    if (mode == sd->kbdmode) return;
4121 #ifdef HAVE_ELEMENTARY_X
4122    _elm_win_xwindow_get(sd);
4123 #endif
4124    sd->kbdmode = mode;
4125 #ifdef HAVE_ELEMENTARY_X
4126    if (sd->x.xwin)
4127      ecore_x_e_virtual_keyboard_state_set
4128        (sd->x.xwin, (Ecore_X_Virtual_Keyboard_State)sd->kbdmode);
4129 #endif
4130 }
4131
4132 EAPI Elm_Win_Keyboard_Mode
4133 elm_win_keyboard_mode_get(const Evas_Object *obj)
4134 {
4135    ELM_WIN_CHECK(obj) ELM_WIN_KEYBOARD_UNKNOWN;
4136    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, ELM_WIN_KEYBOARD_UNKNOWN);
4137
4138    return sd->kbdmode;
4139 }
4140
4141 EAPI void
4142 elm_win_keyboard_win_set(Evas_Object *obj,
4143                          Eina_Bool is_keyboard)
4144 {
4145    ELM_WIN_CHECK(obj);
4146    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4147
4148 #ifdef HAVE_ELEMENTARY_X
4149    _elm_win_xwindow_get(sd);
4150    if (sd->x.xwin)
4151      ecore_x_e_virtual_keyboard_set(sd->x.xwin, is_keyboard);
4152 #else
4153    (void)is_keyboard;
4154 #endif
4155 }
4156
4157 EAPI Eina_Bool
4158 elm_win_keyboard_win_get(const Evas_Object *obj)
4159 {
4160    ELM_WIN_CHECK(obj) EINA_FALSE;
4161    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4162
4163 #ifdef HAVE_ELEMENTARY_X
4164    _elm_win_xwindow_get(sd);
4165    if (sd->x.xwin)
4166      return ecore_x_e_virtual_keyboard_get(sd->x.xwin);
4167 #endif
4168    return EINA_FALSE;
4169 }
4170
4171 EAPI void
4172 elm_win_indicator_mode_set(Evas_Object *obj,
4173                            Elm_Win_Indicator_Mode mode)
4174 {
4175    ELM_WIN_CHECK(obj);
4176    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4177
4178    if (mode == sd->indmode) return;
4179 #ifdef HAVE_ELEMENTARY_X
4180    _elm_win_xwindow_get(sd);
4181 #endif
4182    sd->indmode = mode;
4183 #ifdef HAVE_ELEMENTARY_X
4184    if (sd->x.xwin)
4185      {
4186         if (sd->indmode == ELM_WIN_INDICATOR_SHOW)
4187           ecore_x_e_illume_indicator_state_set
4188             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_STATE_ON);
4189         else if (sd->indmode == ELM_WIN_INDICATOR_HIDE)
4190           ecore_x_e_illume_indicator_state_set
4191             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_STATE_OFF);
4192      }
4193 #endif
4194    evas_object_smart_callback_call(obj, SIG_INDICATOR_PROP_CHANGED, NULL);
4195 }
4196
4197 EAPI Elm_Win_Indicator_Mode
4198 elm_win_indicator_mode_get(const Evas_Object *obj)
4199 {
4200    ELM_WIN_CHECK(obj) ELM_WIN_INDICATOR_UNKNOWN;
4201    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, ELM_WIN_INDICATOR_UNKNOWN);
4202
4203    return sd->indmode;
4204 }
4205
4206 EAPI void
4207 elm_win_indicator_opacity_set(Evas_Object *obj,
4208                               Elm_Win_Indicator_Opacity_Mode mode)
4209 {
4210    ELM_WIN_CHECK(obj);
4211    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4212
4213    if (mode == sd->ind_o_mode) return;
4214    sd->ind_o_mode = mode;
4215 #ifdef HAVE_ELEMENTARY_X
4216    _elm_win_xwindow_get(sd);
4217    if (sd->x.xwin)
4218      {
4219         if (sd->ind_o_mode == ELM_WIN_INDICATOR_OPAQUE)
4220           ecore_x_e_illume_indicator_opacity_set
4221             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_OPAQUE);
4222         else if (sd->ind_o_mode == ELM_WIN_INDICATOR_TRANSLUCENT)
4223           ecore_x_e_illume_indicator_opacity_set
4224             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_TRANSLUCENT);
4225         else if (sd->ind_o_mode == ELM_WIN_INDICATOR_TRANSPARENT)
4226           ecore_x_e_illume_indicator_opacity_set
4227             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_TRANSPARENT);
4228      }
4229 #endif
4230    evas_object_smart_callback_call(obj, SIG_INDICATOR_PROP_CHANGED, NULL);
4231 }
4232
4233 EAPI Elm_Win_Indicator_Opacity_Mode
4234 elm_win_indicator_opacity_get(const Evas_Object *obj)
4235 {
4236    ELM_WIN_CHECK(obj) ELM_WIN_INDICATOR_OPACITY_UNKNOWN;
4237    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, ELM_WIN_INDICATOR_OPACITY_UNKNOWN);
4238
4239    return sd->ind_o_mode;
4240 }
4241
4242 EAPI void
4243 elm_win_indicator_type_set(Evas_Object *obj,
4244                               Elm_Win_Indicator_Type_Mode mode)
4245 {
4246    ELM_WIN_CHECK(obj);
4247    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4248
4249    if (mode == sd->ind_t_mode) return;
4250    sd->ind_t_mode = mode;
4251 #ifdef HAVE_ELEMENTARY_X
4252    _elm_win_xwindow_get(sd);
4253    if (sd->x.xwin)
4254      {
4255         if (sd->ind_t_mode == ELM_WIN_INDICATOR_TYPE_1)
4256           ecore_x_e_illume_indicator_type_set
4257             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_TYPE_1);
4258         else if (sd->ind_t_mode == ELM_WIN_INDICATOR_TYPE_2)
4259           ecore_x_e_illume_indicator_type_set
4260             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_TYPE_2);
4261      }
4262 #endif
4263    //evas_object_smart_callback_call(obj, SIG_INDICATOR_PROP_CHANGED, NULL);
4264 }
4265
4266 EAPI Elm_Win_Indicator_Type_Mode
4267 elm_win_indicator_type_get(const Evas_Object *obj)
4268 {
4269    ELM_WIN_CHECK(obj) ELM_WIN_INDICATOR_TYPE_UNKNOWN;
4270    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, ELM_WIN_INDICATOR_TYPE_UNKNOWN);
4271
4272    return sd->ind_t_mode;
4273 }
4274 EAPI void
4275 elm_win_screen_position_get(const Evas_Object *obj,
4276                             int *x,
4277                             int *y)
4278 {
4279    ELM_WIN_CHECK(obj);
4280    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4281
4282    if (x) *x = sd->screen.x;
4283    if (y) *y = sd->screen.y;
4284 }
4285
4286 EAPI Eina_Bool
4287 elm_win_focus_get(const Evas_Object *obj)
4288 {
4289    ELM_WIN_CHECK(obj) EINA_FALSE;
4290    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4291
4292    return ecore_evas_focus_get(sd->ee);
4293 }
4294
4295 EAPI void
4296 elm_win_screen_constrain_set(Evas_Object *obj,
4297                              Eina_Bool constrain)
4298 {
4299    ELM_WIN_CHECK(obj);
4300    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4301
4302    sd->constrain = !!constrain;
4303 }
4304
4305 EAPI Eina_Bool
4306 elm_win_screen_constrain_get(Evas_Object *obj)
4307 {
4308    ELM_WIN_CHECK(obj) EINA_FALSE;
4309    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4310
4311    return sd->constrain;
4312 }
4313
4314 EAPI void
4315 elm_win_screen_size_get(const Evas_Object *obj,
4316                         int *x,
4317                         int *y,
4318                         int *w,
4319                         int *h)
4320 {
4321    ELM_WIN_CHECK(obj);
4322    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4323
4324    ecore_evas_screen_geometry_get(sd->ee, x, y, w, h);
4325 }
4326
4327 EAPI void
4328 elm_win_screen_dpi_get(const Evas_Object *obj,
4329                        int *xdpi,
4330                        int *ydpi)
4331 {
4332    ELM_WIN_CHECK(obj);
4333    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4334
4335    ecore_evas_screen_dpi_get(sd->ee, xdpi, ydpi);
4336 }
4337
4338 EAPI void
4339 elm_win_conformant_set(Evas_Object *obj,
4340                        Eina_Bool conformant)
4341 {
4342    ELM_WIN_CHECK(obj);
4343    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4344
4345 #ifdef HAVE_ELEMENTARY_X
4346    _elm_win_xwindow_get(sd);
4347    if (sd->x.xwin)
4348      ecore_x_e_illume_conformant_set(sd->x.xwin, conformant);
4349 #else
4350    (void)conformant;
4351 #endif
4352 }
4353
4354 EAPI Eina_Bool
4355 elm_win_conformant_get(const Evas_Object *obj)
4356 {
4357    ELM_WIN_CHECK(obj) EINA_FALSE;
4358    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4359
4360 #ifdef HAVE_ELEMENTARY_X
4361    _elm_win_xwindow_get(sd);
4362    if (sd->x.xwin)
4363      return ecore_x_e_illume_conformant_get(sd->x.xwin);
4364 #endif
4365    return EINA_FALSE;
4366 }
4367
4368 EAPI void
4369 elm_win_quickpanel_set(Evas_Object *obj,
4370                        Eina_Bool quickpanel)
4371 {
4372    ELM_WIN_CHECK(obj);
4373    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4374 #ifdef HAVE_ELEMENTARY_X
4375    _elm_win_xwindow_get(sd);
4376    if (sd->x.xwin)
4377      {
4378         ecore_x_e_illume_quickpanel_set(sd->x.xwin, quickpanel);
4379         if (quickpanel)
4380           {
4381              Ecore_X_Window_State states[2];
4382
4383              states[0] = ECORE_X_WINDOW_STATE_SKIP_TASKBAR;
4384              states[1] = ECORE_X_WINDOW_STATE_SKIP_PAGER;
4385              ecore_x_netwm_window_state_set(sd->x.xwin, states, 2);
4386              ecore_x_icccm_hints_set(sd->x.xwin, 0, 0, 0, 0, 0, 0, 0);
4387           }
4388      }
4389 #else
4390    (void)quickpanel;
4391 #endif
4392 }
4393
4394 EAPI Eina_Bool
4395 elm_win_quickpanel_get(const Evas_Object *obj)
4396 {
4397    ELM_WIN_CHECK(obj) EINA_FALSE;
4398    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4399
4400 #ifdef HAVE_ELEMENTARY_X
4401    _elm_win_xwindow_get(sd);
4402    if (sd->x.xwin)
4403      return ecore_x_e_illume_quickpanel_get(sd->x.xwin);
4404 #endif
4405    return EINA_FALSE;
4406 }
4407
4408 EAPI void
4409 elm_win_quickpanel_priority_major_set(Evas_Object *obj,
4410                                       int priority)
4411 {
4412    ELM_WIN_CHECK(obj);
4413    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4414
4415 #ifdef HAVE_ELEMENTARY_X
4416    _elm_win_xwindow_get(sd);
4417    if (sd->x.xwin)
4418      ecore_x_e_illume_quickpanel_priority_major_set(sd->x.xwin, priority);
4419 #else
4420    (void)priority;
4421 #endif
4422 }
4423
4424 EAPI int
4425 elm_win_quickpanel_priority_major_get(const Evas_Object *obj)
4426 {
4427    ELM_WIN_CHECK(obj) - 1;
4428    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
4429
4430 #ifdef HAVE_ELEMENTARY_X
4431    _elm_win_xwindow_get(sd);
4432    if (sd->x.xwin)
4433      return ecore_x_e_illume_quickpanel_priority_major_get(sd->x.xwin);
4434 #endif
4435    return -1;
4436 }
4437
4438 EAPI void
4439 elm_win_quickpanel_priority_minor_set(Evas_Object *obj,
4440                                       int priority)
4441 {
4442    ELM_WIN_CHECK(obj);
4443    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4444
4445 #ifdef HAVE_ELEMENTARY_X
4446    _elm_win_xwindow_get(sd);
4447    if (sd->x.xwin)
4448      ecore_x_e_illume_quickpanel_priority_minor_set(sd->x.xwin, priority);
4449 #else
4450    (void)priority;
4451 #endif
4452 }
4453
4454 EAPI int
4455 elm_win_quickpanel_priority_minor_get(const Evas_Object *obj)
4456 {
4457    ELM_WIN_CHECK(obj) - 1;
4458    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
4459
4460 #ifdef HAVE_ELEMENTARY_X
4461    _elm_win_xwindow_get(sd);
4462    if (sd->x.xwin)
4463      return ecore_x_e_illume_quickpanel_priority_minor_get(sd->x.xwin);
4464 #endif
4465    return -1;
4466 }
4467
4468 EAPI void
4469 elm_win_quickpanel_zone_set(Evas_Object *obj,
4470                             int zone)
4471 {
4472    ELM_WIN_CHECK(obj);
4473    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4474
4475 #ifdef HAVE_ELEMENTARY_X
4476    _elm_win_xwindow_get(sd);
4477    if (sd->x.xwin)
4478      ecore_x_e_illume_quickpanel_zone_set(sd->x.xwin, zone);
4479 #else
4480    (void)zone;
4481 #endif
4482 }
4483
4484 EAPI int
4485 elm_win_quickpanel_zone_get(const Evas_Object *obj)
4486 {
4487    ELM_WIN_CHECK(obj) 0;
4488    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, 0);
4489
4490 #ifdef HAVE_ELEMENTARY_X
4491    _elm_win_xwindow_get(sd);
4492    if (sd->x.xwin)
4493      return ecore_x_e_illume_quickpanel_zone_get(sd->x.xwin);
4494 #endif
4495    return 0;
4496 }
4497
4498 EAPI void
4499 elm_win_prop_focus_skip_set(Evas_Object *obj,
4500                             Eina_Bool skip)
4501 {
4502    ELM_WIN_CHECK(obj);
4503    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4504
4505    sd->skip_focus = skip;
4506    TRAP(sd, focus_skip_set, skip);
4507 }
4508
4509 EAPI void
4510 elm_win_illume_command_send(Evas_Object *obj,
4511                             Elm_Illume_Command command,
4512                             void *params __UNUSED__)
4513 {
4514    ELM_WIN_CHECK(obj);
4515    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4516
4517 #ifdef HAVE_ELEMENTARY_X
4518    _elm_win_xwindow_get(sd);
4519    if (sd->x.xwin)
4520      {
4521         switch (command)
4522           {
4523            case ELM_ILLUME_COMMAND_FOCUS_BACK:
4524              ecore_x_e_illume_focus_back_send(sd->x.xwin);
4525              break;
4526
4527            case ELM_ILLUME_COMMAND_FOCUS_FORWARD:
4528              ecore_x_e_illume_focus_forward_send(sd->x.xwin);
4529              break;
4530
4531            case ELM_ILLUME_COMMAND_FOCUS_HOME:
4532              ecore_x_e_illume_focus_home_send(sd->x.xwin);
4533              break;
4534
4535            case ELM_ILLUME_COMMAND_CLOSE:
4536              ecore_x_e_illume_close_send(sd->x.xwin);
4537              break;
4538
4539            default:
4540              break;
4541           }
4542      }
4543 #else
4544    (void)command;
4545 #endif
4546 }
4547
4548 EAPI Evas_Object *
4549 elm_win_inlined_image_object_get(Evas_Object *obj)
4550 {
4551    ELM_WIN_CHECK(obj) NULL;
4552    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
4553
4554    return sd->img_obj;
4555 }
4556
4557 EAPI void
4558 elm_win_focus_highlight_enabled_set(Evas_Object *obj,
4559                                     Eina_Bool enabled)
4560 {
4561    ELM_WIN_CHECK(obj);
4562    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4563
4564    enabled = !!enabled;
4565    if (sd->focus_highlight.enabled == enabled)
4566      return;
4567
4568    sd->focus_highlight.enabled = enabled;
4569
4570    if (sd->focus_highlight.enabled)
4571      _elm_win_focus_highlight_init(sd);
4572    else
4573      _elm_win_focus_highlight_shutdown(sd);
4574 }
4575
4576 EAPI Eina_Bool
4577 elm_win_focus_highlight_enabled_get(const Evas_Object *obj)
4578 {
4579    ELM_WIN_CHECK(obj) EINA_FALSE;
4580    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4581
4582    return sd->focus_highlight.enabled;
4583 }
4584
4585 EAPI void
4586 elm_win_focus_highlight_style_set(Evas_Object *obj,
4587                                   const char *style)
4588 {
4589    ELM_WIN_CHECK(obj);
4590    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4591
4592    eina_stringshare_replace(&sd->focus_highlight.style, style);
4593    sd->focus_highlight.changed_theme = EINA_TRUE;
4594    _elm_win_focus_highlight_reconfigure_job_start(sd);
4595 }
4596
4597 EAPI const char *
4598 elm_win_focus_highlight_style_get(const Evas_Object *obj)
4599 {
4600    ELM_WIN_CHECK(obj) NULL;
4601    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
4602
4603    return sd->focus_highlight.style;
4604 }
4605
4606 EAPI Eina_Bool
4607 elm_win_socket_listen(Evas_Object *obj,
4608                       const char *svcname,
4609                       int svcnum,
4610                       Eina_Bool svcsys)
4611 {
4612    ELM_WIN_CHECK(obj) EINA_FALSE;
4613    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4614
4615    if (!sd->ee) return EINA_FALSE;
4616
4617    if (!ecore_evas_extn_socket_listen(sd->ee, svcname, svcnum, svcsys))
4618      return EINA_FALSE;
4619
4620    return EINA_TRUE;
4621 }
4622
4623 /* windowing specific calls - shall we do this differently? */
4624
4625 EAPI Ecore_X_Window
4626 elm_win_xwindow_get(const Evas_Object *obj)
4627 {
4628    if (!obj) return 0;
4629
4630    if (!evas_object_smart_type_check_ptr(obj, WIN_SMART_NAME))
4631      {
4632         Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
4633         return _elm_ee_xwin_get(ee);
4634      }
4635
4636    ELM_WIN_CHECK(obj) 0;
4637    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, 0);
4638
4639 #ifdef HAVE_ELEMENTARY_X
4640    if (sd->x.xwin) return sd->x.xwin;
4641    if (sd->parent) return elm_win_xwindow_get(sd->parent);
4642 #endif
4643    return 0;
4644 }
4645
4646 EAPI Ecore_Wl_Window *
4647 elm_win_wl_window_get(const Evas_Object *obj)
4648 {
4649    if (!obj) return NULL;
4650
4651    if (!evas_object_smart_type_check_ptr(obj, WIN_SMART_NAME))
4652      {
4653         Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
4654         return ecore_evas_wayland_window_get(ee);
4655      }
4656
4657    ELM_WIN_CHECK(obj) NULL;
4658    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
4659 #if HAVE_ELEMENTARY_WAYLAND
4660    if (sd->wl.win) return sd->wl.win;
4661    if (sd->parent) return elm_win_wl_window_get(sd->parent);
4662 #endif
4663    return NULL;
4664 }
4665
4666 EAPI Eina_Bool
4667 elm_win_trap_set(const Elm_Win_Trap *t)
4668 {
4669    DBG("old %p, new %p", trap, t);
4670
4671    if ((t) && (t->version != ELM_WIN_TRAP_VERSION))
4672      {
4673         CRITICAL("trying to set a trap version %lu while %lu was expected!",
4674                  t->version, ELM_WIN_TRAP_VERSION);
4675         return EINA_FALSE;
4676      }
4677
4678    trap = t;
4679    return EINA_TRUE;
4680 }
4681
4682 EAPI void
4683 elm_win_floating_mode_set(Evas_Object *obj, Eina_Bool floating)
4684 {
4685    ELM_WIN_CHECK(obj);
4686    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
4687
4688    if (floating == sd->floating) return;
4689    sd->floating = floating;
4690 #ifdef HAVE_ELEMENTARY_X
4691    _elm_win_xwindow_get(sd);
4692    if (sd->x.xwin)
4693      {
4694         if (sd->floating)
4695           ecore_x_e_illume_window_state_set
4696              (sd->x.xwin, ECORE_X_ILLUME_WINDOW_STATE_FLOATING);
4697         else
4698           ecore_x_e_illume_window_state_set
4699              (sd->x.xwin, ECORE_X_ILLUME_WINDOW_STATE_NORMAL);
4700      }
4701 #endif
4702 }
4703
4704 EAPI Eina_Bool
4705 elm_win_floating_mode_get(const Evas_Object *obj)
4706 {
4707    ELM_WIN_CHECK(obj) EINA_FALSE;
4708    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
4709
4710    return sd->floating;
4711 }