A lot of changes

- Fix the broken itemindex of ComboBox  in the Settings dialog
- Change from LCID to uint32_t
- Rewrite the headers of the lang related functions (can handle the whole LCID as input)
- Add dummy functions to unix.c
- Add proper combobox handling in win_settings.c
- Added a lot of debug calls temporarily
- Reactivate every disabled option related to language changes
- Move lang_id to 86box.h from win.h
- Implement on-fly resource switch as discussed with OBattler
- Reimplement everything language related in the initialization section of the program
- Implemented the ladder of three points
1, what is the --lang?
2, what are definied in the config? (to be implemented)
3, what is the system language
This commit is contained in:
Laci bá
2021-11-09 22:33:54 +01:00
parent 11527d39b0
commit dafc429e93
7 changed files with 79 additions and 42 deletions

View File

@@ -17,6 +17,7 @@
* Copyright 2008-2020 Sarah Walker. * Copyright 2008-2020 Sarah Walker.
* Copyright 2016-2020 Miran Grca. * Copyright 2016-2020 Miran Grca.
* Copyright 2017-2020 Fred N. van Kempen. * Copyright 2017-2020 Fred N. van Kempen.
* Copyright 2021 Laci bá'
*/ */
#include <inttypes.h> #include <inttypes.h>
#include <stdarg.h> #include <stdarg.h>
@@ -395,7 +396,8 @@ pc_init(int argc, char *argv[])
int c, vmrp = 0; int c, vmrp = 0;
int ng = 0, lvmp = 0; int ng = 0, lvmp = 0;
uint32_t *uid, *shwnd; uint32_t *uid, *shwnd;
uint32_t lang_init = 0;
/* Grab the executable's full path. */ /* Grab the executable's full path. */
plat_get_exe_name(exe_path, sizeof(exe_path)-1); plat_get_exe_name(exe_path, sizeof(exe_path)-1);
p = plat_get_filename(exe_path); p = plat_get_filename(exe_path);
@@ -519,7 +521,8 @@ usage:
//This function is currently unimplemented for *nix. //This function is currently unimplemented for *nix.
if (!plat_set_language(argv[++c])) lang_init = plat_language_code(argv[++c]);
if (!lang_init)
printf("\nWarning: Invalid language code, ignoring --lang parameter.\n\n"); printf("\nWarning: Invalid language code, ignoring --lang parameter.\n\n");
//The return value of 0 only means that the code is invalid, //The return value of 0 only means that the code is invalid,
@@ -702,7 +705,19 @@ usage:
/* Load the configuration file. */ /* Load the configuration file. */
config_load(); config_load();
/* Load the desired language */
pclog("lang_init %u, lang_id: %u\n", lang_init, lang_id);
if (lang_init)
lang_id = lang_init;
pclog("lang_init %u, lang_id: %u\n", lang_init, lang_id);
lang_init = lang_id;
lang_id = 0;
if (lang_init)
set_language(lang_init);
pclog("lang_init %u, lang_id: %u\n", lang_init, lang_id);
/* All good! */ /* All good! */
return(1); return(1);
} }

View File

@@ -15,6 +15,7 @@
* *
* Copyright 2016-2020 Miran Grca. * Copyright 2016-2020 Miran Grca.
* Copyright 2017-2020 Fred N. van Kempen. * Copyright 2017-2020 Fred N. van Kempen.
* Copyright 2021 Laci bá'
*/ */
#ifndef EMU_86BOX_H #ifndef EMU_86BOX_H
# define EMU_86BOX_H # define EMU_86BOX_H
@@ -90,6 +91,7 @@ extern int window_w, window_h, /* (C) window size and */
vid_resize, /* (C) allow resizing */ vid_resize, /* (C) allow resizing */
invert_display, /* (C) invert the display */ invert_display, /* (C) invert the display */
suppress_overscan; /* (C) suppress overscans */ suppress_overscan; /* (C) suppress overscans */
extern uint32_t lang_id; /* (C) language code identifier */
extern int scale; /* (C) screen scale factor */ extern int scale; /* (C) screen scale factor */
extern int dpi_scale; /* (C) DPI scaling of the emulated screen */ extern int dpi_scale; /* (C) DPI scaling of the emulated screen */
extern int vid_api; /* (C) video renderer */ extern int vid_api; /* (C) video renderer */

View File

@@ -15,6 +15,7 @@
* *
* Copyright 2016-2019 Miran Grca. * Copyright 2016-2019 Miran Grca.
* Copyright 2017-2019 Fred N. van Kempen. * Copyright 2017-2019 Fred N. van Kempen.
* Copyright 2021 Laci bá'
*/ */
#ifndef EMU_PLAT_H #ifndef EMU_PLAT_H
# define EMU_PLAT_H # define EMU_PLAT_H
@@ -121,10 +122,10 @@ extern void plat_setfullscreen(int on);
extern void plat_resize(int x, int y); extern void plat_resize(int x, int y);
extern void plat_vidapi_enable(int enabled); extern void plat_vidapi_enable(int enabled);
extern void plat_vid_reload_options(void); extern void plat_vid_reload_options(void);
extern int plat_set_language(char* langcode); extern uint32_t plat_language_code(char* langcode);
/* Resource management. */ /* Resource management. */
extern void set_language(int id); extern void set_language(uint32_t id);
extern wchar_t *plat_get_string(int id); extern wchar_t *plat_get_string(int id);

View File

@@ -17,6 +17,7 @@
* Copyright 2008-2019 Sarah Walker. * Copyright 2008-2019 Sarah Walker.
* Copyright 2016-2019 Miran Grca. * Copyright 2016-2019 Miran Grca.
* Copyright 2017-2019 Fred N. van Kempen. * Copyright 2017-2019 Fred N. van Kempen.
* Copyright 2021 Laci bá'
*/ */
#ifndef PLAT_WIN_H #ifndef PLAT_WIN_H
# define PLAT_WIN_H # define PLAT_WIN_H
@@ -105,7 +106,6 @@ extern HINSTANCE hinstance;
extern HWND hwndMain, extern HWND hwndMain,
hwndRender; hwndRender;
extern HANDLE ghMutex; extern HANDLE ghMutex;
extern LCID lang_id;
extern HICON hIcon[256]; extern HICON hIcon[256];
extern RECT oldclip; extern RECT oldclip;
extern int sbar_height, user_resize; extern int sbar_height, user_resize;
@@ -129,8 +129,8 @@ extern void do_start(void);
extern void do_stop(void); extern void do_stop(void);
/* Internal platform support functions. */ /* Internal platform support functions. */
extern int has_language_changed(int id); extern int has_language_changed(uint32_t id);
extern void set_language(int id); extern void set_language(uint32_t id);
extern int get_vidpause(void); extern int get_vidpause(void);
extern void show_cursor(int); extern void show_cursor(int);

View File

@@ -1221,8 +1221,15 @@ char* plat_vidapi_name(int i)
return "default"; return "default";
} }
void
set_language(uint32_t id)
{
lang_id = id;
}
/* Sets up the program language before initialization. */ /* Sets up the program language before initialization. */
int plat_set_language(char* langcode) uint32_t plat_language_code(char* langcode)
{ {
/* or maybe not */ /* or maybe not */
return 0; return 0;

View File

@@ -17,6 +17,7 @@
* Copyright 2008-2019 Sarah Walker. * Copyright 2008-2019 Sarah Walker.
* Copyright 2016-2019 Miran Grca. * Copyright 2016-2019 Miran Grca.
* Copyright 2017-2019 Fred N. van Kempen. * Copyright 2017-2019 Fred N. van Kempen.
* Copyright 2021 Laci bá'
*/ */
#define UNICODE #define UNICODE
#define NTDDI_VERSION 0x06010000 #define NTDDI_VERSION 0x06010000
@@ -66,7 +67,7 @@ typedef struct {
/* Platform Public data, specific. */ /* Platform Public data, specific. */
HINSTANCE hinstance; /* application instance */ HINSTANCE hinstance; /* application instance */
HANDLE ghMutex; HANDLE ghMutex;
LCID lang_id; /* current language ID used */ uint32_t lang_id; /* current language ID used */
DWORD dwSubLangID; DWORD dwSubLangID;
int acp_utf8; /* Windows supports UTF-8 codepage */ int acp_utf8; /* Windows supports UTF-8 codepage */
volatile int cpu_thread_run = 1; volatile int cpu_thread_run = 1;
@@ -138,7 +139,7 @@ win_log(const char *fmt, ...)
#define win_log(fmt, ...) #define win_log(fmt, ...)
#endif #endif
void
free_string(rc_str_t **str) free_string(rc_str_t **str)
{ {
if (*str != NULL) { if (*str != NULL) {
@@ -242,29 +243,28 @@ size_t c16stombs(char dst[], const uint16_t src[], int len)
int int
has_language_changed(int id) has_language_changed(uint32_t id)
{ {
LCID lcidNew = MAKELCID(id, dwSubLangID); pclog("has_language_changed? lang_id:%u == id:%u?\n", lang_id, id);
return (lang_id != id);
return (lang_id != lcidNew);
} }
/* Set (or re-set) the language for the application. */ /* Set (or re-set) the language for the application. */
void void
set_language(int id) set_language(uint32_t id)
{ {
LCID lcidNew = MAKELCID(id, dwSubLangID); pclog("set_language %u, lang_id %u\n", id, lang_id);
if (lang_id != id) {
/* Set our new language ID. */
lang_id = id;
SetThreadUILanguage(lang_id);
SetMenu(hwndMain, LoadMenu(hinstance, L"MainMenu"));
if (lang_id != lcidNew) { /* Load the strings table for this ID. */
/* Set our new language ID. */ LoadCommonStrings();
lang_id = lcidNew; }
SetThreadLocale(lang_id);
/* Load the strings table for this ID. */
LoadCommonStrings();
}
} }
@@ -464,9 +464,9 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow)
/* Set the application version ID string. */ /* Set the application version ID string. */
sprintf(emu_version, "%s v%s", EMU_NAME, EMU_VERSION); sprintf(emu_version, "%s v%s", EMU_NAME, EMU_VERSION);
/* First, set our (default) language. */ /* First, set our (default) language. */
set_language(0x0409); set_language(GetThreadUILanguage());
/* Process the command line for options. */ /* Process the command line for options. */
argc = ProcessCommandLine(&argv); argc = ProcessCommandLine(&argv);
@@ -1193,8 +1193,8 @@ plat_vid_reload_options(void)
} }
/* Sets up the program language before initialization. */ /* Sets up the program language before initialization. */
int uint32_t
plat_set_language(char* langcode) plat_language_code(char* langcode)
{ {
int len = mbstoc16s(NULL, langcode, 0) + 1; int len = mbstoc16s(NULL, langcode, 0) + 1;
wchar_t *temp = malloc(len * sizeof(wchar_t)); wchar_t *temp = malloc(len * sizeof(wchar_t));
@@ -1203,11 +1203,7 @@ plat_set_language(char* langcode)
LCID lcid = LocaleNameToLCID((LPWSTR)temp, 0); LCID lcid = LocaleNameToLCID((LPWSTR)temp, 0);
free(temp); free(temp);
return lcid;
if (lcid)
return (SetThreadUILanguage(lcid) == lcid);
else
return 0;
} }
void void

View File

@@ -15,6 +15,7 @@
* *
* Copyright 2016-2019 Miran Grca. * Copyright 2016-2019 Miran Grca.
* Copyright 2018,2019 David Hrdlička. * Copyright 2018,2019 David Hrdlička.
* Copyright 2021 Laci bá'
*/ */
#define UNICODE #define UNICODE
#define BITMAP WINDOWS_BITMAP #define BITMAP WINDOWS_BITMAP
@@ -78,7 +79,7 @@ static int first_cat = 0;
static int dpi = 96; static int dpi = 96;
/* Language */ /* Language */
static int temp_language; static LCID temp_language;
/* Machine category */ /* Machine category */
static int temp_machine_type, temp_machine, temp_cpu, temp_wait_states, temp_fpu, temp_sync; static int temp_machine_type, temp_machine, temp_cpu, temp_wait_states, temp_fpu, temp_sync;
@@ -318,7 +319,7 @@ settings_msgbox_ex(int flags, void *header, void *message, void *btn1, void *btn
return(i); return(i);
} }
int enum_helper = -1, c = 0; int enum_helper, c;
BOOL CALLBACK BOOL CALLBACK
EnumResLangProc(HMODULE hModule, LPCTSTR lpszType, LPCTSTR lpszName, WORD wIDLanguage, LONG_PTR lParam) EnumResLangProc(HMODULE hModule, LPCTSTR lpszType, LPCTSTR lpszName, WORD wIDLanguage, LONG_PTR lParam)
@@ -326,11 +327,13 @@ EnumResLangProc(HMODULE hModule, LPCTSTR lpszType, LPCTSTR lpszName, WORD wIDLan
wchar_t temp[LOCALE_NAME_MAX_LENGTH + 1]; wchar_t temp[LOCALE_NAME_MAX_LENGTH + 1];
LCIDToLocaleName(wIDLanguage, temp, LOCALE_NAME_MAX_LENGTH, 0); LCIDToLocaleName(wIDLanguage, temp, LOCALE_NAME_MAX_LENGTH, 0);
SendMessage((HWND)lParam, CB_ADDSTRING, 0, (LPARAM)temp); SendMessage((HWND)lParam, CB_ADDSTRING, 0, (LPARAM)temp);
SendMessage((HWND)lParam, CB_SETITEMDATA, c, (LPARAM)wIDLanguage);
if (wIDLanguage == temp_language) pclog("widl: %u, langid: %u, c: %u\n", wIDLanguage, lang_id, c);
if (wIDLanguage == lang_id)
enum_helper = c; enum_helper = c;
c++; c++;
return 1; return 1;
} }
@@ -342,9 +345,13 @@ win_fill_languages(HWND hdlg)
HWND lang_combo = GetDlgItem(hdlg, IDC_COMBO_LANG); HWND lang_combo = GetDlgItem(hdlg, IDC_COMBO_LANG);
SendMessage(lang_combo, CB_RESETCONTENT, 0, 0); SendMessage(lang_combo, CB_RESETCONTENT, 0, 0);
enum_helper = -1; c = 0;
EnumResourceLanguages(hinstance, RT_MENU, L"MainMenu", &EnumResLangProc, (LPARAM)lang_combo); EnumResourceLanguages(hinstance, RT_MENU, L"MainMenu", &EnumResLangProc, (LPARAM)lang_combo);
pclog("enum_helper is %d\n", enum_helper);
SendMessage(lang_combo, CB_SETCURSEL, enum_helper, 0); SendMessage(lang_combo, CB_SETCURSEL, enum_helper, 0);
pclog("win_fill_languages\n");
} }
/* This does the initial read of global variables into the temporary ones. */ /* This does the initial read of global variables into the temporary ones. */
@@ -354,6 +361,8 @@ win_settings_init(void)
int i = 0; int i = 0;
/* Language */ /* Language */
temp_language = lang_id;
pclog("temp_language is %u\n", lang_id);
win_fill_languages(hwndParentDialog); win_fill_languages(hwndParentDialog);
/* Machine category */ /* Machine category */
@@ -482,7 +491,7 @@ win_settings_changed(void)
int i = 0, j = 0; int i = 0, j = 0;
/* Language */ /* Language */
// i = i || has_language_changed(temp_language); i = i || has_language_changed(temp_language);
/* Machine category */ /* Machine category */
i = i || (machine != temp_machine); i = i || (machine != temp_machine);
@@ -575,7 +584,7 @@ win_settings_save(void)
pc_reset_hard_close(); pc_reset_hard_close();
/* Language */ /* Language */
// set_language(temp_language); set_language(temp_language);
/* Machine category */ /* Machine category */
machine = temp_machine; machine = temp_machine;
@@ -5229,6 +5238,13 @@ win_settings_main_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
EndDialog(hdlg, 0); EndDialog(hdlg, 0);
win_notify_dlg_closed(); win_notify_dlg_closed();
return TRUE; return TRUE;
case IDC_COMBO_LANG:
if (HIWORD(wParam) == CBN_SELCHANGE) {
HWND combo = GetDlgItem(hwndParentDialog, IDC_COMBO_LANG);
int index = SendMessage(combo, CB_GETCURSEL, 0, 0);
temp_language = SendMessage(combo, CB_GETITEMDATA, index, 0);
pclog("combobox changed -> temp_language = %u", temp_language);
}
} }
break; break;