Add wxSYS_CARET_{ON,OFF,TIMEOUT}_MSEC system settings

Provide a way to retrieve the caret blink times from wxSystemSe and implement
it for wxOSX and wxGTK.

Closes #17629.
This commit is contained in:
brawer
2016-08-19 22:55:20 +02:00
committed by Vadim Zeitlin
parent 75e254fce7
commit 7f10d1fa8a
5 changed files with 138 additions and 2 deletions

View File

@@ -96,6 +96,7 @@ All (GUI):
- Fix rescaling of wxImage.
- Fix displaying edited value of wxUIntProperty (wxPropertyGrid).
- Fix displaying validation errors for numeric wxPropertyGrid properties.
- Add wxSYS_CARET_{ON,OFF,TIMEOUT}_MSEC system settings (brawer).
wxGTK:

View File

@@ -137,7 +137,10 @@ enum wxSystemMetric
wxSYS_PENWINDOWS_PRESENT,
wxSYS_SHOW_SOUNDS,
wxSYS_SWAP_BUTTONS,
wxSYS_DCLICK_MSEC
wxSYS_DCLICK_MSEC,
wxSYS_CARET_ON_MSEC,
wxSYS_CARET_OFF_MSEC,
wxSYS_CARET_TIMEOUT_MSEC
};
// possible values for wxSystemSettings::HasFeature() parameter

View File

@@ -191,7 +191,41 @@ enum wxSystemMetric
//!< visually in situations where it would otherwise present the information
//!< only in audible form; zero otherwise.
wxSYS_SWAP_BUTTONS, //!< Non-zero if the meanings of the left and right mouse buttons are swapped; zero otherwise.
wxSYS_DCLICK_MSEC //!< Maximal time, in milliseconds, which may pass between subsequent clicks for a double click to be generated.
wxSYS_DCLICK_MSEC, //!< Maximal time, in milliseconds, which may pass between subsequent clicks for a double click to be generated.
/**
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.
@since 3.1.1
*/
wxSYS_CARET_ON_MSEC,
/**
Time, in milliseconds, for how long a blinking caret should
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.
@since 3.1.1
*/
wxSYS_CARET_OFF_MSEC,
/**
Time, in milliseconds, for how long a caret should blink after
a user interaction. After this timeout has expired, the caret
should stay continuously visible until the user interacts with
the caret again (for example by entering, deleting or cutting
text). If this value is negative, carets should blink forever;
if it is zero, carets should not blink at all.
@since 3.1.1
*/
wxSYS_CARET_TIMEOUT_MSEC
};
/**

View File

@@ -19,6 +19,8 @@
#include "wx/fontutil.h"
#include "wx/fontenum.h"
#include <stdint.h>
#include <gtk/gtk.h>
#include "wx/gtk/private/win_gtk.h"
#include "wx/gtk/private/gtk2-compat.h"
@@ -574,6 +576,56 @@ int wxSystemSettingsNative::GetMetric( wxSystemMetric index, wxWindow* win )
"gtk-double-click-time", &dclick, NULL);
return dclick;
case wxSYS_CARET_ON_MSEC:
{
gint blink_time = -1;
g_object_get(GetSettingsForWindowScreen(window),
"gtk-cursor-blink-time", &blink_time, NULL);
if (blink_time > 0)
return blink_time / 2;
return -1;
}
case wxSYS_CARET_OFF_MSEC:
{
gboolean should_blink = true;
gint blink_time = -1;
g_object_get(GetSettingsForWindowScreen(window),
"gtk-cursor-blink", &should_blink,
"gtk-cursor-blink-time", &blink_time,
NULL);
if (!should_blink)
return 0;
if (blink_time > 0)
return blink_time / 2;
return -1;
}
case wxSYS_CARET_TIMEOUT_MSEC:
{
gboolean should_blink = true;
gint timeout = 0;
g_object_get(GetSettingsForWindowScreen(window),
"gtk-cursor-blink", &should_blink,
"gtk-cursor-blink-timeout", &timeout,
NULL);
if (!should_blink)
return 0;
// GTK+ returns this value in seconds, not milliseconds,
// Special value of 2147483647 means that the cursor never
// blinks and we handle any value that would overflow int after
// multiplication in the same manner as it looks quite
// unnecessary to support cursor blinking once a month.
if (timeout > 0 && timeout < INT32_MAX / 1000)
return timeout * 1000;
return -1; // no timeout, blink forever
}
case wxSYS_DRAG_X:
case wxSYS_DRAG_Y:
gint drag_threshold;

View File

@@ -21,6 +21,26 @@
#include "wx/osx/cocoa/private.h"
#import <AppKit/NSColor.h>
#import <Foundation/Foundation.h>
static int wxOSXGetUserDefault(NSString* key, int defaultValue)
{
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
if (!defaults)
{
return defaultValue;
}
id setting = [defaults objectForKey: key];
if (!setting)
{
return defaultValue;
}
return [setting intValue];
}
// ----------------------------------------------------------------------------
// wxSystemSettingsNative
@@ -231,6 +251,32 @@ int wxSystemSettingsNative::GetMetric(wxSystemMetric index, wxWindow *WXUNUSED(w
// but rather rely on the 'click-count' by the system delivered in a mouse event
return 500;
case wxSYS_CARET_ON_MSEC:
value = wxOSXGetUserDefault(@"NSTextInsertionPointBlinkPeriodOn", -1);
if (value > 0)
return value;
value = wxOSXGetUserDefault(@"NSTextInsertionPointBlinkPeriod", -1);
if (value > 0)
return value / 2;
return -1;
case wxSYS_CARET_OFF_MSEC:
value = wxOSXGetUserDefault(@"NSTextInsertionPointBlinkPeriodOff", -1);
if (value > 0)
return value;
value = wxOSXGetUserDefault(@"NSTextInsertionPointBlinkPeriod", -1);
if (value > 0)
return value / 2;
return -1;
case wxSYS_CARET_TIMEOUT_MSEC:
// On MacOS X, carets don't stop blinking after user interactions.
return -1;
default:
return -1; // unsupported metric
}