summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/efl_input_event.c
blob: 8b02713ad789d47f19698ada1b829af42e577459 (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
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
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#define EFL_INPUT_EVENT_PROTECTED

#include <Evas.h>
#include <Evas_Internal.h>
#include "canvas/evas_canvas.eo.h"

#define EFL_INTERNAL_UNSTABLE
#include "interfaces/efl_common_internal.h"

#define MY_CLASS EFL_INPUT_EVENT_MIXIN

EOLIAN static void
_efl_input_event_processed_set(Eo *obj, void *pd EINA_UNUSED, Eina_Bool val)
{
   if (val)
     efl_input_event_flags_set(obj, efl_input_event_flags_get(obj) | EFL_INPUT_FLAGS_PROCESSED);
   else
     efl_input_event_flags_set(obj, efl_input_event_flags_get(obj) & ~EFL_INPUT_FLAGS_PROCESSED);
}

EOLIAN static Eina_Bool
_efl_input_event_processed_get(const Eo *obj EINA_UNUSED, void *pd EINA_UNUSED)
{
   return !!(efl_input_event_flags_get(obj) & EFL_INPUT_FLAGS_PROCESSED);
}

EOLIAN static void
_efl_input_event_scrolling_set(Eo *obj EINA_UNUSED, void *pd EINA_UNUSED, Eina_Bool val)
{
   if (val)
     efl_input_event_flags_set(obj, efl_input_event_flags_get(obj) | EFL_INPUT_FLAGS_SCROLLING);
   else
     efl_input_event_flags_set(obj, efl_input_event_flags_get(obj) & ~EFL_INPUT_FLAGS_SCROLLING);
}

EOLIAN static Eina_Bool
_efl_input_event_scrolling_get(const Eo *obj EINA_UNUSED, void *pd EINA_UNUSED)
{
   return !!(efl_input_event_flags_get(obj) & EFL_INPUT_FLAGS_SCROLLING);
}

EOLIAN static Eina_Bool
_efl_input_event_fake_get(const Eo *obj EINA_UNUSED, void *pd EINA_UNUSED)
{
   return EINA_FALSE;
}

EOLIAN static Efl_Object *
_efl_input_event_efl_object_provider_find(const Eo *obj, void *pd EINA_UNUSED, const Efl_Object *klass)
{
   // Note: provider_find should probably return self if self is a klass object
   if (klass == EVAS_CANVAS_CLASS)
     {
        for (Eo *parent = efl_parent_get(obj); parent; parent = efl_parent_get(parent))
          {
             if (efl_isa(parent, klass))
               return parent;
          }
     }
   return efl_provider_find(efl_super(obj, MY_CLASS), klass);
}

static Eina_Hash *_cached_events = NULL;

static void
_del_hook(Eo *evt)
{
   Efl_Input_Event *cached;
   const Eo *klass = efl_class_get(evt);

   efl_del_intercept_set(evt, NULL);

   cached = eina_hash_find(_cached_events, &klass);
   if (!cached)
     {
        efl_reuse(evt);
        eina_hash_add(_cached_events, &klass, evt);
        efl_input_reset(evt);
     }
   else
     {
        efl_unref(evt);
     }
}

static void
_noref_death(void *data EINA_UNUSED, const Efl_Event *event)
{
   efl_event_callback_del(event->object, EFL_EVENT_NOREF, _noref_death, NULL);
   efl_del(event->object);
}

Efl_Input_Event *
efl_input_event_instance_get(const Eo *klass, Eo *owner)
{
   Efl_Input_Event *evt;

   if (efl_invalidated_get(owner)) return NULL;

   if (!_cached_events)
     _cached_events = eina_hash_pointer_new(EINA_FREE_CB(efl_unref));

   evt = eina_hash_find(_cached_events, &klass);
   if (evt)
     {
        // eina_hash_del will call efl_unref, so prevent the destruction of the object
        evt = efl_ref(evt);
        eina_hash_del(_cached_events, &klass, evt);
        efl_parent_set(evt, owner);
        efl_unref(evt); // Remove reference before turning on self destruction
        efl_del_intercept_set(evt, _del_hook);
        efl_event_callback_add(evt, EFL_EVENT_NOREF, _noref_death, NULL);
     }
   else
     {
        evt = efl_add(klass, owner);
        efl_event_callback_add(evt, EFL_EVENT_NOREF, _noref_death, NULL);
        efl_del_intercept_set(evt, _del_hook);
     }

   return efl_ref(evt);
}

void
efl_input_event_instance_clean(Eo *klass)
{
   if (!_cached_events) return ;

   eina_hash_del(_cached_events, &klass, NULL);
}

/* Internal EO APIs */

EOAPI EFL_FUNC_BODY_CONST(efl_input_legacy_info_get, void *, NULL)
EOAPI EFL_FUNC_BODYV_CONST(efl_input_instance_get, Efl_Input_Event *, NULL, EFL_FUNC_CALL(owner, priv), Efl_Object *owner, void **priv)

#define EFL_INPUT_EVENT_EXTRA_OPS \
   EFL_OBJECT_OP_FUNC(efl_input_legacy_info_get, NULL)

#define EFL_INPUT_EVENT_EXTRA_CLASS_OPS \
   EFL_OBJECT_OP_FUNC(efl_input_instance_get, NULL)

#include "efl_input_event.eo.c"
#include "efl_input_state.eo.c"
#include "efl_input_interface.eo.c"