aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/elementary/src/edje_externals/elm_icon.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/elementary/src/edje_externals/elm_icon.c322
1 files changed, 322 insertions, 0 deletions
diff --git a/libraries/elementary/src/edje_externals/elm_icon.c b/libraries/elementary/src/edje_externals/elm_icon.c
new file mode 100644
index 0000000..fbd1c5f
--- /dev/null
+++ b/libraries/elementary/src/edje_externals/elm_icon.c
@@ -0,0 +1,322 @@
1#include <assert.h>
2#include "private.h"
3
4typedef struct _Elm_Params_Icon
5{
6 const char *file;
7 Eina_Bool scale_up_exists;
8 Eina_Bool scale_up : 1;
9 Eina_Bool scale_down_exists;
10 Eina_Bool scale_down : 1;
11 Eina_Bool smooth_exists;
12 Eina_Bool smooth : 1;
13 Eina_Bool fill_outside_exists;
14 Eina_Bool fill_outside : 1;
15 Eina_Bool no_scale_exists;
16 Eina_Bool no_scale : 1;
17 Eina_Bool prescale_size_exists;
18 int prescale_size;
19 Elm_Params base;
20 const char *icon;
21} Elm_Params_Icon;
22
23static Elm_Params_Icon *param_icon;
24
25static void
26external_icon_state_set(void *data __UNUSED__, Evas_Object *obj,
27 const void *from_params, const void *to_params,
28 float pos __UNUSED__)
29{
30 const Elm_Params_Icon *p;
31 Evas_Object *edje;
32 const char *file;
33
34 if (to_params) p = to_params;
35 else if (from_params) p = from_params;
36 else return;
37
38 if (p->file)
39 {
40 elm_icon_file_set(obj, p->file, NULL);
41 param_icon->file = p->file;
42 }
43 if (p->smooth_exists)
44 {
45 elm_icon_smooth_set(obj, p->smooth);
46 param_icon->smooth = p->smooth;
47 }
48 if (p->no_scale_exists)
49 {
50 elm_icon_no_scale_set(obj, p->no_scale);
51 param_icon->no_scale = p->no_scale;
52 }
53 if (p->scale_up_exists && p->scale_down_exists)
54 {
55 elm_icon_resizable_set(obj, p->scale_up, p->scale_down);
56 param_icon->scale_up = p->scale_up;
57 param_icon->scale_down = p->scale_down;
58 }
59 else if (p->scale_up_exists || p->scale_down_exists)
60 {
61 if (p->scale_up_exists)
62 {
63 elm_icon_resizable_set(obj, p->scale_up, param_icon->scale_down);
64 param_icon->scale_up = p->scale_up;
65 }
66 else
67 {
68 elm_icon_resizable_set(obj, param_icon->scale_up, p->scale_down);
69 param_icon->scale_down = p->scale_down;
70 }
71 }
72 if (p->fill_outside_exists)
73 {
74 elm_icon_fill_outside_set(obj, p->fill_outside);
75 param_icon->fill_outside = p->fill_outside;
76 }
77 if (p->prescale_size_exists)
78 {
79 elm_icon_prescale_set(obj, p->prescale_size);
80 param_icon->prescale_size = p->prescale_size;
81 }
82 if (p->icon)
83 {
84 edje = evas_object_smart_parent_get(obj);
85 edje_object_file_get(edje, &file, NULL);
86
87 if (!elm_icon_file_set(obj, file, p->icon))
88 elm_icon_standard_set(obj, p->icon);
89 }
90}
91
92static Eina_Bool
93external_icon_param_set(void *data __UNUSED__, Evas_Object *obj,
94 const Edje_External_Param *param)
95{
96 Evas_Object *edje;
97 const char *file;
98
99 if (!strcmp(param->name, "file")
100 && param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
101 {
102 Eina_Bool ret = elm_icon_file_set(obj, param->s, NULL);
103 if (ret)
104 param_icon->file = param->s;
105 return ret;
106 }
107 else if (!strcmp(param->name, "smooth")
108 && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
109 {
110 elm_icon_smooth_set(obj, param->i);
111 param_icon->smooth = param->i;
112 return EINA_TRUE;
113 }
114 else if (!strcmp(param->name, "no scale")
115 && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
116 {
117 elm_icon_no_scale_set(obj, param->i);
118 param_icon->no_scale = param->i;
119 return EINA_TRUE;
120 }
121 else if (!strcmp(param->name, "scale up")
122 && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
123 {
124 elm_icon_resizable_set(obj, param->i, param_icon->scale_down);
125 param_icon->scale_up = param->i;
126 return EINA_TRUE;
127 }
128 else if (!strcmp(param->name, "scale down")
129 && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
130 {
131 elm_icon_resizable_set(obj, param_icon->scale_up, param->i);
132 param_icon->scale_down = param->i;
133 return EINA_TRUE;
134 }
135 else if (!strcmp(param->name, "fill outside")
136 && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
137 {
138 elm_icon_fill_outside_set(obj, param->i);
139 param_icon->fill_outside = param->i;
140 return EINA_TRUE;
141 }
142 else if (!strcmp(param->name, "prescale")
143 && param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
144 {
145 elm_icon_prescale_set(obj, param->i);
146 param_icon->prescale_size = param->i;
147 return EINA_TRUE;
148 }
149 else if (!strcmp(param->name, "icon"))
150 {
151 if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
152 {
153 edje = evas_object_smart_parent_get(obj);
154 edje_object_file_get(edje, &file, NULL);
155
156 if (!elm_icon_file_set(obj, file, param->s))
157 elm_icon_standard_set(obj, param->s);
158 return EINA_TRUE;
159 }
160 }
161
162 ERR("unknown parameter '%s' of type '%s'",
163 param->name, edje_external_param_type_str(param->type));
164
165 return EINA_FALSE;
166}
167
168static Eina_Bool
169external_icon_param_get(void *data __UNUSED__,
170 const Evas_Object *obj __UNUSED__,
171 Edje_External_Param *param)
172{
173 if (!strcmp(param->name, "file")
174 && param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
175 {
176 param->s = param_icon->file;
177 return EINA_TRUE;
178 }
179 else if (!strcmp(param->name, "smooth")
180 && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
181 {
182 param->i = param_icon->smooth;
183 return EINA_TRUE;
184 }
185 else if (!strcmp(param->name, "no scale")
186 && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
187 {
188 param->i = param_icon->no_scale;
189 return EINA_TRUE;
190 }
191 else if (!strcmp(param->name, "scale up")
192 && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
193 {
194 param->i = param_icon->scale_up;
195 return EINA_TRUE;
196 }
197 else if (!strcmp(param->name, "scale down")
198 && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
199 {
200 param->i = param_icon->scale_down;
201 return EINA_TRUE;
202 }
203 else if (!strcmp(param->name, "fill outside")
204 && param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
205 {
206 param->i = param_icon->fill_outside;
207 return EINA_TRUE;
208 }
209 else if (!strcmp(param->name, "prescale")
210 && param->type == EDJE_EXTERNAL_PARAM_TYPE_INT)
211 {
212 param->i = param_icon->prescale_size;
213 return EINA_TRUE;
214 }
215 else if (!strcmp(param->name, "icon"))
216 {
217 /* not easy to get icon name back from live object */
218 return EINA_FALSE;
219 }
220
221 ERR("unknown parameter '%s' of type '%s'",
222 param->name, edje_external_param_type_str(param->type));
223
224 return EINA_FALSE;
225}
226
227static void *
228external_icon_params_parse(void *data __UNUSED__, Evas_Object *obj __UNUSED__,
229 const Eina_List *params)
230{
231 Elm_Params_Icon *mem;
232 Edje_External_Param *param;
233 const Eina_List *l;
234 param_icon = calloc(1, sizeof(Elm_Params_Icon));
235 mem = ELM_NEW(Elm_Params_Icon);
236 if (!mem)
237 return NULL;
238
239 EINA_LIST_FOREACH(params, l, param)
240 {
241 if (!strcmp(param->name, "file"))
242 mem->file = eina_stringshare_add(param->s);
243 else if (!strcmp(param->name, "smooth"))
244 {
245 mem->smooth = param->i;
246 mem->smooth_exists = EINA_TRUE;
247 }
248 else if (!strcmp(param->name, "no scale"))
249 {
250 mem->no_scale = param->i;
251 mem->no_scale_exists = EINA_TRUE;
252 }
253 else if (!strcmp(param->name, "scale up"))
254 {
255 mem->scale_up = param->i;
256 mem->scale_up_exists = EINA_TRUE;
257 }
258 else if (!strcmp(param->name, "scale down"))
259 {
260 mem->scale_down = param->i;
261 mem->scale_down_exists = EINA_TRUE;
262 }
263 else if (!strcmp(param->name, "fill outside"))
264 {
265 mem->fill_outside = param->i;
266 mem->fill_outside_exists = EINA_TRUE;
267 }
268 else if (!strcmp(param->name, "prescale"))
269 {
270 mem->prescale_size = param->i;
271 mem->prescale_size_exists = EINA_TRUE;
272 }
273 else if (!strcmp(param->name, "icon"))
274 {
275 mem->icon = eina_stringshare_add(param->s);
276 }
277 }
278
279 return mem;
280}
281
282static Evas_Object *
283external_icon_content_get(void *data __UNUSED__,
284 const Evas_Object *obj __UNUSED__,
285 const char *content __UNUSED__)
286{
287 ERR("no content");
288 return NULL;
289}
290
291static void
292external_icon_params_free(void *params)
293{
294 Elm_Params_Icon *mem = params;
295
296 if (mem->file)
297 eina_stringshare_del(mem->file);
298
299 if (param_icon->file)
300 eina_stringshare_del(param_icon->file);
301 free(param_icon);
302
303 if (mem->icon)
304 eina_stringshare_del(mem->icon);
305 free(mem);
306}
307
308static Edje_External_Param_Info external_icon_params[] = {
309 DEFINE_EXTERNAL_COMMON_PARAMS,
310 EDJE_EXTERNAL_PARAM_INFO_STRING("icon"),
311 EDJE_EXTERNAL_PARAM_INFO_STRING("file"),
312 EDJE_EXTERNAL_PARAM_INFO_BOOL("smooth"),
313 EDJE_EXTERNAL_PARAM_INFO_BOOL("no scale"),
314 EDJE_EXTERNAL_PARAM_INFO_BOOL("scale up"),
315 EDJE_EXTERNAL_PARAM_INFO_BOOL("scale down"),
316 EDJE_EXTERNAL_PARAM_INFO_BOOL("fill outside"),
317 EDJE_EXTERNAL_PARAM_INFO_INT("prescale"),
318 EDJE_EXTERNAL_PARAM_INFO_SENTINEL
319};
320
321DEFINE_EXTERNAL_ICON_ADD(icon, "icon");
322DEFINE_EXTERNAL_TYPE_SIMPLE(icon, "Icon");