[nemerle] r8416 committed - Add closing of WpfHint when the right mouse button is pressed.

1 view
Skip to first unread message

codesite...@google.com

unread,
Oct 30, 2009, 3:04:08 PM10/30/09
to nemer...@googlegroups.com
Revision: 8416
Author: v...@rsdn.ru
Date: Fri Oct 30 12:03:58 2009
Log: Add closing of WpfHint when the right mouse button is pressed.
http://code.google.com/p/nemerle/source/detail?r=8416

Modified:
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WinFormTestHint
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint

/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/HintWindow.xaml.cs

=======================================
---
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/HintWindow.xaml.cs
Fri Oct 30 10:58:03 2009
+++
/nemerle/trunk/VsIntegration/Nemerle.VisualStudio/GUI/WpfHint/HintWindow.xaml.cs
Fri Oct 30 12:03:58 2009
@@ -16,165 +16,172 @@

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;
- var root = HintParser.Parse(value);
- var fe = HintBuilder.Build(root);
- border.Child = fe;
- }
- }
-
- 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;
- SizeToContent = SizeToContent.WidthAndHeight;
- Opacity = 0.9;
-
- timer.Tick += OnTimerTick;
- LayoutUpdated += OnLayoutUpdated;
- MouseLeave += OnMouseLeave;
- hintRoot.MouseLeave += TestMouseOver;
-
- 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 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) return;
- 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)) 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.PrimaryScreenWidth*dx,
-
SystemParameters.PrimaryScreenHeight*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;
- }
-
- // update location
- this.Left = pos.X/dx;
- this.Top = pos.Y/dy;
- }
-
- #endregion
- }
-}
+ /// <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;
+ var root = HintParser.Parse(value);
+ var fe = HintBuilder.Build(root);
+ border.Child = fe;
+ }
+ }
+
+ 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;
+ SizeToContent = SizeToContent.WidthAndHeight;
+ Opacity = 0.9;
+
+ 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;
+ 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) return;
+ 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)) 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.PrimaryScreenWidth * dx,
+ SystemParameters.PrimaryScreenHeight * 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;
+ }
+
+ // update location
+ this.Left = pos.X / dx;
+ this.Top = pos.Y / dy;
+ }
+
+ #endregion
+ }
+}

Reply all
Reply to author
Forward
0 new messages