2011-07-20 09:28:12 -07:00
|
|
|
/**
|
|
|
|
* Simple Elementary's <b>index widget</b> example, illustrating its
|
|
|
|
* usage and API.
|
|
|
|
*
|
|
|
|
* See stdout/stderr for output. Compile with:
|
|
|
|
*
|
|
|
|
* @verbatim
|
2013-01-10 03:49:55 -08:00
|
|
|
* gcc -g index_example_01.c -o index_example_01 `pkg-config --cflags --libs elementary`
|
2011-07-20 09:28:12 -07:00
|
|
|
* @endverbatim
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Elementary.h>
|
2012-05-30 10:41:48 -07:00
|
|
|
#include <assert.h>
|
2011-07-20 09:28:12 -07:00
|
|
|
|
|
|
|
static const char *dict[] = \
|
|
|
|
{
|
|
|
|
#include "dict.txt"
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2013-11-19 17:40:02 -08:00
|
|
|
_index_item_del(void *data, Evas_Object *obj, void *event_info)
|
2011-07-20 09:28:12 -07:00
|
|
|
{
|
2012-05-30 10:41:48 -07:00
|
|
|
fprintf(stdout, "Deleting index node (%s). Comparing index "
|
2013-04-04 00:45:09 -07:00
|
|
|
"item data reported via callback with the one returned by "
|
|
|
|
"index's API on items: %s.\n",
|
2012-05-30 10:41:48 -07:00
|
|
|
elm_index_item_letter_get(event_info),
|
2012-03-09 23:56:54 -08:00
|
|
|
data == elm_object_item_data_get(event_info) ? "OK" :
|
2011-07-20 09:28:12 -07:00
|
|
|
"FAIL, something went wrong");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* delete an index item */
|
|
|
|
static void
|
2013-11-19 17:40:02 -08:00
|
|
|
_item_del(void *data, Evas_Object *obj, void *event_info)
|
2011-07-20 09:28:12 -07:00
|
|
|
{
|
2013-11-19 17:40:02 -08:00
|
|
|
Elm_Object_Item *it = elm_index_selected_item_get(data, 0);
|
2011-07-20 09:28:12 -07:00
|
|
|
|
2013-11-19 17:40:02 -08:00
|
|
|
if (!it) return;
|
2011-07-20 09:28:12 -07:00
|
|
|
|
|
|
|
fprintf(stdout, "Deleting last selected index item, which had letter"
|
2013-11-19 17:40:02 -08:00
|
|
|
" %s (pointing to %p)\n", elm_index_item_letter_get(it),
|
|
|
|
elm_object_item_data_get(it));
|
2011-07-20 09:28:12 -07:00
|
|
|
|
2013-11-19 17:40:02 -08:00
|
|
|
elm_object_item_del(it);
|
|
|
|
elm_index_level_go(data, 0);
|
2011-07-20 09:28:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-19 17:40:02 -08:00
|
|
|
_item_del_all(void *data, Evas_Object *obj, void *event_info)
|
2011-07-20 09:28:12 -07:00
|
|
|
{
|
2013-11-19 17:40:02 -08:00
|
|
|
elm_index_item_clear(data);
|
|
|
|
elm_index_level_go(data, 0);
|
2011-07-20 09:28:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-19 17:40:02 -08:00
|
|
|
_active_set(void *data, Evas_Object *obj, void *event_info)
|
2011-07-20 09:28:12 -07:00
|
|
|
{
|
2013-11-19 17:40:02 -08:00
|
|
|
Eina_Bool disabled = elm_index_autohide_disabled_get(data);
|
|
|
|
elm_index_autohide_disabled_set(data, !disabled);
|
2011-07-20 09:28:12 -07:00
|
|
|
|
2013-11-19 17:40:02 -08:00
|
|
|
fprintf(stdout, "Toggling index programmatically to %s.\n",
|
|
|
|
!disabled ? "On" : "Off");
|
2011-07-20 09:28:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* "delay,changed" hook */
|
|
|
|
static void
|
2013-11-19 17:40:02 -08:00
|
|
|
_index_changed(void *data, Evas_Object *obj, void *event_info)
|
2011-07-20 09:28:12 -07:00
|
|
|
{
|
2012-05-30 10:41:48 -07:00
|
|
|
elm_list_item_bring_in(elm_object_item_data_get(event_info));
|
2011-07-20 09:28:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-19 17:40:02 -08:00
|
|
|
_index_selected(void *data, Evas_Object *obj, void *event_info)
|
2011-07-20 09:28:12 -07:00
|
|
|
{
|
2012-01-11 19:03:56 -08:00
|
|
|
Elm_Object_Item *lit = event_info;
|
2011-07-20 09:28:12 -07:00
|
|
|
|
|
|
|
fprintf(stdout, "New index item selected. Comparing item reported"
|
2013-04-04 00:45:09 -07:00
|
|
|
" via callback with the selection returned by the API: "
|
|
|
|
"%s.\n", lit == elm_index_selected_item_get(obj, 0) ? "OK" :
|
2011-07-20 09:28:12 -07:00
|
|
|
"FAIL, something went wrong");
|
|
|
|
}
|
|
|
|
|
2012-03-27 23:04:36 -07:00
|
|
|
EAPI_MAIN int
|
2013-11-19 17:40:02 -08:00
|
|
|
elm_main(int argc, char **argv)
|
2011-07-20 09:28:12 -07:00
|
|
|
{
|
2013-11-19 17:40:02 -08:00
|
|
|
Evas_Object *win, *hbox, *vbox, *bt, *sep, *list, *id;
|
2012-01-11 19:03:56 -08:00
|
|
|
Elm_Object_Item *lit;
|
2011-07-20 09:28:12 -07:00
|
|
|
unsigned int i;
|
|
|
|
char curr = 0;
|
|
|
|
|
2013-06-25 18:54:58 -07:00
|
|
|
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
|
|
|
|
|
2013-06-25 23:34:38 -07:00
|
|
|
win = elm_win_util_standard_add("index", "Index Example");
|
2013-06-25 18:54:58 -07:00
|
|
|
elm_win_autodel_set(win, EINA_TRUE);
|
2013-11-19 17:40:02 -08:00
|
|
|
evas_object_resize(win, 320, 600);
|
|
|
|
evas_object_show(win);
|
2011-07-20 09:28:12 -07:00
|
|
|
|
|
|
|
vbox = elm_box_add(win);
|
|
|
|
evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
2013-06-26 16:26:42 -07:00
|
|
|
elm_win_resize_object_add(win, vbox);
|
2011-07-20 09:28:12 -07:00
|
|
|
evas_object_show(vbox);
|
|
|
|
|
2013-11-19 17:40:02 -08:00
|
|
|
list = elm_list_add(win);
|
|
|
|
evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
evas_object_show(list);
|
|
|
|
elm_box_pack_end(vbox, list);
|
2011-07-20 09:28:12 -07:00
|
|
|
|
2013-11-19 17:40:02 -08:00
|
|
|
id = elm_index_add(win);
|
|
|
|
evas_object_size_hint_weight_set(id, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
elm_win_resize_object_add(win, id);
|
|
|
|
evas_object_show(id);
|
2011-07-20 09:28:12 -07:00
|
|
|
|
|
|
|
for (i = 0; i < (sizeof(dict) / sizeof(dict[0])); i++)
|
|
|
|
{
|
2013-11-19 17:40:02 -08:00
|
|
|
lit = elm_list_item_append(list, dict[i], NULL, NULL, NULL, NULL);
|
2011-07-20 09:28:12 -07:00
|
|
|
|
|
|
|
if (curr != dict[i][0])
|
|
|
|
{
|
2012-05-30 10:41:48 -07:00
|
|
|
Elm_Object_Item *index_it, *it;
|
2011-07-20 09:28:12 -07:00
|
|
|
char buf[32];
|
|
|
|
|
|
|
|
curr = dict[i][0];
|
|
|
|
/* indexing by first letters */
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%c", curr);
|
2013-11-19 17:40:02 -08:00
|
|
|
index_it = elm_index_item_append(id, buf, NULL, lit);
|
2012-05-30 10:41:48 -07:00
|
|
|
|
|
|
|
/* this is here just to demostrate the API call */
|
2013-11-19 17:40:02 -08:00
|
|
|
it = elm_index_item_find(id, lit);
|
2012-05-30 10:41:48 -07:00
|
|
|
assert(it == index_it);
|
2011-07-20 09:28:12 -07:00
|
|
|
|
2012-01-02 03:46:32 -08:00
|
|
|
elm_object_item_del_cb_set(index_it, _index_item_del);
|
2011-07-20 09:28:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-19 17:40:02 -08:00
|
|
|
evas_object_smart_callback_add(id, "delay,changed", _index_changed,
|
2011-07-20 09:28:12 -07:00
|
|
|
NULL);
|
2013-11-19 17:40:02 -08:00
|
|
|
evas_object_smart_callback_add(id, "selected", _index_selected, NULL);
|
|
|
|
elm_index_level_go(id, 0);
|
2011-07-20 09:28:12 -07:00
|
|
|
|
|
|
|
/* attribute setting knobs */
|
|
|
|
sep = elm_separator_add(win);
|
|
|
|
elm_separator_horizontal_set(sep, EINA_TRUE);
|
|
|
|
elm_box_pack_end(vbox, sep);
|
|
|
|
evas_object_show(sep);
|
|
|
|
|
|
|
|
hbox = elm_box_add(win);
|
|
|
|
elm_box_horizontal_set(hbox, EINA_TRUE);
|
|
|
|
evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, 0);
|
|
|
|
evas_object_size_hint_fill_set(hbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
elm_box_pack_end(vbox, hbox);
|
|
|
|
evas_object_show(hbox);
|
|
|
|
|
|
|
|
bt = elm_button_add(win);
|
|
|
|
elm_object_text_set(bt, "bring in index");
|
2013-11-19 17:40:02 -08:00
|
|
|
evas_object_smart_callback_add(bt, "clicked", _active_set, id);
|
2011-07-20 09:28:12 -07:00
|
|
|
elm_box_pack_end(hbox, bt);
|
|
|
|
evas_object_show(bt);
|
|
|
|
|
|
|
|
bt = elm_button_add(win);
|
|
|
|
elm_object_text_set(bt, "delete last selected item");
|
2013-11-19 17:40:02 -08:00
|
|
|
evas_object_smart_callback_add(bt, "clicked", _item_del, id);
|
2011-07-20 09:28:12 -07:00
|
|
|
elm_box_pack_end(hbox, bt);
|
|
|
|
evas_object_show(bt);
|
|
|
|
|
|
|
|
bt = elm_button_add(win);
|
|
|
|
elm_object_text_set(bt, "delete all items");
|
2013-11-19 17:40:02 -08:00
|
|
|
evas_object_smart_callback_add(bt, "clicked", _item_del_all, id);
|
2011-07-20 09:28:12 -07:00
|
|
|
elm_box_pack_end(hbox, bt);
|
|
|
|
evas_object_show(bt);
|
|
|
|
|
|
|
|
elm_run();
|
2012-03-27 23:04:36 -07:00
|
|
|
elm_shutdown();
|
|
|
|
|
2011-07-20 09:28:12 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2012-05-30 10:41:48 -07:00
|
|
|
|
2011-07-20 09:28:12 -07:00
|
|
|
ELM_MAIN()
|