determine whether or not to accept comma or period as a numeric character based on...
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 13 Nov 2012 18:05:09 +0000 (18:05 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 13 Nov 2012 18:05:09 +0000 (18:05 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@13481 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/utils.cc

index 7771aea65000ca917630def0e9e54d29659d2b94..952a393f279a5b866aa70a1ab7c462c72fd0dca2 100644 (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: