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
This commit is contained in:
PB
2019-04-09 16:13:39 +02:00
committed by Vadim Zeitlin
parent 94907d3893
commit e5d850d76c
2 changed files with 25 additions and 4 deletions

View File

@@ -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
*/

View File

@@ -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 )
{