summaryrefslogtreecommitdiff
path: root/src/lib/elementary/efl_ui_slider.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/elementary/efl_ui_slider.c147
1 files changed, 56 insertions, 91 deletions
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