summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-08-09 16:22:48 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-08-09 18:09:32 +0900
commite2fca6c454c182d4666c2f081697ed6f917ff645 (patch)
tree6c59ecb204378f01a37f72b81ba3bbeffef3d901
parent5d1e959f92e14f1aa45f3c225d8351041125039b (diff)
elm: Prevent style/theme set after finalize (EO)
This is only for EO obviously. style_set and theme_set should only be called when the object is being created, not after. On-the-fly style changes are complex to handle and in most cases it should be easy to simply repopulate the object after creating a new one with a new style. There are only a few cases where style_set is used long after creation of an object, like changing how a label slides, or in the evas 3d map examples. Menu seems to change the hover style a lot, so rewriting it in pure EO would need some extra work, maybe. Ref T5307 Ref T5363
-rw-r--r--src/lib/elementary/efl_ui_layout.c6
-rw-r--r--src/lib/elementary/elc_combobox.c17
-rw-r--r--src/lib/elementary/elm_widget.c15
-rw-r--r--src/lib/elementary/elm_widget.eo2
-rw-r--r--src/lib/elementary/elm_widget.h9
5 files changed, 40 insertions, 9 deletions
diff --git a/src/lib/elementary/efl_ui_layout.c b/src/lib/elementary/efl_ui_layout.c
index ce6a49d88b..e2c7e14384 100644
--- a/src/lib/elementary/efl_ui_layout.c
+++ b/src/lib/elementary/efl_ui_layout.c
@@ -900,6 +900,12 @@ _efl_ui_layout_theme_set(Eo *obj, Efl_Ui_Layout_Data *sd, const char *klass, con
900{ 900{
901 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EINA_FALSE); 901 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EINA_FALSE);
902 902
903 if (!wd->legacy && efl_finalized_get(obj))
904 {
905 ERR("Efl.Ui.Layout.theme can only be set before finalize!");
906 return EFL_UI_THEME_APPLY_FAILED;
907 }
908
903 if (sd->file_set) sd->file_set = EINA_FALSE; 909 if (sd->file_set) sd->file_set = EINA_FALSE;
904 eina_stringshare_replace(&(sd->klass), klass); 910 eina_stringshare_replace(&(sd->klass), klass);
905 eina_stringshare_replace(&(sd->group), group); 911 eina_stringshare_replace(&(sd->group), group);
diff --git a/src/lib/elementary/elc_combobox.c b/src/lib/elementary/elc_combobox.c
index bd745c774d..c8c0d87e2c 100644
--- a/src/lib/elementary/elc_combobox.c
+++ b/src/lib/elementary/elc_combobox.c
@@ -4,6 +4,7 @@
4 4
5#define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED 5#define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED
6#define ELM_INTERFACE_ATSPI_WIDGET_ACTION_PROTECTED 6#define ELM_INTERFACE_ATSPI_WIDGET_ACTION_PROTECTED
7#define ELM_WIDGET_PROTECTED
7 8
8#include <Elementary.h> 9#include <Elementary.h>
9#include "elm_priv.h" 10#include "elm_priv.h"
@@ -354,15 +355,15 @@ _elm_combobox_efl_object_constructor(Eo *obj, Elm_Combobox_Data *sd)
354 //hover-parent 355 //hover-parent
355 sd->hover_parent = elm_object_top_widget_get(obj); 356 sd->hover_parent = elm_object_top_widget_get(obj);
356 357
358 snprintf(buf, sizeof(buf), "combobox_vertical/%s", elm_widget_style_get(obj));
359
357 //hover 360 //hover
358 sd->hover = efl_add(ELM_HOVER_CLASS, sd->hover_parent); 361 sd->hover = efl_add(ELM_HOVER_CLASS, sd->hover_parent,
362 elm_obj_widget_style_set(efl_added, buf));
359 evas_object_layer_set(sd->hover, EVAS_LAYER_MAX); 363 evas_object_layer_set(sd->hover, EVAS_LAYER_MAX);
360 efl_ui_mirrored_automatic_set(sd->hover, EINA_FALSE); 364 efl_ui_mirrored_automatic_set(sd->hover, EINA_FALSE);
361 elm_hover_target_set(sd->hover, obj); 365 elm_hover_target_set(sd->hover, obj);
362 elm_widget_sub_object_add(obj, sd->hover); 366 elm_widget_sub_object_add(obj, sd->hover);
363 snprintf(buf, sizeof(buf), "combobox_vertical/%s",
364 elm_widget_style_get(obj));
365 elm_object_style_set(sd->hover, buf);
366 367
367 efl_event_callback_add 368 efl_event_callback_add
368 (sd->hover, EFL_UI_EVENT_CLICKED, _on_hover_clicked, obj); 369 (sd->hover, EFL_UI_EVENT_CLICKED, _on_hover_clicked, obj);
@@ -382,7 +383,8 @@ _elm_combobox_efl_object_constructor(Eo *obj, Elm_Combobox_Data *sd)
382 elm_table_pack(sd->tbl, sd->spacer, 0, 0, 1, 1); 383 elm_table_pack(sd->tbl, sd->spacer, 0, 0, 1, 1);
383 384
384 // This is the genlist object that will take over the genlist call 385 // This is the genlist object that will take over the genlist call
385 sd->genlist = gl = efl_add(ELM_GENLIST_CLASS, obj); 386 sd->genlist = gl = efl_add(ELM_GENLIST_CLASS, obj,
387 elm_obj_widget_style_set(efl_added, buf));
386 elm_genlist_filter_set(gl, NULL); 388 elm_genlist_filter_set(gl, NULL);
387 efl_ui_mirrored_automatic_set(gl, EINA_FALSE); 389 efl_ui_mirrored_automatic_set(gl, EINA_FALSE);
388 efl_ui_mirrored_set(gl, efl_ui_mirrored_get(obj)); 390 efl_ui_mirrored_set(gl, efl_ui_mirrored_get(obj));
@@ -394,10 +396,10 @@ _elm_combobox_efl_object_constructor(Eo *obj, Elm_Combobox_Data *sd)
394 elm_genlist_homogeneous_set(gl, EINA_TRUE); 396 elm_genlist_homogeneous_set(gl, EINA_TRUE);
395 elm_genlist_mode_set(gl, ELM_LIST_COMPRESS); 397 elm_genlist_mode_set(gl, ELM_LIST_COMPRESS);
396 elm_table_pack(sd->tbl, gl, 0, 0, 1, 1); 398 elm_table_pack(sd->tbl, gl, 0, 0, 1, 1);
397 elm_object_style_set(gl, buf);
398 399
399 // This is the entry object that will take over the entry call 400 // This is the entry object that will take over the entry call
400 sd->entry = entry = efl_add(ELM_ENTRY_CLASS, obj); 401 sd->entry = entry = efl_add(ELM_ENTRY_CLASS, obj,
402 elm_obj_widget_style_set(efl_added, buf));
401 efl_ui_mirrored_automatic_set(entry, EINA_FALSE); 403 efl_ui_mirrored_automatic_set(entry, EINA_FALSE);
402 efl_ui_mirrored_set(entry, efl_ui_mirrored_get(obj)); 404 efl_ui_mirrored_set(entry, efl_ui_mirrored_get(obj));
403 elm_scroller_policy_set(entry, ELM_SCROLLER_POLICY_OFF, 405 elm_scroller_policy_set(entry, ELM_SCROLLER_POLICY_OFF,
@@ -409,7 +411,6 @@ _elm_combobox_efl_object_constructor(Eo *obj, Elm_Combobox_Data *sd)
409 evas_object_show(entry); 411 evas_object_show(entry);
410 412
411 elm_object_part_content_set(obj, "elm.swallow.content", entry); 413 elm_object_part_content_set(obj, "elm.swallow.content", entry);
412 elm_object_style_set(entry, buf);
413 414
414 efl_composite_attach(obj, gl); 415 efl_composite_attach(obj, gl);
415 efl_composite_attach(obj, entry); 416 efl_composite_attach(obj, entry);
diff --git a/src/lib/elementary/elm_widget.c b/src/lib/elementary/elm_widget.c
index b21436b3b5..b0b515cd15 100644
--- a/src/lib/elementary/elm_widget.c
+++ b/src/lib/elementary/elm_widget.c
@@ -3931,6 +3931,12 @@ _elm_widget_theme_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
3931EOLIAN static Efl_Ui_Theme_Apply 3931EOLIAN static Efl_Ui_Theme_Apply
3932_elm_widget_style_set(Eo *obj, Elm_Widget_Smart_Data *sd, const char *style) 3932_elm_widget_style_set(Eo *obj, Elm_Widget_Smart_Data *sd, const char *style)
3933{ 3933{
3934 if (!sd->legacy && efl_finalized_get(obj))
3935 {
3936 ERR("Efl.Ui.Widget.style can only be set before finalize!");
3937 return EFL_UI_THEME_APPLY_FAILED;
3938 }
3939
3934 if (eina_stringshare_replace(&sd->style, style)) 3940 if (eina_stringshare_replace(&sd->style, style))
3935 return elm_widget_theme(obj); 3941 return elm_widget_theme(obj);
3936 3942
@@ -6154,6 +6160,14 @@ _elm_widget_efl_object_destructor(Eo *obj, Elm_Widget_Smart_Data *sd)
6154 sd->on_destroy = EINA_FALSE; 6160 sd->on_destroy = EINA_FALSE;
6155} 6161}
6156 6162
6163/* internal eo */
6164static void
6165_elm_widget_legacy_ctor(Eo *obj, Elm_Widget_Smart_Data *sd)
6166{
6167 efl_canvas_object_legacy_ctor(efl_super(obj, MY_CLASS));
6168 sd->legacy = EINA_TRUE;
6169}
6170
6157EOLIAN static Eina_Strbuf * 6171EOLIAN static Eina_Strbuf *
6158_elm_widget_efl_object_debug_name_override(Eo *obj, Elm_Widget_Smart_Data *sd EINA_UNUSED, Eina_Strbuf *sb) 6172_elm_widget_efl_object_debug_name_override(Eo *obj, Elm_Widget_Smart_Data *sd EINA_UNUSED, Eina_Strbuf *sb)
6159{ 6173{
@@ -6570,6 +6584,7 @@ ELM_PART_TEXT_DEFAULT_GET(elm_widget, NULL)
6570 EFL_CANVAS_GROUP_ADD_DEL_OPS(elm_widget), \ 6584 EFL_CANVAS_GROUP_ADD_DEL_OPS(elm_widget), \
6571 ELM_PART_CONTENT_DEFAULT_OPS(elm_widget), \ 6585 ELM_PART_CONTENT_DEFAULT_OPS(elm_widget), \
6572 ELM_PART_TEXT_DEFAULT_OPS(elm_widget), \ 6586 ELM_PART_TEXT_DEFAULT_OPS(elm_widget), \
6587 EFL_OBJECT_OP_FUNC(efl_canvas_object_legacy_ctor, _elm_widget_legacy_ctor), \
6573 EFL_OBJECT_OP_FUNC(efl_dbg_info_get, _elm_widget_efl_object_dbg_info_get) 6588 EFL_OBJECT_OP_FUNC(efl_dbg_info_get, _elm_widget_efl_object_dbg_info_get)
6574 6589
6575#include "elm_widget_item.eo.c" 6590#include "elm_widget_item.eo.c"
diff --git a/src/lib/elementary/elm_widget.eo b/src/lib/elementary/elm_widget.eo
index 5c369ba18b..59ab22617c 100644
--- a/src/lib/elementary/elm_widget.eo
+++ b/src/lib/elementary/elm_widget.eo
@@ -68,7 +68,7 @@ abstract Elm.Widget (Efl.Canvas.Group, Elm.Interface.Atspi_Accessible,
68 The style can only be set before @Efl.Object.finalize, which means 68 The style can only be set before @Efl.Object.finalize, which means
69 at construction time of the object (inside $efl_add in C). 69 at construction time of the object (inside $efl_add in C).
70 ]] 70 ]]
71 set { 71 set @protected {
72 [[Can only be called during construction, before finalize.]] 72 [[Can only be called during construction, before finalize.]]
73 return: Efl.Ui.Theme.Apply(0); 73 return: Efl.Ui.Theme.Apply(0);
74 [[Whether the style was successfully applied or not, see 74 [[Whether the style was successfully applied or not, see
diff --git a/src/lib/elementary/elm_widget.h b/src/lib/elementary/elm_widget.h
index 8c7382fd5b..86d5b6f4a5 100644
--- a/src/lib/elementary/elm_widget.h
+++ b/src/lib/elementary/elm_widget.h
@@ -468,6 +468,7 @@ typedef struct _Elm_Widget_Smart_Data
468 Eina_Bool on_create : 1; /**< This is true when the widget is on creation(general widget constructor). */ 468 Eina_Bool on_create : 1; /**< This is true when the widget is on creation(general widget constructor). */
469 Eina_Bool on_destroy: 1; /**< This is true when the widget is on destruction(general widget destructor). */ 469 Eina_Bool on_destroy: 1; /**< This is true when the widget is on destruction(general widget destructor). */
470 Eina_Bool provider_lookup : 1; /**< This is true when efl_provider_find is currently walking the tree */ 470 Eina_Bool provider_lookup : 1; /**< This is true when efl_provider_find is currently walking the tree */
471 Eina_Bool legacy : 1; /**< Widget was created with a legacy API, not efl_add() */
471} Elm_Widget_Smart_Data; 472} Elm_Widget_Smart_Data;
472 473
473/** 474/**
@@ -851,6 +852,14 @@ _elm_widget_sub_object_redirect_to_top(Evas_Object *obj, Evas_Object *sobj)
851 return ret; 852 return ret;
852} 853}
853 854
855static inline Eina_Bool
856elm_widget_is_legacy(const Eo *obj)
857{
858 Elm_Widget_Smart_Data *sd = (Elm_Widget_Smart_Data *)
859 efl_data_scope_safe_get(obj, ELM_WIDGET_CLASS);
860 return sd ? sd->legacy : EINA_FALSE;
861}
862
854/* to be used by INTERNAL classes on Elementary, so that the widgets 863/* to be used by INTERNAL classes on Elementary, so that the widgets
855 * parsing script skips it */ 864 * parsing script skips it */
856#define ELM_INTERNAL_SMART_SUBCLASS_NEW EVAS_SMART_SUBCLASS_NEW 865#define ELM_INTERNAL_SMART_SUBCLASS_NEW EVAS_SMART_SUBCLASS_NEW