@@ -19,122 +19,16 @@ public static partial class Application // Mouse handling
19
19
[ ConfigurationProperty ( Scope = typeof ( SettingsScope ) ) ]
20
20
public static bool IsMouseDisabled { get ; set ; }
21
21
22
- /// <summary>Gets <see cref="View"/> that has registered to get continuous mouse button pressed events.</summary>
23
- public static View ? WantContinuousButtonPressedView { get ; internal set ; }
24
-
25
- /// <summary>
26
- /// Gets the view that grabbed the mouse (e.g. for dragging). When this is set, all mouse events will be routed to
27
- /// this view until the view calls <see cref="UngrabMouse"/> or the mouse is released.
28
- /// </summary>
29
- public static View ? MouseGrabView { get ; private set ; }
30
-
31
- /// <summary>Invoked when a view wants to grab the mouse; can be canceled.</summary>
32
- public static event EventHandler < GrabMouseEventArgs > ? GrabbingMouse ;
33
-
34
- /// <summary>Invoked when a view wants un-grab the mouse; can be canceled.</summary>
35
- public static event EventHandler < GrabMouseEventArgs > ? UnGrabbingMouse ;
36
-
37
- /// <summary>Invoked after a view has grabbed the mouse.</summary>
38
- public static event EventHandler < ViewEventArgs > ? GrabbedMouse ;
39
-
40
- /// <summary>Invoked after a view has un-grabbed the mouse.</summary>
41
- public static event EventHandler < ViewEventArgs > ? UnGrabbedMouse ;
42
-
43
22
/// <summary>
44
- /// Grabs the mouse, forcing all mouse events to be routed to the specified view until <see cref="UngrabMouse"/>
45
- /// is called.
23
+ /// Static reference to the current <see cref="IApplication"/> <see cref="IMouseGrabHandler"/>.
46
24
/// </summary>
47
- /// <param name="view">View that will receive all mouse events until <see cref="UngrabMouse"/> is invoked.</param>
48
- public static void GrabMouse ( View ? view )
25
+ public static IMouseGrabHandler MouseGrabHandler
49
26
{
50
- if ( view is null || RaiseGrabbingMouseEvent ( view ) )
51
- {
52
- return ;
53
- }
54
-
55
- RaiseGrabbedMouseEvent ( view ) ;
56
-
57
- if ( Initialized )
58
- {
59
- // MouseGrabView is a static; only set if the application is initialized.
60
- MouseGrabView = view ;
61
- }
27
+ get => ApplicationImpl . Instance . MouseGrabHandler ;
28
+ set => ApplicationImpl . Instance . MouseGrabHandler = value ??
29
+ throw new ArgumentNullException ( nameof ( value ) ) ;
62
30
}
63
31
64
- /// <summary>Releases the mouse grab, so mouse events will be routed to the view on which the mouse is.</summary>
65
- public static void UngrabMouse ( )
66
- {
67
- if ( MouseGrabView is null )
68
- {
69
- return ;
70
- }
71
-
72
- #if DEBUG_IDISPOSABLE
73
- if ( View . EnableDebugIDisposableAsserts )
74
- {
75
- ObjectDisposedException . ThrowIf ( MouseGrabView . WasDisposed , MouseGrabView ) ;
76
- }
77
- #endif
78
-
79
- if ( ! RaiseUnGrabbingMouseEvent ( MouseGrabView ) )
80
- {
81
- View view = MouseGrabView ;
82
- MouseGrabView = null ;
83
- RaiseUnGrabbedMouseEvent ( view ) ;
84
- }
85
- }
86
-
87
- /// <exception cref="Exception">A delegate callback throws an exception.</exception>
88
- private static bool RaiseGrabbingMouseEvent ( View ? view )
89
- {
90
- if ( view is null )
91
- {
92
- return false ;
93
- }
94
-
95
- var evArgs = new GrabMouseEventArgs ( view ) ;
96
- GrabbingMouse ? . Invoke ( view , evArgs ) ;
97
-
98
- return evArgs . Cancel ;
99
- }
100
-
101
- /// <exception cref="Exception">A delegate callback throws an exception.</exception>
102
- private static bool RaiseUnGrabbingMouseEvent ( View ? view )
103
- {
104
- if ( view is null )
105
- {
106
- return false ;
107
- }
108
-
109
- var evArgs = new GrabMouseEventArgs ( view ) ;
110
- UnGrabbingMouse ? . Invoke ( view , evArgs ) ;
111
-
112
- return evArgs . Cancel ;
113
- }
114
-
115
- /// <exception cref="Exception">A delegate callback throws an exception.</exception>
116
- private static void RaiseGrabbedMouseEvent ( View ? view )
117
- {
118
- if ( view is null )
119
- {
120
- return ;
121
- }
122
-
123
- GrabbedMouse ? . Invoke ( view , new ( view ) ) ;
124
- }
125
-
126
- /// <exception cref="Exception">A delegate callback throws an exception.</exception>
127
- private static void RaiseUnGrabbedMouseEvent ( View ? view )
128
- {
129
- if ( view is null )
130
- {
131
- return ;
132
- }
133
-
134
- UnGrabbedMouse ? . Invoke ( view , new ( view ) ) ;
135
- }
136
-
137
-
138
32
/// <summary>
139
33
/// INTERNAL API: Called when a mouse event is raised by the driver. Determines the view under the mouse and
140
34
/// calls the appropriate View mouse event handlers.
@@ -199,15 +93,6 @@ internal static void RaiseMouseEvent (MouseEventArgs mouseEvent)
199
93
return ;
200
94
}
201
95
202
- if ( Initialized )
203
- {
204
- WantContinuousButtonPressedView = deepestViewUnderMouse switch
205
- {
206
- { WantContinuousButtonPressed : true } => deepestViewUnderMouse ,
207
- _ => null
208
- } ;
209
- }
210
-
211
96
// May be null before the prior condition or the condition may set it as null.
212
97
// So, the checking must be outside the prior condition.
213
98
if ( deepestViewUnderMouse is null )
@@ -259,12 +144,7 @@ internal static void RaiseMouseEvent (MouseEventArgs mouseEvent)
259
144
260
145
RaiseMouseEnterLeaveEvents ( viewMouseEvent . ScreenPosition , currentViewsUnderMouse ) ;
261
146
262
- if ( Initialized )
263
- {
264
- WantContinuousButtonPressedView = deepestViewUnderMouse . WantContinuousButtonPressed ? deepestViewUnderMouse : null ;
265
- }
266
-
267
- while ( deepestViewUnderMouse . NewMouseEvent ( viewMouseEvent ) is not true && MouseGrabView is not { } )
147
+ while ( deepestViewUnderMouse . NewMouseEvent ( viewMouseEvent ) is not true && MouseGrabHandler . MouseGrabView is not { } )
268
148
{
269
149
if ( deepestViewUnderMouse is Adornment adornmentView )
270
150
{
@@ -316,42 +196,39 @@ internal static void RaiseMouseEvent (MouseEventArgs mouseEvent)
316
196
317
197
internal static bool HandleMouseGrab ( View ? deepestViewUnderMouse , MouseEventArgs mouseEvent )
318
198
{
319
- if ( MouseGrabView is null )
199
+ if ( MouseGrabHandler . MouseGrabView is { } )
320
200
{
321
- return false ;
322
- }
323
-
324
201
#if DEBUG_IDISPOSABLE
325
- if ( View . EnableDebugIDisposableAsserts && MouseGrabView . WasDisposed )
326
- {
327
- throw new ObjectDisposedException ( MouseGrabView . GetType ( ) . FullName ) ;
328
- }
202
+ if ( View . EnableDebugIDisposableAsserts && MouseGrabHandler . MouseGrabView . WasDisposed )
203
+ {
204
+ throw new ObjectDisposedException ( MouseGrabHandler . MouseGrabView . GetType ( ) . FullName ) ;
205
+ }
329
206
#endif
330
207
331
- // If the mouse is grabbed, send the event to the view that grabbed it.
332
- // The coordinates are relative to the Bounds of the view that grabbed the mouse.
333
- Point frameLoc = MouseGrabView . ScreenToViewport ( mouseEvent . ScreenPosition ) ;
208
+ // If the mouse is grabbed, send the event to the view that grabbed it.
209
+ // The coordinates are relative to the Bounds of the view that grabbed the mouse.
210
+ Point frameLoc = MouseGrabHandler . MouseGrabView . ScreenToViewport ( mouseEvent . ScreenPosition ) ;
334
211
335
- var viewRelativeMouseEvent = new MouseEventArgs
336
- {
337
- Position = frameLoc ,
338
- Flags = mouseEvent . Flags ,
339
- ScreenPosition = mouseEvent . ScreenPosition ,
340
- View = deepestViewUnderMouse ?? MouseGrabView
341
- } ;
342
-
343
- //Logging.Debug ($"{deepestViewUnderMouse!.Id};{viewRelativeMouseEvent.Flags};{viewRelativeMouseEvent.Position};{MouseGrabView.Id}");
344
- if ( MouseGrabView ? . NewMouseEvent ( viewRelativeMouseEvent ) is true || viewRelativeMouseEvent . IsSingleDoubleOrTripleClicked )
345
- {
346
- // If the view that grabbed the mouse handled the event OR it was a click we are done.
347
- return true ;
348
- }
212
+ var viewRelativeMouseEvent = new MouseEventArgs
213
+ {
214
+ Position = frameLoc ,
215
+ Flags = mouseEvent . Flags ,
216
+ ScreenPosition = mouseEvent . ScreenPosition ,
217
+ View = deepestViewUnderMouse ?? MouseGrabHandler . MouseGrabView
218
+ } ;
349
219
350
- // ReSharper disable once ConditionIsAlwaysTrueOrFalse
351
- if ( MouseGrabView is null && deepestViewUnderMouse is Adornment )
352
- {
353
- // The view that grabbed the mouse has been disposed
354
- return true ;
220
+ //System.Diagnostics.Debug.WriteLine ($"{nme.Flags};{nme.X};{nme.Y};{mouseGrabView}");
221
+ if ( MouseGrabHandler . MouseGrabView ? . NewMouseEvent ( viewRelativeMouseEvent ) is true || viewRelativeMouseEvent . IsSingleDoubleOrTripleClicked )
222
+ {
223
+ return true ;
224
+ }
225
+
226
+ // ReSharper disable once ConditionIsAlwaysTrueOrFalse
227
+ if ( MouseGrabHandler . MouseGrabView is null && deepestViewUnderMouse is Adornment )
228
+ {
229
+ // The view that grabbed the mouse has been disposed
230
+ return true ;
231
+ }
355
232
}
356
233
357
234
return false ;
0 commit comments