[Ttssh2-commit] [8569] ドロップダウンリストなどを多言語化するための SetI18nList() を追加

scmno****@osdn***** scmno****@osdn*****
2020年 2月 27日 (木) 01:27:42 JST


Revision: 8569
          https://osdn.net/projects/ttssh2/scm/svn/commits/8569
Author:   zmatsuo
Date:     2020-02-27 01:27:42 +0900 (Thu, 27 Feb 2020)
Log Message:
-----------
ドロップダウンリストなどを多言語化するための SetI18nList() を追加

- addsetting.cpp のリスト初期化に使用

Modified Paths:
--------------
    trunk/teraterm/common/i18n.h
    trunk/teraterm/common/i18n_static.c
    trunk/teraterm/teraterm/addsetting.cpp

-------------- next part --------------
Modified: trunk/teraterm/common/i18n.h
===================================================================
--- trunk/teraterm/common/i18n.h	2020-02-26 16:27:26 UTC (rev 8568)
+++ trunk/teraterm/common/i18n.h	2020-02-26 16:27:42 UTC (rev 8569)
@@ -46,9 +46,13 @@
 	const char *key;
 } DlgTextInfo;
 
+typedef struct {
+	const char *key;				// NULL\x82̏ꍇ\x82͏\xED\x82\xC9default_text \x82\xAA\x8Eg\x97p\x82\xB3\x82\xEA\x82\xE9
+	const wchar_t *default_text;	// key == NULL && default_text == NULL\x82̏ꍇ\x8FI\x92[
+} I18nTextInfo;
+
 DllExport void WINAPI GetI18nStrW(const char *section, const char *key, wchar_t *buf, int buf_len, const wchar_t *def, const char *iniFile);
 DllExport void WINAPI GetI18nStr(const char *section, const char *key, PCHAR buf, int buf_len, const char *def, const char *iniFile);
-void GetI18nStrU8(const char* section, const char* key, char* buf, int buf_len, const char* def, const char* iniFile);
 DllExport int WINAPI GetI18nLogfont(const char *section, const char *key, PLOGFONTA logfont, int ppi, const char *iniFile);
 DllExport int WINAPI SetI18nDlgStrs(const char *section, HWND hDlgWnd,
 							 const DlgTextInfo *infos, size_t infoCount, const char *UILanguageFile);
@@ -55,6 +59,11 @@
 DllExport void WINAPI SetI18nMenuStrs(const char *section, HMENU hMenu,
 							  const DlgTextInfo *infos, size_t infoCount, const char *UILanguageFile);
 
+// i18n_static.c
+void GetI18nStrU8(const char *section, const char *key, char *buf, int buf_len, const char *def, const char *iniFile);
+void SetI18nList(const char *section, HWND hDlg, int nIDDlgItem, const I18nTextInfo *infos, size_t infoCount,
+				 const char *UILanguageFile, int nsel);
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/teraterm/common/i18n_static.c
===================================================================
--- trunk/teraterm/common/i18n_static.c	2020-02-26 16:27:26 UTC (rev 8568)
+++ trunk/teraterm/common/i18n_static.c	2020-02-26 16:27:42 UTC (rev 8569)
@@ -29,6 +29,7 @@
 #include "i18n.h"
 #include "codeconv.h"
 #include "compat_win.h"
+#include "layer_for_unicode.h"
 
 #include <assert.h>
 
@@ -60,4 +61,62 @@
 	}
 }
 
+/**
+ *	\x83\x8A\x83X\x83g\x82\xF0\x90ݒ肷\x82\xE9
+ *	SetDropDownList() \x82̑\xBC\x8C\xBE\x8C\xEA\x94\xC5
+ *
+ *	@param[in]	section			UILanguageFile \x82̃Z\x83N\x83V\x83\x87\x83\x93\x96\xBC
+ *	@param[in]	hDlg			\x83_\x83C\x83A\x83\x8D\x83O
+ *	@param[in]	nIDDlgItem		id
+ *	@param[in]	I18nTextInfo	\x83e\x83L\x83X\x83g\x8F\xEE\x95\xF1
+ *	@param[in]	infoCount		\x83e\x83L\x83X\x83g\x8F\xEE\x95\xF1\x90\x94
+ *	@param[in]	UILanguageFile	lng file
+ *	@param[in]	nsel			CB_SETCURSEL \x82̈\xF8\x90\x94\x82Ɠ\xAF\x82\xB6
+ *								-1	\x96\xA2\x91I\x91\xF0
+ *								0\x81`	\x91I\x91\xF0\x8D\x80\x96\xDA
+ */
+void SetI18nList(const char *section, HWND hDlg, int nIDDlgItem, const I18nTextInfo *infos, size_t infoCount,
+				 const char *UILanguageFile, int nsel)
+{
+	UINT ADDSTRING;
+	UINT SETCURSEL;
+	int i;
+	char ClassName[32];
+	int r = GetClassNameA(GetDlgItem(hDlg, nIDDlgItem), ClassName, _countof(ClassName));
+	assert(r != 0);
+	(void)r;
+
+	if (strcmp(ClassName, "ListBox") == 0) {
+		ADDSTRING = LB_ADDSTRING;
+		SETCURSEL = LB_SETCURSEL;
+	}
+	else {
+		// "ComboBox"
+		ADDSTRING = CB_ADDSTRING;
+		SETCURSEL = CB_SETCURSEL;
+	}
+
+	if (infoCount == 0) {
+		// 0 \x82̂Ƃ\xAB\x82́A\x8FI\x92[\x82\xF0\x92T\x82\xB7
+		i = 0;
+		while (infos[i].key != NULL && infos[i].default_text != NULL) {
+			i++;
+		}
+		infoCount = i;
+	}
+
+	for (i = 0; i < infoCount; i++) {
+		if (infos->key != NULL) {
+			wchar_t uimsg[MAX_UIMSG];
+			GetI18nStrW(section, infos->key, uimsg, _countof(uimsg), infos->default_text, UILanguageFile);
+			_SendDlgItemMessageW(hDlg, nIDDlgItem, ADDSTRING, 0, (LPARAM)uimsg);
+		}
+		else {
+			_SendDlgItemMessageW(hDlg, nIDDlgItem, ADDSTRING, 0, (LPARAM)infos->default_text);
+		}
+		infos++;
+	}
+	SendDlgItemMessageA(hDlg, nIDDlgItem, SETCURSEL, nsel, 0);
+}
+
 /* vim: set ts=4 sw=4 ff=dos : */

Modified: trunk/teraterm/teraterm/addsetting.cpp
===================================================================
--- trunk/teraterm/teraterm/addsetting.cpp	2020-02-26 16:27:26 UTC (rev 8568)
+++ trunk/teraterm/teraterm/addsetting.cpp	2020-02-26 16:27:42 UTC (rev 8569)
@@ -40,6 +40,7 @@
 #define _CRTDBG_MAP_ALLOC
 #include <stdlib.h>
 #include <crtdbg.h>
+#include <assert.h>
 
 #include "teraterm.h"
 #include "tttypes.h"
@@ -51,8 +52,8 @@
 #include "helpid.h"
 #include "addsetting.h"
 #include "debug_pp.h"
-
 #include "tipwin.h"
+#include "i18n.h"
 
 const mouse_cursor_t MouseCursor[] = {
 	{"ARROW", IDC_ARROW},
@@ -246,31 +247,31 @@
 	};
 	SetDlgTexts(m_hWnd, TextInfos, _countof(TextInfos), ts.UILanguageFile);
 
-	wchar_t uimsg[MAX_UIMSG];
-	get_lang_msgW("DLG_TAB_SEQUENCE_ACCEPT_TITLE_CHANGING_OFF", uimsg, _countof(uimsg), L"off", ts.UILanguageFile);
-	SendDlgItemMessageW(IDC_ACCEPT_TITLE_CHANGING, CB_ADDSTRING, 0, (LPARAM)uimsg);
-	get_lang_msgW("DLG_TAB_SEQUENCE_ACCEPT_TITLE_CHANGING_OVERWRITE", uimsg, _countof(uimsg), L"overwrite", ts.UILanguageFile);
-	SendDlgItemMessageW(IDC_ACCEPT_TITLE_CHANGING, CB_ADDSTRING, 0, (LPARAM)uimsg);
-	get_lang_msgW("DLG_TAB_SEQUENCE_ACCEPT_TITLE_CHANGING_AHEAD", uimsg, _countof(uimsg), L"ahead", ts.UILanguageFile);
-	SendDlgItemMessageW(IDC_ACCEPT_TITLE_CHANGING, CB_ADDSTRING, 0, (LPARAM)uimsg);
-	get_lang_msgW("DLG_TAB_SEQUENCE_ACCEPT_TITLE_CHANGING_LAST", uimsg, _countof(uimsg), L"last", ts.UILanguageFile);
-	SendDlgItemMessageW(IDC_ACCEPT_TITLE_CHANGING, CB_ADDSTRING, 0, (LPARAM)uimsg);
+	const static I18nTextInfo accept_title_changing[] = {
+		{ "DLG_TAB_SEQUENCE_ACCEPT_TITLE_CHANGING_OFF", L"off" },
+		{ "DLG_TAB_SEQUENCE_ACCEPT_TITLE_CHANGING_OVERWRITE", L"overwrite" },
+		{ "DLG_TAB_SEQUENCE_ACCEPT_TITLE_CHANGING_AHEAD", L"ahead" },
+		{ "DLG_TAB_SEQUENCE_ACCEPT_TITLE_CHANGING_LAST", L"last" },
+	};
+	SetI18nList("Tera Term", m_hWnd, IDC_ACCEPT_TITLE_CHANGING, accept_title_changing, _countof(accept_title_changing),
+				ts.UILanguageFile, 0);
 
-	get_lang_msgW("DLG_TAB_SEQUENCE_TITLE_REPORT_IGNORE", uimsg, _countof(uimsg), L"ignore", ts.UILanguageFile);
-	SendDlgItemMessageW(IDC_TITLE_REPORT, CB_ADDSTRING, 0, (LPARAM)uimsg);
-	get_lang_msgW("DLG_TAB_SEQUENCE_TITLE_REPORT_ACCEPT", uimsg, _countof(uimsg), L"accept", ts.UILanguageFile);
-	SendDlgItemMessageW(IDC_TITLE_REPORT, CB_ADDSTRING, 0, (LPARAM)uimsg);
-	get_lang_msgW("DLG_TAB_SEQUENCE_TITLE_REPORT_EMPTY", uimsg, _countof(uimsg), L"empty", ts.UILanguageFile);
-	SendDlgItemMessageW(IDC_TITLE_REPORT, CB_ADDSTRING, 0, (LPARAM)uimsg);
+	const static I18nTextInfo sequence_title_report[] = {
+		{ "DLG_TAB_SEQUENCE_TITLE_REPORT_IGNORE", L"ignore" },
+		{ "DLG_TAB_SEQUENCE_TITLE_REPORT_ACCEPT", L"accept" },
+		{ "DLG_TAB_SEQUENCE_TITLE_REPORT_EMPTY", L"empty" },
+	};
+	SetI18nList("Tera Term", m_hWnd, IDC_TITLE_REPORT, sequence_title_report, _countof(sequence_title_report),
+				ts.UILanguageFile, 0);
 
-	get_lang_msgW("DLG_TAB_SEQUENCE_CLIPBOARD_ACCESS_OFF", uimsg, _countof(uimsg), L"off", ts.UILanguageFile);
-	SendDlgItemMessageW(IDC_CLIPBOARD_ACCESS, CB_ADDSTRING, 0, (LPARAM)uimsg);
-	get_lang_msgW("DLG_TAB_SEQUENCE_CLIPBOARD_ACCESS_WRITE", uimsg, _countof(uimsg), L"write only", ts.UILanguageFile);
-	SendDlgItemMessageW(IDC_CLIPBOARD_ACCESS, CB_ADDSTRING, 0, (LPARAM)uimsg);
-	get_lang_msgW("DLG_TAB_SEQUENCE_CLIPBOARD_ACCESS_READ", uimsg, _countof(uimsg), L"read only", ts.UILanguageFile);
-	SendDlgItemMessageW(IDC_CLIPBOARD_ACCESS, CB_ADDSTRING, 0, (LPARAM)uimsg);
-	get_lang_msgW("DLG_TAB_SEQUENCE_CLIPBOARD_ACCESS_ON", uimsg, _countof(uimsg), L"read/write", ts.UILanguageFile);
-	SendDlgItemMessageW(IDC_CLIPBOARD_ACCESS, CB_ADDSTRING, 0, (LPARAM)uimsg);
+	const static I18nTextInfo sequence_clipboard_access[] = {
+		{ "DLG_TAB_SEQUENCE_CLIPBOARD_ACCESS_OFF", L"off" },
+		{ "DLG_TAB_SEQUENCE_CLIPBOARD_ACCESS_WRITE", L"write only" },
+		{ "DLG_TAB_SEQUENCE_CLIPBOARD_ACCESS_READ", L"read only" },
+		{ "DLG_TAB_SEQUENCE_CLIPBOARD_ACCESS_ON", L"read/write" },
+	};
+	SetI18nList("Tera Term", m_hWnd, IDC_CLIPBOARD_ACCESS, sequence_clipboard_access,
+				_countof(sequence_clipboard_access), ts.UILanguageFile, 0);
 
 	// (1)IDC_ACCEPT_MOUSE_EVENT_TRACKING
 	SetCheck(IDC_ACCEPT_MOUSE_EVENT_TRACKING, ts.MouseEventTracking);
@@ -666,19 +667,14 @@
 	};
 	SetDlgTexts(m_hWnd, TextInfos, _countof(TextInfos), ts.UILanguageFile);
 
-	wchar_t uimsg[MAX_UIMSG];
-	get_lang_msgW("DLG_TAB_VISUAL_FONT_QUALITY_DEFAULT",
-				  uimsg, _countof(uimsg), L"Default", ts.UILanguageFile);
-	SendDlgItemMessageW(IDC_FONT_QUALITY, CB_ADDSTRING, 0, (LPARAM)uimsg);
-	get_lang_msgW("DLG_TAB_VISUAL_FONT_QUALITY_NONANTIALIASED",
-				  uimsg, _countof(uimsg), L"Non-Antialiased", ts.UILanguageFile);
-	SendDlgItemMessageW(IDC_FONT_QUALITY, CB_ADDSTRING, 0, (LPARAM)uimsg);
-	get_lang_msgW("DLG_TAB_VISUAL_FONT_QUALITY_ANTIALIASED",
-				  uimsg, _countof(uimsg), L"Antialiased", ts.UILanguageFile);
-	SendDlgItemMessageW(IDC_FONT_QUALITY, CB_ADDSTRING, 0, (LPARAM)uimsg);
-	get_lang_msgW("DLG_TAB_VISUAL_FONT_QUALITY_CLEARTYPE",
-				  uimsg, _countof(uimsg), L"ClearType", ts.UILanguageFile);
-	SendDlgItemMessageW(IDC_FONT_QUALITY, CB_ADDSTRING, 0, (LPARAM)uimsg);
+	const static I18nTextInfo visual_font_quality[] = {
+		{ "DLG_TAB_VISUAL_FONT_QUALITY_DEFAULT", L"Default" },
+		{ "DLG_TAB_VISUAL_FONT_QUALITY_NONANTIALIASED", L"Non-Antialiased" },
+		{ "DLG_TAB_VISUAL_FONT_QUALITY_ANTIALIASED", L"Antialiased" },
+		{ "DLG_TAB_VISUAL_FONT_QUALITY_CLEARTYPE", L"ClearType" },
+	};
+	SetI18nList("Tera Term", m_hWnd, IDC_FONT_QUALITY, visual_font_quality, _countof(visual_font_quality),
+				ts.UILanguageFile, 0);
 
 	// (1)AlphaBlend
 
@@ -1298,17 +1294,15 @@
 	};
 	SetDlgTexts(m_hWnd, TextInfos, _countof(TextInfos), ts.UILanguageFile);
 
-	TCHAR UIMsg[MAX_UIMSG];
-	get_lang_msgT("DLG_FOPT_TIMESTAMP_LOCAL", UIMsg, _countof(UIMsg), _T("Local Time"), ts.UILanguageFile);
-	SendDlgItemMessage(IDC_OPT_TIMESTAMP_TYPE, CB_ADDSTRING, 0, (LPARAM)UIMsg);
-	get_lang_msgT("DLG_FOPT_TIMESTAMP_UTC", UIMsg, _countof(UIMsg), _T("UTC"), ts.UILanguageFile);
-	SendDlgItemMessage(IDC_OPT_TIMESTAMP_TYPE, CB_ADDSTRING, 0, (LPARAM)UIMsg);
-	get_lang_msgT("DLG_FOPT_TIMESTAMP_ELAPSED_LOGGING", UIMsg, _countof(UIMsg), _T("Elapsed Time (Logging)"), ts.UILanguageFile);
-	SendDlgItemMessage(IDC_OPT_TIMESTAMP_TYPE, CB_ADDSTRING, 0, (LPARAM)UIMsg);
-	get_lang_msgT("DLG_FOPT_TIMESTAMP_ELAPSED_CONNECTION", UIMsg, _countof(UIMsg), _T("Elapsed Time (Connection)"), ts.UILanguageFile);
-	SendDlgItemMessage(IDC_OPT_TIMESTAMP_TYPE, CB_ADDSTRING, 0, (LPARAM)UIMsg);
+	const static I18nTextInfo fopt_timestamp[] = {
+		{ "DLG_FOPT_TIMESTAMP_LOCAL", L"Local Time" },
+		{ "DLG_FOPT_TIMESTAMP_UTC", L"UTC" },
+		{ "DLG_FOPT_TIMESTAMP_ELAPSED_LOGGING", L"Elapsed Time (Logging)" },
+		{ "DLG_FOPT_TIMESTAMP_ELAPSED_CONNECTION", L"Elapsed Time (Connection)" },
+	};
+	SetI18nList("Tera Term", m_hWnd, IDC_OPT_TIMESTAMP_TYPE, fopt_timestamp, _countof(fopt_timestamp),
+				ts.UILanguageFile, 0);
 
-
 	// Viewlog Editor path (2005.1.29 yutaka)
 	SetDlgItemTextA(IDC_VIEWLOG_EDITOR, ts.ViewlogEditor);
 


Ttssh2-commit メーリングリストの案内