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