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 _theme_hook(Evas_Object *obj);
49 static void _sizing_eval(Evas_Object *obj);
50 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
51 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
52 static void _units_set(Evas_Object *obj);
53 static void _val_set(Evas_Object *obj);
56 _del_hook(Evas_Object *obj)
58 Widget_Data *wd = elm_widget_data_get(obj);
60 if (wd->label) eina_stringshare_del(wd->label);
61 if (wd->units) eina_stringshare_del(wd->units);
66 _theme_hook(Evas_Object *obj)
68 Widget_Data *wd = elm_widget_data_get(obj);
70 edje_object_part_unswallow(NULL, wd->spacer);
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));
76 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,on", "elm");
78 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,off", "elm");
80 edje_object_signal_emit(wd->progressbar, "elm,state,icon,visible", "elm");
82 edje_object_signal_emit(wd->progressbar, "elm,state,icon,hidden", "elm");
84 edje_object_signal_emit(wd->progressbar, "elm,state,text,visible", "elm");
86 edje_object_signal_emit(wd->progressbar, "elm,state,text,hidden", "elm");
87 edje_object_part_text_set(wd->progressbar, "elm.text", wd->label);
89 edje_object_signal_emit(wd->progressbar, "elm,state,pulse", "elm");
91 edje_object_signal_emit(wd->progressbar, "elm,state,fraction", "elm");
92 if (wd->units && !wd->pulse)
93 edje_object_signal_emit(wd->progressbar, "elm,state,units,visible", "elm");
95 edje_object_signal_emit(wd->progressbar, "elm,state,units,hidden", "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_message_signal_process(wd->progressbar);
105 edje_object_scale_set(wd->progressbar, elm_widget_scale_get(obj) * _elm_config->scale);
111 _sizing_eval(Evas_Object *obj)
113 Widget_Data *wd = elm_widget_data_get(obj);
114 Evas_Coord minw = -1, minh = -1;
116 edje_object_size_min_restricted_calc(wd->progressbar, &minw, &minh, minw, minh);
117 evas_object_size_hint_min_set(obj, minw, minh);
118 evas_object_size_hint_max_set(obj, -1, -1);
122 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
124 Widget_Data *wd = elm_widget_data_get(data);
126 if (obj != wd->icon) return;
131 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
133 Widget_Data *wd = elm_widget_data_get(obj);
134 Evas_Object *sub = event_info;
138 edje_object_signal_emit(wd->progressbar, "elm,state,icon,hidden", "elm");
139 evas_object_event_callback_del_full
140 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
142 edje_object_message_signal_process(wd->progressbar);
148 _val_set(Evas_Object *obj)
150 Widget_Data *wd = elm_widget_data_get(obj);
154 if (wd->inverted) pos = MAX_RATIO_LVL - pos;
155 edje_object_part_drag_value_set(wd->progressbar, "elm.cur.progressbar", pos, pos);
159 _units_set(Evas_Object *obj)
161 Widget_Data *wd = elm_widget_data_get(obj);
166 snprintf(buf, sizeof(buf), wd->units, 100 * wd->val);
167 edje_object_part_text_set(wd->progressbar, "elm.text.status", buf);
170 edje_object_part_text_set(wd->progressbar, "elm.text.status", NULL);
174 * Add a new progressbar to the parent
176 * @param parent The parent object
177 * @return The new object or NULL if it cannot be created
179 * @ingroup Progressbar
182 elm_progressbar_add(Evas_Object *parent)
188 wd = ELM_NEW(Widget_Data);
189 e = evas_object_evas_get(parent);
190 obj = elm_widget_add(e);
191 ELM_SET_WIDTYPE(widtype, "progressbar");
192 elm_widget_type_set(obj, "progressbar");
193 elm_widget_sub_object_add(parent, obj);
194 elm_widget_data_set(obj, wd);
195 elm_widget_del_hook_set(obj, _del_hook);
196 elm_widget_theme_hook_set(obj, _theme_hook);
198 wd->horizontal = EINA_TRUE;
199 wd->inverted = EINA_FALSE;
200 wd->pulse = EINA_FALSE;
201 wd->pulse_state = EINA_FALSE;
202 wd->units = eina_stringshare_add("%.0f %%");
203 wd->val = MIN_RATIO_LVL;
205 wd->progressbar = edje_object_add(e);
206 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "horizontal", "default");
207 elm_widget_resize_object_set(obj, wd->progressbar);
209 wd->spacer = evas_object_rectangle_add(e);
210 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
211 evas_object_pass_events_set(wd->spacer, 1);
212 elm_widget_sub_object_add(obj, wd->spacer);
213 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
215 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
223 * Normally the progressbar will display and interpret values from low to high.
224 * This display a progressbar for jobs with unknow state of progression,
225 * (the cursor pulse right to left and left to right, and loop) if pulse is set to 1.
227 * @param obj The progressbar object
228 * @param pulse The pulse flag. 1 == pulse, 0 == normal
230 * @ingroup Progressbar
233 elm_progressbar_pulse_set(Evas_Object *obj, Eina_Bool pulse)
235 ELM_CHECK_WIDTYPE(obj, widtype);
236 Widget_Data *wd = elm_widget_data_get(obj);
239 if (wd->pulse == pulse) return;
245 * Normally the progressbar will display and interpret values from low to high.
246 * This display a progressbar for jobs with unknow state of progression,
247 * (the cursor pulse right to left and left to right, and loop) if pulse is set to 1.
249 * @param obj The progressbar object
250 * @return The pulse flag
251 * (1 == pulse, 0 == normal)
253 * @ingroup Progressbar
256 elm_progressbar_pulse_get(const Evas_Object *obj)
258 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
259 Widget_Data *wd = elm_widget_data_get(obj);
260 if (!wd) return EINA_FALSE;
265 * Stat/Stop de pulse action
267 * @param obj The progressbar object
268 * @param state The pulse flag. 1 == start pulse, 0 == stop pulse
270 * @ingroup Progressbar
273 elm_progressbar_pulse(Evas_Object *obj, Eina_Bool state)
275 ELM_CHECK_WIDTYPE(obj, widtype);
276 Widget_Data *wd = elm_widget_data_get(obj);
279 if (!wd->pulse && wd->pulse_state == state) return;
280 wd->pulse_state = state;
282 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,start", "elm");
284 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,stop", "elm");
288 * Set the value the progressbar indicates
290 * @param obj The progressbar object
291 * @param val The fraction value (must be beween 0.0 and 1.0)
293 * @ingroup Progressbar
296 elm_progressbar_value_set(Evas_Object *obj, double val)
298 ELM_CHECK_WIDTYPE(obj, widtype);
299 Widget_Data *wd = elm_widget_data_get(obj);
301 if (wd->val == val) return;
303 if (wd->val < MIN_RATIO_LVL) wd->val = MIN_RATIO_LVL;
304 if (wd->val > MAX_RATIO_LVL) wd->val = MAX_RATIO_LVL;
311 * Get the value the progressbar has
313 * @param obj The progressbar object
314 * @return The value of the progressbar
316 * @ingroup Progressbar
319 elm_progressbar_value_get(const Evas_Object *obj)
321 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
322 Widget_Data *wd = elm_widget_data_get(obj);
328 * Set the label of the progressbar
330 * @param obj The progressbar object
331 * @param label The text label string in UTF-8
333 * @ingroup Progressbar
336 elm_progressbar_label_set(Evas_Object *obj, const char *label)
338 ELM_CHECK_WIDTYPE(obj, widtype);
339 Widget_Data *wd = elm_widget_data_get(obj);
341 eina_stringshare_replace(&wd->label, label);
344 edje_object_signal_emit(wd->progressbar, "elm,state,text,visible", "elm");
345 edje_object_message_signal_process(wd->progressbar);
349 edje_object_signal_emit(wd->progressbar, "elm,state,text,hidden", "elm");
350 edje_object_message_signal_process(wd->progressbar);
352 edje_object_part_text_set(wd->progressbar, "elm.text", label);
357 * Get the label of the progressbar
359 * @param obj The progressbar object
360 * @return The text label string in UTF-8
362 * @ingroup Progressbar
365 elm_progressbar_label_get(const Evas_Object *obj)
367 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
368 Widget_Data *wd = elm_widget_data_get(obj);
369 if (!wd) return NULL;
374 * Set the icon object of the progressbar object
376 * Once the icon object is set, a previously set one will be deleted.
378 * @param obj The progressbar object
379 * @param icon The icon object
381 * @ingroup Progressbar
384 elm_progressbar_icon_set(Evas_Object *obj, Evas_Object *icon)
386 ELM_CHECK_WIDTYPE(obj, widtype);
387 Widget_Data *wd = elm_widget_data_get(obj);
389 if (wd->icon == icon) return;
390 if (wd->icon) evas_object_del(wd->icon);
394 elm_widget_sub_object_add(obj, icon);
395 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
396 _changed_size_hints, obj);
397 edje_object_part_swallow(wd->progressbar, "elm.swallow.content", icon);
398 edje_object_signal_emit(wd->progressbar, "elm,state,icon,visible", "elm");
399 edje_object_message_signal_process(wd->progressbar);
405 * Get the icon object of the progressbar object
407 * @param obj The progressbar object
408 * @return The icon object
410 * @ingroup Progressbar
413 elm_progressbar_icon_get(const Evas_Object *obj)
415 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
416 Widget_Data *wd = elm_widget_data_get(obj);
417 if (!wd) return NULL;
422 * Set the length of the progression region of the progressbar
424 * This sets the minimum width or height (depending on orientation) of the
425 * area of the progressbar that allows the progressbar to be dragged around. This in
426 * turn affects the objects minimum size (along with icon label and unit
429 * @param obj The progressbar object
430 * @param size The length of the progressbar area
432 * @ingroup Progressbar
435 elm_progressbar_span_size_set(Evas_Object *obj, Evas_Coord size)
437 ELM_CHECK_WIDTYPE(obj, widtype);
438 Widget_Data *wd = elm_widget_data_get(obj);
440 if (wd->size == size) return;
443 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
445 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
446 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
451 * Get the length of the progression region of the progressbar
453 * @param obj The progressbar object
454 * @return The length of the progressbar area
456 * @ingroup Progressbar
459 elm_progressbar_span_size_get(const Evas_Object *obj)
461 ELM_CHECK_WIDTYPE(obj, widtype) 0;
462 Widget_Data *wd = elm_widget_data_get(obj);
468 * Set the format string of the unit area
470 * If NULL, this disabls the unit area display. If not it sets the format
471 * string for the unit text. The unit text is provided a floating point
472 * value, so the unit text can display up to 1 floating point falue. Note that
473 * this is optional. Use a format string such as "%1.2f meters" for example.
475 * @param obj The progressbar object
476 * @param units The format string for the units display
478 * @ingroup Progressbar
481 elm_progressbar_unit_format_set(Evas_Object *obj, const char *units)
483 ELM_CHECK_WIDTYPE(obj, widtype);
484 Widget_Data *wd = elm_widget_data_get(obj);
486 eina_stringshare_replace(&wd->units, units);
489 edje_object_signal_emit(wd->progressbar, "elm,state,units,visible", "elm");
490 edje_object_message_signal_process(wd->progressbar);
494 edje_object_signal_emit(wd->progressbar, "elm,state,units,hidden", "elm");
495 edje_object_message_signal_process(wd->progressbar);
502 * Get the format string of the unit area
504 * @param obj The progressbar object
505 * @return The format string for the units display
507 * @ingroup Progressbar
510 elm_progressbar_unit_format_get(const Evas_Object *obj)
512 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
513 Widget_Data *wd = elm_widget_data_get(obj);
514 if (!wd) return NULL;
519 * Set orientation of the progressbar
521 * @param obj The progressbar object
522 * @param horizontal If set, the progressbar will be horizontal
524 * @ingroup Progressbar
527 elm_progressbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
529 ELM_CHECK_WIDTYPE(obj, widtype);
530 Widget_Data *wd = elm_widget_data_get(obj);
532 horizontal = !!horizontal;
533 if (wd->horizontal == horizontal) return;
534 wd->horizontal = horizontal;
539 * Gets orientation of the progressbar
541 * @param obj The progressbar object
542 * @return The orientation
543 * (0 = vertical, 1 = horizontal)
545 * @ingroup Progressbar
548 elm_progressbar_horizontal_get(const Evas_Object *obj)
550 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
551 Widget_Data *wd = elm_widget_data_get(obj);
552 if (!wd) return EINA_FALSE;
553 return wd->horizontal;
557 * Invert the progressbar display
559 * Normally the progressbar will display and interpret values from low to high
560 * and when horizontal that is left to right. When vertical that is top
561 * to bottom. This inverts this (so from right to left or bottom to top) if
562 * inverted is set to 1.
564 * @param obj The progressbar object
565 * @param inverted The inverted flag. 1 == inverted, 0 == normal
567 * @ingroup Progressbar
570 elm_progressbar_inverted_set(Evas_Object *obj, Eina_Bool inverted)
572 ELM_CHECK_WIDTYPE(obj, widtype);
573 Widget_Data *wd = elm_widget_data_get(obj);
575 inverted = !!inverted;
576 if (wd->inverted == inverted) return;
577 wd->inverted = inverted;
579 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,on", "elm");
581 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,off", "elm");
582 edje_object_message_signal_process(wd->progressbar);
588 * Gets if the progressbar will displayed inverted
590 * @param obj The progressbar object
591 * @return The inverted flag
592 * (1 == inverted, 0 == normal)
594 * @ingroup Progressbar
597 elm_progressbar_inverted_get(const Evas_Object *obj)
599 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
600 Widget_Data *wd = elm_widget_data_get(obj);
601 if (!wd) return EINA_FALSE;