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;
14 Evas_Object *content, *clip;
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(wd->clip, &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, x2, y2;
119 evas_object_geometry_get(wd->clip, &x, &y, &w, &h);
120 evas_object_geometry_get(wd->content, &x2, &y2, NULL, NULL);
121 if ((x != x2) || (y != y2))
124 evas_object_move(wd->content, x, y);
128 Evas *e = evas_object_evas_get(obj);
129 evas_smart_objects_calculate(e);
130 evas_nochange_push(e);
131 // printf("x-------------------- %i %i\n", x, y);
132 evas_object_move(wd->content, x, y);
133 evas_smart_objects_calculate(e);
134 // printf("y--------------------\n");
135 evas_nochange_pop(e);
138 evas_object_resize(wd->content, w, h);
144 _move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
150 _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
156 * Add a new mapbuf to the parent
158 * @param parent The parent object
159 * @return The new object or NULL if it cannot be created
164 elm_mapbuf_add(Evas_Object *parent)
170 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
172 wd = ELM_NEW(Widget_Data);
173 e = evas_object_evas_get(parent);
175 obj = elm_widget_add(e);
176 ELM_SET_WIDTYPE(widtype, "mapbuf");
177 elm_widget_type_set(obj, "mapbuf");
178 elm_widget_sub_object_add(parent, obj);
179 elm_widget_data_set(obj, wd);
180 elm_widget_del_hook_set(obj, _del_hook);
181 elm_widget_theme_hook_set(obj, _theme_hook);
182 elm_widget_can_focus_set(obj, EINA_FALSE);
184 wd->clip = evas_object_rectangle_add(e);
185 evas_object_static_clip_set(wd->clip, EINA_TRUE);
186 evas_object_pass_events_set(wd->clip, EINA_TRUE);
187 evas_object_color_set(wd->clip, 0, 0, 0, 0);
189 evas_object_event_callback_add(wd->clip, EVAS_CALLBACK_MOVE, _move, obj);
190 evas_object_event_callback_add(wd->clip, EVAS_CALLBACK_RESIZE, _resize, obj);
191 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
193 elm_widget_resize_object_set(obj, wd->clip);
204 * Set the mapbuf front content
206 * Once the content object is set, a previously set one will be deleted.
207 * If you want to keep that old content object, use the
208 * elm_mapbuf_content_unset() function.
210 * @param obj The mapbuf object
211 * @param content The content will be filled in this mapbuf object
216 elm_mapbuf_content_set(Evas_Object *obj, Evas_Object *content)
218 ELM_CHECK_WIDTYPE(obj, widtype);
219 Widget_Data *wd = elm_widget_data_get(obj);
221 if (wd->content == content) return;
222 if (wd->content) evas_object_del(wd->content);
223 wd->content = content;
226 evas_object_data_set(content, "_elm_leaveme", (void *)1);
227 elm_widget_sub_object_add(content, obj);
228 evas_object_smart_member_add(content, obj);
229 evas_object_clip_set(content, wd->clip);
230 evas_object_color_set(wd->clip, 255, 255, 255, 255);
231 evas_object_event_callback_add(content,
232 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
233 _changed_size_hints, obj);
236 evas_object_color_set(wd->clip, 0, 0, 0, 0);
242 * Get the mapbuf front content
244 * Return the content object which is set for this widget.
246 * @param obj The mapbuf object
247 * @return The content that is being used
252 elm_mapbuf_content_get(const Evas_Object *obj)
254 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
255 Widget_Data *wd = elm_widget_data_get(obj);
256 if (!wd) return NULL;
261 * Unset the mapbuf front content
263 * Unparent and return the content object which was set for this widget.
265 * @param obj The mapbuf object
266 * @return The content that was being used
271 elm_mapbuf_content_unset(Evas_Object *obj)
273 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
274 Widget_Data *wd = elm_widget_data_get(obj);
275 Evas_Object *content;
276 if (!wd) return NULL;
277 if (!wd->content) return NULL;
278 content = wd->content;
279 elm_widget_sub_object_del(obj, content);
280 evas_object_smart_member_del(content);
281 evas_object_color_set(wd->clip, 0, 0, 0, 0);
282 evas_object_clip_unset(content);
283 evas_object_data_del(content, "_elm_leaveme");
289 * Set the mapbuf enabled state
291 * @param obj The mapbuf object
292 * @param enabled The value to set the enabled state to
297 elm_mapbuf_enabled_set(Evas_Object *obj, Eina_Bool enabled)
299 ELM_CHECK_WIDTYPE(obj, widtype);
300 Widget_Data *wd = elm_widget_data_get(obj);
302 if (wd->enabled == enabled) return;
303 wd->enabled = enabled;
304 if (wd->content) evas_object_static_clip_set(wd->content, wd->enabled);
309 * Get the mapbuf enabled state
311 * @param obj The mapbuf object
312 * @return The value that the enabled state is set to
317 elm_mapbuf_enabled_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 * Sets the mapbuf smooth state
328 * @param obj The mapbuf object
329 * @param smooth The value of the smooth state of @p obj
334 elm_mapbuf_smooth_set(Evas_Object *obj, Eina_Bool smooth)
336 ELM_CHECK_WIDTYPE(obj, widtype);
337 Widget_Data *wd = elm_widget_data_get(obj);
339 if (wd->smooth == smooth) return;
345 * Gets the mapbuf smooth state
347 * @param obj The mapbuf object
348 * @return The value of the smooth state of @p obj
353 elm_mapbuf_smooth_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;
362 * Enables/disables the mapbuf alpha channel
364 * @param obj The mapbuf object
365 * @param alpha The state of the alpha channel
370 elm_mapbuf_alpha_set(Evas_Object *obj, Eina_Bool alpha)
372 ELM_CHECK_WIDTYPE(obj, widtype);
373 Widget_Data *wd = elm_widget_data_get(obj);
375 if (wd->alpha == alpha) return;
381 * Gets the state of the mapbuf alpha channel
383 * @param obj The mapbuf object
384 * @return The state of the alpha channel
389 elm_mapbuf_alpha_get(const Evas_Object *obj)
391 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
392 Widget_Data *wd = elm_widget_data_get(obj);
393 if (!wd) return EINA_FALSE;