ce1da8ea257857fd268012e22ec7c82cf17dc36b
[framework/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    evas_object_smart_member_add(sd->evas_obj, obj);
121    evas_object_image_size_set(sd->evas_obj, sd->vw, sd->vh);
122    sd->evas = ecore_evas_get(evas_object_data_get(sd->evas_obj, "Ecore_Evas"));
123    e_canvas_add(evas_object_data_get(sd->evas_obj, "Ecore_Evas"));
124 }
125
126 static void
127 _e_smart_del(Evas_Object *obj)
128 {
129    INTERNAL_ENTRY;
130    e_canvas_del(evas_object_data_get(sd->evas_obj, "Ecore_Evas"));
131    evas_object_del(sd->evas_obj);
132    free(sd);
133 }
134
135 static void
136 _e_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
137 {
138    INTERNAL_ENTRY;
139    if ((sd->x == x) && (sd->y == y)) return;
140    sd->x = x;
141    sd->y = y;
142    _e_smart_reconfigure(sd);
143 }
144
145 static void
146 _e_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
147 {
148    INTERNAL_ENTRY;
149    if ((sd->w == w) && (sd->h == h)) return;
150    sd->w = w;
151    sd->h = h;
152    _e_smart_reconfigure(sd);
153 }
154
155 static void
156 _e_smart_show(Evas_Object *obj)
157 {
158    INTERNAL_ENTRY;
159    evas_object_show(sd->evas_obj);
160 }
161
162 static void
163 _e_smart_hide(Evas_Object *obj)
164 {
165    INTERNAL_ENTRY;
166    evas_object_hide(sd->evas_obj);
167 }
168
169 static void
170 _e_smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
171 {
172    INTERNAL_ENTRY;
173    evas_object_color_set(sd->evas_obj, r, g, b, a);
174 }
175
176 static void
177 _e_smart_clip_set(Evas_Object *obj, Evas_Object * clip)
178 {
179    INTERNAL_ENTRY;
180    evas_object_clip_set(sd->evas_obj, clip);
181 }
182
183 static void
184 _e_smart_clip_unset(Evas_Object *obj)
185 {
186    INTERNAL_ENTRY;
187    evas_object_clip_unset(sd->evas_obj);
188 }  
189
190 /* never need to touch this */
191
192 static void
193 _e_smart_init(void)
194 {
195    if (_e_smart) return;
196      {
197         static const Evas_Smart_Class sc =
198           {
199              SMART_NAME,
200                EVAS_SMART_CLASS_VERSION,
201                _e_smart_add,
202                _e_smart_del, 
203                _e_smart_move,
204                _e_smart_resize,
205                _e_smart_show,
206                _e_smart_hide,
207                _e_smart_color_set,
208                _e_smart_clip_set,
209                _e_smart_clip_unset,
210                NULL,
211                NULL,
212                NULL,
213                NULL,
214                NULL,
215                NULL,
216                NULL
217           };
218         _e_smart = evas_smart_class_new(&sc);
219      }
220 }
221