+ evas_object_geometry_get(obj, NULL, NULL, &w, &h);
+ if (w < minw) w = minw;
+ if (h < minh) h = minh;
+ evas_object_resize(obj, w, h);
+}
+
+static void
+_sizing_eval_palette_selector(Evas_Object *obj)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
+ Evas_Coord minw = -1, minh = -1;
+ Evas_Coord bw = 0, bh = 0;
+ Evas_Coord w = 0, h = 0;
+ int i;
+ if (!wd) return;
+ elm_coords_finger_size_adjust(1, &minw, 1, &minh);
+ for (i = 0; i < 4; i++)
+ {
+ if (wd->cp[i]->bg_rect)
+ _colorselector_set_size_hints(wd->cp[i]->bg_rect, 1, 1);
+ _colorselector_set_size_hints(wd->cp[i]->bar, 1, 1);
+ _colorselector_set_size_hints(wd->cp[i]->rbt, 1, 1);
+ _colorselector_set_size_hints(wd->cp[i]->lbt, 1, 1);
+
+ _colorselector_set_size_hints(wd->cp[i]->colorbar, 4, 1);
+ }
+
+ elm_coords_finger_size_adjust(4, &minw, 4, &minh);
+ edje_object_size_min_restricted_calc(wd->sel, &minw, &minh, minw, minh);
+ evas_object_size_hint_min_get(wd->box, &bw, &bh);
+ evas_object_size_hint_min_set(obj, minw, minh+bh);
+ evas_object_size_hint_max_set(obj, -1, -1);
+ evas_object_geometry_get(obj, NULL, NULL, &w, &h);
+ if (w < minw) w = minw;
+ if (h < (minh+bh)) h = (minh+bh);
+ evas_object_resize(obj, w, h);
+}
+
+static void
+_sizing_eval(Evas_Object *obj)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+ switch (wd->mode)
+ {
+ case ELM_COLORSELECTOR_PALETTE:
+ _sizing_eval_palette(obj);
+ break;
+ case ELM_COLORSELECTOR_COMPONENTS:
+ _sizing_eval_selector(obj);
+ break;
+ case ELM_COLORSELECTOR_BOTH:
+ _sizing_eval_palette_selector(obj);
+ break;
+ default:
+ break;
+ }
+}
+
+static Eina_Bool
+_long_press(void *data)
+{
+ Elm_Color_Item *item = (Elm_Color_Item *) data;
+ Widget_Data *wd = elm_widget_data_get(WIDGET(item));
+ if (!wd) return ECORE_CALLBACK_CANCEL;
+ wd->longpress_timer = NULL;
+ wd->longpressed = EINA_TRUE;
+ evas_object_smart_callback_call(WIDGET(item), SIG_COLOR_ITEM_LONGPRESSED, item);
+ return ECORE_CALLBACK_CANCEL;
+}
+
+static void
+_item_highlight(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+ Elm_Color_Item *item = (Elm_Color_Item *) data;
+ Evas_Event_Mouse_Down *ev = event_info;
+ if (!item) return;
+ Widget_Data *wd = elm_widget_data_get(WIDGET(item));
+ if (!wd) return;
+ if (ev->button != 1) return;
+ elm_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
+ wd->longpressed = EINA_FALSE;
+ if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
+ wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
+}
+
+static void
+_item_unhighlight(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+ Elm_Color_Item *item = (Elm_Color_Item *) data;
+ Evas_Event_Mouse_Down *ev = event_info;
+ if (!item) return;
+ Widget_Data *wd = elm_widget_data_get(WIDGET(item));
+ if (!wd) return;
+ if (ev->button != 1) return;
+ if (wd->longpress_timer)
+ {
+ ecore_timer_del(wd->longpress_timer);
+ wd->longpress_timer = NULL;
+ }
+ elm_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
+ if (!wd->longpressed)
+ {
+ evas_object_smart_callback_call(WIDGET(item), SIG_COLOR_ITEM_SELECTED, item);
+ elm_colorselector_color_set(WIDGET(item), item->color->r, item->color->g, item->color->b, item->color->a);
+ }
+}
+
+static void
+_remove_items(Widget_Data *wd)
+{
+ Elm_Color_Item *item;
+
+ if (!wd->items) return;
+
+ EINA_LIST_FREE(wd->items, item)
+ {
+ free(item->color);
+ elm_widget_item_free(item);
+ }
+
+ wd->items = NULL;
+}
+
+static Elm_Color_Item*
+_item_new(Evas_Object *obj)
+{
+ Elm_Color_Item *item;
+ Widget_Data *wd;
+
+ wd = elm_widget_data_get(obj);
+ if (!wd) return NULL;
+
+ item = elm_widget_item_new(obj, Elm_Color_Item);
+ if (!item) return NULL;
+
+ VIEW(item) = elm_layout_add(obj);
+ elm_layout_theme_set(VIEW(item), "colorselector", "item", elm_widget_style_get(obj));
+ evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
+ item->color_obj = edje_object_add(evas_object_evas_get(obj));
+ _elm_theme_object_set(obj, item->color_obj, "colorselector", "item/color", elm_widget_style_get(obj));
+ evas_object_size_hint_weight_set(item->color_obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(item->color_obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_event_callback_add(item->color_obj, EVAS_CALLBACK_MOUSE_DOWN, _item_highlight, item);
+ evas_object_event_callback_add(item->color_obj, EVAS_CALLBACK_MOUSE_UP, _item_unhighlight, item);
+ elm_object_part_content_set(VIEW(item), "color_obj", item->color_obj);
+ _item_sizing_eval(item);
+ evas_object_show(VIEW(item));
+
+ return item;
+}
+
+static void
+_colors_remove(Evas_Object *obj)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
+
+ _remove_items(wd);
+ _elm_config_colors_free(wd->palette_name);
+}
+
+static void _colors_save(Evas_Object *obj)
+{
+ Eina_List *elist;
+ Widget_Data *wd = elm_widget_data_get(obj);
+ Elm_Color_Item *item;
+ _elm_config_colors_free(wd->palette_name);
+ EINA_LIST_FOREACH(wd->items, elist, item)
+ {
+ _elm_config_color_set(wd->palette_name, item->color->r, item->color->g,
+ item->color->b, item->color->a);
+ }
+}
+
+static void
+_colors_load_apply(Evas_Object *obj)
+{
+ Elm_Color_RGBA *color;
+ Eina_List *elist;
+ Eina_List *color_list;
+ Elm_Color_Item *item;
+ Widget_Data *wd = elm_widget_data_get(obj);
+ color_list = _elm_config_color_list_get(wd->palette_name);
+ if (!color_list) return;
+ EINA_LIST_FOREACH(color_list, elist, color)
+ {
+ item = _item_new(obj);
+ if (!item) return;
+ item->color = ELM_NEW(Elm_Color_RGBA);
+ if (!item->color) return;
+ item->color->r = color->r;
+ item->color->g = color->g;
+ item->color->b = color->b;
+ item->color->a = color->a;
+ elm_box_pack_end(wd->box, VIEW(item));
+ evas_object_color_set(item->color_obj, item->color->r, item->color->g,
+ item->color->b, item->color->a);
+ wd->items = eina_list_append(wd->items, item);
+ _sizing_eval_palette(obj);
+ }
+ wd->config_load = EINA_TRUE;