determine whether or not to accept comma or period as a numeric character based on locale settings (once per instance of ardour), related to #5027

git-svn-id: svn://localhost/ardour2/branches/3.0@13481 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2012-11-13 18:05:09 +00:00
parent c0bb288ff1
commit 0c0b04ab5c
1 changed files with 38 additions and 3 deletions

View File

@ -25,6 +25,8 @@
#include <pango/pangocairo.h> // for fontmap resolution control for GnomeCanvas
#include <cstdlib>
#include <clocale>
#include <cstring>
#include <cctype>
#include <fstream>
#include <list>
@ -226,7 +228,7 @@ get_font_for_style (string widgetname)
Glib::RefPtr<const Pango::Layout> layout = foobar.get_layout();
PangoFontDescription *pfd = (PangoFontDescription *)pango_layout_get_font_description(const_cast<PangoLayout *>(layout->gobj()));
PangoFontDescription *pfd = const_cast<PangoFontDescription *> (pango_layout_get_font_description(const_cast<PangoLayout *>(layout->gobj())));
if (!pfd) {
@ -586,11 +588,44 @@ longest (vector<string>& strings)
bool
key_is_legal_for_numeric_entry (guint keyval)
{
/* we assume that this does not change over the life of the process
*/
static int comma_decimal = -1;
switch (keyval) {
case GDK_minus:
case GDK_plus:
case GDK_period:
case GDK_comma:
if (comma_decimal < 0) {
std::lconv* lc = std::localeconv();
if (strchr (lc->decimal_point, ',') != 0) {
comma_decimal = 1;
} else {
comma_decimal = 0;
}
}
break;
default:
break;
}
switch (keyval) {
case GDK_period:
if (comma_decimal) {
return false;
} else {
return true;
}
break;
case GDK_comma:
if (comma_decimal) {
return true;
} else {
return false;
}
break;
case GDK_minus:
case GDK_plus:
case GDK_0:
case GDK_1:
case GDK_2: