[PATCH] Initialize the global C++ locale in Gtk::Main



* gtk/src/main.ccg (init_locale): New internal function to set the
global C++ locale to the locale configured in the user environment.
(Gtk::Main::init): Call init_locale() if the set_locale argument is
true.
(Gtk::Main::Main): Always call init_locale() in the constructor
overload which accepts a Glib::OptionContext, since it a use_locale
parameter is not supported by this variant.
---
 ChangeLog        |   12 ++++++++++++
 gtk/src/main.ccg |   36 ++++++++++++++++++++++++++++++++++--
 2 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5e6c240..a3a0415 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-03-30  Daniel Elstner  <daniel kitta gmail com>
+
+	Initialize the global C++ locale in Gtk::Main
+
+	* gtk/src/main.ccg (init_locale): New internal function to set the
+	global C++ locale to the locale configured in the user environment.
+	(Gtk::Main::init): Call init_locale() if the set_locale argument is
+	true.
+	(Gtk::Main::Main): Always call init_locale() in the constructor
+	overload which accepts a Glib::OptionContext, since it a use_locale
+	parameter is not supported by this variant.
+
 2.20.0:
 
 2010-03-23  Murray Cumming  <murrayc murrayc com>
diff --git a/gtk/src/main.ccg b/gtk/src/main.ccg
index bcbd143..f658cf0 100644
--- a/gtk/src/main.ccg
+++ b/gtk/src/main.ccg
@@ -32,6 +32,10 @@
 #endif //GTKMM_ATKMM_ENABLED
 #include <gdkmm/wrap_init.h>
 #include <gtkmm/wrap_init.h>
+#include <locale>
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+# include <stdexcept>
+#endif
 
 namespace
 {
@@ -200,6 +204,27 @@ void GtkMainConnectionNode::list_notify_all()
   }
 }
 
+/* Initialize the global C++ locale to the environment setting.  Called from
+ * the Gtk::Main constructor to set the C++ locale to the environment locale,
+ * in order to mirror the C locale initialization done by gtk_init() if not
+ * explicitly disabled.
+ */
+static void init_locale()
+{
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  try // do not abort if the user-specified locale does not exist
+#endif
+  {
+    std::locale::global(std::locale(""));
+  }
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  catch (const std::runtime_error& error)
+  {
+    g_warning("%s", error.what());
+  }
+#endif
+}
+
 } // anonymous namespace
 
 
@@ -389,7 +414,9 @@ void Main::init(int* argc, char*** argv, bool set_locale)
   }
   else
   {
-    if(!set_locale)
+    if (set_locale)
+      init_locale();
+    else
       gtk_disable_setlocale();
 
     //TODO: Add support for gtk_init_check().
@@ -408,10 +435,15 @@ Main::Main(int& argc, char**& argv, Glib::OptionContext& option_context)
   }
   else
   {
+    // This constructor lacks a boolean set_locale parameter, thus initialize
+    // the global locale unconditionally.  If absolutely necessary, it could
+    // always be undone later after the constructor has run.
+    init_locale();
+
     init_gtkmm_internals();
     instance_ = this;
 
-    //This reimplements some stuff from gtk_init_with_options(),
+    //This reimplements some stuff from gtk_init_with_args(),
     //without calling check_setugid(), because that is not public API.
 
     add_gtk_option_group(option_context);
-- 
1.6.3.3


--=-pjU+zvxlpZVy+a9Uj9QH--



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]