📄 nums.c
字号:
/*
* PROJECT: ReactOS International Control Panel
* LICENSE: GPL - See COPYING in the top level directory
* FILE: dll/cpl/intl/nums.c
* PURPOSE: ReactOS International Control Panel
* PROGRAMMERS: Alexey Zavyalov (gen_x@mail.ru)
*/
/* INCLUDES *****************************************************************/
#include <windows.h>
#include <commctrl.h>
#include <cpl.h>
#include "intl.h"
#include "resource.h"
/* GLOBALS ******************************************************************/
#define SAMPLE_NUMBER L"123456789"
#define SAMPLE_NEG_NUMBER L"-123456789"
#define MAX_NUM_SEP_SAMPLES 2
#define MAX_FRAC_NUM_SAMPLES 9
#define MAX_FIELD_SEP_SAMPLES 1
#define MAX_FIELD_DIG_SAMPLES 3
#define MAX_NEG_SIGN_SAMPLES 1
#define MAX_NEG_NUMBERS_SAMPLES 5
#define MAX_LEAD_ZEROES_SAMPLES 2
#define MAX_LIST_SEP_SAMPLES 1
#define MAX_UNITS_SYS_SAMPLES 2
#define EOLN_SIZE sizeof(WCHAR)
/* FUNCTIONS ****************************************************************/
/* Init system of units control box */
VOID
InitUnitsSysCB(HWND hwndDlg)
{
WCHAR wszUnitsSysSamples[MAX_UNITS_SYS_SAMPLES][MAX_SAMPLES_STR_SIZE]=
{
L"Metrics",
L"Americans"
};
int nCBIndex;
int nRetCode;
DWORD dwValueSize=MAX_SAMPLES_STR_SIZE*sizeof(WCHAR)+EOLN_SIZE;
WCHAR wszUnitsSys[MAX_SAMPLES_STR_SIZE];
/* Get current system of units */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_IMEASURE,
wszUnitsSys,
dwValueSize);
/* Clear all box content */
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMUNITSSYS_COMBO),
CB_RESETCONTENT,
(WPARAM)0,
(LPARAM)0);
/* Create list of standart system of units */
for(nCBIndex=0;nCBIndex<MAX_UNITS_SYS_SAMPLES;nCBIndex++)
{
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMUNITSSYS_COMBO),
CB_ADDSTRING,
nCBIndex,
(LPARAM)wszUnitsSysSamples[nCBIndex]);
}
/* Set current item to value from registry */
nRetCode = SendMessageW(GetDlgItem(hwndDlg, IDC_NUMUNITSSYS_COMBO),
CB_SETCURSEL,
(WPARAM)_wtoi(wszUnitsSys),
(LPARAM)0);
}
/* Init elements list separator control box */
VOID
InitListSepCB(HWND hwndDlg)
{
WCHAR wszListSepSamples[MAX_LIST_SEP_SAMPLES][MAX_SAMPLES_STR_SIZE]=
{
L";"
};
int nCBIndex;
int nRetCode;
DWORD dwValueSize=MAX_SAMPLES_STR_SIZE*sizeof(WCHAR)+EOLN_SIZE;
WCHAR wszListSep[MAX_SAMPLES_STR_SIZE];
/* Get current list separator */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_SLIST,
wszListSep,
dwValueSize);
/* Clear all box content */
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMELEMLISTSEP_COMBO),
CB_RESETCONTENT,
(WPARAM)0,
(LPARAM)0);
/* Create standart list of signs */
for(nCBIndex=0;nCBIndex<MAX_LIST_SEP_SAMPLES;nCBIndex++)
{
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMELEMLISTSEP_COMBO),
CB_ADDSTRING,
nCBIndex,
(LPARAM)wszListSepSamples[nCBIndex]);
}
/* Set current item to value from registry */
nRetCode = SendMessageW(GetDlgItem(hwndDlg, IDC_NUMELEMLISTSEP_COMBO),
CB_SELECTSTRING,
-1,
(LPARAM)(LPCSTR)wszListSep);
/* if is not success, add new value to list and select them */
if(nRetCode == CB_ERR)
{
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMELEMLISTSEP_COMBO),
CB_ADDSTRING,
MAX_LIST_SEP_SAMPLES+1,
(LPARAM)wszListSep);
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMELEMLISTSEP_COMBO),
CB_SELECTSTRING,
-1,
(LPARAM)(LPCSTR)wszListSep);
}
}
/* Init leading zeroes control box */
VOID
InitLeadingZeroesCB(HWND hwndDlg)
{
WCHAR wszLeadNumFmtSamples[MAX_LEAD_ZEROES_SAMPLES][MAX_SAMPLES_STR_SIZE]=
{
L",7",
L"0,7"
};
int nCBIndex;
int nRetCode;
WCHAR wszLeadNumFmt[MAX_SAMPLES_STR_SIZE];
WCHAR wszNumSep[MAX_SAMPLES_STR_SIZE];
WCHAR* pwszResultStr;
DWORD dwValueSize=MAX_SAMPLES_STR_SIZE*sizeof(WCHAR)+EOLN_SIZE;
/* Get current leading zeroes format */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_ILZERO,
wszLeadNumFmt,
dwValueSize);
/* Clear all box content */
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMLEADZERO_COMBO),
CB_RESETCONTENT,
(WPARAM)0,
(LPARAM)0);
/* Get current decimal separator */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_SDECIMAL,
wszNumSep,
dwValueSize);
/* Create list of standart leading zeroes formats */
for(nCBIndex=0;nCBIndex<MAX_LEAD_ZEROES_SAMPLES;nCBIndex++)
{
pwszResultStr = ReplaceSubStr(wszLeadNumFmtSamples[nCBIndex],
wszNumSep,
L",");
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMLEADZERO_COMBO),
CB_ADDSTRING,
nCBIndex,
(LPARAM)pwszResultStr);
free(pwszResultStr);
}
/* Set current item to value from registry */
nRetCode = SendMessageW(GetDlgItem(hwndDlg, IDC_NUMLEADZERO_COMBO),
CB_SETCURSEL,
(WPARAM)_wtoi(wszLeadNumFmt),
(LPARAM)0);
}
/* Init negative numbers format control box */
VOID
InitNegNumFmtCB(HWND hwndDlg)
{
WCHAR wszNegNumFmtSamples[MAX_NEG_NUMBERS_SAMPLES][MAX_SAMPLES_STR_SIZE]=
{
L"(1,1)",
L"-1,1",
L"- 1,1",
L"1,1-",
L"1,1 -"
};
int nCBIndex;
int nRetCode;
WCHAR wszNegNumFmt[MAX_SAMPLES_STR_SIZE];
WCHAR wszNumSep[MAX_SAMPLES_STR_SIZE];
WCHAR wszNegSign[MAX_SAMPLES_STR_SIZE];
WCHAR wszNewSample[MAX_SAMPLES_STR_SIZE];
WCHAR* pwszResultStr;
DWORD dwValueSize=MAX_SAMPLES_STR_SIZE*sizeof(WCHAR)+EOLN_SIZE;
/* Get current negative numbers format */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_INEGNUMBER,
wszNegNumFmt,
dwValueSize);
/* Clear all box content */
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMNEGFMT_COMBO),
CB_RESETCONTENT,
(WPARAM)0,
(LPARAM)0);
/* Get current decimal separator */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_SDECIMAL,
wszNumSep,
dwValueSize);
/* Get current negative sign */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_SNEGATIVESIGN,
wszNegSign,
dwValueSize);
/* Create standart list of negative numbers formats */
for(nCBIndex=0;nCBIndex<MAX_NEG_NUMBERS_SAMPLES;nCBIndex++)
{
/* Replace standart separator to setted */
pwszResultStr = ReplaceSubStr(wszNegNumFmtSamples[nCBIndex],
wszNumSep,
L",");
wcscpy(wszNewSample,pwszResultStr);
free(pwszResultStr);
/* Replace standart negative sign to setted */
pwszResultStr = ReplaceSubStr(wszNewSample,
wszNegSign,
L"-");
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMNEGFMT_COMBO),
CB_ADDSTRING,
nCBIndex,
(LPARAM)pwszResultStr);
free(pwszResultStr);
}
/* Set current item to value from registry */
nRetCode = SendMessageW(GetDlgItem(hwndDlg, IDC_NUMNEGFMT_COMBO),
CB_SETCURSEL,
(WPARAM)_wtoi(wszNegNumFmt),
(LPARAM)0);
}
/* Init negative sign control box */
VOID
InitNegSignCB(HWND hwndDlg)
{
WCHAR wszNegSignSamples[MAX_NEG_SIGN_SAMPLES][MAX_SAMPLES_STR_SIZE]=
{
L"-"
};
int nCBIndex;
int nRetCode;
DWORD dwValueSize=MAX_SAMPLES_STR_SIZE*sizeof(WCHAR)+EOLN_SIZE;
WCHAR wszNegSign[MAX_SAMPLES_STR_SIZE];
/* Get current negative sign */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_SNEGATIVESIGN,
wszNegSign,
dwValueSize);
/* Clear all box content */
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMNEGSIGN_COMBO),
CB_RESETCONTENT,
(WPARAM)0,
(LPARAM)0);
/* Create standart list of signs */
for(nCBIndex=0;nCBIndex<MAX_NEG_SIGN_SAMPLES;nCBIndex++)
{
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMNEGSIGN_COMBO),
CB_ADDSTRING,
nCBIndex,
(LPARAM)wszNegSignSamples[nCBIndex]);
}
/* Set current item to value from registry */
nRetCode = SendMessageW(GetDlgItem(hwndDlg, IDC_NUMNEGSIGN_COMBO),
CB_SELECTSTRING,
-1,
(LPARAM)(LPCSTR)wszNegSign);
/* if is not success, add new value to list and select them */
if(nRetCode == CB_ERR)
{
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMNEGSIGN_COMBO),
CB_ADDSTRING,
MAX_NUM_SEP_SAMPLES+1,
(LPARAM)wszNegSign);
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMNEGSIGN_COMBO),
CB_SELECTSTRING,
-1,
(LPARAM)(LPCSTR)wszNegSign);
}
}
/* Init number of digidts in field control box */
VOID
InitFieldDigNumCB(HWND hwndDlg)
{
WCHAR wszFieldDigNumSamples[MAX_FIELD_DIG_SAMPLES][MAX_SAMPLES_STR_SIZE]=
{
L"0;0",
L"3;0",
L"3;2;0"
};
int nCBIndex;
int nRetCode;
DWORD dwValueSize=MAX_SAMPLES_STR_SIZE*sizeof(WCHAR)+EOLN_SIZE;
WCHAR wszFieldDigNum[MAX_SAMPLES_STR_SIZE];
WCHAR* pwszFieldDigNumSmpl;
/* Get current field digits num */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_SGROUPING,
wszFieldDigNum,
dwValueSize);
/* Clear all box content */
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMDIGFIELD_COMBO),
CB_RESETCONTENT,
(WPARAM)0,
(LPARAM)0);
/* Create standart list of field digits num */
for(nCBIndex=0;nCBIndex<MAX_FIELD_DIG_SAMPLES;nCBIndex++)
{
pwszFieldDigNumSmpl=InsSpacesFmt(SAMPLE_NUMBER,wszFieldDigNumSamples[nCBIndex]);
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMDIGFIELD_COMBO),
CB_ADDSTRING,
nCBIndex,
(LPARAM)pwszFieldDigNumSmpl);
free(pwszFieldDigNumSmpl);
}
pwszFieldDigNumSmpl=InsSpacesFmt(SAMPLE_NUMBER,wszFieldDigNum);
/* Set current item to value from registry */
nRetCode = SendMessageW(GetDlgItem(hwndDlg, IDC_NUMDIGFIELD_COMBO),
CB_SELECTSTRING,
-1,
(LPARAM)(LPCSTR)pwszFieldDigNumSmpl);
/* if is not success, add new value to list and select them */
if(nRetCode == CB_ERR)
{
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMDIGFIELD_COMBO),
CB_ADDSTRING,
MAX_FIELD_DIG_SAMPLES+1,
(LPARAM)pwszFieldDigNumSmpl);
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMDIGFIELD_COMBO),
CB_SELECTSTRING,
-1,
(LPARAM)(LPCSTR)pwszFieldDigNumSmpl);
}
free(pwszFieldDigNumSmpl);
}
/* Init field separator control box */
VOID
InitNumFieldSepCB(HWND hwndDlg)
{
WCHAR wszFieldSepSamples[MAX_FIELD_SEP_SAMPLES][MAX_SAMPLES_STR_SIZE]=
{
L" "
};
int nCBIndex;
int nRetCode;
DWORD dwValueSize=MAX_SAMPLES_STR_SIZE*sizeof(WCHAR)+EOLN_SIZE;
WCHAR wszFieldSep[MAX_SAMPLES_STR_SIZE];
/* Get current field separator */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_STHOUSAND,
wszFieldSep,
dwValueSize);
/* Clear all box content */
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMFIELDSEP_COMBO),
CB_RESETCONTENT,
(WPARAM)0,
(LPARAM)0);
/* Create standart list of field separators */
for(nCBIndex=0;nCBIndex<MAX_FIELD_SEP_SAMPLES;nCBIndex++)
{
SendMessageW(GetDlgItem(hwndDlg, IDC_NUMFIELDSEP_COMBO),
CB_ADDSTRING,
nCBIndex,
(LPARAM)wszFieldSepSamples[nCBIndex]);
}
/* Set current item to value from registry */
nRetCode = SendMessageW(GetDlgItem(hwndDlg, IDC_NUMFIELDSEP_COMBO),
CB_SELECTSTRING,
-1,
(LPARAM)(LPCSTR)wszFieldSep);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -