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