@@ -213,7 +213,7 @@ protected virtual void OnMouseLeave () { }
213
213
/// </para>
214
214
/// <para>
215
215
/// This method raises <see cref="RaiseMouseEvent"/>/<see cref="MouseEvent"/>; if not handled, and one of the
216
- /// mouse buttons was clicked, the <see cref="OnMouseClick "/>/<see cref="MouseClick"/> event will be raised
216
+ /// mouse buttons was clicked, the <see cref="RaiseMouseClickEvent "/>/<see cref="MouseClick"/> event will be raised
217
217
/// </para>
218
218
/// <para>
219
219
/// See <see cref="SetPressedHighlight"/> for more information.
@@ -286,7 +286,7 @@ protected virtual void OnMouseLeave () { }
286
286
// If it's a click, and we didn't handle it, then we need to generate a click event
287
287
// We get here if the view did not handle the mouse event via OnMouseEvent/MouseEvent and
288
288
// it did not handle the press/release/clicked events via HandlePress/HandleRelease/HandleClicked
289
- return OnMouseClick ( mouseEvent ) ;
289
+ return RaiseMouseClickEvent ( mouseEvent ) ;
290
290
}
291
291
292
292
return false ;
@@ -334,31 +334,19 @@ protected virtual bool OnMouseEvent (MouseEventArgs mouseEvent)
334
334
335
335
#region Mouse Click Events
336
336
337
- /// <summary>Raised when a mouse click occurs.</summary>
338
- ///
337
+ /// <summary>Raises the <see cref="OnMouseClick"/>/<see cref="MouseClick"/> event.</summary>
339
338
/// <remarks>
340
339
/// <para>
341
- /// Fired when the mouse is either clicked or double-clicked. Check
342
- /// <see cref="Terminal.Gui.MouseEventArgs.Flags"/> to see which button was clicked.
343
- /// </para>
344
- /// <para>
345
- /// The coordinates are relative to <see cref="View.Viewport"/>.
340
+ /// Called when the mouse is either clicked or double-clicked.
346
341
/// </para>
347
- /// </remarks>
348
- public event EventHandler < MouseEventArgs > ? MouseClick ;
349
-
350
- /// <summary>Invokes the MouseClick event.</summary>
351
- /// <remarks>
352
342
/// <para>
353
- /// Called when the mouse is either clicked or double-clicked. Check
354
- /// <see cref="Terminal.Gui.MouseEventArgs.Flags"/> to see which button was clicked .
343
+ /// If <see cref="WantContinuousButtonPressed"/> is <see langword="true"/>, will be invoked on every mouse event where
344
+ /// the mouse button is pressed .
355
345
/// </para>
356
346
/// </remarks>
357
347
/// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
358
- protected bool OnMouseClick ( MouseEventArgs args )
348
+ protected bool RaiseMouseClickEvent ( MouseEventArgs args )
359
349
{
360
- // BUGBUG: This should be named NewMouseClickEvent. Fix this in https://github.com/gui-cs/Terminal.Gui/issues/3029
361
-
362
350
// Pre-conditions
363
351
if ( ! Enabled )
364
352
{
@@ -368,7 +356,10 @@ protected bool OnMouseClick (MouseEventArgs args)
368
356
369
357
// Cancellable event
370
358
371
- // BUGBUG: There should be a call to a protected virtual OnMouseClick here. Fix this in https://github.com/gui-cs/Terminal.Gui/issues/3029
359
+ if ( OnMouseClick ( args ) || args . Handled )
360
+ {
361
+ return args . Handled ;
362
+ }
372
363
373
364
MouseClick ? . Invoke ( this , args ) ;
374
365
@@ -386,6 +377,34 @@ protected bool OnMouseClick (MouseEventArgs args)
386
377
return args . Handled ;
387
378
}
388
379
380
+ /// <summary>
381
+ /// Called when a mouse click occurs. Check <see cref="MouseEventArgs.Flags"/> to see which button was clicked.
382
+ /// </summary>
383
+ /// <remarks>
384
+ /// <para>
385
+ /// Called when the mouse is either clicked or double-clicked.
386
+ /// </para>
387
+ /// <para>
388
+ /// If <see cref="WantContinuousButtonPressed"/> is <see langword="true"/>, will be called on every mouse event where
389
+ /// the mouse button is pressed.
390
+ /// </para>
391
+ /// </remarks>
392
+ /// <param name="args"></param>
393
+ /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
394
+ protected virtual bool OnMouseClick ( MouseEventArgs args ) { return false ; }
395
+
396
+ /// <summary>Raised when a mouse click occurs.</summary>
397
+ /// <remarks>
398
+ /// <para>
399
+ /// Raised when the mouse is either clicked or double-clicked.
400
+ /// </para>
401
+ /// <para>
402
+ /// If <see cref="WantContinuousButtonPressed"/> is <see langword="true"/>, will be raised on every mouse event where
403
+ /// the mouse button is pressed.
404
+ /// </para>
405
+ /// </remarks>
406
+ public event EventHandler < MouseEventArgs > ? MouseClick ;
407
+
389
408
/// <summary>
390
409
/// INTERNAL For cases where the view is grabbed and the mouse is clicked, this method handles the click event (typically
391
410
/// when <see cref="WantContinuousButtonPressed"/> or <see cref="HighlightStyle"/> are set).
@@ -414,7 +433,7 @@ internal bool WhenGrabbedHandleClicked (MouseEventArgs mouseEvent)
414
433
// If mouse is still in bounds, generate a click
415
434
if ( ! WantMousePositionReports && Viewport . Contains ( mouseEvent . Position ) )
416
435
{
417
- return OnMouseClick ( mouseEvent ) ;
436
+ return RaiseMouseClickEvent ( mouseEvent ) ;
418
437
}
419
438
420
439
return mouseEvent . Handled = true ;
@@ -468,18 +487,18 @@ private bool WhenGrabbedHandlePressed (MouseEventArgs mouseEvent)
468
487
|| mouseEvent . Flags . HasFlag ( MouseFlags . Button3Pressed )
469
488
|| mouseEvent . Flags . HasFlag ( MouseFlags . Button4Pressed ) )
470
489
{
490
+ bool firstPress = true ;
471
491
// The first time we get pressed event, grab the mouse and set focus
472
492
if ( Application . MouseGrabView != this )
473
493
{
494
+ firstPress = true ;
474
495
Application . GrabMouse ( this ) ;
475
496
476
497
if ( ! HasFocus && CanFocus )
477
498
{
478
499
// Set the focus, but don't invoke Accept
479
500
SetFocus ( ) ;
480
501
}
481
-
482
- mouseEvent . Handled = true ;
483
502
}
484
503
485
504
if ( Viewport . Contains ( mouseEvent . Position ) )
@@ -500,10 +519,10 @@ private bool WhenGrabbedHandlePressed (MouseEventArgs mouseEvent)
500
519
}
501
520
}
502
521
503
- if ( WantContinuousButtonPressed && Application . MouseGrabView == this )
522
+ if ( ! firstPress && WantContinuousButtonPressed && Application . MouseGrabView == this )
504
523
{
505
524
// If this is not the first pressed event, generate a click
506
- return OnMouseClick ( mouseEvent ) ;
525
+ return RaiseMouseClickEvent ( mouseEvent ) ;
507
526
}
508
527
509
528
return mouseEvent . Handled = true ;
0 commit comments