[SETUPLIB][USETUP][INPUT.CPL] MUI integration with setuplib.
[reactos.git] / base / setup / usetup / mui.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2008 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 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS text-mode setup
22 * FILE: base/setup/usetup/mui.c
23 * PURPOSE: Text-mode setup
24 * PROGRAMMER:
25 */
26
27 #include "usetup.h"
28 #include "muilanguages.h"
29
30 #define NDEBUG
31 #include <debug.h>
32
33 static
34 ULONG
35 FindLanguageIndex(VOID)
36 {
37 ULONG lngIndex = 0;
38
39 if (SelectedLanguageId == NULL)
40 {
41 /* Default to en-US */
42 return 0; // FIXME!!
43 // SelectedLanguageId = L"00000409";
44 }
45
46 while (ResourceList[lngIndex].MuiPages != NULL)
47 {
48 if (_wcsicmp(ResourceList[lngIndex].LanguageID, SelectedLanguageId) == 0)
49 {
50 return lngIndex;
51 }
52
53 lngIndex++;
54 }
55
56 return 0;
57 }
58
59
60 #if 0
61 BOOLEAN
62 IsLanguageAvailable(
63 PWCHAR LanguageId)
64 {
65 ULONG lngIndex = 0;
66
67 while (ResourceList[lngIndex].MuiPages != NULL)
68 {
69 if (_wcsicmp(ResourceList[lngIndex].LanguageID, LanguageId) == 0)
70 return TRUE;
71
72 lngIndex++;
73 }
74
75 return FALSE;
76 }
77 #endif
78
79
80 static
81 const MUI_ENTRY *
82 FindMUIEntriesOfPage(
83 IN ULONG PageNumber)
84 {
85 ULONG muiIndex = 0;
86 ULONG lngIndex;
87 const MUI_PAGE * Pages = NULL;
88
89 lngIndex = max(FindLanguageIndex(), 0);
90 Pages = ResourceList[lngIndex].MuiPages;
91
92 while (Pages[muiIndex].MuiEntry != NULL)
93 {
94 if (Pages[muiIndex].Number == PageNumber)
95 return Pages[muiIndex].MuiEntry;
96
97 muiIndex++;
98 }
99
100 return NULL;
101 }
102
103 static
104 const MUI_ERROR *
105 FindMUIErrorEntries(VOID)
106 {
107 ULONG lngIndex = max(FindLanguageIndex(), 0);
108 return ResourceList[lngIndex].MuiErrors;
109 }
110
111 static
112 const MUI_STRING *
113 FindMUIStringEntries(VOID)
114 {
115 ULONG lngIndex = max(FindLanguageIndex(), 0);
116 return ResourceList[lngIndex].MuiStrings;
117 }
118
119
120 VOID
121 MUIClearPage(
122 IN ULONG page)
123 {
124 const MUI_ENTRY * entry;
125 ULONG index;
126
127 entry = FindMUIEntriesOfPage(page);
128 if (!entry)
129 {
130 PopupError("Error: Failed to find translated page",
131 NULL,
132 NULL,
133 POPUP_WAIT_NONE);
134 return;
135 }
136
137 index = 0;
138 while (entry[index].Buffer != NULL)
139 {
140 CONSOLE_ClearStyledText(entry[index].X,
141 entry[index].Y,
142 entry[index].Flags,
143 strlen(entry[index].Buffer));
144 index++;
145 }
146 }
147
148 VOID
149 MUIDisplayPage(
150 IN ULONG page)
151 {
152 const MUI_ENTRY * entry;
153 ULONG index;
154
155 entry = FindMUIEntriesOfPage(page);
156 if (!entry)
157 {
158 PopupError("Error: Failed to find translated page",
159 NULL,
160 NULL,
161 POPUP_WAIT_NONE);
162 return;
163 }
164
165 index = 0;
166 while (entry[index].Buffer != NULL)
167 {
168 CONSOLE_SetStyledText(entry[index].X,
169 entry[index].Y,
170 entry[index].Flags,
171 entry[index].Buffer);
172
173 index++;
174 }
175 }
176
177 VOID
178 MUIDisplayError(
179 IN ULONG ErrorNum,
180 OUT PINPUT_RECORD Ir,
181 IN ULONG WaitEvent,
182 ...)
183 {
184 const MUI_ERROR * entry;
185 CHAR Buffer[2048];
186 va_list ap;
187
188 if (ErrorNum >= ERROR_LAST_ERROR_CODE)
189 {
190 PopupError("Invalid error number provided",
191 "Press ENTER to continue",
192 Ir,
193 POPUP_WAIT_ENTER);
194
195 return;
196 }
197
198 entry = FindMUIErrorEntries();
199 if (!entry)
200 {
201 PopupError("Error: Failed to find translated error message",
202 NULL,
203 NULL,
204 POPUP_WAIT_NONE);
205 return;
206 }
207
208 va_start(ap, WaitEvent);
209 vsprintf(Buffer, entry[ErrorNum].ErrorText, ap);
210 va_end(ap);
211
212 PopupError(Buffer,
213 entry[ErrorNum].ErrorStatus,
214 Ir,
215 WaitEvent);
216 }
217
218 LPSTR
219 MUIGetString(
220 ULONG Number)
221 {
222 ULONG i;
223 const MUI_STRING * entry;
224 CHAR szErr[128];
225
226 entry = FindMUIStringEntries();
227 if (entry)
228 {
229 for (i = 0; entry[i].Number != 0; i++)
230 {
231 if (entry[i].Number == Number)
232 {
233 return entry[i].String;
234 }
235 }
236 }
237
238 sprintf(szErr, "Error: failed find string id %lu for language index %lu\n", Number, FindLanguageIndex());
239
240 PopupError(szErr,
241 NULL,
242 NULL,
243 POPUP_WAIT_NONE);
244
245 return "<nostring>";
246 }
247
248 VOID
249 SetConsoleCodePage(VOID)
250 {
251 UINT wCodePage;
252
253 #if 0
254 ULONG lngIndex = 0;
255
256 while (ResourceList[lngIndex].MuiPages != NULL)
257 {
258 if (_wcsicmp(ResourceList[lngIndex].LanguageID, SelectedLanguageId) == 0)
259 {
260 wCodePage = (UINT) wcstoul(ResourceList[lngIndex].OEMCPage, NULL, 10);
261 SetConsoleOutputCP(wCodePage);
262 return;
263 }
264
265 lngIndex++;
266 }
267 #else
268 wCodePage = (UINT)wcstoul(MUIGetOEMCodePage(SelectedLanguageId), NULL, 10);
269 SetConsoleOutputCP(wCodePage);
270 #endif
271 }
272
273 /* EOF */