[entry] add autoperiod API
[framework/uifw/elementary.git] / src / lib / elc_scrolled_entry.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4 #include <Elementary.h>
5 #include "elm_priv.h"
6
7 /**
8  * @defgroup Scrolled_Entry Scrolled_Entry
9  * @ingroup Elementary
10  *
11  * A scrolled entry is a convenience widget which shows
12  * a box that the user can enter text into.  Unlike an
13  * @ref Entry widget, scrolled entries scroll with user
14  * input so that the window will not expand if the length
15  * of text inside the entry exceeds the initial size of the
16  * widget.
17  *
18  * Signals that you can add callbacks for are:
19  * - "changed" - The text within the entry was changed
20  * - "activated" - The entry has received focus and the cursor
21  * - "press" - The entry has been clicked
22  * - "longpressed" - The entry has been clicked for a couple seconds
23  * - "clicked" - The entry has been clicked
24  * - "clicked,double" - The entry has been double clicked
25  * - "focused" - The entry has received focus
26  * - "unfocused" - The entry has lost focus
27  * - "selection,paste" - A paste action has occurred
28  * - "selection,copy" - A copy action has occurred
29  * - "selection,cut" - A cut action has occurred
30  * - "selection,start" - A selection has begun
31  * - "selection,changed" - The selection has changed
32  * - "selection,cleared" - The selection has been cleared
33  * - "cursor,changed" - The cursor has changed
34  * - "anchor,clicked" - The anchor has been clicked
35  */
36
37 typedef struct _Widget_Data Widget_Data;
38
39 struct _Widget_Data
40 {
41    Evas_Object *scroller;
42    Evas_Object *entry;
43    Elm_Scroller_Policy policy_h, policy_v;
44    Eina_Bool single_line : 1;
45 };
46
47 static const char *widtype = NULL;
48
49 static const char SIG_CHANGED[] = "changed";
50 static const char SIG_ACTIVATED[] = "activated";
51 static const char SIG_PRESS[] = "press";
52 static const char SIG_LONGPRESSED[] = "longpressed";
53 static const char SIG_CLICKED[] = "clicked";
54 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
55 static const char SIG_FOCUSED[] = "focused";
56 static const char SIG_UNFOCUSED[] = "unfocused";
57 static const char SIG_SELECTION_PASTE[] = "selection,paste";
58 static const char SIG_SELECTION_COPY[] = "selection,copy";
59 static const char SIG_SELECTION_CUT[] = "selection,cut";
60 static const char SIG_SELECTION_START[] = "selection,start";
61 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
62 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
63 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
64 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
65 static const Evas_Smart_Cb_Description _signals[] = {
66   {SIG_CHANGED, ""},
67   {SIG_ACTIVATED, ""},
68   {SIG_PRESS, ""},
69   {SIG_LONGPRESSED, ""},
70   {SIG_CLICKED, ""},
71   {SIG_CLICKED_DOUBLE, ""},
72   {SIG_FOCUSED, ""},
73   {SIG_UNFOCUSED, ""},
74   {SIG_SELECTION_PASTE, ""},
75   {SIG_SELECTION_COPY, ""},
76   {SIG_SELECTION_CUT, ""},
77   {SIG_SELECTION_START, ""},
78   {SIG_SELECTION_CHANGED, ""},
79   {SIG_SELECTION_CLEARED, ""},
80   {SIG_CURSOR_CHANGED, ""},
81   {SIG_ANCHOR_CLICKED, ""},
82   {NULL, NULL}
83 };
84
85 static void
86 _del_hook(Evas_Object *obj)
87 {
88    Widget_Data *wd = elm_widget_data_get(obj);
89    if (!wd) return;
90    free(wd);
91 }
92
93 static void
94 _theme_hook(Evas_Object *obj)
95 {
96    Widget_Data *wd = elm_widget_data_get(obj);
97    if (!wd) return;
98    elm_object_style_set(wd->entry, elm_widget_style_get(obj));
99    elm_object_style_set(wd->scroller, elm_widget_style_get(obj));
100 }
101
102 static void
103 _sizing_eval(Evas_Object *obj)
104 {
105    Widget_Data *wd = elm_widget_data_get(obj);
106    Evas_Coord minw, minh, minw_scr, minh_scr;
107    if (!wd) return;
108    
109    evas_object_size_hint_min_get(obj, &minw, &minh);
110    evas_object_size_hint_min_get(wd->scroller, &minw_scr, &minh_scr);
111    if (minw < minw_scr) minw = minw_scr;
112    if (minh < minh_scr) minh = minh_scr;
113
114    evas_object_size_hint_min_set(obj, minw, minh);
115
116    if (wd->single_line)
117      evas_object_size_hint_max_set(obj, -1, minh);
118    else
119      evas_object_size_hint_max_set(obj, -1, -1);
120 }
121
122 static void
123 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
124 {
125    Widget_Data *wd = elm_widget_data_get(obj);
126    if (!wd) return;
127    if (elm_widget_focus_get(obj))
128      elm_widget_focus_steal(wd->entry);
129 }
130
131 static void
132 _disable_hook(Evas_Object *obj)
133 {
134    Widget_Data *wd = elm_widget_data_get(obj);
135    if (!wd) return;
136    elm_object_disabled_set(wd->entry, elm_widget_disabled_get(obj));
137 }
138
139 static void
140 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
141 {
142    Widget_Data *wd = elm_widget_data_get(obj);
143    if (!wd) return;
144    elm_object_signal_emit(wd->entry, emission, source);
145    elm_object_signal_emit(wd->scroller, emission, source);
146 }
147
148
149 static void
150 _entry_changed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
151 {
152    _sizing_eval(data);
153    evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
154 }
155
156 static void
157 _entry_activated(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
158 {
159    evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
160 }
161
162 static void
163 _entry_press(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
164 {
165    evas_object_smart_callback_call(data, SIG_PRESS, NULL);
166 }
167
168 static void
169 _entry_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
170 {
171    evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
172 }
173
174 static void
175 _entry_clicked_double(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
176 {
177    evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
178 }
179
180 static void
181 _entry_cursor_changed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
182 {
183    evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
184 }
185
186 static void
187 _entry_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
188 {
189    evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, NULL);
190 }
191
192 static void
193 _entry_selection_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
194 {
195    evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
196 }
197
198 static void
199 _entry_selection_changed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
200 {
201    evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
202 }
203
204 static void
205 _entry_selection_cleared(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
206 {
207    evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
208 }
209
210 static void
211 _entry_selection_paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
212 {
213    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
214 }
215
216 static void
217 _entry_selection_copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
218 {
219    evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
220 }
221
222 static void
223 _entry_selection_cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
224 {
225    evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
226 }
227
228 static void
229 _entry_longpressed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
230 {
231    evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
232 }
233
234 static void
235 _entry_focused(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
236 {
237    evas_object_smart_callback_call(data, SIG_FOCUSED, NULL);
238 }
239
240 static void
241 _entry_unfocused(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
242 {
243    evas_object_smart_callback_call(data, SIG_UNFOCUSED, NULL);
244 }
245
246 static void
247 _entry_maxlength_reached(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
248 {
249    evas_object_smart_callback_call(data, "maxlength,reached", NULL);
250 }
251
252
253 /**
254  * This adds a scrolled entry to @p parent object.
255  *
256  * @param parent The parent object
257  * @return The new object or NULL if it cannot be created
258  *
259  * @ingroup Scrolled_Entry
260  */
261 EAPI Evas_Object *
262 elm_scrolled_entry_add(Evas_Object *parent)
263 {
264    Evas_Object *obj;
265    Evas *e;
266    Widget_Data *wd;
267
268    wd = ELM_NEW(Widget_Data);
269    e = evas_object_evas_get(parent);
270    obj = elm_widget_add(e);
271    ELM_SET_WIDTYPE(widtype, "scrolled_entry");
272    elm_widget_type_set(obj, "scrolled_entry");
273    elm_widget_sub_object_add(parent, obj);
274    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
275    elm_widget_data_set(obj, wd);
276    elm_widget_del_hook_set(obj, _del_hook);
277    elm_widget_disable_hook_set(obj, _disable_hook);
278    elm_widget_can_focus_set(obj, 1);
279    elm_widget_theme_hook_set(obj, _theme_hook);
280    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
281
282    wd->scroller = elm_scroller_add(parent);
283    elm_widget_resize_object_set(obj, wd->scroller);
284    elm_scroller_bounce_set(wd->scroller, 0, 0);
285    elm_scroller_propagate_events_set(wd->scroller, 1);
286    
287    wd->entry = elm_entry_add(parent);
288    evas_object_size_hint_weight_set(wd->entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
289    evas_object_size_hint_align_set(wd->entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
290    elm_scroller_content_set(wd->scroller, wd->entry);
291    evas_object_show(wd->entry);
292
293    evas_object_smart_callback_add(wd->entry, "changed", _entry_changed, obj);
294    evas_object_smart_callback_add(wd->entry, "activated", _entry_activated, obj);
295    evas_object_smart_callback_add(wd->entry, "press", _entry_press, obj);
296    evas_object_smart_callback_add(wd->entry, "clicked", _entry_clicked, obj);
297    evas_object_smart_callback_add(wd->entry, "clicked,double", _entry_clicked_double, obj);
298    evas_object_smart_callback_add(wd->entry, "cursor,changed", _entry_cursor_changed, obj);
299    evas_object_smart_callback_add(wd->entry, "anchor,clicked", _entry_anchor_clicked, obj);
300    evas_object_smart_callback_add(wd->entry, "selection,start", _entry_selection_start, obj);
301    evas_object_smart_callback_add(wd->entry, "selection,changed", _entry_selection_changed, obj);
302    evas_object_smart_callback_add(wd->entry, "selection,cleared", _entry_selection_cleared, obj);
303    evas_object_smart_callback_add(wd->entry, "selection,paste", _entry_selection_paste, obj);
304    evas_object_smart_callback_add(wd->entry, "selection,copy", _entry_selection_copy, obj);
305    evas_object_smart_callback_add(wd->entry, "selection,cut", _entry_selection_cut, obj);
306    evas_object_smart_callback_add(wd->entry, "longpressed", _entry_longpressed, obj);
307    evas_object_smart_callback_add(wd->entry, "focused", _entry_focused, obj);
308    evas_object_smart_callback_add(wd->entry, "unfocused", _entry_unfocused, obj);
309    evas_object_smart_callback_add(wd->entry, "maxlength,reached", _entry_maxlength_reached, obj);
310
311    _sizing_eval(obj);
312
313    // TODO: convert Elementary to subclassing of Evas_Smart_Class
314    // TODO: and save some bytes, making descriptions per-class and not instance!
315    evas_object_smart_callbacks_descriptions_set(obj, _signals);
316    return obj;
317 }
318
319 /**
320  * This sets the scrolled entry object not to line wrap.  All input will
321  * be on a single line, and the entry box will scroll with user input.
322  *
323  * @param obj The scrolled entry object
324  * @param single_line If true, the text in the scrolled entry
325  * will be on a single line.
326  *
327  * @ingroup Scrolled_Entry
328  */
329 EAPI void
330 elm_scrolled_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
331 {
332    ELM_CHECK_WIDTYPE(obj, widtype);
333    Widget_Data *wd = elm_widget_data_get(obj);
334    if (!wd) return;
335    if (wd->single_line == single_line) return;
336    elm_entry_single_line_set(wd->entry, single_line);
337    wd->single_line = single_line;
338    if (single_line)
339      {
340         elm_scroller_policy_set(wd->scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
341         elm_scroller_content_min_limit(wd->scroller, 0, 1);
342      }
343    else
344      {
345         elm_scroller_policy_set(wd->scroller, wd->policy_h, wd->policy_v);
346         elm_scroller_content_min_limit(wd->scroller, 0, 0);
347      }
348    _sizing_eval(obj);
349 }
350
351 /**
352  * This returns true if the scrolled entry has been set to single line mode.
353  * See also elm_scrolled_entry_single_line_set().
354  *
355  * @param obj The scrolled entry object
356  * @return single_line If true, the text in the scrolled entry is set to display
357  * on a single line.
358  *
359  * @ingroup Scrolled_Entry
360  */
361 EAPI Eina_Bool
362 elm_scrolled_entry_single_line_get(const Evas_Object *obj)
363 {
364    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
365    Widget_Data *wd = elm_widget_data_get(obj);
366    if (!wd) return EINA_FALSE;
367    return elm_entry_single_line_get(wd->entry);
368 }
369
370
371 /**
372  * This sets the scrolled entry object to password mode.  All text entered
373  * and/or displayed within the widget will be replaced with asterisks (*).
374  *
375  * @param obj The scrolled entry object
376  * @param password If true, password mode is enabled.
377  *
378  * @ingroup Scrolled_Entry
379  */
380 EAPI void
381 elm_scrolled_entry_password_set(Evas_Object *obj, Eina_Bool password)
382 {
383    ELM_CHECK_WIDTYPE(obj, widtype);
384    Widget_Data *wd = elm_widget_data_get(obj);
385    if (!wd) return;
386    elm_entry_password_set(wd->entry, password);
387 }
388
389 /**
390  * This returns whether password mode is enabled.
391  * See also elm_scrolled_entry_password_set().
392  *
393  * @param obj The scrolled entry object
394  * @return If true, the scrolled entry is set to display all characters
395  * as asterisks (*).
396  *
397  * @ingroup Scrolled_Entry
398  */
399 EAPI Eina_Bool
400 elm_scrolled_entry_password_get(const Evas_Object *obj)
401 {
402    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
403    Widget_Data *wd = elm_widget_data_get(obj);
404    if (!wd) return EINA_FALSE;
405    return elm_entry_password_get(wd->entry);
406 }
407
408
409 /**
410  * This sets the text displayed within the scrolled entry to @p entry.
411  *
412  * @param obj The scrolled entry object
413  * @param entry The text to be displayed
414  *
415  * @ingroup Scrolled_Entry
416  */
417 EAPI void
418 elm_scrolled_entry_entry_set(Evas_Object *obj, const char *entry)
419 {
420    ELM_CHECK_WIDTYPE(obj, widtype);
421    Widget_Data *wd = elm_widget_data_get(obj);
422    if (!wd) return;
423    elm_entry_entry_set(wd->entry, entry);
424 }
425
426 /**
427  * This returns the text currently shown in object @p entry.
428  * See also elm_scrolled_entry_entry_set().
429  *
430  * @param obj The scrolled entry object
431  * @return The currently displayed text or NULL on failure
432  *
433  * @ingroup Scrolled_Entry
434  */
435 EAPI const char *
436 elm_scrolled_entry_entry_get(const Evas_Object *obj)
437 {
438    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
439    Widget_Data *wd = elm_widget_data_get(obj);
440    if (!wd) return NULL;
441    return elm_entry_entry_get(wd->entry);
442 }
443
444 /**
445  * This returns all selected text within the scrolled entry.
446  *
447  * @param obj The scrolled entry object
448  * @return The selected text within the scrolled entry or NULL on failure
449  *
450  * @ingroup Scrolled_Entry
451  */
452 EAPI const char *
453 elm_scrolled_entry_selection_get(const Evas_Object *obj)
454 {
455    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
456    Widget_Data *wd = elm_widget_data_get(obj);
457    if (!wd) return NULL;
458    return elm_entry_selection_get(wd->entry);
459 }
460
461 /**
462  * This inserts text in @p entry at the beginning of the scrolled entry
463  * object.
464  *
465  * @param obj The scrolled entry object
466  * @param entry The text to insert
467  *
468  * @ingroup Scrolled_Entry
469  */
470 EAPI void
471 elm_scrolled_entry_entry_insert(Evas_Object *obj, const char *entry)
472 {
473    ELM_CHECK_WIDTYPE(obj, widtype);
474    Widget_Data *wd = elm_widget_data_get(obj);
475    if (!wd) return;
476    elm_entry_entry_insert(wd->entry, entry);
477 }
478
479 /**
480  * This enables word line wrapping in the scrolled entry object.  It is the opposite
481  * of elm_scrolled_entry_single_line_set().  Additionally, setting this disables
482  * character line wrapping.
483  * See also elm_scrolled_entry_line_char_wrap_set().
484  *
485  * @param obj The scrolled entry object
486  * @param wrap If true, the scrolled entry will be wrapped once it reaches the end
487  * of the object. Wrapping will occur at the end of the word before the end of the
488  * object.
489  *
490  * @ingroup Scrolled_Entry
491  */
492 EAPI void
493 elm_scrolled_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
494 {
495    ELM_CHECK_WIDTYPE(obj, widtype);
496    Widget_Data *wd = elm_widget_data_get(obj);
497    if (!wd) return;
498    elm_entry_line_wrap_set(wd->entry, wrap);
499 }
500
501 /**
502  * This enables character line wrapping in the scrolled entry object.  It is the opposite
503  * of elm_scrolled_entry_single_line_set().  Additionally, setting this disables
504  * word line wrapping.
505  * See also elm_scrolled_entry_line_wrap_set().
506  *
507  * @param obj The scrolled entry object
508  * @param wrap If true, the scrolled entry will be wrapped once it reaches the end
509  * of the object. Wrapping will occur immediately upon reaching the end of the object.
510  *
511  * @ingroup Scrolled_Entry
512  */
513 EAPI void
514 elm_scrolled_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
515 {
516    ELM_CHECK_WIDTYPE(obj, widtype);
517    Widget_Data *wd = elm_widget_data_get(obj);
518    if (!wd) return;
519    elm_entry_line_char_wrap_set(wd->entry, wrap);
520 }
521
522 /**
523  * This sets the editable attribute of the scrolled entry.
524  *
525  * @param obj The scrolled entry object
526  * @param editable If true, the scrolled entry will be editable by the user.
527  * If false, it will be set to the disabled state.
528  *
529  * @ingroup Scrolled_Entry
530  */
531 EAPI void
532 elm_scrolled_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
533 {
534    ELM_CHECK_WIDTYPE(obj, widtype);
535    Widget_Data *wd = elm_widget_data_get(obj);
536    if (!wd) return;
537    elm_entry_editable_set(wd->entry, editable);
538 }
539
540 /**
541  * This gets the editable attribute of the scrolled entry.
542  * See also elm_scrolled_entry_editable_set().
543  *
544  * @param obj The scrolled entry object
545  * @return If true, the scrolled entry is editable by the user.
546  * If false, it is not editable by the user
547  *
548  * @ingroup Scrolled_Entry
549  */
550 EAPI Eina_Bool
551 elm_scrolled_entry_editable_get(const Evas_Object *obj)
552 {
553    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
554    Widget_Data *wd = elm_widget_data_get(obj);
555    if (!wd) return EINA_FALSE;
556    return elm_entry_editable_get(wd->entry);
557 }
558
559
560 /**
561  * This drops any existing text selection within the scrolled entry.
562  *
563  * @param obj The scrolled entry object
564  *
565  * @ingroup Scrolled_Entry
566  */
567 EAPI void
568 elm_scrolled_entry_select_none(Evas_Object *obj)
569 {
570    ELM_CHECK_WIDTYPE(obj, widtype);
571    Widget_Data *wd = elm_widget_data_get(obj);
572    if (!wd) return;
573    elm_entry_select_none(wd->entry);
574 }
575
576 /**
577  * This selects all text within the scrolled entry.
578  *
579  * @param obj The scrolled entry object
580  *
581  * @ingroup Scrolled_Entry
582  */
583 EAPI void
584 elm_scrolled_entry_select_all(Evas_Object *obj)
585 {
586    ELM_CHECK_WIDTYPE(obj, widtype);
587    Widget_Data *wd = elm_widget_data_get(obj);
588    if (!wd) return;
589    elm_entry_select_all(wd->entry);
590 }
591
592 /**
593  * This moves the cursor one place to the right within the entry.
594  *
595  * @param obj The scrolled entry object
596  * @return EINA_TRUE upon success, EINA_FALSE upon failure
597  *
598  * @ingroup Scrolled_Entry
599  */
600 EAPI Eina_Bool
601 elm_scrolled_entry_cursor_next(Evas_Object *obj)
602 {
603    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
604    Widget_Data *wd = elm_widget_data_get(obj);
605    if (!wd) return EINA_FALSE;
606    return elm_entry_cursor_next(wd->entry);
607 }
608
609 /**
610  * This moves the cursor one place to the left within the entry.
611  *
612  * @param obj The scrolled entry object
613  * @return EINA_TRUE upon success, EINA_FALSE upon failure
614  *
615  * @ingroup Scrolled_Entry
616  */
617 EAPI Eina_Bool
618 elm_scrolled_entry_cursor_prev(Evas_Object *obj)
619 {
620    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
621    Widget_Data *wd = elm_widget_data_get(obj);
622    if (!wd) return EINA_FALSE;
623    return elm_entry_cursor_prev(wd->entry);
624 }
625
626 /**
627  * This moves the cursor one line up within the entry.
628  *
629  * @param obj The scrolled entry object
630  * @return EINA_TRUE upon success, EINA_FALSE upon failure
631  *
632  * @ingroup Scrolled_Entry
633  */
634 EAPI Eina_Bool
635 elm_scrolled_entry_cursor_up(Evas_Object *obj)
636 {
637    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
638    Widget_Data *wd = elm_widget_data_get(obj);
639    if (!wd) return EINA_FALSE;
640    return elm_entry_cursor_up(wd->entry);
641 }
642
643 /**
644  * This moves the cursor one line down within the entry.
645  *
646  * @param obj The scrolled entry object
647  * @return EINA_TRUE upon success, EINA_FALSE upon failure
648  *
649  * @ingroup Scrolled_Entry
650  */
651 EAPI Eina_Bool
652 elm_scrolled_entry_cursor_down(Evas_Object *obj)
653 {
654    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
655    Widget_Data *wd = elm_widget_data_get(obj);
656    if (!wd) return EINA_FALSE;
657    return elm_entry_cursor_down(wd->entry);
658 }
659
660 /**
661  * This moves the cursor to the beginning of the entry.
662  *
663  * @param obj The scrolled entry object
664  *
665  * @ingroup Scrolled_Entry
666  */
667 EAPI void
668 elm_scrolled_entry_cursor_begin_set(Evas_Object *obj)
669 {
670    ELM_CHECK_WIDTYPE(obj, widtype);
671    Widget_Data *wd = elm_widget_data_get(obj);
672    if (!wd) return;
673    elm_entry_cursor_begin_set(wd->entry);
674 }
675
676 /**
677  * This moves the cursor to the end of the entry.
678  *
679  * @param obj The scrolled entry object
680  *
681  * @ingroup Scrolled_Entry
682  */
683 EAPI void
684 elm_scrolled_entry_cursor_end_set(Evas_Object *obj)
685 {
686    ELM_CHECK_WIDTYPE(obj, widtype);
687    Widget_Data *wd = elm_widget_data_get(obj);
688    if (!wd) return;
689    int x, y, w, h;
690    elm_scroller_region_get(wd->scroller, &x, &y, &w, &h);
691    elm_entry_cursor_end_set(wd->entry);
692    elm_scroller_region_show(wd->scroller, x, y, w, h);
693 }
694
695 /**
696  * This moves the cursor to the beginning of the current line.
697  *
698  * @param obj The scrolled entry object
699  *
700  * @ingroup Scrolled_Entry
701  */
702 EAPI void
703 elm_scrolled_entry_cursor_line_begin_set(Evas_Object *obj)
704 {
705    ELM_CHECK_WIDTYPE(obj, widtype);
706    Widget_Data *wd = elm_widget_data_get(obj);
707    if (!wd) return;
708    elm_entry_cursor_line_begin_set(wd->entry);
709 }
710
711 /**
712  * This moves the cursor to the end of the current line.
713  *
714  * @param obj The scrolled entry object
715  *
716  * @ingroup Scrolled_Entry
717  */
718 EAPI void
719 elm_scrolled_entry_cursor_line_end_set(Evas_Object *obj)
720 {
721    ELM_CHECK_WIDTYPE(obj, widtype);
722    Widget_Data *wd = elm_widget_data_get(obj);
723    if (!wd) return;
724    elm_entry_cursor_line_end_set(wd->entry);
725 }
726
727 /**
728  * This begins a selection within the scrolled entry as though
729  * the user were holding down the mouse button to make a selection.
730  *
731  * @param obj The scrolled entry object
732  *
733  * @ingroup Scrolled_Entry
734  */
735 EAPI void
736 elm_scrolled_entry_cursor_selection_begin(Evas_Object *obj)
737 {
738    ELM_CHECK_WIDTYPE(obj, widtype);
739    Widget_Data *wd = elm_widget_data_get(obj);
740    if (!wd) return;
741    elm_entry_cursor_selection_begin(wd->entry);
742 }
743
744 /**
745  * This ends a selection within the scrolled entry as though
746  * the user had just released the mouse button while making a selection.
747  *
748  * @param obj The scrolled entry object
749  *
750  * @ingroup Scrolled_Entry
751  */
752 EAPI void
753 elm_scrolled_entry_cursor_selection_end(Evas_Object *obj)
754 {
755    ELM_CHECK_WIDTYPE(obj, widtype);
756    Widget_Data *wd = elm_widget_data_get(obj);
757    if (!wd) return;
758    elm_entry_cursor_selection_end(wd->entry);
759 }
760
761 /**
762  * TODO: fill this in
763  *
764  * @param obj The scrolled entry object
765  * @return TODO: fill this in
766  *
767  * @ingroup Scrolled_Entry
768  */
769 EAPI Eina_Bool
770 elm_scrolled_entry_cursor_is_format_get(const Evas_Object *obj)
771 {
772    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
773    Widget_Data *wd = elm_widget_data_get(obj);
774    if (!wd) return EINA_FALSE;
775    return elm_entry_cursor_is_format_get(wd->entry);
776 }
777
778 /**
779  * This returns whether the cursor is visible.
780  *
781  * @param obj The scrolled entry object
782  * @return If true, the cursor is visible.
783  *
784  * @ingroup Scrolled_Entry
785  */
786 EAPI Eina_Bool
787 elm_scrolled_entry_cursor_is_visible_format_get(const Evas_Object *obj)
788 {
789    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
790    Widget_Data *wd = elm_widget_data_get(obj);
791    if (!wd) return EINA_FALSE;
792    return elm_entry_cursor_is_visible_format_get(wd->entry);
793 }
794
795 /**
796  * TODO: fill this in
797  *
798  * @param obj The scrolled entry object
799  * @return TODO: fill this in
800  *
801  * @ingroup Scrolled_Entry
802  */
803 EAPI const char *
804 elm_scrolled_entry_cursor_content_get(const Evas_Object *obj)
805 {
806    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
807    Widget_Data *wd = elm_widget_data_get(obj);
808    if (!wd) return NULL;
809    return elm_entry_cursor_content_get(wd->entry);
810 }
811
812 /**
813  * This executes a "cut" action on the selected text in the scrolled entry.
814  *
815  * @param obj The scrolled entry object
816  *
817  * @ingroup Scrolled_Entry
818  */
819 EAPI void
820 elm_scrolled_entry_selection_cut(Evas_Object *obj)
821 {
822    ELM_CHECK_WIDTYPE(obj, widtype);
823    Widget_Data *wd = elm_widget_data_get(obj);
824    if (!wd) return;
825    elm_entry_selection_cut(wd->entry);
826 }
827
828 /**
829  * This executes a "copy" action on the selected text in the scrolled entry.
830  *
831  * @param obj The scrolled entry object
832  *
833  * @ingroup Scrolled_Entry
834  */
835 EAPI void
836 elm_scrolled_entry_selection_copy(Evas_Object *obj)
837 {
838    ELM_CHECK_WIDTYPE(obj, widtype);
839    Widget_Data *wd = elm_widget_data_get(obj);
840    if (!wd) return;
841    elm_entry_selection_copy(wd->entry);
842 }
843
844 /**
845  * This executes a "paste" action in the scrolled entry.
846  *
847  * @param obj The scrolled entry object
848  *
849  * @ingroup Scrolled_Entry
850  */
851 EAPI void
852 elm_scrolled_entry_selection_paste(Evas_Object *obj)
853 {
854    ELM_CHECK_WIDTYPE(obj, widtype);
855    Widget_Data *wd = elm_widget_data_get(obj);
856    if (!wd) return;
857    elm_entry_selection_paste(wd->entry);
858 }
859
860 /**
861  * This clears and frees the items in a scrolled entry's contextual (right click) menu.
862  *
863  * @param obj The scrolled entry object
864  *
865  * @ingroup Scrolled_Entry
866  */
867 EAPI void
868 elm_scrolled_entry_context_menu_clear(Evas_Object *obj)
869 {
870    ELM_CHECK_WIDTYPE(obj, widtype);
871    Widget_Data *wd = elm_widget_data_get(obj);
872    if (!wd) return;
873    elm_entry_context_menu_clear(wd->entry);
874 }
875
876 /**
877  * This adds an item to the scrolled entry's contextual menu.
878  *
879  * @param obj The scrolled entry object
880  * @param label The item's text label
881  * @param icon_file The item's icon file
882  * @param icon_type The item's icon type
883  * @param func The callback to execute when the item is clicked
884  * @param data The data to associate with the item for related functions
885  *
886  * @ingroup Scrolled_Entry
887  */
888 EAPI void
889 elm_scrolled_entry_context_menu_item_add(Evas_Object *obj, const char *label, const char *icon_file, Elm_Icon_Type icon_type, Evas_Smart_Cb func, const void *data)
890 {
891    ELM_CHECK_WIDTYPE(obj, widtype);
892    Widget_Data *wd = elm_widget_data_get(obj);
893    if (!wd) return;
894    elm_entry_context_menu_item_add(wd->entry, label, icon_file, icon_type, func, data);
895 }
896
897 /**
898  * This disables the scrolled entry's contextual (right click) menu.
899  *
900  * @param obj The scrolled entry object
901  * @param disabled If true, the menu is disabled
902  *
903  * @ingroup Scrolled_Entry
904  */
905 EAPI void
906 elm_scrolled_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
907 {
908    ELM_CHECK_WIDTYPE(obj, widtype);
909    Widget_Data *wd = elm_widget_data_get(obj);
910    if (!wd) return;
911    elm_entry_context_menu_disabled_set(wd->entry, disabled);
912 }
913
914 /**
915  * This returns whether the scrolled entry's contextual (right click) menu is disabled.
916  *
917  * @param obj The scrolled entry object
918  * @return If true, the menu is disabled
919  *
920  * @ingroup Scrolled_Entry
921  */
922 EAPI Eina_Bool
923 elm_scrolled_entry_context_menu_disabled_get(const Evas_Object *obj)
924 {
925    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
926    Widget_Data *wd = elm_widget_data_get(obj);
927    if (!wd) return EINA_FALSE;
928    return elm_entry_context_menu_disabled_get(wd->entry);
929 }
930
931 /**
932  * This sets the scrolled entry's scrollbar policy (ie. enabling/disabling them).
933  *
934  * @param obj The scrolled entry object
935  * @param h The horizontal scrollbar policy to apply
936  * @param v The vertical scrollbar policy to apply
937  *
938  * @ingroup Scrolled_Entry
939  */
940 EAPI void
941 elm_scrolled_entry_scrollbar_policy_set(Evas_Object *obj, Elm_Scroller_Policy h, Elm_Scroller_Policy v)
942 {
943    ELM_CHECK_WIDTYPE(obj, widtype);
944    Widget_Data *wd = elm_widget_data_get(obj);
945    if (!wd) return;
946    wd->policy_h = h;
947    wd->policy_v = v;
948    elm_scroller_policy_set(wd->scroller, h, v);
949 }
950
951 /**
952  * This enables/disables bouncing within the entry.
953  *
954  * @param obj The scrolled entry object
955  * @param h The horizontal bounce state
956  * @param v The vertical bounce state
957  *
958  * @ingroup Scrolled_Entry
959  */
960 EAPI void
961 elm_scrolled_entry_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
962 {
963    ELM_CHECK_WIDTYPE(obj, widtype);
964    Widget_Data *wd = elm_widget_data_get(obj);
965    if (!wd) return;
966    elm_scroller_bounce_set(wd->scroller, h_bounce, v_bounce);
967 }
968 /**
969  * This set's the maximum bytes that can be added in to scrolled entry.
970  *
971  * @param obj The  scrolled entry object
972  * @param max_no_of_bytes Maximum number of bytes scrolled entry can have.
973  * 
974  * @ingroup Scrolled_Entry
975  */
976 EAPI void
977 elm_scrolled_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
978 {
979    ELM_CHECK_WIDTYPE(obj, widtype);
980    Widget_Data *wd = elm_widget_data_get(obj);
981    if (!wd) return;
982    elm_entry_maximum_bytes_set(wd->entry,max_no_of_bytes);
983 }
984
985 /**
986  * This set's the scrolled entry in password mode with out masking the last character entered by user,
987  * and later masking the character after 2 seconds.
988  *
989  * @param obj The scrolled entry object
990  * @param show_last_character The show_last_character flag (1 for "password mode along with showing last character" 
991  * 0 for default)
992  *
993  * @ingroup Scrolled_Entry
994  */
995 EAPI void
996 elm_scrolled_entry_password_show_last_character_set(Evas_Object *obj, Eina_Bool show_last_character)
997 {
998    ELM_CHECK_WIDTYPE(obj, widtype);
999    Widget_Data *wd = elm_widget_data_get(obj);
1000    if (!wd) return;
1001    elm_entry_password_show_last_character_set(wd->entry, show_last_character);
1002 }
1003
1004 /**
1005  * Get the input method context in the scrolled entry widget
1006  *
1007  * @param obj The scrolled entry object
1008  * @return The input method context
1009  *
1010  * @ingroup Scrolled_Entry
1011  */
1012 EAPI Ecore_IMF_Context *elm_scrolled_entry_imf_context_get(Evas_Object *obj)
1013 {
1014    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1015    Widget_Data *wd = elm_widget_data_get(obj);
1016    if (!wd || !wd->entry) return NULL;
1017   
1018    return elm_entry_imf_context_get(wd->entry);
1019 }
1020
1021 /**
1022  * This sets the attribute to show the input panel automatically.
1023  *
1024  * @param obj The scrolled entry object
1025  * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
1026  *
1027  * @ingroup Scrolled_Entry
1028  */
1029 EAPI void
1030 elm_scrolled_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
1031 {
1032    ELM_CHECK_WIDTYPE(obj, widtype);
1033    Widget_Data *wd = elm_widget_data_get(obj);
1034    if (!wd || !wd->entry) return;
1035
1036    elm_entry_input_panel_enabled_set(wd->entry, enabled);
1037 }
1038
1039 /**
1040  * Set the input panel layout of the scrolled entry
1041  *
1042  * @param obj The scrolled entry object
1043  * @param layout the layout to set
1044  *
1045  * @ingroup Scrolled_Entry
1046  */
1047 EAPI void
1048 elm_scrolled_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
1049 {
1050    ELM_CHECK_WIDTYPE(obj, widtype);
1051    Widget_Data *wd = elm_widget_data_get(obj);
1052    if (!wd || !wd->entry) return;
1053
1054    elm_entry_input_panel_layout_set(wd->entry, layout);
1055 }
1056
1057 /**
1058  * Set whether scrolled entry should support auto capitalization
1059  *
1060  * @param obj The entry object
1061  * @param on If true, scrolled entry suports auto capitalization.
1062  *
1063  * @ingroup Scrolled_Entry
1064  */
1065 EAPI void 
1066 elm_scrolled_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
1067 {
1068    ELM_CHECK_WIDTYPE(obj, widtype);
1069    Widget_Data *wd = elm_widget_data_get(obj);
1070    if (!wd || !wd->entry) return;
1071
1072    elm_entry_autocapitalization_set(wd->entry, autocap);
1073 }
1074
1075 /**
1076  * Set whether scrolled entry should support auto period
1077  *
1078  * @param obj The entry object
1079  * @param on If true, scrolled entry suports auto period.
1080  *
1081  * @ingroup Scrolled_Entry
1082  */
1083 EAPI void 
1084 elm_scrolled_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
1085 {
1086    ELM_CHECK_WIDTYPE(obj, widtype);
1087    Widget_Data *wd = elm_widget_data_get(obj);
1088    if (!wd || !wd->entry) return;
1089
1090    elm_entry_autoperiod_set(wd->entry, autoperiod);
1091 }
1092