[access] call a callback function with information
[framework/uifw/elementary.git] / src / lib / elm_widget_spinner.h
1 #ifndef ELM_WIDGET_SPINNER_H
2 #define ELM_WIDGET_SPINNER_H
3
4 #include "elm_widget_layout.h"
5
6 #ifdef HAVE_EIO
7 # include <Eio.h>
8 #endif
9
10 /**
11  * @addtogroup Widget
12  * @{
13  *
14  * @section elm-spinner-class The Elementary Spinner Class
15  *
16  * Elementary, besides having the @ref Spinner widget, exposes its
17  * foundation -- the Elementary Spinner Class -- in order to create other
18  * widgets which are a spinner with some more logic on top.
19  */
20
21 /**
22  * @def ELM_SPINNER_CLASS
23  *
24  * Use this macro to cast whichever subclass of
25  * #Elm_Spinner_Smart_Class into it, so to access its fields.
26  *
27  * @ingroup Widget
28  */
29 #define ELM_SPINNER_CLASS(x) ((Elm_Spinner_Smart_Class *)x)
30
31 /**
32  * @def ELM_SPINNER_DATA
33  *
34  * Use this macro to cast whichever subdata of
35  * #Elm_Spinner_Smart_Data into it, so to access its fields.
36  *
37  * @ingroup Widget
38  */
39 #define ELM_SPINNER_DATA(x)  ((Elm_Spinner_Smart_Data *)x)
40
41 /**
42  * @def ELM_SPINNER_SMART_CLASS_VERSION
43  *
44  * Current version for Elementary spinner @b base smart class, a value
45  * which goes to _Elm_Spinner_Smart_Class::version.
46  *
47  * @ingroup Widget
48  */
49 #define ELM_SPINNER_SMART_CLASS_VERSION 1
50
51 /**
52  * @def ELM_SPINNER_SMART_CLASS_INIT
53  *
54  * Initializer for a whole #Elm_Spinner_Smart_Class structure, with
55  * @c NULL values on its specific fields.
56  *
57  * @param smart_class_init initializer to use for the "base" field
58  * (#Evas_Smart_Class).
59  *
60  * @see EVAS_SMART_CLASS_INIT_NULL
61  * @see EVAS_SMART_CLASS_INIT_NAME_VERSION
62  * @see ELM_SPINNER_SMART_CLASS_INIT_NULL
63  * @see ELM_SPINNER_SMART_CLASS_INIT_NAME_VERSION
64  *
65  * @ingroup Widget
66  */
67 #define ELM_SPINNER_SMART_CLASS_INIT(smart_class_init) \
68   {smart_class_init, ELM_SPINNER_SMART_CLASS_VERSION}
69
70 /**
71  * @def ELM_SPINNER_SMART_CLASS_INIT_NULL
72  *
73  * Initializer to zero out a whole #Elm_Spinner_Smart_Class structure.
74  *
75  * @see ELM_SPINNER_SMART_CLASS_INIT_NAME_VERSION
76  * @see ELM_SPINNER_SMART_CLASS_INIT
77  *
78  * @ingroup Widget
79  */
80 #define ELM_SPINNER_SMART_CLASS_INIT_NULL \
81   ELM_SPINNER_SMART_CLASS_INIT(EVAS_SMART_CLASS_INIT_NULL)
82
83 /**
84  * @def ELM_SPINNER_SMART_CLASS_INIT_NAME_VERSION
85  *
86  * Initializer to zero out a whole #Elm_Spinner_Smart_Class structure and
87  * set its name and version.
88  *
89  * This is similar to #ELM_SPINNER_SMART_CLASS_INIT_NULL, but it will
90  * also set the version field of #Elm_Spinner_Smart_Class (base field)
91  * to the latest #ELM_SPINNER_SMART_CLASS_VERSION and name it to the
92  * specific value.
93  *
94  * It will keep a reference to the name field as a <c>"const char *"</c>,
95  * i.e., the name must be available while the structure is
96  * used (hint: static or global variable!) and must not be modified.
97  *
98  * @see ELM_SPINNER_SMART_CLASS_INIT_NULL
99  * @see ELM_SPINNER_SMART_CLASS_INIT
100  *
101  * @ingroup Widget
102  */
103 #define ELM_SPINNER_SMART_CLASS_INIT_NAME_VERSION(name) \
104   ELM_SPINNER_SMART_CLASS_INIT                          \
105     (ELM_LAYOUT_SMART_CLASS_INIT_NAME_VERSION(name))
106
107 /**
108  * Elementary spinner base smart class. This inherits directly from
109  * #Elm_Layout_Smart_Class and is meant to build widgets extending the
110  * behavior of a spinner.
111  *
112  * All of the functions listed on @ref Spinner namespace will work for
113  * objects deriving from #Elm_Spinner_Smart_Class.
114  */
115 typedef struct _Elm_Spinner_Smart_Class
116 {
117    Elm_Layout_Smart_Class base;
118
119    int                    version;    /**< Version of this smart class definition */
120 } Elm_Spinner_Smart_Class;
121
122 /**
123  * Base layout smart data extended with spinner instance data.
124  */
125 typedef struct _Elm_Spinner_Smart_Data    Elm_Spinner_Smart_Data;
126 struct _Elm_Spinner_Smart_Data
127 {
128    Elm_Layout_Smart_Data base;
129
130    Evas_Object          *ent;
131    const char           *label;
132    double                val, val_min, val_max, orig_val, step, val_base;
133    double                drag_start_pos, spin_speed, interval, first_interval;
134    int                   round;
135    Ecore_Timer          *delay, *spin;
136    Eina_List            *special_values;
137
138    Eina_Bool             entry_visible : 1;
139    Eina_Bool             dragging : 1;
140    Eina_Bool             editable : 1;
141    Eina_Bool             wrap : 1;
142 };
143
144 typedef struct _Elm_Spinner_Special_Value Elm_Spinner_Special_Value;
145 struct _Elm_Spinner_Special_Value
146 {
147    double      value;
148    const char *label;
149 };
150
151 /**
152  * @}
153  */
154
155 EAPI extern const char ELM_SPINNER_SMART_NAME[];
156 EAPI const Elm_Spinner_Smart_Class *elm_spinner_smart_class_get(void);
157
158 #define ELM_SPINNER_DATA_GET(o, sd) \
159   Elm_Spinner_Smart_Data * sd = evas_object_smart_data_get(o)
160
161 #define ELM_SPINNER_DATA_GET_OR_RETURN(o, ptr)       \
162   ELM_SPINNER_DATA_GET(o, ptr);                      \
163   if (!ptr)                                          \
164     {                                                \
165        CRITICAL("No widget data for object %p (%s)", \
166                 o, evas_object_type_get(o));         \
167        return;                                       \
168     }
169
170 #define ELM_SPINNER_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
171   ELM_SPINNER_DATA_GET(o, ptr);                         \
172   if (!ptr)                                             \
173     {                                                   \
174        CRITICAL("No widget data for object %p (%s)",    \
175                 o, evas_object_type_get(o));            \
176        return val;                                      \
177     }
178
179 #define ELM_SPINNER_CHECK(obj)                     \
180   if (!obj || !elm_widget_type_check               \
181         ((obj), ELM_SPINNER_SMART_NAME, __func__)) \
182     return
183
184 #endif