diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/elementary/src/edje_externals/elm_slider.c | 339 |
1 files changed, 339 insertions, 0 deletions
diff --git a/libraries/elementary/src/edje_externals/elm_slider.c b/libraries/elementary/src/edje_externals/elm_slider.c new file mode 100644 index 0000000..3b349ce --- /dev/null +++ b/libraries/elementary/src/edje_externals/elm_slider.c | |||
@@ -0,0 +1,339 @@ | |||
1 | #include "private.h" | ||
2 | |||
3 | typedef struct _Elm_Params_Slider | ||
4 | { | ||
5 | Elm_Params base; | ||
6 | const char *label; | ||
7 | Evas_Object *icon; | ||
8 | const char *indicator, *unit; | ||
9 | double min, max, value; | ||
10 | Eina_Bool min_exists:1; | ||
11 | Eina_Bool max_exists:1; | ||
12 | Eina_Bool value_exists:1; | ||
13 | Eina_Bool inverted:1; | ||
14 | Eina_Bool inverted_exists:1; | ||
15 | Eina_Bool span:1; | ||
16 | Eina_Bool span_exists:1; | ||
17 | Eina_Bool horizontal:1; | ||
18 | Eina_Bool horizontal_exists:1; | ||
19 | } Elm_Params_Slider; | ||
20 | |||
21 | static void | ||
22 | external_slider_state_set(void *data __UNUSED__, Evas_Object *obj, const void *from_params, const void *to_params, float pos __UNUSED__) | ||
23 | { | ||
24 | const Elm_Params_Slider *p; | ||
25 | |||
26 | if (to_params) p = to_params; | ||
27 | else if (from_params) p = from_params; | ||
28 | else return; | ||
29 | |||
30 | if (p->label) | ||
31 | elm_object_text_set(obj, p->label); | ||
32 | if (p->icon) | ||
33 | elm_object_part_content_set(obj, "icon", p->icon); | ||
34 | if (p->span_exists) | ||
35 | elm_slider_span_size_set(obj, p->span); | ||
36 | if ((p->min_exists) && (p->max_exists)) | ||
37 | elm_slider_min_max_set(obj, p->min, p->max); | ||
38 | else if ((p->min_exists) || (p->max_exists)) | ||
39 | { | ||
40 | double min, max; | ||
41 | elm_slider_min_max_get(obj, &min, &max); | ||
42 | if (p->min_exists) | ||
43 | elm_slider_min_max_set(obj, p->min, max); | ||
44 | else | ||
45 | elm_slider_min_max_set(obj, min, p->max); | ||
46 | } | ||
47 | if (p->value_exists) | ||
48 | elm_slider_value_set(obj, p->value); | ||
49 | if (p->inverted_exists) | ||
50 | elm_slider_inverted_set(obj, p->inverted); | ||
51 | if (p->horizontal_exists) | ||
52 | elm_slider_horizontal_set(obj, p->horizontal); | ||
53 | if (p->indicator) | ||
54 | elm_slider_indicator_format_set(obj, p->indicator); | ||
55 | if (p->unit) | ||
56 | elm_slider_unit_format_set(obj, p->unit); | ||
57 | } | ||
58 | |||
59 | static Eina_Bool | ||
60 | external_slider_param_set(void *data __UNUSED__, Evas_Object *obj, const Edje_External_Param *param) | ||
61 | { | ||
62 | if (!strcmp(param->name, "label")) | ||
63 | { | ||
64 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING) | ||
65 | { | ||
66 | elm_object_text_set(obj, param->s); | ||
67 | return EINA_TRUE; | ||
68 | } | ||
69 | } | ||
70 | else if (!strcmp(param->name, "icon")) | ||
71 | { | ||
72 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING) | ||
73 | { | ||
74 | Evas_Object *icon = external_common_param_icon_get(obj, param); | ||
75 | if ((strcmp(param->s, "")) && (!icon)) return EINA_FALSE; | ||
76 | elm_object_part_content_set(obj, "icon", icon); | ||
77 | return EINA_TRUE; | ||
78 | } | ||
79 | } | ||
80 | else if (!strcmp(param->name, "min")) | ||
81 | { | ||
82 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE) | ||
83 | { | ||
84 | double min, max; | ||
85 | elm_slider_min_max_get(obj, &min, &max); | ||
86 | elm_slider_min_max_set(obj, param->d, max); | ||
87 | return EINA_TRUE; | ||
88 | } | ||
89 | } | ||
90 | else if (!strcmp(param->name, "max")) | ||
91 | { | ||
92 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE) | ||
93 | { | ||
94 | double min, max; | ||
95 | elm_slider_min_max_get(obj, &min, &max); | ||
96 | elm_slider_min_max_set(obj, min, param->d); | ||
97 | return EINA_TRUE; | ||
98 | } | ||
99 | } | ||
100 | else if (!strcmp(param->name, "value")) | ||
101 | { | ||
102 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE) | ||
103 | { | ||
104 | elm_slider_value_set(obj, param->d); | ||
105 | return EINA_TRUE; | ||
106 | } | ||
107 | } | ||
108 | else if (!strcmp(param->name, "horizontal")) | ||
109 | { | ||
110 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL) | ||
111 | { | ||
112 | elm_slider_horizontal_set(obj, param->i); | ||
113 | return EINA_TRUE; | ||
114 | } | ||
115 | } | ||
116 | else if (!strcmp(param->name, "inverted")) | ||
117 | { | ||
118 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL) | ||
119 | { | ||
120 | elm_slider_inverted_set(obj, param->i); | ||
121 | return EINA_TRUE; | ||
122 | } | ||
123 | } | ||
124 | else if (!strcmp(param->name, "span")) | ||
125 | { | ||
126 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT) | ||
127 | { | ||
128 | elm_slider_span_size_set(obj, param->i); | ||
129 | return EINA_TRUE; | ||
130 | } | ||
131 | } | ||
132 | else if (!strcmp(param->name, "unit format")) | ||
133 | { | ||
134 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING) | ||
135 | { | ||
136 | elm_slider_unit_format_set(obj, param->s); | ||
137 | return EINA_TRUE; | ||
138 | } | ||
139 | } | ||
140 | else if (!strcmp(param->name, "indicator format")) | ||
141 | { | ||
142 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING) | ||
143 | { | ||
144 | elm_slider_indicator_format_set(obj, param->s); | ||
145 | return EINA_TRUE; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | ERR("unknown parameter '%s' of type '%s'", | ||
150 | param->name, edje_external_param_type_str(param->type)); | ||
151 | |||
152 | return EINA_FALSE; | ||
153 | } | ||
154 | |||
155 | static Eina_Bool | ||
156 | external_slider_param_get(void *data __UNUSED__, const Evas_Object *obj, Edje_External_Param *param) | ||
157 | { | ||
158 | if (!strcmp(param->name, "label")) | ||
159 | { | ||
160 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING) | ||
161 | { | ||
162 | param->s = elm_object_text_get(obj); | ||
163 | return EINA_TRUE; | ||
164 | } | ||
165 | } | ||
166 | else if (!strcmp(param->name, "icon")) | ||
167 | { | ||
168 | /* not easy to get icon name back from live object */ | ||
169 | return EINA_FALSE; | ||
170 | } | ||
171 | else if (!strcmp(param->name, "min")) | ||
172 | { | ||
173 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING) | ||
174 | { | ||
175 | double min, max; | ||
176 | elm_slider_min_max_get(obj, &min, &max); | ||
177 | param->d = min; | ||
178 | return EINA_TRUE; | ||
179 | } | ||
180 | } | ||
181 | else if (!strcmp(param->name, "max")) | ||
182 | { | ||
183 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING) | ||
184 | { | ||
185 | double min, max; | ||
186 | elm_slider_min_max_get(obj, &min, &max); | ||
187 | param->d = max; | ||
188 | return EINA_TRUE; | ||
189 | } | ||
190 | } | ||
191 | else if (!strcmp(param->name, "value")) | ||
192 | { | ||
193 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_DOUBLE) | ||
194 | { | ||
195 | param->d = elm_slider_value_get(obj); | ||
196 | return EINA_TRUE; | ||
197 | } | ||
198 | } | ||
199 | else if (!strcmp(param->name, "horizontal")) | ||
200 | { | ||
201 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL) | ||
202 | { | ||
203 | param->i = elm_slider_horizontal_get(obj); | ||
204 | return EINA_TRUE; | ||
205 | } | ||
206 | } | ||
207 | else if (!strcmp(param->name, "inverted")) | ||
208 | { | ||
209 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL) | ||
210 | { | ||
211 | param->i = elm_slider_inverted_get(obj); | ||
212 | return EINA_TRUE; | ||
213 | } | ||
214 | } | ||
215 | else if (!strcmp(param->name, "span")) | ||
216 | { | ||
217 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_INT) | ||
218 | { | ||
219 | param->i = elm_slider_span_size_get(obj); | ||
220 | return EINA_TRUE; | ||
221 | } | ||
222 | } | ||
223 | else if (!strcmp(param->name, "unit format")) | ||
224 | { | ||
225 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING) | ||
226 | { | ||
227 | param->s = elm_slider_unit_format_get(obj); | ||
228 | return EINA_TRUE; | ||
229 | } | ||
230 | } | ||
231 | else if (!strcmp(param->name, "indicator format")) | ||
232 | { | ||
233 | if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING) | ||
234 | { | ||
235 | param->s = elm_slider_indicator_format_get(obj); | ||
236 | return EINA_TRUE; | ||
237 | } | ||
238 | } | ||
239 | |||
240 | ERR("unknown parameter '%s' of type '%s'", | ||
241 | param->name, edje_external_param_type_str(param->type)); | ||
242 | |||
243 | return EINA_FALSE; | ||
244 | } | ||
245 | |||
246 | static void * | ||
247 | external_slider_params_parse(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const Eina_List *params) | ||
248 | { | ||
249 | Elm_Params_Slider *mem; | ||
250 | Edje_External_Param *param; | ||
251 | const Eina_List *l; | ||
252 | |||
253 | mem = calloc(1, sizeof(Elm_Params_Slider)); | ||
254 | if (!mem) | ||
255 | return NULL; | ||
256 | |||
257 | external_common_icon_param_parse(&mem->icon, obj, params); | ||
258 | |||
259 | EINA_LIST_FOREACH(params, l, param) | ||
260 | { | ||
261 | if (!strcmp(param->name, "span")) | ||
262 | { | ||
263 | mem->span = param->i; | ||
264 | mem->span_exists = EINA_TRUE; | ||
265 | } | ||
266 | else if (!strcmp(param->name, "min")) | ||
267 | { | ||
268 | mem->min = param->d; | ||
269 | mem->min_exists = EINA_TRUE; | ||
270 | } | ||
271 | else if (!strcmp(param->name, "max")) | ||
272 | { | ||
273 | mem->max = param->d; | ||
274 | mem->max_exists = EINA_TRUE; | ||
275 | } | ||
276 | else if (!strcmp(param->name, "value")) | ||
277 | { | ||
278 | mem->value = param->d; | ||
279 | mem->value_exists = EINA_TRUE; | ||
280 | } | ||
281 | else if (!strcmp(param->name, "inverted")) | ||
282 | { | ||
283 | mem->inverted = param->i; | ||
284 | mem->inverted_exists = EINA_TRUE; | ||
285 | } | ||
286 | else if (!strcmp(param->name, "horizontal")) | ||
287 | { | ||
288 | mem->horizontal = param->i; | ||
289 | mem->horizontal_exists = EINA_TRUE; | ||
290 | } | ||
291 | else if (!strcmp(param->name, "unit format")) | ||
292 | mem->unit = eina_stringshare_add(param->s); | ||
293 | else if (!strcmp(param->name, "indicator format")) | ||
294 | mem->indicator = eina_stringshare_add(param->s); | ||
295 | else if (!strcmp(param->name, "label")) | ||
296 | mem->label = eina_stringshare_add(param->s); | ||
297 | } | ||
298 | |||
299 | return mem; | ||
300 | } | ||
301 | |||
302 | static Evas_Object *external_slider_content_get(void *data __UNUSED__, | ||
303 | const Evas_Object *obj __UNUSED__, const char *content __UNUSED__) | ||
304 | { | ||
305 | ERR("No content."); | ||
306 | return NULL; | ||
307 | } | ||
308 | |||
309 | static void | ||
310 | external_slider_params_free(void *params) | ||
311 | { | ||
312 | Elm_Params_Slider *mem = params; | ||
313 | |||
314 | if (mem->unit) | ||
315 | eina_stringshare_del(mem->unit); | ||
316 | if (mem->indicator) | ||
317 | eina_stringshare_del(mem->indicator); | ||
318 | if (mem->label) | ||
319 | eina_stringshare_del(mem->label); | ||
320 | free(params); | ||
321 | } | ||
322 | |||
323 | static Edje_External_Param_Info external_slider_params[] = { | ||
324 | DEFINE_EXTERNAL_COMMON_PARAMS, | ||
325 | EDJE_EXTERNAL_PARAM_INFO_STRING("label"), | ||
326 | EDJE_EXTERNAL_PARAM_INFO_STRING("icon"), | ||
327 | EDJE_EXTERNAL_PARAM_INFO_DOUBLE("min"), | ||
328 | EDJE_EXTERNAL_PARAM_INFO_DOUBLE_DEFAULT("max", 10.0), | ||
329 | EDJE_EXTERNAL_PARAM_INFO_DOUBLE("value"), | ||
330 | EDJE_EXTERNAL_PARAM_INFO_BOOL("horizontal"), | ||
331 | EDJE_EXTERNAL_PARAM_INFO_BOOL("inverted"), | ||
332 | EDJE_EXTERNAL_PARAM_INFO_INT("span"), | ||
333 | EDJE_EXTERNAL_PARAM_INFO_STRING_DEFAULT("unit format", "%1.2f"), | ||
334 | EDJE_EXTERNAL_PARAM_INFO_STRING_DEFAULT("indicator format", "%1.2f"), | ||
335 | EDJE_EXTERNAL_PARAM_INFO_SENTINEL | ||
336 | }; | ||
337 | |||
338 | DEFINE_EXTERNAL_ICON_ADD(slider, "slider") | ||
339 | DEFINE_EXTERNAL_TYPE_SIMPLE(slider, "Slider") | ||