peer_ttls_ui now initializes wxWidgets further to support localization

This commit is contained in:
Simon Rozman 2016-08-27 17:54:00 +02:00
parent bc1c56174a
commit 9f770bbb3f
3 changed files with 145 additions and 78 deletions

View File

@ -46,29 +46,15 @@ bool wxEventMonitorApp::OnInit()
::MsiUseFeature(_T(PRODUCT_VERSION_GUID), _T("featEventMonitor"));
#endif
wxConfigBase *cfgPrev = wxConfigBase::Set(new wxConfig(wxT(PRODUCT_NAME_STR), wxT(VENDOR_NAME_STR)));
if (cfgPrev) wxDELETE(cfgPrev);
wxInitializeConfig();
if (!wxApp::OnInit())
return false;
// Set desired locale.
wxLanguage lang_code;
wxString lang;
if (wxConfigBase::Get()->Read(wxT("Language"), &lang)) {
const wxLanguageInfo *lang_info = wxLocale::FindLanguageInfo(lang);
lang_code = lang_info ? (wxLanguage)lang_info->Language : wxLANGUAGE_DEFAULT;
} else
lang_code = wxLANGUAGE_DEFAULT;
if (wxLocale::IsAvailable(lang_code)) {
wxString sPath;
if (wxConfigBase::Get()->Read(wxT("LocalizationRepositoryPath"), &sPath))
m_locale.AddCatalogLookupPathPrefix(sPath);
if (m_locale.Init(lang_code)) {
if (wxInitializeLocale(m_locale)) {
//wxVERIFY(m_locale.AddCatalog(wxT("wxExtend") wxT(wxExtendVersion)));
wxVERIFY(m_locale.AddCatalog(wxT("EventMonitor")));
}
}
#ifdef __WXMSW__
// Find EventMonitor window if already running.

View File

@ -20,6 +20,7 @@
#include <wx/hyperlink.h>
#include <wx/icon.h>
#include <wx/intl.h>
#include <wx/scrolwin.h>
#include <Windows.h>
@ -104,6 +105,17 @@ inline wxIcon wxLoadIconFromResource(HINSTANCE hinst, PCWSTR pszName, const wxSi
///
inline wxString wxEAPGetProviderName(const std::wstring &id);
///
/// Initializes wxWidgets application configuration scheme
///
inline void wxInitializeConfig();
///
/// Inizializes wxWidgets localization scheme
///
inline bool wxInitializeLocale(wxLocale &locale);
namespace eap
{
///
@ -124,6 +136,7 @@ namespace eap
#include <WinStd/Cred.h>
#include <WinStd/Win.h>
#include <wx/config.h>
#include <wx/log.h>
#include <CommCtrl.h>
@ -826,6 +839,36 @@ inline wxString wxEAPGetProviderName(const std::wstring &id)
}
inline void wxInitializeConfig()
{
wxConfigBase *cfgPrev = wxConfigBase::Set(new wxConfig(wxT(PRODUCT_NAME_STR), wxT(VENDOR_NAME_STR)));
if (cfgPrev) wxDELETE(cfgPrev);
}
inline bool wxInitializeLocale(wxLocale &locale)
{
// Read language from configuration.
wxLanguage lang_code;
wxString lang;
if (wxConfigBase::Get()->Read(wxT("Language"), &lang)) {
const wxLanguageInfo *lang_info = wxLocale::FindLanguageInfo(lang);
lang_code = lang_info ? (wxLanguage)lang_info->Language : wxLANGUAGE_DEFAULT;
} else
lang_code = wxLANGUAGE_DEFAULT;
if (wxLocale::IsAvailable(lang_code)) {
// Language is "available". Well... Known actually.
wxString sPath;
if (wxConfigBase::Get()->Read(wxT("LocalizationRepositoryPath"), &sPath))
locale.AddCatalogLookupPathPrefix(sPath);
return locale.Init(lang_code);
}
return false;
}
namespace eap
{
class monitor_ui

View File

@ -24,6 +24,21 @@ using namespace std;
using namespace winstd;
//////////////////////////////////////////////////////////////////////
// wxInitializerPeer
//////////////////////////////////////////////////////////////////////
class wxInitializerPeer
{
public:
wxInitializerPeer(_In_ HINSTANCE instance);
virtual ~wxInitializerPeer();
protected:
wxLocale m_locale; ///< Locale
};
//////////////////////////////////////////////////////////////////////
// eap::peer_ttls_ui
//////////////////////////////////////////////////////////////////////
@ -104,11 +119,11 @@ void eap::peer_ttls_ui::invoke_config_ui(
cfg.m_providers.push_back(std::move(cfg_provider));
}
// Initialize application.
new wxApp();
wxEntryStart(m_instance);
int result;
{
// Initialize application.
wxInitializerPeer init(m_instance);
{
// Create wxWidget-approved parent window.
wxWindow parent;
@ -123,9 +138,8 @@ void eap::peer_ttls_ui::invoke_config_ui(
wxTopLevelWindows.DeleteObject(&parent);
parent.SetHWND((WXHWND)NULL);
}
}
// Clean-up and return.
wxEntryCleanup();
if (result != wxID_OK)
throw win_runtime_error(ERROR_CANCELLED, __FUNCTION__ " Cancelled.");
@ -196,11 +210,11 @@ void eap::peer_ttls_ui::invoke_identity_ui(
cfg_method->m_inner->m_allow_save = false;
}
// Initialize application.
new wxApp();
wxEntryStart(m_instance);
int result;
{
// Initialize application.
wxInitializerPeer init(m_instance);
{
// Create wxWidget-approved parent window.
wxWindow parent;
@ -248,9 +262,8 @@ void eap::peer_ttls_ui::invoke_identity_ui(
wxTopLevelWindows.DeleteObject(&parent);
parent.SetHWND((WXHWND)NULL);
}
}
// Clean-up and return.
wxEntryCleanup();
if (result != wxID_OK)
throw win_runtime_error(ERROR_CANCELLED, __FUNCTION__ " Cancelled.");
@ -281,3 +294,28 @@ void eap::peer_ttls_ui::invoke_interactive_ui(
InitCommonControls();
MessageBox(hwndParent, _T(PRODUCT_NAME_STR) _T(" interactive UI goes here!"), _T(PRODUCT_NAME_STR) _T(" Prompt"), MB_OK);
}
//////////////////////////////////////////////////////////////////////
// wxInitializerPeer
//////////////////////////////////////////////////////////////////////
wxInitializerPeer::wxInitializerPeer(_In_ HINSTANCE instance)
{
// Initialize application.
new wxApp();
wxEntryStart(instance);
// Do our wxWidgets configuration and localization initialization.
wxInitializeConfig();
if (wxInitializeLocale(m_locale)) {
//m_locale.AddCatalog(wxT("wxExtend") wxT(wxExtendVersion));
m_locale.AddCatalog(wxT("EAPTTLSUI"));
}
}
wxInitializerPeer::~wxInitializerPeer()
{
wxEntryCleanup();
}