summaryrefslogtreecommitdiff
path: root/src/lib/elementary/efl_ui_spin_button.c
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-07-05 17:35:06 +0200
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-07-08 19:56:34 +0200
commitf4f4856758ba3cccd01e49172945875f5e5b0613 (patch)
tree78f6703fb23b847200e26834f0a43efc2f2c372c /src/lib/elementary/efl_ui_spin_button.c
parente922a23ddf3fd19df3e1acec3e4575d4ff208ee7 (diff)
efl_ui_spin_button: replace timers with autorepeat of button
this was just reimplementing existing behaviour. This can be done more easily Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Differential Revision: https://phab.enlightenment.org/D9224
Diffstat (limited to 'src/lib/elementary/efl_ui_spin_button.c')
-rw-r--r--src/lib/elementary/efl_ui_spin_button.c86
1 files changed, 11 insertions, 75 deletions
diff --git a/src/lib/elementary/efl_ui_spin_button.c b/src/lib/elementary/efl_ui_spin_button.c
index a975df1..9d87aec 100644
--- a/src/lib/elementary/efl_ui_spin_button.c
+++ b/src/lib/elementary/efl_ui_spin_button.c
@@ -31,10 +31,6 @@ _inc_dec_button_clicked_cb(void *data, const Efl_Event *event);
31static void 31static void
32_inc_dec_button_pressed_cb(void *data, const Efl_Event *event); 32_inc_dec_button_pressed_cb(void *data, const Efl_Event *event);
33static void 33static void
34_inc_dec_button_unpressed_cb(void *data, const Efl_Event *event);
35static void
36_inc_dec_button_mouse_move_cb(void *data, const Efl_Event *event);
37static void
38_entry_activated_cb(void *data, const Efl_Event *event); 34_entry_activated_cb(void *data, const Efl_Event *event);
39static void 35static void
40_entry_focus_changed_cb(void *data, const Efl_Event *event); 36_entry_focus_changed_cb(void *data, const Efl_Event *event);
@@ -43,9 +39,8 @@ _access_increment_decrement_info_say(Evas_Object *obj, Eina_Bool is_incremented)
43 39
44EFL_CALLBACKS_ARRAY_DEFINE(_inc_dec_button_cb, 40EFL_CALLBACKS_ARRAY_DEFINE(_inc_dec_button_cb,
45 { EFL_UI_EVENT_CLICKED, _inc_dec_button_clicked_cb}, 41 { EFL_UI_EVENT_CLICKED, _inc_dec_button_clicked_cb},
46 { EFL_UI_EVENT_PRESSED, _inc_dec_button_pressed_cb}, 42 { EFL_UI_AUTOREPEAT_EVENT_REPEATED, _inc_dec_button_clicked_cb},
47 { EFL_UI_EVENT_UNPRESSED, _inc_dec_button_unpressed_cb}, 43 { EFL_UI_EVENT_PRESSED, _inc_dec_button_pressed_cb}
48 { EFL_EVENT_POINTER_MOVE, _inc_dec_button_mouse_move_cb }
49 ); 44 );
50 45
51static void 46static void
@@ -417,37 +412,10 @@ _spin_value(void *data)
417} 412}
418 413
419static void 414static void
420_spin_stop(Evas_Object *obj)
421{
422 Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(obj, MY_CLASS);
423
424 ELM_SAFE_FREE(sd->spin_timer, ecore_timer_del);
425
426 elm_widget_scroll_freeze_pop(obj);
427}
428
429static Eina_Bool
430_inc_dec_button_press_start(void *data)
431{
432 Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(data, MY_CLASS);
433
434 sd->interval = sd->first_interval;
435 sd->longpress_timer = NULL;
436 ecore_timer_del(sd->spin_timer);
437 sd->spin_timer = ecore_timer_add(sd->interval, _spin_value, data);
438 _spin_value(data);
439
440 elm_widget_scroll_freeze_push(data);
441
442 return ECORE_CALLBACK_CANCEL;
443}
444
445static void
446_inc_dec_button_clicked_cb(void *data, const Efl_Event *event) 415_inc_dec_button_clicked_cb(void *data, const Efl_Event *event)
447{ 416{
448 Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(data, MY_CLASS); 417 Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(data, MY_CLASS);
449 418
450 _spin_stop(data);
451 sd->inc_val = sd->inc_button == event->object ? EINA_TRUE : EINA_FALSE; 419 sd->inc_val = sd->inc_button == event->object ? EINA_TRUE : EINA_FALSE;
452 _spin_value(data); 420 _spin_value(data);
453 421
@@ -463,43 +431,10 @@ _inc_dec_button_pressed_cb(void *data, const Efl_Event *event)
463 431
464 sd->inc_val = sd->inc_button == event->object ? EINA_TRUE : EINA_FALSE; 432 sd->inc_val = sd->inc_button == event->object ? EINA_TRUE : EINA_FALSE;
465 433
466 if (sd->longpress_timer) ecore_timer_del(sd->longpress_timer);
467
468 sd->longpress_timer = ecore_timer_add
469 (_elm_config->longpress_timeout,
470 _inc_dec_button_press_start, data);
471
472 if (sd->entry_visible) _entry_value_apply(data); 434 if (sd->entry_visible) _entry_value_apply(data);
473} 435}
474 436
475static void 437static void
476_inc_dec_button_unpressed_cb(void *data, const Efl_Event *event EINA_UNUSED)
477{
478 Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(data, MY_CLASS);
479
480 if (sd->longpress_timer)
481 {
482 ecore_timer_del(sd->longpress_timer);
483 sd->longpress_timer = NULL;
484 }
485
486 _spin_stop(data);
487}
488
489static void
490_inc_dec_button_mouse_move_cb(void *data, const Efl_Event *event)
491{
492 Efl_Input_Pointer *ev = event->info;
493 Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(data, MY_CLASS);
494
495 if (efl_input_processed_get(ev) && sd->longpress_timer)
496 {
497 ecore_timer_del(sd->longpress_timer);
498 sd->longpress_timer = NULL;
499 }
500}
501
502static void
503_text_button_focus_changed_cb(void *data, const Efl_Event *event) 438_text_button_focus_changed_cb(void *data, const Efl_Event *event)
504{ 439{
505 if (efl_ui_focus_object_focus_get(event->object)) 440 if (efl_ui_focus_object_focus_get(event->object))
@@ -533,8 +468,7 @@ _key_action_toggle(Evas_Object *obj, const char *params EINA_UNUSED)
533{ 468{
534 Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(obj, MY_CLASS); 469 Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(obj, MY_CLASS);
535 470
536 if (sd->spin_timer) _spin_stop(obj); 471 if (sd->entry_visible) _entry_toggle_cb(NULL, obj, NULL, NULL);
537 else if (sd->entry_visible) _entry_toggle_cb(NULL, obj, NULL, NULL);
538 472
539 return EINA_FALSE; 473 return EINA_FALSE;
540} 474}
@@ -547,13 +481,11 @@ _efl_ui_spin_button_efl_ui_widget_widget_input_event_handler(Eo *obj, Efl_Ui_Spi
547 if (efl_input_processed_get(ev)) return EINA_FALSE; 481 if (efl_input_processed_get(ev)) return EINA_FALSE;
548 if (eo_event->desc == EFL_EVENT_KEY_DOWN) 482 if (eo_event->desc == EFL_EVENT_KEY_DOWN)
549 { 483 {
550 if (sd->spin_timer) _spin_stop(obj); 484 return EINA_FALSE;
551 else return EINA_FALSE;
552 } 485 }
553 else if (eo_event->desc == EFL_EVENT_KEY_UP) 486 else if (eo_event->desc == EFL_EVENT_KEY_UP)
554 { 487 {
555 if (sd->spin_timer) _spin_stop(obj); 488 return EINA_FALSE;
556 else return EINA_FALSE;
557 } 489 }
558 else if (eo_event->desc == EFL_EVENT_POINTER_WHEEL) 490 else if (eo_event->desc == EFL_EVENT_POINTER_WHEEL)
559 { 491 {
@@ -582,8 +514,6 @@ _efl_ui_spin_button_efl_ui_focus_object_on_focus_update(Eo *obj, Efl_Ui_Spin_But
582 if (!efl_ui_focus_object_focus_get(obj)) 514 if (!efl_ui_focus_object_focus_get(obj))
583 { 515 {
584 ELM_SAFE_FREE(sd->delay_change_timer, ecore_timer_del); 516 ELM_SAFE_FREE(sd->delay_change_timer, ecore_timer_del);
585 ELM_SAFE_FREE(sd->spin_timer, ecore_timer_del);
586 ELM_SAFE_FREE(sd->longpress_timer, ecore_timer_del);
587 } 517 }
588 else 518 else
589 { 519 {
@@ -830,6 +760,9 @@ _efl_ui_spin_button_efl_object_constructor(Eo *obj, Efl_Ui_Spin_Button_Data *sd)
830 sd->first_interval = 0.85; 760 sd->first_interval = 0.85;
831 761
832 sd->inc_button = efl_add(EFL_UI_BUTTON_CLASS, obj, 762 sd->inc_button = efl_add(EFL_UI_BUTTON_CLASS, obj,
763 efl_ui_autorepeat_enabled_set(efl_added, EINA_TRUE),
764 efl_ui_autorepeat_initial_timeout_set(efl_added, _elm_config->longpress_timeout),
765 efl_ui_autorepeat_gap_timeout_set(efl_added, sd->first_interval),
833 elm_widget_element_update(obj, efl_added, PART_NAME_INC_BUTTON), 766 elm_widget_element_update(obj, efl_added, PART_NAME_INC_BUTTON),
834 efl_event_callback_array_add(efl_added, _inc_dec_button_cb(), obj), 767 efl_event_callback_array_add(efl_added, _inc_dec_button_cb(), obj),
835 efl_content_set(efl_part(obj, "efl.inc_button"), efl_added)); 768 efl_content_set(efl_part(obj, "efl.inc_button"), efl_added));
@@ -843,6 +776,9 @@ _efl_ui_spin_button_efl_object_constructor(Eo *obj, Efl_Ui_Spin_Button_Data *sd)
843 efl_content_set(efl_part(obj, "efl.text_button"), efl_added)); 776 efl_content_set(efl_part(obj, "efl.text_button"), efl_added));
844 777
845 sd->dec_button = efl_add(EFL_UI_BUTTON_CLASS, obj, 778 sd->dec_button = efl_add(EFL_UI_BUTTON_CLASS, obj,
779 efl_ui_autorepeat_enabled_set(efl_added, EINA_TRUE),
780 efl_ui_autorepeat_initial_timeout_set(efl_added, _elm_config->longpress_timeout),
781 efl_ui_autorepeat_gap_timeout_set(efl_added, sd->first_interval),
846 elm_widget_element_update(obj, efl_added, PART_NAME_DEC_BUTTON), 782 elm_widget_element_update(obj, efl_added, PART_NAME_DEC_BUTTON),
847 efl_event_callback_array_add(efl_added, _inc_dec_button_cb(), obj), 783 efl_event_callback_array_add(efl_added, _inc_dec_button_cb(), obj),
848 efl_content_set(efl_part(obj, "efl.dec_button"), efl_added)); 784 efl_content_set(efl_part(obj, "efl.dec_button"), efl_added));