2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
19 using System.Runtime.InteropServices;
24 /// Enumeration for describing InputPanel layout type.
26 public enum InputPanelLayout
29 /// InputPanel layout type default.
34 /// InputPanel layout type number.
39 /// InputPanel layout type email.
44 /// InputPanel layout type url.
49 /// InputPanel layout type phone.
54 /// InputPanel layout type ip.
59 /// InputPanel layout type month.
64 /// InputPanel layout type number.
69 /// InputPanel layout type error type. Do not use it directly!
74 /// InputPanel layout type hexadecimal.
79 /// InputPanel layout type terminal type, esc, alt, ctrl, etc.
84 /// InputPanel layout type password.
89 /// Keyboard layout type date and time.
94 /// InputPanel layout type emoticons.
100 /// Enumeration that defines the "Return" key types on the input panel (virtual keyboard).
102 public enum InputPanelReturnKeyType
135 /// Search string or magnifier icon key type
151 /// Enumeration that defines the autocapitalization types.
153 public enum AutoCapital
156 /// No autocapitalization when typing
161 /// Autocapitalize each typed word
166 /// Autocapitalize the start of each sentence
171 /// Autocapitalize all letters
177 /// Enumeration that defines the entry's copy and paste policy.
179 public enum CopyAndPasteMode
182 /// Copy and paste text with markup tag
187 /// Copy and paste text without item(image) tag
192 /// Copy and paste text without markup tag
198 /// Enumeration that defines the text format types.
200 public enum TextFormat
214 /// Enumeration that defines the types of Input Hints.
216 public enum InputHints
224 /// suggest word auto completion
229 /// typed text should not be stored.
235 /// Enumeration that defines the input panel (virtual keyboard) language modes.
237 public enum InputPanelLanguage
240 /// Automatic language mode
245 /// Alphabet language mode
251 /// The entry is a convenience widget that shows a box in which the user can enter text.
253 public class Entry : Layout
256 SmartEvent _changedByUser;
257 SmartEvent _cursorChanged;
258 SmartEvent _activated;
260 Dictionary<Func<string, EvasObject>, Interop.Elementary.Elm_Entry_Item_Provider_Cb> _itemsProvider = new Dictionary<Func<string, EvasObject>, Interop.Elementary.Elm_Entry_Item_Provider_Cb>();
261 Dictionary<Func<Entry, string, string>, Interop.Elementary.Elm_Entry_Filter_Cb> _textFilters = new Dictionary<Func<Entry, string, string>, Interop.Elementary.Elm_Entry_Filter_Cb>();
264 /// Creates and initializes a new instance of the Entry class.
266 /// <param name="parent">The EvasObject to which the new Entry will be attached as a child.</param>
267 public Entry(EvasObject parent) : base(parent)
269 _clicked = new SmartEvent(this, this.RealHandle, "clicked");
270 _clicked.On += (s, e) => Clicked?.Invoke(this, EventArgs.Empty);
272 _changedByUser = new SmartEvent(this, this.RealHandle, "changed,user");
273 _changedByUser.On += (s, e) => ChangedByUser?.Invoke(this, EventArgs.Empty);
275 _cursorChanged = new SmartEvent(this, this.RealHandle, "cursor,changed");
276 _cursorChanged.On += (s, e) => CursorChanged?.Invoke(this, EventArgs.Empty);
278 _activated = new SmartEvent(this, this.RealHandle, "activated");
279 _activated.On += (s, e) => Activated?.Invoke(this, EventArgs.Empty);
283 /// Activated will be triggered when the entry in Activated stated.
285 public event EventHandler Activated;
288 /// Clicked will be triggered when the entry is clicked.
290 public event EventHandler Clicked;
293 /// ChangedByUser will be triggered when the entry changed by user.
295 public event EventHandler ChangedByUser;
298 /// CursorChanged will be triggered when the Cursor in the entry is changed.
300 public event EventHandler CursorChanged;
303 /// Sets or gets the entry to the single line mode.
305 public bool IsSingleLine
309 return Interop.Elementary.elm_entry_single_line_get(RealHandle);
313 Interop.Elementary.elm_entry_single_line_set(RealHandle, value);
318 /// Sets or gets the entry to the password mode.
320 public bool IsPassword
324 return Interop.Elementary.elm_entry_password_get(RealHandle);
328 Interop.Elementary.elm_entry_password_set(RealHandle, value);
333 /// Sets or gets whether the entry is editable.
335 public bool IsEditable
339 return Interop.Elementary.elm_entry_editable_get(RealHandle);
343 Interop.Elementary.elm_entry_editable_set(RealHandle, value);
348 /// Sets or gets whether the entry is empty.
354 return Interop.Elementary.elm_entry_is_empty(RealHandle);
359 /// Sets or gets text currently shown in the object entry.
361 public override string Text
365 return Interop.Elementary.elm_entry_entry_get(RealHandle);
369 Interop.Elementary.elm_entry_entry_set(RealHandle, value);
374 /// Sets or gets the style on the top of the user style stack.
376 /// <remarks>If there is styles in the user style stack, the properties in the top style of user style stack will replace the properties in current theme. The input style is specified in format tag='property=value' (i.e. DEFAULT='font=Sans font_size=60'hilight=' + font_weight=Bold').</remarks>
377 public string TextStyle
381 return Interop.Elementary.elm_entry_text_style_user_peek(RealHandle);
385 Interop.Elementary.elm_entry_text_style_user_push(RealHandle, value);
390 /// Sets or gets the current position of the cursor in the entry.
392 public int CursorPosition
396 return Interop.Elementary.elm_entry_cursor_pos_get(RealHandle);
400 Interop.Elementary.elm_entry_cursor_pos_set(RealHandle, value);
405 /// Sets or gets the scrollable state of the entry.
407 public bool Scrollable
411 return Interop.Elementary.elm_entry_scrollable_get(RealHandle);
415 // HACK: Enabling the scrollable property of an entry causes its internal
416 // hierarchy to change, making the internal edje object inaccessible.
417 // Access it before the property is set, to cache the edje object's handle.
420 var dummy = EdjeObject;
422 Interop.Elementary.elm_entry_scrollable_set(RealHandle, value);
427 /// Sets or Gets the autocapitalization type on the immodule.
429 public AutoCapital AutoCapital
433 return (AutoCapital)Interop.Elementary.elm_entry_autocapital_type_get(RealHandle);
437 Interop.Elementary.elm_entry_autocapital_type_set(RealHandle, (Interop.Elementary.AutocapitalType)value);
442 /// Sets or Gets the entry object's 'autosave' status.
444 public bool IsAutoSave
448 return Interop.Elementary.elm_entry_autosave_get(RealHandle);
452 Interop.Elementary.elm_entry_autosave_set(RealHandle, value);
457 /// Sets or Gets entry text paste/drop mode.
459 public CopyAndPasteMode CopyAndPasteMode
463 return (CopyAndPasteMode)Interop.Elementary.elm_entry_cnp_mode_get(RealHandle);
467 Interop.Elementary.elm_entry_cnp_mode_set(RealHandle, (Interop.Elementary.CopyAndPasteMode)value);
472 /// Gets the geometry of the cursor.
474 public Rect CursorGeometry
479 Interop.Elementary.elm_entry_cursor_geometry_get(RealHandle, out x, out y, out w, out h);
480 return new Rect(x, y, w, h);
485 /// Gets whether a format node exists at the current cursor position.
487 public bool IsCursorFormat
491 return Interop.Elementary.elm_entry_cursor_is_format_get(RealHandle);
496 /// Gets if the current cursor position holds a visible format node.
498 public bool IsCursorVisibelFormat
502 return Interop.Elementary.elm_entry_cursor_is_visible_format_get(RealHandle);
507 /// Sets or Gets the value of input hint.
509 public InputHints InputHint
513 return (InputHints)Interop.Elementary.elm_entry_input_hint_get(RealHandle);
517 Interop.Elementary.elm_entry_input_hint_set(RealHandle, (Interop.Elementary.InputHints)value);
522 /// Sets or gets the language mode of the input panel.
524 public InputPanelLanguage InputPanelLanguage
528 return (InputPanelLanguage)Interop.Elementary.elm_entry_input_panel_language_get(RealHandle);
532 Interop.Elementary.elm_entry_input_panel_language_set(RealHandle, (Interop.Elementary.InputPanelLanguage)value);
537 /// Sets or gets the input panel layout variation of the entry.
539 public int InputPanelVariation
543 return Interop.Elementary.elm_entry_input_panel_layout_variation_get(RealHandle);
547 Interop.Elementary.elm_entry_input_panel_layout_variation_set(RealHandle, value);
552 /// Sets or gets the line wrap type to use on multi-line entries.
554 public WrapType LineWrapType
558 return (WrapType)Interop.Elementary.elm_entry_line_wrap_get(RealHandle);
562 Interop.Elementary.elm_entry_line_wrap_set(RealHandle, (Interop.Elementary.WrapType)value);
567 /// Sets or gets whether the entry should allow to use the text prediction.
569 public bool PredictionAllowed
573 return Interop.Elementary.elm_entry_prediction_allow_get(RealHandle);
577 Interop.Elementary.elm_entry_prediction_allow_set(RealHandle, value);
582 /// Sets or gets whether the return key on the input panel should be disabled or not.
584 public bool InputPanelReturnKeyDisabled
588 return Interop.Elementary.elm_entry_input_panel_return_key_disabled_get(RealHandle);
592 Interop.Elementary.elm_entry_input_panel_return_key_disabled_set(RealHandle, value);
597 /// Sets or gets the attribute to show the input panel in case of only an user's explicit Mouse Up event.
598 /// It doesn't request to show the input panel even though it has focus.
599 /// If true, the input panel will be shown in case of only Mouse up event. (Focus event will be ignored.)
601 public bool InputPanelShowByOnDemand
605 return Interop.Elementary.elm_entry_input_panel_show_on_demand_get(RealHandle);
609 Interop.Elementary.elm_entry_input_panel_show_on_demand_set(RealHandle, value);
614 /// Sets the file (and implicitly loads it) for the text to display and then edit.
616 /// <param name="file">The path to the file to load and save</param>
617 /// <param name="textFormat">The file format</param>
618 public void SetFile(string file, TextFormat textFormat)
620 Interop.Elementary.elm_entry_file_set(RealHandle, file, (Interop.Elementary.TextFormat)textFormat);
624 /// Converts a markup (HTML-like) string into UTF-8.
626 /// <param name="markup">The string (in markup) to be converted</param>
627 /// <returns>The converted string (in UTF-8) </returns>
628 public static string ConvertMarkupToUtf8(string markup)
630 return Interop.Elementary.elm_entry_markup_to_utf8(markup);
634 /// Moves the cursor by one position to the right within the entry.
636 /// <returns></returns>
637 public bool MoveCursorNext()
639 return Interop.Elementary.elm_entry_cursor_next(RealHandle);
643 /// Moves the cursor one place to the left within the entry.
645 /// <returns>TRUE on success, otherwise FALSE on failure</returns>
646 public bool MoveCursorPrev()
648 return Interop.Elementary.elm_entry_cursor_prev(RealHandle);
652 /// Moves the cursor one line up within the entry.
654 /// <returns>TRUE on success, otherwise FALSE on failure</returns>
655 public bool MoveCursorUp()
657 return Interop.Elementary.elm_entry_cursor_up(RealHandle);
661 /// Moves the cursor one line down within the entry.
663 /// <returns>TRUE on success, otherwise FALSE on failure</returns>
664 public bool MoveCursorDown()
666 return Interop.Elementary.elm_entry_cursor_down(RealHandle);
670 /// Moves the cursor to the beginning of the entry.
672 public void MoveCursorBegin()
674 Interop.Elementary.elm_entry_cursor_begin_set(RealHandle);
678 /// Moves the cursor to the end of the entry.
680 public void MoveCursorEnd()
682 Interop.Elementary.elm_entry_cursor_end_set(RealHandle);
686 /// Moves the cursor to the beginning of the current line.
688 public void MoveCursorLineBegin()
690 Interop.Elementary.elm_entry_cursor_line_begin_set(RealHandle);
694 /// Moves the cursor to the end of the current line.
696 public void MoveCursorLineEnd()
698 Interop.Elementary.elm_entry_cursor_line_end_set(RealHandle);
702 /// Sets the input panel layout of the entry.
704 /// <param name="layout">The layout type</param>
705 public void SetInputPanelLayout(InputPanelLayout layout)
707 Interop.Elementary.elm_entry_input_panel_layout_set(RealHandle, (Interop.Elementary.InputPanelLayout)layout);
711 /// Sets the attribute to show the input panel automatically.
713 /// <param name="enabled">If true the input panel appears when the entry is clicked or has focus, otherwise false</param>
714 public void SetInputPanelEnabled(bool enabled)
716 Interop.Elementary.elm_entry_input_panel_enabled_set(RealHandle, enabled);
720 /// Sets the "return" key type. This type is used to set the string or icon on the "return" key of the input panel.
722 /// <param name="keyType">The type of "return" key on the input panel</param>
723 public void SetInputPanelReturnKeyType(InputPanelReturnKeyType keyType)
725 Interop.Elementary.elm_entry_input_panel_return_key_type_set(RealHandle, (Interop.Elementary.ReturnKeyType)keyType);
729 /// Hides the input panel (virtual keyboard).
732 /// Note that the input panel is shown or hidden automatically according to the focus state of the entry widget.
733 /// This API can be used in case of manually controlling by using SetInputPanelEnabled(false).
735 public void HideInputPanel()
737 Interop.Elementary.elm_entry_input_panel_hide(RealHandle);
741 /// Selects all the text within the entry.
743 public void SelectAll()
745 Interop.Elementary.elm_entry_select_all(RealHandle);
749 /// Drops any existing text selection within the entry.
751 public void SelectNone()
753 Interop.Elementary.elm_entry_select_none(RealHandle);
757 /// Forces calculation of the entry size and text layouting.
759 public void ForceCalculation()
761 Interop.Elementary.elm_entry_calc_force(RealHandle);
765 /// Gets the string by the cursor at its current position.
767 /// <returns></returns>
768 public string GetCursorContent()
770 return Interop.Elementary.elm_entry_cursor_content_get(RealHandle);
774 /// Begins a selection within the entry as though the user were holding down the mouse button to make a selection.
776 public void BeginCursorSelection()
778 Interop.Elementary.elm_entry_cursor_selection_begin(RealHandle);
782 /// Appends the text of the entry.
784 /// <param name="text">The text to be displayed</param>
785 public void AppendText(string text)
787 Interop.Elementary.elm_entry_entry_append(RealHandle, text);
791 /// Sets or gets the value of HorizontalScrollBarVisiblePolicy
794 /// ScrollBarVisiblePolicy.Auto means the horizontal scrollbar is made visible if it is needed, and otherwise kept hidden.
795 /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
797 public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy
802 Interop.Elementary.elm_scroller_policy_get(RealHandle, out policy, IntPtr.Zero);
803 return (ScrollBarVisiblePolicy)policy;
807 ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy;
808 Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)value, (int)v);
813 /// Sets or gets the value of VerticalScrollBarVisiblePolicy
816 /// ScrollBarVisiblePolicy.Auto means the vertical scrollbar is made visible if it is needed, and otherwise kept hidden.
817 /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off.
819 public virtual ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy
824 Interop.Elementary.elm_scroller_policy_get(RealHandle, IntPtr.Zero, out policy);
825 return (ScrollBarVisiblePolicy)policy;
829 ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy;
830 Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)h, (int)value);
835 /// Sets or gets the vertical bounce behaviour.
836 /// When scrolling, the scroller may "bounce" when reaching an edge of the content object.
837 /// This is a visual way to indicate the end has been reached.
838 /// This is enabled by default for both axis.
839 /// This API will set if it is enabled for the given axis with the boolean parameters for each axis.
841 public bool VerticalBounce
846 Interop.Elementary.elm_scroller_bounce_get(RealHandle, out h, out v);
851 bool h = HorizontalBounce;
852 Interop.Elementary.elm_scroller_bounce_set(RealHandle, h, value);
857 /// Sets or gets the horizontal bounce behaviour.
858 /// When scrolling, the scroller may "bounce" when reaching an edge of the content object.
859 /// This is a visual way to indicate the end has been reached.
860 /// This is enabled by default for both axis.
861 /// This API will set if it is enabled for the given axis with the boolean parameters for each axis.
863 public bool HorizontalBounce
868 Interop.Elementary.elm_scroller_bounce_get(RealHandle, out h, out v);
873 bool v = VerticalBounce;
874 Interop.Elementary.elm_scroller_bounce_set(RealHandle, value, v);
879 /// Inserts the given text into the entry at the current cursor position.
881 /// <param name="text"></param>
882 public void InsertTextToCursor(string text)
884 Interop.Elementary.elm_entry_entry_insert(RealHandle, text);
888 /// Ends a selection within the entry as though the user had just released the mouse button while making a selection.
890 public void EndCursorSelection()
892 Interop.Elementary.elm_entry_cursor_selection_end(RealHandle);
896 /// Writes any changes made to the file that is set by File.
898 public void SaveFile()
900 Interop.Elementary.elm_entry_file_save(RealHandle);
904 /// Show the input panel (virtual keyboard) based on the input panel property of entry such as layout, autocapital types, and so on.
907 /// Note that input panel is shown or hidden automatically according to the focus state of entry widget.
908 /// This API can be used in the case of manually controlling by using SetInputPanelEnabled(false).
910 public void ShowInputPanel()
912 Interop.Elementary.elm_entry_input_panel_show(RealHandle);
916 /// This appends a custom item provider to the list for that entry.
918 /// <param name="func">This function is used to provide items.</param>
919 public void AppendItemProvider(Func<string, EvasObject> func)
923 if (!_itemsProvider.ContainsKey(func))
925 Interop.Elementary.Elm_Entry_Item_Provider_Cb itemProviderCallback;
927 itemProviderCallback = (d, o, t) =>
929 return func?.Invoke(t);
931 Interop.Elementary.elm_entry_item_provider_append(RealHandle, itemProviderCallback, IntPtr.Zero);
932 _itemsProvider.Add(func, itemProviderCallback);
938 /// This prepends a custom item provider to the list for that entry.
940 /// <param name="func">This function is used to provide items.</param>
941 public void PrependItemProvider(Func<string, EvasObject> func)
943 if (!_itemsProvider.ContainsKey(func))
945 Interop.Elementary.Elm_Entry_Item_Provider_Cb itemProviderCallback;
947 itemProviderCallback = (d, o, t) =>
949 return func?.Invoke(t);
951 Interop.Elementary.elm_entry_item_provider_prepend(RealHandle, itemProviderCallback, IntPtr.Zero);
952 _itemsProvider.Add(func, itemProviderCallback);
957 /// This removes a custom item provider to the list for that entry.
959 /// <param name="func">This function is used to provide items.</param>
960 public void RemoveItemProvider(Func<string, EvasObject> func)
962 if (_itemsProvider.ContainsKey(func))
964 Interop.Elementary.Elm_Entry_Item_Provider_Cb itemProviderCallback;
965 _itemsProvider.TryGetValue(func, out itemProviderCallback);
967 Interop.Elementary.elm_entry_item_provider_remove(RealHandle, itemProviderCallback, IntPtr.Zero);
968 _itemsProvider.Remove(func);
973 /// Append a markup filter function for text inserted in the entry.
975 /// <param name="filter">This function type is used by entry filters to modify text.</param>
976 public void AppendMarkUpFilter(Func<Entry, string, string> filter)
978 if (!_textFilters.ContainsKey(filter))
980 Interop.Elementary.Elm_Entry_Filter_Cb textFilterCallback = (IntPtr d, IntPtr e, ref IntPtr t) =>
982 var text = Marshal.PtrToStringAnsi(t);
984 var updateText = filter(this, text);
986 if (updateText != text)
988 Interop.Libc.Free(t);
989 t = Marshal.StringToHGlobalAnsi(updateText);
992 Interop.Elementary.elm_entry_markup_filter_append(RealHandle, textFilterCallback, IntPtr.Zero);
993 _textFilters.Add(filter, textFilterCallback);
998 /// Prepend a markup filter function for text inserted in the entry.
1000 /// <param name="filter">This function type is used by entry filters to modify text.</param>
1001 public void PrependMarkUpFilter(Func<Entry, string, string> filter)
1003 if (!_textFilters.ContainsKey(filter))
1005 Interop.Elementary.Elm_Entry_Filter_Cb textFilterCallback = (IntPtr d, IntPtr e, ref IntPtr t) =>
1007 var text = Marshal.PtrToStringAnsi(t);
1009 var updateText = filter(this, text);
1011 if (updateText != text)
1013 Interop.Libc.Free(t);
1014 t = Marshal.StringToHGlobalAnsi(updateText);
1017 Interop.Elementary.elm_entry_markup_filter_prepend(RealHandle, textFilterCallback, IntPtr.Zero);
1018 _textFilters.Add(filter, textFilterCallback);
1023 /// Remove a markup filter
1025 /// <param name="filter">This function type is used by entry filters to modify text.</param>
1026 public void RemoveMarkUpFilter(Func<Entry, string, string> filter)
1028 if (_textFilters.ContainsKey(filter))
1030 Interop.Elementary.Elm_Entry_Filter_Cb textFilterCallback;
1031 _textFilters.TryGetValue(filter, out textFilterCallback);
1033 Interop.Elementary.elm_entry_markup_filter_remove(RealHandle, textFilterCallback, IntPtr.Zero);
1034 _textFilters.Remove(filter);
1039 /// This executes a "copy" action on the selected text in the entry.
1041 public void CopySelection()
1043 Interop.Elementary.elm_entry_selection_copy(RealHandle);
1047 /// This executes a "cut" action on the selected text in the entry.
1049 public void CutSelection()
1051 Interop.Elementary.elm_entry_selection_cut(RealHandle);
1055 /// This executes a "paste" action in the entry.
1057 public void PasteSelection()
1059 Interop.Elementary.elm_entry_selection_paste(RealHandle);
1063 /// This disabled the entry's selection.
1065 /// <param name="disable">If true, the selection are disabled.</param>
1066 public void DisableSelection(bool disable)
1068 Interop.Elementary.elm_entry_selection_handler_disabled_set(RealHandle, disable);
1072 /// Get any selected text within the entry.
1074 /// <returns>Selection's value</returns>
1075 public string GetSelection()
1077 return Interop.Elementary.elm_entry_selection_get(RealHandle);
1081 /// This selects a region of text within the entry.
1083 /// <param name="start">The starting position.</param>
1084 /// <param name="end">The end position.</param>
1085 public void SetSelectionRegion(int start, int end)
1087 Interop.Elementary.elm_entry_select_region_set(RealHandle, start, end);
1091 /// Sets the visibility of the left-side widget of the entry
1093 /// <param name="isDisplay">true if the object should be displayed, false if not.</param>
1094 public void SetIconVisible(bool isDisplay)
1096 Interop.Elementary.elm_entry_icon_visible_set(RealHandle, isDisplay);
1100 /// Set whether the return key on the input panel is disabled automatically when entry has no text.
1102 /// <param name="enable">If enabled is true, the return key is automatically disabled when the entry has no text.</param>
1103 public void SetInputPanelReturnKeyAutoEnable(bool enable)
1105 Interop.Elementary.elm_entry_input_panel_return_key_autoenabled_set(RealHandle, enable);
1109 /// Creates a widget handle.
1111 /// <param name="parent">Parent EvasObject</param>
1112 /// <returns>Handle IntPtr</returns>
1113 protected override IntPtr CreateHandle(EvasObject parent)
1115 return Interop.Elementary.elm_entry_add(parent.Handle);