summaryrefslogtreecommitdiff
path: root/src/lib/elementary/efl_ui_spin_button.c
blob: 2a37bce4791501fb5092c6dd33622349ab602d66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#define EFL_ACCESS_OBJECT_PROTECTED
#define EFL_ACCESS_VALUE_PROTECTED
#define EFL_ACCESS_WIDGET_ACTION_PROTECTED
#define EFL_UI_FOCUS_COMPOSITION_PROTECTED

#include <Elementary.h>

#include "elm_priv.h"
#include "efl_ui_spin_button_private.h"
#include "efl_ui_spin_private.h"
#include "elm_entry.eo.h"

#define MY_CLASS EFL_UI_SPIN_BUTTON_CLASS

#define MY_CLASS_NAME "Efl.Ui.Spin_Button"

#define EFL_UI_SPIN_BUTTON_DELAY_CHANGE_TIME 0.2

static const char PART_NAME_ENTRY[] = "entry";
static const char PART_NAME_DEC_BUTTON[] = "dec_button";
static const char PART_NAME_TEXT_BUTTON[] = "text_button";
static const char PART_NAME_INC_BUTTON[] = "inc_button";

static void
_inc_dec_button_clicked_cb(void *data, const Efl_Event *event);
static void
_inc_dec_button_pressed_cb(void *data, const Efl_Event *event);
static void
_inc_dec_button_unpressed_cb(void *data, const Efl_Event *event);
static void
_inc_dec_button_mouse_move_cb(void *data, const Efl_Event *event);
static void
_entry_activated_cb(void *data, const Efl_Event *event);
static void
_entry_focus_changed_cb(void *data, const Efl_Event *event);
static void
_access_increment_decrement_info_say(Evas_Object *obj, Eina_Bool is_incremented);

EFL_CALLBACKS_ARRAY_DEFINE(_inc_dec_button_cb,
                           { EFL_UI_EVENT_CLICKED, _inc_dec_button_clicked_cb},
                           { EFL_UI_EVENT_PRESSED, _inc_dec_button_pressed_cb},
                           { EFL_UI_EVENT_UNPRESSED, _inc_dec_button_unpressed_cb},
                           { EFL_EVENT_POINTER_MOVE, _inc_dec_button_mouse_move_cb }
                          );

static void
_entry_show(Evas_Object *obj)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(obj, MY_CLASS);
   Efl_Ui_Spin_Data *pd = efl_data_scope_get(obj, EFL_UI_SPIN_CLASS);
   char buf[32], fmt[32] = "%0.f";

   /* try to construct just the format from given label
    * completely ignoring pre/post words
    */
   if (pd->templates)
     {
        const char *start = strchr(pd->templates, '%');
        while (start)
          {
             /* handle %% */
             if (start[1] != '%')
               break;
             else
               start = strchr(start + 2, '%');
          }

        if (start)
          {
             const char *itr, *end = NULL;
             for (itr = start + 1; *itr != '\0'; itr++)
               {
                  if ((*itr == 'd') || (*itr == 'u') || (*itr == 'i') || (*itr == 'o') ||
                      (*itr == 'x') || (*itr == 'X') || (*itr == 'f') || (*itr == 'F'))
                    {
                       end = itr + 1;
                       break;
                    }
               }

             if ((end) && ((size_t)(end - start + 1) < sizeof(fmt)))
               {
                  memcpy(fmt, start, end - start);
                  fmt[end - start] = '\0';
               }
          }
     }

   if (pd->format_type == SPIN_FORMAT_INT)
     snprintf(buf, sizeof(buf), fmt, (int)pd->val);
   else
     snprintf(buf, sizeof(buf), fmt, pd->val);

   elm_object_text_set(sd->ent, buf);
}

static void
_label_write(Evas_Object *obj)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(obj, MY_CLASS);

   Efl_Ui_Spin_Data *pd = efl_data_scope_get(obj, EFL_UI_SPIN_CLASS);

   if (pd->templates)
     {
        efl_text_set(sd->text_button, pd->templates);
     }
   else
     {
        char buf[1024];

        snprintf(buf, sizeof(buf), "%.0f", pd->val);
        efl_text_set(sd->text_button, buf);
     }
}

static Eina_Bool
_delay_change_timer_cb(void *data)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(data, MY_CLASS);

   sd->delay_change_timer = NULL;
   efl_event_callback_call(data, EFL_UI_SPIN_BUTTON_EVENT_DELAY_CHANGED, NULL);

   return ECORE_CALLBACK_CANCEL;
}

static Eina_Bool
_value_set(Evas_Object *obj,
           double new_val)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(obj, MY_CLASS);
   Efl_Ui_Spin_Data *pd = efl_data_scope_get(obj, EFL_UI_SPIN_CLASS);

   if (sd->circulate)
     {
        if (new_val < pd->val_min)
          new_val = pd->val_max;
        else if (new_val > pd->val_max)
          new_val = pd->val_min;
     }

   efl_ui_range_value_set(obj, new_val);
   ecore_timer_del(sd->delay_change_timer);
   sd->delay_change_timer = ecore_timer_add(EFL_UI_SPIN_BUTTON_DELAY_CHANGE_TIME,
                                            _delay_change_timer_cb, obj);

   return EINA_TRUE;
}

static void
_entry_hide(Evas_Object *obj)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(obj, MY_CLASS);

   elm_layout_signal_emit(obj, "elm,state,button,active", "elm");
   elm_layout_signal_emit(obj, "elm,state,entry,inactive", "elm");

   if (sd->entry_visible && !evas_focus_state_get(evas_object_evas_get(obj)))
     sd->entry_reactivate = EINA_TRUE;

   sd->entry_visible = EINA_FALSE;
}

static void
_entry_value_apply(Evas_Object *obj)
{
   const char *str;
   double val;
   char *end;

   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(obj, MY_CLASS);
   Efl_Ui_Spin_Data *pd = efl_data_scope_get(obj, EFL_UI_SPIN_CLASS);

   if (!sd->entry_visible) return;

   efl_event_callback_del(sd->ent, EFL_UI_FOCUS_OBJECT_EVENT_FOCUS_CHANGED,
                          _entry_focus_changed_cb, obj);
   _entry_hide(obj);
   str = elm_object_text_get(sd->ent);
   if (!str) return;

   val = strtod(str, &end);
   if (((*end != '\0') && (!isspace(*end))) || (fabs(val - pd->val) < DBL_EPSILON)) return;
   efl_ui_range_value_set(obj, val);

   efl_event_callback_call(obj, EFL_UI_SPIN_EVENT_CHANGED, NULL);
   ecore_timer_del(sd->delay_change_timer);
   sd->delay_change_timer = ecore_timer_add(EFL_UI_SPIN_BUTTON_DELAY_CHANGE_TIME,
                                            _delay_change_timer_cb, obj);
}

static void
_invalid_input_validity_filter(void *data EINA_UNUSED, Evas_Object *obj, char **text)
{
   char *insert = NULL;
   const char *str = NULL;
   int cursor_pos = 0;
   int read_idx = 0, read_char, cmp_char;

   EINA_SAFETY_ON_NULL_RETURN(obj);
   EINA_SAFETY_ON_NULL_RETURN(text);

   insert = *text;
   str = elm_object_text_get(obj);

   evas_string_char_next_get(*text, 0, &read_char);
   cursor_pos = elm_entry_cursor_pos_get(obj);
   if (read_char)
     {
       if (read_char == '-')
         {
            if (cursor_pos != 0)
              {
                 goto invalid_input;
              }
         }
       if (read_char == '.')
         {
            read_idx = evas_string_char_next_get(str, 0, &cmp_char);
            while (cmp_char)
              {
                 if (read_char == cmp_char)
                   {
                      goto invalid_input;
                   }
                 read_idx = evas_string_char_next_get(str, read_idx, &cmp_char);
               }
         }
       read_idx = evas_string_char_next_get(str, 0, &cmp_char);
       if ((cmp_char == '-') && (cursor_pos == 0))
         {
            goto invalid_input;
         }
     }
   return;

invalid_input:
   *insert = 0;
}

static void
_entry_accept_filter_add(Evas_Object *obj)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(obj, MY_CLASS);
   Efl_Ui_Spin_Data *pd = efl_data_scope_get(obj, EFL_UI_SPIN_CLASS);
   static Elm_Entry_Filter_Accept_Set digits_filter_data;

   if (!sd->ent) return;

   elm_entry_markup_filter_remove(sd->ent, elm_entry_filter_accept_set, &digits_filter_data);

   if (pd->decimal_points > 0)
     digits_filter_data.accepted = "-.0123456789";
   else
     digits_filter_data.accepted = "-0123456789";

   elm_entry_markup_filter_prepend(sd->ent, elm_entry_filter_accept_set, &digits_filter_data);
}

static char *
_text_insert(const char *text, const char *input, int pos)
{
   char *result = NULL;
   int text_len, input_len;

   text_len = evas_string_char_len_get(text);
   input_len = evas_string_char_len_get(input);
   result = (char *)calloc(text_len + input_len + 1, sizeof(char));
   if (!result) return NULL;

   strncpy(result, text, pos);
   strcpy(result + pos, input);
   strcpy(result + pos + input_len, text + pos);

   return result;
}

static void
_min_max_validity_filter(void *data, Evas_Object *obj, char **text)
{
   const char *str, *point;
   char *insert, *new_str = NULL;
   double val;
   int max_len = 0, len;

   EINA_SAFETY_ON_NULL_RETURN(data);
   EINA_SAFETY_ON_NULL_RETURN(obj);
   EINA_SAFETY_ON_NULL_RETURN(text);

   Efl_Ui_Spin_Data *pd = efl_data_scope_get(data, EFL_UI_SPIN_CLASS);

   str = elm_object_text_get(obj);
   if (!str) return;

   insert = *text;
   new_str = _text_insert(str, insert, elm_entry_cursor_pos_get(obj));
   if (!new_str) return;
   if (strchr(new_str, '-')) max_len++;

   if (pd->format_type == SPIN_FORMAT_FLOAT)
     {
        point = strchr(new_str, '.');
        if (point)
          {
             if ((int) strlen(point + 1) > pd->decimal_points)
               {
                  *insert = 0;
                  goto end;
               }
          }
     }

   max_len += (fabs(pd->val_max) > fabs(pd->val_min)) ?
              (log10(fabs(pd->val_max)) + 1) : (log10(fabs(pd->val_min)) + 1);
   len = strlen(new_str);
   if (len < max_len) goto end;

   val = strtod(new_str, NULL);
   if ((val < pd->val_min) || (val > pd->val_max))
     *insert = 0;

end:
   free(new_str);
}

static void
_entry_show_cb(void *data,
               Evas *e EINA_UNUSED,
               Evas_Object *obj,
               void *event_info EINA_UNUSED)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(data, MY_CLASS);

   _entry_show(data);
   elm_object_focus_set(obj, EINA_TRUE);
   elm_entry_select_all(obj);
   sd->entry_visible = EINA_TRUE;
   elm_layout_signal_emit(data, "elm,state,button,inactive", "elm");
}

static void
_toggle_entry(Evas_Object *obj)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(obj, MY_CLASS);

   if (elm_widget_disabled_get(obj)) return;
   if (!sd->editable) return;
   if (sd->entry_visible) _entry_value_apply(obj);
   else
     {
        if (!sd->ent)
          {
             //FIXME: elm_entry will be changed to efl_ui_text after
             //       filter feature implemented.
             //       (Current efl_ui_text has missed filter feature.)
             sd->ent = elm_entry_add(obj);
             Eina_Strbuf *buf = eina_strbuf_new();
             eina_strbuf_append_printf(buf, "spinner/%s", elm_widget_style_get(obj));
             elm_widget_style_set(sd->ent, eina_strbuf_string_get(buf));
             eina_strbuf_free(buf);
             evas_object_event_callback_add
               (sd->ent, EVAS_CALLBACK_SHOW, _entry_show_cb, obj);
             elm_entry_single_line_set(sd->ent, EINA_TRUE);
             elm_layout_content_set(obj, "efl.entry", sd->ent);
             _entry_accept_filter_add(obj);
             elm_entry_markup_filter_append(sd->ent, _invalid_input_validity_filter, NULL);
             if (_elm_config->spinner_min_max_filter_enable)
               elm_entry_markup_filter_append(sd->ent, _min_max_validity_filter, obj);
             efl_event_callback_add(sd->ent, ELM_ENTRY_EVENT_ACTIVATED,
                                    _entry_activated_cb, obj);
          }

        efl_event_callback_add(sd->ent, EFL_UI_FOCUS_OBJECT_EVENT_FOCUS_CHANGED,
                               _entry_focus_changed_cb, obj);
        sd->entry_visible = EINA_TRUE;
        elm_layout_signal_emit(obj, "elm,state,entry,active", "elm");
        {
           Eina_List *items = NULL;

           items = eina_list_append(items, sd->dec_button);
           items = eina_list_append(items, sd->text_button);
           items = eina_list_append(items, sd->ent);
           items = eina_list_append(items, sd->inc_button);

           efl_ui_focus_composition_elements_set(obj, items);
        }
     }
}

static void
_entry_toggle_cb(void *data EINA_UNUSED,
                 Evas_Object *obj,
                 const char *emission EINA_UNUSED,
                 const char *source EINA_UNUSED)
{
   _toggle_entry(obj);
}

static Eina_Bool
_spin_value(void *data)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(data, MY_CLASS);
   Efl_Ui_Spin_Data *pd = efl_data_scope_get(data, EFL_UI_SPIN_CLASS);

   if (_value_set(data, pd->val + (sd->inc_val ? pd->step : -pd->step)))
     _label_write(data);

   return ECORE_CALLBACK_RENEW;
}

static void
_spin_stop(Evas_Object *obj)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(obj, MY_CLASS);

   ELM_SAFE_FREE(sd->spin_timer, ecore_timer_del);

   elm_widget_scroll_freeze_pop(obj);
}

static Eina_Bool
_inc_dec_button_press_start(void *data)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(data, MY_CLASS);

   sd->interval = sd->first_interval;
   sd->longpress_timer = NULL;
   ecore_timer_del(sd->spin_timer);
   sd->spin_timer = ecore_timer_add(sd->interval, _spin_value, data);
   _spin_value(data);

   elm_widget_scroll_freeze_push(data);

   return ECORE_CALLBACK_CANCEL;
}

static void
_inc_dec_button_clicked_cb(void *data, const Efl_Event *event)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(data, MY_CLASS);

   _spin_stop(data);
   sd->inc_val = sd->inc_button == event->object ? EINA_TRUE : EINA_FALSE;
   _spin_value(data);

   if (_elm_config->access_mode)
     _access_increment_decrement_info_say(data, EINA_TRUE);
}


static void
_inc_dec_button_pressed_cb(void *data, const Efl_Event *event)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(data, MY_CLASS);

   sd->inc_val = sd->inc_button == event->object ? EINA_TRUE : EINA_FALSE;

   if (sd->longpress_timer) ecore_timer_del(sd->longpress_timer);

   sd->longpress_timer = ecore_timer_add
                           (_elm_config->longpress_timeout,
                            _inc_dec_button_press_start, data);

   if (sd->entry_visible) _entry_value_apply(data);
}

static void
_inc_dec_button_unpressed_cb(void *data, const Efl_Event *event EINA_UNUSED)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(data, MY_CLASS);

   if (sd->longpress_timer)
     {
        ecore_timer_del(sd->longpress_timer);
        sd->longpress_timer = NULL;
     }

   _spin_stop(data);
}

static void
_inc_dec_button_mouse_move_cb(void *data, const Efl_Event *event)
{
   Efl_Input_Pointer *ev = event->info;
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(data, MY_CLASS);

   if (efl_input_processed_get(ev) && sd->longpress_timer)
     {
        ecore_timer_del(sd->longpress_timer);
        sd->longpress_timer = NULL;
     }
}

static void
_text_button_focus_changed_cb(void *data, const Efl_Event *event)
{
   if (efl_ui_focus_object_focus_get(event->object))
     _toggle_entry(data);
}

static void
_entry_activated_cb(void *data, const Efl_Event *event EINA_UNUSED)
{
   _toggle_entry(data);
}

static void
_entry_focus_changed_cb(void *data, const Efl_Event *event)
{
   if (!efl_ui_focus_object_focus_get(event->object))
     _toggle_entry(data);
}

static void
_text_button_clicked_cb(void *data, const Efl_Event *event EINA_UNUSED)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(data, MY_CLASS);

   if (sd->entry_visible) return;
   _toggle_entry(data);
}

static Eina_Bool
_key_action_toggle(Evas_Object *obj, const char *params EINA_UNUSED)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(obj, MY_CLASS);

   if (sd->spin_timer) _spin_stop(obj);
   else if (sd->entry_visible) _entry_toggle_cb(NULL, obj, NULL, NULL);

   return EINA_FALSE;
}

EOLIAN static Eina_Bool
_efl_ui_spin_button_efl_ui_widget_widget_event(Eo *obj, Efl_Ui_Spin_Button_Data *sd EINA_UNUSED, const Efl_Event *eo_event, Evas_Object *src EINA_UNUSED)
{
   Eo *ev = eo_event->info;

   if (efl_input_processed_get(ev)) return EINA_FALSE;
   if (eo_event->desc == EFL_EVENT_KEY_DOWN)
     {
        if (sd->spin_timer) _spin_stop(obj);
        else return EINA_FALSE;
     }
   else if (eo_event->desc == EFL_EVENT_KEY_UP)
     {
        if (sd->spin_timer) _spin_stop(obj);
        else return EINA_FALSE;
     }
   else if (eo_event->desc == EFL_EVENT_POINTER_WHEEL)
     {
        sd->interval = sd->first_interval;
        if (efl_input_pointer_wheel_delta_get(ev) < 0)
          sd->inc_val = EINA_TRUE;
        else
          sd->inc_val = EINA_FALSE;

	    _spin_value(obj);
     }
   else return EINA_FALSE;

   efl_input_processed_set(ev, EINA_TRUE);
   return EINA_TRUE;
}

EOLIAN static Eina_Bool
_efl_ui_spin_button_efl_ui_focus_object_on_focus_update(Eo *obj, Efl_Ui_Spin_Button_Data *sd)
{
   Eina_Bool int_ret = EINA_FALSE;

   int_ret = efl_ui_focus_object_on_focus_update(efl_super(obj, MY_CLASS));
   if (!int_ret) return EINA_FALSE;

   if (!efl_ui_focus_object_focus_get(obj))
     {
        ELM_SAFE_FREE(sd->delay_change_timer, ecore_timer_del);
        ELM_SAFE_FREE(sd->spin_timer, ecore_timer_del);
        ELM_SAFE_FREE(sd->longpress_timer, ecore_timer_del);
     }
   else
     {
        if (sd->entry_reactivate)
          {
             _toggle_entry(obj);

             sd->entry_reactivate = EINA_FALSE;
          }
     }

   return EINA_TRUE;
}

EOLIAN static void
_efl_ui_spin_button_elm_layout_sizing_eval(Eo *obj, Efl_Ui_Spin_Button_Data *_pd EINA_UNUSED)
{
   Evas_Coord minw = -1, minh = -1;
   ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);

   elm_coords_finger_size_adjust(1, &minw, 1, &minh);
   edje_object_size_min_restricted_calc
     (wd->resize_obj, &minw, &minh, minw, minh);
   elm_coords_finger_size_adjust(1, &minw, 1, &minh);
   evas_object_size_hint_min_set(obj, minw, minh);
   evas_object_size_hint_max_set(obj, -1, -1);
}

static char *
_access_info_cb(void *data, Evas_Object *obj EINA_UNUSED)
{
   const char *txt = NULL;
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(data, MY_CLASS);

   if (sd->entry_visible)
     txt = elm_object_text_get(sd->ent);
   else
	 txt = efl_text_get(sd->text_button);

   if (txt) return strdup(txt);

   return NULL;
}

static char *
_access_state_cb(void *data, Evas_Object *obj EINA_UNUSED)
{
   if (elm_widget_disabled_get(data))
     return strdup(E_("State: Disabled"));

   return NULL;
}

static void
_access_activate_spin_button_cb(void *data,
                            Evas_Object *part_obj EINA_UNUSED,
                            Elm_Object_Item *item EINA_UNUSED)
{
   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(data, MY_CLASS);

   if (elm_widget_disabled_get(data)) return;
   if (!sd->entry_visible)
     _toggle_entry(data);
}

static void
_access_increment_decrement_info_say(Evas_Object *obj,
                                     Eina_Bool is_incremented)
{
   Eina_Strbuf *buf;

   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(obj, MY_CLASS);

   buf = eina_strbuf_new();
   if (is_incremented)
     {
        elm_object_signal_emit
           (sd->inc_button, "elm,action,anim,activate", "elm");
        eina_strbuf_append(buf, E_("incremented"));
     }
   else
     {
        elm_object_signal_emit
           (sd->dec_button, "elm,action,anim,activate", "elm");
        eina_strbuf_append(buf, E_("decremented"));
     }

   eina_strbuf_append_printf
      (buf, "%s", elm_object_text_get(sd->text_button));

   _elm_access_say(eina_strbuf_string_get(buf));
   eina_strbuf_free(buf);
}

static void
_access_spinner_register(Evas_Object *obj, Eina_Bool is_access)
{
   Evas_Object *ao;
   Elm_Access_Info *ai;

   Efl_Ui_Spin_Button_Data *sd = efl_data_scope_get(obj, MY_CLASS);

   if (!is_access)
     {
        /* unregister access */
        _elm_access_edje_object_part_object_unregister
           (obj, elm_layout_edje_get(obj), "access");
        elm_layout_signal_emit(obj, "elm,state,access,inactive", "elm");
        return;
     }
   elm_layout_signal_emit(obj, "elm,state,access,active", "elm");
   ao = _elm_access_edje_object_part_object_register
      (obj, elm_layout_edje_get(obj), "access");

   ai = _elm_access_info_get(ao);
   _elm_access_text_set(ai, ELM_ACCESS_TYPE, E_("spinner"));
   _elm_access_callback_set(ai, ELM_ACCESS_STATE, _access_state_cb, obj);
   _elm_access_activate_callback_set(ai, _access_activate_spin_button_cb, obj);

   /*Do not register spinner buttons if widget is disabled*/
   if (!elm_widget_disabled_get(obj))
     {
        ai = _elm_access_info_get(sd->inc_button);
        _elm_access_text_set(ai, ELM_ACCESS_TYPE,
                             E_("spinner increment button"));
        ai = _elm_access_info_get(sd->dec_button);
        _elm_access_text_set(ai, ELM_ACCESS_TYPE,
                             E_("spinner decrement button"));
        ai = _elm_access_info_get(sd->text_button);
        _elm_access_text_set(ai, ELM_ACCESS_TYPE, E_("spinner text"));
        _elm_access_callback_set(ai, ELM_ACCESS_INFO, _access_info_cb, obj);
     }
}

EOLIAN static Efl_Ui_Theme_Apply
_efl_ui_spin_button_efl_ui_widget_theme_apply(Eo *obj, Efl_Ui_Spin_Button_Data *sd EINA_UNUSED)
{
   Efl_Ui_Theme_Apply int_ret = EFL_UI_THEME_APPLY_FAILED;

   int_ret = efl_ui_widget_theme_apply(efl_super(obj, MY_CLASS));
   if (!int_ret) return EFL_UI_THEME_APPLY_FAILED;

   if (sd->ent)
     elm_widget_element_update(obj, sd->ent, PART_NAME_ENTRY);

   if (sd->inc_button)
     elm_widget_element_update(obj, sd->inc_button, PART_NAME_INC_BUTTON);

   if (sd->text_button)
     elm_widget_element_update(obj, sd->text_button, PART_NAME_TEXT_BUTTON);

   if (sd->dec_button)
     elm_widget_element_update(obj, sd->dec_button, PART_NAME_DEC_BUTTON);

   if (_elm_config->access_mode)
     _access_spinner_register(obj, EINA_TRUE);

   _label_write(obj);
   elm_layout_sizing_eval(obj);
   return EFL_UI_THEME_APPLY_SUCCESS;
}

EOLIAN static Eo *
_efl_ui_spin_button_efl_object_constructor(Eo *obj, Efl_Ui_Spin_Button_Data *sd)
{
   if (!elm_widget_theme_klass_get(obj))
     elm_widget_theme_klass_set(obj, "spin_button");
   obj = efl_constructor(efl_super(obj, MY_CLASS));

   elm_widget_sub_object_parent_add(obj);

   sd->first_interval = 0.85;

   sd->inc_button = efl_add(EFL_UI_BUTTON_CLASS, obj,
                            elm_widget_element_update(obj, efl_added, PART_NAME_INC_BUTTON),
                            efl_event_callback_array_add(efl_added, _inc_dec_button_cb(), obj),
                            efl_content_set(efl_part(obj, "efl.inc_button"), efl_added));

   sd->text_button = efl_add(EFL_UI_BUTTON_CLASS, obj,
                             elm_widget_element_update(obj, efl_added, PART_NAME_TEXT_BUTTON),
                             efl_event_callback_add(efl_added, EFL_UI_EVENT_CLICKED,
                                                    _text_button_clicked_cb, obj),
                             efl_event_callback_add(efl_added, EFL_UI_FOCUS_OBJECT_EVENT_FOCUS_CHANGED,
                                                    _text_button_focus_changed_cb, obj),
                             efl_content_set(efl_part(obj, "efl.text_button"), efl_added));

   sd->dec_button = efl_add(EFL_UI_BUTTON_CLASS, obj,
                            elm_widget_element_update(obj, efl_added, PART_NAME_DEC_BUTTON),
                            efl_event_callback_array_add(efl_added, _inc_dec_button_cb(), obj),
                            efl_content_set(efl_part(obj, "efl.dec_button"), efl_added));

     {
        Eina_List *items = NULL;

        items = eina_list_append(items, sd->dec_button);
        items = eina_list_append(items, sd->text_button);
        items = eina_list_append(items, sd->inc_button);

        efl_ui_focus_composition_elements_set(obj, items);
     }

   elm_layout_signal_callback_add
      (obj, "elm,action,entry,toggle", "*", _entry_toggle_cb, NULL);

   elm_widget_can_focus_set(obj, EINA_TRUE);

   efl_access_object_role_set(obj, EFL_ACCESS_ROLE_SPIN_BUTTON);

   return obj;
}

EOLIAN static void
_efl_ui_spin_button_efl_ui_range_range_value_set(Eo *obj, Efl_Ui_Spin_Button_Data *sd EINA_UNUSED, double val)
{
   efl_ui_range_value_set(efl_super(obj, MY_CLASS), val);

   _label_write(obj);
}

EOLIAN static void
_efl_ui_spin_button_editable_set(Eo *obj EINA_UNUSED, Efl_Ui_Spin_Button_Data *sd, Eina_Bool editable)
{
   sd->editable = editable;
}

EOLIAN static Eina_Bool
_efl_ui_spin_button_editable_get(const Eo *obj EINA_UNUSED, Efl_Ui_Spin_Button_Data *sd)
{
   return sd->editable;
}

EOLIAN static void
_efl_ui_spin_button_circulate_set(Eo *obj EINA_UNUSED, Efl_Ui_Spin_Button_Data *sd, Eina_Bool circulate)
{
   sd->circulate = circulate;
}

EOLIAN static Eina_Bool
_efl_ui_spin_button_circulate_get(const Eo *obj EINA_UNUSED, Efl_Ui_Spin_Button_Data *sd)
{
   return sd->circulate;
}

EOLIAN static const Efl_Access_Action_Data *
_efl_ui_spin_button_efl_access_widget_action_elm_actions_get(const Eo *obj EINA_UNUSED, Efl_Ui_Spin_Button_Data *sd EINA_UNUSED)
{
   static Efl_Access_Action_Data atspi_actions[] = {
          { "toggle", "toggle", NULL, _key_action_toggle},
          { NULL, NULL, NULL, NULL }
   };
   return &atspi_actions[0];
}

// A11Y Accessibility

EOLIAN static void
_efl_ui_spin_button_efl_access_value_value_and_text_get(const Eo *obj EINA_UNUSED, Efl_Ui_Spin_Button_Data *sd EINA_UNUSED, double *value, const char **text)
{
   Efl_Ui_Spin_Data *pd = efl_data_scope_get(obj, EFL_UI_SPIN_CLASS);

   if (value) *value = pd->val;
   if (text) *text = NULL;
}

EOLIAN static Eina_Bool
_efl_ui_spin_button_efl_access_value_value_and_text_set(Eo *obj, Efl_Ui_Spin_Button_Data *sd EINA_UNUSED, double value, const char *text EINA_UNUSED)
{
   Efl_Ui_Spin_Data *pd = efl_data_scope_get(obj, EFL_UI_SPIN_CLASS);

   if (pd->val_min > value) return EINA_FALSE;
   if (pd->val_max < value) return EINA_FALSE;

   pd->val = value;
   efl_ui_range_value_set(efl_super(obj, MY_CLASS), value);

   return EINA_TRUE;
}

EOLIAN static void
_efl_ui_spin_button_efl_access_value_range_get(const Eo *obj EINA_UNUSED, Efl_Ui_Spin_Button_Data *sd EINA_UNUSED, double *lower, double *upper, const char **descr)
{
   Efl_Ui_Spin_Data *pd = efl_data_scope_get(obj, EFL_UI_SPIN_CLASS);

   if (lower) *lower = pd->val_min;
   if (upper) *upper = pd->val_max;
   if (descr) *descr = NULL;
}

EOLIAN static double
_efl_ui_spin_button_efl_access_value_increment_get(const Eo *obj EINA_UNUSED, Efl_Ui_Spin_Button_Data *sd EINA_UNUSED)
{
   Efl_Ui_Spin_Data *pd = efl_data_scope_get(obj, EFL_UI_SPIN_CLASS);

   return pd->step;
}

EOLIAN static const char*
_efl_ui_spin_button_efl_access_object_i18n_name_get(const Eo *obj, Efl_Ui_Spin_Button_Data *sd EINA_UNUSED)
{
   const char *name;
   name = efl_access_object_i18n_name_get(efl_super(obj, EFL_UI_SPIN_BUTTON_CLASS));
   if (name) return name;
   const char *ret = elm_layout_text_get(obj, "efl.text");
   return ret;
}

// A11Y Accessibility - END

#define EFL_UI_SPIN_BUTTON_EXTRA_OPS \
   ELM_LAYOUT_SIZING_EVAL_OPS(efl_ui_spin_button), \

#include "efl_ui_spin_button.eo.c"