fix up copy & paste with inlined win and a few other cnp nigglies.
[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_IMAGE:
1154           {
1155              if (parent)
1156                {
1157                   Evas *e = evas_object_evas_get(parent);
1158                   if (e)
1159                     {
1160                        Ecore_Evas *ee = ecore_evas_ecore_evas_get(e);
1161                        if (ee)
1162                          {
1163                             win->img_obj = ecore_evas_object_image_new(ee);
1164                             if (win->img_obj)
1165                               {
1166                                  win->ee = ecore_evas_object_ecore_evas_get(win->img_obj);
1167                                  if (win->ee)
1168                                    {
1169                                       _win_inlined_image_set(win);
1170                                    }
1171                                  else
1172                                    {
1173                                       evas_object_del(win->img_obj);
1174                                       win->img_obj = NULL;
1175                                    }
1176                               }
1177                          }
1178                     }
1179                }
1180           }
1181         break;
1182       default:
1183         if (ENGINE_COMPARE(ELM_SOFTWARE_X11))
1184           {
1185              win->ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
1186 #ifdef HAVE_ELEMENTARY_X
1187              win->client_message_handler = ecore_event_handler_add
1188                 (ECORE_X_EVENT_CLIENT_MESSAGE, _elm_win_client_message, win);
1189 #endif
1190           }
1191         else if (ENGINE_COMPARE(ELM_SOFTWARE_FB))
1192           {
1193              win->ee = ecore_evas_fb_new(NULL, 0, 1, 1);
1194              FALLBACK_TRY("Sofware FB");
1195           }
1196         else if (ENGINE_COMPARE(ELM_SOFTWARE_DIRECTFB))
1197           {
1198              win->ee = ecore_evas_directfb_new(NULL, 1, 0, 0, 1, 1);
1199              FALLBACK_TRY("Sofware DirectFB");
1200           }
1201         else if (ENGINE_COMPARE(ELM_SOFTWARE_16_X11))
1202           {
1203              win->ee = ecore_evas_software_x11_16_new(NULL, 0, 0, 0, 1, 1);
1204              FALLBACK_TRY("Sofware-16");
1205 #ifdef HAVE_ELEMENTARY_X
1206              win->client_message_handler = ecore_event_handler_add
1207                 (ECORE_X_EVENT_CLIENT_MESSAGE, _elm_win_client_message, win);
1208 #endif
1209      }
1210         else if (ENGINE_COMPARE(ELM_SOFTWARE_8_X11))
1211           {
1212              win->ee = ecore_evas_software_x11_8_new(NULL, 0, 0, 0, 1, 1);
1213              FALLBACK_TRY("Sofware-8");
1214 #ifdef HAVE_ELEMENTARY_X
1215              win->client_message_handler = ecore_event_handler_add
1216                 (ECORE_X_EVENT_CLIENT_MESSAGE, _elm_win_client_message, win);
1217 #endif
1218           }
1219         else if (ENGINE_COMPARE(ELM_XRENDER_X11))
1220           {
1221              win->ee = ecore_evas_xrender_x11_new(NULL, 0, 0, 0, 1, 1);
1222              FALLBACK_TRY("XRender");
1223 #ifdef HAVE_ELEMENTARY_X
1224              win->client_message_handler = ecore_event_handler_add
1225                 (ECORE_X_EVENT_CLIENT_MESSAGE, _elm_win_client_message, win);
1226 #endif
1227           }
1228         else if (ENGINE_COMPARE(ELM_OPENGL_X11))
1229           {
1230              win->ee = ecore_evas_gl_x11_new(NULL, 0, 0, 0, 1, 1);
1231              FALLBACK_TRY("OpenGL");
1232 #ifdef HAVE_ELEMENTARY_X
1233              win->client_message_handler = ecore_event_handler_add
1234                 (ECORE_X_EVENT_CLIENT_MESSAGE, _elm_win_client_message, win);
1235 #endif
1236           }
1237         else if (ENGINE_COMPARE(ELM_SOFTWARE_WIN32))
1238           {
1239              win->ee = ecore_evas_software_gdi_new(NULL, 0, 0, 1, 1);
1240              FALLBACK_TRY("Sofware Win32");
1241           }
1242         else if (ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE))
1243           {
1244              win->ee = ecore_evas_software_wince_gdi_new(NULL, 0, 0, 1, 1);
1245              FALLBACK_TRY("Sofware-16-WinCE");
1246           }
1247         else if (ENGINE_COMPARE(ELM_SOFTWARE_SDL))
1248           {
1249              win->ee = ecore_evas_sdl_new(NULL, 0, 0, 0, 0, 0, 1);
1250              FALLBACK_TRY("Sofware SDL");
1251           }
1252         else if (ENGINE_COMPARE(ELM_SOFTWARE_16_SDL))
1253           {
1254              win->ee = ecore_evas_sdl16_new(NULL, 0, 0, 0, 0, 0, 1);
1255              FALLBACK_TRY("Sofware-16-SDL");
1256           }
1257         else if (ENGINE_COMPARE(ELM_OPENGL_SDL))
1258           {
1259              win->ee = ecore_evas_gl_sdl_new(NULL, 1, 1, 0, 0);
1260              FALLBACK_TRY("OpenGL SDL");
1261           }
1262 #undef FALLBACK_TRY
1263         break;
1264      }
1265
1266    if (!win->ee)
1267      {
1268         ERR("Cannot create window.");
1269         free(win);
1270         return NULL;
1271      }
1272 #ifdef HAVE_ELEMENTARY_X
1273    _elm_win_xwindow_get(win);
1274 #endif
1275    if ((_elm_config->bgpixmap) && (!_elm_config->compositing))
1276      ecore_evas_avoid_damage_set(win->ee, ECORE_EVAS_AVOID_DAMAGE_EXPOSE);
1277    // bg pixmap done by x - has other issues like can be redrawn by x before it
1278    // is filled/ready by app
1279    //     ecore_evas_avoid_damage_set(win->ee, ECORE_EVAS_AVOID_DAMAGE_BUILT_IN);
1280
1281    win->type = type;
1282    win->parent = parent;
1283    if (win->parent)
1284      evas_object_event_callback_add(win->parent, EVAS_CALLBACK_DEL,
1285                                     _elm_win_obj_callback_parent_del, win);
1286
1287    win->evas = ecore_evas_get(win->ee);
1288    win->win_obj = elm_widget_add(win->evas);
1289    elm_widget_type_set(win->win_obj, "win");
1290    ELM_SET_WIDTYPE(widtype, "win");
1291    elm_widget_data_set(win->win_obj, win);
1292    elm_widget_event_hook_set(win->win_obj, _elm_win_event_cb);
1293    elm_widget_on_focus_hook_set(win->win_obj, _elm_win_on_focus_hook, NULL);
1294    elm_widget_can_focus_set(win->win_obj, EINA_TRUE);
1295    elm_widget_highlight_ignore_set(win->win_obj, EINA_TRUE);
1296    elm_widget_focus_next_hook_set(win->win_obj, _elm_win_focus_next_hook);
1297    evas_object_color_set(win->win_obj, 0, 0, 0, 0);
1298    evas_object_move(win->win_obj, 0, 0);
1299    evas_object_resize(win->win_obj, 1, 1);
1300    evas_object_layer_set(win->win_obj, 50);
1301    evas_object_pass_events_set(win->win_obj, EINA_TRUE);
1302
1303    evas_object_intercept_move_callback_add(win->win_obj,
1304                                            _elm_win_obj_intercept_move, win);
1305    evas_object_intercept_show_callback_add(win->win_obj,
1306                                            _elm_win_obj_intercept_show, win);
1307    ecore_evas_object_associate(win->ee, win->win_obj,
1308                                ECORE_EVAS_OBJECT_ASSOCIATE_BASE |
1309                                ECORE_EVAS_OBJECT_ASSOCIATE_STACK |
1310                                ECORE_EVAS_OBJECT_ASSOCIATE_LAYER);
1311    evas_object_event_callback_add(win->win_obj, EVAS_CALLBACK_SHOW,
1312                                   _elm_win_obj_callback_show, win);
1313    evas_object_event_callback_add(win->win_obj, EVAS_CALLBACK_HIDE,
1314                                   _elm_win_obj_callback_hide, win);
1315    evas_object_event_callback_add(win->win_obj, EVAS_CALLBACK_DEL,
1316                                   _elm_win_obj_callback_del, win);
1317    evas_object_event_callback_add(win->win_obj, EVAS_CALLBACK_MOVE,
1318                                   _elm_win_obj_callback_move, win);
1319    evas_object_event_callback_add(win->win_obj, EVAS_CALLBACK_RESIZE,
1320                                   _elm_win_obj_callback_resize, win);
1321
1322    ecore_evas_name_class_set(win->ee, name, _elm_appname);
1323    ecore_evas_callback_delete_request_set(win->ee, _elm_win_delete_request);
1324    ecore_evas_callback_resize_set(win->ee, _elm_win_resize);
1325    ecore_evas_callback_focus_in_set(win->ee, _elm_win_focus_in);
1326    ecore_evas_callback_focus_out_set(win->ee, _elm_win_focus_out);
1327    ecore_evas_callback_move_set(win->ee, _elm_win_move);
1328    evas_image_cache_set(win->evas, (_elm_config->image_cache * 1024));
1329    evas_font_cache_set(win->evas, (_elm_config->font_cache * 1024));
1330    EINA_LIST_FOREACH(_elm_config->font_dirs, l, fontpath)
1331       evas_font_path_append(win->evas, fontpath);
1332    if (!_elm_config->font_hinting)
1333      evas_font_hinting_set(win->evas, EVAS_FONT_HINTING_NONE);
1334    else if (_elm_config->font_hinting == 1)
1335      evas_font_hinting_set(win->evas, EVAS_FONT_HINTING_AUTO);
1336    else if (_elm_config->font_hinting == 2)
1337      evas_font_hinting_set(win->evas, EVAS_FONT_HINTING_BYTECODE);
1338
1339 #ifdef HAVE_ELEMENTARY_X
1340    _elm_win_xwin_update(win);
1341 #endif
1342
1343    _elm_win_list = eina_list_append(_elm_win_list, win->win_obj);
1344
1345    if (ENGINE_COMPARE(ELM_SOFTWARE_FB))
1346      {
1347         ecore_evas_fullscreen_set(win->ee, 1);
1348      }
1349 #undef ENGINE_COMPARE
1350
1351    if (_elm_config->focus_highlight_enable)
1352      elm_win_focus_highlight_enabled_set(win->win_obj, EINA_TRUE);
1353
1354 #ifdef ELM_DEBUG
1355    Evas_Modifier_Mask mask = evas_key_modifier_mask_get(win->evas, "Control");
1356    evas_object_event_callback_add(win->win_obj, EVAS_CALLBACK_KEY_DOWN,
1357                                   _debug_key_down, win);
1358
1359    Eina_Bool ret = evas_object_key_grab(win->win_obj, "F12", mask, 0,
1360                                         EINA_TRUE);
1361    printf("Key F12 exclusive for dot tree generation. (%d)\n", ret);
1362 #endif
1363    return win->win_obj;
1364 }
1365
1366 /**
1367  * Add @p subobj as a resize object of window @p obj.
1368  *
1369  * @param obj The window object
1370  * @param subobj The resize object to add
1371  *
1372  * @ingroup Win
1373  */
1374 EAPI void
1375 elm_win_resize_object_add(Evas_Object *obj, Evas_Object *subobj)
1376 {
1377    Evas_Coord w, h;
1378    Elm_Win *win;
1379    ELM_CHECK_WIDTYPE(obj, widtype);
1380    win = elm_widget_data_get(obj);
1381    if (!win) return;
1382    win->subobjs = eina_list_append(win->subobjs, subobj);
1383    elm_widget_sub_object_add(obj, subobj);
1384    evas_object_event_callback_add(subobj, EVAS_CALLBACK_DEL,
1385                                   _elm_win_subobj_callback_del, obj);
1386    evas_object_event_callback_add(subobj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1387                                   _elm_win_subobj_callback_changed_size_hints,
1388                                   obj);
1389    ecore_evas_geometry_get(win->ee, NULL, NULL, &w, &h);
1390    evas_object_move(subobj, 0, 0);
1391    evas_object_resize(subobj, w, h);
1392    _elm_win_eval_subobjs(obj);
1393 }
1394
1395 /**
1396  * Delete @p subobj as a resize object of window @p obj.
1397  *
1398  * @param obj The window object
1399  * @param subobj The resize object to add
1400  *
1401  * @ingroup Win
1402  */
1403 EAPI void
1404 elm_win_resize_object_del(Evas_Object *obj, Evas_Object *subobj)
1405 {
1406    Elm_Win *win;
1407    ELM_CHECK_WIDTYPE(obj, widtype);
1408    win = elm_widget_data_get(obj);
1409    if (!win) return;
1410    evas_object_event_callback_del_full(subobj,
1411                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1412                                        _elm_win_subobj_callback_changed_size_hints,
1413                                        obj);
1414    evas_object_event_callback_del_full(subobj, EVAS_CALLBACK_DEL,
1415                                        _elm_win_subobj_callback_del, obj);
1416    win->subobjs = eina_list_remove(win->subobjs, subobj);
1417    elm_widget_sub_object_del(obj, subobj);
1418    _elm_win_eval_subobjs(obj);
1419 }
1420
1421 /**
1422  * Set the title of the window
1423  *
1424  * @param obj The window object
1425  * @param title The title to set
1426  *
1427  * @ingroup Win
1428  */
1429 EAPI void
1430 elm_win_title_set(Evas_Object *obj, const char *title)
1431 {
1432    Elm_Win *win;
1433    ELM_CHECK_WIDTYPE(obj, widtype);
1434    win = elm_widget_data_get(obj);
1435    if (!win) return;
1436    ecore_evas_title_set(win->ee, title);
1437 }
1438
1439 /**
1440  * Get the title of the window
1441  *
1442  * @param obj The window object
1443  * @return The title
1444  *
1445  * @ingroup Win
1446  */
1447 EAPI const char *
1448 elm_win_title_get(const Evas_Object *obj)
1449 {
1450    Elm_Win *win;
1451    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1452    win = elm_widget_data_get(obj);
1453    if (!win) return NULL;
1454    return ecore_evas_title_get(win->ee);
1455 }
1456
1457 /**
1458  * Set the window's autodel state.
1459  *
1460  * @param obj The window object
1461  * @param autodel If true, the window will automatically delete itself when closed
1462  *
1463  * @ingroup Win
1464  */
1465 EAPI void
1466 elm_win_autodel_set(Evas_Object *obj, Eina_Bool autodel)
1467 {
1468    Elm_Win *win;
1469    ELM_CHECK_WIDTYPE(obj, widtype);
1470    win = elm_widget_data_get(obj);
1471    if (!win) return;
1472    win->autodel = autodel;
1473 }
1474
1475 /**
1476  * Get the window's autodel state.
1477  *
1478  * @param obj The window object
1479  * @return If the window will automatically delete itself when closed
1480  *
1481  * @ingroup Win
1482  */
1483 EAPI Eina_Bool
1484 elm_win_autodel_get(const Evas_Object *obj)
1485 {
1486    Elm_Win *win;
1487    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1488    win = elm_widget_data_get(obj);
1489    if (!win) return EINA_FALSE;
1490    return win->autodel;
1491 }
1492
1493 /**
1494  * Activate a window object.
1495  *
1496  * @param obj The window object
1497  *
1498  * @ingroup Win
1499  */
1500 EAPI void
1501 elm_win_activate(Evas_Object *obj)
1502 {
1503    Elm_Win *win;
1504    ELM_CHECK_WIDTYPE(obj, widtype);
1505    win = elm_widget_data_get(obj);
1506    if (!win) return;
1507    ecore_evas_activate(win->ee);
1508 }
1509
1510 /**
1511  * Lower a window object.
1512  *
1513  * @param obj The window object
1514  *
1515  * @ingroup Win
1516  */
1517 EAPI void
1518 elm_win_lower(Evas_Object *obj)
1519 {
1520    Elm_Win *win;
1521    ELM_CHECK_WIDTYPE(obj, widtype);
1522    win = elm_widget_data_get(obj);
1523    if (!win) return;
1524    ecore_evas_lower(win->ee);
1525 }
1526
1527 /**
1528  * Raise a window object.
1529  *
1530  * @param obj The window object
1531  *
1532  * @ingroup Win
1533  */
1534 EAPI void
1535 elm_win_raise(Evas_Object *obj)
1536 {
1537    Elm_Win *win;
1538    ELM_CHECK_WIDTYPE(obj, widtype);
1539    win = elm_widget_data_get(obj);
1540    if (!win) return;
1541    ecore_evas_raise(win->ee);
1542 }
1543
1544 /**
1545  * Set the borderless state of a window.
1546  *
1547  * @param obj The window object
1548  * @param borderless If true, the window is borderless
1549  *
1550  * @ingroup Win
1551  */
1552 EAPI void
1553 elm_win_borderless_set(Evas_Object *obj, Eina_Bool borderless)
1554 {
1555    Elm_Win *win;
1556    ELM_CHECK_WIDTYPE(obj, widtype);
1557    win = elm_widget_data_get(obj);
1558    if (!win) return;
1559    ecore_evas_borderless_set(win->ee, borderless);
1560 #ifdef HAVE_ELEMENTARY_X
1561    _elm_win_xwin_update(win);
1562 #endif
1563 }
1564
1565 /**
1566  * Get the borderless state of a window.
1567  *
1568  * @param obj The window object
1569  * @return If true, the window is borderless
1570  *
1571  * @ingroup Win
1572  */
1573 EAPI Eina_Bool
1574 elm_win_borderless_get(const Evas_Object *obj)
1575 {
1576    Elm_Win *win;
1577    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1578    win = elm_widget_data_get(obj);
1579    if (!win) return EINA_FALSE;
1580    return ecore_evas_borderless_get(win->ee);
1581 }
1582
1583 /**
1584  * Set the shaped state of a window.
1585  *
1586  * @param obj The window object
1587  * @param shaped If true, the window is shaped
1588  *
1589  * @ingroup Win
1590  */
1591 EAPI void
1592 elm_win_shaped_set(Evas_Object *obj, Eina_Bool shaped)
1593 {
1594    Elm_Win *win;
1595    ELM_CHECK_WIDTYPE(obj, widtype);
1596    win = elm_widget_data_get(obj);
1597    if (!win) return;
1598    ecore_evas_shaped_set(win->ee, shaped);
1599 #ifdef HAVE_ELEMENTARY_X
1600    _elm_win_xwin_update(win);
1601 #endif
1602 }
1603
1604 /**
1605  * Get the shaped state of a window.
1606  *
1607  * @param obj The window object
1608  * @return If true, the window is shaped
1609  *
1610  * @ingroup Win
1611  */
1612 EAPI Eina_Bool
1613 elm_win_shaped_get(const Evas_Object *obj)
1614 {
1615    Elm_Win *win;
1616    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1617    win = elm_widget_data_get(obj);
1618    if (!win) return EINA_FALSE;
1619    return ecore_evas_shaped_get(win->ee);
1620 }
1621
1622 /**
1623  * Set the alpha channel state of a window.
1624  *
1625  * @param obj The window object
1626  * @param alpha If true, the window has an alpha channel
1627  *
1628  * @ingroup Win
1629  */
1630 EAPI void
1631 elm_win_alpha_set(Evas_Object *obj, Eina_Bool alpha)
1632 {
1633    Elm_Win *win;
1634    ELM_CHECK_WIDTYPE(obj, widtype);
1635    win = elm_widget_data_get(obj);
1636    if (!win) return;
1637    if (win->frame_obj)
1638      {
1639      }
1640    else if (win->img_obj)
1641      {
1642         evas_object_image_alpha_set(win->img_obj, alpha);
1643      }
1644    else
1645      {
1646 #ifdef HAVE_ELEMENTARY_X
1647         if (win->xwin)
1648           {
1649              if (alpha)
1650                {
1651                   if (!_elm_config->compositing)
1652                      elm_win_shaped_set(obj, alpha);
1653                   else
1654                      ecore_evas_alpha_set(win->ee, alpha);
1655                }
1656              else
1657                 ecore_evas_alpha_set(win->ee, alpha);
1658              _elm_win_xwin_update(win);
1659           }
1660         else
1661 #endif
1662            ecore_evas_alpha_set(win->ee, alpha);
1663      }
1664 }
1665
1666 /**
1667  * Get the alpha channel state of a window.
1668  *
1669  * @param obj The window object
1670  * @return If true, the window has an alpha channel
1671  *
1672  * @ingroup Win
1673  */
1674 EAPI Eina_Bool
1675 elm_win_alpha_get(const Evas_Object *obj)
1676 {
1677    Elm_Win *win;
1678    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1679    win = elm_widget_data_get(obj);
1680    if (!win) return EINA_FALSE;
1681    return ecore_evas_alpha_get(win->ee);
1682 }
1683
1684 /**
1685  * Set the transparency state of a window.
1686  *
1687  * @param obj The window object
1688  * @param transparent If true, the window is transparent
1689  *
1690  * @ingroup Win
1691  */
1692 EAPI void
1693 elm_win_transparent_set(Evas_Object *obj, Eina_Bool transparent)
1694 {
1695    Elm_Win *win;
1696    ELM_CHECK_WIDTYPE(obj, widtype);
1697    win = elm_widget_data_get(obj);
1698    if (!win) return;
1699
1700    if (win->frame_obj)
1701      {
1702      }
1703    else if (win->img_obj)
1704      {
1705         evas_object_image_alpha_set(win->img_obj, transparent);
1706      }
1707    else
1708      {
1709 #ifdef HAVE_ELEMENTARY_X
1710         if (win->xwin)
1711           {
1712              ecore_evas_transparent_set(win->ee, transparent);
1713              _elm_win_xwin_update(win);
1714           }
1715         else
1716 #endif
1717            ecore_evas_transparent_set(win->ee, transparent);
1718      }
1719 }
1720
1721 /**
1722  * Get the transparency state of a window.
1723  *
1724  * @param obj The window object
1725  * @return If true, the window is transparent
1726  *
1727  * @ingroup Win
1728  */
1729 EAPI Eina_Bool
1730 elm_win_transparent_get(const Evas_Object *obj)
1731 {
1732    Elm_Win *win;
1733    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1734    win = elm_widget_data_get(obj);
1735    if (!win) return EINA_FALSE;
1736
1737    return ecore_evas_transparent_get(win->ee);
1738 }
1739
1740 /**
1741  * Set the override state of a window.
1742  *
1743  * @param obj The window object
1744  * @param override If true, the window is overridden
1745  *
1746  * @ingroup Win
1747  */
1748 EAPI void
1749 elm_win_override_set(Evas_Object *obj, Eina_Bool override)
1750 {
1751    Elm_Win *win;
1752    ELM_CHECK_WIDTYPE(obj, widtype);
1753    win = elm_widget_data_get(obj);
1754    if (!win) return;
1755    ecore_evas_override_set(win->ee, override);
1756 #ifdef HAVE_ELEMENTARY_X
1757    _elm_win_xwin_update(win);
1758 #endif
1759 }
1760
1761 /**
1762  * Get the override state of a window.
1763  *
1764  * @param obj The window object
1765  * @return If true, the window is overridden
1766  *
1767  * @ingroup Win
1768  */
1769 EAPI Eina_Bool
1770 elm_win_override_get(const Evas_Object *obj)
1771 {
1772    Elm_Win *win;
1773    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1774    win = elm_widget_data_get(obj);
1775    if (!win) return EINA_FALSE;
1776    return ecore_evas_override_get(win->ee);
1777 }
1778
1779 /**
1780  * Set the fullscreen state of a window.
1781  *
1782  * @param obj The window object
1783  * @param fullscreen If true, the window is fullscreen
1784  *
1785  * @ingroup Win
1786  */
1787 EAPI void
1788 elm_win_fullscreen_set(Evas_Object *obj, Eina_Bool fullscreen)
1789 {
1790    Elm_Win *win;
1791    ELM_CHECK_WIDTYPE(obj, widtype);
1792    win = elm_widget_data_get(obj);
1793    if (!win) return;
1794
1795    // YYY: handle if win->img_obj
1796 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
1797    if (ENGINE_COMPARE(ELM_SOFTWARE_FB) ||
1798        ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE))
1799      {
1800         // these engines... can ONLY be fullscreen
1801         return;
1802      }
1803    else
1804      {
1805         ecore_evas_fullscreen_set(win->ee, fullscreen);
1806 #ifdef HAVE_ELEMENTARY_X
1807         _elm_win_xwin_update(win);
1808 #endif
1809      }
1810 #undef ENGINE_COMPARE
1811 }
1812
1813 /**
1814  * Get the fullscreen state of a window.
1815  *
1816  * @param obj The window object
1817  * @return If true, the window is fullscreen
1818  *
1819  * @ingroup Win
1820  */
1821 EAPI Eina_Bool
1822 elm_win_fullscreen_get(const Evas_Object *obj)
1823 {
1824    Elm_Win *win;
1825    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1826    win = elm_widget_data_get(obj);
1827    if (!win) return EINA_FALSE;
1828
1829 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
1830    if (ENGINE_COMPARE(ELM_SOFTWARE_FB) ||
1831        ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE))
1832      {
1833         // these engines... can ONLY be fullscreen
1834         return EINA_TRUE;
1835      }
1836    else
1837      {
1838         return ecore_evas_fullscreen_get(win->ee);
1839      }
1840 #undef ENGINE_COMPARE
1841 }
1842
1843 /**
1844  * Set the maximized state of a window.
1845  *
1846  * @param obj The window object
1847  * @param maximized If true, the window is maximized
1848  *
1849  * @ingroup Win
1850  */
1851 EAPI void
1852 elm_win_maximized_set(Evas_Object *obj, Eina_Bool maximized)
1853 {
1854    Elm_Win *win;
1855    ELM_CHECK_WIDTYPE(obj, widtype);
1856    win = elm_widget_data_get(obj);
1857    if (!win) return;
1858    // YYY: handle if win->img_obj
1859    ecore_evas_maximized_set(win->ee, maximized);
1860 #ifdef HAVE_ELEMENTARY_X
1861    _elm_win_xwin_update(win);
1862 #endif
1863 }
1864
1865 /**
1866  * Get the maximized state of a window.
1867  *
1868  * @param obj The window object
1869  * @return If true, the window is maximized
1870  *
1871  * @ingroup Win
1872  */
1873 EAPI Eina_Bool
1874 elm_win_maximized_get(const Evas_Object *obj)
1875 {
1876    Elm_Win *win;
1877    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1878    win = elm_widget_data_get(obj);
1879    if (!win) return EINA_FALSE;
1880    return ecore_evas_maximized_get(win->ee);
1881 }
1882
1883 /**
1884  * Set the iconified state of a window.
1885  *
1886  * @param obj The window object
1887  * @param iconified If true, the window is iconified
1888  *
1889  * @ingroup Win
1890  */
1891 EAPI void
1892 elm_win_iconified_set(Evas_Object *obj, Eina_Bool iconified)
1893 {
1894    Elm_Win *win;
1895    ELM_CHECK_WIDTYPE(obj, widtype);
1896    win = elm_widget_data_get(obj);
1897    if (!win) return;
1898    ecore_evas_iconified_set(win->ee, iconified);
1899 #ifdef HAVE_ELEMENTARY_X
1900    _elm_win_xwin_update(win);
1901 #endif
1902 }
1903
1904 /**
1905  * Get the iconified state of a window.
1906  *
1907  * @param obj The window object
1908  * @return If true, the window is iconified
1909  *
1910  * @ingroup Win
1911  */
1912 EAPI Eina_Bool
1913 elm_win_iconified_get(const Evas_Object *obj)
1914 {
1915    Elm_Win *win;
1916    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1917    win = elm_widget_data_get(obj);
1918    if (!win) return EINA_FALSE;
1919    return ecore_evas_iconified_get(win->ee);
1920 }
1921
1922 /**
1923  * Set the layer of the window.
1924  *
1925  * @param obj The window object
1926  * @param layer The layer of the window
1927  *
1928  * @ingroup Win
1929  */
1930 EAPI void
1931 elm_win_layer_set(Evas_Object *obj, int layer)
1932 {
1933    Elm_Win *win;
1934    ELM_CHECK_WIDTYPE(obj, widtype);
1935    win = elm_widget_data_get(obj);
1936    if (!win) return;
1937    ecore_evas_layer_set(win->ee, layer);
1938 #ifdef HAVE_ELEMENTARY_X
1939    _elm_win_xwin_update(win);
1940 #endif
1941 }
1942
1943 /**
1944  * Get the layer of the window.
1945  *
1946  * @param obj The window object
1947  * @return The layer of the window
1948  *
1949  * @ingroup Win
1950  */
1951 EAPI int
1952 elm_win_layer_get(const Evas_Object *obj)
1953 {
1954    Elm_Win *win;
1955    ELM_CHECK_WIDTYPE(obj, widtype) -1;
1956    win = elm_widget_data_get(obj);
1957    if (!win) return -1;
1958    return ecore_evas_layer_get(win->ee);
1959 }
1960
1961 /**
1962  * Set the rotation of the window.
1963  *
1964  * @param obj The window object
1965  * @param rotation The rotation of the window, in degrees (0-360)
1966  *
1967  * @ingroup Win
1968  */
1969 EAPI void
1970 elm_win_rotation_set(Evas_Object *obj, int rotation)
1971 {
1972    Elm_Win *win;
1973    ELM_CHECK_WIDTYPE(obj, widtype);
1974    win = elm_widget_data_get(obj);
1975    if (!win) return;
1976    if (win->rot == rotation) return;
1977    win->rot = rotation;
1978    ecore_evas_rotation_set(win->ee, rotation);
1979    evas_object_size_hint_min_set(obj, -1, -1);
1980    evas_object_size_hint_max_set(obj, -1, -1);
1981    _elm_win_eval_subobjs(obj);
1982 #ifdef HAVE_ELEMENTARY_X
1983    _elm_win_xwin_update(win);
1984 #endif
1985 }
1986
1987 /**
1988  * Rotates the window and resizes it
1989  *
1990  * @param obj The window object
1991  * @param layer The rotation of the window in degrees (0-360)
1992  *
1993  * @ingroup Win
1994  */
1995 EAPI void
1996 elm_win_rotation_with_resize_set(Evas_Object *obj, int rotation)
1997 {
1998    Elm_Win *win;
1999    ELM_CHECK_WIDTYPE(obj, widtype);
2000    win = elm_widget_data_get(obj);
2001    if (!win) return;
2002    if (win->rot == rotation) return;
2003    win->rot = rotation;
2004    ecore_evas_rotation_with_resize_set(win->ee, rotation);
2005    evas_object_size_hint_min_set(obj, -1, -1);
2006    evas_object_size_hint_max_set(obj, -1, -1);
2007    _elm_win_eval_subobjs(obj);
2008 #ifdef HAVE_ELEMENTARY_X
2009    _elm_win_xwin_update(win);
2010 #endif
2011 }
2012
2013 /**
2014  * Get the rotation of the window.
2015  *
2016  * @param obj The window object
2017  * @return The rotation of the window in degrees (0-360)
2018  *
2019  * @ingroup Win
2020  */
2021 EAPI int
2022 elm_win_rotation_get(const Evas_Object *obj)
2023 {
2024    Elm_Win *win;
2025    ELM_CHECK_WIDTYPE(obj, widtype) -1;
2026    win = elm_widget_data_get(obj);
2027    if (!win) return -1;
2028    return win->rot;
2029 }
2030
2031 /**
2032  * Set the sticky state of the window.
2033  *
2034  * @param obj The window object
2035  * @param sticky If true, the window's sticky state is enabled
2036  *
2037  * @ingroup Win
2038  */
2039 EAPI void
2040 elm_win_sticky_set(Evas_Object *obj, Eina_Bool sticky)
2041 {
2042    Elm_Win *win;
2043    ELM_CHECK_WIDTYPE(obj, widtype);
2044    win = elm_widget_data_get(obj);
2045    if (!win) return;
2046    ecore_evas_sticky_set(win->ee, sticky);
2047 #ifdef HAVE_ELEMENTARY_X
2048    _elm_win_xwin_update(win);
2049 #endif
2050 }
2051
2052 /**
2053  * Get the sticky state of the window.
2054  *
2055  * @param obj The window object
2056  * @return If true, the window's sticky state is enabled
2057  *
2058  * @ingroup Win
2059  */
2060 EAPI Eina_Bool
2061 elm_win_sticky_get(const Evas_Object *obj)
2062 {
2063    Elm_Win *win;
2064    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2065    win = elm_widget_data_get(obj);
2066    if (!win) return EINA_FALSE;
2067    return ecore_evas_sticky_get(win->ee);
2068 }
2069
2070 /**
2071  * Sets the keyboard mode of the window.
2072  *
2073  * @param obj The window object
2074  * @param mode The mode to set; one of:
2075  * ELM_WIN_KEYBOARD_UNKNOWN
2076  * ELM_WIN_KEYBOARD_OFF
2077  * ELM_WIN_KEYBOARD_ON
2078  * ELM_WIN_KEYBOARD_ALPHA
2079  * ELM_WIN_KEYBOARD_NUMERIC
2080  * ELM_WIN_KEYBOARD_PIN
2081  * ELM_WIN_KEYBOARD_PHONE_NUMBER
2082  * ELM_WIN_KEYBOARD_HEX
2083  * ELM_WIN_KEYBOARD_TERMINAL
2084  * ELM_WIN_KEYBOARD_PASSWORD
2085  * ELM_WIN_KEYBOARD_IP
2086  * ELM_WIN_KEYBOARD_HOST
2087  * ELM_WIN_KEYBOARD_FILE
2088  * ELM_WIN_KEYBOARD_URL
2089  * ELM_WIN_KEYBOARD_KEYPAD
2090  * ELM_WIN_KEYBOARD_J2ME
2091  *
2092  * @ingroup Win
2093  */
2094 EAPI void
2095 elm_win_keyboard_mode_set(Evas_Object *obj, Elm_Win_Keyboard_Mode mode)
2096 {
2097    Elm_Win *win;
2098    ELM_CHECK_WIDTYPE(obj, widtype);
2099    win = elm_widget_data_get(obj);
2100    if (!win) return;
2101    if (mode == win->kbdmode) return;
2102 #ifdef HAVE_ELEMENTARY_X
2103    _elm_win_xwindow_get(win);
2104 #endif
2105    win->kbdmode = mode;
2106 #ifdef HAVE_ELEMENTARY_X
2107    if (win->xwin)
2108      ecore_x_e_virtual_keyboard_state_set
2109         (win->xwin, (Ecore_X_Virtual_Keyboard_State)win->kbdmode);
2110 #endif
2111 }
2112
2113 /**
2114  * Gets the keyboard mode of the window.
2115  *
2116  * @param obj The window object
2117  * @return The mode; one of:
2118  * ELM_WIN_KEYBOARD_UNKNOWN
2119  * ELM_WIN_KEYBOARD_OFF
2120  * ELM_WIN_KEYBOARD_ON
2121  * ELM_WIN_KEYBOARD_ALPHA
2122  * ELM_WIN_KEYBOARD_NUMERIC
2123  * ELM_WIN_KEYBOARD_PIN
2124  * ELM_WIN_KEYBOARD_PHONE_NUMBER
2125  * ELM_WIN_KEYBOARD_HEX
2126  * ELM_WIN_KEYBOARD_TERMINAL
2127  * ELM_WIN_KEYBOARD_PASSWORD
2128  * ELM_WIN_KEYBOARD_IP
2129  * ELM_WIN_KEYBOARD_HOST
2130  * ELM_WIN_KEYBOARD_FILE
2131  * ELM_WIN_KEYBOARD_URL
2132  * ELM_WIN_KEYBOARD_KEYPAD
2133  * ELM_WIN_KEYBOARD_J2ME
2134  *
2135  * @ingroup Win
2136  */
2137 EAPI Elm_Win_Keyboard_Mode
2138 elm_win_keyboard_mode_get(const Evas_Object *obj)
2139 {
2140    Elm_Win *win;
2141    ELM_CHECK_WIDTYPE(obj, widtype) ELM_WIN_KEYBOARD_UNKNOWN;
2142    win = elm_widget_data_get(obj);
2143    if (!win) return ELM_WIN_KEYBOARD_UNKNOWN;
2144    return win->kbdmode;
2145 }
2146
2147 /**
2148  * Sets whether the window is a keyboard.
2149  *
2150  * @param obj The window object
2151  * @param is_keyboard If true, the window is a virtual keyboard
2152  *
2153  * @ingroup Win
2154  */
2155 EAPI void
2156 elm_win_keyboard_win_set(Evas_Object *obj, Eina_Bool is_keyboard)
2157 {
2158    Elm_Win *win;
2159    ELM_CHECK_WIDTYPE(obj, widtype);
2160    win = elm_widget_data_get(obj);
2161    if (!win) return;
2162 #ifdef HAVE_ELEMENTARY_X
2163    _elm_win_xwindow_get(win);
2164    if (win->xwin)
2165      ecore_x_e_virtual_keyboard_set(win->xwin, is_keyboard);
2166 #endif
2167 }
2168
2169 /**
2170  * Gets whether the window is a keyboard.
2171  *
2172  * @param obj The window object
2173  * @return If the window is a virtual keyboard
2174  *
2175  * @ingroup Win
2176  */
2177 EAPI Eina_Bool
2178 elm_win_keyboard_win_get(const Evas_Object *obj)
2179 {
2180    Elm_Win *win;
2181    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2182    win = elm_widget_data_get(obj);
2183    if (!win) return EINA_FALSE;
2184 #ifdef HAVE_ELEMENTARY_X
2185    _elm_win_xwindow_get(win);
2186    if (win->xwin)
2187      return ecore_x_e_virtual_keyboard_get(win->xwin);
2188 #endif
2189    return EINA_FALSE;
2190 }
2191
2192 /**
2193  * Get the screen position of a window.
2194  *
2195  * @param obj The window object
2196  * @param x The int to store the x coordinate to
2197  * @param y The int to store the y coordinate to
2198  *
2199  * @ingroup Win
2200  */
2201 EAPI void
2202 elm_win_screen_position_get(const Evas_Object *obj, int *x, int *y)
2203 {
2204    Elm_Win *win;
2205    ELM_CHECK_WIDTYPE(obj, widtype);
2206    win = elm_widget_data_get(obj);
2207    if (!win) return;
2208    if (x) *x = win->screen.x;
2209    if (y) *y = win->screen.y;
2210 }
2211
2212 /**
2213  * Set if this window is an illume conformant window
2214  *
2215  * @param obj The window object
2216  * @param conformant The conformant flag (1 = conformant, 0 = non-conformant)
2217  *
2218  * @ingroup Win
2219  */
2220 EAPI void
2221 elm_win_conformant_set(Evas_Object *obj, Eina_Bool conformant)
2222 {
2223    Elm_Win *win;
2224    ELM_CHECK_WIDTYPE(obj, widtype);
2225    win = elm_widget_data_get(obj);
2226    if (!win) return;
2227 #ifdef HAVE_ELEMENTARY_X
2228    _elm_win_xwindow_get(win);
2229    if (win->xwin)
2230      ecore_x_e_illume_conformant_set(win->xwin, conformant);
2231 #endif
2232 }
2233
2234 /**
2235  * Get if this window is an illume conformant window
2236  *
2237  * @param obj The window object
2238  * @return A boolean if this window is illume conformant or not
2239  *
2240  * @ingroup Win
2241  */
2242 EAPI Eina_Bool
2243 elm_win_conformant_get(const Evas_Object *obj)
2244 {
2245    Elm_Win *win;
2246    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2247    win = elm_widget_data_get(obj);
2248    if (!win) return EINA_FALSE;
2249 #ifdef HAVE_ELEMENTARY_X
2250    _elm_win_xwindow_get(win);
2251    if (win->xwin)
2252      return ecore_x_e_illume_conformant_get(win->xwin);
2253 #endif
2254    return EINA_FALSE;
2255 }
2256
2257 /**
2258  * Set a window to be an illume quickpanel window
2259  *
2260  * By default window objects are not quickpanel windows.
2261  *
2262  * @param obj The window object
2263  * @param quickpanel The quickpanel flag (1 = quickpanel, 0 = normal window)
2264  *
2265  * @ingroup Win
2266  */
2267 EAPI void
2268 elm_win_quickpanel_set(Evas_Object *obj, Eina_Bool quickpanel)
2269 {
2270    Elm_Win *win;
2271    ELM_CHECK_WIDTYPE(obj, widtype);
2272    win = elm_widget_data_get(obj);
2273    if (!win) return;
2274 #ifdef HAVE_ELEMENTARY_X
2275    _elm_win_xwindow_get(win);
2276    if (win->xwin)
2277      {
2278         ecore_x_e_illume_quickpanel_set(win->xwin, quickpanel);
2279         if (quickpanel)
2280           {
2281              Ecore_X_Window_State states[2];
2282
2283              states[0] = ECORE_X_WINDOW_STATE_SKIP_TASKBAR;
2284              states[1] = ECORE_X_WINDOW_STATE_SKIP_PAGER;
2285              ecore_x_netwm_window_state_set(win->xwin, states, 2);
2286              ecore_x_icccm_hints_set(win->xwin, 0, 0, 0, 0, 0, 0, 0);
2287           }
2288      }
2289 #endif
2290 }
2291
2292 /**
2293  * Get if this window is a quickpanel or not
2294  *
2295  * @param obj The window object
2296  * @return A boolean if this window is a quickpanel or not
2297  *
2298  * @ingroup Win
2299  */
2300 EAPI Eina_Bool
2301 elm_win_quickpanel_get(const Evas_Object *obj)
2302 {
2303    Elm_Win *win;
2304    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2305    win = elm_widget_data_get(obj);
2306    if (!win) return EINA_FALSE;
2307 #ifdef HAVE_ELEMENTARY_X
2308    _elm_win_xwindow_get(win);
2309    if (win->xwin)
2310      return ecore_x_e_illume_quickpanel_get(win->xwin);
2311 #endif
2312    return EINA_FALSE;
2313 }
2314
2315 /**
2316  * Set the major priority of a quickpanel window
2317  *
2318  * @param obj The window object
2319  * @param priority The major priority for this quickpanel
2320  *
2321  * @ingroup Win
2322  */
2323 EAPI void
2324 elm_win_quickpanel_priority_major_set(Evas_Object *obj, int priority)
2325 {
2326    Elm_Win *win;
2327    ELM_CHECK_WIDTYPE(obj, widtype);
2328    win = elm_widget_data_get(obj);
2329    if (!win) return;
2330 #ifdef HAVE_ELEMENTARY_X
2331    _elm_win_xwindow_get(win);
2332    if (win->xwin)
2333      ecore_x_e_illume_quickpanel_priority_major_set(win->xwin, priority);
2334 #endif
2335 }
2336
2337 /**
2338  * Get the major priority of a quickpanel window
2339  *
2340  * @param obj The window object
2341  * @return The major priority of this quickpanel
2342  *
2343  * @ingroup Win
2344  */
2345 EAPI int
2346 elm_win_quickpanel_priority_major_get(const Evas_Object *obj)
2347 {
2348    Elm_Win *win;
2349    ELM_CHECK_WIDTYPE(obj, widtype) -1;
2350    win = elm_widget_data_get(obj);
2351    if (!win) return -1;
2352 #ifdef HAVE_ELEMENTARY_X
2353    _elm_win_xwindow_get(win);
2354    if (win->xwin)
2355      return ecore_x_e_illume_quickpanel_priority_major_get(win->xwin);
2356 #endif
2357    return -1;
2358 }
2359
2360 /**
2361  * Set the minor priority of a quickpanel window
2362  *
2363  * @param obj The window object
2364  * @param priority The minor priority for this quickpanel
2365  *
2366  * @ingroup Win
2367  */
2368 EAPI void
2369 elm_win_quickpanel_priority_minor_set(Evas_Object *obj, int priority)
2370 {
2371    Elm_Win *win;
2372    ELM_CHECK_WIDTYPE(obj, widtype);
2373    win = elm_widget_data_get(obj);
2374    if (!win) return;
2375 #ifdef HAVE_ELEMENTARY_X
2376    _elm_win_xwindow_get(win);
2377    if (win->xwin)
2378      ecore_x_e_illume_quickpanel_priority_minor_set(win->xwin, priority);
2379 #endif
2380 }
2381
2382 /**
2383  * Get the minor priority of a quickpanel window
2384  *
2385  * @param obj The window object
2386  * @return The minor priority of this quickpanel
2387  *
2388  * @ingroup Win
2389  */
2390 EAPI int
2391 elm_win_quickpanel_priority_minor_get(const Evas_Object *obj)
2392 {
2393    Elm_Win *win;
2394    ELM_CHECK_WIDTYPE(obj, widtype) -1;
2395    win = elm_widget_data_get(obj);
2396    if (!win) return -1;
2397 #ifdef HAVE_ELEMENTARY_X
2398    _elm_win_xwindow_get(win);
2399    if (win->xwin)
2400      return ecore_x_e_illume_quickpanel_priority_minor_get(win->xwin);
2401 #endif
2402    return -1;
2403 }
2404
2405 /**
2406  * Set which zone this quickpanel should appear in
2407  *
2408  * @param obj The window object
2409  * @param zone The requested zone for this quickpanel
2410  *
2411  * @ingroup Win
2412  */
2413 EAPI void
2414 elm_win_quickpanel_zone_set(Evas_Object *obj, int zone)
2415 {
2416    Elm_Win *win;
2417    ELM_CHECK_WIDTYPE(obj, widtype);
2418    win = elm_widget_data_get(obj);
2419    if (!win) return;
2420 #ifdef HAVE_ELEMENTARY_X
2421    _elm_win_xwindow_get(win);
2422    if (win->xwin)
2423      ecore_x_e_illume_quickpanel_zone_set(win->xwin, zone);
2424 #endif
2425 }
2426
2427 /**
2428  * Get which zone this quickpanel should appear in
2429  *
2430  * @param obj The window object
2431  * @return The requested zone for this quickpanel
2432  *
2433  * @ingroup Win
2434  */
2435 EAPI int
2436 elm_win_quickpanel_zone_get(const Evas_Object *obj)
2437 {
2438    Elm_Win *win;
2439    ELM_CHECK_WIDTYPE(obj, widtype) 0;
2440    win = elm_widget_data_get(obj);
2441    if (!win) return 0;
2442 #ifdef HAVE_ELEMENTARY_X
2443    _elm_win_xwindow_get(win);
2444    if (win->xwin)
2445      return ecore_x_e_illume_quickpanel_zone_get(win->xwin);
2446 #endif
2447    return 0;
2448 }
2449
2450 /**
2451  * Set the window to be skipped by keyboard focus
2452  *
2453  * This sets the window to be skipped by normal keyboard input. This means
2454  * a window manager will be asked to not focus this window as well as omit
2455  * it from things like the taskbar, pager, "alt-tab" list etc. etc.
2456  *
2457  * Call this and enable it on a window BEFORE you show it for the first time,
2458  * otherwise it may have no effect.
2459  *
2460  * Use this for windows that have only output information or might only be
2461  * interacted with by the mouse or fingers, and never for typing input.
2462  * Be careful that this may have side-effects like making the window
2463  * non-accessible in some cases unless the window is specially handled. Use
2464  * this with care.
2465  *
2466  * @param obj The window object
2467  * @param skip The skip flag state (EINA_TRUE if it is to be skipped)
2468  *
2469  * @ingroup Win
2470  */
2471 EAPI void
2472 elm_win_prop_focus_skip_set(Evas_Object *obj, Eina_Bool skip)
2473 {
2474    Elm_Win *win;
2475    ELM_CHECK_WIDTYPE(obj, widtype);
2476    win = elm_widget_data_get(obj);
2477    if (!win) return;
2478 #ifdef HAVE_ELEMENTARY_X
2479    _elm_win_xwindow_get(win);
2480    if (skip)
2481      {
2482         if (win->xwin)
2483           {
2484              Ecore_X_Window_State states[2];
2485
2486              ecore_x_icccm_hints_set(win->xwin, 0, 0, 0, 0, 0, 0, 0);
2487              states[0] = ECORE_X_WINDOW_STATE_SKIP_TASKBAR;
2488              states[1] = ECORE_X_WINDOW_STATE_SKIP_PAGER;
2489              ecore_x_netwm_window_state_set(win->xwin, states, 2);
2490           }
2491      }
2492 #endif
2493 }
2494
2495 /**
2496  * Send a command to the windowing environment
2497  *
2498  * This is intended to work in touchscreen or small screen device environments
2499  * where there is a more simplistic window management policy in place. This
2500  * uses the window object indicated to select which part of the environment
2501  * to control (the part that this window lives in), and provides a command
2502  * and an optional parameter structure (use NULL for this if not needed).
2503  *
2504  * @param obj The window object that lives in the environment to control
2505  * @param command The command to send
2506  * @param params Optional parameters for the command
2507  *
2508  * @ingroup Win
2509  */
2510 EAPI void
2511 elm_win_illume_command_send(Evas_Object *obj, Elm_Illume_Command command, void *params __UNUSED__)
2512 {
2513    Elm_Win *win;
2514    ELM_CHECK_WIDTYPE(obj, widtype);
2515    win = elm_widget_data_get(obj);
2516    if (!win) return;
2517 #ifdef HAVE_ELEMENTARY_X
2518    _elm_win_xwindow_get(win);
2519    if (win->xwin)
2520      {
2521         switch (command)
2522           {
2523            case ELM_ILLUME_COMMAND_FOCUS_BACK:
2524               ecore_x_e_illume_focus_back_send(win->xwin);
2525               break;
2526            case ELM_ILLUME_COMMAND_FOCUS_FORWARD:
2527               ecore_x_e_illume_focus_forward_send(win->xwin);
2528               break;
2529            case ELM_ILLUME_COMMAND_FOCUS_HOME:
2530               ecore_x_e_illume_focus_home_send(win->xwin);
2531               break;
2532            case ELM_ILLUME_COMMAND_CLOSE:
2533               ecore_x_e_illume_close_send(win->xwin);
2534               break;
2535            default:
2536               break;
2537           }
2538      }
2539 #endif
2540 }
2541
2542 /**
2543  * Get the inlined image object handle
2544  *
2545  * When you create a window with elm_win_add() of type ELM_WIN_INLINED_IMAGE,
2546  * then the window is in fact an evas image object inlined in the parent
2547  * canvas. You can get this object (be careful to not manipulate it as it
2548  * is under control of elementary), and use it to do things like get pixel
2549  * data, save the image to a file, etc.
2550  *
2551  * @param obj The window object to get the inlined image from
2552  * @return The inlined image object, or NULL if none exists
2553  *
2554  * @ingroup Win
2555  */
2556 EAPI Evas_Object *
2557 elm_win_inlined_image_object_get(Evas_Object *obj)
2558 {
2559    Elm_Win *win;
2560    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2561    win = elm_widget_data_get(obj);
2562    if (!win) return NULL;
2563    return win->img_obj;
2564 }
2565
2566 /**
2567  * Set the enabled status for the focus highlight in a window
2568  *
2569  * This function will enable or disable the focus highlight only for the
2570  * given window, regardless of the global setting for it
2571  *
2572  * @param obj The window where to enable the highlight
2573  * @param enabled The enabled value for the highlight
2574  *
2575  * @ingroup Win
2576  */
2577 EAPI void
2578 elm_win_focus_highlight_enabled_set(Evas_Object *obj, Eina_Bool enabled)
2579 {
2580    Elm_Win *win;
2581
2582    ELM_CHECK_WIDTYPE(obj, widtype);
2583
2584    win = elm_widget_data_get(obj);
2585    enabled = !!enabled;
2586    if (win->focus_highlight.enabled == enabled)
2587      return;
2588
2589    win->focus_highlight.enabled = enabled;
2590
2591    if (win->focus_highlight.enabled)
2592      _elm_win_focus_highlight_init(win);
2593    else
2594      _elm_win_focus_highlight_shutdown(win);
2595 }
2596
2597 /**
2598  * Get the enabled value of the focus highlight for this window
2599  *
2600  * @param obj The window in which to check if the focus highlight is enabled
2601  *
2602  * @return EINA_TRUE if enabled, EINA_FALSE otherwise
2603  *
2604  * @ingroup Win
2605  */
2606 EAPI Eina_Bool
2607 elm_win_focus_highlight_enabled_get(const Evas_Object *obj)
2608 {
2609    Elm_Win *win;
2610
2611    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2612
2613    win = elm_widget_data_get(obj);
2614    return win->focus_highlight.enabled;
2615 }
2616
2617 /**
2618  * Set the style for the focus highlight on this window
2619  *
2620  * Sets the style to use for theming the highlight of focused objects on
2621  * the given window. If @p style is NULL, the default will be used.
2622  *
2623  * @param obj The window where to set the style
2624  * @param style The style to set
2625  *
2626  * @ingroup Win
2627  */
2628 EAPI void
2629 elm_win_focus_highlight_style_set(Evas_Object *obj, const char *style)
2630 {
2631    Elm_Win *win;
2632
2633    ELM_CHECK_WIDTYPE(obj, widtype);
2634
2635    win = elm_widget_data_get(obj);
2636    eina_stringshare_replace(&win->focus_highlight.style, style);
2637    win->focus_highlight.changed_theme = EINA_TRUE;
2638    _elm_win_focus_highlight_reconfigure_job_start(win);
2639 }
2640
2641 /**
2642  * Get the style set for the focus highlight object
2643  *
2644  * Gets the style set for this windows highilght object, or NULL if none
2645  * is set.
2646  *
2647  * @param obj The window to retrieve the highlights style from
2648  *
2649  * @return The style set or NULL if none was. Default is used in that case.
2650  *
2651  * @ingroup Win
2652  */
2653 EAPI const char *
2654 elm_win_focus_highlight_style_get(const Evas_Object *obj)
2655 {
2656    Elm_Win *win;
2657
2658    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2659
2660    win = elm_widget_data_get(obj);
2661    return win->focus_highlight.style;
2662 }
2663
2664 typedef struct _Widget_Data Widget_Data;
2665
2666 struct _Widget_Data
2667 {
2668    Evas_Object *frm;
2669    Evas_Object *content;
2670 };
2671
2672 static void _del_hook(Evas_Object *obj);
2673 static void _theme_hook(Evas_Object *obj);
2674 static void _sizing_eval(Evas_Object *obj);
2675 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
2676 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
2677
2678 static const char *widtype2 = NULL;
2679
2680 static void
2681 _del_hook(Evas_Object *obj)
2682 {
2683    Widget_Data *wd = elm_widget_data_get(obj);
2684    if (!wd) return;
2685    free(wd);
2686 }
2687
2688 static void
2689 _theme_hook(Evas_Object *obj)
2690 {
2691    Widget_Data *wd = elm_widget_data_get(obj);
2692    _elm_theme_object_set(obj, wd->frm, "win", "inwin", elm_widget_style_get(obj));
2693    if (wd->content)
2694      edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->content);
2695    _sizing_eval(obj);
2696 }
2697
2698 static Eina_Bool
2699 _elm_inwin_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
2700 {
2701    Widget_Data *wd = elm_widget_data_get(obj);
2702
2703    if (!wd)
2704      return EINA_FALSE;
2705
2706    /* Try Focus cycle in subitem */
2707    if (wd->content)
2708      {
2709         elm_widget_focus_next_get(wd->content, dir, next);
2710         if (*next)
2711           return EINA_TRUE;
2712      }
2713
2714    *next = (Evas_Object *)obj;
2715    return EINA_FALSE;
2716 }
2717
2718 static void
2719 _sizing_eval(Evas_Object *obj)
2720 {
2721    Widget_Data *wd = elm_widget_data_get(obj);
2722    Evas_Coord minw = -1, minh = -1;
2723
2724    evas_object_size_hint_min_get(wd->content, &minw, &minh);
2725    edje_object_size_min_calc(wd->frm, &minw, &minh);
2726    evas_object_size_hint_min_set(obj, minw, minh);
2727    evas_object_size_hint_max_set(obj, -1, -1);
2728 }
2729
2730 static void
2731 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2732 {
2733    _sizing_eval(data);
2734 }
2735
2736 static void
2737 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
2738 {
2739    Widget_Data *wd = elm_widget_data_get(obj);
2740    Evas_Object *sub = event_info;
2741    if (sub == wd->content)
2742      {
2743         evas_object_event_callback_del_full
2744            (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
2745         wd->content = NULL;
2746         _sizing_eval(obj);
2747      }
2748 }
2749
2750 /**
2751  * @defgroup Inwin Inwin
2752  *
2753  * An inwin is a window inside a window that is useful for a quick popup.  It does not hover.
2754  */
2755 EAPI Evas_Object *
2756 elm_win_inwin_add(Evas_Object *obj)
2757 {
2758    Evas_Object *obj2;
2759    Widget_Data *wd;
2760    Elm_Win *win;
2761
2762    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2763    win = elm_widget_data_get(obj);
2764    if (!win) return NULL;
2765    wd = ELM_NEW(Widget_Data);
2766    obj2 = elm_widget_add(win->evas);
2767    elm_widget_type_set(obj2, "inwin");
2768    ELM_SET_WIDTYPE(widtype2, "inwin");
2769    elm_widget_sub_object_add(obj, obj2);
2770    evas_object_size_hint_weight_set(obj2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2771    evas_object_size_hint_align_set(obj2, EVAS_HINT_FILL, EVAS_HINT_FILL);
2772    elm_win_resize_object_add(obj, obj2);
2773
2774    elm_widget_data_set(obj2, wd);
2775    elm_widget_del_hook_set(obj2, _del_hook);
2776    elm_widget_theme_hook_set(obj2, _theme_hook);
2777    elm_widget_focus_next_hook_set(obj2, _elm_inwin_focus_next_hook);
2778    elm_widget_can_focus_set(obj2, EINA_TRUE);
2779    elm_widget_highlight_ignore_set(obj2, EINA_TRUE);
2780
2781    wd->frm = edje_object_add(win->evas);
2782    _elm_theme_object_set(obj, wd->frm, "win", "inwin", "default");
2783    elm_widget_resize_object_set(obj2, wd->frm);
2784
2785    evas_object_smart_callback_add(obj2, "sub-object-del", _sub_del, obj2);
2786
2787    _sizing_eval(obj2);
2788    return obj2;
2789 }
2790
2791 /**
2792  * Activates an inwin object
2793  *
2794  * @param obj The inwin to activate
2795  *
2796  * @ingroup Inwin
2797  */
2798 EAPI void
2799 elm_win_inwin_activate(Evas_Object *obj)
2800 {
2801    ELM_CHECK_WIDTYPE(obj, widtype2);
2802    Widget_Data *wd = elm_widget_data_get(obj);
2803    if (!wd) return;
2804    evas_object_raise(obj);
2805    evas_object_show(obj);
2806    edje_object_signal_emit(wd->frm, "elm,action,show", "elm");
2807    elm_object_focus(obj);
2808 }
2809
2810 /**
2811  * Set the content of an inwin object.
2812  *
2813  * Once the content object is set, a previously set one will be deleted.
2814  * If you want to keep that old content object, use the
2815  * elm_win_inwin_content_unset() function.
2816  *
2817  * @param obj The inwin object
2818  * @param content The object to set as content
2819  *
2820  * @ingroup Inwin
2821  */
2822 EAPI void
2823 elm_win_inwin_content_set(Evas_Object *obj, Evas_Object *content)
2824 {
2825    ELM_CHECK_WIDTYPE(obj, widtype2);
2826    Widget_Data *wd = elm_widget_data_get(obj);
2827    if (!wd) return;
2828    if (wd->content == content) return;
2829    if (wd->content) evas_object_del(wd->content);
2830    wd->content = content;
2831    if (content)
2832      {
2833         elm_widget_sub_object_add(obj, content);
2834         evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
2835                                        _changed_size_hints, obj);
2836         edje_object_part_swallow(wd->frm, "elm.swallow.content", content);
2837      }
2838    _sizing_eval(obj);
2839 }
2840
2841 /**
2842  * Get the content of an inwin object.
2843  *
2844  * Return the content object which is set for this widget.
2845  *
2846  * @param obj The inwin object
2847  * @return The content that is being used
2848  *
2849  * @ingroup Inwin
2850  */
2851 EAPI Evas_Object *
2852 elm_win_inwin_content_get(const Evas_Object *obj)
2853 {
2854    ELM_CHECK_WIDTYPE(obj, widtype2) NULL;
2855    Widget_Data *wd = elm_widget_data_get(obj);
2856    if (!wd) return NULL;
2857    return wd->content;
2858 }
2859
2860 /**
2861  * Unset the content of an inwin object.
2862  *
2863  * Unparent and return the content object which was set for this widget.
2864  *
2865  * @param obj The inwin object
2866  * @return The content that was being used
2867  *
2868  * @ingroup Inwin
2869  */
2870 EAPI Evas_Object *
2871 elm_win_inwin_content_unset(Evas_Object *obj)
2872 {
2873    ELM_CHECK_WIDTYPE(obj, widtype2) NULL;
2874    Widget_Data *wd = elm_widget_data_get(obj);
2875    if (!wd) return NULL;
2876    if (!wd->content) return NULL;
2877    Evas_Object *content = wd->content;
2878    elm_widget_sub_object_del(obj, wd->content);
2879    edje_object_part_unswallow(wd->frm, wd->content);
2880    wd->content = NULL;
2881    return content;
2882 }
2883
2884 /* windowing spcific calls - shall we do this differently? */
2885
2886 static Ecore_X_Window
2887 _elm_ee_win_get(const Evas_Object *obj)
2888 {
2889    if (!obj) return 0;
2890 #ifdef HAVE_ELEMENTARY_X
2891    Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
2892    if (ee) return (Ecore_X_Window)ecore_evas_window_get(ee);
2893 #endif
2894    return 0;
2895 }
2896
2897 /**
2898  * Get the Ecore_X_Window of an Evas_Object
2899  *
2900  * @param obj The object
2901  *
2902  * @return The Ecore_X_Window of @p obj
2903  *
2904  * @ingroup Win
2905  */
2906 EAPI Ecore_X_Window
2907 elm_win_xwindow_get(const Evas_Object *obj)
2908 {
2909    Ecore_X_Window xwin = 0;
2910    Elm_Win *win;
2911    const char *type;
2912
2913    if (!obj) return 0;
2914    type = elm_widget_type_get(obj);
2915    if (!type) return 0;
2916    if (type != widtype) return _elm_ee_win_get(obj);
2917 #ifdef HAVE_ELEMENTARY_X
2918    win = elm_widget_data_get(obj);
2919    if (!win) return xwin;
2920    if (win->xwin) return win->xwin;
2921    if (win->parent) return elm_win_xwindow_get(win->parent);
2922 #endif
2923    return xwin;
2924    win = NULL;
2925 }