parent
cd2dc9574b
commit
37a03c7fb9
|
@ -1,106 +1,147 @@
|
|||
#include <Elementary.h>
|
||||
#include "elm_priv.h"
|
||||
#include "elm_widget_layout.h"
|
||||
|
||||
typedef struct _Widget_Data Widget_Data;
|
||||
static const char SEPARATOR_SMART_NAME[] = "elm_separator";
|
||||
|
||||
struct _Widget_Data
|
||||
typedef struct _Elm_Separator_Smart_Data Elm_Separator_Smart_Data;
|
||||
|
||||
struct _Elm_Separator_Smart_Data
|
||||
{
|
||||
Evas_Object *sep;
|
||||
Eina_Bool horizontal;
|
||||
Elm_Layout_Smart_Data base;
|
||||
|
||||
Eina_Bool horizontal : 1;
|
||||
};
|
||||
|
||||
static const char *widtype = NULL;
|
||||
static void _del_hook(Evas_Object *obj);
|
||||
static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
|
||||
static void _theme_hook(Evas_Object *obj);
|
||||
static void _sizing_eval(Evas_Object *obj);
|
||||
#define ELM_SEPARATOR_DATA_GET(o, sd) \
|
||||
Elm_Separator_Smart_Data * sd = evas_object_smart_data_get(o)
|
||||
|
||||
static void
|
||||
_del_hook(Evas_Object *obj)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return;
|
||||
free(wd);
|
||||
}
|
||||
#define ELM_SEPARATOR_DATA_GET_OR_RETURN(o, ptr) \
|
||||
ELM_SEPARATOR_DATA_GET(o, ptr); \
|
||||
if (!ptr) \
|
||||
{ \
|
||||
CRITICAL("No widget data for object %p (%s)", \
|
||||
o, evas_object_type_get(o)); \
|
||||
return; \
|
||||
}
|
||||
|
||||
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->sep, rtl);
|
||||
}
|
||||
#define ELM_SEPARATOR_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
|
||||
ELM_SEPARATOR_DATA_GET(o, ptr); \
|
||||
if (!ptr) \
|
||||
{ \
|
||||
CRITICAL("No widget data for object %p (%s)", \
|
||||
o, evas_object_type_get(o)); \
|
||||
return val; \
|
||||
}
|
||||
|
||||
static void
|
||||
_theme_hook(Evas_Object *obj)
|
||||
#define ELM_SEPARATOR_CHECK(obj) \
|
||||
if (!obj || !elm_widget_type_check((obj), SEPARATOR_SMART_NAME, __func__)) \
|
||||
return
|
||||
|
||||
/* Inheriting from elm_layout. Besides, we need no more than what is
|
||||
* there */
|
||||
EVAS_SMART_SUBCLASS_NEW
|
||||
(SEPARATOR_SMART_NAME, _elm_separator, Elm_Layout_Smart_Class,
|
||||
Elm_Layout_Smart_Class, elm_layout_smart_class_get, NULL);
|
||||
|
||||
static Eina_Bool
|
||||
_elm_separator_smart_theme(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));
|
||||
if (wd->horizontal)
|
||||
_elm_theme_object_set(obj, wd->sep, "separator", "horizontal", elm_widget_style_get(obj));
|
||||
ELM_SEPARATOR_DATA_GET(obj, sd);
|
||||
|
||||
if (sd->horizontal)
|
||||
eina_stringshare_replace(&(ELM_LAYOUT_DATA(sd)->group), "horizontal");
|
||||
else
|
||||
_elm_theme_object_set(obj, wd->sep, "separator", "vertical", elm_widget_style_get(obj));
|
||||
edje_object_scale_set(wd->sep, elm_widget_scale_get(obj) * _elm_config->scale);
|
||||
_sizing_eval(obj);
|
||||
eina_stringshare_replace(&(ELM_LAYOUT_DATA(sd)->group), "vertical");
|
||||
|
||||
if (!ELM_WIDGET_CLASS(_elm_separator_parent_sc)->theme(obj)) return EINA_FALSE;
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_sizing_eval(Evas_Object *obj)
|
||||
_elm_separator_smart_sizing_eval(Evas_Object *obj)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
|
||||
if (!wd) return;
|
||||
edje_object_size_min_calc(wd->sep, &minw, &minh);
|
||||
|
||||
ELM_SEPARATOR_DATA_GET(obj, sd);
|
||||
|
||||
edje_object_size_min_calc(ELM_WIDGET_DATA(sd)->resize_obj, &minw, &minh);
|
||||
evas_object_size_hint_min_set(obj, minw, minh);
|
||||
evas_object_size_hint_max_set(obj, maxw, maxh);
|
||||
evas_object_size_hint_align_set(obj, maxw, maxh);
|
||||
}
|
||||
|
||||
static void
|
||||
_elm_separator_smart_add(Evas_Object *obj)
|
||||
{
|
||||
EVAS_SMART_DATA_ALLOC(obj, Elm_Separator_Smart_Data);
|
||||
|
||||
ELM_WIDGET_CLASS(_elm_separator_parent_sc)->base.add(obj);
|
||||
|
||||
priv->horizontal = EINA_FALSE;
|
||||
|
||||
elm_widget_can_focus_set(obj, EINA_FALSE);
|
||||
|
||||
elm_layout_theme_set
|
||||
(obj, "separator", "vertical", elm_widget_style_get(obj));
|
||||
|
||||
elm_layout_sizing_eval(obj);
|
||||
}
|
||||
|
||||
static void
|
||||
_elm_separator_smart_set_user(Elm_Layout_Smart_Class *sc)
|
||||
{
|
||||
ELM_WIDGET_CLASS(sc)->base.add = _elm_separator_smart_add;
|
||||
|
||||
ELM_WIDGET_CLASS(sc)->theme = _elm_separator_smart_theme;
|
||||
|
||||
/* not a 'focus chain manager' */
|
||||
ELM_WIDGET_CLASS(sc)->focus_next = NULL;
|
||||
ELM_WIDGET_CLASS(sc)->focus_direction = NULL;
|
||||
|
||||
sc->sizing_eval = _elm_separator_smart_sizing_eval;
|
||||
}
|
||||
|
||||
EAPI Evas_Object *
|
||||
elm_separator_add(Evas_Object *parent)
|
||||
{
|
||||
Evas_Object *obj;
|
||||
Evas *e;
|
||||
Widget_Data *wd;
|
||||
Evas_Object *obj;
|
||||
|
||||
ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
|
||||
|
||||
ELM_SET_WIDTYPE(widtype, "separator");
|
||||
wd->horizontal = EINA_FALSE;
|
||||
elm_widget_type_set(obj, "separator");
|
||||
elm_widget_sub_object_add(parent, obj);
|
||||
elm_widget_data_set(obj, wd);
|
||||
elm_widget_del_hook_set(obj, _del_hook);
|
||||
elm_widget_theme_hook_set(obj, _theme_hook);
|
||||
elm_widget_can_focus_set(obj, EINA_FALSE);
|
||||
e = evas_object_evas_get(parent);
|
||||
if (!e) return NULL;
|
||||
|
||||
obj = evas_object_smart_add(e, _elm_separator_smart_class_new());
|
||||
|
||||
if (!elm_widget_sub_object_add(parent, obj))
|
||||
ERR("could not add %p as sub object of %p", obj, parent);
|
||||
|
||||
wd->sep = edje_object_add(e);
|
||||
_elm_theme_object_set(obj, wd->sep, "separator", "vertical", "default");
|
||||
elm_widget_resize_object_set(obj, wd->sep);
|
||||
_mirrored_set(obj, elm_widget_mirrored_get(obj));
|
||||
_sizing_eval(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
elm_separator_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
|
||||
elm_separator_horizontal_set(Evas_Object *obj,
|
||||
Eina_Bool horizontal)
|
||||
{
|
||||
ELM_CHECK_WIDTYPE(obj, widtype);
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return;
|
||||
ELM_SEPARATOR_CHECK(obj);
|
||||
ELM_SEPARATOR_DATA_GET(obj, sd);
|
||||
|
||||
horizontal = !!horizontal;
|
||||
if (wd->horizontal == horizontal) return;
|
||||
wd->horizontal = horizontal;
|
||||
_theme_hook(obj);
|
||||
if (sd->horizontal == horizontal) return;
|
||||
|
||||
sd->horizontal = horizontal;
|
||||
|
||||
_elm_separator_smart_theme(obj);
|
||||
}
|
||||
|
||||
EAPI Eina_Bool
|
||||
elm_separator_horizontal_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->horizontal;
|
||||
ELM_SEPARATOR_CHECK(obj) EINA_FALSE;
|
||||
ELM_SEPARATOR_DATA_GET(obj, sd);
|
||||
|
||||
return sd->horizontal;
|
||||
}
|
||||
|
|
|
@ -6,9 +6,15 @@
|
|||
*
|
||||
* A separator can be vertical or horizontal.
|
||||
*
|
||||
* This widget inherits from the @ref Layout one, so that all the
|
||||
* functions acting on it also work for separator objects.
|
||||
*
|
||||
* This widget emits the signals coming from @ref Layout.
|
||||
*
|
||||
* @ref tutorial_separator is a good example of how to use a separator.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Add a separator object to @p parent
|
||||
*
|
||||
|
@ -19,6 +25,7 @@
|
|||
* @ingroup Separator
|
||||
*/
|
||||
EAPI Evas_Object *elm_separator_add(Evas_Object *parent);
|
||||
|
||||
/**
|
||||
* @brief Set the horizontal mode of a separator object
|
||||
*
|
||||
|
@ -28,6 +35,7 @@ EAPI Evas_Object *elm_separator_add(Evas_Object *parent);
|
|||
* @ingroup Separator
|
||||
*/
|
||||
EAPI void elm_separator_horizontal_set(Evas_Object *obj, Eina_Bool horizontal);
|
||||
|
||||
/**
|
||||
* @brief Get the horizontal mode of a separator object
|
||||
*
|
||||
|
@ -39,6 +47,7 @@ EAPI void elm_separator_horizontal_set(Evas_Object *obj, Eina_Bool horizont
|
|||
* @ingroup Separator
|
||||
*/
|
||||
EAPI Eina_Bool elm_separator_horizontal_get(const Evas_Object *obj);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue