This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch eolian/improvements
in repository efl.

View the commit online.

commit 4aae9eb50005f6d2da099e09aaa90b1dab52705c
Author: [email protected] <[email protected]>
AuthorDate: Thu Oct 29 22:47:06 2026 -0600

    elementary: Widget.style and Layout_Base.theme are construction only, legacy keeps changing them
    
    The EOAPI efl_ui_widget_style_set and efl_ui_layout_theme_set now
    refuse after finalize for every object, legacy ones included (before,
    legacy objects were let through). A refused call returns EPERM.
    
    Legacy elm_object_style_set and elm_layout_theme_set reach the
    implementation through the internal _elm_widget_style_set and
    _elm_layout_theme_set instead. They keep working on legacy widgets,
    which have always been able to change these at any time, and still
    refuse unified ones.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_layout.c           | 40 ++++++++++++++-----
 src/lib/elementary/efl_ui_layout_base.eo     |  6 ++-
 src/lib/elementary/efl_ui_widget.c           | 28 +++++++++++--
 src/lib/elementary/efl_ui_widget.eo          |  5 +--
 src/lib/elementary/efl_ui_widget_eo.legacy.c |  2 +-
 src/lib/elementary/elm_priv.h                |  6 +++
 src/tests/elementary/efl_ui_test_widget.c    | 59 ++++++++++++++++++++++++++++
 7 files changed, 127 insertions(+), 19 deletions(-)

diff --git a/src/lib/elementary/efl_ui_layout.c b/src/lib/elementary/efl_ui_layout.c
index 59a3f14012..d04a6b395b 100644
--- a/src/lib/elementary/efl_ui_layout.c
+++ b/src/lib/elementary/efl_ui_layout.c
@@ -1187,17 +1187,11 @@ _efl_ui_layout_base_theme_get(const Eo *obj, Efl_Ui_Layout_Data *sd EINA_UNUSED,
    if (style) *style = elm_widget_theme_style_get(obj);
 }
 
-EOLIAN static Eina_Error
-_efl_ui_layout_base_theme_set(Eo *obj, Efl_Ui_Layout_Data *sd, const char *klass, const char *group, const char *style)
+static Eina_Error
+_layout_theme_apply(Eo *obj, Efl_Ui_Layout_Data *sd, const char *klass, const char *group, const char *style)
 {
    Eina_Bool changed = EINA_FALSE;
 
-   if (!elm_widget_is_legacy(obj) && efl_finalized_get(obj))
-     {
-        ERR("Efl.Ui.Layout_theme can only be set before finalize!");
-        return EFL_UI_THEME_APPLY_ERROR_GENERIC;
-     }
-
    if (sd->file_set) sd->file_set = EINA_FALSE;
 
    changed |= elm_widget_theme_klass_set(obj, klass);
@@ -1209,6 +1203,34 @@ _efl_ui_layout_base_theme_set(Eo *obj, Efl_Ui_Layout_Data *sd, const char *klass
    return EFL_UI_THEME_APPLY_ERROR_NONE;
 }
 
+/* Efl.Ui.Layout_Base.theme is construction only: the generated EOAPI refuses
+ * it once the object is finalized, so this is only reached before that. */
+EOLIAN static Eina_Error
+_efl_ui_layout_base_theme_set(Eo *obj, Efl_Ui_Layout_Data *sd, const char *klass, const char *group, const char *style)
+{
+   return _layout_theme_apply(obj, sd, klass, group, style);
+}
+
+/* The entry point of the legacy and internal callers (elm_layout_theme_set).
+ * It does not go through the guarded EOAPI, because a legacy layout has
+ * always been able to change its theme at any time. A unified layout keeps
+ * the rule and refuses once finalized. */
+Eina_Error
+_elm_layout_theme_set(Eo *obj, const char *klass, const char *group, const char *style)
+{
+   Efl_Ui_Layout_Data *sd = efl_data_scope_safe_get(obj, MY_CLASS);
+
+   if (!sd) return EFL_UI_THEME_APPLY_ERROR_GENERIC;
+
+   if (!elm_widget_is_legacy(obj) && efl_finalized_get(obj))
+     {
+        ERR("Efl.Ui.Layout_Base.theme can only be set before finalize!");
+        return EFL_UI_THEME_APPLY_ERROR_GENERIC;
+     }
+
+   return _layout_theme_apply(obj, sd, klass, group, style);
+}
+
 EOLIAN static void
 _efl_ui_layout_base_efl_layout_signal_signal_emit(Eo *obj, Efl_Ui_Layout_Data *_pd EINA_UNUSED, const char *emission, const char *source)
 {
@@ -3758,7 +3780,7 @@ elm_layout_theme_set(Evas_Object *obj, const char *klass, const char *group, con
 {
    Eina_Error theme_apply_ret;
 
-   theme_apply_ret = efl_ui_layout_theme_set(obj, klass, group, style);
+   theme_apply_ret = _elm_layout_theme_set(obj, klass, group, style);
    return (theme_apply_ret != EFL_UI_THEME_APPLY_ERROR_GENERIC);
 }
 
diff --git a/src/lib/elementary/efl_ui_layout_base.eo b/src/lib/elementary/efl_ui_layout_base.eo
index c1b70e99b5..440f625031 100644
--- a/src/lib/elementary/efl_ui_layout_base.eo
+++ b/src/lib/elementary/efl_ui_layout_base.eo
@@ -54,8 +54,7 @@ abstract Efl.Ui.Layout_Base extends Efl.Ui.Widget implements Efl.Container,
            you are dealing directly with a @Efl.Ui.Layout object.
 
            Note that $style will be the new style of this object, as retrieved by
-           @Efl.Ui.Widget.style. As a consequence this function can only be
-           called during construction of the object, before finalize.
+           @Efl.Ui.Widget.style.
 
            If this returns $false the widget is very likely to become non-functioning.
          ]]
@@ -102,6 +101,9 @@ abstract Efl.Ui.Layout_Base extends Efl.Ui.Widget implements Efl.Container,
         }
       }
    }
+   constructors {
+      .theme @optional @construct_only;
+   }
    implements {
       class.constructor;
       class.destructor;
diff --git a/src/lib/elementary/efl_ui_widget.c b/src/lib/elementary/efl_ui_widget.c
index 8db447f20c..820230b2a6 100644
--- a/src/lib/elementary/efl_ui_widget.c
+++ b/src/lib/elementary/efl_ui_widget.c
@@ -2626,19 +2626,39 @@ elm_widget_theme_get(const Evas_Object *obj)
    return sd->theme;
 }
 
+static Eina_Error
+_widget_style_apply(Eo *obj, Elm_Widget_Smart_Data *sd, const char *style)
+{
+   if (eina_stringshare_replace(&sd->style, style))
+      return elm_widget_theme(obj);
+
+   return EFL_UI_THEME_APPLY_ERROR_NONE;
+}
+
+/* Efl.Ui.Widget.style is construction only: the generated EOAPI refuses it
+ * once the object is finalized, so this is only reached before that. */
 EOLIAN static Eina_Error
 _efl_ui_widget_style_set(Eo *obj, Elm_Widget_Smart_Data *sd, const char *style)
 {
+   return _widget_style_apply(obj, sd, style);
+}
+
+/* The entry point of the legacy and internal callers (elm_widget_style_set,
+ * elm_object_style_set). It does not go through the guarded EOAPI, because a
+ * legacy widget has always been able to change its style at any time. A
+ * unified widget keeps the rule and refuses once finalized. */
+Eina_Error
+_elm_widget_style_set(Eo *obj, const char *style)
+{
+   ELM_WIDGET_DATA_GET_OR_RETURN(obj, sd, EFL_UI_THEME_APPLY_ERROR_GENERIC);
+
    if (!elm_widget_is_legacy(obj) && efl_finalized_get(obj))
      {
         ERR("Efl.Ui.Widget.style can only be set before finalize!");
         return EFL_UI_THEME_APPLY_ERROR_GENERIC;
      }
 
-   if (eina_stringshare_replace(&sd->style, style))
-      return elm_widget_theme(obj);
-
-   return EFL_UI_THEME_APPLY_ERROR_NONE;
+   return _widget_style_apply(obj, sd, style);
 }
 
 EOLIAN static const char*
diff --git a/src/lib/elementary/efl_ui_widget.eo b/src/lib/elementary/efl_ui_widget.eo
index a4816eb3d5..6de83afa23 100644
--- a/src/lib/elementary/efl_ui_widget.eo
+++ b/src/lib/elementary/efl_ui_widget.eo
@@ -128,8 +128,7 @@ abstract Efl.Ui.Widget extends Efl.Canvas.Group implements Efl.Access.Object,
            to widget and may be defined by other themes by means of extensions
            and overlays.
 
-           The style can only be set before @Efl.Object.finalize, which means
-           at construction time of the object (inside $efl_add in C).
+           In C this is set inside $efl_add().
          ]]
          set {
             return: Eina.Error;
@@ -424,7 +423,7 @@ abstract Efl.Ui.Widget extends Efl.Canvas.Group implements Efl.Access.Object,
       Efl.Ui.Property_Bind.property_bind;
    }
    constructors {
-      .style @optional;
+      .style @optional @construct_only;
    }
    events {
       language,changed @beta: void; [[Called when widget language changed]]
diff --git a/src/lib/elementary/efl_ui_widget_eo.legacy.c b/src/lib/elementary/efl_ui_widget_eo.legacy.c
index 0d1665bea0..ce853d1f20 100644
--- a/src/lib/elementary/efl_ui_widget_eo.legacy.c
+++ b/src/lib/elementary/efl_ui_widget_eo.legacy.c
@@ -20,7 +20,7 @@ elm_widget_disabled_get(const Efl_Ui_Widget *obj)
 EAPI Eina_Error
 elm_widget_style_set(Efl_Ui_Widget *obj, const char *style)
 {
-   return efl_ui_widget_style_set(obj, style);
+   return _elm_widget_style_set(obj, style);
 }
 
 EAPI const char *
diff --git a/src/lib/elementary/elm_priv.h b/src/lib/elementary/elm_priv.h
index d7d8b6a80a..976b175250 100644
--- a/src/lib/elementary/elm_priv.h
+++ b/src/lib/elementary/elm_priv.h
@@ -966,6 +966,12 @@ void   _elm_entry_entry_paste(Evas_Object *obj, const char *entry);
 double _elm_atof(const char *s);
 
 void _elm_layout_legacy_icon_signal_emit(Evas_Object *obj);
+/* Legacy and internal way to set the style of a widget or the theme of a
+ * layout. The EOAPI efl_ui_widget_style_set and efl_ui_layout_theme_set are
+ * construction only; these also work after finalize on a legacy widget, and
+ * refuse it on a unified one. */
+Eina_Error _elm_widget_style_set(Eo *obj, const char *style);
+Eina_Error _elm_layout_theme_set(Eo *obj, const char *klass, const char *group, const char *style);
 // elm_layout and elm_entry LEGACY signal API (returned the user data pointer)
 void _elm_layout_signal_callback_add_legacy(Eo *obj, Eo *edje, Eina_List **p_edje_signals, const char *emission, const char *source, Edje_Signal_Cb func, void *data);
 Eina_Bool _elm_layout_signal_proxy_add(Eo *obj, Eo *edje, Eina_List **proxies, const char *emission, const char *source, void *func_data, EflLayoutSignalCb func, Eina_Free_Cb func_free_cb);
diff --git a/src/tests/elementary/efl_ui_test_widget.c b/src/tests/elementary/efl_ui_test_widget.c
index 1eeac1d237..b08966987b 100644
--- a/src/tests/elementary/efl_ui_test_widget.c
+++ b/src/tests/elementary/efl_ui_test_widget.c
@@ -547,12 +547,71 @@ EFL_START_TEST(efl_ui_test_widget_enum_reflection)
 }
 EFL_END_TEST
 
+/* Efl.Ui.Widget.style and Efl.Ui.Layout_Base.theme are construction only for
+ * the unified API, while the legacy Elementary API has always been able to
+ * change them at any time. */
+EFL_START_TEST(efl_ui_test_widget_style_construct_only)
+{
+   Efl_Ui_Widget *win, *btn, *lay;
+   Eina_Error err;
+
+   win = win_add(NULL, "widget", EFL_UI_WIN_TYPE_BASIC);
+
+   /* unified: given at construction it sticks */
+   btn = efl_add(EFL_UI_BUTTON_CLASS, win,
+                 err = efl_ui_widget_style_set(efl_added, "anchor"));
+   ck_assert_int_eq(err, EFL_UI_THEME_APPLY_ERROR_NONE);
+   ck_assert_str_eq(efl_ui_widget_style_get(btn), "anchor");
+
+   /* refused once finalized, through the Eo API and the legacy functions
+    * alike, because the widget is a unified one */
+   EXPECT_ERROR_START;
+   err = efl_ui_widget_style_set(btn, "default");
+   EXPECT_ERROR_END;
+   ck_assert_int_eq(err, EPERM);
+   ck_assert_str_eq(efl_ui_widget_style_get(btn), "anchor");
+
+   EXPECT_ERROR_START;
+   ck_assert(!elm_object_style_set(btn, "default"));
+   EXPECT_ERROR_END;
+   ck_assert_str_eq(efl_ui_widget_style_get(btn), "anchor");
+
+   /* same for the theme of a unified layout */
+   lay = efl_add(EFL_UI_LAYOUT_CLASS, win,
+                 err = efl_ui_layout_theme_set(efl_added, "button", NULL, "anchor"));
+   ck_assert_int_eq(err, EFL_UI_THEME_APPLY_ERROR_NONE);
+   EXPECT_ERROR_START;
+   err = efl_ui_layout_theme_set(lay, "button", NULL, "default");
+   EXPECT_ERROR_END;
+   ck_assert_int_eq(err, EPERM);
+   ck_assert_str_eq(efl_ui_widget_style_get(lay), "anchor");
+
+   /* and the legacy function does not get it past the guard either */
+   EXPECT_ERROR_START;
+   ck_assert(!elm_layout_theme_set(lay, "button", "base", "default"));
+   EXPECT_ERROR_END;
+   ck_assert_str_eq(efl_ui_widget_style_get(lay), "anchor");
+
+   /* legacy: still works after the widget is made */
+   btn = elm_button_add(win);
+   ck_assert(elm_object_style_set(btn, "anchor"));
+   ck_assert_str_eq(elm_object_style_get(btn), "anchor");
+   ck_assert(elm_object_style_set(btn, "default"));
+   ck_assert_str_eq(elm_object_style_get(btn), "default");
+
+   lay = elm_layout_add(win);
+   ck_assert(elm_layout_theme_set(lay, "button", "base", "anchor"));
+   ck_assert_str_eq(elm_object_style_get(lay), "anchor");
+}
+EFL_END_TEST
+
 void efl_ui_test_widget(TCase *tc)
 {
    tcase_add_checked_fixture(tc, fail_on_errors_setup, fail_on_errors_teardown);
    tcase_add_test(tc, efl_ui_test_widget_scroll_hold);
    tcase_add_test(tc, efl_ui_test_widget_scroll_freeze);
    tcase_add_test(tc, efl_ui_test_widget_enum_reflection);
+   tcase_add_test(tc, efl_ui_test_widget_style_construct_only);
    tcase_add_test(tc, efl_ui_test_widget_parent_iterator);
    tcase_add_test(tc, efl_ui_test_widget_widget_iterator);
    tcase_add_test(tc, efl_ui_test_widget_widget_sub_iterator);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to