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