using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace Terminal.Gui {
public partial class View {
///
/// Event fired when the view receives the mouse event for the first time.
///
public event EventHandler MouseEnter;
///
/// Event fired when the view receives a mouse event for the last time.
///
public event EventHandler MouseLeave;
///
/// Event fired when a mouse event is generated.
///
public event EventHandler MouseClick;
///
public override bool OnMouseEnter (MouseEvent mouseEvent)
{
if (!Enabled) {
return true;
}
if (!CanBeVisible (this)) {
return false;
}
var args = new MouseEventEventArgs (mouseEvent);
MouseEnter?.Invoke (this, args);
return args.Handled || base.OnMouseEnter (mouseEvent);
}
///
public override bool OnMouseLeave (MouseEvent mouseEvent)
{
if (!Enabled) {
return true;
}
if (!CanBeVisible (this)) {
return false;
}
var args = new MouseEventEventArgs (mouseEvent);
MouseLeave?.Invoke (this, args);
return args.Handled || base.OnMouseLeave (mouseEvent);
}
///
/// Method invoked when a mouse event is generated
///
///
/// , if the event was handled, otherwise.
public virtual bool OnMouseEvent (MouseEvent mouseEvent)
{
if (!Enabled) {
return true;
}
if (!CanBeVisible (this)) {
return false;
}
var args = new MouseEventEventArgs (mouseEvent);
if (OnMouseClick (args))
return true;
if (MouseEvent (mouseEvent))
return true;
if (mouseEvent.Flags == MouseFlags.Button1Clicked) {
if (CanFocus && !HasFocus && SuperView != null) {
SuperView.SetFocus (this);
SetNeedsDisplay ();
}
return true;
}
return false;
}
///
/// Invokes the MouseClick event.
///
protected bool OnMouseClick (MouseEventEventArgs args)
{
if (!Enabled) {
return true;
}
MouseClick?.Invoke (this, args);
return args.Handled;
}
///
/// Gets or sets a value indicating whether this wants mouse position reports.
///
/// if want mouse position reports; otherwise, .
public virtual bool WantMousePositionReports { get; set; }
///
/// Gets or sets a value indicating whether this want continuous button pressed event.
///
public virtual bool WantContinuousButtonPressed { get; set; }
}
}