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 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
172 ELM_SET_WIDTYPE(widtype, "mapbuf");
173 elm_widget_type_set(obj, "mapbuf");
174 elm_widget_sub_object_add(parent, obj);
175 elm_widget_data_set(obj, wd);
176 elm_widget_del_hook_set(obj, _del_hook);
177 elm_widget_theme_hook_set(obj, _theme_hook);
178 elm_widget_can_focus_set(obj, EINA_FALSE);
180 wd->clip = evas_object_rectangle_add(e);
181 evas_object_static_clip_set(wd->clip, EINA_TRUE);
182 evas_object_pass_events_set(wd->clip, EINA_TRUE);
183 evas_object_color_set(wd->clip, 0, 0, 0, 0);
185 evas_object_event_callback_add(wd->clip, EVAS_CALLBACK_MOVE, _move, obj);
186 evas_object_event_callback_add(wd->clip, EVAS_CALLBACK_RESIZE, _resize, obj);
187 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
189 elm_widget_resize_object_set(obj, wd->clip);
200 * Set the mapbuf front content
202 * Once the content object is set, a previously set one will be deleted.
203 * If you want to keep that old content object, use the
204 * elm_mapbuf_content_unset() function.
206 * @param obj The mapbuf object
207 * @param content The content will be filled in this mapbuf object
212 elm_mapbuf_content_set(Evas_Object *obj, Evas_Object *content)
214 ELM_CHECK_WIDTYPE(obj, widtype);
215 Widget_Data *wd = elm_widget_data_get(obj);
217 if (wd->content == content) return;
218 if (wd->content) evas_object_del(wd->content);
219 wd->content = content;
222 evas_object_data_set(content, "_elm_leaveme", (void *)1);
223 elm_widget_sub_object_add(content, obj);
224 evas_object_smart_member_add(content, obj);
225 evas_object_clip_set(content, wd->clip);
226 evas_object_color_set(wd->clip, 255, 255, 255, 255);
227 evas_object_event_callback_add(content,
228 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
229 _changed_size_hints, obj);
232 evas_object_color_set(wd->clip, 0, 0, 0, 0);
238 * Get the mapbuf front content
240 * Return the content object which is set for this widget.
242 * @param obj The mapbuf object
243 * @return The content that is being used
248 elm_mapbuf_content_get(const Evas_Object *obj)
250 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
251 Widget_Data *wd = elm_widget_data_get(obj);
252 if (!wd) return NULL;
257 * Unset the mapbuf front content
259 * Unparent and return the content object which was set for this widget.
261 * @param obj The mapbuf object
262 * @return The content that was being used
267 elm_mapbuf_content_unset(Evas_Object *obj)
269 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
270 Widget_Data *wd = elm_widget_data_get(obj);
271 Evas_Object *content;
272 if (!wd) return NULL;
273 if (!wd->content) return NULL;
274 content = wd->content;
275 elm_widget_sub_object_del(obj, content);
276 evas_object_smart_member_del(content);
277 evas_object_color_set(wd->clip, 0, 0, 0, 0);
278 evas_object_clip_unset(content);
279 evas_object_data_del(content, "_elm_leaveme");
285 * Set the mapbuf enabled state
287 * @param obj The mapbuf object
288 * @param enabled The value to set the enabled state to
293 elm_mapbuf_enabled_set(Evas_Object *obj, Eina_Bool enabled)
295 ELM_CHECK_WIDTYPE(obj, widtype);
296 Widget_Data *wd = elm_widget_data_get(obj);
298 if (wd->enabled == enabled) return;
299 wd->enabled = enabled;
300 if (wd->content) evas_object_static_clip_set(wd->content, wd->enabled);
305 * Get the mapbuf enabled state
307 * @param obj The mapbuf object
308 * @return The value that the enabled state is set to
313 elm_mapbuf_enabled_get(const Evas_Object *obj)
315 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
316 Widget_Data *wd = elm_widget_data_get(obj);
317 if (!wd) return EINA_FALSE;
322 * Sets the mapbuf smooth state
324 * @param obj The mapbuf object
325 * @param smooth The value of the smooth state of @p obj
330 elm_mapbuf_smooth_set(Evas_Object *obj, Eina_Bool smooth)
332 ELM_CHECK_WIDTYPE(obj, widtype);
333 Widget_Data *wd = elm_widget_data_get(obj);
335 if (wd->smooth == smooth) return;
341 * Gets the mapbuf smooth state
343 * @param obj The mapbuf object
344 * @return The value of the smooth state of @p obj
349 elm_mapbuf_smooth_get(const Evas_Object *obj)
351 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
352 Widget_Data *wd = elm_widget_data_get(obj);
353 if (!wd) return EINA_FALSE;
358 * Enables/disables the mapbuf alpha channel
360 * @param obj The mapbuf object
361 * @param alpha The state of the alpha channel
366 elm_mapbuf_alpha_set(Evas_Object *obj, Eina_Bool alpha)
368 ELM_CHECK_WIDTYPE(obj, widtype);
369 Widget_Data *wd = elm_widget_data_get(obj);
371 if (wd->alpha == alpha) return;
377 * Gets the state of the mapbuf alpha channel
379 * @param obj The mapbuf object
380 * @return The state of the alpha channel
385 elm_mapbuf_alpha_get(const Evas_Object *obj)
387 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
388 Widget_Data *wd = elm_widget_data_get(obj);
389 if (!wd) return EINA_FALSE;