aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/elementary/efl_ui_clickable_util.c
blob: b11e0c50e2e8bd874a01e9c4fe66f9870a4880c7 (plain) (blame)
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
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#define EFL_UI_CLICKABLE_PROTECTED 1

#include <Efl_Ui.h>
#include "elm_priv.h"

typedef struct {

} Efl_Ui_Clickable_Util_Data;

static void
_on_press_cb(void *data,
             Evas_Object *obj EINA_UNUSED,
             const char *emission EINA_UNUSED,
             const char *source EINA_UNUSED)
{
   efl_ui_clickable_press(data, 1);
}

static void
_on_unpress_cb(void *data,
             Evas_Object *obj EINA_UNUSED,
             const char *emission EINA_UNUSED,
             const char *source EINA_UNUSED)
{
   efl_ui_clickable_unpress(data, 1);
}

static void
_on_mouse_out(void *data,
             Evas_Object *obj EINA_UNUSED,
             const char *emission EINA_UNUSED,
             const char *source EINA_UNUSED)
{
   efl_ui_clickable_button_state_reset(data, 1);
}

EOLIAN static void
_efl_ui_clickable_util_bind_to_theme(Efl_Canvas_Layout *object, Efl_Ui_Clickable *clickable)
{
   efl_layout_signal_callback_add(object, "efl,action,press", "*", clickable, _on_press_cb, NULL);
   efl_layout_signal_callback_add(object, "efl,action,unpress", "*", clickable, _on_unpress_cb, NULL);
   efl_layout_signal_callback_add(object, "efl,action,mouse_out", "*", clickable, _on_mouse_out, NULL);
}

static void
_press_cb(void *data, const Efl_Event *ev)
{
   Efl_Input_Pointer *pointer = ev->info;
   if (!efl_input_processed_get(pointer))
     {
        efl_ui_clickable_press(data, 1);
        efl_input_processed_set(pointer, EINA_TRUE);
     }
}

static void
_unpress_cb(void *data, const Efl_Event *ev EINA_UNUSED)
{
   Efl_Input_Pointer *pointer = ev->info;
   Eina_Position2D mouse_pos = efl_input_pointer_position_get(pointer);
   Eina_Rect geom = efl_gfx_entity_geometry_get(data);
   if (efl_input_processed_get(pointer))
     {
        efl_ui_clickable_button_state_reset(data, 1);
     }
   else if (!eina_rectangle_coords_inside(&geom.rect, mouse_pos.x, mouse_pos.y))
     {
        //we are emulating edje behavior here, do press unpress on the event, but not click
        efl_ui_clickable_button_state_reset(data, 1);
        if (efl_canvas_object_pointer_mode_get(data) == EFL_INPUT_OBJECT_POINTER_MODE_AUTO_GRAB)
          {
             efl_ui_clickable_unpress(data, 1);
             efl_input_processed_set(pointer, EINA_TRUE);
          }
     }
   else
     {
        efl_ui_clickable_unpress(data, 1);
        efl_input_processed_set(pointer, EINA_TRUE);
     }
}

EFL_CALLBACKS_ARRAY_DEFINE(bind_to_theme_callbacks,
  {EFL_EVENT_POINTER_DOWN, _press_cb},
  {EFL_EVENT_POINTER_UP, _unpress_cb},
)

EOLIAN static void
_efl_ui_clickable_util_bind_to_object(Efl_Input_Interface *object, Efl_Ui_Clickable *clickable)
{
   efl_event_callback_array_add(object, bind_to_theme_callbacks(), clickable);
}


#include "efl_ui_clickable_util.eo.c"