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

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

#define MY_CLASS EFL_UI_RADIO_BOX_CLASS

typedef struct {
   Eina_Bool in_pack;
   Efl_Ui_Radio_Group *group;
} Efl_Ui_Radio_Box_Data;

static inline Eina_Bool
register_safe_in_group_begin(Eo *subobj, Efl_Ui_Radio_Box_Data *pd)
{
   EINA_SAFETY_ON_FALSE_RETURN_VAL(efl_isa(subobj, EFL_UI_RADIO_CLASS), EINA_FALSE);
   if (!pd->in_pack)
     efl_ui_radio_group_register(pd->group, subobj);
   pd->in_pack = EINA_TRUE;

   return EINA_TRUE;
}

static inline Eina_Bool
register_safe_group_end(Eo *subobj, Efl_Ui_Radio_Box_Data *pd, Eina_Bool result)
{
   if (!result)
     efl_ui_radio_group_unregister(pd->group, subobj);
   pd->in_pack = EINA_FALSE;

   return result;
}

#define REGISTER_SAFE(f) \
  Eina_Bool result; \
  if (!register_safe_in_group_begin(subobj, pd)) \
    return EINA_FALSE; \
  result = f ; \
  return register_safe_group_end(subobj, pd, result);

static void
unpack_from_logical(Eo *obj, Efl_Ui_Radio_Box_Data *pd)
{
   int length = efl_content_count(obj);
   for (int i = 0; i < length; ++i)
     {
        efl_ui_radio_group_unregister(pd->group, efl_pack_content_get(obj, i));
     }
}

EOLIAN static Eina_Bool
_efl_ui_radio_box_efl_pack_pack_clear(Eo *obj, Efl_Ui_Radio_Box_Data *pd)
{
   unpack_from_logical(obj, pd);
   return efl_pack_clear(efl_super(obj, MY_CLASS));
}

EOLIAN static Eina_Bool
_efl_ui_radio_box_efl_pack_unpack_all(Eo *obj, Efl_Ui_Radio_Box_Data *pd)
{
   unpack_from_logical(obj, pd);
   return efl_pack_unpack_all(efl_super(obj, MY_CLASS));
}

EOLIAN static Eina_Bool
_efl_ui_radio_box_efl_pack_unpack(Eo *obj, Efl_Ui_Radio_Box_Data *pd, Efl_Gfx_Entity *subobj)
{
   efl_ui_radio_group_unregister(pd->group, subobj);
   return efl_pack_unpack(efl_super(obj, MY_CLASS), subobj);
}

EOLIAN static Efl_Gfx_Entity*
_efl_ui_radio_box_efl_pack_linear_pack_unpack_at(Eo *obj, Efl_Ui_Radio_Box_Data *pd, int index)
{
   efl_ui_radio_group_unregister(pd->group, efl_pack_content_get(obj, index));
   return efl_pack_unpack_at(efl_super(obj, MY_CLASS), index);
}

EOLIAN static Eina_Bool
_efl_ui_radio_box_efl_pack_pack(Eo *obj, Efl_Ui_Radio_Box_Data *pd, Efl_Gfx_Entity *subobj)
{
   REGISTER_SAFE(efl_pack(efl_super(obj, MY_CLASS), subobj))
}

EOLIAN static Eina_Bool
_efl_ui_radio_box_efl_pack_linear_pack_begin(Eo *obj, Efl_Ui_Radio_Box_Data *pd, Efl_Gfx_Entity *subobj)
{
   REGISTER_SAFE(efl_pack_begin(efl_super(obj, MY_CLASS), subobj))
}

EOLIAN static Eina_Bool
_efl_ui_radio_box_efl_pack_linear_pack_end(Eo *obj, Efl_Ui_Radio_Box_Data *pd, Efl_Gfx_Entity *subobj)
{
   REGISTER_SAFE(efl_pack_end(efl_super(obj, MY_CLASS), subobj))
}

EOLIAN static Eina_Bool
_efl_ui_radio_box_efl_pack_linear_pack_before(Eo *obj, Efl_Ui_Radio_Box_Data *pd, Efl_Gfx_Entity *subobj, const Efl_Gfx_Entity *existing)
{
   REGISTER_SAFE(efl_pack_before(efl_super(obj, MY_CLASS), subobj, existing));
}

EOLIAN static Eina_Bool
_efl_ui_radio_box_efl_pack_linear_pack_after(Eo *obj, Efl_Ui_Radio_Box_Data *pd, Efl_Gfx_Entity *subobj, const Efl_Gfx_Entity *existing)
{
   REGISTER_SAFE(efl_pack_after(efl_super(obj, MY_CLASS), subobj, existing));
}

EOLIAN static Eina_Bool
_efl_ui_radio_box_efl_pack_linear_pack_at(Eo *obj, Efl_Ui_Radio_Box_Data *pd, Efl_Gfx_Entity *subobj, int index)
{
   REGISTER_SAFE(efl_pack_at(efl_super(obj, MY_CLASS), subobj, index));
}

EOLIAN static Efl_Object*
_efl_ui_radio_box_efl_object_constructor(Eo *obj, Efl_Ui_Radio_Box_Data *pd)
{
   pd->group = efl_new(EFL_UI_RADIO_GROUP_IMPL_CLASS, NULL);
   efl_composite_attach(obj, pd->group);
   efl_event_callback_forwarder_add(pd->group, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, obj);
   efl_event_callback_forwarder_add(pd->group, EFL_UI_RADIO_GROUP_EVENT_VALUE_CHANGED, obj);
   return efl_constructor(efl_super(obj, MY_CLASS));
}


#include "efl_ui_radio_box.eo.c"