summaryrefslogtreecommitdiff
path: root/libs/gtkmm2ext
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2010-01-30 18:10:50 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2010-01-30 18:10:50 +0000
commitd7707af16b008129ba98e9bd2187fcd4c7a0b299 (patch)
tree4f2da4ad4881528eeaaa237781b03b66be79accb /libs/gtkmm2ext
parent06c8a2baefdb909e40be3c3656ee845de46db310 (diff)
move LocaleGuard "up" into libpbd; use LocaleGuard to replace utterly broken std::locale() in Gtkmm2ext::BarController handling of logarithmic values
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@6598 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/gtkmm2ext')
-rw-r--r--libs/gtkmm2ext/barcontroller.cc42
1 files changed, 17 insertions, 25 deletions
diff --git a/libs/gtkmm2ext/barcontroller.cc b/libs/gtkmm2ext/barcontroller.cc
index 775e6b4a8d..01e67e4010 100644
--- a/libs/gtkmm2ext/barcontroller.cc
+++ b/libs/gtkmm2ext/barcontroller.cc
@@ -25,6 +25,7 @@
#include <algorithm>
#include <pbd/controllable.h>
+#include <pbd/localeguard.h>
#include <gtkmm2ext/gtk_ui.h>
#include <gtkmm2ext/utils.h>
@@ -108,13 +109,14 @@ BarController::entry_input (double* new_value)
// extract a double from the string and take its log
Entry *entry = dynamic_cast<Entry *>(&spinner);
- stringstream stream(entry->get_text());
- stream.imbue(std::locale(""));
- double value;
- stream >> value;
-
- *new_value = log(value);
+ {
+ PBD::LocaleGuard lg (X_("POSIX"));
+ double value;
+ sscanf (entry->get_text().c_str(), "%g", &value);
+ *new_value = log(value);
+ }
+
return true;
}
@@ -141,27 +143,17 @@ BarController::entry_output ()
string str;
size_t found;
- // Gtk.Entry does not like the thousands separator, so we have to
- // remove it after conversion from float to string.
+ // Be sure to use POSIX or C locale here so that
+ // we don't end up with commas (as used by some locales)
+ // in the text entry.
- stream.imbue(std::locale(""));
- stream.precision(spinner.get_digits());
-
- stream << fixed << exp(spinner.get_adjustment()->get_value());
-
- str=stream.str();
-
- // find thousands separators, remove them
- found = str.find(use_facet<numpunct<char> >(std::locale("")).thousands_sep());
- while(found != str.npos) {
- str.erase(found,1);
-
- //find next
- found = str.find(use_facet<numpunct<char> >(std::locale("")).thousands_sep());
+ {
+ PBD::LocaleGuard lg (X_("POSIX"));
+ char buf[128];
+ snprintf (buf, sizeof (buf), "%g", spinner.get_adjustment()->get_value());
+ Entry *entry = dynamic_cast<Entry *>(&spinner);
+ entry->set_text (buf);
}
-
- Entry *entry = dynamic_cast<Entry *>(&spinner);
- entry->set_text(str);
return true;
}