Sync with trunk head (part 1 of 2)
[reactos.git] / dll / cpl / intl / numbers.c
1 /*
2 * ReactOS
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /* $Id$
20 *
21 * PROJECT: ReactOS International Control Panel
22 * FILE: lib/cpl/intl/numbers.c
23 * PURPOSE: Numbers property page
24 * PROGRAMMER: Eric Kohl
25 */
26
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <cpl.h>
30 #include <tchar.h>
31
32 #include "intl.h"
33 #include "resource.h"
34
35 #define SAMPLE_NUMBER _T("123456789")
36 #define SAMPLE_NEG_NUMBER _T("-123456789")
37 #define MAX_NUM_SEP_SAMPLES 2
38 #define MAX_FRAC_NUM_SAMPLES 10
39 #define MAX_FIELD_SEP_SAMPLES 1
40 #define MAX_FIELD_DIG_SAMPLES 3
41 #define MAX_NEG_SIGN_SAMPLES 1
42 #define MAX_NEG_NUMBERS_SAMPLES 5
43 #define MAX_LEAD_ZEROES_SAMPLES 2
44 #define MAX_LIST_SEP_SAMPLES 1
45 #define MAX_UNITS_SYS_SAMPLES 2
46
47 static LPTSTR lpNumSepSamples[MAX_NUM_SEP_SAMPLES] =
48 {_T(","), _T(".")};
49 static LPTSTR lpFieldSepSamples[MAX_FIELD_SEP_SAMPLES] =
50 {_T(" ")};
51 static LPTSTR lpFieldDigNumSamples[MAX_FIELD_DIG_SAMPLES] =
52 {_T("0;0"), _T("3;0"), _T("3;2;0")};
53 static LPTSTR lpNegSignSamples[MAX_NEG_SIGN_SAMPLES] =
54 {_T("-")};
55 static LPTSTR lpNegNumFmtSamples[MAX_NEG_NUMBERS_SAMPLES] =
56 {_T("(1,1)"), _T("-1,1"), _T("- 1,1"), _T("1,1-"), _T("1,1 -")};
57 static LPTSTR lpLeadNumFmtSamples[MAX_LEAD_ZEROES_SAMPLES] =
58 {_T(",7"), _T("0,7")};
59 static LPTSTR lpListSepSamples[MAX_LIST_SEP_SAMPLES] =
60 {_T(";")};
61 static LPTSTR lpUnitsSysSamples[MAX_UNITS_SYS_SAMPLES] =
62 {_T("Metric"), _T("Imperial")};
63
64
65 /* Init num decimal separator control box */
66 static VOID
67 InitNumDecimalSepCB(HWND hwndDlg, LCID lcid)
68 {
69 TCHAR szNumSep[MAX_SAMPLES_STR_SIZE];
70 INT nCBIndex;
71 INT nRetCode;
72
73 /* Limit text length */
74 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERDSYMBOL),
75 CB_LIMITTEXT,
76 MAX_NUMBERDSYMBOL,
77 0);
78
79 /* Get current decimal separator */
80 GetLocaleInfo(lcid,
81 LOCALE_SDECIMAL,
82 szNumSep,
83 MAX_SAMPLES_STR_SIZE);
84
85 /* Clear all box content */
86 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERDSYMBOL),
87 CB_RESETCONTENT,
88 (WPARAM)0,
89 (LPARAM)0);
90
91 /* Create standard list of decimal separators */
92 for (nCBIndex = 0; nCBIndex < MAX_NUM_SEP_SAMPLES; nCBIndex++)
93 {
94 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERDSYMBOL),
95 CB_ADDSTRING,
96 0,
97 (LPARAM)lpNumSepSamples[nCBIndex]);
98 }
99
100 /* Set current item to value from registry */
101 nRetCode = SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERDSYMBOL),
102 CB_SELECTSTRING,
103 -1,
104 (LPARAM)(LPCSTR)szNumSep);
105
106 /* if is not success, add new value to list and select them */
107 if (nRetCode == CB_ERR)
108 {
109 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERDSYMBOL),
110 CB_ADDSTRING,
111 MAX_NUM_SEP_SAMPLES,
112 (LPARAM)szNumSep);
113 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERDSYMBOL),
114 CB_SELECTSTRING,
115 -1,
116 (LPARAM)szNumSep);
117 }
118 }
119
120 /* Init number of fractional symbols control box */
121 static VOID
122 InitNumOfFracSymbCB(HWND hwndDlg, LCID lcid)
123 {
124 TCHAR szFracNum[MAX_SAMPLES_STR_SIZE];
125 TCHAR szFracCount[MAX_SAMPLES_STR_SIZE];
126 INT nCBIndex;
127 INT nRetCode;
128
129 /* Get current number of fractional symbols */
130 GetLocaleInfo(lcid,
131 LOCALE_IDIGITS,
132 szFracNum,
133 MAX_SAMPLES_STR_SIZE);
134
135 /* Clear all box content */
136 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSNDIGDEC),
137 CB_RESETCONTENT,
138 (WPARAM)0,
139 (LPARAM)0);
140
141 /* Create standard list of fractional symbols */
142 for (nCBIndex = 0; nCBIndex < MAX_FRAC_NUM_SAMPLES; nCBIndex++)
143 {
144 /* convert to wide char */
145 _itot(nCBIndex, szFracCount, DECIMAL_RADIX);
146
147 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSNDIGDEC),
148 CB_ADDSTRING,
149 0,
150 (LPARAM)szFracCount);
151 }
152
153 /* Set current item to value from registry */
154 nRetCode = SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSNDIGDEC),
155 CB_SETCURSEL,
156 (WPARAM)_ttoi(szFracNum),
157 (LPARAM)0);
158 }
159
160 /* Init field separator control box */
161 static VOID
162 InitNumFieldSepCB(HWND hwndDlg, LCID lcid)
163 {
164 TCHAR szFieldSep[MAX_SAMPLES_STR_SIZE];
165 INT nCBIndex;
166 INT nRetCode;
167
168 /* Limit text length */
169 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSDIGITGRSYM),
170 CB_LIMITTEXT,
171 MAX_NUMBERSDIGITGRSYM,
172 0);
173
174 /* Get current field separator */
175 GetLocaleInfo(lcid,
176 LOCALE_STHOUSAND,
177 szFieldSep,
178 MAX_SAMPLES_STR_SIZE);
179
180 /* Clear all box content */
181 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSDIGITGRSYM),
182 CB_RESETCONTENT,
183 (WPARAM)0,
184 (LPARAM)0);
185
186 /* Create standard list of field separators */
187 for (nCBIndex = 0; nCBIndex < MAX_FIELD_SEP_SAMPLES; nCBIndex++)
188 {
189 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSDIGITGRSYM),
190 CB_ADDSTRING,
191 0,
192 (LPARAM)lpFieldSepSamples[nCBIndex]);
193 }
194
195 /* Set current item to value from registry */
196 nRetCode = SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSDIGITGRSYM),
197 CB_SELECTSTRING,
198 -1,
199 (LPARAM)szFieldSep);
200
201 /* if is not success, add new value to list and select them */
202 if (nRetCode == CB_ERR)
203 {
204 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSDIGITGRSYM),
205 CB_ADDSTRING,
206 0,
207 (LPARAM)szFieldSep);
208 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSDIGITGRSYM),
209 CB_SELECTSTRING,
210 -1,
211 (LPARAM)szFieldSep);
212 }
213 }
214
215 /* Init number of digits in field control box */
216 static VOID
217 InitFieldDigNumCB(HWND hwndDlg, LCID lcid)
218 {
219 TCHAR szFieldDigNum[MAX_SAMPLES_STR_SIZE];
220 LPTSTR pszFieldDigNumSmpl;
221 INT nCBIndex;
222 INT nRetCode;
223
224 /* Get current field digits num */
225 GetLocaleInfo(lcid,
226 LOCALE_SGROUPING,
227 szFieldDigNum,
228 MAX_SAMPLES_STR_SIZE);
229
230 /* Clear all box content */
231 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSDGROUPING),
232 CB_RESETCONTENT,
233 (WPARAM)0,
234 (LPARAM)0);
235
236 /* Create standard list of field digits num */
237 for (nCBIndex = 0; nCBIndex < MAX_FIELD_DIG_SAMPLES; nCBIndex++)
238 {
239
240 pszFieldDigNumSmpl = InsSpacesFmt(SAMPLE_NUMBER, lpFieldDigNumSamples[nCBIndex]);
241 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSDGROUPING),
242 CB_ADDSTRING,
243 0,
244 (LPARAM)pszFieldDigNumSmpl);
245 free(pszFieldDigNumSmpl);
246 }
247
248 pszFieldDigNumSmpl = InsSpacesFmt(SAMPLE_NUMBER, szFieldDigNum);
249 /* Set current item to value from registry */
250 nRetCode = SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSDGROUPING),
251 CB_SELECTSTRING,
252 -1,
253 (LPARAM)pszFieldDigNumSmpl);
254
255 /* if is not success, add new value to list and select them */
256 if (nRetCode == CB_ERR)
257 {
258 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSDGROUPING),
259 CB_ADDSTRING,
260 0,
261 (LPARAM)pszFieldDigNumSmpl);
262 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSDGROUPING),
263 CB_SELECTSTRING,
264 -1,
265 (LPARAM)pszFieldDigNumSmpl);
266 }
267
268 free(pszFieldDigNumSmpl);
269 }
270
271 /* Init negative sign control box */
272 static VOID
273 InitNegSignCB(HWND hwndDlg, LCID lcid)
274 {
275 TCHAR szNegSign[MAX_SAMPLES_STR_SIZE];
276 INT nCBIndex;
277 INT nRetCode;
278
279 /* Limit text length */
280 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSNSIGNSYM),
281 CB_LIMITTEXT,
282 MAX_NUMBERSNSIGNSYM,
283 0);
284
285 /* Get current negative sign */
286 GetLocaleInfo(lcid,
287 LOCALE_SNEGATIVESIGN,
288 szNegSign,
289 MAX_SAMPLES_STR_SIZE);
290
291 /* Clear all box content */
292 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSNSIGNSYM),
293 CB_RESETCONTENT,
294 (WPARAM)0,
295 (LPARAM)0);
296
297 /* Create standard list of signs */
298 for (nCBIndex = 0; nCBIndex < MAX_NEG_SIGN_SAMPLES; nCBIndex++)
299 {
300 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSNSIGNSYM),
301 CB_ADDSTRING,
302 0,
303 (LPARAM)lpNegSignSamples[nCBIndex]);
304 }
305
306 /* Set current item to value from registry */
307 nRetCode = SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSNSIGNSYM),
308 CB_SELECTSTRING,
309 -1,
310 (LPARAM)szNegSign);
311
312 /* if is not success, add new value to list and select them */
313 if (nRetCode == CB_ERR)
314 {
315 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSNSIGNSYM),
316 CB_ADDSTRING,
317 0,
318 (LPARAM)szNegSign);
319 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSNSIGNSYM),
320 CB_SELECTSTRING,
321 -1,
322 (LPARAM)szNegSign);
323 }
324 }
325
326 /* Init negative numbers format control box */
327 static VOID
328 InitNegNumFmtCB(HWND hwndDlg, LCID lcid)
329 {
330 TCHAR szNegNumFmt[MAX_SAMPLES_STR_SIZE];
331 TCHAR szNumSep[MAX_SAMPLES_STR_SIZE];
332 TCHAR szNegSign[MAX_SAMPLES_STR_SIZE];
333 TCHAR szNewSample[MAX_SAMPLES_STR_SIZE];
334 LPTSTR pszResultStr;
335 INT nCBIndex;
336 INT nRetCode;
337
338 /* Get current negative numbers format */
339 GetLocaleInfo(lcid,
340 LOCALE_INEGNUMBER,
341 szNegNumFmt,
342 MAX_SAMPLES_STR_SIZE);
343
344 /* Clear all box content */
345 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSNNUMFORMAT),
346 CB_RESETCONTENT,
347 (WPARAM)0,
348 (LPARAM)0);
349
350 /* Get current decimal separator */
351 GetLocaleInfo(lcid,
352 LOCALE_SDECIMAL,
353 szNumSep,
354 MAX_SAMPLES_STR_SIZE);
355
356 /* Get current negative sign */
357 GetLocaleInfo(lcid,
358 LOCALE_SNEGATIVESIGN,
359 szNegSign,
360 MAX_SAMPLES_STR_SIZE);
361
362 /* Create standard list of negative numbers formats */
363 for (nCBIndex = 0; nCBIndex < MAX_NEG_NUMBERS_SAMPLES; nCBIndex++)
364 {
365 /* Replace standard separator to setted */
366 pszResultStr = ReplaceSubStr(lpNegNumFmtSamples[nCBIndex],
367 szNumSep,
368 _T(","));
369 _tcscpy(szNewSample, pszResultStr);
370 free(pszResultStr);
371 /* Replace standard negative sign to setted */
372 pszResultStr = ReplaceSubStr(szNewSample,
373 szNegSign,
374 _T("-"));
375 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSNNUMFORMAT),
376 CB_ADDSTRING,
377 0,
378 (LPARAM)pszResultStr);
379 free(pszResultStr);
380 }
381
382 /* Set current item to value from registry */
383 nRetCode = SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSNNUMFORMAT),
384 CB_SETCURSEL,
385 (WPARAM)_ttoi(szNegNumFmt),
386 (LPARAM)0);
387 }
388
389 /* Init leading zeroes control box */
390 static VOID
391 InitLeadingZeroesCB(HWND hwndDlg, LCID lcid)
392 {
393 TCHAR szLeadNumFmt[MAX_SAMPLES_STR_SIZE];
394 TCHAR szNumSep[MAX_SAMPLES_STR_SIZE];
395 LPTSTR pszResultStr;
396 INT nCBIndex;
397 INT nRetCode;
398
399 /* Get current leading zeroes format */
400 GetLocaleInfo(lcid,
401 LOCALE_ILZERO,
402 szLeadNumFmt,
403 MAX_SAMPLES_STR_SIZE);
404
405 /* Clear all box content */
406 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSDISPLEADZER),
407 CB_RESETCONTENT,
408 (WPARAM)0,
409 (LPARAM)0);
410
411 /* Get current decimal separator */
412 GetLocaleInfo(lcid,
413 LOCALE_SDECIMAL,
414 szNumSep,
415 MAX_SAMPLES_STR_SIZE);
416
417 /* Create list of standard leading zeroes formats */
418 for (nCBIndex = 0; nCBIndex < MAX_LEAD_ZEROES_SAMPLES; nCBIndex++)
419 {
420 pszResultStr = ReplaceSubStr(lpLeadNumFmtSamples[nCBIndex],
421 szNumSep,
422 _T(","));
423 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSDISPLEADZER),
424 CB_ADDSTRING,
425 0,
426 (LPARAM)pszResultStr);
427 free(pszResultStr);
428 }
429
430 /* Set current item to value from registry */
431 nRetCode = SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSDISPLEADZER),
432 CB_SETCURSEL,
433 (WPARAM)_ttoi(szLeadNumFmt),
434 (LPARAM)0);
435 }
436
437 static VOID
438 InitListSepCB(HWND hwndDlg,
439 LCID lcid)
440 {
441 TCHAR szListSep[MAX_SAMPLES_STR_SIZE];
442 INT nCBIndex;
443 INT nRetCode;
444
445 /* Limit text length */
446 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSLSEP),
447 CB_LIMITTEXT,
448 MAX_NUMBERSLSEP,
449 0);
450
451 /* Get current list separator */
452 GetLocaleInfo(lcid,
453 LOCALE_SLIST,
454 szListSep,
455 MAX_SAMPLES_STR_SIZE);
456
457 /* Clear all box content */
458 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSLSEP),
459 CB_RESETCONTENT,
460 (WPARAM)0,
461 (LPARAM)0);
462
463 /* Create standard list of signs */
464 for (nCBIndex = 0; nCBIndex < MAX_LIST_SEP_SAMPLES; nCBIndex++)
465 {
466 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSLSEP),
467 CB_ADDSTRING,
468 0,
469 (LPARAM)lpListSepSamples[nCBIndex]);
470 }
471
472 /* Set current item to value from registry */
473 nRetCode = SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSLSEP),
474 CB_SELECTSTRING,
475 -1,
476 (LPARAM)szListSep);
477
478 /* if is not success, add new value to list and select them */
479 if (nRetCode == CB_ERR)
480 {
481 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSLSEP),
482 CB_ADDSTRING,
483 0,
484 (LPARAM)szListSep);
485 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSLSEP),
486 CB_SELECTSTRING,
487 -1,
488 (LPARAM)szListSep);
489 }
490 }
491
492 /* Init system of units control box */
493 static VOID
494 InitUnitsSysCB(HWND hwndDlg,
495 LCID lcid)
496 {
497 TCHAR szUnitsSys[MAX_SAMPLES_STR_SIZE];
498 INT nCBIndex;
499
500 /* Get current system of units */
501 GetLocaleInfo(lcid,
502 LOCALE_IMEASURE,
503 szUnitsSys,
504 MAX_SAMPLES_STR_SIZE);
505
506 /* Clear all box content */
507 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSMEASSYS),
508 CB_RESETCONTENT,
509 (WPARAM)0,
510 (LPARAM)0);
511
512 /* Create list of standard system of units */
513 for (nCBIndex = 0; nCBIndex < MAX_UNITS_SYS_SAMPLES; nCBIndex++)
514 {
515 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSMEASSYS),
516 CB_ADDSTRING,
517 0,
518 (LPARAM)lpUnitsSysSamples[nCBIndex]);
519 }
520
521 /* Set current item to value from registry */
522 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSMEASSYS),
523 CB_SETCURSEL,
524 (WPARAM)_ttoi(szUnitsSys),
525 (LPARAM)0);
526 }
527
528 /* Update all numbers locale samples */
529 static VOID
530 UpdateNumSamples(HWND hwndDlg,
531 LCID lcid)
532 {
533 TCHAR OutBuffer[MAX_FMT_SIZE];
534
535 /* Get positive number format sample */
536 GetNumberFormat(lcid,
537 0,
538 SAMPLE_NUMBER,
539 NULL,
540 OutBuffer,
541 MAX_FMT_SIZE);
542
543 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSPOSSAMPLE),
544 WM_SETTEXT,
545 0,
546 (LPARAM)OutBuffer);
547
548 /* Get positive number format sample */
549 GetNumberFormat(lcid,
550 0,
551 SAMPLE_NEG_NUMBER,
552 NULL,
553 OutBuffer,
554 MAX_FMT_SIZE);
555
556 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSNEGSAMPLE),
557 WM_SETTEXT,
558 0,
559 (LPARAM)OutBuffer);
560 }
561
562 /* Set num decimal separator */
563 static BOOL
564 SetNumDecimalSep(HWND hwndDlg,
565 LCID lcid)
566 {
567 TCHAR szDecimalSep[MAX_SAMPLES_STR_SIZE];
568
569 /* Get setted decimal separator */
570 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERDSYMBOL),
571 WM_GETTEXT,
572 (WPARAM)MAX_SAMPLES_STR_SIZE,
573 (LPARAM)szDecimalSep);
574
575 /* Save decimal separator */
576 SetLocaleInfo(lcid, LOCALE_SDECIMAL, szDecimalSep);
577
578 return TRUE;
579 }
580
581 /* Set number of fractional symbols */
582 static BOOL
583 SetFracSymNum(HWND hwndDlg,
584 LCID lcid)
585 {
586 TCHAR szFracSymNum[MAX_SAMPLES_STR_SIZE];
587 INT nCurrSel;
588
589 /* Get setted number of fractional symbols */
590 nCurrSel = SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSNDIGDEC),
591 CB_GETCURSEL,
592 (WPARAM)0,
593 (LPARAM)0);
594
595 /* convert to wide char */
596 _itot(nCurrSel, szFracSymNum, DECIMAL_RADIX);
597
598 /* Save number of fractional symbols */
599 SetLocaleInfo(lcid, LOCALE_IDIGITS, szFracSymNum);
600
601 return TRUE;
602 }
603
604 /* Set field separator */
605 static BOOL
606 SetNumFieldSep(HWND hwndDlg,
607 LCID lcid)
608 {
609 TCHAR szFieldSep[MAX_SAMPLES_STR_SIZE];
610
611 /* Get setted field separator */
612 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSDIGITGRSYM),
613 WM_GETTEXT,
614 (WPARAM)MAX_SAMPLES_STR_SIZE,
615 (LPARAM)szFieldSep);
616
617 /* Save field separator */
618 SetLocaleInfo(lcid, LOCALE_STHOUSAND, szFieldSep);
619
620 return TRUE;
621 }
622
623 /* Set number of digits in field */
624 static BOOL
625 SetFieldDigNum(HWND hwndDlg,
626 LCID lcid)
627 {
628 TCHAR szFieldDigNum[MAX_SAMPLES_STR_SIZE];
629
630 /* Get setted number of digidts in field */
631 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSDGROUPING),
632 WM_GETTEXT,
633 (WPARAM)MAX_SAMPLES_STR_SIZE,
634 (LPARAM)szFieldDigNum);
635
636 /* Save number of digits in field */
637 SetLocaleInfo(lcid, LOCALE_SGROUPING, szFieldDigNum);
638
639 return TRUE;
640 }
641
642 /* Set negative sign */
643 static BOOL
644 SetNumNegSign(HWND hwndDlg,
645 LCID lcid)
646 {
647 TCHAR szNegSign[MAX_SAMPLES_STR_SIZE];
648
649 /* Get setted negative sign */
650 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSNSIGNSYM),
651 WM_GETTEXT,
652 (WPARAM)MAX_SAMPLES_STR_SIZE,
653 (LPARAM)szNegSign);
654
655 /* Save negative sign */
656 SetLocaleInfo(lcid, LOCALE_SNEGATIVESIGN, szNegSign);
657
658 return TRUE;
659 }
660
661 /* Set negative sum format */
662 static BOOL
663 SetNegSumFmt(HWND hwndDlg,
664 LCID lcid)
665 {
666 TCHAR szNegSumFmt[MAX_SAMPLES_STR_SIZE];
667 INT nCurrSel;
668
669 /* Get setted negative sum format */
670 nCurrSel = SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSNNUMFORMAT),
671 CB_GETCURSEL,
672 (WPARAM)0,
673 (LPARAM)0);
674
675 /* convert to wide char */
676 _itot(nCurrSel, szNegSumFmt,DECIMAL_RADIX);
677
678 /* Save negative sum format */
679 SetLocaleInfo(lcid, LOCALE_INEGNUMBER, szNegSumFmt);
680
681 return TRUE;
682 }
683
684 /* Set leading zero */
685 static BOOL
686 SetNumLeadZero(HWND hwndDlg,
687 LCID lcid)
688 {
689 TCHAR szLeadZero[MAX_SAMPLES_STR_SIZE];
690 INT nCurrSel;
691
692 /* Get setted leading zero format */
693 nCurrSel = SendMessageW(GetDlgItem(hwndDlg, IDC_NUMBERSDISPLEADZER),
694 CB_GETCURSEL,
695 (WPARAM)0,
696 (LPARAM)0);
697
698 /* convert to wide char */
699 _itot(nCurrSel, szLeadZero, DECIMAL_RADIX);
700
701 /* Save leading zero format */
702 SetLocaleInfo(lcid, LOCALE_ILZERO, szLeadZero);
703
704 return TRUE;
705 }
706
707 /* Set elements list separator */
708 static BOOL
709 SetNumListSep(HWND hwndDlg,
710 LCID lcid)
711 {
712 TCHAR szListSep[MAX_SAMPLES_STR_SIZE];
713
714 /* Get setted list separator */
715 SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSLSEP),
716 WM_GETTEXT,
717 (WPARAM)MAX_SAMPLES_STR_SIZE,
718 (LPARAM)szListSep);
719
720 /* Save list separator */
721 SetLocaleInfo(lcid, LOCALE_SLIST, szListSep);
722
723 return TRUE;
724 }
725
726 /* Set units system */
727 static BOOL
728 SetNumUnitsSys(HWND hwndDlg,
729 LCID lcid)
730 {
731 TCHAR szUnitsSys[MAX_SAMPLES_STR_SIZE];
732 INT nCurrSel;
733
734 /* Get setted units system */
735 nCurrSel = SendMessage(GetDlgItem(hwndDlg, IDC_NUMBERSMEASSYS),
736 CB_GETCURSEL,
737 (WPARAM)0,
738 (LPARAM)0);
739
740 /* convert to wide char */
741 _itot(nCurrSel, szUnitsSys, DECIMAL_RADIX);
742
743 /* Save units system */
744 SetLocaleInfo(lcid, LOCALE_IMEASURE, szUnitsSys);
745
746 return TRUE;
747 }
748
749 /* Property page dialog callback */
750 INT_PTR CALLBACK
751 NumbersPageProc(HWND hwndDlg,
752 UINT uMsg,
753 WPARAM wParam,
754 LPARAM lParam)
755 {
756 PGLOBALDATA pGlobalData;
757
758 pGlobalData = (PGLOBALDATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
759
760 switch (uMsg)
761 {
762 case WM_INITDIALOG:
763 pGlobalData = (PGLOBALDATA)((LPPROPSHEETPAGE)lParam)->lParam;
764 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData);
765
766 InitNumDecimalSepCB(hwndDlg, pGlobalData->lcid);
767 InitNumOfFracSymbCB(hwndDlg, pGlobalData->lcid);
768 InitNumFieldSepCB(hwndDlg, pGlobalData->lcid);
769 InitFieldDigNumCB(hwndDlg, pGlobalData->lcid);
770 InitNegSignCB(hwndDlg, pGlobalData->lcid);
771 InitNegNumFmtCB(hwndDlg, pGlobalData->lcid);
772 InitLeadingZeroesCB(hwndDlg, pGlobalData->lcid);
773 InitListSepCB(hwndDlg, pGlobalData->lcid);
774 InitUnitsSysCB(hwndDlg, pGlobalData->lcid);
775 UpdateNumSamples(hwndDlg, pGlobalData->lcid);
776 break;
777
778 case WM_COMMAND:
779 switch (LOWORD(wParam))
780 {
781 case IDC_NUMBERDSYMBOL:
782 case IDC_NUMBERSNDIGDEC:
783 case IDC_NUMBERSDIGITGRSYM:
784 case IDC_NUMBERSDGROUPING:
785 case IDC_NUMBERSNSIGNSYM:
786 case IDC_NUMBERSNNUMFORMAT:
787 case IDC_NUMBERSDISPLEADZER:
788 case IDC_NUMBERSLSEP:
789 case IDC_NUMBERSMEASSYS:
790 if (HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == CBN_EDITCHANGE)
791 {
792 /* Set "Apply" button enabled */
793 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
794 }
795 }
796 break;
797
798 case WM_NOTIFY:
799 /* If push apply button */
800 if (((LPNMHDR)lParam)->code == (UINT)PSN_APPLY)
801 {
802 if (!SetNumDecimalSep(hwndDlg, pGlobalData->lcid))
803 break;
804
805 if (!SetFracSymNum(hwndDlg, pGlobalData->lcid))
806 break;
807
808 if (!SetNumFieldSep(hwndDlg, pGlobalData->lcid))
809 break;
810
811 if (!SetFieldDigNum(hwndDlg, pGlobalData->lcid))
812 break;
813
814 if (!SetNumNegSign(hwndDlg, pGlobalData->lcid))
815 break;
816
817 if (!SetNegSumFmt(hwndDlg, pGlobalData->lcid))
818 break;
819
820 if (!SetNumLeadZero(hwndDlg, pGlobalData->lcid))
821 break;
822
823 if (!SetNumListSep(hwndDlg, pGlobalData->lcid))
824 break;
825
826 if (!SetNumUnitsSys(hwndDlg, pGlobalData->lcid))
827 break;
828
829 UpdateNumSamples(hwndDlg, pGlobalData->lcid);
830 }
831 break;
832 }
833 return FALSE;
834 }
835
836 /* EOF */