Check wether item is NULl in _mouse_move & Add reorder,start &
[framework/uifw/elementary.git] / src / lib / elm_plug.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 typedef struct _Widget_Data Widget_Data;
5
6 struct _Widget_Data
7 {
8    Evas_Object *img;
9 };
10
11 static const char *widtype = NULL;
12 static void _del_hook(Evas_Object *obj);
13 static void _theme_hook(Evas_Object *obj);
14 static void _sizing_eval(Evas_Object *obj);
15 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
16
17 static const char SIG_CLICKED[] = "clicked";
18
19 static const Evas_Smart_Cb_Description _signals[] = {
20        {SIG_CLICKED, ""},
21        {NULL, NULL}
22 };
23
24
25 static void
26 _del_hook(Evas_Object *obj)
27 {
28    Widget_Data *wd = elm_widget_data_get(obj);
29
30    if (!wd) return;
31    free(wd);
32 }
33
34 static void
35 _del_pre_hook(Evas_Object *obj)
36 {
37    Widget_Data *wd = elm_widget_data_get(obj);
38
39    if (!wd) return;
40    evas_object_del(wd->img);
41 }
42
43 static void
44 _theme_hook(Evas_Object *obj)
45 {
46    Widget_Data *wd = elm_widget_data_get(obj);
47
48    if (!wd) return;
49    _sizing_eval(obj);
50 }
51
52 static void
53 _sizing_eval(Evas_Object *obj)
54 {
55    Widget_Data *wd = elm_widget_data_get(obj);
56    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
57
58    if (!wd) return;
59    //TODO: get socket object size
60    evas_object_size_hint_min_set(obj, minw, minh);
61    evas_object_size_hint_max_set(obj, maxw, maxh);
62 }
63
64 static void
65 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
66 {
67    evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
68 }
69
70
71 EAPI Evas_Object *
72 elm_plug_image_object_get(const Evas_Object *obj)
73 {
74    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
75    Widget_Data *wd = elm_widget_data_get(obj);
76    if (!wd) return NULL;
77    if (!wd->img) return NULL;
78    return wd->img;
79 }
80
81 EAPI Evas_Object *
82 elm_plug_add(Evas_Object *parent)
83 {
84    Evas_Object *obj;
85    Evas *e;
86    Widget_Data *wd;
87    Ecore_Evas *ee;
88
89    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
90
91    ELM_SET_WIDTYPE(widtype, "plug");
92    elm_widget_type_set(obj, "plug");
93    elm_widget_sub_object_add(parent, obj);
94    elm_widget_data_set(obj, wd);
95    elm_widget_del_hook_set(obj, _del_hook);
96    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
97    elm_widget_theme_hook_set(obj, _theme_hook);
98    elm_widget_can_focus_set(obj, EINA_FALSE);
99
100    ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
101    if (!ee) return NULL;
102    wd->img = ecore_evas_extn_plug_new(ee);
103    if (!wd->img) return NULL;
104
105    evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
106                                   _mouse_up, obj);
107    elm_widget_resize_object_set(obj, wd->img);
108
109    evas_object_smart_callbacks_descriptions_set(obj, _signals);
110
111    _sizing_eval(obj);
112    return obj;
113 }
114
115 EAPI Eina_Bool
116 elm_plug_connect(Evas_Object *obj, const char *svcname, int svcnum, Eina_Bool svcsys)
117 {
118    Evas_Object *plug_img = NULL;
119
120    plug_img = elm_plug_image_object_get(obj);
121    if (!plug_img) return EINA_FALSE;
122
123    if (ecore_evas_extn_plug_connect(plug_img, svcname, svcnum, svcsys))
124      return EINA_TRUE;
125    else
126      return EINA_FALSE;
127 }
128