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