#include "menu.h"
#include "config.h"
#include "libeg.h"
-#include "refit_call_wrapper.h"
+#include "../include/refit_call_wrapper.h"
-#include "egemb_back_selected_small.h"
-#include "egemb_arrow_left.h"
-#include "egemb_arrow_right.h"
+#include "../include/egemb_back_selected_small.h"
+#include "../include/egemb_arrow_left.h"
+#include "../include/egemb_arrow_right.h"
// other menu definitions
AddListElement((VOID ***) &(Screen->Entries), &(Screen->EntryCount), Entry);
}
-VOID FreeMenu(IN REFIT_MENU_SCREEN *Screen)
-{
- if (Screen->Entries)
- FreePool(Screen->Entries);
-}
static INTN FindMenuShortcutEntry(IN REFIT_MENU_SCREEN *Screen, IN CHAR16 *Shortcut)
{
INTN ShortcutEntry;
BOOLEAN HaveTimeout = FALSE;
UINTN TimeoutCountdown = 0;
- CHAR16 *TimeoutMessage;
+ CHAR16 TimeoutMessage[256];
CHAR16 KeyAsString[2];
UINTN MenuExit;
}
if (HaveTimeout) {
- TimeoutMessage = PoolPrint(L"%s in %d seconds", Screen->TimeoutText, (TimeoutCountdown + 5) / 10);
+ SPrint(TimeoutMessage, 255, L"%s in %d seconds", Screen->TimeoutText, (TimeoutCountdown + 5) / 10);
StyleFunc(Screen, &State, MENU_FUNCTION_PAINT_TIMEOUT, TimeoutMessage);
- FreePool(TimeoutMessage);
}
// read key press (and wait for it if applicable)
case SCAN_F10:
egScreenShot();
break;
- case 0x0016: // F12
- EjectMedia();
- break;
+ case 0x0016: // F12
+ if (EjectMedia())
+ MenuExit = MENU_EXIT_ESCAPE;
+ break;
}
switch (key.UnicodeChar) {
case CHAR_LINEFEED:
if (ChosenEntry)
*ChosenEntry = Screen->Entries[State.CurrentSelection];
return MenuExit;
-} /* static UINTN RunGenericMenu( */
+} /* static UINTN RunGenericMenu() */
//
// text-mode generic style
UINTN MenuWidth, ItemWidth, MenuHeight;
static UINTN MenuPosY;
static CHAR16 **DisplayStrings;
- CHAR16 *TimeoutMessage;
+ CHAR16 TimeoutMessage[256];
State->ScrollMode = SCROLL_MODE_TEXT;
switch (Function) {
// prepare strings for display
DisplayStrings = AllocatePool(sizeof(CHAR16 *) * Screen->EntryCount);
- for (i = 0; i <= State->MaxIndex; i++)
- DisplayStrings[i] = PoolPrint(L" %-.*s ", MenuWidth, Screen->Entries[i]->Title);
- // TODO: shorten strings that are too long (PoolPrint doesn't do that...)
+ for (i = 0; i <= State->MaxIndex; i++) {
+ DisplayStrings[i] = AllocateZeroPool(256 * sizeof(CHAR16));
+ SPrint(DisplayStrings[i], 255, L" %-.*s ", MenuWidth, Screen->Entries[i]->Title);
// TODO: use more elaborate techniques for shortening too long strings (ellipses in the middle)
// TODO: account for double-width characters
+ } // for
// initial painting
BeginTextScreen(Screen->Title);
case MENU_FUNCTION_CLEANUP:
// release temporary memory
for (i = 0; i <= State->MaxIndex; i++)
- FreePool(DisplayStrings[i]);
- FreePool(DisplayStrings);
+ MyFreePool(DisplayStrings[i]);
+ MyFreePool(DisplayStrings);
break;
case MENU_FUNCTION_PAINT_ALL:
// paint or update message
refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_ERROR);
refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 3, ConHeight - 1);
- TimeoutMessage = PoolPrint(L"%s ", ParamText);
+ SPrint(TimeoutMessage, 255, L"%s ", ParamText);
refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, TimeoutMessage);
- FreePool(TimeoutMessage);
}
break;
break;
}
-}
+} // static VOID GraphicsMenuStyle()
//
// graphical main menu style
break;
case MENU_FUNCTION_CLEANUP:
- FreePool(itemPosX);
+ MyFreePool(itemPosX);
break;
case MENU_FUNCTION_PAINT_ALL:
break;
}
-}
+} // VOID MainMenuStyle()
+
+// Enable the user to edit boot loader options.
+// Returns TRUE if the user exited with edited options; FALSE if the user
+// pressed Esc to terminate the edit.
+static BOOLEAN EditOptions(LOADER_ENTRY *MenuEntry) {
+ UINTN x_max, y_max;
+ CHAR16 *EditedOptions;
+ CHAR16 message[] = L"Use cursor keys to edit, Esc to exit, Enter to boot with edited options";
+ EG_PIXEL DarkBackgroundPixel = { 0x0, 0x0, 0x0, 0 };
+ BOOLEAN retval = FALSE;
+
+ refit_call4_wrapper(ST->ConOut->QueryMode, ST->ConOut, ST->ConOut->Mode->Mode, &x_max, &y_max);
+
+ if (!GlobalConfig.TextOnly)
+ SwitchToText(TRUE);
+
+ egClearScreen(&DarkBackgroundPixel);
+
+ refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 0, y_max - 1);
+ refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, message);
+
+ if (line_edit(MenuEntry->LoadOptions, &EditedOptions, x_max, 1)) {
+ MyFreePool(MenuEntry->LoadOptions);
+ MenuEntry->LoadOptions = EditedOptions;
+ retval = TRUE;
+ } // if
+ if (!GlobalConfig.TextOnly)
+ SwitchToGraphics();
+ return retval;
+} // VOID EditOptions()
//
// user-callable dispatcher functions
MenuExit = RunGenericMenu(TempChosenEntry->SubScreen, Style, -1, &TempChosenEntry);
if (MenuExit == MENU_EXIT_ESCAPE || TempChosenEntry->Tag == TAG_RETURN)
MenuExit = 0;
+ if (MenuExit == MENU_EXIT_DETAILS) {
+ if (!EditOptions((LOADER_ENTRY *) TempChosenEntry))
+ MenuExit = 0;
+ } // if
}
}