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);
71 edje_object_part_unswallow(NULL, wd->spacer);
73 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "horizontal", elm_widget_style_get(obj));
75 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "vertical", elm_widget_style_get(obj));
77 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,on", "elm");
79 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,off", "elm");
81 edje_object_signal_emit(wd->progressbar, "elm,state,icon,visible", "elm");
83 edje_object_signal_emit(wd->progressbar, "elm,state,icon,hidden", "elm");
85 edje_object_signal_emit(wd->progressbar, "elm,state,text,visible", "elm");
87 edje_object_signal_emit(wd->progressbar, "elm,state,text,hidden", "elm");
88 edje_object_part_text_set(wd->progressbar, "elm.text", wd->label);
90 edje_object_signal_emit(wd->progressbar, "elm,state,pulse", "elm");
92 edje_object_signal_emit(wd->progressbar, "elm,state,fraction", "elm");
93 if (wd->units && !wd->pulse)
94 edje_object_signal_emit(wd->progressbar, "elm,state,units,visible", "elm");
96 edje_object_signal_emit(wd->progressbar, "elm,state,units,hidden", "elm");
98 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
100 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
102 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
105 edje_object_message_signal_process(wd->progressbar);
106 edje_object_scale_set(wd->progressbar, elm_widget_scale_get(obj) * _elm_config->scale);
112 _sizing_eval(Evas_Object *obj)
114 Widget_Data *wd = elm_widget_data_get(obj);
115 Evas_Coord minw = -1, minh = -1;
117 edje_object_size_min_restricted_calc(wd->progressbar, &minw, &minh, minw, minh);
118 evas_object_size_hint_min_set(obj, minw, minh);
119 evas_object_size_hint_max_set(obj, -1, -1);
123 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
125 Widget_Data *wd = elm_widget_data_get(data);
127 if (obj != wd->icon) return;
132 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
134 Widget_Data *wd = elm_widget_data_get(obj);
135 Evas_Object *sub = event_info;
139 edje_object_signal_emit(wd->progressbar, "elm,state,icon,hidden", "elm");
140 evas_object_event_callback_del_full
141 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
143 edje_object_message_signal_process(wd->progressbar);
149 _val_set(Evas_Object *obj)
151 Widget_Data *wd = elm_widget_data_get(obj);
155 if (wd->inverted) pos = MAX_RATIO_LVL - pos;
156 edje_object_part_drag_value_set(wd->progressbar, "elm.cur.progressbar", pos, pos);
160 _units_set(Evas_Object *obj)
162 Widget_Data *wd = elm_widget_data_get(obj);
167 snprintf(buf, sizeof(buf), wd->units, 100 * wd->val);
168 edje_object_part_text_set(wd->progressbar, "elm.text.status", buf);
171 edje_object_part_text_set(wd->progressbar, "elm.text.status", NULL);
175 * Add a new progressbar to the parent
177 * @param parent The parent object
178 * @return The new object or NULL if it cannot be created
180 * @ingroup Progressbar
183 elm_progressbar_add(Evas_Object *parent)
189 wd = ELM_NEW(Widget_Data);
190 e = evas_object_evas_get(parent);
191 obj = elm_widget_add(e);
192 ELM_SET_WIDTYPE(widtype, "progressbar");
193 elm_widget_type_set(obj, "progressbar");
194 elm_widget_sub_object_add(parent, obj);
195 elm_widget_data_set(obj, wd);
196 elm_widget_del_hook_set(obj, _del_hook);
197 elm_widget_theme_hook_set(obj, _theme_hook);
199 wd->horizontal = EINA_TRUE;
200 wd->inverted = EINA_FALSE;
201 wd->pulse = EINA_FALSE;
202 wd->pulse_state = EINA_FALSE;
203 wd->units = eina_stringshare_add("%.0f %%");
204 wd->val = MIN_RATIO_LVL;
206 wd->progressbar = edje_object_add(e);
207 _elm_theme_object_set(obj, wd->progressbar, "progressbar", "horizontal", "default");
208 elm_widget_resize_object_set(obj, wd->progressbar);
210 wd->spacer = evas_object_rectangle_add(e);
211 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
212 evas_object_pass_events_set(wd->spacer, 1);
213 elm_widget_sub_object_add(obj, wd->spacer);
214 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
216 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
224 * Normally the progressbar will display and interpret values from low to high.
225 * This display a progressbar for jobs with unknow state of progression,
226 * (the cursor pulse right to left and left to right, and loop) if pulse is set to 1.
228 * @param obj The progressbar object
229 * @param pulse The pulse flag. 1 == pulse, 0 == normal
231 * @ingroup Progressbar
234 elm_progressbar_pulse_set(Evas_Object *obj, Eina_Bool pulse)
236 ELM_CHECK_WIDTYPE(obj, widtype);
237 Widget_Data *wd = elm_widget_data_get(obj);
240 if (wd->pulse == pulse) return;
246 * Normally the progressbar will display and interpret values from low to high.
247 * This display a progressbar for jobs with unknow state of progression,
248 * (the cursor pulse right to left and left to right, and loop) if pulse is set to 1.
250 * @param obj The progressbar object
251 * @return The pulse flag
252 * (1 == pulse, 0 == normal)
254 * @ingroup Progressbar
257 elm_progressbar_pulse_get(const Evas_Object *obj)
259 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
260 Widget_Data *wd = elm_widget_data_get(obj);
261 if (!wd) return EINA_FALSE;
266 * Stat/Stop de pulse action
268 * @param obj The progressbar object
269 * @param state The pulse flag. 1 == start pulse, 0 == stop pulse
271 * @ingroup Progressbar
274 elm_progressbar_pulse(Evas_Object *obj, Eina_Bool state)
276 ELM_CHECK_WIDTYPE(obj, widtype);
277 Widget_Data *wd = elm_widget_data_get(obj);
280 if (!wd->pulse && wd->pulse_state == state) return;
281 wd->pulse_state = state;
283 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,start", "elm");
285 edje_object_signal_emit(wd->progressbar, "elm,state,pulse,stop", "elm");
289 * Set the value the progressbar indicates
291 * @param obj The progressbar object
292 * @param val The fraction value (must be beween 0.0 and 1.0)
294 * @ingroup Progressbar
297 elm_progressbar_value_set(Evas_Object *obj, double val)
299 ELM_CHECK_WIDTYPE(obj, widtype);
300 Widget_Data *wd = elm_widget_data_get(obj);
302 if (wd->val == val) return;
304 if (wd->val < MIN_RATIO_LVL) wd->val = MIN_RATIO_LVL;
305 if (wd->val > MAX_RATIO_LVL) wd->val = MAX_RATIO_LVL;
312 * Get the value the progressbar has
314 * @param obj The progressbar object
315 * @return The value of the progressbar
317 * @ingroup Progressbar
320 elm_progressbar_value_get(const Evas_Object *obj)
322 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
323 Widget_Data *wd = elm_widget_data_get(obj);
329 * Set the label of the progressbar
331 * @param obj The progressbar object
332 * @param label The text label string in UTF-8
334 * @ingroup Progressbar
337 elm_progressbar_label_set(Evas_Object *obj, const char *label)
339 ELM_CHECK_WIDTYPE(obj, widtype);
340 Widget_Data *wd = elm_widget_data_get(obj);
342 eina_stringshare_replace(&wd->label, label);
345 edje_object_signal_emit(wd->progressbar, "elm,state,text,visible", "elm");
346 edje_object_message_signal_process(wd->progressbar);
350 edje_object_signal_emit(wd->progressbar, "elm,state,text,hidden", "elm");
351 edje_object_message_signal_process(wd->progressbar);
353 edje_object_part_text_set(wd->progressbar, "elm.text", label);
358 * Get the label of the progressbar
360 * @param obj The progressbar object
361 * @return The text label string in UTF-8
363 * @ingroup Progressbar
366 elm_progressbar_label_get(const Evas_Object *obj)
368 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
369 Widget_Data *wd = elm_widget_data_get(obj);
370 if (!wd) return NULL;
375 * Set the icon object of the progressbar object
377 * Once the icon object is set, a previously set one will be deleted.
379 * @param obj The progressbar object
380 * @param icon The icon object
382 * @ingroup Progressbar
385 elm_progressbar_icon_set(Evas_Object *obj, Evas_Object *icon)
387 ELM_CHECK_WIDTYPE(obj, widtype);
388 Widget_Data *wd = elm_widget_data_get(obj);
390 if (wd->icon == icon) return;
391 if (wd->icon) evas_object_del(wd->icon);
395 elm_widget_sub_object_add(obj, icon);
396 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
397 _changed_size_hints, obj);
398 edje_object_part_swallow(wd->progressbar, "elm.swallow.content", icon);
399 edje_object_signal_emit(wd->progressbar, "elm,state,icon,visible", "elm");
400 edje_object_message_signal_process(wd->progressbar);
406 * Get the icon object of the progressbar object
408 * @param obj The progressbar object
409 * @return The icon object
411 * @ingroup Progressbar
414 elm_progressbar_icon_get(const Evas_Object *obj)
416 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
417 Widget_Data *wd = elm_widget_data_get(obj);
418 if (!wd) return NULL;
423 * Set the length of the progression region of the progressbar
425 * This sets the minimum width or height (depending on orientation) of the
426 * area of the progressbar that allows the progressbar to be dragged around. This in
427 * turn affects the objects minimum size (along with icon label and unit
430 * @param obj The progressbar object
431 * @param size The length of the progressbar area
433 * @ingroup Progressbar
436 elm_progressbar_span_size_set(Evas_Object *obj, Evas_Coord size)
438 ELM_CHECK_WIDTYPE(obj, widtype);
439 Widget_Data *wd = elm_widget_data_get(obj);
441 if (wd->size == size) return;
444 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
446 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
447 edje_object_part_swallow(wd->progressbar, "elm.swallow.bar", wd->spacer);
452 * Get the length of the progression region of the progressbar
454 * @param obj The progressbar object
455 * @return The length of the progressbar area
457 * @ingroup Progressbar
460 elm_progressbar_span_size_get(const Evas_Object *obj)
462 ELM_CHECK_WIDTYPE(obj, widtype) 0;
463 Widget_Data *wd = elm_widget_data_get(obj);
469 * Set the format string of the unit area
471 * If NULL, this disabls the unit area display. If not it sets the format
472 * string for the unit text. The unit text is provided a floating point
473 * value, so the unit text can display up to 1 floating point falue. Note that
474 * this is optional. Use a format string such as "%1.2f meters" for example.
476 * @param obj The progressbar object
477 * @param units The format string for the units display
479 * @ingroup Progressbar
482 elm_progressbar_unit_format_set(Evas_Object *obj, const char *units)
484 ELM_CHECK_WIDTYPE(obj, widtype);
485 Widget_Data *wd = elm_widget_data_get(obj);
487 eina_stringshare_replace(&wd->units, units);
490 edje_object_signal_emit(wd->progressbar, "elm,state,units,visible", "elm");
491 edje_object_message_signal_process(wd->progressbar);
495 edje_object_signal_emit(wd->progressbar, "elm,state,units,hidden", "elm");
496 edje_object_message_signal_process(wd->progressbar);
503 * Get the format string of the unit area
505 * @param obj The progressbar object
506 * @return The format string for the units display
508 * @ingroup Progressbar
511 elm_progressbar_unit_format_get(const Evas_Object *obj)
513 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
514 Widget_Data *wd = elm_widget_data_get(obj);
515 if (!wd) return NULL;
520 * Set orientation of the progressbar
522 * @param obj The progressbar object
523 * @param horizontal If set, the progressbar will be horizontal
525 * @ingroup Progressbar
528 elm_progressbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
530 ELM_CHECK_WIDTYPE(obj, widtype);
531 Widget_Data *wd = elm_widget_data_get(obj);
533 horizontal = !!horizontal;
534 if (wd->horizontal == horizontal) return;
535 wd->horizontal = horizontal;
540 * Gets orientation of the progressbar
542 * @param obj The progressbar object
543 * @return The orientation
544 * (0 = vertical, 1 = horizontal)
546 * @ingroup Progressbar
549 elm_progressbar_horizontal_get(const Evas_Object *obj)
551 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
552 Widget_Data *wd = elm_widget_data_get(obj);
553 if (!wd) return EINA_FALSE;
554 return wd->horizontal;
558 * Invert the progressbar display
560 * Normally the progressbar will display and interpret values from low to high
561 * and when horizontal that is left to right. When vertical that is top
562 * to bottom. This inverts this (so from right to left or bottom to top) if
563 * inverted is set to 1.
565 * @param obj The progressbar object
566 * @param inverted The inverted flag. 1 == inverted, 0 == normal
568 * @ingroup Progressbar
571 elm_progressbar_inverted_set(Evas_Object *obj, Eina_Bool inverted)
573 ELM_CHECK_WIDTYPE(obj, widtype);
574 Widget_Data *wd = elm_widget_data_get(obj);
576 inverted = !!inverted;
577 if (wd->inverted == inverted) return;
578 wd->inverted = inverted;
580 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,on", "elm");
582 edje_object_signal_emit(wd->progressbar, "elm,state,inverted,off", "elm");
583 edje_object_message_signal_process(wd->progressbar);
589 * Gets if the progressbar will displayed inverted
591 * @param obj The progressbar object
592 * @return The inverted flag
593 * (1 == inverted, 0 == normal)
595 * @ingroup Progressbar
598 elm_progressbar_inverted_get(const Evas_Object *obj)
600 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
601 Widget_Data *wd = elm_widget_data_get(obj);
602 if (!wd) return EINA_FALSE;