Add mouse wheel handling to wxGenericCalendarCtrl

Mimics the scrolling behaviour of native MSW and GTK calendars by allowing to
increment/decrement the month by scrolling anywhere on the generic calendar.

Additionally, use horizontal scrolling to increment/decrement the year.

Backport of 50daf1feab + 4177593aef
into WX_3_0_BRANCH.

See also 50daf1feab (commitcomment-13087042)
This commit is contained in:
Lauri Nurmi
2015-09-06 12:14:36 +03:00
committed by Vadim Zeitlin
parent d82306cd2e
commit 61a3e328ef
2 changed files with 27 additions and 0 deletions

View File

@@ -179,6 +179,7 @@ private:
void OnPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent& event);
void OnClick(wxMouseEvent& event); void OnClick(wxMouseEvent& event);
void OnDClick(wxMouseEvent& event); void OnDClick(wxMouseEvent& event);
void OnWheel(wxMouseEvent& event);
void OnChar(wxKeyEvent& event); void OnChar(wxKeyEvent& event);
void OnMonthChange(wxCommandEvent& event); void OnMonthChange(wxCommandEvent& event);

View File

@@ -59,6 +59,7 @@ BEGIN_EVENT_TABLE(wxGenericCalendarCtrl, wxControl)
EVT_LEFT_DOWN(wxGenericCalendarCtrl::OnClick) EVT_LEFT_DOWN(wxGenericCalendarCtrl::OnClick)
EVT_LEFT_DCLICK(wxGenericCalendarCtrl::OnDClick) EVT_LEFT_DCLICK(wxGenericCalendarCtrl::OnDClick)
EVT_MOUSEWHEEL(wxGenericCalendarCtrl::OnWheel)
EVT_SYS_COLOUR_CHANGED(wxGenericCalendarCtrl::OnSysColourChanged) EVT_SYS_COLOUR_CHANGED(wxGenericCalendarCtrl::OnSysColourChanged)
END_EVENT_TABLE() END_EVENT_TABLE()
@@ -1512,6 +1513,31 @@ wxCalendarHitTestResult wxGenericCalendarCtrl::HitTest(const wxPoint& pos,
} }
} }
void wxGenericCalendarCtrl::OnWheel(wxMouseEvent& event)
{
wxDateSpan span;
switch ( event.GetWheelAxis() )
{
case wxMOUSE_WHEEL_VERTICAL:
// For consistency with the native controls, scrolling upwards
// should go to the past, even if the rotation is positive and
// could be normally expected to increase the date.
span = -wxDateSpan::Month();
break;
case wxMOUSE_WHEEL_HORIZONTAL:
span = wxDateSpan::Year();
break;
}
// Currently we only take into account the rotation direction, not its
// magnitude.
if ( event.GetWheelRotation() < 0 )
span = -span;
SetDateAndNotify(m_date + span);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// subcontrols events handling // subcontrols events handling
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------