2 * PROJECT: ReactOS International Control Panel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/cpl/intl/monetary.c
5 * PURPOSE: ReactOS International Control Panel
6 * PROGRAMMERS: Alexey Zavyalov (gen_x@mail.ru)
9 /* INCLUDES *****************************************************************/
18 /* GLOBALS ******************************************************************/
20 #define SAMPLE_NUMBER L"123456789"
21 #define SAMPLE_NEG_NUMBER L"-123456789"
22 #define MAX_CURRENCY_UNIT_SAMPLES 2
23 #define MAX_POS_CURRENCY_SAMPLES 4
24 #define MAX_NEG_CURRENCY_SAMPLES 16
25 #define MAX_CURRENCY_SEP_SAMPLES 2
26 #define MAX_CURRENCY_FRAC_SAMPLES 10
27 #define MAX_FIELD_SEP_SAMPLES 1
28 #define MAX_FIELD_DIG_SAMPLES 3
29 #define EOLN_SIZE sizeof(WCHAR)
31 /* FUNCTIONS ****************************************************************/
33 /* Init number of digidts in field control box */
35 InitCurrencyDigNumCB(HWND hwndDlg
)
37 WCHAR wszFieldDigNumSamples
[MAX_FIELD_DIG_SAMPLES
][MAX_SAMPLES_STR_SIZE
]=
47 DWORD dwValueSize
=MAX_SAMPLES_STR_SIZE
*sizeof(WCHAR
)+EOLN_SIZE
;
48 WCHAR wszFieldDigNum
[MAX_SAMPLES_STR_SIZE
];
49 WCHAR
* pwszFieldDigNumSmpl
;
51 /* Get current field digits num */
52 GetLocaleInfoW(LOCALE_USER_DEFAULT
,
57 /* Clear all box content */
58 SendMessageW(GetDlgItem(hwndDlg
, IDC_DIGINFIELDNUM_COMBO
),
63 /* Create standart list of field digits num */
64 for(nCBIndex
=0;nCBIndex
<MAX_FIELD_DIG_SAMPLES
;nCBIndex
++)
67 pwszFieldDigNumSmpl
=InsSpacesFmt(SAMPLE_NUMBER
,wszFieldDigNumSamples
[nCBIndex
]);
68 SendMessageW(GetDlgItem(hwndDlg
, IDC_DIGINFIELDNUM_COMBO
),
71 (LPARAM
)pwszFieldDigNumSmpl
);
72 free(pwszFieldDigNumSmpl
);
75 pwszFieldDigNumSmpl
=InsSpacesFmt(SAMPLE_NUMBER
,wszFieldDigNum
);
76 /* Set current item to value from registry */
77 nRetCode
= SendMessageW(GetDlgItem(hwndDlg
, IDC_DIGINFIELDNUM_COMBO
),
80 (LPARAM
)(LPCSTR
)pwszFieldDigNumSmpl
);
82 /* if is not success, add new value to list and select them */
83 if(nRetCode
== CB_ERR
)
85 SendMessageW(GetDlgItem(hwndDlg
, IDC_DIGINFIELDNUM_COMBO
),
87 MAX_FIELD_DIG_SAMPLES
+1,
88 (LPARAM
)pwszFieldDigNumSmpl
);
89 SendMessageW(GetDlgItem(hwndDlg
, IDC_DIGINFIELDNUM_COMBO
),
92 (LPARAM
)(LPCSTR
)pwszFieldDigNumSmpl
);
95 free(pwszFieldDigNumSmpl
);
99 /* Init currency field separator control box */
101 InitCurrencyFieldSepCB(HWND hwndDlg
)
103 WCHAR wszFieldSepSamples
[MAX_FIELD_SEP_SAMPLES
][MAX_SAMPLES_STR_SIZE
]=
111 DWORD dwValueSize
=MAX_SAMPLES_STR_SIZE
*sizeof(WCHAR
)+EOLN_SIZE
;
112 WCHAR wszFieldSep
[MAX_SAMPLES_STR_SIZE
];
114 /* Get current field separator */
115 GetLocaleInfoW(LOCALE_USER_DEFAULT
,
116 LOCALE_SMONTHOUSANDSEP
,
120 /* Clear all box content */
121 SendMessageW(GetDlgItem(hwndDlg
, IDC_FIELDSEP_COMBO
),
126 /* Create standart list of field separators */
127 for(nCBIndex
=0;nCBIndex
<MAX_FIELD_SEP_SAMPLES
;nCBIndex
++)
129 SendMessageW(GetDlgItem(hwndDlg
, IDC_FIELDSEP_COMBO
),
132 (LPARAM
)wszFieldSepSamples
[nCBIndex
]);
135 /* Set current item to value from registry */
136 nRetCode
= SendMessageW(GetDlgItem(hwndDlg
, IDC_FIELDSEP_COMBO
),
139 (LPARAM
)(LPCSTR
)wszFieldSep
);
141 /* if is not success, add new value to list and select them */
142 if(nRetCode
== CB_ERR
)
144 SendMessageW(GetDlgItem(hwndDlg
, IDC_FIELDSEP_COMBO
),
146 MAX_FIELD_SEP_SAMPLES
+1,
147 (LPARAM
)wszFieldSep
);
148 SendMessageW(GetDlgItem(hwndDlg
, IDC_FIELDSEP_COMBO
),
151 (LPARAM
)(LPCSTR
)wszFieldSep
);
155 /* Init number of fractional symbols control box */
157 InitCurrencyFracNumCB(HWND hwndDlg
)
162 DWORD dwValueSize
=MAX_SAMPLES_STR_SIZE
*sizeof(WCHAR
)+EOLN_SIZE
;
163 WCHAR wszCurrencyFracNum
[MAX_SAMPLES_STR_SIZE
];
164 WCHAR wszFracCount
[MAX_SAMPLES_STR_SIZE
];
166 /* Get current number of fractional symbols */
167 GetLocaleInfoW(LOCALE_USER_DEFAULT
,
172 /* Clear all box content */
173 SendMessageW(GetDlgItem(hwndDlg
, IDC_FRACSYMBSNUM_COMBO
),
178 /* Create standart list of fractional symbols */
179 for(nCBIndex
=0;nCBIndex
<MAX_CURRENCY_FRAC_SAMPLES
;nCBIndex
++)
181 /* convert to wide char */
182 _itow(nCBIndex
,wszFracCount
,DECIMAL_RADIX
);
184 SendMessageW(GetDlgItem(hwndDlg
, IDC_FRACSYMBSNUM_COMBO
),
187 (LPARAM
)wszFracCount
);
190 /* Set current item to value from registry */
191 nRetCode
= SendMessageW(GetDlgItem(hwndDlg
, IDC_FRACSYMBSNUM_COMBO
),
193 (WPARAM
)_wtoi(wszCurrencyFracNum
),
198 /* Init positive currency sum format control box */
200 InitPosCurrencySumCB(HWND hwndDlg
)
202 WCHAR wszPosCurrencySumSamples
[MAX_POS_CURRENCY_SAMPLES
][MAX_SAMPLES_STR_SIZE
]=
213 WCHAR wszCurrPosFmt
[MAX_SAMPLES_STR_SIZE
];
214 WCHAR wszCurrencyUnit
[MAX_SAMPLES_STR_SIZE
];
215 WCHAR wszNewSample
[MAX_SAMPLES_STR_SIZE
];
216 WCHAR wszCurrencySep
[MAX_SAMPLES_STR_SIZE
];
217 WCHAR
* pwszResultStr
;
218 DWORD dwValueSize
=MAX_SAMPLES_STR_SIZE
*sizeof(WCHAR
)+EOLN_SIZE
;
220 /* Get current currency sum format */
221 GetLocaleInfoW(LOCALE_USER_DEFAULT
,
226 /* Clear all box content */
227 SendMessageW(GetDlgItem(hwndDlg
, IDC_POSCURRENCYSUM_COMBO
),
232 /* Get current currency separator */
233 GetLocaleInfoW(LOCALE_USER_DEFAULT
,
234 LOCALE_SMONDECIMALSEP
,
238 /* Get current currency unit */
239 GetLocaleInfoW(LOCALE_USER_DEFAULT
,
244 /* Create standart list of currency sum formats */
245 for(nCBIndex
=0;nCBIndex
<MAX_POS_CURRENCY_SAMPLES
;nCBIndex
++)
247 pwszResultStr
= ReplaceSubStr(wszPosCurrencySumSamples
[nCBIndex
],
250 wcscpy(wszNewSample
,pwszResultStr
);
252 pwszResultStr
= ReplaceSubStr(wszNewSample
,
255 SendMessageW(GetDlgItem(hwndDlg
, IDC_POSCURRENCYSUM_COMBO
),
258 (LPARAM
)pwszResultStr
);
262 /* Set current item to value from registry */
263 nRetCode
= SendMessageW(GetDlgItem(hwndDlg
, IDC_POSCURRENCYSUM_COMBO
),
265 (WPARAM
)_wtoi(wszCurrPosFmt
),
269 /* Init negative currency sum format control box */
271 InitNegCurrencySumCB(HWND hwndDlg
)
273 WCHAR wszNegCurrencySumSamples
[MAX_NEG_CURRENCY_SAMPLES
][MAX_SAMPLES_STR_SIZE
]=
296 WCHAR wszCurrNegFmt
[MAX_SAMPLES_STR_SIZE
];
297 WCHAR wszCurrencyUnit
[MAX_SAMPLES_STR_SIZE
];
298 WCHAR wszCurrencySep
[MAX_SAMPLES_STR_SIZE
];
299 WCHAR wszNewSample
[MAX_SAMPLES_STR_SIZE
];
300 WCHAR
* pwszResultStr
;
301 DWORD dwValueSize
=MAX_SAMPLES_STR_SIZE
*sizeof(WCHAR
)+EOLN_SIZE
;
303 /* Get current currency sum format */
304 GetLocaleInfoW(LOCALE_USER_DEFAULT
,
309 /* Clear all box content */
310 SendMessageW(GetDlgItem(hwndDlg
, IDC_NEGCURRENCYSUM_COMBO
),
315 /* Get current currency unit */
316 GetLocaleInfoW(LOCALE_USER_DEFAULT
,
321 /* Get current currency separator */
322 GetLocaleInfoW(LOCALE_USER_DEFAULT
,
323 LOCALE_SMONDECIMALSEP
,
327 /* Create standart list of currency sum formats */
328 for(nCBIndex
=0;nCBIndex
<MAX_NEG_CURRENCY_SAMPLES
;nCBIndex
++)
330 pwszResultStr
= ReplaceSubStr(wszNegCurrencySumSamples
[nCBIndex
],
333 wcscpy(wszNewSample
,pwszResultStr
);
335 pwszResultStr
= ReplaceSubStr(wszNewSample
,
338 SendMessageW(GetDlgItem(hwndDlg
, IDC_NEGCURRENCYSUM_COMBO
),
341 (LPARAM
)pwszResultStr
);
345 /* Set current item to value from registry */
346 nRetCode
= SendMessageW(GetDlgItem(hwndDlg
, IDC_NEGCURRENCYSUM_COMBO
),
348 (WPARAM
)_wtoi(wszCurrNegFmt
),
352 /* Init currency separator control box */
354 InitCurrencySepCB(HWND hwndDlg
)
356 WCHAR wszCurrencySepSamples
[MAX_CURRENCY_SEP_SAMPLES
][MAX_SAMPLES_STR_SIZE
]=
365 DWORD dwValueSize
=MAX_SAMPLES_STR_SIZE
*sizeof(WCHAR
)+EOLN_SIZE
;
366 WCHAR wszCurrencySep
[MAX_SAMPLES_STR_SIZE
];
368 /* Get current currency separator */
369 GetLocaleInfoW(LOCALE_USER_DEFAULT
,
370 LOCALE_SMONDECIMALSEP
,
374 /* Clear all box content */
375 SendMessageW(GetDlgItem(hwndDlg
, IDC_WHOLEFRACTSEP_COMBO
),
380 /* Create standart list of currency separators */
381 for(nCBIndex
=0;nCBIndex
<MAX_CURRENCY_SEP_SAMPLES
;nCBIndex
++)
383 SendMessageW(GetDlgItem(hwndDlg
, IDC_WHOLEFRACTSEP_COMBO
),
386 (LPARAM
)wszCurrencySepSamples
[nCBIndex
]);
389 /* Set current item to value from registry */
390 nRetCode
= SendMessageW(GetDlgItem(hwndDlg
, IDC_WHOLEFRACTSEP_COMBO
),
393 (LPARAM
)(LPCSTR
)wszCurrencySep
);
395 /* if is not success, add new value to list and select them */
396 if(nRetCode
== CB_ERR
)
398 SendMessageW(GetDlgItem(hwndDlg
, IDC_WHOLEFRACTSEP_COMBO
),
400 MAX_CURRENCY_SEP_SAMPLES
+1,
401 (LPARAM
)wszCurrencySep
);
402 SendMessageW(GetDlgItem(hwndDlg
, IDC_WHOLEFRACTSEP_COMBO
),
405 (LPARAM
)(LPCSTR
)wszCurrencySep
);
409 /* Init currency unit control box */
411 InitCurrencyUnitCB(HWND hwndDlg
)
413 WCHAR wszCurrencyUnitSamples
[MAX_CURRENCY_UNIT_SAMPLES
][MAX_SAMPLES_STR_SIZE
]=
421 DWORD dwValueSize
=MAX_SAMPLES_STR_SIZE
*sizeof(WCHAR
)+EOLN_SIZE
;
422 WCHAR wszCurrencyUnit
[MAX_SAMPLES_STR_SIZE
];
424 /* Get current currency unit */
425 GetLocaleInfoW(LOCALE_USER_DEFAULT
,
430 /* Clear all box content */
431 SendMessageW(GetDlgItem(hwndDlg
, IDC_CURRENCYUNIT_COMBO
),
436 /* Create standart list of currency units */
437 for(nCBIndex
=0;nCBIndex
<MAX_CURRENCY_UNIT_SAMPLES
;nCBIndex
++)
439 SendMessageW(GetDlgItem(hwndDlg
, IDC_CURRENCYUNIT_COMBO
),
442 (LPARAM
)wszCurrencyUnitSamples
[nCBIndex
]);
445 /* Set current item to value from registry */
446 nRetCode
= SendMessageW(GetDlgItem(hwndDlg
, IDC_CURRENCYUNIT_COMBO
),
449 (LPARAM
)(LPCSTR
)wszCurrencyUnit
);
451 /* if is not success, add new value to list and select them */
452 if(nRetCode
== CB_ERR
)
454 SendMessageW(GetDlgItem(hwndDlg
, IDC_CURRENCYUNIT_COMBO
),
456 MAX_CURRENCY_UNIT_SAMPLES
+1,
457 (LPARAM
)wszCurrencyUnit
);
458 SendMessageW(GetDlgItem(hwndDlg
, IDC_CURRENCYUNIT_COMBO
),
461 (LPARAM
)(LPCSTR
)wszCurrencyUnit
);
465 /* Set number of digidts in field */
467 SetCurrencyDigNum(HWND hwndDlg
)
469 WCHAR wszFieldDigNumSamples
[MAX_FIELD_DIG_SAMPLES
][MAX_SAMPLES_STR_SIZE
]=
478 /* Get setted number of digidts in field */
479 nCurrSel
=SendMessageW(GetDlgItem(hwndDlg
, IDC_DIGINFIELDNUM_COMBO
),
484 /* Save number of digidts in field */
485 SetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONGROUPING
, wszFieldDigNumSamples
[nCurrSel
]);
491 /* Set currency field separator */
493 SetCurrencyFieldSep(HWND hwndDlg
)
495 WCHAR wszCurrencyFieldSep
[MAX_SAMPLES_STR_SIZE
];
497 /* Get setted currency field separator */
498 SendMessageW(GetDlgItem(hwndDlg
, IDC_FIELDSEP_COMBO
),
500 (WPARAM
)MAX_SAMPLES_STR_SIZE
,
501 (LPARAM
)(LPCSTR
)wszCurrencyFieldSep
);
503 /* Save currency field separator */
504 SetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONTHOUSANDSEP
, wszCurrencyFieldSep
);
509 /* Set number of fractional symbols */
511 SetCurrencyFracSymNum(HWND hwndDlg
)
513 WCHAR wszCurrencyFracSymNum
[MAX_SAMPLES_STR_SIZE
];
516 /* Get setted number of fractional symbols */
517 nCurrSel
=SendMessageW(GetDlgItem(hwndDlg
, IDC_FRACSYMBSNUM_COMBO
),
522 /* convert to wide char */
523 _itow(nCurrSel
,wszCurrencyFracSymNum
,DECIMAL_RADIX
);
525 /* Save number of fractional symbols */
526 SetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_ICURRDIGITS
, wszCurrencyFracSymNum
);
531 /* Set currency separator */
533 SetCurrencySep(HWND hwndDlg
)
535 WCHAR wszCurrencySep
[MAX_SAMPLES_STR_SIZE
];
537 /* Get setted currency decimal separator */
538 SendMessageW(GetDlgItem(hwndDlg
, IDC_WHOLEFRACTSEP_COMBO
),
540 (WPARAM
)MAX_SAMPLES_STR_SIZE
,
541 (LPARAM
)(LPCSTR
)wszCurrencySep
);
543 /* TODO: Add check for correctly input */
545 /* Save currency separator */
546 SetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SMONDECIMALSEP
, wszCurrencySep
);
551 /* Set negative currency sum format */
553 SetNegCurrencySumFmt(HWND hwndDlg
)
555 WCHAR wszNegCurrencySumFmt
[MAX_SAMPLES_STR_SIZE
];
558 /* Get setted currency unit */
559 nCurrSel
=SendMessageW(GetDlgItem(hwndDlg
, IDC_NEGCURRENCYSUM_COMBO
),
564 /* convert to wide char */
565 _itow(nCurrSel
,wszNegCurrencySumFmt
,DECIMAL_RADIX
);
567 /* Save currency sum format */
568 SetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_INEGCURR
, wszNegCurrencySumFmt
);
573 /* Set positive currency sum format */
575 SetPosCurrencySumFmt(HWND hwndDlg
)
577 WCHAR wszPosCurrencySumFmt
[MAX_SAMPLES_STR_SIZE
];
580 /* Get setted currency unit */
581 nCurrSel
=SendMessageW(GetDlgItem(hwndDlg
, IDC_POSCURRENCYSUM_COMBO
),
586 /* convert to wide char */
587 _itow(nCurrSel
,wszPosCurrencySumFmt
,DECIMAL_RADIX
);
589 /* Save currency sum format */
590 SetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_ICURRENCY
, wszPosCurrencySumFmt
);
595 /* Set currency unit */
597 SetCurrencyUnit(HWND hwndDlg
)
599 WCHAR wszCurrencyUnit
[MAX_SAMPLES_STR_SIZE
];
601 /* Get setted currency unit */
602 SendMessageW(GetDlgItem(hwndDlg
, IDC_CURRENCYUNIT_COMBO
),
604 (WPARAM
)MAX_SAMPLES_STR_SIZE
,
605 (LPARAM
)(LPCSTR
)wszCurrencyUnit
);
607 /* Save currency unit */
608 SetLocaleInfoW(LOCALE_USER_DEFAULT
, LOCALE_SCURRENCY
, wszCurrencyUnit
);
613 /* Update all currency locale samples */
616 UpdateCurrencyLocaleSamples(HWND hwndDlg
,
619 WCHAR OutBuffer
[MAX_FMT_SIZE
];
621 /* Get currency format sample */
622 GetCurrencyFormatW(lcidLocale
,
629 SendMessageW(GetDlgItem(hwndDlg
, IDC_CURRENCY_EDIT
),
634 /* Get negative currency format sample */
635 GetCurrencyFormatW(lcidLocale
,
642 SendMessageW(GetDlgItem(hwndDlg
, IDC_NEGCURRENCY_EDIT
),
648 /* Currency options setup page dialog callback */
651 CurrencyOptsSetProc(HWND hwndDlg
,
656 UNREFERENCED_PARAMETER(lParam
);
657 UNREFERENCED_PARAMETER(wParam
);
658 UNREFERENCED_PARAMETER(hwndDlg
);
663 InitCurrencyUnitCB(hwndDlg
);
664 InitCurrencySepCB(hwndDlg
);
665 InitCurrencyFieldSepCB(hwndDlg
);
666 InitCurrencyFracNumCB(hwndDlg
);
667 InitPosCurrencySumCB(hwndDlg
);
668 InitNegCurrencySumCB(hwndDlg
);
669 InitCurrencyDigNumCB(hwndDlg
);
671 UpdateCurrencyLocaleSamples(hwndDlg
, LOCALE_USER_DEFAULT
);
677 switch (LOWORD(wParam
))
679 case IDC_CURRENCYUNIT_COMBO
:
680 case IDC_POSCURRENCYSUM_COMBO
:
681 case IDC_NEGCURRENCYSUM_COMBO
:
682 case IDC_WHOLEFRACTSEP_COMBO
:
683 case IDC_FRACSYMBSNUM_COMBO
:
684 case IDC_FIELDSEP_COMBO
:
685 case IDC_DIGINFIELDNUM_COMBO
:
687 if (HIWORD(wParam
) == CBN_SELCHANGE
||
688 HIWORD(wParam
) == CBN_EDITCHANGE
)
690 /* Set "Apply" button enabled */
691 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
701 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
702 /* If push apply button */
703 if (lpnm
->code
== (UINT
)PSN_APPLY
)
705 if(!SetCurrencyUnit(hwndDlg
)) break;
706 if(!SetPosCurrencySumFmt(hwndDlg
)) break;
707 if(!SetNegCurrencySumFmt(hwndDlg
)) break;
708 if(!SetCurrencySep(hwndDlg
)) break;
709 if(!SetCurrencyFracSymNum(hwndDlg
)) break;
710 if(!SetCurrencyFieldSep(hwndDlg
)) break;
711 if(!SetCurrencyDigNum(hwndDlg
)) break;
713 /* Update sum format samples */
714 InitPosCurrencySumCB(hwndDlg
);
715 InitNegCurrencySumCB(hwndDlg
);
719 UpdateCurrencyLocaleSamples(hwndDlg
, LOCALE_USER_DEFAULT
);