Beispiel #1
0
        /// <summary>
        /// Set the spinner input / display mode.
        /// </summary>
        /// <param name="mode">
        /// One of the TextInputMode enumerated values indicating the text
        /// input / display mode to be used by the spinner.
        /// </param>
        public void SetTextInputMode(TextInputMode mode)
        {
            if (mode != _inputMode)
            {
                switch (mode)
                {
                case TextInputMode.FloatingPoint:
                    GetEditbox().SetValidationString(FloatValidator);
                    break;

                case TextInputMode.Integer:
                    GetEditbox().SetValidationString(IntegerValidator);
                    break;

                case TextInputMode.Hexadecimal:
                    GetEditbox().SetValidationString(HexValidator);
                    break;

                case TextInputMode.Octal:
                    GetEditbox().SetValidationString(OctalValidator);
                    break;

                default:
                    throw new InvalidRequestException("An unknown TextInputMode was specified.");
                }

                _inputMode = mode;

                OnTextInputModeChanged(new WindowEventArgs(this));
            }
        }
Beispiel #2
0
        public static string ToTextInputMode(this TextInputMode textInputMode)
        {
            switch (textInputMode)
            {
            case TextInputMode.Text:
                return("text");

            case TextInputMode.Tel:
                return("tel");

            case TextInputMode.Url:
                return("url");

            case TextInputMode.Email:
                return("email");

            case TextInputMode.Numeric:
                return("numeric");

            case TextInputMode.Decimal:
                return("decimal");

            case TextInputMode.Search:
                return("search");

            default:
                return(null);
            }
        }
Beispiel #3
0
 public EditableText()
 {
     this.backgroundSprt = new UISprite(9);
     base.RootUIElement.AddChildLast(this.backgroundSprt);
     this.backgroundSprt.ShaderType = ShaderType.Texture;
     this.backgroundSprt.Image      = new ImageAsset(SystemImageAsset.EditableTextBackgroundNormal);
     this.backgroundNinePatchMargin = AssetManager.GetNinePatchMargin(SystemImageAsset.EditableTextBackgroundNormal);
     this.textSprt = new UISprite(1);
     base.RootUIElement.AddChildLast(this.textSprt);
     this.textSprt.ShaderType = ShaderType.TextTexture;
     this.DefaultText         = "Please input the text.";
     this.DefaultFont         = UISystem.DefaultFont;
     this.DefaultTextColor    = new UIColor(0.75f, 0.75f, 0.75f, 0.75f);
     this.Text                = "";
     this.Font                = this.DefaultFont;
     this.TextColor           = TextRenderHelper.DefaultTextColor;
     this.TextShadow          = null;
     this.HorizontalAlignment = HorizontalAlignment.Left;
     this.VerticalAlignment   = VerticalAlignment.Middle;
     this.LineBreak           = LineBreak.Character;
     this.TextTrimming        = TextTrimming.EllipsisCharacter;
     this.LineGap             = 0f;
     this.Width               = 360f;
     this.Height              = 56f;
     this.PriorityHit         = true;
     this.TextInputMode       = (TextInputMode)0;
     this.updateFlags         = (EditableText.UpdateFlags.Background | EditableText.UpdateFlags.Text);
 }
Beispiel #4
0
        /// <summary>
        /// 检查输入
        /// </summary>
        /// <param name="mode">输入模式</param>
        /// <param name="keyChar">正在输入的字符</param>
        /// <param name="funcGetText">获取已输入内容的回调</param>
        /// <param name="isCasual">GridView请传入True,其他请传入False</param>
        /// <returns>成功或失败</returns>
        public static bool CheckInput(TextInputMode mode, char keyChar, Func <string> funcGetText, bool isCasual = false)
        {
            //控制字符总是允许输入
            if (IsControlChar(keyChar))
            {
                return(true);
            }

            switch (mode)
            {
            case TextInputMode.Characters:
                return(AllowInputCharacters(keyChar));

            case TextInputMode.Digitals:
                return(AllowInputDigitals(keyChar));

            case TextInputMode.UnsignedInt:
                return(AllowInputNumbers(keyChar, false, false, funcGetText, isCasual));

            case TextInputMode.SignedInt:
                return(AllowInputNumbers(keyChar, true, false, funcGetText, isCasual));

            case TextInputMode.UnsignedFloat:
                return(AllowInputNumbers(keyChar, false, true, funcGetText, isCasual));

            case TextInputMode.SignedFloat:
                return(AllowInputNumbers(keyChar, true, true, funcGetText, isCasual));

            case TextInputMode.All:
            default:
                return(true);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 验证输入
        /// </summary>
        /// <param name="mode">输入模式</param>
        /// <param name="inputText">输入的内容</param>
        /// <param name="allowZero">是否允许零值</param>
        /// <param name="format">格式化实例</param>
        /// <param name="extValidate">额外的验证方法</param>
        /// <returns>错误信息</returns>
        public static string ValidateInput(TextInputMode mode, string inputText, bool allowZero,
                                           CustomFormat format = null, Func <string, string> extValidate = null)
        {
            if (!inputText.IsValid() /* || !InputRegexes.ContainsKey(mode)*/)
            {
                return(string.Empty);
            }

            //自定义格式校验
            if (!format?.Validating(inputText) ?? false)
            {
                return(format.ErrorInfos.FirstOrDefault()?.GetValue(InvalidFormat));
            }

            if (!allowZero)
            {
                var value = inputText.TryDouble();
                if (value.HasValue && value == 0.0D)
                {
                    return("不允许输入零值");
                }
            }

            //预定义格式校验
            var rgx = GetValidatingRegex(mode, true);

            if (rgx != null && !rgx.IsMatch(inputText))
            {
                return(mode.GetDesc());
            }

            return(extValidate != null?extValidate(inputText) : string.Empty);
        }
        /// <summary>
        /// 限制输入
        /// </summary>
        /// <param name="ctrl">控件实例</param>
        /// <param name="mode">输入模式</param>
        public static void LimitInput(this TextBox ctrl, TextInputMode mode)
        {
            if (null == ctrl || TextInputMode.All == mode)
            {
                return;
            }

            ctrl.KeyPress += (sender, e) =>
            {
                //控制字符总是允许输入
                if (InputHelper.IsControlChar(e.KeyChar))
                {
                    return;
                }

                var success = InputHelper.CheckInput(mode, e.KeyChar, () => ctrl.Text, false);
                if (!success)
                {
                    e.Handled = true;
                    return;
                }
            };
        }
Beispiel #7
0
 void IRenderWebBrowser.OnVirtualKeyboardRequested(IBrowser browser, TextInputMode inputMode)
 {
     RenderHandler?.OnVirtualKeyboardRequested(browser, inputMode);
 }
Beispiel #8
0
 /// <summary>
 /// Called when an on-screen keyboard should be shown or hidden for the specified browser.
 /// </summary>
 /// <param name="browser">the browser</param>
 /// <param name="inputMode">specifies what kind of keyboard should be opened. If <see cref="TextInputMode.None"/>, any existing keyboard for this browser should be hidden.</param>
 public virtual void OnVirtualKeyboardRequested(IBrowser browser, TextInputMode inputMode)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="VirtualKeyboardRequestedEventArgs"/> class.
 /// </summary>
 /// <param name="browser">browser</param>
 /// <param name="inputMode">input mode</param>
 public VirtualKeyboardRequestedEventArgs(IBrowser browser, TextInputMode inputMode)
 {
     Browser       = browser;
     TextInputMode = inputMode;
 }
Beispiel #10
0
 void IRenderWebBrowser.OnVirtualKeyboardRequested(IBrowser browser, TextInputMode inputMode)
 {
 }
        internal bool ShowFloatingGamepadTextInput(TextInputMode eKeyboardMode, int nTextFieldXPosition, int nTextFieldYPosition, int nTextFieldWidth, int nTextFieldHeight)
        {
            var returnValue = _ShowFloatingGamepadTextInput(Self, eKeyboardMode, nTextFieldXPosition, nTextFieldYPosition, nTextFieldWidth, nTextFieldHeight);

            return(returnValue);
        }
 private static extern bool _ShowFloatingGamepadTextInput(IntPtr self, TextInputMode eKeyboardMode, int nTextFieldXPosition, int nTextFieldYPosition, int nTextFieldWidth, int nTextFieldHeight);
Beispiel #13
0
        public void SetText(string value, TextInputMode mode)
        {
            var pattern = (TextPattern)this.element.GetCurrentPattern(TextPattern.Pattern);

            this.element.SetFocus();
            pattern.DocumentRange.Select();
            System.Windows.Forms.SendKeys.SendWait("{BS}");
            switch (mode)
            {
            case TextInputMode.Paste:
                Thread thread = new Thread(() => { Clipboard.SetText(value); })
                {
                    ApartmentState = ApartmentState.STA
                };
                thread.Start();
                while (thread.ThreadState == ThreadState.Running)
                {
                    Thread.Sleep(100);
                }
                SendKeys.SendWait("^v");
                break;

            case TextInputMode.SendKey:
                string text = "";
                for (int i = 0; i < value.Length; i++)
                {
                    var item = value[i];
                    if (item == '{')
                    {
                        text += "{{}"; continue;
                    }
                    if (item == '}')
                    {
                        text += "{}}"; continue;
                    }
                    if (item == '~')
                    {
                        text += "{~}"; continue;
                    }
                    if (item == '+')
                    {
                        text += "{+}"; continue;
                    }
                    if (item == '^')
                    {
                        text += "{^}"; continue;
                    }
                    if (item == '%')
                    {
                        text += "{%}"; continue;
                    }
                    if (item == '\r' && value[i + 1] == '\n')
                    {
                        text += "\n"; i++; continue;
                    }
                    text += item;
                }
                SendKeys.SendWait(text);
                break;

            default:
                break;
            }
        }
Beispiel #14
0
        /// <summary>
        /// 获取验证的正则表达式实例
        /// </summary>
        /// <param name="mode"></param>
        /// <param name="finalCheck">是否为最终数据验证(输入过程中的验证请传入False)</param>
        /// <returns></returns>
        public static Regex GetValidatingRegex(TextInputMode mode, bool finalCheck)
        {
            var rgxes = finalCheck ? FinalCheckRegexes : InputCheckRegexes;

            return(rgxes.ContainsKey(mode) ? rgxes[mode] : null);
        }