1 #include <Elementary.h>
5 * @defgroup Mapbuf Mapbuf
7 * This holds 1 content object and uses an Evas Map to move/resize etc. it.
10 typedef struct _Widget_Data Widget_Data;
15 Eina_Bool enabled : 1;
20 static const char *widtype = NULL;
21 static void _del_hook(Evas_Object *obj);
22 static void _theme_hook(Evas_Object *obj);
23 static void _sizing_eval(Evas_Object *obj);
24 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
25 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
28 _del_hook(Evas_Object *obj)
30 Widget_Data *wd = elm_widget_data_get(obj);
36 _theme_hook(Evas_Object *obj)
38 Widget_Data *wd = elm_widget_data_get(obj);
44 _sizing_eval(Evas_Object *obj)
46 Widget_Data *wd = elm_widget_data_get(obj);
47 Evas_Coord minw = -1, minh = -1;
48 Evas_Coord maxw = -1, maxh = -1;
52 evas_object_size_hint_min_get(wd->content, &minw, &minh);
53 evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
55 evas_object_size_hint_min_set(obj, minw, minh);
56 evas_object_size_hint_max_set(obj, maxw, maxh);
60 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
62 Widget_Data *wd = elm_widget_data_get(data);
68 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
70 Widget_Data *wd = elm_widget_data_get(obj);
71 Evas_Object *sub = event_info;
73 if (sub == wd->content)
75 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
76 _changed_size_hints, obj);
83 _mapbuf(Evas_Object *obj)
85 Widget_Data *wd = elm_widget_data_get(obj);
86 Evas_Coord x, y, w, h;
88 evas_object_geometry_get(obj, &x, &y, &w, &h);
94 evas_map_util_points_populate_from_geometry(m, x, y, w, h, 0);
95 evas_map_smooth_set(m, wd->smooth);
96 evas_map_alpha_set(m, wd->alpha);
97 evas_object_map_set(wd->content, m);
98 evas_object_map_enable_set(wd->content, wd->enabled);
103 evas_object_map_set(wd->content, NULL);
104 evas_object_map_enable_set(wd->content, 0);
105 evas_object_move(wd->content, x, y);
106 evas_object_resize(wd->content, w, h);
111 _configure(Evas_Object *obj)
113 Widget_Data *wd = elm_widget_data_get(obj);
117 Evas_Coord x, y, w, h;
119 evas_object_geometry_get(obj, &x, &y, &w, &h);
120 if (!wd->enabled) evas_object_move(wd->content, x, y);
121 evas_object_resize(wd->content, w, h);
127 _move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
133 _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
139 * Add a new mapbuf to the parent
141 * @param parent The parent object
142 * @return The new object or NULL if it cannot be created
147 elm_mapbuf_add(Evas_Object *parent)
153 wd = ELM_NEW(Widget_Data);
154 e = evas_object_evas_get(parent);
155 obj = elm_widget_add(e);
156 ELM_SET_WIDTYPE(widtype, "mapbuf");
157 elm_widget_type_set(obj, "mapbuf");
158 elm_widget_sub_object_add(parent, obj);
159 elm_widget_data_set(obj, wd);
160 elm_widget_del_hook_set(obj, _del_hook);
161 elm_widget_theme_hook_set(obj, _theme_hook);
163 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
164 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, NULL);
165 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, NULL);
176 * Set the mapbuf front content
178 * Once the content object is set, a previously set one will be deleted.
179 * If you want to keep that old content object, use the
180 * elm_mapbuf_content_unset() function.
182 * @param obj The mapbuf object
183 * @param content The content will be filled in this mapbuf object
188 elm_mapbuf_content_set(Evas_Object *obj, Evas_Object *content)
190 ELM_CHECK_WIDTYPE(obj, widtype);
191 Widget_Data *wd = elm_widget_data_get(obj);
193 if (wd->content == content) return;
194 if (wd->content) evas_object_del(wd->content);
195 wd->content = content;
198 elm_widget_sub_object_add(content, obj);
199 evas_object_smart_member_add(content, obj);
200 evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
201 _changed_size_hints, obj);
208 * Unset the mapbuf front content
210 * Unparent and return the content object which was set for this widget.
212 * @param obj The mapbuf object
213 * @return The content that was being used
218 elm_mapbuf_content_unset(Evas_Object *obj)
220 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
221 Widget_Data *wd = elm_widget_data_get(obj);
222 Evas_Object *content;
223 if (!wd) return NULL;
224 if (!wd->content) return NULL;
225 content = wd->content;
226 elm_widget_sub_object_del(obj, wd->content);
227 evas_object_smart_member_del(wd->content);
233 * Set the mapbuf enabled state
235 * @param obj The mapbuf object
236 * @param enabled The value to set the enabled state to
241 elm_mapbuf_enabled_set(Evas_Object *obj, Eina_Bool enabled)
243 ELM_CHECK_WIDTYPE(obj, widtype);
244 Widget_Data *wd = elm_widget_data_get(obj);
246 if (wd->enabled == enabled) return;
247 wd->enabled = enabled;
252 * Get the mapbuf enabled state
254 * @param obj The mapbuf object
255 * @return The value that the enabled state is set to
260 elm_mapbuf_enabled_get(const Evas_Object *obj)
262 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
263 Widget_Data *wd = elm_widget_data_get(obj);
264 if (!wd) return EINA_FALSE;
269 * Sets the mapbuf smooth state
271 * @param obj The mapbuf object
272 * @param smooth The value of the smooth state of @p obj
277 elm_mapbuf_smooth_set(Evas_Object *obj, Eina_Bool smooth)
279 ELM_CHECK_WIDTYPE(obj, widtype);
280 Widget_Data *wd = elm_widget_data_get(obj);
282 if (wd->smooth == smooth) return;
288 * Gets the mapbuf smooth state
290 * @param obj The mapbuf object
291 * @return The value of the smooth state of @p obj
296 elm_mapbuf_smooth_get(const Evas_Object *obj)
298 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
299 Widget_Data *wd = elm_widget_data_get(obj);
300 if (!wd) return EINA_FALSE;
305 * Enables/disables the mapbuf alpha channel
307 * @param obj The mapbuf object
308 * @param alpha The state of the alpha channel
313 elm_mapbuf_alpha_set(Evas_Object *obj, Eina_Bool alpha)
315 ELM_CHECK_WIDTYPE(obj, widtype);
316 Widget_Data *wd = elm_widget_data_get(obj);
318 if (wd->alpha == alpha) return;
324 * Gets the state of the mapbuf alpha channel
326 * @param obj The mapbuf object
327 * @return The state of the alpha channel
332 elm_mapbuf_alpha_get(const Evas_Object *obj)
334 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
335 Widget_Data *wd = elm_widget_data_get(obj);
336 if (!wd) return EINA_FALSE;