elementary/map - map supports language,changed
[framework/uifw/elementary.git] / src / lib / elm_widget_list.h
1 #ifndef ELM_WIDGET_LIST_H
2 #define ELM_WIDGET_LIST_H
3
4 #include "elm_interface_scrollable.h"
5 #include "elm_widget_layout.h"
6
7 /**
8  * @addtogroup Widget
9  * @{
10  *
11  * @section elm-list-class The Elementary List Class
12  *
13  * Elementary, besides having the @ref List widget, exposes its
14  * foundation -- the Elementary List Class -- in order to create
15  * other widgets which are a list with some more logic on top.
16  */
17
18 /**
19  * @def ELM_LIST_CLASS
20  *
21  * Use this macro to cast whichever subclass of
22  * #Elm_List_Smart_Class into it, so to access its fields.
23  *
24  * @ingroup Widget
25  */
26 #define ELM_LIST_CLASS(x) ((Elm_List_Smart_Class *)x)
27
28 /**
29  * @def ELM_LIST_DATA
30  *
31  * Use this macro to cast whichever subdata of
32  * #Elm_List_Smart_Data into it, so to access its fields.
33  *
34  * @ingroup Widget
35  */
36 #define ELM_LIST_DATA(x)  ((Elm_List_Smart_Data *)x)
37
38 /**
39  * @def ELM_LIST_SMART_CLASS_VERSION
40  *
41  * Current version for Elementary list @b base smart class, a value
42  * which goes to _Elm_List_Smart_Class::version.
43  *
44  * @ingroup Widget
45  */
46 #define ELM_LIST_SMART_CLASS_VERSION 1
47
48 /**
49  * @def ELM_LIST_SMART_CLASS_INIT
50  *
51  * Initializer for a whole #Elm_List_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_LIST_SMART_CLASS_INIT_NULL
60  * @see ELM_LIST_SMART_CLASS_INIT_NAME_VERSION
61  *
62  * @ingroup Widget
63  */
64 #define ELM_LIST_SMART_CLASS_INIT(smart_class_init) \
65   {smart_class_init, ELM_LIST_SMART_CLASS_VERSION}
66
67 /**
68  * @def ELM_LIST_SMART_CLASS_INIT_NULL
69  *
70  * Initializer to zero out a whole #Elm_List_Smart_Class structure.
71  *
72  * @see ELM_LIST_SMART_CLASS_INIT_NAME_VERSION
73  * @see ELM_LIST_SMART_CLASS_INIT
74  *
75  * @ingroup Widget
76  */
77 #define ELM_LIST_SMART_CLASS_INIT_NULL \
78   ELM_LIST_SMART_CLASS_INIT(EVAS_SMART_CLASS_INIT_NULL)
79
80 /**
81  * @def ELM_LIST_SMART_CLASS_INIT_NAME_VERSION
82  *
83  * Initializer to zero out a whole #Elm_List_Smart_Class structure and
84  * set its name and version.
85  *
86  * This is similar to #ELM_LIST_SMART_CLASS_INIT_NULL, but it will
87  * also set the version field of #Elm_List_Smart_Class (base field)
88  * to the latest #ELM_LIST_SMART_CLASS_VERSION and name it to the
89  * specific value.
90  *
91  * It will keep a reference to the name field as a <c>"const char *"</c>,
92  * i.e., the name must be available while the structure is
93  * used (hint: static or global variable!) and must not be modified.
94  *
95  * @see ELM_LIST_SMART_CLASS_INIT_NULL
96  * @see ELM_LIST_SMART_CLASS_INIT
97  *
98  * @ingroup Widget
99  */
100 #define ELM_LIST_SMART_CLASS_INIT_NAME_VERSION(name) \
101   ELM_LIST_SMART_CLASS_INIT                          \
102     (ELM_LAYOUT_SMART_CLASS_INIT_NAME_VERSION(name))
103
104 /**
105  * Elementary list base smart class. This inherits directly from
106  * #Elm_Layout_Smart_Class and is meant to build widgets extending the
107  * behavior of a list.
108  *
109  * All of the functions listed on @ref List namespace will work for
110  * objects deriving from #Elm_List_Smart_Class.
111  */
112 typedef struct _Elm_List_Smart_Class
113 {
114    Elm_Layout_Smart_Class base;
115
116    int                    version;    /**< Version of this smart class definition */
117 } Elm_List_Smart_Class;
118
119 #define ELM_LIST_SWIPE_MOVES 12
120
121 /**
122  * Base widget smart data extended with list instance data.
123  */
124 typedef struct _Elm_List_Smart_Data Elm_List_Smart_Data;
125 struct _Elm_List_Smart_Data
126 {
127    Elm_Layout_Smart_Data                 base; /* base widget smart data as
128                                                 * first member obligatory, as
129                                                 * we're inheriting from it */
130
131    Evas_Object                          *box, *hit_rect;
132    const Elm_Scrollable_Smart_Interface *s_iface;
133
134    Eina_List                            *items, *selected, *to_delete;
135    Elm_Object_Item                      *last_selected_item;
136    Evas_Coord                            minw[2], minh[2];
137    Elm_Object_Select_Mode                select_mode;
138    int                                   movements;
139    int                                   walking;
140    Elm_List_Mode                         h_mode;
141    Elm_List_Mode                         mode;
142
143    struct
144    {
145       Evas_Coord x, y;
146    } history[ELM_LIST_SWIPE_MOVES];
147
148    Eina_Bool                             was_selected : 1;
149    Eina_Bool                             fix_pending : 1;
150    Eina_Bool                             longpressed : 1;
151    Eina_Bool                             scr_minw : 1;
152    Eina_Bool                             scr_minh : 1;
153    Eina_Bool                             on_hold : 1;
154    Eina_Bool                             multi : 1;
155    Eina_Bool                             swipe : 1;
156    Eina_Bool                             delete_me : 1;
157 };
158
159 typedef struct _Elm_List_Item Elm_List_Item;
160 struct _Elm_List_Item
161 {
162    ELM_WIDGET_ITEM;
163
164    Elm_List_Smart_Data *sd;
165
166    Ecore_Timer         *swipe_timer;
167    Ecore_Timer         *long_timer;
168    Evas_Object         *icon, *end;
169    Evas_Smart_Cb        func;
170
171    const char          *label;
172    Eina_List           *node;
173
174    Eina_Bool            is_separator : 1;
175    Eina_Bool            highlighted : 1;
176    Eina_Bool            dummy_icon : 1;
177    Eina_Bool            dummy_end : 1;
178    Eina_Bool            selected : 1;
179    Eina_Bool            deleted : 1;
180    Eina_Bool            is_even : 1;
181    Eina_Bool            fixed : 1;
182    Eina_Bool            even : 1;
183 };
184
185 /**
186  * @}
187  */
188
189 EAPI extern const char ELM_LIST_SMART_NAME[];
190 EAPI const Elm_List_Smart_Class *elm_list_smart_class_get(void);
191
192 #define ELM_LIST_DATA_GET(o, sd) \
193   Elm_List_Smart_Data * sd = evas_object_smart_data_get(o)
194
195 #define ELM_LIST_DATA_GET_OR_RETURN(o, ptr)          \
196   ELM_LIST_DATA_GET(o, ptr);                         \
197   if (!ptr)                                          \
198     {                                                \
199        CRITICAL("No widget data for object %p (%s)", \
200                 o, evas_object_type_get(o));         \
201        return;                                       \
202     }
203
204 #define ELM_LIST_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
205   ELM_LIST_DATA_GET(o, ptr);                         \
206   if (!ptr)                                          \
207     {                                                \
208        CRITICAL("No widget data for object %p (%s)", \
209                 o, evas_object_type_get(o));         \
210        return val;                                   \
211     }
212
213 #define ELM_LIST_CHECK(obj)                                                 \
214   if (!obj || !elm_widget_type_check((obj), ELM_LIST_SMART_NAME, __func__)) \
215     return
216
217 #define ELM_LIST_ITEM_CHECK(it)                             \
218   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, ); \
219   ELM_LIST_CHECK(it->base.widget);                          \
220   if (((Elm_List_Item *)it)->deleted)                       \
221     {                                                       \
222        ERR("ERROR: " #it " has been DELETED.\n");           \
223        return;                                              \
224     }
225
226 #define ELM_LIST_ITEM_CHECK_OR_RETURN(it, ...)                         \
227   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
228   ELM_LIST_CHECK(it->base.widget) __VA_ARGS__;                         \
229   if (((Elm_List_Item *)it)->deleted)                                  \
230     {                                                                  \
231        ERR("ERROR: " #it " has been DELETED.\n");                      \
232        return __VA_ARGS__;                                             \
233     }
234
235 #endif