summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShilpa Singh <shilpa.singh@samsung.com>2016-02-12 20:38:36 +0100
committerCedric BAIL <cedric@osg.samsung.com>2016-02-12 20:38:40 +0100
commita3e66305d7601fa4a62629ec2ceb29a1af274915 (patch)
tree5ff90d13b36dd52581fdc6b5966c712ad6516f99
parent4c86a66f28876b68e92a90c8f741eed1130dd034 (diff)
spinner: add min, max filter
Summary: In spinner's entry allow numbers only with in min/max range Signed-off-by: Shilpa Singh <shilpa.singh@samsung.com> @feature Test Plan: 1. Set min/max value to spinner 2. Enter numbers beyond min/max value Reviewers: CHAN, cedric Reviewed By: cedric Subscribers: subodh6129, buds, govi, CHAN, cedric, raster, id213sin Differential Revision: https://phab.enlightenment.org/D3265 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
-rw-r--r--config/default/base.src.in1
-rw-r--r--config/mobile/base.src.in1
-rw-r--r--config/standard/base.src.in1
-rw-r--r--src/lib/elm_config.c4
-rw-r--r--src/lib/elm_priv.h1
-rw-r--r--src/lib/elm_spinner.c54
6 files changed, 61 insertions, 1 deletions
diff --git a/config/default/base.src.in b/config/default/base.src.in
index 6a488c41b..f48f4a400 100644
--- a/config/default/base.src.in
+++ b/config/default/base.src.in
@@ -98,6 +98,7 @@ group "Elm_Config" struct {
98 value "naviframe_prev_btn_auto_pushed" uchar: 1; 98 value "naviframe_prev_btn_auto_pushed" uchar: 1;
99 value "popup_horizontal_align" double: 0.5; 99 value "popup_horizontal_align" double: 0.5;
100 value "popup_vertical_align" double: 0.5; 100 value "popup_vertical_align" double: 0.5;
101 value "spinner_min_max_filter_enable" uchar: 0;
101 group "color_palette" list { 102 group "color_palette" list {
102 group "Elm_Custom_Palette" struct { 103 group "Elm_Custom_Palette" struct {
103 value "palette_name" string: "default"; 104 value "palette_name" string: "default";
diff --git a/config/mobile/base.src.in b/config/mobile/base.src.in
index d3ec42ec0..8eca4b8f0 100644
--- a/config/mobile/base.src.in
+++ b/config/mobile/base.src.in
@@ -102,6 +102,7 @@ group "Elm_Config" struct {
102 value "naviframe_prev_btn_auto_pushed" uchar: 1; 102 value "naviframe_prev_btn_auto_pushed" uchar: 1;
103 value "popup_horizontal_align" double: 0.5; 103 value "popup_horizontal_align" double: 0.5;
104 value "popup_vertical_align" double: 0.5; 104 value "popup_vertical_align" double: 0.5;
105 value "spinner_min_max_filter_enable" uchar: 1;
105 group "color_palette" list { 106 group "color_palette" list {
106 group "Elm_Custom_Palette" struct { 107 group "Elm_Custom_Palette" struct {
107 value "palette_name" string: "default"; 108 value "palette_name" string: "default";
diff --git a/config/standard/base.src.in b/config/standard/base.src.in
index 6e8196c16..37c2cda1b 100644
--- a/config/standard/base.src.in
+++ b/config/standard/base.src.in
@@ -99,6 +99,7 @@ group "Elm_Config" struct {
99 value "naviframe_prev_btn_auto_pushed" uchar: 1; 99 value "naviframe_prev_btn_auto_pushed" uchar: 1;
100 value "popup_horizontal_align" double: 0.5; 100 value "popup_horizontal_align" double: 0.5;
101 value "popup_vertical_align" double: 0.5; 101 value "popup_vertical_align" double: 0.5;
102 value "spinner_min_max_filter_enable" uchar: 0;
102 group "color_palette" list { 103 group "color_palette" list {
103 group "Elm_Custom_Palette" struct { 104 group "Elm_Custom_Palette" struct {
104 value "palette_name" string: "default"; 105 value "palette_name" string: "default";
diff --git a/src/lib/elm_config.c b/src/lib/elm_config.c
index d28ebbadc..723924814 100644
--- a/src/lib/elm_config.c
+++ b/src/lib/elm_config.c
@@ -496,6 +496,7 @@ _desc_init(void)
496 ELM_CONFIG_VAL(D, T, naviframe_prev_btn_auto_pushed, T_UCHAR); 496 ELM_CONFIG_VAL(D, T, naviframe_prev_btn_auto_pushed, T_UCHAR);
497 ELM_CONFIG_VAL(D, T, popup_horizontal_align, T_DOUBLE); 497 ELM_CONFIG_VAL(D, T, popup_horizontal_align, T_DOUBLE);
498 ELM_CONFIG_VAL(D, T, popup_vertical_align, T_DOUBLE); 498 ELM_CONFIG_VAL(D, T, popup_vertical_align, T_DOUBLE);
499 ELM_CONFIG_VAL(D, T, spinner_min_max_filter_enable, T_UCHAR);
499#undef T 500#undef T
500#undef D 501#undef D
501#undef T_INT 502#undef T_INT
@@ -1797,6 +1798,7 @@ _config_load(void)
1797 _elm_config->indicator_service_270 = eina_stringshare_add("elm_indicator_landscape"); 1798 _elm_config->indicator_service_270 = eina_stringshare_add("elm_indicator_landscape");
1798 _elm_config->disable_external_menu = EINA_FALSE; 1799 _elm_config->disable_external_menu = EINA_FALSE;
1799 _elm_config->magnifier_enable = EINA_TRUE; 1800 _elm_config->magnifier_enable = EINA_TRUE;
1801 _elm_config->spinner_min_max_filter_enable = EINA_FALSE;
1800 _elm_config->magnifier_scale = 1.5; 1802 _elm_config->magnifier_scale = 1.5;
1801 _elm_config->audio_mute_effect = 0; 1803 _elm_config->audio_mute_effect = 0;
1802 _elm_config->audio_mute_background = 0; 1804 _elm_config->audio_mute_background = 0;
@@ -2497,6 +2499,8 @@ _env_get(void)
2497 if (s) _elm_config->magnifier_scale = _elm_atof(s); 2499 if (s) _elm_config->magnifier_scale = _elm_atof(s);
2498 s = getenv("ELM_ATSPI_MODE"); 2500 s = getenv("ELM_ATSPI_MODE");
2499 if (s) _elm_config->atspi_mode = ELM_ATSPI_MODE_ON; 2501 if (s) _elm_config->atspi_mode = ELM_ATSPI_MODE_ON;
2502 s = getenv("ELM_SPINNER_MIN_MAX_FILTER_ENABLE");
2503 if (s) _elm_config->spinner_min_max_filter_enable = !!atoi(s);
2500 2504
2501 s = getenv("ELM_TRANSITION_DURATION_FACTOR"); 2505 s = getenv("ELM_TRANSITION_DURATION_FACTOR");
2502 if (s) _elm_config->transition_duration_factor = atof(s); 2506 if (s) _elm_config->transition_duration_factor = atof(s);
diff --git a/src/lib/elm_priv.h b/src/lib/elm_priv.h
index 82915a52e..a1dcb50c0 100644
--- a/src/lib/elm_priv.h
+++ b/src/lib/elm_priv.h
@@ -308,6 +308,7 @@ struct _Elm_Config
308 unsigned char win_auto_focus_animate; 308 unsigned char win_auto_focus_animate;
309 double transition_duration_factor; 309 double transition_duration_factor;
310 unsigned char naviframe_prev_btn_auto_pushed; 310 unsigned char naviframe_prev_btn_auto_pushed;
311 unsigned char spinner_min_max_filter_enable;
311 Eina_List *bindings; 312 Eina_List *bindings;
312 Eina_Bool atspi_mode; 313 Eina_Bool atspi_mode;
313 int gl_depth; 314 int gl_depth;
diff --git a/src/lib/elm_spinner.c b/src/lib/elm_spinner.c
index 65ffee4d0..45674bdad 100644
--- a/src/lib/elm_spinner.c
+++ b/src/lib/elm_spinner.c
@@ -81,7 +81,7 @@ _is_label_format_integer(const char *fmt)
81 if ((*itr == 'd') || (*itr == 'u') || (*itr == 'i') || 81 if ((*itr == 'd') || (*itr == 'u') || (*itr == 'i') ||
82 (*itr == 'o') || (*itr == 'x') || (*itr == 'X')) 82 (*itr == 'o') || (*itr == 'x') || (*itr == 'X'))
83 return EINA_TRUE; 83 return EINA_TRUE;
84 else if ((*itr == 'f')) 84 else if ((*itr == 'f') || (*itr == 'F'))
85 return EINA_FALSE; 85 return EINA_FALSE;
86 } 86 }
87 87
@@ -421,6 +421,56 @@ _entry_filter_add(Evas_Object *obj)
421 elm_entry_markup_filter_append(sd->ent, elm_entry_filter_accept_set, &digits_filter_data); 421 elm_entry_markup_filter_append(sd->ent, elm_entry_filter_accept_set, &digits_filter_data);
422} 422}
423 423
424char *
425_text_insert(const char *text, const char *input, int pos)
426{
427 char *result = NULL;
428 int text_len, input_len;
429
430 text_len = evas_string_char_len_get(text);
431 input_len = evas_string_char_len_get(input);
432 result = (char *)calloc(text_len + input_len + 1, sizeof(char));
433 if (!result) return NULL;
434
435 strncpy(result, text, pos);
436 strcpy(result + pos, input);
437 strcpy(result + pos + input_len, text + pos);
438
439 return result;
440}
441
442static void
443_min_max_validity_filter(void *data, Evas_Object *obj, char **text)
444{
445 const char *str, *new_str;
446 char *insert;
447 double val;
448 int max_len, len;
449
450 EINA_SAFETY_ON_NULL_RETURN(data);
451 EINA_SAFETY_ON_NULL_RETURN(obj);
452 EINA_SAFETY_ON_NULL_RETURN(text);
453
454 ELM_SPINNER_DATA_GET(data, sd);
455
456 str = elm_object_text_get(obj);
457 if (!str) return;
458
459 insert = *text;
460 new_str = _text_insert(str, insert, elm_entry_cursor_pos_get(obj));
461 if (!new_str) return;
462
463 max_len = log10(abs(sd->val_max)) + 1;
464 len = evas_string_char_len_get(new_str);
465 if (len < max_len) return;
466
467 val = strtod(new_str, NULL);
468 ELM_SAFE_FREE(new_str, free);
469
470 if ((val < sd->val_min) || (val > sd->val_max))
471 *insert = 0;
472}
473
424static void 474static void
425_entry_show_cb(void *data, 475_entry_show_cb(void *data,
426 Evas *e EINA_UNUSED, 476 Evas *e EINA_UNUSED,
@@ -468,6 +518,8 @@ _toggle_entry(Evas_Object *obj)
468 (ELM_ENTRY_EVENT_ACTIVATED, _entry_activated_cb, obj)); 518 (ELM_ENTRY_EVENT_ACTIVATED, _entry_activated_cb, obj));
469 elm_layout_content_set(obj, "elm.swallow.entry", sd->ent); 519 elm_layout_content_set(obj, "elm.swallow.entry", sd->ent);
470 _entry_filter_add(obj); 520 _entry_filter_add(obj);
521 if (_elm_config->spinner_min_max_filter_enable)
522 elm_entry_markup_filter_append(sd->ent, _min_max_validity_filter, obj);
471 } 523 }
472 if (!sd->button_layout) 524 if (!sd->button_layout)
473 { 525 {