1 #include <Elementary.h>
3 #include "elm_widget_colorselector.h"
5 EAPI const char ELM_COLORSELECTOR_SMART_NAME[] = "elm_colorselector";
7 #define BASE_STEP 360.0
10 #define LIG_STEP 256.0
11 #define ALP_STEP 256.0
12 #define DEFAULT_HOR_PAD 10
13 #define DEFAULT_VER_PAD 10
15 static const char SIG_CHANGED[] = "changed";
16 static const char SIG_COLOR_ITEM_SELECTED[] = "color,item,selected";
17 static const char SIG_COLOR_ITEM_LONGPRESSED[] = "color,item,longpressed";
18 static const Evas_Smart_Cb_Description _smart_callbacks[] =
20 {SIG_COLOR_ITEM_SELECTED, ""},
21 {SIG_COLOR_ITEM_LONGPRESSED, ""},
26 EVAS_SMART_SUBCLASS_NEW
27 (ELM_COLORSELECTOR_SMART_NAME, _elm_colorselector,
28 Elm_Colorselector_Smart_Class, Elm_Layout_Smart_Class,
29 elm_layout_smart_class_get, _smart_callbacks);
32 _items_del(Elm_Colorselector_Smart_Data *sd)
36 if (!sd->items) return;
38 EINA_LIST_FREE (sd->items, item)
41 elm_widget_item_free(item);
49 _color_with_saturation(Elm_Colorselector_Smart_Data *sd)
52 sd->sr = 127 + (int)((double)(sd->er - 127) * sd->s);
54 sd->sr = 127 - (int)((double)(127 - sd->er) * sd->s);
57 sd->sg = 127 + (int)((double)(sd->eg - 127) * sd->s);
59 sd->sg = 127 - (int)((double)(127 - sd->eg) * sd->s);
62 sd->sb = 127 + (int)((double)(sd->eb - 127) * sd->s);
64 sd->sb = 127 - (int)((double)(127 - sd->eb) * sd->s);
68 _color_with_lightness(Elm_Colorselector_Smart_Data *sd)
72 sd->lr = sd->er + (int)((double)(255 - sd->er) * (sd->l - 0.5) * 2.0);
73 sd->lg = sd->eg + (int)((double)(255 - sd->eg) * (sd->l - 0.5) * 2.0);
74 sd->lb = sd->eb + (int)((double)(255 - sd->eb) * (sd->l - 0.5) * 2.0);
78 sd->lr = (double)sd->er * sd->l * 2.0;
79 sd->lg = (double)sd->eg * sd->l * 2.0;
80 sd->lb = (double)sd->eb * sd->l * 2.0;
91 _color_picker_init(Elm_Colorselector_Smart_Data *sd)
99 snprintf(buf, 12, "%i", sd->r);
100 elm_object_text_set(sd->entries[0], buf);
102 snprintf(buf, 12, "%i", sd->g);
103 elm_object_text_set(sd->entries[1], buf);
105 snprintf(buf, 12, "%i", sd->b);
106 elm_object_text_set(sd->entries[2], buf);
108 snprintf(buf, 12, "%i", sd->a);
109 elm_object_text_set(sd->entries[3], buf);
111 color = (sd->a << 24) + (sd->r << 16) + (sd->g << 8) + sd->b;
114 evas_object_image_alpha_set(sd->picker_display, EINA_FALSE);
116 evas_object_image_alpha_set(sd->picker_display, EINA_TRUE);
118 pixels = evas_object_image_data_get(sd->picker_display, EINA_TRUE);
120 for (y = 0; y < 17; y++)
121 for (x = 0; x < 17; x++)
125 evas_object_image_data_set(sd->picker_display, copy);
126 evas_object_geometry_get(sd->picker_display, NULL, NULL, &w, &h);
127 evas_object_image_data_update_add(sd->picker_display, 0, 0, w, h);
132 _rgb_to_hsl(Elm_Colorselector_Smart_Data *sd)
156 sd->l = (m + v) / 2.0;
158 if (sd->l <= 0.0) return;
163 if (sd->s > 0.0) sd->s /= (sd->l <= 0.5) ? (v + m) : (2.0 - v - m);
170 if (r == v) sd->h = (g == m ? 5.0 + b2 : 1.0 - g2);
172 sd->h = (b == m ? 1.0 + r2 : 3.0 - b2);
173 else sd->h = (r == m ? 3.0 + g2 : 5.0 - r2);
179 _hsl_to_rgb(Elm_Colorselector_Smart_Data *sd)
181 double sv, vsf, f, p, q, t, v;
182 double r = 0, g = 0, b = 0;
190 if (_s == 0.0) r = g = b = _l;
193 if (_h == 360.0) _h = 0.0;
196 v = (_l <= 0.5) ? (_l * (1.0 + _s)) : (_l + _s - (_l * _s));
199 if (v) sv = (v - p) / v;
249 i = (int)(r * 255.0);
251 sd->r = (f <= 0.5) ? i : (i + 1);
253 i = (int)(g * 255.0);
255 sd->g = (f <= 0.5) ? i : (i + 1);
257 i = (int)(b * 255.0);
259 sd->b = (f <= 0.5) ? i : (i + 1);
263 _rectangles_redraw(Color_Bar_Data *cb_data, double x)
265 double one_six = 1.0 / 6.0;
267 ELM_COLORSELECTOR_DATA_GET(cb_data->parent, sd);
269 switch (cb_data->color_type)
277 sd->eg = (255.0 * x * 6.0);
280 else if (x < 2 * one_six)
282 sd->er = 255 - (int)(255.0 * (x - one_six) * 6.0);
286 else if (x < 3 * one_six)
290 sd->eb = (int)(255.0 * (x - (2.0 * one_six)) * 6.0);
292 else if (x < 4 * one_six)
295 sd->eg = 255 - (int)(255.0 * (x - (3.0 * one_six)) * 6.0);
298 else if (x < 5 * one_six)
300 sd->er = 255.0 * (x - (4.0 * one_six)) * 6.0;
308 sd->eb = 255 - (int)(255.0 * (x - (5.0 * one_six)) * 6.0);
311 evas_object_color_set
312 (sd->cb_data[0]->arrow, sd->er, sd->eg, sd->eb, 255);
313 evas_object_color_set
314 (sd->cb_data[1]->bg_rect, sd->er, sd->eg, sd->eb, 255);
315 evas_object_color_set
316 (sd->cb_data[2]->bg_rect, sd->er, sd->eg, sd->eb, 255);
317 evas_object_color_set
318 (sd->cb_data[3]->bar, sd->er, sd->eg, sd->eb, 255);
320 _color_with_saturation(sd);
321 evas_object_color_set
322 (sd->cb_data[1]->arrow, sd->sr, sd->sg, sd->sb, 255);
324 _color_with_lightness(sd);
325 evas_object_color_set
326 (sd->cb_data[2]->arrow, sd->lr, sd->lg, sd->lb, 255);
328 evas_object_color_set(sd->cb_data[3]->arrow,
329 (sd->er * sd->a) / 255,
330 (sd->eg * sd->a) / 255,
331 (sd->eb * sd->a) / 255,
337 _color_with_saturation(sd);
338 evas_object_color_set
339 (sd->cb_data[1]->arrow, sd->sr, sd->sg, sd->sb, 255);
344 _color_with_lightness(sd);
345 evas_object_color_set
346 (sd->cb_data[2]->arrow, sd->lr, sd->lg, sd->lb, 255);
351 evas_object_color_set(sd->cb_data[3]->arrow,
352 (sd->er * sd->a) / 255,
353 (sd->eg * sd->a) / 255,
354 (sd->eb * sd->a) / 255,
363 _color_picker_init(sd);
367 _colors_set(Evas_Object *obj,
375 ELM_COLORSELECTOR_DATA_GET(obj, sd);
384 edje_object_part_drag_value_get
385 (sd->cb_data[0]->colorbar, "elm.arrow", &x, &y);
387 edje_object_part_drag_value_set
388 (sd->cb_data[0]->colorbar, "elm.arrow", x, y);
389 _rectangles_redraw(sd->cb_data[0], x);
391 edje_object_part_drag_value_get
392 (sd->cb_data[1]->colorbar, "elm.arrow", &x, &y);
394 edje_object_part_drag_value_set
395 (sd->cb_data[1]->colorbar, "elm.arrow", x, y);
396 _rectangles_redraw(sd->cb_data[1], x);
398 edje_object_part_drag_value_get
399 (sd->cb_data[2]->colorbar, "elm.arrow", &x, &y);
401 edje_object_part_drag_value_set(sd->cb_data[2]->colorbar, "elm.arrow", x, y);
402 _rectangles_redraw(sd->cb_data[2], x);
404 edje_object_part_drag_value_get
405 (sd->cb_data[3]->colorbar, "elm.arrow", &x, &y);
407 edje_object_part_drag_value_set
408 (sd->cb_data[3]->colorbar, "elm.arrow", x, y);
410 _rectangles_redraw(sd->cb_data[3], x);
414 _entry_changed_cb(void *data,
416 void *event_info __UNUSED__)
418 Elm_Colorselector_Smart_Data *sd = data;
424 for (i = 0; i < 4 && sd->entries[i] != obj; i++)
427 parent = evas_object_data_get(obj, "parent");
428 text = elm_object_text_get(obj);
430 if (v > 255) v = 255;
431 else if (v < 0) v = 0;
437 _colors_set(parent, v, sd->g, sd->b, sd->a);
441 _colors_set(parent, sd->r, v, sd->b, sd->a);
445 _colors_set(parent, sd->r, sd->g, v, sd->a);
449 _colors_set(parent, sd->r, sd->g, sd->b, v);
454 #ifdef HAVE_ELEMENTARY_X
455 static Eina_Bool _mouse_grab_pixels(void *data, int type __UNUSED__, void *event __UNUSED__);
457 static Ecore_X_Window
458 _x11_elm_widget_xwin_get(const Evas_Object *obj)
461 Ecore_X_Window xwin = 0;
463 top = elm_widget_top_get(obj);
464 if (!top) top = elm_widget_top_get(elm_widget_parent_widget_get(obj));
465 if (top) xwin = elm_win_xwindow_get(top);
469 Evas *evas = evas_object_evas_get(obj);
471 ee = ecore_evas_ecore_evas_get(evas);
473 xwin = _elm_ee_xwin_get(ee);
479 _start_grab_pick_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
481 Evas_Object *o = data;
483 ELM_COLORSELECTOR_DATA_GET(o, sd);
485 elm_object_disabled_set(obj, EINA_TRUE);
487 ecore_event_handler_del(sd->grab.mouse_motion);
488 sd->grab.mouse_motion = ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE, _mouse_grab_pixels, o);
490 ecore_x_keyboard_grab(sd->grab.xroot);
491 ecore_x_pointer_grab(sd->grab.xroot);
495 _key_up_cb(void *data, int type __UNUSED__, void *event __UNUSED__)
497 Evas_Object *o = data;
500 ELM_COLORSELECTOR_DATA_GET(o, sd);
502 elm_object_disabled_set(sd->button, EINA_FALSE);
503 ecore_x_keyboard_ungrab();
504 ecore_x_pointer_ungrab();
505 ecore_event_handler_del(sd->grab.mouse_motion);
506 sd->grab.mouse_motion = ecore_event_handler_add(ECORE_X_RAW_MOTION, _mouse_grab_pixels, o);
512 _mouse_up_cb(void *data, int type __UNUSED__, void *event __UNUSED__)
514 const unsigned int *pixels;
515 Evas_Object *o = data;
517 /* mouse up => check it */
518 ELM_COLORSELECTOR_DATA_GET(o, sd);
520 elm_object_disabled_set(sd->button, EINA_FALSE);
521 ecore_x_keyboard_ungrab();
522 ecore_x_pointer_ungrab();
523 ecore_event_handler_del(sd->grab.mouse_motion);
524 sd->grab.mouse_motion = ecore_event_handler_add(ECORE_X_RAW_MOTION, _mouse_grab_pixels, o);
526 pixels = evas_object_image_data_get(sd->picker_display, EINA_FALSE);
528 sd->r = (pixels[17 * 9 + 9] >> 16) & 0xFF;
529 sd->g = (pixels[17 * 9 + 9] >> 8) & 0xFF;
530 sd->b = pixels[17 * 9 + 9] & 0xFF;
532 _color_picker_init(sd);
538 _mouse_grab_pixels(void *data, int type __UNUSED__, void *event __UNUSED__)
540 Evas_Object *obj = data;
541 Ecore_X_Visual visual;
542 Ecore_X_Display *display;
547 int bpl = 0, rows = 0, bpp = 0;
550 ELM_COLORSELECTOR_DATA_GET(obj, sd);
552 if (sd->grab.in) return EINA_TRUE;
554 xwin = _x11_elm_widget_xwin_get(obj);
555 sd->grab.xroot = ecore_x_window_root_get(xwin);
556 ecore_x_pointer_xy_get(sd->grab.xroot, &x, &y);
561 if (sd->grab.x == x && sd->grab.y == y) return EINA_TRUE;
565 evas_object_image_alpha_set(sd->picker_display, EINA_FALSE);
567 display = ecore_x_display_get();
568 scr = ecore_x_default_screen_get();
569 visual = ecore_x_default_visual_get(display, scr);
570 img = ecore_x_image_new(17, 17, visual, ecore_x_window_depth_get(sd->grab.xroot));
571 ecore_x_image_get(img, sd->grab.xroot, x - 8, y - 8, 0, 0, 17, 17);
572 src = ecore_x_image_data_get(img, &bpl, &rows, &bpp);
573 if (!ecore_x_image_is_argb32_get(img))
575 Ecore_X_Colormap colormap;
576 unsigned int *pixels;
578 colormap = ecore_x_default_colormap_get(display, scr);
579 pixels = evas_object_image_data_get(sd->picker_display, EINA_TRUE);
580 ecore_x_image_to_argb_convert(src, bpp, bpl, colormap, visual,
582 pixels, (17 * sizeof(int)), 0, 0);
586 evas_object_image_data_copy_set(sd->picker_display, src);
589 ecore_x_image_free(img);
591 evas_object_geometry_get(sd->picker_display, NULL, NULL, &w, &h);
592 evas_object_image_data_update_add(sd->picker_display, 0, 0, w, h);
599 _mouse_in_canvas(void *data, Evas *e __UNUSED__, void *event_info __UNUSED__)
601 Evas_Object *obj = data;
602 ELM_COLORSELECTOR_DATA_GET(obj, sd);
604 sd->grab.in = EINA_TRUE;
608 _mouse_out_canvas(void *data, Evas *e __UNUSED__, void *event_info __UNUSED__)
610 Evas_Object *obj = data;
611 ELM_COLORSELECTOR_DATA_GET(obj, sd);
613 sd->grab.in = EINA_FALSE;
617 _color_picker_add(Evas_Object *obj, Elm_Colorselector_Smart_Data *sd)
625 static const char *labels[4] = { "R:", "G:", "B:", "A:" };
627 #ifdef HAVE_ELEMENTARY_X
630 xwin = _x11_elm_widget_xwin_get(obj);
633 sd->grab.xroot = ecore_x_window_root_get(xwin);
634 ecore_x_input_raw_select(sd->grab.xroot);
636 sd->grab.mouse_motion = ecore_event_handler_add(ECORE_X_RAW_MOTION, _mouse_grab_pixels, obj);
637 sd->grab.key_up = ecore_event_handler_add(ECORE_EVENT_KEY_UP, _key_up_cb, obj);
638 sd->grab.mouse_up = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, _mouse_up_cb, obj);
642 bx = elm_box_add(sd->picker);
643 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
644 evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
645 elm_box_pack_end(sd->picker, bx);
646 evas_object_show(bx);
648 ed = edje_object_add(evas_object_evas_get(sd->picker));
649 elm_widget_theme_object_set(obj, ed, "colorselector", "picker", elm_widget_style_get(obj));
650 evas_object_size_hint_weight_set(ed, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
651 evas_object_size_hint_align_set(ed, EVAS_HINT_FILL, EVAS_HINT_FILL);
652 elm_box_pack_end(bx, ed);
653 evas_object_show(ed);
655 #ifdef HAVE_ELEMENTARY_X
658 sd->button = elm_button_add(sd->picker);
659 elm_object_text_set(sd->button, "Pick a color");
660 evas_object_smart_callback_add(sd->button, "clicked", _start_grab_pick_cb, obj);
661 elm_box_pack_end(bx, sd->button);
662 evas_object_show(sd->button);
666 im = evas_object_image_add(evas_object_evas_get(sd->picker));
667 evas_object_size_hint_aspect_set(im, EVAS_ASPECT_CONTROL_BOTH, 1, 1);
668 evas_object_image_smooth_scale_set(im, EINA_FALSE);
669 evas_object_image_colorspace_set(im, EVAS_COLORSPACE_ARGB8888);
670 evas_object_image_size_set(im, 17, 17);
671 evas_object_image_alpha_set(im, 1);
672 evas_object_image_filled_set(im, EINA_TRUE);
673 edje_object_part_swallow(ed, "elm.picker", im);
674 elm_widget_sub_object_add(obj, im);
676 sd->picker_display = im;
678 table = elm_table_add(sd->picker);
679 evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
680 evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL);
681 elm_box_pack_end(sd->picker, table);
682 evas_object_show(table);
684 for (i = 0; i < 4; i++)
686 static Elm_Entry_Filter_Accept_Set accept_set = {
687 .accepted = "0123456789",
691 label = elm_label_add(table);
692 elm_object_text_set(label, labels[i]);
693 evas_object_size_hint_weight_set(label, 0.0, EVAS_HINT_EXPAND);
694 evas_object_size_hint_align_set(label, 0.0, EVAS_HINT_FILL);
695 elm_table_pack(table, label, 0, i, 1, 1);
696 evas_object_show(label);
698 entry = elm_entry_add(table);
699 elm_entry_markup_filter_append(entry, elm_entry_filter_accept_set, &accept_set);
700 elm_entry_single_line_set(entry, EINA_TRUE);
701 elm_entry_scrollable_set(entry, EINA_TRUE);
702 evas_object_data_set(entry, "parent", obj);
703 evas_object_smart_callback_add(entry, "changed", _entry_changed_cb, sd);
704 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
705 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
706 elm_table_pack(table, entry, 1, i, 1, 1);
707 evas_object_show(entry);
709 sd->entries[i] = entry;
712 evas_event_callback_add(evas_object_evas_get(obj), EVAS_CALLBACK_CANVAS_FOCUS_IN, _mouse_in_canvas, obj);
713 evas_event_callback_add(evas_object_evas_get(obj), EVAS_CALLBACK_CANVAS_FOCUS_OUT, _mouse_out_canvas, obj);
715 _color_picker_init(sd);
719 _arrow_cb(void *data,
721 const char *emission __UNUSED__,
722 const char *source __UNUSED__)
724 Color_Bar_Data *cb_data = data;
727 edje_object_part_drag_value_get(obj, "elm.arrow", &x, &y);
729 _rectangles_redraw(data, x);
730 evas_object_smart_callback_call(cb_data->parent, SIG_CHANGED, NULL);
734 _colorbar_cb(void *data,
736 Evas_Object *obj __UNUSED__,
739 Evas_Event_Mouse_Down *ev = event_info;
740 Color_Bar_Data *cb_data = data;
741 double arrow_x = 0, arrow_y;
742 Evas_Coord x, y, w, h;
743 ELM_COLORSELECTOR_DATA_GET(cb_data->parent, sd);
745 evas_object_geometry_get(cb_data->bar, &x, &y, &w, &h);
746 edje_object_part_drag_value_get
747 (cb_data->colorbar, "elm.arrow", &arrow_x, &arrow_y);
749 if (w > 0) arrow_x = (double)(ev->canvas.x - x) / (double)w;
750 if (arrow_x > 1) arrow_x = 1;
751 if (arrow_x < 0) arrow_x = 0;
752 edje_object_part_drag_value_set
753 (cb_data->colorbar, "elm.arrow", arrow_x, arrow_y);
755 _rectangles_redraw(data, arrow_x);
756 evas_object_smart_callback_call(cb_data->parent, SIG_CHANGED, NULL);
757 evas_event_feed_mouse_cancel(e, 0, NULL);
758 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);
759 sd->sel_color_type = cb_data->color_type;
760 sd->focused = ELM_COLORSELECTOR_COMPONENTS;
764 _button_clicked_cb(void *data,
766 void *event_info __UNUSED__)
768 Eina_Bool is_right = EINA_FALSE;
769 Color_Bar_Data *cb_data = data;
771 ELM_COLORSELECTOR_DATA_GET(cb_data->parent, sd);
773 if (obj == cb_data->rbt)
775 is_right = EINA_TRUE;
780 edje_object_part_drag_value_get(cb_data->colorbar, "elm.arrow", &x, &y);
782 switch (cb_data->color_type)
785 x += step / HUE_STEP;
789 x += step / SAT_STEP;
793 x += step / LIG_STEP;
797 x += step / ALP_STEP;
806 if (x > 1.0) x = 1.0;
810 if (x < 0.0) x = 0.0;
813 edje_object_part_drag_value_set(cb_data->colorbar, "elm.arrow", x, y);
814 _rectangles_redraw(data, x);
815 evas_object_smart_callback_call(cb_data->parent, SIG_CHANGED, NULL);
816 sd->sel_color_type = cb_data->color_type;
817 sd->focused = ELM_COLORSELECTOR_COMPONENTS;
821 _button_repeat_cb(void *data,
822 Evas_Object *obj __UNUSED__,
823 void *event_info __UNUSED__)
825 Eina_Bool is_right = EINA_FALSE;
826 Color_Bar_Data *cb_data = data;
829 if (obj == cb_data->rbt)
831 is_right = EINA_TRUE;
836 edje_object_part_drag_value_get(cb_data->colorbar, "elm.arrow", &x, &y);
837 x += step / BASE_STEP;
841 if (x > 1.0) x = 1.0;
845 if (x < 0.0) x = 0.0;
848 edje_object_part_drag_value_set(cb_data->colorbar, "elm.arrow", x, y);
849 _rectangles_redraw(data, x);
850 evas_object_smart_callback_call(cb_data->parent, SIG_CHANGED, NULL);
854 _access_colorbar_register(Evas_Object *obj,
860 const char* colorbar_type = NULL;
862 ao = _elm_access_edje_object_part_object_register(obj, cd->colorbar, part);
863 ai = _elm_access_object_get(ao);
865 switch (cd->color_type)
868 colorbar_type = "hue color bar";
872 colorbar_type = "saturation color bar";
876 colorbar_type = "lightness color bar";
880 colorbar_type = "alpha color bar";
887 _elm_access_text_set(ai, ELM_ACCESS_TYPE, colorbar_type);
889 // this will be used in focus_next();
894 _color_bars_add(Evas_Object *obj)
896 char colorbar_name[128];
897 char colorbar_s[128];
902 ELM_COLORSELECTOR_DATA_GET(obj, sd);
904 e = evas_object_evas_get(obj);
906 for (i = 0; i < 4; i++)
908 sd->cb_data[i] = ELM_NEW(Color_Bar_Data);
909 sd->cb_data[i]->parent = obj;
914 sd->cb_data[i]->color_type = HUE;
918 sd->cb_data[i]->color_type = SATURATION;
922 sd->cb_data[i]->color_type = LIGHTNESS;
926 sd->cb_data[i]->color_type = ALPHA;
930 /* load colorbar area */
931 sd->cb_data[i]->colorbar = edje_object_add(e);
932 elm_widget_theme_object_set
933 (obj, sd->cb_data[i]->colorbar, "colorselector", "base",
934 elm_widget_style_get(obj));
935 snprintf(colorbar_name, sizeof(colorbar_name), "colorbar_%d", i);
936 snprintf(colorbar_s, sizeof(colorbar_s), "elm.colorbar_%d", i);
937 edje_object_signal_callback_add
938 (sd->cb_data[i]->colorbar, "drag", "*", _arrow_cb, sd->cb_data[i]);
939 edje_object_part_swallow
940 (sd->col_bars_area, colorbar_s, sd->cb_data[i]->colorbar);
941 elm_widget_sub_object_add(obj, sd->cb_data[i]->colorbar);
943 /* load colorbar image */
944 sd->cb_data[i]->bar = edje_object_add(e);
945 snprintf(buf, sizeof(buf), "%s/%s", colorbar_name,
946 elm_widget_style_get(obj));
947 elm_widget_theme_object_set
948 (obj, sd->cb_data[i]->bar, "colorselector", "image", buf);
949 edje_object_part_swallow
950 (sd->cb_data[i]->colorbar, "elm.bar", sd->cb_data[i]->bar);
951 elm_widget_sub_object_add(obj, sd->cb_data[i]->bar);
953 /* provide expanded touch area */
954 sd->cb_data[i]->touch_area = evas_object_rectangle_add(e);
955 evas_object_color_set(sd->cb_data[i]->touch_area, 0, 0, 0, 0);
956 edje_object_part_swallow
957 (sd->cb_data[i]->colorbar, "elm.arrow_bg",
958 sd->cb_data[i]->touch_area);
959 evas_object_event_callback_add
960 (sd->cb_data[i]->touch_area, EVAS_CALLBACK_MOUSE_DOWN, _colorbar_cb,
962 elm_widget_sub_object_add(obj, sd->cb_data[i]->touch_area);
965 if (_elm_config->access_mode == ELM_ACCESS_MODE_ON)
966 _access_colorbar_register(obj, sd->cb_data[i], "elm.arrow_bg_access");
968 /* load background rectangle of the colorbar. used for
969 changing color of the opacity bar */
970 if ((i == 1) || (i == 2))
972 sd->cb_data[i]->bg_rect = evas_object_rectangle_add(e);
973 evas_object_color_set
974 (sd->cb_data[i]->bg_rect, sd->er, sd->eg, sd->eb, 255);
975 edje_object_part_swallow
976 (sd->cb_data[i]->colorbar, "elm.bar_bg",
977 sd->cb_data[i]->bg_rect);
979 elm_widget_sub_object_add(obj, sd->cb_data[i]->bg_rect);
983 sd->cb_data[i]->bg_rect = edje_object_add(e);
984 snprintf(buf, sizeof(buf), "%s/%s", colorbar_name,
985 elm_widget_style_get(obj));
986 elm_widget_theme_object_set
987 (obj, sd->cb_data[i]->bg_rect, "colorselector", "bg_image",
989 edje_object_part_swallow
990 (sd->cb_data[i]->colorbar, "elm.bar_bg",
991 sd->cb_data[i]->bg_rect);
992 elm_widget_sub_object_add(obj, sd->cb_data[i]->bg_rect);
993 evas_object_color_set
994 (sd->cb_data[i]->bar, sd->er, sd->eg, sd->eb, 255);
997 /* load arrow image, pointing the colorbar */
998 sd->cb_data[i]->arrow = edje_object_add(e);
999 elm_widget_theme_object_set
1000 (obj, sd->cb_data[i]->arrow, "colorselector", "arrow",
1001 elm_widget_style_get(obj));
1002 edje_object_part_swallow
1003 (sd->cb_data[i]->colorbar, "elm.arrow_icon",
1004 sd->cb_data[i]->arrow);
1005 elm_widget_sub_object_add(obj, sd->cb_data[i]->arrow);
1008 evas_object_color_set(sd->cb_data[i]->arrow, 0, 0, 0, 255);
1010 evas_object_color_set
1011 (sd->cb_data[i]->arrow, sd->er, sd->eg, sd->eb, 255);
1013 /* load left button */
1014 sd->cb_data[i]->lbt = elm_button_add(obj);
1015 snprintf(buf, sizeof(buf), "colorselector/left/%s",
1016 elm_widget_style_get(obj));
1017 elm_object_style_set(sd->cb_data[i]->lbt, buf);
1018 elm_widget_sub_object_add(obj, sd->cb_data[i]->lbt);
1019 edje_object_part_swallow
1020 (sd->cb_data[i]->colorbar, "elm.l_button", sd->cb_data[i]->lbt);
1021 evas_object_smart_callback_add
1022 (sd->cb_data[i]->lbt, "clicked", _button_clicked_cb,
1024 elm_button_autorepeat_set(sd->cb_data[i]->lbt, EINA_TRUE);
1025 elm_button_autorepeat_initial_timeout_set
1026 (sd->cb_data[i]->lbt, _elm_config->longpress_timeout);
1027 elm_button_autorepeat_gap_timeout_set
1028 (sd->cb_data[i]->lbt, (1.0 / _elm_config->fps));
1029 evas_object_smart_callback_add
1030 (sd->cb_data[i]->lbt, "repeated", _button_repeat_cb,
1033 /* load right button */
1034 sd->cb_data[i]->rbt = elm_button_add(obj);
1035 snprintf(buf, sizeof(buf), "colorselector/right/%s",
1036 elm_widget_style_get(obj));
1037 elm_object_style_set(sd->cb_data[i]->rbt, buf);
1038 elm_widget_sub_object_add(obj, sd->cb_data[i]->rbt);
1039 edje_object_part_swallow
1040 (sd->cb_data[i]->colorbar, "elm.r_button", sd->cb_data[i]->rbt);
1041 evas_object_smart_callback_add
1042 (sd->cb_data[i]->rbt, "clicked", _button_clicked_cb,
1044 elm_button_autorepeat_set(sd->cb_data[i]->rbt, EINA_TRUE);
1045 elm_button_autorepeat_initial_timeout_set
1046 (sd->cb_data[i]->rbt, _elm_config->longpress_timeout);
1047 elm_button_autorepeat_gap_timeout_set
1048 (sd->cb_data[i]->rbt, (1.0 / _elm_config->fps));
1049 evas_object_smart_callback_add
1050 (sd->cb_data[i]->rbt, "repeated", _button_repeat_cb,
1056 _elm_colorselector_smart_theme(Evas_Object *obj)
1060 Elm_Color_Item *item;
1061 const char *hpadstr, *vpadstr;
1062 unsigned int h_pad = DEFAULT_HOR_PAD;
1063 unsigned int v_pad = DEFAULT_VER_PAD;
1065 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1067 if (!ELM_WIDGET_CLASS(_elm_colorselector_parent_sc)->theme(obj))
1070 if (!sd->col_bars_area) return EINA_FALSE;
1072 elm_widget_theme_object_set
1073 (obj, sd->col_bars_area, "colorselector", "bg",
1074 elm_widget_style_get(obj));
1076 hpadstr = edje_object_data_get
1077 (ELM_WIDGET_DATA(sd)->resize_obj, "horizontal_pad");
1078 if (hpadstr) h_pad = atoi(hpadstr);
1079 vpadstr = edje_object_data_get
1080 (ELM_WIDGET_DATA(sd)->resize_obj, "vertical_pad");
1081 if (vpadstr) v_pad = atoi(vpadstr);
1085 (h_pad * elm_widget_scale_get(obj) * elm_config_scale_get()),
1086 (v_pad * elm_widget_scale_get(obj) * elm_config_scale_get()));
1088 EINA_LIST_FOREACH(sd->items, elist, item)
1090 elm_layout_theme_set
1091 (VIEW(item), "colorselector", "item", elm_widget_style_get(obj));
1092 elm_widget_theme_object_set
1093 (obj, item->color_obj, "colorselector", "item/color",
1094 elm_widget_style_get(obj));
1096 for (i = 0; i < 4; i++)
1100 evas_object_del(sd->cb_data[i]->colorbar);
1101 sd->cb_data[i]->colorbar = NULL;
1102 evas_object_del(sd->cb_data[i]->bar);
1103 sd->cb_data[i]->bar = NULL;
1104 evas_object_del(sd->cb_data[i]->lbt);
1105 sd->cb_data[i]->lbt = NULL;
1106 evas_object_del(sd->cb_data[i]->rbt);
1107 sd->cb_data[i]->rbt = NULL;
1110 evas_object_del(sd->cb_data[i]->bg_rect);
1111 sd->cb_data[i]->bg_rect = NULL;
1113 evas_object_del(sd->cb_data[i]->arrow);
1114 sd->cb_data[i]->arrow = NULL;
1115 evas_object_del(sd->cb_data[i]->touch_area);
1116 sd->cb_data[i]->touch_area = NULL;
1120 _color_bars_add(obj);
1121 elm_colorselector_color_set(obj, sd->r, sd->g, sd->b, sd->a);
1123 elm_layout_sizing_eval(obj);
1129 _sub_obj_size_hints_set(Evas_Object *sobj,
1133 Evas_Coord minw = -1, minh = -1;
1135 elm_coords_finger_size_adjust(timesw, &minw, timesh, &minh);
1136 edje_object_size_min_restricted_calc(sobj, &minw, &minh, minw, minh);
1137 evas_object_size_hint_min_set(sobj, minw, minh);
1138 evas_object_size_hint_max_set(sobj, -1, -1);
1142 _item_sizing_eval(Elm_Color_Item *item)
1144 Evas_Coord minw = -1, minh = -1;
1148 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
1149 edje_object_size_min_restricted_calc(VIEW(item), &minw, &minh, minw, minh);
1150 evas_object_size_hint_min_set(VIEW(item), minw, minh);
1153 /* fix size hints of color palette items, so that the box gets it */
1155 _palette_sizing_eval(Evas_Object *obj)
1158 Elm_Color_Item *item;
1160 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1162 EINA_LIST_FOREACH(sd->items, elist, item)
1163 _item_sizing_eval(item);
1167 _component_sizing_eval(Evas_Object *obj)
1169 Evas_Coord minw = -1, minh = -1;
1172 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1174 for (i = 0; i < 4; i++)
1178 if (sd->cb_data[i]->bg_rect)
1179 _sub_obj_size_hints_set(sd->cb_data[i]->bg_rect, 1, 1);
1181 _sub_obj_size_hints_set(sd->cb_data[i]->bar, 1, 1);
1182 _sub_obj_size_hints_set(sd->cb_data[i]->rbt, 1, 1);
1183 _sub_obj_size_hints_set(sd->cb_data[i]->lbt, 1, 1);
1184 _sub_obj_size_hints_set(sd->cb_data[i]->colorbar, 4, 1);
1188 edje_object_size_min_restricted_calc
1189 (sd->col_bars_area, &minw, &minh, minw, minh);
1190 evas_object_size_hint_min_set(sd->col_bars_area, minw, minh);
1194 _full_sizing_eval(Evas_Object *obj)
1196 _palette_sizing_eval(obj);
1197 _component_sizing_eval(obj);
1201 _elm_colorselector_smart_sizing_eval(Evas_Object *obj)
1203 Evas_Coord minw = -1, minh = -1;
1205 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1207 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
1211 case ELM_COLORSELECTOR_PALETTE:
1212 _palette_sizing_eval(obj);
1215 case ELM_COLORSELECTOR_COMPONENTS:
1216 _component_sizing_eval(obj);
1219 case ELM_COLORSELECTOR_BOTH:
1220 _full_sizing_eval(obj);
1227 edje_object_size_min_calc(ELM_WIDGET_DATA(sd)->resize_obj, &minw, &minh);
1228 evas_object_size_hint_min_set(obj, minw, minh);
1229 evas_object_size_hint_max_set(obj, -1, -1);
1233 _on_color_long_press(void *data)
1235 Elm_Color_Item *item = (Elm_Color_Item *)data;
1237 ELM_COLORSELECTOR_DATA_GET(WIDGET(item), sd);
1239 sd->longpress_timer = NULL;
1240 sd->longpressed = EINA_TRUE;
1241 evas_object_smart_callback_call
1242 (WIDGET(item), SIG_COLOR_ITEM_LONGPRESSED, item);
1244 return ECORE_CALLBACK_CANCEL;
1248 _on_color_pressed(void *data,
1250 Evas_Object *obj __UNUSED__,
1251 void *event_info __UNUSED__)
1253 Elm_Color_Item *item = (Elm_Color_Item *)data;
1254 Evas_Event_Mouse_Down *ev = event_info;
1258 ELM_COLORSELECTOR_DATA_GET(WIDGET(item), sd);
1260 if (ev->button != 1) return;
1261 elm_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
1262 sd->longpressed = EINA_FALSE;
1264 if (sd->longpress_timer) ecore_timer_del(sd->longpress_timer);
1265 sd->longpress_timer = ecore_timer_add
1266 (_elm_config->longpress_timeout, _on_color_long_press, data);
1270 _on_color_released(void *data,
1272 Evas_Object *obj __UNUSED__,
1273 void *event_info __UNUSED__)
1275 Elm_Color_Item *item = (Elm_Color_Item *)data;
1277 Elm_Color_Item *temp_item;
1278 Evas_Event_Mouse_Down *ev = event_info;
1281 ELM_COLORSELECTOR_DATA_GET(WIDGET(item), sd);
1283 if (ev->button != 1) return;
1284 if (sd->longpress_timer)
1286 ecore_timer_del(sd->longpress_timer);
1287 sd->longpress_timer = NULL;
1289 elm_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
1290 if (!sd->longpressed)
1292 evas_object_smart_callback_call
1293 (WIDGET(item), SIG_COLOR_ITEM_SELECTED, item);
1294 elm_colorselector_color_set
1295 (WIDGET(item), item->color->r, item->color->g, item->color->b,
1298 EINA_LIST_FOREACH(sd->items, l, temp_item)
1299 if (item == temp_item) sd->selected = l;
1300 sd->focused = ELM_COLORSELECTOR_PALETTE;
1304 _access_info_cb(void *data, Evas_Object *obj __UNUSED__)
1308 int r = 0, g = 0, b = 0 ,a = 0;
1310 Elm_Color_Item *it = data;
1311 ELM_COLORSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1313 elm_colorselector_palette_item_color_get((Elm_Object_Item *)it, &r, &g, &b, &a);
1315 buf = eina_strbuf_new();
1316 eina_strbuf_append_printf(buf, "red %d, green %d, blue %d, alpha %d", r, g, b, a);
1317 ret = eina_strbuf_string_steal(buf);
1318 eina_strbuf_free(buf);
1323 _access_widget_item_register(Elm_Color_Item *it)
1325 Elm_Access_Info *ai;
1327 _elm_access_widget_item_register((Elm_Widget_Item *)it);
1329 ai = _elm_access_object_get(it->base.access_obj);
1331 _elm_access_text_set(ai, ELM_ACCESS_TYPE, E_("color selector palette item"));
1332 _elm_access_callback_set(ai, ELM_ACCESS_INFO, _access_info_cb, it);
1336 _item_resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1337 void *event_info __UNUSED__)
1339 elm_layout_sizing_eval(obj);
1342 static Elm_Color_Item *
1343 _item_new(Evas_Object *obj)
1345 Elm_Color_Item *item;
1347 item = elm_widget_item_new(obj, Elm_Color_Item);
1348 if (!item) return NULL;
1350 VIEW(item) = elm_layout_add(obj);
1351 elm_layout_theme_set
1352 (VIEW(item), "colorselector", "item", elm_widget_style_get(obj));
1353 evas_object_size_hint_weight_set
1354 (VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1355 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1356 evas_object_event_callback_add
1357 (VIEW(item), EVAS_CALLBACK_RESIZE, _item_resize, NULL);
1359 item->color_obj = edje_object_add(evas_object_evas_get(obj));
1360 elm_widget_theme_object_set
1361 (obj, item->color_obj, "colorselector", "item/color",
1362 elm_widget_style_get(obj));
1363 evas_object_size_hint_weight_set
1364 (item->color_obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1365 evas_object_size_hint_align_set
1366 (item->color_obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
1367 evas_object_event_callback_add
1368 (item->color_obj, EVAS_CALLBACK_MOUSE_DOWN, _on_color_pressed, item);
1369 evas_object_event_callback_add
1370 (item->color_obj, EVAS_CALLBACK_MOUSE_UP, _on_color_released, item);
1371 elm_object_part_content_set(VIEW(item), "color_obj", item->color_obj);
1373 _item_sizing_eval(item);
1374 evas_object_show(VIEW(item));
1377 if (_elm_config->access_mode == ELM_ACCESS_MODE_ON)
1378 _access_widget_item_register(item);
1384 _colors_remove(Evas_Object *obj)
1386 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1389 _elm_config_colors_free(sd->palette_name);
1393 _colors_save(Evas_Object *obj)
1396 Elm_Color_Item *item;
1398 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1400 _elm_config_colors_free(sd->palette_name);
1401 EINA_LIST_FOREACH(sd->items, elist, item)
1402 _elm_config_color_set(sd->palette_name, item->color->r, item->color->g,
1403 item->color->b, item->color->a);
1407 _palette_colors_load(Evas_Object *obj)
1410 Elm_Color_Item *item;
1411 Eina_List *color_list;
1412 Elm_Color_RGBA *color;
1414 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1416 color_list = _elm_config_color_list_get(sd->palette_name);
1417 if (!color_list) return;
1419 EINA_LIST_FOREACH(color_list, elist, color)
1421 item = _item_new(obj);
1424 item->color = ELM_NEW(Elm_Color_RGBA);
1425 if (!item->color) return;
1426 item->color->r = color->r;
1427 item->color->g = color->g;
1428 item->color->b = color->b;
1429 item->color->a = color->a;
1431 elm_box_pack_end(sd->palette_box, VIEW(item));
1432 evas_object_color_set
1433 (item->color_obj, item->color->r, item->color->g, item->color->b,
1436 sd->items = eina_list_append(sd->items, item);
1439 sd->config_load = EINA_TRUE;
1443 _elm_colorselector_smart_add(Evas_Object *obj)
1445 const char *hpadstr, *vpadstr;
1446 unsigned int h_pad = DEFAULT_HOR_PAD;
1447 unsigned int v_pad = DEFAULT_VER_PAD;
1449 EVAS_SMART_DATA_ALLOC(obj, Elm_Colorselector_Smart_Data);
1451 ELM_WIDGET_CLASS(_elm_colorselector_parent_sc)->base.add(obj);
1453 elm_layout_theme_set
1454 (obj, "colorselector", "palette", elm_object_style_get(obj));
1456 priv->palette_box = elm_box_add(obj);
1458 (priv->palette_box, evas_object_box_layout_flow_horizontal, NULL, NULL);
1459 elm_box_horizontal_set(priv->palette_box, EINA_TRUE);
1460 evas_object_size_hint_weight_set
1461 (priv->palette_box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1462 evas_object_size_hint_align_set
1463 (priv->palette_box, EVAS_HINT_FILL, EVAS_HINT_FILL);
1464 elm_box_homogeneous_set(priv->palette_box, EINA_TRUE);
1467 edje_object_data_get(ELM_WIDGET_DATA(priv)->resize_obj, "horizontal_pad");
1468 if (hpadstr) h_pad = atoi(hpadstr);
1469 vpadstr = edje_object_data_get
1470 (ELM_WIDGET_DATA(priv)->resize_obj, "vertical_pad");
1471 if (vpadstr) v_pad = atoi(vpadstr);
1475 (h_pad * elm_widget_scale_get(obj) * elm_config_scale_get()),
1476 (v_pad * elm_widget_scale_get(obj) * elm_config_scale_get()));
1478 elm_box_align_set(priv->palette_box, 0.5, 0.5);
1479 elm_layout_content_set(obj, "palette", priv->palette_box);
1480 priv->palette_name = eina_stringshare_add("default");
1481 _palette_colors_load(obj);
1483 /* load background edj */
1484 priv->col_bars_area = edje_object_add(evas_object_evas_get(obj));
1485 elm_widget_theme_object_set
1486 (obj, priv->col_bars_area, "colorselector", "bg",
1487 elm_widget_style_get(obj));
1488 elm_layout_content_set(obj, "selector", priv->col_bars_area);
1490 /* setup the color picker */
1491 priv->picker = elm_box_add(obj);
1492 elm_box_horizontal_set(priv->picker, EINA_TRUE);
1493 evas_object_size_hint_weight_set(priv->picker, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1494 evas_object_size_hint_align_set(priv->picker, EVAS_HINT_FILL, EVAS_HINT_FILL);
1496 elm_box_padding_set(priv->picker,
1497 (h_pad * elm_widget_scale_get(obj) * elm_config_scale_get()),
1498 (v_pad * elm_widget_scale_get(obj) * elm_config_scale_get()));
1499 elm_box_align_set(priv->palette_box, 0.5, 0.5);
1501 priv->mode = ELM_COLORSELECTOR_BOTH;
1502 priv->focused = ELM_COLORSELECTOR_PALETTE;
1503 priv->sel_color_type = HUE;
1504 priv->selected = priv->items;
1514 priv->grab.xroot = -1;
1515 priv->grab.mouse_motion = NULL;
1516 priv->grab.mouse_up = NULL;
1517 priv->grab.key_up = NULL;
1518 priv->grab.in = EINA_TRUE;
1521 _color_bars_add(obj);
1522 _color_picker_add(obj, priv);
1524 elm_layout_sizing_eval(obj);
1525 elm_widget_can_focus_set(obj, EINA_TRUE);
1529 _elm_colorselector_smart_del(Evas_Object *obj)
1534 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1536 evas_event_callback_del_full(evas_object_evas_get(obj), EVAS_CALLBACK_CANVAS_FOCUS_IN, _mouse_in_canvas, obj);
1537 evas_event_callback_del_full(evas_object_evas_get(obj), EVAS_CALLBACK_CANVAS_FOCUS_OUT, _mouse_out_canvas, obj);
1539 if (sd->longpress_timer) ecore_timer_del(sd->longpress_timer);
1540 if (sd->palette_name) eina_stringshare_del(sd->palette_name);
1541 if (sd->grab.mouse_motion) ecore_event_handler_del(sd->grab.mouse_motion);
1542 if (sd->grab.mouse_up) ecore_event_handler_del(sd->grab.mouse_up);
1543 if (sd->grab.key_up) ecore_event_handler_del(sd->grab.key_up);
1546 /* This cb_data are used during the destruction process of base.del */
1547 for (i = 0; i < 4; i++)
1548 tmp[i] = sd->cb_data[i];
1549 ELM_WIDGET_CLASS(_elm_colorselector_parent_sc)->base.del(obj);
1550 for (i = 0; i < 4; i++)
1555 _elm_colorselector_smart_event(Evas_Object *obj,
1556 Evas_Object *src __UNUSED__,
1557 Evas_Callback_Type type,
1560 Eina_List *cl = NULL;
1561 Elm_Color_Item *item = NULL;
1562 char colorbar_s[128];
1563 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
1564 Evas_Event_Key_Down *ev = event_info;
1565 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1567 if (!sd) return EINA_FALSE;
1568 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
1569 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
1570 if (!sd->selected) sd->selected = sd->items;
1572 if ((!strcmp(ev->keyname, "Left")) ||
1573 ((!strcmp(ev->keyname, "KP_Left")) && (!ev->string)))
1575 if (sd->focused == ELM_COLORSELECTOR_PALETTE && sd->selected)
1576 cl = eina_list_prev(sd->selected);
1577 else if (sd->focused == ELM_COLORSELECTOR_COMPONENTS)
1578 _button_clicked_cb(sd->cb_data[sd->sel_color_type], sd->cb_data[sd->sel_color_type]->lbt, NULL);
1579 else return EINA_FALSE;
1581 else if ((!strcmp(ev->keyname, "Right")) ||
1582 ((!strcmp(ev->keyname, "KP_Right")) && (!ev->string)))
1584 if (sd->focused == ELM_COLORSELECTOR_PALETTE && sd->selected)
1585 cl = eina_list_next(sd->selected);
1586 else if (sd->focused == ELM_COLORSELECTOR_COMPONENTS)
1587 _button_clicked_cb(sd->cb_data[sd->sel_color_type], sd->cb_data[sd->sel_color_type]->rbt, NULL);
1588 else return EINA_FALSE;
1590 else if ((!strcmp(ev->keyname, "Up")) ||
1591 ((!strcmp(ev->keyname, "KP_Up")) && (!ev->string)))
1593 if (sd->focused == ELM_COLORSELECTOR_COMPONENTS)
1595 sd->sel_color_type = sd->sel_color_type - 1;
1596 if (sd->sel_color_type < HUE)
1598 if (sd->mode == ELM_COLORSELECTOR_BOTH)
1600 sd->focused = ELM_COLORSELECTOR_PALETTE;
1601 /*when focus is shifted to palette start from
1603 sd->selected = sd->items;
1608 sd->sel_color_type = HUE;
1613 else if (sd->focused == ELM_COLORSELECTOR_PALETTE)
1616 else if ((!strcmp(ev->keyname, "Down")) ||
1617 ((!strcmp(ev->keyname, "KP_Down")) && (!ev->string)))
1619 if (sd->focused == ELM_COLORSELECTOR_PALETTE)
1621 if (sd->mode == ELM_COLORSELECTOR_BOTH)
1623 sd->focused = ELM_COLORSELECTOR_COMPONENTS;
1624 /*when focus is shifted to component start from
1625 * first color type*/
1626 sd->sel_color_type = HUE;
1628 else return EINA_FALSE;
1630 else if (sd->focused == ELM_COLORSELECTOR_COMPONENTS)
1632 snprintf(colorbar_s, sizeof(colorbar_s), "elm.colorbar_%d",
1633 (sd->sel_color_type + 1));
1634 /*Append color type only if next color bar is available*/
1635 if (edje_object_part_swallow_get(sd->col_bars_area, colorbar_s))
1636 sd->sel_color_type = sd->sel_color_type + 1;
1637 else return EINA_FALSE;
1640 else return EINA_FALSE;
1643 item = eina_list_data_get(cl);
1644 elm_object_signal_emit(VIEW(item), "elm,anim,activate", "elm");
1645 evas_object_smart_callback_call
1646 (WIDGET(item), SIG_COLOR_ITEM_SELECTED, item);
1647 elm_colorselector_color_set
1648 (WIDGET(item), item->color->r, item->color->g, item->color->b,
1652 else if (!cl && sd->focused == ELM_COLORSELECTOR_PALETTE)
1654 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1659 _elm_colorselector_smart_focus_next(const Evas_Object *obj,
1660 Elm_Focus_Direction dir,
1663 Eina_List *items = NULL;
1665 Elm_Widget_Item *item;
1668 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1669 if (!sd) return EINA_FALSE;
1671 if (!sd->items) return EINA_FALSE;
1673 EINA_LIST_FOREACH(sd->items, l, item)
1674 items = eina_list_append(items, item->access_obj);
1676 for (i = 0; i < 4; i++)
1678 items = eina_list_append(items, sd->cb_data[i]->lbt);
1679 items = eina_list_append(items, sd->cb_data[i]->access_obj);
1680 items = eina_list_append(items, sd->cb_data[i]->rbt);
1683 return elm_widget_focus_list_next_get
1684 (obj, items, eina_list_data_get, dir, next);
1688 _access_obj_process(Evas_Object *obj, Eina_Bool is_access)
1694 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1698 EINA_LIST_FOREACH(sd->items, l, it)
1699 _access_widget_item_register(it);
1701 for (i = 0; i < 4; i++)
1702 _access_colorbar_register(obj, sd->cb_data[i],
1703 "elm.arrow_bg_access");
1707 EINA_LIST_FOREACH(sd->items, l, it)
1708 _elm_access_widget_item_unregister((Elm_Widget_Item *)it);
1710 //TODO: _elm_access_edje_object_part_object_unregister() ?
1715 _access_hook(Evas_Object *obj, Eina_Bool is_access)
1717 ELM_COLORSELECTOR_CHECK(obj);
1718 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1721 ELM_WIDGET_CLASS(ELM_WIDGET_DATA(sd)->api)->focus_next =
1722 _elm_colorselector_smart_focus_next;
1724 ELM_WIDGET_CLASS(ELM_WIDGET_DATA(sd)->api)->focus_next = NULL;
1726 _access_obj_process(obj, is_access);
1730 _elm_colorselector_smart_set_user(Elm_Colorselector_Smart_Class *sc)
1732 ELM_WIDGET_CLASS(sc)->base.add = _elm_colorselector_smart_add;
1733 ELM_WIDGET_CLASS(sc)->base.del = _elm_colorselector_smart_del;
1735 /* not a 'focus chain manager' */
1736 ELM_WIDGET_CLASS(sc)->focus_next = NULL;
1737 ELM_WIDGET_CLASS(sc)->focus_direction = NULL;
1739 ELM_WIDGET_CLASS(sc)->theme = _elm_colorselector_smart_theme;
1740 ELM_WIDGET_CLASS(sc)->event = _elm_colorselector_smart_event;
1742 ELM_LAYOUT_CLASS(sc)->sizing_eval = _elm_colorselector_smart_sizing_eval;
1745 if (_elm_config->access_mode == ELM_ACCESS_MODE_ON)
1746 ELM_WIDGET_CLASS(sc)->focus_next = _elm_colorselector_smart_focus_next;
1748 ELM_WIDGET_CLASS(sc)->access = _access_hook;
1751 EAPI const Elm_Colorselector_Smart_Class *
1752 elm_colorselector_smart_class_get(void)
1754 static Elm_Colorselector_Smart_Class _sc =
1755 ELM_COLORSELECTOR_SMART_CLASS_INIT_NAME_VERSION
1756 (ELM_COLORSELECTOR_SMART_NAME);
1757 static const Elm_Colorselector_Smart_Class *class = NULL;
1758 Evas_Smart_Class *esc = (Evas_Smart_Class *)&_sc;
1763 _elm_colorselector_smart_set(&_sc);
1764 esc->callbacks = _smart_callbacks;
1771 elm_colorselector_add(Evas_Object *parent)
1775 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
1777 obj = elm_widget_add(_elm_colorselector_smart_class_new(), parent);
1778 if (!obj) return NULL;
1780 if (!elm_widget_sub_object_add(parent, obj))
1781 ERR("could not add %p as sub object of %p", obj, parent);
1787 elm_colorselector_color_set(Evas_Object *obj,
1793 ELM_COLORSELECTOR_CHECK(obj);
1795 _colors_set(obj, r, g, b, a);
1799 elm_colorselector_color_get(const Evas_Object *obj,
1805 ELM_COLORSELECTOR_CHECK(obj);
1806 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1815 elm_colorselector_mode_set(Evas_Object *obj,
1816 Elm_Colorselector_Mode mode)
1818 ELM_COLORSELECTOR_CHECK(obj);
1819 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1821 if (sd->mode == mode) return;
1824 evas_object_hide(elm_layout_content_unset(obj, "selector"));
1825 evas_object_hide(elm_layout_content_unset(obj, "palette"));
1826 evas_object_hide(elm_layout_content_unset(obj, "picker"));
1830 case ELM_COLORSELECTOR_PALETTE:
1831 elm_layout_content_set(obj, "palette", sd->palette_box);
1832 elm_layout_signal_emit(obj, "elm,state,palette", "elm");
1833 sd->focused = ELM_COLORSELECTOR_PALETTE;
1834 sd->selected = sd->items;
1837 case ELM_COLORSELECTOR_COMPONENTS:
1838 elm_layout_content_set(obj, "selector", sd->col_bars_area);
1839 elm_layout_signal_emit(obj, "elm,state,components", "elm");
1840 sd->focused = ELM_COLORSELECTOR_COMPONENTS;
1841 sd->sel_color_type = HUE;
1844 case ELM_COLORSELECTOR_BOTH:
1845 elm_layout_content_set(obj, "palette", sd->palette_box);
1846 elm_layout_content_set(obj, "selector", sd->col_bars_area);
1847 elm_layout_signal_emit(obj, "elm,state,both", "elm");
1848 sd->focused = ELM_COLORSELECTOR_PALETTE;
1849 sd->selected = sd->items;
1852 case ELM_COLORSELECTOR_PICKER:
1853 elm_layout_content_set(obj, "picker", sd->picker);
1854 elm_layout_signal_emit(obj, "elm,state,picker", "elm");
1855 sd->focused = ELM_COLORSELECTOR_PICKER;
1858 case ELM_COLORSELECTOR_ALL:
1859 elm_layout_content_set(obj, "picker", sd->picker);
1860 elm_layout_content_set(obj, "palette", sd->palette_box);
1861 elm_layout_content_set(obj, "selector", sd->col_bars_area);
1862 elm_layout_signal_emit(obj, "elm,state,all", "elm");
1863 sd->focused = ELM_COLORSELECTOR_PALETTE;
1864 sd->selected = sd->items;
1871 edje_object_message_signal_process(ELM_WIDGET_DATA(sd)->resize_obj);
1873 elm_layout_sizing_eval(obj);
1876 EAPI Elm_Colorselector_Mode
1877 elm_colorselector_mode_get(const Evas_Object *obj)
1879 ELM_COLORSELECTOR_CHECK(obj) ELM_COLORSELECTOR_BOTH;
1880 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1886 elm_colorselector_palette_item_color_get(const Elm_Object_Item *it,
1892 Elm_Color_Item *item;
1894 ELM_COLORSELECTOR_ITEM_CHECK_OR_RETURN(it);
1896 item = (Elm_Color_Item *)it;
1899 if (r) *r = item->color->r;
1900 if (g) *g = item->color->g;
1901 if (b) *b = item->color->b;
1902 if (a) *a = item->color->a;
1907 elm_colorselector_palette_item_color_set(Elm_Object_Item *it,
1913 Elm_Color_Item *item;
1915 ELM_COLORSELECTOR_ITEM_CHECK_OR_RETURN(it);
1917 item = (Elm_Color_Item *)it;
1922 evas_object_color_set
1923 (item->color_obj, item->color->r, item->color->g, item->color->b,
1926 _colors_save(WIDGET(it));
1929 EAPI Elm_Object_Item *
1930 elm_colorselector_palette_color_add(Evas_Object *obj,
1936 Elm_Color_Item *item;
1938 ELM_COLORSELECTOR_CHECK(obj) NULL;
1939 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1941 if (sd->config_load)
1943 _colors_remove(obj);
1944 sd->config_load = EINA_FALSE;
1946 item = _item_new(obj);
1947 if (!item) return NULL;
1949 item->color = ELM_NEW(Elm_Color_RGBA);
1950 if (!item->color) return NULL;
1956 _elm_config_color_set
1957 (sd->palette_name, item->color->r, item->color->g, item->color->b,
1960 elm_box_pack_end(sd->palette_box, VIEW(item));
1961 evas_object_color_set
1962 (item->color_obj, item->color->r, item->color->g, item->color->b,
1965 sd->items = eina_list_append(sd->items, item);
1967 elm_layout_sizing_eval(obj);
1969 return (Elm_Object_Item *)item;
1973 elm_colorselector_palette_clear(Evas_Object *obj)
1975 ELM_COLORSELECTOR_CHECK(obj);
1976 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1978 _colors_remove(obj);
1979 if (sd->mode == ELM_COLORSELECTOR_BOTH)
1980 sd->focused = ELM_COLORSELECTOR_COMPONENTS;
1984 elm_colorselector_palette_name_set(Evas_Object *obj,
1985 const char *palette_name)
1987 ELM_COLORSELECTOR_CHECK(obj);
1988 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1989 EINA_SAFETY_ON_NULL_RETURN(palette_name);
1991 if (!strcmp(sd->palette_name, palette_name)) return;
1993 _colors_remove(obj);
1994 eina_stringshare_replace(&sd->palette_name, palette_name);
1995 _palette_colors_load(obj);
1999 elm_colorselector_palette_name_get(const Evas_Object *obj)
2001 ELM_COLORSELECTOR_CHECK(obj) NULL;
2002 ELM_COLORSELECTOR_DATA_GET(obj, sd);
2004 return sd->palette_name;