1 #include <Elementary.h>
4 #define MIN_RATIO_LVL 0.0
5 #define MAX_RATIO_LVL 1.0
7 typedef struct _Widget_Data Widget_Data;
11 Evas_Object *progressbar;
15 Eina_Bool horizontal : 1;
16 Eina_Bool inverted : 1;
18 Eina_Bool pulse_state : 1;
24 static const char *widtype = NULL;
25 static void _del_hook(Evas_Object *obj);
26 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
27 static void _theme_hook(Evas_Object *obj);
28 static void _sizing_eval(Evas_Object *obj);
29 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
30 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
31 static void _units_set(Evas_Object *obj);
32 static void _val_set(Evas_Object *obj);
35 _del_hook(Evas_Object *obj)
37 Widget_Data *wd = elm_widget_data_get(obj);
39 if (wd->label) eina_stringshare_del(wd->label);
40 if (wd->units) eina_stringshare_del(wd->units);
45 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
47 Widget_Data *wd = elm_widget_data_get(obj);
49 edje_object_mirrored_set(wd->progressbar, rtl);
53 _theme_hook(Evas_Object *obj)
55 Widget_Data *wd = elm_widget_data_get(obj);
57 _elm_widget_mirrored_reload(obj);
58 _mirrored_set(obj, elm_widget_mirrored_get(obj));
60 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "horizontal", elm_widget_style_get(obj));
62 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "vertical", elm_widget_style_get(obj));
66 edje_object_part_swallow(wd->progressbar, "elm.swallow.content", wd->icon);
67 edje_object_signal_emit(wd->progressbar, "elm,state,icon,visible", "elm");
71 edje_object_part_text_set(wd->progressbar, "elm.text", wd->label);
72 edje_object_signal_emit(wd->progressbar, "elm,state,text,visible", "elm");
75 edje_object_signal_emit(wd->progressbar, "elm,state,pulse", "elm");
77 edje_object_signal_emit(wd->progressbar, "elm,state,fraction", "elm");
79 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,start", "elm");
81 if ((wd->units) && (!wd->pulse))
82 edje_object_signal_emit(wd->progressbar, "elm,state,units,visible", "elm");
85 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
87 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
89 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
92 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,on", "elm");
95 edje_object_message_signal_process(wd->progressbar);
96 edje_object_scale_set(wd->progressbar, elm_widget_scale_get(obj) * _elm_config->scale);
102 _sizing_eval(Evas_Object *obj)
104 Widget_Data *wd = elm_widget_data_get(obj);
105 Evas_Coord minw = -1, minh = -1;
107 edje_object_size_min_restricted_calc(wd->progressbar, &minw, &minh, minw, minh);
108 evas_object_size_hint_min_set(obj, minw, minh);
109 evas_object_size_hint_max_set(obj, -1, -1);
113 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
115 Widget_Data *wd = elm_widget_data_get(data);
117 if (obj != wd->icon) return;
122 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
124 Widget_Data *wd = elm_widget_data_get(obj);
125 Evas_Object *sub = event_info;
129 edje_object_signal_emit(wd->progressbar, "elm,state,icon,hidden", "elm");
130 evas_object_event_callback_del_full
131 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
133 edje_object_message_signal_process(wd->progressbar);
139 _val_set(Evas_Object *obj)
141 Widget_Data *wd = elm_widget_data_get(obj);
146 rtl = elm_widget_mirrored_get(obj);
147 if ((!rtl && wd->inverted) || (rtl &&
148 ((!wd->horizontal && wd->inverted) ||
149 (wd->horizontal && !wd->inverted)))) pos = MAX_RATIO_LVL - pos;
150 edje_object_part_drag_value_set(wd->progressbar, "elm.cur.progressbar", pos, pos);
154 _units_set(Evas_Object *obj)
156 Widget_Data *wd = elm_widget_data_get(obj);
161 snprintf(buf, sizeof(buf), wd->units, 100 * wd->val);
162 edje_object_part_text_set(wd->progressbar, "elm.text.status", buf);
165 edje_object_part_text_set(wd->progressbar, "elm.text.status", NULL);
169 _elm_progressbar_label_set(Evas_Object *obj, const char *item, const char *label)
171 ELM_CHECK_WIDTYPE(obj, widtype);
172 Widget_Data *wd = elm_widget_data_get(obj);
173 if (item && strcmp(item, "default")) return;
175 eina_stringshare_replace(&wd->label, label);
178 edje_object_signal_emit(wd->progressbar, "elm,state,text,visible", "elm");
179 edje_object_message_signal_process(wd->progressbar);
183 edje_object_signal_emit(wd->progressbar, "elm,state,text,hidden", "elm");
184 edje_object_message_signal_process(wd->progressbar);
186 edje_object_part_text_set(wd->progressbar, "elm.text", label);
191 _elm_progressbar_label_get(const Evas_Object *obj, const char *item)
193 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
194 Widget_Data *wd = elm_widget_data_get(obj);
195 if (item && strcmp(item, "default")) return NULL;
196 if (!wd) return NULL;
201 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
203 ELM_CHECK_WIDTYPE(obj, widtype);
205 if (part && strcmp(part, "icon")) return;
206 wd = elm_widget_data_get(obj);
208 if (wd->icon == content) return;
209 if (wd->icon) evas_object_del(wd->icon);
213 elm_widget_sub_object_add(obj, content);
214 evas_object_event_callback_add(content,
215 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
216 _changed_size_hints, obj);
217 edje_object_part_swallow(wd->progressbar, "elm.swallow.content", content);
218 edje_object_signal_emit(wd->progressbar, "elm,state,icon,visible", "elm");
219 edje_object_message_signal_process(wd->progressbar);
225 _content_get_hook(const Evas_Object *obj, const char *part)
227 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
229 if (part && strcmp(part, "icon")) return NULL;
230 wd = elm_widget_data_get(obj);
231 if (!wd) return NULL;
236 _content_unset_hook(Evas_Object *obj, const char *part)
238 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
241 if (part && strcmp(part, "icon")) return NULL;
242 wd = elm_widget_data_get(obj);
243 if (!wd) return NULL;
244 if (!wd->icon) return NULL;
246 elm_widget_sub_object_del(obj, wd->icon);
247 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
248 _changed_size_hints, obj);
249 edje_object_part_unswallow(wd->progressbar, wd->icon);
256 elm_progressbar_add(Evas_Object *parent)
262 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
264 ELM_SET_WIDTYPE(widtype, "progressbar");
265 elm_widget_type_set(obj, "progressbar");
266 elm_widget_sub_object_add(parent, obj);
267 elm_widget_data_set(obj, wd);
268 elm_widget_del_hook_set(obj, _del_hook);
269 elm_widget_theme_hook_set(obj, _theme_hook);
270 elm_widget_can_focus_set(obj, EINA_FALSE);
271 elm_widget_text_set_hook_set(obj, _elm_progressbar_label_set);
272 elm_widget_text_get_hook_set(obj, _elm_progressbar_label_get);
273 elm_widget_content_set_hook_set(obj, _content_set_hook);
274 elm_widget_content_get_hook_set(obj, _content_get_hook);
275 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
277 wd->horizontal = EINA_TRUE;
278 wd->inverted = EINA_FALSE;
279 wd->pulse = EINA_FALSE;
280 wd->pulse_state = EINA_FALSE;
281 wd->units = eina_stringshare_add("%.0f %%");
282 wd->val = MIN_RATIO_LVL;
284 wd->progressbar = edje_object_add(e);
285 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "horizontal", "default");
286 elm_widget_resize_object_set(obj, wd->progressbar);
288 wd->spacer = evas_object_rectangle_add(e);
289 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
290 evas_object_pass_events_set(wd->spacer, EINA_TRUE);
291 elm_widget_sub_object_add(obj, wd->spacer);
292 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
294 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
297 _mirrored_set(obj, elm_widget_mirrored_get(obj));
303 elm_progressbar_pulse_set(Evas_Object *obj, Eina_Bool pulse)
305 ELM_CHECK_WIDTYPE(obj, widtype);
306 Widget_Data *wd = elm_widget_data_get(obj);
309 if (wd->pulse == pulse) return;
315 elm_progressbar_pulse_get(const Evas_Object *obj)
317 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
318 Widget_Data *wd = elm_widget_data_get(obj);
319 if (!wd) return EINA_FALSE;
324 elm_progressbar_pulse(Evas_Object *obj, Eina_Bool state)
326 ELM_CHECK_WIDTYPE(obj, widtype);
327 Widget_Data *wd = elm_widget_data_get(obj);
330 if ((!wd->pulse) && (wd->pulse_state == state)) return;
331 wd->pulse_state = state;
333 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,start", "elm");
335 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,stop", "elm");
339 elm_progressbar_value_set(Evas_Object *obj, double val)
341 ELM_CHECK_WIDTYPE(obj, widtype);
342 Widget_Data *wd = elm_widget_data_get(obj);
344 if (wd->val == val) return;
346 if (wd->val < MIN_RATIO_LVL) wd->val = MIN_RATIO_LVL;
347 if (wd->val > MAX_RATIO_LVL) wd->val = MAX_RATIO_LVL;
353 elm_progressbar_value_get(const Evas_Object *obj)
355 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
356 Widget_Data *wd = elm_widget_data_get(obj);
362 elm_progressbar_span_size_set(Evas_Object *obj, Evas_Coord size)
364 ELM_CHECK_WIDTYPE(obj, widtype);
365 Widget_Data *wd = elm_widget_data_get(obj);
367 if (wd->size == size) return;
370 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
372 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
373 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
378 elm_progressbar_span_size_get(const Evas_Object *obj)
380 ELM_CHECK_WIDTYPE(obj, widtype) 0;
381 Widget_Data *wd = elm_widget_data_get(obj);
387 elm_progressbar_unit_format_set(Evas_Object *obj, const char *units)
389 ELM_CHECK_WIDTYPE(obj, widtype);
390 Widget_Data *wd = elm_widget_data_get(obj);
392 eina_stringshare_replace(&wd->units, units);
395 edje_object_signal_emit(wd->progressbar, "elm,state,units,visible", "elm");
396 edje_object_message_signal_process(wd->progressbar);
400 edje_object_signal_emit(wd->progressbar, "elm,state,units,hidden", "elm");
401 edje_object_message_signal_process(wd->progressbar);
408 elm_progressbar_unit_format_get(const Evas_Object *obj)
410 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
411 Widget_Data *wd = elm_widget_data_get(obj);
412 if (!wd) return NULL;
417 elm_progressbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
419 ELM_CHECK_WIDTYPE(obj, widtype);
420 Widget_Data *wd = elm_widget_data_get(obj);
422 horizontal = !!horizontal;
423 if (wd->horizontal == horizontal) return;
424 wd->horizontal = horizontal;
429 elm_progressbar_horizontal_get(const Evas_Object *obj)
431 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
432 Widget_Data *wd = elm_widget_data_get(obj);
433 if (!wd) return EINA_FALSE;
434 return wd->horizontal;
438 elm_progressbar_inverted_set(Evas_Object *obj, Eina_Bool inverted)
440 ELM_CHECK_WIDTYPE(obj, widtype);
441 Widget_Data *wd = elm_widget_data_get(obj);
443 inverted = !!inverted;
444 if (wd->inverted == inverted) return;
445 wd->inverted = inverted;
447 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,on", "elm");
449 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,off", "elm");
450 edje_object_message_signal_process(wd->progressbar);
456 elm_progressbar_inverted_get(const Evas_Object *obj)
458 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
459 Widget_Data *wd = elm_widget_data_get(obj);
460 if (!wd) return EINA_FALSE;