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