Revision: 8426
Author:
v...@rsdn.ru
Date: Wed Nov 4 01:21:20 2009
Log: Fix WpfHint behavior. Now hint closed by timer.
http://code.google.com/p/nemerle/source/detail?r=8426
Added:
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/Utils.cs
Modified:
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/Hint.cs
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/HintRoot.cs
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/HintSource.cs
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/HintWindow.xaml.cs
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/PopupWindow.cs
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/Win32.cs
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/WpfHint.csproj
=======================================
--- /dev/null
+++ /nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/Utils.cs
Wed Nov 4 01:21:20 2009
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+
+namespace WpfHint
+{
+ static class Utils
+ {
+ public static bool Contains(this Rect rect, Point pt)
+ {
+ if (pt.X < rect.Left)
+ return false;
+
+ if (pt.X > rect.Right - 1)
+ return false;
+
+ if (pt.Y < rect.Top)
+ return false;
+
+ if (pt.Y > rect.Bottom - 1)
+ return false;
+
+ return true;
+ }
+ }
+}
=======================================
--- /nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/Hint.cs
Tue Nov 3 07:48:08 2009
+++ /nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/Hint.cs
Wed Nov 4 01:21:20 2009
@@ -5,70 +5,70 @@
namespace WpfHint
{
- public class Hint
- {
- private HintWindow _hintWindow;
- private HintSource _hintSource;
- private string _text;
- private double _wrapWidth = 400.0;
+ public class Hint
+ {
+ private HintWindow _hintWindow;
+ private HintSource _hintSource;
+ private string _text;
+ private double _wrapWidth = 400.0;
private Func<string, string> _getHintContent;
public event Action<Hint, string> Click;
- public event Action<Hint> Closed;
-
- /// <summary>
- /// Deafult = 400.0
- /// </summary>
- public double WrapWidth
- {
- get { return _wrapWidth; }
- set
- {
- _wrapWidth = value;
-
- if (_hintWindow != null)
- _hintWindow.WrapWidth = value;
- }
- }
-
- /// <summary>
- /// Placment rect, relative to the screen
- /// (in screen coord)
- /// </summary>
- public Rect PlacementRect { get; set; }
-
- /// <summary>
- /// Hint text, could be change any time
- /// </summary>
- public string Text
- {
- get { return _text; }
- set
- {
- _text = value;
-
- if (_hintWindow == null)
- return;
-
- foreach (Window window in _hintWindow.OwnedWindows)
- window.Close();
-
- _hintWindow.Text = _text;
- }
- }
-
- public bool IsOpen { get { return _hintWindow != null; } }
-
- public void Close()
- {
- if (_hintWindow != null)
- _hintWindow.Close();
- }
+ public event Action<Hint> Closed;
+
+ /// <summary>
+ /// Deafult = 400.0
+ /// </summary>
+ public double WrapWidth
+ {
+ get { return _wrapWidth; }
+ set
+ {
+ _wrapWidth = value;
+
+ if (_hintWindow != null)
+ _hintWindow.WrapWidth = value;
+ }
+ }
+
+ /// <summary>
+ /// Placment rect, relative to the screen
+ /// (in screen coord)
+ /// </summary>
+ public Rect PlacementRect { get; set; }
+
+ /// <summary>
+ /// Hint text, could be change any time
+ /// </summary>
+ public string Text
+ {
+ get { return _text; }
+ set
+ {
+ _text = value;
+
+ if (_hintWindow == null)
+ return;
+
+ foreach (Window window in _hintWindow.OwnedWindows)
+ window.Close();
+
+ _hintWindow.Text = _text;
+ }
+ }
+
+ public bool IsOpen { get { return _hintWindow != null; } }
+
+ public void Close()
+ {
+ if (_hintWindow != null)
+ _hintWindow.Close();
+ }
public void Show(IntPtr owner, Rect placementRect, Func<string, string>
getHintContent, string text)
- {
- PlacementRect = placementRect;
- Text = text;
+ {
+ PlacementRect = placementRect;
+ Text = text;
_getHintContent = getHintContent;
try
@@ -78,57 +78,57 @@
catch
{
}
- }
-
- private void Show(IntPtr owner)
- {
- if (_hintWindow != null)
- throw new NotSupportedException("Hint already shown");
-
- // subclass
- _hintSource = new HintSource();
- _hintSource.Activate += Close;
- _hintSource.SubClass(owner);
-
- // create hint window
- var ht = HintRoot.Create(PlacementRect, _hintSource);
- _hintWindow = new HintWindow(this, ht) { Text = _text };
- new WindowInteropHelper(_hintWindow) { Owner = _hintSource.Owner };
- _hintWindow.Closed += HintWindowClosed;
+ }
+
+ private void Show(IntPtr owner)
+ {
+ if (_hintWindow != null)
+ throw new NotSupportedException("Hint already shown");
+
+ // subclass
+ _hintSource = new HintSource();
+ _hintSource.Activate += Close;
+ _hintSource.SubClass(owner);
+
+ // create hint window
+ var ht = HintRoot.Create(PlacementRect, _hintSource);
+ _hintWindow = new HintWindow(this, ht) { Text = _text };
+ new WindowInteropHelper(_hintWindow) { Owner = _hintSource.Owner };
+ _hintWindow.Closed += HintWindowClosed;
_hintWindow.MaxHeight =
800.0;//System.Windows.Forms.Screen.FromRectangle(PlacementRect).WorkingArea.
- _hintWindow.WrapWidth = _wrapWidth;
- _hintWindow.Show();
- }
-
- void HintWindowClosed(object sender, EventArgs e)
- {
- _hintSource.UnSubClass();
- _hintSource = null;
- _hintWindow = null;
- if (Closed != null) Closed(this);
- }
+ _hintWindow.WrapWidth = _wrapWidth;
+ _hintWindow.Show();
+ }
+
+ void HintWindowClosed(object sender, EventArgs e)
+ {
+ _hintSource.UnSubClass();
+ _hintSource = null;
+ _hintWindow = null;
+ if (Closed != null) Closed(this);
+ }
internal string RaiseGetHintContent(string key)
{
- try
- {
- if (_getHintContent != null)
- return _getHintContent(key);
- }
- catch (Exception ex)
- {
- Trace.WriteLine(ex);
- return "<hint><font color=\"Red\"><b>Exception throw when do hint
text lookup:</b></font><lb/>" + ex.Message + "</hint>";
- }
+ try
+ {
+ if (_getHintContent != null)
+ return _getHintContent(key);
+ }
+ catch (Exception ex)
+ {
+ Trace.WriteLine(ex);
+ return "<hint><font color=\"Red\"><b>Exception throw when do hint text
lookup:</b></font><lb/>" + ex.Message + "</hint>";
+ }
return key;
}
internal void RaiseClick(string handler)
- {
- if (Click != null)
+ {
+ if (Click != null)
Click(this, handler);
- }
- }
-}
+ }
+ }
+}
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/HintRoot.cs
Fri Oct 30 10:58:03 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/HintRoot.cs
Wed Nov 4 01:21:20 2009
@@ -4,143 +4,134 @@
namespace WpfHint
{
- internal abstract class HintRoot : IDisposable
- {
- public event Action MouseLeave;
- public Rect ActiveRect { get; protected set; }
-
- public abstract bool IsMouseOver { get; }
- protected void RaiseEvent()
- {
- if (MouseLeave != null) MouseLeave();
- }
-
- #region IDisposable Members
-
- public virtual void Dispose() { }
-
- #endregion
-
- public static HintRoot Create(FrameworkElement fe)
- {
- return new HintRootWpf(fe);
- }
-
- public static HintRoot Create(Rect rect, HintSource source)
- {
- return new HintRootWin32(rect, source);
- }
-
- private class HintRootWpf : HintRoot
- {
- private readonly FrameworkElement _fe;
-
- public HintRootWpf(FrameworkElement fe)
- {
- _fe = fe;
- var pt = fe.PointToScreen(new Point());
- var pt2 = fe.PointToScreen(new Point(fe.ActualWidth,
fe.ActualHeight));
- ActiveRect = new Rect(pt.X, pt.Y, pt2.X - pt.X, pt2.Y - pt.Y);
-
- fe.MouseLeave += OnMouse;
- }
-
- void OnMouse(object sender, MouseEventArgs e)
- {
- RaiseEvent();
- }
-
- public override bool IsMouseOver
- {
- get { return _fe.IsMouseOver; }
- }
-
- public override void Dispose()
- {
- _fe.MouseLeave -= OnMouse;
- }
-
- #region Equality
-
- public bool Equals(HintRootWpf other)
- {
- if (ReferenceEquals(null, other))
- return false;
-
- if (ReferenceEquals(this, other))
- return true;
-
- return Equals(other._fe, _fe);
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj))
- return false;
-
- if (ReferenceEquals(this, obj))
- return true;
-
- if (obj.GetType() != typeof(HintRootWpf))
- return false;
-
- return Equals((HintRootWpf)obj);
- }
-
- public override int GetHashCode()
- {
- return (_fe != null ? _fe.GetHashCode() : 0);
- }
-
- public static bool operator ==(HintRootWpf left, HintRootWpf right)
- {
- return Equals(left, right);
- }
-
- public static bool operator !=(HintRootWpf left, HintRootWpf right)
- {
- return !Equals(left, right);
- }
-
- #endregion
- }
-
- private class HintRootWin32 : HintRoot
- {
- private readonly HintSource source;
-
- public HintRootWin32(Rect rect, HintSource source)
- {
- this.source = source;
- ActiveRect = rect;
- source.MouseMove += OnMouse;
- source.MouseLeave += OnMouse;
- }
-
- private void OnMouse()
- {
- if (!IsMouseOver) RaiseEvent();
- }
-
- public override bool IsMouseOver
- {
- get
- {
- var pt = Win32.GetCursorPos();
- var rect = ActiveRect;
- if (pt.X < rect.Left) return false;
- if (pt.X > rect.Right - 1) return false;
- if (pt.Y < rect.Top) return false;
- if (pt.Y > rect.Bottom - 1) return false;
- return true;
- }
- }
-
- public override void Dispose()
- {
- source.MouseMove -= OnMouse;
- source.MouseLeave -= OnMouse;
- }
- }
- }
-}
+ internal abstract class HintRoot : IDisposable
+ {
+ public event Action MouseLeave;
+ public Rect ActiveRect { get; protected set; }
+
+ public abstract bool IsMouseOver { get; }
+ protected void RaiseEvent()
+ {
+ if (MouseLeave != null) MouseLeave();
+ }
+
+ #region IDisposable Members
+
+ public virtual void Dispose() { }
+
+ #endregion
+
+ public static HintRoot Create(FrameworkElement fe)
+ {
+ return new HintRootWpf(fe);
+ }
+
+ public static HintRoot Create(Rect rect, HintSource source)
+ {
+ return new HintRootWin32(rect, source);
+ }
+
+ private class HintRootWpf : HintRoot
+ {
+ private readonly FrameworkElement _fe;
+
+ public HintRootWpf(FrameworkElement fe)
+ {
+ _fe = fe;
+ var pt = fe.PointToScreen(new Point());
+ var pt2 = fe.PointToScreen(new Point(fe.ActualWidth, fe.ActualHeight));
+ ActiveRect = new Rect(pt.X, pt.Y, pt2.X - pt.X, pt2.Y - pt.Y);
+
+ fe.MouseLeave += OnMouse;
+ }
+
+ void OnMouse(object sender, MouseEventArgs e)
+ {
+ RaiseEvent();
+ }
+
+ public override bool IsMouseOver
+ {
+ get { return _fe.IsMouseOver; }
+ }
+
+ public override void Dispose()
+ {
+ _fe.MouseLeave -= OnMouse;
+ }
+
+ #region Equality
+
+ public bool Equals(HintRootWpf other)
+ {
+ if (ReferenceEquals(null, other))
+ return false;
+
+ if (ReferenceEquals(this, other))
+ return true;
+
+ return Equals(other._fe, _fe);
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(null, obj))
+ return false;
+
+ if (ReferenceEquals(this, obj))
+ return true;
+
+ if (obj.GetType() != typeof(HintRootWpf))
+ return false;
+
+ return Equals((HintRootWpf)obj);
+ }
+
+ public override int GetHashCode()
+ {
+ return (_fe != null ? _fe.GetHashCode() : 0);
+ }
+
+ public static bool operator ==(HintRootWpf left, HintRootWpf right)
+ {
+ return Equals(left, right);
+ }
+
+ public static bool operator !=(HintRootWpf left, HintRootWpf right)
+ {
+ return !Equals(left, right);
+ }
+
+ #endregion
+ }
+
+ private class HintRootWin32 : HintRoot
+ {
+ private readonly HintSource source;
+
+ public HintRootWin32(Rect rect, HintSource source)
+ {
+ this.source = source;
+ ActiveRect = rect;
+ source.MouseMove += OnMouse;
+ source.MouseLeave += OnMouse;
+ }
+
+ private void OnMouse()
+ {
+ if (!IsMouseOver) RaiseEvent();
+ }
+
+ public override bool IsMouseOver
+ {
+ get { return ActiveRect.Contains(Win32.GetCursorPos()); }
+ }
+
+ public override void Dispose()
+ {
+ source.MouseMove -= OnMouse;
+ source.MouseLeave -= OnMouse;
+ }
+ }
+ }
+}
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/HintSource.cs
Tue Nov 3 23:51:04 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/HintSource.cs
Wed Nov 4 01:21:20 2009
@@ -3,110 +3,114 @@
namespace WpfHint
{
- internal class HintSource : IDisposable
- {
- private Win32.Callback _ownerWndProc;
- private Win32.Callback _rootWndProc;
-
- private Win32.Callback _oldRoot;
- private Win32.Callback _oldOwner;
-
- private IntPtr _owner; // text editor window handle
- private IntPtr _root; // main window handle (visual studio)
-
- public event Action Activate;
- public event Action MouseMove;
- public event Action MouseLeave;
-
- public IntPtr Owner { get { return _owner; } }
-
- public void SubClass(IntPtr owner)
- {
- Debug.WriteLine("SubClass(): " + owner);
-
- var pt = Win32.GetCursorPos();
- var pt1 = new Win32.POINT(pt.X, pt.Y);
-
- _owner = owner == IntPtr.Zero ? Win32.WindowFromPoint(pt1) : owner;
-
- if (_owner == IntPtr.Zero)
- throw new NullReferenceException("Can't find owner");
-
- _root = Win32.GetAncestor(_owner, Win32.GA_ROOT);
- if (_root == IntPtr.Zero)
- throw new NullReferenceException("Can't find root");
-
- _ownerWndProc = WndProc;
- _oldOwner = Win32.SetWindowLong(_owner, Win32.GWL_WNDPROC,
_ownerWndProc);
-
- if (_oldOwner == null)
- throw new InvalidOperationException("Failed subclass");
-
- _rootWndProc = RootWndProc;
- _oldRoot = Win32.SetWindowLong(_root, Win32.GWL_WNDPROC,
_rootWndProc);
-
- if (_rootWndProc == null)
- throw new InvalidOperationException("Failed subclass");
- }
-
- public void UnSubClass()
- {
- Debug.WriteLine("UnSubClass(): " + _owner);
- if (_owner != IntPtr.Zero && _oldOwner != null)
- {
- _oldOwner = null;
- Win32.SetWindowLong(_owner, Win32.GWL_WNDPROC, _oldOwner);
- }
-
- if (_root != IntPtr.Zero && _oldRoot != null)
- {
- Win32.SetWindowLong(_root, Win32.GWL_WNDPROC, _oldRoot);
- _oldRoot = null;
- }
- }
-
- private int WndProc(IntPtr hwnd, int msg, int wParam, int lParam)
- {
+ internal class HintSource : IDisposable
+ {
+ private Win32.Callback _ownerWndProc;
+ private Win32.Callback _rootWndProc;
+
+ private Win32.Callback _oldRoot;
+ private Win32.Callback _oldOwner;
+
+ private IntPtr _owner; // text editor window handle
+ private IntPtr _root; // main window handle (visual studio)
+
+ public event Action Activate;
+ public event Action MouseMove;
+ public event Action MouseLeave;
+
+ public IntPtr Owner { get { return _owner; } }
+
+ public void SubClass(IntPtr owner)
+ {
+ Debug.WriteLine("SubClass(): " + owner);
+
+ var pt = Win32.GetCursorPos();
+ var pt1 = new Win32.POINT(pt.X, pt.Y);
+
+ _owner = owner == IntPtr.Zero ? Win32.WindowFromPoint(pt1) : owner;
+
+ if (_owner == IntPtr.Zero)
+ throw new NullReferenceException("Can't find owner");
+
+ _root = Win32.GetAncestor(_owner, Win32.GA_ROOT);
+ if (_root == IntPtr.Zero)
+ throw new NullReferenceException("Can't find root");
+
+ _ownerWndProc = WndProc;
+ _oldOwner = Win32.SetWindowLong(_owner, Win32.GWL_WNDPROC,
_ownerWndProc);
+
+ if (_oldOwner == null)
+ throw new InvalidOperationException("Failed subclass");
+
+ _rootWndProc = RootWndProc;
+ _oldRoot = Win32.SetWindowLong(_root, Win32.GWL_WNDPROC, _rootWndProc);
+
+ if (_rootWndProc == null)
+ throw new InvalidOperationException("Failed subclass");
+ }
+
+ public void UnSubClass()
+ {
+ Debug.WriteLine("UnSubClass(): " + _owner);
+ if (_owner != IntPtr.Zero && _oldOwner != null)
+ {
+ Win32.SetWindowLong(_owner, Win32.GWL_WNDPROC, _oldOwner);
+ _oldOwner = null;
+ }
+
+ if (_root != IntPtr.Zero && _oldRoot != null)
+ {
+ Win32.SetWindowLong(_root, Win32.GWL_WNDPROC, _oldRoot);
+ _oldRoot = null;
+ }
+ }
+
+ private int WndProc(IntPtr hwnd, int msg, int wParam, int lParam)
+ {
+ // We mast pracess window messages before our logic will be done.
+ // Otherwise UnSubClass() will be remove (hide) current messege.
int result = Win32.CallWindowProc(_oldOwner, hwnd, msg, wParam, lParam);
if ((msg == Win32.WM_KEYDOWN || msg == Win32.WM_MOUSEWHEEL) &&
Activate != null)
Activate();
- if ((msg == Win32.WM_LBUTTONDOWN || msg == Win32.WM_RBUTTONDOWN) &&
Activate != null)
- Activate();
-
- if (msg == Win32.WM_MOUSEMOVE && MouseMove != null)
- MouseMove();
-
- if (msg == Win32.WM_MOUSELEAVE && MouseLeave != null)
- MouseLeave();
+ if ((msg == Win32.WM_LBUTTONDOWN || msg == Win32.WM_RBUTTONDOWN) &&
Activate != null)
+ Activate();
+
+ if (msg == Win32.WM_MOUSEMOVE && MouseMove != null)
+ MouseMove();
+
+ if (msg == Win32.WM_MOUSELEAVE && MouseLeave != null)
+ MouseLeave();
return result;
- }
-
- private int RootWndProc(IntPtr hwnd, int msg, int wParam, int lParam)
- {
+ }
+
+ private int RootWndProc(IntPtr hwnd, int msg, int wParam, int lParam)
+ {
+ // We mast pracess window messages before our logic will be done.
+ // Otherwise UnSubClass() will be remove (hide) current messege.
int result = Win32.CallWindowProc(_oldRoot, hwnd, msg, wParam, lParam);
- if ((msg == Win32.WM_ACTIVATE || msg == Win32.WM_ACTIVATEAPP) &&
Activate != null)
- Activate();
+ if ((msg == Win32.WM_ACTIVATE || msg == Win32.WM_ACTIVATEAPP) &&
Activate != null)
+ Activate();
return result;
- }
-
- #region Implementation of IDisposable
+ }
+
+ #region Implementation of IDisposable
- ~HintSource()
- {
- Dispose();
- }
-
- public void Dispose()
- {
- UnSubClass();
- }
-
- #endregion
- }
-}
+ ~HintSource()
+ {
+ Dispose();
+ }
+
+ public void Dispose()
+ {
+ UnSubClass();
+ }
+
+ #endregion
+ }
+}
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/HintWindow.xaml.cs
Tue Nov 3 14:16:52 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/HintWindow.xaml.cs
Wed Nov 4 01:21:20 2009
@@ -17,191 +17,205 @@
namespace WpfHint
{
- /// <summary>
- /// Interaction logic for HintWindow.xaml
- /// </summary>
- internal partial class HintWindow
- {
- private readonly Hint hint;
- private readonly HintRoot hintRoot;
- private readonly DispatcherTimer timer =
- new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(100) };
-
- private string text;
- public string Text
- {
- get { return text; }
- set
- {
- text = value;
-
- try
- {
- var root = HintParser.Parse(value);
- var fe = HintBuilder.Build(root, hint);
- border.Child = fe;
- }
- catch (Exception ex)
- {
- Trace.WriteLine(ex);
- }
- }
- }
-
- public double WrapWidth
- {
- get { return ((HintDecorator)border.Child).WrapWidth; }
- set { ((HintDecorator)border.Child).WrapWidth = value; }
- }
-
- public HintWindow(Hint hint, HintRoot root)
- {
- InitializeComponent();
-
- this.hint = hint;
- hintRoot = root;
-
- // window props
- Left = 0;
- Top = 0;
- MaxHeight = 800;
- SizeToContent = SizeToContent.WidthAndHeight;
- Opacity = 1;
-
- timer.Tick += OnTimerTick;
- LayoutUpdated += OnLayoutUpdated;
- MouseLeave += OnMouseLeave;
- hintRoot.MouseLeave += TestMouseOver;
- MouseRightButtonUp += MouseButtonEventHandler;
-
- HintControl.AddClickHandler(this, OnClick);
- HintControl.AddMouseHoverHandler(this, OnMouseHover);
- }
-
- protected override void OnClosed(EventArgs e)
- {
- hintRoot.MouseLeave -= TestMouseOver;
- MouseLeave -= OnMouseLeave;
-
- timer.Stop();
- hintRoot.Dispose();
- base.OnClosed(e);
- }
-
- #region HintControl event handling
-
- private void MouseButtonEventHandler(object sender,
MouseButtonEventArgs e)
- {
- if (e.ChangedButton == MouseButton.Right && e.ButtonState ==
MouseButtonState.Released)
- Close();
- }
-
- private void OnClick(object sender, RoutedEventArgs e)
- {
- var hc = e.Source as HintControl;
-
+ /// <summary>
+ /// Interaction logic for HintWindow.xaml
+ /// </summary>
+ internal partial class HintWindow
+ {
+ private readonly Hint _hint;
+ private readonly HintRoot _hintRoot;
+ private readonly DispatcherTimer _timer = new DispatcherTimer
+ { Interval =
TimeSpan.FromMilliseconds(1000) };
+ private string _text;
+
+ public string Text
+ {
+ get { return _text; }
+ set
+ {
+ _text = value;
+
+ try
+ {
+ var root = HintParser.Parse(value);
+ var fe = HintBuilder.Build(root, _hint);
+ border.Child = fe;
+ }
+ catch (Exception ex)
+ {
+ Trace.WriteLine(ex);
+ }
+ }
+ }
+
+ public double WrapWidth
+ {
+ get { return ((HintDecorator)border.Child).WrapWidth; }
+ set { ((HintDecorator)border.Child).WrapWidth = value; }
+ }
+
+ public HintWindow(Hint hint, HintRoot root)
+ {
+ InitializeComponent();
+
+ this._hint = hint;
+ _hintRoot = root;
+
+ // window props
+ Left = 0;
+ Top = 0;
+ MaxHeight = 800;
+ SizeToContent = SizeToContent.WidthAndHeight;
+ Opacity = 1;
+
+ _timer.Tick += OnTimerTick;
+ LayoutUpdated += OnLayoutUpdated;
+ MouseLeave += OnMouseLeave;
+ _hintRoot.MouseLeave += RestartCloseTimer;
+ MouseRightButtonUp += MouseButtonEventHandler;
+
+ HintControl.AddClickHandler(this, OnClick);
+ HintControl.AddMouseHoverHandler(this, OnMouseHover);
+ }
+
+ protected override void OnInitialized(EventArgs e)
+ {
+ base.OnInitialized(e);
+ RestartCloseTimer();
+ }
+
+ protected override void OnClosed(EventArgs e)
+ {
+ _hintRoot.MouseLeave -= RestartCloseTimer;
+ MouseLeave -= OnMouseLeave;
+
+ _timer.Stop();
+ _hintRoot.Dispose();
+ base.OnClosed(e);
+ }
+
+ #region HintControl event handling
+
+ private void MouseButtonEventHandler(object sender, MouseButtonEventArgs
e)
+ {
+ if (e.ChangedButton == MouseButton.Right && e.ButtonState ==
MouseButtonState.Released)
+ Close();
+ }
+
+ private void OnClick(object sender, RoutedEventArgs e)
+ {
+ var hc = e.Source as HintControl;
+
if (hc == null)
return;
- if (hc.Handler != null)
- hint.RaiseClick(hc.Handler);
- }
-
- private void OnMouseHover(object sender, RoutedEventArgs e)
- {
- var hc = e.Source as HintControl;
- if (hc == null)
+ if (hc.Handler != null)
+ _hint.RaiseClick(hc.Handler);
+ }
+
+ private void OnMouseHover(object sender, RoutedEventArgs e)
+ {
+ var hc = e.Source as HintControl;
+ if (hc == null)
return;
- if (hc.Hint != null)
+ if (hc.Hint != null)
ShowSubHint(hc, hc.Hint);
- }
-
- private void ShowSubHint(FrameworkElement el, string hintText)
- {
- var ht = HintRoot.Create(el);
-
- foreach (HintWindow window in OwnedWindows)
- {
- if (!window.hintRoot.Equals(ht))
+ }
+
+ private void ShowSubHint(FrameworkElement el, string hintText)
+ {
+ var ht = HintRoot.Create(el);
+
+ foreach (HintWindow window in OwnedWindows)
+ {
+ if (!window._hintRoot.Equals(ht))
+ {
+ window.Close();
continue;
-
- ht.Dispose();
- return;
- }
-
- var wnd = new HintWindow(hint, ht) { Text = hintText, Owner = this };
- wnd.Show();
- }
-
- #endregion
-
- #region Mouse leave checking
-
- void OnMouseLeave(object sender, MouseEventArgs e)
- {
- TestMouseOver();
- }
-
- void TestMouseOver()
- {
- // restart timer
- timer.Stop();
- timer.Start();
- }
-
- void OnTimerTick(object sender, EventArgs e)
- {
- timer.Stop();
-
- if (OwnedWindows.Count > 0) return;
- if (IsMouseOver) return;
- if (hintRoot.IsMouseOver) return;
-
- this.Close();
- var owner = Owner as HintWindow;
- if (owner != null) owner.TestMouseOver();
- }
-
- #endregion
-
- #region Window layout relative to screen
-
- void OnLayoutUpdated(object sender, EventArgs e)
- {
- var dx = 1.0;
- var dy = 1.0;
-
- var src = PresentationSource.FromVisual(this);
- if (src != null)
- {
- var m = src.CompositionTarget.TransformToDevice;
- dx = m.M11;
- dy = m.M22;
- }
-
- var rect = hintRoot.ActiveRect;
-
- var size = new Size(ActualWidth * dx, ActualHeight * dy);
- var scrSize = new Size(SystemParameters.VirtualScreenWidth * dx,
- SystemParameters.VirtualScreenHeight * dy);
-
- var pos = rect.BottomLeft;
-
- if (rect.Bottom + size.Height > scrSize.Height)
- pos.Y = rect.Top - size.Height;
-
- if (rect.Left + size.Width > scrSize.Width)
- pos.X = scrSize.Width - size.Width;
-
- if (pos.Y < 0) pos.Y = 0;
- if (pos.X < 0) pos.X = 0;
-
- // update location
- this.Left = pos.X / dx;
- this.Top = pos.Y / dy;
- }
-
- #endregion
- }
-}
+ }
+
+ ht.Dispose();
+ return;
+ }
+
+ var wnd = new HintWindow(_hint, ht) { Text = hintText, Owner = this };
+ wnd.Show();
+ }
+
+ #endregion
+
+ #region Mouse leave checking
+
+ void OnMouseLeave(object sender, MouseEventArgs e)
+ {
+ RestartCloseTimer();
+ }
+
+ public void RestartCloseTimer()
+ {
+ // restart timer
+ _timer.Stop();
+ _timer.Start();
+ }
+
+ void OnTimerTick(object sender, EventArgs e)
+ {
+ _timer.Stop();
+
+ if (OwnedWindows.Count > 0 || IsMouseOver || _hintRoot.IsMouseOver)
+ {
+ _timer.Start();
+ return;
+ }
+
+ this.Close();
+
+ var owner = Owner as HintWindow;
+
+ if (owner != null)
+ owner.OnTimerTick(sender, e);
+ }
+
+ #endregion
+
+ #region Window layout relative to screen
+
+ void OnLayoutUpdated(object sender, EventArgs e)
+ {
+ var dx = 1.0;
+ var dy = 1.0;
+
+ var src = PresentationSource.FromVisual(this);
+ if (src != null)
+ {
+ var m = src.CompositionTarget.TransformToDevice;
+ dx = m.M11;
+ dy = m.M22;
+ }
+
+ var rect = _hintRoot.ActiveRect;
+
+ var size = new Size(ActualWidth * dx, ActualHeight * dy);
+ var scrSize = new Size(SystemParameters.VirtualScreenWidth * dx,
+ SystemParameters.VirtualScreenHeight * dy);
+
+ var pos = rect.BottomLeft;
+
+ if (rect.Bottom + size.Height > scrSize.Height)
+ pos.Y = rect.Top - size.Height;
+
+ if (rect.Left + size.Width > scrSize.Width)
+ pos.X = scrSize.Width - size.Width;
+
+ if (pos.Y < 0) pos.Y = 0;
+ if (pos.X < 0) pos.X = 0;
+
+ // update location
+ this.Left = pos.X / dx;
+ this.Top = pos.Y / dy;
+ }
+
+ #endregion
+ }
+}
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/PopupWindow.cs
Fri Oct 30 10:58:03 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/PopupWindow.cs
Wed Nov 4 01:21:20 2009
@@ -5,46 +5,46 @@
namespace WpfHint
{
- internal class PopupWindow : Window
- {
- public PopupWindow()
- {
- AllowsTransparency = true;
- WindowStyle = WindowStyle.None;
- Background = Brushes.Transparent;
- FontSize = 12.0d * (96d / 72d);
-
- Topmost = true;
- ShowActivated = false;
- ShowInTaskbar = false;
-
- Loaded += InvisibleWindow_Loaded;
- }
-
- void InvisibleWindow_Loaded(object sender, RoutedEventArgs e)
- {
- var source = HwndSource.FromHwnd(
- new WindowInteropHelper(this).Handle);
- if (source != null) source.AddHook(WndProc);
- }
-
- // Prevent activation of window
- private static IntPtr WndProc(IntPtr hwnd, int msg,
- IntPtr wParam, IntPtr lParam, ref bool
handled)
- {
- // ReSharper disable InconsistentNaming
- const int WM_MOUSEACTIVATE = 0x0021;
- const int MA_NOACTIVATE = 3;
- //const int MA_NOACTIVATEANDEAT = 4;
- // ReSharper restore InconsistentNaming
-
- if (msg == WM_MOUSEACTIVATE)
- {
- handled = true;
- return new IntPtr(MA_NOACTIVATE);
- }
-
- return IntPtr.Zero;
- }
- }
-}
+ internal class PopupWindow : Window
+ {
+ public PopupWindow()
+ {
+ AllowsTransparency = true;
+ WindowStyle = WindowStyle.None;
+ Background = Brushes.Transparent;
+ FontSize = 12.0d * (96d / 72d);
+
+ Topmost = true;
+ ShowActivated = false;
+ ShowInTaskbar = false;
+
+ Loaded += InvisibleWindow_Loaded;
+ }
+
+ void InvisibleWindow_Loaded(object sender, RoutedEventArgs e)
+ {
+ var source = HwndSource.FromHwnd(
+ new WindowInteropHelper(this).Handle);
+ if (source != null) source.AddHook(WndProc);
+ }
+
+ // Prevent activation of window
+ private static IntPtr WndProc(IntPtr hwnd, int msg,
+ IntPtr wParam, IntPtr lParam, ref bool handled)
+ {
+ // ReSharper disable InconsistentNaming
+ const int WM_MOUSEACTIVATE = 0x0021;
+ const int MA_NOACTIVATE = 3;
+ //const int MA_NOACTIVATEANDEAT = 4;
+ // ReSharper restore InconsistentNaming
+
+ if (msg == WM_MOUSEACTIVATE)
+ {
+ handled = true;
+ return new IntPtr(MA_NOACTIVATE);
+ }
+
+ return IntPtr.Zero;
+ }
+ }
+}
=======================================
--- /nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/Win32.cs
Fri Oct 30 10:58:03 2009
+++ /nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/Win32.cs
Wed Nov 4 01:21:20 2009
@@ -4,66 +4,66 @@
namespace WpfHint
{
-// ReSharper disable InconsistentNaming
- public static class Win32
- {
- public delegate int Callback(IntPtr wHwnd, int msg, int wParam,
int lParam);
-
- [StructLayout(LayoutKind.Sequential)]
- public struct POINT
- {
- public POINT(double x, double y)
- {
- X = (int) x;
- Y = (int) y;
- }
- public int X;
- public int Y;
- }
-
- public const int GA_PARENT = 1;
- public const int GA_ROOT = 2;
- public const int GA_ROOTOWNER = 3;
-
- public const int WM_ACTIVATE = 0x0006;
- public const int WM_ACTIVATEAPP = 0x001C;
-
- public const int WM_KEYDOWN = 0x0100;
- public const int WM_MOUSEWHEEL = 0x020A;
- public const int WM_RBUTTONDOWN = 0x204;
- public const int WM_LBUTTONDOWN = 0x201;
- public const int WM_LBUTTONUP = 0x202;
- public const int WM_MOUSEMOVE = 0x0200;
- public const int WM_MOUSELEAVE = 0x02A3;
- public const int WM_MOUSEHOVER = 0x02A1;
- public const int GWL_WNDPROC = -4;
-
- [DllImport("user32.dll")]
- public static extern bool ClientToScreen(IntPtr hWnd, POINT[]
lpPoint);
- [DllImport("user32.dll")]
- public static extern bool ClientToScreen(IntPtr hWnd, ref POINT
lpPoint);
-
- [DllImport("user32.dll", CallingConvention =
CallingConvention.StdCall, EntryPoint = "SetWindowLong", CharSet =
CharSet.Auto)]
- public static extern Callback SetWindowLong(IntPtr hwnd, int
nIndex, Callback dwNewLong);
-
- [DllImport("user32.dll", CallingConvention =
CallingConvention.StdCall, EntryPoint = "CallWindowProc", CharSet =
CharSet.Auto)]
- public static extern int CallWindowProc(Callback lpPrevWndFunc,
IntPtr hwnd, int msg, int wParam, int lParam);
-
- [DllImport("user32.dll")]
- public static extern IntPtr WindowFromPoint(POINT Point);
-
- [DllImport("user32.dll")]
- [return: MarshalAs(UnmanagedType.Bool)]
- private static extern bool GetCursorPos(out POINT lpPoint);
-
- [DllImport("user32.dll", ExactSpelling = true)]
- public static extern IntPtr GetAncestor(IntPtr hwnd, uint gaFlags);
-
- public static Point GetCursorPos()
- {
- POINT pt;
- GetCursorPos(out pt);
- return new Point(pt.X, pt.Y);
- }
- }
-}
+ // ReSharper disable InconsistentNaming
+ public static class Win32
+ {
+ public delegate int Callback(IntPtr wHwnd, int msg, int wParam, int
lParam);
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct POINT
+ {
+ public POINT(double x, double y)
+ {
+ X = (int)x;
+ Y = (int)y;
+ }
+ public int X;
+ public int Y;
+ }
+
+ public const int GA_PARENT = 1;
+ public const int GA_ROOT = 2;
+ public const int GA_ROOTOWNER = 3;
+
+ public const int WM_ACTIVATE = 0x0006;
+ public const int WM_ACTIVATEAPP = 0x001C;
+
+ public const int WM_KEYDOWN = 0x0100;
+ public const int WM_MOUSEWHEEL = 0x020A;
+ public const int WM_RBUTTONDOWN = 0x204;
+ public const int WM_LBUTTONDOWN = 0x201;
+ public const int WM_LBUTTONUP = 0x202;
+ public const int WM_MOUSEMOVE = 0x0200;
+ public const int WM_MOUSELEAVE = 0x02A3;
+ public const int WM_MOUSEHOVER = 0x02A1;
+ public const int GWL_WNDPROC = -4;
+
+ [DllImport("user32.dll")]
+ public static extern bool ClientToScreen(IntPtr hWnd, POINT[] lpPoint);
+ [DllImport("user32.dll")]
+ public static extern bool ClientToScreen(IntPtr hWnd, ref POINT lpPoint);
+
+ [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall,
EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
+ public static extern Callback SetWindowLong(IntPtr hwnd, int nIndex,
Callback dwNewLong);
+
+ [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall,
EntryPoint = "CallWindowProc", CharSet = CharSet.Auto)]
+ public static extern int CallWindowProc(Callback lpPrevWndFunc, IntPtr
hwnd, int msg, int wParam, int lParam);
+
+ [DllImport("user32.dll")]
+ public static extern IntPtr WindowFromPoint(POINT Point);
+
+ [DllImport("user32.dll")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static extern bool GetCursorPos(out POINT lpPoint);
+
+ [DllImport("user32.dll", ExactSpelling = true)]
+ public static extern IntPtr GetAncestor(IntPtr hwnd, uint gaFlags);
+
+ public static Point GetCursorPos()
+ {
+ POINT pt;
+ GetCursorPos(out pt);
+ return new Point(pt.X, pt.Y);
+ }
+ }
+}
=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/WpfHint.csproj
Mon Nov 2 09:09:59 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/WpfHint.csproj
Wed Nov 4 01:21:20 2009
@@ -78,6 +78,7 @@
<Compile Include="UIBuilding\ParamPanel.cs" />
<Compile Include="PopupWindow.cs" />
<Compile Include="UIBuilding\SoftBreak.cs" />
+ <Compile Include="Utils.cs" />
<Compile Include="Win32.cs" />
</ItemGroup>
<ItemGroup>