tweak HyperlinkCell mouse-capture/mouse-over-click-area logic
This commit is contained in:
1 parent
5e5db254de
commit
c8be6fb6ca
1 file changed
+35
-8
@@ -1,14 +1,17 @@
|
||||
using mbts.ui.dpi;
|
||||
using mbts.spark;
|
||||
using mbts.ui.dpi;
|
||||
using mbts.ui.utilities;
|
||||
using mbts.ui.utility.text;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using FontFamily = System.Windows.Media.FontFamily;
|
||||
|
||||
namespace mbts.ui.controls {
|
||||
@@ -26,7 +29,7 @@ namespace mbts.ui.controls {
|
||||
GlyphRun _glyph_run => _gcr.glyph_run;
|
||||
bool
|
||||
_is_mouse_over_text,
|
||||
_is_mouse_over_click_area,
|
||||
_is_mouse_over_click_area_backing,
|
||||
_can_execute,
|
||||
_snaps_to_device_pixels;
|
||||
Pen _underline_pen_backing, _border_stroke_pen_backing;
|
||||
@@ -34,7 +37,25 @@ namespace mbts.ui.controls {
|
||||
// add 2 pixels to account for underline (1 for space, 1 for the line itself)
|
||||
content_height_offset = HighDpiExtensions.pixel_unit * 2
|
||||
};
|
||||
IDisposable _mouse_over_click_area_op;
|
||||
|
||||
bool _is_mouse_over_click_area {
|
||||
get => _is_mouse_over_click_area_backing;
|
||||
set {
|
||||
if (_is_mouse_over_click_area_backing != value) {
|
||||
Disposable.dispose(ref _mouse_over_click_area_op);
|
||||
_is_mouse_over_click_area_backing = value;
|
||||
if (value) {
|
||||
_mouse_over_click_area_op = WorkLoop.Start(
|
||||
$"Evaluate {nameof(HyperlinkCell)} {nameof(IsMouseOverClickArea)}",
|
||||
TimeSpan.FromMilliseconds(100),
|
||||
DispatcherPriority.Input,
|
||||
_on_mouse_changed,
|
||||
WorkLoop.default_excessive_cycle_ratio);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Brush _foreground {
|
||||
get => _foreground_backing;
|
||||
set {
|
||||
@@ -382,6 +403,8 @@ namespace mbts.ui.controls {
|
||||
if (e.ButtonState == MouseButtonState.Pressed) {
|
||||
// Capture the mouse, and make sure we got it.
|
||||
CaptureMouse();
|
||||
} else {
|
||||
ReleaseMouseCapture();
|
||||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
@@ -390,18 +413,22 @@ namespace mbts.ui.controls {
|
||||
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) {
|
||||
base.OnMouseLeftButtonUp(e);
|
||||
_on_mouse_changed(e);
|
||||
if (IsMouseCaptured)
|
||||
if (IsMouseCaptured) {
|
||||
ReleaseMouseCapture();
|
||||
if (_can_execute && _is_mouse_over_click_area)
|
||||
CommandHelper.ExecuteCommandSource(this);
|
||||
_on_mouse_changed(e);
|
||||
e.Handled = true;
|
||||
if (_can_execute)
|
||||
CommandHelper.ExecuteCommandSource(this);
|
||||
_on_mouse_changed(e);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected override void OnIsMouseDirectlyOverChanged(DependencyPropertyChangedEventArgs e) => _on_mouse_changed();
|
||||
protected override void OnPreviewMouseMove(MouseEventArgs e) => _on_mouse_changed(e);
|
||||
protected override void OnPreviewMouseMove(MouseEventArgs e) {
|
||||
_on_mouse_changed(e);
|
||||
e.Handled = IsMouseCaptured;
|
||||
}
|
||||
protected override void OnMouseEnter(MouseEventArgs e) => _on_mouse_changed(e);
|
||||
protected override void OnMouseLeave(MouseEventArgs e) => _on_mouse_changed(e);
|
||||
|
||||
|
||||
Reference in new issue
Block a user