This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository efl.
View the commit online.
commit c1049e5694af0c6f34f3bf94d5fb02d59580ec11
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Oct 31 11:42:58 2026 -0600
elementary: what the user changes in a bound widget reaches its model
Efl.Ui.Widget binds a widget property to its model's in both
directions: the model's properties,changed sets the widget, and the
widget's Efl.Ui.Property_Bind properties,changed writes the widget's
value back with efl_model_property_set. No widget ever raised that
event, so a model bound to a textbox, a check or a slider never heard
what the user did with them.
Textbox (text), Check and Radio (selected), Slider and Spin_Button
(range_value) now raise it on the paths a user's edit takes, and only
when the value really changed. Raising it on every change would loop:
Efl.Generic_Model reports every set, changed or not. For the same
reason the widget is no longer set to the value it already holds when
its model reports back the edit it was just given: a textbox would
rebuild its text and lose the cursor, the selection and the markup.
Only the widget's own bindings are looked up for the write-back. A
part bound under the same key, such as a textbox's guide text, used
to take the user's edit for itself when it was bound first.
A spin button's open entry follows a value set meanwhile, so leaving
it does not write the old value back, and a slider value refused as
out of range is not reported. A radio reports its own press; a group
is followed through the group's value, as its documentation now says.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/lib/elementary/efl_ui_check.c | 4 +
src/lib/elementary/efl_ui_radio.c | 1 +
src/lib/elementary/efl_ui_radio.eo | 4 +
src/lib/elementary/efl_ui_slider.c | 5 +
src/lib/elementary/efl_ui_spin_button.c | 8 +-
src/lib/elementary/efl_ui_textbox.c | 11 +
src/lib/elementary/efl_ui_widget.c | 24 +-
src/lib/elementary/elm_priv.h | 29 ++
src/tests/elementary/efl_ui_suite.c | 1 +
src/tests/elementary/efl_ui_suite.h | 1 +
src/tests/elementary/efl_ui_test_property_bind.c | 590 +++++++++++++++++++++++
src/tests/elementary/meson.build | 1 +
12 files changed, 676 insertions(+), 3 deletions(-)
diff --git a/src/lib/elementary/efl_ui_check.c b/src/lib/elementary/efl_ui_check.c
index da51f880ce..79749a5b1d 100644
--- a/src/lib/elementary/efl_ui_check.c
+++ b/src/lib/elementary/efl_ui_check.c
@@ -121,6 +121,7 @@ _activate(Evas_Object *obj)
efl_access_state_changed_signal_emit(obj,
EFL_ACCESS_STATE_TYPE_CHECKED,
efl_ui_selectable_selected_get(obj));
+ _efl_ui_property_bind_user_changed(obj, "selected");
}
EOLIAN static Efl_Access_State_Set
@@ -232,12 +233,15 @@ _access_state_cb(void *data, Evas_Object *obj)
static void
_flush_selected(Eo *obj, Eina_Bool sel)
{
+ Eina_Bool changed = (efl_ui_selectable_selected_get(obj) != sel);
+
efl_ui_selectable_selected_set(obj, sel);
if (_elm_config->atspi_mode)
efl_access_state_changed_signal_emit(obj,
EFL_ACCESS_STATE_TYPE_CHECKED,
efl_ui_selectable_selected_get(obj));
+ if (changed) _efl_ui_property_bind_user_changed(obj, "selected");
}
static void
diff --git a/src/lib/elementary/efl_ui_radio.c b/src/lib/elementary/efl_ui_radio.c
index e78168318c..b4690794a4 100644
--- a/src/lib/elementary/efl_ui_radio.c
+++ b/src/lib/elementary/efl_ui_radio.c
@@ -145,6 +145,7 @@ _activate(Evas_Object *obj)
{
//in new API, we just toggle the state of the widget, rest will be automatically handled
efl_ui_selectable_selected_set(obj, !efl_ui_selectable_selected_get(obj));
+ _efl_ui_property_bind_user_changed(obj, "selected");
}
}
diff --git a/src/lib/elementary/efl_ui_radio.eo b/src/lib/elementary/efl_ui_radio.eo
index b6d6d3715e..df458d158e 100644
--- a/src/lib/elementary/efl_ui_radio.eo
+++ b/src/lib/elementary/efl_ui_radio.eo
@@ -12,6 +12,10 @@ class Efl.Ui.Radio extends Efl.Ui.Check implements Efl.Access.Widget.Action
To handle button grouping, you can either use an @Efl.Ui.Radio_Group_Impl object or
use more convenient widgets like @Efl.Ui.Radio_Box.
+ A radio button raises @[Efl.Ui.Property_Bind.properties,changed] for "selected" when the
+ user presses it. The buttons the group unchecks as a result do not: to follow a whole
+ group from a model, bind the group's value instead.
+
@since 1.23
]]
methods {
diff --git a/src/lib/elementary/efl_ui_slider.c b/src/lib/elementary/efl_ui_slider.c
index 041316de68..dbfe364a1b 100644
--- a/src/lib/elementary/efl_ui_slider.c
+++ b/src/lib/elementary/efl_ui_slider.c
@@ -82,6 +82,7 @@ static void
_user_value_update(Evas_Object *obj, double value)
{
EFL_UI_SLIDER_DATA_GET(obj, sd);
+ double previous = sd->val;
efl_ui_range_value_set(obj, value);
@@ -89,6 +90,10 @@ _user_value_update(Evas_Object *obj, double value)
sd->delay = ecore_timer_add(SLIDER_DELAY_CHANGED_INTERVAL, _delay_change, obj);
evas_object_smart_changed(obj);
+
+ // Last, as a handler may delete the slider.
+ if (!EINA_DBL_EQ(previous, sd->val))
+ _efl_ui_property_bind_user_changed(obj, "range_value");
}
static void
diff --git a/src/lib/elementary/efl_ui_spin_button.c b/src/lib/elementary/efl_ui_spin_button.c
index b44a93f30b..60fee97146 100644
--- a/src/lib/elementary/efl_ui_spin_button.c
+++ b/src/lib/elementary/efl_ui_spin_button.c
@@ -158,6 +158,9 @@ _value_set(Evas_Object *obj,
.free = _delay_change_timer_cleanup,
.data = ""
+ // Last, as a handler may delete the spin button.
+ _efl_ui_property_bind_user_changed(obj, "range_value");
+
return EINA_TRUE;
}
@@ -714,11 +717,14 @@ _efl_ui_spin_button_efl_ui_layout_orientable_orientation_get(const Eo *obj EINA_
}
EOLIAN static void
-_efl_ui_spin_button_efl_ui_range_display_range_value_set(Eo *obj, Efl_Ui_Spin_Button_Data *sd EINA_UNUSED, double val)
+_efl_ui_spin_button_efl_ui_range_display_range_value_set(Eo *obj, Efl_Ui_Spin_Button_Data *sd, double val)
{
efl_ui_range_value_set(efl_super(obj, MY_CLASS), val);
_label_write(obj);
+ /* The entry is filled when it opens: refresh it, or leaving it would
+ apply the value it held before this one. */
+ if (sd->entry_visible && sd->ent) _entry_show(obj);
}
EOLIAN static void
diff --git a/src/lib/elementary/efl_ui_textbox.c b/src/lib/elementary/efl_ui_textbox.c
index 6445186978..6358917739 100644
--- a/src/lib/elementary/efl_ui_textbox.c
+++ b/src/lib/elementary/efl_ui_textbox.c
@@ -181,6 +181,7 @@ static void _update_decorations(Eo *obj);
static void _create_text_cursors(Eo *obj, Efl_Ui_Textbox_Data *sd);
static void _efl_ui_textbox_changed_cb(void *data, const Efl_Event *event);
static void _efl_ui_textbox_changed_user_cb(void *data, const Efl_Event *event);
+static void _efl_ui_textbox_property_bind_changed_user_cb(void *data, const Efl_Event *event);
static void _efl_ui_textbox_selection_start_clear_cb(void *data, const Efl_Event *event);
static void _efl_ui_textbox_selection_changed_cb(void *data, const Efl_Event *event);
static void _efl_ui_textbox_cursor_changed_cb(void *data, const Efl_Event *event);
@@ -1696,6 +1697,9 @@ _efl_ui_textbox_efl_object_constructor(Eo *obj, Efl_Ui_Textbox_Data *sd)
text_obj = efl_add(EFL_UI_INTERNAL_TEXT_INTERACTIVE_CLASS, obj);
efl_event_callback_forwarder_add(text_obj, EFL_TEXT_INTERACTIVE_EVENT_CHANGED_USER, obj);
+ // Pasting and deleting a selection emit it on the textbox itself, so listen here.
+ efl_event_callback_add(obj, EFL_TEXT_INTERACTIVE_EVENT_CHANGED_USER,
+ _efl_ui_textbox_property_bind_changed_user_cb, NULL);
efl_event_callback_forwarder_add(text_obj, EFL_TEXT_INTERACTIVE_EVENT_HAVE_SELECTION_CHANGED, obj);
efl_event_callback_forwarder_add(text_obj, EFL_TEXT_INTERACTIVE_EVENT_SELECTION_CHANGED, obj);
efl_event_callback_forwarder_add(text_obj, EFL_TEXT_INTERACTIVE_EVENT_REDO_REQUEST, obj);
@@ -3224,6 +3228,13 @@ _efl_ui_textbox_changed_user_cb(void *data, const Efl_Event *event)
_decoration_defer_all(obj);
}
+static void
+_efl_ui_textbox_property_bind_changed_user_cb(void *data EINA_UNUSED, const Efl_Event *event)
+{
+ if (efl_invalidated_get(event->object)) return;
+ _efl_ui_property_bind_user_changed(event->object, "text");
+}
+
static void
_efl_ui_textbox_cursor_changed_cb(void *data, const Efl_Event *event EINA_UNUSED)
{
diff --git a/src/lib/elementary/efl_ui_widget.c b/src/lib/elementary/efl_ui_widget.c
index 8a9efeb8c5..915d46c9ef 100644
--- a/src/lib/elementary/efl_ui_widget.c
+++ b/src/lib/elementary/efl_ui_widget.c
@@ -5897,8 +5897,26 @@ _efl_ui_property_bind_get(Eo *obj, Efl_Ui_Widget_Data *pd, Efl_Ui_Property_Bound
return;
}
- target = prop->part ? efl_part(obj, prop->part) : obj;
+ /* The model tells about every set, including the one this widget made
+ when the user edited it. Setting again what the widget already holds
+ is not harmless: a text is cleared and rebuilt, which loses the cursor,
+ the selection and the markup the user is working in. */
+ {
+ /* efl_part() hands out one object for one use: ask again for each. */
+ Eina_Value current = efl_property_reflection_get(prop->part ? efl_part(obj, prop->part) : obj,
+ prop->key);
+ Eina_Bool same = (eina_value_type_get(¤t) == eina_value_type_get(value)) &&
+ (eina_value_compare(¤t, value) == 0);
+ eina_value_flush(¤t);
+ if (same)
+ {
+ eina_value_free(value);
+ return;
+ }
+ }
+
+ target = prop->part ? efl_part(obj, prop->part) : obj;
err = efl_property_reflection_set(target, prop->key, eina_value_reference_copy(value));
eina_value_free(value);
@@ -6105,7 +6123,9 @@ _efl_ui_property_bind(Eo *widget, Eo *target, Efl_Ui_Widget_Data *pd,
prop->property = eina_stringshare_add(property);
eina_hash_direct_add(pd->properties.model_lookup, prop->property, prop);
- eina_hash_direct_add(pd->properties.view_lookup, prop->key, prop);
+ // Only the widget itself raises properties,changed, never its parts.
+ if (!prop->part)
+ eina_hash_direct_add(pd->properties.view_lookup, prop->key, prop);
_efl_ui_property_bind_get(widget, pd, prop);
diff --git a/src/lib/elementary/elm_priv.h b/src/lib/elementary/elm_priv.h
index 5a3fab04a8..32aa36b1fa 100644
--- a/src/lib/elementary/elm_priv.h
+++ b/src/lib/elementary/elm_priv.h
@@ -1080,4 +1080,33 @@ void _drop_event_unregister(Eo *obj);
void _register_selection_changed(Efl_Ui_Selection *selection);
Efl_Ui_Win* efl_ui_win_get(Evas_Object *obj);
+/*
+ * Tells whoever is bound to @p property of @p obj that the user changed it.
+ *
+ * It raises Efl.Ui.Property_Bind's properties,changed, which Efl.Ui.Widget
+ * turns into an efl_model_property_set() on the bound model. Call it last
+ * on the path a user interaction takes, once the new value is readable from
+ * @p obj and only if it really changed -- never from a setter, or a value
+ * the model just handed over would be written straight back to it. A
+ * handler may delete @p obj: touch nothing of it afterward.
+ *
+ * @p property is the object's own property name: the key given to
+ * efl_ui_property_bind().
+ */
+static inline void
+_efl_ui_property_bind_user_changed(Eo *obj, const char *property)
+{
+ Efl_Ui_Property_Event evt;
+
+ if (!efl_event_callback_count(obj, EFL_UI_PROPERTY_BIND_EVENT_PROPERTIES_CHANGED))
+ return;
+
+ evt.changed_properties = eina_array_new(1);
+ if (!evt.changed_properties) return;
+ eina_array_push(evt.changed_properties, eina_stringshare_add(property));
+ efl_event_callback_call(obj, EFL_UI_PROPERTY_BIND_EVENT_PROPERTIES_CHANGED, &evt);
+ eina_stringshare_del(eina_array_pop(evt.changed_properties));
+ eina_array_free(evt.changed_properties);
+}
+
#endif
diff --git a/src/tests/elementary/efl_ui_suite.c b/src/tests/elementary/efl_ui_suite.c
index d714b2eb7b..11adc9d70b 100644
--- a/src/tests/elementary/efl_ui_suite.c
+++ b/src/tests/elementary/efl_ui_suite.c
@@ -28,6 +28,7 @@ static const Efl_Test_Case etc[] = {
{ "efl_ui_widget", efl_ui_test_widget },
{ "efl_ui_spotlight", efl_ui_test_spotlight},
{ "efl_ui_check", efl_ui_test_check },
+ { "efl_ui_property_bind", efl_ui_test_property_bind },
{ "efl_ui_popup", efl_ui_test_popup },
{ "efl_ui_progressbar", efl_ui_test_progressbar },
{ "efl_ui_radio_group", efl_ui_test_radio_group },
diff --git a/src/tests/elementary/efl_ui_suite.h b/src/tests/elementary/efl_ui_suite.h
index 015ff15f1d..3c57b063e2 100644
--- a/src/tests/elementary/efl_ui_suite.h
+++ b/src/tests/elementary/efl_ui_suite.h
@@ -38,6 +38,7 @@ void efl_ui_model(TCase *tc);
void efl_ui_test_widget(TCase *tc);
void efl_ui_test_spotlight(TCase *tc);
void efl_ui_test_check(TCase *tc);
+void efl_ui_test_property_bind(TCase *tc);
void efl_ui_test_progressbar(TCase *tc);
void efl_ui_test_radio_group(TCase *tc);
void efl_ui_test_slider(TCase *tc);
diff --git a/src/tests/elementary/efl_ui_test_property_bind.c b/src/tests/elementary/efl_ui_test_property_bind.c
new file mode 100644
index 0000000000..65fd898366
--- /dev/null
+++ b/src/tests/elementary/efl_ui_test_property_bind.c
@@ -0,0 +1,590 @@
+#ifdef HAVE_CONFIG_H
+# include "elementary_config.h"
+#endif
+
+#include <Efl_Ui.h>
+#include <Elementary.h>
+#include "efl_ui_suite.h"
+
+/* A widget bound to a property of its model must write what the user did
+ * back to that model, and must not do it for what the model told it. */
+
+static Eo *
+_model_new(const char *property, Eina_Value *value)
+{
+ Eo *model = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
+ Eina_Future *f;
+
+ ck_assert_ptr_ne(model, NULL);
+ f = efl_model_property_set(model, property, value);
+ eina_future_cancel(f);
+ return model;
+}
+
+static void
+_model_set(Eo *model, const char *property, Eina_Value *value)
+{
+ eina_future_cancel(efl_model_property_set(model, property, value));
+}
+
+static Eina_Value *
+_model_get(Eo *model, const char *property)
+{
+ Eina_Value *value = efl_model_property_get(model, property);
+
+ ck_assert_ptr_ne(value, NULL);
+ return value;
+}
+
+static unsigned int model_changes;
+
+static void
+_model_changed(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
+{
+ model_changes++;
+}
+
+static Eo *
+_window(void)
+{
+ Eo *win = win_add(NULL, "win", EFL_UI_WIN_TYPE_BASIC);
+
+ efl_gfx_entity_size_set(win, EINA_SIZE2D(400, 200));
+ return win;
+}
+
+EFL_START_TEST(textbox_user_edit_reaches_the_model)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("t", eina_value_string_new("Hello"));
+ Eo *txt;
+ Eina_Value *v;
+ char *s;
+
+ txt = efl_add(EFL_UI_TEXTBOX_CLASS, win,
+ efl_ui_view_model_set(efl_added, model),
+ efl_ui_property_bind(efl_added, "text", "t"),
+ efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(300, 100)));
+ ck_assert_str_eq(efl_text_get(txt), "Hello");
+
+ efl_gfx_entity_visible_set(txt, EINA_TRUE);
+ efl_ui_focus_util_focus(txt);
+ efl_text_cursor_object_move(efl_text_interactive_main_cursor_get(txt),
+ EFL_TEXT_CURSOR_MOVE_TYPE_LAST);
+ evas_event_feed_key_down(evas_object_evas_get(txt), "s", "s", "s", "s", time(NULL), NULL);
+ ecore_main_loop_iterate();
+ ck_assert_str_eq(efl_text_get(txt), "Hellos");
+
+ v = _model_get(model, "t");
+ ck_assert_ptr_eq(eina_value_type_get(v), EINA_VALUE_TYPE_STRING);
+ s = eina_value_to_string(v);
+ ck_assert_str_eq(s, "Hellos");
+ free(s);
+ eina_value_free(v);
+}
+EFL_END_TEST
+
+EFL_START_TEST(textbox_model_change_does_not_loop)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("t", eina_value_string_new("one"));
+ Eo *txt;
+
+ txt = efl_add(EFL_UI_TEXTBOX_CLASS, win,
+ efl_ui_view_model_set(efl_added, model),
+ efl_ui_property_bind(efl_added, "text", "t"));
+ model_changes = 0;
+ efl_event_callback_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+
+ _model_set(model, "t", eina_value_string_new("two"));
+ ecore_main_loop_iterate();
+
+ ck_assert_str_eq(efl_text_get(txt), "two");
+ // Only the set made above: the widget must not have answered the model.
+ ck_assert_uint_eq(model_changes, 1);
+ efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+}
+EFL_END_TEST
+
+static Eo *
+_typing_textbox(Eo *win, Eo *model)
+{
+ Eo *txt = efl_add(EFL_UI_TEXTBOX_CLASS, win,
+ efl_ui_view_model_set(efl_added, model),
+ efl_ui_property_bind(efl_added, "text", "t"),
+ efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(300, 100)));
+
+ efl_gfx_entity_visible_set(txt, EINA_TRUE);
+ efl_ui_focus_util_focus(txt);
+ return txt;
+}
+
+static void
+_type_s(Eo *txt)
+{
+ evas_event_feed_key_down(evas_object_evas_get(txt), "s", "s", "s", "s", time(NULL), NULL);
+ ecore_main_loop_iterate();
+}
+
+static void
+_assert_model_text(Eo *model, const char *expected)
+{
+ Eina_Value *v = _model_get(model, "t");
+ char *s = eina_value_to_string(v);
+
+ ck_assert_str_eq(s, expected);
+ free(s);
+ eina_value_free(v);
+}
+
+EFL_START_TEST(textbox_typing_in_the_middle_keeps_the_cursor)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("t", eina_value_string_new("Hello"));
+ Eo *txt = _typing_textbox(win, model);
+ Eo *cur = efl_text_interactive_main_cursor_get(txt);
+
+ efl_text_cursor_object_position_set(cur, 2);
+ _type_s(txt);
+ ck_assert_str_eq(efl_text_get(txt), "Hesllo");
+ ck_assert_int_eq(efl_text_cursor_object_position_get(cur), 3);
+ _assert_model_text(model, "Hesllo");
+}
+EFL_END_TEST
+
+EFL_START_TEST(textbox_typing_at_the_start_keeps_the_cursor)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("t", eina_value_string_new("Hello"));
+ Eo *txt = _typing_textbox(win, model);
+ Eo *cur = efl_text_interactive_main_cursor_get(txt);
+
+ efl_text_cursor_object_position_set(cur, 0);
+ _type_s(txt);
+ ck_assert_str_eq(efl_text_get(txt), "sHello");
+ ck_assert_int_eq(efl_text_cursor_object_position_get(cur), 1);
+ _assert_model_text(model, "sHello");
+}
+EFL_END_TEST
+
+EFL_START_TEST(textbox_typing_keeps_the_selection)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("t", eina_value_string_new("Hello"));
+ Eo *txt = _typing_textbox(win, model);
+ Eo *start, *end;
+
+ efl_text_interactive_all_select(txt);
+ // Typing over a selection replaces it; select again afterwards to see the echo leave it alone.
+ _type_s(txt);
+ ck_assert_str_eq(efl_text_get(txt), "s");
+ _assert_model_text(model, "s");
+
+ efl_text_interactive_all_select(txt);
+ efl_text_interactive_selection_cursors_get(txt, &start, &end);
+ _model_set(model, "t", eina_value_string_new("s"));
+ ck_assert(efl_text_interactive_have_selection_get(txt));
+ ck_assert_int_eq(efl_text_cursor_object_position_get(end)
+ - efl_text_cursor_object_position_get(start), 1);
+}
+EFL_END_TEST
+
+EFL_START_TEST(textbox_cut_reaches_the_model)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("t", eina_value_string_new("Hello"));
+ Eo *txt = _typing_textbox(win, model);
+
+ efl_text_interactive_all_select(txt);
+ efl_ui_textbox_selection_cut(txt);
+ ecore_main_loop_iterate();
+ ck_assert_str_eq(efl_text_get(txt), "");
+ _assert_model_text(model, "");
+}
+EFL_END_TEST
+
+EFL_START_TEST(textbox_paste_reaches_the_model)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("t", eina_value_string_new("Hello"));
+ Eo *txt = _typing_textbox(win, model);
+ int i;
+
+ efl_text_interactive_all_select(txt);
+ efl_ui_textbox_selection_copy(txt);
+ efl_text_interactive_all_unselect(txt);
+ efl_text_cursor_object_move(efl_text_interactive_main_cursor_get(txt),
+ EFL_TEXT_CURSOR_MOVE_TYPE_LAST);
+ efl_ui_textbox_selection_paste(txt);
+ // The clipboard answers from the loop.
+ for (i = 0; (i < 50) && strcmp(efl_text_get(txt), "HelloHello"); i++)
+ ecore_main_loop_iterate();
+ ck_assert_str_eq(efl_text_get(txt), "HelloHello");
+ _assert_model_text(model, "HelloHello");
+}
+EFL_END_TEST
+
+EFL_START_TEST(part_binding_does_not_swallow_the_widget_write_back)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("t", eina_value_string_new("Hello"));
+ Eo *txt;
+
+ eina_future_cancel(efl_model_property_set(model, "hint", eina_value_string_new("Type here")));
+ txt = efl_add(EFL_UI_TEXTBOX_CLASS, win,
+ efl_ui_view_model_set(efl_added, model),
+ efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(300, 100)));
+ // The part is bound first: it must not take the widget's key.
+ ck_assert_int_eq(efl_ui_property_bind(efl_part(txt, "efl.text_guide"), "text", "hint"), 0);
+ ck_assert_int_eq(efl_ui_property_bind(txt, "text", "t"), 0);
+ efl_gfx_entity_visible_set(txt, EINA_TRUE);
+ efl_ui_focus_util_focus(txt);
+ efl_text_cursor_object_move(efl_text_interactive_main_cursor_get(txt),
+ EFL_TEXT_CURSOR_MOVE_TYPE_LAST);
+ _type_s(txt);
+ _assert_model_text(model, "Hellos");
+}
+EFL_END_TEST
+
+EFL_START_TEST(check_click_reaches_the_model)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("on", eina_value_bool_new(EINA_FALSE));
+ Eo *check;
+ Eina_Value *v;
+ Eina_Bool b = EINA_FALSE;
+
+ check = efl_add(EFL_UI_CHECK_CLASS, win,
+ efl_ui_view_model_set(efl_added, model),
+ efl_ui_property_bind(efl_added, "selected", "on"),
+ efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(100, 50)));
+ efl_gfx_entity_visible_set(check, EINA_TRUE);
+ ck_assert(!efl_ui_selectable_selected_get(check));
+
+ click_object(check);
+ ecore_main_loop_iterate();
+ ck_assert(efl_ui_selectable_selected_get(check));
+ v = _model_get(model, "on");
+ ck_assert_ptr_eq(eina_value_type_get(v), EINA_VALUE_TYPE_UCHAR);
+ eina_value_bool_get(v, &b);
+ ck_assert(b);
+ eina_value_free(v);
+
+ click_object(check);
+ ecore_main_loop_iterate();
+ v = _model_get(model, "on");
+ eina_value_bool_get(v, &b);
+ ck_assert(!b);
+ eina_value_free(v);
+}
+EFL_END_TEST
+
+EFL_START_TEST(check_model_change_does_not_loop)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("on", eina_value_bool_new(EINA_FALSE));
+ Eo *check;
+
+ check = efl_add(EFL_UI_CHECK_CLASS, win,
+ efl_ui_view_model_set(efl_added, model),
+ efl_ui_property_bind(efl_added, "selected", "on"));
+ model_changes = 0;
+ efl_event_callback_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+
+ _model_set(model, "on", eina_value_bool_new(EINA_TRUE));
+ ecore_main_loop_iterate();
+ ck_assert(efl_ui_selectable_selected_get(check));
+ ck_assert_uint_eq(model_changes, 1);
+ efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+}
+EFL_END_TEST
+
+EFL_START_TEST(slider_key_reaches_the_model)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("level", eina_value_double_new(0.5));
+ Eo *slider;
+ Eina_Value *v;
+ double d = 0;
+
+ slider = efl_add(EFL_UI_SLIDER_CLASS, win,
+ efl_ui_view_model_set(efl_added, model),
+ efl_ui_property_bind(efl_added, "range_value", "level"),
+ efl_ui_range_limits_set(efl_added, 0.0, 1.0),
+ efl_ui_range_step_set(efl_added, 0.1),
+ efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(300, 50)));
+ efl_gfx_entity_visible_set(slider, EINA_TRUE);
+ ck_assert(EINA_DBL_EQ(efl_ui_range_value_get(slider), 0.5));
+ efl_ui_focus_util_focus(slider);
+
+ evas_event_feed_key_down(evas_object_evas_get(slider), "Right", "Right", "", "",
+ time(NULL), NULL);
+ ecore_main_loop_iterate();
+ ck_assert(efl_ui_range_value_get(slider) > 0.55);
+
+ v = _model_get(model, "level");
+ ck_assert_ptr_eq(eina_value_type_get(v), EINA_VALUE_TYPE_DOUBLE);
+ eina_value_double_get(v, &d);
+ ck_assert(EINA_DBL_EQ(d, efl_ui_range_value_get(slider)));
+ eina_value_free(v);
+}
+EFL_END_TEST
+
+EFL_START_TEST(slider_model_change_does_not_loop)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("level", eina_value_double_new(0.5));
+ Eo *slider;
+
+ slider = efl_add(EFL_UI_SLIDER_CLASS, win,
+ efl_ui_view_model_set(efl_added, model),
+ efl_ui_property_bind(efl_added, "range_value", "level"));
+ model_changes = 0;
+ efl_event_callback_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+
+ _model_set(model, "level", eina_value_double_new(0.25));
+ ecore_main_loop_iterate();
+ ck_assert(EINA_DBL_EQ(efl_ui_range_value_get(slider), 0.25));
+ ck_assert_uint_eq(model_changes, 1);
+ efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+}
+EFL_END_TEST
+
+EFL_START_TEST(spin_button_wheel_reaches_the_model)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("count", eina_value_double_new(3.0));
+ Eo *spin;
+ Eina_Value *v;
+ double d = 0;
+ Evas *e;
+
+ spin = efl_add(EFL_UI_SPIN_BUTTON_CLASS, win,
+ efl_ui_view_model_set(efl_added, model),
+ efl_ui_property_bind(efl_added, "range_value", "count"),
+ efl_ui_range_limits_set(efl_added, 0, 10),
+ efl_ui_range_step_set(efl_added, 1),
+ efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(200, 50)));
+ efl_gfx_entity_visible_set(spin, EINA_TRUE);
+ ck_assert(EINA_DBL_EQ(efl_ui_range_value_get(spin), 3.0));
+
+ e = evas_object_evas_get(spin);
+ get_me_to_those_events(spin);
+ evas_event_feed_mouse_in(e, 0, NULL);
+ evas_event_feed_mouse_move(e, 100, 25, 0, NULL);
+ evas_event_feed_mouse_wheel(e, 0, -1, 0, NULL);
+ ecore_main_loop_iterate();
+ ck_assert(!EINA_DBL_EQ(efl_ui_range_value_get(spin), 3.0));
+
+ v = _model_get(model, "count");
+ ck_assert_ptr_eq(eina_value_type_get(v), EINA_VALUE_TYPE_DOUBLE);
+ eina_value_double_get(v, &d);
+ ck_assert(EINA_DBL_EQ(d, efl_ui_range_value_get(spin)));
+ eina_value_free(v);
+}
+EFL_END_TEST
+
+EFL_START_TEST(check_toggle_style_emits_once)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("on", eina_value_bool_new(EINA_FALSE));
+ Eo *check;
+ int i;
+
+ check = efl_add(EFL_UI_CHECK_CLASS, win,
+ efl_ui_widget_style_set(efl_added, "toggle"),
+ efl_ui_view_model_set(efl_added, model),
+ efl_ui_property_bind(efl_added, "selected", "on"),
+ efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(200, 100)));
+ efl_gfx_entity_visible_set(check, EINA_TRUE);
+ for (i = 0; i < 3; i++)
+ {
+ efl_layout_signal_process(check, EINA_TRUE);
+ ecore_main_loop_iterate();
+ }
+
+ model_changes = 0;
+ efl_event_callback_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+ click_object(check);
+ for (i = 0; i < 5; i++)
+ {
+ efl_layout_signal_process(check, EINA_TRUE);
+ ecore_main_loop_iterate();
+ }
+ ck_assert(efl_ui_selectable_selected_get(check));
+ ck_assert_uint_eq(model_changes, 1);
+ efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+}
+EFL_END_TEST
+
+EFL_START_TEST(slider_refused_value_does_not_reach_the_model)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("level", eina_value_double_new(1.0));
+ Eo *slider;
+
+ slider = efl_add(EFL_UI_SLIDER_CLASS, win,
+ efl_ui_view_model_set(efl_added, model),
+ efl_ui_property_bind(efl_added, "range_value", "level"),
+ efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(300, 50)));
+ efl_gfx_entity_visible_set(slider, EINA_TRUE);
+ efl_ui_focus_util_focus(slider);
+ ck_assert(EINA_DBL_EQ(efl_ui_range_value_get(slider), 1.0));
+
+ model_changes = 0;
+ efl_event_callback_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+ // Already at the maximum: the key moves nothing.
+ evas_event_feed_key_down(evas_object_evas_get(slider), "Right", "Right", "", "",
+ time(NULL), NULL);
+ ecore_main_loop_iterate();
+ ck_assert_uint_eq(model_changes, 0);
+ efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+}
+EFL_END_TEST
+
+static Eo *
+_spin_button(Eo *win, Eo *model)
+{
+ Eo *spin = efl_add(EFL_UI_SPIN_BUTTON_CLASS, win,
+ efl_ui_view_model_set(efl_added, model),
+ efl_ui_property_bind(efl_added, "range_value", "count"),
+ efl_ui_range_limits_set(efl_added, 0, 10),
+ efl_ui_range_step_set(efl_added, 1),
+ efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(200, 50)));
+
+ efl_gfx_entity_visible_set(spin, EINA_TRUE);
+ return spin;
+}
+
+static double
+_model_double(Eo *model, const char *property)
+{
+ Eina_Value *v = _model_get(model, property);
+ double d = -1;
+
+ eina_value_double_get(v, &d);
+ eina_value_free(v);
+ return d;
+}
+
+EFL_START_TEST(spin_button_model_change_does_not_loop)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("count", eina_value_double_new(3.0));
+ Eo *spin = _spin_button(win, model);
+
+ model_changes = 0;
+ efl_event_callback_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+ _model_set(model, "count", eina_value_double_new(7.0));
+ ecore_main_loop_iterate();
+ ck_assert(EINA_DBL_EQ(efl_ui_range_value_get(spin), 7.0));
+ ck_assert_uint_eq(model_changes, 1);
+ efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+}
+EFL_END_TEST
+
+static Eo *
+_open_entry(Eo *spin)
+{
+ Eo *entry;
+
+ efl_ui_spin_button_direct_text_input_set(spin, EINA_TRUE);
+ efl_ui_focus_util_focus(efl_content_get(efl_part(spin, "efl.text_button")));
+ get_me_to_those_events(spin);
+ entry = efl_content_get(efl_part(spin, "efl.entry"));
+ ck_assert_ptr_ne(entry, NULL);
+ efl_ui_focus_util_focus(entry);
+ get_me_to_those_events(spin);
+ return entry;
+}
+
+static void
+_leave_entry(Eo *spin)
+{
+ efl_ui_focus_util_focus(efl_content_get(efl_part(spin, "efl.inc_button")));
+ get_me_to_those_events(spin);
+}
+
+EFL_START_TEST(spin_button_entry_reaches_the_model)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("count", eina_value_double_new(3.0));
+ Eo *spin = _spin_button(win, model);
+ Eo *entry;
+
+ get_me_to_those_events(spin);
+ entry = _open_entry(spin);
+ elm_object_text_set(entry, "");
+ write_key_sequence(spin, "8");
+ get_me_to_those_events(spin);
+ _leave_entry(spin);
+ ck_assert_msg(EINA_DBL_EQ(efl_ui_range_value_get(spin), 8.0), "value %f entry %s",
+ efl_ui_range_value_get(spin), elm_object_text_get(entry));
+ ck_assert(EINA_DBL_EQ(_model_double(model, "count"), 8.0));
+}
+EFL_END_TEST
+
+EFL_START_TEST(spin_button_stale_entry_is_not_written_back)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("count", eina_value_double_new(3.0));
+ Eo *spin = _spin_button(win, model);
+
+ get_me_to_those_events(spin);
+ _open_entry(spin);
+ // The model moves on while the entry shows the value it opened with.
+ _model_set(model, "count", eina_value_double_new(7.0));
+ ecore_main_loop_iterate();
+ _leave_entry(spin);
+ ck_assert(EINA_DBL_EQ(efl_ui_range_value_get(spin), 7.0));
+ ck_assert(EINA_DBL_EQ(_model_double(model, "count"), 7.0));
+}
+EFL_END_TEST
+
+EFL_START_TEST(radio_click_reaches_the_model)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("on", eina_value_bool_new(EINA_FALSE));
+ Eo *radio;
+ Eina_Value *v;
+ Eina_Bool b = EINA_FALSE;
+
+ radio = efl_add(EFL_UI_RADIO_CLASS, win,
+ efl_ui_view_model_set(efl_added, model),
+ efl_ui_property_bind(efl_added, "selected", "on"),
+ efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(100, 50)));
+ efl_gfx_entity_visible_set(radio, EINA_TRUE);
+
+ click_object(radio);
+ ecore_main_loop_iterate();
+ ck_assert(efl_ui_selectable_selected_get(radio));
+ v = _model_get(model, "on");
+ eina_value_bool_get(v, &b);
+ eina_value_free(v);
+ ck_assert(b);
+}
+EFL_END_TEST
+
+void
+efl_ui_test_property_bind(TCase *tc)
+{
+ tcase_add_test(tc, textbox_user_edit_reaches_the_model);
+ tcase_add_test(tc, textbox_model_change_does_not_loop);
+ tcase_add_test(tc, textbox_typing_in_the_middle_keeps_the_cursor);
+ tcase_add_test(tc, textbox_typing_at_the_start_keeps_the_cursor);
+ tcase_add_test(tc, textbox_typing_keeps_the_selection);
+ tcase_add_test(tc, textbox_cut_reaches_the_model);
+ tcase_add_test(tc, textbox_paste_reaches_the_model);
+ tcase_add_test(tc, part_binding_does_not_swallow_the_widget_write_back);
+ tcase_add_test(tc, check_toggle_style_emits_once);
+ tcase_add_test(tc, slider_refused_value_does_not_reach_the_model);
+ tcase_add_test(tc, spin_button_model_change_does_not_loop);
+ tcase_add_test(tc, spin_button_entry_reaches_the_model);
+ tcase_add_test(tc, spin_button_stale_entry_is_not_written_back);
+ tcase_add_test(tc, radio_click_reaches_the_model);
+ tcase_add_test(tc, check_click_reaches_the_model);
+ tcase_add_test(tc, check_model_change_does_not_loop);
+ tcase_add_test(tc, slider_key_reaches_the_model);
+ tcase_add_test(tc, slider_model_change_does_not_loop);
+ tcase_add_test(tc, spin_button_wheel_reaches_the_model);
+}
diff --git a/src/tests/elementary/meson.build b/src/tests/elementary/meson.build
index 2c287760b5..9e765832f7 100644
--- a/src/tests/elementary/meson.build
+++ b/src/tests/elementary/meson.build
@@ -154,6 +154,7 @@ efl_ui_suite_src = [
'efl_ui_test_widget.c',
'efl_ui_test_spotlight.c',
'efl_ui_test_check.c',
+ 'efl_ui_test_property_bind.c',
'efl_ui_test_radio_group.c',
'efl_ui_test_progressbar.c',
'efl_ui_test_spin.c',
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.