Merge branch 'master' of eunmi15.lee@165.213.180.234:/git/slp/pkgs/elementary
[framework/uifw/elementary.git] / src / edje_externals / elm_toggle.c
1 #include <string.h>
2
3 #include "private.h"
4
5 typedef struct _Elm_Params_Toggle
6 {
7    Elm_Params base;
8    Evas_Object *icon;
9    const char *on, *off;
10    Eina_Bool state:1;
11    Eina_Bool state_exists:1;
12 } Elm_Params_Toggle;
13
14 static void
15 external_toggle_state_set(void *data __UNUSED__, Evas_Object *obj, const void *from_params, const void *to_params, float pos __UNUSED__)
16 {
17    const Elm_Params_Toggle *p;
18
19    if (to_params) p = to_params;
20    else if (from_params) p = from_params;
21    else return;
22
23    if (p->base.label)
24      elm_toggle_label_set(obj, p->base.label);
25    if (p->icon)
26      elm_toggle_icon_set(obj, p->icon);
27
28    if ((p->on) && (p->off))
29      elm_toggle_states_labels_set(obj, p->on, p->off);
30    else if ((p->on) || (p->off))
31      {
32         const char *on, *off;
33         elm_toggle_states_labels_get(obj, &on, &off);
34         if (p->on)
35           elm_toggle_states_labels_set(obj, p->on, off);
36         else
37           elm_toggle_states_labels_set(obj, on, p->off);
38      }
39
40    if (p->state_exists)
41      elm_toggle_state_set(obj, p->state);
42 }
43
44 static Eina_Bool
45 external_toggle_param_set(void *data __UNUSED__, Evas_Object *obj, const Edje_External_Param *param)
46 {
47    if (!strcmp(param->name, "label"))
48      {
49         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
50           {
51              elm_toggle_label_set(obj, param->s);
52              return EINA_TRUE;
53           }
54      }
55    else if (!strcmp(param->name, "icon"))
56      {
57         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
58           {
59              Evas_Object *icon = external_common_param_icon_get(obj, param);
60              if ((strcmp(param->s, "")) && (!icon)) return EINA_FALSE;
61              elm_toggle_icon_set(obj, icon);
62              return EINA_TRUE;
63           }
64      }
65    else if (!strcmp(param->name, "label on"))
66      {
67         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
68           {
69              const char *on, *off;
70              elm_toggle_states_labels_get(obj, &on, &off);
71              elm_toggle_states_labels_set(obj, param->s, off);
72              return EINA_TRUE;
73           }
74      }
75    else if (!strcmp(param->name, "label off"))
76      {
77         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
78           {
79              const char *on, *off;
80              elm_toggle_states_labels_get(obj, &on, &off);
81              elm_toggle_states_labels_set(obj, on, param->s);
82              return EINA_TRUE;
83           }
84      }
85    else if (!strcmp(param->name, "state"))
86      {
87         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
88           {
89              elm_toggle_state_set(obj, param->i);
90              return EINA_TRUE;
91           }
92      }
93
94    ERR("unknown parameter '%s' of type '%s'",
95        param->name, edje_external_param_type_str(param->type));
96
97    return EINA_FALSE;
98 }
99
100 static Eina_Bool
101 external_toggle_param_get(void *data __UNUSED__, const Evas_Object *obj, Edje_External_Param *param)
102 {
103    if (!strcmp(param->name, "label"))
104      {
105         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
106           {
107              param->s = elm_toggle_label_get(obj);
108              return EINA_TRUE;
109           }
110      }
111    else if (!strcmp(param->name, "icon"))
112      {
113         /* not easy to get icon name back from live object */
114         return EINA_FALSE;
115      }
116    else if (!strcmp(param->name, "label on"))
117      {
118         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
119           {
120              const char *on, *off;
121              elm_toggle_states_labels_get(obj, &on, &off);
122              param->s = on;
123              return EINA_TRUE;
124           }
125      }
126    else if (!strcmp(param->name, "label off"))
127      {
128         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
129           {
130              const char *on, *off;
131              elm_toggle_states_labels_get(obj, &on, &off);
132              param->s = off;
133              return EINA_TRUE;
134           }
135      }
136    else if (!strcmp(param->name, "state"))
137      {
138         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
139           {
140              param->i = elm_toggle_state_get(obj);
141              return EINA_TRUE;
142           }
143      }
144
145    ERR("unknown parameter '%s' of type '%s'",
146        param->name, edje_external_param_type_str(param->type));
147
148    return EINA_FALSE;
149 }
150
151 static void *
152 external_toggle_params_parse(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const Eina_List *params)
153 {
154    Elm_Params_Toggle *mem;
155    Edje_External_Param *param;
156    const Eina_List *l;
157
158    mem = external_common_params_parse(Elm_Params_Toggle, data, obj, params);
159    if (!mem)
160      return NULL;
161
162    external_common_icon_param_parse(&mem->icon, obj, params);
163
164    EINA_LIST_FOREACH(params, l, param)
165      {
166         if (!strcmp(param->name, "state")) {
167            mem->state = param->i;
168            mem->state_exists = EINA_TRUE;
169           }
170         else if (!strcmp(param->name, "label on"))
171           mem->on = eina_stringshare_add(param->s);
172         else if (!strcmp(param->name, "label off"))
173           mem->off = eina_stringshare_add(param->s);
174      }
175
176    return mem;
177 }
178
179 static Evas_Object *external_toggle_content_get(void *data __UNUSED__,
180                 const Evas_Object *obj, const char *content)
181 {
182         ERR("so content");
183         return NULL;
184 }
185
186 static void
187 external_toggle_params_free(void *params)
188 {
189    Elm_Params_Toggle *mem = params;
190
191    if (mem->on)
192      eina_stringshare_del(mem->on);
193    if (mem->off)
194      eina_stringshare_del(mem->off);
195    external_common_params_free(params);
196 }
197
198 static Edje_External_Param_Info external_toggle_params[] = {
199    DEFINE_EXTERNAL_COMMON_PARAMS,
200    EDJE_EXTERNAL_PARAM_INFO_STRING("icon"),
201    EDJE_EXTERNAL_PARAM_INFO_STRING_DEFAULT("label on", "ON"),
202    EDJE_EXTERNAL_PARAM_INFO_STRING_DEFAULT("label off", "OFF"),
203    EDJE_EXTERNAL_PARAM_INFO_BOOL("state"),
204    EDJE_EXTERNAL_PARAM_INFO_SENTINEL
205 };
206
207 DEFINE_EXTERNAL_ICON_ADD(toggle, "toggle")
208 DEFINE_EXTERNAL_TYPE_SIMPLE(toggle, "Toggle")