summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Jagiello <m.jagiello@samsung.com>2014-07-03 13:05:28 +0200
committerLukasz Stanislawski <l.stanislaws@samsung.com>2014-07-03 13:05:28 +0200
commit467adad7808a60cc16e872b888ff451730f92d8d (patch)
tree409a603447d2510bd4ac14b9be02f3f6ddd3a339
parentb58434fc0faf645a26e299d1f68f648acad20299 (diff)
ctxpopup: Add get_items, get_last_item, get_first_item, get_next_item and get_prev_item API
Summary: API to get list of ctxpopup items and give the possibility to iterate the ctxpopup items Reviewers: stanluk, z.kosinski, Hermet, seoz, raster CC: Hermet, seoz Differential Revision: https://phab.enlightenment.org/D1055
-rw-r--r--src/lib/elc_ctxpopup.c148
-rw-r--r--src/lib/elc_ctxpopup.eo79
-rw-r--r--src/lib/elc_ctxpopup_common.h30
-rw-r--r--src/lib/elm_widget_ctxpopup.h4
4 files changed, 232 insertions, 29 deletions
diff --git a/src/lib/elc_ctxpopup.c b/src/lib/elc_ctxpopup.c
index 9278dcbfa..a2ae83d25 100644
--- a/src/lib/elc_ctxpopup.c
+++ b/src/lib/elc_ctxpopup.c
@@ -35,6 +35,10 @@ static const Evas_Smart_Cb_Description _smart_callbacks[] = {
35 35
36static Eina_Bool _key_action_move(Evas_Object *obj, const char *params); 36static Eina_Bool _key_action_move(Evas_Object *obj, const char *params);
37static Eina_Bool _key_action_escape(Evas_Object *obj, const char *params); 37static Eina_Bool _key_action_escape(Evas_Object *obj, const char *params);
38static Elm_Ctxpopup_Item* _item_new(Eo *obj,
39 Elm_Ctxpopup_Data *sd,
40 Evas_Smart_Cb func,
41 const void *data);
38 42
39static const Elm_Action key_actions[] = { 43static const Elm_Action key_actions[] = {
40 {"move", _key_action_move}, 44 {"move", _key_action_move},
@@ -1254,41 +1258,13 @@ _elm_ctxpopup_item_append(Eo *obj, Elm_Ctxpopup_Data *sd, const char *label, Eva
1254{ 1258{
1255 Elm_Ctxpopup_Item *item; 1259 Elm_Ctxpopup_Item *item;
1256 1260
1257 1261 item = _item_new(obj, sd, func, data);
1258 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1259 if (!item) return NULL; 1262 if (!item) return NULL;
1260 1263
1261 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
1262 elm_widget_item_disable_hook_set(item, _item_disable_hook);
1263 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1264 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1265 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1266 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1267 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1268
1269 if (!sd->list)
1270 {
1271 //The first item is appended.
1272 sd->list = elm_list_add(obj);
1273 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
1274 elm_object_style_set(sd->list, "ctxpopup");
1275 else elm_object_style_set(sd->list, elm_object_style_get(obj));
1276 elm_list_mode_set(sd->list, ELM_LIST_EXPAND);
1277 elm_list_horizontal_set(sd->list, sd->horizontal);
1278 evas_object_event_callback_add
1279 (sd->list, EVAS_CALLBACK_RESIZE, _list_resize_cb, obj);
1280 elm_layout_content_set(obj, "default", sd->list);
1281 }
1282
1283 item->wcb.org_func_cb = func;
1284 item->wcb.org_data = data;
1285 item->wcb.cobj = obj;
1286 item->list_item = 1264 item->list_item =
1287 elm_list_item_append(sd->list, label, icon, NULL, _item_wrap_cb, item); 1265 elm_list_item_append(sd->list, label, icon, NULL, _item_wrap_cb, item);
1288 sd->items = eina_list_append(sd->items, item); 1266 sd->items = eina_list_append(sd->items, item);
1289 1267
1290 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1291
1292 if (sd->visible) elm_layout_sizing_eval(obj); 1268 if (sd->visible) elm_layout_sizing_eval(obj);
1293 1269
1294 return (Elm_Object_Item *)item; 1270 return (Elm_Object_Item *)item;
@@ -1346,4 +1322,118 @@ _elm_ctxpopup_class_constructor(Eo_Class *klass)
1346 evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass); 1322 evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
1347} 1323}
1348 1324
1325EOLIAN static const Eina_List*
1326_elm_ctxpopup_items_get(Eo *obj EINA_UNUSED, Elm_Ctxpopup_Data *sd)
1327{
1328 return sd->items;
1329}
1330
1331EOLIAN static Elm_Object_Item*
1332_elm_ctxpopup_first_item_get(Eo *obj EINA_UNUSED, Elm_Ctxpopup_Data *sd)
1333{
1334 if (!sd->items) return NULL;
1335
1336 return eina_list_data_get(sd->items);
1337}
1338
1339EOLIAN static Elm_Object_Item*
1340_elm_ctxpopup_last_item_get(Eo *obj EINA_UNUSED, Elm_Ctxpopup_Data *sd)
1341{
1342 if (!sd->items) return NULL;
1343
1344 return eina_list_data_get(eina_list_last(sd->items));
1345}
1346
1347EOLIAN static Elm_Object_Item*
1348_elm_ctxpopup_item_prepend(Eo *obj, Elm_Ctxpopup_Data *sd, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1349{
1350 Elm_Ctxpopup_Item *item;
1351
1352 item = _item_new(obj, sd, func, data);
1353 if (!item) return NULL;
1354
1355 item->list_item =
1356 elm_list_item_prepend(sd->list, label, icon, NULL, _item_wrap_cb, item);
1357 sd->items = eina_list_prepend(sd->items, item);
1358
1359 if (sd->visible) elm_layout_sizing_eval(obj);
1360
1361 return (Elm_Object_Item *)item;
1362}
1363
1364EAPI Elm_Object_Item *
1365elm_ctxpopup_item_prev_get(const Elm_Object_Item *it)
1366{
1367 Eina_List *l;
1368 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *)it;
1369
1370 ELM_CTXPOPUP_ITEM_CHECK_OR_RETURN(it, NULL);
1371 ELM_CTXPOPUP_DATA_GET(WIDGET(item), sd);
1372
1373 if (!sd->items) return NULL;
1374
1375 l = eina_list_data_find_list(sd->items, it);
1376 if (l && l->prev) return eina_list_data_get(l->prev);
1377
1378 return NULL;
1379}
1380
1381EAPI Elm_Object_Item *
1382elm_ctxpopup_item_next_get(const Elm_Object_Item *it)
1383{
1384 Eina_List *l;
1385 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *)it;
1386
1387 ELM_CTXPOPUP_ITEM_CHECK_OR_RETURN(it, NULL);
1388 ELM_CTXPOPUP_DATA_GET(WIDGET(item), sd);
1389
1390 if (!sd->items) return NULL;
1391
1392 l = eina_list_data_find_list(sd->items, it);
1393 if (l && l->next) return eina_list_data_get(l->next);
1394
1395 return NULL;
1396}
1397
1398static Elm_Ctxpopup_Item*
1399_item_new(Eo *obj,
1400 Elm_Ctxpopup_Data *sd,
1401 Evas_Smart_Cb func,
1402 const void *data)
1403{
1404 Elm_Ctxpopup_Item *item;
1405
1406 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1407 if (!item) return NULL;
1408
1409 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
1410 elm_widget_item_disable_hook_set(item, _item_disable_hook);
1411 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1412 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1413 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1414 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1415 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1416
1417 if (!sd->list)
1418 {
1419 sd->list = elm_list_add(obj);
1420 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
1421 elm_object_style_set(sd->list, "ctxpopup");
1422 else elm_object_style_set(sd->list, elm_object_style_get(obj));
1423 elm_list_mode_set(sd->list, ELM_LIST_EXPAND);
1424 elm_list_horizontal_set(sd->list, sd->horizontal);
1425 evas_object_event_callback_add
1426 (sd->list, EVAS_CALLBACK_RESIZE, _list_resize_cb, obj);
1427 elm_layout_content_set(obj, "default", sd->list);
1428 }
1429
1430 item->wcb.org_func_cb = func;
1431 item->wcb.org_data = data;
1432 item->wcb.cobj = obj;
1433
1434 sd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1435
1436 return item;
1437}
1438
1349#include "elc_ctxpopup.eo.c" 1439#include "elc_ctxpopup.eo.c"
diff --git a/src/lib/elc_ctxpopup.eo b/src/lib/elc_ctxpopup.eo
index 0fe7fee93..30ef26cbe 100644
--- a/src/lib/elc_ctxpopup.eo
+++ b/src/lib/elc_ctxpopup.eo
@@ -124,6 +124,63 @@ class Elm_Ctxpopup (Elm_Layout)
124 return Elm_Ctxpopup_Direction; 124 return Elm_Ctxpopup_Direction;
125 } 125 }
126 } 126 }
127 items {
128 get {
129 /*@
130 @brief Get the internal list of items in a given ctxpopup widget.
131 @since 1.11
132
133 @return The list of items (#Elm_Object_Item as data) or
134 @c NULL on errors.
135
136 This list is @b not to be modified in any way and must not be
137 freed. Use the list members with functions like
138 elm_object_item_text_set(),
139 elm_object_item_text_get(),
140 elm_object_item_del().
141
142 @warning This list is only valid until @p obj object's internal
143 items list is changed. It should be fetched again with another
144 call to this function when changes happen.
145
146 @ingroup Ctxpopup */
147 return const(Eina_List)*;
148 }
149 }
150 first_item {
151 get {
152 /*@
153 Get the first item in the given ctxpopup widget's list of
154 items.
155 @since 1.11
156
157 @return The first item or @c NULL, if it has no items (and on
158 errors)
159
160 @see elm_ctxpopup_item_append()
161 @see elm_ctxpopup_last_item_get()
162
163 @ingroup Ctxpopup */
164 return Elm_Object_Item *;
165 }
166 }
167 last_item {
168 get {
169 /*@
170 Get the last item in the given ctxpopup widget's list of
171 items.
172 @since 1.11
173
174 @return The last item or @c NULL, if it has no items (and on
175 errors)
176
177 @see elm_ctxpopup_item_prepend()
178 @see elm_ctxpopup_first_item_get()
179
180 @ingroup Ctxpopup */
181 return Elm_Object_Item *;
182 }
183 }
127 } 184 }
128 methods { 185 methods {
129 dismiss { 186 dismiss {
@@ -163,6 +220,28 @@ class Elm_Ctxpopup (Elm_Layout)
163 @in const(void)* data; /*@ Data passed to @p func */ 220 @in const(void)* data; /*@ Data passed to @p func */
164 } 221 }
165 } 222 }
223 item_prepend {
224 /*@
225 @brief Prepend a new item to a ctxpopup object.
226 @since 1.11
227
228 @return A handle to the item added or @c NULL, on errors
229
230 @warning Ctxpopup can't hold both an item list and a content at the same
231 time. When an item is added, any previous content will be removed.
232
233 @see elm_object_content_set()
234
235 @ingroup Ctxpopup */
236
237 return Elm_Object_Item *;
238 params {
239 @in const(char)* label; /*@ The Label of the new item */
240 @in Evas_Object *icon; /*@ Icon to be set on new item */
241 @in Evas_Smart_Cb func; /*@ Convenience function called when item selected */
242 @in const(void)* data; /*@ Data passed to @p func */
243 }
244 }
166 } 245 }
167 implements { 246 implements {
168 class.constructor; 247 class.constructor;
diff --git a/src/lib/elc_ctxpopup_common.h b/src/lib/elc_ctxpopup_common.h
index d4a26fbef..9f658e07a 100644
--- a/src/lib/elc_ctxpopup_common.h
+++ b/src/lib/elc_ctxpopup_common.h
@@ -7,3 +7,33 @@ typedef enum
7 ELM_CTXPOPUP_DIRECTION_UNKNOWN, /**< ctxpopup does not determine it's direction yet*/ 7 ELM_CTXPOPUP_DIRECTION_UNKNOWN, /**< ctxpopup does not determine it's direction yet*/
8} Elm_Ctxpopup_Direction; /**< Direction in which to show the popup */ 8} Elm_Ctxpopup_Direction; /**< Direction in which to show the popup */
9 9
10/**
11 * Get the item before @p it in a ctxpopup widget's internal list of
12 * items.
13 *
14 * @param it The item to fetch previous from
15 * @return The item before the @p it in its parent's list. If there is no
16 * previous item for @p it or there's an error, @c NULL is returned.
17 *
18 * @see elm_ctxpopup_item_next_get()
19 *
20 * @since 1.11
21 * @ingroup Ctxpopup
22 */
23EAPI Elm_Object_Item *elm_ctxpopup_item_prev_get(const Elm_Object_Item *it);
24
25/**
26 * Get the item after @p it in a ctxpopup widget's
27 * internal list of items.
28 *
29 * @param it The item to fetch next from
30 * @return The item after the @p it in its parent's list. If there is no next
31 * item for @p it or there's an error, @c NULL is returned.
32 *
33 * @see elm_ctxpopup_item_prev_get()
34 *
35 * @since 1.11
36 * @ingroup Ctxpopup
37 */
38EAPI Elm_Object_Item *elm_ctxpopup_item_next_get(const Elm_Object_Item *it);
39
diff --git a/src/lib/elm_widget_ctxpopup.h b/src/lib/elm_widget_ctxpopup.h
index 3f4eabc89..391359a87 100644
--- a/src/lib/elm_widget_ctxpopup.h
+++ b/src/lib/elm_widget_ctxpopup.h
@@ -85,4 +85,8 @@ struct _Elm_Ctxpopup_Data
85 if (EINA_UNLIKELY(!eo_isa((obj), ELM_CTXPOPUP_CLASS))) \ 85 if (EINA_UNLIKELY(!eo_isa((obj), ELM_CTXPOPUP_CLASS))) \
86 return 86 return
87 87
88#define ELM_CTXPOPUP_ITEM_CHECK_OR_RETURN(it, ...) \
89 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
90 ELM_CTXPOPUP_CHECK(it->base.widget) __VA_ARGS__;
91
88#endif 92#endif