[access] support back gesture
[framework/uifw/elementary.git] / src / lib / elm_widget_segment_control.h
1 #ifndef ELM_WIDGET_SEGMENT_CONTROL_H
2 #define ELM_WIDGET_SEGMENT_CONTROL_H
3
4 #include "elm_widget_layout.h"
5
6 /**
7  * @addtogroup Widget
8  * @{
9  *
10  * @section elm-segment-control-class The Elementary Segment control Class
11  *
12  * Elementary, besides having the @ref SegmentControl widget, exposes
13  * its foundation -- the Elementary Segment control Class -- in order
14  * to create other widgets which are a segment control with some more
15  * logic on top.
16  */
17
18 /**
19  * @def ELM_SEGMENT_CONTROL_CLASS
20  *
21  * Use this macro to cast whichever subclass of
22  * #Elm_Segment_Control_Smart_Class into it, so to access its fields.
23  *
24  * @ingroup Widget
25  */
26 #define ELM_SEGMENT_CONTROL_CLASS(x) ((Elm_Segment_Control_Smart_Class *)x)
27
28 /**
29  * @def ELM_SEGMENT_CONTROL_DATA
30  *
31  * Use this macro to cast whichever subdata of
32  * #Elm_Segment_Control_Smart_Data into it, so to access its fields.
33  *
34  * @ingroup Widget
35  */
36 #define ELM_SEGMENT_CONTROL_DATA(x)  ((Elm_Segment_Control_Smart_Data *)x)
37
38 /**
39  * @def ELM_SEGMENT_CONTROL_SMART_CLASS_VERSION
40  *
41  * Current version for Elementary segment control @b base smart class, a value
42  * which goes to _Elm_Segment_Control_Smart_Class::version.
43  *
44  * @ingroup Widget
45  */
46 #define ELM_SEGMENT_CONTROL_SMART_CLASS_VERSION 1
47
48 /**
49  * @def ELM_SEGMENT_CONTROL_SMART_CLASS_INIT
50  *
51  * Initializer for a whole #Elm_Segment_Control_Smart_Class structure, with
52  * @c NULL values on its specific fields.
53  *
54  * @param smart_class_init initializer to use for the "base" field
55  * (#Evas_Smart_Class).
56  *
57  * @see EVAS_SMART_CLASS_INIT_NULL
58  * @see EVAS_SMART_CLASS_INIT_NAME_VERSION
59  * @see ELM_SEGMENT_CONTROL_SMART_CLASS_INIT_NULL
60  * @see ELM_SEGMENT_CONTROL_SMART_CLASS_INIT_NAME_VERSION
61  *
62  * @ingroup Widget
63  */
64 #define ELM_SEGMENT_CONTROL_SMART_CLASS_INIT(smart_class_init) \
65   {smart_class_init, ELM_SEGMENT_CONTROL_SMART_CLASS_VERSION}
66
67 /**
68  * @def ELM_SEGMENT_CONTROL_SMART_CLASS_INIT_NULL
69  *
70  * Initializer to zero out a whole #Elm_Segment_Control_Smart_Class structure.
71  *
72  * @see ELM_SEGMENT_CONTROL_SMART_CLASS_INIT_NAME_VERSION
73  * @see ELM_SEGMENT_CONTROL_SMART_CLASS_INIT
74  *
75  * @ingroup Widget
76  */
77 #define ELM_SEGMENT_CONTROL_SMART_CLASS_INIT_NULL \
78   ELM_SEGMENT_CONTROL_SMART_CLASS_INIT(EVAS_SMART_CLASS_INIT_NULL)
79
80 /**
81  * @def ELM_SEGMENT_CONTROL_SMART_CLASS_INIT_NAME_VERSION
82  *
83  * Initializer to zero out a whole #Elm_Segment_Control_Smart_Class
84  * structure and set its name and version.
85  *
86  * This is similar to #ELM_SEGMENT_CONTROL_SMART_CLASS_INIT_NULL, but
87  * it will also set the version field of
88  * #Elm_Segment_Control_Smart_Class (base field) to the latest
89  * #ELM_SEGMENT_CONTROL_SMART_CLASS_VERSION and name it to the
90  * specific value.
91  *
92  * It will keep a reference to the name field as a <c>"const char *"</c>,
93  * i.e., the name must be available while the structure is
94  * used (hint: static or global variable!) and must not be modified.
95  *
96  * @see ELM_SEGMENT_CONTROL_SMART_CLASS_INIT_NULL
97  * @see ELM_SEGMENT_CONTROL_SMART_CLASS_INIT
98  *
99  * @ingroup Widget
100  */
101 #define ELM_SEGMENT_CONTROL_SMART_CLASS_INIT_NAME_VERSION(name) \
102   ELM_SEGMENT_CONTROL_SMART_CLASS_INIT                          \
103     (ELM_LAYOUT_SMART_CLASS_INIT_NAME_VERSION(name))
104
105 /**
106  * Elementary segment control base smart class. This inherits directly from
107  * #Elm_Layout_Smart_Class and is meant to build widgets extending the
108  * behavior of a segment control.
109  *
110  * All of the functions listed on @ref SegmentControl namespace will work for
111  * objects deriving from #Elm_Segment_Control_Smart_Class.
112  */
113 typedef struct _Elm_Segment_Control_Smart_Class
114 {
115    Elm_Layout_Smart_Class base;
116
117    int                    version;    /**< Version of this smart class definition */
118 } Elm_Segment_Control_Smart_Class;
119
120 /**
121  * Base layout smart data extended with segment control instance data.
122  */
123 typedef struct _Elm_Segment_Control_Smart_Data Elm_Segment_Control_Smart_Data;
124 typedef struct _Elm_Segment_Item               Elm_Segment_Item;
125
126 struct _Elm_Segment_Control_Smart_Data
127 {
128    Elm_Layout_Smart_Data base;
129
130    Eina_List            *items;
131    Elm_Segment_Item     *selected_item;
132
133    int                   item_width;
134 };
135
136 struct _Elm_Segment_Item
137 {
138    ELM_WIDGET_ITEM;
139
140    Evas_Object *icon;
141    const char  *label;
142    int          seg_index;
143 };
144
145 /**
146  * @}
147  */
148
149 EAPI extern const char ELM_SEGMENT_CONTROL_SMART_NAME[];
150 EAPI const Elm_Segment_Control_Smart_Class
151 *elm_segment_control_smart_class_get(void);
152
153
154 #define ELM_SEGMENT_CONTROL_DATA_GET(o, sd) \
155   Elm_Segment_Control_Smart_Data * sd = evas_object_smart_data_get(o)
156
157 #define ELM_SEGMENT_CONTROL_DATA_GET_OR_RETURN(o, ptr) \
158   ELM_SEGMENT_CONTROL_DATA_GET(o, ptr);                \
159   if (!ptr)                                            \
160     {                                                  \
161        CRITICAL("No widget data for object %p (%s)",   \
162                 o, evas_object_type_get(o));           \
163        return;                                         \
164     }
165
166 #define ELM_SEGMENT_CONTROL_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
167   ELM_SEGMENT_CONTROL_DATA_GET(o, ptr);                         \
168   if (!ptr)                                                     \
169     {                                                           \
170        CRITICAL("No widget data for object %p (%s)",            \
171                 o, evas_object_type_get(o));                    \
172        return val;                                              \
173     }
174
175 #define ELM_SEGMENT_CONTROL_CHECK(obj)                     \
176   if (!obj || !elm_widget_type_check                       \
177         ((obj), ELM_SEGMENT_CONTROL_SMART_NAME, __func__)) \
178     return
179
180 #define ELM_SEGMENT_CONTROL_ITEM_CHECK(it)                  \
181   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, ); \
182   ELM_SEGMENT_CONTROL_CHECK(it->base.widget);
183
184 #define ELM_SEGMENT_CONTROL_ITEM_CHECK_OR_RETURN(it, ...)              \
185   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
186   ELM_SEGMENT_CONTROL_CHECK(it->base.widget) __VA_ARGS__;
187
188 #endif