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
This commit is contained in:
Paul Davis 2010-01-30 18:10:50 +00:00
parent 06c8a2baef
commit d7707af16b
21 changed files with 89 additions and 48 deletions

View File

@ -25,6 +25,7 @@
#include <pbd/failed_constructor.h>
#include <pbd/xml++.h>
#include <pbd/error.h>
#include <pbd/localeguard.h>
#include <ardour/ardour.h>

View File

@ -79,12 +79,6 @@ namespace ARDOUR {
extern Change NameChanged;
extern Change BoundsChanged;
struct LocaleGuard {
LocaleGuard (const char*);
~LocaleGuard ();
const char* old;
};
static const double SHUTTLE_FRACT_SPEED1=0.48412291827; /* derived from A1,A2 */
void setup_fpu ();

View File

@ -32,6 +32,7 @@
#include <pbd/error.h>
#include <pbd/basename.h>
#include <pbd/localeguard.h>
#include <glibmm/thread.h>
#include <pbd/xml++.h>
#include <pbd/memento_command.h>

View File

@ -23,6 +23,7 @@
#include <pbd/error.h>
#include <pbd/enumwriter.h>
#include <pbd/localeguard.h>
#include <ardour/audio_track.h>
#include <ardour/audio_diskstream.h>

View File

@ -28,6 +28,7 @@
#include <pbd/xml++.h>
#include <pbd/whitespace.h>
#include <pbd/pathscanner.h>
#include <pbd/localeguard.h>
#include <glibmm/thread.h>
#include <glibmm/fileutils.h>

View File

@ -34,6 +34,7 @@
#include <pbd/stacktrace.h>
#include <pbd/enumwriter.h>
#include <pbd/convert.h>
#include <pbd/localeguard.h>
#include <ardour/audioregion.h>
#include <ardour/session.h>

View File

@ -26,6 +26,7 @@
#include <sigc++/bind.h>
#include <ardour/automation_event.h>
#include <pbd/stacktrace.h>
#include <pbd/localeguard.h>
#include "i18n.h"

View File

@ -26,6 +26,7 @@
#include <pbd/failed_constructor.h>
#include <pbd/xml++.h>
#include <pbd/localeguard.h>
#include <midi++/manager.h>

View File

@ -19,7 +19,7 @@
#include <sigc++/bind.h>
#include <pbd/stacktrace.h>
#include <pbd/localeguard.h>
#include <ardour/types.h>
#include <ardour/crossfade.h>

View File

@ -24,7 +24,6 @@
#include <sys/resource.h>
#include <unistd.h>
#include <fcntl.h>
#include <locale.h>
#include <errno.h>
#ifdef VST_SUPPORT
@ -606,20 +605,6 @@ ARDOUR::find_data_file (string name, string subdir)
return find_file (name, envvar, subdir);
}
ARDOUR::LocaleGuard::LocaleGuard (const char* str)
{
old = strdup (setlocale (LC_NUMERIC, NULL));
if (strcmp (old, str)) {
setlocale (LC_NUMERIC, str);
}
}
ARDOUR::LocaleGuard::~LocaleGuard ()
{
setlocale (LC_NUMERIC, old);
free ((char*)old);
}
void
ARDOUR::setup_fpu ()
{

View File

@ -30,6 +30,7 @@
#include <pbd/xml++.h>
#include <pbd/replace_all.h>
#include <pbd/localeguard.h>
#include <ardour/audioengine.h>
#include <ardour/io.h>

View File

@ -33,6 +33,7 @@
#include <pbd/error.h>
#include <pbd/pathscanner.h>
#include <pbd/xml++.h>
#include <pbd/localeguard.h>
#include <midi++/manager.h>
@ -44,7 +45,6 @@
#include <pbd/stl_delete.h>
#include "i18n.h"
#include <locale.h>
using namespace std;
using namespace ARDOUR;

View File

@ -29,6 +29,7 @@
#include <pbd/error.h>
#include <pbd/pathscanner.h>
#include <pbd/xml++.h>
#include <pbd/localeguard.h>
#include <ardour/ardour.h>
#include <ardour/session.h>

View File

@ -33,6 +33,7 @@
#include <pbd/failed_constructor.h>
#include <pbd/xml++.h>
#include <pbd/enumwriter.h>
#include <pbd/localeguard.h>
#include <ardour/session.h>
#include <ardour/panner.h>

View File

@ -55,6 +55,7 @@
#include <pbd/strsplit.h>
#include <pbd/stacktrace.h>
#include <pbd/copyfile.h>
#include <pbd/localeguard.h>
#include <ardour/audioengine.h>
#include <ardour/configuration.h>

View File

@ -25,7 +25,10 @@
#include <sigc++/bind.h>
#include <glibmm/thread.h>
#include <pbd/xml++.h>
#include <pbd/localeguard.h>
#include <ardour/tempo.h>
#include <ardour/utils.h>

View File

@ -40,6 +40,7 @@
#include <pbd/error.h>
#include <pbd/pathscanner.h>
#include <pbd/xml++.h>
#include <pbd/localeguard.h>
#include <ardour/ardour.h>
#include <ardour/session.h>

View File

@ -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;
}

View File

@ -29,6 +29,7 @@ dmalloc.cc
error.cc
fpu.cc
id.cc
localeguard.cc
mountpoint.cc
path.cc
pathscanner.cc

21
libs/pbd/localeguard.cc Normal file
View File

@ -0,0 +1,21 @@
#include <cstring>
#include <locale.h>
#include <stdlib.h>
#include "pbd/localeguard.h"
PBD::LocaleGuard::LocaleGuard (const char* str)
{
old = strdup (setlocale (LC_NUMERIC, NULL));
if (strcmp (old, str)) {
setlocale (LC_NUMERIC, str);
}
}
PBD::LocaleGuard::~LocaleGuard ()
{
setlocale (LC_NUMERIC, old);
free ((char*)old);
}

View File

@ -0,0 +1,33 @@
/*
Copyright (C) 1999-2010 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __pbd_localeguard_h__
#define __pbd_localeguard_h__
namespace PBD {
struct LocaleGuard {
LocaleGuard (const char*);
~LocaleGuard ();
const char* old;
};
}; // namespace
#endif /* __pbd_localeguard_h__ */