Initialize Tizen 2.3
[framework/uifw/elementary.git] / mobile / src / lib / elm_widget_colorselector.h
1 #ifndef ELM_WIDGET_COLORSELECTOR_H
2 #define ELM_WIDGET_COLORSELECTOR_H
3
4 #include "elm_widget_layout.h"
5
6 /**
7  * @addtogroup Widget
8  * @{
9  *
10  * @section elm-colorselector-class The Elementary Colorselector Class
11  *
12  * Elementary, besides having the @ref Colorselector widget, exposes its
13  * foundation -- the Elementary Colorselector Class -- in order to create other
14  * widgets which are a colorselector with some more logic on top.
15  */
16
17 /**
18  * @def ELM_COLORSELECTOR_CLASS
19  *
20  * Use this macro to cast whichever subclass of
21  * #Elm_Colorselector_Smart_Class into it, so to access its fields.
22  *
23  * @ingroup Widget
24  */
25 #define ELM_COLORSELECTOR_CLASS(x) ((Elm_Colorselector_Smart_Class *)x)
26
27 /**
28  * @def ELM_COLORSELECTOR_DATA
29  *
30  * Use this macro to cast whichever subdata of
31  * #Elm_Colorselector_Smart_Data into it, so to access its fields.
32  *
33  * @ingroup Widget
34  */
35 #define ELM_COLORSELECTOR_DATA(x)  ((Elm_Colorselector_Smart_Data *)x)
36
37 /**
38  * @def ELM_COLORSELECTOR_SMART_CLASS_VERSION
39  *
40  * Current version for Elementary colorselector @b base smart class, a value
41  * which goes to _Elm_Colorselector_Smart_Class::version.
42  *
43  * @ingroup Widget
44  */
45 #define ELM_COLORSELECTOR_SMART_CLASS_VERSION 1
46
47 /**
48  * @def ELM_COLORSELECTOR_SMART_CLASS_INIT
49  *
50  * Initializer for a whole #Elm_Colorselector_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_COLORSELECTOR_SMART_CLASS_INIT_NULL
59  * @see ELM_COLORSELECTOR_SMART_CLASS_INIT_NAME_VERSION
60  *
61  * @ingroup Widget
62  */
63 #define ELM_COLORSELECTOR_SMART_CLASS_INIT(smart_class_init) \
64   {smart_class_init, ELM_COLORSELECTOR_SMART_CLASS_VERSION}
65
66 /**
67  * @def ELM_COLORSELECTOR_SMART_CLASS_INIT_NULL
68  *
69  * Initializer to zero out a whole #Elm_Colorselector_Smart_Class structure.
70  *
71  * @see ELM_COLORSELECTOR_SMART_CLASS_INIT_NAME_VERSION
72  * @see ELM_COLORSELECTOR_SMART_CLASS_INIT
73  *
74  * @ingroup Widget
75  */
76 #define ELM_COLORSELECTOR_SMART_CLASS_INIT_NULL \
77   ELM_COLORSELECTOR_SMART_CLASS_INIT(EVAS_SMART_CLASS_INIT_NULL)
78
79 /**
80  * @def ELM_COLORSELECTOR_SMART_CLASS_INIT_NAME_VERSION
81  *
82  * Initializer to zero out a whole #Elm_Colorselector_Smart_Class structure and
83  * set its name and version.
84  *
85  * This is similar to #ELM_COLORSELECTOR_SMART_CLASS_INIT_NULL, but it will
86  * also set the version field of #Elm_Colorselector_Smart_Class (base field)
87  * to the latest #ELM_COLORSELECTOR_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_COLORSELECTOR_SMART_CLASS_INIT_NULL
95  * @see ELM_COLORSELECTOR_SMART_CLASS_INIT
96  *
97  * @ingroup Widget
98  */
99 #define ELM_COLORSELECTOR_SMART_CLASS_INIT_NAME_VERSION(name) \
100   ELM_COLORSELECTOR_SMART_CLASS_INIT                          \
101     (ELM_LAYOUT_SMART_CLASS_INIT_NAME_VERSION(name))
102
103 /**
104  * Elementary colorselector base smart class. This inherits directly from
105  * #Elm_Layout_Smart_Class and is meant to build widgets extending the
106  * behavior of a colorselector.
107  *
108  * All of the functions listed on @ref Colorselector namespace will work for
109  * objects deriving from #Elm_Colorselector_Smart_Class.
110  */
111 typedef struct _Elm_Colorselector_Smart_Class
112 {
113    Elm_Layout_Smart_Class base;
114
115    int                    version;    /**< Version of this smart class definition */
116 } Elm_Colorselector_Smart_Class;
117
118 typedef struct _Color_Bar_Data Color_Bar_Data;
119
120 /**
121  * Base layout smart data extended with colorselector instance data.
122  */
123 typedef struct _Elm_Colorselector_Smart_Data Elm_Colorselector_Smart_Data;
124 struct _Elm_Colorselector_Smart_Data
125 {
126    Elm_Layout_Smart_Data  base;
127
128    /* for the 3 displaying modes of the widget */
129    Evas_Object           *col_bars_area;
130    Evas_Object           *palette_box;
131    Evas_Object           *picker;
132    Evas_Object           *picker_display;
133    Evas_Object           *entries[4];
134    Evas_Object           *button;
135
136    struct {
137       int                 x, y;
138       Eina_Bool           in;
139 #ifdef HAVE_ELEMENTARY_X
140       Ecore_X_Window       xroot;
141       Ecore_Event_Handler *mouse_motion;
142       Ecore_Event_Handler *key_up;
143       Ecore_Event_Handler *mouse_up;
144 #endif
145    } grab;
146
147    Eina_List             *items, *selected;
148    Color_Bar_Data        *cb_data[4];
149
150    Ecore_Timer           *longpress_timer;
151    const char            *palette_name;
152    Evas_Coord             _x, _y, _w, _h;
153
154    /* color components */
155    int                    r, g, b, a;
156    int                    er, eg, eb;
157    int                    sr, sg, sb;
158    int                    lr, lg, lb;
159
160    double                 h, s, l;
161    Elm_Colorselector_Mode mode, focused;
162    int                    sel_color_type;
163
164    Eina_Bool              longpressed : 1;
165    Eina_Bool              config_load : 1;
166 };
167
168 typedef enum _Color_Type
169 {
170    HUE,
171    SATURATION,
172    LIGHTNESS,
173    ALPHA
174 } Color_Type;
175
176 struct _Color_Bar_Data
177 {
178    Evas_Object *parent;
179    Evas_Object *colorbar;
180    Evas_Object *bar;
181    Evas_Object *lbt;
182    Evas_Object *rbt;
183    Evas_Object *bg_rect;
184    Evas_Object *arrow;
185    Evas_Object *touch_area;
186    Evas_Object *access_obj;
187    Color_Type   color_type;
188 };
189
190 typedef struct _Elm_Color_Item Elm_Color_Item;
191 struct _Elm_Color_Item
192 {
193    ELM_WIDGET_ITEM;
194
195    Evas_Object    *color_obj;
196    Elm_Color_RGBA *color;
197 };
198
199 /**
200  * @}
201  */
202
203 EAPI extern const char ELM_COLORSELECTOR_SMART_NAME[];
204 EAPI const Elm_Colorselector_Smart_Class
205 *elm_colorselector_smart_class_get(void);
206
207 #define ELM_COLORSELECTOR_DATA_GET(o, sd) \
208   Elm_Colorselector_Smart_Data * sd = evas_object_smart_data_get(o)
209
210 #define ELM_COLORSELECTOR_DATA_GET_OR_RETURN(o, ptr) \
211   ELM_COLORSELECTOR_DATA_GET(o, ptr);                \
212   if (!ptr)                                          \
213     {                                                \
214        CRITICAL("No widget data for object %p (%s)", \
215                 o, evas_object_type_get(o));         \
216        return;                                       \
217     }
218
219 #define ELM_COLORSELECTOR_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
220   ELM_COLORSELECTOR_DATA_GET(o, ptr);                         \
221   if (!ptr)                                                   \
222     {                                                         \
223        CRITICAL("No widget data for object %p (%s)",          \
224                 o, evas_object_type_get(o));                  \
225        return val;                                            \
226     }
227
228 #define ELM_COLORSELECTOR_CHECK(obj)                     \
229   if (!obj || !elm_widget_type_check                     \
230         ((obj), ELM_COLORSELECTOR_SMART_NAME, __func__)) \
231     return
232
233 #define ELM_COLORSELECTOR_ITEM_CHECK(it)                    \
234   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, ); \
235   ELM_COLORSELECTOR_CHECK(it->base.widget);
236
237 #define ELM_COLORSELECTOR_ITEM_CHECK_OR_RETURN(it, ...)                \
238   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
239   ELM_COLORSELECTOR_CHECK(it->base.widget) __VA_ARGS__;
240
241 #endif