From db9a0d12b22c188309e7c947b403d5b5aaaa2f06 Mon Sep 17 00:00:00 2001 From: shallowmallow Date: Sun, 12 May 2024 14:57:37 +0200 Subject: [PATCH 1/4] add Locale externs --- src/hx/widgets/Locale.hx | 36 ++++++++++++++++++++++++++++++++++-- src/wx/widgets/Locale.hx | 4 +++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/hx/widgets/Locale.hx b/src/hx/widgets/Locale.hx index 62548f73..1bddd4e4 100644 --- a/src/hx/widgets/Locale.hx +++ b/src/hx/widgets/Locale.hx @@ -2,8 +2,15 @@ package hx.widgets; import wx.widgets.Locale in WxLocale; import wx.widgets.WxString; +import cpp.Pointer; -class Locale { +class Locale extends Object { + + public function new(language:Int) { + if (_ref == null) { + _ref = WxLocale.createInstance(language).reinterpret(); + } + } public static function getLanguageName(lang:Int):String { var r:WxString = WxLocale.getLanguageName(lang); @@ -29,5 +36,30 @@ class Locale { public static function isAvailable(lang:Int):Bool { return WxLocale.isAvailable(lang); } - + + public static function addCatalogLookupPathPrefix(prefix:String):Void { + var s = WxString.createInstance(prefix); + WxLocale.addCatalogLookupPathPrefix(s.ref); + s.destroy(); + } + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Member functions + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + + public function addCatalog(domain:String):Bool { + var s = WxString.createInstance(domain); + var b = localeRef.ptr.addCatalog(s.ref); + s.destroy(); + return b; + } + + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Helpers + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + private var localeRef(get, null):Pointer; + private function get_localeRef():Pointer { + return _ref.reinterpret(); + } + } diff --git a/src/wx/widgets/Locale.hx b/src/wx/widgets/Locale.hx index 9d347787..7785c88a 100644 --- a/src/wx/widgets/Locale.hx +++ b/src/wx/widgets/Locale.hx @@ -22,4 +22,6 @@ extern class Locale { @:native("wxLocale::GetSystemEncodingName") public static function getSystemEncodingName():WxString; @:native("wxLocale::GetSystemLanguage") public static function getSystemLanguage():Int; @:native("wxLocale::IsAvailable") public static function isAvailable(lang:Int):Bool; -} + @:native("wxLocale::AddCatalogLookupPathPrefix") public static function addCatalogLookupPathPrefix(prefix:WxString):Void; + @:native("wxLocale::AddCatalog") public function addCatalog(domain:WxString):Bool; +} \ No newline at end of file From 876075f7725ae1e923efcd47ade47afa4e6e35c3 Mon Sep 17 00:00:00 2001 From: shallowmallow Date: Sun, 12 May 2024 14:58:45 +0200 Subject: [PATCH 2/4] use hxLocale and not wxLocale --- src/hx/widgets/App.hx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hx/widgets/App.hx b/src/hx/widgets/App.hx index df15a8fd..895cf5ab 100644 --- a/src/hx/widgets/App.hx +++ b/src/hx/widgets/App.hx @@ -1,7 +1,7 @@ package hx.widgets; import cpp.Pointer; -import wx.widgets.Locale; +import hx.widgets.Locale; import wx.widgets.App in WxApp; import wx.widgets.WxString; @@ -10,7 +10,7 @@ import wx.widgets.WxString; #undef RegisterClass ") class App extends AppConsole { - private var _locale:Pointer; + private var locale:Locale; public static var instance:App; @@ -22,9 +22,10 @@ class App extends AppConsole { } super(); - var systemLanguage = Locale.getSystemLanguage(); + var systemLanguage = Locale.systemLanguage; + if (systemLanguage != 1) { - _locale = Locale.createInstance(systemLanguage); + locale = new Locale(systemLanguage); } //setCLocale(); } @@ -39,7 +40,7 @@ class App extends AppConsole { } public function exit() { - _locale.destroy(); + locale.destroy(); appRef.ptr.exit(); Entry.cleanup(); } From d322d13cae12a476d98e277727b807ea60b15e34 Mon Sep 17 00:00:00 2001 From: shallowmallow Date: Sun, 12 May 2024 15:06:38 +0200 Subject: [PATCH 3/4] add translations catalog and then resetting local numeric to C so that it doesn't cause parseFloat problems https://github.com/HaxeFoundation/hxcpp/issues/762 --- src/hx/widgets/App.hx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/hx/widgets/App.hx b/src/hx/widgets/App.hx index 895cf5ab..323d301a 100644 --- a/src/hx/widgets/App.hx +++ b/src/hx/widgets/App.hx @@ -26,6 +26,9 @@ class App extends AppConsole { if (systemLanguage != 1) { locale = new Locale(systemLanguage); + Locale.addCatalogLookupPathPrefix("locale"); + locale.addCatalog("wxstd"); + untyped __cpp__("setlocale(LC_NUMERIC, \"C\")"); } //setCLocale(); } From b816b7f00c79d2d82d06ad3d8b1e348fc9932124 Mon Sep 17 00:00:00 2001 From: shallowmallow Date: Sun, 12 May 2024 15:22:01 +0200 Subject: [PATCH 4/4] null check --- src/hx/widgets/App.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hx/widgets/App.hx b/src/hx/widgets/App.hx index 323d301a..2e09c768 100644 --- a/src/hx/widgets/App.hx +++ b/src/hx/widgets/App.hx @@ -43,7 +43,7 @@ class App extends AppConsole { } public function exit() { - locale.destroy(); + if (locale != null) locale.destroy(); appRef.ptr.exit(); Entry.cleanup(); }