1 #include <Elementary.h>
5 * @defgroup Progressbar Progressbar
8 * The progressbar adds a widget for representing current progress
11 * A progressbar can be horizontal or vertical. It can contain an Icon and has a
12 * primary label as well as a units label (that is formatted with floating
13 * point values and thus accepts a printf-style format string, like
16 * Label, Icon and Unit strings/objects are optional.
18 * A progressbar may be inverted which means values invert, with high vales being
19 * on the left or top and low values on the right or bottom (as opposed to
20 * normally being low on the left or top and high on the bottom and right).
22 * The span of the progressbar is its length (horizontally or vertically).
23 * This will be scaled by the object or applications scaling factor. At any point
24 * code can query the progressbar for its value with elm_progressbar_value_get().
27 #define MIN_RATIO_LVL 0.0
28 #define MAX_RATIO_LVL 1.0
30 typedef struct _Widget_Data Widget_Data;
34 Evas_Object *progressbar;
38 Eina_Bool horizontal : 1;
39 Eina_Bool inverted : 1;
41 Eina_Bool pulse_state : 1;
47 static const char *widtype = NULL;
48 static void _del_hook(Evas_Object *obj);
49 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
50 static void _theme_hook(Evas_Object *obj);
51 static void _sizing_eval(Evas_Object *obj);
52 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
53 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
54 static void _units_set(Evas_Object *obj);
55 static void _val_set(Evas_Object *obj);
58 _del_hook(Evas_Object *obj)
60 Widget_Data *wd = elm_widget_data_get(obj);
62 if (wd->label) eina_stringshare_del(wd->label);
63 if (wd->units) eina_stringshare_del(wd->units);
68 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
70 Widget_Data *wd = elm_widget_data_get(obj);
72 edje_object_mirrored_set(wd->progressbar, rtl);
76 _theme_hook(Evas_Object *obj)
78 Widget_Data *wd = elm_widget_data_get(obj);
80 _elm_widget_mirrored_reload(obj);
81 _mirrored_set(obj, elm_widget_mirrored_get(obj));
83 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "horizontal", elm_widget_style_get(obj));
85 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "vertical", elm_widget_style_get(obj));
89 edje_object_part_swallow(wd->progressbar, "elm.swallow.content", wd->icon);
90 edje_object_signal_emit(wd->progressbar, "elm,state,icon,visible", "elm");
94 edje_object_part_text_set(wd->progressbar, "elm.text", wd->label);
95 edje_object_signal_emit(wd->progressbar, "elm,state,text,visible", "elm");
98 edje_object_signal_emit(wd->progressbar, "elm,state,pulse", "elm");
100 edje_object_signal_emit(wd->progressbar, "elm,state,fraction", "elm");
102 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,start", "elm");
104 if ((wd->units) && (!wd->pulse))
105 edje_object_signal_emit(wd->progressbar, "elm,state,units,visible", "elm");
108 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
110 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
112 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
115 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,on", "elm");
118 edje_object_message_signal_process(wd->progressbar);
119 edje_object_scale_set(wd->progressbar, elm_widget_scale_get(obj) * _elm_config->scale);
125 _sizing_eval(Evas_Object *obj)
127 Widget_Data *wd = elm_widget_data_get(obj);
128 Evas_Coord minw = -1, minh = -1;
130 edje_object_size_min_restricted_calc(wd->progressbar, &minw, &minh, minw, minh);
131 evas_object_size_hint_min_set(obj, minw, minh);
132 evas_object_size_hint_max_set(obj, -1, -1);
136 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
138 Widget_Data *wd = elm_widget_data_get(data);
140 if (obj != wd->icon) return;
145 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
147 Widget_Data *wd = elm_widget_data_get(obj);
148 Evas_Object *sub = event_info;
152 edje_object_signal_emit(wd->progressbar, "elm,state,icon,hidden", "elm");
153 evas_object_event_callback_del_full
154 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
156 edje_object_message_signal_process(wd->progressbar);
162 _val_set(Evas_Object *obj)
164 Widget_Data *wd = elm_widget_data_get(obj);
169 rtl = elm_widget_mirrored_get(obj);
170 if ((!rtl && wd->inverted) || (rtl &&
171 ((!wd->horizontal && wd->inverted) ||
172 (wd->horizontal && !wd->inverted)))) pos = MAX_RATIO_LVL - pos;
173 edje_object_part_drag_value_set(wd->progressbar, "elm.cur.progressbar", pos, pos);
177 _units_set(Evas_Object *obj)
179 Widget_Data *wd = elm_widget_data_get(obj);
184 snprintf(buf, sizeof(buf), wd->units, 100 * wd->val);
185 edje_object_part_text_set(wd->progressbar, "elm.text.status", buf);
188 edje_object_part_text_set(wd->progressbar, "elm.text.status", NULL);
192 _elm_progressbar_label_set(Evas_Object *obj, const char *item, const char *label)
194 ELM_CHECK_WIDTYPE(obj, widtype);
195 Widget_Data *wd = elm_widget_data_get(obj);
196 if (item && strcmp(item, "default")) return;
198 eina_stringshare_replace(&wd->label, label);
201 edje_object_signal_emit(wd->progressbar, "elm,state,text,visible", "elm");
202 edje_object_message_signal_process(wd->progressbar);
206 edje_object_signal_emit(wd->progressbar, "elm,state,text,hidden", "elm");
207 edje_object_message_signal_process(wd->progressbar);
209 edje_object_part_text_set(wd->progressbar, "elm.text", label);
214 _elm_progressbar_label_get(const Evas_Object *obj, const char *item)
216 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
217 Widget_Data *wd = elm_widget_data_get(obj);
218 if (item && strcmp(item, "default")) return NULL;
219 if (!wd) return NULL;
224 * Add a new progressbar to the parent
226 * @param parent The parent object
227 * @return The new object or NULL if it cannot be created
229 * @ingroup Progressbar
232 elm_progressbar_add(Evas_Object *parent)
238 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
240 ELM_SET_WIDTYPE(widtype, "progressbar");
241 elm_widget_type_set(obj, "progressbar");
242 elm_widget_sub_object_add(parent, obj);
243 elm_widget_data_set(obj, wd);
244 elm_widget_del_hook_set(obj, _del_hook);
245 elm_widget_theme_hook_set(obj, _theme_hook);
246 elm_widget_can_focus_set(obj, EINA_FALSE);
247 elm_widget_text_set_hook_set(obj, _elm_progressbar_label_set);
248 elm_widget_text_get_hook_set(obj, _elm_progressbar_label_get);
250 wd->horizontal = EINA_TRUE;
251 wd->inverted = EINA_FALSE;
252 wd->pulse = EINA_FALSE;
253 wd->pulse_state = EINA_FALSE;
254 wd->units = eina_stringshare_add("%.0f %%");
255 wd->val = MIN_RATIO_LVL;
257 wd->progressbar = edje_object_add(e);
258 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "horizontal", "default");
259 elm_widget_resize_object_set(obj, wd->progressbar);
261 wd->spacer = evas_object_rectangle_add(e);
262 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
263 evas_object_pass_events_set(wd->spacer, EINA_TRUE);
264 elm_widget_sub_object_add(obj, wd->spacer);
265 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
267 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
270 _mirrored_set(obj, elm_widget_mirrored_get(obj));
276 * Normally the progressbar will display and interpret values from low to high.
277 * This display a progressbar for jobs with unknow state of progression,
278 * (the cursor pulse right to left and left to right, and loop) if pulse is set to 1.
280 * @param obj The progressbar object
281 * @param pulse The pulse flag. 1 == pulse, 0 == normal
283 * @ingroup Progressbar
286 elm_progressbar_pulse_set(Evas_Object *obj, Eina_Bool pulse)
288 ELM_CHECK_WIDTYPE(obj, widtype);
289 Widget_Data *wd = elm_widget_data_get(obj);
292 if (wd->pulse == pulse) return;
298 * Normally the progressbar will display and interpret values from low to high.
299 * This display a progressbar for jobs with unknow state of progression,
300 * (the cursor pulse right to left and left to right, and loop) if pulse is set to 1.
302 * @param obj The progressbar object
303 * @return The pulse flag
304 * (1 == pulse, 0 == normal)
306 * @ingroup Progressbar
309 elm_progressbar_pulse_get(const Evas_Object *obj)
311 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
312 Widget_Data *wd = elm_widget_data_get(obj);
313 if (!wd) return EINA_FALSE;
318 * Stat/Stop de pulse action
320 * @param obj The progressbar object
321 * @param state The pulse flag. 1 == start pulse, 0 == stop pulse
323 * @ingroup Progressbar
326 elm_progressbar_pulse(Evas_Object *obj, Eina_Bool state)
328 ELM_CHECK_WIDTYPE(obj, widtype);
329 Widget_Data *wd = elm_widget_data_get(obj);
332 if ((!wd->pulse) && (wd->pulse_state == state)) return;
333 wd->pulse_state = state;
335 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,start", "elm");
337 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,stop", "elm");
341 * Set the value the progressbar indicates
343 * @param obj The progressbar object
344 * @param val The fraction value (must be between 0.0 and 1.0)
346 * @ingroup Progressbar
349 elm_progressbar_value_set(Evas_Object *obj, double val)
351 ELM_CHECK_WIDTYPE(obj, widtype);
352 Widget_Data *wd = elm_widget_data_get(obj);
354 if (wd->val == val) return;
356 if (wd->val < MIN_RATIO_LVL) wd->val = MIN_RATIO_LVL;
357 if (wd->val > MAX_RATIO_LVL) wd->val = MAX_RATIO_LVL;
364 * Get the value the progressbar has
366 * @param obj The progressbar object
367 * @return The value of the progressbar
369 * @ingroup Progressbar
372 elm_progressbar_value_get(const Evas_Object *obj)
374 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
375 Widget_Data *wd = elm_widget_data_get(obj);
381 * Set the label of the progressbar
383 * @param obj The progressbar object
384 * @param label The text label string in UTF-8
386 * @ingroup Progressbar
387 * @deprecated use elm_object_text_set() instead.
390 elm_progressbar_label_set(Evas_Object *obj, const char *label)
392 _elm_progressbar_label_set(obj, NULL, label);
396 * Get the label of the progressbar
398 * @param obj The progressbar object
399 * @return The text label string in UTF-8
401 * @ingroup Progressbar
402 * @deprecated use elm_object_text_set() instead.
405 elm_progressbar_label_get(const Evas_Object *obj)
407 return _elm_progressbar_label_get(obj, NULL);
411 * Set the icon object of the progressbar object
413 * Once the icon object is set, a previously set one will be deleted.
414 * If you want to keep that old content object, use the
415 * elm_progressbar_icon_unset() function.
417 * @param obj The progressbar object
418 * @param icon The icon object
420 * @ingroup Progressbar
423 elm_progressbar_icon_set(Evas_Object *obj, Evas_Object *icon)
425 ELM_CHECK_WIDTYPE(obj, widtype);
426 Widget_Data *wd = elm_widget_data_get(obj);
428 if (wd->icon == icon) return;
429 if (wd->icon) evas_object_del(wd->icon);
433 elm_widget_sub_object_add(obj, icon);
434 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
435 _changed_size_hints, obj);
436 edje_object_part_swallow(wd->progressbar, "elm.swallow.content", icon);
437 edje_object_signal_emit(wd->progressbar, "elm,state,icon,visible", "elm");
438 edje_object_message_signal_process(wd->progressbar);
444 * Get the icon object of the progressbar object
446 * @param obj The progressbar object
447 * @return The icon object
449 * @ingroup Progressbar
452 elm_progressbar_icon_get(const Evas_Object *obj)
454 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
455 Widget_Data *wd = elm_widget_data_get(obj);
456 if (!wd) return NULL;
461 * Unset the icon used for the progressbar object
463 * Unparent and return the icon object which was set for this widget.
465 * @param obj The progressbar object
466 * @return The icon object that was being used
468 * @ingroup Progressbar
471 elm_progressbar_icon_unset(Evas_Object *obj)
473 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
474 Widget_Data *wd = elm_widget_data_get(obj);
475 if (!wd) return NULL;
476 if (!wd->icon) return NULL;
477 Evas_Object *icon = wd->icon;
478 elm_widget_sub_object_del(obj, wd->icon);
479 edje_object_part_unswallow(wd->progressbar, wd->icon);
485 * Set the length of the progression region of the progressbar
487 * This sets the minimum width or height (depending on orientation) of the
488 * area of the progressbar that allows the progressbar to be dragged around. This in
489 * turn affects the objects minimum size (along with icon label and unit
492 * @param obj The progressbar object
493 * @param size The length of the progressbar area
495 * @ingroup Progressbar
498 elm_progressbar_span_size_set(Evas_Object *obj, Evas_Coord size)
500 ELM_CHECK_WIDTYPE(obj, widtype);
501 Widget_Data *wd = elm_widget_data_get(obj);
503 if (wd->size == size) return;
506 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
508 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
509 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
514 * Get the length of the progression region of the progressbar
516 * @param obj The progressbar object
517 * @return The length of the progressbar area
519 * @ingroup Progressbar
522 elm_progressbar_span_size_get(const Evas_Object *obj)
524 ELM_CHECK_WIDTYPE(obj, widtype) 0;
525 Widget_Data *wd = elm_widget_data_get(obj);
531 * Set the format string of the unit area
533 * If NULL, this disabls the unit area display. If not it sets the format
534 * string for the unit text. The unit text is provided a floating point
535 * value, so the unit text can display up to 1 floating point falue. Note that
536 * this is optional. Use a format string such as "%1.2f meters" for example.
538 * @param obj The progressbar object
539 * @param units The format string for the units display
541 * @ingroup Progressbar
544 elm_progressbar_unit_format_set(Evas_Object *obj, const char *units)
546 ELM_CHECK_WIDTYPE(obj, widtype);
547 Widget_Data *wd = elm_widget_data_get(obj);
549 eina_stringshare_replace(&wd->units, units);
552 edje_object_signal_emit(wd->progressbar, "elm,state,units,visible", "elm");
553 edje_object_message_signal_process(wd->progressbar);
557 edje_object_signal_emit(wd->progressbar, "elm,state,units,hidden", "elm");
558 edje_object_message_signal_process(wd->progressbar);
565 * Get the format string of the unit area
567 * @param obj The progressbar object
568 * @return The format string for the units display
570 * @ingroup Progressbar
573 elm_progressbar_unit_format_get(const Evas_Object *obj)
575 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
576 Widget_Data *wd = elm_widget_data_get(obj);
577 if (!wd) return NULL;
582 * Set orientation of the progressbar
584 * @param obj The progressbar object
585 * @param horizontal If set, the progressbar will be horizontal
587 * @ingroup Progressbar
590 elm_progressbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
592 ELM_CHECK_WIDTYPE(obj, widtype);
593 Widget_Data *wd = elm_widget_data_get(obj);
595 horizontal = !!horizontal;
596 if (wd->horizontal == horizontal) return;
597 wd->horizontal = horizontal;
602 * Gets orientation of the progressbar
604 * @param obj The progressbar object
605 * @return The orientation
606 * (0 = vertical, 1 = horizontal)
608 * @ingroup Progressbar
611 elm_progressbar_horizontal_get(const Evas_Object *obj)
613 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
614 Widget_Data *wd = elm_widget_data_get(obj);
615 if (!wd) return EINA_FALSE;
616 return wd->horizontal;
620 * Invert the progressbar display
622 * Normally the progressbar will display and interpret values from low to high
623 * and when horizontal that is left to right. When vertical that is top
624 * to bottom. This inverts this (so from right to left or bottom to top) if
625 * inverted is set to 1.
627 * @param obj The progressbar object
628 * @param inverted The inverted flag. 1 == inverted, 0 == normal
630 * @ingroup Progressbar
633 elm_progressbar_inverted_set(Evas_Object *obj, Eina_Bool inverted)
635 ELM_CHECK_WIDTYPE(obj, widtype);
636 Widget_Data *wd = elm_widget_data_get(obj);
638 inverted = !!inverted;
639 if (wd->inverted == inverted) return;
640 wd->inverted = inverted;
642 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,on", "elm");
644 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,off", "elm");
645 edje_object_message_signal_process(wd->progressbar);
651 * Gets if the progressbar will displayed inverted
653 * @param obj The progressbar object
654 * @return The inverted flag
655 * (1 == inverted, 0 == normal)
657 * @ingroup Progressbar
660 elm_progressbar_inverted_get(const Evas_Object *obj)
662 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
663 Widget_Data *wd = elm_widget_data_get(obj);
664 if (!wd) return EINA_FALSE;