1 #include <Elementary.h>
5 * @defgroup Mapbuf Mapbuf
8 * This holds 1 content object and uses an Evas Map to move/resize etc. it.
11 typedef struct _Widget_Data Widget_Data;
16 Eina_Bool enabled : 1;
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);
29 _del_hook(Evas_Object *obj)
31 Widget_Data *wd = elm_widget_data_get(obj);
37 _theme_hook(Evas_Object *obj)
39 Widget_Data *wd = elm_widget_data_get(obj);
45 _sizing_eval(Evas_Object *obj)
47 Widget_Data *wd = elm_widget_data_get(obj);
48 Evas_Coord minw = -1, minh = -1;
49 Evas_Coord maxw = -1, maxh = -1;
53 evas_object_size_hint_min_get(wd->content, &minw, &minh);
54 evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
56 evas_object_size_hint_min_set(obj, minw, minh);
57 evas_object_size_hint_max_set(obj, maxw, maxh);
61 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
63 Widget_Data *wd = elm_widget_data_get(data);
69 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
71 Widget_Data *wd = elm_widget_data_get(obj);
72 Evas_Object *sub = event_info;
74 if (sub == wd->content)
76 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
77 _changed_size_hints, obj);
84 _mapbuf(Evas_Object *obj)
86 Widget_Data *wd = elm_widget_data_get(obj);
87 Evas_Coord x, y, w, h;
89 evas_object_geometry_get(obj, &x, &y, &w, &h);
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);
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);
112 _configure(Evas_Object *obj)
114 Widget_Data *wd = elm_widget_data_get(obj);
118 Evas_Coord x, y, w, h, x2, y2;
120 evas_object_geometry_get(obj, &x, &y, &w, &h);
121 evas_object_geometry_get(wd->content, &x2, &y2, NULL, NULL);
122 if ((x != x2) || (y != y2))
125 evas_object_move(wd->content, x, y);
129 Evas *e = evas_object_evas_get(obj);
130 evas_smart_objects_calculate(e);
131 evas_nochange_push(e);
132 // printf("x--------------------\n");
133 evas_object_move(wd->content, x, y);
134 evas_smart_objects_calculate(e);
135 // printf("y--------------------\n");
136 evas_nochange_pop(e);
139 evas_object_resize(wd->content, w, h);
145 _move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
151 _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
157 * Add a new mapbuf to the parent
159 * @param parent The parent object
160 * @return The new object or NULL if it cannot be created
165 elm_mapbuf_add(Evas_Object *parent)
171 wd = ELM_NEW(Widget_Data);
172 e = evas_object_evas_get(parent);
173 obj = elm_widget_add(e);
174 ELM_SET_WIDTYPE(widtype, "mapbuf");
175 elm_widget_type_set(obj, "mapbuf");
176 elm_widget_sub_object_add(parent, obj);
177 elm_widget_data_set(obj, wd);
178 elm_widget_del_hook_set(obj, _del_hook);
179 elm_widget_theme_hook_set(obj, _theme_hook);
181 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
182 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, NULL);
183 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, NULL);
194 * Set the mapbuf front content
196 * Once the content object is set, a previously set one will be deleted.
197 * If you want to keep that old content object, use the
198 * elm_mapbuf_content_unset() function.
200 * @param obj The mapbuf object
201 * @param content The content will be filled in this mapbuf object
206 elm_mapbuf_content_set(Evas_Object *obj, Evas_Object *content)
208 ELM_CHECK_WIDTYPE(obj, widtype);
209 Widget_Data *wd = elm_widget_data_get(obj);
211 if (wd->content == content) return;
212 if (wd->content) evas_object_del(wd->content);
213 wd->content = content;
216 elm_widget_sub_object_add(content, obj);
217 evas_object_smart_member_add(content, obj);
218 evas_object_clip_set(content, evas_object_clip_get(obj));
219 evas_object_event_callback_add(content,
220 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
221 _changed_size_hints, obj);
228 * Unset the mapbuf front content
230 * Unparent and return the content object which was set for this widget.
232 * @param obj The mapbuf object
233 * @return The content that was being used
238 elm_mapbuf_content_unset(Evas_Object *obj)
240 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
241 Widget_Data *wd = elm_widget_data_get(obj);
242 Evas_Object *content;
243 if (!wd) return NULL;
244 if (!wd->content) return NULL;
245 content = wd->content;
246 elm_widget_sub_object_del(obj, wd->content);
247 evas_object_smart_member_del(wd->content);
248 evas_object_clip_unset(wd->content);
254 * Set the mapbuf enabled state
256 * @param obj The mapbuf object
257 * @param enabled The value to set the enabled state to
262 elm_mapbuf_enabled_set(Evas_Object *obj, Eina_Bool enabled)
264 ELM_CHECK_WIDTYPE(obj, widtype);
265 Widget_Data *wd = elm_widget_data_get(obj);
267 if (wd->enabled == enabled) return;
268 wd->enabled = enabled;
273 * Get the mapbuf enabled state
275 * @param obj The mapbuf object
276 * @return The value that the enabled state is set to
281 elm_mapbuf_enabled_get(const Evas_Object *obj)
283 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
284 Widget_Data *wd = elm_widget_data_get(obj);
285 if (!wd) return EINA_FALSE;
290 * Sets the mapbuf smooth state
292 * @param obj The mapbuf object
293 * @param smooth The value of the smooth state of @p obj
298 elm_mapbuf_smooth_set(Evas_Object *obj, Eina_Bool smooth)
300 ELM_CHECK_WIDTYPE(obj, widtype);
301 Widget_Data *wd = elm_widget_data_get(obj);
303 if (wd->smooth == smooth) return;
309 * Gets the mapbuf smooth state
311 * @param obj The mapbuf object
312 * @return The value of the smooth state of @p obj
317 elm_mapbuf_smooth_get(const Evas_Object *obj)
319 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
320 Widget_Data *wd = elm_widget_data_get(obj);
321 if (!wd) return EINA_FALSE;
326 * Enables/disables the mapbuf alpha channel
328 * @param obj The mapbuf object
329 * @param alpha The state of the alpha channel
334 elm_mapbuf_alpha_set(Evas_Object *obj, Eina_Bool alpha)
336 ELM_CHECK_WIDTYPE(obj, widtype);
337 Widget_Data *wd = elm_widget_data_get(obj);
339 if (wd->alpha == alpha) return;
345 * Gets the state of the mapbuf alpha channel
347 * @param obj The mapbuf object
348 * @return The state of the alpha channel
353 elm_mapbuf_alpha_get(const Evas_Object *obj)
355 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
356 Widget_Data *wd = elm_widget_data_get(obj);
357 if (!wd) return EINA_FALSE;