From 773690203ef579edeb9981221934e6e2970873bc Mon Sep 17 00:00:00 2001 From: Lauri Nurmi Date: Thu, 3 Dec 2015 22:30:44 +0200 Subject: [PATCH 1/4] Handle all consecutive clicks on generic calendar month buttons Without handling the double click event, some (or all, on OS X) of the following clicks in a rapid series of clicks are ignored. This makes changing the month unnecessarily slow. --- src/generic/calctrlg.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/generic/calctrlg.cpp b/src/generic/calctrlg.cpp index 97db680459..db92313b42 100644 --- a/src/generic/calctrlg.cpp +++ b/src/generic/calctrlg.cpp @@ -1325,13 +1325,21 @@ bool wxGenericCalendarCtrl::GetDateCoord(const wxDateTime& date, int *day, int * void wxGenericCalendarCtrl::OnDClick(wxMouseEvent& event) { - if ( HitTest(event.GetPosition()) != wxCAL_HITTEST_DAY ) + switch ( HitTest(event.GetPosition()) ) { - event.Skip(); - } - else - { - GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED); + case wxCAL_HITTEST_DAY: + GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED); + break; + case wxCAL_HITTEST_DECMONTH: + case wxCAL_HITTEST_INCMONTH: + + // allow quickly clicking the inc/dec button any number of + // times in a row by handling also the double-click event. + OnClick(event); + break; + default: + event.Skip(); + break; } } From b4b6975badef41c5f49907284842937f5bff6939 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 6 Dec 2015 19:38:48 +0100 Subject: [PATCH 2/4] Fix jagged indentation in wxGenericCalendarCtrl mouse code No real changes. --- src/generic/calctrlg.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/generic/calctrlg.cpp b/src/generic/calctrlg.cpp index db92313b42..4c91d266b1 100644 --- a/src/generic/calctrlg.cpp +++ b/src/generic/calctrlg.cpp @@ -1329,17 +1329,17 @@ void wxGenericCalendarCtrl::OnDClick(wxMouseEvent& event) { case wxCAL_HITTEST_DAY: GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED); - break; + break; + case wxCAL_HITTEST_DECMONTH: case wxCAL_HITTEST_INCMONTH: - // allow quickly clicking the inc/dec button any number of // times in a row by handling also the double-click event. OnClick(event); - break; + break; + default: event.Skip(); - break; } } @@ -1361,14 +1361,14 @@ void wxGenericCalendarCtrl::OnClick(wxMouseEvent& event) // GenerateAllChangeEvents() here, we know which event to send GenerateEvent(wxEVT_CALENDAR_DAY_CHANGED); } - break; + break; case wxCAL_HITTEST_WEEK: - { - wxCalendarEvent send( this, date, wxEVT_CALENDAR_WEEK_CLICKED ); - HandleWindowEvent( send ); - } - break; + { + wxCalendarEvent send( this, date, wxEVT_CALENDAR_WEEK_CLICKED ); + HandleWindowEvent( send ); + } + break; case wxCAL_HITTEST_HEADER: { From f4172484348e4315edb138b3ed9eb3a65970f78c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 6 Dec 2015 19:43:24 +0100 Subject: [PATCH 3/4] Don't call event handler from another handler We advise people to not call the event handlers directly, so don't show bad example in our own code and just handle double clicks directly instead of forwarding them to the single click handler. Alternatively, we could just handle both events in the same handler. --- src/generic/calctrlg.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/generic/calctrlg.cpp b/src/generic/calctrlg.cpp index 4c91d266b1..ed2f38ddfa 100644 --- a/src/generic/calctrlg.cpp +++ b/src/generic/calctrlg.cpp @@ -1325,7 +1325,8 @@ bool wxGenericCalendarCtrl::GetDateCoord(const wxDateTime& date, int *day, int * void wxGenericCalendarCtrl::OnDClick(wxMouseEvent& event) { - switch ( HitTest(event.GetPosition()) ) + wxDateTime date; + switch ( HitTest(event.GetPosition(), &date) ) { case wxCAL_HITTEST_DAY: GenerateEvent(wxEVT_CALENDAR_DOUBLECLICKED); @@ -1333,9 +1334,9 @@ void wxGenericCalendarCtrl::OnDClick(wxMouseEvent& event) case wxCAL_HITTEST_DECMONTH: case wxCAL_HITTEST_INCMONTH: - // allow quickly clicking the inc/dec button any number of - // times in a row by handling also the double-click event. - OnClick(event); + // Consecutive simple clicks result in a series of simple and + // double click events, so handle them in the same way. + SetDateAndNotify(date); break; default: From 84e2492ea4f980e7b02d6d296b5a4ebccf272a90 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 6 Dec 2015 19:44:15 +0100 Subject: [PATCH 4/4] Handle all wxCalendarHitTestResult elements in a switch This ensures that the compiler will warn us if a new wxCAL_HITTEST_XXX is added but forgotten to be handled here. --- src/generic/calctrlg.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/generic/calctrlg.cpp b/src/generic/calctrlg.cpp index ed2f38ddfa..a03cfbd4da 100644 --- a/src/generic/calctrlg.cpp +++ b/src/generic/calctrlg.cpp @@ -1339,8 +1339,12 @@ void wxGenericCalendarCtrl::OnDClick(wxMouseEvent& event) SetDateAndNotify(date); break; - default: + case wxCAL_HITTEST_WEEK: + case wxCAL_HITTEST_HEADER: + case wxCAL_HITTEST_SURROUNDING_WEEK: + case wxCAL_HITTEST_NOWHERE: event.Skip(); + break; } }