EAPI void
+elm_check_states_labels_set(Evas_Object *obj, const char *ontext,
const char *offtext)
+{
+ _elm_check_label_set(obj, "on", ontext);
+ _elm_check_label_set(obj, "off", offtext);
+}
+
+EAPI void
+elm_check_states_labels_get(const Evas_Object *obj, const char
**ontext, const char **offtext)
+{
+ if (ontext) *ontext = _elm_check_label_get(obj, "on");
+ if (offtext) *offtext = _elm_check_label_get(obj, "off");
+}
Why new APIs?
With recent elementary changes, we use elm_object_text_set() and
elm_object_text_part_set() to set texts of widgets instead of
elm_{widget}_label_set().
This is inconsistent.
We need to fix the policy to set texts.
1. Use elm_object_text_set, elm_object_text_part_set.
2. Use each widgets' APIs elm_{widget}_label_set,
elm_{widget}_{blarblar}_labels_set, elm_{widget}_info_set, and so on.
Now it's a mess.
Thanks.
Daniel Juyung Seo (SeoZ)
On Thu, Oct 20, 2011 at 9:30 PM, Enlightenment SVN
<[email protected]> wrote:
> Log:
> make toggle just a feature of check - on/off state and a togle style.
> keep toggle api (wrapped around check) and deprecate it. it will
> eventually go.
>
>
>
> Author: raster
> Date: 2011-10-20 05:30:04 -0700 (Thu, 20 Oct 2011)
> New Revision: 64199
> Trac: http://trac.enlightenment.org/e/changeset/64199
>
> Modified:
> trunk/elementary/data/themes/widgets/check.edc
> trunk/elementary/src/lib/Elementary.h.in trunk/elementary/src/lib/elm_check.c
> trunk/elementary/src/lib/elm_toggle.c
>
> Modified: trunk/elementary/data/themes/widgets/check.edc
> ===================================================================
> --- trunk/elementary/data/themes/widgets/check.edc 2011-10-20 12:21:41
> UTC (rev 64198)
> +++ trunk/elementary/data/themes/widgets/check.edc 2011-10-20 12:30:04
> UTC (rev 64199)
> @@ -247,3 +247,448 @@
> }
> }
> }
> +
> +group { name: "elm/check/base/toggle";
> + images {
> + image: "shelf_inset.png" COMP;
> + image: "bt_basew.png" COMP;
> + image: "bt_bases.png" COMP;
> + image: "bt_hilightw.png" COMP;
> + image: "tog_base_on.png" COMP;
> + image: "tog_base_off.png" COMP;
> + image: "tog_dis_base_on.png" COMP;
> + image: "tog_dis_base_off.png" COMP;
> + }
> + script {
> + public is_rtl;
> + }
> + parts {
> + part { name: "bg";
> + type: RECT;
> + mouse_events: 0;
> + scale: 1;
> + description { state: "default" 0.0;
> + rel1.relative: 1.0 0.0;
> + rel1.offset: -4 3;
> + rel2.offset: -4 -4;
> + align: 1.0 0.5;
> + min: 96 16;
> + max: 96 16;
> + aspect: 4.0 4.0;
> + aspect_preference: VERTICAL;
> + color: 255 255 255 255;
> + }
> + }
> + part { name: "clipper";
> + type: RECT;
> + mouse_events: 0;
> + description { state: "default" 0.0;
> + rel1.to: "bg";
> + rel2.to: "bg";
> + color: 255 255 255 255;
> + }
> + }
> + part { name: "button";
> + type: RECT;
> + scale: 1;
> + clip_to: "clipper";
> + mouse_events: 1;
> + dragable {
> + x: 1 1 0;
> + y: 0 0 0;
> + confine: "bg";
> + }
> + description { state: "default" 0.0;
> + fixed: 1 1;
> + rel1.to: "bg";
> + rel2.to: "bg";
> + min: 16 16;
> + max: 16 16;
> + aspect: 1.0 1.0;
> + aspect_preference: VERTICAL;
> + color: 0 0 0 0;
> + }
> + }
> + part { name: "button_events";
> + type: RECT;
> + dragable {
> + events: "button";
> + }
> + description { state: "default" 0.0;
> + rel1.to_x: "bg";
> + rel1.offset: 0 0;
> + rel1.relative: 0.0 0.0;
> + rel2.to_x: "bg";
> + rel2.offset: -1 -1;
> + rel2.relative: 1.0 1.0;
> + color: 0 0 0 0;
> + }
> + }
> + part { name: "onrect";
> + type: IMAGE;
> + scale: 1;
> + clip_to: "clipper";
> + mouse_events: 0;
> + description { state: "default" 0.0;
> + rel1.to: "button";
> + rel1.relative: -5.0 0.0;
> + rel2.to: "button";
> + rel2.relative: 0.5 1.0;
> + image.normal: "tog_base_on.png";
> + }
> + description { state: "disabled" 0.0;
> + inherit: "default" 0.0;
> + image.normal: "tog_dis_base_on.png";
> + }
> + }
> + part { name: "offrect";
> + type: IMAGE;
> + scale: 1;
> + clip_to: "clipper";
> + mouse_events: 0;
> + description { state: "default" 0.0;
> + rel1.to: "button";
> + rel1.relative: 0.5 0.0;
> + rel2.to: "button";
> + rel2.relative: 6.0 1.0;
> + image.normal: "tog_base_off.png";
> + }
> + description { state: "disabled" 0.0;
> + inherit: "default" 0.0;
> + image.normal: "tog_dis_base_off.png";
> + }
> + }
> + part { name: "elm.offtext";
> + type: TEXT;
> + mouse_events: 0;
> + scale: 1;
> + clip_to: "clipper";
> + description { state: "default" 0.0;
> + fixed: 1 1;
> + rel1.to_x: "button";
> + rel1.relative: 1.0 0.0;
> + rel2.to_x: "offrect";
> + color: 0 0 0 255;
> + text {
> + font: "Sans,Edje-Vera";
> + size: 10;
> + min: 0 1;
> + align: 0.5 0.5;
> + text: "OFF";
> + }
> + }
> + description { state: "disabled" 0.0;
> + inherit: "default" 0.0;
> + color: 128 128 128 128;
> + }
> + }
> + part { name: "elm.ontext";
> + type: TEXT;
> + effect: SOFT_SHADOW;
> + mouse_events: 0;
> + scale: 1;
> + clip_to: "clipper";
> + description { state: "default" 0.0;
> + fixed: 1 1;
> + rel1.to_x: "onrect";
> + rel1.offset: 1 1;
> + rel2.to_x: "button";
> + rel2.offset: 0 0;
> + rel2.relative: 0.0 1.0;
> + color: 224 224 224 255;
> + color3: 0 0 0 64;
> + text {
> + font: "Sans,Edje-Vera";
> + size: 10;
> + min: 0 1;
> + align: 0.5 0.5;
> + text: "ON";
> + }
> + }
> + description { state: "disabled" 0.0;
> + inherit: "default" 0.0;
> + color: 128 128 128 128;
> + color3: 0 0 0 24;
> + }
> + }
> + part { name: "conf_over";
> + mouse_events: 0;
> + description { state: "default" 0.0;
> + rel1.offset: -1 -1;
> + rel1.to: "bg";
> + rel2.offset: 0 0;
> + rel2.to: "bg";
> + image {
> + normal: "shelf_inset.png";
> + border: 7 7 7 7;
> + middle: 0;
> + }
> + fill.smooth : 0;
> + }
> + }
> + part { name: "button0";
> + mouse_events: 0;
> + clip_to: "clipper";
> + description { state: "default" 0.0;
> + rel1.to: "button2";
> + rel1.offset: -4 -4;
> + rel2.to: "button2";
> + rel2.offset: 3 3;
> + image {
> + normal: "bt_bases.png";
> + border: 11 11 11 11;
> + }
> + image.middle: SOLID;
> + color: 255 255 255 128;
> + }
> + }
> + part { name: "button2";
> + mouse_events: 0;
> + clip_to: "clipper";
> + description { state: "default" 0.0;
> + rel1.to: "button";
> + rel1.offset: -2 -2;
> + rel2.to: "button";
> + rel2.offset: 1 1;
> + image {
> + normal: "bt_basew.png";
> + border: 7 7 7 7;
> + }
> + image.middle: SOLID;
> + }
> + }
> + part { name: "button3";
> + mouse_events: 0;
> + clip_to: "clipper";
> + description { state: "default" 0.0;
> + rel1.to: "button2";
> + rel2.to: "button2";
> + rel2.relative: 1.0 0.5;
> + image {
> + normal: "bt_hilightw.png";
> + border: 4 4 4 0;
> + }
> + }
> + }
> + part { name: "elm.swallow.content";
> + type: SWALLOW;
> + description { state: "default" 0.0;
> + fixed: 1 0;
> + visible: 0;
> + align: 0.0 0.5;
> + rel1.offset: 4 4;
> + rel2.relative: 0.0 1.0;
> + rel2.offset: 3 -5;
> + }
> + description { state: "visible" 0.0;
> + inherit: "default" 0.0;
> + visible: 1;
> + aspect: 1.0 1.0;
> + rel2.offset: 4 -5;
> + }
> + description { state: "disabled" 0.0;
> + inherit: "default" 0.0;
> + color: 128 128 128 128;
> + }
> + description { state: "disabled_visible" 0.0;
> + inherit: "default" 0.0;
> + color: 128 128 128 128;
> + visible: 1;
> + aspect: 1.0 1.0;
> + }
> + }
> + part { name: "elm.text";
> + type: TEXT;
> + mouse_events: 0;
> + scale: 1;
> + description { state: "default" 0.0;
> + visible: 0;
> + rel1.to_x: "elm.swallow.content";
> + rel1.relative: 1.0 0.0;
> + rel1.offset: 0 4;
> + rel2.to_x: "bg";
> + rel2.relative: 0.0 1.0;
> + rel2.offset: -5 -5;
> + color: 0 0 0 255;
> + text {
> + font: "Sans,Edje-Vera";
> + size: 10;
> + min: 0 0;
> + align: 0.0 0.5;
> + }
> + }
> + 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: 128 128 128 128;
> + }
> + description { state: "disabled_visible" 0.0;
> + inherit: "default" 0.0;
> + color: 128 128 128 128;
> + visible: 1;
> + text.min: 1 1;
> + }
> + }
> + part { name: "disabler";
> + type: RECT;
> + description { state: "default" 0.0;
> + color: 0 0 0 0;
> + visible: 0;
> + }
> + description { state: "disabled" 0.0;
> + inherit: "default" 0.0;
> + visible: 1;
> + }
> + }
> + }
> + programs {
> + program { name: "drag_end";
> + signal: "mouse,up,1";
> + source: "button";
> + script {
> + new Float:dx, Float:dy;
> + get_drag(PART:"button", dx, dy);
> + if (dx > 0.5)
> + {
> + set_drag(PART:"button", 1.0, 0.0);
> + }
> + else
> + {
> + set_drag(PART:"button", 0.0, 0.0);
> + }
> + if (((get_int(is_rtl) == 1) && (dx <= 0.5)) ||
> + (get_int(is_rtl) == 0) && (dx > 0.5)) {
> + emit("elm,action,toggle,on", "");
> + }
> + else {
> + emit("elm,action,toggle,off", "");
> + }
> +
> + }
> + }
> + program { name: "toggle_on";
> + signal: "elm,state,toggle,on";
> + source: "elm";
> + script {
> + new Float:drag;
> + if (get_int(is_rtl) == 0) {
> + drag = 100.0;
> + }
> + else {
> + drag = 0.0;
> + }
> + set_drag(PART:"button", drag, 0.0);
> + }
> + }
> + program { name: "toggle_off";
> + signal: "elm,state,toggle,off";
> + source: "elm";
> + script {
> + new Float:drag;
> + if (get_int(is_rtl) == 0) {
> + drag = 0.0;
> + }
> + else {
> + drag = 100.0;
> + }
> + set_drag(PART:"button", drag, 0.0);
> + }
> + }
> + program { name: "text_show";
> + signal: "elm,state,text,visible";
> + source: "elm";
> + action: STATE_SET "visible" 0.0;
> + target: "elm.text";
> + }
> + program { name: "text_hide";
> + signal: "elm,state,text,hidden";
> + source: "elm";
> + action: STATE_SET "default" 0.0;
> + target: "elm.text";
> + }
> + program { name: "icon_show";
> + signal: "elm,state,icon,visible";
> + source: "elm";
> + action: STATE_SET "visible" 0.0;
> + target: "elm.swallow.content";
> + }
> + program { name: "icon_hide";
> + signal: "elm,state,icon,hidden";
> + source: "elm";
> + action: STATE_SET "default" 0.0;
> + target: "elm.swallow.content";
> + }
> + program { name: "disable";
> + signal: "elm,state,disabled";
> + source: "elm";
> + action: STATE_SET "disabled" 0.0;
> + target: "elm.offtext";
> + target: "elm.ontext";
> + target: "onrect";
> + target: "offrect";
> + target: "disabler";
> + 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);
> +
> + get_state(PART:"elm.swallow.content", st, 30, vl);
> + if (!strcmp(st, "visible"))
> + set_state(PART:"elm.swallow.content", "disabled_visible", 0.0);
> + else
> + set_state(PART:"elm.swallow.content", "disabled", 0.0);
> + }
> + }
> + program { name: "enable";
> + signal: "elm,state,enabled";
> + source: "elm";
> + action: STATE_SET "default" 0.0;
> + target: "disabler";
> + target: "onrect";
> + target: "offrect";
> + 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);
> +
> + get_state(PART:"elm.swallow.content", st, 30, vl);
> + if (!strcmp(st, "visible"))
> + set_state(PART:"elm.swallow.content", "visible", 0.0);
> + else
> + set_state(PART:"elm.swallow.content", "default", 0.0);
> + }
> + }
> + program { name: "to_rtl";
> + signal: "edje,state,rtl";
> + source: "edje";
> + script {
> + set_int(is_rtl, 1);
> + }
> + }
> + program { name: "to_ltr";
> + signal: "edje,state,ltr";
> + source: "edje";
> + script {
> + set_int(is_rtl, 0);
> + }
> + }
> + }
> +}
>
> Modified: trunk/elementary/src/lib/Elementary.h.in
> ===================================================================
> --- trunk/elementary/src/lib/Elementary.h.in 2011-10-20 12:21:41 UTC (rev
> 64198)
> +++ trunk/elementary/src/lib/Elementary.h.in 2011-10-20 12:30:04 UTC (rev
> 64199)
> @@ -7578,6 +7578,15 @@
> * @brief A toggle is a slider which can be used to toggle between
> * two values. It has two states: on and off.
> *
> + * This widget is deprecated. Please use elm_check_add() instead using the
> + * toggle style like:
> + *
> + * @code
> + * obj = elm_check_add(parent);
> + * elm_object_style_set(obj, "toggle");
> + * elm_check_states_labels_set(obj, "ON", "OFF");
> + * @endcode
> + *
> * Signals that you can add callbacks for are:
> * @li "changed" - Whenever the toggle value has been changed. Is not
> called
> * until the toggle is released by the cursor (assuming it
> @@ -7593,7 +7602,7 @@
> *
> * @return The toggle object
> */
> - EAPI Evas_Object *elm_toggle_add(Evas_Object *parent) EINA_ARG_NONNULL(1);
> + EINA_DEPRECATED EAPI Evas_Object *elm_toggle_add(Evas_Object *parent)
> EINA_ARG_NONNULL(1);
> /**
> * @brief Sets the label to be displayed with the toggle.
> *
> @@ -7622,7 +7631,7 @@
> * If you want to keep that old content object, use the
> * elm_toggle_icon_unset() function.
> */
> - EAPI void elm_toggle_icon_set(Evas_Object *obj, Evas_Object
> *icon) EINA_ARG_NONNULL(1);
> + EINA_DEPRECATED EAPI void elm_toggle_icon_set(Evas_Object *obj,
> Evas_Object *icon) EINA_ARG_NONNULL(1);
> /**
> * @brief Get the icon used for the toggle
> *
> @@ -7633,7 +7642,7 @@
> *
> * @see elm_toggle_icon_set()
> */
> - EAPI Evas_Object *elm_toggle_icon_get(const Evas_Object *obj)
> EINA_ARG_NONNULL(1);
> + EINA_DEPRECATED EAPI Evas_Object *elm_toggle_icon_get(const Evas_Object
> *obj) EINA_ARG_NONNULL(1);
> /**
> * @brief Unset the icon used for the toggle
> *
> @@ -7644,7 +7653,7 @@
> *
> * @see elm_toggle_icon_set()
> */
> - EAPI Evas_Object *elm_toggle_icon_unset(Evas_Object *obj)
> EINA_ARG_NONNULL(1);
> + EINA_DEPRECATED EAPI Evas_Object *elm_toggle_icon_unset(Evas_Object *obj)
> EINA_ARG_NONNULL(1);
> /**
> * @brief Sets the labels to be associated with the on and off states of
> the toggle.
> *
> @@ -7652,7 +7661,7 @@
> * @param onlabel The label displayed when the toggle is in the "on" state
> * @param offlabel The label displayed when the toggle is in the "off"
> state
> */
> - EAPI void elm_toggle_states_labels_set(Evas_Object *obj, const
> char *onlabel, const char *offlabel) EINA_ARG_NONNULL(1);
> + EINA_DEPRECATED EAPI void
> elm_toggle_states_labels_set(Evas_Object *obj, const char *onlabel, const
> char *offlabel) EINA_ARG_NONNULL(1);
> /**
> * @brief Gets the labels associated with the on and off states of the
> toggle.
> *
> @@ -7660,28 +7669,28 @@
> * @param onlabel A char** to place the onlabel of @p obj into
> * @param offlabel A char** to place the offlabel of @p obj into
> */
> - EAPI void elm_toggle_states_labels_get(const Evas_Object *obj,
> const char **onlabel, const char **offlabel) EINA_ARG_NONNULL(1);
> + EINA_DEPRECATED EAPI void elm_toggle_states_labels_get(const
> Evas_Object *obj, const char **onlabel, const char **offlabel)
> EINA_ARG_NONNULL(1);
> /**
> * @brief Sets the state of the toggle to @p state.
> *
> * @param obj The toggle object
> * @param state The state of @p obj
> */
> - EAPI void elm_toggle_state_set(Evas_Object *obj, Eina_Bool state)
> EINA_ARG_NONNULL(1);
> + EINA_DEPRECATED EAPI void elm_toggle_state_set(Evas_Object *obj,
> Eina_Bool state) EINA_ARG_NONNULL(1);
> /**
> * @brief Gets the state of the toggle to @p state.
> *
> * @param obj The toggle object
> * @return The state of @p obj
> */
> - EAPI Eina_Bool elm_toggle_state_get(const Evas_Object *obj)
> EINA_ARG_NONNULL(1);
> + EINA_DEPRECATED EAPI Eina_Bool elm_toggle_state_get(const Evas_Object
> *obj) EINA_ARG_NONNULL(1);
> /**
> * @brief Sets the state pointer of the toggle to @p statep.
> *
> * @param obj The toggle object
> * @param statep The state pointer of @p obj
> */
> - EAPI void elm_toggle_state_pointer_set(Evas_Object *obj,
> Eina_Bool *statep) EINA_ARG_NONNULL(1);
> + EINA_DEPRECATED EAPI void
> elm_toggle_state_pointer_set(Evas_Object *obj, Eina_Bool *statep)
> EINA_ARG_NONNULL(1);
> /**
> * @}
> */
>
> Modified: trunk/elementary/src/lib/elm_check.c
> ===================================================================
> --- trunk/elementary/src/lib/elm_check.c 2011-10-20 12:21:41 UTC (rev
> 64198)
> +++ trunk/elementary/src/lib/elm_check.c 2011-10-20 12:30:04 UTC (rev
> 64199)
> @@ -9,6 +9,7 @@
> Eina_Bool state;
> Eina_Bool *statep;
> const char *label;
> + const char *ontext, *offtext;
> };
>
> static const char *widtype = NULL;
> @@ -57,6 +58,8 @@
> Widget_Data *wd = elm_widget_data_get(obj);
> if (!wd) return;
> if (wd->label) eina_stringshare_del(wd->label);
> + if (wd->ontext) eina_stringshare_del(wd->ontext);
> + if (wd->offtext) eina_stringshare_del(wd->offtext);
> free(wd);
> }
>
> @@ -98,14 +101,22 @@
> else
> edje_object_signal_emit(wd->chk, "elm,state,icon,hidden", "elm");
> if (wd->state)
> - edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
> + {
> + edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
> + edje_object_signal_emit(wd->chk, "elm,state,toggle,on", "elm");
> + }
> else
> - edje_object_signal_emit(wd->chk, "elm,state,check,off", "elm");
> + {
> + edje_object_signal_emit(wd->chk, "elm,state,check,off", "elm");
> + edje_object_signal_emit(wd->chk, "elm,state,toggle,off", "elm");
> + }
> if (wd->label)
> edje_object_signal_emit(wd->chk, "elm,state,text,visible", "elm");
> else
> edje_object_signal_emit(wd->chk, "elm,state,text,hidden", "elm");
> edje_object_part_text_set(wd->chk, "elm.text", wd->label);
> + edje_object_part_text_set(wd->chk, "elm.ontext", wd->ontext);
> + edje_object_part_text_set(wd->chk, "elm.offtext", wd->offtext);
> if (elm_widget_disabled_get(obj))
> edje_object_signal_emit(wd->chk, "elm,state,disabled", "elm");
> edje_object_message_signal_process(wd->chk);
> @@ -143,8 +154,6 @@
> Widget_Data *wd = elm_widget_data_get(data);
> if (!wd) return;
> if (obj != wd->icon) return;
> - Evas_Coord mw, mh;
> - evas_object_size_hint_min_get(obj, &mw, &mh);
> _sizing_eval(data);
> }
>
> @@ -173,6 +182,7 @@
> wd->state = EINA_FALSE;
> if (wd->statep) *wd->statep = wd->state;
> edje_object_signal_emit(wd->chk, "elm,state,check,off", "elm");
> + edje_object_signal_emit(wd->chk, "elm,state,toggle,off", "elm");
> evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
> }
>
> @@ -184,6 +194,7 @@
> wd->state = EINA_TRUE;
> if (wd->statep) *wd->statep = wd->state;
> edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
> + edje_object_signal_emit(wd->chk, "elm,state,toggle,on", "elm");
> evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
> }
>
> @@ -213,13 +224,27 @@
> {
> edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
> if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
> - _elm_access_say(E_("State: On"));
> + {
> + if (!wd->ontext)
> + {
> + _elm_access_say(E_("State: On"));
> + }
> + else
> + _elm_access_say(E_("State: On"));
> + }
> }
> else
> {
> edje_object_signal_emit(wd->chk, "elm,state,check,off", "elm");
> if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
> - _elm_access_say(E_("State: Off"));
> + {
> + if (!wd->offtext)
> + {
> + _elm_access_say(E_("State: Off"));
> + }
> + else
> + _elm_access_say(E_("State: Off"));
> + }
> }
> evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
> }
> @@ -230,15 +255,27 @@
> {
> ELM_CHECK_WIDTYPE(obj, widtype);
> Widget_Data *wd = elm_widget_data_get(obj);
> - if (item && strcmp(item, "default")) return;
> if (!wd) return;
> - eina_stringshare_replace(&wd->label, label);
> - if (label)
> - edje_object_signal_emit(wd->chk, "elm,state,text,visible", "elm");
> - else
> - edje_object_signal_emit(wd->chk, "elm,state,text,hidden", "elm");
> - edje_object_message_signal_process(wd->chk);
> - edje_object_part_text_set(wd->chk, "elm.text", label);
> + if ((!item) || (!strcmp(item, "default")))
> + {
> + eina_stringshare_replace(&wd->label, label);
> + if (label)
> + edje_object_signal_emit(wd->chk, "elm,state,text,visible", "elm");
> + else
> + edje_object_signal_emit(wd->chk, "elm,state,text,hidden", "elm");
> + edje_object_message_signal_process(wd->chk);
> + edje_object_part_text_set(wd->chk, "elm.text", label);
> + }
> + else if ((item) && (!strcmp(item, "on")))
> + {
> + eina_stringshare_replace(&wd->ontext, label);
> + edje_object_part_text_set(wd->chk, "elm.ontext", wd->ontext);
> + }
> + else if ((item) && (!strcmp(item, "off")))
> + {
> + eina_stringshare_replace(&wd->offtext, label);
> + edje_object_part_text_set(wd->chk, "elm.offtext", wd->offtext);
> + }
> _sizing_eval(obj);
> }
>
> @@ -247,9 +284,14 @@
> {
> ELM_CHECK_WIDTYPE(obj, widtype) NULL;
> Widget_Data *wd = elm_widget_data_get(obj);
> - if (item && strcmp(item, "default")) return NULL;
> if (!wd) return NULL;
> - return wd->label;
> + if ((!item) || (!strcmp(item, "default")))
> + return wd->label;
> + else if ((item) && (!strcmp(item, "on")))
> + return wd->ontext;
> + else if ((item) && (!strcmp(item, "off")))
> + return wd->offtext;
> + return NULL;
> }
>
> static char *
> @@ -270,7 +312,24 @@
> if (elm_widget_disabled_get(obj))
> return strdup(E_("State: Disabled"));
> if (wd->state)
> - return strdup(E_("State: On"));
> + {
> + if (wd->ontext)
> + {
> + char buf[1024];
> +
> + snprintf(buf, sizeof(buf), "%s: %s", E_("State"), wd->ontext);
> + return strdup(buf);
> + }
> + else
> + return strdup(E_("State: On"));
> + }
> + if (wd->offtext)
> + {
> + char buf[1024];
> +
> + snprintf(buf, sizeof(buf), "%s: %s", E_("State"), wd->offtext);
> + return strdup(buf);
> + }
> return strdup(E_("State: Off"));
> }
>
> @@ -339,6 +398,20 @@
> }
>
> EAPI void
> +elm_check_states_labels_set(Evas_Object *obj, const char *ontext, const char
> *offtext)
> +{
> + _elm_check_label_set(obj, "on", ontext);
> + _elm_check_label_set(obj, "off", offtext);
> +}
> +
> +EAPI void
> +elm_check_states_labels_get(const Evas_Object *obj, const char **ontext,
> const char **offtext)
> +{
> + if (ontext) *ontext = _elm_check_label_get(obj, "on");
> + if (offtext) *offtext = _elm_check_label_get(obj, "off");
> +}
> +
> +EAPI void
> elm_check_icon_set(Evas_Object *obj, Evas_Object *icon)
> {
> ELM_CHECK_WIDTYPE(obj, widtype);
> @@ -393,9 +466,15 @@
> wd->state = state;
> if (wd->statep) *wd->statep = wd->state;
> if (wd->state)
> - edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
> + {
> + edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
> + edje_object_signal_emit(wd->chk, "elm,state,toggle,on", "elm");
> + }
> else
> - edje_object_signal_emit(wd->chk, "elm,state,check,off", "elm");
> + {
> + edje_object_signal_emit(wd->chk, "elm,state,check,off", "elm");
> + edje_object_signal_emit(wd->chk, "elm,state,toggle,off", "elm");
> + }
> }
> edje_object_message_signal_process(wd->chk);
> }
> @@ -422,9 +501,15 @@
> {
> wd->state = *wd->statep;
> if (wd->state)
> - edje_object_signal_emit(wd->chk, "elm,state,check,on", "elm");
> + {
> + edje_object_signal_emit(wd->chk, "elm,state,check,on",
> "elm");
> + edje_object_signal_emit(wd->chk, "elm,state,toggle,on",
> "elm");
> + }
> else
> - edje_object_signal_emit(wd->chk, "elm,state,check,off",
> "elm");
> + {
> + edje_object_signal_emit(wd->chk, "elm,state,check,off",
> "elm");
> + edje_object_signal_emit(wd->chk, "elm,state,toggle,off",
> "elm");
> + }
> }
> }
> else
>
> Modified: trunk/elementary/src/lib/elm_toggle.c
> ===================================================================
> --- trunk/elementary/src/lib/elm_toggle.c 2011-10-20 12:21:41 UTC (rev
> 64198)
> +++ trunk/elementary/src/lib/elm_toggle.c 2011-10-20 12:30:04 UTC (rev
> 64199)
> @@ -1,391 +1,73 @@
> #include <Elementary.h>
> #include "elm_priv.h"
>
> -typedef struct _Widget_Data Widget_Data;
> -
> -struct _Widget_Data
> -{
> - Evas_Object *tgl;
> - Evas_Object *icon;
> - Eina_Bool state;
> - Eina_Bool *statep;
> - const char *label;
> - const char *ontext, *offtext;
> -};
> -
> -static const char *widtype = NULL;
> -static void _del_hook(Evas_Object *obj);
> -static void _disable_hook(Evas_Object *obj);
> -static void _theme_hook(Evas_Object *obj);
> -static void _sizing_eval(Evas_Object *obj);
> -static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void
> *event_info);
> -static void _sub_del(void *data, Evas_Object *obj, void *event_info);
> -static void _signal_toggle_off(void *data, Evas_Object *obj, const char
> *emission, const char *source);
> -static void _signal_toggle_on(void *data, Evas_Object *obj, const char
> *emission, const char *source);
> -static void _on_focus_hook(void *data, Evas_Object *obj);
> -static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
> - Evas_Callback_Type type, void *event_info);
> -
> -static const char SIG_CHANGED[] = "changed";
> -static const Evas_Smart_Cb_Description _signals[] = {
> - {SIG_CHANGED, ""},
> - {NULL, NULL}
> -};
> -
> -static Eina_Bool
> -_event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
> Evas_Callback_Type type, void *event_info)
> -{
> - if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
> - Evas_Event_Key_Down *ev = event_info;
> - Widget_Data *wd = elm_widget_data_get(obj);
> - if (!wd) return EINA_FALSE;
> - if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
> - if (elm_widget_disabled_get(obj)) return EINA_FALSE;
> - if ((strcmp(ev->keyname, "Return")) &&
> - (strcmp(ev->keyname, "KP_Enter")) &&
> - (strcmp(ev->keyname, "space")))
> - return EINA_FALSE;
> - elm_toggle_state_set(obj, !wd->state);
> - evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
> - ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
> - return EINA_TRUE;
> -}
> -
> -static void
> -_del_hook(Evas_Object *obj)
> -{
> - Widget_Data *wd = elm_widget_data_get(obj);
> - if (!wd) return;
> - if (wd->label) eina_stringshare_del(wd->label);
> - if (wd->ontext) eina_stringshare_del(wd->ontext);
> - if (wd->offtext) eina_stringshare_del(wd->offtext);
> - free(wd);
> -}
> -
> -static void
> -_disable_hook(Evas_Object *obj)
> -{
> - Widget_Data *wd = elm_widget_data_get(obj);
> - if (!wd) return;
> - if (elm_widget_disabled_get(obj))
> - edje_object_signal_emit(wd->tgl, "elm,state,disabled", "elm");
> - else
> - edje_object_signal_emit(wd->tgl, "elm,state,enabled", "elm");
> -}
> -
> -static void
> -_on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
> -{
> - Widget_Data *wd = elm_widget_data_get(obj);
> - if (!wd) return;
> - if (elm_widget_focus_get(obj))
> - {
> - edje_object_signal_emit(wd->tgl, "elm,action,focus", "elm");
> - evas_object_focus_set(wd->tgl, EINA_TRUE);
> - }
> - else
> - {
> - edje_object_signal_emit(wd->tgl, "elm,action,unfocus", "elm");
> - evas_object_focus_set(wd->tgl, EINA_FALSE);
> - }
> -}
> -
> -static void
> -_mirrored_set(Evas_Object *obj, Eina_Bool rtl)
> -{
> - Widget_Data *wd = elm_widget_data_get(obj);
> - if (!wd) return;
> - edje_object_mirrored_set(wd->tgl, rtl);
> -}
> -
> -static void
> -_theme_hook(Evas_Object *obj)
> -{
> - Widget_Data *wd = elm_widget_data_get(obj);
> - if (!wd) return;
> - _elm_widget_mirrored_reload(obj);
> - _mirrored_set(obj, elm_widget_mirrored_get(obj));
> - _elm_theme_object_set(obj, wd->tgl, "toggle", "base",
> elm_widget_style_get(obj));
> - if (wd->icon)
> - edje_object_signal_emit(wd->tgl, "elm,state,icon,visible", "elm");
> - else
> - edje_object_signal_emit(wd->tgl, "elm,state,icon,hidden", "elm");
> - if (wd->state)
> - edje_object_signal_emit(wd->tgl, "elm,state,toggle,on", "elm");
> - else
> - edje_object_signal_emit(wd->tgl, "elm,state,toggle,off", "elm");
> - if (wd->label)
> - edje_object_signal_emit(wd->tgl, "elm,state,text,visible", "elm");
> - else
> - edje_object_signal_emit(wd->tgl, "elm,state,text,hidden", "elm");
> - edje_object_part_text_set(wd->tgl, "elm.text", wd->label);
> - edje_object_part_text_set(wd->tgl, "elm.ontext", wd->ontext);
> - edje_object_part_text_set(wd->tgl, "elm.offtext", wd->offtext);
> - if (elm_widget_disabled_get(obj))
> - edje_object_signal_emit(wd->tgl, "elm,state,disabled", "elm");
> - edje_object_message_signal_process(wd->tgl);
> - edje_object_scale_set(wd->tgl, elm_widget_scale_get(obj) *
> _elm_config->scale);
> - _sizing_eval(obj);
> -}
> -
> -static void
> -_sizing_eval(Evas_Object *obj)
> -{
> - Widget_Data *wd = elm_widget_data_get(obj);
> - Evas_Coord minw = -1, minh = -1;
> -
> - if (!wd) return;
> - elm_coords_finger_size_adjust(1, &minw, 1, &minh);
> - edje_object_size_min_restricted_calc(wd->tgl, &minw, &minh, minw, minh);
> - elm_coords_finger_size_adjust(1, &minw, 1, &minh);
> - evas_object_size_hint_min_set(obj, minw, minh);
> - evas_object_size_hint_max_set(obj, -1, -1);
> -}
> -
> -static void
> -_changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void
> *event_info __UNUSED__)
> -{
> - Widget_Data *wd = elm_widget_data_get(data);
> - if (!wd) return;
> - if (obj != wd->icon) return;
> - _sizing_eval(data);
> -}
> -
> -static void
> -_sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
> -{
> - Widget_Data *wd = elm_widget_data_get(obj);
> - Evas_Object *sub = event_info;
> - if (!wd) return;
> - if (sub == wd->icon)
> - {
> - edje_object_signal_emit(wd->tgl, "elm,state,icon,hidden", "elm");
> - evas_object_event_callback_del_full
> - (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
> - wd->icon = NULL;
> - edje_object_message_signal_process(wd->tgl);
> - _sizing_eval(obj);
> - }
> -}
> -
> -static void
> -_signal_toggle_off(void *data, Evas_Object *obj __UNUSED__, const char
> *emission __UNUSED__, const char *source __UNUSED__)
> -{
> - Widget_Data *wd = elm_widget_data_get(data);
> - if (!wd || !wd->state) return;
> - wd->state = 0;
> - if (wd->statep) *wd->statep = wd->state;
> - evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
> -}
> -
> -static void
> -_signal_toggle_on(void *data, Evas_Object *obj __UNUSED__, const char
> *emission __UNUSED__, const char *source __UNUSED__)
> -{
> - Widget_Data *wd = elm_widget_data_get(data);
> - if (!wd || wd->state) return;
> - wd->state = 1;
> - if (wd->statep) *wd->statep = wd->state;
> - evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
> -}
> -
> -static void
> -_elm_toggle_label_set(Evas_Object *obj, const char *item, const char *label)
> -{
> - ELM_CHECK_WIDTYPE(obj, widtype);
> - Widget_Data *wd = elm_widget_data_get(obj);
> - if (item && strcmp(item, "default")) return;
> - if (!wd) return;
> - eina_stringshare_replace(&wd->label, label);
> - if (label)
> - edje_object_signal_emit(wd->tgl, "elm,state,text,visible", "elm");
> - else
> - edje_object_signal_emit(wd->tgl, "elm,state,text,hidden", "elm");
> - edje_object_message_signal_process(wd->tgl);
> - edje_object_part_text_set(wd->tgl, "elm.text", label);
> - _sizing_eval(obj);
> -}
> -
> -static const char *
> -_elm_toggle_label_get(const Evas_Object *obj, const char *item)
> -{
> - ELM_CHECK_WIDTYPE(obj, widtype) NULL;
> - Widget_Data *wd = elm_widget_data_get(obj);
> - if (item && strcmp(item, "default")) return NULL;
> - if (!wd) return NULL;
> - return wd->label;
> -}
> -
> EAPI Evas_Object *
> elm_toggle_add(Evas_Object *parent)
> {
> Evas_Object *obj;
> - Evas *e;
> - Widget_Data *wd;
> -
> - ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
> -
> - ELM_SET_WIDTYPE(widtype, "toggle");
> - elm_widget_type_set(obj, "toggle");
> - elm_widget_sub_object_add(parent, obj);
> - elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
> - elm_widget_data_set(obj, wd);
> - elm_widget_del_hook_set(obj, _del_hook);
> - elm_widget_theme_hook_set(obj, _theme_hook);
> - elm_widget_disable_hook_set(obj, _disable_hook);
> - elm_widget_can_focus_set(obj, EINA_TRUE);
> - elm_widget_event_hook_set(obj, _event_hook);
> - elm_widget_text_set_hook_set(obj, _elm_toggle_label_set);
> - elm_widget_text_get_hook_set(obj, _elm_toggle_label_get);
> -
> - wd->tgl = edje_object_add(e);
> - _mirrored_set(obj, elm_widget_mirrored_get(obj));
> - _elm_theme_object_set(obj, wd->tgl, "toggle", "base", "default");
> - wd->ontext = eina_stringshare_add("ON");
> - wd->offtext = eina_stringshare_add("OFF");
> - edje_object_signal_callback_add(wd->tgl, "elm,action,toggle,on", "",
> - _signal_toggle_on, obj);
> - edje_object_signal_callback_add(wd->tgl, "elm,action,toggle,off", "",
> - _signal_toggle_off, obj);
> - elm_widget_resize_object_set(obj, wd->tgl);
> - edje_object_part_text_set(wd->tgl, "elm.ontext", wd->ontext);
> - edje_object_part_text_set(wd->tgl, "elm.offtext", wd->offtext);
> -
> - evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
> - edje_object_signal_emit(wd->tgl, "elm,state,toggle,off", "elm");
> -
> - _sizing_eval(obj);
> -
> - // TODO: convert Elementary to subclassing of Evas_Smart_Class
> - // TODO: and save some bytes, making descriptions per-class and not
> instance!
> - evas_object_smart_callbacks_descriptions_set(obj, _signals);
> +
> + obj = elm_check_add(parent);
> + elm_object_style_set(obj, "toggle");
> + elm_check_states_labels_set(obj, E_("ON"), E_("OFF"));
> return obj;
> }
>
> EAPI void
> elm_toggle_label_set(Evas_Object *obj, const char *label)
> {
> - _elm_toggle_label_set(obj, NULL, label);
> + elm_check_label_set(obj, label);
> }
>
> EAPI const char *
> elm_toggle_label_get(const Evas_Object *obj)
> {
> - return _elm_toggle_label_get(obj, NULL);
> + return elm_check_label_get(obj);
> }
>
> EAPI void
> elm_toggle_icon_set(Evas_Object *obj, Evas_Object *icon)
> {
> - ELM_CHECK_WIDTYPE(obj, widtype);
> - Widget_Data *wd = elm_widget_data_get(obj);
> - if (!wd) return;
> - if (wd->icon == icon) return;
> - if (wd->icon) evas_object_del(wd->icon);
> - wd->icon = icon;
> - if (icon)
> - {
> - elm_widget_sub_object_add(obj, icon);
> - evas_object_event_callback_add(icon,
> EVAS_CALLBACK_CHANGED_SIZE_HINTS,
> - _changed_size_hints, obj);
> - edje_object_part_swallow(wd->tgl, "elm.swallow.content", icon);
> - edje_object_signal_emit(wd->tgl, "elm,state,icon,visible", "elm");
> - edje_object_message_signal_process(wd->tgl);
> - }
> - _sizing_eval(obj);
> + elm_check_icon_set(obj, icon);
> }
>
> EAPI Evas_Object *
> elm_toggle_icon_get(const Evas_Object *obj)
> {
> - ELM_CHECK_WIDTYPE(obj, widtype) NULL;
> - Widget_Data *wd = elm_widget_data_get(obj);
> - if (!wd) return NULL;
> - return wd->icon;
> + return elm_check_icon_get(obj);
> }
>
> EAPI Evas_Object *
> elm_toggle_icon_unset(Evas_Object *obj)
> {
> - ELM_CHECK_WIDTYPE(obj, widtype) NULL;
> - Widget_Data *wd = elm_widget_data_get(obj);
> - if (!wd) return NULL;
> - if (!wd->icon) return NULL;
> - Evas_Object *icon = wd->icon;
> - elm_widget_sub_object_del(obj, wd->icon);
> - edje_object_part_unswallow(wd->tgl, wd->icon);
> - wd->icon = NULL;
> - return icon;
> + return elm_check_icon_unset(obj);
> }
>
> EAPI void
> elm_toggle_states_labels_set(Evas_Object *obj, const char *onlabel, const
> char *offlabel)
> {
> - ELM_CHECK_WIDTYPE(obj, widtype);
> - Widget_Data *wd = elm_widget_data_get(obj);
> - if (!wd) return;
> - eina_stringshare_replace(&wd->ontext, onlabel);
> - eina_stringshare_replace(&wd->offtext, offlabel);
> - edje_object_part_text_set(wd->tgl, "elm.ontext", onlabel);
> - edje_object_part_text_set(wd->tgl, "elm.offtext", offlabel);
> - _sizing_eval(obj);
> + elm_check_states_labels_set(obj, onlabel, offlabel);
> }
>
> EAPI void
> elm_toggle_states_labels_get(const Evas_Object *obj, const char **onlabel,
> const char **offlabel)
> {
> - if (onlabel) *onlabel = NULL;
> - if (offlabel) *offlabel = NULL;
> - ELM_CHECK_WIDTYPE(obj, widtype);
> - Widget_Data *wd = elm_widget_data_get(obj);
> - if (!wd) return;
> - if (onlabel) *onlabel = wd->ontext;
> - if (offlabel) *offlabel = wd->offtext;
> + elm_check_states_labels_set(obj, onlabel, offlabel);
> }
>
> EAPI void
> elm_toggle_state_set(Evas_Object *obj, Eina_Bool state)
> {
> - ELM_CHECK_WIDTYPE(obj, widtype);
> - Widget_Data *wd = elm_widget_data_get(obj);
> - if (!wd) return;
> - if (state != wd->state)
> - {
> - wd->state = state;
> - if (wd->statep) *wd->statep = wd->state;
> - if (wd->state)
> - edje_object_signal_emit(wd->tgl, "elm,state,toggle,on", "elm");
> - else
> - edje_object_signal_emit(wd->tgl, "elm,state,toggle,off", "elm");
> - }
> + elm_check_state_set(obj, state);
> }
>
> EAPI Eina_Bool
> elm_toggle_state_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->state;
> + return elm_check_state_get(obj);
> }
>
> EAPI void
> elm_toggle_state_pointer_set(Evas_Object *obj, Eina_Bool *statep)
> {
> - ELM_CHECK_WIDTYPE(obj, widtype);
> - Widget_Data *wd = elm_widget_data_get(obj);
> - if (!wd) return;
> - if (statep)
> - {
> - wd->statep = statep;
> - if (*wd->statep != wd->state)
> - {
> - wd->state = *wd->statep;
> - if (wd->state)
> - edje_object_signal_emit(wd->tgl, "elm,state,toggle,on",
> "elm");
> - else
> - edje_object_signal_emit(wd->tgl, "elm,state,toggle,off",
> "elm");
> - }
> - }
> - else
> - wd->statep = NULL;
> + elm_check_state_pointer_set(obj, statep);
> }
>
>
> ------------------------------------------------------------------------------
> The demand for IT networking professionals continues to grow, and the
> demand for specialized networking skills is growing even more rapidly.
> Take a complimentary Learning@Ciosco Self-Assessment and learn
> about Cisco certifications, training, and career opportunities.
> http://p.sf.net/sfu/cisco-dev2dev
> _______________________________________________
> enlightenment-svn mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/enlightenment-svn
>
------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Ciosco Self-Assessment and learn
about Cisco certifications, training, and career opportunities.
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel