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 of50daf1feab
+4177593aef
into WX_3_0_BRANCH. See also50daf1feab (commitcomment-13087042)
This commit is contained in:
committed by
Vadim Zeitlin
parent
d82306cd2e
commit
61a3e328ef
@@ -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);
|
||||||
|
|
||||||
|
@@ -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
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user