Beispiel #1
0
        protected override void OnLateUpdate()
        {
            if (!_isDirty)
            {
                _isDirty = _lastSize.X != Size.X || _lastSize.Y != Size.Y;
            }

            if (_isDirty)
            {
                var style = Desktop.GetStyle(Style).Styles[State];
                UpdateText(style);
            }

            if (Desktop.HotControl == this)
            {
                var m = Gui.MousePosition;
                _activeHref = null;

                foreach (var line in _lines)
                {
                    foreach (var element in line.Elements)
                    {
                        if (!element.IsLink)
                        {
                            continue;
                        }

                        if (element.Rectangle.Contains(m))
                        {
                            _activeHref = element.Href;
                            break;
                        }
                    }
                }
            }
        }
        public void Open()
        {
            if (OnOpening != null)
            {
                var args = new SquidEventArgs();
                OnOpening(this, args);
                if (args.Cancel)
                {
                    return;
                }
            }

            if (!_wasOpenOnce)
            {
                if (DropdownAutoSize)
                {
                    Dropdown.Size = new Point(Size.X, DropdownSize.Y);
                }
                else
                {
                    Dropdown.Size = new Point(DropdownSize.X, DropdownSize.Y);
                }

                _wasOpenOnce = true;
            }

            Dropdown.Position = Location + new Point(0, Size.Y);

            Desktop.ShowDropdown(Dropdown, false);
            IsOpen = true;

            if (OnOpened != null)
            {
                OnOpened(this, null);
            }
        }
Beispiel #3
0
        //protected override void Bind(object instance)
        //{
        //    if (string.IsNullOrEmpty(Aspect)) return;
        //    if (instance == null) return;

        //    Type type = instance.GetType();
        //    object value = null;

        //    System.Reflection.PropertyInfo property = type.GetProperty(Aspect);
        //    if (property != null)
        //    {
        //        value = property.GetValue(instance, null);
        //        if (value != null) Text = value.ToString();
        //    }
        //    else
        //    {
        //        System.Reflection.FieldInfo field = type.GetField(Aspect);
        //        if (field != null)
        //        {
        //            value = field.GetValue(instance);
        //            if (value != null) Text = value.ToString();
        //        }
        //    }
        //}

        protected override void OnStateChanged()
        {
            var style = Desktop.GetStyle(Style).Styles[State];

            UpdateText(style);
        }
Beispiel #4
0
        void TextBox_MouseDown(Control sender, MouseEventArgs args)
        {
            if (args.Button > 0)
            {
                return;
            }

            if (!_hasFocus)
            {
                _savedText = Text;
                _hasFocus  = true;
            }

            var style = Desktop.GetStyle(Style).Styles[State];

            var masked = Text;

            if (IsPassword)
            {
                masked = new string(PasswordChar, masked.Length);
            }

            if (string.IsNullOrEmpty(masked))
            {
                return;
            }

            var font = Gui.Renderer.GetFont(style.Font);

            if (font < 0)
            {
                return;
            }

            var p     = Gui.MousePosition - Location;
            var s1    = Gui.Renderer.GetTextSize(masked, font);
            var carex = p.X + _offset + s1.X;
            var x     = 0;

            var text = string.Empty;

            for (var i = 1; i <= masked.Length; i++)
            {
                text = masked.Substring(0, i);
                x    = _offset + Gui.Renderer.GetTextSize(text, font).X;
                if (x > p.X)
                {
                    _caret = i - 1;
                    break;
                }
            }

            if (x < p.X)
            {
                _caret = masked.Length;
            }

            if (Gui.CtrlPressed)
            {
                var left  = FindIndexLeft(_caret, masked);
                var right = FindIndexRight(_caret, masked);

                if (char.IsWhiteSpace(masked, left) || char.IsPunctuation(masked, left))
                {
                    left++;
                }

                if (char.IsWhiteSpace(masked, right - 1) || char.IsPunctuation(masked, right - 1))
                {
                    right--;
                }

                _selectStart = left;
                _selectEnd   = right;

                _caret = _selectEnd;
            }
            else if (Gui.ShiftPressed)
            {
                _selectEnd = _caret;
            }
            else
            {
                _selectStart = _caret;
                _selectEnd   = _caret;
            }
        }
Beispiel #5
0
        void TextBox_MousePress(Control sender, MouseEventArgs args)
        {
            if (args.Button > 0)
            {
                return;
            }
            if (Gui.CtrlPressed)
            {
                return;
            }

            var style = Desktop.GetStyle(Style).Styles[State];

            var masked = Text;

            if (IsPassword)
            {
                masked = new string(PasswordChar, masked.Length);
            }

            if (string.IsNullOrEmpty(masked))
            {
                return;
            }

            var font = Gui.Renderer.GetFont(style.Font);

            if (font < 0)
            {
                return;
            }

            var p     = Gui.MousePosition - Location;
            var s1    = Gui.Renderer.GetTextSize(masked, font);
            var carex = p.X + _offset + s1.X;
            var x     = 0;

            var text  = string.Empty;
            var caret = _caret;

            for (var i = 1; i <= masked.Length; i++)
            {
                text = masked.Substring(0, i);
                x    = _offset + Gui.Renderer.GetTextSize(text, font).X;
                if (x > p.X)
                {
                    _selectEnd = i - 1;
                    break;
                }
            }

            if (x < p.X)
            {
                _selectEnd = masked.Length;
            }

            var start = Math.Min(_selectStart, _selectEnd);
            var end   = Math.Max(_selectStart, _selectEnd);

            if (_selectEnd < _selectStart)
            {
                _caret = start;
            }
            else
            {
                _caret = end;
            }
        }
Beispiel #6
0
 public override void Show(Desktop target)
 {
     _result = DialogResult.None;
     base.Show(target);
 }