Merge "[Password]: New design based changes, a new style removed password mode contro...
[framework/uifw/elementary.git] / src / edje_externals / elm_scrolled_entry.c
1 #include "private.h"
2
3 typedef struct _Elm_Params_Entry
4 {
5    const char *text;
6    Eina_Bool text_set:1;
7    Eina_Bool editable:1;
8    Eina_Bool editable_exists:1;   
9    Eina_Bool single:1;
10    Eina_Bool single_exists:1;   
11    Eina_Bool wrap:1;
12    Eina_Bool wrap_exists:1;   
13    Eina_Bool char_wrap:1;
14    Eina_Bool char_wrap_exists:1;
15    Eina_Bool password:1;
16    Eina_Bool password_exists:1;
17    Eina_Bool context_menu_disabled:1;
18    Eina_Bool context_menu_disabled_exists:1;
19    Eina_Bool bounce:1;
20    Eina_Bool bounce_exists;
21    Eina_Bool h_bounce:1;
22    Eina_Bool h_bounce_exists:1;
23    Eina_Bool v_bounce:1;
24    Eina_Bool v_bounce_exists:1;
25    Eina_Bool autocapitalization:1;
26    Eina_Bool autocapitalization_exists:1;   
27    Eina_Bool autoperiod:1;
28    Eina_Bool autoperiod_exists:1;   
29    
30 } Elm_Params_Entry;
31
32 static void
33 external_scrolled_entry_state_set(void *data __UNUSED__, Evas_Object *obj, const void *from_params, const void *to_params, float pos __UNUSED__)
34 {
35    const Elm_Params_Entry *p;
36
37    if (to_params) p = to_params;
38    else if (from_params) p = from_params;
39    else return;
40
41    if ((!p->text_set) && (p->text))
42      {
43         elm_scrolled_entry_entry_set(obj, p->text);
44         ((Elm_Params_Entry *)p)->text_set = EINA_TRUE;
45      }
46    if (p->editable_exists)
47      elm_scrolled_entry_editable_set(obj, p->editable);
48    if (p->single_exists)
49      elm_scrolled_entry_single_line_set(obj, p->single);
50    if (p->wrap_exists)
51      elm_scrolled_entry_line_wrap_set(obj, p->wrap);
52    if (p->char_wrap_exists)
53      elm_scrolled_entry_line_char_wrap_set(obj, p->char_wrap);  
54    if (p->password_exists)
55      elm_scrolled_entry_password_set(obj, p->password);
56    if (p->context_menu_disabled_exists)
57      elm_scrolled_entry_context_menu_disabled_set(obj, p->context_menu_disabled);   
58    if ((p->h_bounce_exists) && (p->v_bounce_exists))
59      elm_scrolled_entry_bounce_set(obj, p->h_bounce, p->v_bounce);   
60    else if ((p->h_bounce_exists) || (p->v_bounce_exists))
61      {
62         Eina_Bool h_bounce, v_bounce;
63
64         elm_smart_scroller_bounce_allow_get(obj, &h_bounce, &v_bounce);
65         if (p->h_bounce_exists)
66           elm_scrolled_entry_bounce_set(obj, p->h_bounce, v_bounce);
67         else
68           elm_scrolled_entry_bounce_set(obj, h_bounce, p->v_bounce);
69      }
70    if (p->autocapitalization_exists)
71      elm_scrolled_entry_autocapitalization_set(obj, p->autocapitalization);
72    if (p->autoperiod_exists)
73      elm_scrolled_entry_autoperiod_set(obj, p->autoperiod);   
74 }
75
76 static Eina_Bool
77 external_scrolled_entry_param_set(void *data __UNUSED__, Evas_Object *obj, const Edje_External_Param *param)
78 {
79    if (!strcmp(param->name, "text"))
80      {
81         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
82           {
83              elm_scrolled_entry_entry_set(obj, param->s);
84              return EINA_TRUE;
85           }
86      }
87    else if (!strcmp(param->name, "editable"))
88      {
89         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
90           {
91              elm_scrolled_entry_editable_set(obj, param->i);
92              return EINA_TRUE;
93           }
94      }
95    else if (!strcmp(param->name, "single line"))
96      {
97         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
98           {
99              elm_scrolled_entry_single_line_set(obj, param->i);
100              return EINA_TRUE;
101           }
102      }
103    else if (!strcmp(param->name, "line wrap"))
104      {
105         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
106           {
107              elm_scrolled_entry_line_wrap_set(obj, param->i);
108              return EINA_TRUE;
109           }
110      }
111    else if (!strcmp(param->name, "character line wrap"))
112      {
113         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
114           {
115              elm_scrolled_entry_line_char_wrap_set(obj, param->i);
116              return EINA_TRUE;
117           }
118      }     
119    else if (!strcmp(param->name, "password"))
120      {
121         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
122           {
123              elm_scrolled_entry_password_set(obj, param->i);
124              return EINA_TRUE;
125           }
126      }
127    else if (!strcmp(param->name, "context menu disabled"))
128      {
129         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
130           {
131              elm_scrolled_entry_context_menu_disabled_set(obj, param->i);
132              return EINA_TRUE;
133           }
134      }
135    else if (!strcmp(param->name, "height bounce"))
136      {
137         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
138           {
139              Eina_Bool h_bounce, v_bounce;
140              elm_smart_scroller_bounce_allow_get(obj, &h_bounce, &v_bounce);
141              elm_scrolled_entry_bounce_set(obj, param->i, v_bounce);
142              return EINA_TRUE;
143           }
144      }
145    else if (!strcmp(param->name, "width bounce"))
146      {
147         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
148           {
149              Eina_Bool h_bounce, v_bounce;
150              elm_smart_scroller_bounce_allow_get(obj, &h_bounce, &v_bounce);
151              elm_scrolled_entry_bounce_set(obj, h_bounce, param->i);
152              return EINA_TRUE;
153           }
154      }  
155    else if (!strcmp(param->name, "autocapitalization"))
156      {
157         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
158           {
159              elm_scrolled_entry_autocapitalization_set(obj, param->i);
160              return EINA_TRUE;
161           }
162      }
163    else if (!strcmp(param->name, "autoperiod"))
164      {
165         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
166           {
167              elm_scrolled_entry_autoperiod_set(obj, param->i);
168              return EINA_TRUE;
169           }
170      }
171    
172    ERR("unknown parameter '%s' of type '%s'",
173        param->name, edje_external_param_type_str(param->type));
174
175    return EINA_FALSE;
176 }
177
178 static Eina_Bool
179 external_scrolled_entry_param_get(void *data __UNUSED__, const Evas_Object *obj, Edje_External_Param *param)
180 {
181    if (!strcmp(param->name, "text"))
182      {
183         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_STRING)
184           {
185              param->s = elm_scrolled_entry_entry_get(obj);
186              return EINA_TRUE;
187           }
188      }
189    else if (!strcmp(param->name, "editable"))
190      {
191         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
192           {
193              param->i = elm_scrolled_entry_editable_get(obj);
194              return EINA_TRUE;
195           }
196      }
197    else if (!strcmp(param->name, "single line"))
198      {
199         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
200           {
201              param->i = elm_scrolled_entry_single_line_get(obj);
202              return EINA_TRUE;
203           }
204      }
205    else if (!strcmp(param->name, "password"))
206      {
207         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
208           {
209              param->i = elm_scrolled_entry_password_get(obj);
210              return EINA_TRUE;
211           }
212      }
213    else if (!strcmp(param->name, "context menu disabled"))
214      {
215         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
216           {
217              param->i = elm_scrolled_entry_context_menu_disabled_get(obj);
218              return EINA_TRUE;
219           }
220      }
221    else if (!strcmp(param->name, "height bounce"))
222      {
223         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
224           {
225              Eina_Bool h_bounce, v_bounce;
226              elm_smart_scroller_bounce_allow_get(obj, &h_bounce, &v_bounce);
227              param->i = h_bounce;
228              return EINA_TRUE;
229           }
230      }
231    else if (!strcmp(param->name, "width bounce"))
232      {
233         if (param->type == EDJE_EXTERNAL_PARAM_TYPE_BOOL)
234           {
235              Eina_Bool h_bounce, v_bounce;
236              elm_smart_scroller_bounce_allow_get(obj, &h_bounce, &v_bounce);
237              param->i = v_bounce;
238              return EINA_TRUE;
239           }
240      }   
241
242    ERR("unknown parameter '%s' of type '%s'",
243        param->name, edje_external_param_type_str(param->type));
244
245    return EINA_FALSE;
246 }
247
248 static void *
249 external_scrolled_entry_params_parse(void *data __UNUSED__, Evas_Object *obj __UNUSED__, const Eina_List *params)
250 {
251    Elm_Params_Entry *mem;
252    Edje_External_Param *param;
253    const Eina_List *l;
254
255    mem = calloc(1, sizeof(Elm_Params_Entry));
256    if (!mem)
257      return NULL;
258
259    EINA_LIST_FOREACH(params, l, param)
260      {
261         if (!strcmp(param->name, "text"))
262           mem->text = eina_stringshare_add(param->s);
263         else if (!strcmp(param->name, "single line"))
264           {
265              mem->single = !!param->i;
266              mem->single_exists = EINA_TRUE;
267           }
268         else if (!strcmp(param->name, "line wrap"))
269           {
270              mem->wrap = !!param->i;
271              mem->wrap_exists = EINA_TRUE;
272           }
273         else if (!strcmp(param->name, "character line wrap"))
274           {
275              mem->char_wrap = !!param->i;
276              mem->char_wrap_exists = EINA_TRUE;
277           }   
278         else if (!strcmp(param->name, "password"))
279           {
280              mem->password = !!param->i;
281              mem->password_exists = EINA_TRUE;
282           }
283         else if (!strcmp(param->name, "editable"))
284           {
285              mem->editable = param->i;
286              mem->editable_exists = EINA_TRUE;
287           }
288         else if (!strcmp(param->name, "context menu disabled"))
289           {
290              mem->context_menu_disabled = param->i;
291              mem->context_menu_disabled_exists = EINA_TRUE;
292           }   
293         else if (!strcmp(param->name, "height bounce"))
294           {
295              mem->h_bounce = !!param->i;
296              mem->h_bounce_exists = EINA_TRUE;
297           }
298         else if (!strcmp(param->name, "width bounce"))
299           {
300              mem->v_bounce = !!param->i;
301              mem->v_bounce_exists = EINA_TRUE;
302           }
303         else if (!strcmp(param->name, "autocapitalization"))
304           {
305              mem->autocapitalization = !!param->i;
306              mem->autocapitalization_exists = EINA_TRUE;
307           }
308         else if (!strcmp(param->name, "autoperiod"))
309           {
310              mem->autoperiod = !!param->i;
311              mem->autoperiod_exists = EINA_TRUE;
312           }
313      }
314
315    return mem;
316 }
317
318 static Evas_Object *external_scrolled_entry_content_get(void *data __UNUSED__,
319                 const Evas_Object *obj __UNUSED__, const char *content __UNUSED__)
320 {
321         ERR("No content.");
322         return NULL;
323 }
324
325 static void
326 external_scrolled_entry_params_free(void *params)
327 {
328    Elm_Params_Entry *mem = params;
329
330    if (mem->text)
331      eina_stringshare_del(mem->text);
332    free(mem);
333 }
334
335 static Edje_External_Param_Info external_scrolled_entry_params[] = {
336    DEFINE_EXTERNAL_COMMON_PARAMS,
337    EDJE_EXTERNAL_PARAM_INFO_STRING_DEFAULT("text", "some text"),
338    EDJE_EXTERNAL_PARAM_INFO_BOOL("editable"),
339    EDJE_EXTERNAL_PARAM_INFO_BOOL("single line"),
340    EDJE_EXTERNAL_PARAM_INFO_BOOL("line wrap"),
341    EDJE_EXTERNAL_PARAM_INFO_BOOL("character line wrap"),
342    EDJE_EXTERNAL_PARAM_INFO_BOOL("password"),
343    EDJE_EXTERNAL_PARAM_INFO_BOOL("context menu disabled"),
344    EDJE_EXTERNAL_PARAM_INFO_BOOL("height bounce"),
345    EDJE_EXTERNAL_PARAM_INFO_BOOL("width bounce"),
346    EDJE_EXTERNAL_PARAM_INFO_BOOL("autocapitalization"),   
347    EDJE_EXTERNAL_PARAM_INFO_BOOL("autoperiod"),      
348    EDJE_EXTERNAL_PARAM_INFO_SENTINEL
349 };
350
351 DEFINE_EXTERNAL_ICON_ADD(scrolled_entry, "scrolled_entry")
352 DEFINE_EXTERNAL_TYPE_SIMPLE(scrolled_entry, "Entry");