summaryrefslogtreecommitdiff
path: root/src/lib/elementary/elm_widget_item_static_focus.c
blob: fffb397fa8c9b9f8cc1c7ed32247c9b8684805cf (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
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#define EFL_UI_FOCUS_COMPOSITION_ADAPTER_PROTECTED
#define ELM_WIDGET_ITEM_PROTECTED
#define MY_CLASS ELM_WIDGET_ITEM_STATIC_FOCUS_CLASS

#include <Elementary.h>
#include "elm_genlist.eo.h"
#include "elm_gengrid.eo.h"
#include "elm_priv.h"
#include "efl_ui_focus_composition_adapter.eo.h"

typedef struct {
   Eo *adapter;
   Eina_Bool realized;
} Elm_Widget_Item_Static_Focus_Data;

static void
_realized_cb(void *data, const Efl_Event *ev)
{
   Elm_Widget_Item_Static_Focus_Data *pd = efl_data_scope_get(data, MY_CLASS);

   if (ev->info != data) return;

   pd->realized = EINA_TRUE;
   efl_ui_focus_object_prepare_logical(data);
}

static void
_unrealized_cb(void *data, const Efl_Event *ev EINA_UNUSED)
{
   Elm_Widget_Item_Static_Focus_Data *pd = efl_data_scope_get(data, MY_CLASS);

   if (ev->info != data) return;

   if (pd) /* if the obect is dead pd is NULL */
     {
        //only delete the adapter when not focused, this will lead to awfull artifacts
        if (!efl_ui_focus_object_focus_get(pd->adapter))
          {
             efl_del(pd->adapter);
          }
        pd->realized = EINA_FALSE;
     }
}

EOLIAN static void
_elm_widget_item_static_focus_efl_ui_focus_object_prepare_logical_none_recursive(Eo *obj, Elm_Widget_Item_Static_Focus_Data *pd EINA_UNUSED)
{
   Eo *logical_child;
   Elm_Widget_Item_Data *wpd = efl_data_scope_get(obj, ELM_WIDGET_ITEM_CLASS);

   efl_ui_focus_object_prepare_logical_none_recursive(efl_super(obj, MY_CLASS));

   if (!pd->realized)
     {
        WRN("This item is not realized, thus things will fall over, better return NOW");
        return;
     }

   logical_child = efl_ui_focus_manager_request_subchild(wpd->widget, obj);

   if (logical_child == pd->adapter)
     {
        Eo *next_widget;
        next_widget = efl_ui_focus_manager_request_move(wpd->widget, EFL_UI_FOCUS_DIRECTION_NEXT, logical_child, EINA_TRUE);

        if (efl_isa(next_widget, ELM_WIDGET_ITEM_STATIC_FOCUS_CLASS))
          {
             next_widget = NULL;
          }
        logical_child = next_widget;
     }

   if (!logical_child)
     {
        if (!pd->adapter)
          {
             // parent has to stay the object, since this is used to get the item of a adapter
             pd->adapter = efl_add(EFL_UI_FOCUS_COMPOSITION_ADAPTER_CLASS, obj);
             efl_ui_focus_composition_adapter_focus_manager_parent_set(pd->adapter, wpd->widget);
             efl_ui_focus_composition_adapter_focus_manager_object_set(pd->adapter, wpd->widget);
             efl_wref_add(pd->adapter, &pd->adapter);
             efl_ui_focus_manager_calc_register(wpd->widget, pd->adapter, obj, NULL);
          }
     }
   else if (logical_child && logical_child != pd->adapter)
     {
        efl_ui_focus_manager_calc_unregister(wpd->widget, pd->adapter);
        efl_del(pd->adapter);
        pd->adapter = NULL;
     }

   //genlist sometimes changes views when doing quick scrolls so reset the view in every possible call
   if (pd->adapter)
     efl_ui_focus_composition_adapter_canvas_object_set(pd->adapter,  wpd->view);
}

EOLIAN static Efl_Object*
_elm_widget_item_static_focus_efl_object_constructor(Eo *obj, Elm_Widget_Item_Static_Focus_Data *pd EINA_UNUSED)
{
   Elm_Widget_Item_Data *wpd = efl_data_scope_get(obj, ELM_WIDGET_ITEM_CLASS);
   Eo *ret = efl_constructor(efl_super(obj, MY_CLASS));

   if (efl_isa(wpd->widget, ELM_GENLIST_CLASS))
     {
        efl_event_callback_add(wpd->widget, ELM_GENLIST_EVENT_REALIZED, _realized_cb, obj);
        efl_event_callback_add(wpd->widget, ELM_GENLIST_EVENT_UNREALIZED, _unrealized_cb, obj);
     }
   else
     {
        efl_event_callback_add(wpd->widget, ELM_GENGRID_EVENT_REALIZED, _realized_cb, obj);
        efl_event_callback_add(wpd->widget, ELM_GENGRID_EVENT_UNREALIZED, _unrealized_cb, obj);
     }
   return ret;
}

EOLIAN static void
_elm_widget_item_static_focus_efl_object_destructor(Eo *obj, Elm_Widget_Item_Static_Focus_Data *pd EINA_UNUSED)
{
   Elm_Widget_Item_Data *wpd = efl_data_scope_get(obj, ELM_WIDGET_ITEM_CLASS);
   if (efl_isa(wpd->widget, ELM_GENLIST_CLASS))
     {
        efl_event_callback_del(wpd->widget, ELM_GENLIST_EVENT_REALIZED, _realized_cb, obj);
        efl_event_callback_del(wpd->widget, ELM_GENLIST_EVENT_UNREALIZED, _unrealized_cb, obj);
     }
   else
     {
        efl_event_callback_del(wpd->widget, ELM_GENGRID_EVENT_REALIZED, _realized_cb, obj);
        efl_event_callback_del(wpd->widget, ELM_GENGRID_EVENT_UNREALIZED, _unrealized_cb, obj);
     }

   if (pd->adapter)
     efl_del(pd->adapter);

   return efl_destructor(efl_super(obj, MY_CLASS));
}


#include "elm_widget_item_static_focus.eo.c"