tizen 2.3 release
[framework/uifw/elementary.git] / src / lib / elm_inwin.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3 #include "elm_widget_inwin.h"
4
5 EAPI const char ELM_INWIN_SMART_NAME[] = "elm_inwin";
6
7 EVAS_SMART_SUBCLASS_NEW
8   (ELM_INWIN_SMART_NAME, _elm_inwin, Elm_Inwin_Smart_Class,
9   Elm_Layout_Smart_Class, elm_layout_smart_class_get, NULL);
10
11 static const Elm_Layout_Part_Alias_Description _content_aliases[] =
12 {
13    {"default", "elm.swallow.content"},
14    {NULL, NULL}
15 };
16
17 static void
18 _elm_inwin_smart_sizing_eval(Evas_Object *obj)
19 {
20    Evas_Object *content;
21    Evas_Coord minw = -1, minh = -1;
22
23    ELM_INWIN_DATA_GET(obj, sd);
24
25    content = elm_layout_content_get(obj, NULL);
26
27    if (!content) return;
28
29    evas_object_size_hint_min_get(content, &minw, &minh);
30    edje_object_size_min_calc(ELM_WIDGET_DATA(sd)->resize_obj, &minw, &minh);
31
32    evas_object_size_hint_min_set(obj, minw, minh);
33    evas_object_size_hint_max_set(obj, -1, -1);
34 }
35
36 static Eina_Bool
37 _elm_inwin_smart_focus_next(const Evas_Object *obj,
38                             Elm_Focus_Direction dir,
39                             Evas_Object **next)
40 {
41    Evas_Object *content;
42
43    content = elm_layout_content_get(obj, NULL);
44
45    /* attempt to follow focus cycle into sub-object */
46    if (content)
47      {
48         elm_widget_focus_next_get(content, dir, next);
49         if (*next)
50           return EINA_TRUE;
51      }
52
53    *next = (Evas_Object *)obj;
54    return EINA_FALSE;
55 }
56
57 static void
58 _elm_inwin_smart_add(Evas_Object *obj)
59 {
60    EVAS_SMART_DATA_ALLOC(obj, Elm_Inwin_Smart_Data);
61
62    ELM_WIDGET_CLASS(_elm_inwin_parent_sc)->base.add(obj);
63 }
64
65 static void
66 _elm_inwin_smart_parent_set(Evas_Object *obj,
67                             Evas_Object *parent)
68 {
69    elm_win_resize_object_add(parent, obj);
70
71    elm_layout_sizing_eval(obj);
72 }
73
74 static void
75 _elm_inwin_smart_set_user(Elm_Inwin_Smart_Class *sc)
76 {
77    ELM_WIDGET_CLASS(sc)->base.add = _elm_inwin_smart_add;
78
79    ELM_WIDGET_CLASS(sc)->focus_next = _elm_inwin_smart_focus_next;
80    ELM_WIDGET_CLASS(sc)->parent_set = _elm_inwin_smart_parent_set;
81
82    ELM_LAYOUT_CLASS(sc)->sizing_eval = _elm_inwin_smart_sizing_eval;
83
84    ELM_LAYOUT_CLASS(sc)->content_aliases = _content_aliases;
85 }
86
87 EAPI const Elm_Inwin_Smart_Class *
88 elm_inwin_smart_class_get(void)
89 {
90    static Elm_Inwin_Smart_Class _sc =
91      ELM_INWIN_SMART_CLASS_INIT_NAME_VERSION(ELM_INWIN_SMART_NAME);
92    static const Elm_Inwin_Smart_Class *class = NULL;
93
94    if (class)
95      return class;
96
97    _elm_inwin_smart_set(&_sc);
98    class = &_sc;
99
100    return class;
101 }
102
103 EAPI Evas_Object *
104 elm_win_inwin_add(Evas_Object *parent)
105 {
106    Evas_Object *obj;
107
108    if (!parent || !elm_widget_type_check((parent), "elm_win", __func__))
109      return NULL;  /* *has* to have a parent window */
110
111    obj = elm_widget_add(_elm_inwin_smart_class_new(), parent);
112    if (!obj) return NULL;
113
114    if (!elm_widget_sub_object_add(parent, obj))
115      ERR("could not add %p as sub object of %p", obj, parent);
116
117    elm_widget_can_focus_set(obj, EINA_FALSE);
118    elm_widget_highlight_ignore_set(obj, EINA_TRUE);
119
120    evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
121    evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
122    elm_layout_theme_set(obj, "win", "inwin", elm_object_style_get(obj));
123
124    //Tizen Only: This should be removed when eo is applied.
125    ELM_WIDGET_DATA_GET(obj, wsd);
126    wsd->on_create = EINA_FALSE;
127
128    return obj;
129 }
130
131 EAPI void
132 elm_win_inwin_activate(Evas_Object *obj)
133 {
134    ELM_INWIN_CHECK(obj);
135    ELM_INWIN_DATA_GET_OR_RETURN(obj, sd);
136
137    evas_object_raise(obj);
138    evas_object_show(obj);
139    edje_object_signal_emit
140      (ELM_WIDGET_DATA(sd)->resize_obj, "elm,action,show", "elm");
141    elm_object_focus_set(obj, EINA_TRUE);
142 }
143
144 EAPI void
145 elm_win_inwin_content_set(Evas_Object *obj,
146                           Evas_Object *content)
147 {
148    ELM_INWIN_CHECK(obj);
149    ELM_INWIN_DATA_GET_OR_RETURN(obj, sd);
150
151    ELM_CONTAINER_CLASS(_elm_inwin_parent_sc)->content_set(obj, NULL, content);
152 }
153
154 EAPI Evas_Object *
155 elm_win_inwin_content_get(const Evas_Object *obj)
156 {
157    ELM_INWIN_CHECK(obj) NULL;
158    ELM_INWIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
159
160    return ELM_CONTAINER_CLASS(_elm_inwin_parent_sc)->content_get(obj, NULL);
161 }
162
163 EAPI Evas_Object *
164 elm_win_inwin_content_unset(Evas_Object *obj)
165 {
166    ELM_INWIN_CHECK(obj) NULL;
167    ELM_INWIN_DATA_GET_OR_RETURN_VAL(obj, sd, NULL);
168
169    return ELM_CONTAINER_CLASS(_elm_inwin_parent_sc)->content_unset(obj, NULL);
170 }