Merge "[Issue fix]: background not deleted even when selector was deleted."
[framework/uifw/elementary.git] / src / lib / elm_colorselector.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 #define BASE_STEP 360.0
5 #define HUE_STEP 360.0
6 #define SAT_STEP 128.0
7 #define LIG_STEP 256.0
8 #define ALP_STEP 256.0
9 #define DEFAULT_HOR_PAD 10
10 #define DEFAULT_VER_PAD 10
11
12 typedef enum _Color_Type
13 {
14    HUE,
15    SATURATION,
16    LIGHTNESS,
17    ALPHA
18 } Color_Type;
19
20 typedef struct _Colorselector_Data Colorselector_Data;
21 struct _Colorselector_Data
22 {
23    Evas_Object *parent;
24    Evas_Object *colorbar;
25    Evas_Object *bar;
26    Evas_Object *lbt;
27    Evas_Object *rbt;
28    Evas_Object *bg_rect;
29    Evas_Object *arrow;
30    Evas_Object *touch_area;
31    Color_Type color_type;
32 };
33
34 typedef struct _Widget_Data Widget_Data;
35 typedef struct _Elm_Color_Item Elm_Color_Item;
36 struct _Widget_Data
37 {
38    Evas_Object *sel;
39    Evas_Object *base;
40    Evas_Object *box;
41    Eina_List *items;
42    Colorselector_Data *cp[4];
43    Ecore_Timer *longpress_timer;
44    const char *palette_name;
45    Evas_Coord _x, _y, _w, _h;
46    int r, g, b, a;
47    int er, eg, eb;
48    int sr, sg, sb;
49    int lr, lg, lb;
50    double h, s, l;
51    Elm_Colorselector_Mode mode;
52    Eina_Bool longpressed : 1;
53    Eina_Bool config_load: 1;
54 };
55
56 struct _Elm_Color_Item
57 {
58    ELM_WIDGET_ITEM;
59    Evas_Object *color_obj;
60    Elm_Color_RGBA *color;
61 };
62
63 static const char *widtype = NULL;
64
65 static void _del_hook(Evas_Object *obj);
66 static void _theme_hook(Evas_Object *obj);
67 static void _sizing_eval(Evas_Object *obj);
68 static void _resize_cb(void *data, Evas *a, Evas_Object *obj, void *event_info);
69 static void _rgb_to_hsl(void *data);
70 static void _hsl_to_rgb(void *data);
71 static void _color_with_saturation(void *data);
72 static void _color_with_lightness(void *data);
73 static void _draw_rects(void *data, double x);
74 static void _arrow_cb(void *data, Evas_Object *obj, const char *emission,
75                       const char *source);
76 static void _colorbar_cb(void *data, Evas *e, Evas_Object *obj,
77                          void *event_info);
78 static void _left_button_clicked_cb(void *data, Evas_Object * obj,
79                                     void *event_info);
80 static void _left_button_repeat_cb(void *data, Evas_Object * obj,
81                                    void *event_info);
82 static void _right_button_clicked_cb(void *data, Evas_Object * obj,
83                                      void *event_info);
84 static void _right_button_repeat_cb(void *data, Evas_Object * obj,
85                                     void *event_info);
86 static void _add_colorbar(Evas_Object *obj);
87 static void _set_color(Evas_Object *obj, int r, int g, int b, int a);
88 static Elm_Color_Item *_item_new(Evas_Object *obj);
89 static void _item_sizing_eval(Elm_Color_Item *item);
90 static void _item_highlight(void *data, Evas *e, Evas_Object *obj, void *event_info);
91 static void _item_unhighlight(void *data, Evas *e, Evas_Object *obj, void *event_info);
92 static Eina_Bool _long_press(void *data);
93 static void _remove_items(Widget_Data *wd);
94 static void _colors_remove(Evas_Object *obj);
95 static void _colors_save(Evas_Object *obj);
96 static void _colors_load_apply(Evas_Object *obj);
97
98 static const char SIG_CHANGED[] = "changed";
99 static const char SIG_COLOR_ITEM_SELECTED[] = "color,item,selected";
100 static const char SIG_COLOR_ITEM_LONGPRESSED[] = "color,item,longpressed";
101
102 static const Evas_Smart_Cb_Description _signals[] =
103 {
104    {SIG_COLOR_ITEM_SELECTED, ""},
105    {SIG_COLOR_ITEM_LONGPRESSED, ""},
106    {SIG_CHANGED, ""},
107    {NULL, NULL}
108 };
109
110 static void
111 _del_hook(Evas_Object *obj)
112 {
113    Widget_Data *wd = elm_widget_data_get(obj);
114    int i = 0;
115
116    if (!wd) return;
117    if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
118    if (wd->palette_name) eina_stringshare_del(wd->palette_name);
119    _remove_items(wd);
120    for (i = 0; i < 4; i++) free(wd->cp[i]);
121    free(wd);
122 }
123
124 static void
125 _theme_hook(Evas_Object *obj)
126 {
127    Widget_Data *wd = elm_widget_data_get(obj);
128    Eina_List *elist;
129    Elm_Color_Item *item;
130    int i;
131    const char *hpadstr, *vpadstr;
132    unsigned int h_pad = DEFAULT_HOR_PAD;
133    unsigned int v_pad = DEFAULT_VER_PAD;
134
135    if ((!wd) || (!wd->sel)) return;
136
137    _elm_theme_object_set(obj, wd->base, "colorselector", "palette",
138                          elm_widget_style_get(obj));
139    _elm_theme_object_set(obj, wd->sel, "colorselector", "bg",
140                          elm_widget_style_get(obj));
141    hpadstr = edje_object_data_get(wd->base, "horizontal_pad");
142    if (hpadstr) h_pad = atoi(hpadstr);
143    vpadstr = edje_object_data_get(wd->base, "vertical_pad");
144    if (vpadstr) v_pad = atoi(vpadstr);
145    elm_box_padding_set(wd->box, h_pad, v_pad);
146    EINA_LIST_FOREACH(wd->items, elist, item)
147      {
148         elm_layout_theme_set(VIEW(item), "colorselector", "item", elm_widget_style_get(obj));
149         _elm_theme_object_set(obj, item->color_obj, "colorselector", "item/color", elm_widget_style_get(obj));
150      }
151    for (i = 0; i < 4; i++)
152      {
153         evas_object_del(wd->cp[i]->colorbar);
154         wd->cp[i]->colorbar = NULL;
155         evas_object_del(wd->cp[i]->bar);
156         wd->cp[i]->bar = NULL;
157         evas_object_del(wd->cp[i]->lbt);
158         wd->cp[i]->lbt = NULL;
159         evas_object_del(wd->cp[i]->rbt);
160         wd->cp[i]->rbt = NULL;
161         if (i != 0)
162           {
163              evas_object_del(wd->cp[i]->bg_rect);
164              wd->cp[i]->bg_rect = NULL;
165           }
166         evas_object_del(wd->cp[i]->arrow);
167         wd->cp[i]->arrow = NULL;
168         evas_object_del(wd->cp[i]->touch_area);
169         wd->cp[i]->touch_area = NULL;
170      }
171
172    _add_colorbar(obj);
173    elm_colorselector_color_set(obj, wd->r, wd->g, wd->b, wd->a);
174    _sizing_eval(obj);
175 }
176
177 static void
178 _colorselector_set_size_hints(Evas_Object *obj, int timesw, int timesh)
179 {
180    Evas_Coord minw = -1, minh = -1;
181
182    elm_coords_finger_size_adjust(timesw, &minw, timesh, &minh);
183    edje_object_size_min_restricted_calc(obj, &minw, &minh,
184                                         minw, minh);
185    evas_object_size_hint_min_set(obj, minw, minh);
186    evas_object_size_hint_max_set(obj, -1, -1);
187 }
188
189 static void
190 _item_sizing_eval(Elm_Color_Item *item)
191 {
192    Evas_Coord minw = -1, minh = -1;
193
194    if (!item) return;
195
196    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
197    edje_object_size_min_restricted_calc(VIEW(item), &minw, &minh, minw,
198                                         minh);
199    evas_object_size_hint_min_set(VIEW(item), minw, minh);
200 }
201
202 static void _resize_cb(void *data, Evas *a __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
203 {
204    _sizing_eval(data);
205 }
206
207 static void
208 _sizing_eval_palette(Evas_Object *obj)
209 {
210    Widget_Data *wd = elm_widget_data_get(obj);
211    Eina_List *elist;
212    Elm_Color_Item *item;
213    Evas_Coord bw = 0, bh = 0;
214    Evas_Coord w = 0, h = 0;
215    if (!wd) return;
216
217    EINA_LIST_FOREACH(wd->items, elist, item)
218      {
219         _item_sizing_eval(item);
220      }
221    evas_object_size_hint_min_get(wd->box, &bw, &bh);
222    evas_object_size_hint_min_set(obj, bw, bh);
223    evas_object_size_hint_max_set(obj, -1, -1);
224    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
225    if (w < bw) w = bw;
226    if (h < bh) h = bh;
227    evas_object_resize(obj, w, h);
228 }
229
230 static void
231 _sizing_eval_selector(Evas_Object *obj)
232 {
233    Widget_Data *wd = elm_widget_data_get(obj);
234    Evas_Coord minw = -1, minh = -1;
235    Evas_Coord w = 0, h = 0;
236    int i;
237
238    if (!wd) return;
239    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
240    for (i = 0; i < 4; i++)
241      {
242         if (wd->cp[i]->bg_rect)
243           _colorselector_set_size_hints(wd->cp[i]->bg_rect, 1, 1);
244         _colorselector_set_size_hints(wd->cp[i]->bar, 1, 1);
245         _colorselector_set_size_hints(wd->cp[i]->rbt, 1, 1);
246         _colorselector_set_size_hints(wd->cp[i]->lbt, 1, 1);
247
248         _colorselector_set_size_hints(wd->cp[i]->colorbar, 4, 1);
249      }
250
251    elm_coords_finger_size_adjust(4, &minw, 4, &minh);
252    edje_object_size_min_restricted_calc(wd->sel, &minw, &minh, minw, minh);
253    evas_object_size_hint_min_set(obj, minw, minh);
254    evas_object_size_hint_max_set(obj, -1, -1);
255    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
256    if (w < minw) w = minw;
257    if (h < minh) h = minh;
258    evas_object_resize(obj, w, h);
259 }
260
261 static void
262 _sizing_eval_palette_selector(Evas_Object *obj)
263 {
264    Widget_Data *wd = elm_widget_data_get(obj);
265    Evas_Coord minw = -1, minh = -1;
266    Evas_Coord bw = 0, bh = 0;
267    Evas_Coord w = 0, h = 0;
268    int i;
269    if (!wd) return;
270    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
271    for (i = 0; i < 4; i++)
272      {
273         if (wd->cp[i]->bg_rect)
274           _colorselector_set_size_hints(wd->cp[i]->bg_rect, 1, 1);
275         _colorselector_set_size_hints(wd->cp[i]->bar, 1, 1);
276         _colorselector_set_size_hints(wd->cp[i]->rbt, 1, 1);
277         _colorselector_set_size_hints(wd->cp[i]->lbt, 1, 1);
278
279         _colorselector_set_size_hints(wd->cp[i]->colorbar, 4, 1);
280      }
281
282    elm_coords_finger_size_adjust(4, &minw, 4, &minh);
283    edje_object_size_min_restricted_calc(wd->sel, &minw, &minh, minw, minh);
284    evas_object_size_hint_min_get(wd->box, &bw, &bh);
285    evas_object_size_hint_min_set(obj, minw, minh+bh);
286    evas_object_size_hint_max_set(obj, -1, -1);
287    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
288    if (w < minw) w = minw;
289    if (h < (minh+bh)) h = (minh+bh);
290    evas_object_resize(obj, w, h);
291 }
292
293 static void
294 _sizing_eval(Evas_Object *obj)
295 {
296    Widget_Data *wd = elm_widget_data_get(obj);
297    if (!wd) return;
298    switch (wd->mode)
299      {
300         case ELM_COLORSELECTOR_PALETTE:
301            _sizing_eval_palette(obj);
302            break;
303         case ELM_COLORSELECTOR_COMPONENTS:
304            _sizing_eval_selector(obj);
305            break;
306         case ELM_COLORSELECTOR_BOTH:
307            _sizing_eval_palette_selector(obj);
308            break;
309         default:
310            break;
311      }
312 }
313
314 static Eina_Bool
315 _long_press(void *data)
316 {
317    Elm_Color_Item *item = (Elm_Color_Item *) data;
318    Widget_Data *wd = elm_widget_data_get(WIDGET(item));
319    if (!wd) return ECORE_CALLBACK_CANCEL;
320    wd->longpress_timer = NULL;
321    wd->longpressed = EINA_TRUE;
322    evas_object_smart_callback_call(WIDGET(item), SIG_COLOR_ITEM_LONGPRESSED, item);
323    return ECORE_CALLBACK_CANCEL;
324 }
325
326 static void
327 _item_highlight(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
328 {
329    Elm_Color_Item *item = (Elm_Color_Item *) data;
330    Evas_Event_Mouse_Down *ev = event_info;
331    if (!item) return;
332    Widget_Data *wd = elm_widget_data_get(WIDGET(item));
333    if (!wd) return;
334    if (ev->button != 1) return;
335    elm_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
336    wd->longpressed = EINA_FALSE;
337    if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
338    wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
339 }
340
341 static void
342 _item_unhighlight(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
343 {
344    Elm_Color_Item *item = (Elm_Color_Item *) data;
345    Evas_Event_Mouse_Down *ev = event_info;
346    if (!item) return;
347    Widget_Data *wd = elm_widget_data_get(WIDGET(item));
348    if (!wd) return;
349    if (ev->button != 1) return;
350    if (wd->longpress_timer)
351      {
352         ecore_timer_del(wd->longpress_timer);
353         wd->longpress_timer = NULL;
354      }
355    elm_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
356    if (!wd->longpressed)
357      {
358         evas_object_smart_callback_call(WIDGET(item), SIG_COLOR_ITEM_SELECTED, item);
359         elm_colorselector_color_set(WIDGET(item), item->color->r, item->color->g, item->color->b, item->color->a);
360      }
361 }
362
363 static void
364 _remove_items(Widget_Data *wd)
365 {
366    Elm_Color_Item *item;
367
368    if (!wd->items) return;
369
370    EINA_LIST_FREE(wd->items, item)
371      {
372         free(item->color);
373         elm_widget_item_free(item);
374      }
375
376    wd->items = NULL;
377 }
378
379 static Elm_Color_Item*
380 _item_new(Evas_Object *obj)
381 {
382    Elm_Color_Item *item;
383    Widget_Data *wd;
384
385    wd = elm_widget_data_get(obj);
386    if (!wd) return NULL;
387
388    item = elm_widget_item_new(obj, Elm_Color_Item);
389    if (!item) return NULL;
390
391    VIEW(item) = elm_layout_add(obj);
392    elm_layout_theme_set(VIEW(item), "colorselector", "item", elm_widget_style_get(obj));
393    evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
394    evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
395    item->color_obj = edje_object_add(evas_object_evas_get(obj));
396    _elm_theme_object_set(obj, item->color_obj, "colorselector", "item/color", elm_widget_style_get(obj));
397    evas_object_size_hint_weight_set(item->color_obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
398    evas_object_size_hint_align_set(item->color_obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
399    evas_object_event_callback_add(item->color_obj, EVAS_CALLBACK_MOUSE_DOWN, _item_highlight, item);
400    evas_object_event_callback_add(item->color_obj, EVAS_CALLBACK_MOUSE_UP, _item_unhighlight, item);
401    elm_object_part_content_set(VIEW(item), "color_obj", item->color_obj);
402    _item_sizing_eval(item);
403    evas_object_show(VIEW(item));
404
405    return item;
406 }
407
408 static void
409 _colors_remove(Evas_Object *obj)
410 {
411    Widget_Data *wd = elm_widget_data_get(obj);
412
413    _remove_items(wd);
414    _elm_config_colors_free(wd->palette_name);
415 }
416
417 static void _colors_save(Evas_Object *obj)
418 {
419    Eina_List *elist;
420    Widget_Data *wd = elm_widget_data_get(obj);
421    Elm_Color_Item *item;
422    _elm_config_colors_free(wd->palette_name);
423    EINA_LIST_FOREACH(wd->items, elist, item)
424      {
425         _elm_config_color_set(wd->palette_name, item->color->r, item->color->g,
426                               item->color->b, item->color->a);
427      }
428 }
429
430 static void
431 _colors_load_apply(Evas_Object *obj)
432 {
433    Elm_Color_RGBA *color;
434    Eina_List *elist;
435    Eina_List *color_list;
436    Elm_Color_Item *item;
437    Widget_Data *wd = elm_widget_data_get(obj);
438    color_list = _elm_config_color_list_get(wd->palette_name);
439    if (!color_list) return;
440    EINA_LIST_FOREACH(color_list, elist, color)
441      {
442         item = _item_new(obj);
443         if (!item) return;
444         item->color = ELM_NEW(Elm_Color_RGBA);
445         if (!item->color) return;
446         item->color->r = color->r;
447         item->color->g = color->g;
448         item->color->b = color->b;
449         item->color->a = color->a;
450         elm_box_pack_end(wd->box, VIEW(item));
451         evas_object_color_set(item->color_obj, item->color->r, item->color->g,
452                               item->color->b, item->color->a);
453         wd->items = eina_list_append(wd->items, item);
454         _sizing_eval_palette(obj);
455      }
456    wd->config_load = EINA_TRUE;
457 }
458
459 static void
460 _rgb_to_hsl(void *data)
461 {
462    Widget_Data *wd = data;
463    double r, g, b;
464    double v, m, vm;
465    double r2, g2, b2;
466
467    r = wd->r;
468    g = wd->g;
469    b = wd->b;
470
471    r /= 255.0;
472    g /= 255.0;
473    b /= 255.0;
474
475    v = (r > g) ? r : g;
476    v = (v > b) ? v : b;
477
478    m = (r < g) ? r : g;
479    m = (m < b) ? m : b;
480
481    wd->h = 0.0;
482    wd->s = 0.0;
483    wd->l = 0.0;
484
485    wd->l = (m + v) / 2.0;
486
487    if (wd->l <= 0.0) return;
488
489    vm = v - m;
490    wd->s = vm;
491
492    if (wd->s > 0.0) wd->s /= (wd->l <= 0.5) ? (v + m) : (2.0 - v - m);
493    else return;
494
495    r2 = (v - r) / vm;
496    g2 = (v - g) / vm;
497    b2 = (v - b) / vm;
498
499    if (r == v) wd->h = (g == m ? 5.0 + b2 : 1.0 - g2);
500    else if (g == v) wd->h = (b == m ? 1.0 + r2 : 3.0 - b2);
501    else wd->h = (r == m ? 3.0 + g2 : 5.0 - r2);
502
503    wd->h *= 60.0;
504 }
505
506 static void
507 _hsl_to_rgb(void *data)
508 {
509    Widget_Data *wd = data;
510    double r = 0, g = 0, b = 0;
511    double _h, _s, _l;
512    int i = 0;
513    double sv, vsf, f, p, q, t, v;
514
515    _h = wd->h;
516    _s = wd->s;
517    _l = wd->l;
518
519    if (_s == 0.0) r = g = b = _l;
520    else
521      {
522         if (_h == 360.0) _h = 0.0;
523         _h /= 60.0;
524
525         v = (_l <= 0.5) ? (_l * (1.0 + _s)) : (_l + _s - (_l * _s));
526         p = _l + _l - v;
527
528         if (v) sv = (v - p) / v;
529         else sv = 0;
530
531         i = (int)_h;
532         f = _h - i;
533
534         vsf = v * sv * f;
535
536         t = p + vsf;
537         q = v - vsf;
538
539         switch (i)
540           {
541            case 0:
542               r = v;
543               g = t;
544               b = p;
545               break;
546            case 1:
547               r = q;
548               g = v;
549               b = p;
550               break;
551            case 2:
552               r = p;
553               g = v;
554               b = t;
555               break;
556            case 3:
557               r = p;
558               g = q;
559               b = v;
560               break;
561            case 4:
562               r = t;
563               g = p;
564               b = v;
565               break;
566            case 5:
567               r = v;
568               g = p;
569               b = q;
570               break;
571           }
572      }
573    i = (int)(r * 255.0);
574    f = (r * 255.0) - i;
575    wd->r = (f <= 0.5) ? i : (i + 1);
576
577    i = (int)(g * 255.0);
578    f = (g * 255.0) - i;
579    wd->g = (f <= 0.5) ? i : (i + 1);
580
581    i = (int)(b * 255.0);
582    f = (b * 255.0) - i;
583    wd->b = (f <= 0.5) ? i : (i + 1);
584 }
585
586 static void
587 _color_with_saturation(void *data)
588 {
589    Widget_Data *wd = data;
590
591    if (wd->er > 127)
592      wd->sr = 127 + (int)((double)(wd->er - 127) * wd->s);
593    else
594      wd->sr = 127 - (int)((double)(127 - wd->er) * wd->s);
595
596    if (wd->eg > 127)
597      wd->sg = 127 + (int)((double)(wd->eg - 127) * wd->s);
598    else
599      wd->sg = 127 - (int)((double)(127 - wd->eg) * wd->s);
600
601    if (wd->eb > 127)
602      wd->sb = 127 + (int)((double)(wd->eb - 127) * wd->s);
603    else
604      wd->sb = 127 - (int)((double)(127 - wd->eb) * wd->s);
605 }
606
607 static void
608 _color_with_lightness(void *data)
609 {
610    Widget_Data *wd = data;
611
612    if (wd->l > 0.5)
613      {
614         wd->lr = wd->er + (int)((double)(255 - wd->er) * (wd->l - 0.5) * 2.0);
615         wd->lg = wd->eg + (int)((double)(255 - wd->eg) * (wd->l - 0.5) * 2.0);
616         wd->lb = wd->eb + (int)((double)(255 - wd->eb) * (wd->l - 0.5) * 2.0);
617      }
618    else if (wd->l < 0.5)
619      {
620         wd->lr = (double)wd->er * wd->l * 2.0;
621         wd->lg = (double)wd->eg * wd->l * 2.0;
622         wd->lb = (double)wd->eb * wd->l * 2.0;
623      }
624    else
625      {
626         wd->lr = wd->er;
627         wd->lg = wd->eg;
628         wd->lb = wd->eb;
629      }
630 }
631
632 static void
633 _draw_rects(void *data, double x)
634 {
635    Colorselector_Data *cp = data;
636    Widget_Data *wd = elm_widget_data_get(cp->parent);
637    double one_six = 1.0 / 6.0;
638
639    switch (cp->color_type)
640      {
641       case HUE:
642          wd->h = 360.0 * x;
643
644          if (x < one_six)
645            {
646               wd->er = 255;
647               wd->eg = (255.0 * x * 6.0);
648               wd->eb = 0;
649            }
650          else if (x < 2 * one_six)
651            {
652               wd->er = 255 - (int)(255.0 * (x - one_six) * 6.0);
653               wd->eg = 255;
654               wd->eb = 0;
655            }
656          else if (x < 3 * one_six)
657            {
658               wd->er = 0;
659               wd->eg = 255;
660               wd->eb = (int)(255.0 * (x - (2.0 * one_six)) * 6.0);
661            }
662          else if (x < 4 * one_six)
663            {
664               wd->er = 0;
665               wd->eg = 255 - (int)(255.0 * (x - (3.0 * one_six)) * 6.0);
666               wd->eb = 255;
667            }
668          else if (x < 5 * one_six)
669            {
670               wd->er = 255.0 * (x - (4.0 * one_six)) * 6.0;
671               wd->eg = 0;
672               wd->eb = 255;
673            }
674          else
675            {
676               wd->er = 255;
677               wd->eg = 0;
678               wd->eb = 255 - (int)(255.0 * (x - (5.0 * one_six)) * 6.0);
679            }
680
681          evas_object_color_set(wd->cp[0]->arrow, wd->er, wd->eg, wd->eb, 255);
682          evas_object_color_set(wd->cp[1]->bg_rect, wd->er, wd->eg, wd->eb, 255);
683          evas_object_color_set(wd->cp[2]->bg_rect, wd->er, wd->eg, wd->eb, 255);
684          evas_object_color_set(wd->cp[3]->bar, wd->er, wd->eg, wd->eb, 255);
685
686          _color_with_saturation(wd);
687          evas_object_color_set(wd->cp[1]->arrow, wd->sr, wd->sg, wd->sb, 255);
688
689          _color_with_lightness(wd);
690          evas_object_color_set(wd->cp[2]->arrow, wd->lr, wd->lg, wd->lb, 255);
691
692          evas_object_color_set(wd->cp[3]->arrow,
693                                (wd->er * wd->a) / 255,
694                                (wd->eg * wd->a) / 255,
695                                (wd->eb * wd->a) / 255,
696                                wd->a);
697          break;
698       case SATURATION:
699          wd->s = 1.0 - x;
700          _color_with_saturation(wd);
701          evas_object_color_set(wd->cp[1]->arrow, wd->sr, wd->sg, wd->sb, 255);
702          break;
703       case LIGHTNESS:
704          wd->l = x;
705          _color_with_lightness(wd);
706          evas_object_color_set(wd->cp[2]->arrow, wd->lr, wd->lg, wd->lb, 255);
707          break;
708       case ALPHA:
709          wd->a = 255.0 * x;
710          evas_object_color_set(wd->cp[3]->arrow,
711                                (wd->er * wd->a) / 255,
712                                (wd->eg * wd->a) / 255,
713                                (wd->eb * wd->a) / 255,
714                                wd->a);
715          break;
716       default:
717          break;
718      }
719    _hsl_to_rgb(wd);
720 }
721
722 static void
723 _arrow_cb(void *data, Evas_Object *obj, const char *emission __UNUSED__,
724           const char *source __UNUSED__)
725 {
726    Colorselector_Data *cp = data;
727    double x, y;
728
729    edje_object_part_drag_value_get(obj, "elm.arrow", &x, &y);
730    _draw_rects(data, x);
731    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
732 }
733
734 static void
735 _colorbar_cb(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
736 {
737    Colorselector_Data *cp = data;
738    Evas_Event_Mouse_Down *ev = event_info;
739    Evas_Coord x, y, w, h;
740    double arrow_x = 0, arrow_y;
741
742    evas_object_geometry_get(cp->bar, &x, &y, &w, &h);
743    edje_object_part_drag_value_get(cp->colorbar, "elm.arrow",
744                                    &arrow_x, &arrow_y);
745    if (w > 0) arrow_x = (double)(ev->canvas.x - x) / (double)w;
746    if (arrow_x > 1) arrow_x = 1;
747    if (arrow_x < 0) arrow_x = 0;
748    edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", arrow_x, arrow_y);
749    _draw_rects(data, arrow_x);
750    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
751    evas_event_feed_mouse_cancel(e, 0, NULL);
752    evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);
753 }
754
755 static void
756 _left_button_clicked_cb(void *data, Evas_Object * obj __UNUSED__,
757                         void *event_info __UNUSED__)
758 {
759    Colorselector_Data *cp = data;
760    double x, y;
761
762    edje_object_signal_emit(cp->lbt, "elm,state,left,button,down",
763                            "left_button");
764    edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
765
766    switch(cp->color_type)
767      {
768       case HUE :
769          x -= 1.0 / HUE_STEP;
770          break;
771       case SATURATION :
772          x -= 1.0 / SAT_STEP;
773          break;
774       case LIGHTNESS :
775          x -= 1.0 / LIG_STEP;
776          break;
777       case ALPHA :
778          x -= 1.0 / ALP_STEP;
779          break;
780       default :
781          break;
782      }
783
784    if (x < 0.0) x = 0.0;
785
786    edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
787    _draw_rects(data, x);
788    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
789 }
790
791 static void
792 _left_button_repeat_cb(void *data, Evas_Object * obj __UNUSED__,
793                        void *event_info __UNUSED__)
794 {
795    Colorselector_Data *cp = data;
796    double x, y;
797
798    edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
799    x -= 1.0 / BASE_STEP;
800    if (x < 0.0) x = 0.0;
801    edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
802    _draw_rects(data, x);
803    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
804
805 }
806
807 static void
808 _right_button_clicked_cb(void *data, Evas_Object * obj __UNUSED__,
809                          void *event_info __UNUSED__)
810 {
811    Colorselector_Data *cp = data;
812    double x, y;
813
814    edje_object_signal_emit(cp->rbt, "elm,state,right,button,down",
815                            "right_button");
816    edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
817
818    switch(cp->color_type)
819      {
820       case HUE :
821          x += 1.0 / HUE_STEP;
822          break;
823       case SATURATION :
824          x += 1.0 / SAT_STEP;
825          break;
826       case LIGHTNESS :
827          x += 1.0 / LIG_STEP;
828          break;
829       case ALPHA :
830          x += 1.0 / ALP_STEP;
831          break;
832       default :
833          break;
834      }
835
836    if (x > 1.0) x = 1.0;
837
838    edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
839    _draw_rects(data, x);
840    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
841 }
842
843 static void
844 _right_button_repeat_cb(void *data, Evas_Object * obj __UNUSED__,
845                         void *event_info __UNUSED__)
846 {
847    Colorselector_Data *cp = data;
848    double x, y;
849
850    edje_object_part_drag_value_get(cp->colorbar, "elm.arrow", &x, &y);
851    x += 1.0 / BASE_STEP;
852    if (x > 1.0) x = 1.0;
853    edje_object_part_drag_value_set(cp->colorbar, "elm.arrow", x, y);
854    _draw_rects(data, x);
855    evas_object_smart_callback_call(cp->parent, SIG_CHANGED, NULL);
856 }
857
858 static void
859 _add_colorbar(Evas_Object *obj)
860 {
861    char colorbar_name[128];
862    char colorbar_s[128];
863    Widget_Data *wd;
864    Evas *e;
865    int i = 0;
866    char buf[1024];
867
868    wd = elm_widget_data_get(obj);
869    if (!wd) return;
870
871    e = evas_object_evas_get(obj);
872
873    for (i = 0; i < 4; i++)
874      {
875         wd->cp[i] = ELM_NEW(Colorselector_Data);
876         wd->cp[i]->parent = obj;
877         switch(i)
878           {
879            case 0 :
880               wd->cp[i]->color_type = HUE;
881               break;
882            case 1 :
883               wd->cp[i]->color_type = SATURATION;
884               break;
885            case 2 :
886               wd->cp[i]->color_type = LIGHTNESS;
887               break;
888            case 3 :
889               wd->cp[i]->color_type = ALPHA;
890               break;
891            default :
892               break;
893           }
894         /* load colorbar area */
895         wd->cp[i]->colorbar = edje_object_add(e);
896         _elm_theme_object_set(obj, wd->cp[i]->colorbar, "colorselector", "base",
897                               elm_widget_style_get(obj));
898         snprintf(colorbar_name, sizeof(colorbar_name), "colorbar_%d", i);
899         snprintf(colorbar_s, sizeof(colorbar_s), "elm.colorbar_%d", i);
900         edje_object_signal_callback_add(wd->cp[i]->colorbar, "drag", "*",
901                                         _arrow_cb, wd->cp[i]);
902         edje_object_part_swallow(wd->sel, colorbar_s, wd->cp[i]->colorbar);
903         elm_widget_sub_object_add(obj, wd->cp[i]->colorbar);
904
905         /* load colorbar image */
906         wd->cp[i]->bar = edje_object_add(e);
907         snprintf(buf, sizeof(buf), "%s/%s", colorbar_name,
908                  elm_widget_style_get(obj));
909         _elm_theme_object_set(obj, wd->cp[i]->bar, "colorselector", "image",
910                               buf);
911         edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar",
912                                  wd->cp[i]->bar);
913         elm_widget_sub_object_add(obj, wd->cp[i]->bar);
914
915         /* provide expanded touch area */
916         wd->cp[i]->touch_area = evas_object_rectangle_add(e);
917         evas_object_color_set(wd->cp[i]->touch_area, 0, 0, 0, 0);
918         edje_object_part_swallow(wd->cp[i]->colorbar, "elm.arrow_bg",
919                                  wd->cp[i]->touch_area);
920         evas_object_event_callback_add(wd->cp[i]->touch_area,
921                                        EVAS_CALLBACK_MOUSE_DOWN, _colorbar_cb,
922                                        wd->cp[i]);
923         elm_widget_sub_object_add(obj, wd->cp[i]->touch_area);
924
925         /* load background rectangle of the colorbar. used for
926            changing color of the opacity bar */
927         if ((i == 1) || (i == 2))
928           {
929              wd->cp[i]->bg_rect = evas_object_rectangle_add(e);
930              evas_object_color_set(wd->cp[i]->bg_rect, wd->er, wd->eg, wd->eb,
931                                    255);
932              edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar_bg",
933                                       wd->cp[i]->bg_rect);
934
935              elm_widget_sub_object_add(obj, wd->cp[i]->bg_rect);
936           }
937         if (i == 3)
938           {
939              wd->cp[i]->bg_rect = edje_object_add(e);
940              snprintf(buf, sizeof(buf), "%s/%s", colorbar_name,
941                       elm_widget_style_get(obj));
942              _elm_theme_object_set(obj, wd->cp[i]->bg_rect, "colorselector",
943                                    "bg_image", buf);
944              edje_object_part_swallow(wd->cp[i]->colorbar, "elm.bar_bg",
945                                       wd->cp[i]->bg_rect);
946              elm_widget_sub_object_add(obj, wd->cp[i]->bg_rect);
947              evas_object_color_set(wd->cp[i]->bar, wd->er, wd->eg, wd->eb, 255);
948           }
949         /* load arrow image, pointing the colorbar */
950         wd->cp[i]->arrow = edje_object_add(e);
951         _elm_theme_object_set(obj, wd->cp[i]->arrow, "colorselector", "arrow",
952                               elm_widget_style_get(obj));
953         edje_object_part_swallow(wd->cp[i]->colorbar, "elm.arrow_icon",
954                                  wd->cp[i]->arrow);
955         elm_widget_sub_object_add(obj, wd->cp[i]->arrow);
956         if (i == 2)
957           evas_object_color_set(wd->cp[i]->arrow, 0, 0, 0, 255);
958         else
959           evas_object_color_set(wd->cp[i]->arrow, wd->er, wd->eg, wd->eb, 255);
960
961         /* load left button */
962         wd->cp[i]->lbt = elm_button_add(obj);
963         snprintf(buf, sizeof(buf), "colorselector/left/%s",
964                  elm_widget_style_get(obj));
965         elm_object_style_set(wd->cp[i]->lbt, buf);
966         elm_widget_sub_object_add(obj, wd->cp[i]->lbt);
967         edje_object_part_swallow(wd->cp[i]->colorbar, "elm.l_button",
968                                  wd->cp[i]->lbt);
969         evas_object_smart_callback_add(wd->cp[i]->lbt, "clicked",
970                                        _left_button_clicked_cb, wd->cp[i]);
971         elm_button_autorepeat_set(wd->cp[i]->lbt, EINA_TRUE);
972         elm_button_autorepeat_initial_timeout_set(wd->cp[i]->lbt,
973                                                   _elm_config->longpress_timeout);
974         elm_button_autorepeat_gap_timeout_set(wd->cp[i]->lbt,
975                                               (1.0 / _elm_config->fps));
976         evas_object_smart_callback_add(wd->cp[i]->lbt, "repeated",
977                                        _left_button_repeat_cb, wd->cp[i]);
978
979         /* load right button */
980         wd->cp[i]->rbt = elm_button_add(obj);
981         snprintf(buf, sizeof(buf), "colorselector/right/%s",
982                  elm_widget_style_get(obj));
983         elm_object_style_set(wd->cp[i]->rbt, buf);
984         elm_widget_sub_object_add(obj, wd->cp[i]->rbt);
985         edje_object_part_swallow(wd->cp[i]->colorbar, "elm.r_button",
986                                  wd->cp[i]->rbt);
987         evas_object_smart_callback_add(wd->cp[i]->rbt, "clicked",
988                                        _right_button_clicked_cb, wd->cp[i]);
989         elm_button_autorepeat_set(wd->cp[i]->rbt, EINA_TRUE);
990         elm_button_autorepeat_initial_timeout_set(wd->cp[i]->rbt,
991                                                   _elm_config->longpress_timeout);
992         elm_button_autorepeat_gap_timeout_set(wd->cp[i]->rbt,
993                                               (1.0 / _elm_config->fps));
994         evas_object_smart_callback_add(wd->cp[i]->rbt, "repeated",
995                                        _right_button_repeat_cb, wd->cp[i]);
996      }
997 }
998
999 static void
1000 _set_color(Evas_Object *obj, int r, int g, int b, int a)
1001 {
1002    Widget_Data *wd = elm_widget_data_get(obj);
1003    double x, y;
1004
1005    wd->r = r;
1006    wd->g = g;
1007    wd->b = b;
1008    wd->a = a;
1009
1010    _rgb_to_hsl(wd);
1011
1012    edje_object_part_drag_value_get(wd->cp[0]->colorbar, "elm.arrow", &x, &y);
1013    x = wd->h / 360.0;
1014    edje_object_part_drag_value_set(wd->cp[0]->colorbar, "elm.arrow", x, y);
1015    _draw_rects(wd->cp[0], x);
1016
1017    edje_object_part_drag_value_get(wd->cp[1]->colorbar, "elm.arrow", &x, &y);
1018    x = 1.0 - wd->s;
1019    edje_object_part_drag_value_set(wd->cp[1]->colorbar, "elm.arrow", x, y);
1020    _draw_rects(wd->cp[1], x);
1021
1022    edje_object_part_drag_value_get(wd->cp[2]->colorbar, "elm.arrow", &x, &y);
1023    x = wd->l;
1024    edje_object_part_drag_value_set(wd->cp[2]->colorbar, "elm.arrow", x, y);
1025    _draw_rects(wd->cp[2], x);
1026
1027    edje_object_part_drag_value_get(wd->cp[3]->colorbar, "elm.arrow", &x, &y);
1028    x = wd->a / 255.0;
1029    edje_object_part_drag_value_set(wd->cp[3]->colorbar, "elm.arrow", x, y);
1030    _draw_rects(wd->cp[3], x);
1031 }
1032
1033 EAPI Evas_Object *
1034 elm_colorselector_add(Evas_Object *parent)
1035 {
1036    Evas_Object *obj = NULL;
1037    Widget_Data *wd = NULL;
1038    Evas *e;
1039    const char *hpadstr, *vpadstr;
1040    unsigned int h_pad = DEFAULT_HOR_PAD;
1041    unsigned int v_pad = DEFAULT_VER_PAD;
1042
1043    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1044
1045    ELM_SET_WIDTYPE(widtype, "colorselector");
1046    elm_widget_type_set(obj, "colorselector");
1047    elm_widget_sub_object_add(parent, obj);
1048    elm_widget_data_set(obj, wd);
1049    elm_widget_del_hook_set(obj, _del_hook);
1050    elm_widget_theme_hook_set(obj, _theme_hook);
1051    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1052
1053    /* load background edj */
1054    wd->base = edje_object_add(e);
1055    _elm_theme_object_set(obj, wd->base, "colorselector", "palette", "default");
1056    elm_widget_resize_object_set(obj, wd->base);
1057    evas_object_event_callback_add(wd->base, EVAS_CALLBACK_RESIZE,
1058                                   _resize_cb, obj);
1059
1060    wd->box = elm_box_add(obj);
1061    elm_box_layout_set(wd->box, evas_object_box_layout_flow_horizontal,
1062                       NULL, NULL);
1063    elm_box_horizontal_set(wd->box, EINA_TRUE);
1064    evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1065                                     0);
1066    evas_object_size_hint_align_set(wd->box, EVAS_HINT_FILL, 0);
1067    elm_box_homogeneous_set(wd->box, EINA_TRUE);
1068    hpadstr = edje_object_data_get(wd->base, "horizontal_pad");
1069    if (hpadstr) h_pad = atoi(hpadstr);
1070    vpadstr = edje_object_data_get(wd->base, "vertical_pad");
1071    if (vpadstr) v_pad = atoi(vpadstr);
1072    elm_box_padding_set(wd->box, h_pad, v_pad);
1073    elm_box_align_set(wd->box, 0.5, 0.5);
1074    elm_widget_sub_object_add(obj, wd->box);
1075    evas_object_show(wd->box);
1076    edje_object_part_swallow(wd->base, "palette", wd->box);
1077    wd->palette_name = eina_stringshare_add("default");
1078    _colors_load_apply(obj);
1079
1080    /* load background edj */
1081    wd->sel = edje_object_add(e);
1082    _elm_theme_object_set(obj, wd->sel, "colorselector", "bg", "default");
1083    edje_object_part_swallow(wd->base, "selector", wd->sel);
1084    elm_widget_sub_object_add(obj, wd->sel);
1085
1086    wd->mode = ELM_COLORSELECTOR_BOTH;
1087    wd->er = 255;
1088    wd->eg = 0;
1089    wd->eb = 0;
1090    wd->h = 0.0;
1091    wd->s = 1.0;
1092    wd->l = 0.0;
1093    wd->a = 255;
1094
1095    _hsl_to_rgb(wd);
1096    _add_colorbar(obj);
1097    _sizing_eval(obj);
1098
1099    return obj;
1100 }
1101
1102 EAPI void
1103 elm_colorselector_color_set(Evas_Object *obj, int r, int g, int b, int a)
1104 {
1105    ELM_CHECK_WIDTYPE(obj, widtype);
1106    _set_color(obj, r, g, b, a);
1107 }
1108
1109 EAPI void
1110 elm_colorselector_color_get(const Evas_Object *obj, int *r, int *g, int *b, int *a)
1111 {
1112    ELM_CHECK_WIDTYPE(obj, widtype);
1113    Widget_Data *wd = elm_widget_data_get(obj);
1114
1115    if (r) *r = wd->r;
1116    if (g) *g = wd->g;
1117    if (b) *b = wd->b;
1118    if (a) *a = wd->a;
1119 }
1120
1121 EAPI void
1122 elm_colorselector_mode_set(Evas_Object *obj, Elm_Colorselector_Mode mode)
1123 {
1124    ELM_CHECK_WIDTYPE(obj, widtype);
1125    Widget_Data *wd = elm_widget_data_get(obj);
1126    if (!wd) return;
1127    if (wd->mode == mode) return;
1128    wd->mode = mode;
1129    switch (wd->mode)
1130      {
1131         case ELM_COLORSELECTOR_PALETTE:
1132            if (edje_object_part_swallow_get(wd->base, "selector"))
1133              {
1134                 edje_object_part_unswallow(wd->base, wd->sel);
1135                 evas_object_hide(wd->sel);
1136              }
1137            if (!edje_object_part_swallow_get(wd->base, "palette"))
1138              {
1139                 edje_object_part_swallow(wd->base, "palette", wd->box);
1140                 evas_object_show(wd->box);
1141              }
1142            break;
1143         case ELM_COLORSELECTOR_COMPONENTS:
1144            if (edje_object_part_swallow_get(wd->base, "palette"))
1145              {
1146                 edje_object_part_unswallow(wd->base, wd->box);
1147                 evas_object_hide(wd->box);
1148              }
1149            if (!edje_object_part_swallow_get(wd->base, "selector"))
1150              {
1151                 edje_object_part_swallow(wd->base, "selector", wd->sel);
1152                 evas_object_show(wd->sel);
1153              }
1154            break;
1155         case ELM_COLORSELECTOR_BOTH:
1156            if (!edje_object_part_swallow_get(wd->base, "palette"))
1157              {
1158                 edje_object_part_swallow(wd->base, "palette", wd->box);
1159                 evas_object_show(wd->box);
1160              }
1161            if (!edje_object_part_swallow_get(wd->base, "selector"))
1162              {
1163                 edje_object_part_swallow(wd->base, "selector", wd->sel);
1164                 evas_object_show(wd->sel);
1165              }
1166            break;
1167         default:
1168            return;
1169      }
1170    _sizing_eval(obj);
1171 }
1172
1173 EAPI Elm_Colorselector_Mode
1174 elm_colorselector_mode_get(const Evas_Object *obj)
1175 {
1176    ELM_CHECK_WIDTYPE(obj, widtype) ELM_COLORSELECTOR_BOTH;
1177    Widget_Data *wd = elm_widget_data_get(obj);
1178    if (!wd) return ELM_COLORSELECTOR_BOTH;
1179    return wd->mode;
1180 }
1181
1182 EAPI void
1183 elm_colorselector_palette_item_color_get(const Elm_Object_Item *it, int *r __UNUSED__, int *g __UNUSED__, int *b __UNUSED__, int*a __UNUSED__)
1184 {
1185    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1186    Elm_Color_Item *item;
1187    item = (Elm_Color_Item *) it;
1188    if (item)
1189      {
1190         if(r) *r = item->color->r;
1191         if(g) *g = item->color->g;
1192         if(b) *b = item->color->b;
1193         if(a) *a = item->color->a;
1194      }
1195 }
1196
1197 EAPI void
1198 elm_colorselector_palette_item_color_set(Elm_Object_Item *it, int r __UNUSED__, int g __UNUSED__, int b __UNUSED__, int a __UNUSED__)
1199 {
1200    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1201    Elm_Color_Item *item;
1202    item = (Elm_Color_Item *) it;
1203    item->color->r = r;
1204    item->color->g = g;
1205    item->color->b = b;
1206    item->color->a = a;
1207    evas_object_color_set(item->color_obj, item->color->r, item->color->g, item->color->b, item->color->a);
1208    _colors_save(WIDGET(it));
1209 }
1210
1211 EAPI Elm_Object_Item *
1212 elm_colorselector_palette_color_add(Evas_Object *obj, int r, int g, int b, int a)
1213 {
1214    Elm_Color_Item *item;
1215    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1216    Widget_Data *wd = elm_widget_data_get(obj);
1217    if (!wd) return NULL;
1218    if (wd->config_load)
1219      {
1220         _colors_remove(obj);
1221         wd->config_load = EINA_FALSE;
1222      }
1223    item = _item_new(obj);
1224    if (!item) return NULL;
1225    item->color = ELM_NEW(Elm_Color_RGBA);
1226    if (!item->color) return NULL;
1227    item->color->r = r;
1228    item->color->g = g;
1229    item->color->b = b;
1230    item->color->a = a;
1231    _elm_config_color_set(wd->palette_name, item->color->r, item->color->g,
1232                          item->color->b, item->color->a);
1233    elm_box_pack_end(wd->box, VIEW(item));
1234    evas_object_color_set(item->color_obj, item->color->r, item->color->g,
1235                          item->color->b, item->color->a);
1236    wd->items = eina_list_append(wd->items, item);
1237    _sizing_eval(obj);
1238    return (Elm_Object_Item *) item;
1239 }
1240
1241 EAPI void
1242 elm_colorselector_palette_clear(Evas_Object *obj)
1243 {
1244    ELM_CHECK_WIDTYPE(obj, widtype);
1245    Widget_Data *wd = elm_widget_data_get(obj);
1246    if (!wd) return;
1247    _colors_remove(obj);
1248 }
1249
1250 EAPI void
1251 elm_colorselector_palette_name_set(Evas_Object *obj, const char *palette_name)
1252 {
1253    ELM_CHECK_WIDTYPE(obj, widtype);
1254    Widget_Data *wd = elm_widget_data_get(obj);
1255    if (!wd) return;
1256    if (!strcmp(wd->palette_name, palette_name)) return;
1257    if (palette_name)
1258      {
1259         _colors_remove(obj);
1260         eina_stringshare_replace(&wd->palette_name, palette_name);
1261         _colors_load_apply(obj);
1262      }
1263 }
1264
1265 EAPI const char*
1266 elm_colorselector_palette_name_get(const Evas_Object *obj)
1267 {
1268    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1269    Widget_Data *wd = elm_widget_data_get(obj);
1270    if (!wd) return NULL;
1271    return wd->palette_name;
1272 }