Author: pbartok
Date: 2006-03-12 18:30:48 -0500 (Sun, 12 Mar 2006)
New Revision: 57885

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBoxBase.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextControl.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIWin32.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIX11.cs
Log:
2006-03-12  Peter Dennis Bartok  <[EMAIL PROTECTED]>

        * TextControl.cs:
          - Switched caret to be just 1 pixel wide, matches MS and looks less
            clunky
          - Moved caret display 1 pixel down from the top of the control
            to improve view
          - InsertCharAtCharet: Update the selection start if moving the caret
            (fixes bug #77696; based on patch suggested by [EMAIL PROTECTED])
          - No longer always creating the caret when the caret methods are
            called. Only the actual ShowCaret/HideCaret will do that now
          - Only setting caret visible if the owner control has focus
          - UpdateView: Added invalidation-shortcut logic for center and right 
            aligned text. Previously we'd update all according to the left
            logic which caused drawing errors. Also fixed height of invalidated
            areas, now properly invalidating the whole area (was off-by-one)
          - owner_HandleCreated: Always generate the document when the
            handle is created; this ensures that 
        * TextBoxBase.cs:
          - Fixed situation where caret would disappear under the right
            window border, also improved scrolling behaviour on left-
            aligned textboxes
          - Fixed right-aligned textboxes to have a border to the
            right instead of the caret being under the right border
        * XplatUIX11.cs:
          - Switched from 'nested' to simple visible/not visible tracking 
            for caret (part of fix for #77671)
          - No longer passing through translated FocusIn/FocusOut messages
            since we were notifying too often and the wrong windows. Instead
            we just notify our focussed window of receiving or loosing focus
        * XplatUIWin32.cs: Switched from 'nested' show/hide 
          counting for caret to simple visible yes/no behaviour (part of 
          fix for #77671)



Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-03-12 23:16:05 UTC (rev 57884)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-03-12 23:30:48 UTC (rev 57885)
@@ -1,3 +1,37 @@
+2006-03-12  Peter Dennis Bartok  <[EMAIL PROTECTED]>
+
+       * TextControl.cs:
+         - Switched caret to be just 1 pixel wide, matches MS and looks less
+           clunky
+         - Moved caret display 1 pixel down from the top of the control
+           to improve view
+         - InsertCharAtCharet: Update the selection start if moving the caret
+           (fixes bug #77696; based on patch suggested by [EMAIL PROTECTED])
+         - No longer always creating the caret when the caret methods are
+           called. Only the actual ShowCaret/HideCaret will do that now
+         - Only setting caret visible if the owner control has focus
+         - UpdateView: Added invalidation-shortcut logic for center and right 
+           aligned text. Previously we'd update all according to the left
+           logic which caused drawing errors. Also fixed height of invalidated
+           areas, now properly invalidating the whole area (was off-by-one)
+         - owner_HandleCreated: Always generate the document when the
+           handle is created; this ensures that 
+       * TextBoxBase.cs:
+         - Fixed situation where caret would disappear under the right
+           window border, also improved scrolling behaviour on left-
+           aligned textboxes
+         - Fixed right-aligned textboxes to have a border to the
+           right instead of the caret being under the right border
+       * XplatUIX11.cs:
+         - Switched from 'nested' to simple visible/not visible tracking 
+           for caret (part of fix for #77671)
+         - No longer passing through translated FocusIn/FocusOut messages
+           since we were notifying too often and the wrong windows. Instead
+           we just notify our focussed window of receiving or loosing focus
+       * XplatUIWin32.cs: Switched from 'nested' show/hide 
+         counting for caret to simple visible yes/no behaviour (part of 
+         fix for #77671)
+
 2006-03-11  Alexander Olk  <[EMAIL PROTECTED]>
 
        * Mime.cs: Remove debug code...

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBoxBase.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBoxBase.cs   
2006-03-12 23:16:05 UTC (rev 57884)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBoxBase.cs   
2006-03-12 23:30:48 UTC (rev 57885)
@@ -63,7 +63,8 @@
                internal int                    requested_height;
                internal int                    canvas_width;
                internal int                    canvas_height;
-               internal int                    track_width = 20;
+               static internal int             track_width = 20;
+               static internal int             track_border = 5;
                internal DateTime               click_last;
                internal CaretSelection         click_mode;
                internal Bitmap                 bmp;
@@ -1097,12 +1098,10 @@
                                }
                        }
 
-                       document.ViewPortWidth = width;
-                       document.ViewPortHeight = height;
+                       base.SetBoundsCore (x, y, width, height, specified);
 
+                       TextBoxBase_SizeChanged(this, EventArgs.Empty);
                        CalculateDocument();
-
-                       base.SetBoundsCore (x, y, width, height, specified);
                }
 
                protected override void WndProc(ref Message m) {
@@ -1398,6 +1397,8 @@
                private void TextBoxBase_SizeChanged(object sender, EventArgs 
e) {
                        canvas_width = ClientSize.Width;
                        canvas_height = ClientSize.Height;
+                       document.ViewPortWidth = canvas_width;
+                       document.ViewPortHeight = canvas_height;
 
                        // We always move them, they just might not be displayed
                        hscroll.Bounds = new Rectangle (ClientRectangle.Left, 
ClientRectangle.Bottom - hscroll.Height, ClientSize.Width - (vscroll.Visible ? 
SystemInformation.VerticalScrollBarWidth : 0), hscroll.Height);
@@ -1449,7 +1450,7 @@
                        if (document.Width >= ClientSize.Width) {
                                hscroll.Enabled = true;
                                hscroll.Minimum = 0;
-                               hscroll.Maximum = document.Width - 
ClientSize.Width;
+                               hscroll.Maximum = document.Width - 
ClientSize.Width + track_border;
                        } else {
                                hscroll.Maximum = document.ViewPortWidth;
                                hscroll.Enabled = false;
@@ -1572,7 +1573,7 @@
                                        } while (hscroll.Value > pos.X);
                                }
 
-                               if ((pos.X > (this.canvas_width + 
document.ViewPortX - track_width)) && (hscroll.Value != hscroll.Maximum)) {
+                               if ((pos.X > (this.canvas_width + 
document.ViewPortX - track_width)) && (hscroll.Enabled && (hscroll.Value != 
hscroll.Maximum))) {
                                        do {
                                                if ((hscroll.Value + 
track_width) <= hscroll.Maximum) {
                                                        hscroll.Value += 
track_width;
@@ -1590,7 +1591,7 @@
                                        }
                                }
 
-                               if ((pos.X > (this.canvas_width + 
document.ViewPortX)) && (hscroll.Value != hscroll.Maximum)) {
+                               if ((pos.X > (this.canvas_width + 
document.ViewPortX)) && (hscroll.Enabled && (hscroll.Value != 
hscroll.Maximum))) {
                                        hscroll.Value = hscroll.Maximum;
                                }
                        } else {

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextControl.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextControl.cs   
2006-03-12 23:16:05 UTC (rev 57884)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextControl.cs   
2006-03-12 23:30:48 UTC (rev 57885)
@@ -758,6 +758,8 @@
                internal int            crlf_size;              // 1 or 2, 
depending on whether we use \r\n or just \n
 
                internal TextBoxBase    owner;                  // Who's owning 
us?
+               static internal int     caret_width = 1;
+               static internal int     caret_shift = 1;
                #endregion      // Local Variables
 
                #region Constructors
@@ -949,7 +951,7 @@
                        }
 
                        set {
-                               viewport_width = value - 4;
+                               viewport_width = value - 2;
                        }
                }
 
@@ -1280,6 +1282,7 @@
                                return;
                        }
 
+                       // Optimize invalidation based on Line alignment
                        if (RecalculateDocument(owner.CreateGraphicsInternal(), 
line.line_no, line.line_no, true)) {
                                // Lineheight changed, invalidate the rest of 
the document
                                if ((line.Y - viewport_y) >=0 ) {
@@ -1290,7 +1293,22 @@
                                        owner.Invalidate();
                                }
                        } else {
-                               owner.Invalidate(new 
Rectangle((int)line.widths[pos] - viewport_x - 1, line.Y - viewport_y, 
viewport_width, line.height));
+                               switch(line.alignment) {
+                                       case HorizontalAlignment.Left: {
+                                               owner.Invalidate(new 
Rectangle((int)line.widths[pos] - viewport_x - 1, line.Y - viewport_y, 
viewport_width, line.height + 1));
+                                               break;
+                                       }
+
+                                       case HorizontalAlignment.Center: {
+                                               owner.Invalidate(new 
Rectangle(0, line.Y - viewport_y, viewport_width, line.height + 1));
+                                               break;
+                                       }
+
+                                       case HorizontalAlignment.Right: {
+                                               owner.Invalidate(new 
Rectangle(0, line.Y - viewport_y, (int)line.widths[pos + 1] - viewport_x + 
line.align_shift, line.height + 1));
+                                               break;
+                                       }
+                               }
                        }
                }
 
@@ -1375,9 +1393,9 @@
                        caret.pos = pos;
                        caret.height = caret.tag.height;
 
-                       XplatUI.DestroyCaret(owner.Handle);
-                       XplatUI.CreateCaret(owner.Handle, 2, caret.height);
-                       XplatUI.SetCaretPos(owner.Handle, 
(int)caret.tag.line.widths[caret.pos] + caret.line.align_shift - viewport_x, 
caret.line.Y + caret.tag.shift - viewport_y);
+                       if (owner.Focused) {
+                               XplatUI.SetCaretPos(owner.Handle, 
(int)caret.tag.line.widths[caret.pos] + caret.line.align_shift - viewport_x, 
caret.line.Y + caret.tag.shift - viewport_y + caret_shift);
+                       }
 
                        if (CaretMoved != null) CaretMoved(this, 
EventArgs.Empty);
                }
@@ -1393,18 +1411,23 @@
                        caret.line = caret.tag.line;
                        caret.height = caret.tag.height;
 
-                       XplatUI.DestroyCaret(owner.Handle);
-                       XplatUI.CreateCaret(owner.Handle, 2, caret.height);
-                       XplatUI.SetCaretPos(owner.Handle, 
(int)caret.tag.line.widths[caret.pos] + caret.line.align_shift - viewport_x, 
caret.line.Y + caret.tag.shift - viewport_y);
+                       if (owner.Focused) {
+                               XplatUI.SetCaretPos(owner.Handle, 
(int)caret.tag.line.widths[caret.pos] + caret.line.align_shift - viewport_x, 
caret.line.Y + caret.tag.shift - viewport_y + caret_shift);
+                       }
 
                        if (CaretMoved != null) CaretMoved(this, 
EventArgs.Empty);
                }
 
                internal void CaretHasFocus() {
-                       if ((caret.tag != null) && (!selection_visible) && 
owner.IsHandleCreated) {
-                               XplatUI.CreateCaret(owner.Handle, 2, 
caret.height);
-                               XplatUI.SetCaretPos(owner.Handle, 
(int)caret.tag.line.widths[caret.pos] + caret.line.align_shift - viewport_x, 
caret.line.Y + caret.tag.shift - viewport_y);
-                               XplatUI.CaretVisible(owner.Handle, true);
+                       if ((caret.tag != null) && owner.IsHandleCreated) {
+                               XplatUI.CreateCaret(owner.Handle, caret_width, 
caret.height);
+                               XplatUI.SetCaretPos(owner.Handle, 
(int)caret.tag.line.widths[caret.pos] + caret.line.align_shift - viewport_x, 
caret.line.Y + caret.tag.shift - viewport_y + caret_shift);
+
+                               if (!selection_visible) {
+                                       XplatUI.CaretVisible(owner.Handle, 
true);
+                               } else {
+                                       XplatUI.CaretVisible(owner.Handle, 
false);
+                               }
                        }
                }
 
@@ -1425,9 +1448,11 @@
                        caret.tag = LineTag.FindTag(caret.line, caret.pos);
                        caret.height = caret.tag.height;
 
-                       XplatUI.CreateCaret(owner.Handle, 2, caret.height);
-                       XplatUI.SetCaretPos(owner.Handle, 
(int)caret.tag.line.widths[caret.pos] + caret.line.align_shift - viewport_x, 
caret.line.Y + caret.tag.shift - viewport_y);
-                       XplatUI.CaretVisible(owner.Handle, true);
+                       if (owner.Focused) {
+                               XplatUI.CreateCaret(owner.Handle, caret_width, 
caret.height);
+                               XplatUI.SetCaretPos(owner.Handle, 
(int)caret.tag.line.widths[caret.pos] + caret.line.align_shift - viewport_x, 
caret.line.Y + caret.tag.shift - viewport_y + caret_shift);
+                               XplatUI.CaretVisible(owner.Handle, true);
+                       }
 
                        if (CaretMoved != null) CaretMoved(this, 
EventArgs.Empty);
                }
@@ -1441,11 +1466,16 @@
 
                        if (caret.tag.height != caret.height) {
                                caret.height = caret.tag.height;
-                               XplatUI.CreateCaret(owner.Handle, 2, 
caret.height);
+                               if (owner.Focused) {
+                                       XplatUI.CreateCaret(owner.Handle, 
caret_width, caret.height);
+                               }
                        }
-                       XplatUI.SetCaretPos(owner.Handle, 
(int)caret.tag.line.widths[caret.pos] + caret.line.align_shift - viewport_x, 
caret.line.Y + caret.tag.shift - viewport_y);
-                       XplatUI.CaretVisible(owner.Handle, true);
 
+                       if (owner.Focused) {
+                               XplatUI.SetCaretPos(owner.Handle, 
(int)caret.tag.line.widths[caret.pos] + caret.line.align_shift - viewport_x, 
caret.line.Y + caret.tag.shift - viewport_y + caret_shift);
+                               XplatUI.CaretVisible(owner.Handle, true);
+                       }
+
                        if (CaretMoved != null) CaretMoved(this, 
EventArgs.Empty);
                }
 
@@ -1453,14 +1483,20 @@
                        if (!owner.IsHandleCreated) {
                                return;
                        }
-                       XplatUI.CaretVisible(owner.Handle, true);
+
+                       if (owner.Focused) {
+                               XplatUI.CaretVisible(owner.Handle, true);
+                       }
                }
 
                internal void HideCaret() {
                        if (!owner.IsHandleCreated) {
                                return;
                        }
-                       XplatUI.CaretVisible(owner.Handle, false);
+
+                       if (owner.Focused) {
+                               XplatUI.CaretVisible(owner.Handle, false);
+                       }
                }
 
                internal void MoveCaret(CaretDirection direction) {
@@ -2089,6 +2125,7 @@
                        if (move_caret) {
                                caret.pos++;
                                UpdateCaret();
+                               SetSelectionToCaret(true);
                        }
                }
 
@@ -3608,9 +3645,7 @@
                }
 
                private void owner_HandleCreated(object sender, EventArgs e) {
-                       if (owner.Visible) {
-                               
RecalculateDocument(owner.CreateGraphicsInternal());
-                       }
+                       RecalculateDocument(owner.CreateGraphicsInternal());
                        PositionCaret(0, 0);
                }
 
@@ -4436,7 +4471,7 @@
                                        if (document.owner.IsHandleCreated) {
                                                
XplatUI.DestroyCaret(document.owner.Handle);
                                                
XplatUI.CreateCaret(document.owner.Handle, 2, document.caret.height);
-                                               
XplatUI.SetCaretPos(document.owner.Handle, 
(int)document.caret.tag.line.widths[document.caret.pos] + 
document.caret.line.align_shift - document.viewport_x, document.caret.line.Y + 
document.caret.tag.shift - document.viewport_y);
+                                               
XplatUI.SetCaretPos(document.owner.Handle, 
(int)document.caret.tag.line.widths[document.caret.pos] + 
document.caret.line.align_shift - document.viewport_x, document.caret.line.Y + 
document.caret.tag.shift - document.viewport_y + Document.caret_shift);
                                                
XplatUI.CaretVisible(document.owner.Handle, true);
                                        }
 

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIWin32.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIWin32.cs  
2006-03-12 23:16:05 UTC (rev 57884)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIWin32.cs  
2006-03-12 23:30:48 UTC (rev 57885)
@@ -53,6 +53,7 @@
                internal static WndProc         wnd_proc;
                internal static IntPtr          prev_mouse_hwnd;
                internal static IntPtr          override_cursor;
+               internal static bool            caret_visible;
 
                internal static bool            themes_enabled;
                private Hashtable               timer_list;
@@ -1757,6 +1758,7 @@
        
                internal override void CreateCaret(IntPtr hwnd, int width, int 
height) {
                        Win32CreateCaret(hwnd, IntPtr.Zero, width, height);
+                       caret_visible = false;
                }
 
                internal override void DestroyCaret(IntPtr hwnd) {
@@ -1769,9 +1771,15 @@
 
                internal override void CaretVisible(IntPtr hwnd, bool visible) {
                        if (visible) {
-                               Win32ShowCaret(hwnd);
+                               if (!caret_visible) {
+                                       Win32ShowCaret(hwnd);
+                                       caret_visible = true;
+                               }
                        } else {
-                               Win32HideCaret(hwnd);
+                               if (caret_visible) {
+                                       Win32HideCaret(hwnd);
+                                       caret_visible = false;
+                               }
                        }
                }
 

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIX11.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIX11.cs    
2006-03-12 23:16:05 UTC (rev 57884)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUIX11.cs    
2006-03-12 23:30:48 UTC (rev 57885)
@@ -1708,20 +1708,15 @@
                        // Visible is cumulative; two hides require two shows 
before the caret is visible again
                        if (Caret.Hwnd == handle) {
                                if (visible) {
-                                       if (Caret.Visible < 1) {
-                                               Caret.Visible++;
-                                               Caret.On = false;
-                                               if (Caret.Visible == 1) {
-                                                       ShowCaret();
-                                                       Caret.Timer.Start();
-                                               }
+                                       if (!Caret.Visible) {
+                                               Caret.Visible = true;
+                                               ShowCaret();
+                                               Caret.Timer.Start();
                                        }
                                } else {
-                                       Caret.Visible--;
-                                       if (Caret.Visible == 0) {
-                                               Caret.Timer.Stop();
-                                               HideCaret();
-                                       }
+                                       Caret.Visible = false;
+                                       Caret.Timer.Stop();
+                                       HideCaret();
                                }
                        }
                }
@@ -1864,7 +1859,7 @@
                        Caret.Window = hwnd.client_window;
                        Caret.Width = width;
                        Caret.Height = height;
-                       Caret.Visible = 0;
+                       Caret.Visible = false;
                        Caret.On = false;
 
                        gc_values = new XGCValues();
@@ -2331,7 +2326,7 @@
 
                internal override void DestroyCaret(IntPtr handle) {
                        if (Caret.Hwnd == handle) {
-                               if (Caret.Visible == 1) {
+                               if (Caret.Visible == true) {
                                        Caret.Timer.Stop();
                                        HideCaret();
                                }
@@ -2340,7 +2335,7 @@
                                        Caret.gc = IntPtr.Zero;
                                }
                                Caret.Hwnd = IntPtr.Zero;
-                               Caret.Visible = 0;
+                               Caret.Visible = false;
                                Caret.On = false;
                        }
                }
@@ -3008,21 +3003,25 @@
                                }
 
                                case XEventName.FocusIn: {
-                                       if (!hwnd.Enabled) {
+                                       // We received focus. We use X11 focus 
only to know if the app window does or does not have focus
+                                       // We do not track the actual focussed 
window via it. Instead, this is done via FocusWindow internally
+                                       // Receiving focus means we've gotten 
activated and therefore we need to let the actual FocusWindow know 
+                                       // about it having focus again
+                                       if (xevent.FocusChangeEvent.detail != 
NotifyDetail.NotifyNonlinear) {
                                                goto ProcessNextMessage;
                                        }
-                                       msg.message=Msg.WM_SETFOCUS;
-                                       msg.wParam=IntPtr.Zero;
-                                       break;
+                                       SendMessage(FocusWindow, 
Msg.WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero);
+                                       goto ProcessNextMessage;
                                }
 
                                case XEventName.FocusOut: {
-                                       if (!hwnd.Enabled) {
+                                       // Se the comment for our FocusIn 
handler
+                                       if (xevent.FocusChangeEvent.detail != 
NotifyDetail.NotifyNonlinear) {
                                                goto ProcessNextMessage;
                                        }
-                                       msg.message=Msg.WM_KILLFOCUS;
-                                       msg.wParam=IntPtr.Zero;
-                                       break;
+
+                                       SendMessage(FocusWindow, 
Msg.WM_KILLFOCUS, IntPtr.Zero, IntPtr.Zero);
+                                       goto ProcessNextMessage;
                                }
 
                                case XEventName.Expose: {
@@ -3074,12 +3073,12 @@
                                        #if DriverDebugExtra
                                                
Console.WriteLine("GetMessage(): Window {0:X} Exposed area {1},{2} {3}x{4}", 
hwnd.client_window.ToInt32(), xevent.ExposeEvent.x, xevent.ExposeEvent.y, 
xevent.ExposeEvent.width, xevent.ExposeEvent.height);
                                        #endif
-                                       if (Caret.Visible == 1) {
+                                       if (Caret.Visible == true) {
                                                Caret.Paused = true;
                                                HideCaret();
                                        }
 
-                                       if (Caret.Visible == 1) {
+                                       if (Caret.Visible == true) {
                                                ShowCaret();
                                                Caret.Paused = false;
                                        }
@@ -3385,7 +3384,7 @@
 
                        hwnd = Hwnd.ObjectFromHandle(handle);
 
-                       if (Caret.Visible == 1) {
+                       if (Caret.Visible == true) {
                                Caret.Paused = true;
                                HideCaret();
                        }
@@ -3428,7 +3427,7 @@
 
                        
 
-                       if (Caret.Visible == 1) {
+                       if (Caret.Visible == true) {
                                ShowCaret();
                                Caret.Paused = false;
                        }
@@ -3681,8 +3680,7 @@
                                Caret.X = x;
                                Caret.Y = y;
 
-//Console.WriteLine("Setting caret pos {0},{1}", x, y);
-                               if (Caret.Visible == 1) {
+                               if (Caret.Visible == true) {
                                        ShowCaret();
                                        Caret.Timer.Start();
                                }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to