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