summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorAmitesh Singh <amitesh.sh@samsung.com>2017-10-26 15:36:07 +0900
committerAmitesh Singh <amitesh.sh@samsung.com>2017-10-26 21:11:36 +0900
commitde74fd11ba1b8afce81c89777d381016cee454ea (patch)
tree5b2e89835458f30561266fa81d2587c5eadb552b /src/lib
parent3092c0fdeaad221c37da996b3ea4a9aaa437ada6 (diff)
Efl.Ui.Mbe: implement format_cb.set()
Ref T6204
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/elementary/efl_ui_multibuttonentry.c111
-rw-r--r--src/lib/elementary/efl_ui_multibuttonentry.eo17
-rw-r--r--src/lib/elementary/efl_ui_multibuttonentry_private.h11
-rw-r--r--src/lib/elementary/elc_multibuttonentry_legacy.h17
4 files changed, 109 insertions, 47 deletions
diff --git a/src/lib/elementary/efl_ui_multibuttonentry.c b/src/lib/elementary/efl_ui_multibuttonentry.c
index 4cec0b167c..81e2b391ca 100644
--- a/src/lib/elementary/efl_ui_multibuttonentry.c
+++ b/src/lib/elementary/efl_ui_multibuttonentry.c
@@ -191,6 +191,7 @@ _shrink_mode_set(Evas_Object *obj,
191 { 191 {
192 Evas_Coord w = 0; 192 Evas_Coord w = 0;
193 Evas_Coord box_inner_item_width_padding = 0; 193 Evas_Coord box_inner_item_width_padding = 0;
194 Eina_Value val;
194 195
195 elm_box_padding_get(sd->box, &box_inner_item_width_padding, NULL); 196 elm_box_padding_get(sd->box, &box_inner_item_width_padding, NULL);
196 // unpack all items and entry 197 // unpack all items and entry
@@ -219,7 +220,6 @@ _shrink_mode_set(Evas_Object *obj,
219 EINA_LIST_FOREACH(sd->items, l, eo_item) 220 EINA_LIST_FOREACH(sd->items, l, eo_item)
220 { 221 {
221 Evas_Coord w_label_count = 0, h = 0; 222 Evas_Coord w_label_count = 0, h = 0;
222 char *buf;
223 223
224 ELM_MULTIBUTTONENTRY_ITEM_DATA_GET(eo_item, item); 224 ELM_MULTIBUTTONENTRY_ITEM_DATA_GET(eo_item, item);
225 elm_box_pack_end(sd->box, VIEW(item)); 225 elm_box_pack_end(sd->box, VIEW(item));
@@ -233,15 +233,15 @@ _shrink_mode_set(Evas_Object *obj,
233 w -= box_inner_item_width_padding; 233 w -= box_inner_item_width_padding;
234 count--; 234 count--;
235 235
236 eina_value_setup(&val, EINA_VALUE_TYPE_INT);
237
236 if (count > 0) 238 if (count > 0)
237 { 239 {
238 buf = sd->format_func(count, (void *)sd->format_func_data); 240 eina_strbuf_reset(sd->format_strbuf);
239 if (buf) 241 eina_value_set(&val, count);
240 { 242 sd->format_cb(sd->format_cb_data, sd->format_strbuf, val);
241 edje_object_part_text_escaped_set 243 edje_object_part_text_escaped_set(sd->end, "elm.text",
242 (sd->end, "elm.text", buf); 244 eina_strbuf_string_get(sd->format_strbuf));
243 free(buf);
244 }
245 245
246 edje_object_size_min_calc(sd->end, &w_label_count, NULL); 246 edje_object_size_min_calc(sd->end, &w_label_count, NULL);
247 elm_coords_finger_size_adjust(1, &w_label_count, 1, NULL); 247 elm_coords_finger_size_adjust(1, &w_label_count, 1, NULL);
@@ -254,13 +254,12 @@ _shrink_mode_set(Evas_Object *obj,
254 item->visible = EINA_FALSE; 254 item->visible = EINA_FALSE;
255 count++; 255 count++;
256 256
257 buf = sd->format_func(count, (void *)sd->format_func_data); 257 eina_strbuf_reset(sd->format_strbuf);
258 if (buf) 258
259 { 259 eina_value_set(&val, count);
260 edje_object_part_text_escaped_set 260 sd->format_cb(sd->format_cb_data, sd->format_strbuf, val);
261 (sd->end, "elm.text", buf); 261 edje_object_part_text_escaped_set(sd->end, "elm.text",
262 free(buf); 262 eina_strbuf_string_get(sd->format_strbuf));
263 }
264 263
265 edje_object_size_min_calc(sd->end, &w_label_count, &h); 264 edje_object_size_min_calc(sd->end, &w_label_count, &h);
266 elm_coords_finger_size_adjust(1, &w_label_count, 1, &h); 265 elm_coords_finger_size_adjust(1, &w_label_count, 1, &h);
@@ -1639,7 +1638,8 @@ _efl_ui_multibuttonentry_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Multibuttone
1639 priv->last_it_select = EINA_TRUE; 1638 priv->last_it_select = EINA_TRUE;
1640 priv->editable = EINA_TRUE; 1639 priv->editable = EINA_TRUE;
1641 priv->parent = obj; 1640 priv->parent = obj;
1642 priv->format_func = _format_count; 1641
1642 efl_ui_format_string_set(obj, "+%d");
1643 1643
1644 _view_init(obj, priv); 1644 _view_init(obj, priv);
1645 _callbacks_register(obj); 1645 _callbacks_register(obj);
@@ -1675,6 +1675,10 @@ _efl_ui_multibuttonentry_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Multibuttone
1675 evas_object_del(sd->end); 1675 evas_object_del(sd->end);
1676 ecore_timer_del(sd->longpress_timer); 1676 ecore_timer_del(sd->longpress_timer);
1677 1677
1678 if (sd->format_free_cb) sd->format_free_cb(sd->format_cb_data);
1679 efl_ui_format_cb_set(obj, NULL, NULL, NULL);
1680 eina_strbuf_free(sd->format_strbuf);
1681
1678 EINA_LIST_FREE(sd->filter_list, _item_filter) 1682 EINA_LIST_FREE(sd->filter_list, _item_filter)
1679 _filter_free(_item_filter); 1683 _filter_free(_item_filter);
1680 1684
@@ -1736,17 +1740,6 @@ _efl_ui_multibuttonentry_expanded_get(Eo *obj EINA_UNUSED, Efl_Ui_Multibuttonent
1736} 1740}
1737 1741
1738EOLIAN static void 1742EOLIAN static void
1739_efl_ui_multibuttonentry_format_function_set(Eo *obj EINA_UNUSED, Efl_Ui_Multibuttonentry_Data *sd, Efl_Ui_Multibuttonentry_Format_Cb f_func, const void *data)
1740{
1741 sd->format_func = f_func;
1742 if (!sd->format_func) sd->format_func = _format_count;
1743
1744 sd->format_func_data = data;
1745
1746 _view_update(sd);
1747}
1748
1749EOLIAN static void
1750_efl_ui_multibuttonentry_expanded_set(Eo *obj, Efl_Ui_Multibuttonentry_Data *sd, Eina_Bool expanded) 1743_efl_ui_multibuttonentry_expanded_set(Eo *obj, Efl_Ui_Multibuttonentry_Data *sd, Eina_Bool expanded)
1751{ 1744{
1752 if (((sd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK) ? 1745 if (((sd->view_state == MULTIBUTTONENTRY_VIEW_SHRINK) ?
@@ -1998,6 +1991,23 @@ _efl_ui_multibuttonentry_item_filter_remove(Eo *obj EINA_UNUSED, Efl_Ui_Multibut
1998 } 1991 }
1999} 1992}
2000 1993
1994EOLIAN static void
1995_efl_ui_multibuttonentry_efl_ui_format_format_cb_set(Eo *obj EINA_UNUSED, Efl_Ui_Multibuttonentry_Data *sd, void *func_data, Efl_Ui_Format_Func_Cb func, Eina_Free_Cb func_free_cb)
1996{
1997 if (sd->format_cb_data == func_data && sd->format_cb == func)
1998 return;
1999
2000 if (sd->format_cb_data && sd->format_free_cb)
2001 sd->format_free_cb(sd->format_cb_data);
2002
2003 sd->format_cb = func;
2004 sd->format_cb_data = func_data;
2005 sd->format_free_cb = func_free_cb;
2006 if (!sd->format_strbuf) sd->format_strbuf = eina_strbuf_new();
2007
2008 _view_update(sd);
2009}
2010
2001static void 2011static void
2002_efl_ui_multibuttonentry_class_constructor(Efl_Class *klass) 2012_efl_ui_multibuttonentry_class_constructor(Efl_Class *klass)
2003{ 2013{
@@ -2100,3 +2110,50 @@ ELM_PART_OVERRIDE_TEXT_GET(efl_ui_multibuttonentry, EFL_UI_MULTIBUTTONENTRY, Efl
2100 2110
2101#include "elm_multibuttonentry_item.eo.c" 2111#include "elm_multibuttonentry_item.eo.c"
2102#include "efl_ui_multibuttonentry.eo.c" 2112#include "efl_ui_multibuttonentry.eo.c"
2113
2114/* Legacy APIs */
2115
2116typedef struct
2117{
2118 Efl_Ui_Multibuttonentry_Format_Cb format_cb;
2119 void *data;
2120} Mbe_Format_Wrapper_Data ;
2121
2122static void
2123_format_legacy_to_format_eo_cb(void *data, Eina_Strbuf *str, const Eina_Value value)
2124{
2125 Mbe_Format_Wrapper_Data *mfwd = data;
2126 char *buf;
2127 int count = 0;
2128
2129 const Eina_Value_Type *type = eina_value_type_get(&value);
2130
2131 if (type == EINA_VALUE_TYPE_INT)
2132 eina_value_get(&value, &count);
2133
2134 buf = mfwd->format_cb(count, mfwd->data);
2135 if (buf)
2136 eina_strbuf_append(str, buf);
2137 free(buf);
2138}
2139
2140static void
2141_format_legacy_to_format_eo_free_cb(void *data)
2142{
2143 Mbe_Format_Wrapper_Data *mfwd = data;
2144
2145 free(mfwd);
2146}
2147
2148EAPI void
2149elm_multibuttonentry_format_function_set(Eo *obj, Efl_Ui_Multibuttonentry_Format_Cb format_function, const void *data)
2150{
2151 Mbe_Format_Wrapper_Data *mfwd = malloc(sizeof(Mbe_Format_Wrapper_Data));
2152
2153 mfwd->format_cb = format_function;
2154 if (!mfwd->format_cb) mfwd->format_cb = _format_count;
2155
2156 mfwd->data = (void *)data;
2157
2158 efl_ui_format_cb_set(obj, mfwd, _format_legacy_to_format_eo_cb, _format_legacy_to_format_eo_free_cb);
2159}
diff --git a/src/lib/elementary/efl_ui_multibuttonentry.eo b/src/lib/elementary/efl_ui_multibuttonentry.eo
index 9462eb2a76..fb60d2ebcc 100644
--- a/src/lib/elementary/efl_ui_multibuttonentry.eo
+++ b/src/lib/elementary/efl_ui_multibuttonentry.eo
@@ -1,7 +1,7 @@
1type Elm_Multibuttonentry_Item_Filter_Cb: __undefined_type; [[Elementary multibuttonentry item filter callback type]] 1type Elm_Multibuttonentry_Item_Filter_Cb: __undefined_type; [[Elementary multibuttonentry item filter callback type]]
2type Efl_Ui_Multibuttonentry_Format_Cb: __undefined_type; [[Elementary multibuttonentry format callback type]] 2type Efl_Ui_Multibuttonentry_Format_Cb: __undefined_type; [[Elementary multibuttonentry format callback type]]
3 3
4class Efl.Ui.Multibuttonentry (Efl.Ui.Layout, Efl.Ui.Clickable) 4class Efl.Ui.Multibuttonentry (Efl.Ui.Layout, Efl.Ui.Clickable, Efl.Ui.Format)
5{ 5{
6 [[Elementary multibuttonentry class]] 6 [[Elementary multibuttonentry class]]
7 legacy_prefix: elm_multibuttonentry; 7 legacy_prefix: elm_multibuttonentry;
@@ -32,20 +32,6 @@ class Efl.Ui.Multibuttonentry (Efl.Ui.Layout, Efl.Ui.Clickable)
32 this to $false for single line state.]] 32 this to $false for single line state.]]
33 } 33 }
34 } 34 }
35 @property format_function {
36 set {
37 [[Set a function to format the string that will be used to display the hidden items counter.
38
39 If $format_function is $NULL, the default format will be used,
40 which is $"... + %d".
41
42 @since 1.9]]
43 }
44 values {
45 format_function: Efl_Ui_Multibuttonentry_Format_Cb @nullable; [[Format_function The actual format function]]
46 data: const(void_ptr) @optional; [[Data User data to passed to $format_function]]
47 }
48 }
49 @property items { 35 @property items {
50 get { 36 get {
51 [[Get a list of items in the multibuttonentry]] 37 [[Get a list of items in the multibuttonentry]]
@@ -183,6 +169,7 @@ class Efl.Ui.Multibuttonentry (Efl.Ui.Layout, Efl.Ui.Clickable)
183 Elm.Widget.widget_event; 169 Elm.Widget.widget_event;
184 Efl.Access.children { get; } 170 Efl.Access.children { get; }
185 Efl.Part.part; 171 Efl.Part.part;
172 Efl.Ui.Format.format_cb { set; }
186 } 173 }
187 events { 174 events {
188 item,selected; [[Called when item was selected]] 175 item,selected; [[Called when item was selected]]
diff --git a/src/lib/elementary/efl_ui_multibuttonentry_private.h b/src/lib/elementary/efl_ui_multibuttonentry_private.h
index 64acf38e87..572e5fa47b 100644
--- a/src/lib/elementary/efl_ui_multibuttonentry_private.h
+++ b/src/lib/elementary/efl_ui_multibuttonentry_private.h
@@ -88,9 +88,6 @@ struct _Efl_Ui_Multibuttonentry_Data
88 Elm_Multibuttonentry_Item_Data *selected_it; /* selected item */ 88 Elm_Multibuttonentry_Item_Data *selected_it; /* selected item */
89 Elm_Multibuttonentry_Item_Data *focused_it; 89 Elm_Multibuttonentry_Item_Data *focused_it;
90 90
91 Efl_Ui_Multibuttonentry_Format_Cb format_func;
92 const void *format_func_data;
93
94 const char *label_str, *guide_text_str; 91 const char *label_str, *guide_text_str;
95 92
96 int n_str; 93 int n_str;
@@ -101,13 +98,17 @@ struct _Efl_Ui_Multibuttonentry_Data
101 98
102 Elm_Multibuttonentry_Item_Filter_Cb add_callback; 99 Elm_Multibuttonentry_Item_Filter_Cb add_callback;
103 void *add_callback_data; 100 void *add_callback_data;
101 Ecore_Timer *longpress_timer;
102
103 Efl_Ui_Format_Func_Cb format_cb;
104 Eina_Free_Cb format_free_cb;
105 void *format_cb_data;
106 Eina_Strbuf *format_strbuf;
104 107
105 Eina_Bool last_it_select : 1; 108 Eina_Bool last_it_select : 1;
106 Eina_Bool editable : 1; 109 Eina_Bool editable : 1;
107 Eina_Bool focused : 1; 110 Eina_Bool focused : 1;
108 Eina_Bool label_packed : 1; 111 Eina_Bool label_packed : 1;
109
110 Ecore_Timer *longpress_timer;
111}; 112};
112 113
113/** 114/**
diff --git a/src/lib/elementary/elc_multibuttonentry_legacy.h b/src/lib/elementary/elc_multibuttonentry_legacy.h
index 157ffb645a..8831fe71ca 100644
--- a/src/lib/elementary/elc_multibuttonentry_legacy.h
+++ b/src/lib/elementary/elc_multibuttonentry_legacy.h
@@ -9,5 +9,22 @@
9 */ 9 */
10EAPI Evas_Object *elm_multibuttonentry_add(Evas_Object *parent); 10EAPI Evas_Object *elm_multibuttonentry_add(Evas_Object *parent);
11 11
12/**
13 * @brief Set a function to format the string that will be used to display the
14 * hidden items counter.
15 *
16 * If @c format_function is @c NULL, the default format will be used, which is
17 * $"... + %d".
18 *
19 * @param[in] obj The object.
20 * @param[in] format_function Format_function The actual format function
21 * @param[in] data Data User data to passed to @c format_function
22 *
23 * @since 1.9
24 *
25 * @ingroup Multibuttonentry
26 */
27 EAPI void elm_multibuttonentry_format_function_set(Eo *obj, Efl_Ui_Multibuttonentry_Format_Cb format_function, const void *data);
28
12#include "elm_multibuttonentry_item.eo.legacy.h" 29#include "elm_multibuttonentry_item.eo.legacy.h"
13#include "efl_ui_multibuttonentry.eo.legacy.h" 30#include "efl_ui_multibuttonentry.eo.legacy.h"