diff --git a/legacy/elementary/data/themes/default.edc b/legacy/elementary/data/themes/default.edc index 5d739d925e..f1037032e1 100644 --- a/legacy/elementary/data/themes/default.edc +++ b/legacy/elementary/data/themes/default.edc @@ -5068,6 +5068,18 @@ collections { inherit: "default" 0.0; visible: 0; } + description { state: "disabled" 0.0; + inherit: "default" 0.0; + color: 0 0 0 128; + color3: 0 0 0 0; + } + description { state: "disabled_visible" 0.0; + inherit: "default" 0.0; + color: 0 0 0 128; + color3: 0 0 0 0; + visible: 1; + text.min: 1 1; + } } part { name: "bg"; mouse_events: 0; @@ -5086,6 +5098,11 @@ collections { visible: 1; color: 255 255 255 255; } + description { state: "disabled" 0.0; + inherit: "default" 0.0; + visible: 0; + color: 255 255 255 0; + } } part { name: "elm.swallow.icon"; type: SWALLOW; @@ -5135,6 +5152,23 @@ collections { inherit: "default" 0.0; visible: 1; } + description { state: "visible" 0.0; + inherit: "default" 0.0; + visible: 1; + text.min: 1 1; + } + description { state: "disabled" 0.0; + inherit: "default" 0.0; + color: 0 0 0 128; + color3: 0 0 0 0; + } + description { state: "disabled_visible" 0.0; + inherit: "default" 0.0; + color: 0 0 0 128; + color3: 0 0 0 0; + visible: 1; + text.min: 1 1; + } } part { name: "event"; type: RECT; @@ -5169,6 +5203,44 @@ collections { source: "event"; action: SIGNAL_EMIT "elm,action,click" "elm"; } + program { name: "disable"; + signal: "elm,state,disabled"; + source: "elm"; + action: STATE_SET "disabled" 0.0; + target: "label2"; + target: "bg"; + after: "disable_text"; + } + program { name: "disable_text"; + script { + new st[31]; + new Float:vl; + get_state(PART:"elm.text", st, 30, vl); + if (!strcmp(st, "visible")) + set_state(PART:"elm.text", "disabled_visible", 0.0); + else + set_state(PART:"elm.text", "disabled", 0.0); + } + } + program { name: "enable"; + signal: "elm,state,enabled"; + source: "elm"; + action: STATE_SET "default" 0.0; + target: "label2"; + target: "bg"; + after: "enable_text"; + } + program { name: "enable_text"; + script { + new st[31]; + new Float:vl; + get_state(PART:"elm.text", st, 30, vl); + if (!strcmp(st, "disabled_visible")) + set_state(PART:"elm.text", "visible", 0.0); + else + set_state(PART:"elm.text", "default", 0.0); + } + } } } diff --git a/legacy/elementary/src/bin/test_toolbar.c b/legacy/elementary/src/bin/test_toolbar.c index b24158c364..b73f498d70 100644 --- a/legacy/elementary/src/bin/test_toolbar.c +++ b/legacy/elementary/src/bin/test_toolbar.c @@ -43,6 +43,7 @@ test_toolbar(void *data, Evas_Object *obj, void *event_info) { Evas_Object *win, *bg, *bx, *tb, *ic, *ph; Evas_Object *ph1, *ph2, *ph3, *ph4; + Elm_Toolbar_Item *item; char buf[PATH_MAX]; win = elm_win_add(NULL, "toolbar", ELM_WIN_BASIC); @@ -71,7 +72,8 @@ test_toolbar(void *data, Evas_Object *obj, void *event_info) ic = elm_icon_add(win); snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR); elm_icon_file_set(ic, buf, NULL); - elm_toolbar_item_add(tb, ic, "Hello", tb_1, ph1); + item = elm_toolbar_item_add(tb, ic, "Hello", tb_1, ph1); + elm_toolbar_item_disabled_set(item, EINA_TRUE); ic = elm_icon_add(win); snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR); diff --git a/legacy/elementary/src/lib/Elementary.h.in b/legacy/elementary/src/lib/Elementary.h.in index aa1d122bcf..fb14715085 100644 --- a/legacy/elementary/src/lib/Elementary.h.in +++ b/legacy/elementary/src/lib/Elementary.h.in @@ -550,6 +550,8 @@ extern "C" { EAPI const char *elm_toolbar_item_label_get(Elm_Toolbar_Item *item); EAPI void elm_toolbar_item_del(Elm_Toolbar_Item *item); EAPI void elm_toolbar_item_select(Elm_Toolbar_Item *item); + EAPI Eina_Bool elm_toolbar_item_disabled_get(Elm_Toolbar_Item *item); + EAPI void elm_toolbar_item_disabled_set(Elm_Toolbar_Item *item, Eina_Bool disabled); EAPI void elm_toolbar_scrollable_set(Evas_Object *obj, Eina_Bool scrollable); /* smart callbacks called: * "clicked" - when the user clicks on a toolbar item and becomes selected diff --git a/legacy/elementary/src/lib/elm_toolbar.c b/legacy/elementary/src/lib/elm_toolbar.c index 3f90e84b77..eb5c612f7b 100644 --- a/legacy/elementary/src/lib/elm_toolbar.c +++ b/legacy/elementary/src/lib/elm_toolbar.c @@ -20,8 +20,12 @@ struct _Elm_Toolbar_Item void (*func) (void *data, Evas_Object *obj, void *event_info); const void *data; Eina_Bool selected : 1; + Eina_Bool disabled : 1; }; +static void _item_show(Elm_Toolbar_Item *it); +static void _item_select(Elm_Toolbar_Item *it); +static void _item_disable(Elm_Toolbar_Item *it, Eina_Bool disabled); static void _del_hook(Evas_Object *obj); static void _theme_hook(Evas_Object *obj); static void _sizing_eval(Evas_Object *obj); @@ -44,7 +48,8 @@ _item_select(Elm_Toolbar_Item *it) Widget_Data *wd = elm_widget_data_get(it->obj); Evas_Object *obj2; const Eina_List *l; - if (it->selected) return; + + if ((it->selected) || (it->disabled)) return; EINA_LIST_FOREACH(wd->items, l, it2) { if (it2->selected) @@ -62,11 +67,26 @@ _item_select(Elm_Toolbar_Item *it) evas_object_smart_callback_call(obj2, "clicked", it); } +static void +_item_disable(Elm_Toolbar_Item *it, Eina_Bool disabled) +{ + Widget_Data *wd = elm_widget_data_get(it->obj); + + if (it->disabled == disabled) return; + it->disabled = disabled; + if (it->disabled) + edje_object_signal_emit(it->base, "elm,state,disabled", "elm"); + else + edje_object_signal_emit(it->base, "elm,state,enabled", "elm"); +// _item_show(it); +} + static void _del_hook(Evas_Object *obj) { Widget_Data *wd = elm_widget_data_get(obj); Elm_Toolbar_Item *it; + EINA_LIST_FREE(wd->items, it) { eina_stringshare_del(it->label); @@ -90,8 +110,10 @@ _theme_hook(Evas_Object *obj) EINA_LIST_FOREACH(wd->items, l, it) { edje_object_scale_set(it->base, elm_widget_scale_get(obj) * _elm_config->scale); - if (it->selected) + if (it->selected) edje_object_signal_emit(it->base, "elm,state,selected", "elm"); + if (it->disabled) + edje_object_signal_emit(it->base, "elm,state,disabled", "elm"); _elm_theme_set(it->base, "toolbar", "item", style); if (it->icon) { @@ -217,6 +239,7 @@ elm_toolbar_item_add(Evas_Object *obj, Evas_Object *icon, const char *label, voi Widget_Data *wd = elm_widget_data_get(obj); Evas_Coord mw, mh; Elm_Toolbar_Item *it = calloc(1, sizeof(Elm_Toolbar_Item)); + if (!it) return NULL; wd->items = eina_list_append(wd->items, it); it->obj = obj; @@ -272,6 +295,7 @@ elm_toolbar_item_del(Elm_Toolbar_Item *it) { Widget_Data *wd = elm_widget_data_get(it->obj); Evas_Object *obj2 = it->obj; + wd->items = eina_list_remove(wd->items, it); eina_stringshare_del(it->label); if (it->icon) evas_object_del(it->icon); @@ -286,10 +310,24 @@ elm_toolbar_item_select(Elm_Toolbar_Item *item) _item_select(item); } +EAPI Eina_Bool +elm_toolbar_item_disabled_get(Elm_Toolbar_Item *item) +{ + if (!item) return EINA_FALSE; + return item->disabled; +} + +EAPI void +elm_toolbar_item_disabled_set(Elm_Toolbar_Item *item, Eina_Bool disabled) +{ + _item_disable(item, disabled); +} + EAPI void elm_toolbar_scrollable_set(Evas_Object *obj, Eina_Bool scrollable) { Widget_Data *wd = elm_widget_data_get(obj); + wd->scrollable = scrollable; _sizing_eval(obj); }