atspi: Handle default label object on toolkit side
[platform/upstream/elementary.git] / src / lib / elm_win.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4
5 #define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED
6 #define ELM_INTERFACE_ATSPI_WIDGET_ACTION_PROTECTED
7 #define ELM_INTERFACE_ATSPI_COMPONENT_PROTECTED
8 #define ELM_WIN_PROTECTED
9
10 #include <Elementary.h>
11 #include <Elementary_Cursor.h>
12
13 #include "elm_priv.h"
14 #include "elm_widget_menu.h"
15
16 #define MY_CLASS ELM_WIN_CLASS
17
18 #define MY_CLASS_NAME "Elm_Win"
19 #define MY_CLASS_NAME_LEGACY "elm_win"
20
21 static const Elm_Win_Trap *trap = NULL;
22
23 #define TRAP(sd, name, ...)                                             \
24   do                                                                    \
25     {                                                                   \
26        if (sd->type != ELM_WIN_FAKE)                                    \
27          if ((!trap) || (!trap->name) ||                                \
28              ((trap->name) &&                                           \
29               (trap->name(sd->trap_data, sd->obj, ## __VA_ARGS__))))    \
30            ecore_evas_##name(sd->ee, ##__VA_ARGS__);                    \
31     }                                                                   \
32   while (0)
33
34 #define ELM_WIN_DATA_GET(o, sd) \
35   Elm_Win_Data * sd = eo_data_scope_get(o, MY_CLASS)
36
37 #define ELM_WIN_DATA_GET_OR_RETURN(o, ptr)           \
38   ELM_WIN_DATA_GET(o, ptr);                          \
39   if (!ptr)                                          \
40     {                                                \
41        CRI("No widget data for object %p (%s)", \
42                 o, evas_object_type_get(o));         \
43        return;                                       \
44     }
45
46 #define ELM_WIN_DATA_GET_OR_RETURN_VAL(o, ptr, val)  \
47   ELM_WIN_DATA_GET(o, ptr);                          \
48   if (!ptr)                                          \
49     {                                                \
50        CRI("No widget data for object %p (%s)", \
51                 o, evas_object_type_get(o));         \
52        return val;                                   \
53     }
54
55 #define ELM_WIN_CHECK(obj)                                             \
56   if (!obj || !eo_isa(obj, MY_CLASS)) \
57     return
58
59 #define DECREMENT_MODALITY()                                    \
60   EINA_LIST_FOREACH(_elm_win_list, l, current)                  \
61     {                                                           \
62        ELM_WIN_DATA_GET_OR_RETURN(current, cursd);              \
63        if ((obj != current) && (cursd->modal_count > 0))        \
64          {                                                      \
65             cursd->modal_count--;                               \
66          }                                                      \
67        if (cursd->modal_count == 0)                             \
68          {                                                      \
69             edje_object_signal_emit(cursd->edje, \
70                         "elm,action,hide_blocker", "elm");      \
71             eo_do(cursd->main_menu, eo_event_callback_call      \
72               (ELM_MENU_EVENT_ELM_ACTION_UNBLOCK_MENU, NULL));  \
73          }                                                      \
74     }
75
76 #define INCREMENT_MODALITY()                                    \
77   EINA_LIST_FOREACH(_elm_win_list, l, current)                  \
78     {                                                           \
79        ELM_WIN_DATA_GET_OR_RETURN(current, cursd);              \
80        if (obj != current)                                      \
81          {                                                      \
82             cursd->modal_count++;                               \
83          }                                                      \
84        if (cursd->modal_count > 0)                              \
85          {                                                      \
86             edje_object_signal_emit(cursd->edje, \
87                              "elm,action,show_blocker", "elm"); \
88             eo_do(cursd->main_menu, eo_event_callback_call      \
89               (ELM_WIN_EVENT_ELM_ACTION_BLOCK_MENU, NULL));     \
90          }                                                      \
91     }
92
93 #define ENGINE_GET() (_elm_preferred_engine ? _elm_preferred_engine : _elm_config->engine)
94
95 typedef struct _Elm_Win_Data Elm_Win_Data;
96
97 struct _Elm_Win_Data
98 {
99    Ecore_Evas           *ee;
100    Evas                 *evas;
101    Evas_Object          *parent; /* parent *window* object*/
102    Evas_Object          *img_obj, *frame_obj;
103    Evas_Object          *client_obj; /* rect representing the client */
104    Eo                   *edje; /**< edje object for a window layout */
105    Eo                   *box;
106    Evas_Object          *obj; /* The object itself */
107 #ifdef HAVE_ELEMENTARY_X
108    struct
109    {
110       Ecore_X_Window       xwin;
111       Ecore_Event_Handler *client_message_handler;
112       Ecore_Event_Handler *property_handler;
113    } x;
114 #endif
115 #ifdef HAVE_ELEMENTARY_WAYLAND
116    struct
117    {
118       Ecore_Wl_Window *win;
119       Eina_Bool opaque_dirty : 1;
120       Ecore_Event_Handler *effect_start_handler;
121       Ecore_Event_Handler *effect_end_handler;
122       Ecore_Event_Handler *indicator_flick_handler; // TIZEN_ONLY(20160801): indicator implementation
123       Ecore_Event_Handler *aux_msg_handler;
124    } wl;
125 #endif
126 #ifdef HAVE_ELEMENTARY_COCOA
127    struct {
128       Ecore_Cocoa_Window *win;
129    } cocoa;
130 #endif
131 #ifdef HAVE_ELEMENTARY_WIN32
132    struct
133    {
134       Ecore_Win32_Window *win;
135    } win32;
136 #endif
137
138    Ecore_Job                     *deferred_resize_job;
139    Ecore_Job                     *deferred_child_eval_job;
140    Ecore_Event_Handler           *mouse_up_handler;//TIZEN_ONLY(20161121) tizen don't have canvas mouse up event like opensource now.
141
142    Elm_Win_Type                   type;
143    Elm_Win_Keyboard_Mode          kbdmode;
144    Elm_Win_Indicator_Mode         indmode;
145    Elm_Win_Indicator_Opacity_Mode ind_o_mode;
146    Eina_Rectangle kbd;
147    Eina_Rectangle ind;
148    struct
149    {
150       const char  *info;
151       Ecore_Timer *timer;
152       int          repeat_count;
153       int          shot_counter;
154    } shot;
155    int                            resize_location;
156    int                           *autodel_clear, rot;
157    struct
158    {
159       int x, y;
160    } screen;
161    struct
162    {
163 #if 0
164       Ecore_Evas  *ee;
165 #endif
166       Evas        *evas;
167       Evas_Object *obj, *hot_obj;
168       int          hot_x, hot_y;
169    } pointer;
170    struct
171    {
172       Evas_Object *fobj; /* focus highlight edje object */
173
174       struct
175       {
176          Evas_Object *target;
177          Eina_Bool    visible : 1;
178          Eina_Bool    in_theme: 1; /**< focus highlight is handled by theme.
179                                      this is set true if edc data item "focus_highlight" is set to "on" during focus in callback. */
180       } cur, prev;
181
182       const char  *style;
183       Ecore_Job   *reconf_job;
184
185       Eina_Bool    enabled : 1;
186       Eina_Bool    theme_changed : 1; /* set true when the focus theme is changed */
187       Eina_Bool    animate : 1; /* set true when the focus highlight animate is enabled */
188       Eina_Bool    animate_supported : 1; /* set true when the focus highlight animate is supported by theme */
189       Eina_Bool    geometry_changed : 1;
190       Eina_Bool    auto_enabled : 1;
191       Eina_Bool    auto_animate : 1;
192    } focus_highlight;
193    //TIZEN_ONLY(20160404) Accessibility Highlight Frame added (99248ce)
194    struct
195    {
196       Evas_Object *fobj; /* accessibility highlight edje object */
197
198       struct
199       {
200          Evas_Object *target;
201          //TIZEN_ONLY(20160623): atspi: moved highlight when object is out of screen
202          int x;
203          int y;
204          int w;
205          int h;
206          Eina_Bool need_moved;
207          //
208       } cur, prev;
209
210    } accessibility_highlight;
211    //
212    //TIZEN_ONLY(20170919): Handle default label object
213    Eina_List *default_label_objs;
214    //
215    Evas_Object *icon;
216    const char  *title;
217    const char  *icon_name;
218    const char  *role;
219    const char  *frame_style;
220    Eina_Stringshare *name;
221
222    Evas_Object *main_menu;
223
224    struct
225    {
226       const char  *name;
227       const char **available_list;
228       unsigned int count;
229    } profile;
230    struct
231    {
232       int          preferred_rot; /* indicates preferred rotation value, -1 means invalid. */
233       int         *rots; /* indicates available rotations */
234       unsigned int count; /* number of elements in available rotations */
235       Eina_Bool    wm_supported : 1; /* set true when the window manager support window rotation */
236       Eina_Bool    use : 1; /* set ture when application use window manager rotation. */
237 // TIZEN_ONLY(20170212): pend rotation until app set rotation
238       Eina_Bool    rotation_pending : 1; /* set true when application will manage the rotation */
239 //
240    } wm_rot;
241
242    Eo *socket_proxy; /* reference object to atspi object in separate process @since 1.15 */
243
244    void *trap_data;
245
246    struct
247      {
248         Ecore_Animator *obj;
249         unsigned short wants;
250      } animator;
251
252    double       aspect;
253    int          size_base_w, size_base_h;
254    int          size_step_w, size_step_h;
255    int          norender;
256    int          modal_count;
257    Eina_Bool    urgent : 1;
258    Eina_Bool    modal : 1;
259    Eina_Bool    demand_attention : 1;
260    Eina_Bool    autodel : 1;
261    Eina_Bool    autohide : 1;
262    Eina_Bool    constrain : 1;
263    Eina_Bool    resizing : 1;
264    Eina_Bool    iconified : 1;
265    Eina_Bool    withdrawn : 1;
266    Eina_Bool    sticky : 1;
267    Eina_Bool    fullscreen : 1;
268    Eina_Bool    maximized : 1;
269    Eina_Bool    skip_focus : 1;
270    Eina_Bool    floating : 1;
271    Eina_Bool    noblank : 1;
272    Eina_Bool    theme_alpha : 1; /**< alpha value fetched by a theme. this has higher priority than application_alpha */
273    Eina_Bool    application_alpha : 1; /**< alpha value set by an elm_win_alpha_set() api. this has lower priority than theme_alpha */
274    Eina_Bool    obscured :1;
275    Eina_Bool    borderless : 1;
276 };
277
278 static const char SIG_DELETE_REQUEST[] = "delete,request";
279 static const char SIG_FOCUS_OUT[] = "focus,out"; // deprecated. use "unfocused" instead.
280 static const char SIG_FOCUS_IN[] = "focus,in"; // deprecated. use "focused" instead.
281 static const char SIG_MOVED[] = "moved";
282 static const char SIG_WITHDRAWN[] = "withdrawn";
283 static const char SIG_ICONIFIED[] = "iconified";
284 static const char SIG_NORMAL[] = "normal";
285 static const char SIG_STICK[] = "stick";
286 static const char SIG_UNSTICK[] = "unstick";
287 static const char SIG_FULLSCREEN[] = "fullscreen";
288 static const char SIG_UNFULLSCREEN[] = "unfullscreen";
289 static const char SIG_MAXIMIZED[] = "maximized";
290 static const char SIG_UNMAXIMIZED[] = "unmaximized";
291 static const char SIG_IOERR[] = "ioerr";
292 static const char SIG_INDICATOR_PROP_CHANGED[] = "indicator,prop,changed";
293 static const char SIG_ROTATION_CHANGED[] = "rotation,changed";
294 static const char SIG_PROFILE_CHANGED[] = "profile,changed";
295 static const char SIG_WM_ROTATION_CHANGED[] = "wm,rotation,changed";
296 #ifdef HAVE_ELEMENTARY_WAYLAND
297 static const char SIG_CONFORMANT_CHANGED[] = "conformant,changed";
298 static const char SIG_INDICATOR_FLICK_DONE[] = "indicator,flick,done"; // TIZEN_ONLY(20160801): indicator implementation
299 #endif
300 static const char SIG_AUX_HINT_ALLOWED[] = "aux,hint,allowed";
301 static const char SIG_AUX_MESSAGE_RECEIVED[] = "aux,msg,received";
302 static const char SIG_VISIBILITY_CHANGED[] = "visibility,changed";
303 static const char SIG_EFFECT_STARTED[] = "effect,started";
304 static const char SIG_EFFECT_DONE[] = "effect,done";
305 static const char SIG_LAUNCH_DONE[] = "launch,done";
306 //TIZEN_ONLY(20161028): add smart signal 'atspi,screen,reader,changed'
307 static const char SIG_ATSPI_SCREEN_READER_CHANGED[] = "atspi,screen,reader,changed";
308 //
309
310 static const Evas_Smart_Cb_Description _smart_callbacks[] = {
311    {SIG_DELETE_REQUEST, ""},
312    {SIG_FOCUS_OUT, ""},
313    {SIG_FOCUS_IN, ""},
314    {SIG_MOVED, ""},
315    {SIG_WITHDRAWN, ""},
316    {SIG_ICONIFIED, ""},
317    {SIG_NORMAL, ""},
318    {SIG_STICK, ""},
319    {SIG_UNSTICK, ""},
320    {SIG_FULLSCREEN, ""},
321    {SIG_UNFULLSCREEN, ""},
322    {SIG_MAXIMIZED, ""},
323    {SIG_UNMAXIMIZED, ""},
324    {SIG_IOERR, ""},
325    {SIG_INDICATOR_PROP_CHANGED, ""},
326    {SIG_ROTATION_CHANGED, ""},
327    {SIG_PROFILE_CHANGED, ""},
328    {SIG_WM_ROTATION_CHANGED, ""},
329    {SIG_WIDGET_FOCUSED, ""}, /**< handled by elm_widget */
330    {SIG_WIDGET_UNFOCUSED, ""}, /**< handled by elm_widget */
331 #ifdef HAVE_ELEMENTARY_WAYLAND
332    {SIG_CONFORMANT_CHANGED, ""},
333 #endif
334    {SIG_AUX_HINT_ALLOWED, ""},
335    {SIG_VISIBILITY_CHANGED, ""},
336    {SIG_EFFECT_STARTED, ""},
337    {SIG_EFFECT_DONE, ""},
338    {SIG_LAUNCH_DONE, ""},
339    //TIZEN_ONLY(20161028): add smart signal 'atspi,screen,reader,changed'
340    {SIG_ATSPI_SCREEN_READER_CHANGED, ""},
341    //
342    {NULL, NULL}
343 };
344
345 static Eina_Bool _key_action_return(Evas_Object *obj, const char *params);
346 static Eina_Bool _key_action_move(Evas_Object *obj, const char *params);
347
348 static const Elm_Action key_actions[] = {
349    {"return", _key_action_return},
350    {"move", _key_action_move},
351    {NULL, NULL}
352 };
353
354 Eina_List *_elm_win_list = NULL;
355 int _elm_win_deferred_free = 0;
356
357 static Eina_Bool _elm_win_throttle_ok = EINA_FALSE;
358 static int _elm_win_count = 0;
359
360 // TIZEN_ONLY(20160218): Improve launching performance.
361 static Evas_Object *_precreated_win_obj = NULL;
362 //
363
364 static Eina_Bool _elm_win_auto_throttled = EINA_FALSE;
365
366 static Ecore_Job *_elm_win_state_eval_job = NULL;
367
368 static void
369 _elm_win_on_resize_obj_changed_size_hints(void *data,
370                                           Evas *e,
371                                           Evas_Object *obj,
372                                           void *event_info);
373 static void
374 _elm_win_img_callbacks_del(Evas_Object *obj, Evas_Object *imgobj);
375 static Elm_Theme_Apply _elm_win_theme_internal(Eo *obj, Elm_Win_Data *sd);
376 static void
377 _elm_win_borderless_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool borderless);
378
379 #ifdef HAVE_ELEMENTARY_X
380 static void _elm_win_xwin_update(Elm_Win_Data *sd);
381 #endif
382
383 EAPI double _elm_startup_time = 0;
384
385 static void
386 _elm_win_first_frame_do(void *data, Evas *e EINA_UNUSED, void *event_info EINA_UNUSED)
387 {
388    double end = ecore_time_unix_get();
389    char *first = data;
390
391    switch (*first)
392      {
393       case 'A': abort();
394       case 'E':
395       case 'D': exit(-1);
396       case 'T': fprintf(stderr, "Startup time: '%f' - '%f' = '%f' sec\n", end, _elm_startup_time, end - _elm_startup_time);
397                 break;
398      }
399
400    evas_event_callback_del_full(e, EVAS_CALLBACK_RENDER_POST, _elm_win_first_frame_do, data);
401 }
402
403 static void
404 _win_noblank_eval(void)
405 {
406 #ifdef HAVE_ELEMENTARY_X
407    Eina_List *l;
408    Evas_Object *obj;
409    int noblanks = 0;
410    Eina_Bool change = EINA_FALSE;
411
412    EINA_LIST_FOREACH(_elm_win_list, l, obj)
413      {
414         ELM_WIN_DATA_GET(obj, sd);
415
416         if (sd->x.xwin)
417           {
418              if ((sd->noblank) && (!sd->iconified) && (!sd->withdrawn) &&
419                  evas_object_visible_get(obj))
420                noblanks++;
421
422              change = EINA_TRUE;
423           }
424      }
425
426    if (!change) return;
427
428    if (noblanks > 0) ecore_x_screensaver_suspend();
429    else ecore_x_screensaver_resume();
430 #endif
431 #ifdef HAVE_ELEMENTARY_WAYLAND
432    // XXX: no wl implementation of this yet - maybe higher up at prop level
433 #endif
434 }
435
436 static Elm_Process_State _elm_process_state = ELM_PROCESS_STATE_FOREGROUND;
437
438 EAPI Elm_Process_State
439 elm_process_state_get(void)
440 {
441    return _elm_process_state;
442 }
443
444 static void
445 _elm_win_apply_alpha(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
446 {
447    Eina_Bool enabled;
448
449    enabled = sd->theme_alpha | sd->application_alpha;
450    if (sd->img_obj)
451      {
452         evas_object_image_alpha_set(sd->img_obj, enabled);
453         ecore_evas_alpha_set(sd->ee, enabled);
454      }
455    else
456      {
457 #ifdef HAVE_ELEMENTARY_X
458         if (sd->x.xwin)
459           {
460              if (enabled)
461                {
462                   if (!ecore_x_screen_is_composited(0))
463                     elm_win_shaped_set(obj, enabled);
464                   else
465                     TRAP(sd, alpha_set, enabled);
466                }
467              else
468                TRAP(sd, alpha_set, enabled);
469              _elm_win_xwin_update(sd);
470           }
471         else
472 #endif
473           TRAP(sd, alpha_set, enabled);
474      }
475 }
476
477 static void
478 _elm_win_state_eval(void *data EINA_UNUSED)
479 {
480    Eina_List *l;
481    Evas_Object *obj;
482    int _elm_win_count_shown = 0;
483    int _elm_win_count_iconified = 0;
484    int _elm_win_count_withdrawn = 0;
485    Eina_Bool throttle = EINA_FALSE;
486
487    _elm_win_state_eval_job = NULL;
488
489    EINA_LIST_FOREACH(_elm_win_list, l, obj)
490      {
491         if (_elm_config->auto_norender_withdrawn)
492           {
493              if ((elm_win_withdrawn_get(obj)) ||
494                  ((elm_win_iconified_get(obj) &&
495                    (_elm_config->auto_norender_iconified_same_as_withdrawn))))
496                {
497                   if (!evas_object_data_get(obj, "__win_auto_norender"))
498                     {
499                        Evas *evas = evas_object_evas_get(obj);
500
501                        elm_win_norender_push(obj);
502                        evas_object_data_set(obj, "__win_auto_norender", obj);
503
504                        if (_elm_config->auto_flush_withdrawn)
505                          {
506                             edje_file_cache_flush();
507                             edje_collection_cache_flush();
508                             evas_image_cache_flush(evas);
509                             evas_font_cache_flush(evas);
510                          }
511                        if (_elm_config->auto_dump_withdrawn)
512                          {
513                             evas_render_dump(evas);
514                          }
515                     }
516                   continue;
517                }
518           }
519         if (evas_object_data_get(obj, "__win_auto_norender"))
520           {
521              elm_win_norender_pop(obj);
522              evas_object_data_del(obj, "__win_auto_norender");
523           }
524      }
525    if (((_elm_config->auto_throttle) &&
526         (elm_policy_get(ELM_POLICY_THROTTLE) != ELM_POLICY_THROTTLE_NEVER)) ||
527         (elm_policy_get(ELM_POLICY_THROTTLE) == ELM_POLICY_THROTTLE_HIDDEN_ALWAYS))
528      throttle = EINA_TRUE;
529    if (_elm_win_count == 0)
530      {
531         if ((_elm_win_throttle_ok) && (_elm_win_auto_throttled))
532           {
533              _elm_process_state = ELM_PROCESS_STATE_FOREGROUND;
534              ecore_event_add(ELM_EVENT_PROCESS_FOREGROUND, NULL, NULL, NULL);
535              if (throttle)
536                ecore_throttle_adjust(-_elm_config->auto_throttle_amount);
537              _elm_win_auto_throttled = EINA_FALSE;
538           }
539      }
540    else
541      {
542         EINA_LIST_FOREACH(_elm_win_list, l, obj)
543           {
544              if (elm_win_withdrawn_get(obj)) _elm_win_count_withdrawn++;
545              else if (elm_win_iconified_get(obj)) _elm_win_count_iconified++;
546              else if (evas_object_visible_get(obj)) _elm_win_count_shown++;
547           }
548         if (_elm_win_count_shown <= 0)
549           {
550              if ((_elm_win_throttle_ok) && (!_elm_win_auto_throttled))
551                {
552                   _elm_process_state = ELM_PROCESS_STATE_BACKGROUND;
553                   ecore_event_add(ELM_EVENT_PROCESS_BACKGROUND, NULL, NULL, NULL);
554                   if (throttle)
555                     ecore_throttle_adjust(_elm_config->auto_throttle_amount);
556                   _elm_win_auto_throttled = EINA_TRUE;
557                }
558           }
559         else
560           {
561              if ((_elm_win_throttle_ok) && (_elm_win_auto_throttled))
562                {
563                   _elm_process_state = ELM_PROCESS_STATE_FOREGROUND;
564                   ecore_event_add(ELM_EVENT_PROCESS_FOREGROUND, NULL, NULL, NULL);
565                   if (throttle)
566                     ecore_throttle_adjust(-_elm_config->auto_throttle_amount);
567                   _elm_win_auto_throttled = EINA_FALSE;
568                }
569           }
570      }
571    _win_noblank_eval();
572    return;
573 }
574
575 static Eina_Bool
576 _elm_win_policy_quit_triggered(Eo* triggering_obj)
577 {
578    if ((!_elm_win_list) &&
579        (elm_policy_get(ELM_POLICY_QUIT) == ELM_POLICY_QUIT_LAST_WINDOW_CLOSED))
580      {
581         return EINA_TRUE;
582      }
583
584    if (elm_policy_get(ELM_POLICY_QUIT) == ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN)
585      {
586         Eina_List *l;
587         Evas_Object *win;
588
589         EINA_LIST_FOREACH(_elm_win_list, l, win)
590           if (win != triggering_obj && evas_object_visible_get(win) == EINA_TRUE)
591             {
592                return EINA_FALSE;
593             }
594         return EINA_TRUE;
595      }
596
597    return EINA_FALSE;
598 }
599
600 static void
601 _elm_win_flush_cache_and_exit(Eo *obj)
602 {
603    edje_file_cache_flush();
604    edje_collection_cache_flush();
605    evas_image_cache_flush(evas_object_evas_get(obj));
606    evas_font_cache_flush(evas_object_evas_get(obj));
607    elm_exit();
608 }
609
610 static void
611 _elm_win_state_eval_queue(void)
612 {
613    if (_elm_win_state_eval_job) ecore_job_del(_elm_win_state_eval_job);
614    _elm_win_state_eval_job = ecore_job_add(_elm_win_state_eval, NULL);
615 }
616
617 // example shot spec (wait 0.1 sec then save as my-window.png):
618 // ELM_ENGINE="shot:delay=0.1:file=my-window.png"
619
620 static double
621 _shot_delay_get(Elm_Win_Data *sd)
622 {
623    char *p, *pd;
624    char *d = strdup(sd->shot.info);
625
626    if (!d) return 0.5;
627    for (p = (char *)sd->shot.info; *p; p++)
628      {
629         if (!strncmp(p, "delay=", 6))
630           {
631              double v;
632
633              for (pd = d, p += 6; (*p) && (*p != ':'); p++, pd++)
634                {
635                   *pd = *p;
636                }
637              *pd = 0;
638              v = _elm_atof(d);
639              free(d);
640              return v;
641           }
642      }
643    free(d);
644
645    return 0.5;
646 }
647
648 static char *
649 _shot_file_get(Elm_Win_Data *sd)
650 {
651    char *p;
652    char *tmp = strdup(sd->shot.info);
653    char *repname = NULL;
654
655    if (!tmp) return NULL;
656
657    for (p = (char *)sd->shot.info; *p; p++)
658      {
659         if (!strncmp(p, "file=", 5))
660           {
661              strcpy(tmp, p + 5);
662              if (!sd->shot.repeat_count) return tmp;
663              else
664                {
665                   char *dotptr = strrchr(tmp, '.');
666                   if (dotptr)
667                     {
668                        size_t size = sizeof(char) * (strlen(tmp) + 16);
669                        repname = malloc(size);
670                        if (repname)
671                          {
672                             strncpy(repname, tmp, dotptr - tmp);
673                             snprintf(repname + (dotptr - tmp), size -
674                                      (dotptr - tmp), "%03i",
675                                      sd->shot.shot_counter + 1);
676                             strcat(repname, dotptr);
677                          }
678                        free(tmp);
679                        return repname;
680                     }
681                }
682           }
683      }
684    free(tmp);
685    if (!sd->shot.repeat_count) return strdup("out.png");
686
687    repname = malloc(sizeof(char) * 24);
688    if (!repname) return NULL;
689    snprintf(repname, sizeof(char) * 24, "out%03i.png",
690             sd->shot.shot_counter + 1);
691
692    return repname;
693 }
694
695 static int
696 _shot_repeat_count_get(Elm_Win_Data *sd)
697 {
698    char *p, *pd;
699    char *d = strdup(sd->shot.info);
700
701    if (!d) return 0;
702    for (p = (char *)sd->shot.info; *p; p++)
703      {
704         if (!strncmp(p, "repeat=", 7))
705           {
706              int v;
707
708              for (pd = d, p += 7; (*p) && (*p != ':'); p++, pd++)
709                {
710                   *pd = *p;
711                }
712              *pd = 0;
713              v = atoi(d);
714              if (v < 0) v = 0;
715              if (v > 1000) v = 999;
716              free(d);
717              return v;
718           }
719      }
720    free(d);
721
722    return 0;
723 }
724
725 static char *
726 _shot_key_get(Elm_Win_Data *sd EINA_UNUSED)
727 {
728    return NULL;
729 }
730
731 static char *
732 _shot_flags_get(Elm_Win_Data *sd EINA_UNUSED)
733 {
734    return NULL;
735 }
736
737 static void
738 _shot_do(Elm_Win_Data *sd)
739 {
740    Ecore_Evas *ee;
741    Evas_Object *o;
742    unsigned int *pixels;
743    int w, h;
744    char *file, *key, *flags;
745
746    ecore_evas_manual_render(sd->ee);
747    pixels = (void *)ecore_evas_buffer_pixels_get(sd->ee);
748    if (!pixels) return;
749
750    ecore_evas_geometry_get(sd->ee, NULL, NULL, &w, &h);
751    if ((w < 1) || (h < 1)) return;
752
753    file = _shot_file_get(sd);
754    if (!file) return;
755
756    key = _shot_key_get(sd);
757    flags = _shot_flags_get(sd);
758    ee = ecore_evas_buffer_new(1, 1);
759    o = evas_object_image_add(ecore_evas_get(ee));
760    evas_object_image_alpha_set(o,
761                                sd->theme_alpha | sd->application_alpha);
762    evas_object_image_size_set(o, w, h);
763    evas_object_image_data_set(o, pixels);
764    if (!evas_object_image_save(o, file, key, flags))
765      {
766         ERR("Cannot save window to '%s' (key '%s', flags '%s')",
767             file, key, flags);
768      }
769    free(file);
770    free(key);
771    free(flags);
772    ecore_evas_free(ee);
773    if (sd->shot.repeat_count) sd->shot.shot_counter++;
774 }
775
776 static Eina_Bool
777 _shot_delay(void *data)
778 {
779    ELM_WIN_DATA_GET(data, sd);
780
781    _shot_do(sd);
782    if (sd->shot.repeat_count)
783      {
784         int remainshot = (sd->shot.repeat_count - sd->shot.shot_counter);
785         if (remainshot > 0) return EINA_TRUE;
786      }
787    sd->shot.timer = NULL;
788    elm_exit();
789
790    return EINA_FALSE;
791 }
792
793 static void
794 _shot_init(Elm_Win_Data *sd)
795 {
796    if (!sd->shot.info) return;
797
798    sd->shot.repeat_count = _shot_repeat_count_get(sd);
799    sd->shot.shot_counter = 0;
800 }
801
802 static void
803 _shot_handle(Elm_Win_Data *sd)
804 {
805    if (!sd->shot.info) return;
806
807    if (!sd->shot.timer)
808      sd->shot.timer = ecore_timer_add(_shot_delay_get(sd), _shot_delay,
809                                       sd->obj);
810 }
811
812 /* elm-win specific associate, does the trap while ecore_evas_object_associate()
813  * does not.
814  */
815 static Elm_Win_Data *
816 _elm_win_associate_get(const Ecore_Evas *ee)
817 {
818    Evas_Object *obj = ecore_evas_data_get(ee, "elm_win");
819    if (!obj) return NULL;
820    ELM_WIN_DATA_GET(obj, sd);
821    return sd;
822 }
823
824 /* Interceptors Callbacks */
825 static void
826 _elm_win_obj_intercept_raise(void *data, Evas_Object *obj EINA_UNUSED)
827 {
828    ELM_WIN_DATA_GET(data, sd);
829    TRAP(sd, raise);
830 }
831
832 static void
833 _elm_win_obj_intercept_lower(void *data, Evas_Object *obj EINA_UNUSED)
834 {
835    ELM_WIN_DATA_GET(data, sd);
836    TRAP(sd, lower);
837 }
838
839 static void
840 _elm_win_obj_intercept_stack_above(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, Evas_Object *above EINA_UNUSED)
841 {
842    INF("TODO: %s", __FUNCTION__);
843 }
844
845 static void
846 _elm_win_obj_intercept_stack_below(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, Evas_Object *below EINA_UNUSED)
847 {
848    INF("TODO: %s", __FUNCTION__);
849 }
850
851 static void
852 _elm_win_obj_intercept_layer_set(void *data, Evas_Object *obj EINA_UNUSED, int l)
853 {
854    ELM_WIN_DATA_GET(data, sd);
855    TRAP(sd, layer_set, l);
856 }
857
858 /* Event Callbacks */
859
860 static void
861 _elm_win_obj_callback_changed_size_hints(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
862 {
863    ELM_WIN_DATA_GET(data, sd);
864    Evas_Coord w, h;
865
866    evas_object_size_hint_min_get(obj, &w, &h);
867    TRAP(sd, size_min_set, w, h);
868
869    evas_object_size_hint_max_get(obj, &w, &h);
870    if (w < 1) w = -1;
871    if (h < 1) h = -1;
872    TRAP(sd, size_max_set, w, h);
873 }
874 /* end of elm-win specific associate */
875
876 static void
877 _elm_win_move(Ecore_Evas *ee)
878 {
879    Elm_Win_Data *sd = _elm_win_associate_get(ee);
880    int x, y;
881
882    if (!sd) return;
883
884    ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
885    sd->screen.x = x;
886    sd->screen.y = y;
887    eo_do(sd->obj, eo_event_callback_call(ELM_WIN_EVENT_MOVED, NULL));
888    evas_nochange_push(evas_object_evas_get(sd->obj));
889    evas_object_move(sd->obj, x, y);
890    evas_nochange_pop(evas_object_evas_get(sd->obj));
891 }
892
893 static void
894 _elm_win_resize_job(void *data)
895 {
896    ELM_WIN_DATA_GET(data, sd);
897    int x, y, w, h;
898
899    sd->deferred_resize_job = NULL;
900    ecore_evas_request_geometry_get(sd->ee, &x, &y, &w, &h);
901    if (sd->constrain)
902      {
903         int sw, sh;
904         ecore_evas_screen_geometry_get(sd->ee, NULL, NULL, &sw, &sh);
905         w = MIN(w, sw);
906         h = MIN(h, sh);
907      }
908
909    if (sd->frame_obj)
910      {
911         int fx, fy, fw, fh;
912
913         evas_output_framespace_get(sd->evas, &fx, &fy, &fw, &fh);
914         evas_object_move(sd->frame_obj, -fx, -fy);
915         evas_object_resize(sd->frame_obj, w + fw, h + fh);
916      }
917
918    evas_object_resize(sd->obj, w, h);
919    evas_object_resize(sd->edje, w, h);
920
921 #ifdef HAVE_ELEMENTARY_WAYLAND
922    ecore_wl_window_opaque_region_set(sd->wl.win, x, y, w, h);
923 #endif
924 }
925
926 static void
927 _elm_win_resize(Ecore_Evas *ee)
928 {
929    Elm_Win_Data *sd = _elm_win_associate_get(ee);
930    if (!sd) return;
931
932    ecore_job_del(sd->deferred_resize_job);
933    sd->deferred_resize_job = ecore_job_add(_elm_win_resize_job, sd->obj);
934 }
935
936 static void
937 _elm_win_mouse_in(Ecore_Evas *ee)
938 {
939    Elm_Win_Data *sd = _elm_win_associate_get(ee);
940    if (!sd) return;
941
942    _elm_win_throttle_ok = EINA_TRUE;
943    if (sd->resizing) sd->resizing = EINA_FALSE;
944 }
945
946 static void
947 _elm_win_focus_highlight_reconfigure_job_stop(Elm_Win_Data *sd)
948 {
949    ELM_SAFE_FREE(sd->focus_highlight.reconf_job, ecore_job_del);
950 }
951
952 static void
953 _elm_win_accessibility_highlight_visible_set(Elm_Win_Data *sd,
954                                      Eina_Bool visible)
955 {
956    Evas_Object *fobj = sd->accessibility_highlight.fobj;
957
958    if (!fobj)
959      return;
960
961    if (visible)
962      {
963         evas_object_show(fobj);
964      }
965    else
966      {
967         evas_object_smart_member_del(fobj);
968         evas_object_hide(fobj);
969         evas_object_del(fobj);
970      }
971 }
972
973 static void
974 _elm_win_focus_highlight_visible_set(Elm_Win_Data *sd,
975                                      Eina_Bool visible)
976 {
977    Evas_Object *fobj = sd->focus_highlight.fobj;
978    if (!fobj) return;
979
980    if (visible)
981      {
982         evas_object_show(fobj);
983         edje_object_signal_emit(fobj, "elm,action,focus,show", "elm");
984      }
985    else
986      {
987         edje_object_signal_emit(fobj, "elm,action,focus,hide", "elm");
988      }
989 }
990
991 Evas_Object *
992 _elm_win_focus_highlight_object_get(Evas_Object *obj)
993 {
994    ELM_WIN_DATA_GET(obj, sd);
995
996    return sd->focus_highlight.fobj;
997 }
998
999 static void
1000 _elm_win_focus_highlight_anim_setup(Elm_Win_Data *sd,
1001                                     Evas_Object *obj)
1002 {
1003    Evas_Coord tx, ty, tw, th;
1004    Evas_Coord px, py, pw, ph;
1005    Edje_Message_Int_Set *m;
1006    Evas_Object *target = sd->focus_highlight.cur.target;
1007
1008    evas_object_geometry_get(obj, &px, &py, &pw, &ph);
1009    elm_widget_focus_highlight_geometry_get(target, &tx, &ty, &tw, &th);
1010    evas_object_move(obj, tx, ty);
1011    evas_object_resize(obj, tw, th);
1012
1013    if ((px == tx) && (py == ty) && (pw == tw) && (ph == th)) return;
1014
1015    if (!_elm_config->focus_highlight_clip_disable)
1016      evas_object_clip_unset(obj);
1017
1018    m = alloca(sizeof(*m) + (sizeof(int) * 8));
1019    m->count = 8;
1020    m->val[0] = px - tx;
1021    m->val[1] = py - ty;
1022    m->val[2] = pw;
1023    m->val[3] = ph;
1024    m->val[4] = 0;
1025    m->val[5] = 0;
1026    m->val[6] = tw;
1027    m->val[7] = th;
1028    edje_object_message_send(obj, EDJE_MESSAGE_INT_SET, 1, m);
1029 }
1030
1031 static void
1032 _elm_win_accessibility_highlight_simple_setup(Elm_Win_Data *sd,
1033                                       Evas_Object *obj)
1034 {
1035    Evas_Object *target = sd->accessibility_highlight.cur.target;
1036    Evas_Coord x, y, w, h;
1037    //TIZEN_ONLY(20160623): atspi: moved highlight when object is out of screen
1038    Evas_Coord ox, oy;
1039    Elm_Atspi_Role role;
1040    //
1041
1042    _elm_widget_showing_geometry_get(target, &x, &y, &w, &h);
1043
1044    //TIZEN_ONLY(20160623): atspi: moved highlight when object is out of screen
1045    evas_object_geometry_get(target, &ox, &oy, NULL, NULL);
1046
1047    if (((w < 0 && ox > sd->accessibility_highlight.cur.x) || (h < 0 && oy < sd->accessibility_highlight.cur.y))
1048      && sd->accessibility_highlight.cur.need_moved
1049      && eo_isa(target, ELM_INTERFACE_ATSPI_ACCESSIBLE_MIXIN))
1050      {
1051         eo_do(target, role = elm_interface_atspi_accessible_role_get());
1052         if (role && role != ELM_ATSPI_ROLE_MENU_ITEM && role != ELM_ATSPI_ROLE_LIST_ITEM)
1053           {
1054              elm_interface_atspi_accessible_move_outed_signal_emit(target, ELM_ATSPI_MOVE_OUTED_TOP_LEFT);
1055              sd->accessibility_highlight.cur.need_moved = EINA_FALSE;
1056              return ;
1057           }
1058      }
1059    else if (((w < 0 && ox < sd->accessibility_highlight.cur.x) || (h < 0 && oy > sd->accessibility_highlight.cur.y))
1060            && sd->accessibility_highlight.cur.need_moved
1061            && eo_isa(target, ELM_INTERFACE_ATSPI_ACCESSIBLE_MIXIN))
1062      {
1063         eo_do(target, role = elm_interface_atspi_accessible_role_get());
1064         if (role && role != ELM_ATSPI_ROLE_MENU_ITEM && role != ELM_ATSPI_ROLE_LIST_ITEM)
1065           {
1066              elm_interface_atspi_accessible_move_outed_signal_emit(target, ELM_ATSPI_MOVE_OUTED_BOTTOM_RIGHT);
1067                  sd->accessibility_highlight.cur.need_moved = EINA_FALSE;
1068              return ;
1069           }
1070      }
1071    //
1072
1073    evas_object_move(obj, x, y);
1074    evas_object_resize(obj, w, h);
1075
1076    //TIZEN_ONLY(20160623): atspi: moved highlight when object is out of screen
1077    sd->accessibility_highlight.cur.x = ox;
1078    sd->accessibility_highlight.cur.y = oy;
1079    //
1080 }
1081
1082 static void
1083 _elm_win_focus_highlight_simple_setup(Elm_Win_Data *sd,
1084                                       Evas_Object *obj)
1085 {
1086    Evas_Object *clip, *target = sd->focus_highlight.cur.target;
1087    Evas_Coord x, y, w, h;
1088
1089    elm_widget_focus_highlight_geometry_get(target, &x, &y, &w, &h);
1090
1091    evas_object_move(obj, x, y);
1092    evas_object_resize(obj, w, h);
1093
1094    if (!_elm_config->focus_highlight_clip_disable)
1095      {
1096         clip = evas_object_clip_get(target);
1097         if (clip) evas_object_clip_set(obj, clip);
1098      }
1099
1100    edje_object_signal_emit(obj, "elm,state,anim,stop", "elm");
1101 }
1102
1103 static void
1104 _elm_win_focus_prev_target_del(void *data,
1105                                Evas *e EINA_UNUSED,
1106                                Evas_Object *obj EINA_UNUSED,
1107                                void *event_info EINA_UNUSED)
1108 {
1109    ELM_WIN_DATA_GET(data, sd);
1110    sd->focus_highlight.prev.target = NULL;
1111 }
1112
1113 static void
1114 _elm_win_accessibility_highlight_hide(void *data)
1115 {
1116    ELM_WIN_DATA_GET(data, sd);
1117    _elm_win_accessibility_highlight_visible_set(sd, EINA_FALSE);
1118 }
1119
1120 static void
1121 _elm_win_accessibility_highlight_show(void *data)
1122 {
1123    ELM_WIN_DATA_GET(data, sd);
1124    Evas_Object *fobj = sd->accessibility_highlight.fobj;
1125    _elm_win_accessibility_highlight_simple_setup(sd, fobj);
1126    _elm_win_accessibility_highlight_visible_set(sd, EINA_TRUE);
1127 }
1128
1129
1130 static void
1131 _elm_win_focus_highlight_reconfigure_job(void *data)
1132 {
1133    ELM_WIN_DATA_GET(data, sd);
1134    Evas_Object *target = sd->focus_highlight.cur.target;
1135    Evas_Object *previous = sd->focus_highlight.prev.target;
1136    Evas_Object *fobj = sd->focus_highlight.fobj;
1137    Eina_Bool visible_changed;
1138    Eina_Bool common_visible;
1139    const char *sig = NULL;
1140    const char *focus_style_target = NULL;
1141    const char *focus_style_previous = NULL;
1142
1143    _elm_win_focus_highlight_reconfigure_job_stop(sd);
1144
1145    visible_changed = (sd->focus_highlight.cur.visible !=
1146                       sd->focus_highlight.prev.visible);
1147
1148    if ((target == previous) && (!visible_changed) &&
1149        (!sd->focus_highlight.geometry_changed) &&
1150        (!sd->focus_highlight.theme_changed))
1151      return;
1152
1153    if (previous)
1154      {
1155         evas_object_event_callback_del_full
1156            (previous, EVAS_CALLBACK_DEL, _elm_win_focus_prev_target_del, data);
1157         if (sd->focus_highlight.prev.in_theme)
1158           elm_widget_signal_emit
1159              (previous, "elm,action,focus_highlight,hide", "elm");
1160      }
1161
1162    if (!target)
1163      common_visible = EINA_FALSE;
1164    else if (sd->focus_highlight.cur.in_theme)
1165      {
1166         common_visible = EINA_FALSE;
1167         if (sd->focus_highlight.cur.visible)
1168           sig = "elm,action,focus_highlight,show";
1169         else
1170           sig = "elm,action,focus_highlight,hide";
1171      }
1172    else
1173      common_visible = sd->focus_highlight.cur.visible;
1174
1175    if (sig)
1176      elm_widget_signal_emit(target, sig, "elm");
1177
1178    if ((!target) || (!common_visible) || (sd->focus_highlight.cur.in_theme))
1179      {
1180         if (target)
1181           _elm_win_focus_highlight_simple_setup(sd, fobj);
1182         goto the_end;
1183      }
1184
1185    if (previous)
1186      focus_style_previous = elm_widget_focus_highlight_style_get(previous);
1187    focus_style_target = elm_widget_focus_highlight_style_get(target);
1188
1189    if (sd->focus_highlight.theme_changed ||
1190        (focus_style_target != focus_style_previous))
1191      {
1192         const char *str;
1193
1194         if (focus_style_target)
1195           str = focus_style_target;
1196         else if (sd->focus_highlight.style)
1197           str = sd->focus_highlight.style;
1198         else
1199           str = "default";
1200
1201         elm_widget_theme_object_set
1202           (sd->obj, fobj, "focus_highlight", "top", str);
1203         sd->focus_highlight.theme_changed = EINA_FALSE;
1204
1205         if ((sd->focus_highlight.animate) || (sd->focus_highlight.auto_animate))
1206           {
1207              str = edje_object_data_get(sd->focus_highlight.fobj, "animate");
1208              sd->focus_highlight.animate_supported = ((str) && (!strcmp(str, "on")));
1209           }
1210         else
1211           sd->focus_highlight.animate_supported = EINA_FALSE;
1212      }
1213
1214    if ((sd->focus_highlight.animate_supported) && (previous) &&
1215        (!sd->focus_highlight.prev.in_theme))
1216      _elm_win_focus_highlight_anim_setup(sd, fobj);
1217    else
1218      _elm_win_focus_highlight_simple_setup(sd, fobj);
1219    evas_object_raise(fobj);
1220
1221 the_end:
1222    _elm_win_focus_highlight_visible_set(sd, common_visible);
1223    sd->focus_highlight.geometry_changed = EINA_FALSE;
1224    sd->focus_highlight.prev = sd->focus_highlight.cur;
1225    evas_object_event_callback_add
1226      (sd->focus_highlight.prev.target,
1227       EVAS_CALLBACK_DEL, _elm_win_focus_prev_target_del, data);
1228 }
1229
1230 static void
1231 _elm_win_focus_highlight_reconfigure_job_start(Elm_Win_Data *sd)
1232 {
1233    ecore_job_del(sd->focus_highlight.reconf_job);
1234
1235    sd->focus_highlight.reconf_job = ecore_job_add(
1236        _elm_win_focus_highlight_reconfigure_job, sd->obj);
1237 }
1238
1239 static void
1240 _elm_win_focus_in(Ecore_Evas *ee)
1241 {
1242    Elm_Win_Data *sd = _elm_win_associate_get(ee);
1243    Evas_Object *obj;
1244
1245    if ((!sd) || (sd->modal_count)) return;
1246
1247    _elm_win_throttle_ok = EINA_TRUE;
1248    obj = sd->obj;
1249
1250    _elm_widget_top_win_focused_set(obj, EINA_TRUE);
1251    if (sd->type != ELM_WIN_FAKE)
1252      {
1253         if (!elm_widget_focus_order_get(obj))
1254           {
1255              elm_widget_focus_steal(obj, NULL);
1256           }
1257         else
1258           {
1259              Evas_Object *newest = NULL;
1260              unsigned int newest_focus_order = 0;
1261
1262              newest = elm_widget_newest_focus_order_get
1263                (obj, &newest_focus_order, EINA_TRUE);
1264              // TIZEN_ONLY(20161118): onscreen_is should not be checked
1265              //                       to keep compatibility with Tizen 2.4
1266              /*
1267              if ((newest) &&
1268                  (_elm_widget_onscreen_is(newest) || (newest == obj)))
1269                elm_widget_focus_restore(obj);
1270              */
1271              if (newest) elm_widget_focus_restore(obj);
1272              /////////////////////////////////////////////////////////
1273              else
1274                evas_object_focus_set(obj, EINA_TRUE);
1275           }
1276      }
1277    // FIXME: the event is deprecated but still in use.
1278    // Has to be removed in EFL2.0
1279    evas_object_smart_callback_call(obj, SIG_FOCUS_IN, NULL);
1280    sd->focus_highlight.cur.visible = EINA_TRUE;
1281    _elm_win_focus_highlight_reconfigure_job_start(sd);
1282    if (sd->frame_obj)
1283      {
1284         edje_object_signal_emit(sd->frame_obj, "elm,action,focus", "elm");
1285      }
1286
1287    if (_elm_atspi_enabled())
1288      {
1289         elm_interface_atspi_window_activated_signal_emit(obj);
1290         elm_interface_atspi_accessible_state_changed_signal_emit(obj, ELM_ATSPI_STATE_ACTIVE, EINA_TRUE);
1291      }
1292
1293    /* do nothing */
1294    /* else if (sd->img_obj) */
1295    /*   { */
1296    /*   } */
1297 }
1298
1299 static void
1300 _elm_win_focus_out(Ecore_Evas *ee)
1301 {
1302    Elm_Win_Data *sd = _elm_win_associate_get(ee);
1303    Evas_Object *obj;
1304
1305    if (!sd) return;
1306
1307    obj = sd->obj;
1308
1309    _elm_widget_top_win_focused_set(obj, EINA_FALSE);
1310    // FIXME: the event is deprecated but still in use.
1311    // Has to be removed in EFL2.0
1312    evas_object_smart_callback_call(obj, SIG_FOCUS_OUT, NULL);
1313    sd->focus_highlight.cur.visible = EINA_FALSE;
1314    _elm_win_focus_highlight_reconfigure_job_start(sd);
1315    if (sd->frame_obj)
1316      {
1317         edje_object_signal_emit(sd->frame_obj, "elm,action,unfocus", "elm");
1318      }
1319
1320    /* access */
1321    _elm_access_object_highlight_disable(evas_object_evas_get(obj));
1322
1323    if (_elm_atspi_enabled())
1324      {
1325         elm_interface_atspi_window_deactivated_signal_emit(obj);
1326         elm_interface_atspi_accessible_state_changed_signal_emit(obj, ELM_ATSPI_STATE_ACTIVE, EINA_FALSE);
1327      }
1328
1329    /* do nothing */
1330    /* if (sd->img_obj) */
1331    /*   { */
1332    /*   } */
1333 }
1334
1335 static void
1336 _elm_win_available_profiles_del(Elm_Win_Data *sd)
1337 {
1338    if (!sd->profile.available_list) return;
1339
1340    unsigned int i;
1341    for (i = 0; i < sd->profile.count; i++)
1342      ELM_SAFE_FREE(sd->profile.available_list[i], eina_stringshare_del);
1343    sd->profile.count = 0;
1344    ELM_SAFE_FREE(sd->profile.available_list, free);
1345 }
1346
1347 static void
1348 _elm_win_profile_del(Elm_Win_Data *sd)
1349 {
1350    ELM_SAFE_FREE(sd->profile.name, eina_stringshare_del);
1351 }
1352
1353 static Eina_Bool
1354 _internal_elm_win_profile_set(Elm_Win_Data *sd, const char *profile)
1355 {
1356    Eina_Bool changed = EINA_FALSE;
1357    if (profile)
1358      {
1359         if (sd->profile.name)
1360           {
1361              if (strcmp(sd->profile.name, profile) != 0)
1362                {
1363                   eina_stringshare_replace(&(sd->profile.name), profile);
1364                   changed = EINA_TRUE;
1365                }
1366           }
1367         else
1368           {
1369              sd->profile.name = eina_stringshare_add(profile);
1370              changed = EINA_TRUE;
1371           }
1372      }
1373    else
1374      _elm_win_profile_del(sd);
1375
1376    return changed;
1377 }
1378
1379 static void
1380 _elm_win_profile_update(Elm_Win_Data *sd)
1381 {
1382    if (getenv("ELM_PROFILE")) return;
1383
1384    if (sd->profile.available_list)
1385      {
1386         Eina_Bool found = EINA_FALSE;
1387         if (sd->profile.name)
1388           {
1389              unsigned int i;
1390              for (i = 0; i < sd->profile.count; i++)
1391                {
1392                   if (!strcmp(sd->profile.name,
1393                               sd->profile.available_list[i]))
1394                     {
1395                        found = EINA_TRUE;
1396                        break;
1397                     }
1398                }
1399           }
1400
1401         /* If current profile is not present in an available profiles,
1402          * change current profile to the 1st element of an array.
1403          */
1404         if (!found)
1405           _internal_elm_win_profile_set(sd, sd->profile.available_list[0]);
1406      }
1407
1408    _config_profile_lock = EINA_TRUE;
1409    _elm_config_profile_set(sd->profile.name);
1410
1411    /* update sub ee */
1412    Ecore_Evas *ee2;
1413    Eina_List *sub, *l = NULL;
1414
1415    sub = ecore_evas_sub_ecore_evas_list_get(sd->ee);
1416    EINA_LIST_FOREACH(sub, l, ee2)
1417      ecore_evas_window_profile_set(ee2, sd->profile.name);
1418
1419    eo_do(sd->obj, eo_event_callback_call(ELM_WIN_EVENT_PROFILE_CHANGED, NULL));
1420 }
1421
1422 #ifdef HAVE_ELEMENTARY_WAYLAND
1423 static void
1424 _elm_win_opaque_update(Elm_Win_Data *sd)
1425 {
1426    int ox = 0, oy = 0, ow = 0, oh = 0;
1427
1428    if (sd->fullscreen)
1429      {
1430         ecore_evas_geometry_get(sd->ee, NULL, NULL, &ow, &oh);
1431         ecore_wl_window_opaque_region_set(sd->wl.win, 0, 0, ow, oh);
1432         ecore_wl_window_update_location(sd->wl.win, 0, 0);
1433         return;
1434      }
1435
1436    if (sd->frame_obj)
1437      edje_object_part_geometry_get(sd->frame_obj, "elm.spacer.opaque",
1438                                    &ox, &oy, &ow, &oh);
1439    ecore_wl_window_opaque_region_set(sd->wl.win, ox, oy, ow, oh);
1440    ecore_wl_window_update_location(sd->wl.win, sd->screen.x + ox, sd->screen.y + oy);
1441 }
1442 #endif
1443
1444 static void
1445 _elm_win_frame_obj_update(Elm_Win_Data *sd)
1446 {
1447    int fx = 0, fy = 0, fw = 0, fh = 0;
1448    int ox = 0, oy = 0, ow = 0, oh = 0;
1449
1450 #ifdef HAVE_ELEMENTARY_WAYLAND
1451    sd->wl.opaque_dirty = 1;
1452 #endif
1453    if (sd->fullscreen || !sd->frame_obj)
1454      {
1455         evas_output_framespace_set(sd->evas, 0, 0, 0, 0);
1456         return;
1457      }
1458
1459    evas_object_geometry_get(sd->frame_obj, &fx, &fy, &fw, &fh);
1460    evas_object_geometry_get(sd->client_obj, &ox, &oy, &ow, &oh);
1461
1462    evas_output_framespace_set(sd->evas, (ox - fx), (oy - fy), (fw - ow), (fh - oh));
1463 }
1464
1465 static void
1466 _elm_win_state_change(Ecore_Evas *ee)
1467 {
1468    Elm_Win_Data *sd = _elm_win_associate_get(ee);
1469    Evas_Object *obj;
1470    int w, h;
1471    Eina_Bool ch_withdrawn = EINA_FALSE;
1472    Eina_Bool ch_sticky = EINA_FALSE;
1473    Eina_Bool ch_iconified = EINA_FALSE;
1474    Eina_Bool ch_fullscreen = EINA_FALSE;
1475    Eina_Bool ch_maximized = EINA_FALSE;
1476    Eina_Bool ch_profile = EINA_FALSE;
1477    Eina_Bool ch_wm_rotation = EINA_FALSE;
1478 #ifdef HAVE_ELEMENTARY_WAYLAND
1479    Eina_Bool ch_conformant  = EINA_FALSE;
1480 #endif
1481    Eina_Bool ch_visibility = EINA_FALSE;
1482    Eina_Bool ch_aux_hint = EINA_FALSE;
1483    Eina_List *aux_hints = NULL;
1484    const char *profile;
1485 #ifdef HAVE_ELEMENTARY_WAYLAND
1486    Conformant_Property property = CONFORMANT_DEFAULT; //TIZEN_ONLY(20160330): add processing properties of window
1487 #endif
1488
1489    if (!sd) return;
1490
1491    obj = sd->obj;
1492
1493    if (sd->withdrawn != ecore_evas_withdrawn_get(sd->ee))
1494      {
1495         sd->withdrawn = ecore_evas_withdrawn_get(sd->ee);
1496         ch_withdrawn = EINA_TRUE;
1497      }
1498    if (sd->sticky != ecore_evas_sticky_get(sd->ee))
1499      {
1500         sd->sticky = ecore_evas_sticky_get(sd->ee);
1501         ch_sticky = EINA_TRUE;
1502      }
1503    if (sd->iconified != ecore_evas_iconified_get(sd->ee))
1504      {
1505         sd->iconified = ecore_evas_iconified_get(sd->ee);
1506         ch_iconified = EINA_TRUE;
1507      }
1508    if (sd->fullscreen != ecore_evas_fullscreen_get(sd->ee))
1509      {
1510         sd->fullscreen = ecore_evas_fullscreen_get(sd->ee);
1511         ch_fullscreen = EINA_TRUE;
1512      }
1513    if (sd->maximized != ecore_evas_maximized_get(sd->ee))
1514      {
1515         sd->maximized = ecore_evas_maximized_get(sd->ee);
1516         ch_maximized = EINA_TRUE;
1517      }
1518
1519    if (ecore_evas_window_profile_supported_get(sd->ee))
1520      {
1521         profile = ecore_evas_window_profile_get(sd->ee);
1522         ch_profile = _internal_elm_win_profile_set(sd, profile);
1523      }
1524
1525    if (sd->wm_rot.use)
1526      {
1527         if (sd->rot != ecore_evas_rotation_get(sd->ee))
1528           {
1529              sd->rot = ecore_evas_rotation_get(sd->ee);
1530              ch_wm_rotation = EINA_TRUE;
1531           }
1532      }
1533
1534    if (sd->obscured != ecore_evas_obscured_get(sd->ee))
1535      {
1536         sd->obscured = ecore_evas_obscured_get(sd->ee);
1537         ch_visibility = EINA_TRUE;
1538      }
1539
1540    aux_hints = ecore_evas_aux_hints_allowed_get(sd->ee);
1541    if (aux_hints)
1542      {
1543         ch_aux_hint = EINA_TRUE;
1544      }
1545
1546 #ifdef HAVE_ELEMENTARY_WAYLAND
1547    int x = 0, y = 0;
1548    if (sd->indmode != (Elm_Win_Indicator_Mode)ecore_wl_window_indicator_state_get(sd->wl.win))
1549      {
1550         sd->indmode = (Elm_Win_Indicator_Mode)ecore_wl_window_indicator_state_get(sd->wl.win);
1551         ch_conformant = EINA_TRUE;
1552         property |= CONFORMANT_INDICATOR_STATE; //TIZEN_ONLY(20160330): add processing properties of window
1553
1554      }
1555    if (sd->kbdmode != (Elm_Win_Keyboard_Mode)ecore_wl_window_keyboard_state_get(sd->wl.win))
1556      {
1557         sd->kbdmode = (Elm_Win_Keyboard_Mode)ecore_wl_window_keyboard_state_get(sd->wl.win);
1558         ch_conformant = EINA_TRUE;
1559         property |= CONFORMANT_KEYBOARD_STATE; //TIZEN_ONLY(20160330): add processing properties of window
1560
1561      }
1562    if (ecore_wl_window_indicator_geometry_get(sd->wl.win, &x, &y, &w, &h))
1563      {
1564         if ((sd->ind.x != x) || (sd->ind.y != y) || (sd->ind.w != w) || (sd->ind.h != h))
1565           {
1566              sd->ind.x = x;
1567              sd->ind.y = y;
1568              sd->ind.w = w;
1569              sd->ind.h = h;
1570              ch_conformant  = EINA_TRUE;
1571              property |= CONFORMANT_INDICATOR_GEOMETRY; //TIZEN_ONLY(20160330): add processing properties of window
1572
1573           }
1574      }
1575    if (ecore_wl_window_keyboard_geometry_get(sd->wl.win, &x, &y, &w, &h))
1576      {
1577         if ((sd->kbd.x != x) || (sd->kbd.y != y) || (sd->kbd.w != w) || (sd->kbd.h != h))
1578           {
1579              sd->kbd.x = x;
1580              sd->kbd.y = y;
1581              sd->kbd.w = w;
1582              sd->kbd.h = h;
1583              ch_conformant  = EINA_TRUE;
1584              property |= CONFORMANT_KEYBOARD_GEOMETRY; //TIZEN_ONLY(20160330): add processing properties of window
1585
1586           }
1587      }
1588 #endif
1589
1590    _elm_win_state_eval_queue();
1591
1592    if ((ch_withdrawn) || (ch_iconified))
1593      {
1594         if (sd->withdrawn)
1595           eo_do(obj, eo_event_callback_call(ELM_WIN_EVENT_WITHDRAWN, NULL));
1596         else if (sd->iconified)
1597           {
1598              eo_do(obj, eo_event_callback_call(ELM_WIN_EVENT_ICONIFIED, NULL));
1599              if (_elm_atspi_enabled())
1600                elm_interface_atspi_window_minimized_signal_emit(obj);
1601           }
1602         else
1603           {
1604              eo_do(obj, eo_event_callback_call(ELM_WIN_EVENT_NORMAL, NULL));
1605              if (_elm_atspi_enabled())
1606                elm_interface_atspi_window_restored_signal_emit(obj);
1607           }
1608      }
1609    if (ch_sticky)
1610      {
1611         if (sd->sticky)
1612           eo_do(obj, eo_event_callback_call(ELM_WIN_EVENT_STICK, NULL));
1613         else
1614           eo_do(obj, eo_event_callback_call(ELM_WIN_EVENT_UNSTICK, NULL));
1615      }
1616    if (ch_fullscreen)
1617      {
1618         _elm_win_frame_obj_update(sd);
1619         if (sd->fullscreen)
1620           {
1621              eo_do(obj, eo_event_callback_call
1622                (ELM_WIN_EVENT_FULLSCREEN, NULL));
1623              if (sd->frame_obj)
1624                evas_object_hide(sd->frame_obj);
1625              ecore_evas_geometry_get(sd->ee, NULL, NULL, &w, &h);
1626              ecore_evas_resize(sd->ee, w, h);
1627           }
1628         else
1629           {
1630              eo_do(obj, eo_event_callback_call
1631                (ELM_WIN_EVENT_UNFULLSCREEN, NULL));
1632              if (sd->frame_obj)
1633                evas_object_show(sd->frame_obj);
1634           }
1635      }
1636    if (ch_maximized)
1637      {
1638         if (sd->maximized)
1639           {
1640              eo_do(obj, eo_event_callback_call(ELM_WIN_EVENT_MAXIMIZED, NULL));
1641              if (_elm_atspi_enabled())
1642                elm_interface_atspi_window_maximized_signal_emit(obj);
1643           }
1644         else
1645           {
1646              eo_do(obj, eo_event_callback_call(ELM_WIN_EVENT_UNMAXIMIZED, NULL));
1647              if (_elm_atspi_enabled())
1648                elm_interface_atspi_window_restored_signal_emit(obj);
1649           }
1650      }
1651    if (ch_profile)
1652      {
1653         _elm_win_profile_update(sd);
1654      }
1655    if (ch_wm_rotation)
1656      {
1657         evas_object_size_hint_min_set(obj, -1, -1);
1658         evas_object_size_hint_max_set(obj, -1, -1);
1659 #ifdef HAVE_ELEMENTARY_X
1660         _elm_win_xwin_update(sd);
1661 #endif
1662         elm_widget_orientation_set(obj, sd->rot);
1663
1664         /* if there are deferred resize job, do the job immediately
1665            before calling rotation change callback */
1666         if (sd->deferred_resize_job)
1667           {
1668              ecore_job_del(sd->deferred_resize_job);
1669              sd->deferred_resize_job = NULL;
1670              _elm_win_resize_job(obj);
1671           }
1672
1673         eo_do(obj, eo_event_callback_call
1674           (ELM_WIN_EVENT_ROTATION_CHANGED, NULL));
1675         eo_do(obj, eo_event_callback_call
1676           (ELM_WIN_EVENT_WM_ROTATION_CHANGED, NULL));
1677         //TIZEN_ONLY(20160915): send information to screen reader on window rotation
1678         if (_elm_atspi_enabled())
1679           {
1680              Evas_Coord width = 0, height = 0;
1681              elm_win_screen_size_get(obj, NULL, NULL, &width, &height);
1682              if ((sd->rot == 0) || (sd->rot == 180))
1683                {
1684                   elm_interface_atspi_accessible_bounds_changed_signal_emit(obj, 0, 0, width, height);
1685                }
1686              else
1687                {
1688                   elm_interface_atspi_accessible_bounds_changed_signal_emit(obj, 0, 0, height, width);
1689                }
1690           }
1691           //
1692      }
1693 #ifdef HAVE_ELEMENTARY_WAYLAND
1694    if (ch_conformant)
1695      {
1696         evas_object_smart_callback_call(obj, SIG_CONFORMANT_CHANGED, (void *)property); //TIZEN_ONLY(20160330): add processing properties of window
1697
1698      }
1699 #endif
1700    if (ch_aux_hint)
1701      {
1702         void *id;
1703         Eina_List *l;
1704         EINA_LIST_FOREACH(aux_hints, l, id)
1705           {
1706              evas_object_smart_callback_call(obj, SIG_AUX_HINT_ALLOWED, id);
1707           }
1708         eina_list_free(aux_hints);
1709      }
1710    if (ch_visibility)
1711      {
1712         evas_object_smart_callback_call(obj, SIG_VISIBILITY_CHANGED, (void*)!sd->obscured);
1713         //TIZEN_ONLY(20160701): add atspi window state visible change signal
1714         if (_elm_atspi_enabled())
1715           elm_interface_atspi_accessible_state_changed_signal_emit(obj, ELM_ATSPI_STATE_VISIBLE, !sd->obscured);
1716         //
1717      }
1718 }
1719
1720 EOLIAN static Eina_Bool
1721 _elm_win_elm_widget_focus_next_manager_is(Eo *obj EINA_UNUSED, Elm_Win_Data *_pd EINA_UNUSED)
1722 {
1723    return EINA_TRUE;
1724 }
1725
1726 EOLIAN static Eina_Bool
1727 _elm_win_elm_widget_focus_next(Eo *obj, Elm_Win_Data *_pd EINA_UNUSED, Elm_Focus_Direction dir, Evas_Object **next, Elm_Object_Item **next_item)
1728 {
1729    ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EINA_FALSE);
1730
1731    const Eina_List *items;
1732    void *(*list_data_get)(const Eina_List *list);
1733
1734    /* Focus chain */
1735    if (wd->subobjs)
1736      {
1737         if (!(items = elm_widget_focus_custom_chain_get(obj)))
1738           {
1739              items = wd->subobjs;
1740              if (!items)
1741                return EINA_FALSE;
1742           }
1743         list_data_get = eina_list_data_get;
1744
1745         elm_widget_focus_list_next_get(obj, items, list_data_get, dir, next, next_item);
1746
1747         if (*next) return EINA_TRUE;
1748      }
1749    *next = (Evas_Object *)obj;
1750    return EINA_FALSE;
1751 }
1752
1753 EOLIAN static Eina_Bool
1754 _elm_win_elm_widget_focus_direction_manager_is(Eo *obj EINA_UNUSED, Elm_Win_Data *_pd EINA_UNUSED)
1755 {
1756    return EINA_TRUE;
1757 }
1758
1759 EOLIAN static Eina_Bool
1760 _elm_win_elm_widget_focus_direction(Eo *obj, Elm_Win_Data *_pd EINA_UNUSED, const Evas_Object *base, double degree, Evas_Object **direction, Elm_Object_Item **direction_item, double *weight)
1761 {
1762    const Eina_List *items;
1763    void *(*list_data_get)(const Eina_List *list);
1764
1765    ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EINA_FALSE);
1766
1767    /* Focus chain */
1768    if (wd->subobjs)
1769      {
1770         if (!(items = elm_widget_focus_custom_chain_get(obj)))
1771           items = wd->subobjs;
1772
1773         list_data_get = eina_list_data_get;
1774
1775         return elm_widget_focus_list_direction_get
1776                  (obj, base, items, list_data_get, degree, direction, direction_item, weight);
1777      }
1778
1779    return EINA_FALSE;
1780 }
1781
1782 EOLIAN static Eina_Bool
1783 _elm_win_elm_widget_on_focus(Eo *obj, Elm_Win_Data *sd, Elm_Object_Item *item EINA_UNUSED)
1784 {
1785    Eina_Bool int_ret = EINA_FALSE;
1786    eo_do_super(obj, MY_CLASS, int_ret = elm_obj_widget_on_focus(NULL));
1787    if (!int_ret) return EINA_TRUE;
1788
1789    if (sd->img_obj)
1790      evas_object_focus_set(sd->img_obj, elm_widget_focus_get(obj));
1791    else
1792      evas_object_focus_set(obj, elm_widget_focus_get(obj));
1793
1794    return EINA_TRUE;
1795 }
1796
1797 static Eina_Bool
1798 _key_action_return(Evas_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
1799 {
1800    return EINA_FALSE;
1801 }
1802
1803 static Eina_Bool
1804 _key_action_move(Evas_Object *obj, const char *params)
1805 {
1806    const char *dir = params;
1807
1808    _elm_widget_focus_auto_show(obj);
1809    if (!strcmp(dir, "previous"))
1810      elm_widget_focus_cycle(obj, ELM_FOCUS_PREVIOUS);
1811    else if (!strcmp(dir, "next"))
1812      elm_widget_focus_cycle(obj, ELM_FOCUS_NEXT);
1813    else if (!strcmp(dir, "left"))
1814      elm_widget_focus_cycle(obj, ELM_FOCUS_LEFT);
1815    else if (!strcmp(dir, "right"))
1816      elm_widget_focus_cycle(obj, ELM_FOCUS_RIGHT);
1817    else if (!strcmp(dir, "up"))
1818      elm_widget_focus_cycle(obj, ELM_FOCUS_UP);
1819    else if (!strcmp(dir, "down"))
1820      elm_widget_focus_cycle(obj, ELM_FOCUS_DOWN);
1821    else return EINA_FALSE;
1822
1823    return EINA_TRUE;
1824 }
1825
1826 EOLIAN static Eina_Bool
1827 _elm_win_elm_widget_event(Eo *obj, Elm_Win_Data *_pd EINA_UNUSED, Evas_Object *src EINA_UNUSED, Evas_Callback_Type type, void *event_info)
1828 {
1829    Evas_Event_Key_Down *ev = event_info;
1830
1831    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
1832    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
1833
1834    if (!_elm_config_key_binding_call(obj, ev, key_actions))
1835      return EINA_FALSE;
1836
1837    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1838    return EINA_TRUE;
1839 }
1840
1841 static void
1842 _deferred_ecore_evas_free(void *data)
1843 {
1844    ecore_evas_free(data);
1845    _elm_win_deferred_free--;
1846 }
1847
1848 //TIZEN_ONLY(20170613) -listen if atspi is enabled
1849 static void
1850 _atspi_socket_proxy_listen(Eo * obj)
1851 {
1852    ELM_WIN_DATA_GET(obj, sd);
1853
1854    const char *plug_id;
1855    plug_id = evas_object_data_get(obj, "___PLUGID");
1856    if ((plug_id) != NULL)
1857      {
1858         char *svcname, *svcnum;
1859         if (!sd->socket_proxy && _elm_atspi_bridge_plug_id_split(plug_id, &svcname, &svcnum))
1860           {
1861              sd->socket_proxy = _elm_atspi_bridge_utils_proxy_create(obj, svcname, atoi(svcnum), ELM_ATSPI_PROXY_TYPE_SOCKET);
1862              elm_atspi_bridge_utils_proxy_listen(sd->socket_proxy);
1863              free(svcname);
1864              free(svcnum);
1865           }
1866      }
1867 }
1868 //
1869
1870 EOLIAN static void
1871 _elm_win_evas_object_smart_show(Eo *obj, Elm_Win_Data *sd)
1872 {
1873    if (sd->modal_count) return;
1874    const Eina_List *l;
1875    Evas_Object *current;
1876    Eina_Bool do_eval = EINA_FALSE;
1877
1878    if (!evas_object_visible_get(obj)) do_eval = EINA_TRUE;
1879    eo_do_super(obj, MY_CLASS, evas_obj_smart_show());
1880
1881    if ((sd->modal) && (!evas_object_visible_get(obj)))
1882      {
1883         INCREMENT_MODALITY()
1884      }
1885
1886    evas_smart_objects_calculate(evas_object_evas_get(obj));
1887
1888    TRAP(sd, show);
1889
1890    if (_elm_atspi_enabled())
1891      {
1892         Eo *bridge = _elm_atspi_bridge_get();
1893         elm_interface_atspi_window_created_signal_emit(obj);
1894         if (bridge)
1895            elm_interface_atspi_accessible_children_changed_added_signal_emit(elm_atspi_bridge_root_get(bridge), obj);
1896      }
1897
1898    // TIZEN_ONLY(20160705) - enable atspi_proxy to work
1899    if (_elm_atspi_enabled())
1900      {
1901         //TIZEN_ONLY(20170613) -listen if atspi is enabled
1902         _atspi_socket_proxy_listen(obj);
1903         //
1904      }
1905    //
1906
1907    if (do_eval)
1908      {
1909         if (_elm_win_state_eval_job)
1910           {
1911              ecore_job_del(_elm_win_state_eval_job);
1912              _elm_win_state_eval_job = NULL;
1913           }
1914         _elm_win_state_eval(NULL);
1915      }
1916    if (sd->shot.info) _shot_handle(sd);
1917 }
1918
1919 EOLIAN static void
1920 _elm_win_evas_object_smart_hide(Eo *obj, Elm_Win_Data *sd)
1921 {
1922    if (sd->modal_count) return;
1923    const Eina_List *l;
1924    Evas_Object *current;
1925
1926    if (evas_object_visible_get(obj))
1927      _elm_win_state_eval_queue();
1928    eo_do_super(obj, MY_CLASS, evas_obj_smart_hide());
1929
1930    if ((sd->modal) && (evas_object_visible_get(obj)))
1931      {
1932         DECREMENT_MODALITY()
1933      }
1934
1935    TRAP(sd, hide);
1936
1937    if (sd->frame_obj)
1938      {
1939         evas_object_hide(sd->frame_obj);
1940      }
1941    if (sd->img_obj)
1942      {
1943         evas_object_hide(sd->img_obj);
1944      }
1945    if (sd->pointer.obj)
1946      {
1947         evas_object_hide(sd->pointer.obj);
1948 #if 0
1949         ecore_evas_hide(sd->pointer.ee);
1950 #endif
1951      }
1952    if (_elm_atspi_enabled())
1953      {
1954         Eo *bridge = _elm_atspi_bridge_get();
1955         elm_interface_atspi_window_destroyed_signal_emit(obj);
1956         if (bridge)
1957            elm_interface_atspi_accessible_children_changed_del_signal_emit(elm_atspi_bridge_root_get(bridge), obj);
1958      }
1959
1960    if (_elm_win_policy_quit_triggered(obj))
1961      _elm_win_flush_cache_and_exit(obj);
1962 }
1963
1964 static void
1965 _elm_win_accessibility_highlight_obj_del(void *data,
1966                            Evas *e EINA_UNUSED,
1967                            Evas_Object *obj EINA_UNUSED,
1968                            void *event_info EINA_UNUSED)
1969 {
1970    ELM_WIN_DATA_GET(data, sd);
1971
1972    // TIZEN_ONLY(20160805): set _accessibility_currently_highlighted_obj to NULL in object delete callback
1973    /* set _accessibility_currently_highlighted_obj to NULL */
1974    elm_object_accessibility_highlight_set(obj, EINA_FALSE);
1975    //
1976    _elm_win_accessibility_highlight_hide(sd->obj);
1977 }
1978
1979 static void
1980 _elm_win_accessibility_highlight_obj_move(void *data,
1981                            Evas *e EINA_UNUSED,
1982                            Evas_Object *obj EINA_UNUSED,
1983                            void *event_info EINA_UNUSED)
1984 {
1985    ELM_WIN_DATA_GET(data, sd);
1986
1987    _elm_win_accessibility_highlight_show(sd->obj);
1988 }
1989
1990 static void
1991 _elm_win_accessibility_highlight_obj_resize(void *data,
1992                              Evas *e EINA_UNUSED,
1993                              Evas_Object *obj EINA_UNUSED,
1994                              void *event_info EINA_UNUSED)
1995 {
1996    ELM_WIN_DATA_GET(data, sd);
1997    _elm_win_accessibility_highlight_show(sd->obj);
1998
1999 }
2000
2001 static void
2002 _elm_win_on_parent_del(void *data,
2003                        Evas *e EINA_UNUSED,
2004                        Evas_Object *obj,
2005                        void *event_info EINA_UNUSED)
2006 {
2007    ELM_WIN_DATA_GET(data, sd);
2008
2009    if (obj == sd->parent) sd->parent = NULL;
2010 }
2011
2012 static void
2013 _elm_win_focus_target_move(void *data,
2014                            Evas *e EINA_UNUSED,
2015                            Evas_Object *obj EINA_UNUSED,
2016                            void *event_info EINA_UNUSED)
2017 {
2018    ELM_WIN_DATA_GET(data, sd);
2019
2020    sd->focus_highlight.geometry_changed = EINA_TRUE;
2021    _elm_win_focus_highlight_reconfigure_job_start(sd);
2022 }
2023
2024 static void
2025 _elm_win_focus_target_resize(void *data,
2026                              Evas *e EINA_UNUSED,
2027                              Evas_Object *obj EINA_UNUSED,
2028                              void *event_info EINA_UNUSED)
2029 {
2030    ELM_WIN_DATA_GET(data, sd);
2031
2032    sd->focus_highlight.geometry_changed = EINA_TRUE;
2033    _elm_win_focus_highlight_reconfigure_job_start(sd);
2034 }
2035
2036 static void
2037 _elm_win_focus_target_del(void *data,
2038                           Evas *e EINA_UNUSED,
2039                           Evas_Object *obj EINA_UNUSED,
2040                           void *event_info EINA_UNUSED)
2041 {
2042    ELM_WIN_DATA_GET(data, sd);
2043
2044    sd->focus_highlight.cur.target = NULL;
2045
2046    _elm_win_focus_highlight_reconfigure_job_start(sd);
2047 }
2048
2049 static Evas_Object *
2050 _elm_win_focus_target_get(Evas_Object *obj)
2051 {
2052    Evas_Object *o = obj;
2053
2054    do
2055      {
2056         if (elm_widget_is(o))
2057           {
2058              if (!elm_widget_highlight_ignore_get(o))
2059                break;
2060              o = elm_widget_parent_get(o);
2061              if (!o)
2062                o = evas_object_smart_parent_get(o);
2063           }
2064         else
2065           {
2066              o = elm_widget_parent_widget_get(o);
2067              if (!o)
2068                o = evas_object_smart_parent_get(o);
2069           }
2070      }
2071    while (o);
2072
2073    return o;
2074 }
2075
2076 static void
2077 _elm_win_focus_target_callbacks_add(Elm_Win_Data *sd)
2078 {
2079    Evas_Object *obj = sd->focus_highlight.cur.target;
2080    if (!obj) return;
2081
2082    evas_object_event_callback_add
2083      (obj, EVAS_CALLBACK_MOVE, _elm_win_focus_target_move, sd->obj);
2084    evas_object_event_callback_add
2085      (obj, EVAS_CALLBACK_RESIZE, _elm_win_focus_target_resize, sd->obj);
2086 }
2087
2088 static void
2089 _elm_win_focus_target_callbacks_del(Elm_Win_Data *sd)
2090 {
2091    Evas_Object *obj = sd->focus_highlight.cur.target;
2092
2093    evas_object_event_callback_del_full
2094      (obj, EVAS_CALLBACK_MOVE, _elm_win_focus_target_move, sd->obj);
2095    evas_object_event_callback_del_full
2096      (obj, EVAS_CALLBACK_RESIZE, _elm_win_focus_target_resize, sd->obj);
2097 }
2098
2099 static void
2100 _elm_win_accessibility_highlight_callbacks_add(Elm_Win_Data *sd)
2101 {
2102    Evas_Object *obj = sd->accessibility_highlight.cur.target;
2103    if (!obj) return;
2104    evas_object_event_callback_add
2105      (obj, EVAS_CALLBACK_DEL, _elm_win_accessibility_highlight_obj_del, sd->obj);
2106    evas_object_event_callback_add
2107      (obj, EVAS_CALLBACK_MOVE, _elm_win_accessibility_highlight_obj_move, sd->obj);
2108    evas_object_event_callback_add
2109      (obj, EVAS_CALLBACK_RESIZE, _elm_win_accessibility_highlight_obj_resize, sd->obj);
2110 }
2111
2112 static void
2113 _elm_win_accessibility_highlight_callbacks_del(Elm_Win_Data *sd)
2114 {
2115    Evas_Object *obj = sd->accessibility_highlight.cur.target;
2116    if (!obj) return;
2117
2118    evas_object_event_callback_del_full
2119      (obj, EVAS_CALLBACK_DEL, _elm_win_accessibility_highlight_obj_del, sd->obj);
2120    evas_object_event_callback_del_full
2121      (obj, EVAS_CALLBACK_MOVE, _elm_win_accessibility_highlight_obj_move, sd->obj);
2122    evas_object_event_callback_del_full
2123      (obj, EVAS_CALLBACK_RESIZE, _elm_win_accessibility_highlight_obj_resize, sd->obj);
2124 }
2125
2126 static void
2127 _elm_win_object_focus_in(void *data,
2128                          Evas *e EINA_UNUSED,
2129                          void *event_info)
2130 {
2131    Evas_Object *obj = event_info, *target;
2132    ELM_WIN_DATA_GET(data, sd);
2133
2134    if (sd->focus_highlight.cur.target == obj)
2135      return;
2136
2137    target = _elm_win_focus_target_get(obj);
2138    sd->focus_highlight.cur.target = target;
2139    if (target && elm_widget_highlight_in_theme_get(target))
2140      sd->focus_highlight.cur.in_theme = EINA_TRUE;
2141    else
2142      _elm_win_focus_target_callbacks_add(sd);
2143
2144    evas_object_event_callback_add
2145      (target, EVAS_CALLBACK_DEL, _elm_win_focus_target_del, sd->obj);
2146
2147    _elm_win_focus_highlight_reconfigure_job_start(sd);
2148 }
2149
2150 static void
2151 _elm_win_object_focus_out(void *data,
2152                           Evas *e EINA_UNUSED,
2153                           void *event_info EINA_UNUSED)
2154 {
2155    ELM_WIN_DATA_GET(data, sd);
2156
2157    if (!sd->focus_highlight.cur.target)
2158      return;
2159
2160    if (!sd->focus_highlight.cur.in_theme)
2161      _elm_win_focus_target_callbacks_del(sd);
2162
2163    evas_object_event_callback_del_full
2164       (sd->focus_highlight.cur.target,
2165        EVAS_CALLBACK_DEL, _elm_win_focus_target_del, sd->obj);
2166
2167    sd->focus_highlight.cur.target = NULL;
2168    sd->focus_highlight.cur.in_theme = EINA_FALSE;
2169
2170    _elm_win_focus_highlight_reconfigure_job_start(sd);
2171 }
2172
2173 static void
2174 _elm_win_focus_highlight_shutdown(Elm_Win_Data *sd)
2175 {
2176    _elm_win_focus_highlight_reconfigure_job_stop(sd);
2177    if (sd->focus_highlight.cur.target)
2178      {
2179         elm_widget_signal_emit(sd->focus_highlight.cur.target,
2180                                "elm,action,focus_highlight,hide", "elm");
2181         _elm_win_focus_target_callbacks_del(sd);
2182         evas_object_event_callback_del_full
2183            (sd->focus_highlight.cur.target,
2184             EVAS_CALLBACK_DEL, _elm_win_focus_target_del, sd->obj);
2185         sd->focus_highlight.cur.target = NULL;
2186      }
2187    ELM_SAFE_FREE(sd->focus_highlight.fobj, evas_object_del);
2188
2189    evas_event_callback_del_full
2190      (sd->evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
2191      _elm_win_object_focus_in, sd->obj);
2192    evas_event_callback_del_full
2193      (sd->evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_OUT,
2194      _elm_win_object_focus_out, sd->obj);
2195 }
2196
2197 static void
2198 _win_img_hide(void *data,
2199               Evas *e EINA_UNUSED,
2200               Evas_Object *obj EINA_UNUSED,
2201               void *event_info EINA_UNUSED)
2202 {
2203    elm_widget_focus_hide_handle(data);
2204 }
2205
2206 static void
2207 _win_img_mouse_up(void *data,
2208                   Evas *e EINA_UNUSED,
2209                   Evas_Object *obj EINA_UNUSED,
2210                   void *event_info)
2211 {
2212    Evas_Event_Mouse_Up *ev = event_info;
2213    if (!(ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD))
2214      elm_widget_focus_mouse_up_handle(data);
2215 }
2216
2217 static void
2218 _win_img_focus_in(void *data,
2219                   Evas *e EINA_UNUSED,
2220                   Evas_Object *obj EINA_UNUSED,
2221                   void *event_info EINA_UNUSED)
2222 {
2223    elm_widget_focus_steal(data, NULL);
2224 }
2225
2226 static void
2227 _win_img_focus_out(void *data,
2228                    Evas *e EINA_UNUSED,
2229                    Evas_Object *obj EINA_UNUSED,
2230                    void *event_info EINA_UNUSED)
2231 {
2232    elm_widget_focused_object_clear(data);
2233 }
2234
2235 static void
2236 _elm_win_on_img_obj_del(void *data,
2237                         Evas *e EINA_UNUSED,
2238                         Evas_Object *obj EINA_UNUSED,
2239                         void *event_info EINA_UNUSED)
2240 {
2241    ELM_WIN_DATA_GET(data, sd);
2242    _elm_win_img_callbacks_del(sd->obj, sd->img_obj);
2243    sd->img_obj = NULL;
2244 }
2245
2246 static void
2247 _elm_win_img_callbacks_del(Evas_Object *obj, Evas_Object *imgobj)
2248 {
2249    evas_object_event_callback_del_full
2250      (imgobj, EVAS_CALLBACK_DEL, _elm_win_on_img_obj_del, obj);
2251    evas_object_event_callback_del_full
2252      (imgobj, EVAS_CALLBACK_HIDE, _win_img_hide, obj);
2253    evas_object_event_callback_del_full
2254      (imgobj, EVAS_CALLBACK_MOUSE_UP, _win_img_mouse_up, obj);
2255    evas_object_event_callback_del_full
2256      (imgobj, EVAS_CALLBACK_FOCUS_IN, _win_img_focus_in, obj);
2257    evas_object_event_callback_del_full
2258      (imgobj, EVAS_CALLBACK_FOCUS_OUT, _win_img_focus_out, obj);
2259 }
2260
2261 EOLIAN static void
2262 _elm_win_evas_object_smart_del(Eo *obj, Elm_Win_Data *sd)
2263 {
2264    const Eina_List *l;
2265    Evas_Object *current;
2266
2267    if ((sd->modal) && (evas_object_visible_get(obj)))
2268      {
2269        DECREMENT_MODALITY()
2270      }
2271
2272    if ((sd->modal) && (sd->modal_count > 0))
2273      ERR("Deleted modal win was blocked by another modal win which was created after creation of that win.");
2274
2275    evas_object_event_callback_del_full(sd->edje,
2276                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2277                                        _elm_win_on_resize_obj_changed_size_hints,
2278                                        obj);
2279    evas_object_del(sd->box);
2280    evas_object_del(sd->edje);
2281
2282    /* NB: child deletion handled by parent's smart del */
2283
2284    if ((sd->type != ELM_WIN_FAKE) && (trap) && (trap->del))
2285      trap->del(sd->trap_data, obj);
2286
2287    if (sd->parent)
2288      {
2289         evas_object_event_callback_del_full
2290           (sd->parent, EVAS_CALLBACK_DEL, _elm_win_on_parent_del, obj);
2291         sd->parent = NULL;
2292      }
2293
2294    if (sd->autodel_clear) *(sd->autodel_clear) = -1;
2295
2296    if (_elm_atspi_enabled())
2297      elm_interface_atspi_window_destroyed_signal_emit(obj);
2298
2299    _elm_win_list = eina_list_remove(_elm_win_list, obj);
2300    _elm_win_count--;
2301    _elm_win_state_eval_queue();
2302
2303    if (sd->ee)
2304      {
2305         ecore_evas_callback_delete_request_set(sd->ee, NULL);
2306         ecore_evas_callback_resize_set(sd->ee, NULL);
2307      }
2308
2309    ecore_job_del(sd->deferred_resize_job);
2310    ecore_job_del(sd->deferred_child_eval_job);
2311    eina_stringshare_del(sd->shot.info);
2312    ecore_timer_del(sd->shot.timer);
2313
2314 #ifdef HAVE_ELEMENTARY_X
2315    ecore_event_handler_del(sd->x.client_message_handler);
2316    ecore_event_handler_del(sd->x.property_handler);
2317 #endif
2318 #ifdef HAVE_ELEMENTARY_WAYLAND
2319    ecore_event_handler_del(sd->wl.effect_start_handler);
2320    ecore_event_handler_del(sd->wl.effect_end_handler);
2321    ecore_event_handler_del(sd->wl.indicator_flick_handler); // TIZEN_ONLY(20160801): indicator implementation
2322    ecore_event_handler_del(sd->wl.aux_msg_handler);
2323 #endif
2324    ecore_event_handler_del(sd->mouse_up_handler);//TIZEN_ONLY(20161121) tizen don't have canvas mouse up event like opensource now.
2325
2326    if (sd->img_obj)
2327      {
2328         _elm_win_img_callbacks_del(obj, sd->img_obj);
2329         sd->img_obj = NULL;
2330      }
2331    else
2332      {
2333         if (sd->ee && (sd->type != ELM_WIN_FAKE))
2334           {
2335              ecore_job_add(_deferred_ecore_evas_free, sd->ee);
2336              _elm_win_deferred_free++;
2337           }
2338      }
2339
2340    _elm_win_focus_highlight_shutdown(sd);
2341    eina_stringshare_del(sd->focus_highlight.style);
2342
2343    eina_stringshare_del(sd->title);
2344    eina_stringshare_del(sd->icon_name);
2345    eina_stringshare_del(sd->role);
2346    eina_stringshare_del(sd->frame_style);
2347    eina_stringshare_del(sd->name);
2348    evas_object_del(sd->icon);
2349    evas_object_del(sd->main_menu);
2350
2351    sd->focus_highlight.style = NULL;
2352    sd->title = NULL;
2353    sd->icon_name = NULL;
2354    sd->role = NULL;
2355    sd->name = NULL;
2356    sd->icon = NULL;
2357    sd->main_menu = NULL;
2358
2359    _elm_win_profile_del(sd);
2360    _elm_win_available_profiles_del(sd);
2361
2362    free(sd->wm_rot.rots);
2363    sd->wm_rot.rots = NULL;
2364
2365    /* Don't let callback in the air that point to sd */
2366    ecore_evas_callback_delete_request_set(sd->ee, NULL);
2367    ecore_evas_callback_resize_set(sd->ee, NULL);
2368    ecore_evas_callback_mouse_in_set(sd->ee, NULL);
2369    ecore_evas_callback_focus_in_set(sd->ee, NULL);
2370    ecore_evas_callback_focus_out_set(sd->ee, NULL);
2371    ecore_evas_callback_move_set(sd->ee, NULL);
2372    ecore_evas_callback_state_change_set(sd->ee, NULL);
2373
2374    eo_do_super(obj, MY_CLASS, evas_obj_smart_del());
2375
2376    if (_elm_win_policy_quit_triggered(obj))
2377      {
2378         _elm_win_flush_cache_and_exit(obj);
2379      }
2380 }
2381
2382 static void
2383 _elm_win_obj_intercept_show(void *data,
2384                             Evas_Object *obj)
2385 {
2386    ELM_WIN_DATA_GET(data, sd);
2387
2388    // this is called to make sure all smart containers have calculated their
2389    // sizes BEFORE we show the window to make sure it initially appears at
2390    // our desired size (ie min size is known first)
2391    evas_smart_objects_calculate(evas_object_evas_get(obj));
2392    if (sd->frame_obj)
2393      {
2394         evas_object_show(sd->frame_obj);
2395      }
2396    if (sd->img_obj)
2397      {
2398         evas_object_show(sd->img_obj);
2399      }
2400    if (sd->pointer.obj)
2401      {
2402 #if 0
2403         ecore_evas_show(sd->pointer.ee);
2404 #endif
2405         evas_object_show(sd->pointer.obj);
2406      }
2407    evas_object_show(obj);
2408 #ifdef HAVE_ELEMENTARY_WAYLAND
2409    int x, y, w, h;
2410    Eina_Rectangle input_rect = { -1, -1, 1, 1 };
2411
2412    evas_object_geometry_get(obj, &x, &y, &w, &h);
2413    ecore_wl_window_opaque_region_set(sd->wl.win, x, y, w, h);
2414
2415    /* TIZEN_ONLY: ecore_evas_input_rect_set api is exist only in tizen */
2416    if (sd->type == ELM_WIN_TOOLTIP)
2417      ecore_evas_input_rect_set(sd->ee, &input_rect);
2418 #endif
2419
2420 #ifdef ELEMENTARY_X
2421    if (sd->type == ELM_WIN_TOOLTIP)
2422      ecore_x_window_shape_input_rectangle_set(sd->x.xwin, 0, 0, 0, 0);
2423 #endif
2424 }
2425
2426 EOLIAN static void
2427 _elm_win_evas_object_smart_move(Eo *obj, Elm_Win_Data *sd, Evas_Coord x, Evas_Coord y)
2428 {
2429    if (sd->img_obj)
2430      {
2431         if ((x != sd->screen.x) || (y != sd->screen.y))
2432           {
2433              sd->screen.x = x;
2434              sd->screen.y = y;
2435              eo_do(obj, eo_event_callback_call(ELM_WIN_EVENT_MOVED, NULL));
2436           }
2437         return;
2438      }
2439    else
2440      {
2441         TRAP(sd, move, x, y);
2442         if (!ecore_evas_override_get(sd->ee))  return;
2443      }
2444
2445    eo_do_super(obj, MY_CLASS, evas_obj_smart_move(x, y));
2446
2447    if (ecore_evas_override_get(sd->ee))
2448      {
2449         sd->screen.x = x;
2450         sd->screen.y = y;
2451         eo_do(obj, eo_event_callback_call(ELM_WIN_EVENT_MOVED, NULL));
2452      }
2453    if (sd->frame_obj)
2454      {
2455 #ifdef HAVE_ELEMENTARY_WAYLAND
2456         ecore_wl_window_update_location(sd->wl.win, x, y);
2457 #endif
2458         sd->screen.x = x;
2459         sd->screen.y = y;
2460      }
2461    if (sd->img_obj)
2462      {
2463         sd->screen.x = x;
2464         sd->screen.y = y;
2465      }
2466 }
2467
2468 EOLIAN static void
2469 _elm_win_evas_object_smart_resize(Eo *obj, Elm_Win_Data *sd, Evas_Coord w, Evas_Coord h)
2470 {
2471    eo_do_super(obj, MY_CLASS, evas_obj_smart_resize(w, h));
2472
2473    if (sd->img_obj)
2474      {
2475         if (sd->constrain)
2476           {
2477              int sw, sh;
2478
2479              ecore_evas_screen_geometry_get(sd->ee, NULL, NULL, &sw, &sh);
2480              w = MIN(w, sw);
2481              h = MIN(h, sh);
2482           }
2483         if (w < 1) w = 1;
2484         if (h < 1) h = 1;
2485
2486         evas_object_image_size_set(sd->img_obj, w, h);
2487      }
2488
2489    TRAP(sd, resize, w, h);
2490 }
2491
2492 static void
2493 _elm_win_delete_request(Ecore_Evas *ee)
2494 {
2495    Elm_Win_Data *sd = _elm_win_associate_get(ee);
2496    Evas_Object *obj;
2497
2498    if (!sd) return;
2499
2500    obj = sd->obj;
2501
2502    int autodel = sd->autodel;
2503    sd->autodel_clear = &autodel;
2504    evas_object_ref(obj);
2505    eo_do(obj, eo_event_callback_call(ELM_WIN_EVENT_DELETE_REQUEST, NULL));
2506    if (sd->autohide)
2507      evas_object_hide(obj);
2508    // FIXME: if above callback deletes - then the below will be invalid
2509    if (_elm_atspi_enabled())
2510      elm_interface_atspi_window_destroyed_signal_emit(obj);
2511    if (autodel) evas_object_del(obj);
2512    else sd->autodel_clear = NULL;
2513    evas_object_unref(obj);
2514 }
2515
2516 Ecore_X_Window
2517 _elm_ee_xwin_get(const Ecore_Evas *ee)
2518 {
2519 #ifdef HAVE_ELEMENTARY_X
2520    const char *engine_name;
2521    if (!ee) return 0;
2522
2523    engine_name = ecore_evas_engine_name_get(ee);
2524    if (EINA_UNLIKELY(!engine_name)) return 0;
2525
2526    if (!strcmp(engine_name, ELM_SOFTWARE_X11))
2527      {
2528         return ecore_evas_software_x11_window_get(ee);
2529      }
2530    else if (!strcmp(engine_name, ELM_OPENGL_X11))
2531      {
2532         return ecore_evas_gl_x11_window_get(ee);
2533      }
2534 #else
2535    (void)ee;
2536 #endif
2537    return 0;
2538 }
2539
2540 #ifdef HAVE_ELEMENTARY_X
2541 static void
2542 _internal_elm_win_xwindow_get(Elm_Win_Data *sd)
2543 {
2544    sd->x.xwin = _elm_ee_xwin_get(sd->ee);
2545 }
2546 #endif
2547
2548 Ecore_Wl_Window *
2549 _elm_ee_wlwin_get(const Ecore_Evas *ee)
2550 {
2551 #ifdef HAVE_ELEMENTARY_WAYLAND
2552    const char *engine_name;
2553
2554    if (!ee) return NULL;
2555
2556    engine_name = ecore_evas_engine_name_get(ee);
2557    if (EINA_UNLIKELY(!engine_name)) return NULL;
2558
2559    if ((!strcmp(engine_name, ELM_WAYLAND_SHM)) ||
2560        (!strcmp(engine_name, ELM_WAYLAND_EGL)))
2561      {
2562         return ecore_evas_wayland_window_get(ee);
2563      }
2564 #else
2565    (void)ee;
2566 #endif
2567    return NULL;
2568 }
2569
2570 struct _Elm_Win_Aux_Message
2571 {
2572    const char *key;
2573    const char *val;
2574    Eina_List *options;
2575 };
2576
2577 #ifdef HAVE_ELEMENTARY_WAYLAND
2578 static void
2579 _elm_win_wlwindow_get(Elm_Win_Data *sd)
2580 {
2581    sd->wl.win = _elm_ee_wlwin_get(sd->ee);
2582 }
2583
2584 static Eina_Bool
2585 _elm_win_wl_effect_start(void *data, int type EINA_UNUSED, void *event)
2586 {
2587    ELM_WIN_DATA_GET(data, sd);
2588    Ecore_Wl_Event_Effect_Start *e = event;
2589
2590    if (!sd->wl.win) return ECORE_CALLBACK_PASS_ON;
2591
2592    if ((ecore_wl_window_id_get(sd->wl.win) != e->win))
2593      return ECORE_CALLBACK_PASS_ON;
2594
2595    evas_object_smart_callback_call(data, SIG_EFFECT_STARTED, (void*)e->type);
2596
2597    return ECORE_CALLBACK_PASS_ON;
2598 }
2599
2600 static Eina_Bool
2601 _elm_win_wl_effect_end(void *data, int type EINA_UNUSED, void *event)
2602 {
2603    ELM_WIN_DATA_GET(data, sd);
2604    Ecore_Wl_Event_Effect_End *e = event;
2605    unsigned int eff_type;
2606
2607    if (!sd->wl.win) return ECORE_CALLBACK_PASS_ON;
2608
2609    if ((ecore_wl_window_id_get(sd->wl.win) != e->win))
2610      return ECORE_CALLBACK_PASS_ON;
2611
2612    eff_type = e->type;
2613    if (eff_type == 4)
2614      evas_object_smart_callback_call(data, SIG_LAUNCH_DONE, (void*)e->type);
2615    else
2616      evas_object_smart_callback_call(data, SIG_EFFECT_DONE, (void*)e->type);
2617
2618    return ECORE_CALLBACK_PASS_ON;
2619 }
2620
2621 static Eina_Bool
2622 _elm_win_wl_aux_message(void *data, int type EINA_UNUSED, void *event)
2623 {
2624    ELM_WIN_DATA_GET(data, sd);
2625    Ecore_Wl_Event_Aux_Message *ev = event;
2626    Elm_Win_Aux_Message *msg = NULL;
2627    const char *opt = NULL, *tmp = NULL;
2628    Eina_List *l;
2629
2630    if (!sd->wl.win) return ECORE_CALLBACK_PASS_ON;
2631
2632    if ((ecore_wl_window_id_get(sd->wl.win) != ev->win))
2633      return ECORE_CALLBACK_PASS_ON;
2634
2635    msg = calloc(1, sizeof(*msg));
2636    if (!msg) return ECORE_CALLBACK_PASS_ON;
2637
2638    msg->key = eina_stringshare_add(ev->key);
2639    msg->val = eina_stringshare_add(ev->val);
2640
2641    EINA_LIST_FOREACH(ev->options, l, opt)
2642      {
2643         if (!opt) continue;
2644         tmp = eina_stringshare_add(opt);
2645         msg->options = eina_list_append(msg->options, tmp);
2646      }
2647
2648    evas_object_smart_callback_call(sd->obj, SIG_AUX_MESSAGE_RECEIVED, (void*)msg);
2649
2650    eina_stringshare_del(msg->key);
2651    eina_stringshare_del(msg->val);
2652    EINA_LIST_FREE(msg->options, opt)
2653       eina_stringshare_del(opt);
2654    free(msg);
2655
2656    return ECORE_CALLBACK_PASS_ON;
2657 }
2658 #endif
2659
2660 static Eina_Bool
2661 _elm_win_mouse_up(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
2662 {
2663    ELM_WIN_DATA_GET(data, sd);
2664
2665    if (sd->resizing) sd->resizing = EINA_FALSE;
2666
2667    return ECORE_CALLBACK_PASS_ON;
2668 }
2669
2670 Ecore_Cocoa_Window *
2671 _elm_ee_cocoa_win_get(const Ecore_Evas *ee)
2672 {
2673 #ifdef HAVE_ELEMENTARY_COCOA
2674    const char *engine_name;
2675
2676    if (!ee) return NULL;
2677
2678    engine_name = ecore_evas_engine_name_get(ee);
2679    if (EINA_UNLIKELY(!engine_name)) return NULL;
2680
2681    if (!strcmp(engine_name, "opengl_cocoa") ||
2682        !strcmp(engine_name, "gl_cocoa"))
2683      return ecore_evas_cocoa_window_get(ee);
2684 #else
2685    (void)ee;
2686 #endif
2687    return NULL;
2688 }
2689
2690 Ecore_Win32_Window *
2691 _elm_ee_win32win_get(const Ecore_Evas *ee)
2692 {
2693 #ifdef HAVE_ELEMENTARY_WIN32
2694    const char *engine_name;
2695
2696    if (!ee) return NULL;
2697
2698    engine_name = ecore_evas_engine_name_get(ee);
2699    if (EINA_UNLIKELY(!engine_name)) return NULL;
2700
2701    if ((!strcmp(engine_name, ELM_SOFTWARE_WIN32)) ||
2702        (!strcmp(engine_name, ELM_SOFTWARE_DDRAW)))
2703      {
2704         return ecore_evas_win32_window_get(ee);
2705      }
2706 #else
2707    (void)ee;
2708 #endif
2709    return NULL;
2710 }
2711
2712 #ifdef HAVE_ELEMENTARY_COCOA
2713 static void
2714 _elm_win_cocoawindow_get(Elm_Win_Data *sd)
2715 {
2716    sd->cocoa.win = _elm_ee_cocoa_win_get(sd->ee);
2717 }
2718 #endif
2719
2720 #ifdef HAVE_ELEMENTARY_WIN32
2721 static void
2722 _internal_elm_win_win32window_get(Elm_Win_Data *sd)
2723 {
2724    sd->win32.win = _elm_ee_win32win_get(sd->ee);
2725 }
2726 #endif
2727
2728 #ifdef HAVE_ELEMENTARY_X
2729 static void
2730 _elm_win_xwin_update(Elm_Win_Data *sd)
2731 {
2732    const char *s;
2733
2734    if (sd->type == ELM_WIN_FAKE) return;
2735    _internal_elm_win_xwindow_get(sd);
2736    if (sd->parent)
2737      {
2738         ELM_WIN_DATA_GET(sd->parent, sdp);
2739         if (sdp)
2740           {
2741              if (sd->x.xwin)
2742                ecore_x_icccm_transient_for_set(sd->x.xwin, sdp->x.xwin);
2743           }
2744      }
2745
2746    if (!sd->x.xwin) return;  /* nothing more to do */
2747
2748    s = sd->title;
2749    if (!s) s = _elm_appname;
2750    if (!s) s = "";
2751    if (sd->icon_name) s = sd->icon_name;
2752    ecore_x_icccm_icon_name_set(sd->x.xwin, s);
2753    ecore_x_netwm_icon_name_set(sd->x.xwin, s);
2754
2755    s = sd->role;
2756    if (s) ecore_x_icccm_window_role_set(sd->x.xwin, s);
2757
2758    // set window icon
2759    if (sd->icon)
2760      {
2761         void *data;
2762
2763         data = evas_object_image_data_get(sd->icon, EINA_FALSE);
2764         if (data)
2765           {
2766              Ecore_X_Icon ic;
2767              int w = 0, h = 0, stride, x, y;
2768              unsigned char *p;
2769              unsigned int *p2;
2770
2771              evas_object_image_size_get(sd->icon, &w, &h);
2772              stride = evas_object_image_stride_get(sd->icon);
2773              if ((w > 0) && (h > 0) &&
2774                  (stride >= (int)(w * sizeof(unsigned int))))
2775                {
2776                   ic.width = w;
2777                   ic.height = h;
2778                   ic.data = malloc(w * h * sizeof(unsigned int));
2779
2780                   if (ic.data)
2781                     {
2782                        p = (unsigned char *)data;
2783                        p2 = (unsigned int *)ic.data;
2784                        for (y = 0; y < h; y++)
2785                          {
2786                             for (x = 0; x < w; x++)
2787                               {
2788                                  *p2 = *((unsigned int *)p);
2789                                  p += sizeof(unsigned int);
2790                                  p2++;
2791                               }
2792                             p += (stride - (w * sizeof(unsigned int)));
2793                          }
2794                        ecore_x_netwm_icons_set(sd->x.xwin, &ic, 1);
2795                        free(ic.data);
2796                     }
2797                }
2798              evas_object_image_data_set(sd->icon, data);
2799           }
2800      }
2801
2802    switch (sd->type)
2803      {
2804       case ELM_WIN_BASIC:
2805         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_NORMAL);
2806         break;
2807
2808       case ELM_WIN_DIALOG_BASIC:
2809         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_DIALOG);
2810         break;
2811
2812       case ELM_WIN_DESKTOP:
2813         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_DESKTOP);
2814         break;
2815
2816       case ELM_WIN_DOCK:
2817         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_DOCK);
2818         break;
2819
2820       case ELM_WIN_TOOLBAR:
2821         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_TOOLBAR);
2822         break;
2823
2824       case ELM_WIN_MENU:
2825         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_MENU);
2826         break;
2827
2828       case ELM_WIN_UTILITY:
2829         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_UTILITY);
2830         break;
2831
2832       case ELM_WIN_SPLASH:
2833         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_SPLASH);
2834         break;
2835
2836       case ELM_WIN_DROPDOWN_MENU:
2837         ecore_x_netwm_window_type_set
2838           (sd->x.xwin, ECORE_X_WINDOW_TYPE_DROPDOWN_MENU);
2839         break;
2840
2841       case ELM_WIN_POPUP_MENU:
2842         ecore_x_netwm_window_type_set
2843           (sd->x.xwin, ECORE_X_WINDOW_TYPE_POPUP_MENU);
2844         break;
2845
2846       case ELM_WIN_TOOLTIP:
2847         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_TOOLTIP);
2848         ecore_x_window_shape_input_rectangle_set(sd->x.xwin, 0, 0, 0, 0);
2849         break;
2850
2851       case ELM_WIN_NOTIFICATION:
2852         ecore_x_netwm_window_type_set
2853           (sd->x.xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
2854         break;
2855
2856       case ELM_WIN_COMBO:
2857         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_COMBO);
2858         break;
2859
2860       case ELM_WIN_DND:
2861         ecore_x_netwm_window_type_set(sd->x.xwin, ECORE_X_WINDOW_TYPE_DND);
2862         break;
2863
2864       default:
2865         break;
2866      }
2867    ecore_x_e_virtual_keyboard_state_set
2868      (sd->x.xwin, (Ecore_X_Virtual_Keyboard_State)sd->kbdmode);
2869    if (sd->indmode == ELM_WIN_INDICATOR_SHOW)
2870      ecore_x_e_illume_indicator_state_set
2871        (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_STATE_ON);
2872    else if (sd->indmode == ELM_WIN_INDICATOR_HIDE)
2873      ecore_x_e_illume_indicator_state_set
2874        (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_STATE_OFF);
2875
2876    if ((sd->wm_rot.count) && (sd->wm_rot.rots))
2877      ecore_evas_wm_rotation_available_rotations_set(sd->ee,
2878                                                     sd->wm_rot.rots,
2879                                                     sd->wm_rot.count);
2880    if (sd->wm_rot.preferred_rot != -1)
2881      ecore_evas_wm_rotation_preferred_rotation_set(sd->ee,
2882                                                    sd->wm_rot.preferred_rot);
2883 }
2884
2885 #endif
2886
2887 #ifdef HAVE_ELEMENTARY_WAYLAND
2888 static void
2889 _elm_win_wlwin_update(Elm_Win_Data *sd)
2890 {
2891    switch (sd->type)
2892      {
2893         case ELM_WIN_BASIC:
2894           ecore_evas_wayland_type_set(sd->ee, ECORE_WL_WINDOW_TYPE_TOPLEVEL);
2895           break;
2896         case ELM_WIN_NOTIFICATION:
2897           ecore_evas_wayland_type_set(sd->ee, ECORE_WL_WINDOW_TYPE_NOTIFICATION);
2898           break;
2899         case ELM_WIN_UTILITY:
2900           ecore_evas_wayland_type_set(sd->ee, ECORE_WL_WINDOW_TYPE_UTILITY);
2901           break;
2902         case ELM_WIN_DIALOG_BASIC:
2903           ecore_evas_wayland_type_set(sd->ee, ECORE_WL_WINDOW_TYPE_DIALOG);
2904           break;
2905         case ELM_WIN_DOCK:
2906           ecore_evas_wayland_type_set(sd->ee, ECORE_WL_WINDOW_TYPE_DOCK);
2907           break;
2908         case ELM_WIN_SPLASH:
2909           ecore_evas_wayland_type_set(sd->ee, ECORE_WL_WINDOW_TYPE_SPLASH);
2910           break;
2911         default:
2912           break;
2913      }
2914 }
2915
2916 #endif
2917
2918 /**
2919   * @internal
2920   *
2921   * Resize the window according to window layout's min and weight.
2922   * If the window layout's weight is 0.0, the window max is limited to layout's
2923   * min size.
2924   *
2925   * This is called when the window layout's weight hint is changed or when the
2926   * window is rotated.
2927   *
2928   * @param obj window object
2929   */
2930 static void
2931 _elm_win_resize_objects_eval(Evas_Object *obj)
2932 {
2933    ELM_WIN_DATA_GET(obj, sd);
2934    Evas_Coord w, h, minw, minh, maxw, maxh;
2935    double wx, wy;
2936
2937    evas_object_size_hint_min_get(sd->edje, &minw, &minh);
2938    if (minw < 1) minw = 1;
2939    if (minh < 1) minh = 1;
2940
2941    evas_object_size_hint_weight_get(sd->edje, &wx, &wy);
2942    if (!wx) maxw = minw;
2943    else maxw = 32767;
2944    if (!wy) maxh = minh;
2945    else maxh = 32767;
2946
2947    evas_object_size_hint_min_set(obj, minw, minh);
2948    evas_object_size_hint_max_set(obj, maxw, maxh);
2949
2950    /* if there are deferred resize job, do the job immediately */
2951    if (sd->deferred_resize_job)
2952      {
2953         ecore_job_del(sd->deferred_resize_job);
2954         sd->deferred_resize_job = NULL;
2955         _elm_win_resize_job(obj);
2956      }
2957
2958    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
2959    if (w < minw) w = minw;
2960    if (h < minh) h = minh;
2961    if (w > maxw) w = maxw;
2962    if (h > maxh) h = maxh;
2963    evas_object_resize(obj, w, h);
2964 }
2965
2966 static void
2967 _elm_win_on_resize_obj_changed_size_hints(void *data,
2968                                           Evas *e EINA_UNUSED,
2969                                           Evas_Object *obj EINA_UNUSED,
2970                                           void *event_info EINA_UNUSED)
2971 {
2972    _elm_win_resize_objects_eval(data);
2973 }
2974
2975 void
2976 _elm_win_shutdown(void)
2977 {
2978    while (_elm_win_list)
2979      {
2980         Eina_List *itr = _elm_win_list;
2981         evas_object_del(itr->data);
2982         if (_elm_win_list == itr)
2983           {
2984              _elm_win_list = eina_list_remove_list(_elm_win_list, _elm_win_list);
2985           }
2986      }
2987    ELM_SAFE_FREE(_elm_win_state_eval_job, ecore_job_del);
2988 }
2989
2990 void
2991 _elm_win_rescale(Elm_Theme *th,
2992                  Eina_Bool use_theme)
2993 {
2994    const Eina_List *l;
2995    Evas_Object *obj;
2996
2997    if (!use_theme)
2998      {
2999         EINA_LIST_FOREACH(_elm_win_list, l, obj)
3000           elm_widget_theme(obj);
3001      }
3002    else
3003      {
3004         EINA_LIST_FOREACH(_elm_win_list, l, obj)
3005           elm_widget_theme_specific(obj, th, EINA_FALSE);
3006      }
3007 }
3008
3009 void
3010 _elm_win_access(Eina_Bool is_access)
3011 {
3012    Evas *evas;
3013    const Eina_List *l;
3014    Evas_Object *obj;
3015    Evas_Object *fobj;
3016
3017    EINA_LIST_FOREACH(_elm_win_list, l, obj)
3018      {
3019         elm_widget_access(obj, is_access);
3020
3021          /* floating orphan object. if there are A, B, C objects and user does
3022             as below, then there would be floating orphan objects.
3023
3024               1. elm_object_content_set(layout, A);
3025               2. elm_object_content_set(layout, B);
3026               3. elm_object_content_set(layout, C);
3027
3028             now, the object A and B are floating orphan objects */
3029
3030         fobj = obj;
3031         for (;;)
3032           {
3033              fobj = evas_object_below_get(fobj);
3034              if (!fobj) break;
3035
3036              if (elm_widget_is(fobj) && !elm_widget_parent_get(fobj))
3037                {
3038                   elm_widget_access(fobj, is_access);
3039                }
3040           }
3041
3042         if (!is_access)
3043           {
3044              evas = evas_object_evas_get(obj);
3045             if (evas) _elm_access_object_highlight_disable(evas);
3046           }
3047      }
3048 }
3049
3050 //TIZEN_ONLY(20160822): When atspi mode is dynamically switched on/off,
3051 //register/unregister access objects accordingly.
3052 // TIZEN_ONLY(20170516): connect to at-spi dbus based on org.a11y.Status.IsEnabled property
3053 void
3054 _elm_win_screen_reader(Eina_Bool is_screen_reader)
3055 {
3056    const Eina_List *l;
3057    Evas_Object *obj;
3058    Evas_Object *fobj;
3059
3060    EINA_LIST_FOREACH(_elm_win_list, l, obj)
3061      {
3062         elm_widget_screen_reader(obj, is_screen_reader);
3063         evas_object_smart_callback_call(obj, SIG_ATSPI_SCREEN_READER_CHANGED, &is_screen_reader);
3064
3065          /* floating orphan object. if there are A, B, C objects and user does
3066             as below, then there would be floating orphan objects.
3067
3068               1. elm_object_content_set(layout, A);
3069               2. elm_object_content_set(layout, B);
3070               3. elm_object_content_set(layout, C);
3071
3072             now, the object A and B are floating orphan objects */
3073
3074         fobj = obj;
3075         for (;;)
3076           {
3077              fobj = evas_object_below_get(fobj);
3078              if (!fobj) break;
3079
3080              if (elm_widget_is(fobj) && !elm_widget_parent_get(fobj))
3081                {
3082                   elm_widget_screen_reader(fobj, is_screen_reader);
3083                }
3084           }
3085      }
3086
3087    if (!is_screen_reader)
3088      {
3089         Evas_Object *highlighted_obj;
3090         highlighted_obj = _elm_object_accessibility_currently_highlighted_get();
3091         elm_object_accessibility_highlight_set(highlighted_obj, EINA_FALSE);
3092      }
3093 }
3094
3095 //TIZEN_ONLY(20170621) handle atspi proxy connection at runtime
3096 void
3097 _elm_win_atspi(Eina_Bool is_atspi)
3098 {
3099    const Eina_List *l;
3100    Evas_Object *obj;
3101    Elm_Atspi_State_Set ss;
3102
3103    EINA_LIST_FOREACH(_elm_win_list, l, obj)
3104      {
3105         if (!is_atspi)
3106           {
3107              ELM_WIN_DATA_GET(obj, sd);
3108              if (sd->socket_proxy)
3109                {
3110                   eo_unref(sd->socket_proxy);
3111                   sd->socket_proxy = NULL;
3112                }
3113           }
3114         else
3115           {
3116              _atspi_socket_proxy_listen(obj);
3117              eo_do(obj, ss = elm_interface_atspi_accessible_state_set_get());
3118              if (STATE_TYPE_GET(ss, ELM_ATSPI_STATE_ACTIVE))
3119                {
3120                   elm_interface_atspi_window_activated_signal_emit(obj);
3121                   elm_interface_atspi_accessible_state_changed_signal_emit(obj, ELM_ATSPI_STATE_ACTIVE, EINA_TRUE);
3122                }
3123           }
3124
3125         elm_widget_atspi(obj, is_atspi);
3126      }
3127 }
3128 //
3129 //
3130 //
3131
3132 void
3133 _elm_win_translate(void)
3134 {
3135    const Eina_List *l;
3136    Evas_Object *obj;
3137
3138    /* TIZEN_ONLY(20160622): Apply paragraph direction when language is changed
3139    EINA_LIST_FOREACH(_elm_win_list, l, obj)
3140      elm_widget_translate(obj);
3141     */
3142    EINA_LIST_FOREACH(_elm_win_list, l, obj)
3143      {
3144         if (!strcmp(E_("default:LTR"), "default:RTL"))
3145           evas_object_paragraph_direction_set(obj, EVAS_BIDI_DIRECTION_ANY_RTL);
3146         else
3147           evas_object_paragraph_direction_set(obj, EVAS_BIDI_DIRECTION_LTR);
3148
3149         elm_widget_translate(obj);
3150      }
3151    /* END */
3152
3153    //TIZEN_ONLY(20161202): Temporary code - Apply mirroring in _elm_win_translate()
3154    if (_elm_config && _elm_config->language_auto_mirrored)
3155      {
3156         if (!strcmp(E_("default:LTR"), "default:RTL"))
3157           elm_config_mirrored_set(EINA_TRUE);
3158         else
3159           elm_config_mirrored_set(EINA_FALSE);
3160      }
3161    //
3162 }
3163
3164 void
3165 _elm_win_focus_reconfigure(void)
3166 {
3167    const Eina_List *l;
3168    Evas_Object *obj;
3169
3170    EINA_LIST_FOREACH(_elm_win_list, l, obj)
3171      elm_widget_focus_reconfigure(obj);
3172 }
3173
3174 #ifdef HAVE_ELEMENTARY_X
3175 static Eina_Bool
3176 _elm_win_client_message(void *data,
3177                         int type EINA_UNUSED,
3178                         void *event)
3179 {
3180    ELM_WIN_DATA_GET(data, sd);
3181    Ecore_X_Event_Client_Message *e = event;
3182
3183    if (e->format != 32) return ECORE_CALLBACK_PASS_ON;
3184    if (e->message_type == ECORE_X_ATOM_E_COMP_FLUSH)
3185      {
3186         if ((unsigned int)e->data.l[0] == sd->x.xwin)
3187           {
3188              Evas *evas = evas_object_evas_get(sd->obj);
3189              if (evas)
3190                {
3191                   edje_file_cache_flush();
3192                   edje_collection_cache_flush();
3193                   evas_image_cache_flush(evas);
3194                   evas_font_cache_flush(evas);
3195                }
3196           }
3197      }
3198    else if (e->message_type == ECORE_X_ATOM_E_COMP_DUMP)
3199      {
3200         if ((unsigned int)e->data.l[0] == sd->x.xwin)
3201           {
3202              Evas *evas = evas_object_evas_get(sd->obj);
3203              if (evas)
3204                {
3205                   edje_file_cache_flush();
3206                   edje_collection_cache_flush();
3207                   evas_image_cache_flush(evas);
3208                   evas_font_cache_flush(evas);
3209                   evas_render_dump(evas);
3210                }
3211           }
3212      }
3213    else if (e->message_type == ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL)
3214      {
3215         if ((unsigned int)e->data.l[0] == sd->x.xwin)
3216           {
3217              if ((unsigned int)e->data.l[1] ==
3218                  ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_NEXT)
3219                {
3220                   // XXX: call right access func
3221                }
3222              else if ((unsigned int)e->data.l[1] ==
3223                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_PREV)
3224                {
3225                   // XXX: call right access func
3226                }
3227              else if ((unsigned int)e->data.l[1] ==
3228                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ACTIVATE)
3229                {
3230                   _elm_access_highlight_object_activate
3231                     (sd->obj, ELM_ACTIVATE_DEFAULT);
3232                }
3233              else if ((unsigned int)e->data.l[1] ==
3234                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ)
3235                {
3236                   /* there would be better way to read highlight object */
3237                   Evas *evas;
3238                   evas = evas_object_evas_get(sd->obj);
3239                   if (!evas) return ECORE_CALLBACK_PASS_ON;
3240
3241                   _elm_access_mouse_event_enabled_set(EINA_TRUE);
3242
3243                   evas_event_feed_mouse_in(evas, 0, NULL);
3244                   evas_event_feed_mouse_move
3245                     (evas, e->data.l[2], e->data.l[3], 0, NULL);
3246
3247                   _elm_access_mouse_event_enabled_set(EINA_FALSE);
3248                }
3249              else if ((unsigned int)e->data.l[1] ==
3250                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_NEXT)
3251                {
3252                   _elm_access_highlight_cycle(sd->obj, ELM_FOCUS_NEXT);
3253                }
3254              else if ((unsigned int)e->data.l[1] ==
3255                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_PREV)
3256                {
3257                   _elm_access_highlight_cycle(sd->obj, ELM_FOCUS_PREVIOUS);
3258                }
3259              else if ((unsigned int)e->data.l[1] ==
3260                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_UP)
3261                {
3262                   _elm_access_highlight_object_activate
3263                     (sd->obj, ELM_ACTIVATE_UP);
3264                }
3265              else if ((unsigned int)e->data.l[1] ==
3266                       ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DOWN)
3267                {
3268                   _elm_access_highlight_object_activate
3269                     (sd->obj, ELM_ACTIVATE_DOWN);
3270                }
3271           }
3272      }
3273    return ECORE_CALLBACK_PASS_ON;
3274 }
3275
3276 static Eina_Bool
3277 _elm_win_property_change(void *data,
3278                          int type EINA_UNUSED,
3279                          void *event)
3280 {
3281    ELM_WIN_DATA_GET(data, sd);
3282    Ecore_X_Event_Window_Property *e = event;
3283
3284    if (e->atom == ECORE_X_ATOM_E_ILLUME_INDICATOR_STATE)
3285      {
3286         if (e->win == sd->x.xwin)
3287           {
3288              sd->indmode = (Elm_Win_Indicator_Mode)ecore_x_e_illume_indicator_state_get(e->win);
3289              eo_do(sd->obj, eo_event_callback_call
3290                (ELM_WIN_EVENT_INDICATOR_PROP_CHANGED, NULL));
3291           }
3292      }
3293    return ECORE_CALLBACK_PASS_ON;
3294 }
3295 #endif
3296
3297 static void
3298 _elm_win_focus_highlight_hide(void *data EINA_UNUSED,
3299                               Evas_Object *obj,
3300                               const char *emission EINA_UNUSED,
3301                               const char *source EINA_UNUSED)
3302 {
3303    evas_object_hide(obj);
3304 }
3305
3306 static void
3307 _elm_win_focus_highlight_anim_end(void *data,
3308                                   Evas_Object *obj,
3309                                   const char *emission EINA_UNUSED,
3310                                   const char *source EINA_UNUSED)
3311 {
3312    ELM_WIN_DATA_GET(data, sd);
3313
3314    _elm_win_focus_highlight_simple_setup(sd, obj);
3315 }
3316
3317 static void
3318 _elm_win_focus_skip_set(Elm_Win_Data *sd, Eina_Bool skip)
3319 {
3320    sd->skip_focus = skip;
3321    TRAP(sd, focus_skip_set, skip);
3322 }
3323
3324 static void
3325 _elm_win_focus_highlight_init(Elm_Win_Data *sd)
3326 {
3327    evas_event_callback_add(sd->evas, EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_IN,
3328                            _elm_win_object_focus_in, sd->obj);
3329    evas_event_callback_add(sd->evas,
3330                            EVAS_CALLBACK_CANVAS_OBJECT_FOCUS_OUT,
3331                            _elm_win_object_focus_out, sd->obj);
3332
3333    sd->focus_highlight.cur.target = _elm_win_focus_target_get(evas_focus_get(sd->evas));
3334    if (sd->focus_highlight.cur.target)
3335      {
3336         if (elm_widget_highlight_in_theme_get(sd->focus_highlight.cur.target))
3337           sd->focus_highlight.cur.in_theme = EINA_TRUE;
3338         else
3339           _elm_win_focus_target_callbacks_add(sd);
3340
3341         evas_object_event_callback_add
3342            (sd->focus_highlight.cur.target,
3343             EVAS_CALLBACK_DEL, _elm_win_focus_target_del, sd->obj);
3344      }
3345
3346    sd->focus_highlight.prev.target = NULL;
3347    sd->focus_highlight.fobj = edje_object_add(sd->evas);
3348    sd->focus_highlight.theme_changed = EINA_TRUE;
3349
3350    edje_object_signal_callback_add(sd->focus_highlight.fobj,
3351                                    "elm,action,focus,hide,end", "*",
3352                                    _elm_win_focus_highlight_hide, NULL);
3353    edje_object_signal_callback_add(sd->focus_highlight.fobj,
3354                                    "elm,action,focus,anim,end", "*",
3355                                    _elm_win_focus_highlight_anim_end, sd->obj);
3356    _elm_win_focus_highlight_reconfigure_job_start(sd);
3357 }
3358 static void
3359 _elm_win_accessibility_highlight_init(Elm_Win_Data *sd, Evas_Object *atarget)
3360 {
3361    sd->accessibility_highlight.cur.target = atarget;
3362
3363    Evas_Object *fobj = edje_object_add(sd->evas);
3364    sd->accessibility_highlight.fobj = fobj;
3365    elm_widget_theme_object_set (sd->obj, fobj, "accessibility_highlight", "top", "default");
3366    if (atarget)
3367      {
3368         evas_object_smart_member_add(fobj, atarget);
3369         evas_object_smart_changed(atarget);
3370         _elm_win_accessibility_highlight_callbacks_add(sd);
3371      }
3372 }
3373
3374 static void
3375 _elm_win_frame_cb_move_start(void *data,
3376                              Evas_Object *obj EINA_UNUSED,
3377                              const char *sig EINA_UNUSED,
3378                              const char *source)
3379 {
3380    int ox, oy;
3381
3382    ELM_WIN_DATA_GET(data, sd);
3383
3384    if (!sd) return;
3385
3386 #ifdef HAVE_ELEMENTARY_WAYLAND
3387    if (!strcmp(source, "elm"))
3388      ecore_wl_window_cursor_from_name_set(sd->wl.win, ELM_CURSOR_HAND1);
3389    else
3390      ecore_wl_window_cursor_default_restore(sd->wl.win);
3391 #else
3392    (void)source;
3393 #endif
3394
3395    /* NB: Wayland handles moving surfaces by itself so we cannot
3396     * specify a specific x/y we want. Instead, we will pass in the
3397     * existing x/y values so they can be recorded as 'previous'
3398     * position. The new position will get updated automatically when
3399     * the move is finished */
3400
3401    edje_object_part_geometry_get(sd->frame_obj, "elm.spacer.opaque",
3402                                  &ox, &oy, NULL, NULL);
3403    ecore_evas_wayland_move(sd->ee, ox, oy);
3404 }
3405
3406 static void
3407 _elm_win_frame_cb_move_stop(void *data,
3408                             Evas_Object *obj EINA_UNUSED,
3409                             const char *sig EINA_UNUSED,
3410                             const char *source EINA_UNUSED)
3411 {
3412    ELM_WIN_DATA_GET(data, sd);
3413
3414    if (!sd) return;
3415
3416 #ifdef HAVE_ELEMENTARY_WAYLAND
3417    ecore_wl_window_cursor_default_restore(sd->wl.win);
3418 #endif
3419 }
3420
3421 #ifdef HAVE_ELEMENTARY_WAYLAND
3422 struct _resize_info
3423 {
3424    const char *name;
3425    int location;
3426 };
3427
3428 static struct _resize_info _border_side[4] =
3429 {
3430      { ELM_CURSOR_TOP_SIDE, 1 },
3431      { ELM_CURSOR_LEFT_SIDE, 4 },
3432      { ELM_CURSOR_BOTTOM_SIDE, 2 },
3433      { ELM_CURSOR_RIGHT_SIDE, 8 },
3434 };
3435
3436 static struct _resize_info _border_corner[4] =
3437 {
3438      { ELM_CURSOR_TOP_LEFT_CORNER, 5 },
3439      { ELM_CURSOR_BOTTOM_LEFT_CORNER, 6 },
3440      { ELM_CURSOR_BOTTOM_RIGHT_CORNER, 10 },
3441      { ELM_CURSOR_TOP_RIGHT_CORNER, 9 },
3442 };
3443 #endif
3444
3445 static void
3446 _elm_win_frame_obj_move(void *data,
3447                         Evas *e EINA_UNUSED,
3448                         Evas_Object *obj EINA_UNUSED,
3449                         void *event_info EINA_UNUSED)
3450 {
3451    Elm_Win_Data *sd;
3452
3453    if (!(sd = data)) return;
3454    if (!sd->client_obj) return;
3455
3456    _elm_win_frame_obj_update(sd);
3457 }
3458
3459 static void
3460 _elm_win_frame_obj_resize(void *data,
3461                           Evas *e EINA_UNUSED,
3462                           Evas_Object *obj EINA_UNUSED,
3463                           void *event_info EINA_UNUSED)
3464 {
3465    Elm_Win_Data *sd;
3466
3467    if (!(sd = data)) return;
3468    if (!sd->client_obj) return;
3469
3470    _elm_win_frame_obj_update(sd);
3471 }
3472
3473 static void
3474 _elm_win_frame_cb_resize_show(void *data,
3475                               Evas_Object *obj EINA_UNUSED,
3476                               const char *sig EINA_UNUSED,
3477                               const char *source)
3478 {
3479    ELM_WIN_DATA_GET(data, sd);
3480
3481    if (!sd) return;
3482    if (sd->resizing) return;
3483
3484 #ifdef HAVE_ELEMENTARY_WAYLAND
3485    int i;
3486    i = sd->rot / 90;
3487    if (!strcmp(source, "elm.event.resize.t"))
3488      ecore_wl_window_cursor_from_name_set(sd->wl.win,
3489                                           _border_side[(0 + i) % 4].name);
3490    else if (!strcmp(source, "elm.event.resize.b"))
3491      ecore_wl_window_cursor_from_name_set(sd->wl.win,
3492                                           _border_side[(2 + i) % 4].name);
3493    else if (!strcmp(source, "elm.event.resize.l"))
3494      ecore_wl_window_cursor_from_name_set(sd->wl.win,
3495                                           _border_side[(1 + i) % 4].name);
3496    else if (!strcmp(source, "elm.event.resize.r"))
3497      ecore_wl_window_cursor_from_name_set(sd->wl.win,
3498                                           _border_side[(3 + i) % 4].name);
3499    else if (!strcmp(source, "elm.event.resize.tl"))
3500      ecore_wl_window_cursor_from_name_set(sd->wl.win,
3501                                           _border_corner[(0 + i) % 4].name);
3502    else if (!strcmp(source, "elm.event.resize.tr"))
3503      ecore_wl_window_cursor_from_name_set(sd->wl.win,
3504                                           _border_corner[(3 + i) % 4].name);
3505    else if (!strcmp(source, "elm.event.resize.bl"))
3506      ecore_wl_window_cursor_from_name_set(sd->wl.win,
3507                                           _border_corner[(1 + i) % 4].name);
3508    else if (!strcmp(source, "elm.event.resize.br"))
3509      ecore_wl_window_cursor_from_name_set(sd->wl.win,
3510                                           _border_corner[(2 + i) % 4].name);
3511    else
3512      ecore_wl_window_cursor_default_restore(sd->wl.win);
3513 #else
3514    (void)source;
3515 #endif
3516 }
3517
3518 static void
3519 _elm_win_frame_cb_resize_hide(void *data,
3520                               Evas_Object *obj EINA_UNUSED,
3521                               const char *sig EINA_UNUSED,
3522                               const char *source EINA_UNUSED)
3523 {
3524    ELM_WIN_DATA_GET(data, sd);
3525
3526    if (!sd) return;
3527    if (sd->resizing) return;
3528
3529 #ifdef HAVE_ELEMENTARY_WAYLAND
3530    ecore_wl_window_cursor_default_restore(sd->wl.win);
3531 #endif
3532 }
3533
3534 static void
3535 _elm_win_frame_cb_resize_start(void *data,
3536                                Evas_Object *obj EINA_UNUSED,
3537                                const char *sig EINA_UNUSED,
3538                                const char *source)
3539 {
3540 #ifdef HAVE_ELEMENTARY_WAYLAND
3541    ELM_WIN_DATA_GET(data, sd);
3542    int i;
3543
3544    if (!sd) return;
3545    if (sd->resizing) return;
3546
3547    sd->resizing = EINA_TRUE;
3548    i = sd->rot / 90;
3549    if (!strcmp(source, "elm.event.resize.t"))
3550      sd->resize_location = _border_side[(0 + i) % 4].location;
3551    else if (!strcmp(source, "elm.event.resize.b"))
3552      sd->resize_location = _border_side[(2 + i) % 4].location;
3553    else if (!strcmp(source, "elm.event.resize.l"))
3554      sd->resize_location = _border_side[(1 + i) % 4].location;
3555    else if (!strcmp(source, "elm.event.resize.r"))
3556      sd->resize_location = _border_side[(3 + i) % 4].location;
3557    else if (!strcmp(source, "elm.event.resize.tl"))
3558      sd->resize_location = _border_corner[(0 + i) % 4].location;
3559    else if (!strcmp(source, "elm.event.resize.tr"))
3560      sd->resize_location = _border_corner[(3 + i) % 4].location;
3561    else if (!strcmp(source, "elm.event.resize.bl"))
3562      sd->resize_location = _border_corner[(1 + i) % 4].location;
3563    else if (!strcmp(source, "elm.event.resize.br"))
3564      sd->resize_location = _border_corner[(2 + i) % 4].location;
3565    else
3566      sd->resize_location = 0;
3567
3568    if (sd->resize_location > 0)
3569      ecore_evas_wayland_resize(sd->ee, sd->resize_location);
3570 #else
3571    (void)data;
3572    (void)source;
3573 #endif
3574 }
3575
3576 static void
3577 _elm_win_frame_cb_resize_end(void *data,
3578                              Evas_Object *obj EINA_UNUSED,
3579                              const char *sig EINA_UNUSED,
3580                              const char *source EINA_UNUSED)
3581 {
3582 #ifdef HAVE_ELEMENTARY_WAYLAND
3583    ELM_WIN_DATA_GET(data, sd);
3584
3585    if (!sd) return;
3586    if (sd->resizing) sd->resizing = EINA_FALSE;
3587 #else
3588    (void)data;
3589 #endif
3590 }
3591 static void
3592 _elm_win_frame_cb_minimize(void *data,
3593                            Evas_Object *obj EINA_UNUSED,
3594                            const char *sig EINA_UNUSED,
3595                            const char *source EINA_UNUSED)
3596 {
3597    ELM_WIN_DATA_GET(data, sd);
3598
3599    if (!sd) return;
3600 //   sd->iconified = EINA_TRUE;
3601    TRAP(sd, iconified_set, EINA_TRUE);
3602 }
3603
3604 static void
3605 _elm_win_frame_maximized_state_update(Elm_Win_Data *sd, Eina_Bool maximized)
3606 {
3607    const char *emission;
3608
3609    if (!sd->frame_obj) return;
3610
3611    if (maximized)
3612      emission = "elm,state,maximized";
3613    else
3614      emission = "elm,state,unmaximized";
3615
3616    edje_object_signal_emit(sd->frame_obj, emission, "elm");
3617    edje_object_message_signal_process(sd->frame_obj);
3618    evas_object_smart_calculate(sd->frame_obj);
3619
3620    _elm_win_frame_obj_update(sd);
3621 }
3622
3623 static void
3624 _elm_win_frame_cb_maximize(void *data,
3625                            Evas_Object *obj EINA_UNUSED,
3626                            const char *sig EINA_UNUSED,
3627                            const char *source EINA_UNUSED)
3628 {
3629    Eina_Bool value;
3630    ELM_WIN_DATA_GET(data, sd);
3631
3632    if (!sd) return;
3633    if (sd->maximized) value = EINA_FALSE;
3634    else value = EINA_TRUE;
3635
3636    _elm_win_frame_maximized_state_update(sd, value);
3637
3638    TRAP(sd, maximized_set, value);
3639 }
3640
3641 static void
3642 _elm_win_frame_cb_close(void *data,
3643                         Evas_Object *obj EINA_UNUSED,
3644                         const char *sig EINA_UNUSED,
3645                         const char *source EINA_UNUSED)
3646 {
3647    ELM_WIN_DATA_GET(data, sd);
3648    Evas_Object *win;
3649
3650    /* FIXME: After the current freeze, this should be handled differently.
3651     *
3652     * Ideally, we would want to mimic the X11 backend and use something
3653     * like ECORE_WL_EVENT_WINDOW_DELETE and handle the delete_request
3654     * inside of ecore_evas. That would be the 'proper' way, but since we are
3655     * in a freeze right now, I cannot add a new event value, or a new
3656     * event structure to ecore_wayland.
3657     *
3658     * So yes, this is a temporary 'stop-gap' solution which will be fixed
3659     * when the freeze is over, but it does fix a trac bug for now, and in a
3660     * way which does not break API or the freeze. - dh
3661     */
3662
3663    if (!sd) return;
3664
3665    win = sd->obj;
3666
3667    int autodel = sd->autodel;
3668    sd->autodel_clear = &autodel;
3669    evas_object_ref(win);
3670    eo_do(win, eo_event_callback_call(ELM_WIN_EVENT_DELETE_REQUEST, NULL));
3671    if (sd->autohide)
3672      evas_object_hide(win);
3673    // FIXME: if above callback deletes - then the below will be invalid
3674    if (autodel) evas_object_del(win);
3675    else sd->autodel_clear = NULL;
3676    evas_object_unref(win);
3677 }
3678
3679 #ifdef HAVE_ELEMENTARY_WAYLAND
3680 static void
3681 _elm_win_frame_pre_render(void *data, Evas *e EINA_UNUSED, void *ev EINA_UNUSED)
3682 {
3683    Elm_Win_Data *sd = data;
3684
3685    if (sd->wl.opaque_dirty)
3686      _elm_win_opaque_update(sd);
3687    sd->wl.opaque_dirty = 0;
3688 }
3689 #endif
3690
3691 static void
3692 _elm_win_frame_add(Elm_Win_Data *sd,
3693                    const char *style)
3694 {
3695    Evas_Object *obj = sd->obj;
3696    int w, h, mw, mh;
3697    short layer;
3698
3699    sd->frame_obj = edje_object_add(sd->evas);
3700    layer = evas_object_layer_get(obj);
3701    evas_object_layer_set(sd->frame_obj, layer + 1);
3702    if (!elm_widget_theme_object_set
3703        (sd->obj, sd->frame_obj, "border", "base", style))
3704      {
3705         ELM_SAFE_FREE(sd->frame_obj, evas_object_del);
3706         return;
3707      }
3708
3709    sd->client_obj = evas_object_rectangle_add(sd->evas);
3710    evas_object_color_set(sd->client_obj, 0, 0, 0, 0);
3711    /* NB: Tried pass_events here, but that fails to send events */
3712    evas_object_repeat_events_set(sd->client_obj, EINA_TRUE);
3713    edje_object_part_swallow(sd->frame_obj, "elm.swallow.client",
3714                             sd->client_obj);
3715
3716    evas_object_is_frame_object_set(sd->frame_obj, EINA_TRUE);
3717
3718    if (sd->icon)
3719      evas_object_show(sd->icon);
3720    else
3721      {
3722         Eina_Bool set = EINA_FALSE;
3723
3724         sd->icon = elm_icon_add(sd->obj);
3725
3726         if (sd->icon_name)
3727           set = elm_icon_standard_set(sd->icon, sd->icon_name);
3728         if ((!sd->icon_name) || (!set))
3729           {
3730              Efreet_Desktop *d;
3731              d = efreet_util_desktop_exec_find(_elm_appname);
3732              if (d)
3733                {
3734                   elm_icon_standard_set(sd->icon, d->icon);
3735                   efreet_desktop_free(d);
3736                }
3737           }
3738      }
3739
3740    edje_object_part_swallow(sd->frame_obj, "elm.swallow.icon",
3741                             sd->icon);
3742
3743    evas_object_event_callback_add
3744      (sd->frame_obj, EVAS_CALLBACK_MOVE, _elm_win_frame_obj_move, sd);
3745    evas_object_event_callback_add
3746      (sd->frame_obj, EVAS_CALLBACK_RESIZE, _elm_win_frame_obj_resize, sd);
3747 #ifdef HAVE_ELEMENTARY_WAYLAND
3748    evas_event_callback_add(sd->evas, EVAS_CALLBACK_RENDER_PRE, _elm_win_frame_pre_render, sd);
3749 #endif
3750
3751    /* NB: Do NOT remove these calls !! Needed to calculate proper
3752     * framespace on initial show of the window */
3753    edje_object_size_min_calc(sd->frame_obj, &mw, &mh);
3754    evas_object_move(sd->frame_obj, 0, 0);
3755    evas_object_resize(sd->frame_obj, mw, mh);
3756    evas_object_smart_calculate(sd->frame_obj);
3757
3758    edje_object_signal_callback_add
3759      (sd->frame_obj, "elm,action,move,start", "elm",
3760      _elm_win_frame_cb_move_start, obj);
3761    edje_object_signal_callback_add
3762      (sd->frame_obj, "elm,action,move,stop", "elm",
3763      _elm_win_frame_cb_move_stop, obj);
3764    edje_object_signal_callback_add
3765      (sd->frame_obj, "elm,action,resize,show", "*",
3766      _elm_win_frame_cb_resize_show, obj);
3767    edje_object_signal_callback_add
3768      (sd->frame_obj, "elm,action,resize,hide", "*",
3769      _elm_win_frame_cb_resize_hide, obj);
3770    edje_object_signal_callback_add
3771      (sd->frame_obj, "elm,action,resize,start", "*",
3772      _elm_win_frame_cb_resize_start, obj);
3773    edje_object_signal_callback_add
3774      (sd->frame_obj, "elm,action,resize,end", "*",
3775      _elm_win_frame_cb_resize_end, obj);
3776    edje_object_signal_callback_add
3777      (sd->frame_obj, "elm,action,minimize", "elm",
3778      _elm_win_frame_cb_minimize, obj);
3779    edje_object_signal_callback_add
3780      (sd->frame_obj, "elm,action,maximize", "elm",
3781      _elm_win_frame_cb_maximize, obj);
3782    edje_object_signal_callback_add
3783      (sd->frame_obj, "elm,action,close", "elm", _elm_win_frame_cb_close, obj);
3784
3785    if (sd->title)
3786      {
3787         edje_object_part_text_escaped_set
3788           (sd->frame_obj, "elm.text.title", sd->title);
3789      }
3790
3791    ecore_evas_geometry_get(sd->ee, NULL, NULL, &w, &h);
3792    ecore_evas_resize(sd->ee, w, h);
3793 }
3794
3795 static void
3796 _elm_win_frame_del(Elm_Win_Data *sd)
3797 {
3798    int w, h;
3799
3800    ELM_SAFE_FREE(sd->client_obj, evas_object_del);
3801
3802    if (sd->frame_obj)
3803      {
3804         evas_object_event_callback_del_full
3805           (sd->frame_obj, EVAS_CALLBACK_MOVE, _elm_win_frame_obj_move, sd);
3806         evas_object_event_callback_del_full
3807           (sd->frame_obj, EVAS_CALLBACK_RESIZE, _elm_win_frame_obj_resize, sd);
3808 #ifdef HAVE_ELEMENTARY_WAYLAND
3809         evas_event_callback_del_full(sd->evas, EVAS_CALLBACK_RENDER_PRE, _elm_win_frame_pre_render, sd);
3810 #endif
3811
3812         edje_object_signal_callback_del
3813           (sd->frame_obj, "elm,action,move,start", "elm",
3814               _elm_win_frame_cb_move_start);
3815         edje_object_signal_callback_del
3816           (sd->frame_obj, "elm,action,move,stop", "elm",
3817               _elm_win_frame_cb_move_stop);
3818         edje_object_signal_callback_del
3819           (sd->frame_obj, "elm,action,resize,show", "*",
3820               _elm_win_frame_cb_resize_show);
3821         edje_object_signal_callback_del
3822           (sd->frame_obj, "elm,action,resize,hide", "*",
3823               _elm_win_frame_cb_resize_hide);
3824         edje_object_signal_callback_del
3825           (sd->frame_obj, "elm,action,resize,start", "*",
3826               _elm_win_frame_cb_resize_start);
3827         edje_object_signal_callback_del
3828           (sd->frame_obj, "elm,action,resize,end", "*",
3829               _elm_win_frame_cb_resize_end);
3830         edje_object_signal_callback_del
3831           (sd->frame_obj, "elm,action,minimize", "elm",
3832               _elm_win_frame_cb_minimize);
3833         edje_object_signal_callback_del
3834           (sd->frame_obj, "elm,action,maximize", "elm",
3835               _elm_win_frame_cb_maximize);
3836         edje_object_signal_callback_del
3837           (sd->frame_obj, "elm,action,close", "elm",
3838               _elm_win_frame_cb_close);
3839
3840         ELM_SAFE_FREE(sd->frame_obj, evas_object_del);
3841      }
3842    if (sd->icon) evas_object_hide(sd->icon);
3843
3844    evas_output_framespace_set(sd->evas, 0, 0, 0, 0);
3845    ecore_evas_geometry_get(sd->ee, NULL, NULL, &w, &h);
3846    ecore_evas_resize(sd->ee, w, h);
3847 }
3848
3849 #ifdef ELM_DEBUG
3850 static void
3851 _debug_key_down(void *data EINA_UNUSED,
3852                 Evas *e EINA_UNUSED,
3853                 Evas_Object *obj,
3854                 void *event_info)
3855 {
3856    Evas_Event_Key_Down *ev = event_info;
3857
3858    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
3859      return;
3860
3861    if ((strcmp(ev->key, "F12")) ||
3862        (!evas_key_modifier_is_set(ev->modifiers, "Control")))
3863      return;
3864
3865    INF("Tree graph generated.");
3866    elm_object_tree_dot_dump(obj, "./dump.dot");
3867 }
3868
3869 #endif
3870
3871 static void
3872 _win_inlined_image_set(Elm_Win_Data *sd)
3873 {
3874    evas_object_image_alpha_set(sd->img_obj, EINA_FALSE);
3875    evas_object_image_filled_set(sd->img_obj, EINA_TRUE);
3876
3877    evas_object_event_callback_add
3878      (sd->img_obj, EVAS_CALLBACK_DEL, _elm_win_on_img_obj_del, sd->obj);
3879    evas_object_event_callback_add
3880      (sd->img_obj, EVAS_CALLBACK_HIDE, _win_img_hide, sd->obj);
3881    evas_object_event_callback_add
3882      (sd->img_obj, EVAS_CALLBACK_MOUSE_UP, _win_img_mouse_up, sd->obj);
3883    evas_object_event_callback_add
3884      (sd->img_obj, EVAS_CALLBACK_FOCUS_IN, _win_img_focus_in, sd->obj);
3885    evas_object_event_callback_add
3886      (sd->img_obj, EVAS_CALLBACK_FOCUS_OUT, _win_img_focus_out, sd->obj);
3887 }
3888
3889 static void
3890 _elm_win_on_icon_del(void *data,
3891                      Evas *e EINA_UNUSED,
3892                      Evas_Object *obj,
3893                      void *event_info EINA_UNUSED)
3894 {
3895    ELM_WIN_DATA_GET(data, sd);
3896
3897    if (sd->icon == obj) sd->icon = NULL;
3898 }
3899
3900 EOLIAN static void
3901 _elm_win_evas_object_smart_add(Eo *obj, Elm_Win_Data *_pd EINA_UNUSED)
3902 {
3903    eo_do_super(obj, MY_CLASS, evas_obj_smart_add());
3904
3905    elm_widget_can_focus_set(obj, EINA_TRUE);
3906
3907    elm_widget_highlight_ignore_set(obj, EINA_TRUE);
3908 }
3909
3910 #ifdef HAVE_ELEMENTARY_X
3911 static void
3912 _elm_x_io_err(void *data EINA_UNUSED)
3913 {
3914    Eina_List *l;
3915    Evas_Object *obj;
3916
3917    EINA_LIST_FOREACH(_elm_win_list, l, obj)
3918      eo_do(obj, eo_event_callback_call(ELM_WIN_EVENT_IOERR, NULL));
3919    elm_exit();
3920 }
3921 #endif
3922
3923 // TIZEN_ONLY(20160218): Improve launching performance.
3924 EAPI void
3925 elm_win_precreated_object_set(Evas_Object *obj)
3926 {
3927    INF("Set precreated obj(%p).", obj);
3928    _precreated_win_obj = obj;
3929 }
3930
3931 EAPI Evas_Object *
3932 elm_win_precreated_object_get(void)
3933 {
3934    INF("Get precreated obj(%p).", _precreated_win_obj);
3935    return _precreated_win_obj;
3936 }
3937 //
3938
3939 // TIZEN_ONLY(20160728): Indicator Implementation
3940 #ifdef HAVE_ELEMENTARY_WAYLAND
3941 static Eina_Bool
3942 _elm_win_wl_indicator_flick(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
3943 {
3944    ELM_WIN_DATA_GET(data, sd);
3945    evas_object_smart_callback_call(sd->obj, SIG_INDICATOR_FLICK_DONE, NULL);
3946    return ECORE_CALLBACK_PASS_ON;
3947 }
3948 #endif
3949 // END
3950
3951 EAPI Evas_Object *
3952 elm_win_add(Evas_Object *parent,
3953             const char *name,
3954             Elm_Win_Type type)
3955 {
3956 //TIZEN_ONLY(20160628):  Add Performance log for cold booting
3957 #ifdef ENABLE_TTRACE
3958    traceBegin(TTRACE_TAG_EFL, "elm_win_add");
3959 #endif
3960 //
3961
3962 //TIZEN_ONLY(20161202): Temporary code - Apply mirroring in elm_win_add()
3963    if (_elm_config && _elm_config->language_auto_mirrored)
3964      {
3965         if (!strcmp(E_("default:LTR"), "default:RTL"))
3966           elm_config_mirrored_set(EINA_TRUE);
3967         else
3968           elm_config_mirrored_set(EINA_FALSE);
3969      }
3970 //
3971
3972 // TIZEN_ONLY(20160218): Improve launching performance.
3973    if (_precreated_win_obj)
3974      {
3975         ELM_WIN_DATA_GET(_precreated_win_obj, sd);
3976
3977         if ((type != ELM_WIN_SOCKET_IMAGE) &&
3978             (type != ELM_WIN_INLINED_IMAGE))
3979           {
3980              if (sd)
3981                {
3982                   if (sd->parent == parent)
3983                     {
3984                        Evas_Object *tmp = _precreated_win_obj;
3985                        TRAP(sd, name_class_set, name, _elm_appname);
3986                        TRAP(sd, title_set, sd->title ? sd->title : name);
3987                        _precreated_win_obj = NULL;
3988                        if (sd->type != type)
3989                          elm_win_type_set(tmp, type);
3990                        INF("Return precreated obj(%p).", tmp);
3991
3992                        //TIZEN_ONLY(20160628):  Add Performance log for cold booting
3993 #ifdef ENABLE_TTRACE
3994                        traceEnd(TTRACE_TAG_EFL);
3995 #endif
3996                        //
3997
3998                        // TIZEN_ONLY(20161202): Apply paragraph direction
3999                        if (!strcmp(E_("default:LTR"), "default:RTL"))
4000                          evas_object_paragraph_direction_set(tmp, EVAS_BIDI_DIRECTION_ANY_RTL);
4001                        else
4002                          evas_object_paragraph_direction_set(tmp, EVAS_BIDI_DIRECTION_LTR);
4003                        //
4004
4005                        return tmp;
4006                     }
4007                }
4008           }
4009         Evas_Object *bg = elm_bg_precreated_object_get();
4010         if (bg)
4011           {
4012              evas_object_del(bg);
4013              elm_bg_precreated_object_set(NULL);
4014           }
4015         Evas_Object *conform = elm_conformant_precreated_object_get();
4016         if (conform)
4017           {
4018              evas_object_del(conform);
4019              elm_conformant_precreated_object_set(NULL);
4020           }
4021         evas_object_del(_precreated_win_obj);
4022         _precreated_win_obj = NULL;
4023      }
4024 //
4025
4026    Evas_Object *obj = eo_add(MY_CLASS, parent,
4027                              elm_obj_win_name_set(name),
4028                              elm_obj_win_type_set(type));
4029 //TIZEN_ONLY(20160628):  Add Performance log for cold booting
4030 #ifdef ENABLE_TTRACE
4031    traceEnd(TTRACE_TAG_EFL);
4032 #endif
4033 //
4034
4035
4036    return obj;
4037 }
4038
4039 EAPI Evas_Object *
4040 elm_win_fake_add(Ecore_Evas *ee)
4041 {
4042    return eo_add(MY_CLASS, NULL,
4043          elm_obj_win_fake_canvas_set(ee),
4044          elm_obj_win_name_set(NULL),
4045          elm_obj_win_type_set(ELM_WIN_FAKE));
4046 }
4047
4048 static void
4049 _elm_win_cb_hide(void *data EINA_UNUSED,
4050                  Evas *e EINA_UNUSED,
4051                  Evas_Object *obj EINA_UNUSED,
4052                  void *event_info EINA_UNUSED)
4053 {
4054    _elm_win_state_eval_queue();
4055 }
4056
4057 static void
4058 _elm_win_cb_show(void *data EINA_UNUSED,
4059                  Evas *e EINA_UNUSED,
4060                  Evas_Object *obj EINA_UNUSED,
4061                  void *event_info EINA_UNUSED)
4062 {
4063    _elm_win_state_eval_queue();
4064 }
4065
4066 /**
4067   * @internal
4068   *
4069   * Recalculate the size of window considering its resize objects' weight and
4070   * min size. If any of its resize objects' weight equals to 0.0, window
4071   * layout's weight will be set to 0.0.
4072   *
4073   * @param o box object
4074   * @param p box's private data
4075   * @param data window object
4076   */
4077 static void
4078 _window_layout_stack(Evas_Object *o, Evas_Object_Box_Data *p, void *data)
4079 {
4080    const Eina_List *l;
4081    Evas_Object *child;
4082    Evas_Object_Box_Option *opt;
4083    Evas_Coord x, y, w, h;
4084    double wx, wy;
4085    Evas_Coord minw = -1, minh = -1;
4086    double weight_x = EVAS_HINT_EXPAND;
4087    double weight_y = EVAS_HINT_EXPAND;
4088
4089    EINA_LIST_FOREACH(p->children, l, opt)
4090      {
4091         child = opt->obj;
4092         evas_object_size_hint_weight_get(child, &wx, &wy);
4093         if (wx == 0.0) weight_x = 0;
4094         if (wy == 0.0) weight_y = 0;
4095
4096         evas_object_size_hint_min_get(child, &w, &h);
4097         if (w > minw) minw = w;
4098         if (h > minh) minh = h;
4099      }
4100
4101    evas_object_size_hint_min_set(o, minw, minh);
4102    evas_object_geometry_get(o, &x, &y, &w, &h);
4103    if (w < minw) w = minw;
4104    if (h < minh) h = minh;
4105    evas_object_resize(o, w, h);
4106
4107    EINA_LIST_FOREACH(p->children, l, opt)
4108      {
4109         child = opt->obj;
4110         evas_object_move(child, x, y);
4111         evas_object_resize(child, w, h);
4112      }
4113
4114    ELM_WIN_DATA_GET(data, sd);
4115    evas_object_size_hint_weight_set(sd->edje, weight_x, weight_y);
4116    evas_object_smart_changed(sd->edje);
4117 }
4118
4119 static Eina_Bool
4120 _accel_is_gl(void)
4121 {
4122    const char *env = NULL;
4123    const char *str = NULL;
4124
4125    if (_elm_config->accel) str = _elm_config->accel;
4126    if (_elm_accel_preference) str = _elm_accel_preference;
4127    if ((_elm_config->accel_override) && (_elm_config->accel))
4128      str = _elm_config->accel;
4129    env = getenv("ELM_ACCEL");
4130    if (env) str = env;
4131    if ((str) &&
4132        ((!strcasecmp(str, "gl")) ||
4133         (!strcasecmp(str, "opengl")) ||
4134         (!strcasecmp(str, "3d")) ||
4135         (!strcasecmp(str, "hw")) ||
4136         (!strcasecmp(str, "accel")) ||
4137         (!strcasecmp(str, "hardware"))
4138        ))
4139      return EINA_TRUE;
4140    return EINA_FALSE;
4141 }
4142
4143 static Eina_Bool
4144 _animator_tick_cb(void *_obj)
4145 {
4146    Elm_Win *obj = _obj;
4147    eo_do(obj, eo_event_callback_call(ELM_WIN_EVENT_ANIMATOR_TICK, NULL));
4148
4149    return ECORE_CALLBACK_RENEW;
4150 }
4151
4152 static Eina_Bool
4153 _cb_added(void *_data,
4154           Eo *obj,
4155           const Eo_Event_Description *desc EINA_UNUSED,
4156           void *event_info)
4157 {
4158    const Eo_Callback_Array_Item *event = event_info;
4159    Elm_Win_Data *data = _data;
4160
4161    if (event->desc == ELM_WIN_EVENT_ANIMATOR_TICK)
4162      {
4163         data->animator.wants++;
4164         if (data->animator.wants == 1)
4165           {
4166              data->animator.obj = eo_add(ECORE_ANIMATOR_CLASS, obj,
4167                    ecore_animator_constructor(_animator_tick_cb, obj));
4168           }
4169      }
4170
4171    return EO_CALLBACK_CONTINUE;
4172 }
4173
4174 static Eina_Bool
4175 _cb_deled(void *_data,
4176           Eo *obj EINA_UNUSED,
4177           const Eo_Event_Description *desc EINA_UNUSED,
4178           void *event_info)
4179 {
4180    const Eo_Callback_Array_Item *event = event_info;
4181    Elm_Win_Data *data = _data;
4182
4183    if (event->desc == ELM_WIN_EVENT_ANIMATOR_TICK)
4184      {
4185         data->animator.wants--;
4186         if (data->animator.wants == 0)
4187           {
4188              eo_del(data->animator.obj);
4189              data->animator.obj = NULL;
4190           }
4191      }
4192
4193    return EO_CALLBACK_CONTINUE;
4194 }
4195
4196 static Eo *
4197 _elm_win_finalize_internal(Eo *obj, Elm_Win_Data *sd, const char *name, Elm_Win_Type type)
4198 {
4199    sd->obj = obj; // in ctor
4200
4201    Evas_Object *parent = NULL;
4202    Evas *e;
4203    const Eina_List *l;
4204    const char *fontpath, *engine = NULL, *enginelist[32], *disp;
4205    int i, p = 0;
4206
4207    Elm_Win_Data tmp_sd;
4208
4209    eo_do(obj, parent = eo_parent_get());
4210
4211    /* just to store some data while trying out to create a canvas */
4212    memset(&tmp_sd, 0, sizeof(Elm_Win_Data));
4213
4214    switch (type)
4215      {
4216       case ELM_WIN_FAKE:
4217         tmp_sd.ee = sd->ee;
4218         break;
4219       case ELM_WIN_INLINED_IMAGE:
4220         if (!parent) break;
4221           {
4222              e = evas_object_evas_get(parent);
4223              Ecore_Evas *ee;
4224
4225              if (!e) break;
4226
4227              ee = ecore_evas_ecore_evas_get(e);
4228              if (!ee) break;
4229
4230              tmp_sd.img_obj = ecore_evas_object_image_new(ee);
4231              if (!tmp_sd.img_obj) break;
4232
4233              tmp_sd.ee = ecore_evas_object_ecore_evas_get(tmp_sd.img_obj);
4234              if (!tmp_sd.ee)
4235                {
4236                   ELM_SAFE_FREE(tmp_sd.img_obj, evas_object_del);
4237                }
4238           }
4239         break;
4240
4241       case ELM_WIN_SOCKET_IMAGE:
4242         tmp_sd.ee = ecore_evas_extn_socket_new(1, 1);
4243         break;
4244
4245       default:
4246         disp = getenv("ELM_DISPLAY");
4247         if ((disp) && (!strcmp(disp, "ews")))
4248           {
4249              enginelist[p++] = ELM_EWS;
4250           }
4251         else if ((disp) && (!strcmp(disp, "buffer")))
4252           {
4253              enginelist[p++] = ELM_BUFFER;
4254           }
4255         else if ((disp) && (!strcmp(disp, "shot")))
4256           {
4257              enginelist[p++] = ENGINE_GET();
4258           }
4259 // welcome to ifdef hell! :)
4260
4261 #ifdef HAVE_ELEMENTARY_X
4262         else if ((disp) && (!strcmp(disp, "x11")))
4263           {
4264              if (_accel_is_gl())
4265                {
4266                   enginelist[p++] = ELM_OPENGL_X11;
4267                   enginelist[p++] = ELM_SOFTWARE_X11;
4268                }
4269              else
4270                {
4271                   enginelist[p++] = ELM_SOFTWARE_X11;
4272                   enginelist[p++] = ELM_OPENGL_X11;
4273                }
4274           }
4275 #endif
4276
4277 #ifdef HAVE_ELEMENTARY_WAYLAND
4278         else if ((disp) && (!strcmp(disp, "wl")))
4279           {
4280              if (_accel_is_gl())
4281                {
4282                   enginelist[p++] = ELM_WAYLAND_EGL;
4283                   enginelist[p++] = ELM_WAYLAND_SHM;
4284                }
4285              else
4286                {
4287                   enginelist[p++] = ELM_WAYLAND_SHM;
4288                   enginelist[p++] = ELM_WAYLAND_EGL;
4289                }
4290           }
4291 #endif
4292
4293 #ifdef HAVE_ELEMENTARY_WIN32
4294         else if ((disp) && (!strcmp(disp, "win")))
4295           {
4296              enginelist[p++] = ELM_SOFTWARE_WIN32;
4297              enginelist[p++] = ELM_SOFTWARE_DDRAW;
4298           }
4299 #endif
4300
4301 #ifdef HAVE_ELEMENTARY_SDL
4302         else if ((disp) && (!strcmp(disp, "sdl")))
4303           {
4304              if (_accel_is_gl())
4305                {
4306                   enginelist[p++] = ELM_OPENGL_SDL;
4307                   enginelist[p++] = ELM_SOFTWARE_SDL;
4308                }
4309              else
4310                {
4311                   enginelist[p++] = ELM_SOFTWARE_SDL;
4312                   enginelist[p++] = ELM_OPENGL_SDL;
4313                }
4314           }
4315 #endif
4316
4317 #ifdef HAVE_ELEMENTARY_COCOA
4318         else if ((disp) && (!strcmp(disp, "mac")))
4319           {
4320              enginelist[p++] = ELM_OPENGL_COCOA;
4321           }
4322 #endif
4323
4324 #if defined(HAVE_ELEMENTARY_DRM) || defined(HAVE_ELEMENTARY_FB)
4325         else if ((disp) && (!strcmp(disp, "fb")))
4326           {
4327 #ifdef HAVE_ELEMENTARY_DRM
4328              enginelist[p++] = ELM_DRM;
4329 #endif
4330 #ifdef HAVE_ELEMENTARY_FB
4331              enginelist[p++] = ELM_SOFTWARE_FB;
4332 #endif
4333           }
4334 #endif
4335
4336 #ifdef HAVE_ELEMENTARY_PSL1GHT
4337         else if ((disp) && (!strcmp(disp, "ps3")))
4338           {
4339              enginelist[p++] = ELM_SOFTWARE_PSL1GHT;
4340           }
4341 #endif
4342 #ifdef HAVE_ELEMENTARY_X
4343         else if (!_elm_preferred_engine &&
4344                  getenv("DISPLAY") && !getenv("ELM_ENGINE"))
4345           {
4346              if (_accel_is_gl())
4347                {
4348                   enginelist[p++] = ELM_OPENGL_X11;
4349                   enginelist[p++] = ELM_SOFTWARE_X11;
4350                }
4351              else
4352                {
4353                   enginelist[p++] = ELM_SOFTWARE_X11;
4354                   enginelist[p++] = ELM_OPENGL_X11;
4355                }
4356           }
4357 #endif
4358 #ifdef HAVE_ELEMENTARY_WAYLAND
4359         else if (!_elm_preferred_engine &&
4360                  getenv("WAYLAND_DISPLAY") && !getenv("ELM_ENGINE"))
4361           {
4362              if (_accel_is_gl())
4363                {
4364                   enginelist[p++] = ELM_WAYLAND_EGL;
4365                   enginelist[p++] = ELM_WAYLAND_SHM;
4366                }
4367              else
4368                {
4369                   enginelist[p++] = ELM_WAYLAND_SHM;
4370                   enginelist[p++] = ELM_WAYLAND_EGL;
4371                }
4372           }
4373 #endif
4374         else
4375           {
4376              if (_accel_is_gl())
4377                {
4378 // add all engines with selected engine first - if any
4379                   if (ENGINE_GET())
4380                     enginelist[p++] = ENGINE_GET();
4381
4382 // add all engines with gl/accelerated ones first - only engines compiled
4383 #ifdef HAVE_ELEMENTARY_X
4384                   enginelist[p++] = ELM_OPENGL_X11;
4385 #endif
4386 #ifdef HAVE_ELEMENTARY_WAYLAND
4387                   enginelist[p++] = ELM_WAYLAND_EGL;
4388 #endif
4389 #ifdef HAVE_ELEMENTARY_DRM
4390                   enginelist[p++] = ELM_DRM;
4391 #endif
4392 #ifdef HAVE_ELEMENTARY_FB
4393                   enginelist[p++] = ELM_SOFTWARE_FB;
4394 #endif
4395 #ifdef HAVE_ELEMENTARY_COCOA
4396                   enginelist[p++] = ELM_OPENGL_COCOA;
4397 #endif
4398 #ifdef HAVE_ELEMENTARY_SDL
4399                   enginelist[p++] = ELM_OPENGL_SDL;
4400 #endif
4401 #ifdef HAVE_ELEMENTARY_X
4402                   enginelist[p++] = ELM_SOFTWARE_X11;
4403 #endif
4404 #ifdef HAVE_ELEMENTARY_WAYLAND
4405                   enginelist[p++] = ELM_WAYLAND_SHM;
4406 #endif
4407 #ifdef HAVE_ELEMENTARY_WIN32
4408                   enginelist[p++] = ELM_SOFTWARE_WIN32;
4409                   enginelist[p++] = ELM_SOFTWARE_DDRAW;
4410 #endif
4411 #ifdef HAVE_ELEMENTARY_SDL
4412                   enginelist[p++] = ELM_SOFTWARE_SDL;
4413 #endif
4414 #ifdef HAVE_ELEMENTARY_PSL1GHT
4415                   enginelist[p++] = ELM_SOFTWARE_PSL1GHT;
4416 #endif
4417                }
4418              else
4419                {
4420 // add all engines with selected engine first - if any
4421                   if (elm_config_preferred_engine_get())
4422                     enginelist[p++] = elm_config_preferred_engine_get();
4423 // add check _elm_gl_preference whether "none" or not
4424                   else if (_elm_config->engine &&
4425                            elm_config_accel_preference_get() &&
4426                            !strcmp(elm_config_accel_preference_get(),"none"))
4427                     enginelist[p++] = _elm_config->engine;
4428 // add all engines with gl/accelerated ones first - only engines compiled
4429 #ifdef HAVE_ELEMENTARY_X
4430                   enginelist[p++] = ELM_SOFTWARE_X11;
4431 #endif
4432 #ifdef HAVE_ELEMENTARY_WAYLAND
4433                   enginelist[p++] = ELM_WAYLAND_SHM;
4434 #endif
4435 #ifdef HAVE_ELEMENTARY_DRM
4436                   enginelist[p++] = ELM_DRM;
4437 #endif
4438 #ifdef HAVE_ELEMENTARY_FB
4439                   enginelist[p++] = ELM_SOFTWARE_FB;
4440 #endif
4441 #ifdef HAVE_ELEMENTARY_COCOA
4442                   enginelist[p++] = ELM_OPENGL_COCOA;
4443 #endif
4444 #ifdef HAVE_ELEMENTARY_WIN32
4445                   enginelist[p++] = ELM_SOFTWARE_WIN32;
4446                   enginelist[p++] = ELM_SOFTWARE_DDRAW;
4447 #endif
4448 #ifdef HAVE_ELEMENTARY_SDL
4449                   enginelist[p++] = ELM_SOFTWARE_SDL;
4450 #endif
4451 #ifdef HAVE_ELEMENTARY_X
4452                   enginelist[p++] = ELM_OPENGL_X11;
4453 #endif
4454 #ifdef HAVE_ELEMENTARY_WAYLAND
4455                   enginelist[p++] = ELM_WAYLAND_EGL;
4456 #endif
4457 #ifdef HAVE_ELEMENTARY_DRM
4458                   enginelist[p++] = ELM_DRM;
4459 #endif
4460 #ifdef HAVE_ELEMENTARY_SDL
4461                   enginelist[p++] = ELM_OPENGL_SDL;
4462 #endif
4463 #ifdef HAVE_ELEMENTARY_PSL1GHT
4464                   enginelist[p++] = ELM_SOFTWARE_PSL1GHT;
4465 #endif
4466                }
4467           }
4468
4469         for (i = 0; i < p; i++)
4470           {
4471              if (!strcmp(enginelist[i], ELM_SOFTWARE_X11))
4472                tmp_sd.ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
4473              else if (!strcmp(enginelist[i], ELM_OPENGL_X11))
4474                {
4475                   int opt[20], opt_i = 0;
4476
4477                   if (_elm_config->vsync)
4478                     {
4479                        opt[opt_i++] = ECORE_EVAS_GL_X11_OPT_VSYNC;
4480                        opt[opt_i++] = 1;
4481                     }
4482                   if (_elm_config->gl_depth)
4483                     {
4484                        opt[opt_i++] = ECORE_EVAS_GL_X11_OPT_GL_DEPTH;
4485                        opt[opt_i++] = _elm_config->gl_depth;
4486                     }
4487                   if (_elm_config->gl_stencil)
4488                     {
4489                        opt[opt_i++] = ECORE_EVAS_GL_X11_OPT_GL_STENCIL;
4490                        opt[opt_i++] = _elm_config->gl_stencil;
4491                     }
4492                   if (_elm_config->gl_msaa)
4493                     {
4494                        opt[opt_i++] = ECORE_EVAS_GL_X11_OPT_GL_MSAA;
4495                        opt[opt_i++] = _elm_config->gl_msaa;
4496                     }
4497                   opt[opt_i] = 0;
4498                   if (opt_i > 0)
4499                     tmp_sd.ee = ecore_evas_gl_x11_options_new(NULL, 0, 0, 0, 1, 1, opt);
4500                   else
4501                     tmp_sd.ee = ecore_evas_gl_x11_new(NULL, 0, 0, 0, 1, 1);
4502                }
4503              else if (!strcmp(enginelist[i], ELM_WAYLAND_SHM))
4504                tmp_sd.ee = ecore_evas_wayland_shm_new(NULL, 0, 0, 0, 1, 1, 0);
4505              else if (!strcmp(enginelist[i], ELM_WAYLAND_EGL))
4506                {
4507                   int opt[20], opt_i = 0;
4508
4509                   if (_elm_config->vsync)
4510                     {
4511                        opt[opt_i++] = ECORE_EVAS_OPT_VSYNC;
4512                        opt[opt_i++] = 1;
4513                     }
4514                   if (_elm_config->gl_depth)
4515                     {
4516                        opt[opt_i++] = ECORE_EVAS_OPT_GL_DEPTH;
4517                        opt[opt_i++] = _elm_config->gl_depth;
4518                     }
4519                   if (_elm_config->gl_stencil)
4520                     {
4521                        opt[opt_i++] = ECORE_EVAS_OPT_GL_STENCIL;
4522                        opt[opt_i++] = _elm_config->gl_stencil;
4523                     }
4524                   if (_elm_config->gl_msaa)
4525                     {
4526                        opt[opt_i++] = ECORE_EVAS_OPT_GL_MSAA;
4527                        opt[opt_i++] = _elm_config->gl_msaa;
4528                     }
4529                   opt[opt_i] = 0;
4530                   if (opt_i > 0)
4531                     tmp_sd.ee = ecore_evas_wayland_egl_options_new(NULL, 0, 0, 0, 1, 1, 0, opt);
4532                   else
4533                     tmp_sd.ee = ecore_evas_wayland_egl_new(NULL, 0, 0, 0, 1, 1, 0);
4534                }
4535              else if (!strcmp(enginelist[i], ELM_SOFTWARE_WIN32))
4536                tmp_sd.ee = ecore_evas_software_gdi_new(NULL, 0, 0, 1, 1);
4537              else if (!strcmp(enginelist[i], ELM_SOFTWARE_DDRAW))
4538                tmp_sd.ee = ecore_evas_software_ddraw_new(NULL, 0, 0, 1, 1);
4539              else if (!strcmp(enginelist[i], ELM_SOFTWARE_SDL))
4540                tmp_sd.ee = ecore_evas_sdl_new(NULL, 0, 0, 0, 0, 0, 1);
4541              else if (!strcmp(enginelist[i], ELM_OPENGL_SDL))
4542                tmp_sd.ee = ecore_evas_gl_sdl_new(NULL, 1, 1, 0, 0);
4543              else if (!strcmp(enginelist[i], ELM_OPENGL_COCOA))
4544                tmp_sd.ee = ecore_evas_cocoa_new(NULL, 1, 1, 0, 0);
4545              else if (!strcmp(enginelist[i], ELM_EWS))
4546                tmp_sd.ee = ecore_evas_ews_new(0, 0, 1, 1);
4547              else if (!strcmp(enginelist[i], ELM_SOFTWARE_FB))
4548                tmp_sd.ee = ecore_evas_fb_new(NULL, 0, 1, 1);
4549              else if (!strcmp(enginelist[i], ELM_BUFFER))
4550                tmp_sd.ee = ecore_evas_buffer_new(1, 1);
4551              else if (!strcmp(enginelist[i], ELM_SOFTWARE_PSL1GHT))
4552                tmp_sd.ee = ecore_evas_psl1ght_new(NULL, 1, 1);
4553              else if (!strcmp(enginelist[i], ELM_DRM))
4554                tmp_sd.ee = ecore_evas_drm_new(NULL, 0, 0, 0, 1, 1);
4555              else if (!strncmp(enginelist[i], "shot:", 5))
4556                {
4557                   tmp_sd.ee = ecore_evas_buffer_new(1, 1);
4558                   ecore_evas_manual_render_set(tmp_sd.ee, EINA_TRUE);
4559                   tmp_sd.shot.info = eina_stringshare_add(ENGINE_GET() + 5);
4560                }
4561              engine = enginelist[i];
4562              if (tmp_sd.ee) break;
4563           }
4564         break;
4565      }
4566
4567    if (!tmp_sd.ee)
4568      {
4569         ERR("Cannot create window.");
4570         return NULL;
4571      }
4572
4573    eo_do(obj, eo_parent_set(ecore_evas_get(tmp_sd.ee)));
4574
4575    eo_do_super(obj, MY_CLASS, eo_constructor());
4576    eo_do(obj,
4577          evas_obj_type_set(MY_CLASS_NAME_LEGACY),
4578          evas_obj_smart_callbacks_descriptions_set(_smart_callbacks));
4579
4580    if (getenv("ELM_FIRST_FRAME"))
4581      evas_event_callback_add(ecore_evas_get(tmp_sd.ee), EVAS_CALLBACK_RENDER_POST,
4582                              _elm_win_first_frame_do, getenv("ELM_FIRST_FRAME"));
4583
4584    /* copying possibly altered fields back */
4585 #define SD_CPY(_field)             \
4586   do                               \
4587     {                              \
4588        sd->_field = tmp_sd._field; \
4589     } while (0)
4590
4591    SD_CPY(ee);
4592    SD_CPY(img_obj);
4593    SD_CPY(shot.info);
4594 #undef SD_CPY
4595
4596    if ((type != ELM_WIN_FAKE) && (trap) && (trap->add))
4597      sd->trap_data = trap->add(obj);
4598
4599    /* complementary actions, which depend on final smart data
4600     * pointer */
4601    if (type == ELM_WIN_INLINED_IMAGE)
4602      _win_inlined_image_set(sd);
4603 #ifdef HAVE_ELEMENTARY_X
4604    else if ((engine) &&
4605             ((!strcmp(engine, ELM_SOFTWARE_X11)) ||
4606              (!strcmp(engine, ELM_OPENGL_X11))))
4607      {
4608         sd->x.client_message_handler = ecore_event_handler_add
4609             (ECORE_X_EVENT_CLIENT_MESSAGE, _elm_win_client_message, obj);
4610         sd->x.property_handler = ecore_event_handler_add
4611             (ECORE_X_EVENT_WINDOW_PROPERTY, _elm_win_property_change, obj);
4612      }
4613 #endif
4614 #ifdef HAVE_ELEMENTARY_WAYLAND
4615    else if ((engine) &&
4616             ((!strcmp(engine, ELM_WAYLAND_SHM)) ||
4617              (!strcmp(engine, ELM_WAYLAND_EGL))))
4618      {
4619         sd->wl.effect_start_handler = ecore_event_handler_add
4620            (ECORE_WL_EVENT_EFFECT_START, _elm_win_wl_effect_start, obj);
4621         sd->wl.effect_end_handler = ecore_event_handler_add
4622            (ECORE_WL_EVENT_EFFECT_END, _elm_win_wl_effect_end, obj);
4623         // TIZEN_ONLY(20160801): indicator implementation
4624         sd->wl.indicator_flick_handler = ecore_event_handler_add
4625            (ECORE_WL_EVENT_INDICATOR_FLICK, _elm_win_wl_indicator_flick, obj);
4626         // END
4627         sd->wl.aux_msg_handler = ecore_event_handler_add
4628            (ECORE_WL_EVENT_AUX_MESSAGE, _elm_win_wl_aux_message, obj);
4629      }
4630 #endif
4631    else if ((engine) && (!strncmp(engine, "shot:", 5)))
4632      _shot_init(sd);
4633    //TIZEN_ONLY(20161121) tizen don't have canvas mouse up event like opensource now.
4634    //window should deal with mouse up event related with move resize.
4635    sd->mouse_up_handler = ecore_event_handler_add
4636       (ECORE_EVENT_MOUSE_BUTTON_UP, _elm_win_mouse_up, obj);
4637
4638    sd->kbdmode = ELM_WIN_KEYBOARD_UNKNOWN;
4639    sd->indmode = ELM_WIN_INDICATOR_UNKNOWN;
4640
4641 #ifdef HAVE_ELEMENTARY_X
4642    _internal_elm_win_xwindow_get(sd);
4643    if (sd->x.xwin)
4644      {
4645         ecore_x_io_error_handler_set(_elm_x_io_err, NULL);
4646      }
4647 #endif
4648
4649 #ifdef HAVE_ELEMENTARY_WAYLAND
4650    _elm_win_wlwindow_get(sd);
4651 #endif
4652
4653 #ifdef HAVE_ELEMENTARY_COCOA
4654    _elm_win_cocoawindow_get(sd);
4655 #endif
4656 #ifdef HAVE_ELEMENTARY_WIN32
4657    _internal_elm_win_win32window_get(sd);
4658 #endif
4659
4660    if ((_elm_config->bgpixmap)
4661 #ifdef HAVE_ELEMENTARY_X
4662        &&
4663        (((sd->x.xwin) && (!ecore_x_screen_is_composited(0))) ||
4664            (!sd->x.xwin)))
4665 #else
4666      )
4667 #endif
4668      TRAP(sd, avoid_damage_set, ECORE_EVAS_AVOID_DAMAGE_EXPOSE);
4669    // bg pixmap done by x - has other issues like can be redrawn by x before it
4670    // is filled/ready by app
4671    //     TRAP(sd, avoid_damage_set, ECORE_EVAS_AVOID_DAMAGE_BUILT_IN);
4672
4673    sd->type = type;
4674    sd->parent = parent;
4675    sd->modal_count = 0;
4676    sd->withdrawn = ecore_evas_withdrawn_get(sd->ee);
4677    sd->obscured = ecore_evas_obscured_get(sd->ee);
4678
4679    if (sd->parent)
4680      {
4681 #ifdef HAVE_ELEMENTARY_WAYLAND
4682         if ((sd->type >= ELM_WIN_BASIC) && (sd->type <= ELM_WIN_DND))
4683           ecore_wl_window_parent_set(sd->wl.win, elm_win_wl_window_get(sd->parent));
4684 #endif
4685         evas_object_event_callback_add
4686           (sd->parent, EVAS_CALLBACK_DEL, _elm_win_on_parent_del, obj);
4687      }
4688
4689 // TIZEN_ONLY(20161114): Sync the state of indicator with window manager
4690 #ifdef HAVE_ELEMENTARY_WAYLAND
4691    if (sd->wl.win)
4692      ecore_wl_indicator_visible_type_set(sd->wl.win, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN);
4693 #endif
4694 // END
4695
4696    sd->evas = ecore_evas_get(sd->ee);
4697
4698    evas_object_color_set(obj, 0, 0, 0, 0);
4699    evas_object_move(obj, 0, 0);
4700    evas_object_resize(obj, 1, 1);
4701    evas_object_pass_events_set(obj, EINA_TRUE);
4702
4703    if (type == ELM_WIN_INLINED_IMAGE)
4704      elm_widget_parent2_set(obj, parent);
4705
4706    /* use own version of ecore_evas_object_associate() that does TRAP() */
4707    ecore_evas_data_set(sd->ee, "elm_win", obj);
4708
4709    if (type != ELM_WIN_FAKE)
4710      {
4711         evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
4712            _elm_win_obj_callback_changed_size_hints, obj);
4713         evas_object_intercept_raise_callback_add
4714           (obj, _elm_win_obj_intercept_raise, obj);
4715         evas_object_intercept_lower_callback_add
4716           (obj, _elm_win_obj_intercept_lower, obj);
4717         evas_object_intercept_stack_above_callback_add
4718           (obj, _elm_win_obj_intercept_stack_above, obj);
4719         evas_object_intercept_stack_below_callback_add
4720           (obj, _elm_win_obj_intercept_stack_below, obj);
4721         evas_object_intercept_layer_set_callback_add
4722           (obj, _elm_win_obj_intercept_layer_set, obj);
4723         evas_object_intercept_show_callback_add
4724           (obj, _elm_win_obj_intercept_show, obj);
4725      }
4726
4727    TRAP(sd, name_class_set, name, _elm_appname);
4728    TRAP(sd, title_set, sd->title);
4729    ecore_evas_callback_delete_request_set(sd->ee, _elm_win_delete_request);
4730    ecore_evas_callback_state_change_set(sd->ee, _elm_win_state_change);
4731    ecore_evas_callback_focus_in_set(sd->ee, _elm_win_focus_in);
4732    ecore_evas_callback_focus_out_set(sd->ee, _elm_win_focus_out);
4733    ecore_evas_callback_resize_set(sd->ee, _elm_win_resize);
4734    ecore_evas_callback_move_set(sd->ee, _elm_win_move);
4735    if (type != ELM_WIN_FAKE)
4736      ecore_evas_callback_mouse_in_set(sd->ee, _elm_win_mouse_in);
4737    evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _elm_win_cb_hide, NULL);
4738    evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _elm_win_cb_show, NULL);
4739
4740    evas_image_cache_set(sd->evas, (_elm_config->image_cache * 1024));
4741    evas_font_cache_set(sd->evas, (_elm_config->font_cache * 1024));
4742
4743    EINA_LIST_FOREACH(_elm_config->font_dirs, l, fontpath)
4744      evas_font_path_append(sd->evas, fontpath);
4745
4746    if (!_elm_config->font_hinting)
4747      evas_font_hinting_set(sd->evas, EVAS_FONT_HINTING_NONE);
4748    else if (_elm_config->font_hinting == 1)
4749      evas_font_hinting_set(sd->evas, EVAS_FONT_HINTING_AUTO);
4750    else if (_elm_config->font_hinting == 2)
4751      evas_font_hinting_set(sd->evas, EVAS_FONT_HINTING_BYTECODE);
4752
4753    sd->wm_rot.wm_supported = ecore_evas_wm_rotation_supported_get(sd->ee);
4754    sd->wm_rot.preferred_rot = -1; // it means that elm_win doesn't use preferred rotation.
4755
4756 #ifdef HAVE_ELEMENTARY_X
4757    _elm_win_xwin_update(sd);
4758 #endif
4759 #ifdef HAVE_ELEMENTARY_WAYLAND
4760    _elm_win_wlwin_update(sd);
4761 #endif
4762
4763    /* do not append to list; all windows render as black rects */
4764
4765    sd->frame_style = eina_stringshare_add("default");
4766    if (type != ELM_WIN_FAKE)
4767      {
4768         _elm_win_list = eina_list_append(_elm_win_list, obj);
4769         _elm_win_count++;
4770
4771         if ((engine) && ((!strcmp(engine, ELM_SOFTWARE_FB)) || (!strcmp(engine, ELM_DRM))))
4772           {
4773              TRAP(sd, fullscreen_set, 1);
4774           }
4775         else if ((type != ELM_WIN_INLINED_IMAGE) &&
4776                  (!_elm_config->win_no_border) && //TIZEN_ONLY(20160601): In order to avoid creating unnecessary part.
4777                  ((engine) &&
4778                   ((!strcmp(engine, ELM_WAYLAND_SHM) ||
4779                    (!strcmp(engine, ELM_WAYLAND_EGL))))))
4780           _elm_win_frame_add(sd, sd->frame_style);
4781
4782         if (_elm_config->focus_highlight_enable)
4783           elm_win_focus_highlight_enabled_set(obj, EINA_TRUE);
4784         if (_elm_config->focus_highlight_animate)
4785           elm_win_focus_highlight_animate_set(obj, EINA_TRUE);
4786
4787         //Prohibiting auto-rendering, until elm_win is shown.
4788         if (_elm_config->auto_norender_withdrawn)
4789           {
4790              if (elm_win_withdrawn_get(obj))
4791                {
4792                   if (!evas_object_data_get(obj, "__win_auto_norender"))
4793                     {
4794                        elm_win_norender_push(obj);
4795                        evas_object_data_set(obj, "__win_auto_norender", obj);
4796                     }
4797                }
4798           }
4799      }
4800
4801 #ifdef ELM_DEBUG
4802    Evas_Modifier_Mask mask = evas_key_modifier_mask_get(sd->evas, "Control");
4803    evas_object_event_callback_add
4804      (obj, EVAS_CALLBACK_KEY_DOWN, _debug_key_down, NULL);
4805
4806    if (evas_object_key_grab(obj, "F12", mask, 0, EINA_TRUE))
4807      INF("Ctrl+F12 key combination exclusive for dot tree generation\n");
4808    else
4809      ERR("failed to grab F12 key to elm widgets (dot) tree generation");
4810 #endif
4811
4812    if (type != ELM_WIN_FAKE)
4813      {
4814         if ((_elm_config->softcursor_mode == ELM_SOFTCURSOR_MODE_ON) ||
4815             ((_elm_config->softcursor_mode == ELM_SOFTCURSOR_MODE_AUTO) &&
4816              ((engine) &&
4817               ((!strcmp(engine, ELM_SOFTWARE_FB)) || (!strcmp(engine, ELM_DRM))))))
4818           {
4819              Evas_Object *o;
4820              Evas_Coord mw = 1, mh = 1, hx = 0, hy = 0;
4821
4822              sd->pointer.obj = o = edje_object_add(ecore_evas_get(tmp_sd.ee));
4823              _elm_theme_object_set(obj, o, "pointer", "base", "default");
4824              edje_object_size_min_calc(o, &mw, &mh);
4825              evas_object_resize(o, mw, mh);
4826              edje_object_part_geometry_get(o, "elm.swallow.hotspot",
4827                                            &hx, &hy, NULL, NULL);
4828              sd->pointer.hot_x = hx;
4829              sd->pointer.hot_y = hy;
4830              evas_object_show(o);
4831              ecore_evas_object_cursor_set(tmp_sd.ee, o, EVAS_LAYER_MAX, hx, hy);
4832           }
4833         else if (_elm_config->softcursor_mode == ELM_SOFTCURSOR_MODE_OFF)
4834           {
4835              // do nothing
4836           }
4837      }
4838
4839    sd->edje = edje_object_add(sd->evas);
4840    _elm_win_theme_internal(obj, sd);
4841
4842    //TIZEN_ONLY(20161208): supported floating window
4843    if (type != ELM_WIN_BASIC)
4844      edje_object_signal_emit(sd->edje, "elm,state,floating,on", "elm");
4845    //
4846    sd->box = evas_object_box_add(sd->evas);
4847    evas_object_box_layout_set(sd->box, _window_layout_stack, obj, NULL);
4848    edje_object_part_swallow(sd->edje, "elm.swallow.contents", sd->box);
4849    evas_object_move(sd->edje, 0, 0);
4850    evas_object_resize(sd->edje, 1, 1);
4851    if (type != ELM_WIN_FAKE)
4852      {
4853         edje_object_update_hints_set(sd->edje, EINA_TRUE);
4854         evas_object_event_callback_add(sd->edje, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
4855                                        _elm_win_on_resize_obj_changed_size_hints, obj);
4856      }
4857
4858    eo_do(obj, elm_interface_atspi_accessible_role_set(ELM_ATSPI_ROLE_WINDOW));
4859    if (_elm_atspi_enabled())
4860      elm_interface_atspi_window_created_signal_emit(obj);
4861
4862    if(_elm_config->win_no_border)
4863      _elm_win_borderless_set(obj, sd, EINA_TRUE);
4864
4865    evas_object_show(sd->edje);
4866
4867    eo_do(obj, eo_event_callback_add(EO_EV_CALLBACK_ADD, _cb_added, sd),
4868          eo_event_callback_add(EO_EV_CALLBACK_DEL, _cb_deled, sd));
4869    if (type == ELM_WIN_FAKE)
4870      {
4871         _elm_win_resize_job(obj);
4872         _elm_win_move(sd->ee);
4873      }
4874
4875    /* TIZEN_ONLY(20160622): Apply paragraph direction when language is changed */
4876    if (!strcmp(E_("default:LTR"), "default:RTL"))
4877      evas_object_paragraph_direction_set(obj, EVAS_BIDI_DIRECTION_ANY_RTL);
4878    else
4879      evas_object_paragraph_direction_set(obj, EVAS_BIDI_DIRECTION_LTR);
4880    /* END */
4881
4882    return obj;
4883 }
4884
4885 EOLIAN static Eo *
4886 _elm_win_eo_base_finalize(Eo *obj, Elm_Win_Data *_pd)
4887 {
4888    obj = _elm_win_finalize_internal(obj, _pd, _pd->name, _pd->type);
4889    if (obj)
4890      {
4891         eo_do_super(obj, MY_CLASS, obj = eo_finalize());
4892      }
4893    return obj;
4894 }
4895
4896 EOLIAN static Eo *
4897 _elm_win_eo_base_constructor(Eo *obj, Elm_Win_Data *_pd EINA_UNUSED)
4898 {
4899    /* Do nothing. */
4900    /* XXX: We are calling the constructor chain from the finalizer. It's
4901     * really bad and hacky. Needs fixing. */
4902
4903    return obj;
4904 }
4905
4906 EOLIAN static void
4907 _elm_win_fake_canvas_set(Eo *obj EINA_UNUSED, Elm_Win_Data *pd, Ecore_Evas *oee)
4908 {
4909    pd->ee = oee;
4910 }
4911
4912 EOLIAN static void
4913 _elm_win_type_set(Eo *obj, Elm_Win_Data *sd, Elm_Win_Type type)
4914 {
4915    Eina_Bool finalized;
4916    if (eo_do_ret(obj, finalized, eo_finalized_get()))
4917      {
4918 // TIZEN_ONLY(20160720): Allowed changing type after initializing
4919 #ifdef HAVE_ELEMENTARY_WAYLAND
4920         sd->type = type;
4921         _elm_win_wlwin_update(sd);
4922         //TIZEN_ONLY(20161208): supported floating window
4923         if (type != ELM_WIN_BASIC)
4924           edje_object_signal_emit(sd->edje, "elm,state,floating,on", "elm");
4925         else
4926           edje_object_signal_emit(sd->edje, "elm,state,floating,off", "elm");
4927         //
4928 #endif
4929 //
4930         ERR("This function is only allowed during construction.");
4931         return;
4932      }
4933    sd->type = type;
4934 }
4935
4936 EOLIAN static Elm_Win_Type
4937 _elm_win_type_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
4938 {
4939    return sd->type;
4940 }
4941
4942 EOLIAN static void
4943 _elm_win_name_set(Eo *obj, Elm_Win_Data *sd, const char *name)
4944 {
4945    Eina_Bool finalized;
4946    if (eo_do_ret(obj, finalized, eo_finalized_get()))
4947      {
4948         ERR("This function is only allowed during construction.");
4949         return;
4950      }
4951    sd->name = eina_stringshare_add(name);
4952 }
4953
4954 EOLIAN static void
4955 _elm_win_noblank_set(Eo *obj EINA_UNUSED, Elm_Win_Data *pd, Eina_Bool noblank)
4956 {
4957    noblank = !!noblank;
4958    if (pd->noblank == noblank) return;
4959    pd->noblank = noblank;
4960    _win_noblank_eval();
4961 }
4962
4963 EOLIAN static Eina_Bool
4964 _elm_win_noblank_get(Eo *obj EINA_UNUSED, Elm_Win_Data *pd)
4965 {
4966    return pd->noblank;
4967 }
4968
4969 EOLIAN static void *
4970 _elm_win_trap_data_get(Eo *obj EINA_UNUSED, Elm_Win_Data *pd)
4971 {
4972    return pd->trap_data;
4973 }
4974
4975
4976 EAPI Evas_Object *
4977 elm_win_util_standard_add(const char *name, const char *title)
4978 {
4979    Evas_Object *win, *bg;
4980
4981    win = elm_win_add(NULL, name, ELM_WIN_BASIC);
4982    if (!win) return NULL;
4983
4984    elm_win_title_set(win, title);
4985    bg = elm_bg_add(win);
4986    if (!bg)
4987      {
4988         evas_object_del(win);
4989         return NULL;
4990      }
4991    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
4992    elm_win_resize_object_add(win, bg);
4993    evas_object_show(bg);
4994
4995    return win;
4996 }
4997
4998 EAPI Evas_Object *
4999 elm_win_util_dialog_add(Evas_Object *parent, const char *name, const char *title)
5000 {
5001    Evas_Object *win, *bg;
5002
5003    win = elm_win_add(parent, name, ELM_WIN_DIALOG_BASIC);
5004    if (!win) return NULL;
5005
5006    elm_win_title_set(win, title);
5007    bg = elm_bg_add(win);
5008    if (!bg)
5009      {
5010         evas_object_del(win);
5011         return NULL;
5012      }
5013    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
5014    elm_win_resize_object_add(win, bg);
5015    evas_object_show(bg);
5016
5017    return win;
5018 }
5019
5020 EOLIAN static void
5021 _elm_win_resize_object_add(Eo *obj, Elm_Win_Data *sd, Evas_Object *subobj)
5022 {
5023    elm_widget_sub_object_add(obj, subobj);
5024
5025    if (!evas_object_box_append(sd->box, subobj))
5026      ERR("could not append %p to box", subobj);
5027 }
5028
5029 EOLIAN static void
5030 _elm_win_resize_object_del(Eo *obj, Elm_Win_Data *sd, Evas_Object *subobj)
5031 {
5032    if (!elm_widget_sub_object_del(obj, subobj))
5033      ERR("could not remove sub object %p from %p", subobj, obj);
5034
5035    evas_object_box_remove(sd->box, subobj);
5036 }
5037
5038 // TIZEN_ONLY(20170212): pend rotation until app set rotation
5039
5040 /* Efl don't have any plan to open new API to support the client rotation.(ex: elm_win_rotation_set)
5041  * But it is need that apps deal with rotation
5042  * For example, if the app want to do the object rotation effect during the rotation,
5043  * canvas should not be rotated until app's rotation effect ends.
5044  * so until to decide app's rotaion policy,
5045  * just use the "wm.policy.win.rot.render.nopending" aux_hint.
5046  * Using this hint, elm- ecore_evas - engine -tizen display server will manage the pending rotation.
5047 */
5048
5049 static int
5050 _elm_win_wm_pending_rotation_set(Evas_Object *obj EINA_UNUSED, const char *hint EINA_UNUSED, const char *val)
5051 {
5052    ELM_WIN_CHECK(obj) -1;
5053    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
5054
5055    int id = -1;
5056
5057    //TODO: aux_hint_del, aux_hint_val_set.
5058    //Currently only 1 is available.
5059
5060    if (!val || (strncmp(val, "1", 1))) return -1;
5061    id = ecore_evas_aux_hint_add(sd->ee, "wm.policy.win.rot.render.nopending", val);
5062
5063    if (id == -1)
5064      {
5065         ERR("PendingRotation: elm_win pending_rotation_set aux id failed");
5066         //return id;
5067      }
5068    sd->wm_rot.rotation_pending = EINA_TRUE;
5069    DBG("PendingRotation: elm_win rotation_pending_set sucess");
5070    return id;
5071 }
5072 //
5073
5074 EOLIAN static void
5075 _elm_win_title_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *title)
5076 {
5077    if (!title) return;
5078    eina_stringshare_replace(&(sd->title), title);
5079    if (sd->ee)
5080      TRAP(sd, title_set, sd->title);
5081    if (sd->frame_obj)
5082      edje_object_part_text_escaped_set
5083        (sd->frame_obj, "elm.text.title", sd->title);
5084 }
5085
5086 EOLIAN static const char*
5087 _elm_win_title_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5088 {
5089    return sd->title;
5090 }
5091
5092 EOLIAN static void
5093 _elm_win_icon_name_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *icon_name)
5094 {
5095    if (!icon_name) return;
5096    eina_stringshare_replace(&(sd->icon_name), icon_name);
5097 #ifdef HAVE_ELEMENTARY_X
5098    _elm_win_xwin_update(sd);
5099 #endif
5100 }
5101
5102 EOLIAN static const char*
5103 _elm_win_icon_name_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5104 {
5105    return sd->icon_name;
5106 }
5107
5108 EOLIAN static void
5109 _elm_win_role_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *role)
5110 {
5111    if (!role) return;
5112    eina_stringshare_replace(&(sd->role), role);
5113 #ifdef HAVE_ELEMENTARY_X
5114    _elm_win_xwin_update(sd);
5115 #endif
5116 #ifdef HAVE_ELEMENTARY_WAYLAND
5117    ecore_wl_window_role_set(sd->wl.win, role);
5118 #endif
5119 }
5120
5121 EOLIAN static const char*
5122 _elm_win_role_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5123 {
5124    return sd->role;
5125 }
5126
5127 EOLIAN static void
5128 _elm_win_icon_object_set(Eo *obj, Elm_Win_Data *sd, Evas_Object *icon)
5129 {
5130    if (sd->icon)
5131      evas_object_event_callback_del_full(sd->icon, EVAS_CALLBACK_DEL,
5132        _elm_win_on_icon_del, obj);
5133    evas_object_del(sd->icon);
5134    sd->icon = icon;
5135    if (sd->icon)
5136      {
5137         evas_object_event_callback_add(sd->icon, EVAS_CALLBACK_DEL,
5138           _elm_win_on_icon_del, obj);
5139         if (sd->frame_obj)
5140           edje_object_part_swallow(sd->frame_obj, "elm.swallow.icon", sd->icon);
5141      }
5142 #ifdef HAVE_ELEMENTARY_X
5143    _elm_win_xwin_update(sd);
5144 //TIZEN_ONLY(160628): To support an app window icon on SDK UI Tools.
5145 #elif HAVE_ELEMENTARY_WIN32
5146    const char *path;
5147    elm_image_file_get(icon, &path, NULL);
5148    ecore_win32_window_icon_set(ecore_evas_win32_window_get(sd->ee), path);
5149 #endif
5150 }
5151
5152 EOLIAN static const Evas_Object*
5153 _elm_win_icon_object_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5154 {
5155    return sd->icon;
5156 }
5157
5158 EOLIAN static void
5159 _elm_win_autodel_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool autodel)
5160 {
5161    sd->autodel = autodel;
5162 }
5163
5164 EOLIAN static Eina_Bool
5165 _elm_win_autodel_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5166 {
5167    return sd->autodel;
5168 }
5169
5170 EOLIAN static void
5171 _elm_win_autohide_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool autohide)
5172 {
5173    sd->autohide = autohide;
5174 }
5175
5176 EOLIAN static Eina_Bool
5177 _elm_win_autohide_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5178 {
5179    return sd->autohide;
5180 }
5181
5182 EOLIAN static void
5183 _elm_win_activate(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5184 {
5185    TRAP(sd, activate);
5186 }
5187
5188 EOLIAN static void
5189 _elm_win_lower(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5190 {
5191    TRAP(sd, lower);
5192 }
5193
5194 EOLIAN static void
5195 _elm_win_raise(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5196 {
5197    TRAP(sd, raise);
5198 }
5199
5200 EOLIAN static void
5201 _elm_win_center(Eo *obj, Elm_Win_Data *sd, Eina_Bool h, Eina_Bool v)
5202 {
5203    int win_w, win_h, screen_w, screen_h, nx, ny;
5204
5205    if ((trap) && (trap->center) && (!trap->center(sd->trap_data, obj, h, v)))
5206      return;
5207
5208    ecore_evas_screen_geometry_get(sd->ee, NULL, NULL, &screen_w, &screen_h);
5209    if ((!screen_w) || (!screen_h)) return;
5210
5211    evas_object_geometry_get(obj, &nx, &ny, &win_w, &win_h);
5212    if ((!win_w) || (!win_h)) return;
5213
5214    if (h) nx = win_w >= screen_w ? 0 : (screen_w / 2) - (win_w / 2);
5215    if (v) ny = win_h >= screen_h ? 0 : (screen_h / 2) - (win_h / 2);
5216    if (nx < sd->screen.x) nx = sd->screen.x;
5217    if (ny < sd->screen.y) ny = sd->screen.y;
5218
5219    evas_object_move(obj, nx, ny);
5220 }
5221
5222 EOLIAN static void
5223 _elm_win_borderless_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool borderless)
5224 {
5225    const char *engine_name = ecore_evas_engine_name_get(sd->ee);
5226    Eina_Bool need_frame = engine_name &&
5227                           ((!strcmp(engine_name, ELM_WAYLAND_SHM)) ||
5228                            (!strcmp(engine_name, ELM_WAYLAND_EGL)));
5229
5230    if (need_frame)
5231      need_frame = !sd->fullscreen;
5232
5233    if (borderless)
5234      {
5235         if (need_frame)
5236           _elm_win_frame_del(sd);
5237      }
5238    else
5239      {
5240         if (need_frame)
5241           _elm_win_frame_add(sd, sd->frame_style);
5242
5243         if (sd->frame_obj)
5244           evas_object_show(sd->frame_obj);
5245      }
5246
5247    sd->borderless = borderless;
5248
5249    TRAP(sd, borderless_set, borderless);
5250 #ifdef HAVE_ELEMENTARY_X
5251    _elm_win_xwin_update(sd);
5252 #endif
5253 }
5254
5255 EOLIAN static Eina_Bool
5256 _elm_win_borderless_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5257 {
5258    return ecore_evas_borderless_get(sd->ee);
5259 }
5260
5261 EOLIAN static void
5262 _elm_win_border_style_set(Eo *obj, Elm_Win_Data *sd, const char *style)
5263 {
5264    Elm_Theme *theme;
5265    char buf[1024];
5266
5267    if (!style) return;
5268    if (!strcmp(sd->frame_style, style))
5269      return;
5270
5271    theme = elm_widget_theme_get(obj);
5272    if (!theme) theme = elm_theme_default_get();
5273    if (theme)
5274      {
5275         snprintf(buf, sizeof(buf), "elm/border/base/%s", style);
5276         if (!elm_theme_group_path_find(theme, buf))
5277           return;
5278      }
5279
5280    eina_stringshare_replace(&(sd->frame_style), style);
5281
5282    if (sd->frame_obj)
5283      {
5284         _elm_win_frame_del(sd);
5285         _elm_win_frame_add(sd, sd->frame_style);
5286
5287         if (sd->frame_obj)
5288           evas_object_show(sd->frame_obj);
5289      }
5290 }
5291
5292 EOLIAN static const char*
5293 _elm_win_border_style_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5294 {
5295    return sd->frame_style;
5296 }
5297
5298 EOLIAN static void
5299 _elm_win_shaped_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool shaped)
5300 {
5301    TRAP(sd, shaped_set, shaped);
5302 #ifdef HAVE_ELEMENTARY_X
5303    _elm_win_xwin_update(sd);
5304 #endif
5305 }
5306
5307 EOLIAN static Eina_Bool
5308 _elm_win_shaped_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5309 {
5310    return ecore_evas_shaped_get(sd->ee);
5311 }
5312
5313 EOLIAN static void
5314 _elm_win_alpha_set(Eo *obj, Elm_Win_Data *sd, Eina_Bool enabled)
5315 {
5316    sd->application_alpha = enabled;
5317    _elm_win_apply_alpha(obj, sd);
5318 }
5319
5320 EOLIAN static Eina_Bool
5321 _elm_win_alpha_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5322 {
5323    if (sd->img_obj)
5324      {
5325         return evas_object_image_alpha_get(sd->img_obj);
5326      }
5327    else
5328      {
5329         return ecore_evas_alpha_get(sd->ee);
5330      }
5331
5332    return EINA_FALSE;
5333 }
5334
5335 EOLIAN static void
5336 _elm_win_override_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool override)
5337 {
5338    TRAP(sd, override_set, override);
5339 #ifdef HAVE_ELEMENTARY_X
5340    _elm_win_xwin_update(sd);
5341 #endif
5342 }
5343
5344 EOLIAN static Eina_Bool
5345 _elm_win_override_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5346 {
5347    return ecore_evas_override_get(sd->ee);
5348 }
5349
5350 EOLIAN static void
5351 _elm_win_fullscreen_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool fullscreen)
5352 {
5353    const char *engine_name = ecore_evas_engine_name_get(sd->ee);
5354    // YYY: handle if sd->img_obj
5355    if (engine_name &&
5356        ((!strcmp(engine_name, ELM_SOFTWARE_FB)) ||
5357         (!strcmp(engine_name, ELM_DRM))))
5358      {
5359         // these engines... can ONLY be fullscreen
5360         return;
5361      }
5362    else if (sd->type == ELM_WIN_FAKE)
5363      sd->fullscreen = !!fullscreen;
5364    else
5365      {
5366 //        sd->fullscreen = fullscreen;
5367         Eina_Bool need_frame = engine_name &&
5368                                ((!strcmp(engine_name, ELM_WAYLAND_SHM)) ||
5369                                 (!strcmp(engine_name, ELM_WAYLAND_EGL)));
5370
5371         if (need_frame)
5372           need_frame = !ecore_evas_borderless_get(sd->ee);
5373
5374         TRAP(sd, fullscreen_set, fullscreen);
5375
5376         if (fullscreen)
5377           {
5378              if (need_frame)
5379                _elm_win_frame_del(sd);
5380           }
5381         else
5382           {
5383              if (need_frame)
5384                _elm_win_frame_add(sd, sd->frame_style);
5385
5386              if (sd->frame_obj)
5387                evas_object_show(sd->frame_obj);
5388           }
5389 #ifdef HAVE_ELEMENTARY_X
5390         _elm_win_xwin_update(sd);
5391 #endif
5392      }
5393 }
5394
5395 EOLIAN static Eina_Bool
5396 _elm_win_fullscreen_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5397 {
5398    const char *engine_name = ecore_evas_engine_name_get(sd->ee);
5399
5400    if (engine_name &&
5401        ((!strcmp(engine_name, ELM_SOFTWARE_FB)) ||
5402         (!strcmp(engine_name, ELM_DRM))))
5403      {
5404         // these engines... can ONLY be fullscreen
5405         return EINA_TRUE;
5406      }
5407    return sd->fullscreen;
5408 }
5409
5410 static void
5411 _dbus_menu_set(Eina_Bool dbus_connect, void *data)
5412 {
5413    ELM_WIN_DATA_GET_OR_RETURN(data, sd);
5414
5415    if (dbus_connect)
5416      {
5417         DBG("Setting menu to D-Bus");
5418         edje_object_part_unswallow(sd->edje, sd->main_menu);
5419         edje_object_signal_emit(sd->edje, "elm,action,hide_menu", "elm");
5420         _elm_menu_menu_bar_hide(sd->main_menu);
5421      }
5422    else
5423      {
5424         DBG("Setting menu to local mode");
5425         edje_object_part_swallow(sd->edje, "elm.swallow.menu", sd->main_menu);
5426         edje_object_signal_emit(sd->edje, "elm,action,show_menu", "elm");
5427         evas_object_show(sd->main_menu);
5428      }
5429 }
5430
5431 EOLIAN static Evas_Object *
5432 _elm_win_main_menu_get(Eo *obj, Elm_Win_Data *sd)
5433 {
5434    if (sd->main_menu) goto end;
5435
5436    sd->main_menu = elm_menu_add(obj);
5437    _elm_menu_menu_bar_set(sd->main_menu, EINA_TRUE);
5438
5439 #ifdef HAVE_ELEMENTARY_X
5440    Eina_Bool use_dbus = EINA_FALSE;
5441
5442    if (!_elm_config->disable_external_menu && sd->x.xwin) use_dbus = EINA_TRUE;
5443
5444    if (use_dbus && _elm_dbus_menu_register(sd->main_menu))
5445      {
5446         _elm_dbus_menu_app_menu_register(sd->x.xwin, sd->main_menu,
5447                                          _dbus_menu_set, obj);
5448      }
5449    else
5450 #endif
5451      _dbus_menu_set(EINA_FALSE, obj);
5452
5453 end:
5454    return sd->main_menu;
5455 }
5456
5457 EOLIAN static void
5458 _elm_win_maximized_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool maximized)
5459 {
5460    _elm_win_frame_maximized_state_update(sd, maximized);
5461    // YYY: handle if sd->img_obj
5462    TRAP(sd, maximized_set, maximized);
5463 #ifdef HAVE_ELEMENTARY_X
5464    _elm_win_xwin_update(sd);
5465 #endif
5466 }
5467
5468 EOLIAN static Eina_Bool
5469 _elm_win_maximized_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5470 {
5471    return sd->maximized;
5472 }
5473
5474 EOLIAN static void
5475 _elm_win_iconified_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool iconified)
5476 {
5477 //   sd->iconified = iconified;
5478    TRAP(sd, iconified_set, iconified);
5479 #ifdef HAVE_ELEMENTARY_X
5480    _elm_win_xwin_update(sd);
5481 #endif
5482 }
5483
5484 EOLIAN static Eina_Bool
5485 _elm_win_iconified_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5486 {
5487    return sd->iconified;
5488 }
5489
5490 EOLIAN static void
5491 _elm_win_withdrawn_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool withdrawn)
5492 {
5493 //   sd->withdrawn = withdrawn;
5494    TRAP(sd, withdrawn_set, withdrawn);
5495 #ifdef HAVE_ELEMENTARY_X
5496    _elm_win_xwin_update(sd);
5497 #endif
5498 }
5499
5500 EOLIAN static Eina_Bool
5501 _elm_win_withdrawn_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5502 {
5503    return sd->withdrawn;
5504 }
5505
5506 EOLIAN static void
5507 _elm_win_available_profiles_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char **profiles, unsigned int count)
5508 {
5509    Eina_Bool found = EINA_FALSE;
5510
5511    _elm_win_available_profiles_del(sd);
5512    if ((profiles) && (count >= 1))
5513      {
5514         sd->profile.available_list = calloc(count, sizeof(char *));
5515         if (sd->profile.available_list)
5516           {
5517              if (!sd->profile.name) found = EINA_TRUE;
5518
5519              unsigned int i;
5520              for (i = 0; i < count; i++)
5521                {
5522                   sd->profile.available_list[i] = eina_stringshare_add(profiles[i]);
5523
5524                   /* check to see if a given array has a current profile of elm_win */
5525                   if ((sd->profile.name) &&
5526                       (!strcmp(sd->profile.name, profiles[i])))
5527                     {
5528                        found = EINA_TRUE;
5529                     }
5530                }
5531              sd->profile.count = count;
5532           }
5533      }
5534
5535    if (ecore_evas_window_profile_supported_get(sd->ee))
5536      {
5537         ecore_evas_window_available_profiles_set(sd->ee,
5538                                                  sd->profile.available_list,
5539                                                  sd->profile.count);
5540
5541         /* current profile of elm_win is wrong, change profile */
5542         if ((sd->profile.available_list) && (!found))
5543           {
5544              eina_stringshare_replace(&(sd->profile.name),
5545                                       sd->profile.available_list[0]);
5546              ecore_evas_window_profile_set(sd->ee, sd->profile.name);
5547           }
5548
5549      }
5550    else
5551      {
5552         if (sd->profile.available_list)
5553           _elm_win_profile_update(sd);
5554      }
5555 }
5556
5557 EOLIAN static Eina_Bool
5558 _elm_win_available_profiles_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, char ***profiles, unsigned int *count)
5559 {
5560    if (ecore_evas_window_profile_supported_get(sd->ee))
5561      {
5562         return ecore_evas_window_available_profiles_get(sd->ee,
5563                                                        profiles,
5564                                                        count);
5565      }
5566    else
5567      {
5568         if (profiles) *profiles = (char **)sd->profile.available_list;
5569         if (count) *count = sd->profile.count;
5570         return EINA_TRUE;
5571      }
5572 }
5573
5574 EOLIAN static void
5575 _elm_win_profile_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *profile)
5576 {
5577    /* check to see if a given profile is present in an available profiles */
5578    if ((profile) && (sd->profile.available_list))
5579      {
5580         Eina_Bool found = EINA_FALSE;
5581         unsigned int i;
5582         for (i = 0; i < sd->profile.count; i++)
5583           {
5584              if (!strcmp(profile,
5585                          sd->profile.available_list[i]))
5586                {
5587                   found = EINA_TRUE;
5588                   break;
5589                }
5590           }
5591         if (!found) return;
5592      }
5593
5594    if (ecore_evas_window_profile_supported_get(sd->ee))
5595      {
5596         if (!profile) _elm_win_profile_del(sd);
5597         ecore_evas_window_profile_set(sd->ee, profile);
5598      }
5599    else
5600      {
5601         if (_internal_elm_win_profile_set(sd, profile))
5602           _elm_win_profile_update(sd);
5603      }
5604 }
5605
5606 EOLIAN static const char*
5607 _elm_win_profile_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5608 {
5609    return sd->profile.name;
5610 }
5611
5612 EOLIAN static void
5613 _elm_win_urgent_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool urgent)
5614 {
5615    if (sd->urgent == urgent)
5616      return;
5617    sd->urgent = urgent;
5618    TRAP(sd, urgent_set, urgent);
5619 #ifdef HAVE_ELEMENTARY_X
5620    _elm_win_xwin_update(sd);
5621 #endif
5622 }
5623
5624 EOLIAN static Eina_Bool
5625 _elm_win_urgent_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5626 {
5627    return sd->urgent;
5628 }
5629
5630 EOLIAN static void
5631 _elm_win_demand_attention_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool demand_attention)
5632 {
5633    sd->demand_attention = demand_attention;
5634    TRAP(sd, demand_attention_set, demand_attention);
5635 #ifdef HAVE_ELEMENTARY_X
5636    _elm_win_xwin_update(sd);
5637 #endif
5638 }
5639
5640 EOLIAN static Eina_Bool
5641 _elm_win_demand_attention_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5642 {
5643    return sd->demand_attention;
5644 }
5645
5646 EOLIAN static void
5647 _elm_win_modal_set(Eo *obj, Elm_Win_Data *sd, Eina_Bool modal)
5648 {
5649    if (sd->modal_count) return;
5650
5651    const Eina_List *l;
5652    Evas_Object *current;
5653
5654    if ((modal) && (!sd->modal) && (evas_object_visible_get(obj)))
5655      {
5656        INCREMENT_MODALITY()
5657      }
5658    else if ((!modal) && (sd->modal) && (evas_object_visible_get(obj)))
5659      {
5660        DECREMENT_MODALITY()
5661      }
5662
5663    sd->modal = modal;
5664    TRAP(sd, modal_set, modal);
5665 #ifdef HAVE_ELEMENTARY_X
5666    _elm_win_xwin_update(sd);
5667 #endif
5668 }
5669
5670 EOLIAN static Eina_Bool
5671 _elm_win_modal_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5672 {
5673    return sd->modal;
5674 }
5675
5676 EOLIAN static void
5677 _elm_win_aspect_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, double aspect)
5678 {
5679    sd->aspect = aspect;
5680    TRAP(sd, aspect_set, aspect);
5681 #ifdef HAVE_ELEMENTARY_X
5682    _elm_win_xwin_update(sd);
5683 #endif
5684 }
5685
5686 EOLIAN static double
5687 _elm_win_aspect_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5688 {
5689    return sd->aspect;
5690 }
5691
5692 EOLIAN static void
5693 _elm_win_size_base_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int w, int h)
5694 {
5695    sd->size_base_w = w;
5696    sd->size_base_h = h;
5697    TRAP(sd, size_base_set, w, h);
5698 #ifdef HAVE_ELEMENTARY_X
5699    _elm_win_xwin_update(sd);
5700 #endif
5701 }
5702
5703 EOLIAN static void
5704 _elm_win_size_base_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int *w, int *h)
5705 {
5706    if (w) *w = sd->size_base_w;
5707    if (h) *h = sd->size_base_h;
5708 }
5709
5710 EOLIAN static void
5711 _elm_win_size_step_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int w, int h)
5712 {
5713    sd->size_step_w = w;
5714    sd->size_step_h = h;
5715    TRAP(sd, size_step_set, w, h);
5716 #ifdef HAVE_ELEMENTARY_X
5717    _elm_win_xwin_update(sd);
5718 #endif
5719 }
5720
5721 EOLIAN static void
5722 _elm_win_size_step_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int *w, int *h)
5723 {
5724    if (w) *w = sd->size_step_w;
5725    if (h) *h = sd->size_step_h;
5726 }
5727
5728 EOLIAN static void
5729 _elm_win_layer_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int layer)
5730 {
5731    TRAP(sd, layer_set, layer);
5732 #ifdef HAVE_ELEMENTARY_X
5733    _elm_win_xwin_update(sd);
5734 #endif
5735 }
5736
5737 EOLIAN static int
5738 _elm_win_layer_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5739 {
5740    return ecore_evas_layer_get(sd->ee);
5741 }
5742
5743 EAPI void
5744 elm_win_norender_push(Evas_Object *obj)
5745 {
5746    ELM_WIN_CHECK(obj);
5747    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
5748
5749    sd->norender++;
5750    if (sd->norender == 1) ecore_evas_manual_render_set(sd->ee, EINA_TRUE);
5751 }
5752
5753 EAPI void
5754 elm_win_norender_pop(Evas_Object *obj)
5755 {
5756    ELM_WIN_CHECK(obj);
5757    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
5758
5759    if (sd->norender <= 0) return;
5760    sd->norender--;
5761    if (sd->norender == 0) ecore_evas_manual_render_set(sd->ee, EINA_FALSE);
5762 }
5763
5764 EAPI int
5765 elm_win_norender_get(const Evas_Object *obj)
5766 {
5767    ELM_WIN_CHECK(obj) - 1;
5768    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
5769    return sd->norender;
5770 }
5771
5772 EAPI void
5773 elm_win_render(Evas_Object *obj)
5774 {
5775    ELM_WIN_CHECK(obj);
5776    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
5777    ecore_evas_manual_render(sd->ee);
5778 }
5779
5780 static int
5781 _win_rotation_degree_check(int rotation)
5782 {
5783    if ((rotation > 360) || (rotation < 0))
5784      {
5785         WRN("Rotation degree should be 0 ~ 360 (passed degree: %d)", rotation);
5786         rotation %= 360;
5787         if (rotation < 0) rotation += 360;
5788      }
5789    return rotation;
5790 }
5791
5792 // TIZEN_ONLY(20170212): pend rotation until app set rotation
5793 /*
5794  * This API rotates the window by app side.
5795  */
5796
5797 static void
5798 _win_pending_rotate(Evas_Object *obj EINA_UNUSED, Elm_Win_Data *sd, int rotation, Eina_Bool resize)
5799 {
5800    rotation = _win_rotation_degree_check(rotation);
5801    DBG("PendingRotation: elm_win pending rotation set rot=%d", rotation);
5802    if (sd->rot == rotation) return;
5803
5804    //TODO: We need time to set up the role of pending rotation between the server and client.
5805    //and also need time to discuss this concept with opensource.
5806    //so until that time, we add ecore evas data instead of opening the new ecore_evas_XXX api.
5807    ecore_evas_data_set(sd->ee, "pending_rotation", (void *)1);
5808
5809    // Currently only support rotation_with_resize
5810    if (resize) TRAP(sd, rotation_with_resize_set, rotation);
5811    else return;
5812 }
5813 //
5814
5815 /*
5816  * This API resizes the internal window(ex: X window) and evas_output.
5817  * But this does not resize the elm window object and its contents.
5818  */
5819 static void
5820 _win_rotate(Evas_Object *obj, Elm_Win_Data *sd, int rotation, Eina_Bool resize)
5821 {
5822    rotation = _win_rotation_degree_check(rotation);
5823    if (sd->rot == rotation) return;
5824    sd->rot = rotation;
5825    if (resize) TRAP(sd, rotation_with_resize_set, rotation);
5826    else TRAP(sd, rotation_set, rotation);
5827    evas_object_size_hint_min_set(obj, -1, -1);
5828    evas_object_size_hint_max_set(obj, -1, -1);
5829    _elm_win_resize_objects_eval(obj);
5830 #ifdef HAVE_ELEMENTARY_X
5831    _elm_win_xwin_update(sd);
5832 #endif
5833    _elm_win_frame_obj_update(sd);
5834    elm_widget_orientation_set(obj, rotation);
5835    eo_do(obj, eo_event_callback_call
5836      (ELM_WIN_EVENT_ROTATION_CHANGED, NULL));
5837    //TIZEN_ONLY(20160915): send information to screen reader on window rotation.
5838    if (_elm_atspi_enabled())
5839      {
5840         Evas_Coord width = 0, height = 0;
5841         elm_win_screen_size_get(obj, NULL, NULL, &width, &height);
5842         if ((sd->rot == 0) || (sd->rot == 180))
5843           {
5844              elm_interface_atspi_accessible_bounds_changed_signal_emit(obj, 0, 0, width, height);
5845           }
5846         else
5847           {
5848              elm_interface_atspi_accessible_bounds_changed_signal_emit(obj, 0, 0, height, width);
5849           }
5850      }
5851      //
5852 }
5853
5854 EOLIAN static void
5855 _elm_win_rotation_set(Eo *obj, Elm_Win_Data *sd, int rotation)
5856 {
5857    _win_rotate(obj, sd, rotation, EINA_FALSE);
5858 }
5859
5860 /*
5861  * This API does not resize the internal window (ex: X window).
5862  * But this resizes evas_output, elm window, and its contents.
5863  */
5864 EOLIAN static void
5865 _elm_win_rotation_with_resize_set(Eo *obj, Elm_Win_Data *sd, int rotation)
5866 {
5867 // TIZEN_ONLY(20170212): pend rotation until app set rotation
5868    if (sd->wm_rot.rotation_pending)
5869      {
5870         _win_pending_rotate(obj, sd, rotation, EINA_TRUE);
5871      }
5872    else
5873 //
5874      _win_rotate(obj, sd, rotation, EINA_TRUE);
5875 }
5876
5877 EOLIAN static int
5878 _elm_win_rotation_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5879 {
5880    return sd->rot;
5881 }
5882
5883 EOLIAN static Eina_Bool
5884 _elm_win_wm_rotation_supported_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5885 {
5886    return sd->wm_rot.wm_supported;
5887 }
5888
5889 /* This will unset a preferred rotation, if given preferred rotation is '-1'.
5890  */
5891 EAPI void
5892 elm_win_wm_rotation_preferred_rotation_set(const Evas_Object *obj,
5893                                            int rotation)
5894 {
5895    ELM_WIN_CHECK(obj);
5896    eo_do((Eo *) obj, elm_obj_win_wm_preferred_rotation_set(rotation));
5897 }
5898
5899 EOLIAN static void
5900 _elm_win_wm_preferred_rotation_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int rotation)
5901 {
5902    int rot;
5903
5904    if (!sd->wm_rot.use)
5905      sd->wm_rot.use = EINA_TRUE;
5906
5907    // '-1' means that elm_win doesn't use preferred rotation.
5908    if (rotation == -1)
5909      rot = -1;
5910    else
5911      rot = _win_rotation_degree_check(rotation);
5912
5913    if (sd->wm_rot.preferred_rot == rot) return;
5914    sd->wm_rot.preferred_rot = rot;
5915
5916    ecore_evas_wm_rotation_preferred_rotation_set(sd->ee, rot);
5917 }
5918
5919 EOLIAN static int
5920 _elm_win_wm_preferred_rotation_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5921 {
5922    return sd->wm_rot.preferred_rot;
5923 }
5924
5925 EOLIAN static void
5926 _elm_win_wm_available_rotations_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const int *rotations, unsigned int count)
5927 {
5928    unsigned int i;
5929    int r;
5930
5931    if (!sd->wm_rot.use)
5932      sd->wm_rot.use = EINA_TRUE;
5933
5934    ELM_SAFE_FREE(sd->wm_rot.rots, free);
5935    sd->wm_rot.count = 0;
5936
5937    if (count > 0)
5938      {
5939         sd->wm_rot.rots = calloc(count, sizeof(int));
5940         if (!sd->wm_rot.rots) return;
5941         for (i = 0; i < count; i++)
5942           {
5943              r = _win_rotation_degree_check(rotations[i]);
5944              sd->wm_rot.rots[i] = r;
5945           }
5946      }
5947
5948    sd->wm_rot.count = count;
5949
5950    ecore_evas_wm_rotation_available_rotations_set(sd->ee,
5951                                                   sd->wm_rot.rots,
5952                                                   sd->wm_rot.count);
5953 }
5954
5955 EOLIAN static Eina_Bool
5956 _elm_win_wm_available_rotations_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int **rotations, unsigned int *count)
5957 {
5958    if (!sd->wm_rot.use) return EINA_FALSE;
5959
5960    if (sd->wm_rot.count > 0)
5961      {
5962         if (rotations)
5963           {
5964              *rotations = calloc(sd->wm_rot.count, sizeof(int));
5965              if (*rotations)
5966                {
5967                   memcpy(*rotations,
5968                          sd->wm_rot.rots,
5969                          sizeof(int) * sd->wm_rot.count);
5970                }
5971           }
5972      }
5973
5974    if (count) *count = sd->wm_rot.count;
5975    return EINA_TRUE;
5976 }
5977
5978 EOLIAN static void
5979 _elm_win_wm_manual_rotation_done_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool set)
5980 {
5981    if (!sd->wm_rot.use) return;
5982    ecore_evas_wm_rotation_manual_rotation_done_set(sd->ee, set);
5983 }
5984
5985 EOLIAN static Eina_Bool
5986 _elm_win_wm_manual_rotation_done_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5987 {
5988    if (!sd->wm_rot.use) return EINA_FALSE;
5989    return ecore_evas_wm_rotation_manual_rotation_done_get(sd->ee);
5990 }
5991
5992 EOLIAN static void
5993 _elm_win_wm_manual_rotation_done_manual(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
5994 {
5995    if (!sd->wm_rot.use) return;
5996    ecore_evas_wm_rotation_manual_rotation_done(sd->ee);
5997 }
5998
5999 EOLIAN static void
6000 _elm_win_sticky_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool sticky)
6001 {
6002 //   sd->sticky = sticky;
6003    TRAP(sd, sticky_set, sticky);
6004 #ifdef HAVE_ELEMENTARY_X
6005    _elm_win_xwin_update(sd);
6006 #endif
6007 }
6008
6009 EOLIAN static Eina_Bool
6010 _elm_win_sticky_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6011 {
6012    return sd->sticky;
6013 }
6014
6015 EOLIAN static void
6016 _elm_win_keyboard_mode_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Elm_Win_Keyboard_Mode mode)
6017 {
6018    if (mode == sd->kbdmode) return;
6019 #ifdef HAVE_ELEMENTARY_X
6020    _internal_elm_win_xwindow_get(sd);
6021 #endif
6022    sd->kbdmode = mode;
6023 #ifdef HAVE_ELEMENTARY_X
6024    if (sd->x.xwin)
6025      ecore_x_e_virtual_keyboard_state_set
6026        (sd->x.xwin, (Ecore_X_Virtual_Keyboard_State)sd->kbdmode);
6027 #endif
6028 }
6029
6030 EOLIAN static Elm_Win_Keyboard_Mode
6031 _elm_win_keyboard_mode_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6032 {
6033    return sd->kbdmode;
6034 }
6035
6036 EOLIAN static void
6037 _elm_win_keyboard_win_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool is_keyboard)
6038 {
6039 #ifdef HAVE_ELEMENTARY_X
6040    _internal_elm_win_xwindow_get(sd);
6041    if (sd->x.xwin)
6042      ecore_x_e_virtual_keyboard_set(sd->x.xwin, is_keyboard);
6043 #else
6044    (void)is_keyboard;
6045    (void)sd;
6046 #endif
6047 }
6048
6049 EOLIAN static Eina_Bool
6050 _elm_win_keyboard_win_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6051 {
6052 #ifdef HAVE_ELEMENTARY_X
6053    _internal_elm_win_xwindow_get(sd);
6054    if (sd->x.xwin) return ecore_x_e_virtual_keyboard_get(sd->x.xwin);
6055 #else
6056    (void)sd;
6057 #endif
6058    return EINA_FALSE;
6059 }
6060
6061 EOLIAN static void
6062 _elm_win_indicator_mode_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Elm_Win_Indicator_Mode mode)
6063 {
6064    if (mode == sd->indmode) return;
6065 #ifdef HAVE_ELEMENTARY_X
6066    _internal_elm_win_xwindow_get(sd);
6067 #endif
6068    sd->indmode = mode;
6069 #ifdef HAVE_ELEMENTARY_X
6070    if (sd->x.xwin)
6071      {
6072         if (sd->indmode == ELM_WIN_INDICATOR_SHOW)
6073           ecore_x_e_illume_indicator_state_set
6074             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_STATE_ON);
6075         else if (sd->indmode == ELM_WIN_INDICATOR_HIDE)
6076           ecore_x_e_illume_indicator_state_set
6077             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_STATE_OFF);
6078      }
6079 #endif
6080 #ifdef HAVE_ELEMENTARY_WAYLAND
6081    _elm_win_wlwindow_get(sd);
6082    if (sd->wl.win)
6083      {
6084         if (sd->indmode == ELM_WIN_INDICATOR_SHOW)
6085           ecore_wl_window_indicator_state_set
6086             (sd->wl.win, ECORE_WL_INDICATOR_STATE_ON);
6087         else if (sd->indmode == ELM_WIN_INDICATOR_HIDE)
6088           ecore_wl_window_indicator_state_set
6089             (sd->wl.win, ECORE_WL_INDICATOR_STATE_OFF);
6090      }
6091 #endif
6092    eo_do(obj, eo_event_callback_call
6093      (ELM_WIN_EVENT_INDICATOR_PROP_CHANGED, NULL));
6094 }
6095
6096 EOLIAN static Elm_Win_Indicator_Mode
6097 _elm_win_indicator_mode_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6098 {
6099    return sd->indmode;
6100 }
6101
6102 EOLIAN static void
6103 _elm_win_indicator_opacity_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Elm_Win_Indicator_Opacity_Mode mode)
6104 {
6105    if (mode == sd->ind_o_mode) return;
6106    sd->ind_o_mode = mode;
6107 #ifdef HAVE_ELEMENTARY_X
6108    _internal_elm_win_xwindow_get(sd);
6109    if (sd->x.xwin)
6110      {
6111         if (sd->ind_o_mode == ELM_WIN_INDICATOR_OPAQUE)
6112           ecore_x_e_illume_indicator_opacity_set
6113             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_OPAQUE);
6114         else if (sd->ind_o_mode == ELM_WIN_INDICATOR_TRANSLUCENT)
6115           ecore_x_e_illume_indicator_opacity_set
6116             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_TRANSLUCENT);
6117         else if (sd->ind_o_mode == ELM_WIN_INDICATOR_TRANSPARENT)
6118           ecore_x_e_illume_indicator_opacity_set
6119             (sd->x.xwin, ECORE_X_ILLUME_INDICATOR_TRANSPARENT);
6120      }
6121 #endif
6122 #ifdef HAVE_ELEMENTARY_WAYLAND
6123    _elm_win_wlwindow_get(sd);
6124    if (sd->wl.win)
6125      {
6126         if (sd->ind_o_mode == ELM_WIN_INDICATOR_OPAQUE)
6127           ecore_wl_window_indicator_opacity_set
6128             (sd->wl.win, ECORE_WL_INDICATOR_OPAQUE);
6129         else if (sd->ind_o_mode == ELM_WIN_INDICATOR_TRANSLUCENT)
6130           ecore_wl_window_indicator_opacity_set
6131             (sd->wl.win, ECORE_WL_INDICATOR_TRANSLUCENT);
6132         else if (sd->ind_o_mode == ELM_WIN_INDICATOR_TRANSPARENT)
6133           ecore_wl_window_indicator_opacity_set
6134             (sd->wl.win, ECORE_WL_INDICATOR_TRANSPARENT);
6135         else if (sd->ind_o_mode == ELM_WIN_INDICATOR_BG_TRANSPARENT)
6136           ecore_wl_window_indicator_opacity_set
6137             (sd->wl.win, ECORE_WL_INDICATOR_BG_TRANSPARENT);
6138      }
6139 #endif
6140    eo_do(obj, eo_event_callback_call
6141      (ELM_WIN_EVENT_INDICATOR_PROP_CHANGED, NULL));
6142 }
6143
6144 EOLIAN static Elm_Win_Indicator_Opacity_Mode
6145 _elm_win_indicator_opacity_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6146 {
6147    return sd->ind_o_mode;
6148 }
6149
6150 EOLIAN static void
6151 _elm_win_screen_position_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int *x, int *y)
6152 {
6153    if (x) *x = sd->screen.x;
6154    if (y) *y = sd->screen.y;
6155 }
6156
6157 EOLIAN static Eina_Bool
6158 _elm_win_focus_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6159 {
6160    return ecore_evas_focus_get(sd->ee);
6161 }
6162
6163 EOLIAN static void
6164 _elm_win_screen_constrain_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool constrain)
6165 {
6166    sd->constrain = !!constrain;
6167 }
6168
6169 EOLIAN static Eina_Bool
6170 _elm_win_screen_constrain_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6171 {
6172    return sd->constrain;
6173 }
6174
6175 EOLIAN static void
6176 _elm_win_screen_size_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int *x, int *y, int *w, int *h)
6177 {
6178    ecore_evas_screen_geometry_get(sd->ee, x, y, w, h);
6179 }
6180
6181 EOLIAN static void
6182 _elm_win_screen_dpi_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int *xdpi, int *ydpi)
6183 {
6184    ecore_evas_screen_dpi_get(sd->ee, xdpi, ydpi);
6185 }
6186
6187 EOLIAN static void
6188 _elm_win_conformant_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool conformant)
6189 {
6190 #ifdef HAVE_ELEMENTARY_X
6191    _internal_elm_win_xwindow_get(sd);
6192    if (sd->x.xwin)
6193      ecore_x_e_illume_conformant_set(sd->x.xwin, conformant);
6194 #elif HAVE_ELEMENTARY_WAYLAND
6195    _elm_win_wlwindow_get(sd);
6196    if (sd->wl.win)
6197      ecore_wl_window_conformant_set(sd->wl.win, conformant);
6198 #else
6199    (void)conformant;
6200 #endif
6201 }
6202
6203 EOLIAN static Eina_Bool
6204 _elm_win_conformant_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6205 {
6206 #ifdef HAVE_ELEMENTARY_X
6207    _internal_elm_win_xwindow_get(sd);
6208    if (sd->x.xwin)
6209      return ecore_x_e_illume_conformant_get(sd->x.xwin);
6210 #endif
6211 #if HAVE_ELEMENTARY_WAYLAND
6212    _elm_win_wlwindow_get(sd);
6213    if (sd->wl.win)
6214      return ecore_wl_window_conformant_get(sd->wl.win);
6215 #endif
6216
6217    return EINA_FALSE;
6218 }
6219
6220 EOLIAN static void
6221 _elm_win_quickpanel_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool quickpanel)
6222 {
6223 #ifdef HAVE_ELEMENTARY_X
6224    _internal_elm_win_xwindow_get(sd);
6225    if (sd->x.xwin)
6226      {
6227         ecore_x_e_illume_quickpanel_set(sd->x.xwin, quickpanel);
6228         if (quickpanel)
6229           {
6230              Ecore_X_Window_State states[2];
6231
6232              states[0] = ECORE_X_WINDOW_STATE_SKIP_TASKBAR;
6233              states[1] = ECORE_X_WINDOW_STATE_SKIP_PAGER;
6234              ecore_x_netwm_window_state_set(sd->x.xwin, states, 2);
6235              ecore_x_icccm_hints_set(sd->x.xwin, 0, 0, 0, 0, 0, 0, 0);
6236           }
6237      }
6238 #else
6239    (void)quickpanel;
6240 #endif
6241 #ifdef HAVE_ELEMENTARY_WAYLAND
6242    _elm_win_focus_skip_set(sd, EINA_TRUE);
6243 #endif
6244 }
6245
6246 EOLIAN static Eina_Bool
6247 _elm_win_quickpanel_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6248 {
6249 #ifdef HAVE_ELEMENTARY_X
6250    _internal_elm_win_xwindow_get(sd);
6251    if (sd->x.xwin)
6252      return ecore_x_e_illume_quickpanel_get(sd->x.xwin);
6253 #else
6254    (void)sd;
6255 #endif
6256
6257    return EINA_FALSE;
6258 }
6259
6260 EOLIAN static void
6261 _elm_win_quickpanel_priority_major_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int priority)
6262 {
6263 #ifdef HAVE_ELEMENTARY_X
6264    _internal_elm_win_xwindow_get(sd);
6265    if (sd->x.xwin)
6266      ecore_x_e_illume_quickpanel_priority_major_set(sd->x.xwin, priority);
6267 #else
6268    (void)priority;
6269    (void)sd;
6270 #endif
6271 }
6272
6273 EOLIAN static int
6274 _elm_win_quickpanel_priority_major_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6275 {
6276 #ifdef HAVE_ELEMENTARY_X
6277    _internal_elm_win_xwindow_get(sd);
6278    if (sd->x.xwin)
6279      return ecore_x_e_illume_quickpanel_priority_major_get(sd->x.xwin);
6280 #else
6281    (void)sd;
6282 #endif
6283
6284    return -1;
6285 }
6286
6287 EOLIAN static void
6288 _elm_win_quickpanel_priority_minor_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int priority)
6289 {
6290 #ifdef HAVE_ELEMENTARY_X
6291    _internal_elm_win_xwindow_get(sd);
6292    if (sd->x.xwin)
6293      ecore_x_e_illume_quickpanel_priority_minor_set(sd->x.xwin, priority);
6294 #else
6295    (void)priority;
6296    (void)sd;
6297 #endif
6298 }
6299
6300 EOLIAN static int
6301 _elm_win_quickpanel_priority_minor_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6302 {
6303 #ifdef HAVE_ELEMENTARY_X
6304    _internal_elm_win_xwindow_get(sd);
6305    if (sd->x.xwin)
6306      return ecore_x_e_illume_quickpanel_priority_minor_get(sd->x.xwin);
6307 #else
6308    (void)sd;
6309 #endif
6310
6311    return -1;
6312 }
6313
6314 EOLIAN static void
6315 _elm_win_quickpanel_zone_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, int zone)
6316 {
6317 #ifdef HAVE_ELEMENTARY_X
6318    _internal_elm_win_xwindow_get(sd);
6319    if (sd->x.xwin)
6320      ecore_x_e_illume_quickpanel_zone_set(sd->x.xwin, zone);
6321 #else
6322    (void)zone;
6323    (void)sd;
6324 #endif
6325 }
6326
6327 EOLIAN static int
6328 _elm_win_quickpanel_zone_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6329 {
6330 #ifdef HAVE_ELEMENTARY_X
6331    _internal_elm_win_xwindow_get(sd);
6332    if (sd->x.xwin)
6333      return ecore_x_e_illume_quickpanel_zone_get(sd->x.xwin);
6334 #else
6335    (void)sd;
6336 #endif
6337
6338    return 0;
6339 }
6340
6341 EOLIAN static void
6342 _elm_win_prop_focus_skip_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool skip)
6343 {
6344    _elm_win_focus_skip_set(sd, skip);
6345 }
6346
6347 EOLIAN static void
6348 _elm_win_illume_command_send(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Elm_Illume_Command command, void *params)
6349 {
6350    (void) params;
6351
6352 #ifdef HAVE_ELEMENTARY_X
6353    _internal_elm_win_xwindow_get(sd);
6354    if (sd->x.xwin)
6355      {
6356         switch (command)
6357           {
6358            case ELM_ILLUME_COMMAND_FOCUS_BACK:
6359              ecore_x_e_illume_focus_back_send(sd->x.xwin);
6360              break;
6361
6362            case ELM_ILLUME_COMMAND_FOCUS_FORWARD:
6363              ecore_x_e_illume_focus_forward_send(sd->x.xwin);
6364              break;
6365
6366            case ELM_ILLUME_COMMAND_FOCUS_HOME:
6367              ecore_x_e_illume_focus_home_send(sd->x.xwin);
6368              break;
6369
6370            case ELM_ILLUME_COMMAND_CLOSE:
6371              ecore_x_e_illume_close_send(sd->x.xwin);
6372              break;
6373
6374            default:
6375              break;
6376           }
6377      }
6378 #else
6379    (void)command;
6380    (void)sd;
6381 #endif
6382 }
6383
6384 EOLIAN static Eina_Bool
6385 _elm_win_keygrab_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *key, Evas_Modifier_Mask modifiers EINA_UNUSED, Evas_Modifier_Mask not_modifiers EINA_UNUSED, int priority EINA_UNUSED, Elm_Win_Keygrab_Mode grab_mode)
6386 {
6387    Eina_Bool ret = EINA_FALSE;
6388 #ifdef HAVE_ELEMENTARY_X
6389    _internal_elm_win_xwindow_get(sd);
6390    if (sd->x.xwin)
6391      {
6392         Ecore_X_Win_Keygrab_Mode x_grab_mode;
6393         switch (grab_mode)
6394           {
6395            case ELM_WIN_KEYGRAB_SHARED:
6396              x_grab_mode = ECORE_X_WIN_KEYGRAB_SHARED;
6397              break;
6398            case ELM_WIN_KEYGRAB_TOPMOST:
6399              x_grab_mode = ECORE_X_WIN_KEYGRAB_TOPMOST;
6400              break;
6401            case ELM_WIN_KEYGRAB_EXCLUSIVE:
6402              x_grab_mode = ECORE_X_WIN_KEYGRAB_EXCLUSIVE;
6403              break;
6404            case ELM_WIN_KEYGRAB_OVERRIDE_EXCLUSIVE:
6405              x_grab_mode = ECORE_X_WIN_KEYGRAB_OVERRIDE_EXCLUSIVE;
6406              break;
6407            default:
6408              return ret;
6409           }
6410          ret = ecore_x_window_keygrab_set(sd->x.xwin, key, 0, 0, 0, x_grab_mode);
6411      }
6412 #endif
6413 // TIZEN_ONLY(20150722): Add ecore_wl_window_keygrab_* APIs
6414 #ifdef HAVE_ELEMENTARY_WAYLAND
6415    _elm_win_wlwindow_get(sd);
6416    if (sd->wl.win)
6417      {
6418         Ecore_Wl_Window_Keygrab_Mode wl_grab_mode;
6419         switch (grab_mode)
6420           {
6421            case ELM_WIN_KEYGRAB_SHARED:
6422              wl_grab_mode = ECORE_WL_WINDOW_KEYGRAB_SHARED;
6423              break;
6424            case ELM_WIN_KEYGRAB_TOPMOST:
6425              wl_grab_mode = ECORE_WL_WINDOW_KEYGRAB_TOPMOST;
6426              break;
6427            case ELM_WIN_KEYGRAB_EXCLUSIVE:
6428              wl_grab_mode = ECORE_WL_WINDOW_KEYGRAB_EXCLUSIVE;
6429              break;
6430            case ELM_WIN_KEYGRAB_OVERRIDE_EXCLUSIVE:
6431              wl_grab_mode = ECORE_WL_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
6432              break;
6433            default:
6434              return ret;
6435           }
6436         ret = ecore_wl_window_keygrab_set(sd->wl.win, key, 0, 0, 0, wl_grab_mode);
6437      }
6438 #endif
6439 //
6440    return ret;
6441 }
6442
6443 EOLIAN static Eina_Bool
6444 _elm_win_keygrab_unset(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *key, Evas_Modifier_Mask modifiers EINA_UNUSED, Evas_Modifier_Mask not_modifiers EINA_UNUSED)
6445 {
6446    Eina_Bool ret = EINA_FALSE;
6447 #ifdef HAVE_ELEMENTARY_X
6448    _internal_elm_win_xwindow_get(sd);
6449    if (sd->x.xwin)
6450      ret = ecore_x_window_keygrab_unset(sd->x.xwin, key, 0, 0);
6451 #endif
6452 // TIZEN_ONLY(20150722): Add ecore_wl_window_keygrab_* APIs
6453 #ifdef HAVE_ELEMENTARY_WAYLAND
6454    _elm_win_wlwindow_get(sd);
6455    if (sd->wl.win)
6456      ret = ecore_wl_window_keygrab_unset(sd->wl.win, key, 0, 0);
6457 #endif
6458 //
6459    return ret;
6460 }
6461
6462 EOLIAN static Evas_Object*
6463 _elm_win_inlined_image_object_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6464 {
6465    return sd->img_obj;
6466 }
6467
6468 EOLIAN static void
6469 _elm_win_focus_highlight_enabled_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool enabled)
6470 {
6471    enabled = !!enabled;
6472    if (sd->focus_highlight.enabled == enabled)
6473      return;
6474
6475    sd->focus_highlight.enabled = enabled;
6476
6477    if ((sd->focus_highlight.enabled) || (sd->focus_highlight.auto_enabled))
6478      _elm_win_focus_highlight_init(sd);
6479    else
6480      _elm_win_focus_highlight_shutdown(sd);
6481 }
6482
6483 EOLIAN static Eina_Bool
6484 _elm_win_focus_highlight_enabled_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6485 {
6486    return sd->focus_highlight.enabled;
6487 }
6488
6489 static Elm_Theme_Apply
6490 _elm_win_theme_internal(Eo *obj, Elm_Win_Data *sd)
6491 {
6492    Elm_Theme_Apply int_ret = ELM_THEME_APPLY_FAILED;
6493    Eina_Bool ret = EINA_FALSE;
6494    const char *s;
6495
6496    int_ret = _elm_theme_object_set(obj, sd->edje, "win", "base",
6497                                    elm_widget_style_get(obj));
6498
6499    if (!int_ret) return ELM_THEME_APPLY_FAILED;
6500
6501    edje_object_mirrored_set(sd->edje, elm_widget_mirrored_get(obj));
6502    edje_object_scale_set(sd->edje,
6503                          elm_widget_scale_get(obj) * elm_config_scale_get());
6504
6505    eo_do(obj, eo_event_callback_call(ELM_WIN_EVENT_THEME_CHANGED, NULL));
6506    eo_do(obj, ret = elm_obj_widget_disable());
6507
6508    if (!ret) int_ret = ELM_THEME_APPLY_FAILED;
6509
6510    if (!sd->theme_alpha && !sd->application_alpha)
6511      {
6512         s = edje_object_data_get(sd->edje, "alpha");
6513         if (s)
6514           {
6515              if (!strcmp(s, "1") ||
6516                  !strcmp(s, "true"))
6517                {
6518                   sd->application_alpha = 1;
6519                   _elm_win_apply_alpha(obj, sd);
6520                }
6521           }
6522      }
6523
6524    return int_ret;
6525 }
6526
6527 EOLIAN static Elm_Theme_Apply
6528 _elm_win_elm_widget_theme_apply(Eo *obj, Elm_Win_Data *sd)
6529 {
6530    Elm_Theme_Apply int_ret = ELM_THEME_APPLY_FAILED;
6531    eo_do_super(obj, MY_CLASS, int_ret = elm_obj_widget_theme_apply());
6532    if (!int_ret) return ELM_THEME_APPLY_FAILED;
6533
6534    sd->focus_highlight.theme_changed = EINA_TRUE;
6535
6536    int_ret = _elm_win_theme_internal(obj, sd) & int_ret;
6537    if (!int_ret)
6538      return ELM_THEME_APPLY_FAILED;
6539    _elm_win_focus_highlight_reconfigure_job_start(sd);
6540
6541    return int_ret;
6542 }
6543
6544 EOLIAN static void
6545 _elm_win_focus_highlight_style_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *style)
6546 {
6547    eina_stringshare_replace(&sd->focus_highlight.style, style);
6548    sd->focus_highlight.theme_changed = EINA_TRUE;
6549    _elm_win_focus_highlight_reconfigure_job_start(sd);
6550 }
6551
6552 EOLIAN static const char*
6553 _elm_win_focus_highlight_style_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6554 {
6555    return sd->focus_highlight.style;
6556 }
6557
6558 EOLIAN static void
6559 _elm_win_focus_highlight_animate_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool animate)
6560 {
6561    animate = !!animate;
6562    if (sd->focus_highlight.animate == animate)
6563      return;
6564
6565    sd->focus_highlight.animate = animate;
6566    sd->focus_highlight.theme_changed = EINA_TRUE;
6567    _elm_win_focus_highlight_reconfigure_job_start(sd);
6568 }
6569
6570 EOLIAN static Eina_Bool
6571 _elm_win_focus_highlight_animate_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6572 {
6573    return sd->focus_highlight.animate;
6574 }
6575
6576 EOLIAN static Eina_Bool
6577 _elm_win_socket_listen(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, const char *svcname, int svcnum, Eina_Bool svcsys)
6578 {
6579    if (!sd->ee) return EINA_FALSE;
6580    if (sd->type != ELM_WIN_SOCKET_IMAGE) return EINA_FALSE;
6581
6582    if (!ecore_evas_extn_socket_listen(sd->ee, svcname, svcnum, svcsys))
6583      return EINA_FALSE;
6584
6585    if (_elm_atspi_enabled())
6586      {
6587         if (sd->socket_proxy)
6588           eo_unref(sd->socket_proxy);
6589         sd->socket_proxy = _elm_atspi_bridge_utils_proxy_create(obj, svcname, svcnum, ELM_ATSPI_PROXY_TYPE_SOCKET);
6590         elm_atspi_bridge_utils_proxy_listen(sd->socket_proxy);
6591      }
6592
6593    return EINA_TRUE;
6594 }
6595
6596 EOLIAN static Eina_Bool
6597 _elm_win_move_resize_start(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Elm_Win_Move_Resize_Mode mode)
6598 {
6599    Eina_Bool res = EINA_FALSE;
6600
6601 #ifdef HAVE_ELEMENTARY_WAYLAND
6602    int i;
6603    //1. move_resize can be start after mouse down event
6604    i = evas_event_down_count_get(sd->evas);
6605    if (i <= 0) return res;
6606
6607    //2. check move_resize start already .
6608    if (sd->resizing) return res;
6609
6610    i = sd->rot / 90;
6611    if (mode == ELM_WIN_MOVE_RESIZE_MOVE)
6612      {
6613         if (sd->wl.win)
6614           {
6615              sd->resizing = EINA_TRUE;
6616              ecore_wl_window_pointer_set(sd->wl.win, NULL,
6617                                          sd->pointer.hot_x, sd->pointer.hot_y);
6618
6619              /* Note: Not passing any X,Y position as those don't make sense, only
6620               * the compositor can really handle the window & pointer position. */
6621              ecore_evas_wayland_move(sd->ee, 0, 0);
6622              res = EINA_TRUE;
6623           }
6624      }
6625    else
6626      {
6627         if(mode == ELM_WIN_MOVE_RESIZE_TOP)
6628           sd->resize_location = _border_side[(0 + i) % 4].location;
6629         else if (mode == ELM_WIN_MOVE_RESIZE_BOTTOM)
6630           sd->resize_location = _border_side[(2 + i) % 4].location;
6631         else if (mode == ELM_WIN_MOVE_RESIZE_LEFT)
6632           sd->resize_location = _border_side[(1 + i) % 4].location;
6633         else if (mode == ELM_WIN_MOVE_RESIZE_RIGHT)
6634           sd->resize_location = _border_side[(3 + i) % 4].location;
6635         else if (mode == (ELM_WIN_MOVE_RESIZE_TOP | ELM_WIN_MOVE_RESIZE_LEFT))
6636           sd->resize_location = _border_corner[(0 + i) % 4].location;
6637         else if (mode == (ELM_WIN_MOVE_RESIZE_TOP | ELM_WIN_MOVE_RESIZE_RIGHT))
6638           sd->resize_location = _border_corner[(3 + i) % 4].location;
6639         else if (mode == (ELM_WIN_MOVE_RESIZE_BOTTOM | ELM_WIN_MOVE_RESIZE_LEFT))
6640           sd->resize_location = _border_corner[(1 + i) % 4].location;
6641         else if (mode == (ELM_WIN_MOVE_RESIZE_BOTTOM | ELM_WIN_MOVE_RESIZE_RIGHT))
6642           sd->resize_location = _border_corner[(2 + i) % 4].location;
6643         else
6644           sd->resize_location = 0;
6645
6646         if (sd->resize_location > 0)
6647           {
6648              sd->resizing = EINA_TRUE;
6649              ecore_evas_wayland_resize(sd->ee, sd->resize_location);
6650              res = EINA_TRUE;
6651           }
6652      }
6653 #endif
6654    return res;
6655 }
6656
6657 /* windowing specific calls - shall we do this differently? */
6658
6659 EOLIAN static Ecore_X_Window
6660 _elm_win_xwindow_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6661 {
6662 #ifdef HAVE_ELEMENTARY_X
6663    if (sd->x.xwin) return sd->x.xwin;
6664    if (sd->parent) return elm_win_xwindow_get(sd->parent);
6665 #else
6666    (void)sd;
6667 #endif
6668    return 0;
6669 }
6670
6671 EAPI Ecore_Wl_Window *
6672 elm_win_wl_window_get(const Evas_Object *obj)
6673 {
6674    ELM_WIN_CHECK(obj) NULL;
6675    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
6676    const char *engine_name = ecore_evas_engine_name_get(sd->ee);
6677
6678    if (!(engine_name &&
6679          ((!strcmp(engine_name, ELM_WAYLAND_SHM)) ||
6680           (!strcmp(engine_name, ELM_WAYLAND_EGL)))))
6681      return NULL;
6682
6683    if (!evas_object_smart_type_check_ptr(obj, MY_CLASS_NAME_LEGACY))
6684      {
6685         Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
6686         return _elm_ee_wlwin_get(ee);
6687      }
6688
6689    Ecore_Wl_Window *ret = NULL;
6690    eo_do((Eo *) obj, ret = elm_obj_win_wl_window_get());
6691    return ret;
6692 }
6693
6694 EOLIAN static Ecore_Cocoa_Window *
6695 _elm_win_cocoa_window_get(Eo           *obj,
6696                           Elm_Win_Data *sd)
6697 {
6698    const char *engine_name = ecore_evas_engine_name_get(sd->ee);
6699    if (!engine_name) return NULL;
6700    if (strcmp(engine_name, "gl_cocoa") != 0 &&
6701        strcmp(engine_name, "opengl_cocoa") != 0)
6702        return NULL;
6703
6704    Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
6705    return _elm_ee_cocoa_win_get(ee);
6706 }
6707
6708 EOLIAN static Ecore_Wl_Window*
6709 _elm_win_wl_window_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6710 {
6711 #if HAVE_ELEMENTARY_WAYLAND
6712    if (sd->wl.win) return sd->wl.win;
6713    if (sd->parent) return elm_win_wl_window_get(sd->parent);
6714 #else
6715    (void)sd;
6716 #endif
6717    return NULL;
6718 }
6719
6720 EAPI Ecore_Win32_Window *
6721 elm_win_win32_window_get(const Evas_Object *obj)
6722 {
6723    ELM_WIN_CHECK(obj) NULL;
6724    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
6725    const char *engine_name = ecore_evas_engine_name_get(sd->ee);
6726
6727    if (!(engine_name &&
6728          ((!strcmp(engine_name, ELM_SOFTWARE_WIN32)) ||
6729           (!strcmp(engine_name, ELM_SOFTWARE_DDRAW)))))
6730      return NULL;
6731
6732    if (!evas_object_smart_type_check_ptr(obj, MY_CLASS_NAME_LEGACY))
6733      {
6734         Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
6735         return _elm_ee_win32win_get(ee);
6736      }
6737
6738    Ecore_Win32_Window *ret = NULL;
6739    eo_do((Eo *) obj, ret = elm_obj_win_win32_window_get());
6740    return ret;
6741 }
6742
6743 EOLIAN static Ecore_Win32_Window *
6744 _elm_win_win32_window_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6745 {
6746 #if HAVE_ELEMENTARY_WIN32
6747    if (sd->win32.win) return sd->win32.win;
6748    if (sd->parent) return elm_win_win32_window_get(sd->parent);
6749 #else
6750    (void)sd;
6751 #endif
6752    return NULL;
6753 }
6754
6755 EAPI Eina_Bool
6756 elm_win_trap_set(const Elm_Win_Trap *t)
6757 {
6758    DBG("old %p, new %p", trap, t);
6759
6760    if ((t) && (t->version != ELM_WIN_TRAP_VERSION))
6761      {
6762         CRI("trying to set a trap version %lu while %lu was expected!",
6763                  t->version, ELM_WIN_TRAP_VERSION);
6764         return EINA_FALSE;
6765      }
6766
6767    trap = t;
6768    return EINA_TRUE;
6769 }
6770
6771 EAPI void
6772 elm_win_floating_mode_set(Evas_Object *obj, Eina_Bool floating)
6773 {
6774    ELM_WIN_CHECK(obj);
6775    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
6776
6777    floating = !!floating;
6778    if (floating == sd->floating) return;
6779    sd->floating = floating;
6780 #if HAVE_ELEMENTARY_WAYLAND
6781    _elm_win_wlwindow_get(sd);
6782    if (sd->wl.win)
6783      {
6784         if (floating)
6785           {
6786              if (!sd->borderless)
6787                {
6788                   const char *engine_name = ecore_evas_engine_name_get(sd->ee);
6789                   Eina_Bool need_frame = engine_name &&
6790                      ((!strcmp(engine_name, ELM_WAYLAND_SHM)) ||
6791                       (!strcmp(engine_name, ELM_WAYLAND_EGL)));
6792
6793                   if (need_frame)
6794                     need_frame = !sd->fullscreen;
6795
6796                   if (need_frame)
6797                     {
6798                        _elm_win_frame_del(sd);
6799                        _elm_win_frame_add(sd, "floating");
6800                     }
6801
6802                   if (sd->frame_obj)
6803                     evas_object_show(sd->frame_obj);
6804                }
6805
6806              //TIZEN_ONLY(20161208): supported floating window
6807              edje_object_signal_emit(sd->edje, "elm,state,floating,on", "elm");
6808              //
6809           }
6810         else
6811           {
6812              elm_win_borderless_set(obj, sd->borderless);
6813              //TIZEN_ONLY(20161208): supported floating window
6814              edje_object_signal_emit(sd->edje, "elm,state,floating,off", "elm");
6815              //
6816           }
6817         ecore_wl_window_floating_mode_set(sd->wl.win, floating);
6818      }
6819 #endif
6820 #ifdef HAVE_ELEMENTARY_X
6821    _internal_elm_win_xwindow_get(sd);
6822    if (sd->x.xwin)
6823      {
6824         if (sd->floating)
6825           ecore_x_e_illume_window_state_set
6826              (sd->x.xwin, ECORE_X_ILLUME_WINDOW_STATE_FLOATING);
6827         else
6828           ecore_x_e_illume_window_state_set
6829              (sd->x.xwin, ECORE_X_ILLUME_WINDOW_STATE_NORMAL);
6830      }
6831 #endif
6832 }
6833
6834 EAPI Eina_Bool
6835 elm_win_floating_mode_get(const Evas_Object *obj)
6836 {
6837    ELM_WIN_CHECK(obj) EINA_FALSE;
6838    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
6839
6840    return sd->floating;
6841 }
6842
6843 EOLIAN static Ecore_Window
6844 _elm_win_window_id_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
6845 {
6846    const char *engine_name = ecore_evas_engine_name_get(sd->ee);
6847
6848    if ((engine_name &&
6849         ((!strcmp(engine_name, ELM_WAYLAND_SHM)) ||
6850          (!strcmp(engine_name, ELM_WAYLAND_EGL)))))
6851      {
6852 #if HAVE_ELEMENTARY_WAYLAND
6853         if (sd->wl.win) return (Ecore_Window)ecore_wl_window_surface_id_get(sd->wl.win);
6854         if (sd->parent)
6855           {
6856              Ecore_Wl_Window *parent;
6857
6858              parent = elm_win_wl_window_get(sd->parent);
6859              if (parent) return (Ecore_Window)ecore_wl_window_surface_id_get(parent);
6860              return 0;
6861           }
6862 #endif
6863      }
6864    else if ((engine_name &&
6865              ((!strcmp(engine_name, ELM_SOFTWARE_X11)) ||
6866               (!strcmp(engine_name, ELM_OPENGL_X11)))))
6867      {
6868 #ifdef HAVE_ELEMENTARY_X
6869         _internal_elm_win_xwindow_get(sd);
6870         if (sd->x.xwin) return (Ecore_Window)sd->x.xwin;
6871         if (sd->parent) return (Ecore_Window)elm_win_xwindow_get(sd->parent);
6872 #endif
6873      }
6874    else if (engine_name &&
6875             ((!strcmp(engine_name, ELM_OPENGL_COCOA)) ||
6876              (!strcmp(engine_name, "gl_cocoa"))))
6877      {
6878 #ifdef HAVE_ELEMENTARY_COCOA
6879         if (sd->cocoa.win) return (Ecore_Window)(sd->cocoa.win);
6880         if (sd->parent)
6881           {
6882              Ecore_Cocoa_Window *pwin;
6883              eo_do(sd->parent, pwin = elm_obj_win_cocoa_window_get());
6884              return (Ecore_Window)pwin;
6885           }
6886 #endif
6887      }
6888    else if ((engine_name &&
6889              ((!strcmp(engine_name, ELM_SOFTWARE_WIN32)) ||
6890               (!strcmp(engine_name, ELM_SOFTWARE_DDRAW)))))
6891      {
6892 #ifdef HAVE_ELEMENTARY_WIN32
6893         _internal_elm_win_win32window_get(sd);
6894         if (sd->win32.win) return (Ecore_Window)sd->win32.win;
6895         if (sd->parent) return (Ecore_Window)elm_win_win32_window_get(sd->parent);
6896 #endif
6897      }
6898
6899    return 0;
6900 }
6901
6902 void
6903 _elm_win_focus_highlight_in_theme_update(Evas_Object *obj, Eina_Bool in_theme)
6904 {
6905    ELM_WIN_DATA_GET(obj, sd);
6906    sd->focus_highlight.cur.in_theme = !!in_theme;
6907 }
6908
6909 void
6910 _elm_win_focus_highlight_start(Evas_Object *obj)
6911 {
6912    ELM_WIN_DATA_GET(obj, sd);
6913
6914    if (!(sd->focus_highlight.enabled) && !(sd->focus_highlight.auto_enabled)) return;
6915    sd->focus_highlight.cur.visible = EINA_TRUE;
6916    sd->focus_highlight.geometry_changed = EINA_TRUE;
6917    _elm_win_focus_highlight_reconfigure_job(obj);
6918 }
6919
6920 void
6921 _elm_win_focus_auto_show(Evas_Object *obj)
6922 {
6923    ELM_WIN_DATA_GET(obj, sd);
6924    Eina_Bool pfocus = (sd->focus_highlight.enabled) || (sd->focus_highlight.auto_enabled);
6925    sd->focus_highlight.auto_enabled = _elm_config->win_auto_focus_enable;
6926    sd->focus_highlight.auto_animate = _elm_config->win_auto_focus_animate;
6927    if (pfocus != ((sd->focus_highlight.enabled) || (sd->focus_highlight.auto_enabled)))
6928      {
6929         if ((sd->focus_highlight.enabled) || (sd->focus_highlight.auto_enabled))
6930           _elm_win_focus_highlight_init(sd);
6931      }
6932 }
6933
6934 void
6935 _elm_win_focus_auto_hide(Evas_Object *obj)
6936 {
6937    ELM_WIN_DATA_GET(obj, sd);
6938    Eina_Bool pfocus = (sd->focus_highlight.enabled) || (sd->focus_highlight.auto_enabled);
6939    sd->focus_highlight.auto_enabled = EINA_FALSE;
6940    sd->focus_highlight.auto_animate = EINA_FALSE;
6941    if (pfocus != ((sd->focus_highlight.enabled) || (sd->focus_highlight.auto_enabled)))
6942      {
6943         if (!((sd->focus_highlight.enabled) || (sd->focus_highlight.auto_enabled)))
6944           _elm_win_focus_highlight_shutdown(sd);
6945      }
6946 }
6947
6948 void
6949 _elm_win_object_set_accessibility_highlight(Evas_Object *win, Evas_Object *obj, Eina_Bool visible)
6950 {
6951    if (!win) return;
6952    ELM_WIN_DATA_GET(win, sd);
6953    if (visible || sd->accessibility_highlight.cur.target == obj)
6954      {
6955          _elm_win_accessibility_highlight_hide(win);
6956          _elm_win_accessibility_highlight_callbacks_del(sd);
6957      }
6958
6959    if (visible)
6960      {
6961          _elm_win_accessibility_highlight_init(sd, obj);
6962          _elm_win_accessibility_highlight_show(win);
6963          //TIZEN_ONLY(20160623): atspi: moved highlight when object is out of screen
6964          sd->accessibility_highlight.cur.need_moved = EINA_TRUE;
6965          //
6966      }
6967 }
6968
6969 //TIZEN_ONLY(20170919): Handle default label object
6970 static void
6971 _default_label_obj_del_cb (void *data,
6972                            Evas *e EINA_UNUSED,
6973                            Evas_Object *obj,
6974                            void *event_info EINA_UNUSED)
6975 {
6976    ELM_WIN_DATA_GET(data, sd);
6977    if (!sd) return;
6978
6979    sd->default_label_objs = eina_list_remove(sd->default_label_objs, obj);
6980 }
6981
6982 static int _sort_parent_child_order(const void *data1, const void *data2)
6983 {
6984    if (data1)
6985      {
6986         Eo *parent;
6987         eo_do(data1, parent = elm_interface_atspi_accessible_parent_get());
6988         while (parent)
6989           {
6990              if (parent == data2) return 1;
6991              eo_do(parent, parent = elm_interface_atspi_accessible_parent_get());
6992           }
6993      }
6994    return -1;
6995 }
6996
6997 void
6998 _elm_win_default_label_obj_append(Evas_Object *default_label_obj)
6999 {
7000    if (!default_label_obj) return;
7001
7002    Evas_Object *win = elm_widget_top_get(default_label_obj);
7003    if (!win || !eo_isa(win, ELM_WIN_CLASS))
7004      {
7005         WRN("The top object of %s is not a window.",
7006             eo_class_name_get(eo_class_get(default_label_obj)));
7007         return;
7008      }
7009
7010    ELM_WIN_DATA_GET(win, sd);
7011    if (!sd) return;
7012
7013    if (eina_list_data_find(sd->default_label_objs, default_label_obj))
7014      {
7015         sd->default_label_objs =
7016           eina_list_remove(sd->default_label_objs, default_label_obj);
7017         evas_object_event_callback_del_full(default_label_obj, EVAS_CALLBACK_DEL,
7018                                             _default_label_obj_del_cb, win);
7019      }
7020
7021    evas_object_event_callback_add(default_label_obj, EVAS_CALLBACK_DEL,
7022                                   _default_label_obj_del_cb, win);
7023    sd->default_label_objs =
7024      eina_list_append(sd->default_label_objs, default_label_obj);
7025
7026    sd->default_label_objs =
7027      eina_list_sort(sd->default_label_objs, -1, _sort_parent_child_order);
7028 }
7029
7030 void
7031 _elm_win_default_label_obj_remove(Evas_Object *default_label_obj)
7032 {
7033    if (!default_label_obj) return;
7034
7035    Evas_Object *win = elm_widget_top_get(default_label_obj);
7036    if (!win || !eo_isa(win, ELM_WIN_CLASS))
7037      {
7038         WRN("The top object of %s is not a window.",
7039             eo_class_name_get(eo_class_get(default_label_obj)));
7040         return;
7041      }
7042
7043    ELM_WIN_DATA_GET(win, sd);
7044    if (!sd) return;
7045
7046    if (eina_list_data_find(sd->default_label_objs, default_label_obj))
7047      {
7048         sd->default_label_objs =
7049           eina_list_remove(sd->default_label_objs, default_label_obj);
7050         evas_object_event_callback_del_full(default_label_obj, EVAS_CALLBACK_DEL,
7051                                             _default_label_obj_del_cb, win);
7052      }
7053 }
7054
7055 Evas_Object *
7056 _elm_win_default_label_obj_get(Evas_Object *obj)
7057 {
7058    if (!obj) return NULL;
7059    ELM_WIN_DATA_GET(obj, sd);
7060    if (!sd) return NULL;
7061
7062    return eina_list_last_data_get(sd->default_label_objs);
7063 }
7064 //
7065
7066 EAPI Ecore_Window
7067 elm_win_window_id_get(const Evas_Object *obj)
7068 {
7069    if (!obj) return 0;
7070
7071    if (!evas_object_smart_type_check_ptr(obj, MY_CLASS_NAME_LEGACY))
7072      {
7073         Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
7074         return ecore_evas_window_get(ee);
7075      }
7076
7077    ELM_WIN_CHECK(obj) 0;
7078    Ecore_Window ret = 0;
7079    eo_do((Eo *) obj, ret = elm_obj_win_window_id_get());
7080    return ret;
7081 }
7082
7083 /* TIZEN_ONLY(20160622): Override Paragraph Direction APIs */
7084 EOLIAN static void
7085 _elm_win_evas_object_paragraph_direction_set(Eo *obj, Elm_Win_Data *sd, Evas_BiDi_Direction dir)
7086 {
7087    evas_object_paragraph_direction_set(sd->edje, dir);
7088
7089    eo_do_super(obj, MY_CLASS, evas_obj_paragraph_direction_set(dir));
7090 }
7091 /* END */
7092
7093 EOLIAN static void
7094 _elm_win_class_constructor(Eo_Class *klass)
7095 {
7096    evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
7097 }
7098
7099 EOLIAN static Eo*
7100 _elm_win_elm_interface_atspi_accessible_parent_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
7101 {
7102    // TIZEN_ONLY(20160705) - enable atspi_proxy to work
7103    if (sd->socket_proxy) return sd->socket_proxy;
7104    //
7105
7106    // attach all kinds of windows directly to ATSPI application root object
7107    Eo *bridge = _elm_atspi_bridge_get();
7108    return elm_atspi_bridge_root_get(bridge);
7109 }
7110
7111 EOLIAN static const Elm_Atspi_Action*
7112 _elm_win_elm_interface_atspi_widget_action_elm_actions_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd EINA_UNUSED)
7113 {
7114    static Elm_Atspi_Action atspi_actions[] = {
7115           { "move,previous", "move", "previous", _key_action_move},
7116           { "move,next", "move", "next", _key_action_move},
7117           { "move,left", "move", "left", _key_action_move},
7118           { "move,right", "move", "right", _key_action_move},
7119           { "move,up", "move", "up", _key_action_move},
7120           { "move,down", "move", "down", _key_action_move},
7121           { NULL, NULL, NULL, NULL }
7122    };
7123    return &atspi_actions[0];
7124 }
7125
7126 EOLIAN static Elm_Atspi_State_Set
7127 _elm_win_elm_interface_atspi_accessible_state_set_get(Eo *obj, Elm_Win_Data *sd EINA_UNUSED)
7128 {
7129    Elm_Atspi_State_Set ret;
7130    eo_do_super(obj, MY_CLASS, ret = elm_interface_atspi_accessible_state_set_get());
7131
7132    if (elm_win_focus_get(obj))
7133      STATE_TYPE_SET(ret, ELM_ATSPI_STATE_ACTIVE);
7134
7135    return ret;
7136 }
7137
7138 EOLIAN static const char*
7139 _elm_win_elm_interface_atspi_accessible_name_get(Eo *obj, Elm_Win_Data *sd EINA_UNUSED)
7140 {
7141    const char *ret = NULL;
7142    eo_do_super(obj, ELM_WIN_CLASS, ret = elm_interface_atspi_accessible_name_get());
7143    if (ret) return ret;
7144
7145    return _elm_widget_accessible_plain_name_get(obj, elm_win_title_get(obj));
7146 }
7147
7148 #include "elm_win.eo.c"
7149
7150 //////////////////////////////////////////////////////////////////
7151
7152 EAPI const Eina_List *
7153 elm_win_aux_hints_supported_get(const Evas_Object *obj)
7154 {
7155    ELM_WIN_CHECK(obj) NULL;
7156    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
7157    return ecore_evas_aux_hints_supported_get(sd->ee);
7158 }
7159
7160 EAPI int
7161 elm_win_aux_hint_add(Evas_Object *obj, const char *hint, const char *val)
7162 {
7163    ELM_WIN_CHECK(obj) -1;
7164    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, -1);
7165
7166 // TIZEN_ONLY(20170212): pend rotation until app set rotation
7167    if ((hint) && (!strncmp(hint, "wm.policy.win.rot.render.nopending", strlen(hint))))
7168      {
7169         return _elm_win_wm_pending_rotation_set(obj, hint, val);
7170      }
7171 //
7172    return ecore_evas_aux_hint_add(sd->ee, hint, val);
7173 }
7174
7175 EAPI Eina_Bool
7176 elm_win_aux_hint_del(Evas_Object *obj,
7177                      const int    id)
7178 {
7179    ELM_WIN_CHECK(obj) EINA_FALSE;
7180    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
7181    return ecore_evas_aux_hint_del(sd->ee, id);
7182 }
7183
7184 EAPI Eina_Bool
7185 elm_win_aux_hint_val_set(Evas_Object *obj, const int id, const char *val)
7186 {
7187    ELM_WIN_CHECK(obj) EINA_FALSE;
7188    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
7189    return ecore_evas_aux_hint_val_set(sd->ee, id, val);
7190 }
7191
7192 EAPI const char *
7193 elm_win_aux_hint_val_get(Evas_Object *obj, int id)
7194 {
7195    ELM_WIN_CHECK(obj) EINA_FALSE;
7196    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
7197    return ecore_evas_aux_hint_val_get(sd->ee, id);
7198 }
7199
7200 EAPI int
7201 elm_win_aux_hint_id_get(Evas_Object *obj, const char *hint)
7202 {
7203    ELM_WIN_CHECK(obj) EINA_FALSE;
7204    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, EINA_FALSE);
7205    return ecore_evas_aux_hint_id_get(sd->ee, hint);
7206 }
7207
7208 EINA_DEPRECATED EAPI void
7209 elm_win_profiles_set(Evas_Object *obj, const char **profiles, unsigned int num_profiles)
7210 {
7211    ELM_WIN_CHECK(obj);
7212    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
7213
7214    _elm_win_available_profiles_set(obj, sd, profiles, num_profiles);
7215 }
7216
7217 EAPI void
7218 elm_win_input_rect_set(Evas_Object *obj, Eina_Rectangle *input_rect)
7219 {
7220    ELM_WIN_CHECK(obj);
7221    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
7222    TRAP(sd, input_rect_set, input_rect);
7223 }
7224
7225 EAPI void
7226 elm_win_input_rect_add(Evas_Object *obj, Eina_Rectangle *input_rect)
7227 {
7228    ELM_WIN_CHECK(obj);
7229    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
7230    TRAP(sd, input_rect_add, input_rect);
7231 }
7232
7233 EAPI void
7234 elm_win_input_rect_subtract(Evas_Object *obj, Eina_Rectangle *input_rect)
7235 {
7236    ELM_WIN_CHECK(obj);
7237    ELM_WIN_DATA_GET_OR_RETURN(obj, sd);
7238    TRAP(sd, input_rect_subtract, input_rect);
7239 }
7240
7241 EAPI int
7242 elm_win_active_win_orientation_get(Evas_Object *obj)
7243 {
7244    int angle = -1;
7245 #ifdef HAVE_ELEMENTARY_WAYLAND
7246    Ecore_Wl_Window *win = NULL;
7247    if (obj)
7248      {
7249         ELM_WIN_DATA_GET(obj, sd);
7250         if (sd)
7251           win = sd->wl.win;
7252      }
7253    angle = ecore_wl_window_active_angle_get(win);
7254 #endif
7255    return angle;
7256 }
7257
7258 EAPI const char *
7259 elm_win_aux_msg_key_get(Evas_Object *obj,
7260                         Elm_Win_Aux_Message *msg)
7261 {
7262    ELM_WIN_CHECK(obj) NULL;
7263    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
7264
7265    if (!msg) return NULL;
7266    return msg->key;
7267 }
7268
7269 EAPI const char *
7270 elm_win_aux_msg_val_get(Evas_Object *obj,
7271                         Elm_Win_Aux_Message *msg)
7272 {
7273    ELM_WIN_CHECK(obj) NULL;
7274    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
7275
7276    if (!msg) return NULL;
7277    return msg->val;
7278 }
7279
7280 EAPI const Eina_List *
7281 elm_win_aux_msg_options_get(Evas_Object *obj,
7282                             Elm_Win_Aux_Message *msg)
7283 {
7284    ELM_WIN_CHECK(obj) NULL;
7285    ELM_WIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
7286
7287    if (!msg) return NULL;
7288    return msg->options;
7289 }
7290 //////////////////////////////////////////////////////////////////