Merge branch 'master' of juyung.seo@165.213.180.234:/git/slp2.0/slp2.0-pkgs/EFL-pkgs...
[framework/uifw/elementary.git] / src / lib / elm_mapbuf.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup Mapbuf Mapbuf
6  * @ingroup Elementary
7  *
8  * This holds 1 content object and uses an Evas Map to move/resize etc. it.
9  */
10
11 typedef struct _Widget_Data Widget_Data;
12
13 struct _Widget_Data
14 {
15    Evas_Object *content;
16    Eina_Bool enabled : 1;
17    Eina_Bool alpha : 1;
18    Eina_Bool smooth : 1;
19 };
20
21 static const char *widtype = NULL;
22 static void _del_hook(Evas_Object *obj);
23 static void _theme_hook(Evas_Object *obj);
24 static void _sizing_eval(Evas_Object *obj);
25 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
26 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
27
28 static void
29 _del_hook(Evas_Object *obj)
30 {
31    Widget_Data *wd = elm_widget_data_get(obj);
32    if (!wd) return;
33    free(wd);
34 }
35
36 static void
37 _theme_hook(Evas_Object *obj)
38 {
39    Widget_Data *wd = elm_widget_data_get(obj);
40    if (!wd) return;
41    _sizing_eval(obj);
42 }
43
44 static void
45 _sizing_eval(Evas_Object *obj)
46 {
47    Widget_Data *wd = elm_widget_data_get(obj);
48    Evas_Coord minw = -1, minh = -1;
49    Evas_Coord maxw = -1, maxh = -1;
50    if (!wd) return;
51    if (wd->content)
52      {
53         evas_object_size_hint_min_get(wd->content, &minw, &minh);
54         evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
55      }
56    evas_object_size_hint_min_set(obj, minw, minh);
57    evas_object_size_hint_max_set(obj, maxw, maxh);
58 }
59
60 static void
61 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
62 {
63    Widget_Data *wd = elm_widget_data_get(data);
64    if (!wd) return;
65    _sizing_eval(data);
66 }
67
68 static void
69 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
70 {
71    Widget_Data *wd = elm_widget_data_get(obj);
72    Evas_Object *sub = event_info;
73    if (!wd) return;
74    if (sub == wd->content)
75      {
76         evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
77                                             _changed_size_hints, obj);
78         wd->content = NULL;
79         _sizing_eval(obj);
80      }
81 }
82
83 static void
84 _mapbuf(Evas_Object *obj)
85 {
86    Widget_Data *wd = elm_widget_data_get(obj);
87    Evas_Coord x, y, w, h;
88    if (!wd) return;
89    evas_object_geometry_get(obj, &x, &y, &w, &h);
90    if (wd->enabled)
91      {
92         Evas_Map *m;
93
94         m = evas_map_new(4);
95         evas_map_util_points_populate_from_geometry(m, x, y, w, h, 0);
96         evas_map_smooth_set(m, wd->smooth);
97         evas_map_alpha_set(m, wd->alpha);
98         evas_object_map_set(wd->content, m);
99         evas_object_map_enable_set(wd->content, wd->enabled);
100         evas_map_free(m);
101      }
102    else
103      {
104         evas_object_map_set(wd->content, NULL);
105         evas_object_map_enable_set(wd->content, 0);
106         evas_object_move(wd->content, x, y);
107         evas_object_resize(wd->content, w, h);
108      }
109 }
110
111 static void
112 _configure(Evas_Object *obj)
113 {
114    Widget_Data *wd = elm_widget_data_get(obj);
115    if (!wd) return;
116    if (wd->content)
117      {
118         Evas_Coord x, y, w, h;
119         
120         evas_object_geometry_get(obj, &x, &y, &w, &h);
121         if (!wd->enabled) evas_object_move(wd->content, x, y);
122         evas_object_resize(wd->content, w, h);
123         _mapbuf(obj);
124      }
125 }
126
127 static void
128 _move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
129 {
130    _configure(obj);
131 }
132
133 static void
134 _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
135 {    
136    _configure(obj);
137 }
138
139 /**
140  * Add a new mapbuf to the parent
141  *
142  * @param parent The parent object
143  * @return The new object or NULL if it cannot be created
144  *
145  * @ingroup Mapbuf
146  */
147 EAPI Evas_Object *
148 elm_mapbuf_add(Evas_Object *parent)
149 {
150    Evas_Object *obj;
151    Evas *e;
152    Widget_Data *wd;
153
154    wd = ELM_NEW(Widget_Data);
155    e = evas_object_evas_get(parent);
156    obj = elm_widget_add(e);
157    ELM_SET_WIDTYPE(widtype, "mapbuf");
158    elm_widget_type_set(obj, "mapbuf");
159    elm_widget_sub_object_add(parent, obj);
160    elm_widget_data_set(obj, wd);
161    elm_widget_del_hook_set(obj, _del_hook);
162    elm_widget_theme_hook_set(obj, _theme_hook);
163
164    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
165    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, NULL);
166    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, NULL);
167
168    wd->enabled = 0;
169    wd->alpha = 1;
170    wd->smooth = 1;
171    
172    _sizing_eval(obj);
173    return obj;
174 }
175
176 /**
177  * Set the mapbuf front content
178  *
179  * @param obj The mapbuf object
180  * @param content The content will be filled in this mapbuf object
181  *
182  * @ingroup Mapbuf
183  */
184 EAPI void
185 elm_mapbuf_content_set(Evas_Object *obj, Evas_Object *content)
186 {
187    ELM_CHECK_WIDTYPE(obj, widtype);
188    Widget_Data *wd = elm_widget_data_get(obj);
189    if (!wd) return;
190    if (wd->content == content) return;
191    if ((wd->content != content) && (wd->content))
192      {
193         elm_widget_sub_object_del(obj, wd->content);
194         evas_object_smart_member_del(wd->content);
195      }
196    wd->content = content;
197    if (content)
198      {
199         elm_widget_sub_object_add(content, obj);
200         evas_object_smart_member_add(content, obj);
201         evas_object_event_callback_add(content,
202                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
203                                        _changed_size_hints, obj);
204         _sizing_eval(obj);
205      }
206    _configure(obj);
207 }
208
209 /**
210  * Set the mapbuf enabled state
211  *
212  * @param obj The mapbuf object
213  * @param enabled The value to set the enabled state to
214  *
215  * @ingroup Mapbuf
216  */
217 EAPI void
218 elm_mapbuf_enabled_set(Evas_Object *obj, Eina_Bool enabled)
219 {
220    ELM_CHECK_WIDTYPE(obj, widtype);
221    Widget_Data *wd = elm_widget_data_get(obj);
222    if (!wd) return;
223    if (wd->enabled == enabled) return;
224    wd->enabled = enabled;
225    _configure(obj);
226 }
227
228 /**
229  * Get the mapbuf enabled state
230  *
231  * @param obj The mapbuf object
232  * @return The value that the enabled state is set to
233  *
234  * @ingroup Mapbuf
235  */
236 EAPI Eina_Bool
237 elm_mapbuf_enabled_get(const Evas_Object *obj)
238 {
239    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
240    Widget_Data *wd = elm_widget_data_get(obj);
241    if (!wd) return EINA_FALSE;
242    return wd->enabled;
243 }
244
245 /**
246  * Sets the mapbuf smooth state
247  *
248  * @param obj The mapbuf object
249  * @param smooth The value of the smooth state of @p obj
250  *
251  * @ingroup Mapbuf
252  */
253 EAPI void
254 elm_mapbuf_smooth_set(Evas_Object *obj, Eina_Bool smooth)
255 {
256    ELM_CHECK_WIDTYPE(obj, widtype);
257    Widget_Data *wd = elm_widget_data_get(obj);
258    if (!wd) return;
259    if (wd->smooth == smooth) return;
260    wd->smooth = smooth;
261    _configure(obj);
262 }
263
264 /**
265  * Gets the mapbuf smooth state
266  *
267  * @param obj The mapbuf object
268  * @return The value of the smooth state of @p obj
269  *
270  * @ingroup Mapbuf
271  */
272 EAPI Eina_Bool
273 elm_mapbuf_smooth_get(const Evas_Object *obj)
274 {
275    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
276    Widget_Data *wd = elm_widget_data_get(obj);
277    if (!wd) return EINA_FALSE;
278    return wd->smooth;
279 }
280
281 /**
282  * Enables/disables the mapbuf alpha channel
283  *
284  * @param obj The mapbuf object
285  * @param alpha The state of the alpha channel
286  *
287  * @ingroup Mapbuf
288  */
289 EAPI void
290 elm_mapbuf_alpha_set(Evas_Object *obj, Eina_Bool alpha)
291 {
292    ELM_CHECK_WIDTYPE(obj, widtype);
293    Widget_Data *wd = elm_widget_data_get(obj);
294    if (!wd) return;
295    if (wd->alpha == alpha) return;
296    wd->alpha = alpha;
297    _configure(obj);
298 }
299
300 /**
301  * Gets the state of the mapbuf alpha channel
302  *
303  * @param obj The mapbuf object
304  * @return The state of the alpha channel
305  *
306  * @ingroup Mapbuf
307  */
308 EAPI Eina_Bool
309 elm_mapbuf_alpha_get(const Evas_Object *obj)
310 {
311    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
312    Widget_Data *wd = elm_widget_data_get(obj);
313    if (!wd) return EINA_FALSE;
314    return wd->alpha;
315 }