summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJyotiprakash Sahoo <jp.sahoo@samsung.com>2014-07-23 11:35:20 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-07-23 11:35:20 +0900
commitcb10e929f20cfa2f971e2bee80e8b82b9989ad65 (patch)
treeec11dce7cd11a9dba93a4ad2367e941b7a5a165c
parent1ad8575e8fd2abb274725f9b24898623c757b3bd (diff)
gengrid: Add function to search item by string.
Summary: This function allows user to search for item in Gengrid. Test Plan: elementary_test -to "Gengrid Item Search By Text" Reviewers: seoz, singh.amitesh, Hermet, raster Differential Revision: https://phab.enlightenment.org/D1178
-rw-r--r--src/bin/test.c4
-rw-r--r--src/bin/test_gengrid.c198
-rw-r--r--src/lib/elm_gengrid.c25
-rw-r--r--src/lib/elm_gengrid.eo10
4 files changed, 236 insertions, 1 deletions
diff --git a/src/bin/test.c b/src/bin/test.c
index ae3976c19..11045a19f 100644
--- a/src/bin/test.c
+++ b/src/bin/test.c
@@ -130,8 +130,9 @@ void test_table7(void *data, Evas_Object *obj, void *event_info);
130void test_gengrid(void *data, Evas_Object *obj, void *event_info); 130void test_gengrid(void *data, Evas_Object *obj, void *event_info);
131void test_gengrid2(void *data, Evas_Object *obj, void *event_info); 131void test_gengrid2(void *data, Evas_Object *obj, void *event_info);
132void test_gengrid3(void *data, Evas_Object *obj, void *event_info); 132void test_gengrid3(void *data, Evas_Object *obj, void *event_info);
133void test_gengrid_item_styles(void *data, Evas_Object *obj, void *event_info);
134void test_gengrid4(void *data, Evas_Object *obj, void *event_info); 133void test_gengrid4(void *data, Evas_Object *obj, void *event_info);
134void test_gengrid5(void *data, Evas_Object *obj, void *event_info);
135void test_gengrid_item_styles(void *data, Evas_Object *obj, void *event_info);
135void test_gengrid_speed(void *data, Evas_Object *obj, void *event_info); 136void test_gengrid_speed(void *data, Evas_Object *obj, void *event_info);
136void test_gengrid_focus(void *data, Evas_Object *obj, void *event_info); 137void test_gengrid_focus(void *data, Evas_Object *obj, void *event_info);
137void test_win_state(void *data, Evas_Object *obj, void *event_info); 138void test_win_state(void *data, Evas_Object *obj, void *event_info);
@@ -666,6 +667,7 @@ add_tests:
666 ADD_TEST(NULL, "Lists - Gengrid", "GenGrid 2", test_gengrid2); 667 ADD_TEST(NULL, "Lists - Gengrid", "GenGrid 2", test_gengrid2);
667 ADD_TEST(NULL, "Lists - Gengrid", "GenGrid Group", test_gengrid3); 668 ADD_TEST(NULL, "Lists - Gengrid", "GenGrid Group", test_gengrid3);
668 ADD_TEST(NULL, "Lists - Gengrid", "GenGrid Show/Bring_in", test_gengrid4); 669 ADD_TEST(NULL, "Lists - Gengrid", "GenGrid Show/Bring_in", test_gengrid4);
670 ADD_TEST(NULL, "Lists - Gengrid", "GenGrid Item Search by Text", test_gengrid5);
669 ADD_TEST(NULL, "Lists - Gengrid", "GenGrid Item Styles", test_gengrid_item_styles); 671 ADD_TEST(NULL, "Lists - Gengrid", "GenGrid Item Styles", test_gengrid_item_styles);
670 ADD_TEST(NULL, "Lists - Gengrid", "Gengrid Update Speed", test_gengrid_speed); 672 ADD_TEST(NULL, "Lists - Gengrid", "Gengrid Update Speed", test_gengrid_speed);
671 ADD_TEST(NULL, "Lists - Gengrid", "GenGrid Focus", test_gengrid_focus); 673 ADD_TEST(NULL, "Lists - Gengrid", "GenGrid Focus", test_gengrid_focus);
diff --git a/src/bin/test_gengrid.c b/src/bin/test_gengrid.c
index 71b3ba65b..a2ca6a08b 100644
--- a/src/bin/test_gengrid.c
+++ b/src/bin/test_gengrid.c
@@ -1344,6 +1344,204 @@ test_gengrid4(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_
1344 evas_object_show(win); 1344 evas_object_show(win);
1345} 1345}
1346 1346
1347typedef struct _grid5_Event_Data grid5_Event_Data;
1348struct _grid5_Event_Data
1349{
1350 Evas_Object *grid_obj;
1351 Evas_Object *en_obj;
1352 Elm_Object_Item *last_item_found;
1353};
1354
1355static const char *_grid5_items_text[] = {
1356 "Albany", "Annapolis",
1357 "Atlanta", "Augusta",
1358 "Austin", "Baton Rouge",
1359 "Bismarck", "Boise",
1360 "Boston", "Carson City",
1361 "Charleston", "Cheyenne",
1362 "Columbia", "Columbus",
1363 "Concord", "Denver",
1364 "Des Moines", "Dover",
1365 "Frankfort", "Harrisburg",
1366 "Hartford", "Helena",
1367 "Honolulu", "Indianapolis",
1368 "Jackson", "Jefferson City",
1369 "Juneau", "Lansing",
1370 "Lincoln", "Little Rock",
1371 "Madison", "Montgomery",
1372 "Montpelier", "Nashville",
1373 "Oklahoma City", "Olympia",
1374 "Phoenix", "Pierre",
1375 "Providence", "Raleigh",
1376 "Richmond", "Sacramento",
1377 "Saint Paul", "Salem",
1378 "Salt Lake City", "Santa Fe",
1379 "Springfield", "Tallahassee",
1380 "Topeka", "Trenton"
1381};
1382
1383static char *
1384_grid5_search_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
1385{
1386 char buf[32];
1387 Item_Data *id = data;
1388
1389 snprintf(buf, sizeof(buf), "%s", _grid5_items_text[id->mode]);
1390 return strdup(buf);
1391}
1392
1393static char *
1394_grid5_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
1395{
1396 char buf[64];
1397 snprintf(buf, sizeof(buf), "%s", _grid5_search_text_get(data, NULL, NULL));
1398 return strdup(buf);
1399}
1400
1401static void
1402_grid5_search_item(grid5_Event_Data *event_data, Elm_Object_Item * it)
1403{
1404 const char *str = elm_entry_entry_get(event_data->en_obj);
1405 if (!str || !strlen(str)) return;
1406
1407 printf("Looking for \"%s\". ", str);
1408 event_data->last_item_found = elm_gengrid_search_by_text_item_get(event_data->grid_obj, it, _grid5_search_text_get, NULL, str, 0);
1409
1410 if (event_data->last_item_found)
1411 {
1412 printf("Found.\n");
1413 elm_gengrid_item_selected_set(event_data->last_item_found, EINA_TRUE);
1414 elm_gengrid_item_bring_in(event_data->last_item_found, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
1415 elm_object_focus_set(event_data->en_obj, EINA_TRUE);
1416 }
1417 else
1418 printf("Not Found.\n");
1419}
1420
1421static void
1422_grid5_search_settings_changed_cb(void *data, Evas_Object *obj EINA_UNUSED, void *einfo EINA_UNUSED)
1423{
1424 _grid5_search_item(data, NULL);
1425}
1426
1427static void
1428_grid5_on_keydown(void *data, Evas *evas EINA_UNUSED, Evas_Object *o EINA_UNUSED, void *event_info)
1429{
1430 Evas_Event_Key_Down *ev = event_info;
1431 grid5_Event_Data * event_data = (grid5_Event_Data *)data;
1432
1433 if (!strcmp(ev->key, "Return"))
1434 {
1435 printf("Looking for next item\n");
1436 _grid5_search_item(data, event_data->last_item_found);
1437 }
1438}
1439
1440static Elm_Gengrid_Item_Class *
1441_grid5_item_class_create(const char *item_style)
1442{
1443 Elm_Gengrid_Item_Class * itc = elm_gengrid_item_class_new();
1444 itc->item_style = item_style;
1445 itc->func.text_get = _grid5_text_get;
1446 itc->func.content_get = grid_content_get;
1447 itc->func.state_get = grid_state_get;
1448 itc->func.del = NULL;
1449 return itc;
1450}
1451
1452void
1453test_gengrid5(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
1454{
1455 Evas_Object *win, *bx, *grid;
1456 Evas_Object *fr, *lb_frame;
1457 Evas_Object *en, *bx_entry, *lb_entry;
1458 grid5_Event_Data *event_data;
1459 Elm_Gengrid_Item_Class *itc = NULL;
1460 static Item_Data id[50];
1461 char buf[PATH_MAX];
1462 int i, n;
1463
1464 win = elm_win_util_standard_add("gengrid-item-search-by-text", "Gengrid Item Search By Text");
1465 elm_win_autodel_set(win, EINA_TRUE);
1466
1467 bx = elm_box_add(win);
1468 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1469 elm_win_resize_object_add(win, bx);
1470 evas_object_show(bx);
1471
1472 fr = elm_frame_add(bx);
1473 evas_object_size_hint_weight_set(fr, EVAS_HINT_EXPAND, 0.0);
1474 evas_object_size_hint_align_set(fr, EVAS_HINT_FILL, 0.0);
1475 elm_object_text_set(fr, "Information");
1476 elm_box_pack_end(bx, fr);
1477 evas_object_show(fr);
1478
1479 lb_frame = elm_label_add(fr);
1480 elm_object_text_set(lb_frame,
1481 "<align=left>This is an example of elm_gengrid_search_by_text_item_get() usage.<br>"
1482 "Enter search string to the entry and press Enter to show next search result.<br>");
1483 elm_object_content_set(fr, lb_frame);
1484 evas_object_show(lb_frame);
1485
1486 bx_entry = elm_box_add(win);
1487 elm_box_horizontal_set(bx_entry, EINA_TRUE);
1488 evas_object_size_hint_weight_set(bx_entry, EVAS_HINT_EXPAND, 0.0);
1489 evas_object_size_hint_align_set(bx_entry, EVAS_HINT_FILL, 0.0);
1490 elm_box_pack_end(bx, bx_entry);
1491 evas_object_show(bx_entry);
1492
1493 lb_entry = elm_label_add(win);
1494 elm_object_text_set(lb_entry, " Search:");
1495 evas_object_size_hint_weight_set(lb_entry, 0.0, EVAS_HINT_EXPAND);
1496 evas_object_size_hint_align_set(lb_entry, 0.0, EVAS_HINT_FILL);
1497 elm_box_pack_end(bx_entry, lb_entry);
1498 evas_object_show(lb_entry);
1499
1500 en = elm_entry_add(win);
1501 elm_entry_single_line_set(en, EINA_TRUE);
1502 elm_entry_scrollable_set(en, EINA_TRUE);
1503 elm_object_part_text_set(en, "guide", "Type item's name here to search.");
1504 evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1505 evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
1506 elm_box_pack_end(bx_entry, en);
1507 evas_object_show(en);
1508 elm_object_focus_set(en, EINA_TRUE);
1509
1510 grid = elm_gengrid_add(bx);
1511 elm_gengrid_item_size_set(grid, elm_config_scale_get() * 200, elm_config_scale_get() * 150);
1512 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1513 evas_object_size_hint_align_set(grid, EVAS_HINT_FILL, EVAS_HINT_FILL);
1514 elm_gengrid_select_mode_set(grid, ELM_OBJECT_SELECT_MODE_ALWAYS);
1515 elm_box_pack_end(bx, grid);
1516 evas_object_show(grid);
1517
1518 event_data = calloc(1, sizeof(grid5_Event_Data));
1519 event_data->en_obj = en;
1520 event_data->grid_obj = grid;
1521 event_data->last_item_found = NULL;
1522
1523 evas_object_event_callback_add(en, EVAS_CALLBACK_KEY_DOWN, _grid5_on_keydown, (void*)event_data);
1524 evas_object_smart_callback_add(en, "changed,user", _grid5_search_settings_changed_cb, (void*)event_data);
1525 evas_object_event_callback_add(grid, EVAS_CALLBACK_FREE, _cleanup_cb, (void*)event_data);
1526
1527 itc = _grid5_item_class_create("default");
1528
1529 for (i = 0, n = 0; i < 50; i++)
1530 {
1531 snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), img[n]);
1532 n = (n + 1) % 9;
1533 id[i].mode = i;
1534 id[i].path = eina_stringshare_add(buf);
1535 id[i].item = elm_gengrid_item_append(grid, itc, &(id[i]), grid_sel, NULL);
1536 if (!(i % 5))
1537 elm_gengrid_item_selected_set(id[i].item, EINA_TRUE);
1538 }
1539 elm_gengrid_item_class_free(itc);
1540
1541 evas_object_resize(win, 320, 500);
1542 evas_object_show(win);
1543}
1544
1347void 1545void
1348test_gengrid_speed(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) 1546test_gengrid_speed(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
1349{ 1547{
diff --git a/src/lib/elm_gengrid.c b/src/lib/elm_gengrid.c
index 607d400fd..9d06c64e6 100644
--- a/src/lib/elm_gengrid.c
+++ b/src/lib/elm_gengrid.c
@@ -102,6 +102,31 @@ static const Elm_Action key_actions[] = {
102 {NULL, NULL} 102 {NULL, NULL}
103}; 103};
104 104
105EOLIAN static Elm_Object_Item *
106_elm_gengrid_search_by_text_item_get(Eo *obj EINA_UNUSED,
107 Elm_Gengrid_Data *sd,
108 Elm_Object_Item * item_to_search_from,
109 Elm_Gen_Item_Text_Get_Cb _text_get,
110 const char * part_name,
111 const char * pattern,
112 int flags)
113{
114 Elm_Gen_Item *it = NULL;
115 const char * str = NULL;
116 Eina_Inlist * start = NULL;
117
118 if (!_text_get || !pattern) return NULL;
119 if (!sd->items) return NULL;
120
121 start = (item_to_search_from) ? EINA_INLIST_GET((Elm_Gen_Item *)item_to_search_from) : sd->items;
122 EINA_INLIST_FOREACH(start, it)
123 {
124 str = _text_get((void *)it->base.data, VIEW(it), part_name);
125 if (!fnmatch(pattern, str, flags)) return (Elm_Object_Item *)it;
126 }
127 return NULL;
128}
129
105static void 130static void
106_item_show_region(void *data) 131_item_show_region(void *data)
107{ 132{
diff --git a/src/lib/elm_gengrid.eo b/src/lib/elm_gengrid.eo
index a7c5f7037..6b125f97a 100644
--- a/src/lib/elm_gengrid.eo
+++ b/src/lib/elm_gengrid.eo
@@ -656,6 +656,16 @@ class Elm_Gengrid (Elm_Layout, Elm_Interface_Scrollable, Evas.Clickable_Interfac
656 @in const(void)* func_data; /*@ Data to be passed to @p func. */ 656 @in const(void)* func_data; /*@ Data to be passed to @p func. */
657 } 657 }
658 } 658 }
659 search_by_text_item_get {
660 return Elm_Object_Item *;
661 params {
662 @in Elm_Object_Item * item_to_search_from; /*@ Pointer to item to start search from. If NULL search will be started from the first item of the genlist. */
663 @in Elm_Gen_Item_Text_Get_Cb _text_get; /*@ Pointer to Elm_Gen_Item_Text_Get_Cb function to get text for comparison. */
664 @in const(char)* part_name; /*@ Name of the TEXT part of genlist item to search string in. */
665 @in const(char)* pattern; /*@ The search pattern. */
666 @in int flags; /*@ fnmatch search flags */
667 }
668 }
659 } 669 }
660 implements { 670 implements {
661 class.constructor; 671 class.constructor;