Colorselector: Item Selection/Unselection logic changes and corresponding API additions.
authorShilpa Singh <shilpa.singh@samsung.com>
Sat, 8 Feb 2014 04:33:58 +0000 (13:33 +0900)
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>
Sat, 8 Feb 2014 04:33:58 +0000 (13:33 +0900)
SUMMARY
Item should remain selected once pressed.
When one item is selected other items should be unselected.
No special behavior on long press, item gets selected on mouse up.
APIs added are to get current selected item and to programmatically
control the selection/unselection of an item.

This is patch D515 (had to do by hand).

legacy/elementary/src/bin/test_colorselector.c
legacy/elementary/src/lib/elm_colorselector.c
legacy/elementary/src/lib/elm_colorselector_common.h
legacy/elementary/src/lib/elm_colorselector_eo.h
legacy/elementary/src/lib/elm_colorselector_legacy.h
legacy/elementary/src/lib/elm_widget_colorselector.h

index 411d7a0..5947632 100644 (file)
@@ -84,6 +84,7 @@ test_colorselector(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
    const Eina_List *item_list, *last_item_list;
    Elm_Object_Item *color_item;
    int r, g, b, a;
+   Elm_Object_Item *item;
 
    win = elm_win_util_standard_add("colorselector", "ColorSelector");
    elm_win_autodel_set(win, EINA_TRUE);
@@ -113,7 +114,9 @@ test_colorselector(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
    evas_object_show(fr);
 
    cs = elm_colorselector_add(fr);
-   elm_colorselector_palette_color_add(cs, 255, 90, 18, 128);
+   item = elm_colorselector_palette_color_add(cs, 255, 90, 18, 128);
+   elm_colorselector_palette_item_selected_set(item, EINA_TRUE);
+
    elm_colorselector_palette_color_add(cs, 255, 213, 0, 255);
    elm_colorselector_palette_color_add(cs, 146, 255, 11, 255);
    elm_colorselector_palette_color_add(cs, 9, 186, 10, 255);
index 714cd79..daf3261 100644 (file)
@@ -1272,7 +1272,7 @@ _on_color_long_press(void *data)
    ELM_COLORSELECTOR_DATA_GET(WIDGET(item), sd);
 
    sd->longpress_timer = NULL;
-   sd->longpressed = EINA_TRUE;
+
    evas_object_smart_callback_call
      (WIDGET(item), SIG_COLOR_ITEM_LONGPRESSED, item);
 
@@ -1293,8 +1293,6 @@ _on_color_pressed(void *data,
    ELM_COLORSELECTOR_DATA_GET(WIDGET(item), sd);
 
    if (ev->button != 1) return;
-   elm_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
-   sd->longpressed = EINA_FALSE;
 
    ecore_timer_del(sd->longpress_timer);
    sd->longpress_timer = ecore_timer_add
@@ -1317,15 +1315,17 @@ _on_color_released(void *data,
 
    if (ev->button != 1) return;
    ELM_SAFE_FREE(sd->longpress_timer, ecore_timer_del);
-   elm_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
-   if (!sd->longpressed)
-     {
-        elm_colorselector_color_set
-          (WIDGET(item), item->color->r, item->color->g, item->color->b,
-          item->color->a);
-        evas_object_smart_callback_call
-          (WIDGET(item), SIG_COLOR_ITEM_SELECTED, item);
-     }
+
+   elm_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
+   elm_colorselector_color_set(WIDGET(item), item->color->r, item->color->g,
+                               item->color->b, item->color->a);
+   evas_object_smart_callback_call(WIDGET(item), SIG_COLOR_ITEM_SELECTED,
+                                   item);
+
+   temp_item = eina_list_data_get(sd->selected);
+   if (temp_item && (temp_item != item))
+     elm_object_signal_emit(VIEW(temp_item), "elm,state,unselected", "elm");
+
    EINA_LIST_FOREACH(sd->items, l, temp_item)
      if (item == temp_item) sd->selected = l;
    sd->focused = ELM_COLORSELECTOR_PALETTE;
@@ -2167,6 +2167,67 @@ _palette_items_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
 }
 
 EAPI void
+elm_colorselector_palette_item_selected_set(Elm_Object_Item *it,
+                              Eina_Bool selected)
+{
+   Elm_Color_Item *temp_item, *item;
+   item = (Elm_Color_Item *)it;
+   Eina_List *l;
+
+   ELM_COLORSELECTOR_DATA_GET(WIDGET(item), sd);
+   ELM_COLORSELECTOR_ITEM_CHECK_OR_RETURN(it);
+
+   if (selected)
+     {
+        temp_item = eina_list_data_get(sd->selected);
+        if (item == temp_item) return;
+        elm_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
+        elm_colorselector_color_set(WIDGET(item), item->color->r, item->color->g,
+                                    item->color->b, item->color->a);
+        if (temp_item)
+          elm_object_signal_emit(VIEW(temp_item), "elm,state,unselected", "elm");
+
+        EINA_LIST_FOREACH(sd->items, l, temp_item)
+          if (item == temp_item) sd->selected = l;
+     }
+   else
+     {
+        elm_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
+        sd->selected = NULL;
+     }
+}
+
+EAPI Eina_Bool
+elm_colorselector_palette_item_selected_get(const Elm_Object_Item *it)
+{
+   Elm_Color_Item *temp_item, *item;
+   item = (Elm_Color_Item *)it;
+   ELM_COLORSELECTOR_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
+   ELM_COLORSELECTOR_DATA_GET(WIDGET(item), sd);
+
+   temp_item = eina_list_data_get(sd->selected);
+   if (item == temp_item) return EINA_TRUE;
+   else return EINA_FALSE;
+}
+
+EAPI Elm_Object_Item *
+elm_colorselector_palette_selected_item_get(const Evas_Object *obj)
+{
+   ELM_COLORSELECTOR_CHECK(obj) NULL;
+   Elm_Object_Item *ret = NULL;
+   eo_do((Eo *) obj, elm_obj_colorselector_palette_selected_item_get(&ret));
+   return ret;
+}
+
+static void
+_palette_selected_item_get(Eo *obj EINA_UNUSED, void *_pd, va_list *list)
+{
+   Elm_Object_Item **ret = va_arg(*list, Elm_Object_Item **);
+   Elm_Colorselector_Smart_Data *sd = _pd;
+   *ret = eina_list_data_get(sd->selected);
+}
+
+EAPI void
 elm_colorselector_palette_name_set(Evas_Object *obj,
                                    const char *palette_name)
 {
@@ -2230,6 +2291,7 @@ _class_constructor(Eo_Class *klass)
         EO_OP_FUNC(ELM_OBJ_COLORSELECTOR_ID(ELM_OBJ_COLORSELECTOR_SUB_ID_MODE_GET), _mode_get),
         EO_OP_FUNC(ELM_OBJ_COLORSELECTOR_ID(ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_COLOR_ADD), _palette_color_add),
         EO_OP_FUNC(ELM_OBJ_COLORSELECTOR_ID(ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_CLEAR), _palette_clear),
+        EO_OP_FUNC(ELM_OBJ_COLORSELECTOR_ID(ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_SELECTED_ITEM_GET), _palette_selected_item_get),
         EO_OP_FUNC(ELM_OBJ_COLORSELECTOR_ID(ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_ITEMS_GET), _palette_items_get),
         EO_OP_FUNC(ELM_OBJ_COLORSELECTOR_ID(ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_NAME_SET), _palette_name_set),
         EO_OP_FUNC(ELM_OBJ_COLORSELECTOR_ID(ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_NAME_GET), _palette_name_get),
@@ -2249,6 +2311,7 @@ static const Eo_Op_Description op_desc[] = {
      EO_OP_DESCRIPTION(ELM_OBJ_COLORSELECTOR_SUB_ID_MODE_GET, "Get Colorselector's mode."),
      EO_OP_DESCRIPTION(ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_COLOR_ADD, "Add a new color item to palette."),
      EO_OP_DESCRIPTION(ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_CLEAR, "Clear the palette items."),
+     EO_OP_DESCRIPTION(ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_SELECTED_ITEM_GET, "Get Palette's current selected item"),
      EO_OP_DESCRIPTION(ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_ITEMS_GET, "Get palette's item list"),
      EO_OP_DESCRIPTION(ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_NAME_SET, "Set current palette's name."),
      EO_OP_DESCRIPTION(ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_NAME_GET, "Get current palette's name."),
index d39cf56..801b416 100644 (file)
@@ -56,3 +56,24 @@ EAPI void elm_colorselector_palette_item_color_get(const Elm_Object_Item *it, in
  */
 EAPI void elm_colorselector_palette_item_color_set(Elm_Object_Item *it, int r, int g, int b, int a);
 
+/**
+ * Get the selected state of color palette item.
+ *
+ * @param it The Colorpalette item
+ * @return EINA_TRUE if the item is selected, EINA_FALSE otherwise.
+ *
+ * @since 1.9
+ * @ingroup Colorselector
+ */
+EAPI Eina_Bool elm_colorselector_palette_item_selected_get(const Elm_Object_Item *it);
+
+/**
+ * Set the selected state of color palette item
+ *
+ * @param it The Colorpalette item
+ * @param selected if it's EINA_TRUE, select the item otherwise, unselect the item
+ *
+ * @since 1.9
+ * @ingroup Colorselector
+ */
+EAPI void elm_colorselector_palette_item_selected_set(Elm_Object_Item *it, Eina_Bool selected);
index b7ac81a..b8cc88e 100644 (file)
@@ -12,6 +12,7 @@ enum
    ELM_OBJ_COLORSELECTOR_SUB_ID_MODE_GET,
    ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_COLOR_ADD,
    ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_CLEAR,
+   ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_SELECTED_ITEM_GET,
    ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_ITEMS_GET,
    ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_NAME_SET,
    ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_NAME_GET,
@@ -127,6 +128,18 @@ enum
 #define elm_obj_colorselector_palette_items_get(ret) ELM_OBJ_COLORSELECTOR_ID(ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_ITEMS_GET), EO_TYPECHECK(const Eina_List **, ret)
 
 /**
+ * @def elm_obj_colorselector_palette_selected_item_get
+ * @since 1.9
+ *
+ * Get current selected palette item
+ *
+ * @param[out] ret
+ *
+ * @ingroup Colorselector
+ */
+#define elm_obj_colorselector_palette_selected_item_get(ret) ELM_OBJ_COLORSELECTOR_ID(ELM_OBJ_COLORSELECTOR_SUB_ID_PALETTE_SELECTED_ITEM_GET), EO_TYPECHECK(Elm_Object_Item **, ret)
+
+/**
  * @def elm_obj_colorselector_palette_name_set
  * @since 1.8
  *
index b366056..7a7dd03 100644 (file)
@@ -95,6 +95,17 @@ EAPI void elm_colorselector_palette_clear(Evas_Object *obj);
 EAPI const Eina_List *elm_colorselector_palette_items_get(const Evas_Object *obj);
 
 /**
+ * Get the selected item in colorselector palette.
+ *
+ * @param obj The Colorselector object
+ * @return The selected item, or NULL if none is selected.
+ *
+ * @since 1.9
+ * @ingroup Colorselector
+ */
+EAPI Elm_Object_Item *elm_colorselector_palette_selected_item_get(const Evas_Object *obj);
+
+/**
  * Set current palette's name
  *
  * @param obj The Colorselector object
index 4dbc4ac..7b1c5ed 100644 (file)
@@ -56,7 +56,6 @@ struct _Elm_Colorselector_Smart_Data
    Elm_Colorselector_Mode mode, focused;
    int                    sel_color_type;
 
-   Eina_Bool              longpressed : 1;
    Eina_Bool              config_load : 1;
 };