[access] call a callback function with information
[framework/uifw/elementary.git] / src / lib / elm_widget_popup.h
1 #ifndef ELM_WIDGET_POPUP_H
2 #define ELM_WIDGET_POPUP_H
3
4 #include "elm_widget_layout.h"
5
6 /**
7  * @addtogroup Widget
8  * @{
9  *
10  * @section elm-popup-class The Elementary Popup Class
11  *
12  * Elementary, besides having the @ref Popup widget, exposes its
13  * foundation -- the Elementary Popup Class -- in order to create other
14  * widgets which are a popup with some more logic on top.
15  */
16
17 /**
18  * @def ELM_POPUP_CLASS
19  *
20  * Use this macro to cast whichever subclass of
21  * #Elm_Popup_Smart_Class into it, so to access its fields.
22  *
23  * @ingroup Widget
24  */
25 #define ELM_POPUP_CLASS(x) ((Elm_Popup_Smart_Class *)x)
26
27 /**
28  * @def ELM_POPUP_DATA
29  *
30  * Use this macro to cast whichever subdata of
31  * #Elm_Popup_Smart_Data into it, so to access its fields.
32  *
33  * @ingroup Widget
34  */
35 #define ELM_POPUP_DATA(x)  ((Elm_Popup_Smart_Data *)x)
36
37 /**
38  * @def ELM_POPUP_SMART_CLASS_VERSION
39  *
40  * Current version for Elementary popup @b base smart class, a value
41  * which goes to _Elm_Popup_Smart_Class::version.
42  *
43  * @ingroup Widget
44  */
45 #define ELM_POPUP_SMART_CLASS_VERSION 1
46
47 /**
48  * @def ELM_POPUP_SMART_CLASS_INIT
49  *
50  * Initializer for a whole #Elm_Popup_Smart_Class structure, with
51  * @c NULL values on its specific fields.
52  *
53  * @param smart_class_init initializer to use for the "base" field
54  * (#Evas_Smart_Class).
55  *
56  * @see EVAS_SMART_CLASS_INIT_NULL
57  * @see EVAS_SMART_CLASS_INIT_NAME_VERSION
58  * @see ELM_POPUP_SMART_CLASS_INIT_NULL
59  * @see ELM_POPUP_SMART_CLASS_INIT_NAME_VERSION
60  *
61  * @ingroup Widget
62  */
63 #define ELM_POPUP_SMART_CLASS_INIT(smart_class_init) \
64   {smart_class_init, ELM_POPUP_SMART_CLASS_VERSION}
65
66 /**
67  * @def ELM_POPUP_SMART_CLASS_INIT_NULL
68  *
69  * Initializer to zero out a whole #Elm_Popup_Smart_Class structure.
70  *
71  * @see ELM_POPUP_SMART_CLASS_INIT_NAME_VERSION
72  * @see ELM_POPUP_SMART_CLASS_INIT
73  *
74  * @ingroup Widget
75  */
76 #define ELM_POPUP_SMART_CLASS_INIT_NULL \
77   ELM_POPUP_SMART_CLASS_INIT(EVAS_SMART_CLASS_INIT_NULL)
78
79 /**
80  * @def ELM_POPUP_SMART_CLASS_INIT_NAME_VERSION
81  *
82  * Initializer to zero out a whole #Elm_Popup_Smart_Class structure and
83  * set its name and version.
84  *
85  * This is similar to #ELM_POPUP_SMART_CLASS_INIT_NULL, but it will
86  * also set the version field of #Elm_Popup_Smart_Class (base field)
87  * to the latest #ELM_POPUP_SMART_CLASS_VERSION and name it to the
88  * specific value.
89  *
90  * It will keep a reference to the name field as a <c>"const char *"</c>,
91  * i.e., the name must be available while the structure is
92  * used (hint: static or global variable!) and must not be modified.
93  *
94  * @see ELM_POPUP_SMART_CLASS_INIT_NULL
95  * @see ELM_POPUP_SMART_CLASS_INIT
96  *
97  * @ingroup Widget
98  */
99 #define ELM_POPUP_SMART_CLASS_INIT_NAME_VERSION(name) \
100   ELM_POPUP_SMART_CLASS_INIT                          \
101     (ELM_LAYOUT_SMART_CLASS_INIT_NAME_VERSION(name))
102
103 /**
104  * Elementary popup base smart class. This inherits directly from
105  * #Elm_Layout_Smart_Class and is meant to build widgets extending the
106  * behavior of a popup.
107  *
108  * All of the functions listed on @ref Popup namespace will work for
109  * objects deriving from #Elm_Popup_Smart_Class.
110  */
111 typedef struct _Elm_Popup_Smart_Class
112 {
113    Elm_Layout_Smart_Class base;
114
115    int                    version;    /**< Version of this smart class definition */
116 } Elm_Popup_Smart_Class;
117
118 #define ELM_POPUP_ACTION_BUTTON_MAX 3
119
120 typedef struct _Action_Area_Data Action_Area_Data;
121
122 /**
123  * Base layout smart data extended with popup instance data.
124  */
125 typedef struct _Elm_Popup_Smart_Data Elm_Popup_Smart_Data;
126 struct _Elm_Popup_Smart_Data
127 {
128    Elm_Layout_Smart_Data base;
129
130    Evas_Object          *notify;
131    Evas_Object          *title_icon;
132    Evas_Object          *content_area;
133    Evas_Object          *text_content_obj;
134    Evas_Object          *action_area;
135    Evas_Object          *box;
136    Evas_Object          *tbl;
137    Evas_Object          *spacer;
138    Evas_Object          *scr;
139    Evas_Object          *content;
140    Eina_List            *items;
141    const char           *title_text;
142    Action_Area_Data     *buttons[ELM_POPUP_ACTION_BUTTON_MAX];
143    Elm_Wrap_Type         content_text_wrap_type;
144    unsigned int          button_count;
145    Evas_Coord            max_sc_w;
146    Evas_Coord            max_sc_h;
147
148    Eina_Bool             visible : 1;
149    Eina_Bool             no_shift : 1;
150    Eina_Bool             scr_size_recalc : 1;
151 };
152
153 typedef struct _Elm_Popup_Item Elm_Popup_Item;
154 struct _Elm_Popup_Item
155 {
156    Elm_Widget_Item base;
157
158    const char     *label;
159    Evas_Object    *icon;
160    Evas_Smart_Cb   func;
161    Eina_Bool       disabled : 1;
162 };
163
164 struct _Action_Area_Data
165 {
166    Evas_Object *obj;
167    Evas_Object *btn;
168    Eina_Bool    delete_me;
169 };
170
171 /**
172  * @}
173  */
174
175 EAPI extern const char ELM_POPUP_SMART_NAME[];
176 EAPI const Elm_Popup_Smart_Class *elm_popup_smart_class_get(void);
177
178 #define ELM_POPUP_DATA_GET(o, sd) \
179   Elm_Popup_Smart_Data * sd = evas_object_smart_data_get(o)
180
181 #define ELM_POPUP_DATA_GET_OR_RETURN(o, ptr)         \
182   ELM_POPUP_DATA_GET(o, ptr);                        \
183   if (!ptr)                                          \
184     {                                                \
185        CRITICAL("No widget data for object %p (%s)", \
186                 o, evas_object_type_get(o));         \
187        return;                                       \
188     }
189
190 #define ELM_POPUP_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
191   ELM_POPUP_DATA_GET(o, ptr);                         \
192   if (!ptr)                                           \
193     {                                                 \
194        CRITICAL("No widget data for object %p (%s)",  \
195                 o, evas_object_type_get(o));          \
196        return val;                                    \
197     }
198
199 #define ELM_POPUP_CHECK(obj)                     \
200   if (!obj || !elm_widget_type_check             \
201         ((obj), ELM_POPUP_SMART_NAME, __func__)) \
202     return
203
204 #define ELM_POPUP_ITEM_CHECK(it)                            \
205   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, ); \
206   ELM_POPUP_CHECK(it->base.widget);
207
208 #define ELM_POPUP_ITEM_CHECK_OR_RETURN(it, ...)                        \
209   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
210   ELM_POPUP_CHECK(it->base.widget) __VA_ARGS__;
211
212 #endif