/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Collections.Generic; using System.Runtime.InteropServices; namespace ElmSharp { /// /// Enumeration for describing the InputPanel layout types. /// /// preview public enum InputPanelLayout { /// /// The InputPanel layout type default. /// Normal, /// /// The InputPanel layout type number. /// Number, /// /// The InputPanel layout type email. /// Email, /// /// The InputPanel layout type URL. /// Url, /// /// The InputPanel layout type phone. /// PhoneNumber, /// /// The InputPanel layout type IP. /// Ip, /// /// The InputPanel layout type month. /// Month, /// /// The InputPanel layout type number. /// NumberOnly, /// /// The InputPanel layout type error type. Do not use it directly! /// Invalid, /// /// The InputPanel layout type hexadecimal. /// Hex, /// /// The InputPanel layout type terminal type: Esc, Alt, Ctrl, etc. /// Terminal, /// /// The InputPanel layout type password. /// Password, /// /// The keyboard layout type date and time. /// DateTime, /// /// The InputPanel layout type emoticons. /// Emoticon } /// /// Enumeration for defining the "Return" key types on the input panel (virtual keyboard). /// /// preview public enum InputPanelReturnKeyType { /// /// The Default key type. /// Default, /// /// The Done key type. /// Done, /// /// The Go key type. /// Go, /// /// The Join key type. /// Join, /// /// The Login key type. /// Login, /// /// The Next key type. /// Next, /// /// The Search string or magnifier icon key type. /// Search, /// /// The Send key type. /// Send, /// /// The Sign-in key type. /// Signin } /// /// Enumeration for defining the autocapitalization types. /// /// preview public enum AutoCapital { /// /// No autocapitalization when typing. /// None, /// /// Autocapitalize each of the typed word. /// Word, /// /// Autocapitalize the start of each sentence. /// Sentence, /// /// Autocapitalize all the letters. /// All } /// /// Enumeration for defining the entry's copy and paste policy. /// /// preview public enum CopyAndPasteMode { /// /// Copy and paste text with a markup tag. /// Markup, /// /// Copy and paste text without an item (image) tag. /// NoImage, /// /// Copy and paste text without a markup tag. /// PlainText } /// /// Enumeration for the text format types. /// /// preview public enum TextFormat { /// /// Plain type. /// Plain, /// /// Markup type. /// Markup } /// /// Enumeration that defines the types of Input Hints. /// /// preview public enum InputHints { /// /// No active hints. /// None, /// /// Suggest word auto-completion. /// AutoComplete, /// /// The typed text should not be stored. /// SensitiveData, } /// /// Enumeration for defining the input panel (virtual keyboard) language modes. /// /// preview public enum InputPanelLanguage { /// /// Automatic language mode. /// Automatic, /// /// Alphabet language mode. /// Alphabet, } /// /// The Entry is a convenience widget that shows a box in which the user can enter text. /// /// preview public class Entry : Layout { SmartEvent _clicked; SmartEvent _changedByUser; SmartEvent _cursorChanged; SmartEvent _activated; Dictionary, Interop.Elementary.Elm_Entry_Item_Provider_Cb> _itemsProvider = new Dictionary, Interop.Elementary.Elm_Entry_Item_Provider_Cb>(); Dictionary, Interop.Elementary.Elm_Entry_Filter_Cb> _textFilters = new Dictionary, Interop.Elementary.Elm_Entry_Filter_Cb>(); /// /// Creates and initializes a new instance of the Entry class. /// /// The EvasObject to which the new Entry will be attached as a child. /// preview public Entry(EvasObject parent) : base(parent) { _clicked = new SmartEvent(this, this.RealHandle, "clicked"); _clicked.On += (s, e) => Clicked?.Invoke(this, EventArgs.Empty); _changedByUser = new SmartEvent(this, this.RealHandle, "changed,user"); _changedByUser.On += (s, e) => ChangedByUser?.Invoke(this, EventArgs.Empty); _cursorChanged = new SmartEvent(this, this.RealHandle, "cursor,changed"); _cursorChanged.On += (s, e) => CursorChanged?.Invoke(this, EventArgs.Empty); _activated = new SmartEvent(this, this.RealHandle, "activated"); _activated.On += (s, e) => Activated?.Invoke(this, EventArgs.Empty); } /// /// Activated will be triggered when the entry is activated. /// /// preview public event EventHandler Activated; /// /// Clicked will be triggered when the entry is clicked. /// /// preview public event EventHandler Clicked; /// /// ChangedByUser will be triggered when the entry is changed by user. /// /// preview public event EventHandler ChangedByUser; /// /// CursorChanged will be triggered when the cursor in the entry is changed. /// /// preview public event EventHandler CursorChanged; /// /// Sets or gets the entry to the single line mode. /// /// preview public bool IsSingleLine { get { return Interop.Elementary.elm_entry_single_line_get(RealHandle); } set { Interop.Elementary.elm_entry_single_line_set(RealHandle, value); } } /// /// Sets or gets the entry to the password mode. /// /// preview public bool IsPassword { get { return Interop.Elementary.elm_entry_password_get(RealHandle); } set { Interop.Elementary.elm_entry_password_set(RealHandle, value); } } /// /// Sets or gets whether the entry is editable. /// /// preview public bool IsEditable { get { return Interop.Elementary.elm_entry_editable_get(RealHandle); } set { Interop.Elementary.elm_entry_editable_set(RealHandle, value); } } /// /// Sets or gets whether the entry is empty. /// /// preview public bool IsEmpty { get { return Interop.Elementary.elm_entry_is_empty(RealHandle); } } /// /// Sets or gets the text currently shown in the object entry. /// /// preview public override string Text { get { return Interop.Elementary.elm_entry_entry_get(RealHandle); } set { Interop.Elementary.elm_entry_entry_set(RealHandle, value); } } /// /// Sets or gets the style on top of the user style stack. /// /// If there are styles in the user style stack, the properties in the top style of the user style stack will replace the properties in current theme. The input style is specified in the format, tag='property=value' (i.e., DEFAULT='font=Sans font_size=60'hilight=' + font_weight=Bold'). /// preview public string TextStyle { get { return Interop.Elementary.elm_entry_text_style_user_peek(RealHandle); } set { Interop.Elementary.elm_entry_text_style_user_push(RealHandle, value); } } /// /// Sets or gets the current position of the cursor in the entry. /// /// preview public int CursorPosition { get { return Interop.Elementary.elm_entry_cursor_pos_get(RealHandle); } set { Interop.Elementary.elm_entry_cursor_pos_set(RealHandle, value); } } /// /// Sets or gets the scrollable state of the entry. /// /// preview public bool Scrollable { get { return Interop.Elementary.elm_entry_scrollable_get(RealHandle); } set { // HACK: Enabling the scrollable property of an entry causes its internal // hierarchy to change, making the internal edje object inaccessible. // Access it before the property is set, to cache the edje object's handle. if (value) { var dummy = EdjeObject; } Interop.Elementary.elm_entry_scrollable_set(RealHandle, value); } } /// /// Sets or gets the autocapitalization type on the immodule. /// /// preview public AutoCapital AutoCapital { get { return (AutoCapital)Interop.Elementary.elm_entry_autocapital_type_get(RealHandle); } set { Interop.Elementary.elm_entry_autocapital_type_set(RealHandle, (Interop.Elementary.AutocapitalType)value); } } /// /// Sets or gets the entry object's 'autosave' status. /// /// preview public bool IsAutoSave { get { return Interop.Elementary.elm_entry_autosave_get(RealHandle); } set { Interop.Elementary.elm_entry_autosave_set(RealHandle, value); } } /// /// Sets or gets the entry text paste/drop mode. /// /// preview public CopyAndPasteMode CopyAndPasteMode { get { return (CopyAndPasteMode)Interop.Elementary.elm_entry_cnp_mode_get(RealHandle); } set { Interop.Elementary.elm_entry_cnp_mode_set(RealHandle, (Interop.Elementary.CopyAndPasteMode)value); } } /// /// Gets the geometry of the cursor. /// /// preview public Rect CursorGeometry { get { int x, y, w, h; Interop.Elementary.elm_entry_cursor_geometry_get(RealHandle, out x, out y, out w, out h); return new Rect(x, y, w, h); } } /// /// Gets whether a format node exists at the current cursor position. /// /// preview public bool IsCursorFormat { get { return Interop.Elementary.elm_entry_cursor_is_format_get(RealHandle); } } /// /// Gets if the current cursor position holds a visible format node. /// /// preview public bool IsCursorVisibelFormat { get { return Interop.Elementary.elm_entry_cursor_is_visible_format_get(RealHandle); } } /// /// Sets or gets the value of the input hint. /// /// preview public InputHints InputHint { get { return (InputHints)Interop.Elementary.elm_entry_input_hint_get(RealHandle); } set { Interop.Elementary.elm_entry_input_hint_set(RealHandle, (Interop.Elementary.InputHints)value); } } /// /// Sets or gets the language mode of the input panel. /// /// preview public InputPanelLanguage InputPanelLanguage { get { return (InputPanelLanguage)Interop.Elementary.elm_entry_input_panel_language_get(RealHandle); } set { Interop.Elementary.elm_entry_input_panel_language_set(RealHandle, (Interop.Elementary.InputPanelLanguage)value); } } /// /// Sets or gets the input panel layout variation of the entry. /// /// preview public int InputPanelVariation { get { return Interop.Elementary.elm_entry_input_panel_layout_variation_get(RealHandle); } set { Interop.Elementary.elm_entry_input_panel_layout_variation_set(RealHandle, value); } } /// /// Sets or gets the line wrap type to use on multiline entries. /// /// preview public WrapType LineWrapType { get { return (WrapType)Interop.Elementary.elm_entry_line_wrap_get(RealHandle); } set { Interop.Elementary.elm_entry_line_wrap_set(RealHandle, (Interop.Elementary.WrapType)value); } } /// /// Sets or gets whether the entry should allow to use the text prediction. /// /// preview public bool PredictionAllowed { get { return Interop.Elementary.elm_entry_prediction_allow_get(RealHandle); } set { Interop.Elementary.elm_entry_prediction_allow_set(RealHandle, value); } } /// /// Sets or gets whether the return key on the input panel should be disabled or not. /// /// preview public bool InputPanelReturnKeyDisabled { get { return Interop.Elementary.elm_entry_input_panel_return_key_disabled_get(RealHandle); } set { Interop.Elementary.elm_entry_input_panel_return_key_disabled_set(RealHandle, value); } } /// /// Sets or gets the attribute to show the input panel, in case of only an user's explicit Mouse Up event. /// It doesn't request to show the input panel even though it has focus. /// If true, the input panel will be shown only in case of the Mouse up event (Focus event will be ignored). /// /// preview public bool InputPanelShowByOnDemand { get { return Interop.Elementary.elm_entry_input_panel_show_on_demand_get(RealHandle); } set { Interop.Elementary.elm_entry_input_panel_show_on_demand_set(RealHandle, value); } } /// /// Sets the file (and implicitly loads it) for the text to display and then edit. /// /// The path to the file to load and save. /// The file format. /// preview public void SetFile(string file, TextFormat textFormat) { Interop.Elementary.elm_entry_file_set(RealHandle, file, (Interop.Elementary.TextFormat)textFormat); } /// /// Converts a markup (HTML-like) string into UTF-8. /// /// The string (in markup) to be converted. /// The converted string (in UTF-8). /// preview public static string ConvertMarkupToUtf8(string markup) { return Interop.Elementary.elm_entry_markup_to_utf8(markup); } /// /// Moves the cursor by one position to the right within the entry. /// /// /// preview public bool MoveCursorNext() { return Interop.Elementary.elm_entry_cursor_next(RealHandle); } /// /// Moves the cursor one place to the left within the entry. /// /// TRUE on success, otherwise FALSE on failure. /// preview public bool MoveCursorPrev() { return Interop.Elementary.elm_entry_cursor_prev(RealHandle); } /// /// Moves the cursor one line up within the entry. /// /// TRUE on success, otherwise FALSE on failure. /// preview public bool MoveCursorUp() { return Interop.Elementary.elm_entry_cursor_up(RealHandle); } /// /// Moves the cursor one line down within the entry. /// /// TRUE on success, otherwise FALSE on failure. /// preview public bool MoveCursorDown() { return Interop.Elementary.elm_entry_cursor_down(RealHandle); } /// /// Moves the cursor to the beginning of the entry. /// /// preview public void MoveCursorBegin() { Interop.Elementary.elm_entry_cursor_begin_set(RealHandle); } /// /// Moves the cursor to the end of the entry. /// /// preview public void MoveCursorEnd() { Interop.Elementary.elm_entry_cursor_end_set(RealHandle); } /// /// Moves the cursor to the beginning of the current line. /// /// preview public void MoveCursorLineBegin() { Interop.Elementary.elm_entry_cursor_line_begin_set(RealHandle); } /// /// Moves the cursor to the end of the current line. /// /// preview public void MoveCursorLineEnd() { Interop.Elementary.elm_entry_cursor_line_end_set(RealHandle); } /// /// Sets the input panel layout of the entry. /// /// The layout type. /// preview public void SetInputPanelLayout(InputPanelLayout layout) { Interop.Elementary.elm_entry_input_panel_layout_set(RealHandle, (Interop.Elementary.InputPanelLayout)layout); } /// /// Sets the attribute to show the input panel automatically. /// /// If true, the input panel appears when the entry is clicked or has focus, otherwise false. /// preview public void SetInputPanelEnabled(bool enabled) { Interop.Elementary.elm_entry_input_panel_enabled_set(RealHandle, enabled); } /// /// Sets the "return" key type. This type is used to set the string or icon on the "return" key of the input panel. /// /// The type of "return" key on the input panel. /// preview public void SetInputPanelReturnKeyType(InputPanelReturnKeyType keyType) { Interop.Elementary.elm_entry_input_panel_return_key_type_set(RealHandle, (Interop.Elementary.ReturnKeyType)keyType); } /// /// Hides the input panel (virtual keyboard). /// /// /// Note that the input panel is shown or hidden automatically according to the focus state of the entry widget. /// This API can be used in case of manually controlling by using SetInputPanelEnabled(false). /// /// preview public void HideInputPanel() { Interop.Elementary.elm_entry_input_panel_hide(RealHandle); } /// /// Selects all the text within the entry. /// /// preview public void SelectAll() { Interop.Elementary.elm_entry_select_all(RealHandle); } /// /// Drops any existing text selection within the entry. /// /// preview public void SelectNone() { Interop.Elementary.elm_entry_select_none(RealHandle); } /// /// Forces calculation of the entry size and text layout. /// /// preview public void ForceCalculation() { Interop.Elementary.elm_entry_calc_force(RealHandle); } /// /// Gets the string by the cursor at its current position. /// /// /// preview public string GetCursorContent() { return Interop.Elementary.elm_entry_cursor_content_get(RealHandle); } /// /// Begins a selection within the entry, as though the user was holding down the mouse button to make a selection. /// /// preview public void BeginCursorSelection() { Interop.Elementary.elm_entry_cursor_selection_begin(RealHandle); } /// /// Appends the text of the entry. /// /// The text to be displayed. /// preview public void AppendText(string text) { Interop.Elementary.elm_entry_entry_append(RealHandle, text); } /// /// Sets or gets the value of the HorizontalScrollBarVisiblePolicy. /// /// /// ScrollBarVisiblePolicy.Auto means that the horizontal scrollbar is made visible if it is needed, or otherwise kept hidden. /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. /// /// preview public virtual ScrollBarVisiblePolicy HorizontalScrollBarVisiblePolicy { get { int policy; Interop.Elementary.elm_scroller_policy_get(RealHandle, out policy, IntPtr.Zero); return (ScrollBarVisiblePolicy)policy; } set { ScrollBarVisiblePolicy v = VerticalScrollBarVisiblePolicy; Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)value, (int)v); } } /// /// Sets or gets the value of VerticalScrollBarVisiblePolicy. /// /// /// ScrollBarVisiblePolicy.Auto means that the vertical scrollbar is made visible if it is needed, or otherwise kept hidden. /// ScrollBarVisiblePolicy.Visible turns it on all the time, and ScrollBarVisiblePolicy.Invisible always keeps it off. /// /// preview public virtual ScrollBarVisiblePolicy VerticalScrollBarVisiblePolicy { get { int policy; Interop.Elementary.elm_scroller_policy_get(RealHandle, IntPtr.Zero, out policy); return (ScrollBarVisiblePolicy)policy; } set { ScrollBarVisiblePolicy h = HorizontalScrollBarVisiblePolicy; Interop.Elementary.elm_scroller_policy_set(RealHandle, (int)h, (int)value); } } /// /// Sets or gets the vertical bounce behavior. /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. /// This is a visual way to indicate that the end has reached. /// This is enabled by default for both the axis. /// This API will be set if it is enabled for the given axis with boolean parameters for each axis. /// /// preview public bool VerticalBounce { get { bool v, h; Interop.Elementary.elm_scroller_bounce_get(RealHandle, out h, out v); return v; } set { bool h = HorizontalBounce; Interop.Elementary.elm_scroller_bounce_set(RealHandle, h, value); } } /// /// Sets or gets the horizontal bounce behavior. /// When scrolling, the scroller may "bounce" when reaching an edge of the content object. /// This is a visual way to indicate that the end has reached. /// This is enabled by default for both the axis. /// This API will be set if it is enabled for the given axis with boolean parameters for each axis. /// /// preview public bool HorizontalBounce { get { bool v, h; Interop.Elementary.elm_scroller_bounce_get(RealHandle, out h, out v); return h; } set { bool v = VerticalBounce; Interop.Elementary.elm_scroller_bounce_set(RealHandle, value, v); } } /// /// Inserts the given text into the entry at the current cursor position. /// /// The text to be inserted. /// preview public void InsertTextToCursor(string text) { Interop.Elementary.elm_entry_entry_insert(RealHandle, text); } /// /// Ends a selection within the entry as though the user had just released the mouse button while making a selection. /// /// preview public void EndCursorSelection() { Interop.Elementary.elm_entry_cursor_selection_end(RealHandle); } /// /// Writes any changes made to the file that is set by a file. /// /// preview public void SaveFile() { Interop.Elementary.elm_entry_file_save(RealHandle); } /// /// Show the input panel (virtual keyboard) based on the input panel property of the entry such as layout, autocapital types, and so on. /// /// /// Note that the input panel is shown or hidden automatically according to the focus state of the entry widget. /// This API can be used in the case of manual control by using the SetInputPanelEnabled(false). /// /// preview public void ShowInputPanel() { Interop.Elementary.elm_entry_input_panel_show(RealHandle); } /// /// This appends a custom item provider to the list for that entry. /// /// This function is used to provide items. /// preview public void AppendItemProvider(Func func) { if (func != null) { if (!_itemsProvider.ContainsKey(func)) { Interop.Elementary.Elm_Entry_Item_Provider_Cb itemProviderCallback; itemProviderCallback = (d, o, t) => { return func?.Invoke(t); }; Interop.Elementary.elm_entry_item_provider_append(RealHandle, itemProviderCallback, IntPtr.Zero); _itemsProvider.Add(func, itemProviderCallback); } } } /// /// This prepends a custom item provider to the list for that entry. /// /// This function is used to provide items. /// preview public void PrependItemProvider(Func func) { if (!_itemsProvider.ContainsKey(func)) { Interop.Elementary.Elm_Entry_Item_Provider_Cb itemProviderCallback; itemProviderCallback = (d, o, t) => { return func?.Invoke(t); }; Interop.Elementary.elm_entry_item_provider_prepend(RealHandle, itemProviderCallback, IntPtr.Zero); _itemsProvider.Add(func, itemProviderCallback); } } /// /// This removes a custom item provider to the list for that entry. /// /// This function is used to provide items. /// preview public void RemoveItemProvider(Func func) { if (_itemsProvider.ContainsKey(func)) { Interop.Elementary.Elm_Entry_Item_Provider_Cb itemProviderCallback; _itemsProvider.TryGetValue(func, out itemProviderCallback); Interop.Elementary.elm_entry_item_provider_remove(RealHandle, itemProviderCallback, IntPtr.Zero); _itemsProvider.Remove(func); } } /// /// Appends a markup filter function for text inserted in the entry. /// /// This function type is used by entry filters to modify text. /// preview public void AppendMarkUpFilter(Func filter) { if (!_textFilters.ContainsKey(filter)) { Interop.Elementary.Elm_Entry_Filter_Cb textFilterCallback = (IntPtr d, IntPtr e, ref IntPtr t) => { var text = Marshal.PtrToStringAnsi(t); var updateText = filter(this, text); if (updateText != text) { Interop.Libc.Free(t); t = Marshal.StringToHGlobalAnsi(updateText); } }; Interop.Elementary.elm_entry_markup_filter_append(RealHandle, textFilterCallback, IntPtr.Zero); _textFilters.Add(filter, textFilterCallback); } } /// /// Prepends a markup filter function for text inserted in the entry. /// /// This function type is used by entry filters to modify text. /// preview public void PrependMarkUpFilter(Func filter) { if (!_textFilters.ContainsKey(filter)) { Interop.Elementary.Elm_Entry_Filter_Cb textFilterCallback = (IntPtr d, IntPtr e, ref IntPtr t) => { var text = Marshal.PtrToStringAnsi(t); var updateText = filter(this, text); if (updateText != text) { Interop.Libc.Free(t); t = Marshal.StringToHGlobalAnsi(updateText); } }; Interop.Elementary.elm_entry_markup_filter_prepend(RealHandle, textFilterCallback, IntPtr.Zero); _textFilters.Add(filter, textFilterCallback); } } /// /// Removes a markup filter. /// /// This function type is used by entry filters to modify text. /// preview public void RemoveMarkUpFilter(Func filter) { if (_textFilters.ContainsKey(filter)) { Interop.Elementary.Elm_Entry_Filter_Cb textFilterCallback; _textFilters.TryGetValue(filter, out textFilterCallback); Interop.Elementary.elm_entry_markup_filter_remove(RealHandle, textFilterCallback, IntPtr.Zero); _textFilters.Remove(filter); } } /// /// This executes a "copy" action on the selected text in the entry. /// /// preview public void CopySelection() { Interop.Elementary.elm_entry_selection_copy(RealHandle); } /// /// This executes a "cut" action on the selected text in the entry. /// /// preview public void CutSelection() { Interop.Elementary.elm_entry_selection_cut(RealHandle); } /// /// This executes a "paste" action in the entry. /// /// preview public void PasteSelection() { Interop.Elementary.elm_entry_selection_paste(RealHandle); } /// /// This disables the entry's selection handlers. /// This works properly on the profile that provides selection handlers. /// /// If true, the selection handlers are disabled. /// preview public void DisableSelection(bool disable) { Interop.Elementary.elm_entry_selection_handler_disabled_set(RealHandle, disable); } /// /// Gets any selected text within the entry. /// /// Selection's value. /// preview public string GetSelection() { return Interop.Elementary.elm_entry_selection_get(RealHandle); } /// /// This selects a region of text within the entry. /// /// The start position. /// The end position. /// preview public void SetSelectionRegion(int start, int end) { Interop.Elementary.elm_entry_select_region_set(RealHandle, start, end); } /// /// Sets the visibility of the left-side widget of the entry. /// /// true if the object should be displayed, otherwise false. /// preview public void SetIconVisible(bool isDisplay) { Interop.Elementary.elm_entry_icon_visible_set(RealHandle, isDisplay); } /// /// Sets whether the return key on the input panel is disabled automatically, when the entry has no text. /// /// If enabled is true, the return key is automatically disabled when the entry has no text. /// preview public void SetInputPanelReturnKeyAutoEnable(bool enable) { Interop.Elementary.elm_entry_input_panel_return_key_autoenabled_set(RealHandle, enable); } /// /// Creates a widget handle. /// /// Parent EvasObject. /// Handle IntPtr. /// preview protected override IntPtr CreateHandle(EvasObject parent) { return Interop.Elementary.elm_entry_add(parent.Handle); } } }