Merge "[Copy&Paste] remove "Paste" button when CBHM has no item"
[framework/uifw/elementary.git] / src / edje_externals / elm_entry.c
1 #include <assert.h>
2
3 #include "private.h"
4
5 typedef struct _Elm_Params_Entry
6 {
7    Elm_Params base;
8    const char *label;
9    const char *entry;
10    Evas_Object *icon;
11    Eina_Bool scrollable:1;
12    Eina_Bool scrollable_exists:1;
13    Eina_Bool single_line:1;
14    Eina_Bool single_line_exists:1;
15    Eina_Bool password:1;
16    Eina_Bool password_exists:1;
17    Eina_Bool horizontal_bounce:1;
18    Eina_Bool horizontal_bounce_exists:1;
19    Eina_Bool vertical_bounce:1;
20    Eina_Bool vertical_bounce_exists:1;
21    Eina_Bool editable:1;
22    Eina_Bool editable_exists:1;
23    const char *line_wrap;
24 } Elm_Params_Entry;
25
26 #define CHOICE_GET(CHOICES, STR)                \
27   unsigned int i;                               \
28   for (i = 0; i < sizeof(CHOICES)/sizeof (CHOICES)[0]; i++)         \
29     if (strcmp((STR), (CHOICES)[i]) == 0)           \
30       return i
31
32
33 static const char *entry_line_wrap_choices[] = {"none", "char", "word",
34                                           "mixed", NULL};
35
36 static Elm_Wrap_Type
37 _entry_line_wrap_choices_setting_get(const char *line_wrap_str)
38 {
39    assert(sizeof(entry_line_wrap_choices)/
40           sizeof(entry_line_wrap_choices[0]) == ELM_WRAP_LAST + 1);
41    CHOICE_GET(entry_line_wrap_choices, line_wrap_str);
42    return ELM_WRAP_LAST;
43 }
44
45 static void
46 external_entry_state_set(void *data __UNUSED__, Evas_Object *obj, const void *from_params, const void *to_params, float pos __UNUSED__)
47 {
48    const Elm_Params_Entry *p;
49    Eina_Bool hbounce, vbounce;
50    Elm_Wrap_Type line_wrap;
51
52    if (to_params) p = to_params;
53    else if (from_params) p = from_params;
54    else return;
55
56    if (p->label)
57      elm_object_text_set(obj, p->label);
58    if (p->icon)
59      elm_entry_icon_set(obj, p->icon);
60    if (p->entry)
61      elm_entry_entry_set(obj, p->entry);
62    if (p->scrollable_exists)
63      elm_entry_scrollable_set(obj, p->scrollable);
64    if (p->single_line_exists)
65      elm_entry_single_line_set(obj, p->single_line);
66    if (p->password_exists)
67      elm_entry_password_set(obj, p->password);
68    if (p->horizontal_bounce_exists && p->vertical_bounce_exists)
69      elm_entry_bounce_set(obj, p->horizontal_bounce, p->vertical_bounce);
70    else if (p->horizontal_bounce_exists || p->vertical_bounce_exists)
71      {
72         elm_entry_bounce_get(obj, &hbounce, &vbounce);
73         if (p->horizontal_bounce_exists)
74           elm_entry_bounce_set(obj, p->horizontal_bounce, vbounce);
75         else
76           elm_entry_bounce_set(obj, hbounce, p->vertical_bounce);
77      }
78    if (p->editable_exists)
79      elm_entry_editable_set(obj, p->editable);
80    if (p->line_wrap)
81      {
82         line_wrap = _entry_line_wrap_choices_setting_get(p->line_wrap);
83         elm_entry_line_wrap_set(obj, line_wrap);
84      }
85 }
86
87 static Eina_Bool
88 external_entry_param_set(void *data __UNUSED__, Evas_Object *obj, const Edje_External_Param *param)
89 {
90    if (!strcmp(param->name, "label"))
91      {
92         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
93           {
94              elm_object_text_set(obj, param->s);
95              return EINA_TRUE;
96           }
97      }
98    else if (!strcmp(param->name, "icon"))
99      {
100         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
101           {
102              Evas_Object *icon = external_common_param_icon_get(obj, param);
103              elm_entry_icon_set(obj, icon);
104              return EINA_TRUE;
105           }
106      }
107    else if (!strcmp(param->name, "entry"))
108      {
109         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
110           {
111              elm_entry_entry_set(obj, param->s);
112              return EINA_TRUE;
113           }
114      }
115    else if (!strcmp(param->name, "scrollable"))
116      {
117         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
118           {
119              elm_entry_scrollable_set(obj, param->i);
120              return EINA_TRUE;
121           }
122      }
123    else if (!strcmp(param->name, "single line"))
124      {
125         if(param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
126           {
127              elm_entry_single_line_set(obj, param->i);
128              return EINA_TRUE;
129           }
130      }
131    else if (!strcmp(param->name, "password"))
132      {
133         if(param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
134           {
135              elm_entry_password_set(obj, param->i);
136              return EINA_TRUE;
137           }
138      }
139    else if (!strcmp(param->name, "horizontal bounce"))
140      {
141         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
142           {
143              Eina_Bool hbounce, vbounce;
144              elm_entry_bounce_get(obj, NULL, &vbounce);
145              hbounce = !!param->i;
146              elm_entry_bounce_set(obj, hbounce, vbounce);
147              return EINA_TRUE;
148           }
149      }
150    else if (!strcmp(param->name, "vertical bounce"))
151      {
152         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
153           {
154              Eina_Bool hbounce, vbounce;
155              elm_entry_bounce_get(obj, &hbounce, NULL);
156              vbounce = !!param->i;
157              elm_entry_bounce_set(obj, hbounce, vbounce);
158              return EINA_TRUE;
159           }
160      }
161    else if (!strcmp(param->name, "editable"))
162      {
163         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
164           {
165              elm_entry_editable_set(obj, param->i);
166              return EINA_TRUE;
167           }
168      }
169    else if (!strcmp(param->name, "line wrap"))
170      {
171         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
172           {
173              Elm_Wrap_Type line_wrap;
174              line_wrap = _entry_line_wrap_choices_setting_get(param->s);
175              if (line_wrap == ELM_WRAP_LAST) return EINA_FALSE;
176              elm_entry_line_wrap_set(obj, line_wrap);
177              return EINA_TRUE;
178           }
179      }
180
181    ERR("unknown parameter '%s' of type '%s'",
182        param->name, edje_external_param_type_str(param->type));
183
184    return EINA_FALSE;
185 }
186
187 static Eina_Bool
188 external_entry_param_get(void *data __UNUSED__, const Evas_Object *obj, Edje_External_Param *param)
189 {
190    if (!strcmp(param->name, "label"))
191      {
192         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
193           {
194              param->s = elm_object_text_get(obj);
195              return EINA_TRUE;
196           }
197      }
198    else if (!strcmp(param->name, "icon"))
199      {
200         /* not easy to get icon name back from live object */
201         return EINA_FALSE;
202      }
203    else if (!strcmp(param->name, "entry"))
204      {
205         if (param->type ==  EDJE_EXTERNAL_PARAM_TYPE_STRING)
206           {
207              param->s = elm_entry_entry_get(obj);
208              return EINA_TRUE;
209           }
210      }
211    else if (!strcmp(param->name, "scrollable"))
212      {
213         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
214           {
215              param->i = elm_entry_scrollable_get(obj);
216              return EINA_TRUE;
217           }
218      }
219    else if (!strcmp(param->name, "single line"))
220      {
221         if (param->type ==  EDJE_EXTERNAL_PARAM_TYPE_BOOL)
222           {
223              param->i = elm_entry_single_line_get(obj);
224              return EINA_TRUE;
225           }
226      }
227    else if (!strcmp(param->name, "password"))
228      {
229         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
230           {
231              param->i = elm_entry_password_get(obj);
232              return EINA_TRUE;
233           }
234      }
235    else if (!strcmp(param->name, "horizontal bounce"))
236      {
237         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
238           {
239              Eina_Bool hbounce;
240              elm_entry_bounce_get(obj, &hbounce, NULL);
241              param->i = hbounce;
242              return EINA_TRUE;
243           }
244      }
245    else if (!strcmp(param->name, "vertical bounce"))
246      {
247         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
248           {
249              Eina_Bool vbounce;
250              elm_entry_bounce_get(obj, NULL, &vbounce);
251              param->i = vbounce;
252              return EINA_TRUE;
253           }
254      }
255    else if (!strcmp(param->name, "editable"))
256      {
257         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
258           {
259              param->i = elm_entry_editable_get(obj);
260              return EINA_TRUE;
261           }
262      }
263    else if (!strcmp(param->name, "line wrap"))
264      {
265         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
266           {
267              Elm_Wrap_Type line_wrap;
268              line_wrap = elm_entry_line_wrap_get(obj);
269              param->s = entry_line_wrap_choices[line_wrap];
270              return EINA_TRUE;
271           }
272      }
273
274    ERR("unknown parameter '%s' of type '%s'",
275        param->name, edje_external_param_type_str(param->type));
276
277    return EINA_FALSE;
278 }
279
280 static void *
281 external_entry_params_parse(void *data __UNUSED__, Evas_Object *obj, const Eina_List *params)
282 {
283    Elm_Params_Entry *mem;
284    Edje_External_Param *param;
285    const Eina_List *l;
286
287    mem = ELM_NEW(Elm_Params_Entry);
288    if (!mem)
289      return NULL;
290
291    external_common_icon_param_parse(&mem->icon, obj, params);
292
293    EINA_LIST_FOREACH(params, l, param)
294      {
295         if (!strcmp(param->name, "label"))
296           {
297              mem->label = eina_stringshare_add(param->s);
298           }
299         else if (!strcmp(param->name, "entry"))
300           {
301              mem->entry = eina_stringshare_add(param->s);
302           }
303         else if (!strcmp(param->name, "scrollable"))
304           {
305              mem->scrollable = !!param->i;
306              mem->scrollable_exists = EINA_TRUE;
307           }
308         else if (!strcmp(param->name, "single line"))
309           {
310              mem->single_line = !!param->i;
311              mem->single_line_exists = EINA_TRUE;
312           }
313         else if (!strcmp(param->name, "password"))
314           {
315              mem->password = !!param->i;
316              mem->password_exists = EINA_TRUE;
317           }
318         else if (!strcmp(param->name, "horizontal bounce"))
319           {
320              mem->horizontal_bounce = !!param->i;
321              mem->horizontal_bounce_exists = EINA_TRUE;
322           }
323         else if (!strcmp(param->name, "vertical bounce"))
324           {
325              mem->vertical_bounce = !!param->i;
326              mem->vertical_bounce_exists = EINA_TRUE;
327           }
328         else if (!strcmp(param->name, "editable"))
329           {
330              mem->editable = !!param->i;
331              mem->editable_exists = EINA_TRUE;
332           }
333         else if (!strcmp(param->name, "line wrap"))
334           mem->line_wrap = eina_stringshare_add(param->s);
335      }
336
337    return mem;
338 }
339
340 static Evas_Object *external_entry_content_get(void *data __UNUSED__,
341                 const Evas_Object *obj __UNUSED__, const char *content __UNUSED__)
342 {
343         ERR("No content.");
344         return NULL;
345 }
346
347 static void
348 external_entry_params_free(void *params)
349 {
350    Elm_Params_Entry *mem = params;
351    if (mem->label)
352      eina_stringshare_del(mem->label);
353    if (mem->entry)
354      eina_stringshare_del(mem->entry);
355    if (mem->line_wrap)
356      eina_stringshare_del(mem->line_wrap);
357    free(params);
358 }
359
360 static Edje_External_Param_Info external_entry_params[] = {
361    DEFINE_EXTERNAL_COMMON_PARAMS,
362    EDJE_EXTERNAL_PARAM_INFO_STRING("label"),
363    EDJE_EXTERNAL_PARAM_INFO_STRING("icon"),
364    EDJE_EXTERNAL_PARAM_INFO_STRING("entry"),
365    EDJE_EXTERNAL_PARAM_INFO_BOOL("scrollable"),
366    EDJE_EXTERNAL_PARAM_INFO_BOOL("single line"),
367    EDJE_EXTERNAL_PARAM_INFO_BOOL("password"),
368    EDJE_EXTERNAL_PARAM_INFO_BOOL("horizontal bounce"),
369    EDJE_EXTERNAL_PARAM_INFO_BOOL("vertical bounce"),
370    EDJE_EXTERNAL_PARAM_INFO_BOOL("editable"),
371    EDJE_EXTERNAL_PARAM_INFO_STRING("line_wrap"),
372    EDJE_EXTERNAL_PARAM_INFO_SENTINEL
373 };
374
375 DEFINE_EXTERNAL_ICON_ADD(entry, "entry");
376 DEFINE_EXTERNAL_TYPE_SIMPLE(entry, "Entry");