📄 currency.c
字号:
/*
* PROJECT: ReactOS International Control Panel
* LICENSE: GPL - See COPYING in the top level directory
* FILE: dll/cpl/intl/monetary.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_CURRENCY_UNIT_SAMPLES 2
#define MAX_POS_CURRENCY_SAMPLES 4
#define MAX_NEG_CURRENCY_SAMPLES 16
#define MAX_CURRENCY_SEP_SAMPLES 2
#define MAX_CURRENCY_FRAC_SAMPLES 10
#define MAX_FIELD_SEP_SAMPLES 1
#define MAX_FIELD_DIG_SAMPLES 3
#define EOLN_SIZE sizeof(WCHAR)
/* FUNCTIONS ****************************************************************/
/* Init number of digidts in field control box */
VOID
InitCurrencyDigNumCB(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_SMONGROUPING,
wszFieldDigNum,
dwValueSize);
/* Clear all box content */
SendMessageW(GetDlgItem(hwndDlg, IDC_DIGINFIELDNUM_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_DIGINFIELDNUM_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_DIGINFIELDNUM_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_DIGINFIELDNUM_COMBO),
CB_ADDSTRING,
MAX_FIELD_DIG_SAMPLES+1,
(LPARAM)pwszFieldDigNumSmpl);
SendMessageW(GetDlgItem(hwndDlg, IDC_DIGINFIELDNUM_COMBO),
CB_SELECTSTRING,
-1,
(LPARAM)(LPCSTR)pwszFieldDigNumSmpl);
}
free(pwszFieldDigNumSmpl);
}
/* Init currency field separator control box */
VOID
InitCurrencyFieldSepCB(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_SMONTHOUSANDSEP,
wszFieldSep,
dwValueSize);
/* Clear all box content */
SendMessageW(GetDlgItem(hwndDlg, IDC_FIELDSEP_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_FIELDSEP_COMBO),
CB_ADDSTRING,
nCBIndex,
(LPARAM)wszFieldSepSamples[nCBIndex]);
}
/* Set current item to value from registry */
nRetCode = SendMessageW(GetDlgItem(hwndDlg, IDC_FIELDSEP_COMBO),
CB_SELECTSTRING,
-1,
(LPARAM)(LPCSTR)wszFieldSep);
/* if is not success, add new value to list and select them */
if(nRetCode == CB_ERR)
{
SendMessageW(GetDlgItem(hwndDlg, IDC_FIELDSEP_COMBO),
CB_ADDSTRING,
MAX_FIELD_SEP_SAMPLES+1,
(LPARAM)wszFieldSep);
SendMessageW(GetDlgItem(hwndDlg, IDC_FIELDSEP_COMBO),
CB_SELECTSTRING,
-1,
(LPARAM)(LPCSTR)wszFieldSep);
}
}
/* Init number of fractional symbols control box */
VOID
InitCurrencyFracNumCB(HWND hwndDlg)
{
int nCBIndex;
int nRetCode;
DWORD dwValueSize=MAX_SAMPLES_STR_SIZE*sizeof(WCHAR)+EOLN_SIZE;
WCHAR wszCurrencyFracNum[MAX_SAMPLES_STR_SIZE];
WCHAR wszFracCount[MAX_SAMPLES_STR_SIZE];
/* Get current number of fractional symbols */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_ICURRDIGITS,
wszCurrencyFracNum,
dwValueSize);
/* Clear all box content */
SendMessageW(GetDlgItem(hwndDlg, IDC_FRACSYMBSNUM_COMBO),
CB_RESETCONTENT,
(WPARAM)0,
(LPARAM)0);
/* Create standart list of fractional symbols */
for(nCBIndex=0;nCBIndex<MAX_CURRENCY_FRAC_SAMPLES;nCBIndex++)
{
/* convert to wide char */
_itow(nCBIndex,wszFracCount,DECIMAL_RADIX);
SendMessageW(GetDlgItem(hwndDlg, IDC_FRACSYMBSNUM_COMBO),
CB_ADDSTRING,
nCBIndex,
(LPARAM)wszFracCount);
}
/* Set current item to value from registry */
nRetCode = SendMessageW(GetDlgItem(hwndDlg, IDC_FRACSYMBSNUM_COMBO),
CB_SETCURSEL,
(WPARAM)_wtoi(wszCurrencyFracNum),
(LPARAM)0);
}
/* Init positive currency sum format control box */
VOID
InitPosCurrencySumCB(HWND hwndDlg)
{
WCHAR wszPosCurrencySumSamples[MAX_POS_CURRENCY_SAMPLES][MAX_SAMPLES_STR_SIZE]=
{
L"$1,1",
L"1,1$",
L"$ 1,1",
L"1,1 $"
};
int nCBIndex;
int nRetCode;
WCHAR wszCurrPosFmt[MAX_SAMPLES_STR_SIZE];
WCHAR wszCurrencyUnit[MAX_SAMPLES_STR_SIZE];
WCHAR wszNewSample[MAX_SAMPLES_STR_SIZE];
WCHAR wszCurrencySep[MAX_SAMPLES_STR_SIZE];
WCHAR* pwszResultStr;
DWORD dwValueSize=MAX_SAMPLES_STR_SIZE*sizeof(WCHAR)+EOLN_SIZE;
/* Get current currency sum format */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_ICURRENCY,
wszCurrPosFmt,
dwValueSize);
/* Clear all box content */
SendMessageW(GetDlgItem(hwndDlg, IDC_POSCURRENCYSUM_COMBO),
CB_RESETCONTENT,
(WPARAM)0,
(LPARAM)0);
/* Get current currency separator */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_SMONDECIMALSEP,
wszCurrencySep,
dwValueSize);
/* Get current currency unit */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_SCURRENCY,
wszCurrencyUnit,
dwValueSize);
/* Create standart list of currency sum formats */
for(nCBIndex=0;nCBIndex<MAX_POS_CURRENCY_SAMPLES;nCBIndex++)
{
pwszResultStr = ReplaceSubStr(wszPosCurrencySumSamples[nCBIndex],
wszCurrencyUnit,
L"$");
wcscpy(wszNewSample,pwszResultStr);
free(pwszResultStr);
pwszResultStr = ReplaceSubStr(wszNewSample,
wszCurrencySep,
L",");
SendMessageW(GetDlgItem(hwndDlg, IDC_POSCURRENCYSUM_COMBO),
CB_ADDSTRING,
nCBIndex,
(LPARAM)pwszResultStr);
free(pwszResultStr);
}
/* Set current item to value from registry */
nRetCode = SendMessageW(GetDlgItem(hwndDlg, IDC_POSCURRENCYSUM_COMBO),
CB_SETCURSEL,
(WPARAM)_wtoi(wszCurrPosFmt),
(LPARAM)0);
}
/* Init negative currency sum format control box */
VOID
InitNegCurrencySumCB(HWND hwndDlg)
{
WCHAR wszNegCurrencySumSamples[MAX_NEG_CURRENCY_SAMPLES][MAX_SAMPLES_STR_SIZE]=
{
L"(?1,1)",
L"-?1,1",
L"?-1,1",
L"?1,1-",
L"(1,1?)",
L"-1,1?",
L"1,1-?",
L"1,1?-",
L"-1,1 ?",
L"-? 1,1",
L"1,1 ?-",
L"? 1,1-",
L"? -1,1",
L"1,1- ?",
L"(? 1,1)",
L"(1,1 ?)" /* 16 */
};
int nCBIndex;
int nRetCode;
WCHAR wszCurrNegFmt[MAX_SAMPLES_STR_SIZE];
WCHAR wszCurrencyUnit[MAX_SAMPLES_STR_SIZE];
WCHAR wszCurrencySep[MAX_SAMPLES_STR_SIZE];
WCHAR wszNewSample[MAX_SAMPLES_STR_SIZE];
WCHAR* pwszResultStr;
DWORD dwValueSize=MAX_SAMPLES_STR_SIZE*sizeof(WCHAR)+EOLN_SIZE;
/* Get current currency sum format */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_INEGCURR,
wszCurrNegFmt,
dwValueSize);
/* Clear all box content */
SendMessageW(GetDlgItem(hwndDlg, IDC_NEGCURRENCYSUM_COMBO),
CB_RESETCONTENT,
(WPARAM)0,
(LPARAM)0);
/* Get current currency unit */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_SCURRENCY,
wszCurrencyUnit,
dwValueSize);
/* Get current currency separator */
GetLocaleInfoW(LOCALE_USER_DEFAULT,
LOCALE_SMONDECIMALSEP,
wszCurrencySep,
dwValueSize);
/* Create standart list of currency sum formats */
for(nCBIndex=0;nCBIndex<MAX_NEG_CURRENCY_SAMPLES;nCBIndex++)
{
pwszResultStr = ReplaceSubStr(wszNegCurrencySumSamples[nCBIndex],
wszCurrencyUnit,
L"?");
wcscpy(wszNewSample,pwszResultStr);
free(pwszResultStr);
pwszResultStr = ReplaceSubStr(wszNewSample,
wszCurrencySep,
L",");
SendMessageW(GetDlgItem(hwndDlg, IDC_NEGCURRENCYSUM_COMBO),
CB_ADDSTRING,
nCBIndex,
(LPARAM)pwszResultStr);
free(pwszResultStr);
}
/* Set current item to value from registry */
nRetCode = SendMessageW(GetDlgItem(hwndDlg, IDC_NEGCURRENCYSUM_COMBO),
CB_SETCURSEL,
(WPARAM)_wtoi(wszCurrNegFmt),
(LPARAM)0);
}
/* Init currency separator control box */
VOID
InitCurrencySepCB(HWND hwndDlg)
{
WCHAR wszCurrencySepSamples[MAX_CURRENCY_SEP_SAMPLES][MAX_SAMPLES_STR_SIZE]=
{
L",",
L"."
};
int nCBIndex;
int nRetCode;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -