[access] call a callback function with information
[framework/uifw/elementary.git] / src / lib / elm_widget_menu.h
1 #ifndef ELM_WIDGET_MENU_H
2 #define ELM_WIDGET_MENU_H
3
4 /**
5  * @addtogroup Widget
6  * @{
7  *
8  * @section elm-menu-class The Elementary Menu Class
9  *
10  * Elementary, besides having the @ref Menu widget, exposes its
11  * foundation -- the Elementary Menu Class -- in order to create
12  * other widgets which are a menu with some more logic on top.
13  */
14
15 /**
16  * @def ELM_MENU_CLASS
17  *
18  * Use this macro to cast whichever subclass of
19  * #Elm_Menu_Smart_Class into it, so to access its fields.
20  *
21  * @ingroup Widget
22  */
23 #define ELM_MENU_CLASS(x) ((Elm_Menu_Smart_Class *) x)
24
25 /**
26  * @def ELM_MENU_DATA
27  *
28  * Use this macro to cast whichever subdata of
29  * #Elm_Menu_Smart_Data into it, so to access its fields.
30  *
31  * @ingroup Widget
32  */
33 #define ELM_MENU_DATA(x) ((Elm_Menu_Smart_Data *) x)
34
35 /**
36  * @def ELM_MENU_SMART_CLASS_VERSION
37  *
38  * Current version for Elementary menu @b base smart class, a value
39  * which goes to _Elm_Menu_Smart_Class::version.
40  *
41  * @ingroup Widget
42  */
43 #define ELM_MENU_SMART_CLASS_VERSION 1
44
45 /**
46  * @def ELM_MENU_SMART_CLASS_INIT
47  *
48  * Initializer for a whole #Elm_Menu_Smart_Class structure, with
49  * @c NULL values on its specific fields.
50  *
51  * @param smart_class_init initializer to use for the "base" field
52  * (#Evas_Smart_Class).
53  *
54  * @see EVAS_SMART_CLASS_INIT_NULL
55  * @see EVAS_SMART_CLASS_INIT_NAME_VERSION
56  * @see ELM_MENU_SMART_CLASS_INIT_NULL
57  * @see ELM_MENU_SMART_CLASS_INIT_NAME_VERSION
58  *
59  * @ingroup Widget
60  */
61 #define ELM_MENU_SMART_CLASS_INIT(smart_class_init)                        \
62   {smart_class_init, ELM_MENU_SMART_CLASS_VERSION}
63
64 /**
65  * @def ELM_MENU_SMART_CLASS_INIT_NULL
66  *
67  * Initializer to zero out a whole #Elm_Menu_Smart_Class structure.
68  *
69  * @see ELM_MENU_SMART_CLASS_INIT_NAME_VERSION
70  * @see ELM_MENU_SMART_CLASS_INIT
71  *
72  * @ingroup Widget
73  */
74 #define ELM_MENU_SMART_CLASS_INIT_NULL \
75   ELM_MENU_SMART_CLASS_INIT(EVAS_SMART_CLASS_INIT_NULL)
76
77 /**
78  * @def ELM_MENU_SMART_CLASS_INIT_NAME_VERSION
79  *
80  * Initializer to zero out a whole #Elm_Menu_Smart_Class structure and
81  * set its name and version.
82  *
83  * This is similar to #ELM_MENU_SMART_CLASS_INIT_NULL, but it will
84  * also set the version field of #Elm_Menu_Smart_Class (base field)
85  * to the latest #ELM_MENU_SMART_CLASS_VERSION and name it to the
86  * specific value.
87  *
88  * It will keep a reference to the name field as a <c>"const char *"</c>,
89  * i.e., the name must be available while the structure is
90  * used (hint: static or global variable!) and must not be modified.
91  *
92  * @see ELM_MENU_SMART_CLASS_INIT_NULL
93  * @see ELM_MENU_SMART_CLASS_INIT
94  *
95  * @ingroup Widget
96  */
97 #define ELM_MENU_SMART_CLASS_INIT_NAME_VERSION(name) \
98   ELM_MENU_SMART_CLASS_INIT(ELM_WIDGET_SMART_CLASS_INIT_NAME_VERSION(name))
99
100 /**
101  * Elementary menu base smart class. This inherits directly from
102  * #Elm_Widget_Smart_Class and is meant to build widgets extending the
103  * behavior of a menu.
104  *
105  * All of the functions listed on @ref Menu namespace will work for
106  * objects deriving from #Elm_Menu_Smart_Class.
107  */
108 typedef struct _Elm_Menu_Smart_Class
109 {
110    Elm_Widget_Smart_Class base;
111
112    int                    version; /**< Version of this smart class definition */
113 } Elm_Menu_Smart_Class;
114
115 /**
116  * Base widget smart data extended with menu instance data.
117  */
118 typedef struct _Elm_Menu_Smart_Data Elm_Menu_Smart_Data;
119 struct _Elm_Menu_Smart_Data
120 {
121    Elm_Widget_Smart_Data base;    /* base widget smart data as
122                                    * first member obligatory, as
123                                    * we're inheriting from it */
124
125    Evas_Object          *hv, *bx, *location, *parent;
126
127    Eina_List            *items;
128    Evas_Coord            xloc, yloc;
129 };
130
131 typedef struct _Elm_Menu_Item       Elm_Menu_Item;
132 struct _Elm_Menu_Item
133 {
134    ELM_WIDGET_ITEM;
135
136    Elm_Menu_Item *parent;
137    Evas_Object   *content;
138    const char    *icon_str;
139    const char    *label;
140    Evas_Smart_Cb  func;
141    unsigned int   idx;
142
143    struct
144    {
145       Evas_Object *hv, *bx, *location;
146       Eina_List   *items;
147       Eina_Bool    open : 1;
148    } submenu;
149
150    Eina_Bool      separator : 1;
151    Eina_Bool      selected : 1;
152    Eina_Bool      object_item : 1;
153 };
154
155 /**
156  * @}
157  */
158
159 EAPI extern const char ELM_MENU_SMART_NAME[];
160 EAPI const Elm_Menu_Smart_Class *elm_menu_smart_class_get(void);
161
162 #define ELM_MENU_DATA_GET(o, sd) \
163   Elm_Menu_Smart_Data * sd = evas_object_smart_data_get(o)
164
165 #define ELM_MENU_DATA_GET_OR_RETURN(o, ptr)          \
166   ELM_MENU_DATA_GET(o, ptr);                         \
167   if (!ptr)                                          \
168     {                                                \
169        CRITICAL("No widget data for object %p (%s)", \
170                 o, evas_object_type_get(o));         \
171        return;                                       \
172     }
173
174 #define ELM_MENU_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
175   ELM_MENU_DATA_GET(o, ptr);                         \
176   if (!ptr)                                          \
177     {                                                \
178        CRITICAL("No widget data for object %p (%s)", \
179                 o, evas_object_type_get(o));         \
180        return val;                                   \
181     }
182
183 #define ELM_MENU_CHECK(obj)                                                 \
184   if (!obj || !elm_widget_type_check((obj), ELM_MENU_SMART_NAME, __func__)) \
185     return
186
187 #define ELM_MENU_ITEM_CHECK(it)                             \
188   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, ); \
189   ELM_MENU_CHECK(it->base.widget);
190
191 #define ELM_MENU_ITEM_CHECK_OR_RETURN(it, ...)                         \
192   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
193   ELM_MENU_CHECK(it->base.widget) __VA_ARGS__;
194
195 #endif