summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwoochan lee <wc0917.lee@samsung.com>2015-12-24 13:40:00 +0900
committerHermet Park <hermet@hermet.pe.kr>2015-12-24 13:42:32 +0900
commitb8e15ef9d9819759c2724fe712b0b32188f8cd44 (patch)
tree14e91d57c81af2a0aca68f2bbd200790bfcee1fb
parent9dbba7412358ac31af2f8e962d30438681b0f097 (diff)
spinner: Internal code refactoring.
Summary: Even doing almost same thihgs in inc_XXX fucntions, dec_XXX fucntion. It was separated up. So i merged those functions for code size reduce. Test Plan: Run elementary_test Execute spinner sample. Reviewers: cedric, Hermet Differential Revision: https://phab.enlightenment.org/D3455
-rw-r--r--src/lib/elm_spinner.c217
-rw-r--r--src/lib/elm_widget_spinner.h1
2 files changed, 61 insertions, 157 deletions
diff --git a/src/lib/elm_spinner.c b/src/lib/elm_spinner.c
index 893773d72..65ffee4d0 100644
--- a/src/lib/elm_spinner.c
+++ b/src/lib/elm_spinner.c
@@ -42,26 +42,17 @@ static Eina_Bool _key_action_spin(Evas_Object *obj, const char *params);
42static Eina_Bool _key_action_toggle(Evas_Object *obj, const char *params); 42static Eina_Bool _key_action_toggle(Evas_Object *obj, const char *params);
43 43
44static Eina_Bool 44static Eina_Bool
45_inc_button_clicked_cb(void *data, Eo *obj EINA_UNUSED, 45_inc_dec_button_clicked_cb(void *data, Eo *obj EINA_UNUSED,
46 const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED); 46 const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED);
47static Eina_Bool 47static Eina_Bool
48_inc_button_pressed_cb(void *data, Eo *obj EINA_UNUSED, 48_inc_dec_button_pressed_cb(void *data, Eo *obj,
49 const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED); 49 const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED);
50static Eina_Bool 50static Eina_Bool
51_inc_button_unpressed_cb(void *data, Eo *obj EINA_UNUSED, 51_inc_dec_button_unpressed_cb(void *data, Eo *obj EINA_UNUSED,
52 const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED); 52 const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED);
53static Eina_Bool 53static Eina_Bool
54_inc_dec_button_mouse_move_cb(void *data, Eo *obj EINA_UNUSED, 54_inc_dec_button_mouse_move_cb(void *data, Eo *obj EINA_UNUSED,
55 const Eo_Event_Description *desc EINA_UNUSED, void *event_info); 55 const Eo_Event_Description *desc EINA_UNUSED, void *event_info);
56static Eina_Bool
57_dec_button_clicked_cb(void *data, Eo *obj EINA_UNUSED,
58 const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED);
59static Eina_Bool
60_dec_button_pressed_cb(void *data, Eo *obj EINA_UNUSED,
61 const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED);
62static Eina_Bool
63_dec_button_unpressed_cb(void *data, Eo *obj EINA_UNUSED,
64 const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED);
65 56
66static const Elm_Action key_actions[] = { 57static const Elm_Action key_actions[] = {
67 {"spin", _key_action_spin}, 58 {"spin", _key_action_spin},
@@ -69,21 +60,13 @@ static const Elm_Action key_actions[] = {
69 {NULL, NULL} 60 {NULL, NULL}
70}; 61};
71 62
72EO_CALLBACKS_ARRAY_DEFINE(_inc_button_cb, 63EO_CALLBACKS_ARRAY_DEFINE(_inc_dec_button_cb,
73 { EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _inc_button_clicked_cb}, 64 { EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _inc_dec_button_clicked_cb},
74 { EVAS_CLICKABLE_INTERFACE_EVENT_PRESSED, _inc_button_pressed_cb}, 65 { EVAS_CLICKABLE_INTERFACE_EVENT_PRESSED, _inc_dec_button_pressed_cb},
75 { EVAS_CLICKABLE_INTERFACE_EVENT_UNPRESSED, _inc_button_unpressed_cb}, 66 { EVAS_CLICKABLE_INTERFACE_EVENT_UNPRESSED, _inc_dec_button_unpressed_cb},
76 { EVAS_OBJECT_EVENT_MOUSE_MOVE, _inc_dec_button_mouse_move_cb }
77);
78
79EO_CALLBACKS_ARRAY_DEFINE(_dec_button_cb,
80 { EVAS_CLICKABLE_INTERFACE_EVENT_CLICKED, _dec_button_clicked_cb},
81 { EVAS_CLICKABLE_INTERFACE_EVENT_PRESSED, _dec_button_pressed_cb},
82 { EVAS_CLICKABLE_INTERFACE_EVENT_UNPRESSED, _dec_button_unpressed_cb},
83 { EVAS_OBJECT_EVENT_MOUSE_MOVE, _inc_dec_button_mouse_move_cb } 67 { EVAS_OBJECT_EVENT_MOUSE_MOVE, _inc_dec_button_mouse_move_cb }
84); 68);
85 69
86
87static void _access_increment_decrement_info_say(Evas_Object *obj, 70static void _access_increment_decrement_info_say(Evas_Object *obj,
88 Eina_Bool is_incremented); 71 Eina_Bool is_incremented);
89 72
@@ -531,29 +514,12 @@ _spin_value(void *data)
531} 514}
532 515
533static Eina_Bool 516static Eina_Bool
534_val_inc_start(void *data) 517_val_inc_dec_start(void *data)
535{ 518{
536 ELM_SPINNER_DATA_GET(data, sd); 519 ELM_SPINNER_DATA_GET(data, sd);
537 520
538 sd->interval = sd->first_interval; 521 sd->interval = sd->first_interval;
539 sd->spin_speed = sd->step; 522 sd->spin_speed = sd->inc_clicked ? sd->step : -sd->step;
540 sd->longpress_timer = NULL;
541 ecore_timer_del(sd->spin_timer);
542 sd->spin_timer = ecore_timer_add(sd->interval, _spin_value, data);
543 _spin_value(data);
544
545 elm_widget_scroll_freeze_push(data);
546
547 return ECORE_CALLBACK_CANCEL;
548}
549
550static Eina_Bool
551_val_dec_start(void *data)
552{
553 ELM_SPINNER_DATA_GET(data, sd);
554
555 sd->interval = sd->first_interval;
556 sd->spin_speed = -sd->step;
557 sd->longpress_timer = NULL; 523 sd->longpress_timer = NULL;
558 ecore_timer_del(sd->spin_timer); 524 ecore_timer_del(sd->spin_timer);
559 sd->spin_timer = ecore_timer_add(sd->interval, _spin_value, data); 525 sd->spin_timer = ecore_timer_add(sd->interval, _spin_value, data);
@@ -581,17 +547,20 @@ _key_action_spin(Evas_Object *obj, const char *params)
581{ 547{
582 const char *dir = params; 548 const char *dir = params;
583 Eina_Bool horz = !!strncmp(elm_widget_style_get(obj), "vertical", 8); 549 Eina_Bool horz = !!strncmp(elm_widget_style_get(obj), "vertical", 8);
550 ELM_SPINNER_DATA_GET(obj, sd);
584 551
585 if (((!strcmp(dir, "left")) && horz) || 552 if (((!strcmp(dir, "left")) && horz) ||
586 ((!strcmp(dir, "down")) && !horz)) 553 ((!strcmp(dir, "down")) && !horz))
587 { 554 {
588 _val_dec_start(obj); 555 sd->inc_clicked = EINA_FALSE;
556 _val_inc_dec_start(obj);
589 elm_layout_signal_emit(obj, "elm,left,anim,activate", "elm"); 557 elm_layout_signal_emit(obj, "elm,left,anim,activate", "elm");
590 } 558 }
591 else if (((!strcmp(dir, "right")) && horz) || 559 else if (((!strcmp(dir, "right")) && horz) ||
592 ((!strcmp(dir, "up")) && !horz)) 560 ((!strcmp(dir, "up")) && !horz))
593 { 561 {
594 _val_inc_start(obj); 562 sd->inc_clicked = EINA_TRUE;
563 _val_inc_dec_start(obj);
595 elm_layout_signal_emit(obj, "elm,right,anim,activate", "elm"); 564 elm_layout_signal_emit(obj, "elm,right,anim,activate", "elm");
596 } 565 }
597 else return EINA_FALSE; 566 else return EINA_FALSE;
@@ -660,26 +629,40 @@ _elm_spinner_elm_widget_event(Eo *obj, Elm_Spinner_Data *sd EINA_UNUSED, Evas_Ob
660} 629}
661 630
662static void 631static void
663_button_inc_start_cb(void *data, 632_button_inc_dec_start_cb(void *data,
664 Evas_Object *obj, 633 Evas_Object *obj,
665 const char *emission EINA_UNUSED, 634 const char *emission,
666 const char *source EINA_UNUSED) 635 const char *source EINA_UNUSED)
667{ 636{
668 ELM_SPINNER_DATA_GET(data, sd); 637 ELM_SPINNER_DATA_GET(data, sd);
669 638
639 sd->inc_clicked = !strcmp(emission, "elm,action,increment,start")
640 ? EINA_TRUE : EINA_FALSE;
641
670 if (sd->entry_visible) 642 if (sd->entry_visible)
671 { 643 {
672 _entry_value_apply(obj); 644 _entry_value_apply(obj);
673 if ((sd->val_updated) && (sd->val == sd->val_min)) return; 645
646 if (sd->val_updated)
647 {
648 if (sd->inc_clicked)
649 {
650 if (sd->val == sd->val_min) return;
651 }
652 else
653 {
654 if (sd->val == sd->val_max) return;
655 }
656 }
674 } 657 }
675 658
676 ecore_timer_del(sd->longpress_timer); 659 ecore_timer_del(sd->longpress_timer);
677 sd->longpress_timer = ecore_timer_add 660 sd->longpress_timer = ecore_timer_add
678 (_elm_config->longpress_timeout, _val_inc_start, data); 661 (_elm_config->longpress_timeout, _val_inc_dec_start, data);
679} 662}
680 663
681static void 664static void
682_button_inc_stop_cb(void *data, 665_button_inc_dec_stop_cb(void *data,
683 Evas_Object *obj EINA_UNUSED, 666 Evas_Object *obj EINA_UNUSED,
684 const char *emission EINA_UNUSED, 667 const char *emission EINA_UNUSED,
685 const char *source EINA_UNUSED) 668 const char *source EINA_UNUSED)
@@ -689,44 +672,12 @@ _button_inc_stop_cb(void *data,
689 if (sd->longpress_timer) 672 if (sd->longpress_timer)
690 { 673 {
691 ELM_SAFE_FREE(sd->longpress_timer, ecore_timer_del); 674 ELM_SAFE_FREE(sd->longpress_timer, ecore_timer_del);
692 sd->spin_speed = sd->step;
693 _spin_value(data);
694 }
695
696 _spin_stop(data);
697}
698
699static void
700_button_dec_start_cb(void *data,
701 Evas_Object *obj EINA_UNUSED,
702 const char *emission EINA_UNUSED,
703 const char *source EINA_UNUSED)
704{
705 ELM_SPINNER_DATA_GET(data, sd);
706
707 if (sd->entry_visible)
708 {
709 _entry_value_apply(obj);
710 if ((sd->val_updated) && (sd->val == sd->val_max)) return;
711 }
712
713 ecore_timer_del(sd->longpress_timer);
714 sd->longpress_timer = ecore_timer_add
715 (_elm_config->longpress_timeout, _val_dec_start, data);
716}
717 675
718static void 676 if (sd->inc_clicked)
719_button_dec_stop_cb(void *data, 677 sd->spin_speed = sd->step;
720 Evas_Object *obj EINA_UNUSED, 678 else
721 const char *emission EINA_UNUSED, 679 sd->spin_speed = -sd->step;
722 const char *source EINA_UNUSED)
723{
724 ELM_SPINNER_DATA_GET(data, sd);
725 680
726 if (sd->longpress_timer)
727 {
728 ELM_SAFE_FREE(sd->longpress_timer, ecore_timer_del);
729 sd->spin_speed = -sd->step;
730 _spin_value(data); 681 _spin_value(data);
731 } 682 }
732 683
@@ -734,14 +685,14 @@ _button_dec_stop_cb(void *data,
734} 685}
735 686
736static Eina_Bool 687static Eina_Bool
737_inc_button_clicked_cb(void *data, 688_inc_dec_button_clicked_cb(void *data,
738 Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, 689 Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED,
739 void *event_info EINA_UNUSED) 690 void *event_info EINA_UNUSED)
740{ 691{
741 ELM_SPINNER_DATA_GET(data, sd); 692 ELM_SPINNER_DATA_GET(data, sd);
742 693
743 _spin_stop(data); 694 _spin_stop(data);
744 sd->spin_speed = sd->step; 695 sd->spin_speed = sd->inc_clicked ? sd->step : -sd->step;
745 _spin_value(data); 696 _spin_value(data);
746 697
747 if (sd->entry_visible) _entry_value_apply(data); 698 if (sd->entry_visible) _entry_value_apply(data);
@@ -752,16 +703,19 @@ _inc_button_clicked_cb(void *data,
752} 703}
753 704
754static Eina_Bool 705static Eina_Bool
755_inc_button_pressed_cb(void *data, 706_inc_dec_button_pressed_cb(void *data,
756 Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, 707 Eo *obj, const Eo_Event_Description *desc EINA_UNUSED,
757 void *event_info EINA_UNUSED) 708 void *event_info EINA_UNUSED)
758{ 709{
759 ELM_SPINNER_DATA_GET(data, sd); 710 ELM_SPINNER_DATA_GET(data, sd);
760 711
712 sd->inc_clicked = sd->inc_button == obj ? EINA_TRUE : EINA_FALSE;
713
761 if (sd->longpress_timer) ecore_timer_del(sd->longpress_timer); 714 if (sd->longpress_timer) ecore_timer_del(sd->longpress_timer);
715
762 sd->longpress_timer = ecore_timer_add 716 sd->longpress_timer = ecore_timer_add
763 (_elm_config->longpress_timeout, 717 (_elm_config->longpress_timeout,
764 _val_inc_start, data); 718 _val_inc_dec_start, data);
765 719
766 if (sd->entry_visible) _entry_value_apply(data); 720 if (sd->entry_visible) _entry_value_apply(data);
767 721
@@ -769,7 +723,7 @@ _inc_button_pressed_cb(void *data,
769} 723}
770 724
771static Eina_Bool 725static Eina_Bool
772_inc_button_unpressed_cb(void *data, 726_inc_dec_button_unpressed_cb(void *data,
773 Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, 727 Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED,
774 void *event_info EINA_UNUSED) 728 void *event_info EINA_UNUSED)
775{ 729{
@@ -797,60 +751,6 @@ _text_button_clicked_cb(void *data,
797} 751}
798 752
799static Eina_Bool 753static Eina_Bool
800_dec_button_clicked_cb(void *data,
801 Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED,
802 void *event_info EINA_UNUSED)
803{
804 ELM_SPINNER_DATA_GET(data, sd);
805
806 _spin_stop(data);
807 sd->spin_speed = -sd->step;
808 _spin_value(data);
809
810 if (sd->entry_visible) _entry_value_apply(data);
811
812 if (_elm_config->access_mode)
813 _access_increment_decrement_info_say(data, EINA_FALSE);
814
815 return EINA_TRUE;
816}
817
818static Eina_Bool
819_dec_button_pressed_cb(void *data,
820 Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED,
821 void *event_info EINA_UNUSED)
822{
823 ELM_SPINNER_DATA_GET(data, sd);
824
825 if (sd->longpress_timer) ecore_timer_del(sd->longpress_timer);
826 sd->longpress_timer = ecore_timer_add
827 (_elm_config->longpress_timeout,
828 _val_dec_start, data);
829
830 if (sd->entry_visible) _entry_value_apply(data);
831
832 return EINA_TRUE;
833}
834
835static Eina_Bool
836_dec_button_unpressed_cb(void *data,
837 Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED,
838 void *event_info EINA_UNUSED)
839{
840 ELM_SPINNER_DATA_GET(data, sd);
841
842 if (sd->longpress_timer)
843 {
844 ecore_timer_del(sd->longpress_timer);
845 sd->longpress_timer = NULL;
846 }
847
848 _spin_stop(data);
849
850 return EINA_TRUE;
851}
852
853static Eina_Bool
854_inc_dec_button_mouse_move_cb(void *data, Eo *obj EINA_UNUSED, 754_inc_dec_button_mouse_move_cb(void *data, Eo *obj EINA_UNUSED,
855 const Eo_Event_Description *desc EINA_UNUSED, 755 const Eo_Event_Description *desc EINA_UNUSED,
856 void *event_info) 756 void *event_info)
@@ -909,6 +809,7 @@ _access_activate_cb(void *data,
909 Eina_Strbuf *buf; 809 Eina_Strbuf *buf;
910 Evas_Object *eo, *inc_btn; 810 Evas_Object *eo, *inc_btn;
911 const char* increment_part; 811 const char* increment_part;
812 ELM_SPINNER_DATA_GET(data, sd);
912 813
913 if (!strncmp(elm_widget_style_get(data), "vertical", 8)) 814 if (!strncmp(elm_widget_style_get(data), "vertical", 8))
914 increment_part = "up_bt"; 815 increment_part = "up_bt";
@@ -920,14 +821,16 @@ _access_activate_cb(void *data,
920 821
921 if (part_obj != inc_btn) 822 if (part_obj != inc_btn)
922 { 823 {
923 _val_dec_start(data); 824 sd->inc_clicked = EINA_FALSE;
825 _val_inc_dec_start(data);
924 elm_layout_signal_emit(data, "elm,left,anim,activate", "elm"); 826 elm_layout_signal_emit(data, "elm,left,anim,activate", "elm");
925 _spin_stop(data); 827 _spin_stop(data);
926 text = "decremented"; 828 text = "decremented";
927 } 829 }
928 else 830 else
929 { 831 {
930 _val_inc_start(data); 832 sd->inc_clicked = EINA_TRUE;
833 _val_inc_dec_start(data);
931 elm_layout_signal_emit(data, "elm,right,anim,activate", "elm"); 834 elm_layout_signal_emit(data, "elm,right,anim,activate", "elm");
932 _spin_stop(data); 835 _spin_stop(data);
933 text = "incremented"; 836 text = "incremented";
@@ -1146,7 +1049,7 @@ _elm_spinner_evas_object_smart_add(Eo *obj, Elm_Spinner_Data *priv)
1146 elm_object_style_set(priv->inc_button, "spinner/increase/default"); 1049 elm_object_style_set(priv->inc_button, "spinner/increase/default");
1147 1050
1148 eo_do(priv->inc_button, 1051 eo_do(priv->inc_button,
1149 eo_event_callback_array_add(_inc_button_cb(), obj)); 1052 eo_event_callback_array_add(_inc_dec_button_cb(), obj));
1150 1053
1151 elm_layout_content_set(obj, "elm.swallow.inc_button", priv->inc_button); 1054 elm_layout_content_set(obj, "elm.swallow.inc_button", priv->inc_button);
1152 elm_widget_sub_object_add(obj, priv->inc_button); 1055 elm_widget_sub_object_add(obj, priv->inc_button);
@@ -1164,7 +1067,7 @@ _elm_spinner_evas_object_smart_add(Eo *obj, Elm_Spinner_Data *priv)
1164 elm_object_style_set(priv->dec_button, "spinner/decrease/default"); 1067 elm_object_style_set(priv->dec_button, "spinner/decrease/default");
1165 1068
1166 eo_do(priv->dec_button, 1069 eo_do(priv->dec_button,
1167 eo_event_callback_array_add(_dec_button_cb(), obj)); 1070 eo_event_callback_array_add(_inc_dec_button_cb(), obj));
1168 1071
1169 elm_layout_content_set(obj, "elm.swallow.dec_button", priv->dec_button); 1072 elm_layout_content_set(obj, "elm.swallow.dec_button", priv->dec_button);
1170 elm_widget_sub_object_add(obj, priv->dec_button); 1073 elm_widget_sub_object_add(obj, priv->dec_button);
@@ -1172,13 +1075,13 @@ _elm_spinner_evas_object_smart_add(Eo *obj, Elm_Spinner_Data *priv)
1172 else 1075 else
1173 { 1076 {
1174 elm_layout_signal_callback_add 1077 elm_layout_signal_callback_add
1175 (obj, "elm,action,increment,start", "*", _button_inc_start_cb, obj); 1078 (obj, "elm,action,increment,start", "*", _button_inc_dec_start_cb, obj);
1176 elm_layout_signal_callback_add 1079 elm_layout_signal_callback_add
1177 (obj, "elm,action,increment,stop", "*", _button_inc_stop_cb, obj); 1080 (obj, "elm,action,increment,stop", "*", _button_inc_dec_stop_cb, obj);
1178 elm_layout_signal_callback_add 1081 elm_layout_signal_callback_add
1179 (obj, "elm,action,decrement,start", "*", _button_dec_start_cb, obj); 1082 (obj, "elm,action,decrement,start", "*", _button_inc_dec_start_cb, obj);
1180 elm_layout_signal_callback_add 1083 elm_layout_signal_callback_add
1181 (obj, "elm,action,decrement,stop", "*", _button_dec_stop_cb, obj); 1084 (obj, "elm,action,decrement,stop", "*", _button_inc_dec_stop_cb, obj);
1182 } 1085 }
1183 1086
1184 edje_object_part_drag_value_set 1087 edje_object_part_drag_value_set
diff --git a/src/lib/elm_widget_spinner.h b/src/lib/elm_widget_spinner.h
index 4287eecc2..85af77511 100644
--- a/src/lib/elm_widget_spinner.h
+++ b/src/lib/elm_widget_spinner.h
@@ -48,6 +48,7 @@ struct _Elm_Spinner_Data
48 Eina_Bool wrap : 1; 48 Eina_Bool wrap : 1;
49 Eina_Bool val_updated : 1; 49 Eina_Bool val_updated : 1;
50 Eina_Bool button_layout : 1; 50 Eina_Bool button_layout : 1;
51 Eina_Bool inc_clicked : 1;
51}; 52};
52 53
53typedef struct _Elm_Spinner_Special_Value Elm_Spinner_Special_Value; 54typedef struct _Elm_Spinner_Special_Value Elm_Spinner_Special_Value;