summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Hirt <daniel.hirt@samsung.com>2016-03-15 10:42:36 +0200
committerDaniel Hirt <daniel.hirt@samsung.com>2016-03-15 10:42:36 +0200
commit4d907c466eda323cbcd08a388a48fafa2c3beb91 (patch)
tree9b307d65f655f3281d5c36b86264e6c281965051
parent580550223d60bdc84418ba8c2afe7a568efff064 (diff)
Widget: split construction logic
This moves the setup of private data from smart_add to the constructor. Also, the theming logic is split so we can have proper widget inheritance without repeated calls for theme_set, sizing_eval (etc?). The general idea is as follows: - ctors set the private data; this means no theme-related operations like part_set. - Theming is moved to Elm.Widget's finalize function, where the virtual "theme_init" method is called. This method should be overridden by the Widget subclasses, and basically just do the theme_set and sizing_eval calls. This also includes changes to Elm.Layout, which inherits the theme_init method.
-rw-r--r--src/lib/elm_layout.c44
-rw-r--r--src/lib/elm_layout.eo2
-rw-r--r--src/lib/elm_widget.c62
-rw-r--r--src/lib/elm_widget.eo6
4 files changed, 68 insertions, 46 deletions
diff --git a/src/lib/elm_layout.c b/src/lib/elm_layout.c
index 8058b832e..4ca2eda60 100644
--- a/src/lib/elm_layout.c
+++ b/src/lib/elm_layout.c
@@ -3,6 +3,7 @@
3#endif 3#endif
4 4
5#define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED 5#define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED
6#define ELM_WIDGET_PROTECTED
6 7
7#include <Elementary.h> 8#include <Elementary.h>
8 9
@@ -400,6 +401,14 @@ _elm_layout_elm_widget_theme_apply(Eo *obj, Elm_Layout_Smart_Data *sd)
400 return _elm_layout_theme_internal(obj, sd); 401 return _elm_layout_theme_internal(obj, sd);
401} 402}
402 403
404EOLIAN static Eina_Bool
405_elm_layout_elm_widget_theme_init(Eo *obj EINA_UNUSED, Elm_Layout_Smart_Data *_pd EINA_UNUSED)
406{
407 /* Nothing to theme for a layout object. Theme should be set later by the
408 * user. */
409 return EINA_TRUE;
410}
411
403static void * 412static void *
404_elm_layout_list_data_get(const Eina_List *list) 413_elm_layout_list_data_get(const Eina_List *list)
405{ 414{
@@ -750,27 +759,6 @@ _on_size_evaluate_signal(void *data,
750} 759}
751 760
752EOLIAN static void 761EOLIAN static void
753_elm_layout_evas_object_smart_add(Eo *obj, Elm_Layout_Smart_Data *_pd EINA_UNUSED)
754{
755 Evas_Object *edje;
756
757 elm_widget_sub_object_parent_add(obj);
758
759 /* has to be there *before* parent's smart_add() */
760 edje = edje_object_add(evas_object_evas_get(obj));
761 elm_widget_resize_object_set(obj, edje, EINA_TRUE);
762
763 evas_obj_smart_add(eo_super(obj, MY_CLASS));
764
765 elm_widget_can_focus_set(obj, EINA_FALSE);
766
767 edje_object_signal_callback_add
768 (edje, "size,eval", "elm", _on_size_evaluate_signal, obj);
769
770 elm_obj_layout_sizing_eval(obj);
771}
772
773EOLIAN static void
774_elm_layout_evas_object_smart_del(Eo *obj, Elm_Layout_Smart_Data *sd) 762_elm_layout_evas_object_smart_del(Eo *obj, Elm_Layout_Smart_Data *sd)
775{ 763{
776 Elm_Layout_Sub_Object_Data *sub_d; 764 Elm_Layout_Sub_Object_Data *sub_d;
@@ -1778,11 +1766,23 @@ elm_layout_add(Evas_Object *parent)
1778EOLIAN static Eo * 1766EOLIAN static Eo *
1779_elm_layout_eo_base_constructor(Eo *obj, Elm_Layout_Smart_Data *sd) 1767_elm_layout_eo_base_constructor(Eo *obj, Elm_Layout_Smart_Data *sd)
1780{ 1768{
1781 sd->obj = obj;
1782 obj = eo_constructor(eo_super(obj, MY_CLASS)); 1769 obj = eo_constructor(eo_super(obj, MY_CLASS));
1770
1771 Evas_Object *edje;
1772
1783 evas_obj_type_set(obj, MY_CLASS_NAME_LEGACY); 1773 evas_obj_type_set(obj, MY_CLASS_NAME_LEGACY);
1784 evas_obj_smart_callbacks_descriptions_set(obj, _smart_callbacks); 1774 evas_obj_smart_callbacks_descriptions_set(obj, _smart_callbacks);
1785 elm_interface_atspi_accessible_role_set(obj, ELM_ATSPI_ROLE_FILLER); 1775 elm_interface_atspi_accessible_role_set(obj, ELM_ATSPI_ROLE_FILLER);
1776 elm_widget_sub_object_parent_add(obj);
1777
1778 sd->obj = obj;
1779
1780 edje = edje_object_add(evas_object_evas_get(obj));
1781 elm_widget_resize_object_set(obj, edje, EINA_TRUE);
1782 elm_widget_can_focus_set(obj, EINA_FALSE);
1783
1784 edje_object_signal_callback_add
1785 (edje, "size,eval", "elm", _on_size_evaluate_signal, obj);
1786 1786
1787 return obj; 1787 return obj;
1788} 1788}
diff --git a/src/lib/elm_layout.eo b/src/lib/elm_layout.eo
index 50f4e8865..3d4626450 100644
--- a/src/lib/elm_layout.eo
+++ b/src/lib/elm_layout.eo
@@ -476,7 +476,6 @@ class Elm.Layout (Elm.Container, Efl.File)
476 Efl.File.file.set; 476 Efl.File.file.set;
477 Efl.File.file.get; 477 Efl.File.file.get;
478 Evas.Object_Smart.del; 478 Evas.Object_Smart.del;
479 Evas.Object_Smart.add;
480 Evas.Object_Smart.calculate; 479 Evas.Object_Smart.calculate;
481 Elm.Widget.focus_direction; 480 Elm.Widget.focus_direction;
482 Elm.Widget.sub_object_add; 481 Elm.Widget.sub_object_add;
@@ -487,6 +486,7 @@ class Elm.Layout (Elm.Container, Efl.File)
487 Elm.Widget.disable; 486 Elm.Widget.disable;
488 Elm.Widget.sub_object_del; 487 Elm.Widget.sub_object_del;
489 Elm.Widget.on_focus; 488 Elm.Widget.on_focus;
489 Elm.Widget.theme_init;
490 Elm.Container.content_get; 490 Elm.Container.content_get;
491 Elm.Container.content_set; 491 Elm.Container.content_set;
492 Elm.Container.content_unset; 492 Elm.Container.content_unset;
diff --git a/src/lib/elm_widget.c b/src/lib/elm_widget.c
index ac7aeb3e7..7f732bcc4 100644
--- a/src/lib/elm_widget.c
+++ b/src/lib/elm_widget.c
@@ -5,6 +5,8 @@
5#define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED 5#define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED
6#define ELM_INTERFACE_ATSPI_COMPONENT_PROTECTED 6#define ELM_INTERFACE_ATSPI_COMPONENT_PROTECTED
7#define ELM_WIDGET_ITEM_PROTECTED 7#define ELM_WIDGET_ITEM_PROTECTED
8#define ELM_WIDGET_PROTECTED
9
8#include <Elementary.h> 10#include <Elementary.h>
9 11
10#include "elm_priv.h" 12#include "elm_priv.h"
@@ -336,25 +338,9 @@ _obj_mouse_in(void *data,
336} 338}
337 339
338EOLIAN static void 340EOLIAN static void
339_elm_widget_evas_object_smart_add(Eo *obj, Elm_Widget_Smart_Data *priv) 341_elm_widget_evas_object_smart_add(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *priv EINA_UNUSED)
340{ 342{
341 343 /* Do nothing */
342 priv->obj = obj;
343 priv->mirrored_auto_mode = EINA_TRUE; /* will follow system locale
344 * settings */
345 priv->focus_region_show_mode = ELM_FOCUS_REGION_SHOW_WIDGET;
346 elm_widget_can_focus_set(obj, EINA_TRUE);
347 priv->is_mirrored = elm_config_mirrored_get();
348 priv->focus_move_policy = _elm_config->focus_move_policy;
349
350 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN,
351 _obj_mouse_down, obj);
352 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_MOVE,
353 _obj_mouse_move, obj);
354 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
355 _obj_mouse_up, obj);
356 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_IN,
357 _obj_mouse_in, obj);
358} 344}
359 345
360static void 346static void
@@ -4394,6 +4380,20 @@ _elm_widget_item_eo_base_constructor(Eo *eo_item, Elm_Widget_Item_Data *item)
4394 return eo_item; 4380 return eo_item;
4395} 4381}
4396 4382
4383EOLIAN static Eo *
4384_elm_widget_eo_base_finalize(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
4385{
4386 if (!elm_obj_widget_theme_init(obj))
4387 {
4388 WRN("Could not set theme during construction");
4389#if 0
4390 /* TODO: do cleanup */
4391 return NULL;
4392#endif
4393 }
4394 return obj;
4395}
4396
4397EOLIAN static void 4397EOLIAN static void
4398_elm_widget_item_eo_base_destructor(Eo *eo_item, Elm_Widget_Item_Data *item) 4398_elm_widget_item_eo_base_destructor(Eo *eo_item, Elm_Widget_Item_Data *item)
4399{ 4399{
@@ -5659,19 +5659,35 @@ elm_widget_tree_dot_dump(const Evas_Object *top,
5659} 5659}
5660 5660
5661EOLIAN static Eo * 5661EOLIAN static Eo *
5662_elm_widget_eo_base_constructor(Eo *obj, Elm_Widget_Smart_Data *sd EINA_UNUSED) 5662_elm_widget_eo_base_constructor(Eo *obj, Elm_Widget_Smart_Data *sd)
5663{ 5663{
5664 Eo *parent = NULL;
5665
5666 sd->on_create = EINA_TRUE;
5667 obj = eo_constructor(eo_super(obj, MY_CLASS)); 5664 obj = eo_constructor(eo_super(obj, MY_CLASS));
5665
5666 Eo *parent = NULL;
5668 evas_obj_type_set(obj, MY_CLASS_NAME_LEGACY); 5667 evas_obj_type_set(obj, MY_CLASS_NAME_LEGACY);
5669 evas_obj_smart_callbacks_descriptions_set(obj, _smart_callbacks); 5668 evas_obj_smart_callbacks_descriptions_set(obj, _smart_callbacks);
5670 parent = eo_parent_get(obj); 5669 parent = eo_parent_get(obj);
5671 elm_obj_widget_parent_set(obj, parent); 5670 elm_obj_widget_parent_set(obj, parent);
5672 sd->on_create = EINA_FALSE;
5673 5671
5674 elm_interface_atspi_accessible_role_set(obj, ELM_ATSPI_ROLE_UNKNOWN); 5672 elm_interface_atspi_accessible_role_set(obj, ELM_ATSPI_ROLE_UNKNOWN);
5673
5674 sd->obj = obj;
5675 sd->mirrored_auto_mode = EINA_TRUE; /* will follow system locale
5676 * settings */
5677 sd->focus_region_show_mode = ELM_FOCUS_REGION_SHOW_WIDGET;
5678 elm_widget_can_focus_set(obj, EINA_TRUE);
5679 sd->is_mirrored = elm_config_mirrored_get();
5680 sd->focus_move_policy = _elm_config->focus_move_policy;
5681
5682 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN,
5683 _obj_mouse_down, obj);
5684 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_MOVE,
5685 _obj_mouse_move, obj);
5686 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
5687 _obj_mouse_up, obj);
5688 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_IN,
5689 _obj_mouse_in, obj);
5690
5675 return obj; 5691 return obj;
5676} 5692}
5677 5693
diff --git a/src/lib/elm_widget.eo b/src/lib/elm_widget.eo
index e5db7679d..3f98a8ab9 100644
--- a/src/lib/elm_widget.eo
+++ b/src/lib/elm_widget.eo
@@ -754,6 +754,10 @@ abstract Elm.Widget (Evas.Object_Smart, Elm.Interface_Atspi_Accessible, Elm.Inte
754 [['Virtual' function on the widget being re-themed.]] 754 [['Virtual' function on the widget being re-themed.]]
755 return: bool; 755 return: bool;
756 } 756 }
757 theme_init @protected {
758 [['Virtual' function on the widget to setup the theme]]
759 return: bool;
760 }
757 focus_direction_get @const { 761 focus_direction_get @const {
758 return: bool; 762 return: bool;
759 params { 763 params {
@@ -825,6 +829,7 @@ abstract Elm.Widget (Evas.Object_Smart, Elm.Interface_Atspi_Accessible, Elm.Inte
825 implements { 829 implements {
826 class.constructor; 830 class.constructor;
827 Eo.Base.constructor; 831 Eo.Base.constructor;
832 Eo.Base.finalize;
828 Eo.Base.destructor; 833 Eo.Base.destructor;
829 Eo.Base.dbg_info_get; 834 Eo.Base.dbg_info_get;
830 Evas.Object_Smart.hide; 835 Evas.Object_Smart.hide;
@@ -842,6 +847,7 @@ abstract Elm.Widget (Evas.Object_Smart, Elm.Interface_Atspi_Accessible, Elm.Inte
842 @virtual .focus_direction; 847 @virtual .focus_direction;
843 @virtual .focus_next; 848 @virtual .focus_next;
844 @virtual .parent_widget.get; 849 @virtual .parent_widget.get;
850 @virtual .theme_init;
845 Elm.Interface_Atspi_Accessible.name.get; 851 Elm.Interface_Atspi_Accessible.name.get;
846 Elm.Interface_Atspi_Accessible.state_set.get; 852 Elm.Interface_Atspi_Accessible.state_set.get;
847 Elm.Interface_Atspi_Accessible.children.get; 853 Elm.Interface_Atspi_Accessible.children.get;