]> O.S.I.I.S - jp/crow.git/commitdiff
label.Text locations check, event.Handled = true for mouse overrides in TextBox
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 9 Apr 2021 02:42:23 +0000 (04:42 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 9 Apr 2021 02:42:23 +0000 (04:42 +0200)
Crow/src/Widgets/Label.cs
Crow/src/Widgets/TextBox.cs

index 00788de40041fcb1236be4dc537df2f7545c76d2..f8574959823023375d6fe8ff9e97212893eea801 100644 (file)
@@ -161,12 +161,26 @@ namespace Crow
                                        getLines ();
                                        textMeasureIsUpToDate = false;
                                }
+                               constraintsLocations();
                                NotifyValueChanged ("Text", Text);
                                OnTextChanged (this, new TextChangeEventArgs (new TextChange (0, oldTextLength, _text)));
                                RegisterForGraphicUpdate ();
             }
         }
 
+               void constraintsLocations () {
+                       if (selectionStart.HasValue) {
+                               CharLocation loc = CurrentLoc.Value;
+                               int l = Math.Min (loc.Line, lines.Count - 1);
+                               selectionStart = new CharLocation (l, Math.Min (loc.Column, lines[l].Length - 1));
+                       }
+                       if (CurrentLoc.HasValue) {
+                               CharLocation loc = CurrentLoc.Value;
+                               int l = Math.Min (loc.Line, lines.Count - 1);
+                               CurrentLoc = new CharLocation (l, Math.Min (loc.Column, lines[l].Length - 1));
+                       }
+               }
+
                /// <summary>
                /// If 'true', linebreaks will be interpreted. If 'false', linebreaks are threated as unprintable
                /// unicode characters. Default value is 'False'.
@@ -181,6 +195,7 @@ namespace Crow
                                        return;
                                _multiline = value;
                                getLines ();
+                               constraintsLocations();
                                NotifyValueChangedAuto (_multiline);
                                RegisterForGraphicUpdate();
                        }
@@ -445,6 +460,7 @@ namespace Crow
                                                                selRect.Width = selEnd.VisualCharXPosition - selStart.VisualCharXPosition;
                                                        }
 
+
                                                        gr.SetSource (selBackground);
                                                        gr.Rectangle (selRect);
                                                        if (encodedBytes < 0)
@@ -518,7 +534,7 @@ namespace Crow
                        return true;
                }
 
-               void updateLocation (Context gr, int clientWidth, ref CharLocation? location) {
+               protected void updateLocation (Context gr, int clientWidth, ref CharLocation? location) {
                        if (location == null)
                                return;
                        CharLocation loc = location.Value;
index dddcdfb1e2b625c0ed54203754acffe410177a93..bf1678f47b5b0efa62a9fbb33ef137f764e54e1f 100644 (file)
@@ -133,17 +133,20 @@ namespace Crow
                }
 
                /// <summary> Process scrolling vertically, or if shift is down, vertically </summary>
-               public override void onMouseWheel (object sender, MouseWheelEventArgs e) {
-                       base.onMouseWheel (sender, e);
+               public override void onMouseWheel (object sender, MouseWheelEventArgs e) {                      
                        if (IFace.Shift)
                                ScrollX += e.Delta * MouseWheelSpeed;
                        else
                                ScrollY -= e.Delta * MouseWheelSpeed;
+                       
+                       e.Handled = true;
+                       base.onMouseWheel (sender, e);
                }
-        public override void onMouseMove (object sender, MouseMoveEventArgs e) {
-            base.onMouseMove (sender, e);
-            if (!HasFocus || !IFace.IsDown (MouseButton.Left))
-                return;
+        public override void onMouseMove (object sender, MouseMoveEventArgs e) {            
+            if (!HasFocus || !IFace.IsDown (MouseButton.Left)) {
+                base.onMouseMove (sender, e);
+                               return;
+                       }
             Rectangle cb = ClientRectangle;
 
             if (CurrentLoc.Value.VisualCharXPosition < scrollX)
@@ -161,6 +164,8 @@ namespace Crow
             else if (CurrentLoc.Value.Line > lastLine)
                 ScrollY = (int)(lineHeight * (CurrentLoc.Value.Line + 1)) - cb.Height;
 
+                       e.Handled = true;
+                       base.onMouseMove (sender, e);
         }
         #endregion
         public override void OnLayoutChanges (LayoutingType layoutType) {