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