From e5d850d76c87a3e77f5c8cb0db9a0e2ff4b95e66 Mon Sep 17 00:00:00 2001 From: PB Date: Tue, 9 Apr 2019 16:13:39 +0200 Subject: [PATCH] Improve returning wxSYS_CARET_* metrics in wxMSW The documentation stated that (a) wxSYS_CARET_{ON|OFF}_MSEC settings were not supported on MSW and (b) if a setting was not supported a negative value was returned. However, when calling wxSystemSettings::GetMetric(wxSYS_CARET_{ON|OFF}_MSEC), not only the method asserted but 0 was returned instead of a negative value. Fix this by using the value returned by ::GetCaretBlinkTime() for wxSYS_CARET_{ON|OFF}_MSEC. The documentation for wxSYS_CARET_TIMEOUT_MSEC does not list any platform limitations; however, attempting to obtain this value resulted in an assert and 0 returned. Fix this by returning -1. Returning -1 may not the be the ideal solution, but there is no value reserved for the setting not being supported and the caret on MSW usually blinks. Closes https://github.com/wxWidgets/wxWidgets/pull/1285 --- interface/wx/settings.h | 5 ++--- src/msw/settings.cpp | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/interface/wx/settings.h b/interface/wx/settings.h index 925c6aa9c4..9a6d8621e3 100644 --- a/interface/wx/settings.h +++ b/interface/wx/settings.h @@ -197,7 +197,7 @@ enum wxSystemMetric Time, in milliseconds, for how long a blinking caret should stay visible during a single blink cycle before it disappears. If this value is negative, the platform does not support the - user setting. Implemented only on GTK+ and MacOS X. + user setting. @since 3.1.1 */ @@ -208,8 +208,7 @@ enum wxSystemMetric stay invisible during a single blink cycle before it reappears. If this value is zero, carets should be visible all the time instead of blinking. If the value is negative, the platform - does not support the user setting. Implemented only on GTK+ - and MacOS X. + does not support the user setting. @since 3.1.1 */ diff --git a/src/msw/settings.cpp b/src/msw/settings.cpp index 4b8534f18b..3377b5b080 100644 --- a/src/msw/settings.cpp +++ b/src/msw/settings.cpp @@ -253,7 +253,10 @@ static const int gs_metricsMap[] = SM_PENWINDOWS, SM_SHOWSOUNDS, SM_SWAPBUTTON, - -1 // wxSYS_DCLICK_MSEC - not available as system metric + -1, // wxSYS_DCLICK_MSEC - not available as system metric + -1, // wxSYS_CARET_ON_MSEC - not available as system metric + -1, // wxSYS_CARET_OFF_MSEC - not available as system metric + -1 // wxSYS_CARET_TIMEOUT_MSEC - not available as system metric }; // Get a system metric, e.g. scrollbar size @@ -268,6 +271,25 @@ int wxSystemSettingsNative::GetMetric(wxSystemMetric index, wxWindow* WXUNUSED(w return ::GetDoubleClickTime(); } + // return the caret blink time for both + // wxSYS_CARET_ON_MSEC and wxSYS_CARET_OFF_MSEC + if ( index == wxSYS_CARET_ON_MSEC || index == wxSYS_CARET_OFF_MSEC ) + { + const UINT blinkTime = ::GetCaretBlinkTime(); + + if ( blinkTime == 0 ) // error + { + return -1; + } + + if ( blinkTime == INFINITE ) // caret does not blink + { + return 0; + } + + return blinkTime; + } + int indexMSW = gs_metricsMap[index]; if ( indexMSW == -1 ) {