Merge from TIZEN 2.3
[platform/core/uifw/e17.git] / src / bin / e_livethumb.c
1 #include "e.h"
2
3 #define SMART_NAME     "e_livethumb"
4 #define API_ENTRY      E_Smart_Data * sd; sd = evas_object_smart_data_get(obj); if ((!obj) || (!sd) || (evas_object_type_get(obj) && strcmp(evas_object_type_get(obj), SMART_NAME)))
5 #define INTERNAL_ENTRY E_Smart_Data * sd; sd = evas_object_smart_data_get(obj); if (!sd) return;
6 typedef struct _E_Smart_Data E_Smart_Data;
7 typedef struct _E_Smart_Item E_Smart_Item;
8
9 struct _E_Smart_Data
10 {
11    Evas_Coord   x, y, w, h;
12
13    Evas_Object *smart_obj;
14    Evas_Object *evas_obj;
15    Evas_Object *thumb_obj;
16    Evas        *evas;
17    Evas_Coord   vw, vh;
18 };
19
20 /* local subsystem functions */
21 static void _e_smart_reconfigure(E_Smart_Data *sd);
22 static void _e_smart_add(Evas_Object *obj);
23 static void _e_smart_del(Evas_Object *obj);
24 static void _e_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
25 static void _e_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
26 static void _e_smart_show(Evas_Object *obj);
27 static void _e_smart_hide(Evas_Object *obj);
28 static void _e_smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
29 static void _e_smart_clip_set(Evas_Object *obj, Evas_Object *clip);
30 static void _e_smart_clip_unset(Evas_Object *obj);
31 static void _e_smart_init(void);
32
33 /* local subsystem globals */
34 static Evas_Smart *_e_smart = NULL;
35
36 /* externally accessible functions */
37 EAPI Evas_Object *
38 e_livethumb_add(Evas *e)
39 {
40    _e_smart_init();
41    return evas_object_smart_add(e, _e_smart);
42 }
43
44 EAPI Evas *
45 e_livethumb_evas_get(Evas_Object *obj)
46 {
47    API_ENTRY return NULL;
48    return sd->evas;
49 }
50
51 EAPI void
52 e_livethumb_vsize_set(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
53 {
54    API_ENTRY return;
55    if ((w == sd->vw) && (h == sd->vh)) return;
56    sd->vw = w;
57    sd->vh = h;
58    evas_object_image_size_set(sd->evas_obj, sd->vw, sd->vh);
59    if (sd->thumb_obj) evas_object_resize(sd->thumb_obj, sd->vw, sd->vh);
60 }
61
62 EAPI void
63 e_livethumb_vsize_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
64 {
65    API_ENTRY return;
66    if (w) *w = sd->vw;
67    if (h) *h = sd->vh;
68 }
69
70 EAPI void
71 e_livethumb_thumb_set(Evas_Object *obj, Evas_Object *thumb)
72 {
73    API_ENTRY return;
74    if (!thumb)
75      {
76         sd->thumb_obj = NULL;
77         return;
78      }
79    sd->thumb_obj = thumb;
80    evas_object_show(sd->thumb_obj);
81    evas_object_move(sd->thumb_obj, 0, 0);
82    evas_object_resize(sd->thumb_obj, sd->vw, sd->vh);
83 }
84
85 EAPI Evas_Object *
86 e_livethumb_thumb_get(Evas_Object *obj)
87 {
88    API_ENTRY return NULL;
89    return sd->thumb_obj;
90 }
91
92 /* local subsystem functions */
93
94 static void
95 _e_smart_reconfigure(E_Smart_Data *sd)
96 {
97    evas_object_move(sd->evas_obj, sd->x, sd->y);
98    evas_object_resize(sd->evas_obj, sd->w, sd->h);
99    evas_object_image_fill_set(sd->evas_obj, 0, 0, sd->w, sd->h);
100 }
101
102 static void
103 _e_smart_add(Evas_Object *obj)
104 {
105    E_Smart_Data *sd;
106
107    sd = calloc(1, sizeof(E_Smart_Data));
108    if (!sd) return;
109    evas_object_smart_data_set(obj, sd);
110
111    sd->smart_obj = obj;
112    sd->x = 0;
113    sd->y = 0;
114    sd->w = 0;
115    sd->h = 0;
116    sd->vw = 1;
117    sd->vh = 1;
118
119    sd->evas_obj = ecore_evas_object_image_new(ecore_evas_ecore_evas_get(evas_object_evas_get(obj)));
120    ecore_evas_alpha_set(evas_object_data_get(sd->evas_obj, "Ecore_Evas"), 1);
121    evas_object_smart_member_add(sd->evas_obj, obj);
122    evas_object_image_size_set(sd->evas_obj, sd->vw, sd->vh);
123    sd->evas = ecore_evas_get(evas_object_data_get(sd->evas_obj, "Ecore_Evas"));
124    e_canvas_add(evas_object_data_get(sd->evas_obj, "Ecore_Evas"));
125 }
126
127 static void
128 _e_smart_del(Evas_Object *obj)
129 {
130    INTERNAL_ENTRY;
131    e_canvas_del(evas_object_data_get(sd->evas_obj, "Ecore_Evas"));
132    evas_object_del(sd->evas_obj);
133    free(sd);
134 }
135
136 static void
137 _e_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
138 {
139    INTERNAL_ENTRY;
140    if ((sd->x == x) && (sd->y == y)) return;
141    sd->x = x;
142    sd->y = y;
143    _e_smart_reconfigure(sd);
144 }
145
146 static void
147 _e_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
148 {
149    INTERNAL_ENTRY;
150    if ((sd->w == w) && (sd->h == h)) return;
151    sd->w = w;
152    sd->h = h;
153    _e_smart_reconfigure(sd);
154 }
155
156 static void
157 _e_smart_show(Evas_Object *obj)
158 {
159    INTERNAL_ENTRY;
160    evas_object_show(sd->evas_obj);
161 }
162
163 static void
164 _e_smart_hide(Evas_Object *obj)
165 {
166    INTERNAL_ENTRY;
167    evas_object_hide(sd->evas_obj);
168 }
169
170 static void
171 _e_smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
172 {
173    INTERNAL_ENTRY;
174    evas_object_color_set(sd->evas_obj, r, g, b, a);
175 }
176
177 static void
178 _e_smart_clip_set(Evas_Object *obj, Evas_Object *clip)
179 {
180    INTERNAL_ENTRY;
181    evas_object_clip_set(sd->evas_obj, clip);
182 }
183
184 static void
185 _e_smart_clip_unset(Evas_Object *obj)
186 {
187    INTERNAL_ENTRY;
188    evas_object_clip_unset(sd->evas_obj);
189 }
190
191 /* never need to touch this */
192
193 static void
194 _e_smart_init(void)
195 {
196    if (_e_smart) return;
197    {
198       static const Evas_Smart_Class sc =
199       {
200          SMART_NAME,
201          EVAS_SMART_CLASS_VERSION,
202          _e_smart_add,
203          _e_smart_del,
204          _e_smart_move,
205          _e_smart_resize,
206          _e_smart_show,
207          _e_smart_hide,
208          _e_smart_color_set,
209          _e_smart_clip_set,
210          _e_smart_clip_unset,
211          NULL,
212          NULL,
213          NULL,
214          NULL,
215          NULL,
216          NULL,
217          NULL
218       };
219       _e_smart = evas_smart_class_new(&sc);
220    }
221 }
222