Browse Source

Removed mouse capture shenanigans from the calendar

pull/4812/head
Nikita Tsukanov 6 years ago
parent
commit
103a72cfd3
  1. 79
      src/Avalonia.Controls/Calendar/CalendarItem.cs

79
src/Avalonia.Controls/Calendar/CalendarItem.cs

@ -36,11 +36,7 @@ namespace Avalonia.Controls.Primitives
private Button _headerButton; private Button _headerButton;
private Button _nextButton; private Button _nextButton;
private Button _previousButton; private Button _previousButton;
private Grid _monthView;
private Grid _yearView;
private ITemplate<IControl> _dayTitleTemplate; private ITemplate<IControl> _dayTitleTemplate;
private CalendarButton _lastCalendarButton;
private CalendarDayButton _lastCalendarDayButton;
private DateTime _currentMonth; private DateTime _currentMonth;
private bool _isMouseLeftButtonDown = false; private bool _isMouseLeftButtonDown = false;
@ -160,38 +156,12 @@ namespace Avalonia.Controls.Primitives
/// <summary> /// <summary>
/// Gets the Grid that hosts the content when in month mode. /// Gets the Grid that hosts the content when in month mode.
/// </summary> /// </summary>
internal Grid MonthView internal Grid MonthView { get; set; }
{
get { return _monthView; }
private set
{
if (_monthView != null)
_monthView.PointerLeave -= MonthView_MouseLeave;
_monthView = value;
if (_monthView != null)
_monthView.PointerLeave += MonthView_MouseLeave;
}
}
/// <summary> /// <summary>
/// Gets the Grid that hosts the content when in year or decade mode. /// Gets the Grid that hosts the content when in year or decade mode.
/// </summary> /// </summary>
internal Grid YearView internal Grid YearView { get; set; }
{
get { return _yearView; }
private set
{
if (_yearView != null)
_yearView.PointerLeave -= YearView_MouseLeave;
_yearView = value;
if (_yearView != null)
_yearView.PointerLeave += YearView_MouseLeave;
}
}
private void PopulateGrids() private void PopulateGrids()
{ {
if (MonthView != null) if (MonthView != null)
@ -226,7 +196,6 @@ namespace Avalonia.Controls.Primitives
cell.CalendarDayButtonMouseDown += Cell_MouseLeftButtonDown; cell.CalendarDayButtonMouseDown += Cell_MouseLeftButtonDown;
cell.CalendarDayButtonMouseUp += Cell_MouseLeftButtonUp; cell.CalendarDayButtonMouseUp += Cell_MouseLeftButtonUp;
cell.PointerEnter += Cell_MouseEnter; cell.PointerEnter += Cell_MouseEnter;
cell.PointerLeave += Cell_MouseLeave;
cell.Click += Cell_Click; cell.Click += Cell_Click;
children.Add(cell); children.Add(cell);
} }
@ -256,7 +225,6 @@ namespace Avalonia.Controls.Primitives
month.CalendarLeftMouseButtonDown += Month_CalendarButtonMouseDown; month.CalendarLeftMouseButtonDown += Month_CalendarButtonMouseDown;
month.CalendarLeftMouseButtonUp += Month_CalendarButtonMouseUp; month.CalendarLeftMouseButtonUp += Month_CalendarButtonMouseUp;
month.PointerEnter += Month_MouseEnter; month.PointerEnter += Month_MouseEnter;
month.PointerLeave += Month_MouseLeave;
children.Add(month); children.Add(month);
} }
} }
@ -937,17 +905,7 @@ namespace Avalonia.Controls.Primitives
} }
} }
} }
internal void Cell_MouseLeave(object sender, PointerEventArgs e)
{
if (_isMouseLeftButtonDown)
{
CalendarDayButton b = (CalendarDayButton)sender;
// The button is in Pressed state. Change the state to normal.
if (e.Pointer.Captured == b)
e.Pointer.Capture(null);
_lastCalendarDayButton = b;
}
}
internal void Cell_MouseLeftButtonDown(object sender, PointerPressedEventArgs e) internal void Cell_MouseLeftButtonDown(object sender, PointerPressedEventArgs e)
{ {
if (Owner != null) if (Owner != null)
@ -1207,35 +1165,6 @@ namespace Avalonia.Controls.Primitives
} }
} }
private void Month_MouseLeave(object sender, PointerEventArgs e)
{
if (_isMouseLeftButtonDownYearView)
{
CalendarButton b = (CalendarButton)sender;
// The button is in Pressed state. Change the state to normal.
if (e.Pointer.Captured == b)
e.Pointer.Capture(null);
//b.ReleaseMouseCapture();
_lastCalendarButton = b;
}
}
private void MonthView_MouseLeave(object sender, PointerEventArgs e)
{
if (_lastCalendarDayButton != null)
{
e.Pointer.Capture(_lastCalendarDayButton);
}
}
private void YearView_MouseLeave(object sender, PointerEventArgs e)
{
if (_lastCalendarButton != null)
{
e.Pointer.Capture(_lastCalendarButton);
}
}
internal void UpdateDisabled(bool isEnabled) internal void UpdateDisabled(bool isEnabled)
{ {
PseudoClasses.Set(":calendardisabled", !isEnabled); PseudoClasses.Set(":calendardisabled", !isEnabled);

Loading…
Cancel
Save