diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/CodeCompletionWindow.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/CodeCompletionWindow.cs
index 9c616fafde..dc8e8a1fee 100644
--- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/CodeCompletionWindow.cs
+++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/CodeCompletionWindow.cs
@@ -79,6 +79,7 @@ namespace ICSharpCode.XmlEditor
declarationViewWindow = new DeclarationViewWindow(parentForm);
SetDeclarationViewLocation();
+ declarationViewWindow.MouseMove += ControlMouseMove;
declarationViewWindow.ShowDeclarationViewWindow();
control.Focus();
CodeCompletionListViewSelectedItemChanged(this, EventArgs.Empty);
diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/AbstractCompletionWindow.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/AbstractCompletionWindow.cs
index c139e53acd..6e07fb7905 100644
--- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/AbstractCompletionWindow.cs
+++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/AbstractCompletionWindow.cs
@@ -125,6 +125,10 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
control.ActiveTextAreaControl.Caret.PositionChanged += new EventHandler(CaretOffsetChanged);
control.ActiveTextAreaControl.TextArea.LostFocus += new EventHandler(this.TextEditorLostFocus);
control.Resize += new EventHandler(ParentFormLocationChanged);
+
+ foreach (Control c in Controls) {
+ c.MouseMove += ControlMouseMove;
+ }
}
void ParentFormLocationChanged(object sender, EventArgs e)
@@ -168,6 +172,10 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
// take out the inserted methods
parentForm.LocationChanged -= new EventHandler(ParentFormLocationChanged);
+ foreach (Control c in Controls) {
+ c.MouseMove -= ControlMouseMove;
+ }
+
if (control.ActiveTextAreaControl.VScrollBar != null) {
control.ActiveTextAreaControl.VScrollBar.ValueChanged -= new EventHandler(ParentFormLocationChanged);
}
@@ -181,5 +189,25 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
control.Resize -= new EventHandler(ParentFormLocationChanged);
Dispose();
}
+
+ protected override void OnMouseMove(MouseEventArgs e)
+ {
+ base.OnMouseMove(e);
+ ControlMouseMove(this, e);
+ }
+
+ ///
+ /// Invoked when the mouse moves over this form or any child control.
+ /// Shows the mouse cursor on the text area if it has been hidden.
+ ///
+ ///
+ /// Derived classes should attach this handler to the MouseMove event
+ /// of all created controls which are not added to the Controls
+ /// collection.
+ ///
+ protected void ControlMouseMove(object sender, MouseEventArgs e)
+ {
+ control.ActiveTextAreaControl.TextArea.ShowHiddenCursor(false);
+ }
}
}
diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionWindow.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionWindow.cs
index fd44816ad1..f984f85ad6 100644
--- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionWindow.cs
+++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionWindow.cs
@@ -79,6 +79,7 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
}
SetDeclarationViewLocation();
declarationViewWindow.ShowDeclarationViewWindow();
+ declarationViewWindow.MouseMove += ControlMouseMove;
control.Focus();
CodeCompletionListViewSelectedItemChanged(this, EventArgs.Empty);
diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs
index 10addd8b38..44a1fdc40c 100644
--- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs
+++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs
@@ -29,12 +29,12 @@ namespace ICSharpCode.TextEditor
[ToolboxItem(false)]
public class TextArea : Control
{
- internal bool HiddenMouseCursor = false;
+ bool hiddenMouseCursor = false;
///
/// The position where the mouse cursor was when it was hidden. Sometimes the text editor gets MouseMove
/// events when typing text even if the mouse is not moved.
///
- internal Point MouseCursorHidePosition;
+ Point mouseCursorHidePosition;
Point virtualTop = new Point(0, 0);
TextAreaControl motherTextAreaControl;
@@ -315,6 +315,20 @@ namespace ICSharpCode.TextEditor
}
}
+ ///
+ /// Shows the mouse cursor if it has been hidden.
+ ///
+ /// true to always show the cursor or false to show it only if it has been moved since it was hidden.
+ internal void ShowHiddenCursor(bool forceShow)
+ {
+ if (hiddenMouseCursor) {
+ if (mouseCursorHidePosition != Cursor.Position || forceShow) {
+ Cursor.Show();
+ hiddenMouseCursor = false;
+ }
+ }
+ }
+
// static because the mouse can only be in one text area and we don't want to have
// tooltips of text areas from inactive tabs floating around.
@@ -576,10 +590,10 @@ namespace ICSharpCode.TextEditor
return;
}
- if (!HiddenMouseCursor && TextEditorProperties.HideMouseCursor) {
+ if (!hiddenMouseCursor && TextEditorProperties.HideMouseCursor) {
if (this.ClientRectangle.Contains(PointToClient(Cursor.Position))) {
- MouseCursorHidePosition = Cursor.Position;
- HiddenMouseCursor = true;
+ mouseCursorHidePosition = Cursor.Position;
+ hiddenMouseCursor = true;
Cursor.Hide();
}
}
diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs
index e19e30f98e..7bf8d1c678 100644
--- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs
+++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs
@@ -91,23 +91,26 @@ namespace ICSharpCode.TextEditor
}
}
- void ShowHiddenCursor(bool forceShow)
+ void ShowHiddenCursorIfMovedOrLeft()
{
- if (textArea.HiddenMouseCursor) {
- if (textArea.MouseCursorHidePosition != Cursor.Position) {
- Cursor.Show();
- textArea.HiddenMouseCursor = false;
- }
- }
+ textArea.ShowHiddenCursor(!textArea.Focused ||
+ !textArea.ClientRectangle.Contains(textArea.PointToClient(Cursor.Position)));
}
void TextAreaLostFocus(object sender, EventArgs e)
{
- ShowHiddenCursor(true);
+ // The call to ShowHiddenCursorIfMovedOrLeft is delayed
+ // until pending messages have been processed
+ // so that it can properly detect whether the TextArea
+ // has really lost focus.
+ // For example, the CodeCompletionWindow gets focus when it is shown,
+ // but immediately gives back focus to the TextArea.
+ textArea.BeginInvoke(new MethodInvoker(ShowHiddenCursorIfMovedOrLeft));
}
+
void OnMouseLeave(object sender, EventArgs e)
{
- ShowHiddenCursor(true);
+ ShowHiddenCursorIfMovedOrLeft();
gotmousedown = false;
mousedownpos = nilPoint;
}
@@ -157,7 +160,7 @@ namespace ICSharpCode.TextEditor
break;
}
- ShowHiddenCursor(false);
+ textArea.ShowHiddenCursor(false);
if (dodragdrop) {
dodragdrop = false;
return;