From 30729fd4fb74fc1ae0a0311a29bcec2ae19e51d9 Mon Sep 17 00:00:00 2001 From: discomfitor Date: Thu, 29 Sep 2011 23:46:55 +0000 Subject: [PATCH] new toolbar mode: always_select when this mode is enabled, a toolbar item will always be selected. if the selected item is deleted, the next item will be selected. if there is no next item, the first item will be selected. if there is no next or first item, you can go yourself. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/elementary@63691 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/Elementary.h.in | 32 ++++++++++++++++++++++++++++++++ src/lib/elm_toolbar.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/lib/Elementary.h.in b/src/lib/Elementary.h.in index 984e4a1..ecf32c2 100644 --- a/src/lib/Elementary.h.in +++ b/src/lib/Elementary.h.in @@ -14053,6 +14053,38 @@ extern "C" { EAPI Elm_Icon_Lookup_Order elm_toolbar_icon_order_lookup_get(const Evas_Object *obj) EINA_ARG_NONNULL(1); /** + * Set whether the toolbar should always have an item selected. + * + * @param obj The toolbar object. + * @param wrap @c EINA_TRUE to enable always-select mode or @c EINA_FALSE to + * disable it. + * + * This will cause the toolbar to always have an item selected, and clicking + * the selected item will not cause a selected event to be emitted. Enabling this mode + * will immediately select the first toolbar item. + * + * Always-selected is disabled by default. + * + * @see elm_toolbar_always_select_mode_get(). + * + * @ingroup Toolbar + */ + EAPI void elm_toolbar_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select) EINA_ARG_NONNULL(1); + + /** + * Get whether the toolbar should always have an item selected. + * + * @param obj The toolbar object. + * @return @c EINA_TRUE means an item will always be selected, @c EINA_FALSE indicates + * that it is possible to have no items selected. If @p obj is @c NULL, @c EINA_FALSE is returned. + * + * @see elm_toolbar_always_select_mode_set() for details. + * + * @ingroup Toolbar + */ + EAPI Eina_Bool elm_toolbar_always_select_mode_get(const Evas_Object *obj) EINA_ARG_NONNULL(1); + + /** * Set whether the toolbar items' should be selected by the user or not. * * @param obj The toolbar object. diff --git a/src/lib/elm_toolbar.c b/src/lib/elm_toolbar.c index 20f63c3..4030a9c 100644 --- a/src/lib/elm_toolbar.c +++ b/src/lib/elm_toolbar.c @@ -15,6 +15,7 @@ struct _Widget_Data double align; Eina_Bool homogeneous : 1; Eina_Bool no_select : 1; + Eina_Bool always_select : 1; Eina_Bool vertical : 1; Ecore_Job *resize_job; }; @@ -144,7 +145,11 @@ _item_select(Elm_Toolbar_Item *it) if (!wd->no_select) { - if (sel) _item_unselect(it); + if (sel) + { + if (wd->always_select) return; + _item_unselect(it); + } else { it2 = elm_toolbar_selected_item_get(it->base.widget); @@ -746,6 +751,7 @@ _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb f evas_object_size_hint_min_set(it->base.view, mw, mh); evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_RESIZE, _resize_item, obj); + if ((!wd->items) && wd->always_select) _item_select(it); return it; } @@ -1449,12 +1455,16 @@ elm_toolbar_item_del(Elm_Toolbar_Item *item) { Widget_Data *wd; Evas_Object *obj2; + Elm_Toolbar_Item *next; ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item); wd = elm_widget_data_get(item->base.widget); if (!wd) return; obj2 = item->base.widget; + next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next); wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item)); + if (!next) next = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items); + if (wd->always_select && item->selected && next) _item_select(next); _item_del(item); _theme_hook(obj2); } @@ -1770,6 +1780,26 @@ elm_toolbar_item_data_get(const Elm_Toolbar_Item *item) } EAPI void +elm_toolbar_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select) +{ + ELM_CHECK_WIDTYPE(obj, widtype); + Widget_Data *wd = elm_widget_data_get(obj); + if (!wd) return; + if (always_select && (!wd->always_select) && wd->items) + _item_select(ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items)); + wd->always_select = always_select; +} + +EAPI Eina_Bool +elm_toolbar_always_select_mode_get(const Evas_Object *obj) +{ + ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE; + Widget_Data *wd = elm_widget_data_get(obj); + if (!wd) return EINA_FALSE; + return wd->always_select; +} + +EAPI void elm_toolbar_no_select_mode_set(Evas_Object *obj, Eina_Bool no_select) { ELM_CHECK_WIDTYPE(obj, widtype); -- 2.7.4