ReactOS  0.4.15-dev-5608-gafb953a
mui.c
Go to the documentation of this file.
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 /* Special characters */
34 CHAR CharBullet = 0x07; /* bullet */
35 CHAR CharBlock = 0xDB; /* block */
36 CHAR CharHalfBlock = 0xDD; /* half-left block */
37 CHAR CharUpArrow = 0x18; /* up arrow */
38 CHAR CharDownArrow = 0x19; /* down arrow */
39 CHAR CharHorizontalLine = 0xC4; /* horizontal line */
40 CHAR CharVerticalLine = 0xB3; /* vertical line */
41 CHAR CharUpperLeftCorner = 0xDA; /* upper left corner */
42 CHAR CharUpperRightCorner = 0xBF; /* upper right corner */
43 CHAR CharLowerLeftCorner = 0xC0; /* lower left corner */
44 CHAR CharLowerRightCorner = 0xD9; /* lower right corner */
45 CHAR CharVertLineAndRightHorizLine = 0xC3; /* |- (vertical line and right horizontal line) */
46 CHAR CharLeftHorizLineAndVertLine = 0xB4; /* -| (left horizontal line and vertical line) */
47 CHAR CharDoubleHorizontalLine = 0xCD; /* double horizontal line (and underline) */
48 CHAR CharDoubleVerticalLine = 0xBA; /* double vertical line */
49 CHAR CharDoubleUpperLeftCorner = 0xC9; /* double upper left corner */
50 CHAR CharDoubleUpperRightCorner = 0xBB; /* double upper right corner */
51 CHAR CharDoubleLowerLeftCorner = 0xC8; /* double lower left corner */
52 CHAR CharDoubleLowerRightCorner = 0xBC; /* double lower right corner */
53 
54 static
55 ULONG
57 {
58  ULONG lngIndex = 0;
59 
60  if (SelectedLanguageId == NULL)
61  {
62  /* Default to en-US */
63  return 0; // FIXME!!
64  // SelectedLanguageId = L"00000409";
65  }
66 
67  while (ResourceList[lngIndex].MuiPages != NULL)
68  {
69  if (_wcsicmp(ResourceList[lngIndex].LanguageID, SelectedLanguageId) == 0)
70  {
71  return lngIndex;
72  }
73 
74  lngIndex++;
75  }
76 
77  return 0;
78 }
79 
80 
81 #if 0
82 BOOLEAN
84  PWCHAR LanguageId)
85 {
86  ULONG lngIndex = 0;
87 
88  while (ResourceList[lngIndex].MuiPages != NULL)
89  {
90  if (_wcsicmp(ResourceList[lngIndex].LanguageID, LanguageId) == 0)
91  return TRUE;
92 
93  lngIndex++;
94  }
95 
96  return FALSE;
97 }
98 #endif
99 
100 
101 static
102 const MUI_ENTRY *
104  IN ULONG PageNumber)
105 {
106  ULONG muiIndex = 0;
107  ULONG lngIndex;
108  const MUI_PAGE * Pages = NULL;
109 
110  lngIndex = max(FindLanguageIndex(), 0);
111  Pages = ResourceList[lngIndex].MuiPages;
112 
113  while (Pages[muiIndex].MuiEntry != NULL)
114  {
115  if (Pages[muiIndex].Number == PageNumber)
116  return Pages[muiIndex].MuiEntry;
117 
118  muiIndex++;
119  }
120 
121  return NULL;
122 }
123 
124 static
125 const MUI_ERROR *
127 {
128  ULONG lngIndex = max(FindLanguageIndex(), 0);
129  return ResourceList[lngIndex].MuiErrors;
130 }
131 
132 static
133 const MUI_STRING *
135 {
136  ULONG lngIndex = max(FindLanguageIndex(), 0);
137  return ResourceList[lngIndex].MuiStrings;
138 }
139 
140 
141 VOID
143  IN ULONG page)
144 {
145  const MUI_ENTRY * entry;
146  ULONG index;
147 
149  if (!entry)
150  {
151  PopupError("Error: Failed to find translated page",
152  NULL,
153  NULL,
155  return;
156  }
157 
158  index = 0;
159  while (entry[index].Buffer != NULL)
160  {
162  entry[index].Y,
163  entry[index].Flags,
165  index++;
166  }
167 }
168 
169 VOID
171  IN ULONG page)
172 {
173  const MUI_ENTRY * entry;
174  ULONG index;
175 
177  if (!entry)
178  {
179  PopupError("Error: Failed to find translated page",
180  NULL,
181  NULL,
183  return;
184  }
185 
186  index = 0;
187  while (entry[index].Buffer != NULL)
188  {
190  entry[index].Y,
191  entry[index].Flags,
192  entry[index].Buffer);
193 
194  index++;
195  }
196 }
197 
198 VOID
200  IN ULONG ErrorNum,
201  OUT PINPUT_RECORD Ir,
202  IN ULONG WaitEvent,
203  IN va_list args)
204 {
205  const MUI_ERROR* entry;
206  CHAR Buffer[2048];
207 
208  if (ErrorNum >= ERROR_LAST_ERROR_CODE)
209  {
210  PopupError("Invalid error number provided",
211  "Press ENTER to continue",
212  Ir,
214  return;
215  }
216 
218  if (!entry)
219  {
220  PopupError("Error: Failed to find translated error message",
221  NULL,
222  NULL,
224  return;
225  }
226 
227  vsprintf(Buffer, entry[ErrorNum].ErrorText, args);
228 
230  entry[ErrorNum].ErrorStatus,
231  Ir,
232  WaitEvent);
233 }
234 
235 VOID
236 __cdecl
238  IN ULONG ErrorNum,
239  OUT PINPUT_RECORD Ir,
240  IN ULONG WaitEvent,
241  ...)
242 {
243  va_list arg_ptr;
244 
245  va_start(arg_ptr, WaitEvent);
246  MUIDisplayErrorV(ErrorNum, Ir, WaitEvent, arg_ptr);
247  va_end(arg_ptr);
248 }
249 
250 PCSTR
252  ULONG Number)
253 {
254  ULONG i;
255  const MUI_STRING * entry;
256  CHAR szErr[128];
257 
259  if (entry)
260  {
261  for (i = 0; entry[i].Number != 0; i++)
262  {
263  if (entry[i].Number == Number)
264  {
265  return entry[i].String;
266  }
267  }
268  }
269 
270  sprintf(szErr, "Error: failed find string id %lu for language index %lu\n", Number, FindLanguageIndex());
271 
273  NULL,
274  NULL,
276 
277  return "<nostring>";
278 }
279 
296 const MUI_ENTRY *
298  IN ULONG Page,
299  IN INT TextID)
300 {
301  const MUI_ENTRY * entry;
302  ULONG index;
303 
304  /* Retrieve the entries of a MUI page */
306  if (!entry)
307  {
308  DPRINT("MUIGetEntryData(): Failed to get the translated entry page!\n");
309  return NULL;
310  }
311 
312  /* Loop over the ID entries and check if it matches with one of them */
313  for (index = 0; entry[index].Buffer != NULL; index++)
314  {
315  if (entry[index].TextID == TextID)
316  {
317  /* They match so return the MUI entry */
318  return &entry[index];
319  }
320  }
321 
322  /* Page number or ID are incorrect so in this case bail out */
323  DPRINT("Couldn't get the MUI entry field from the page!\n");
324  return NULL;
325 }
326 
343 VOID
345  IN ULONG Page,
346  IN INT TextID)
347 {
348  const MUI_ENTRY * entry;
349  ULONG Index = 0;
350 
351  /* Get the MUI entry */
352  entry = MUIGetEntry(Page, TextID);
353 
354  if (!entry)
355  return;
356 
357  /* Ensure that the text string given by the text ID and page is not NULL */
358  while (entry[Index].Buffer != NULL)
359  {
360  /* If text ID is not correct, skip the entry */
361  if (entry[Index].TextID != TextID)
362  {
363  Index++;
364  continue;
365  }
366 
367  /* Remove the text by using CONSOLE_ClearTextXY() */
369  entry[Index].X,
370  entry[Index].Y,
372 
373  /* Increment the index and loop over next entires with the same ID */
374  Index++;
375  }
376 }
377 
398 VOID
400  IN ULONG Page,
401  IN INT TextID,
402  IN INT Flags)
403 {
404  const MUI_ENTRY * entry;
405  ULONG Index = 0;
406 
407  /* Get the MUI entry */
408  entry = MUIGetEntry(Page, TextID);
409 
410  if (!entry)
411  return;
412 
413  /* Ensure that the text string given by the text ID and page is not NULL */
414  while (entry[Index].Buffer != NULL)
415  {
416  /* If text ID is not correct, skip the entry */
417  if (entry[Index].TextID != TextID)
418  {
419  Index++;
420  continue;
421  }
422 
423  /* Now, begin removing the text by calling CONSOLE_ClearStyledText() */
425  entry[Index].X,
426  entry[Index].Y,
427  Flags,
429 
430  /* Increment the index and loop over next entires with the same ID */
431  Index++;
432  }
433 }
434 
451 VOID
453  IN ULONG Page,
454  IN INT TextID)
455 {
456  const MUI_ENTRY * entry;
457  ULONG Index = 0;
458 
459  /* Get the MUI entry */
460  entry = MUIGetEntry(Page, TextID);
461 
462  if (!entry)
463  return;
464 
465  /* Ensure that the text string given by the text ID and page is not NULL */
466  while (entry[Index].Buffer != NULL)
467  {
468  /* If text ID is not correct, skip the entry */
469  if (entry[Index].TextID != TextID)
470  {
471  Index++;
472  continue;
473  }
474 
475  /* Print the text to the console output by calling CONSOLE_SetTextXY() */
477 
478  /* Increment the index and loop over next entires with the same ID */
479  Index++;
480  }
481 }
482 
503 VOID
505  IN ULONG Page,
506  IN INT TextID,
507  IN INT Flags)
508 {
509  const MUI_ENTRY * entry;
510  ULONG Index = 0;
511 
512  /* Get the MUI entry */
513  entry = MUIGetEntry(Page, TextID);
514 
515  if (!entry)
516  return;
517 
518  /* Ensure that the text string given by the text ID and page is not NULL */
519  while (entry[Index].Buffer != NULL)
520  {
521  /* If text ID is not correct, skip the entry */
522  if (entry[Index].TextID != TextID)
523  {
524  Index++;
525  continue;
526  }
527 
528  /* Print the text to the console output by calling CONSOLE_SetStyledText() */
530 
531  /* Increment the index and loop over next entires with the same ID */
532  Index++;
533  }
534 }
535 
536 VOID
538 {
539  UINT wCodePage;
540 
541 #if 0
542  ULONG lngIndex = 0;
543 
544  while (ResourceList[lngIndex].MuiPages != NULL)
545  {
546  if (_wcsicmp(ResourceList[lngIndex].LanguageID, SelectedLanguageId) == 0)
547  {
548  wCodePage = (UINT) wcstoul(ResourceList[lngIndex].OEMCPage, NULL, 10);
549  SetConsoleOutputCP(wCodePage);
550  return;
551  }
552 
553  lngIndex++;
554  }
555 #else
557  SetConsoleOutputCP(wCodePage);
558 #endif
559 
560  switch (wCodePage)
561  {
562  case 28606: /* Romanian */
563  case 932: /* Japanese */
564  /* Set special characters */
565  CharBullet = 0x07;
566  CharBlock = 0x01;
567  CharHalfBlock = 0x02;
568  CharUpArrow = 0x03;
569  CharDownArrow = 0x04;
570  CharHorizontalLine = 0x05;
571  CharVerticalLine = 0x06;
572  CharUpperLeftCorner = 0x08;
573  CharUpperRightCorner = 0x09;
574  CharLowerLeftCorner = 0x0B;
575  CharLowerRightCorner = 0x0C;
579  CharDoubleVerticalLine = 0x11;
584 
585  /* FIXME: Enter 640x400 video mode */
586  break;
587 
588  default: /* Other codepages */
589  /* Set special characters */
590  CharBullet = 0x07;
591  CharBlock = 0xDB;
592  CharHalfBlock = 0xDD;
593  CharUpArrow = 0x18;
594  CharDownArrow = 0x19;
595  CharHorizontalLine = 0xC4;
596  CharVerticalLine = 0xB3;
597  CharUpperLeftCorner = 0xDA;
598  CharUpperRightCorner = 0xBF;
599  CharLowerLeftCorner = 0xC0;
600  CharLowerRightCorner = 0xD9;
604  CharDoubleVerticalLine = 0xBA;
609 
610  /* FIXME: Enter 720x400 video mode */
611  break;
612  }
613 }
CHAR CharUpperRightCorner
Definition: mui.c:42
CHAR CharDoubleLowerRightCorner
Definition: mui.c:52
CHAR CharUpArrow
Definition: mui.c:37
#define IN
Definition: typedefs.h:39
BOOL WINAPI SetConsoleOutputCP(IN UINT wCodepage)
Definition: console.c:695
#define max(a, b)
Definition: svc.c:63
CHAR CharDownArrow
Definition: mui.c:38
CHAR CharHorizontalLine
Definition: mui.c:39
#define POPUP_WAIT_NONE
Definition: usetup.h:123
VOID CONSOLE_SetTextXY(IN SHORT x, IN SHORT y, IN LPCSTR Text)
Definition: consup.c:320
#define Y(I)
#define __cdecl
Definition: accygwin.h:79
CHAR CharBlock
Definition: mui.c:35
CHAR CharBullet
Definition: mui.c:34
CHAR CharDoubleHorizontalLine
Definition: mui.c:47
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
VOID CONSOLE_ClearTextXY(IN SHORT x, IN SHORT y, IN SHORT Length)
Definition: consup.c:339
VOID MUIDisplayPage(IN ULONG page)
Definition: mui.c:170
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
CHAR CharVerticalLine
Definition: mui.c:40
CHAR CharLowerLeftCorner
Definition: mui.c:43
VOID PopupError(PCCH Text, PCCH Status, PINPUT_RECORD Ir, ULONG WaitEvent)
Definition: usetup.c:256
CHAR CharDoubleUpperRightCorner
Definition: mui.c:50
CHAR CharDoubleVerticalLine
Definition: mui.c:48
Definition: mui.h:18
uint16_t * PWCHAR
Definition: typedefs.h:56
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
CHAR CharLowerRightCorner
Definition: mui.c:44
static const MUI_STRING * FindMUIStringEntries(VOID)
Definition: mui.c:134
Definition: match.c:390
int32_t INT
Definition: typedefs.h:58
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:304
PCWSTR MUIGetOEMCodePage(IN PCWSTR LanguageId)
Definition: mui.c:96
VOID MUISetStyledText(IN ULONG Page, IN INT TextID, IN INT Flags)
Definition: mui.c:504
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define va_end(ap)
Definition: acmsvcex.h:90
_In_ PVOID _Out_opt_ BOOLEAN _Out_opt_ PPFN_NUMBER Page
Definition: mm.h:1295
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
VOID MUIClearStyledText(IN ULONG Page, IN INT TextID, IN INT Flags)
Definition: mui.c:399
char * va_list
Definition: acmsvcex.h:78
Definition: module.h:566
Definition: bufpool.h:45
GLuint index
Definition: glext.h:6031
PCSTR MUIGetString(ULONG Number)
Definition: mui.c:251
CHAR CharVertLineAndRightHorizLine
Definition: mui.c:45
CHAR CharUpperLeftCorner
Definition: mui.c:41
Definition: mui.h:24
static const MUI_ERROR * FindMUIErrorEntries(VOID)
Definition: mui.c:126
CHAR CharDoubleLowerLeftCorner
Definition: mui.c:51
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_In_ WDFCOLLECTION _In_ ULONG Index
VOID MUIClearPage(IN ULONG page)
Definition: mui.c:142
VOID CONSOLE_SetStyledText(IN SHORT x, IN SHORT y, IN INT Flags, IN LPCSTR Text)
Definition: consup.c:671
PCWSTR SelectedLanguageId
Definition: usetup.c:66
va_start(ap, x)
CHAR CharLeftHorizLineAndVertLine
Definition: mui.c:46
#define index(s, c)
Definition: various.h:29
uint32_t entry
Definition: isohybrid.c:63
VOID __cdecl MUIDisplayError(IN ULONG ErrorNum, OUT PINPUT_RECORD Ir, IN ULONG WaitEvent,...)
Definition: mui.c:237
CHAR CharHalfBlock
Definition: mui.c:36
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:204
Definition: mui.h:3
static ULONG FindLanguageIndex(VOID)
Definition: mui.c:56
#define POPUP_WAIT_ENTER
Definition: usetup.h:125
Definition: mui.h:12
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
VOID MUIClearText(IN ULONG Page, IN INT TextID)
Definition: mui.c:344
unsigned short USHORT
Definition: pedump.c:61
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
CHAR CharDoubleUpperLeftCorner
Definition: mui.c:49
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
BOOLEAN IsLanguageAvailable(IN PCWSTR LanguageId)
Definition: mui.c:70
VOID MUIDisplayErrorV(IN ULONG ErrorNum, OUT PINPUT_RECORD Ir, IN ULONG WaitEvent, IN va_list args)
Definition: mui.c:199
TCHAR szErr[256]
Definition: service.c:38
#define OUT
Definition: typedefs.h:40
unsigned int ULONG
Definition: retypes.h:1
const MUI_ENTRY * MUIGetEntry(IN ULONG Page, IN INT TextID)
Definition: mui.c:297
const char * PCSTR
Definition: typedefs.h:52
VOID CONSOLE_ClearStyledText(IN SHORT x, IN SHORT y, IN INT Flags, IN SHORT Length)
Definition: consup.c:755
static const MUI_ENTRY * FindMUIEntriesOfPage(IN ULONG PageNumber)
Definition: mui.c:103
#define DPRINT
Definition: sndvol32.h:71
VOID MUISetText(IN ULONG Page, IN INT TextID)
Definition: mui.c:452
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
VOID SetConsoleCodePage(VOID)
Definition: mui.c:537
MUI_ENTRY * MuiEntry
Definition: mui.h:21