1 #ifndef ELM_WIDGET_MULTIBUTTONENTRY_H
2 #define ELM_WIDGET_MULTIBUTTONENTRY_H
3 
4 #include "elm_widget_layout.h"
5 
6 /* DO NOT USE THIS HEADER UNLESS YOU ARE PREPARED FOR BREAKING OF YOUR
7  * CODE. THIS IS ELEMENTARY'S INTERNAL WIDGET API (for now) AND IS NOT
8  * FINAL. CALL elm_widget_api_check(ELM_INTERNAL_API_VERSION) TO CHECK
9  * IT AT RUNTIME.
10  */
11 
12 /**
13  * @addtogroup Widget
14  * @{
15  *
16  * @section elm-multibuttonentry-class The Elementary Multi Button Entry Class
17  *
18  * Elementary, besides having the @ref Multibuttonentry widget,
19  * exposes its foundation -- the Elementary Multi Button Entry Class --
20  * in order to create other widgets which are a multi button entry with
21  * some more logic on top.
22  */
23 
24 /**
25  * Base widget smart data extended with multibuttonentry instance data.
26  */
27 
28 typedef enum _Multibuttonentry_Pos
29 {
30    MULTIBUTTONENTRY_POS_START,
31    MULTIBUTTONENTRY_POS_END,
32    MULTIBUTTONENTRY_POS_BEFORE,
33    MULTIBUTTONENTRY_POS_AFTER,
34 } Multibuttonentry_Pos;
35 
36 typedef enum _Multibuttonentry_Button_State
37 {
38    MULTIBUTTONENTRY_BUTTON_STATE_DEFAULT,
39    MULTIBUTTONENTRY_BUTTON_STATE_SELECTED,
40 } Multibuttonentry_Button_State;
41 
42 typedef enum _MultiButtonEntry_Closed_Button_Type
43 {
44    MULTIBUTTONENTRY_CLOSED_IMAGE,
45    MULTIBUTTONENTRY_CLOSED_LABEL
46 } MultiButtonEntry_Closed_Button_Type;
47 
48 typedef enum _Multibuttonentry_View_State
49 {
50    MULTIBUTTONENTRY_VIEW_NONE,
51    MULTIBUTTONENTRY_VIEW_GUIDETEXT,
52    MULTIBUTTONENTRY_VIEW_ENTRY,
53    MULTIBUTTONENTRY_VIEW_SHRINK
54 } Multibuttonentry_View_State;
55 
56 typedef struct _Multibuttonentry_Item Elm_Multibuttonentry_Item_Data;
57 
58 struct _Multibuttonentry_Item
59 {
60    Elm_Widget_Item_Data *base;
61 
62    Evas_Coord    vw, rw; // vw: visual width, real width
63    Eina_Bool     visible : 1;
64    Evas_Smart_Cb func;
65 };
66 
67 typedef struct _Elm_Multibuttonentry_Item_Filter
68 {
69    Elm_Multibuttonentry_Item_Filter_Cb callback_func;
70    void                               *data;
71 } Elm_Multibuttonentry_Item_Filter;
72 
73 typedef struct _Elm_Multibuttonentry_Data
74   Elm_Multibuttonentry_Data;
75 struct _Elm_Multibuttonentry_Data
76 {
77    Evas_Object                        *parent;
78    Evas_Object                        *box;
79    Evas_Object                        *entry;
80    Evas_Object                        *label;
81    Evas_Object                        *guide_text;
82    Evas_Object                        *end; /* used to represent the
83                                              * total number of
84                                              * invisible buttons */
85 
86    Eina_List                          *items;
87    Eina_List                          *filter_list;
88    Elm_Multibuttonentry_Item_Data     *selected_it; /* selected item */
89    Elm_Multibuttonentry_Item_Data     *focused_it;
90 
91    Elm_Multibuttonentry_Format_Cb      format_func;
92    const void                         *format_func_data;
93 
94    const char                         *label_str, *guide_text_str;
95 
96    int                                 n_str;
97    Multibuttonentry_View_State         view_state;
98 
99    Evas_Coord                          w_box, h_box;
100    int                                 shrink;
101 
102    Elm_Multibuttonentry_Item_Filter_Cb add_callback;
103    void                               *add_callback_data;
104    Ecore_Timer                        *longpress_timer;
105 
106    Efl_Ui_Format_Func                  format_cb;
107    Eina_Free_Cb                        format_free_cb;
108    void                               *format_cb_data;
109    Eina_Strbuf                        *format_strbuf;
110 
111    Eina_Bool                           last_it_select : 1;
112    Eina_Bool                           editable : 1;
113    Eina_Bool                           focused : 1; // avoids infinite loop on focus in/out
114    Eina_Bool                           label_packed : 1;
115 };
116 
117 /**
118  * @}
119  */
120 
121 #define ELM_MULTIBUTTONENTRY_DATA_GET(o, sd) \
122   Elm_Multibuttonentry_Data *sd = efl_data_scope_get(o, ELM_MULTIBUTTONENTRY_CLASS);
123 
124 #define ELM_MULTIBUTTONENTRY_DATA_GET_OR_RETURN(o, ptr) \
125   ELM_MULTIBUTTONENTRY_DATA_GET(o, ptr);                \
126   if (EINA_UNLIKELY(!ptr))                              \
127     {                                                   \
128        ERR("No widget data for object %p (%s)",         \
129            o, evas_object_type_get(o));                 \
130        return;                                          \
131     }
132 
133 #define ELM_MULTIBUTTONENTRY_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
134   Elm_Multibuttonentry_Data * ptr = efl_data_scope_get(o, ELM_MULTIBUTTONENTRY_CLASS); \
135   if (EINA_UNLIKELY(!ptr))                                       \
136     {                                                            \
137        ERR("No widget data for object %p (%s)",                  \
138            o, evas_object_type_get(o));                          \
139        return val;                                               \
140     }
141 
142 #define ELM_MULTIBUTTONENTRY_ITEM_DATA_GET(o, sd) \
143   Elm_Multibuttonentry_Item_Data *sd = efl_data_scope_get(o, ELM_MULTIBUTTONENTRY_ITEM_CLASS)
144 
145 #define ELM_MULTIBUTTONENTRY_CHECK(obj)                              \
146   if (EINA_UNLIKELY(!efl_isa((obj), ELM_MULTIBUTTONENTRY_CLASS))) \
147     return
148 
149 #define ELM_MULTIBUTTONENTRY_ITEM_CHECK(it)                 \
150   if (EINA_UNLIKELY(!efl_isa((it->base->eo_obj), ELM_MULTIBUTTONENTRY_ITEM_CLASS))) \
151     return
152 
153 #define ELM_MULTIBUTTONENTRY_ITEM_CHECK_OR_RETURN(it, ...)             \
154   if (EINA_UNLIKELY(!efl_isa((it->base->eo_obj), ELM_MULTIBUTTONENTRY_ITEM_CLASS))) \
155     return __VA_ARGS__;
156 
157 #endif
158