/* static */ bool wxLocale::IsAvailable(int lang) { const wxLanguageInfo *info = wxLocale::GetLanguageInfo(lang); wxCHECK_MSG( info, false, wxS("invalid language") ); #if defined(__WIN32__) if ( !info->WinLang ) return false; if ( !::IsValidLocale(info->GetLCID(), LCID_INSTALLED) ) return false; #elif defined(__UNIX__) // Test if setting the locale works, then set it back. char * const oldLocale = wxStrdupA(setlocale(LC_ALL, NULL)); // Some platforms don't like xx_YY form and require xx only so test for // it too. const bool available = wxSetlocaleTryUTF8(LC_ALL, info->CanonicalName) || wxSetlocaleTryUTF8(LC_ALL, ExtractLang(info->CanonicalName)); // restore the original locale wxSetlocale(LC_ALL, oldLocale); free(oldLocale); if ( !available ) return false; #endif return true; }
// use unusual names for the parameters to avoid conflict with wxApp::arg[cv] bool wxApp::Initialize(int& argc_, wxChar **argv_) { if ( !wxAppBase::Initialize(argc_, argv_) ) return false; #if wxUSE_THREADS if (!g_thread_supported()) { g_thread_init(NULL); gdk_threads_init(); } #endif // wxUSE_THREADS // gtk+ 2.0 supports Unicode through UTF-8 strings wxConvCurrent = &wxConvUTF8; #ifdef __UNIX__ // decide which conversion to use for the file names // (1) this variable exists for the sole purpose of specifying the encoding // of the filenames for GTK+ programs, so use it if it is set wxString encName(wxGetenv(wxT("G_FILENAME_ENCODING"))); encName = encName.BeforeFirst(wxT(',')); if (encName.CmpNoCase(wxT("@locale")) == 0) encName.clear(); encName.MakeUpper(); #if wxUSE_INTL if (encName.empty()) { // (2) if a non default locale is set, assume that the user wants his // filenames in this locale too encName = wxLocale::GetSystemEncodingName().Upper(); // But don't consider ASCII in this case. if ( !encName.empty() ) { #if wxUSE_FONTMAP wxFontEncoding enc = wxFontMapperBase::GetEncodingFromName(encName); if ( enc == wxFONTENCODING_DEFAULT ) #else // !wxUSE_FONTMAP if ( encName == wxT("US-ASCII") ) #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP { // This means US-ASCII when returned from GetEncodingFromName(). encName.clear(); } } // (3) finally use UTF-8 by default if ( encName.empty() ) encName = wxT("UTF-8"); wxSetEnv(wxT("G_FILENAME_ENCODING"), encName); } #else if (encName.empty()) encName = wxT("UTF-8"); // if wxUSE_INTL==0 it probably indicates that only "C" locale is supported // by the program anyhow so prevent GTK+ from calling setlocale(LC_ALL, "") // from gtk_init_check() as it does by default gtk_disable_setlocale(); #endif // wxUSE_INTL static wxConvBrokenFileNames fileconv(encName); wxConvFileName = &fileconv; #endif // __UNIX__ bool init_result; int i; #if wxUSE_UNICODE // gtk_init() wants UTF-8, not wchar_t, so convert char **argvGTK = new char *[argc_ + 1]; for ( i = 0; i < argc_; i++ ) { argvGTK[i] = wxStrdupA(wxConvUTF8.cWX2MB(argv_[i])); } argvGTK[argc_] = NULL; int argcGTK = argc_; #ifdef __WXGPE__ init_result = true; // is there a _check() version of this? gpe_application_init( &argcGTK, &argvGTK ); #else init_result = gtk_init_check( &argcGTK, &argvGTK ); #endif wxUpdateLocaleIsUtf8(); if ( argcGTK != argc_ ) { // we have to drop the parameters which were consumed by GTK+ for ( i = 0; i < argcGTK; i++ ) { while ( strcmp(wxConvUTF8.cWX2MB(argv_[i]), argvGTK[i]) != 0 ) { memmove(argv_ + i, argv_ + i + 1, (argc_ - i)*sizeof(*argv_)); } } argc_ = argcGTK; argv_[argc_] = NULL; } //else: gtk_init() didn't modify our parameters // free our copy for ( i = 0; i < argcGTK; i++ ) { free(argvGTK[i]); } delete [] argvGTK; #else // !wxUSE_UNICODE // gtk_init() shouldn't actually change argv_ itself (just its contents) so // it's ok to pass pointer to it init_result = gtk_init_check( &argc_, &argv_ ); #endif // wxUSE_UNICODE/!wxUSE_UNICODE // update internal arg[cv] as GTK+ may have removed processed options: this->argc = argc_; this->argv = argv_; if ( m_traits ) { // if there are still GTK+ standard options unparsed in the command // line, it means that they were not syntactically correct and GTK+ // already printed a warning on the command line and we should now // exit: wxArrayString opt, desc; m_traits->GetStandardCmdLineOptions(opt, desc); for ( i = 0; i < argc_; i++ ) { // leave just the names of the options with values const wxString str = wxString(argv_[i]).BeforeFirst('='); for ( size_t j = 0; j < opt.size(); j++ ) { // remove the leading spaces from the option string as it does // have them if ( opt[j].Trim(false).BeforeFirst('=') == str ) { // a GTK+ option can be left on the command line only if // there was an error in (or before, in another standard // options) it, so abort, just as we do if incorrect // program option is given wxLogError(_("Invalid GTK+ command line option, use \"%s --help\""), argv_[0]); return false; } } } } if ( !init_result ) { wxLogError(_("Unable to initialize GTK+, is DISPLAY set properly?")); return false; } // we cannot enter threads before gtk_init is done gdk_threads_enter(); #if wxUSE_INTL wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding()); #endif // make sure GtkWidget type is loaded, idle hooks need it g_type_class_ref(GTK_TYPE_WIDGET); WakeUpIdle(); return true; }
bool wxApp::Initialize(int& argc, wxChar **argv) { bool init_result; #if wxUSE_THREADS if (!g_thread_supported()) g_thread_init(NULL); wxgs_poll_func = g_main_context_get_poll_func(NULL); g_main_context_set_poll_func(NULL, wxapp_poll_func); #endif // wxUSE_THREADS gtk_set_locale(); // We should have the wxUSE_WCHAR_T test on the _outside_ #if wxUSE_WCHAR_T // gtk+ 2.0 supports Unicode through UTF-8 strings wxConvCurrent = &wxConvUTF8; #else // !wxUSE_WCHAR_T if (!wxOKlibc()) wxConvCurrent = (wxMBConv*) NULL; #endif // wxUSE_WCHAR_T/!wxUSE_WCHAR_T // decide which conversion to use for the file names // (1) this variable exists for the sole purpose of specifying the encoding // of the filenames for GTK+ programs, so use it if it is set wxString encName(wxGetenv(_T("G_FILENAME_ENCODING"))); encName = encName.BeforeFirst(_T(',')); if (encName.CmpNoCase(_T("@locale")) == 0) encName.clear(); encName.MakeUpper(); #if wxUSE_INTL if (encName.empty()) { // (2) if a non default locale is set, assume that the user wants his // filenames in this locale too encName = wxLocale::GetSystemEncodingName().Upper(); // (3) finally use UTF-8 by default if (encName.empty() || encName == _T("US-ASCII")) encName = _T("UTF-8"); wxSetEnv(_T("G_FILENAME_ENCODING"), encName); } #else if (encName.empty()) encName = _T("UTF-8"); #endif // wxUSE_INTL #if wxUSE_WCHAR_T static wxConvBrokenFileNames fileconv(encName); wxConvFileName = &fileconv; #endif // wxUSE_WCHAR_T #if wxUSE_UNICODE // gtk_init() wants UTF-8, not wchar_t, so convert int i; char **argvGTK = new char *[argc + 1]; for ( i = 0; i < argc; i++ ) { argvGTK[i] = wxStrdupA(wxConvUTF8.cWX2MB(argv[i])); } argvGTK[argc] = NULL; int argcGTK = argc; #ifdef __WXGPE__ init_result = true; // is there a _check() version of this? gpe_application_init( &argcGTK, &argvGTK ); #else init_result = gtk_init_check( &argcGTK, &argvGTK ); #endif if ( argcGTK != argc ) { // we have to drop the parameters which were consumed by GTK+ for ( i = 0; i < argcGTK; i++ ) { while ( strcmp(wxConvUTF8.cWX2MB(argv[i]), argvGTK[i]) != 0 ) { memmove(argv + i, argv + i + 1, (argc - i)*sizeof(*argv)); } } argc = argcGTK; } //else: gtk_init() didn't modify our parameters // free our copy for ( i = 0; i < argcGTK; i++ ) { free(argvGTK[i]); } delete [] argvGTK; #else // !wxUSE_UNICODE // gtk_init() shouldn't actually change argv itself (just its contents) so // it's ok to pass pointer to it init_result = gtk_init_check( &argc, &argv ); #endif // wxUSE_UNICODE/!wxUSE_UNICODE if (!init_result) { wxLogError(wxT("Unable to initialize gtk, is DISPLAY set properly?")); return false; } // update internal arg[cv] as GTK+ may have removed processed options: this->argc = argc; this->argv = argv; // we can not enter threads before gtk_init is done gdk_threads_enter(); if ( !wxAppBase::Initialize(argc, argv) ) { gdk_threads_leave(); return false; } wxSetDetectableAutoRepeat( true ); #if wxUSE_INTL wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding()); #endif return true; }