1 #include <Elementary.h>
5 * @defgroup Progressbar Progressbar
7 * The progressbar adds a widget for representing current progress
10 * A progressbar can be horizontal or vertical. It can contain an Icon and has a
11 * primary label as well as a units label (that is formatted with floating
12 * point values and thus accepts a printf-style format string, like
15 * Label, Icon and Unit strings/objects are optional.
17 * A progressbar may be inverted which means values invert, with high vales being
18 * on the left or top and low values on the right or bottom (as opposed to
19 * normally being low on the left or top and high on the bottom and right).
21 * The span of the progressbar is its length (horizontally or vertically).
22 * This will be scaled by the object or applications scaling factor. At any point
23 * code can query the progressbar for its value with elm_progressbar_value_get().
26 #define MIN_RATIO_LVL 0.0
27 #define MAX_RATIO_LVL 1.0
29 typedef struct _Widget_Data Widget_Data;
33 Evas_Object *progressbar;
37 Eina_Bool horizontal : 1;
38 Eina_Bool inverted : 1;
40 Eina_Bool pulse_state : 1;
46 static const char *widtype = NULL;
47 static void _del_hook(Evas_Object *obj);
48 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
49 static void _theme_hook(Evas_Object *obj);
50 static void _sizing_eval(Evas_Object *obj);
51 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
52 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
53 static void _units_set(Evas_Object *obj);
54 static void _val_set(Evas_Object *obj);
57 _del_hook(Evas_Object *obj)
59 Widget_Data *wd = elm_widget_data_get(obj);
61 if (wd->label) eina_stringshare_del(wd->label);
62 if (wd->units) eina_stringshare_del(wd->units);
67 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
69 Widget_Data *wd = elm_widget_data_get(obj);
71 edje_object_mirrored_set(wd->progressbar, rtl);
75 _theme_hook(Evas_Object *obj)
77 Widget_Data *wd = elm_widget_data_get(obj);
79 _elm_widget_mirrored_reload(obj);
80 _mirrored_set(obj, elm_widget_mirrored_get(obj));
82 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "horizontal", elm_widget_style_get(obj));
84 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "vertical", elm_widget_style_get(obj));
88 edje_object_part_swallow(wd->progressbar, "elm.swallow.content", wd->icon);
89 edje_object_signal_emit(wd->progressbar, "elm,state,icon,visible", "elm");
93 edje_object_part_text_set(wd->progressbar, "elm.text", wd->label);
94 edje_object_signal_emit(wd->progressbar, "elm,state,text,visible", "elm");
97 edje_object_signal_emit(wd->progressbar, "elm,state,pulse", "elm");
99 edje_object_signal_emit(wd->progressbar, "elm,state,fraction", "elm");
101 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,start", "elm");
103 if ((wd->units) && (!wd->pulse))
104 edje_object_signal_emit(wd->progressbar, "elm,state,units,visible", "elm");
107 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
109 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
111 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
114 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,on", "elm");
117 edje_object_message_signal_process(wd->progressbar);
118 edje_object_scale_set(wd->progressbar, elm_widget_scale_get(obj) * _elm_config->scale);
124 _sizing_eval(Evas_Object *obj)
126 Widget_Data *wd = elm_widget_data_get(obj);
127 Evas_Coord minw = -1, minh = -1;
129 edje_object_size_min_restricted_calc(wd->progressbar, &minw, &minh, minw, minh);
130 evas_object_size_hint_min_set(obj, minw, minh);
131 evas_object_size_hint_max_set(obj, -1, -1);
135 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
137 Widget_Data *wd = elm_widget_data_get(data);
139 if (obj != wd->icon) return;
144 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
146 Widget_Data *wd = elm_widget_data_get(obj);
147 Evas_Object *sub = event_info;
151 edje_object_signal_emit(wd->progressbar, "elm,state,icon,hidden", "elm");
152 evas_object_event_callback_del_full
153 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
155 edje_object_message_signal_process(wd->progressbar);
161 _val_set(Evas_Object *obj)
163 Widget_Data *wd = elm_widget_data_get(obj);
168 rtl = elm_widget_mirrored_get(obj);
169 if ((!rtl && wd->inverted) || (rtl &&
170 ((!wd->horizontal && wd->inverted) ||
171 (wd->horizontal && !wd->inverted)))) pos = MAX_RATIO_LVL - pos;
172 edje_object_part_drag_value_set(wd->progressbar, "elm.cur.progressbar", pos, pos);
176 _units_set(Evas_Object *obj)
178 Widget_Data *wd = elm_widget_data_get(obj);
183 snprintf(buf, sizeof(buf), wd->units, 100 * wd->val);
184 edje_object_part_text_set(wd->progressbar, "elm.text.status", buf);
187 edje_object_part_text_set(wd->progressbar, "elm.text.status", NULL);
191 * Add a new progressbar to the parent
193 * @param parent The parent object
194 * @return The new object or NULL if it cannot be created
196 * @ingroup Progressbar
199 elm_progressbar_add(Evas_Object *parent)
205 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
207 ELM_SET_WIDTYPE(widtype, "progressbar");
208 elm_widget_type_set(obj, "progressbar");
209 elm_widget_sub_object_add(parent, obj);
210 elm_widget_data_set(obj, wd);
211 elm_widget_del_hook_set(obj, _del_hook);
212 elm_widget_theme_hook_set(obj, _theme_hook);
213 elm_widget_can_focus_set(obj, EINA_FALSE);
215 wd->horizontal = EINA_TRUE;
216 wd->inverted = EINA_FALSE;
217 wd->pulse = EINA_FALSE;
218 wd->pulse_state = EINA_FALSE;
219 wd->units = eina_stringshare_add("%.0f %%");
220 wd->val = MIN_RATIO_LVL;
222 wd->progressbar = edje_object_add(e);
223 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "horizontal", "default");
224 elm_widget_resize_object_set(obj, wd->progressbar);
226 wd->spacer = evas_object_rectangle_add(e);
227 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
228 evas_object_pass_events_set(wd->spacer, EINA_TRUE);
229 elm_widget_sub_object_add(obj, wd->spacer);
230 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
232 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
235 _mirrored_set(obj, elm_widget_mirrored_get(obj));
241 * Normally the progressbar will display and interpret values from low to high.
242 * This display a progressbar for jobs with unknow state of progression,
243 * (the cursor pulse right to left and left to right, and loop) if pulse is set to 1.
245 * @param obj The progressbar object
246 * @param pulse The pulse flag. 1 == pulse, 0 == normal
248 * @ingroup Progressbar
251 elm_progressbar_pulse_set(Evas_Object *obj, Eina_Bool pulse)
253 ELM_CHECK_WIDTYPE(obj, widtype);
254 Widget_Data *wd = elm_widget_data_get(obj);
257 if (wd->pulse == pulse) return;
263 * Normally the progressbar will display and interpret values from low to high.
264 * This display a progressbar for jobs with unknow state of progression,
265 * (the cursor pulse right to left and left to right, and loop) if pulse is set to 1.
267 * @param obj The progressbar object
268 * @return The pulse flag
269 * (1 == pulse, 0 == normal)
271 * @ingroup Progressbar
274 elm_progressbar_pulse_get(const Evas_Object *obj)
276 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
277 Widget_Data *wd = elm_widget_data_get(obj);
278 if (!wd) return EINA_FALSE;
283 * Stat/Stop de pulse action
285 * @param obj The progressbar object
286 * @param state The pulse flag. 1 == start pulse, 0 == stop pulse
288 * @ingroup Progressbar
291 elm_progressbar_pulse(Evas_Object *obj, Eina_Bool state)
293 ELM_CHECK_WIDTYPE(obj, widtype);
294 Widget_Data *wd = elm_widget_data_get(obj);
297 if ((!wd->pulse) && (wd->pulse_state == state)) return;
298 wd->pulse_state = state;
300 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,start", "elm");
302 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,stop", "elm");
306 * Set the value the progressbar indicates
308 * @param obj The progressbar object
309 * @param val The fraction value (must be between 0.0 and 1.0)
311 * @ingroup Progressbar
314 elm_progressbar_value_set(Evas_Object *obj, double val)
316 ELM_CHECK_WIDTYPE(obj, widtype);
317 Widget_Data *wd = elm_widget_data_get(obj);
319 if (wd->val == val) return;
321 if (wd->val < MIN_RATIO_LVL) wd->val = MIN_RATIO_LVL;
322 if (wd->val > MAX_RATIO_LVL) wd->val = MAX_RATIO_LVL;
329 * Get the value the progressbar has
331 * @param obj The progressbar object
332 * @return The value of the progressbar
334 * @ingroup Progressbar
337 elm_progressbar_value_get(const Evas_Object *obj)
339 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
340 Widget_Data *wd = elm_widget_data_get(obj);
346 * Set the label of the progressbar
348 * @param obj The progressbar object
349 * @param label The text label string in UTF-8
351 * @ingroup Progressbar
354 elm_progressbar_label_set(Evas_Object *obj, const char *label)
356 ELM_CHECK_WIDTYPE(obj, widtype);
357 Widget_Data *wd = elm_widget_data_get(obj);
359 eina_stringshare_replace(&wd->label, label);
362 edje_object_signal_emit(wd->progressbar, "elm,state,text,visible", "elm");
363 edje_object_message_signal_process(wd->progressbar);
367 edje_object_signal_emit(wd->progressbar, "elm,state,text,hidden", "elm");
368 edje_object_message_signal_process(wd->progressbar);
370 edje_object_part_text_set(wd->progressbar, "elm.text", label);
375 * Get the label of the progressbar
377 * @param obj The progressbar object
378 * @return The text label string in UTF-8
380 * @ingroup Progressbar
383 elm_progressbar_label_get(const Evas_Object *obj)
385 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
386 Widget_Data *wd = elm_widget_data_get(obj);
387 if (!wd) return NULL;
392 * Set the icon object of the progressbar object
394 * Once the icon object is set, a previously set one will be deleted.
395 * If you want to keep that old content object, use the
396 * elm_progressbar_icon_unset() function.
398 * @param obj The progressbar object
399 * @param icon The icon object
401 * @ingroup Progressbar
404 elm_progressbar_icon_set(Evas_Object *obj, Evas_Object *icon)
406 ELM_CHECK_WIDTYPE(obj, widtype);
407 Widget_Data *wd = elm_widget_data_get(obj);
409 if (wd->icon == icon) return;
410 if (wd->icon) evas_object_del(wd->icon);
414 elm_widget_sub_object_add(obj, icon);
415 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
416 _changed_size_hints, obj);
417 edje_object_part_swallow(wd->progressbar, "elm.swallow.content", icon);
418 edje_object_signal_emit(wd->progressbar, "elm,state,icon,visible", "elm");
419 edje_object_message_signal_process(wd->progressbar);
425 * Get the icon object of the progressbar object
427 * @param obj The progressbar object
428 * @return The icon object
430 * @ingroup Progressbar
433 elm_progressbar_icon_get(const Evas_Object *obj)
435 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
436 Widget_Data *wd = elm_widget_data_get(obj);
437 if (!wd) return NULL;
442 * Unset the icon used for the progressbar object
444 * Unparent and return the icon object which was set for this widget.
446 * @param obj The progressbar object
447 * @return The icon object that was being used
449 * @ingroup Progressbar
452 elm_progressbar_icon_unset(Evas_Object *obj)
454 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
455 Widget_Data *wd = elm_widget_data_get(obj);
456 if (!wd) return NULL;
457 if (!wd->icon) return NULL;
458 Evas_Object *icon = wd->icon;
459 elm_widget_sub_object_del(obj, wd->icon);
460 edje_object_part_unswallow(wd->progressbar, wd->icon);
466 * Set the length of the progression region of the progressbar
468 * This sets the minimum width or height (depending on orientation) of the
469 * area of the progressbar that allows the progressbar to be dragged around. This in
470 * turn affects the objects minimum size (along with icon label and unit
473 * @param obj The progressbar object
474 * @param size The length of the progressbar area
476 * @ingroup Progressbar
479 elm_progressbar_span_size_set(Evas_Object *obj, Evas_Coord size)
481 ELM_CHECK_WIDTYPE(obj, widtype);
482 Widget_Data *wd = elm_widget_data_get(obj);
484 if (wd->size == size) return;
487 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
489 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
490 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
495 * Get the length of the progression region of the progressbar
497 * @param obj The progressbar object
498 * @return The length of the progressbar area
500 * @ingroup Progressbar
503 elm_progressbar_span_size_get(const Evas_Object *obj)
505 ELM_CHECK_WIDTYPE(obj, widtype) 0;
506 Widget_Data *wd = elm_widget_data_get(obj);
512 * Set the format string of the unit area
514 * If NULL, this disabls the unit area display. If not it sets the format
515 * string for the unit text. The unit text is provided a floating point
516 * value, so the unit text can display up to 1 floating point falue. Note that
517 * this is optional. Use a format string such as "%1.2f meters" for example.
519 * @param obj The progressbar object
520 * @param units The format string for the units display
522 * @ingroup Progressbar
525 elm_progressbar_unit_format_set(Evas_Object *obj, const char *units)
527 ELM_CHECK_WIDTYPE(obj, widtype);
528 Widget_Data *wd = elm_widget_data_get(obj);
530 eina_stringshare_replace(&wd->units, units);
533 edje_object_signal_emit(wd->progressbar, "elm,state,units,visible", "elm");
534 edje_object_message_signal_process(wd->progressbar);
538 edje_object_signal_emit(wd->progressbar, "elm,state,units,hidden", "elm");
539 edje_object_message_signal_process(wd->progressbar);
546 * Get the format string of the unit area
548 * @param obj The progressbar object
549 * @return The format string for the units display
551 * @ingroup Progressbar
554 elm_progressbar_unit_format_get(const Evas_Object *obj)
556 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
557 Widget_Data *wd = elm_widget_data_get(obj);
558 if (!wd) return NULL;
563 * Set orientation of the progressbar
565 * @param obj The progressbar object
566 * @param horizontal If set, the progressbar will be horizontal
568 * @ingroup Progressbar
571 elm_progressbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
573 ELM_CHECK_WIDTYPE(obj, widtype);
574 Widget_Data *wd = elm_widget_data_get(obj);
576 horizontal = !!horizontal;
577 if (wd->horizontal == horizontal) return;
578 wd->horizontal = horizontal;
583 * Gets orientation of the progressbar
585 * @param obj The progressbar object
586 * @return The orientation
587 * (0 = vertical, 1 = horizontal)
589 * @ingroup Progressbar
592 elm_progressbar_horizontal_get(const Evas_Object *obj)
594 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
595 Widget_Data *wd = elm_widget_data_get(obj);
596 if (!wd) return EINA_FALSE;
597 return wd->horizontal;
601 * Invert the progressbar display
603 * Normally the progressbar will display and interpret values from low to high
604 * and when horizontal that is left to right. When vertical that is top
605 * to bottom. This inverts this (so from right to left or bottom to top) if
606 * inverted is set to 1.
608 * @param obj The progressbar object
609 * @param inverted The inverted flag. 1 == inverted, 0 == normal
611 * @ingroup Progressbar
614 elm_progressbar_inverted_set(Evas_Object *obj, Eina_Bool inverted)
616 ELM_CHECK_WIDTYPE(obj, widtype);
617 Widget_Data *wd = elm_widget_data_get(obj);
619 inverted = !!inverted;
620 if (wd->inverted == inverted) return;
621 wd->inverted = inverted;
623 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,on", "elm");
625 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,off", "elm");
626 edje_object_message_signal_process(wd->progressbar);
632 * Gets if the progressbar will displayed inverted
634 * @param obj The progressbar object
635 * @return The inverted flag
636 * (1 == inverted, 0 == normal)
638 * @ingroup Progressbar
641 elm_progressbar_inverted_get(const Evas_Object *obj)
643 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
644 Widget_Data *wd = elm_widget_data_get(obj);
645 if (!wd) return EINA_FALSE;