aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/elementary/src/lib/elm_mapbuf.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/elementary/src/lib/elm_mapbuf.c305
1 files changed, 305 insertions, 0 deletions
diff --git a/libraries/elementary/src/lib/elm_mapbuf.c b/libraries/elementary/src/lib/elm_mapbuf.c
new file mode 100644
index 0000000..4608872
--- /dev/null
+++ b/libraries/elementary/src/lib/elm_mapbuf.c
@@ -0,0 +1,305 @@
1#include <Elementary.h>
2#include "elm_priv.h"
3
4typedef struct _Widget_Data Widget_Data;
5
6struct _Widget_Data
7{
8 Evas_Object *content, *clip;
9 Eina_Bool enabled : 1;
10 Eina_Bool alpha : 1;
11 Eina_Bool smooth : 1;
12};
13
14static const char *widtype = NULL;
15static void _del_hook(Evas_Object *obj);
16static void _theme_hook(Evas_Object *obj);
17static void _sizing_eval(Evas_Object *obj);
18static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
19static void _sub_del(void *data, Evas_Object *obj, void *event_info);
20
21static void
22_del_hook(Evas_Object *obj)
23{
24 Widget_Data *wd = elm_widget_data_get(obj);
25 if (!wd) return;
26 free(wd);
27}
28
29static void
30_theme_hook(Evas_Object *obj)
31{
32 Widget_Data *wd = elm_widget_data_get(obj);
33 if (!wd) return;
34 _sizing_eval(obj);
35}
36
37static void
38_sizing_eval(Evas_Object *obj)
39{
40 Widget_Data *wd = elm_widget_data_get(obj);
41 Evas_Coord minw = -1, minh = -1;
42 Evas_Coord maxw = -1, maxh = -1;
43 if (!wd) return;
44 if (wd->content)
45 {
46 evas_object_size_hint_min_get(wd->content, &minw, &minh);
47 evas_object_size_hint_max_get(wd->content, &maxw, &maxh);
48 }
49 evas_object_size_hint_min_set(obj, minw, minh);
50 evas_object_size_hint_max_set(obj, maxw, maxh);
51}
52
53static void
54_changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
55{
56 Widget_Data *wd = elm_widget_data_get(data);
57 if (!wd) return;
58 _sizing_eval(data);
59}
60
61static void
62_sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
63{
64 Widget_Data *wd = elm_widget_data_get(obj);
65 Evas_Object *sub = event_info;
66 if (!wd) return;
67 if (sub == wd->content)
68 {
69 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
70 _changed_size_hints, obj);
71 wd->content = NULL;
72 _sizing_eval(obj);
73 }
74}
75
76static void
77_mapbuf(Evas_Object *obj)
78{
79 Widget_Data *wd = elm_widget_data_get(obj);
80 Evas_Coord x, y, w, h;
81 if (!wd) return;
82 evas_object_geometry_get(wd->clip, &x, &y, &w, &h);
83 if (wd->enabled)
84 {
85 Evas_Map *m;
86
87 m = evas_map_new(4);
88 evas_map_util_points_populate_from_geometry(m, x, y, w, h, 0);
89 evas_map_smooth_set(m, wd->smooth);
90 evas_map_alpha_set(m, wd->alpha);
91 evas_object_map_set(wd->content, m);
92 evas_object_map_enable_set(wd->content, EINA_TRUE);
93 evas_map_free(m);
94 }
95 else
96 {
97 evas_object_map_set(wd->content, NULL);
98 evas_object_map_enable_set(wd->content, EINA_FALSE);
99 evas_object_move(wd->content, x, y);
100 evas_object_resize(wd->content, w, h);
101 }
102}
103
104static void
105_configure(Evas_Object *obj)
106{
107 Widget_Data *wd = elm_widget_data_get(obj);
108 if (!wd) return;
109 if (wd->content)
110 {
111 Evas_Coord x, y, w, h, x2, y2;
112
113 evas_object_geometry_get(wd->clip, &x, &y, &w, &h);
114 evas_object_geometry_get(wd->content, &x2, &y2, NULL, NULL);
115 if ((x != x2) || (y != y2))
116 {
117 if (!wd->enabled)
118 evas_object_move(wd->content, x, y);
119 else
120 {
121
122 Evas *e = evas_object_evas_get(obj);
123 evas_smart_objects_calculate(e);
124 evas_nochange_push(e);
125 evas_object_move(wd->content, x, y);
126 evas_smart_objects_calculate(e);
127 evas_nochange_pop(e);
128 }
129 }
130 evas_object_resize(wd->content, w, h);
131 _mapbuf(obj);
132 }
133}
134
135static void
136_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
137{
138 _configure(data);
139}
140
141static void
142_resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
143{
144 _configure(data);
145}
146
147static void
148_content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
149{
150 ELM_CHECK_WIDTYPE(obj, widtype);
151 Widget_Data *wd;
152
153 if (part && strcmp(part, "default")) return;
154 wd = elm_widget_data_get(obj);
155 if (!wd) return;
156 if (wd->content == content) return;
157 if (wd->content) evas_object_del(wd->content);
158 wd->content = content;
159 if (content)
160 {
161 evas_object_data_set(content, "_elm_leaveme", (void *)1);
162 elm_widget_sub_object_add(obj, content);
163 evas_object_smart_member_add(content, obj);
164 evas_object_clip_set(content, wd->clip);
165 evas_object_color_set(wd->clip, 255, 255, 255, 255);
166 evas_object_event_callback_add(content,
167 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
168 _changed_size_hints, obj);
169 }
170 else
171 evas_object_color_set(wd->clip, 0, 0, 0, 0);
172 _sizing_eval(obj);
173 _configure(obj);
174}
175
176static Evas_Object *
177_content_get_hook(const Evas_Object *obj, const char *part)
178{
179 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
180 Widget_Data *wd;
181
182 if (part && strcmp(part, "default")) return NULL;
183 wd = elm_widget_data_get(obj);
184 if (!wd) return NULL;
185 return wd->content;
186}
187
188static Evas_Object *
189_content_unset_hook(Evas_Object *obj, const char *part)
190{
191 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
192 Widget_Data *wd;
193 Evas_Object *content;
194
195 if (part && strcmp(part, "default")) return NULL;
196 wd = elm_widget_data_get(obj);
197 if (!wd) return NULL;
198 if (!wd->content) return NULL;
199 content = wd->content;
200 elm_widget_sub_object_del(obj, content);
201 evas_object_smart_member_del(content);
202 evas_object_color_set(wd->clip, 0, 0, 0, 0);
203 evas_object_data_del(content, "_elm_leaveme");
204 return content;
205}
206
207EAPI Evas_Object *
208elm_mapbuf_add(Evas_Object *parent)
209{
210 Evas_Object *obj;
211 Evas *e;
212 Widget_Data *wd;
213
214 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
215
216 ELM_SET_WIDTYPE(widtype, "mapbuf");
217 elm_widget_type_set(obj, "mapbuf");
218 elm_widget_sub_object_add(parent, obj);
219 elm_widget_data_set(obj, wd);
220 elm_widget_del_hook_set(obj, _del_hook);
221 elm_widget_theme_hook_set(obj, _theme_hook);
222 elm_widget_content_set_hook_set(obj, _content_set_hook);
223 elm_widget_content_get_hook_set(obj, _content_get_hook);
224 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
225 elm_widget_can_focus_set(obj, EINA_FALSE);
226
227 wd->clip = evas_object_rectangle_add(e);
228 evas_object_static_clip_set(wd->clip, EINA_TRUE);
229 evas_object_pass_events_set(wd->clip, EINA_TRUE);
230 evas_object_color_set(wd->clip, 0, 0, 0, 0);
231
232 evas_object_event_callback_add(wd->clip, EVAS_CALLBACK_MOVE, _move, obj);
233 evas_object_event_callback_add(wd->clip, EVAS_CALLBACK_RESIZE, _resize, obj);
234 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
235
236 elm_widget_resize_object_set(obj, wd->clip);
237
238 wd->enabled = 0;
239 wd->alpha = 1;
240 wd->smooth = 1;
241
242 _sizing_eval(obj);
243 return obj;
244}
245
246EAPI void
247elm_mapbuf_enabled_set(Evas_Object *obj, Eina_Bool enabled)
248{
249 ELM_CHECK_WIDTYPE(obj, widtype);
250 Widget_Data *wd = elm_widget_data_get(obj);
251 if (!wd) return;
252 if (wd->enabled == enabled) return;
253 wd->enabled = enabled;
254 if (wd->content) evas_object_static_clip_set(wd->content, wd->enabled);
255 _configure(obj);
256}
257
258EAPI Eina_Bool
259elm_mapbuf_enabled_get(const Evas_Object *obj)
260{
261 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
262 Widget_Data *wd = elm_widget_data_get(obj);
263 if (!wd) return EINA_FALSE;
264 return wd->enabled;
265}
266
267EAPI void
268elm_mapbuf_smooth_set(Evas_Object *obj, Eina_Bool smooth)
269{
270 ELM_CHECK_WIDTYPE(obj, widtype);
271 Widget_Data *wd = elm_widget_data_get(obj);
272 if (!wd) return;
273 if (wd->smooth == smooth) return;
274 wd->smooth = smooth;
275 _configure(obj);
276}
277
278EAPI Eina_Bool
279elm_mapbuf_smooth_get(const Evas_Object *obj)
280{
281 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
282 Widget_Data *wd = elm_widget_data_get(obj);
283 if (!wd) return EINA_FALSE;
284 return wd->smooth;
285}
286
287EAPI void
288elm_mapbuf_alpha_set(Evas_Object *obj, Eina_Bool alpha)
289{
290 ELM_CHECK_WIDTYPE(obj, widtype);
291 Widget_Data *wd = elm_widget_data_get(obj);
292 if (!wd) return;
293 if (wd->alpha == alpha) return;
294 wd->alpha = alpha;
295 _configure(obj);
296}
297
298EAPI Eina_Bool
299elm_mapbuf_alpha_get(const Evas_Object *obj)
300{
301 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
302 Widget_Data *wd = elm_widget_data_get(obj);
303 if (!wd) return EINA_FALSE;
304 return wd->alpha;
305}