Alexey Zavyalov: Add functionally Numbers, Currency, Time, Date tabs. Fix some bugs.
[reactos.git] / reactos / dll / cpl / intl_new / setupreg.c
1 /*
2 * PROJECT: ReactOS International Control Panel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/cpl/intl/setupreg.c
5 * PURPOSE: ReactOS International Control Panel
6 * PROGRAMMERS: Alexey Zavyalov (gen_x@mail.ru)
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #include <windows.h>
12 #include <commctrl.h>
13 #include <cpl.h>
14
15 #include "intl.h"
16 #include "resource.h"
17
18 /* GLOBALS ******************************************************************/
19
20 #define NUM_SHEETS 4
21
22 /* FUNCTIONS ****************************************************************/
23
24 /* Insert the space */
25 WCHAR*
26 InsSpacePos(const WCHAR *wszInsStr, const int nPos)
27 {
28 WCHAR* pwszDestStr;
29 pwszDestStr=(WCHAR*) malloc(MAX_SAMPLES_STR_SIZE);
30
31 int nDestStrCnt=0;
32 int nStrCnt;
33 int nStrSize;
34
35 wcscpy(pwszDestStr,wszInsStr);
36
37 nStrSize = wcslen(wszInsStr);
38
39 for(nStrCnt=0; nStrCnt<nStrSize; nStrCnt++)
40 {
41 if(nStrCnt==nStrSize-nPos)
42 {
43 pwszDestStr[nDestStrCnt]=' ';
44 nDestStrCnt++;
45 }
46 pwszDestStr[nDestStrCnt]=wszInsStr[nStrCnt];
47 nDestStrCnt++;
48 }
49 pwszDestStr[nDestStrCnt]='\0';
50
51 return pwszDestStr;
52 }
53
54 /* Insert the spaces by format string separated by ';' */
55 WCHAR*
56 InsSpacesFmt(const WCHAR *wszSourceStr, const WCHAR *wszFmtStr)
57 {
58 WCHAR* pwszDestStr;
59 pwszDestStr=(WCHAR*) malloc(255);
60
61 WCHAR* pwszTempStr;
62
63 WCHAR wszFmtVal[255];
64
65 int nFmtCount=0;
66 int nValCount=0;
67 int nLastVal=0;
68 int nSpaceOffset=0;
69
70 BOOL wasNul=FALSE;
71
72 wcscpy(pwszDestStr,wszSourceStr);
73
74 /* if format is clean return source string */
75 if(!*wszFmtStr) return pwszDestStr;
76
77 /* Search for all format values */
78 for(nFmtCount=0;nFmtCount<=(int)wcslen(wszFmtStr);nFmtCount++)
79 {
80 if(wszFmtStr[nFmtCount]==';' || wszFmtStr[nFmtCount]=='\0')
81 {
82 if(_wtoi(wszFmtVal)==0 && !wasNul)
83 {
84 wasNul=TRUE;
85 break;
86 }
87 /* If was 0, repeat spaces */
88 if(wasNul)
89 {
90 nSpaceOffset+=nLastVal;
91 }
92 else
93 {
94 nSpaceOffset+=_wtoi(wszFmtVal);
95 }
96 wszFmtVal[nValCount]='\0';
97 nValCount=0;
98 /* insert space to finded position plus all pos before */
99 pwszTempStr=InsSpacePos(pwszDestStr,nSpaceOffset);
100 wcscpy(pwszDestStr,pwszTempStr);
101 free(pwszTempStr);
102 /* num of spaces total increment */
103
104 if(!wasNul)
105 {
106 nSpaceOffset++;
107 nLastVal=_wtoi(wszFmtVal);
108 }
109
110 }
111 else
112 {
113 wszFmtVal[nValCount++]=wszFmtStr[nFmtCount];
114 }
115 }
116
117 /* Create spaces for rest part of string */
118 if(wasNul && nLastVal!=0)
119 {
120 for(nFmtCount=nSpaceOffset+nLastVal;nFmtCount<wcslen(pwszDestStr);nFmtCount+=nLastVal+1)
121 {
122 pwszTempStr=InsSpacePos(pwszDestStr,nFmtCount);
123 wcscpy(pwszDestStr,pwszTempStr);
124 free(pwszTempStr);
125 }
126 }
127
128 return pwszDestStr;
129 }
130
131 /* Replace given template in source string with string to replace and return recieved string */
132 WCHAR*
133 ReplaceSubStr(const WCHAR *wszSourceStr,
134 const WCHAR *wszStrToReplace,
135 const WCHAR *wszTempl)
136 {
137 int nCharCnt;
138 int nSubStrCnt;
139 int nDestStrCnt;
140 int nFirstCharCnt;
141
142 WCHAR* wszDestStr;
143 wszDestStr=(WCHAR*) malloc(MAX_SAMPLES_STR_SIZE*sizeof(WCHAR));
144
145 nDestStrCnt=0;
146 nFirstCharCnt=0;
147
148 wcscpy(wszDestStr,L"");
149
150 while(nFirstCharCnt<(int)wcslen(wszSourceStr))
151 {
152 if(wszSourceStr[nFirstCharCnt]==wszTempl[0])
153 {
154 nSubStrCnt=0;
155 for(nCharCnt=nFirstCharCnt;nCharCnt<nFirstCharCnt+(int)wcslen(wszTempl);nCharCnt++)
156 {
157 if(wszSourceStr[nCharCnt]==wszTempl[nSubStrCnt])
158 {
159 nSubStrCnt++;
160 }
161 else
162 {
163 break;
164 }
165 if((int)wcslen(wszTempl)==nSubStrCnt)
166 {
167 wcscat(wszDestStr,wszStrToReplace);
168 nDestStrCnt=(int)wcslen(wszDestStr);
169 nFirstCharCnt+=(int)wcslen(wszTempl)-1;
170 break;
171 }
172 }
173 }
174 else
175 {
176 wszDestStr[nDestStrCnt++]=wszSourceStr[nFirstCharCnt];
177 wszDestStr[nDestStrCnt]='\0';
178 }
179 nFirstCharCnt++;
180 }
181
182 return wszDestStr;
183 }
184
185 static
186 VOID
187 InitPropSheetPage(PROPSHEETPAGE *PsPage, WORD IdDlg, DLGPROC DlgProc)
188 {
189 ZeroMemory(PsPage, sizeof(PROPSHEETPAGE));
190 PsPage->dwSize = sizeof(PROPSHEETPAGE);
191 PsPage->dwFlags = PSP_DEFAULT;
192 PsPage->hInstance = hApplet;
193 PsPage->pszTemplate = MAKEINTRESOURCE(IdDlg);
194 PsPage->pfnDlgProc = DlgProc;
195 }
196
197 /* Create applets */
198 LONG
199 APIENTRY
200 SetupApplet(HWND hwnd, UINT uMsg, LONG wParam, LONG lParam)
201 {
202
203 PROPSHEETPAGE PsPage[NUM_SHEETS];
204 PROPSHEETHEADER psh;
205 TCHAR Caption[MAX_STR_SIZE];
206
207 UNREFERENCED_PARAMETER(lParam);
208 UNREFERENCED_PARAMETER(wParam);
209 UNREFERENCED_PARAMETER(uMsg);
210 UNREFERENCED_PARAMETER(hwnd);
211
212 LoadString(hApplet, IDS_CPLNAME, Caption, sizeof(Caption) / sizeof(TCHAR));
213
214 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
215 psh.dwSize = sizeof(PROPSHEETHEADER);
216 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK | PSH_PROPTITLE;
217 psh.hwndParent = NULL;
218 psh.hInstance = hApplet;
219 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON));
220 psh.pszCaption = Caption;
221 psh.nPages = sizeof(PsPage) / sizeof(PROPSHEETPAGE);
222 psh.nStartPage = 0;
223 psh.ppsp = PsPage;
224
225 InitPropSheetPage(&PsPage[0], IDD_NUMSOPTSSETUP, NumsOptsSetProc);
226 InitPropSheetPage(&PsPage[1], IDD_CURRENCYOPTSSETUP, CurrencyOptsSetProc);
227 InitPropSheetPage(&PsPage[2], IDD_TIMEOPTSSETUP, TimeOptsSetProc);
228 InitPropSheetPage(&PsPage[3], IDD_DATEOPTSSETUP, DateOptsSetProc);
229
230 return (LONG)(PropertySheet(&psh) != -1);
231 }
232
233 /* EOF */