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 _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 _theme_hook(Evas_Object *obj)
69 Widget_Data *wd = elm_widget_data_get(obj);
72 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "horizontal", elm_widget_style_get(obj));
74 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "vertical", elm_widget_style_get(obj));
78 edje_object_part_swallow(wd->progressbar, "elm.swallow.content", wd->icon);
79 edje_object_signal_emit(wd->progressbar, "elm,state,icon,visible", "elm");
83 edje_object_part_text_set(wd->progressbar, "elm.text", wd->label);
84 edje_object_signal_emit(wd->progressbar, "elm,state,text,visible", "elm");
87 edje_object_signal_emit(wd->progressbar, "elm,state,pulse", "elm");
89 edje_object_signal_emit(wd->progressbar, "elm,state,fraction", "elm");
91 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,start", "elm");
93 if ((wd->units) && (!wd->pulse))
94 edje_object_signal_emit(wd->progressbar, "elm,state,units,visible", "elm");
97 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
99 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
101 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
104 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,on", "elm");
107 edje_object_message_signal_process(wd->progressbar);
108 edje_object_scale_set(wd->progressbar, elm_widget_scale_get(obj) * _elm_config->scale);
114 _sizing_eval(Evas_Object *obj)
116 Widget_Data *wd = elm_widget_data_get(obj);
117 Evas_Coord minw = -1, minh = -1;
119 edje_object_size_min_restricted_calc(wd->progressbar, &minw, &minh, minw, minh);
120 evas_object_size_hint_min_set(obj, minw, minh);
121 evas_object_size_hint_max_set(obj, -1, -1);
125 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
127 Widget_Data *wd = elm_widget_data_get(data);
129 if (obj != wd->icon) return;
134 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
136 Widget_Data *wd = elm_widget_data_get(obj);
137 Evas_Object *sub = event_info;
141 edje_object_signal_emit(wd->progressbar, "elm,state,icon,hidden", "elm");
142 evas_object_event_callback_del_full
143 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
145 edje_object_message_signal_process(wd->progressbar);
151 _val_set(Evas_Object *obj)
153 Widget_Data *wd = elm_widget_data_get(obj);
157 if (wd->inverted) pos = MAX_RATIO_LVL - pos;
158 edje_object_part_drag_value_set(wd->progressbar, "elm.cur.progressbar", pos, pos);
162 _units_set(Evas_Object *obj)
164 Widget_Data *wd = elm_widget_data_get(obj);
169 snprintf(buf, sizeof(buf), wd->units, 100 * wd->val);
170 edje_object_part_text_set(wd->progressbar, "elm.text.status", buf);
173 edje_object_part_text_set(wd->progressbar, "elm.text.status", NULL);
177 * Add a new progressbar to the parent
179 * @param parent The parent object
180 * @return The new object or NULL if it cannot be created
182 * @ingroup Progressbar
185 elm_progressbar_add(Evas_Object *parent)
191 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
193 wd = ELM_NEW(Widget_Data);
194 e = evas_object_evas_get(parent);
196 obj = elm_widget_add(e);
197 ELM_SET_WIDTYPE(widtype, "progressbar");
198 elm_widget_type_set(obj, "progressbar");
199 elm_widget_sub_object_add(parent, obj);
200 elm_widget_data_set(obj, wd);
201 elm_widget_del_hook_set(obj, _del_hook);
202 elm_widget_theme_hook_set(obj, _theme_hook);
203 elm_widget_can_focus_set(obj, EINA_FALSE);
205 wd->horizontal = EINA_TRUE;
206 wd->inverted = EINA_FALSE;
207 wd->pulse = EINA_FALSE;
208 wd->pulse_state = EINA_FALSE;
209 wd->units = eina_stringshare_add("%.0f %%");
210 wd->val = MIN_RATIO_LVL;
212 wd->progressbar = edje_object_add(e);
213 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "horizontal", "default");
214 elm_widget_resize_object_set(obj, wd->progressbar);
216 wd->spacer = evas_object_rectangle_add(e);
217 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
218 evas_object_pass_events_set(wd->spacer, EINA_TRUE);
219 elm_widget_sub_object_add(obj, wd->spacer);
220 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
222 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
230 * Normally the progressbar will display and interpret values from low to high.
231 * This display a progressbar for jobs with unknow state of progression,
232 * (the cursor pulse right to left and left to right, and loop) if pulse is set to 1.
234 * @param obj The progressbar object
235 * @param pulse The pulse flag. 1 == pulse, 0 == normal
237 * @ingroup Progressbar
240 elm_progressbar_pulse_set(Evas_Object *obj, Eina_Bool pulse)
242 ELM_CHECK_WIDTYPE(obj, widtype);
243 Widget_Data *wd = elm_widget_data_get(obj);
246 if (wd->pulse == pulse) return;
252 * Normally the progressbar will display and interpret values from low to high.
253 * This display a progressbar for jobs with unknow state of progression,
254 * (the cursor pulse right to left and left to right, and loop) if pulse is set to 1.
256 * @param obj The progressbar object
257 * @return The pulse flag
258 * (1 == pulse, 0 == normal)
260 * @ingroup Progressbar
263 elm_progressbar_pulse_get(const Evas_Object *obj)
265 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
266 Widget_Data *wd = elm_widget_data_get(obj);
267 if (!wd) return EINA_FALSE;
272 * Stat/Stop de pulse action
274 * @param obj The progressbar object
275 * @param state The pulse flag. 1 == start pulse, 0 == stop pulse
277 * @ingroup Progressbar
280 elm_progressbar_pulse(Evas_Object *obj, Eina_Bool state)
282 ELM_CHECK_WIDTYPE(obj, widtype);
283 Widget_Data *wd = elm_widget_data_get(obj);
286 if ((!wd->pulse) && (wd->pulse_state == state)) return;
287 wd->pulse_state = state;
289 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,start", "elm");
291 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,stop", "elm");
295 * Set the value the progressbar indicates
297 * @param obj The progressbar object
298 * @param val The fraction value (must be between 0.0 and 1.0)
300 * @ingroup Progressbar
303 elm_progressbar_value_set(Evas_Object *obj, double val)
305 ELM_CHECK_WIDTYPE(obj, widtype);
306 Widget_Data *wd = elm_widget_data_get(obj);
308 if (wd->val == val) return;
310 if (wd->val < MIN_RATIO_LVL) wd->val = MIN_RATIO_LVL;
311 if (wd->val > MAX_RATIO_LVL) wd->val = MAX_RATIO_LVL;
318 * Get the value the progressbar has
320 * @param obj The progressbar object
321 * @return The value of the progressbar
323 * @ingroup Progressbar
326 elm_progressbar_value_get(const Evas_Object *obj)
328 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
329 Widget_Data *wd = elm_widget_data_get(obj);
335 * Set the label of the progressbar
337 * @param obj The progressbar object
338 * @param label The text label string in UTF-8
340 * @ingroup Progressbar
343 elm_progressbar_label_set(Evas_Object *obj, const char *label)
345 ELM_CHECK_WIDTYPE(obj, widtype);
346 Widget_Data *wd = elm_widget_data_get(obj);
348 eina_stringshare_replace(&wd->label, label);
351 edje_object_signal_emit(wd->progressbar, "elm,state,text,visible", "elm");
352 edje_object_message_signal_process(wd->progressbar);
356 edje_object_signal_emit(wd->progressbar, "elm,state,text,hidden", "elm");
357 edje_object_message_signal_process(wd->progressbar);
359 edje_object_part_text_set(wd->progressbar, "elm.text", label);
364 * Get the label of the progressbar
366 * @param obj The progressbar object
367 * @return The text label string in UTF-8
369 * @ingroup Progressbar
372 elm_progressbar_label_get(const Evas_Object *obj)
374 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
375 Widget_Data *wd = elm_widget_data_get(obj);
376 if (!wd) return NULL;
381 * Set the icon object of the progressbar object
383 * Once the icon object is set, a previously set one will be deleted.
384 * If you want to keep that old content object, use the
385 * elm_progressbar_icon_unset() function.
387 * @param obj The progressbar object
388 * @param icon The icon object
390 * @ingroup Progressbar
393 elm_progressbar_icon_set(Evas_Object *obj, Evas_Object *icon)
395 ELM_CHECK_WIDTYPE(obj, widtype);
396 Widget_Data *wd = elm_widget_data_get(obj);
398 if (wd->icon == icon) return;
399 if (wd->icon) evas_object_del(wd->icon);
403 elm_widget_sub_object_add(obj, icon);
404 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
405 _changed_size_hints, obj);
406 edje_object_part_swallow(wd->progressbar, "elm.swallow.content", icon);
407 edje_object_signal_emit(wd->progressbar, "elm,state,icon,visible", "elm");
408 edje_object_message_signal_process(wd->progressbar);
414 * Get the icon object of the progressbar object
416 * @param obj The progressbar object
417 * @return The icon object
419 * @ingroup Progressbar
422 elm_progressbar_icon_get(const Evas_Object *obj)
424 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
425 Widget_Data *wd = elm_widget_data_get(obj);
426 if (!wd) return NULL;
431 * Unset the icon used for the progressbar object
433 * Unparent and return the icon object which was set for this widget.
435 * @param obj The progressbar object
436 * @return The icon object that was being used
438 * @ingroup Progressbar
441 elm_progressbar_icon_unset(Evas_Object *obj)
443 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
444 Widget_Data *wd = elm_widget_data_get(obj);
445 if (!wd) return NULL;
446 if (!wd->icon) return NULL;
447 Evas_Object *icon = wd->icon;
448 elm_widget_sub_object_del(obj, wd->icon);
449 edje_object_part_unswallow(wd->progressbar, wd->icon);
455 * Set the length of the progression region of the progressbar
457 * This sets the minimum width or height (depending on orientation) of the
458 * area of the progressbar that allows the progressbar to be dragged around. This in
459 * turn affects the objects minimum size (along with icon label and unit
462 * @param obj The progressbar object
463 * @param size The length of the progressbar area
465 * @ingroup Progressbar
468 elm_progressbar_span_size_set(Evas_Object *obj, Evas_Coord size)
470 ELM_CHECK_WIDTYPE(obj, widtype);
471 Widget_Data *wd = elm_widget_data_get(obj);
473 if (wd->size == size) return;
476 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
478 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
479 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
484 * Get the length of the progression region of the progressbar
486 * @param obj The progressbar object
487 * @return The length of the progressbar area
489 * @ingroup Progressbar
492 elm_progressbar_span_size_get(const Evas_Object *obj)
494 ELM_CHECK_WIDTYPE(obj, widtype) 0;
495 Widget_Data *wd = elm_widget_data_get(obj);
501 * Set the format string of the unit area
503 * If NULL, this disabls the unit area display. If not it sets the format
504 * string for the unit text. The unit text is provided a floating point
505 * value, so the unit text can display up to 1 floating point falue. Note that
506 * this is optional. Use a format string such as "%1.2f meters" for example.
508 * @param obj The progressbar object
509 * @param units The format string for the units display
511 * @ingroup Progressbar
514 elm_progressbar_unit_format_set(Evas_Object *obj, const char *units)
516 ELM_CHECK_WIDTYPE(obj, widtype);
517 Widget_Data *wd = elm_widget_data_get(obj);
519 eina_stringshare_replace(&wd->units, units);
522 edje_object_signal_emit(wd->progressbar, "elm,state,units,visible", "elm");
523 edje_object_message_signal_process(wd->progressbar);
527 edje_object_signal_emit(wd->progressbar, "elm,state,units,hidden", "elm");
528 edje_object_message_signal_process(wd->progressbar);
535 * Get the format string of the unit area
537 * @param obj The progressbar object
538 * @return The format string for the units display
540 * @ingroup Progressbar
543 elm_progressbar_unit_format_get(const Evas_Object *obj)
545 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
546 Widget_Data *wd = elm_widget_data_get(obj);
547 if (!wd) return NULL;
552 * Set orientation of the progressbar
554 * @param obj The progressbar object
555 * @param horizontal If set, the progressbar will be horizontal
557 * @ingroup Progressbar
560 elm_progressbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
562 ELM_CHECK_WIDTYPE(obj, widtype);
563 Widget_Data *wd = elm_widget_data_get(obj);
565 horizontal = !!horizontal;
566 if (wd->horizontal == horizontal) return;
567 wd->horizontal = horizontal;
572 * Gets orientation of the progressbar
574 * @param obj The progressbar object
575 * @return The orientation
576 * (0 = vertical, 1 = horizontal)
578 * @ingroup Progressbar
581 elm_progressbar_horizontal_get(const Evas_Object *obj)
583 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
584 Widget_Data *wd = elm_widget_data_get(obj);
585 if (!wd) return EINA_FALSE;
586 return wd->horizontal;
590 * Invert the progressbar display
592 * Normally the progressbar will display and interpret values from low to high
593 * and when horizontal that is left to right. When vertical that is top
594 * to bottom. This inverts this (so from right to left or bottom to top) if
595 * inverted is set to 1.
597 * @param obj The progressbar object
598 * @param inverted The inverted flag. 1 == inverted, 0 == normal
600 * @ingroup Progressbar
603 elm_progressbar_inverted_set(Evas_Object *obj, Eina_Bool inverted)
605 ELM_CHECK_WIDTYPE(obj, widtype);
606 Widget_Data *wd = elm_widget_data_get(obj);
608 inverted = !!inverted;
609 if (wd->inverted == inverted) return;
610 wd->inverted = inverted;
612 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,on", "elm");
614 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,off", "elm");
615 edje_object_message_signal_process(wd->progressbar);
621 * Gets if the progressbar will displayed inverted
623 * @param obj The progressbar object
624 * @return The inverted flag
625 * (1 == inverted, 0 == normal)
627 * @ingroup Progressbar
630 elm_progressbar_inverted_get(const Evas_Object *obj)
632 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
633 Widget_Data *wd = elm_widget_data_get(obj);
634 if (!wd) return EINA_FALSE;