2 # include "elementary_config.h"
5 #include <Elementary.h>
7 #include "elm_widget_colorselector.h"
9 #define MY_CLASS ELM_OBJ_COLORSELECTOR_CLASS
11 #define MY_CLASS_NAME "Elm_Colorselector"
12 #define MY_CLASS_NAME_LEGACY "elm_colorselector"
14 #define BASE_STEP 360.0
15 #define HUE_STEP 360.0
16 #define SAT_STEP 128.0
17 #define LIG_STEP 256.0
18 #define ALP_STEP 256.0
19 #define DEFAULT_HOR_PAD 10
20 #define DEFAULT_VER_PAD 10
22 static const char SIG_CHANGED[] = "changed";
23 static const char SIG_COLOR_ITEM_SELECTED[] = "color,item,selected";
24 static const char SIG_COLOR_ITEM_LONGPRESSED[] = "color,item,longpressed";
25 static const Evas_Smart_Cb_Description _smart_callbacks[] =
27 {SIG_COLOR_ITEM_SELECTED, ""},
28 {SIG_COLOR_ITEM_LONGPRESSED, ""},
30 {SIG_WIDGET_LANG_CHANGED, ""}, /**< handled by elm_widget */
31 {SIG_WIDGET_ACCESS_CHANGED, ""}, /**< handled by elm_widget */
32 {SIG_LAYOUT_FOCUSED, ""}, /**< handled by elm_layout */
33 {SIG_LAYOUT_UNFOCUSED, ""}, /**< handled by elm_layout */
37 static Eina_Bool _key_action_move(Evas_Object *obj, const char *params);
39 static const Elm_Action key_actions[] = {
40 {"move", _key_action_move},
44 enum Palette_Box_Direction
51 _items_del(Elm_Colorselector_Data *sd)
55 if (!sd->items) return;
57 EINA_LIST_FREE(sd->items, item)
60 elm_widget_item_free(item);
68 _color_with_saturation(Elm_Colorselector_Data *sd, int *sr, int *sg, int *sb)
71 *sr = 127 + (int)((double)(sd->er - 127) * sd->s);
73 *sr = 127 - (int)((double)(127 - sd->er) * sd->s);
76 *sg = 127 + (int)((double)(sd->eg - 127) * sd->s);
78 *sg = 127 - (int)((double)(127 - sd->eg) * sd->s);
81 *sb = 127 + (int)((double)(sd->eb - 127) * sd->s);
83 *sb = 127 - (int)((double)(127 - sd->eb) * sd->s);
87 _color_with_lightness(Elm_Colorselector_Data *sd, int *lr, int *lg, int *lb)
91 *lr = sd->er + (int)((double)(255 - sd->er) * (sd->l - 0.5) * 2.0);
92 *lg = sd->eg + (int)((double)(255 - sd->eg) * (sd->l - 0.5) * 2.0);
93 *lb = sd->eb + (int)((double)(255 - sd->eb) * (sd->l - 0.5) * 2.0);
97 *lr = (double)sd->er * sd->l * 2.0;
98 *lg = (double)sd->eg * sd->l * 2.0;
99 *lb = (double)sd->eb * sd->l * 2.0;
110 _color_picker_init(Elm_Colorselector_Data *sd)
113 unsigned int *pixels;
118 if (!evas_object_data_get(sd->entries[0], "_changed"))
120 snprintf(buf, 12, "%i", sd->r);
121 elm_object_text_set(sd->entries[0], buf);
123 if (!evas_object_data_get(sd->entries[1], "_changed"))
125 snprintf(buf, 12, "%i", sd->g);
126 elm_object_text_set(sd->entries[1], buf);
128 if (!evas_object_data_get(sd->entries[2], "_changed"))
130 snprintf(buf, 12, "%i", sd->b);
131 elm_object_text_set(sd->entries[2], buf);
133 if (!evas_object_data_get(sd->entries[3], "_changed"))
135 snprintf(buf, 12, "%i", sd->a);
136 elm_object_text_set(sd->entries[3], buf);
139 color = (sd->a << 24) |
140 (((sd->r * sd->a) / 255) << 16) |
141 (((sd->g * sd->a) / 255) << 8) |
142 (((sd->b * sd->a) / 255));
145 evas_object_image_alpha_set(sd->picker_display, EINA_FALSE);
147 evas_object_image_alpha_set(sd->picker_display, EINA_TRUE);
149 pixels = evas_object_image_data_get(sd->picker_display, EINA_TRUE);
151 for (y = 0; y < 17; y++)
153 for (x = 0; x < 17; x++)
158 evas_object_image_data_set(sd->picker_display, copy);
159 evas_object_geometry_get(sd->picker_display, NULL, NULL, &w, &h);
160 evas_object_image_data_update_add(sd->picker_display, 0, 0, w, h);
164 _rgb_to_hsl(Elm_Colorselector_Data *sd)
188 sd->l = (m + v) / 2.0;
190 if (sd->l <= 0.0) return;
195 if (sd->s > 0.0) sd->s /= (sd->l <= 0.5) ? (v + m) : (2.0 - v - m);
202 if (r == v) sd->h = (g == m ? 5.0 + b2 : 1.0 - g2);
204 sd->h = (b == m ? 1.0 + r2 : 3.0 - b2);
205 else sd->h = (r == m ? 3.0 + g2 : 5.0 - r2);
211 _hsl_to_rgb(Elm_Colorselector_Data *sd)
213 double sv, vsf, f, p, q, t, v;
214 double r = 0, g = 0, b = 0;
222 if (_s == 0.0) r = g = b = _l;
225 if (_h == 360.0) _h = 0.0;
228 v = (_l <= 0.5) ? (_l * (1.0 + _s)) : (_l + _s - (_l * _s));
231 if (v) sv = (v - p) / v;
281 i = (int)(r * 255.0);
283 r = (f <= 0.5) ? i : (i + 1);
285 i = (int)(g * 255.0);
287 g = (f <= 0.5) ? i : (i + 1);
289 i = (int)(b * 255.0);
291 b = (f <= 0.5) ? i : (i + 1);
293 if (sd->r == r && sd->g == g && sd->b == b) return EINA_FALSE;
303 _update_ergb(Elm_Colorselector_Data *sd, double x)
305 double one_six = 1.0 / 6.0;
310 sd->eg = (255.0 * x * 6.0);
313 else if (x < 2 * one_six)
315 sd->er = 255 - (int)(255.0 * (x - one_six) * 6.0);
319 else if (x < 3 * one_six)
323 sd->eb = (int)(255.0 * (x - (2.0 * one_six)) * 6.0);
325 else if (x < 4 * one_six)
328 sd->eg = 255 - (int)(255.0 * (x - (3.0 * one_six)) * 6.0);
331 else if (x < 5 * one_six)
333 sd->er = 255.0 * (x - (4.0 * one_six)) * 6.0;
341 sd->eb = 255 - (int)(255.0 * (x - (5.0 * one_six)) * 6.0);
346 _update_colorbars(Elm_Colorselector_Data *sd)
349 evas_object_color_set
350 (sd->cb_data[0]->arrow, sd->er, sd->eg, sd->eb, 255);
351 evas_object_color_set
352 (sd->cb_data[1]->bg_rect, sd->er, sd->eg, sd->eb, 255);
353 evas_object_color_set
354 (sd->cb_data[2]->bg_rect, sd->er, sd->eg, sd->eb, 255);
355 evas_object_color_set
356 (sd->cb_data[3]->bar, sd->er, sd->eg, sd->eb, 255);
358 _color_with_saturation(sd, &r, &g, &b);
359 evas_object_color_set(sd->cb_data[1]->arrow, r, g, b, 255);
361 _color_with_lightness(sd, &r, &g, &b);
362 evas_object_color_set(sd->cb_data[2]->arrow, r, g, b, 255);
364 evas_object_color_set(sd->cb_data[3]->arrow,
365 (sd->er * sd->a) / 255,
366 (sd->eg * sd->a) / 255,
367 (sd->eb * sd->a) / 255,
372 _update_hsla_from_colorbar(Evas_Object *obj, Color_Type type, double x)
376 ELM_COLORSELECTOR_DATA_GET(obj, sd);
395 if (ta == sd->a) return;
403 if (type != ALPHA && !_hsl_to_rgb(sd)) return;
405 _update_colorbars(sd);
406 _color_picker_init(sd);
407 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
411 _colors_set(Evas_Object *obj,
419 ELM_COLORSELECTOR_DATA_GET(obj, sd);
421 if ((sd->r == r) && (sd->g == g) && (sd->b == b) && (sd->a == a))
431 edje_object_part_drag_value_get
432 (sd->cb_data[0]->colorbar, "elm.arrow", &x, &y);
434 edje_object_part_drag_value_set
435 (sd->cb_data[0]->colorbar, "elm.arrow", x, y);
438 edje_object_part_drag_value_get
439 (sd->cb_data[1]->colorbar, "elm.arrow", &x, &y);
441 edje_object_part_drag_value_set
442 (sd->cb_data[1]->colorbar, "elm.arrow", x, y);
444 edje_object_part_drag_value_get
445 (sd->cb_data[2]->colorbar, "elm.arrow", &x, &y);
447 edje_object_part_drag_value_set(sd->cb_data[2]->colorbar, "elm.arrow", x, y);
449 edje_object_part_drag_value_get
450 (sd->cb_data[3]->colorbar, "elm.arrow", &x, &y);
452 edje_object_part_drag_value_set
453 (sd->cb_data[3]->colorbar, "elm.arrow", x, y);
455 _update_colorbars(sd);
456 _color_picker_init(sd);
457 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
461 _entry_changed_cb(void *data,
463 void *event_info EINA_UNUSED)
465 Elm_Colorselector_Data *sd = data;
470 for (i = 0; i < 4 && sd->entries[i] != obj; i++);
472 parent = evas_object_data_get(obj, "parent");
473 text = elm_object_text_get(obj);
475 if (v > 255) v = 255;
476 else if (v < 0) v = 0;
477 evas_object_data_set(obj, "_changed", obj);
482 _colors_set(parent, v, sd->g, sd->b, sd->a);
485 _colors_set(parent, sd->r, v, sd->b, sd->a);
488 _colors_set(parent, sd->r, sd->g, v, sd->a);
491 _colors_set(parent, sd->r, sd->g, sd->b, v);
494 evas_object_data_del(obj, "_changed");
497 #ifdef HAVE_ELEMENTARY_X
498 static Eina_Bool _mouse_grab_pixels(void *data, int type EINA_UNUSED, void *event EINA_UNUSED);
499 static Eina_Bool _key_up_cb(void *data, int type EINA_UNUSED, void *event EINA_UNUSED);
500 static Eina_Bool _mouse_up_cb(void *data, int type EINA_UNUSED, void *event EINA_UNUSED);
502 static Ecore_X_Window
503 _x11_elm_widget_xwin_get(const Evas_Object *obj)
506 Ecore_X_Window xwin = 0;
508 top = elm_widget_top_get(obj);
509 if (!top) top = elm_widget_top_get(elm_widget_parent_widget_get(obj));
510 if (top) xwin = elm_win_xwindow_get(top);
514 Evas *evas = evas_object_evas_get(obj);
516 ee = ecore_evas_ecore_evas_get(evas);
518 xwin = _elm_ee_xwin_get(ee);
524 _start_grab_pick_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
526 Evas_Object *o = data;
528 ELM_COLORSELECTOR_DATA_GET(o, sd);
530 elm_object_disabled_set(obj, EINA_TRUE);
532 sd->grab.mouse_motion = ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE, _mouse_grab_pixels, o);
533 sd->grab.key_up = ecore_event_handler_add(ECORE_EVENT_KEY_UP, _key_up_cb, o);
534 sd->grab.mouse_up = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, _mouse_up_cb, o);
536 ecore_x_keyboard_grab(sd->grab.xroot);
537 ecore_x_pointer_grab(sd->grab.xroot);
541 _key_up_cb(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
543 Evas_Object *o = data;
546 ELM_COLORSELECTOR_DATA_GET(o, sd);
548 elm_object_disabled_set(sd->button, EINA_FALSE);
549 ecore_x_keyboard_ungrab();
550 ecore_x_pointer_ungrab();
551 ELM_SAFE_FREE(sd->grab.mouse_motion, ecore_event_handler_del);
552 ELM_SAFE_FREE(sd->grab.key_up, ecore_event_handler_del);
553 ELM_SAFE_FREE(sd->grab.mouse_up, ecore_event_handler_del);
559 _mouse_up_cb(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
561 const unsigned int *pixels;
562 Evas_Object *o = data;
565 /* mouse up => check it */
566 ELM_COLORSELECTOR_DATA_GET(o, sd);
568 elm_object_disabled_set(sd->button, EINA_FALSE);
569 ecore_x_keyboard_ungrab();
570 ecore_x_pointer_ungrab();
571 ELM_SAFE_FREE(sd->grab.mouse_motion, ecore_event_handler_del);
572 ELM_SAFE_FREE(sd->grab.key_up, ecore_event_handler_del);
573 ELM_SAFE_FREE(sd->grab.mouse_up, ecore_event_handler_del);
575 pixels = evas_object_image_data_get(sd->picker_display, EINA_FALSE);
576 r = (pixels[17 * 9 + 9] >> 16) & 0xFF;
577 g = (pixels[17 * 9 + 9] >> 8) & 0xFF;
578 b = pixels[17 * 9 + 9] & 0xFF;
580 _colors_set(o, r, g, b, 0xFF);
586 _mouse_grab_pixels(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
588 Evas_Object *obj = data;
589 Ecore_X_Visual visual;
590 Ecore_X_Display *display;
595 int bpl = 0, rows = 0, bpp = 0;
598 ELM_COLORSELECTOR_DATA_GET(obj, sd);
600 if (sd->grab.in) return EINA_TRUE;
602 xwin = _x11_elm_widget_xwin_get(obj);
603 sd->grab.xroot = ecore_x_window_root_get(xwin);
604 ecore_x_pointer_xy_get(sd->grab.xroot, &x, &y);
609 if (sd->grab.x == x && sd->grab.y == y) return EINA_TRUE;
613 evas_object_image_alpha_set(sd->picker_display, EINA_FALSE);
615 display = ecore_x_display_get();
616 scr = ecore_x_default_screen_get();
617 visual = ecore_x_default_visual_get(display, scr);
618 img = ecore_x_image_new(17, 17, visual, ecore_x_window_depth_get(sd->grab.xroot));
619 ecore_x_image_get(img, sd->grab.xroot, x - 8, y - 8, 0, 0, 17, 17);
620 src = ecore_x_image_data_get(img, &bpl, &rows, &bpp);
621 if (!ecore_x_image_is_argb32_get(img))
623 Ecore_X_Colormap colormap;
624 unsigned int *pixels;
626 colormap = ecore_x_default_colormap_get(display, scr);
627 pixels = evas_object_image_data_get(sd->picker_display, EINA_TRUE);
628 ecore_x_image_to_argb_convert(src, bpp, bpl, colormap, visual,
630 pixels, (17 * sizeof(int)), 0, 0);
634 evas_object_image_data_copy_set(sd->picker_display, src);
637 ecore_x_image_free(img);
639 evas_object_geometry_get(sd->picker_display, NULL, NULL, &w, &h);
640 evas_object_image_data_update_add(sd->picker_display, 0, 0, w, h);
647 _mouse_in_canvas(void *data, Evas *e EINA_UNUSED, void *event_info EINA_UNUSED)
649 Evas_Object *obj = data;
650 ELM_COLORSELECTOR_DATA_GET(obj, sd);
652 sd->grab.in = EINA_TRUE;
656 _mouse_out_canvas(void *data, Evas *e EINA_UNUSED, void *event_info EINA_UNUSED)
658 Evas_Object *obj = data;
659 ELM_COLORSELECTOR_DATA_GET(obj, sd);
661 sd->grab.in = EINA_FALSE;
665 _color_picker_add(Evas_Object *obj, Elm_Colorselector_Data *sd)
673 static const char *labels[4] = { "R:", "G:", "B:", "A:" };
675 #ifdef HAVE_ELEMENTARY_X
678 xwin = _x11_elm_widget_xwin_get(obj);
681 sd->grab.xroot = ecore_x_window_root_get(xwin);
682 ecore_x_input_raw_select(sd->grab.xroot);
686 bx = elm_box_add(sd->picker);
687 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
688 evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
689 elm_box_pack_end(sd->picker, bx);
690 evas_object_show(bx);
692 ed = edje_object_add(evas_object_evas_get(sd->picker));
693 elm_widget_theme_object_set(obj, ed, "colorselector", "picker", elm_widget_style_get(obj));
694 evas_object_size_hint_weight_set(ed, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
695 evas_object_size_hint_align_set(ed, EVAS_HINT_FILL, EVAS_HINT_FILL);
696 elm_box_pack_end(bx, ed);
697 evas_object_show(ed);
699 #ifdef HAVE_ELEMENTARY_X
702 sd->button = elm_button_add(sd->picker);
703 elm_object_text_set(sd->button, "Pick a color");
704 evas_object_smart_callback_add(sd->button, "clicked", _start_grab_pick_cb, obj);
705 elm_box_pack_end(bx, sd->button);
706 evas_object_show(sd->button);
710 im = evas_object_image_add(evas_object_evas_get(sd->picker));
711 evas_object_size_hint_aspect_set(im, EVAS_ASPECT_CONTROL_BOTH, 1, 1);
712 evas_object_image_smooth_scale_set(im, EINA_FALSE);
713 evas_object_image_colorspace_set(im, EVAS_COLORSPACE_ARGB8888);
714 evas_object_image_size_set(im, 17, 17);
715 evas_object_image_alpha_set(im, EINA_TRUE);
716 evas_object_image_filled_set(im, EINA_TRUE);
717 edje_object_part_swallow(ed, "elm.picker", im);
718 elm_widget_sub_object_add(obj, im);
720 sd->picker_display = im;
722 table = elm_table_add(sd->picker);
723 evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
724 evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL);
725 elm_box_pack_end(sd->picker, table);
726 evas_object_show(table);
728 for (i = 0; i < 4; i++)
730 static Elm_Entry_Filter_Accept_Set accept_set = {
731 .accepted = "0123456789",
735 label = elm_label_add(table);
736 elm_object_text_set(label, labels[i]);
737 evas_object_size_hint_weight_set(label, 0.0, EVAS_HINT_EXPAND);
738 evas_object_size_hint_align_set(label, 0.0, EVAS_HINT_FILL);
739 elm_table_pack(table, label, 0, i, 1, 1);
740 evas_object_show(label);
742 entry = elm_entry_add(table);
743 elm_entry_markup_filter_append(entry, elm_entry_filter_accept_set, &accept_set);
744 elm_entry_single_line_set(entry, EINA_TRUE);
745 elm_entry_scrollable_set(entry, EINA_TRUE);
746 evas_object_data_set(entry, "parent", obj);
747 evas_object_smart_callback_add(entry, "changed", _entry_changed_cb, sd);
748 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
749 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
750 elm_table_pack(table, entry, 1, i, 1, 1);
751 evas_object_show(entry);
753 sd->entries[i] = entry;
756 evas_event_callback_add(evas_object_evas_get(obj), EVAS_CALLBACK_CANVAS_FOCUS_IN, _mouse_in_canvas, obj);
757 evas_event_callback_add(evas_object_evas_get(obj), EVAS_CALLBACK_CANVAS_FOCUS_OUT, _mouse_out_canvas, obj);
759 _color_picker_init(sd);
763 _arrow_cb(void *data,
765 const char *emission EINA_UNUSED,
766 const char *source EINA_UNUSED)
768 Color_Bar_Data *cb_data = data;
771 edje_object_part_drag_value_get(obj, "elm.arrow", &x, &y);
772 _update_hsla_from_colorbar(cb_data->parent, cb_data->color_type, x);
776 _colorbar_cb(void *data,
778 Evas_Object *obj EINA_UNUSED,
781 Evas_Event_Mouse_Down *ev = event_info;
782 Color_Bar_Data *cb_data = data;
783 double arrow_x = 0, arrow_y;
784 Evas_Coord x, y, w, h;
785 ELM_COLORSELECTOR_DATA_GET(cb_data->parent, sd);
787 evas_object_geometry_get(cb_data->bar, &x, &y, &w, &h);
788 edje_object_part_drag_value_get
789 (cb_data->colorbar, "elm.arrow", &arrow_x, &arrow_y);
791 if (w > 0) arrow_x = (double)(ev->canvas.x - x) / (double)w;
792 if (arrow_x > 1) arrow_x = 1;
793 if (arrow_x < 0) arrow_x = 0;
794 edje_object_part_drag_value_set
795 (cb_data->colorbar, "elm.arrow", arrow_x, arrow_y);
797 _update_hsla_from_colorbar(cb_data->parent, cb_data->color_type, arrow_x);
798 evas_event_feed_mouse_cancel(e, 0, NULL);
799 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);
800 sd->sel_color_type = cb_data->color_type;
801 sd->focused = ELM_COLORSELECTOR_COMPONENTS;
805 _button_clicked_cb(void *data,
807 void *event_info EINA_UNUSED)
809 Color_Bar_Data *cb_data = data;
811 ELM_COLORSELECTOR_DATA_GET(cb_data->parent, sd);
813 if (obj == cb_data->rbt) step = 1.0;
816 edje_object_part_drag_value_get(cb_data->colorbar, "elm.arrow", &x, &y);
818 switch (cb_data->color_type)
821 x += step / HUE_STEP;
825 x += step / SAT_STEP;
829 x += step / LIG_STEP;
833 x += step / ALP_STEP;
840 if (x > 1.0) x = 1.0;
841 else if (x < 0.0) x = 0.0;
843 edje_object_part_drag_value_set(cb_data->colorbar, "elm.arrow", x, y);
844 _update_hsla_from_colorbar(cb_data->parent, cb_data->color_type, x);
845 sd->sel_color_type = cb_data->color_type;
846 sd->focused = ELM_COLORSELECTOR_COMPONENTS;
850 _button_repeat_cb(void *data,
851 Evas_Object *obj EINA_UNUSED,
852 void *event_info EINA_UNUSED)
854 Color_Bar_Data *cb_data = data;
857 if (obj == cb_data->rbt) step = 1.0 / BASE_STEP;
858 else step = -1.0 / BASE_STEP;
860 edje_object_part_drag_value_get(cb_data->colorbar, "elm.arrow", &x, &y);
863 if (x > 1.0) x = 1.0;
864 else if (x < 0.0) x = 0.0;
866 edje_object_part_drag_value_set(cb_data->colorbar, "elm.arrow", x, y);
867 _update_hsla_from_colorbar(cb_data->parent, cb_data->color_type, x);
871 _access_colorbar_register(Evas_Object *obj,
877 const char* colorbar_type = NULL;
879 ao = _elm_access_edje_object_part_object_register(obj, cd->colorbar, part);
880 ai = _elm_access_info_get(ao);
882 switch (cd->color_type)
885 colorbar_type = "hue color bar";
889 colorbar_type = "saturation color bar";
893 colorbar_type = "lightness color bar";
897 colorbar_type = "alpha color bar";
904 _elm_access_text_set(ai, ELM_ACCESS_TYPE, colorbar_type);
906 // this will be used in focus_next();
911 _color_bars_add(Evas_Object *obj)
913 char colorbar_name[128];
914 char colorbar_s[128];
919 ELM_COLORSELECTOR_DATA_GET(obj, sd);
921 e = evas_object_evas_get(obj);
923 for (i = 0; i < 4; i++)
925 sd->cb_data[i] = ELM_NEW(Color_Bar_Data);
926 sd->cb_data[i]->parent = obj;
931 sd->cb_data[i]->color_type = HUE;
935 sd->cb_data[i]->color_type = SATURATION;
939 sd->cb_data[i]->color_type = LIGHTNESS;
943 sd->cb_data[i]->color_type = ALPHA;
947 /* load colorbar area */
948 sd->cb_data[i]->colorbar = edje_object_add(e);
949 elm_widget_theme_object_set
950 (obj, sd->cb_data[i]->colorbar, "colorselector", "base",
951 elm_widget_style_get(obj));
952 snprintf(colorbar_name, sizeof(colorbar_name), "colorbar_%d", i);
953 snprintf(colorbar_s, sizeof(colorbar_s), "elm.colorbar_%d", i);
954 edje_object_signal_callback_add
955 (sd->cb_data[i]->colorbar, "drag", "*", _arrow_cb, sd->cb_data[i]);
956 edje_object_part_swallow
957 (sd->col_bars_area, colorbar_s, sd->cb_data[i]->colorbar);
958 elm_widget_sub_object_add(obj, sd->cb_data[i]->colorbar);
960 /* load colorbar image */
961 sd->cb_data[i]->bar = edje_object_add(e);
962 snprintf(buf, sizeof(buf), "%s/%s", colorbar_name,
963 elm_widget_style_get(obj));
964 elm_widget_theme_object_set
965 (obj, sd->cb_data[i]->bar, "colorselector", "image", buf);
966 edje_object_part_swallow
967 (sd->cb_data[i]->colorbar, "elm.bar", sd->cb_data[i]->bar);
968 elm_widget_sub_object_add(obj, sd->cb_data[i]->bar);
970 /* provide expanded touch area */
971 sd->cb_data[i]->touch_area = evas_object_rectangle_add(e);
972 evas_object_color_set(sd->cb_data[i]->touch_area, 0, 0, 0, 0);
973 edje_object_part_swallow
974 (sd->cb_data[i]->colorbar, "elm.arrow_bg",
975 sd->cb_data[i]->touch_area);
976 evas_object_event_callback_add
977 (sd->cb_data[i]->touch_area, EVAS_CALLBACK_MOUSE_DOWN, _colorbar_cb,
979 elm_widget_sub_object_add(obj, sd->cb_data[i]->touch_area);
982 if (_elm_config->access_mode == ELM_ACCESS_MODE_ON)
983 _access_colorbar_register(obj, sd->cb_data[i], "elm.arrow_bg_access");
985 /* load background rectangle of the colorbar. used for
986 changing color of the opacity bar */
987 if ((i == 1) || (i == 2))
989 sd->cb_data[i]->bg_rect = evas_object_rectangle_add(e);
990 evas_object_color_set
991 (sd->cb_data[i]->bg_rect, sd->er, sd->eg, sd->eb, 255);
992 edje_object_part_swallow
993 (sd->cb_data[i]->colorbar, "elm.bar_bg",
994 sd->cb_data[i]->bg_rect);
996 elm_widget_sub_object_add(obj, sd->cb_data[i]->bg_rect);
1000 sd->cb_data[i]->bg_rect = edje_object_add(e);
1001 snprintf(buf, sizeof(buf), "%s/%s", colorbar_name,
1002 elm_widget_style_get(obj));
1003 elm_widget_theme_object_set
1004 (obj, sd->cb_data[i]->bg_rect, "colorselector", "bg_image",
1006 edje_object_part_swallow
1007 (sd->cb_data[i]->colorbar, "elm.bar_bg",
1008 sd->cb_data[i]->bg_rect);
1009 elm_widget_sub_object_add(obj, sd->cb_data[i]->bg_rect);
1010 evas_object_color_set
1011 (sd->cb_data[i]->bar, sd->er, sd->eg, sd->eb, 255);
1014 /* load arrow image, pointing the colorbar */
1015 sd->cb_data[i]->arrow = edje_object_add(e);
1016 elm_widget_theme_object_set
1017 (obj, sd->cb_data[i]->arrow, "colorselector", "arrow",
1018 elm_widget_style_get(obj));
1019 edje_object_part_swallow
1020 (sd->cb_data[i]->colorbar, "elm.arrow_icon",
1021 sd->cb_data[i]->arrow);
1022 elm_widget_sub_object_add(obj, sd->cb_data[i]->arrow);
1025 evas_object_color_set(sd->cb_data[i]->arrow, 0, 0, 0, 255);
1027 evas_object_color_set
1028 (sd->cb_data[i]->arrow, sd->er, sd->eg, sd->eb, 255);
1030 /* load left button */
1031 sd->cb_data[i]->lbt = elm_button_add(obj);
1032 snprintf(buf, sizeof(buf), "colorselector/left/%s",
1033 elm_widget_style_get(obj));
1034 elm_object_style_set(sd->cb_data[i]->lbt, buf);
1035 elm_widget_sub_object_add(obj, sd->cb_data[i]->lbt);
1036 edje_object_part_swallow
1037 (sd->cb_data[i]->colorbar, "elm.l_button", sd->cb_data[i]->lbt);
1038 evas_object_smart_callback_add
1039 (sd->cb_data[i]->lbt, "clicked", _button_clicked_cb,
1041 elm_button_autorepeat_set(sd->cb_data[i]->lbt, EINA_TRUE);
1042 elm_button_autorepeat_initial_timeout_set
1043 (sd->cb_data[i]->lbt, _elm_config->longpress_timeout);
1044 elm_button_autorepeat_gap_timeout_set
1045 (sd->cb_data[i]->lbt, (1.0 / _elm_config->fps));
1046 evas_object_smart_callback_add
1047 (sd->cb_data[i]->lbt, "repeated", _button_repeat_cb,
1050 /* load right button */
1051 sd->cb_data[i]->rbt = elm_button_add(obj);
1052 snprintf(buf, sizeof(buf), "colorselector/right/%s",
1053 elm_widget_style_get(obj));
1054 elm_object_style_set(sd->cb_data[i]->rbt, buf);
1055 elm_widget_sub_object_add(obj, sd->cb_data[i]->rbt);
1056 edje_object_part_swallow
1057 (sd->cb_data[i]->colorbar, "elm.r_button", sd->cb_data[i]->rbt);
1058 evas_object_smart_callback_add
1059 (sd->cb_data[i]->rbt, "clicked", _button_clicked_cb,
1061 elm_button_autorepeat_set(sd->cb_data[i]->rbt, EINA_TRUE);
1062 elm_button_autorepeat_initial_timeout_set
1063 (sd->cb_data[i]->rbt, _elm_config->longpress_timeout);
1064 elm_button_autorepeat_gap_timeout_set
1065 (sd->cb_data[i]->rbt, (1.0 / _elm_config->fps));
1066 evas_object_smart_callback_add
1067 (sd->cb_data[i]->rbt, "repeated", _button_repeat_cb,
1072 EOLIAN static Eina_Bool
1073 _elm_colorselector_elm_widget_theme_apply(Eo *obj, Elm_Colorselector_Data *sd)
1077 Elm_Color_Item *item;
1078 const char *hpadstr, *vpadstr;
1079 unsigned int h_pad = DEFAULT_HOR_PAD;
1080 unsigned int v_pad = DEFAULT_VER_PAD;
1082 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EINA_FALSE);
1083 Eina_Bool int_ret = EINA_FALSE;
1085 eo_do_super(obj, MY_CLASS, elm_obj_widget_theme_apply(&int_ret));
1086 if (!int_ret) return EINA_FALSE;
1088 if (!sd->col_bars_area) return EINA_FALSE;
1090 elm_widget_theme_object_set
1091 (obj, sd->col_bars_area, "colorselector", "bg",
1092 elm_widget_style_get(obj));
1094 hpadstr = edje_object_data_get
1095 (wd->resize_obj, "horizontal_pad");
1096 if (hpadstr) h_pad = atoi(hpadstr);
1097 vpadstr = edje_object_data_get
1098 (wd->resize_obj, "vertical_pad");
1099 if (vpadstr) v_pad = atoi(vpadstr);
1103 (h_pad * elm_widget_scale_get(obj) * elm_config_scale_get()),
1104 (v_pad * elm_widget_scale_get(obj) * elm_config_scale_get()));
1106 EINA_LIST_FOREACH(sd->items, elist, item)
1108 if (!elm_layout_theme_set
1109 (VIEW(item), "colorselector", "item", elm_widget_style_get(obj)))
1110 CRI("Failed to set layout!");
1112 elm_widget_theme_object_set
1113 (obj, item->color_obj, "colorselector", "item/color",
1114 elm_widget_style_get(obj));
1116 for (i = 0; i < 4; i++)
1120 ELM_SAFE_FREE(sd->cb_data[i]->colorbar, evas_object_del);
1121 ELM_SAFE_FREE(sd->cb_data[i]->bar, evas_object_del);
1122 ELM_SAFE_FREE(sd->cb_data[i]->lbt, evas_object_del);
1123 ELM_SAFE_FREE(sd->cb_data[i]->rbt, evas_object_del);
1125 ELM_SAFE_FREE(sd->cb_data[i]->bg_rect, evas_object_del);
1126 ELM_SAFE_FREE(sd->cb_data[i]->arrow, evas_object_del);
1127 ELM_SAFE_FREE(sd->cb_data[i]->touch_area, evas_object_del);
1131 _color_bars_add(obj);
1132 elm_colorselector_color_set(obj, sd->r, sd->g, sd->b, sd->a);
1134 elm_layout_sizing_eval(obj);
1140 _sub_obj_size_hints_set(Evas_Object *sobj,
1144 Evas_Coord minw = -1, minh = -1;
1146 elm_coords_finger_size_adjust(timesw, &minw, timesh, &minh);
1147 if (sobj && eo_isa(sobj, EDJE_OBJ_CLASS))
1148 edje_object_size_min_restricted_calc(sobj, &minw, &minh, minw, minh);
1149 evas_object_size_hint_min_set(sobj, minw, minh);
1150 evas_object_size_hint_max_set(sobj, -1, -1);
1154 _item_sizing_eval(Elm_Color_Item *item)
1156 Evas_Coord minw = -1, minh = -1;
1160 edje = elm_layout_edje_get(VIEW(item));
1163 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
1164 edje_object_size_min_restricted_calc(edje, &minw, &minh, minw, minh);
1165 evas_object_size_hint_min_set(VIEW(item), minw, minh);
1168 /* fix size hints of color palette items, so that the box gets it */
1170 _palette_sizing_eval(Evas_Object *obj)
1173 Elm_Color_Item *item;
1175 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1177 EINA_LIST_FOREACH(sd->items, elist, item)
1178 _item_sizing_eval(item);
1182 _component_sizing_eval(Evas_Object *obj)
1184 Evas_Coord minw = -1, minh = -1;
1187 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1189 for (i = 0; i < 4; i++)
1193 if (sd->cb_data[i]->bg_rect)
1194 _sub_obj_size_hints_set(sd->cb_data[i]->bg_rect, 1, 1);
1196 _sub_obj_size_hints_set(sd->cb_data[i]->bar, 1, 1);
1197 _sub_obj_size_hints_set(sd->cb_data[i]->rbt, 1, 1);
1198 _sub_obj_size_hints_set(sd->cb_data[i]->lbt, 1, 1);
1199 _sub_obj_size_hints_set(sd->cb_data[i]->colorbar, 4, 1);
1203 edje_object_size_min_restricted_calc
1204 (sd->col_bars_area, &minw, &minh, minw, minh);
1205 evas_object_size_hint_min_set(sd->col_bars_area, minw, minh);
1209 _full_sizing_eval(Evas_Object *obj)
1211 _palette_sizing_eval(obj);
1212 _component_sizing_eval(obj);
1216 _elm_colorselector_elm_layout_sizing_eval(Eo *obj, Elm_Colorselector_Data *sd)
1218 Evas_Coord minw = -1, minh = -1;
1220 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
1222 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
1226 case ELM_COLORSELECTOR_PALETTE:
1227 _palette_sizing_eval(obj);
1230 case ELM_COLORSELECTOR_COMPONENTS:
1231 _component_sizing_eval(obj);
1234 case ELM_COLORSELECTOR_BOTH:
1235 _full_sizing_eval(obj);
1242 evas_object_resize(sd->palette_box, minw, minh);
1243 evas_object_smart_calculate(sd->palette_box);
1244 edje_object_size_min_calc(wd->resize_obj, &minw, &minh);
1245 evas_object_size_hint_min_set(obj, minw, minh);
1246 evas_object_size_hint_max_set(obj, -1, -1);
1250 _on_resize(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
1251 Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
1253 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1255 if ((sd->mode == ELM_COLORSELECTOR_PALETTE) ||
1256 (sd->mode == ELM_COLORSELECTOR_BOTH))
1258 Evas_Coord w = 0, h = 0, minw = -1;
1260 evas_object_size_hint_min_get(obj, &minw, NULL);
1261 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
1262 if ((w != sd->_w) && (w < minw))
1263 elm_layout_sizing_eval(obj);
1270 _on_color_long_press(void *data)
1272 Elm_Color_Item *item = (Elm_Color_Item *)data;
1274 ELM_COLORSELECTOR_DATA_GET(WIDGET(item), sd);
1276 sd->longpress_timer = NULL;
1278 evas_object_smart_callback_call
1279 (WIDGET(item), SIG_COLOR_ITEM_LONGPRESSED, item);
1281 return ECORE_CALLBACK_CANCEL;
1285 _on_color_pressed(void *data,
1286 Evas *e EINA_UNUSED,
1287 Evas_Object *obj EINA_UNUSED,
1288 void *event_info EINA_UNUSED)
1290 Elm_Color_Item *item = (Elm_Color_Item *)data;
1291 Evas_Event_Mouse_Down *ev = event_info;
1295 ELM_COLORSELECTOR_DATA_GET(WIDGET(item), sd);
1297 if (ev->button != 1) return;
1299 ecore_timer_del(sd->longpress_timer);
1300 sd->longpress_timer = ecore_timer_add
1301 (_elm_config->longpress_timeout, _on_color_long_press, data);
1305 _on_color_released(void *data,
1306 Evas *e EINA_UNUSED,
1307 Evas_Object *obj EINA_UNUSED,
1308 void *event_info EINA_UNUSED)
1310 Elm_Color_Item *item = (Elm_Color_Item *)data;
1312 Elm_Color_Item *temp_item;
1313 Evas_Event_Mouse_Down *ev = event_info;
1316 ELM_COLORSELECTOR_DATA_GET(WIDGET(item), sd);
1318 if (ev->button != 1) return;
1319 ELM_SAFE_FREE(sd->longpress_timer, ecore_timer_del);
1321 elm_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
1322 elm_colorselector_color_set(WIDGET(item), item->color->r, item->color->g,
1323 item->color->b, item->color->a);
1324 evas_object_smart_callback_call(WIDGET(item), SIG_COLOR_ITEM_SELECTED,
1327 temp_item = eina_list_data_get(sd->selected);
1328 if (temp_item && (temp_item != item))
1329 elm_object_signal_emit(VIEW(temp_item), "elm,state,unselected", "elm");
1331 EINA_LIST_FOREACH(sd->items, l, temp_item)
1332 if (item == temp_item) sd->selected = l;
1333 sd->focused = ELM_COLORSELECTOR_PALETTE;
1337 _access_info_cb(void *data, Evas_Object *obj EINA_UNUSED)
1341 int r = 0, g = 0, b = 0 ,a = 0;
1343 Elm_Color_Item *it = data;
1344 ELM_COLORSELECTOR_ITEM_CHECK_OR_RETURN(it, NULL);
1346 elm_colorselector_palette_item_color_get((Elm_Object_Item *)it, &r, &g, &b, &a);
1348 buf = eina_strbuf_new();
1349 eina_strbuf_append_printf(buf, "red %d, green %d, blue %d, alpha %d", r, g, b, a);
1350 ret = eina_strbuf_string_steal(buf);
1351 eina_strbuf_free(buf);
1356 _access_widget_item_register(Elm_Color_Item *it)
1358 Elm_Access_Info *ai;
1360 _elm_access_widget_item_register((Elm_Widget_Item *)it);
1362 ai = _elm_access_info_get(it->base.access_obj);
1364 _elm_access_text_set(ai, ELM_ACCESS_TYPE, E_("color selector palette item"));
1365 _elm_access_callback_set(ai, ELM_ACCESS_INFO, _access_info_cb, it);
1369 _item_resize(void *data EINA_UNUSED,
1370 Evas *e EINA_UNUSED,
1372 void *event_info EINA_UNUSED)
1374 elm_layout_sizing_eval(obj);
1378 _item_signal_emit_hook(Elm_Object_Item *it,
1379 const char *emission,
1382 elm_object_signal_emit(VIEW(it), emission, source);
1385 static Elm_Color_Item *
1386 _item_new(Evas_Object *obj)
1388 Elm_Color_Item *item;
1390 item = elm_widget_item_new(obj, Elm_Color_Item);
1391 if (!item) return NULL;
1393 VIEW(item) = elm_layout_add(obj);
1394 if (!elm_layout_theme_set
1395 (VIEW(item), "colorselector", "item", elm_widget_style_get(obj)))
1396 CRI("Failed to set layout!");
1397 evas_object_size_hint_weight_set
1398 (VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1399 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1400 evas_object_event_callback_add
1401 (VIEW(item), EVAS_CALLBACK_RESIZE, _item_resize, NULL);
1403 item->color_obj = edje_object_add(evas_object_evas_get(obj));
1404 elm_widget_theme_object_set
1405 (obj, item->color_obj, "colorselector", "item/color",
1406 elm_widget_style_get(obj));
1407 evas_object_size_hint_weight_set
1408 (item->color_obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1409 evas_object_size_hint_align_set
1410 (item->color_obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
1411 evas_object_event_callback_add
1412 (item->color_obj, EVAS_CALLBACK_MOUSE_DOWN, _on_color_pressed, item);
1413 evas_object_event_callback_add
1414 (item->color_obj, EVAS_CALLBACK_MOUSE_UP, _on_color_released, item);
1415 elm_object_part_content_set(VIEW(item), "color_obj", item->color_obj);
1417 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1419 _item_sizing_eval(item);
1420 evas_object_show(VIEW(item));
1423 if (_elm_config->access_mode == ELM_ACCESS_MODE_ON)
1424 _access_widget_item_register(item);
1430 _colors_remove(Evas_Object *obj)
1432 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1435 _elm_config_colors_free(sd->palette_name);
1439 _colors_save(Evas_Object *obj)
1442 Elm_Color_Item *item;
1444 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1446 _elm_config_colors_free(sd->palette_name);
1447 EINA_LIST_FOREACH(sd->items, elist, item)
1448 _elm_config_color_set(sd->palette_name, item->color->r, item->color->g,
1449 item->color->b, item->color->a);
1453 _palette_colors_load(Evas_Object *obj)
1456 Elm_Color_Item *item;
1457 Eina_List *color_list;
1458 Elm_Color_RGBA *color;
1460 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1462 color_list = _elm_config_color_list_get(sd->palette_name);
1463 if (!color_list) return;
1465 EINA_LIST_FOREACH(color_list, elist, color)
1467 item = _item_new(obj);
1470 item->color = ELM_NEW(Elm_Color_RGBA);
1471 if (!item->color) return;
1472 item->color->r = color->r;
1473 item->color->g = color->g;
1474 item->color->b = color->b;
1475 item->color->a = color->a;
1477 elm_box_pack_end(sd->palette_box, VIEW(item));
1478 evas_object_color_set(item->color_obj,
1479 (item->color->r * item->color->a) / 255,
1480 (item->color->g * item->color->a) / 255,
1481 (item->color->b * item->color->a) / 255,
1484 sd->items = eina_list_append(sd->items, item);
1487 sd->config_load = EINA_TRUE;
1491 _elm_colorselector_evas_smart_add(Eo *obj, Elm_Colorselector_Data *priv)
1493 const char *hpadstr, *vpadstr;
1494 unsigned int h_pad = DEFAULT_HOR_PAD;
1495 unsigned int v_pad = DEFAULT_VER_PAD;
1497 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
1499 eo_do_super(obj, MY_CLASS, evas_obj_smart_add());
1500 elm_widget_sub_object_parent_add(obj);
1502 if (!elm_layout_theme_set
1503 (obj, "colorselector", "palette", elm_object_style_get(obj)))
1504 CRI("Failed to set layout!");
1506 priv->palette_box = elm_box_add(obj);
1508 (priv->palette_box, evas_object_box_layout_flow_horizontal, NULL, NULL);
1509 elm_box_horizontal_set(priv->palette_box, EINA_TRUE);
1510 evas_object_size_hint_weight_set
1511 (priv->palette_box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1512 evas_object_size_hint_align_set
1513 (priv->palette_box, EVAS_HINT_FILL, EVAS_HINT_FILL);
1514 elm_box_homogeneous_set(priv->palette_box, EINA_TRUE);
1516 hpadstr = edje_object_data_get(wd->resize_obj, "horizontal_pad");
1517 if (hpadstr) h_pad = atoi(hpadstr);
1518 vpadstr = edje_object_data_get(wd->resize_obj, "vertical_pad");
1519 if (vpadstr) v_pad = atoi(vpadstr);
1523 (h_pad * elm_widget_scale_get(obj) * elm_config_scale_get()),
1524 (v_pad * elm_widget_scale_get(obj) * elm_config_scale_get()));
1526 elm_box_align_set(priv->palette_box, 0.5, 0.5);
1527 if (!elm_layout_content_set(obj, "elm.palette", priv->palette_box))
1528 elm_layout_content_set(obj, "palette", priv->palette_box);
1529 priv->palette_name = eina_stringshare_add("default");
1530 _palette_colors_load(obj);
1532 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _on_resize, NULL);
1534 /* load background edj */
1535 priv->col_bars_area = edje_object_add(evas_object_evas_get(obj));
1536 elm_widget_theme_object_set
1537 (obj, priv->col_bars_area, "colorselector", "bg",
1538 elm_widget_style_get(obj));
1539 if (!elm_layout_content_set(obj, "elm.selector", priv->col_bars_area))
1540 elm_layout_content_set(obj, "selector", priv->col_bars_area);
1542 elm_layout_signal_emit(obj, "elm,state,both", "elm");
1544 /* setup the color picker */
1545 priv->picker = elm_box_add(obj);
1546 elm_box_horizontal_set(priv->picker, EINA_TRUE);
1547 evas_object_size_hint_weight_set(priv->picker, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1548 evas_object_size_hint_align_set(priv->picker, EVAS_HINT_FILL, EVAS_HINT_FILL);
1550 elm_box_padding_set(priv->picker,
1551 (h_pad * elm_widget_scale_get(obj) * elm_config_scale_get()),
1552 (v_pad * elm_widget_scale_get(obj) * elm_config_scale_get()));
1553 elm_box_align_set(priv->palette_box, 0.5, 0.5);
1555 priv->mode = ELM_COLORSELECTOR_BOTH;
1556 priv->focused = ELM_COLORSELECTOR_PALETTE;
1557 priv->sel_color_type = HUE;
1558 priv->selected = priv->items;
1568 #ifdef HAVE_ELEMENTARY_X
1569 priv->grab.xroot = -1;
1571 priv->grab.in = EINA_TRUE;
1574 _color_bars_add(obj);
1575 _color_picker_add(obj, priv);
1577 elm_layout_sizing_eval(obj);
1578 elm_widget_can_focus_set(obj, EINA_TRUE);
1582 _elm_colorselector_evas_smart_del(Eo *obj, Elm_Colorselector_Data *sd)
1588 evas_event_callback_del_full(evas_object_evas_get(obj), EVAS_CALLBACK_CANVAS_FOCUS_IN, _mouse_in_canvas, obj);
1589 evas_event_callback_del_full(evas_object_evas_get(obj), EVAS_CALLBACK_CANVAS_FOCUS_OUT, _mouse_out_canvas, obj);
1591 ecore_timer_del(sd->longpress_timer);
1592 eina_stringshare_del(sd->palette_name);
1594 #ifdef HAVE_ELEMENTARY_X
1595 ecore_event_handler_del(sd->grab.mouse_motion);
1596 ecore_event_handler_del(sd->grab.mouse_up);
1597 ecore_event_handler_del(sd->grab.key_up);
1601 /* This cb_data are used during the destruction process of base.del */
1602 for (i = 0; i < 4; i++)
1603 tmp[i] = sd->cb_data[i];
1604 eo_do_super(obj, MY_CLASS, evas_obj_smart_del());
1605 for (i = 0; i < 4; i++)
1610 _palette_box_vertical_item_get(Eina_List* ref_item, enum Palette_Box_Direction dir)
1612 Evas_Coord basex, basey, x, y, dx, min_dx;
1613 Elm_Color_Item *item;
1615 Eina_List* res = NULL;
1616 Eina_List* (*dir_func)(const Eina_List*);
1618 if (!ref_item) return NULL;
1622 case PALETTE_BOX_UP:
1623 dir_func = eina_list_prev;
1625 case PALETTE_BOX_DOWN:
1626 dir_func = eina_list_next;
1632 item = eina_list_data_get(ref_item);
1633 evas_object_geometry_get(VIEW(item), &basex, &basey, NULL, NULL);
1635 for (l = ref_item; l; l = dir_func(l))
1637 item = eina_list_data_get(l);
1638 evas_object_geometry_get(VIEW(item), &x, &y, NULL, NULL);
1639 if (basey != y) break;
1645 for (; l; l = dir_func(l))
1647 item = eina_list_data_get(l);
1648 evas_object_geometry_get(VIEW(item), &x, &y, NULL, NULL);
1649 if (basey != y) break;
1651 dx = abs(x - basex);
1652 if (dx < min_dx || min_dx < 0)
1667 _key_action_move(Evas_Object *obj, const char *params)
1669 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1670 Eina_List *cl = NULL;
1671 Elm_Color_Item *item = NULL;
1672 char colorbar_s[128];
1675 if (!strcmp(dir, "left"))
1677 if (sd->focused == ELM_COLORSELECTOR_PALETTE && sd->selected)
1678 cl = eina_list_prev(sd->selected);
1679 else if (sd->focused == ELM_COLORSELECTOR_COMPONENTS)
1680 _button_clicked_cb(sd->cb_data[sd->sel_color_type],
1681 sd->cb_data[sd->sel_color_type]->lbt, NULL);
1682 else return EINA_FALSE;
1684 else if (!strcmp(dir, "right"))
1686 if (sd->focused == ELM_COLORSELECTOR_PALETTE && sd->selected)
1687 cl = eina_list_next(sd->selected);
1688 else if (sd->focused == ELM_COLORSELECTOR_COMPONENTS)
1689 _button_clicked_cb(sd->cb_data[sd->sel_color_type],
1690 sd->cb_data[sd->sel_color_type]->rbt, NULL);
1691 else return EINA_FALSE;
1693 else if (!strcmp(dir, "up"))
1695 if (sd->focused == ELM_COLORSELECTOR_COMPONENTS)
1697 sd->sel_color_type = sd->sel_color_type - 1;
1698 if (sd->sel_color_type < HUE)
1700 if (sd->mode == ELM_COLORSELECTOR_BOTH)
1702 sd->focused = ELM_COLORSELECTOR_PALETTE;
1703 /*when focus is shifted to palette start from
1705 sd->selected = sd->items;
1710 sd->sel_color_type = HUE;
1715 else if (sd->focused == ELM_COLORSELECTOR_PALETTE)
1717 cl = _palette_box_vertical_item_get(sd->selected, PALETTE_BOX_UP);
1718 if (!cl) cl = sd->selected;
1721 else if (!strcmp(dir, "down"))
1723 if (sd->focused == ELM_COLORSELECTOR_PALETTE)
1725 cl = _palette_box_vertical_item_get(sd->selected, PALETTE_BOX_DOWN);
1726 if (sd->mode == ELM_COLORSELECTOR_BOTH && !cl)
1728 sd->focused = ELM_COLORSELECTOR_COMPONENTS;
1729 /*when focus is shifted to component start from
1730 * first color type*/
1731 sd->sel_color_type = HUE;
1734 else if (sd->focused == ELM_COLORSELECTOR_COMPONENTS)
1736 snprintf(colorbar_s, sizeof(colorbar_s), "elm.colorbar_%d",
1737 (sd->sel_color_type + 1));
1738 /*Append color type only if next color bar is available*/
1739 if (edje_object_part_swallow_get(sd->col_bars_area, colorbar_s))
1740 sd->sel_color_type = sd->sel_color_type + 1;
1741 else return EINA_FALSE;
1744 else return EINA_FALSE;
1748 item = eina_list_data_get(cl);
1749 elm_object_signal_emit(VIEW(item), "elm,anim,activate", "elm");
1750 elm_colorselector_color_set
1751 (WIDGET(item), item->color->r, item->color->g, item->color->b,
1753 evas_object_smart_callback_call
1754 (WIDGET(item), SIG_COLOR_ITEM_SELECTED, item);
1757 else if (!cl && sd->focused == ELM_COLORSELECTOR_PALETTE)
1763 EOLIAN static Eina_Bool
1764 _elm_colorselector_elm_widget_event(Eo *obj, Elm_Colorselector_Data *sd, Evas_Object *src, Evas_Callback_Type type, void *event_info)
1766 Evas_Event_Key_Down *ev = event_info;
1767 Eina_List *cl = NULL;
1768 Elm_Color_Item *item = NULL;
1769 char colorbar_s[128];
1773 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
1774 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
1775 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
1776 if (!sd) return EINA_FALSE;
1777 if (!sd->selected) sd->selected = sd->items;
1779 if (!_elm_config_key_binding_call(obj, ev, key_actions))
1782 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1786 static Eina_Bool _elm_colorselector_smart_focus_next_enable = EINA_FALSE;
1788 EOLIAN static Eina_Bool
1789 _elm_colorselector_elm_widget_focus_direction_manager_is(Eo *obj EINA_UNUSED, Elm_Colorselector_Data *_pd EINA_UNUSED)
1794 EOLIAN static Eina_Bool
1795 _elm_colorselector_elm_widget_focus_next_manager_is(Eo *obj EINA_UNUSED, Elm_Colorselector_Data *_pd EINA_UNUSED)
1797 return _elm_colorselector_smart_focus_next_enable;
1800 EOLIAN static Eina_Bool
1801 _elm_colorselector_elm_widget_focus_next(Eo *obj, Elm_Colorselector_Data *sd, Elm_Focus_Direction dir, Evas_Object **next)
1803 Eina_List *items = NULL;
1805 Elm_Widget_Item *item;
1808 if (!sd) return EINA_FALSE;
1810 if (!sd->items) return EINA_FALSE;
1812 EINA_LIST_FOREACH(sd->items, l, item)
1813 items = eina_list_append(items, item->access_obj);
1815 for (i = 0; i < 4; i++)
1817 items = eina_list_append(items, sd->cb_data[i]->lbt);
1818 items = eina_list_append(items, sd->cb_data[i]->access_obj);
1819 items = eina_list_append(items, sd->cb_data[i]->rbt);
1822 return elm_widget_focus_list_next_get
1823 (obj, items, eina_list_data_get, dir, next);
1827 _access_obj_process(Evas_Object *obj, Eina_Bool is_access)
1833 ELM_COLORSELECTOR_DATA_GET(obj, sd);
1837 EINA_LIST_FOREACH(sd->items, l, it)
1838 _access_widget_item_register(it);
1840 for (i = 0; i < 4; i++)
1841 _access_colorbar_register(obj, sd->cb_data[i],
1842 "elm.arrow_bg_access");
1846 EINA_LIST_FOREACH(sd->items, l, it)
1847 _elm_access_widget_item_unregister((Elm_Widget_Item *)it);
1849 //TODO: _elm_access_edje_object_part_object_unregister() ?
1854 _elm_colorselector_elm_widget_access(Eo *obj, Elm_Colorselector_Data *_pd EINA_UNUSED, Eina_Bool acs)
1856 _elm_colorselector_smart_focus_next_enable = acs;
1857 _access_obj_process(obj, _elm_colorselector_smart_focus_next_enable);
1861 elm_colorselector_add(Evas_Object *parent)
1863 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
1864 Evas_Object *obj = eo_add(MY_CLASS, parent);
1870 _elm_colorselector_eo_base_constructor(Eo *obj, Elm_Colorselector_Data *_pd EINA_UNUSED)
1872 eo_do_super(obj, MY_CLASS, eo_constructor());
1874 evas_obj_type_set(MY_CLASS_NAME_LEGACY),
1875 evas_obj_smart_callbacks_descriptions_set(_smart_callbacks, NULL));
1879 _elm_colorselector_color_set(Eo *obj, Elm_Colorselector_Data *_pd EINA_UNUSED, int r, int g, int b, int a)
1881 _colors_set(obj, r, g, b, a);
1885 _elm_colorselector_color_get(Eo *obj EINA_UNUSED, Elm_Colorselector_Data *sd, int *r, int *g, int *b, int *a)
1894 _elm_colorselector_mode_set(Eo *obj, Elm_Colorselector_Data *sd, Elm_Colorselector_Mode mode)
1896 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
1899 if (sd->mode == mode) return;
1902 o = elm_layout_content_unset(obj, "elm.selector");
1903 if (!o) o = elm_layout_content_unset(obj, "selector");
1904 if (o) evas_object_hide(o);
1906 o = elm_layout_content_unset(obj, "elm.palette");
1907 if (!o) o = elm_layout_content_unset(obj, "palette");
1908 if (o) evas_object_hide(o);
1910 o = elm_layout_content_unset(obj, "elm.picker");
1911 if (!o) o = elm_layout_content_unset(obj, "picker");
1912 if (o) evas_object_hide(o);
1916 case ELM_COLORSELECTOR_PALETTE:
1917 if (!elm_layout_content_set(obj, "elm.palette", sd->palette_box))
1918 elm_layout_content_set(obj, "palette", sd->palette_box);
1919 elm_layout_signal_emit(obj, "elm,state,palette", "elm");
1920 sd->focused = ELM_COLORSELECTOR_PALETTE;
1921 sd->selected = sd->items;
1924 case ELM_COLORSELECTOR_COMPONENTS:
1925 if (!elm_layout_content_set(obj, "elm.selector", sd->col_bars_area))
1926 elm_layout_content_set(obj, "selector", sd->col_bars_area);
1927 elm_layout_signal_emit(obj, "elm,state,components", "elm");
1928 sd->focused = ELM_COLORSELECTOR_COMPONENTS;
1929 sd->sel_color_type = HUE;
1932 case ELM_COLORSELECTOR_BOTH:
1933 if (!elm_layout_content_set(obj, "elm.palette", sd->palette_box))
1934 elm_layout_content_set(obj, "palette", sd->palette_box);
1935 if (!elm_layout_content_set(obj, "elm.selector", sd->col_bars_area))
1936 elm_layout_content_set(obj, "selector", sd->col_bars_area);
1937 elm_layout_signal_emit(obj, "elm,state,both", "elm");
1938 sd->focused = ELM_COLORSELECTOR_PALETTE;
1939 sd->selected = sd->items;
1942 case ELM_COLORSELECTOR_PICKER:
1943 if (!elm_layout_content_set(obj, "elm.picker", sd->picker))
1944 elm_layout_content_set(obj, "picker", sd->picker);
1945 elm_layout_signal_emit(obj, "elm,state,picker", "elm");
1946 sd->focused = ELM_COLORSELECTOR_PICKER;
1949 case ELM_COLORSELECTOR_ALL:
1950 if (!elm_layout_content_set(obj, "elm.palette", sd->palette_box))
1951 elm_layout_content_set(obj, "palette", sd->palette_box);
1952 if (!elm_layout_content_set(obj, "elm.selector", sd->col_bars_area))
1953 elm_layout_content_set(obj, "selector", sd->col_bars_area);
1954 if (!elm_layout_content_set(obj, "elm.picker", sd->picker))
1955 elm_layout_content_set(obj, "picker", sd->picker);
1956 elm_layout_signal_emit(obj, "elm,state,all", "elm");
1957 sd->focused = ELM_COLORSELECTOR_PALETTE;
1958 sd->selected = sd->items;
1965 edje_object_message_signal_process(wd->resize_obj);
1967 elm_layout_sizing_eval(obj);
1970 EOLIAN static Elm_Colorselector_Mode
1971 _elm_colorselector_mode_get(Eo *obj EINA_UNUSED, Elm_Colorselector_Data *sd)
1977 elm_colorselector_palette_item_color_get(const Elm_Object_Item *it,
1983 Elm_Color_Item *item;
1985 ELM_COLORSELECTOR_ITEM_CHECK_OR_RETURN(it);
1987 item = (Elm_Color_Item *)it;
1990 if (r) *r = item->color->r;
1991 if (g) *g = item->color->g;
1992 if (b) *b = item->color->b;
1993 if (a) *a = item->color->a;
1998 elm_colorselector_palette_item_color_set(Elm_Object_Item *it,
2004 Elm_Color_Item *item;
2006 ELM_COLORSELECTOR_ITEM_CHECK_OR_RETURN(it);
2008 item = (Elm_Color_Item *)it;
2013 evas_object_color_set(item->color_obj,
2014 (item->color->r * item->color->a) / 255,
2015 (item->color->g * item->color->a) / 255,
2016 (item->color->b * item->color->a) / 255,
2018 _colors_save(WIDGET(it));
2021 EOLIAN static Elm_Object_Item*
2022 _elm_colorselector_palette_color_add(Eo *obj, Elm_Colorselector_Data *sd, int r, int g, int b, int a)
2024 Elm_Color_Item *item;
2026 if (sd->config_load)
2029 sd->config_load = EINA_FALSE;
2031 item = _item_new(obj);
2032 if (!item) return NULL;
2034 item->color = ELM_NEW(Elm_Color_RGBA);
2035 if (!item->color) return NULL;
2042 elm_box_pack_end(sd->palette_box, VIEW(item));
2043 evas_object_color_set(item->color_obj,
2044 (item->color->r * item->color->a) / 255,
2045 (item->color->g * item->color->a) / 255,
2046 (item->color->b * item->color->a) / 255,
2049 sd->items = eina_list_append(sd->items, item);
2051 elm_layout_sizing_eval(obj);
2053 return (Elm_Object_Item *)item;
2057 _elm_colorselector_palette_clear(Eo *obj, Elm_Colorselector_Data *sd)
2060 _colors_remove(obj);
2061 if (sd->mode == ELM_COLORSELECTOR_BOTH)
2062 sd->focused = ELM_COLORSELECTOR_COMPONENTS;
2065 EOLIAN static const Eina_List*
2066 _elm_colorselector_palette_items_get(Eo *obj EINA_UNUSED, Elm_Colorselector_Data *sd)
2072 elm_colorselector_palette_item_selected_set(Elm_Object_Item *it,
2075 Elm_Color_Item *temp_item, *item;
2076 item = (Elm_Color_Item *)it;
2079 ELM_COLORSELECTOR_DATA_GET(WIDGET(item), sd);
2080 ELM_COLORSELECTOR_ITEM_CHECK_OR_RETURN(it);
2084 temp_item = eina_list_data_get(sd->selected);
2085 if (item == temp_item) return;
2086 elm_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
2087 elm_colorselector_color_set(WIDGET(item), item->color->r, item->color->g,
2088 item->color->b, item->color->a);
2090 elm_object_signal_emit(VIEW(temp_item), "elm,state,unselected", "elm");
2092 EINA_LIST_FOREACH(sd->items, l, temp_item)
2093 if (item == temp_item) sd->selected = l;
2097 elm_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
2098 sd->selected = NULL;
2103 elm_colorselector_palette_item_selected_get(const Elm_Object_Item *it)
2105 Elm_Color_Item *temp_item, *item;
2106 item = (Elm_Color_Item *)it;
2107 ELM_COLORSELECTOR_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2108 ELM_COLORSELECTOR_DATA_GET(WIDGET(item), sd);
2110 temp_item = eina_list_data_get(sd->selected);
2111 if (item == temp_item) return EINA_TRUE;
2112 else return EINA_FALSE;
2115 EOLIAN static Elm_Object_Item*
2116 _elm_colorselector_palette_selected_item_get(Eo *obj EINA_UNUSED, Elm_Colorselector_Data *sd)
2118 return eina_list_data_get(sd->selected);
2122 _elm_colorselector_palette_name_set(Eo *obj, Elm_Colorselector_Data *sd, const char *palette_name)
2124 EINA_SAFETY_ON_NULL_RETURN(palette_name);
2126 if (!strcmp(sd->palette_name, palette_name)) return;
2129 eina_stringshare_replace(&sd->palette_name, palette_name);
2130 _palette_colors_load(obj);
2133 EOLIAN static const char*
2134 _elm_colorselector_palette_name_get(Eo *obj EINA_UNUSED, Elm_Colorselector_Data *sd)
2136 return sd->palette_name;
2140 _elm_colorselector_class_constructor(Eo_Class *klass)
2142 evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
2144 if (_elm_config->access_mode == ELM_ACCESS_MODE_ON)
2145 _elm_colorselector_smart_focus_next_enable = EINA_TRUE;
2148 #include "elm_colorselector.eo.c"