summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/efl/interfaces/efl_interfaces_main.c1
-rw-r--r--src/lib/efl/interfaces/efl_ui_format.c63
-rw-r--r--src/lib/efl/interfaces/efl_ui_format.eo4
-rw-r--r--src/lib/elementary/efl_ui_slider.c147
-rw-r--r--src/lib/elementary/efl_ui_slider.eo1
-rw-r--r--src/lib/elementary/efl_ui_slider_private.h4
6 files changed, 121 insertions, 99 deletions
diff --git a/src/lib/efl/interfaces/efl_interfaces_main.c b/src/lib/efl/interfaces/efl_interfaces_main.c
index eb85ef2773..778108e699 100644
--- a/src/lib/efl/interfaces/efl_interfaces_main.c
+++ b/src/lib/efl/interfaces/efl_interfaces_main.c
@@ -68,7 +68,6 @@
68#include "interfaces/efl_ui_scrollable.eo.c" 68#include "interfaces/efl_ui_scrollable.eo.c"
69#include "interfaces/efl_ui_selectable.eo.c" 69#include "interfaces/efl_ui_selectable.eo.c"
70#include "interfaces/efl_ui_zoom.eo.c" 70#include "interfaces/efl_ui_zoom.eo.c"
71#include "interfaces/efl_ui_format.eo.c"
72 71
73EAPI void 72EAPI void
74__efl_internal_init(void) 73__efl_internal_init(void)
diff --git a/src/lib/efl/interfaces/efl_ui_format.c b/src/lib/efl/interfaces/efl_ui_format.c
new file mode 100644
index 0000000000..6cb64f3913
--- /dev/null
+++ b/src/lib/efl/interfaces/efl_ui_format.c
@@ -0,0 +1,63 @@
1#include "config.h"
2#include "Efl.h"
3
4typedef struct
5{
6 const char *template;
7} Efl_Ui_Format_Data;
8
9static void
10_default_format_cb(void *data, Eina_Strbuf *str, const Eina_Value value)
11{
12 const Eina_Value_Type *type = eina_value_type_get(&value);
13 Efl_Ui_Format_Data *sd = data;
14
15 if (type == EINA_VALUE_TYPE_DOUBLE)
16 {
17 double v;
18 eina_value_get(&value, &v);
19 eina_strbuf_append_printf(str, sd->template, v);
20 }
21 else if (type == EINA_VALUE_TYPE_INT)
22 {
23 int v;
24 eina_value_get(&value, &v);
25 eina_strbuf_append_printf(str, sd->template, v);
26 }
27 //XXX: handle other types e.g. struct tm
28 else
29 {
30 char *v = eina_value_to_string(&value);
31 eina_strbuf_append_printf(str, "%s", v);
32 free(v);
33 }
34}
35
36static void
37_default_format_free_cb(void *data)
38{
39 Efl_Ui_Format_Data *sd = data;
40
41 if (sd->template)
42 {
43 eina_stringshare_del(sd->template);
44 sd->template = NULL;
45 }
46}
47
48EOLIAN static void
49_efl_ui_format_format_string_set(Eo *obj, Efl_Ui_Format_Data *sd, const char *template)
50{
51 if (!template) return;
52 eina_stringshare_replace(&sd->template, template);
53 efl_ui_format_cb_set(obj, sd, _default_format_cb, _default_format_free_cb);
54}
55
56EOLIAN static const char *
57_efl_ui_format_format_string_get(Eo *obj EINA_UNUSED, Efl_Ui_Format_Data *sd)
58{
59 return sd->template;
60}
61
62#include "interfaces/efl_ui_format.eo.c"
63
diff --git a/src/lib/efl/interfaces/efl_ui_format.eo b/src/lib/efl/interfaces/efl_ui_format.eo
index 38d51c18bd..2f386dafa7 100644
--- a/src/lib/efl/interfaces/efl_ui_format.eo
+++ b/src/lib/efl/interfaces/efl_ui_format.eo
@@ -8,12 +8,12 @@ function Efl.Ui.Format_Func_Cb {
8 } 8 }
9}; 9};
10 10
11interface Efl.Ui.Format 11mixin Efl.Ui.Format
12{ 12{
13 [[interface class for format_func]] 13 [[interface class for format_func]]
14 methods { 14 methods {
15 @property format_cb { 15 @property format_cb {
16 set { 16 set @pure_virtual {
17 [[Set the format function pointer to format the string. 17 [[Set the format function pointer to format the string.
18 ]] 18 ]]
19 } 19 }
diff --git a/src/lib/elementary/efl_ui_slider.c b/src/lib/elementary/efl_ui_slider.c
index 6b543a861e..1020747318 100644
--- a/src/lib/elementary/efl_ui_slider.c
+++ b/src/lib/elementary/efl_ui_slider.c
@@ -221,39 +221,21 @@ _units_set(Evas_Object *obj)
221 Eina_Value val; 221 Eina_Value val;
222 222
223 eina_value_setup(&val, EINA_VALUE_TYPE_DOUBLE); 223 eina_value_setup(&val, EINA_VALUE_TYPE_DOUBLE);
224 eina_value_set(&val, sd->val);
225 224
226 eina_strbuf_reset(sd->format_strbuf); 225 eina_strbuf_reset(sd->format_strbuf);
227
228 sd->format_cb(sd->format_cb_data, sd->format_strbuf, val);
229
230 elm_layout_text_set(obj, "elm.units", eina_strbuf_string_get(sd->format_strbuf));
231 if (!sd->units_show)
232 {
233 elm_layout_signal_emit(obj, "elm,state,units,visible", "elm");
234 sd->units_show = EINA_TRUE;
235 }
236 else
237 {
238 elm_layout_signal_emit(obj, "elm,state,units,hidden", "elm");
239 sd->units_show = EINA_FALSE;
240 }
241 }
242 else if (sd->units)
243 {
244 char buf[1024];
245
246 if (!sd->intvl_enable) 226 if (!sd->intvl_enable)
247 snprintf(buf, sizeof(buf), sd->units, sd->val); 227 eina_value_set(&val, sd->val);
248 else 228 else
249 { 229 {
250 double v1, v2; 230 double v1, v2;
251 231
252 elm_slider_range_get(obj, &v1, &v2); 232 elm_slider_range_get(obj, &v1, &v2);
253 snprintf(buf, sizeof(buf), sd->units, v2 - v1); 233 eina_value_set(&val, v2 - v1);
254 } 234 }
255 235
256 elm_layout_text_set(obj, "elm.units", buf); 236 sd->format_cb(sd->format_cb_data, sd->format_strbuf, val);
237 elm_layout_text_set(obj, "elm.units", eina_strbuf_string_get(sd->format_strbuf));
238
257 if (!sd->units_show) 239 if (!sd->units_show)
258 { 240 {
259 elm_layout_signal_emit(obj, "elm,state,units,visible", "elm"); 241 elm_layout_signal_emit(obj, "elm,state,units,visible", "elm");
@@ -1031,35 +1013,26 @@ _spacer_up_cb(void *data,
1031static void 1013static void
1032_min_max_set(Evas_Object *obj) 1014_min_max_set(Evas_Object *obj)
1033{ 1015{
1034 char *buf_min = NULL;
1035 char *buf_max = NULL;
1036
1037 EFL_UI_SLIDER_DATA_GET(obj, sd); 1016 EFL_UI_SLIDER_DATA_GET(obj, sd);
1017 Eina_Strbuf *str;
1018 Eina_Value val;
1038 1019
1039 if (sd->units_format_func) 1020 if (!sd->format_cb) return;
1040 { 1021 eina_value_setup(&val, EINA_VALUE_TYPE_DOUBLE);
1041 buf_min = sd->units_format_func(sd->val_min);
1042 buf_max = sd->units_format_func(sd->val_max);
1043 }
1044 else if (sd->units)
1045 {
1046 int length = eina_stringshare_strlen(sd->units);
1047 1022
1048 buf_min = alloca(length + 128); 1023 str = eina_strbuf_new();
1049 buf_max = alloca(length + 128);
1050 1024
1051 snprintf((char *)buf_min, length + 128, sd->units, sd->val_min); 1025 eina_value_set(&val, sd->val_max);
1052 snprintf((char *)buf_max, length + 128, sd->units, sd->val_max); 1026 sd->format_cb(sd->format_cb_data, str, val);
1053 } 1027 elm_layout_text_set(obj, "elm.units.min", eina_strbuf_string_get(str));
1054 1028
1055 elm_layout_text_set(obj, "elm.units.min", buf_min); 1029 eina_strbuf_reset(str);
1056 elm_layout_text_set(obj, "elm.units.max", buf_max);
1057 1030
1058 if (sd->units_format_func && sd->units_format_free) 1031 eina_value_set(&val, sd->val_min);
1059 { 1032 sd->format_cb(sd->format_cb_data, str, val);
1060 sd->units_format_free(buf_min); 1033 elm_layout_text_set(obj, "elm.units.max", eina_strbuf_string_get(str));
1061 sd->units_format_free(buf_max); 1034
1062 } 1035 eina_strbuf_free(str);
1063} 1036}
1064 1037
1065EOLIAN static void 1038EOLIAN static void
@@ -1196,7 +1169,6 @@ EOLIAN static void
1196_efl_ui_slider_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Slider_Data *sd) 1169_efl_ui_slider_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Slider_Data *sd)
1197{ 1170{
1198 eina_stringshare_del(sd->indicator); 1171 eina_stringshare_del(sd->indicator);
1199 eina_stringshare_del(sd->units);
1200 ecore_timer_del(sd->delay); 1172 ecore_timer_del(sd->delay);
1201 ecore_timer_del(sd->wheel_indicator_timer); 1173 ecore_timer_del(sd->wheel_indicator_timer);
1202 evas_object_del(sd->popup); 1174 evas_object_del(sd->popup);
@@ -1432,41 +1404,10 @@ _efl_ui_slider_efl_access_value_increment_get(Eo *obj EINA_UNUSED, Efl_Ui_Slider
1432} 1404}
1433 1405
1434EOLIAN static void 1406EOLIAN static void
1435_efl_ui_slider_efl_ui_format_format_string_set(Eo *obj, Efl_Ui_Slider_Data *sd, const char *units)
1436{
1437 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
1438
1439 eina_stringshare_replace(&sd->units, units);
1440 if (units)
1441 {
1442 elm_layout_signal_emit(obj, "elm,state,units,visible", "elm");
1443 edje_object_message_signal_process(wd->resize_obj);
1444 if (sd->popup)
1445 edje_object_signal_emit(sd->popup, "elm,state,units,visible", "elm");
1446 if (sd->popup2)
1447 edje_object_signal_emit(sd->popup2, "elm,state,units,visible", "elm");
1448 }
1449 else
1450 {
1451 elm_layout_signal_emit(obj, "elm,state,units,hidden", "elm");
1452 edje_object_message_signal_process(wd->resize_obj);
1453 if (sd->popup)
1454 edje_object_signal_emit(sd->popup, "elm,state,units,hidden", "elm");
1455 if (sd->popup2)
1456 edje_object_signal_emit(sd->popup2, "elm,state,units,hidden", "elm");
1457 }
1458 evas_object_smart_changed(obj);
1459}
1460
1461EOLIAN static const char *
1462_efl_ui_slider_efl_ui_format_format_string_get(Eo *obj EINA_UNUSED, Efl_Ui_Slider_Data *sd)
1463{
1464 return sd->units;
1465}
1466
1467EOLIAN static void
1468_efl_ui_slider_efl_ui_format_format_cb_set(Eo *obj, Efl_Ui_Slider_Data *sd, void *func_data, Efl_Ui_Format_Func_Cb func, Eina_Free_Cb func_free_cb) 1407_efl_ui_slider_efl_ui_format_format_cb_set(Eo *obj, Efl_Ui_Slider_Data *sd, void *func_data, Efl_Ui_Format_Func_Cb func, Eina_Free_Cb func_free_cb)
1469{ 1408{
1409 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
1410
1470 if (sd->format_cb_data == func_data && sd->format_cb == func) 1411 if (sd->format_cb_data == func_data && sd->format_cb == func)
1471 return; 1412 return;
1472 1413
@@ -1478,6 +1419,13 @@ _efl_ui_slider_efl_ui_format_format_cb_set(Eo *obj, Efl_Ui_Slider_Data *sd, void
1478 sd->format_free_cb = func_free_cb; 1419 sd->format_free_cb = func_free_cb;
1479 if (!sd->format_strbuf) sd->format_strbuf = eina_strbuf_new(); 1420 if (!sd->format_strbuf) sd->format_strbuf = eina_strbuf_new();
1480 1421
1422 elm_layout_signal_emit(obj, "elm,state,units,visible", "elm");
1423 edje_object_message_signal_process(wd->resize_obj);
1424 if (sd->popup)
1425 edje_object_signal_emit(sd->popup, "elm,state,units,visible", "elm");
1426 if (sd->popup2)
1427 edje_object_signal_emit(sd->popup2, "elm,state,units,visible", "elm");
1428
1481 efl_canvas_group_change(obj); 1429 efl_canvas_group_change(obj);
1482} 1430}
1483 1431
@@ -1614,29 +1562,46 @@ elm_slider_inverted_get(const Evas_Object *obj)
1614 return _is_inverted(dir); 1562 return _is_inverted(dir);
1615} 1563}
1616 1564
1565typedef struct
1566{
1567 slider_func_type format_cb;
1568 slider_freefunc_type format_free_cb;
1569} Slider_Format_Wrapper_Data;
1570
1617static void 1571static void
1618_format_legacy_to_format_eo_cb(void *data, Eina_Strbuf *str, const Eina_Value value EINA_UNUSED) 1572_format_legacy_to_format_eo_cb(void *data, Eina_Strbuf *str, const Eina_Value value)
1619{ 1573{
1620 Efl_Ui_Slider_Data *sd = data; 1574 Slider_Format_Wrapper_Data *sfwd = data;
1621 char *buf; 1575 char *buf = NULL;
1576 double val = 0;
1577 const Eina_Value_Type *type = eina_value_type_get(&value);
1578
1579 if (type == EINA_VALUE_TYPE_DOUBLE)
1580 eina_value_get(&value, &val);
1622 1581
1623 buf = sd->units_format_func(sd->val); 1582 if (sfwd->format_cb)
1583 buf = sfwd->format_cb(val);
1624 if (buf) 1584 if (buf)
1625 eina_strbuf_append(str, buf); 1585 eina_strbuf_append(str, buf);
1626 if (sd->units_format_free) sd->units_format_free(buf); 1586 if (sfwd->format_free_cb) sfwd->format_free_cb(buf);
1587}
1588
1589static void
1590_format_legacy_to_format_eo_free_cb(void *data)
1591{
1592 Slider_Format_Wrapper_Data *sfwd = data;
1593 free(sfwd);
1627} 1594}
1628 1595
1629EAPI void 1596EAPI void
1630elm_slider_units_format_function_set(Evas_Object *obj, slider_func_type func, slider_freefunc_type free_func) 1597elm_slider_units_format_function_set(Evas_Object *obj, slider_func_type func, slider_freefunc_type free_func)
1631{ 1598{
1632 EFL_UI_SLIDER_DATA_GET_OR_RETURN(obj, sd); 1599 Slider_Format_Wrapper_Data *sfwd = malloc(sizeof(Slider_Format_Wrapper_Data));
1633
1634 sd->units_format_func = func;
1635 sd->units_format_free = free_func;
1636 1600
1637 efl_ui_format_cb_set(obj, sd, _format_legacy_to_format_eo_cb, NULL); 1601 sfwd->format_cb = func;
1602 sfwd->format_free_cb = free_func;
1638 1603
1639 evas_object_smart_changed(obj); 1604 efl_ui_format_cb_set(obj, sfwd, _format_legacy_to_format_eo_cb, _format_legacy_to_format_eo_free_cb);
1640} 1605}
1641 1606
1642EAPI void 1607EAPI void
diff --git a/src/lib/elementary/efl_ui_slider.eo b/src/lib/elementary/efl_ui_slider.eo
index 1283e0a86b..609c3fa258 100644
--- a/src/lib/elementary/efl_ui_slider.eo
+++ b/src/lib/elementary/efl_ui_slider.eo
@@ -128,7 +128,6 @@ class Efl.Ui.Slider (Efl.Ui.Layout, Efl.Ui.Range, Efl.Ui.Direction,
128 Elm.Interface.Atspi_Widget_Action.elm_actions { get; } 128 Elm.Interface.Atspi_Widget_Action.elm_actions { get; }
129 Efl.Text.text { get; set; } 129 Efl.Text.text { get; set; }
130 Efl.Text.Markup.markup { get; set; } 130 Efl.Text.Markup.markup { get; set; }
131 Efl.Ui.Format.format_string { get; set; }
132 Efl.Ui.Format.format_cb { set; } 131 Efl.Ui.Format.format_cb { set; }
133 Efl.Ui.Translatable.translatable_text { get; set; } 132 Efl.Ui.Translatable.translatable_text { get; set; }
134 } 133 }
diff --git a/src/lib/elementary/efl_ui_slider_private.h b/src/lib/elementary/efl_ui_slider_private.h
index 03ac83bb4f..d79a1cc6de 100644
--- a/src/lib/elementary/efl_ui_slider_private.h
+++ b/src/lib/elementary/efl_ui_slider_private.h
@@ -29,15 +29,11 @@ struct _Efl_Ui_Slider_Data
29 Evas_Object *spacer, *popup, *popup2, *track, *track2; 29 Evas_Object *spacer, *popup, *popup2, *track, *track2;
30 Ecore_Timer *delay; 30 Ecore_Timer *delay;
31 31
32 const char *units;
33 const char *indicator; 32 const char *indicator;
34 33
35 char *(*indicator_format_func)(double val); 34 char *(*indicator_format_func)(double val);
36 void (*indicator_format_free)(char *str); 35 void (*indicator_format_free)(char *str);
37 36
38 char *(*units_format_func)(double val);
39 void (*units_format_free)(char *str);
40
41 double val, val_min, val_max, val2, step; 37 double val, val_min, val_max, val2, step;
42 38
43 Ecore_Timer *wheel_indicator_timer; 39 Ecore_Timer *wheel_indicator_timer;