tizen 2.3.1 release
[framework/uifw/elementary.git] / src / lib / elm_widget_toolbar.h
1 #ifndef ELM_WIDGET_TOOLBAR_H
2 #define ELM_WIDGET_TOOLBAR_H
3
4 #include "elm_interface_scrollable.h"
5 #include "els_box.h"
6
7 /**
8  * @internal
9  * @addtogroup Widget
10  * @{
11  *
12  * @section elm-toolbar-class The Elementary Toolbar Class
13  *
14  * Elementary, besides having the @ref Toolbar widget, exposes its
15  * foundation -- the Elementary Toolbar Class -- in order to create other
16  * widgets which are a toolbar with some more logic on top.
17  */
18
19 /**
20  * @def ELM_TOOLBAR_CLASS
21  *
22  * Use this macro to cast whichever subclass of
23  * #Elm_Toolbar_Smart_Class into it, so to access its fields.
24  *
25  * @ingroup Widget
26  */
27 #define ELM_TOOLBAR_CLASS(x) ((Elm_Toolbar_Smart_Class *)x)
28
29 /**
30  * @def ELM_TOOLBAR_DATA
31  *
32  * Use this macro to cast whichever subdata of
33  * #Elm_Toolbar_Smart_Data into it, so to access its fields.
34  *
35  * @ingroup Widget
36  */
37 #define ELM_TOOLBAR_DATA(x)  ((Elm_Toolbar_Smart_Data *)x)
38
39 /**
40  * @def ELM_TOOLBAR_SMART_CLASS_VERSION
41  *
42  * Current version for Elementary toolbar @b base smart class, a value
43  * which goes to _Elm_Toolbar_Smart_Class::version.
44  *
45  * @ingroup Widget
46  */
47 #define ELM_TOOLBAR_SMART_CLASS_VERSION 1
48
49 /**
50  * @def ELM_TOOLBAR_SMART_CLASS_INIT
51  *
52  * Initializer for a whole #Elm_Toolbar_Smart_Class structure, with
53  * @c NULL values on its specific fields.
54  *
55  * @param smart_class_init initializer to use for the "base" field
56  * (#Evas_Smart_Class).
57  *
58  * @see EVAS_SMART_CLASS_INIT_NULL
59  * @see EVAS_SMART_CLASS_INIT_NAME_VERSION
60  * @see ELM_TOOLBAR_SMART_CLASS_INIT_NULL
61  * @see ELM_TOOLBAR_SMART_CLASS_INIT_NAME_VERSION
62  *
63  * @ingroup Widget
64  */
65 #define ELM_TOOLBAR_SMART_CLASS_INIT(smart_class_init) \
66   {smart_class_init, ELM_TOOLBAR_SMART_CLASS_VERSION}
67
68 /**
69  * @def ELM_TOOLBAR_SMART_CLASS_INIT_NULL
70  *
71  * Initializer to zero out a whole #Elm_Toolbar_Smart_Class structure.
72  *
73  * @see ELM_TOOLBAR_SMART_CLASS_INIT_NAME_VERSION
74  * @see ELM_TOOLBAR_SMART_CLASS_INIT
75  *
76  * @ingroup Widget
77  */
78 #define ELM_TOOLBAR_SMART_CLASS_INIT_NULL \
79   ELM_TOOLBAR_SMART_CLASS_INIT(EVAS_SMART_CLASS_INIT_NULL)
80
81 /**
82  * @def ELM_TOOLBAR_SMART_CLASS_INIT_NAME_VERSION
83  *
84  * Initializer to zero out a whole #Elm_Toolbar_Smart_Class structure and
85  * set its name and version.
86  *
87  * This is similar to #ELM_TOOLBAR_SMART_CLASS_INIT_NULL, but it will
88  * also set the version field of #Elm_Toolbar_Smart_Class (base field)
89  * to the latest #ELM_TOOLBAR_SMART_CLASS_VERSION and name it to the
90  * specific value.
91  *
92  * It will keep a reference to the name field as a <c>"const char *"</c>,
93  * i.e., the name must be available while the structure is
94  * used (hint: static or global variable!) and must not be modified.
95  *
96  * @see ELM_TOOLBAR_SMART_CLASS_INIT_NULL
97  * @see ELM_TOOLBAR_SMART_CLASS_INIT
98  *
99  * @ingroup Widget
100  */
101 #define ELM_TOOLBAR_SMART_CLASS_INIT_NAME_VERSION(name) \
102   ELM_TOOLBAR_SMART_CLASS_INIT(ELM_WIDGET_SMART_CLASS_INIT_NAME_VERSION(name))
103
104 /**
105  * Elementary toolbar base smart class. This inherits directly from
106  * #Elm_Widget_Smart_Class and is meant to build widgets extending the
107  * behavior of a toolbar.
108  *
109  * All of the functions listed on @ref Toolbar namespace will work for
110  * objects deriving from #Elm_Toolbar_Smart_Class.
111  */
112 typedef struct _Elm_Toolbar_Smart_Class
113 {
114    Elm_Widget_Smart_Class base;
115
116    int                    version; /**< Version of this smart class definition */
117 } Elm_Toolbar_Smart_Class;
118
119 typedef struct _Elm_Toolbar_Item Elm_Toolbar_Item;
120
121 /**
122  * Base widget smart data extended with toolbar instance data.
123  */
124 typedef struct _Elm_Toolbar_Smart_Data Elm_Toolbar_Smart_Data;
125 struct _Elm_Toolbar_Smart_Data
126 {
127    Elm_Widget_Smart_Data                 base; /* base widget smart data as
128                                                 * first member obligatory, as
129                                                 * we're inheriting from it */
130
131    Evas_Object                          *hit_rect;
132    const Elm_Scrollable_Smart_Interface *s_iface;
133
134    Evas_Object                          *bx, *more, *bx_more, *bx_more2;
135    Evas_Object                          *menu_parent;
136    Eina_Inlist                          *items;
137    Elm_Toolbar_Item                     *more_item;
138    Elm_Toolbar_Item                     *selected_item, *highlighted_item;
139    Elm_Toolbar_Item                     *reorder_empty, *reorder_item;
140    Elm_Toolbar_Shrink_Mode               shrink_mode;
141    Elm_Icon_Lookup_Order                 lookup_order;
142    int                                   theme_icon_size, priv_icon_size,
143                                          icon_size;
144    int                                   standard_priority;
145    unsigned int                          item_count;
146    unsigned int                          separator_count;
147    double                                align;
148    Elm_Object_Select_Mode                select_mode;
149    Ecore_Timer                          *long_timer;
150    Ecore_Job                            *resize_job;
151
152    Eina_Bool                             vertical : 1;
153    Eina_Bool                             long_press : 1;
154    Eina_Bool                             homogeneous : 1;
155    Eina_Bool                             on_deletion : 1;
156    Eina_Bool                             reorder_mode : 1;
157    Eina_Bool                             transverse_expanded : 1;
158    Eina_Bool                             mouse_down : 1;
159 };
160
161 struct _Elm_Toolbar_Item
162 {
163    ELM_WIDGET_ITEM;
164    EINA_INLIST;
165
166    const char   *label;
167    const char   *icon_str;
168    Evas_Object  *icon;
169    Evas_Object  *object;
170    Evas_Object  *o_menu;
171    Evas_Object  *in_box;
172    Evas_Object  *proxy;
173    Evas_Smart_Cb func;
174    Elm_Transit  *trans;
175    Elm_Toolbar_Item *reorder_to;
176    struct
177    {
178       int       priority;
179       Eina_Bool visible : 1;
180    } prio;
181
182    Eina_List    *states;
183    Eina_List    *current_state;
184
185    Eina_Bool     separator : 1;
186    Eina_Bool     selected : 1;
187    Eina_Bool     menu : 1;
188    Eina_Bool     on_move : 1;
189
190    //******************** TIZEN Only
191    Eina_Bool     pressed : 1;
192    //****************************
193 };
194
195 struct _Elm_Toolbar_Item_State
196 {
197    const char   *label;
198    const char   *icon_str;
199    Evas_Object  *icon;
200    Evas_Smart_Cb func;
201    const void   *data;
202 };
203
204 /**
205  * @}
206  */
207
208 EAPI extern const char ELM_TOOLBAR_SMART_NAME[];
209 EAPI const Elm_Toolbar_Smart_Class
210 *elm_toolbar_smart_class_get(void);
211
212 #define ELM_TOOLBAR_DATA_GET(o, sd) \
213   Elm_Toolbar_Smart_Data * sd = evas_object_smart_data_get(o)
214
215 #define ELM_TOOLBAR_DATA_GET_OR_RETURN(o, ptr)       \
216   ELM_TOOLBAR_DATA_GET(o, ptr);                      \
217   if (!ptr)                                          \
218     {                                                \
219        CRITICAL("No widget data for object %p (%s)", \
220                 o, evas_object_type_get(o));         \
221        return;                                       \
222     }
223
224 #define ELM_TOOLBAR_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
225   ELM_TOOLBAR_DATA_GET(o, ptr);                         \
226   if (!ptr)                                             \
227     {                                                   \
228        CRITICAL("No widget data for object %p (%s)",    \
229                 o, evas_object_type_get(o));            \
230        return val;                                      \
231     }
232
233 #define ELM_TOOLBAR_CHECK(obj)                                          \
234   if (!obj || !elm_widget_type_check((obj),                             \
235                                      ELM_TOOLBAR_SMART_NAME, __func__)) \
236     return
237
238 #define ELM_TOOLBAR_ITEM_CHECK(it)                          \
239   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, ); \
240   ELM_TOOLBAR_CHECK(it->base.widget);
241
242 #define ELM_TOOLBAR_ITEM_CHECK_OR_RETURN(it, ...)                      \
243   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
244   ELM_TOOLBAR_CHECK(it->base.widget) __VA_ARGS__;
245
246 #define ELM_TOOLBAR_ITEM_CHECK_OR_GOTO(it, label)              \
247   ELM_WIDGET_ITEM_CHECK_OR_GOTO((Elm_Widget_Item *)it, label); \
248   if (!it->base.widget || !elm_widget_type_check               \
249         ((it->base.widget), ELM_TOOLBAR_SMART_NAME, __func__)) goto label;
250
251 #endif