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 * Add a new progressbar to the parent
194 * @param parent The parent object
195 * @return The new object or NULL if it cannot be created
197 * @ingroup Progressbar
200 elm_progressbar_add(Evas_Object *parent)
206 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
208 ELM_SET_WIDTYPE(widtype, "progressbar");
209 elm_widget_type_set(obj, "progressbar");
210 elm_widget_sub_object_add(parent, obj);
211 elm_widget_data_set(obj, wd);
212 elm_widget_del_hook_set(obj, _del_hook);
213 elm_widget_theme_hook_set(obj, _theme_hook);
214 elm_widget_can_focus_set(obj, EINA_FALSE);
216 wd->horizontal = EINA_TRUE;
217 wd->inverted = EINA_FALSE;
218 wd->pulse = EINA_FALSE;
219 wd->pulse_state = EINA_FALSE;
220 wd->units = eina_stringshare_add("%.0f %%");
221 wd->val = MIN_RATIO_LVL;
223 wd->progressbar = edje_object_add(e);
224 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "horizontal", "default");
225 elm_widget_resize_object_set(obj, wd->progressbar);
227 wd->spacer = evas_object_rectangle_add(e);
228 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
229 evas_object_pass_events_set(wd->spacer, EINA_TRUE);
230 elm_widget_sub_object_add(obj, wd->spacer);
231 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
233 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
236 _mirrored_set(obj, elm_widget_mirrored_get(obj));
242 * Normally the progressbar will display and interpret values from low to high.
243 * This display a progressbar for jobs with unknow state of progression,
244 * (the cursor pulse right to left and left to right, and loop) if pulse is set to 1.
246 * @param obj The progressbar object
247 * @param pulse The pulse flag. 1 == pulse, 0 == normal
249 * @ingroup Progressbar
252 elm_progressbar_pulse_set(Evas_Object *obj, Eina_Bool pulse)
254 ELM_CHECK_WIDTYPE(obj, widtype);
255 Widget_Data *wd = elm_widget_data_get(obj);
258 if (wd->pulse == pulse) return;
264 * Normally the progressbar will display and interpret values from low to high.
265 * This display a progressbar for jobs with unknow state of progression,
266 * (the cursor pulse right to left and left to right, and loop) if pulse is set to 1.
268 * @param obj The progressbar object
269 * @return The pulse flag
270 * (1 == pulse, 0 == normal)
272 * @ingroup Progressbar
275 elm_progressbar_pulse_get(const Evas_Object *obj)
277 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
278 Widget_Data *wd = elm_widget_data_get(obj);
279 if (!wd) return EINA_FALSE;
284 * Stat/Stop de pulse action
286 * @param obj The progressbar object
287 * @param state The pulse flag. 1 == start pulse, 0 == stop pulse
289 * @ingroup Progressbar
292 elm_progressbar_pulse(Evas_Object *obj, Eina_Bool state)
294 ELM_CHECK_WIDTYPE(obj, widtype);
295 Widget_Data *wd = elm_widget_data_get(obj);
298 if ((!wd->pulse) && (wd->pulse_state == state)) return;
299 wd->pulse_state = state;
301 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,start", "elm");
303 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,stop", "elm");
307 * Set the value the progressbar indicates
309 * @param obj The progressbar object
310 * @param val The fraction value (must be between 0.0 and 1.0)
312 * @ingroup Progressbar
315 elm_progressbar_value_set(Evas_Object *obj, double val)
317 ELM_CHECK_WIDTYPE(obj, widtype);
318 Widget_Data *wd = elm_widget_data_get(obj);
320 if (wd->val == val) return;
322 if (wd->val < MIN_RATIO_LVL) wd->val = MIN_RATIO_LVL;
323 if (wd->val > MAX_RATIO_LVL) wd->val = MAX_RATIO_LVL;
330 * Get the value the progressbar has
332 * @param obj The progressbar object
333 * @return The value of the progressbar
335 * @ingroup Progressbar
338 elm_progressbar_value_get(const Evas_Object *obj)
340 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
341 Widget_Data *wd = elm_widget_data_get(obj);
347 * Set the label of the progressbar
349 * @param obj The progressbar object
350 * @param label The text label string in UTF-8
352 * @ingroup Progressbar
355 elm_progressbar_label_set(Evas_Object *obj, const char *label)
357 ELM_CHECK_WIDTYPE(obj, widtype);
358 Widget_Data *wd = elm_widget_data_get(obj);
360 eina_stringshare_replace(&wd->label, label);
363 edje_object_signal_emit(wd->progressbar, "elm,state,text,visible", "elm");
364 edje_object_message_signal_process(wd->progressbar);
368 edje_object_signal_emit(wd->progressbar, "elm,state,text,hidden", "elm");
369 edje_object_message_signal_process(wd->progressbar);
371 edje_object_part_text_set(wd->progressbar, "elm.text", label);
376 * Get the label of the progressbar
378 * @param obj The progressbar object
379 * @return The text label string in UTF-8
381 * @ingroup Progressbar
384 elm_progressbar_label_get(const Evas_Object *obj)
386 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
387 Widget_Data *wd = elm_widget_data_get(obj);
388 if (!wd) return NULL;
393 * Set the icon object of the progressbar object
395 * Once the icon object is set, a previously set one will be deleted.
396 * If you want to keep that old content object, use the
397 * elm_progressbar_icon_unset() function.
399 * @param obj The progressbar object
400 * @param icon The icon object
402 * @ingroup Progressbar
405 elm_progressbar_icon_set(Evas_Object *obj, Evas_Object *icon)
407 ELM_CHECK_WIDTYPE(obj, widtype);
408 Widget_Data *wd = elm_widget_data_get(obj);
410 if (wd->icon == icon) return;
411 if (wd->icon) evas_object_del(wd->icon);
415 elm_widget_sub_object_add(obj, icon);
416 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
417 _changed_size_hints, obj);
418 edje_object_part_swallow(wd->progressbar, "elm.swallow.content", icon);
419 edje_object_signal_emit(wd->progressbar, "elm,state,icon,visible", "elm");
420 edje_object_message_signal_process(wd->progressbar);
426 * Get the icon object of the progressbar object
428 * @param obj The progressbar object
429 * @return The icon object
431 * @ingroup Progressbar
434 elm_progressbar_icon_get(const Evas_Object *obj)
436 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
437 Widget_Data *wd = elm_widget_data_get(obj);
438 if (!wd) return NULL;
443 * Unset the icon used for the progressbar object
445 * Unparent and return the icon object which was set for this widget.
447 * @param obj The progressbar object
448 * @return The icon object that was being used
450 * @ingroup Progressbar
453 elm_progressbar_icon_unset(Evas_Object *obj)
455 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
456 Widget_Data *wd = elm_widget_data_get(obj);
457 if (!wd) return NULL;
458 if (!wd->icon) return NULL;
459 Evas_Object *icon = wd->icon;
460 elm_widget_sub_object_del(obj, wd->icon);
461 edje_object_part_unswallow(wd->progressbar, wd->icon);
467 * Set the length of the progression region of the progressbar
469 * This sets the minimum width or height (depending on orientation) of the
470 * area of the progressbar that allows the progressbar to be dragged around. This in
471 * turn affects the objects minimum size (along with icon label and unit
474 * @param obj The progressbar object
475 * @param size The length of the progressbar area
477 * @ingroup Progressbar
480 elm_progressbar_span_size_set(Evas_Object *obj, Evas_Coord size)
482 ELM_CHECK_WIDTYPE(obj, widtype);
483 Widget_Data *wd = elm_widget_data_get(obj);
485 if (wd->size == size) return;
488 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
490 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
491 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
496 * Get the length of the progression region of the progressbar
498 * @param obj The progressbar object
499 * @return The length of the progressbar area
501 * @ingroup Progressbar
504 elm_progressbar_span_size_get(const Evas_Object *obj)
506 ELM_CHECK_WIDTYPE(obj, widtype) 0;
507 Widget_Data *wd = elm_widget_data_get(obj);
513 * Set the format string of the unit area
515 * If NULL, this disabls the unit area display. If not it sets the format
516 * string for the unit text. The unit text is provided a floating point
517 * value, so the unit text can display up to 1 floating point falue. Note that
518 * this is optional. Use a format string such as "%1.2f meters" for example.
520 * @param obj The progressbar object
521 * @param units The format string for the units display
523 * @ingroup Progressbar
526 elm_progressbar_unit_format_set(Evas_Object *obj, const char *units)
528 ELM_CHECK_WIDTYPE(obj, widtype);
529 Widget_Data *wd = elm_widget_data_get(obj);
531 eina_stringshare_replace(&wd->units, units);
534 edje_object_signal_emit(wd->progressbar, "elm,state,units,visible", "elm");
535 edje_object_message_signal_process(wd->progressbar);
539 edje_object_signal_emit(wd->progressbar, "elm,state,units,hidden", "elm");
540 edje_object_message_signal_process(wd->progressbar);
547 * Get the format string of the unit area
549 * @param obj The progressbar object
550 * @return The format string for the units display
552 * @ingroup Progressbar
555 elm_progressbar_unit_format_get(const Evas_Object *obj)
557 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
558 Widget_Data *wd = elm_widget_data_get(obj);
559 if (!wd) return NULL;
564 * Set orientation of the progressbar
566 * @param obj The progressbar object
567 * @param horizontal If set, the progressbar will be horizontal
569 * @ingroup Progressbar
572 elm_progressbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
574 ELM_CHECK_WIDTYPE(obj, widtype);
575 Widget_Data *wd = elm_widget_data_get(obj);
577 horizontal = !!horizontal;
578 if (wd->horizontal == horizontal) return;
579 wd->horizontal = horizontal;
584 * Gets orientation of the progressbar
586 * @param obj The progressbar object
587 * @return The orientation
588 * (0 = vertical, 1 = horizontal)
590 * @ingroup Progressbar
593 elm_progressbar_horizontal_get(const Evas_Object *obj)
595 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
596 Widget_Data *wd = elm_widget_data_get(obj);
597 if (!wd) return EINA_FALSE;
598 return wd->horizontal;
602 * Invert the progressbar display
604 * Normally the progressbar will display and interpret values from low to high
605 * and when horizontal that is left to right. When vertical that is top
606 * to bottom. This inverts this (so from right to left or bottom to top) if
607 * inverted is set to 1.
609 * @param obj The progressbar object
610 * @param inverted The inverted flag. 1 == inverted, 0 == normal
612 * @ingroup Progressbar
615 elm_progressbar_inverted_set(Evas_Object *obj, Eina_Bool inverted)
617 ELM_CHECK_WIDTYPE(obj, widtype);
618 Widget_Data *wd = elm_widget_data_get(obj);
620 inverted = !!inverted;
621 if (wd->inverted == inverted) return;
622 wd->inverted = inverted;
624 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,on", "elm");
626 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,off", "elm");
627 edje_object_message_signal_process(wd->progressbar);
633 * Gets if the progressbar will displayed inverted
635 * @param obj The progressbar object
636 * @return The inverted flag
637 * (1 == inverted, 0 == normal)
639 * @ingroup Progressbar
642 elm_progressbar_inverted_get(const Evas_Object *obj)
644 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
645 Widget_Data *wd = elm_widget_data_get(obj);
646 if (!wd) return EINA_FALSE;