parent
4f8b51b1aa
commit
8645ac25ac
|
@ -78,8 +78,8 @@ test_win_plug(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_in
|
|||
Evas_Object *win, *bg, *plug;
|
||||
char buf[PATH_MAX];
|
||||
|
||||
win = elm_win_add(NULL, "window-inline", ELM_WIN_BASIC);
|
||||
elm_win_title_set(win, "Window Inline");
|
||||
win = elm_win_add(NULL, "window-plug", ELM_WIN_BASIC);
|
||||
elm_win_title_set(win, "Window Plug");
|
||||
elm_win_autodel_set(win, EINA_TRUE);
|
||||
|
||||
bg = elm_bg_add(win);
|
||||
|
|
|
@ -1,128 +1,155 @@
|
|||
#include <Elementary.h>
|
||||
#include "elm_priv.h"
|
||||
|
||||
typedef struct _Widget_Data Widget_Data;
|
||||
static const char PLUG_SMART_NAME[] = "elm_plug";
|
||||
|
||||
struct _Widget_Data
|
||||
#define ELM_PLUG_DATA_GET(o, sd) \
|
||||
Elm_Plug_Smart_Data * sd = evas_object_smart_data_get(o)
|
||||
|
||||
#define ELM_PLUG_DATA_GET_OR_RETURN(o, ptr) \
|
||||
ELM_PLUG_DATA_GET(o, ptr); \
|
||||
if (!ptr) \
|
||||
{ \
|
||||
CRITICAL("No widget data for object %p (%s)", \
|
||||
o, evas_object_type_get(o)); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ELM_PLUG_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
|
||||
ELM_PLUG_DATA_GET(o, ptr); \
|
||||
if (!ptr) \
|
||||
{ \
|
||||
CRITICAL("No widget data for object %p (%s)", \
|
||||
o, evas_object_type_get(o)); \
|
||||
return val; \
|
||||
}
|
||||
|
||||
#define ELM_PLUG_CHECK(obj) \
|
||||
if (!obj || !elm_widget_type_check((obj), PLUG_SMART_NAME, __func__)) \
|
||||
return
|
||||
|
||||
typedef struct _Elm_Plug_Smart_Data Elm_Plug_Smart_Data;
|
||||
|
||||
struct _Elm_Plug_Smart_Data
|
||||
{
|
||||
Evas_Object *img;
|
||||
Elm_Widget_Smart_Data base; /* base widget smart data as
|
||||
* first member obligatory, as
|
||||
* we're inheriting from it */
|
||||
Evas_Object *img;
|
||||
};
|
||||
|
||||
static const char *widtype = NULL;
|
||||
static void _del_hook(Evas_Object *obj);
|
||||
static void _theme_hook(Evas_Object *obj);
|
||||
static void _sizing_eval(Evas_Object *obj);
|
||||
static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
|
||||
|
||||
static const char SIG_CLICKED[] = "clicked";
|
||||
|
||||
static const Evas_Smart_Cb_Description _signals[] = {
|
||||
{SIG_CLICKED, ""},
|
||||
{NULL, NULL}
|
||||
static const Evas_Smart_Cb_Description _smart_callbacks[] = {
|
||||
{SIG_CLICKED, ""},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
_del_hook(Evas_Object *obj)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
|
||||
if (!wd) return;
|
||||
free(wd);
|
||||
}
|
||||
|
||||
static void
|
||||
_del_pre_hook(Evas_Object *obj)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
|
||||
if (!wd) return;
|
||||
evas_object_del(wd->img);
|
||||
}
|
||||
|
||||
static void
|
||||
_theme_hook(Evas_Object *obj)
|
||||
{
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
|
||||
if (!wd) return;
|
||||
_sizing_eval(obj);
|
||||
}
|
||||
EVAS_SMART_SUBCLASS_NEW
|
||||
(PLUG_SMART_NAME, _elm_plug, Elm_Widget_Smart_Class,
|
||||
Elm_Widget_Smart_Class, elm_widget_smart_class_get, _smart_callbacks);
|
||||
|
||||
static void
|
||||
_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;
|
||||
//TODO: get socket object size
|
||||
evas_object_size_hint_min_set(obj, minw, minh);
|
||||
evas_object_size_hint_max_set(obj, maxw, maxh);
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_elm_plug_smart_theme(Evas_Object *obj)
|
||||
{
|
||||
if (!_elm_plug_parent_sc->theme(obj)) return EINA_FALSE;
|
||||
|
||||
_sizing_eval(obj);
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
||||
_on_mouse_up(void *data,
|
||||
Evas *e __UNUSED__,
|
||||
Evas_Object *obj __UNUSED__,
|
||||
void *event_info __UNUSED__)
|
||||
{
|
||||
evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
|
||||
}
|
||||
|
||||
|
||||
EAPI Evas_Object *
|
||||
elm_plug_image_object_get(const Evas_Object *obj)
|
||||
static void
|
||||
_elm_plug_smart_add(Evas_Object *obj)
|
||||
{
|
||||
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
|
||||
Widget_Data *wd = elm_widget_data_get(obj);
|
||||
if (!wd) return NULL;
|
||||
if (!wd->img) return NULL;
|
||||
return wd->img;
|
||||
EVAS_SMART_DATA_ALLOC(obj, Elm_Plug_Smart_Data);
|
||||
|
||||
elm_widget_can_focus_set(obj, EINA_FALSE);
|
||||
|
||||
_elm_plug_parent_sc->base.add(obj);
|
||||
}
|
||||
|
||||
static void
|
||||
_elm_plug_smart_set_user(Elm_Widget_Smart_Class *sc)
|
||||
{
|
||||
sc->base.add = _elm_plug_smart_add;
|
||||
|
||||
sc->theme = _elm_plug_smart_theme;
|
||||
}
|
||||
|
||||
EAPI Evas_Object *
|
||||
elm_plug_add(Evas_Object *parent)
|
||||
{
|
||||
Evas_Object *obj;
|
||||
Evas *e;
|
||||
Widget_Data *wd;
|
||||
Ecore_Evas *ee;
|
||||
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, "plug");
|
||||
elm_widget_type_set(obj, "plug");
|
||||
elm_widget_sub_object_add(parent, obj);
|
||||
elm_widget_data_set(obj, wd);
|
||||
elm_widget_del_hook_set(obj, _del_hook);
|
||||
elm_widget_del_pre_hook_set(obj, _del_pre_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_plug_smart_class_new());
|
||||
|
||||
if (!elm_widget_sub_object_add(parent, obj))
|
||||
ERR("could not add %p as sub object of %p", obj, parent);
|
||||
|
||||
ELM_PLUG_DATA_GET(obj, sd);
|
||||
|
||||
ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
|
||||
if (!ee) return NULL;
|
||||
wd->img = ecore_evas_extn_plug_new(ee);
|
||||
if (!wd->img) return NULL;
|
||||
if (!ee) goto err;
|
||||
sd->img = ecore_evas_extn_plug_new(ee);
|
||||
if (!sd->img) goto err;
|
||||
|
||||
evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
|
||||
_mouse_up, obj);
|
||||
elm_widget_resize_object_set(obj, wd->img);
|
||||
|
||||
evas_object_smart_callbacks_descriptions_set(obj, _signals);
|
||||
evas_object_event_callback_add
|
||||
(sd->img, EVAS_CALLBACK_MOUSE_UP, _on_mouse_up, obj);
|
||||
elm_widget_resize_object_set(obj, sd->img);
|
||||
|
||||
_sizing_eval(obj);
|
||||
return obj;
|
||||
|
||||
err:
|
||||
evas_object_del(obj);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EAPI Evas_Object *
|
||||
elm_plug_image_object_get(const Evas_Object *obj)
|
||||
{
|
||||
ELM_PLUG_CHECK(obj) NULL;
|
||||
ELM_PLUG_DATA_GET(obj, sd);
|
||||
|
||||
return sd->img;
|
||||
}
|
||||
|
||||
EAPI Eina_Bool
|
||||
elm_plug_connect(Evas_Object *obj, const char *svcname, int svcnum, Eina_Bool svcsys)
|
||||
elm_plug_connect(Evas_Object *obj,
|
||||
const char *svcname,
|
||||
int svcnum,
|
||||
Eina_Bool svcsys)
|
||||
{
|
||||
Evas_Object *plug_img = NULL;
|
||||
|
||||
plug_img = elm_plug_image_object_get(obj);
|
||||
if (!plug_img) return EINA_FALSE;
|
||||
|
||||
if (ecore_evas_extn_plug_connect(plug_img, svcname, svcnum, svcsys))
|
||||
return EINA_TRUE;
|
||||
else
|
||||
return EINA_FALSE;
|
||||
return ecore_evas_extn_plug_connect(plug_img, svcname, svcnum, svcsys);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue