elementary/map - map supports language,changed
[framework/uifw/elementary.git] / src / lib / elm_plug.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3 #include "elm_widget_plug.h"
4
5 EAPI const char ELM_PLUG_SMART_NAME[] = "elm_plug";
6
7 static const char PLUG_KEY[] = "__Plug_Ecore_Evas";
8
9 static const char SIG_CLICKED[] = "clicked";
10 static const char SIG_IMAGE_DELETED[] = "image.deleted";
11 static const Evas_Smart_Cb_Description _smart_callbacks[] = {
12    {SIG_CLICKED, ""},
13    {SIG_IMAGE_DELETED, ""},
14    {NULL, NULL}
15 };
16
17 EVAS_SMART_SUBCLASS_NEW
18   (ELM_PLUG_SMART_NAME, _elm_plug, Elm_Plug_Smart_Class,
19   Elm_Widget_Smart_Class, elm_widget_smart_class_get, _smart_callbacks);
20
21 static void
22 _sizing_eval(Evas_Object *obj __UNUSED__)
23 {
24    //Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
25
26    //TODO: get socket object size
27    //this reset plug's min/max size
28    //evas_object_size_hint_min_set(obj, minw, minh);
29    //evas_object_size_hint_max_set(obj, maxw, maxh);
30 }
31
32 static void
33 _elm_plug_disconnected(Ecore_Evas *ee)
34 {
35    Evas_Object *plug = NULL;
36
37    if (!ee) return;
38    plug = ecore_evas_data_get(ee, PLUG_KEY);
39    if (!plug) return;
40    evas_object_smart_callback_call(plug, SIG_IMAGE_DELETED, NULL);
41 }
42
43 static Eina_Bool
44 _elm_plug_smart_theme(Evas_Object *obj)
45 {
46    if (!_elm_plug_parent_sc->theme(obj)) return EINA_FALSE;
47
48    _sizing_eval(obj);
49
50    return EINA_TRUE;
51 }
52
53 static void
54 _on_mouse_up(void *data,
55              Evas *e __UNUSED__,
56              Evas_Object *obj __UNUSED__,
57              void *event_info __UNUSED__)
58 {
59    evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
60 }
61
62 static void
63 _elm_plug_smart_add(Evas_Object *obj)
64 {
65    Evas_Object *p_obj;
66    Ecore_Evas *ee;
67
68    EVAS_SMART_DATA_ALLOC(obj, Elm_Plug_Smart_Data);
69
70    _elm_plug_parent_sc->base.add(obj);
71
72    ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
73    if (!ee) return;
74
75    p_obj = ecore_evas_extn_plug_new(ee);
76    if (!p_obj) return;
77
78    elm_widget_resize_object_set(obj, p_obj);
79
80    evas_object_event_callback_add
81      (ELM_WIDGET_DATA(priv)->resize_obj, EVAS_CALLBACK_MOUSE_UP, _on_mouse_up,
82      obj);
83
84    elm_widget_can_focus_set(obj, EINA_FALSE);
85    _sizing_eval(obj);
86 }
87
88 static void
89 _elm_plug_smart_set_user(Elm_Plug_Smart_Class *sc)
90 {
91    ELM_WIDGET_CLASS(sc)->base.add = _elm_plug_smart_add;
92
93    ELM_WIDGET_CLASS(sc)->theme = _elm_plug_smart_theme;
94 }
95
96 EAPI const Elm_Plug_Smart_Class *
97 elm_plug_smart_class_get(void)
98 {
99    static Elm_Plug_Smart_Class _sc =
100      ELM_PLUG_SMART_CLASS_INIT_NAME_VERSION(ELM_PLUG_SMART_NAME);
101    static const Elm_Plug_Smart_Class *class = NULL;
102
103    if (class) return class;
104
105    _elm_plug_smart_set(&_sc);
106    class = &_sc;
107
108    return class;
109 }
110
111 EAPI Evas_Object *
112 elm_plug_add(Evas_Object *parent)
113 {
114    Evas_Object *obj;
115
116    EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
117
118    obj = elm_widget_add(_elm_plug_smart_class_new(), parent);
119    if (!obj) return NULL;
120
121    ELM_PLUG_DATA_GET(obj, sd);
122    if (!ELM_WIDGET_DATA(sd)->resize_obj) return NULL;
123
124    if (!elm_widget_sub_object_add(parent, obj))
125      ERR("could not add %p as sub object of %p", obj, parent);
126
127    return obj;
128 }
129
130 EAPI Evas_Object *
131 elm_plug_image_object_get(const Evas_Object *obj)
132 {
133    ELM_PLUG_CHECK(obj) NULL;
134    ELM_PLUG_DATA_GET(obj, sd);
135
136    return ELM_WIDGET_DATA(sd)->resize_obj;
137 }
138
139 EAPI Eina_Bool
140 elm_plug_connect(Evas_Object *obj,
141                  const char *svcname,
142                  int svcnum,
143                  Eina_Bool svcsys)
144 {
145    Evas_Object *plug_img = NULL;
146
147    ELM_PLUG_CHECK(obj) EINA_FALSE;
148
149    plug_img = elm_plug_image_object_get(obj);
150    if (!plug_img) return EINA_FALSE;
151
152    if (ecore_evas_extn_plug_connect(plug_img, svcname, svcnum, svcsys))
153      {
154         Ecore_Evas *ee = NULL;
155         ee = ecore_evas_object_ecore_evas_get(plug_img);
156         if (!ee) return EINA_FALSE;
157
158         ecore_evas_data_set(ee, PLUG_KEY, obj);
159         ecore_evas_callback_delete_request_set(ee, _elm_plug_disconnected);
160         return EINA_TRUE;
161      }
162    else
163      return EINA_FALSE;
164 }