summaryrefslogtreecommitdiff
path: root/src/lib/elementary
diff options
context:
space:
mode:
authorAmitesh Singh <amitesh.sh@samsung.com>2017-10-26 02:10:29 +0900
committerAmitesh Singh <amitesh.sh@samsung.com>2017-10-26 21:11:36 +0900
commit3092c0fdeaad221c37da996b3ea4a9aaa437ada6 (patch)
tree8955529794a2e74da31b12db64aab2ced241a961 /src/lib/elementary
parent5298cb59d2dc21b5b4507e7e05d86c7b17580536 (diff)
Efl.Ui.Progressbar: implement format_cb.set
Also remove format_string.set/get implmentation since it takes care by base Efl.Ui.Format.format_string Ref T6204
Diffstat (limited to 'src/lib/elementary')
-rw-r--r--src/lib/elementary/efl_ui_progressbar.c113
-rw-r--r--src/lib/elementary/efl_ui_progressbar.eo2
-rw-r--r--src/lib/elementary/efl_ui_progressbar_private.h14
3 files changed, 85 insertions, 44 deletions
diff --git a/src/lib/elementary/efl_ui_progressbar.c b/src/lib/elementary/efl_ui_progressbar.c
index ba15caeda0..32589fd32e 100644
--- a/src/lib/elementary/efl_ui_progressbar.c
+++ b/src/lib/elementary/efl_ui_progressbar.c
@@ -104,22 +104,22 @@ _units_set(Evas_Object *obj)
104{ 104{
105 EFL_UI_PROGRESSBAR_DATA_GET(obj, sd); 105 EFL_UI_PROGRESSBAR_DATA_GET(obj, sd);
106 106
107 if (sd->unit_format_func) 107 if (sd->format_cb)
108 { 108 {
109 char *buf; 109 Eina_Value val;
110 110
111 buf = sd->unit_format_func(sd->val); 111 eina_value_setup(&val, EINA_VALUE_TYPE_DOUBLE);
112 elm_layout_text_set(obj, "elm.text.status", buf); 112 if (!sd->is_legacy_format)
113 if (sd->unit_format_free) sd->unit_format_free(buf); 113 eina_value_set(&val, sd->val);
114 } 114 else // Keeping this bug since the legacy code was like that.
115 else if (sd->units) 115 eina_value_set(&val, 100 * sd->val);
116 {
117 char buf[1024];
118 116
119 snprintf(buf, sizeof(buf), sd->units, 100 * sd->val); 117 eina_strbuf_reset(sd->format_strbuf);
120 elm_layout_text_set(obj, "elm.text.status", buf); 118 sd->format_cb(sd->format_cb_data, sd->format_strbuf, val);
119 elm_layout_text_set(obj, "elm.text.status", eina_strbuf_string_get(sd->format_strbuf));
121 } 120 }
122 else elm_layout_text_set(obj, "elm.text.status", NULL); 121 else
122 elm_layout_text_set(obj, "elm.text.status", NULL);
123} 123}
124 124
125static void 125static void
@@ -216,7 +216,7 @@ _efl_ui_progressbar_elm_widget_theme_apply(Eo *obj, Efl_Ui_Progressbar_Data *sd)
216 if (sd->pulse_state) 216 if (sd->pulse_state)
217 elm_layout_signal_emit(obj, "elm,state,pulse,start", "elm"); 217 elm_layout_signal_emit(obj, "elm,state,pulse,start", "elm");
218 218
219 if (((sd->units) || (sd->unit_format_func)) && (!sd->pulse)) 219 if (sd->format_cb && (!sd->pulse))
220 elm_layout_signal_emit(obj, "elm,state,units,visible", "elm"); 220 elm_layout_signal_emit(obj, "elm,state,units,visible", "elm");
221 221
222 if (_is_horizontal(sd->dir)) 222 if (_is_horizontal(sd->dir))
@@ -292,13 +292,14 @@ _efl_ui_progressbar_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Progressbar_Data
292 elm_widget_sub_object_parent_add(obj); 292 elm_widget_sub_object_parent_add(obj);
293 293
294 priv->dir = EFL_UI_DIR_RIGHT; 294 priv->dir = EFL_UI_DIR_RIGHT;
295 priv->units = eina_stringshare_add("%.0f %%");
296 priv->val = MIN_RATIO_LVL; 295 priv->val = MIN_RATIO_LVL;
297 296
298 if (!elm_layout_theme_set 297 if (!elm_layout_theme_set
299 (obj, "progressbar", "horizontal", elm_widget_style_get(obj))) 298 (obj, "progressbar", "horizontal", elm_widget_style_get(obj)))
300 CRI("Failed to set layout!"); 299 CRI("Failed to set layout!");
301 300
301 efl_ui_format_string_set(obj, "%.0f %%");
302
302 priv->spacer = evas_object_rectangle_add(evas_object_evas_get(obj)); 303 priv->spacer = evas_object_rectangle_add(evas_object_evas_get(obj));
303 evas_object_color_set(priv->spacer, 0, 0, 0, 0); 304 evas_object_color_set(priv->spacer, 0, 0, 0, 0);
304 evas_object_pass_events_set(priv->spacer, EINA_TRUE); 305 evas_object_pass_events_set(priv->spacer, EINA_TRUE);
@@ -327,8 +328,6 @@ _efl_ui_progressbar_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Progressbar_Data
327{ 328{
328 Efl_Ui_Progress_Status *progress_obj; 329 Efl_Ui_Progress_Status *progress_obj;
329 330
330 eina_stringshare_del(sd->units);
331 sd->units = NULL;
332 if (sd->progress_status) 331 if (sd->progress_status)
333 { 332 {
334 EINA_LIST_FREE(sd->progress_status, progress_obj) 333 EINA_LIST_FREE(sd->progress_status, progress_obj)
@@ -337,6 +336,9 @@ _efl_ui_progressbar_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Progressbar_Data
337 } 336 }
338 } 337 }
339 338
339 efl_ui_format_cb_set(obj, NULL, NULL, NULL);
340 eina_strbuf_free(sd->format_strbuf);
341
340 efl_canvas_group_del(efl_super(obj, MY_CLASS)); 342 efl_canvas_group_del(efl_super(obj, MY_CLASS));
341} 343}
342 344
@@ -344,7 +346,10 @@ EAPI Evas_Object *
344elm_progressbar_add(Evas_Object *parent) 346elm_progressbar_add(Evas_Object *parent)
345{ 347{
346 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL); 348 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
347 return efl_add(MY_CLASS, parent, efl_canvas_object_legacy_ctor(efl_added)); 349 Eo *obj = efl_add(MY_CLASS, parent, efl_canvas_object_legacy_ctor(efl_added));
350 elm_progressbar_unit_format_set(obj, "%.0f %%");
351
352 return obj;
348} 353}
349 354
350EOLIAN static Eo * 355EOLIAN static Eo *
@@ -473,26 +478,28 @@ _efl_ui_progressbar_efl_ui_range_range_value_get(Eo *obj EINA_UNUSED, Efl_Ui_Pro
473} 478}
474 479
475EOLIAN static void 480EOLIAN static void
476_efl_ui_progressbar_efl_ui_format_format_string_set(Eo *obj, Efl_Ui_Progressbar_Data *sd, const char *units) 481_efl_ui_progressbar_efl_ui_format_format_cb_set(Eo *obj, Efl_Ui_Progressbar_Data *sd, void *func_data, Efl_Ui_Format_Func_Cb func, Eina_Free_Cb func_free_cb)
477{ 482{
478 const char *sig;
479 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd); 483 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
480 484
481 eina_stringshare_replace(&sd->units, units); 485 if (sd->format_cb_data == func_data && sd->format_cb == func)
482 sig = (units) ? "elm,state,units,visible" : "elm,state,units,hidden"; 486 return;
483 elm_layout_signal_emit(obj, sig, "elm"); 487
488 if (sd->format_cb_data && sd->format_free_cb)
489 sd->format_free_cb(sd->format_cb_data);
490
491 sd->format_cb = func;
492 sd->format_cb_data = func_data;
493 sd->format_free_cb = func_free_cb;
494 if (!sd->format_strbuf) sd->format_strbuf = eina_strbuf_new();
495
496 elm_layout_signal_emit(obj, "elm,state,units,visible", "elm");
484 edje_object_message_signal_process(wd->resize_obj); 497 edje_object_message_signal_process(wd->resize_obj);
485 498
486 _units_set(obj); 499 _units_set(obj);
487 elm_layout_sizing_eval(obj); 500 elm_layout_sizing_eval(obj);
488} 501}
489 502
490EOLIAN static const char *
491_efl_ui_progressbar_efl_ui_format_format_string_get(Eo *obj EINA_UNUSED, Efl_Ui_Progressbar_Data *sd)
492{
493 return sd->units;
494}
495
496EOLIAN static void 503EOLIAN static void
497_efl_ui_progressbar_pulse_set(Eo *obj, Efl_Ui_Progressbar_Data *sd, Eina_Bool state) 504_efl_ui_progressbar_pulse_set(Eo *obj, Efl_Ui_Progressbar_Data *sd, Eina_Bool state)
498{ 505{
@@ -542,6 +549,10 @@ elm_progressbar_span_size_get(const Evas_Object *obj)
542EAPI void 549EAPI void
543elm_progressbar_unit_format_set(Evas_Object *obj, const char *units) 550elm_progressbar_unit_format_set(Evas_Object *obj, const char *units)
544{ 551{
552 EFL_UI_PROGRESSBAR_DATA_GET_OR_RETURN(obj, sd);
553
554 sd->is_legacy_format = EINA_TRUE;
555
545 efl_ui_format_string_set(obj, units); 556 efl_ui_format_string_set(obj, units);
546} 557}
547 558
@@ -551,21 +562,47 @@ elm_progressbar_unit_format_get(const Evas_Object *obj)
551 return efl_ui_format_string_get(obj); 562 return efl_ui_format_string_get(obj);
552} 563}
553 564
565typedef struct
566{
567 progressbar_func_type format_cb;
568 progressbar_freefunc_type format_free_cb;
569} Pb_Format_Wrapper_Data;
570
571static void
572_format_legacy_to_format_eo_cb(void *data, Eina_Strbuf *str, const Eina_Value value)
573{
574 Pb_Format_Wrapper_Data *pfwd = data;
575 char *buf = NULL;
576 double val = 0;
577 const Eina_Value_Type *type = eina_value_type_get(&value);
578
579 if (type == EINA_VALUE_TYPE_DOUBLE)
580 eina_value_get(&value, &val);
581
582 if (pfwd->format_cb)
583 buf = pfwd->format_cb(val);
584 if (buf)
585 eina_strbuf_append(str, buf);
586 if (pfwd->format_free_cb) pfwd->format_free_cb(buf);
587}
588
589static void
590_format_legacy_to_format_eo_free_cb(void *data)
591{
592 Pb_Format_Wrapper_Data *pfwd = data;
593 free(pfwd);
594}
595
554EAPI void 596EAPI void
555elm_progressbar_unit_format_function_set(Evas_Object *obj, progressbar_func_type func, progressbar_freefunc_type free_func) 597elm_progressbar_unit_format_function_set(Evas_Object *obj, progressbar_func_type func, progressbar_freefunc_type free_func)
556{ 598{
557 const char *sig; 599 Pb_Format_Wrapper_Data *pfwd = malloc(sizeof(Pb_Format_Wrapper_Data));
558 EFL_UI_PROGRESSBAR_DATA_GET(obj, sd);
559 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
560 600
561 sd->unit_format_func = func; 601 pfwd->format_cb = func;
562 sd->unit_format_free = free_func; 602 pfwd->format_free_cb = free_func;
563 sig = (func) ? "elm,state,units,visible" : "elm,state,units,hidden";
564 elm_layout_signal_emit(obj, sig, "elm");
565 edje_object_message_signal_process(wd->resize_obj);
566 603
567 _units_set(obj); 604 efl_ui_format_cb_set(obj, pfwd, _format_legacy_to_format_eo_cb,
568 elm_layout_sizing_eval(obj); 605 _format_legacy_to_format_eo_free_cb);
569} 606}
570 607
571EAPI void 608EAPI void
diff --git a/src/lib/elementary/efl_ui_progressbar.eo b/src/lib/elementary/efl_ui_progressbar.eo
index da65e80fc0..eb86cf8e55 100644
--- a/src/lib/elementary/efl_ui_progressbar.eo
+++ b/src/lib/elementary/efl_ui_progressbar.eo
@@ -54,7 +54,7 @@ class Efl.Ui.Progressbar (Efl.Ui.Layout, Efl.Ui.Range, Efl.Ui.Format, Efl.Ui.Dir
54 Elm.Widget.widget_sub_object_del; 54 Elm.Widget.widget_sub_object_del;
55 Efl.Ui.Range.range_value { get; set; } 55 Efl.Ui.Range.range_value { get; set; }
56 Efl.Ui.Direction.direction { get; set; } 56 Efl.Ui.Direction.direction { get; set; }
57 Efl.Ui.Format.format_string { get; set; } 57 Efl.Ui.Format.format_cb { set; }
58 Efl.Part.part; 58 Efl.Part.part;
59 } 59 }
60 events { 60 events {
diff --git a/src/lib/elementary/efl_ui_progressbar_private.h b/src/lib/elementary/efl_ui_progressbar_private.h
index afc7017002..76ce9907c4 100644
--- a/src/lib/elementary/efl_ui_progressbar_private.h
+++ b/src/lib/elementary/efl_ui_progressbar_private.h
@@ -29,18 +29,22 @@ typedef struct _Efl_Ui_Progress_Status Efl_Ui_Progress_Status;
29struct _Efl_Ui_Progressbar_Data 29struct _Efl_Ui_Progressbar_Data
30{ 30{
31 Evas_Object *spacer; /**< The rect actual progressbar area, gets the progressbar size and gets the events */ 31 Evas_Object *spacer; /**< The rect actual progressbar area, gets the progressbar size and gets the events */
32 const char *units; /**< The units will be displayed on progressbar */
33 32
34 Evas_Coord size; /**< Width or height of progressbar */ 33 Evas_Coord size; /**< Width or height of progressbar */
35 double val; /**< Value of progressbar */ 34 double val; /**< Value of progressbar */
36 35
36 Eina_List *progress_status; /**< The list of _Elm_Progress_Status. To save the progress value(in percentage) each part of given progress bar */
37
38 Efl_Ui_Format_Func_Cb format_cb;
39 Eina_Free_Cb format_free_cb;
40 void *format_cb_data;
41 Eina_Strbuf *format_strbuf;
42
37 Efl_Ui_Dir dir; /**< Orientation of the progressbar */ 43 Efl_Ui_Dir dir; /**< Orientation of the progressbar */
44
38 Eina_Bool pulse : 1; /**< Whether object is put in the pulsing mode */ 45 Eina_Bool pulse : 1; /**< Whether object is put in the pulsing mode */
39 Eina_Bool pulse_state : 1; /**< To start the pulsing animation, otherwise to stop it */ 46 Eina_Bool pulse_state : 1; /**< To start the pulsing animation, otherwise to stop it */
40 Eina_List *progress_status; /**< The list of _Elm_Progress_Status. To save the progress value(in percentage) each part of given progress bar */ 47 Eina_Bool is_legacy_format : 1;
41
42 char *(*unit_format_func)(double val); /**< The function pointer will be called when user wants to set a customized unit format */
43 void (*unit_format_free)(char *str); /**< The freeing function for the format string */
44}; 48};
45 49
46struct _Efl_Ui_Progress_Status 50struct _Efl_Ui_Progress_Status