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;
15 Evas_Object *content, *clip;
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(wd->clip, &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(wd->clip, &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-------------------- %i %i\n", x, y);
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 __UNUSED__, void *event_info __UNUSED__)
151 _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, 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 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
173 ELM_SET_WIDTYPE(widtype, "mapbuf");
174 elm_widget_type_set(obj, "mapbuf");
175 elm_widget_sub_object_add(parent, obj);
176 elm_widget_data_set(obj, wd);
177 elm_widget_del_hook_set(obj, _del_hook);
178 elm_widget_theme_hook_set(obj, _theme_hook);
179 elm_widget_can_focus_set(obj, EINA_FALSE);
181 wd->clip = evas_object_rectangle_add(e);
182 evas_object_static_clip_set(wd->clip, EINA_TRUE);
183 evas_object_pass_events_set(wd->clip, EINA_TRUE);
184 evas_object_color_set(wd->clip, 0, 0, 0, 0);
186 evas_object_event_callback_add(wd->clip, EVAS_CALLBACK_MOVE, _move, obj);
187 evas_object_event_callback_add(wd->clip, EVAS_CALLBACK_RESIZE, _resize, obj);
188 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
190 elm_widget_resize_object_set(obj, wd->clip);
201 * Set the mapbuf front content
203 * Once the content object is set, a previously set one will be deleted.
204 * If you want to keep that old content object, use the
205 * elm_mapbuf_content_unset() function.
207 * @param obj The mapbuf object
208 * @param content The content will be filled in this mapbuf object
213 elm_mapbuf_content_set(Evas_Object *obj, Evas_Object *content)
215 ELM_CHECK_WIDTYPE(obj, widtype);
216 Widget_Data *wd = elm_widget_data_get(obj);
218 if (wd->content == content) return;
219 if (wd->content) evas_object_del(wd->content);
220 wd->content = content;
223 evas_object_data_set(content, "_elm_leaveme", (void *)1);
224 elm_widget_sub_object_add(content, obj);
225 evas_object_smart_member_add(content, obj);
226 evas_object_clip_set(content, wd->clip);
227 evas_object_color_set(wd->clip, 255, 255, 255, 255);
228 evas_object_event_callback_add(content,
229 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
230 _changed_size_hints, obj);
233 evas_object_color_set(wd->clip, 0, 0, 0, 0);
239 * Get the mapbuf front content
241 * Return the content object which is set for this widget.
243 * @param obj The mapbuf object
244 * @return The content that is being used
249 elm_mapbuf_content_get(const Evas_Object *obj)
251 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
252 Widget_Data *wd = elm_widget_data_get(obj);
253 if (!wd) return NULL;
258 * Unset the mapbuf front content
260 * Unparent and return the content object which was set for this widget.
262 * @param obj The mapbuf object
263 * @return The content that was being used
268 elm_mapbuf_content_unset(Evas_Object *obj)
270 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
271 Widget_Data *wd = elm_widget_data_get(obj);
272 Evas_Object *content;
273 if (!wd) return NULL;
274 if (!wd->content) return NULL;
275 content = wd->content;
276 elm_widget_sub_object_del(obj, content);
277 evas_object_smart_member_del(content);
278 evas_object_color_set(wd->clip, 0, 0, 0, 0);
279 evas_object_clip_unset(content);
280 evas_object_data_del(content, "_elm_leaveme");
286 * Set the mapbuf enabled state
288 * @param obj The mapbuf object
289 * @param enabled The value to set the enabled state to
294 elm_mapbuf_enabled_set(Evas_Object *obj, Eina_Bool enabled)
296 ELM_CHECK_WIDTYPE(obj, widtype);
297 Widget_Data *wd = elm_widget_data_get(obj);
299 if (wd->enabled == enabled) return;
300 wd->enabled = enabled;
301 if (wd->content) evas_object_static_clip_set(wd->content, wd->enabled);
306 * Get the mapbuf enabled state
308 * @param obj The mapbuf object
309 * @return The value that the enabled state is set to
314 elm_mapbuf_enabled_get(const Evas_Object *obj)
316 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
317 Widget_Data *wd = elm_widget_data_get(obj);
318 if (!wd) return EINA_FALSE;
323 * Sets the mapbuf smooth state
325 * @param obj The mapbuf object
326 * @param smooth The value of the smooth state of @p obj
331 elm_mapbuf_smooth_set(Evas_Object *obj, Eina_Bool smooth)
333 ELM_CHECK_WIDTYPE(obj, widtype);
334 Widget_Data *wd = elm_widget_data_get(obj);
336 if (wd->smooth == smooth) return;
342 * Gets the mapbuf smooth state
344 * @param obj The mapbuf object
345 * @return The value of the smooth state of @p obj
350 elm_mapbuf_smooth_get(const Evas_Object *obj)
352 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
353 Widget_Data *wd = elm_widget_data_get(obj);
354 if (!wd) return EINA_FALSE;
359 * Enables/disables the mapbuf alpha channel
361 * @param obj The mapbuf object
362 * @param alpha The state of the alpha channel
367 elm_mapbuf_alpha_set(Evas_Object *obj, Eina_Bool alpha)
369 ELM_CHECK_WIDTYPE(obj, widtype);
370 Widget_Data *wd = elm_widget_data_get(obj);
372 if (wd->alpha == alpha) return;
378 * Gets the state of the mapbuf alpha channel
380 * @param obj The mapbuf object
381 * @return The state of the alpha channel
386 elm_mapbuf_alpha_get(const Evas_Object *obj)
388 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
389 Widget_Data *wd = elm_widget_data_get(obj);
390 if (!wd) return EINA_FALSE;