diff --git a/sdk/xtdk/bltypes.h b/sdk/xtdk/bltypes.h index 5615a6b..09e20c8 100644 --- a/sdk/xtdk/bltypes.h +++ b/sdk/xtdk/bltypes.h @@ -30,6 +30,18 @@ #define XTBL_DEBUGPORT_SCREEN 1 #define XTBL_DEBUGPORT_SERIAL 2 +/* TUI dialog box attributes */ +#define XTBL_TUI_DIALOG_GENERIC_BOX 1 +#define XTBL_TUI_DIALOG_ERROR_BOX 2 +#define XTBL_TUI_DIALOG_ACTIVE_BUTTON 4 +#define XTBL_TUI_DIALOG_INACTIVE_BUTTON 8 +#define XTBL_TUI_DIALOG_ACTIVE_INPUT_FIELD 16 +#define XTBL_TUI_DIALOG_INACTIVE_INPUT_FIELD 32 +#define XTBL_TUI_DIALOG_PROGRESS_BAR 64 + +/* TUI dialog box maximum width */ +#define XTBL_TUI_MAX_DIALOG_WIDTH 100 + /* Loader protocol routine pointers */ typedef EFI_STATUS (*PBL_ALLOCATE_PAGES)(IN UINT64 Size, OUT PEFI_PHYSICAL_ADDRESS Memory); typedef EFI_STATUS (*PBL_ALLOCATE_POOL)(IN UINT_PTR Size, OUT PVOID *Memory); diff --git a/xtldr2/textui.c b/xtldr2/textui.c index 88360d2..3901af1 100644 --- a/xtldr2/textui.c +++ b/xtldr2/textui.c @@ -9,17 +9,6 @@ #include -/* TUI dialog box attributes */ -#define TUI_DIALOG_GENERIC_BOX 1 -#define TUI_DIALOG_ERROR_BOX 2 -#define TUI_DIALOG_ACTIVE_BUTTON 4 -#define TUI_DIALOG_INACTIVE_BUTTON 8 -#define TUI_DIALOG_ACTIVE_INPUT_FIELD 16 -#define TUI_DIALOG_INACTIVE_INPUT_FIELD 32 -#define TUI_DIALOG_PROGRESS_BAR 64 - -#define TUI_MAX_DIALOG_WIDTH 100 - /** * Displays a red error dialog box with the specified caption and message. * @@ -43,7 +32,7 @@ BlDisplayErrorDialog(IN PWCHAR Caption, UINT_PTR Index; /* Set dialog window attributes */ - Handle.Attributes = TUI_DIALOG_ERROR_BOX | TUI_DIALOG_ACTIVE_BUTTON; + Handle.Attributes = XTBL_TUI_DIALOG_ERROR_BOX | XTBL_TUI_DIALOG_ACTIVE_BUTTON; /* Determine dialog window size and position */ BlpDetermineDialogBoxSize(&Handle, Message); @@ -96,7 +85,7 @@ BlDisplayInfoDialog(IN PWCHAR Caption, UINT_PTR Index; /* Set dialog window attributes */ - Handle.Attributes = TUI_DIALOG_GENERIC_BOX | TUI_DIALOG_ACTIVE_BUTTON; + Handle.Attributes = XTBL_TUI_DIALOG_GENERIC_BOX | XTBL_TUI_DIALOG_ACTIVE_BUTTON; /* Determine dialog window size and position */ BlpDetermineDialogBoxSize(&Handle, Message); @@ -151,7 +140,7 @@ BlDisplayProgressDialog(IN PWCHAR Caption, XTBL_DIALOG_HANDLE Handle; /* Set dialog window attributes */ - Handle.Attributes = TUI_DIALOG_GENERIC_BOX | TUI_DIALOG_PROGRESS_BAR; + Handle.Attributes = XTBL_TUI_DIALOG_GENERIC_BOX | XTBL_TUI_DIALOG_PROGRESS_BAR; /* Determine dialog window size and position */ BlpDetermineDialogBoxSize(&Handle, Message); @@ -238,13 +227,13 @@ BlpDetermineDialogBoxSize(IN OUT PXTBL_DIALOG_HANDLE Handle, /* Check enabled components that affect dialog window size */ switch(Attributes & Mask) { - case TUI_DIALOG_ACTIVE_BUTTON: - case TUI_DIALOG_INACTIVE_BUTTON: + case XTBL_TUI_DIALOG_ACTIVE_BUTTON: + case XTBL_TUI_DIALOG_INACTIVE_BUTTON: Height += 1; break; - case TUI_DIALOG_ACTIVE_INPUT_FIELD: - case TUI_DIALOG_INACTIVE_INPUT_FIELD: - case TUI_DIALOG_PROGRESS_BAR: + case XTBL_TUI_DIALOG_ACTIVE_INPUT_FIELD: + case XTBL_TUI_DIALOG_INACTIVE_INPUT_FIELD: + case XTBL_TUI_DIALOG_PROGRESS_BAR: Height += 2; break; } @@ -255,10 +244,10 @@ BlpDetermineDialogBoxSize(IN OUT PXTBL_DIALOG_HANDLE Handle, } /* Check if input field is active */ - if(Handle->Attributes & (TUI_DIALOG_ACTIVE_INPUT_FIELD | TUI_DIALOG_INACTIVE_INPUT_FIELD)) + if(Handle->Attributes & (XTBL_TUI_DIALOG_ACTIVE_INPUT_FIELD | XTBL_TUI_DIALOG_INACTIVE_INPUT_FIELD)) { /* Set maximum dialog window width to fit input field */ - Width = TUI_MAX_DIALOG_WIDTH; + Width = XTBL_TUI_MAX_DIALOG_WIDTH; } /* Get message length and count dialog window dimensions */ @@ -292,10 +281,10 @@ BlpDetermineDialogBoxSize(IN OUT PXTBL_DIALOG_HANDLE Handle, BlQueryConsoleMode(&Handle->ResX, &Handle->ResY); /* Make sure dialog window fits in the buffer */ - if(Width > TUI_MAX_DIALOG_WIDTH) + if(Width > XTBL_TUI_MAX_DIALOG_WIDTH) { /* Set maximum dialog window width */ - Width = TUI_MAX_DIALOG_WIDTH; + Width = XTBL_TUI_MAX_DIALOG_WIDTH; } /* Make sure dialog window fits on the screen (X axis) and it is not too small for input field */ @@ -341,12 +330,12 @@ BlpDrawDialogBox(IN OUT PXTBL_DIALOG_HANDLE Handle, IN PWCHAR Caption, IN PWCHAR Message) { - WCHAR BoxLine[TUI_MAX_DIALOG_WIDTH]; + WCHAR BoxLine[XTBL_TUI_MAX_DIALOG_WIDTH]; SIZE_T CaptionLength; UINT_PTR PosX, PosY; /* Set dialog colors */ - if(Handle->Attributes & TUI_DIALOG_ERROR_BOX) + if(Handle->Attributes & XTBL_TUI_DIALOG_ERROR_BOX) { /* Error dialog with red background and brown button */ Handle->DialogColor = EFI_TEXT_BGCOLOR_RED; @@ -457,10 +446,10 @@ BlpDrawDialogButton(IN PXTBL_DIALOG_HANDLE Handle) ULONG ButtonColor, TextColor; /* Set dialog button colors */ - if(Handle->Attributes & TUI_DIALOG_ACTIVE_BUTTON) + if(Handle->Attributes & XTBL_TUI_DIALOG_ACTIVE_BUTTON) { /* This is an active button */ - if(Handle->Attributes & TUI_DIALOG_ERROR_BOX) + if(Handle->Attributes & XTBL_TUI_DIALOG_ERROR_BOX) { /* This is an error dialog box */ ButtonColor = EFI_TEXT_BGCOLOR_BROWN; @@ -505,15 +494,15 @@ VOID BlpDrawDialogInputField(IN PXTBL_DIALOG_HANDLE Handle, IN PWCHAR InputFieldText) { - WCHAR InputField[TUI_MAX_DIALOG_WIDTH]; + WCHAR InputField[XTBL_TUI_MAX_DIALOG_WIDTH]; ULONG InputColor, TextColor; UINT_PTR Index, Position; /* Set dialog button colors */ - if(Handle->Attributes & TUI_DIALOG_ACTIVE_INPUT_FIELD) + if(Handle->Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT_FIELD) { /* This is an active input field */ - if(Handle->Attributes & TUI_DIALOG_ERROR_BOX) + if(Handle->Attributes & XTBL_TUI_DIALOG_ERROR_BOX) { /* This is an error dialog box */ InputColor = EFI_TEXT_BGCOLOR_BROWN; @@ -535,7 +524,7 @@ BlpDrawDialogInputField(IN PXTBL_DIALOG_HANDLE Handle, /* Set progress bar color and position */ BlSetConsoleAttributes(InputColor | TextColor); - Position = (Handle->Attributes & (TUI_DIALOG_ACTIVE_BUTTON | TUI_DIALOG_INACTIVE_BUTTON)) ? 4 : 3; + Position = (Handle->Attributes & (XTBL_TUI_DIALOG_ACTIVE_BUTTON | XTBL_TUI_DIALOG_INACTIVE_BUTTON)) ? 4 : 3; BlSetCursorPosition(Handle->PosX + 4, Handle->PosY + Handle->Height - Position); /* Draw input field */ @@ -554,7 +543,7 @@ BlpDrawDialogInputField(IN PXTBL_DIALOG_HANDLE Handle, BlConsoleWrite(InputFieldText); /* Check if this is an active input field */ - if(Handle->Attributes & TUI_DIALOG_ACTIVE_INPUT_FIELD) + if(Handle->Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT_FIELD) { /* Enable cursor for active input field */ BlEnableConsoleCursor(); @@ -633,7 +622,7 @@ BlpDrawDialogProgressBar(IN PXTBL_DIALOG_HANDLE Handle, IN UCHAR Percentage) { UINT_PTR Index, ProgressLength, ProgressBarLength; - WCHAR ProgressBar[TUI_MAX_DIALOG_WIDTH]; + WCHAR ProgressBar[XTBL_TUI_MAX_DIALOG_WIDTH]; UINT_PTR Position; /* Determine progress bar length and calculate progress */ @@ -642,7 +631,7 @@ BlpDrawDialogProgressBar(IN PXTBL_DIALOG_HANDLE Handle, /* Set progress bar color and position */ BlSetConsoleAttributes(EFI_TEXT_FGCOLOR_YELLOW); - Position = (Handle->Attributes & (TUI_DIALOG_ACTIVE_BUTTON | TUI_DIALOG_INACTIVE_BUTTON)) ? 4 : 3; + Position = (Handle->Attributes & (XTBL_TUI_DIALOG_ACTIVE_BUTTON | XTBL_TUI_DIALOG_INACTIVE_BUTTON)) ? 4 : 3; BlSetCursorPosition(Handle->PosX + 4, Handle->PosY + Handle->Height - Position); /* Draw progress bar */ @@ -687,7 +676,7 @@ BlDisplayInputDialog(IN PWCHAR Caption, UINT_PTR Index; /* Set dialog window attributes */ - Handle.Attributes = TUI_DIALOG_GENERIC_BOX | TUI_DIALOG_ACTIVE_INPUT_FIELD | TUI_DIALOG_INACTIVE_BUTTON; + Handle.Attributes = XTBL_TUI_DIALOG_GENERIC_BOX | XTBL_TUI_DIALOG_ACTIVE_INPUT_FIELD | XTBL_TUI_DIALOG_INACTIVE_BUTTON; /* Determine dialog window size and position */ BlpDetermineDialogBoxSize(&Handle, Message); @@ -734,13 +723,13 @@ BlDisplayInputDialog(IN PWCHAR Caption, else if(Key.UnicodeChar == 0x09) { /* TAB key pressed, toggle input field and button */ - Handle.Attributes ^= (TUI_DIALOG_ACTIVE_INPUT_FIELD | TUI_DIALOG_INACTIVE_INPUT_FIELD); - Handle.Attributes ^= (TUI_DIALOG_ACTIVE_BUTTON | TUI_DIALOG_INACTIVE_BUTTON); + Handle.Attributes ^= (XTBL_TUI_DIALOG_ACTIVE_INPUT_FIELD | XTBL_TUI_DIALOG_INACTIVE_INPUT_FIELD); + Handle.Attributes ^= (XTBL_TUI_DIALOG_ACTIVE_BUTTON | XTBL_TUI_DIALOG_INACTIVE_BUTTON); } else if(Key.ScanCode == 0x03) { /* RIGHT key pressed, move cursor forward */ - if(Handle.Attributes & TUI_DIALOG_ACTIVE_INPUT_FIELD && TextPosition < InputFieldLength) + if(Handle.Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT_FIELD && TextPosition < InputFieldLength) { TextPosition++; } @@ -748,7 +737,7 @@ BlDisplayInputDialog(IN PWCHAR Caption, else if(Key.ScanCode == 0x04) { /* LEFT key pressed, move cursor back */ - if(Handle.Attributes & TUI_DIALOG_ACTIVE_INPUT_FIELD && TextPosition > 0) + if(Handle.Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT_FIELD && TextPosition > 0) { TextPosition--; } @@ -756,7 +745,7 @@ BlDisplayInputDialog(IN PWCHAR Caption, else if(Key.ScanCode == 0x05) { /* HOME key pressed, move cursor to the beginning */ - if(Handle.Attributes & TUI_DIALOG_ACTIVE_INPUT_FIELD) + if(Handle.Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT_FIELD) { TextPosition = 0; } @@ -764,7 +753,7 @@ BlDisplayInputDialog(IN PWCHAR Caption, else if(Key.ScanCode == 0x06) { /* END key pressed, move cursor to the end */ - if(Handle.Attributes & TUI_DIALOG_ACTIVE_INPUT_FIELD) + if(Handle.Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT_FIELD) { TextPosition = InputFieldLength; } @@ -772,7 +761,7 @@ BlDisplayInputDialog(IN PWCHAR Caption, else if(Key.ScanCode == 0x08) { /* DELETE key pressed, delete character */ - if(Handle.Attributes & TUI_DIALOG_ACTIVE_INPUT_FIELD) + if(Handle.Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT_FIELD) { if(InputFieldLength > 0 && TextPosition < InputFieldLength) { @@ -785,7 +774,7 @@ BlDisplayInputDialog(IN PWCHAR Caption, else if(Key.UnicodeChar == 0x08) { /* BACKSPACE key pressed, delete character */ - if(Handle.Attributes & TUI_DIALOG_ACTIVE_INPUT_FIELD) + if(Handle.Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT_FIELD) { if(InputFieldLength > 0 && TextPosition > 0 && TextPosition <= InputFieldLength) { @@ -803,7 +792,7 @@ BlDisplayInputDialog(IN PWCHAR Caption, else { /* Other key pressed, add character to the buffer */ - if(Handle.Attributes & TUI_DIALOG_ACTIVE_INPUT_FIELD && Key.UnicodeChar != 0) + if(Handle.Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT_FIELD && Key.UnicodeChar != 0) { if(InputFieldLength < Handle.Width - 8 - 1 && TextPosition < Handle.Width - 8 - 1) { @@ -831,7 +820,7 @@ BlDisplayInputDialog(IN PWCHAR Caption, BlpDrawDialogButton(&Handle); BlpDrawDialogInputField(&Handle, &InputFieldBuffer[TextIndex]); - if(Handle.Attributes & TUI_DIALOG_ACTIVE_INPUT_FIELD) + if(Handle.Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT_FIELD) { BlSetCursorPosition(Handle.PosX + 4 + TextCursorPosition, Handle.PosY + Handle.Height - 4); }