1 #include <Elementary.h>
3 #include "elm_widget_progressbar.h"
5 EAPI const char ELM_PROGRESSBAR_SMART_NAME[] = "elm_progressbar";
7 static const char SIG_CHANGED[] = "changed";
9 #define MIN_RATIO_LVL 0.0
10 #define MAX_RATIO_LVL 1.0
12 /* smart callbacks coming from elm progressbar objects (besides the
13 * ones coming from elm layout): */
14 static const Evas_Smart_Cb_Description _smart_callbacks[] = {
19 EVAS_SMART_SUBCLASS_NEW
20 (ELM_PROGRESSBAR_SMART_NAME, _elm_progressbar, Elm_Progressbar_Smart_Class,
21 Elm_Layout_Smart_Class, elm_layout_smart_class_get, _smart_callbacks);
23 static const Elm_Layout_Part_Alias_Description _content_aliases[] =
25 {"icon", "elm.swallow.content"},
29 static const Elm_Layout_Part_Alias_Description _text_aliases[] =
31 {"default", "elm.text"},
36 _units_set(Evas_Object *obj)
38 ELM_PROGRESSBAR_DATA_GET(obj, sd);
40 if (sd->unit_format_func)
44 buf = sd->unit_format_func(sd->val);
45 elm_layout_text_set(obj, "elm.text.status", buf);
46 if (sd->unit_format_free) sd->unit_format_free(buf);
52 snprintf(buf, sizeof(buf), sd->units, 100 * sd->val);
53 elm_layout_text_set(obj, "elm.text.status", buf);
55 else elm_layout_text_set(obj, "elm.text.status", NULL);
59 _val_set(Evas_Object *obj)
64 ELM_PROGRESSBAR_DATA_GET(obj, sd);
67 rtl = elm_widget_mirrored_get(obj);
69 if ((!rtl && sd->inverted) ||
70 (rtl && ((!sd->horizontal && sd->inverted) ||
71 (sd->horizontal && !sd->inverted))))
72 pos = MAX_RATIO_LVL - pos;
74 edje_object_part_drag_value_set
75 (ELM_WIDGET_DATA(sd)->resize_obj, "elm.cur.progressbar", pos, pos);
77 elm_layout_signal_emit(obj, "elm,state,change", "elm");
81 _elm_progressbar_smart_sizing_eval(Evas_Object *obj)
83 Evas_Coord minw = -1, minh = -1;
85 ELM_PROGRESSBAR_DATA_GET(obj, sd);
87 edje_object_size_min_restricted_calc
88 (ELM_WIDGET_DATA(sd)->resize_obj, &minw, &minh, minw, minh);
89 evas_object_size_hint_min_set(obj, minw, minh);
90 evas_object_size_hint_max_set(obj, -1, -1);
93 /* FIXME: replicated from elm_layout just because progressbar's icon
94 * spot is elm.swallow.content, not elm.swallow.icon. Fix that
95 * whenever we can changed the theme API */
97 _icon_signal_emit(Evas_Object *obj)
101 snprintf(buf, sizeof(buf), "elm,state,icon,%s",
102 elm_layout_content_get(obj, "icon") ? "visible" : "hidden");
104 elm_layout_signal_emit(obj, buf, "elm");
107 /* FIXME: replicated from elm_layout just because progressbar's icon
108 * spot is elm.swallow.content, not elm.swallow.icon. Fix that
109 * whenever we can changed the theme API */
111 _elm_progressbar_smart_sub_object_del(Evas_Object *obj,
114 if (!ELM_WIDGET_CLASS(_elm_progressbar_parent_sc)->sub_object_del
118 _icon_signal_emit(obj);
123 /* FIXME: replicated from elm_layout just because progressbar's icon
124 * spot is elm.swallow.content, not elm.swallow.icon. Fix that
125 * whenever we can changed the theme API */
127 _elm_progressbar_smart_content_set(Evas_Object *obj,
129 Evas_Object *content)
131 if (!ELM_CONTAINER_CLASS(_elm_progressbar_parent_sc)->content_set
132 (obj, part, content))
135 _icon_signal_emit(obj);
141 _elm_progressbar_smart_theme(Evas_Object *obj)
143 ELM_PROGRESSBAR_DATA_GET(obj, sd);
146 eina_stringshare_replace(&ELM_LAYOUT_DATA(sd)->group, "horizontal");
147 else eina_stringshare_replace(&ELM_LAYOUT_DATA(sd)->group, "vertical");
149 if (!ELM_WIDGET_CLASS(_elm_progressbar_parent_sc)->theme(obj))
153 elm_layout_signal_emit(obj, "elm,state,pulse", "elm");
155 elm_layout_signal_emit(obj, "elm,state,fraction", "elm");
158 elm_layout_signal_emit(obj, "elm,state,pulse,start", "elm");
160 if ((sd->units) && (!sd->pulse))
161 elm_layout_signal_emit(obj, "elm,state,units,visible", "elm");
164 evas_object_size_hint_min_set
165 (sd->spacer, (double)sd->size * elm_widget_scale_get(obj) *
166 elm_config_scale_get(), 1);
168 evas_object_size_hint_min_set
169 (sd->spacer, 1, (double)sd->size * elm_widget_scale_get(obj) *
170 elm_config_scale_get());
173 elm_layout_signal_emit(obj, "elm,state,inverted,on", "elm");
178 /* FIXME: replicated from elm_layout just because progressbar's
179 * icon spot is elm.swallow.content, not elm.swallow.icon. Fix that
180 * whenever we can changed the theme API */
181 _icon_signal_emit(obj);
183 edje_object_message_signal_process(ELM_WIDGET_DATA(sd)->resize_obj);
185 elm_layout_sizing_eval(obj);
191 _access_info_cb(void *data __UNUSED__, Evas_Object *obj)
193 const char *txt = elm_widget_access_info_get(obj);
195 if (!txt) txt = elm_layout_text_get(obj, NULL);
196 if (txt) return strdup(txt);
202 _access_state_cb(void *data __UNUSED__, Evas_Object *obj)
206 buf = eina_strbuf_new();
208 const char *txt = elm_layout_text_get(obj, "elm.text.status");
209 if (txt) eina_strbuf_append(buf, txt);
211 if (elm_widget_disabled_get(obj))
212 eina_strbuf_append(buf, " state: disabled");
214 if (eina_strbuf_length_get(buf))
216 ret = eina_strbuf_string_steal(buf);
217 eina_strbuf_free(buf);
221 eina_strbuf_free(buf);
226 _elm_progressbar_smart_add(Evas_Object *obj)
228 EVAS_SMART_DATA_ALLOC(obj, Elm_Progressbar_Smart_Data);
230 ELM_WIDGET_CLASS(_elm_progressbar_parent_sc)->base.add(obj);
232 priv->horizontal = EINA_TRUE;
233 priv->inverted = EINA_FALSE;
234 priv->pulse = EINA_FALSE;
235 priv->pulse_state = EINA_FALSE;
236 priv->units = eina_stringshare_add("%.0f %%");
237 priv->val = MIN_RATIO_LVL;
240 (obj, "progressbar", "horizontal", elm_widget_style_get(obj));
242 priv->spacer = evas_object_rectangle_add(evas_object_evas_get(obj));
243 evas_object_color_set(priv->spacer, 0, 0, 0, 0);
244 evas_object_pass_events_set(priv->spacer, EINA_TRUE);
246 elm_layout_content_set(obj, "elm.swallow.bar", priv->spacer);
251 elm_layout_sizing_eval(obj);
253 if (_elm_config->access_mode == ELM_ACCESS_MODE_ON)
254 elm_widget_can_focus_set(obj, EINA_TRUE);
256 _elm_access_object_register(obj, ELM_WIDGET_DATA(priv)->resize_obj);
258 (_elm_access_object_get(obj), ELM_ACCESS_TYPE, E_("progressbar"));
259 _elm_access_callback_set
260 (_elm_access_object_get(obj), ELM_ACCESS_INFO, _access_info_cb, NULL);
261 _elm_access_callback_set
262 (_elm_access_object_get(obj), ELM_ACCESS_STATE, _access_state_cb, priv);
266 _elm_progressbar_smart_del(Evas_Object *obj)
268 ELM_PROGRESSBAR_DATA_GET(obj, sd);
270 if (sd->units) eina_stringshare_del(sd->units);
272 ELM_WIDGET_CLASS(_elm_progressbar_parent_sc)->base.del(obj);
276 _elm_progressbar_smart_set_user(Elm_Progressbar_Smart_Class *sc)
278 ELM_WIDGET_CLASS(sc)->base.add = _elm_progressbar_smart_add;
279 ELM_WIDGET_CLASS(sc)->base.del = _elm_progressbar_smart_del;
281 ELM_WIDGET_CLASS(sc)->theme = _elm_progressbar_smart_theme;
282 ELM_WIDGET_CLASS(sc)->sub_object_del =
283 _elm_progressbar_smart_sub_object_del;
285 /* not a 'focus chain manager' */
286 ELM_WIDGET_CLASS(sc)->focus_next = NULL;
287 ELM_WIDGET_CLASS(sc)->focus_direction = NULL;
289 ELM_CONTAINER_CLASS(sc)->content_set = _elm_progressbar_smart_content_set;
291 ELM_LAYOUT_CLASS(sc)->sizing_eval = _elm_progressbar_smart_sizing_eval;
293 ELM_LAYOUT_CLASS(sc)->content_aliases = _content_aliases;
294 ELM_LAYOUT_CLASS(sc)->text_aliases = _text_aliases;
297 EAPI const Elm_Progressbar_Smart_Class *
298 elm_progressbar_smart_class_get(void)
300 static Elm_Progressbar_Smart_Class _sc =
301 ELM_PROGRESSBAR_SMART_CLASS_INIT_NAME_VERSION(ELM_PROGRESSBAR_SMART_NAME);
302 static const Elm_Progressbar_Smart_Class *class = NULL;
303 Evas_Smart_Class *esc = (Evas_Smart_Class *)&_sc;
308 _elm_progressbar_smart_set(&_sc);
309 esc->callbacks = _smart_callbacks;
316 elm_progressbar_add(Evas_Object *parent)
320 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
322 obj = elm_widget_add(_elm_progressbar_smart_class_new(), parent);
323 if (!obj) return NULL;
325 if (!elm_widget_sub_object_add(parent, obj))
326 ERR("could not add %p as sub object of %p", obj, parent);
332 elm_progressbar_pulse_set(Evas_Object *obj,
335 ELM_PROGRESSBAR_CHECK(obj);
336 ELM_PROGRESSBAR_DATA_GET(obj, sd);
339 if (sd->pulse == pulse) return;
343 _elm_progressbar_smart_theme(obj);
347 elm_progressbar_pulse_get(const Evas_Object *obj)
349 ELM_PROGRESSBAR_CHECK(obj) EINA_FALSE;
350 ELM_PROGRESSBAR_DATA_GET(obj, sd);
356 elm_progressbar_pulse(Evas_Object *obj,
359 ELM_PROGRESSBAR_CHECK(obj);
360 ELM_PROGRESSBAR_DATA_GET(obj, sd);
363 if ((!sd->pulse) && (sd->pulse_state == state)) return;
365 sd->pulse_state = state;
368 elm_layout_signal_emit(obj, "elm,state,pulse,start", "elm");
370 elm_layout_signal_emit(obj, "elm,state,pulse,stop", "elm");
374 elm_progressbar_value_set(Evas_Object *obj,
377 ELM_PROGRESSBAR_CHECK(obj);
378 ELM_PROGRESSBAR_DATA_GET(obj, sd);
380 if (sd->val == val) return;
383 if (sd->val < MIN_RATIO_LVL) sd->val = MIN_RATIO_LVL;
384 if (sd->val > MAX_RATIO_LVL) sd->val = MAX_RATIO_LVL;
388 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
392 elm_progressbar_value_get(const Evas_Object *obj)
394 ELM_PROGRESSBAR_CHECK(obj) 0.0;
395 ELM_PROGRESSBAR_DATA_GET(obj, sd);
401 elm_progressbar_span_size_set(Evas_Object *obj,
404 ELM_PROGRESSBAR_CHECK(obj);
405 ELM_PROGRESSBAR_DATA_GET(obj, sd);
407 if (sd->size == size) return;
412 evas_object_size_hint_min_set
413 (sd->spacer, (double)sd->size * elm_widget_scale_get(obj) *
414 elm_config_scale_get(), 1);
416 evas_object_size_hint_min_set
417 (sd->spacer, 1, (double)sd->size * elm_widget_scale_get(obj) *
418 elm_config_scale_get());
420 elm_layout_sizing_eval(obj);
424 elm_progressbar_span_size_get(const Evas_Object *obj)
426 ELM_PROGRESSBAR_CHECK(obj) 0;
427 ELM_PROGRESSBAR_DATA_GET(obj, sd);
433 elm_progressbar_unit_format_set(Evas_Object *obj,
436 ELM_PROGRESSBAR_CHECK(obj);
437 ELM_PROGRESSBAR_DATA_GET(obj, sd);
439 eina_stringshare_replace(&sd->units, units);
442 elm_layout_signal_emit(obj, "elm,state,units,visible", "elm");
443 edje_object_message_signal_process(ELM_WIDGET_DATA(sd)->resize_obj);
447 elm_layout_signal_emit(obj, "elm,state,units,hidden", "elm");
448 edje_object_message_signal_process(ELM_WIDGET_DATA(sd)->resize_obj);
452 elm_layout_sizing_eval(obj);
456 elm_progressbar_unit_format_get(const Evas_Object *obj)
458 ELM_PROGRESSBAR_CHECK(obj) NULL;
459 ELM_PROGRESSBAR_DATA_GET(obj, sd);
465 elm_progressbar_unit_format_function_set(Evas_Object *obj, char *(func)(double), void (*free_func) (char *))
467 ELM_PROGRESSBAR_CHECK(obj);
468 ELM_PROGRESSBAR_DATA_GET(obj, sd);
470 sd->unit_format_func = func;
471 sd->unit_format_free = free_func;
474 elm_layout_sizing_eval(obj);
478 elm_progressbar_horizontal_set(Evas_Object *obj,
479 Eina_Bool horizontal)
481 ELM_PROGRESSBAR_CHECK(obj);
482 ELM_PROGRESSBAR_DATA_GET(obj, sd);
484 horizontal = !!horizontal;
485 if (sd->horizontal == horizontal) return;
487 sd->horizontal = horizontal;
488 _elm_progressbar_smart_theme(obj);
492 elm_progressbar_horizontal_get(const Evas_Object *obj)
494 ELM_PROGRESSBAR_CHECK(obj) EINA_FALSE;
495 ELM_PROGRESSBAR_DATA_GET(obj, sd);
497 return sd->horizontal;
501 elm_progressbar_inverted_set(Evas_Object *obj,
504 ELM_PROGRESSBAR_CHECK(obj);
505 ELM_PROGRESSBAR_DATA_GET(obj, sd);
507 inverted = !!inverted;
508 if (sd->inverted == inverted) return;
510 sd->inverted = inverted;
512 elm_layout_signal_emit(obj, "elm,state,inverted,on", "elm");
514 elm_layout_signal_emit(obj, "elm,state,inverted,off", "elm");
516 edje_object_message_signal_process(ELM_WIDGET_DATA(sd)->resize_obj);
523 elm_progressbar_inverted_get(const Evas_Object *obj)
525 ELM_PROGRESSBAR_CHECK(obj) EINA_FALSE;
526 ELM_PROGRESSBAR_DATA_GET(obj, sd);