b6dfb9ed50ee1632aedcebbc852fd05f4fe2acc5
[platform/upstream/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 #define ELM_LIST_SWIPE_MOVES 12
19
20 /**
21  * Base widget smart data extended with list instance data.
22  */
23 typedef struct _Elm_List_Smart_Data Elm_List_Smart_Data;
24 struct _Elm_List_Smart_Data
25 {
26    Evas_Object                          *box, *hit_rect;
27
28    Eina_List                            *items, *selected, *to_delete;
29    Elm_Object_Item                      *last_selected_item;
30    Elm_Object_Item                      *focused_item; /**< a focused item by keypad arrow or mouse. This is set to NULL if widget looses focus. */
31    Elm_Object_Item                      *prev_focused_item; /**< a previous focused item by keypad arrow or mouse. */
32    Elm_Object_Item                      *last_focused_item; /**< This records the last focused item when widget looses focus. This is required to set the focus on last focused item when widgets gets focus. */
33    Evas_Coord                            minw[2], minh[2];
34    Elm_Object_Select_Mode                select_mode;
35    Elm_Object_Multi_Select_Mode          multi_select_mode; /**< select mode for multiple selection */
36    int                                   movements;
37    int                                   walking;
38    Elm_List_Mode                         h_mode;
39    Elm_List_Mode                         mode;
40
41    struct
42    {
43       Evas_Coord x, y;
44    } history[ELM_LIST_SWIPE_MOVES];
45
46    Eina_Bool                             focus_on_selection_enabled : 1;
47    Eina_Bool                             was_selected : 1;
48    Eina_Bool                             fix_pending : 1;
49    Eina_Bool                             longpressed : 1;
50    Eina_Bool                             scr_minw : 1;
51    Eina_Bool                             scr_minh : 1;
52    Eina_Bool                             on_hold : 1;
53    Eina_Bool                             multi : 1;
54    Eina_Bool                             swipe : 1;
55    Eina_Bool                             delete_me : 1;
56    Eina_Bool                             mouse_down : 1; /**< a flag that mouse is down on the list at the moment. this flag is set to true on mouse and reset to false on mouse up */
57 };
58
59 typedef struct _Elm_List_Item Elm_List_Item;
60 struct _Elm_List_Item
61 {
62    ELM_WIDGET_ITEM;
63
64    Ecore_Timer         *swipe_timer;
65    Ecore_Timer         *long_timer;
66    Evas_Object         *icon, *end;
67    Evas_Smart_Cb        func;
68
69    const char          *label;
70    Eina_List           *node;
71
72    Eina_Bool            is_separator : 1;
73    Eina_Bool            highlighted : 1;
74    Eina_Bool            dummy_icon : 1;
75    Eina_Bool            dummy_end : 1;
76    Eina_Bool            selected : 1;
77    Eina_Bool            deleted : 1;
78    Eina_Bool            is_even : 1;
79    Eina_Bool            fixed : 1;
80    Eina_Bool            even : 1;
81 };
82
83 /**
84  * @}
85  */
86
87 #define ELM_LIST_DATA_GET(o, sd) \
88   Elm_List_Smart_Data * sd = eo_data_scope_get(o, ELM_OBJ_LIST_CLASS)
89
90 #define ELM_LIST_DATA_GET_OR_RETURN(o, ptr)          \
91   ELM_LIST_DATA_GET(o, ptr);                         \
92   if (EINA_UNLIKELY(!ptr))                           \
93     {                                                \
94        CRI("No widget data for object %p (%s)",      \
95            o, evas_object_type_get(o));              \
96        return;                                       \
97     }
98
99 #define ELM_LIST_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
100   ELM_LIST_DATA_GET(o, ptr);                         \
101   if (EINA_UNLIKELY(!ptr))                           \
102     {                                                \
103        CRI("No widget data for object %p (%s)",      \
104            o, evas_object_type_get(o));              \
105        return val;                                   \
106     }
107
108 #define ELM_LIST_CHECK(obj)                              \
109   if (EINA_UNLIKELY(!eo_isa((obj), ELM_OBJ_LIST_CLASS))) \
110     return
111
112 #define ELM_LIST_ITEM_CHECK(it)                             \
113   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, ); \
114   ELM_LIST_CHECK(it->base.widget);                          \
115   if (((Elm_List_Item *)it)->deleted)                       \
116     {                                                       \
117        ERR("ERROR: " #it " has been DELETED.\n");           \
118        return;                                              \
119     }
120
121 #define ELM_LIST_ITEM_CHECK_OR_RETURN(it, ...)                         \
122   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
123   ELM_LIST_CHECK(it->base.widget) __VA_ARGS__;                         \
124   if (((Elm_List_Item *)it)->deleted)                                  \
125     {                                                                  \
126        ERR("ERROR: " #it " has been DELETED.\n");                      \
127        return __VA_ARGS__;                                             \
128     }
129
130 #endif