Fix a couple of problems with FreeLDR portability.
[reactos.git] / reactos / boot / freeldr / freeldr / ui / tui.c
index 0f635aa..ff9d73f 100644 (file)
 #include <freeldr.h>
 
 PVOID  TextVideoBuffer = NULL;
-extern BOOLEAN UiDrawTime;
-extern BOOLEAN UiMinimal;
 
 /*
  * printf() - prints formatted text to stdout
  * originally from GRUB
  */
-int printf(const char *format, ... )
+int TuiPrintf(const char *format, ... )
 {
        va_list ap;
        va_start(ap,format);
@@ -113,25 +111,6 @@ VOID TuiUnInitialize(VOID)
 
 VOID TuiDrawBackdrop(VOID)
 {
-    if (UiMinimal)
-    {
-        //
-        // Fill in a black background
-        //
-        TuiFillArea(0,
-                    0,
-                    UiScreenWidth - 1,
-                    UiScreenHeight - 1,
-                    0,
-                    0);
-
-        //
-        // Update the screen buffer
-        //
-        VideoCopyOffScreenBufferToVRAM();
-        return;
-    }
-
        //
        // Fill in the background (excluding title box & status bar)
        //
@@ -450,11 +429,6 @@ VOID TuiDrawStatusText(PCSTR StatusText)
 {
        ULONG           i;
 
-    //
-    // Minimal UI doesn't have a status bar
-    //
-    if (UiMinimal) return;
-
        TuiDrawText(0, UiScreenHeight-1, " ", ATTR(UiStatusBarFgColor, UiStatusBarBgColor));
        TuiDrawText(1, UiScreenHeight-1, StatusText, ATTR(UiStatusBarFgColor, UiStatusBarBgColor));
 
@@ -585,7 +559,7 @@ VOID TuiMessageBox(PCSTR MessageText)
        PVOID   ScreenBuffer;
 
        // Save the screen contents
-       ScreenBuffer = MmAllocateMemory(UiScreenWidth * UiScreenHeight * 2);
+       ScreenBuffer = MmHeapAlloc(UiScreenWidth * UiScreenHeight * 2);
        TuiSaveScreen(ScreenBuffer);
 
        // Display the message box
@@ -593,7 +567,7 @@ VOID TuiMessageBox(PCSTR MessageText)
 
        // Restore the screen contents
        TuiRestoreScreen(ScreenBuffer);
-       MmFreeMemory(ScreenBuffer);
+       MmHeapFree(ScreenBuffer);
 }
 
 VOID TuiMessageBoxCritical(PCSTR MessageText)
@@ -692,28 +666,10 @@ VOID TuiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText)
        ULONG           Width = 50; // Allow for 50 "bars"
        ULONG           Height = 2;
 
-       //
-       // Is this the minimal UI?
-       //
-       if (UiMinimal)
-       {
-               //
-               // Use alternate settings
-               //
-               Width = 80;
-               Left = 0;
-               Right = Left + Width;
-               Top = UiScreenHeight - Height - 4;
-               Bottom = Top + Height + 1;
-       }
-       else
-       {
-               Left = (UiScreenWidth - Width - 4) / 2;
-               Right = Left + Width + 3;
-               Top = (UiScreenHeight - Height - 2) / 2;
-               Top += 2;
-       }
-
+       Left = (UiScreenWidth - Width - 4) / 2;
+       Right = Left + Width + 3;
+       Top = (UiScreenHeight - Height - 2) / 2;
+       Top += 2;
        Bottom = Top + Height + 1;
 
        TuiDrawProgressBar(Left, Top, Right, Bottom, Position, Range, ProgressText);
@@ -732,26 +688,13 @@ VOID TuiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG
                Position = Range;
        }
 
-    //
-    // Minimal UI has no box, and only generic loading text
-    //
-    if (!UiMinimal)
-    {
-           // Draw the box
-           TuiDrawBox(Left, Top, Right, Bottom, VERT, HORZ, TRUE, TRUE, ATTR(UiMenuFgColor, UiMenuBgColor));
-
-       //
-        //  Draw the "Loading..." text
-        //
-           TuiDrawCenteredText(Left + 2, Top + 2, Right - 2, Top + 2, ProgressText, ATTR(UiTextColor, UiMenuBgColor));
-    }
-    else
-    {
-       //
-        //  Draw the "Loading..." text
-        //
-        TuiDrawCenteredText(Left + 2, Top + 1, Right - 2, Top + 1, "ReactOS is loading files...", ATTR(7, 0));
-    }
+       // Draw the box
+       TuiDrawBox(Left, Top, Right, Bottom, VERT, HORZ, TRUE, TRUE, ATTR(UiMenuFgColor, UiMenuBgColor));
+
+       //
+       //  Draw the "Loading..." text
+       //
+       TuiDrawCenteredText(Left + 2, Top + 2, Right - 2, Top + 2, ProgressText, ATTR(UiTextColor, UiMenuBgColor));
 
        // Draw the percent complete
        for (i=0; i<(Position*ProgressBarWidth)/Range; i++)
@@ -759,14 +702,11 @@ VOID TuiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG
                TuiDrawText(Left+2+i, Top+2, "\xDB", ATTR(UiTextColor, UiMenuBgColor));
        }
 
-       // Draw the shadow for non-minimal UI
-    if (!UiMinimal)
-    {
-           for (; i<ProgressBarWidth; i++)
-           {
-                   TuiDrawText(Left+2+i, Top+2, "\xB2", ATTR(UiTextColor, UiMenuBgColor));
-           }
-    }
+       // Draw the shadow
+       for (; i<ProgressBarWidth; i++)
+       {
+               TuiDrawText(Left+2+i, Top+2, "\xB2", ATTR(UiTextColor, UiMenuBgColor));
+       }
 
        TuiUpdateDateTime();
        VideoCopyOffScreenBufferToVRAM();
@@ -834,7 +774,7 @@ VOID TuiFadeInBackdrop(VOID)
 
        if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed())
        {
-               TuiFadePalette = (PPALETTE_ENTRY)MmAllocateMemory(sizeof(PALETTE_ENTRY) * 64);
+               TuiFadePalette = (PPALETTE_ENTRY)MmHeapAlloc(sizeof(PALETTE_ENTRY) * 64);
 
                if (TuiFadePalette != NULL)
                {
@@ -849,7 +789,7 @@ VOID TuiFadeInBackdrop(VOID)
        if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed() && TuiFadePalette != NULL)
        {
                VideoFadeIn(TuiFadePalette, 64);
-               MmFreeMemory(TuiFadePalette);
+               MmHeapFree(TuiFadePalette);
        }
 }
 
@@ -859,7 +799,7 @@ VOID TuiFadeOut(VOID)
 
        if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed())
        {
-               TuiFadePalette = (PPALETTE_ENTRY)MmAllocateMemory(sizeof(PALETTE_ENTRY) * 64);
+               TuiFadePalette = (PPALETTE_ENTRY)MmHeapAlloc(sizeof(PALETTE_ENTRY) * 64);
 
                if (TuiFadePalette != NULL)
                {
@@ -877,7 +817,7 @@ VOID TuiFadeOut(VOID)
        if (UiUseSpecialEffects && ! MachVideoIsPaletteFixed() && TuiFadePalette != NULL)
        {
                VideoRestorePaletteState(TuiFadePalette, 64);
-               MmFreeMemory(TuiFadePalette);
+               MmHeapFree(TuiFadePalette);
        }
 
 }
@@ -901,7 +841,7 @@ BOOLEAN TuiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length)
        PVOID   ScreenBuffer;
 
        // Save the screen contents
-       ScreenBuffer = MmAllocateMemory(UiScreenWidth * UiScreenHeight * 2);
+       ScreenBuffer = MmHeapAlloc(UiScreenWidth * UiScreenHeight * 2);
        TuiSaveScreen(ScreenBuffer);
 
        // Find the height
@@ -995,7 +935,7 @@ BOOLEAN TuiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length)
                                }
                                else
                                {
-                                       beep();
+                                       MachBeep();
                                }
                        }
                        else // Add this key to the buffer
@@ -1008,7 +948,7 @@ BOOLEAN TuiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length)
                                }
                                else
                                {
-                                       beep();
+                                       MachBeep();
                                }
                        }
                }
@@ -1042,7 +982,32 @@ BOOLEAN TuiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length)
 
        // Restore the screen contents
        TuiRestoreScreen(ScreenBuffer);
-       MmFreeMemory(ScreenBuffer);
+       MmHeapFree(ScreenBuffer);
 
        return ReturnCode;
 }
+
+const UIVTBL TuiVtbl =
+{
+       TuiInitialize,
+       TuiUnInitialize,
+       TuiDrawBackdrop,
+       TuiFillArea,
+       TuiDrawShadow,
+       TuiDrawBox,
+       TuiDrawText,
+       TuiDrawCenteredText,
+       TuiDrawStatusText,
+       TuiUpdateDateTime,
+       TuiMessageBox,
+       TuiMessageBoxCritical,
+       TuiDrawProgressBarCenter,
+       TuiDrawProgressBar,
+       TuiEditBox,
+       TuiTextToColor,
+       TuiTextToFillStyle,
+       TuiFadeInBackdrop,
+       TuiFadeOut,
+       TuiDisplayMenu,
+       TuiDrawMenu,
+};