Initialize Tizen 2.3
[framework/uifw/elementary.git] / mobile / src / lib / elm_widget_button.h
1 #ifndef ELM_WIDGET_BUTTON_H
2 #define ELM_WIDGET_BUTTON_H
3
4 #include "elm_widget_layout.h"
5
6 /**
7  * @addtogroup Widget
8  * @{
9  *
10  * @section elm-button-class The Elementary Button Class
11  *
12  * Elementary, besides having the @ref Button widget, exposes its
13  * foundation -- the Elementary Button Class -- in order to create
14  * other widgets which are, basically, a button with some more logic
15  * on top.
16  */
17
18 /**
19  * @def ELM_BUTTON_CLASS
20  *
21  * Use this macro to cast whichever subclass of
22  * #Elm_Button_Smart_Class into it, so to access its fields.
23  *
24  * @ingroup Widget
25  */
26 #define ELM_BUTTON_CLASS(x) ((Elm_Button_Smart_Class *)x)
27
28 /**
29  * @def ELM_BUTTON_DATA
30  *
31  * Use this macro to cast whichever subdata of
32  * #Elm_Button_Smart_Data into it, so to access its fields.
33  *
34  * @ingroup Widget
35  */
36 #define ELM_BUTTON_DATA(x)  ((Elm_Button_Smart_Data *)x)
37
38 /**
39  * @def ELM_BUTTON_SMART_CLASS_VERSION
40  *
41  * Current version for Elementary button @b base smart class, a value
42  * which goes to _Elm_Button_Smart_Class::version.
43  *
44  * @ingroup Widget
45  */
46 #define ELM_BUTTON_SMART_CLASS_VERSION 1
47
48 /**
49  * @def ELM_BUTTON_SMART_CLASS_INIT
50  *
51  * Initializer for a whole #Elm_Button_Smart_Class structure, with
52  * @c NULL values on its specific fields.
53  *
54  * @param smart_class_init initializer to use for the "base" field
55  * (#Evas_Smart_Class).
56  *
57  * @see EVAS_SMART_CLASS_INIT_NULL
58  * @see EVAS_SMART_CLASS_INIT_NAME_VERSION
59  * @see ELM_BUTTON_SMART_CLASS_INIT_NULL
60  * @see ELM_BUTTON_SMART_CLASS_INIT_NAME_VERSION
61  *
62  * @ingroup Widget
63  */
64 #define ELM_BUTTON_SMART_CLASS_INIT(smart_class_init) \
65   {smart_class_init, ELM_BUTTON_SMART_CLASS_VERSION, EINA_TRUE}
66
67 /**
68  * @def ELM_BUTTON_SMART_CLASS_INIT_NULL
69  *
70  * Initializer to zero out a whole #Elm_Button_Smart_Class structure.
71  *
72  * @see ELM_BUTTON_SMART_CLASS_INIT_NAME_VERSION
73  * @see ELM_BUTTON_SMART_CLASS_INIT
74  *
75  * @ingroup Widget
76  */
77 #define ELM_BUTTON_SMART_CLASS_INIT_NULL \
78   ELM_BUTTON_SMART_CLASS_INIT(EVAS_SMART_CLASS_INIT_NULL)
79
80 /**
81  * @def ELM_BUTTON_SMART_CLASS_INIT_NAME_VERSION
82  *
83  * Initializer to zero out a whole #Elm_Button_Smart_Class structure and
84  * set its name and version.
85  *
86  * This is similar to #ELM_BUTTON_SMART_CLASS_INIT_NULL, but it will
87  * also set the version field of #Elm_Button_Smart_Class (base field)
88  * to the latest #ELM_BUTTON_SMART_CLASS_VERSION and name it to the
89  * specific value.
90  *
91  * It will keep a reference to the name field as a <c>"const char *"</c>,
92  * i.e., the name must be available while the structure is
93  * used (hint: static or global variable!) and must not be modified.
94  *
95  * @see ELM_BUTTON_SMART_CLASS_INIT_NULL
96  * @see ELM_BUTTON_SMART_CLASS_INIT
97  *
98  * @ingroup Widget
99  */
100 #define ELM_BUTTON_SMART_CLASS_INIT_NAME_VERSION(name) \
101   ELM_BUTTON_SMART_CLASS_INIT(ELM_LAYOUT_SMART_CLASS_INIT_NAME_VERSION(name))
102
103 /**
104  * Elementary button base smart class. This inherits directly from
105  * #Elm_Layout_Smart_Class and is meant to build widgets extending the
106  * behavior of a button.
107  *
108  * All of the functions listed on @ref Button namespace will work for
109  * objects deriving from #Elm_Button_Smart_Class.
110  */
111 typedef struct _Elm_Button_Smart_Class
112 {
113    Elm_Layout_Smart_Class base; /**< Layout widget class struct, since we're inheriting from it */
114
115    int                    version; /**< Version of this smart class definition */
116
117    Eina_Bool              admits_autorepeat : 1; /**< Whether the button objects of this class admit auto-repetition of click events, when one holds the click on them. This is true by default. */
118 } Elm_Button_Smart_Class;
119
120 /**
121  * Base widget smart data extended with button instance data.
122  */
123 typedef struct _Elm_Button_Smart_Data
124 {
125    Elm_Layout_Smart_Data base; /**< Base widget smart data as first member obligatory, as we're inheriting from it */
126
127    /* auto-repeat stuff */
128    double                ar_threshold; /**< Time to wait until first auto-repeated click is generated */
129    double                ar_interval; /**< Time frame for subsequent auto-repeated clicks, after the first automatic one is triggerred */
130
131    Ecore_Timer          *timer; /**< Internal timer object for auto-repeat behavior */
132
133    Eina_Bool             autorepeat : 1; /**< Whether auto-repetition of clicks is enabled or not (bound to _Elm_Button_Smart_Class::admits_autorepeat) */
134    Eina_Bool             repeating : 1; /**< Whether auto-repetition is going on */
135 } Elm_Button_Smart_Data;
136
137 /**
138  * @}
139  */
140
141 EAPI const Elm_Button_Smart_Class *elm_button_smart_class_get(void);
142
143 #define ELM_BUTTON_DATA_GET(o, sd) \
144   Elm_Button_Smart_Data * sd = evas_object_smart_data_get(o)
145
146 #define ELM_BUTTON_DATA_GET_OR_RETURN(o, ptr)        \
147   ELM_BUTTON_DATA_GET(o, ptr);                       \
148   if (!ptr)                                          \
149     {                                                \
150        CRITICAL("No widget data for object %p (%s)", \
151                 o, evas_object_type_get(o));         \
152        return;                                       \
153     }
154
155 #define ELM_BUTTON_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
156   ELM_BUTTON_DATA_GET(o, ptr);                         \
157   if (!ptr)                                            \
158     {                                                  \
159        CRITICAL("No widget data for object %p (%s)",   \
160                 o, evas_object_type_get(o));           \
161        return val;                                     \
162     }
163
164 #define ELM_BUTTON_CHECK(obj)                     \
165   if (!obj || !elm_widget_type_check              \
166         ((obj), ELM_BUTTON_SMART_NAME, __func__)) \
167     return
168
169 #endif