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 2016-2020 Miran Grca.
* Copyright 2017-2020 Fred N. van Kempen.
* Copyright 2021 Laci bá'
*/
#include <inttypes.h>
#include <stdarg.h>
@@ -395,6 +396,7 @@ pc_init(int argc, char *argv[])
int c, vmrp = 0;
int ng = 0, lvmp = 0;
uint32_t *uid, *shwnd;
uint32_t lang_init = 0;
/* Grab the executable's full path. */
plat_get_exe_name(exe_path, sizeof(exe_path)-1);
@@ -519,7 +521,8 @@ usage:
//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");
//The return value of 0 only means that the code is invalid,
@@ -703,6 +706,18 @@ usage:
/* Load the configuration file. */
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! */
return(1);
}

View File

@@ -15,6 +15,7 @@
*
* Copyright 2016-2020 Miran Grca.
* Copyright 2017-2020 Fred N. van Kempen.
* Copyright 2021 Laci bá'
*/
#ifndef 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 */
invert_display, /* (C) invert the display */
suppress_overscan; /* (C) suppress overscans */
extern uint32_t lang_id; /* (C) language code identifier */
extern int scale; /* (C) screen scale factor */
extern int dpi_scale; /* (C) DPI scaling of the emulated screen */
extern int vid_api; /* (C) video renderer */

View File

@@ -15,6 +15,7 @@
*
* Copyright 2016-2019 Miran Grca.
* Copyright 2017-2019 Fred N. van Kempen.
* Copyright 2021 Laci bá'
*/
#ifndef 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_vidapi_enable(int enabled);
extern void plat_vid_reload_options(void);
extern int plat_set_language(char* langcode);
extern uint32_t plat_language_code(char* langcode);
/* Resource management. */
extern void set_language(int id);
extern void set_language(uint32_t id);
extern wchar_t *plat_get_string(int id);

View File

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

View File

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

View File

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

View File

@@ -15,6 +15,7 @@
*
* Copyright 2016-2019 Miran Grca.
* Copyright 2018,2019 David Hrdlička.
* Copyright 2021 Laci bá'
*/
#define UNICODE
#define BITMAP WINDOWS_BITMAP
@@ -78,7 +79,7 @@ static int first_cat = 0;
static int dpi = 96;
/* Language */
static int temp_language;
static LCID temp_language;
/* Machine category */
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);
}
int enum_helper = -1, c = 0;
int enum_helper, c;
BOOL CALLBACK
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];
LCIDToLocaleName(wIDLanguage, temp, LOCALE_NAME_MAX_LENGTH, 0);
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;
c++;
return 1;
}
@@ -342,9 +345,13 @@ win_fill_languages(HWND hdlg)
HWND lang_combo = GetDlgItem(hdlg, IDC_COMBO_LANG);
SendMessage(lang_combo, CB_RESETCONTENT, 0, 0);
enum_helper = -1; c = 0;
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);
pclog("win_fill_languages\n");
}
/* This does the initial read of global variables into the temporary ones. */
@@ -354,6 +361,8 @@ win_settings_init(void)
int i = 0;
/* Language */
temp_language = lang_id;
pclog("temp_language is %u\n", lang_id);
win_fill_languages(hwndParentDialog);
/* Machine category */
@@ -482,7 +491,7 @@ win_settings_changed(void)
int i = 0, j = 0;
/* Language */
// i = i || has_language_changed(temp_language);
i = i || has_language_changed(temp_language);
/* Machine category */
i = i || (machine != temp_machine);
@@ -575,7 +584,7 @@ win_settings_save(void)
pc_reset_hard_close();
/* Language */
// set_language(temp_language);
set_language(temp_language);
/* Machine category */
machine = temp_machine;
@@ -5229,6 +5238,13 @@ win_settings_main_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
EndDialog(hdlg, 0);
win_notify_dlg_closed();
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;