]> code.delx.au - refind/blob - refind/menu.c
Improvements to icon- and banner-positioning code. Fixes crash if
[refind] / refind / menu.c
1 /*
2 * refit/menu.c
3 * Menu functions
4 *
5 * Copyright (c) 2006 Christoph Pfisterer
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the
18 * distribution.
19 *
20 * * Neither the name of Christoph Pfisterer nor the names of the
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36 /*
37 * Modifications copyright (c) 2012 Roderick W. Smith
38 *
39 * Modifications distributed under the terms of the GNU General Public
40 * License (GPL) version 3 (GPLv3), a copy of which must be distributed
41 * with this source code or binaries made from it.
42 *
43 */
44
45 #include "global.h"
46 #include "screen.h"
47 #include "lib.h"
48 #include "menu.h"
49 #include "config.h"
50 #include "libeg.h"
51 #include "../include/refit_call_wrapper.h"
52
53 #include "../include/egemb_back_selected_small.h"
54 #include "../include/egemb_arrow_left.h"
55 #include "../include/egemb_arrow_right.h"
56
57 // other menu definitions
58
59 #define MENU_FUNCTION_INIT (0)
60 #define MENU_FUNCTION_CLEANUP (1)
61 #define MENU_FUNCTION_PAINT_ALL (2)
62 #define MENU_FUNCTION_PAINT_SELECTION (3)
63 #define MENU_FUNCTION_PAINT_TIMEOUT (4)
64 #define MENU_FUNCTION_PAINT_HINTS (5)
65
66 typedef VOID (*MENU_STYLE_FUNC)(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, IN UINTN Function, IN CHAR16 *ParamText);
67
68 static CHAR16 ArrowUp[2] = { ARROW_UP, 0 };
69 static CHAR16 ArrowDown[2] = { ARROW_DOWN, 0 };
70
71 // Text and icon spacing constants....
72 #define TEXT_YMARGIN (2)
73 #define TEXT_XMARGIN (8)
74 #define TEXT_LINE_HEIGHT (FONT_CELL_HEIGHT + TEXT_YMARGIN * 2)
75 #define TITLEICON_SPACING (16)
76
77 #define ROW0_TILESIZE (144)
78 #define ROW1_TILESIZE (64)
79 #define TILE_XSPACING (8)
80 #define TILE_YSPACING (16)
81
82 // Alignment values for PaintIcon()
83 #define ALIGN_RIGHT 1
84 #define ALIGN_LEFT 0
85
86 static EG_IMAGE *SelectionImages[4] = { NULL, NULL, NULL, NULL };
87 static EG_PIXEL SelectionBackgroundPixel = { 0xff, 0xff, 0xff, 0 };
88 static EG_IMAGE *TextBuffer = NULL;
89
90 //
91 // Graphics helper functions
92 //
93
94 static VOID InitSelection(VOID)
95 {
96 UINTN x, y, src_x, src_y;
97 EG_PIXEL *DestPtr, *SrcPtr;
98
99 if (!AllowGraphicsMode)
100 return;
101 if (SelectionImages[0] != NULL)
102 return;
103
104 // load small selection image
105 if (GlobalConfig.SelectionSmallFileName != NULL) {
106 SelectionImages[2] = egLoadImage(SelfDir, GlobalConfig.SelectionSmallFileName, FALSE);
107 }
108 if (SelectionImages[2] == NULL)
109 SelectionImages[2] = egPrepareEmbeddedImage(&egemb_back_selected_small, FALSE);
110 SelectionImages[2] = egEnsureImageSize(SelectionImages[2],
111 ROW1_TILESIZE, ROW1_TILESIZE, &MenuBackgroundPixel);
112 if (SelectionImages[2] == NULL)
113 return;
114
115 // load big selection image
116 if (GlobalConfig.SelectionBigFileName != NULL) {
117 SelectionImages[0] = egLoadImage(SelfDir, GlobalConfig.SelectionBigFileName, FALSE);
118 SelectionImages[0] = egEnsureImageSize(SelectionImages[0],
119 ROW0_TILESIZE, ROW0_TILESIZE, &MenuBackgroundPixel);
120 }
121 if (SelectionImages[0] == NULL) {
122 // calculate big selection image from small one
123
124 SelectionImages[0] = egCreateImage(ROW0_TILESIZE, ROW0_TILESIZE, FALSE);
125 if (SelectionImages[0] == NULL) {
126 egFreeImage(SelectionImages[2]);
127 SelectionImages[2] = NULL;
128 return;
129 }
130
131 DestPtr = SelectionImages[0]->PixelData;
132 SrcPtr = SelectionImages[2]->PixelData;
133 for (y = 0; y < ROW0_TILESIZE; y++) {
134 if (y < (ROW1_TILESIZE >> 1))
135 src_y = y;
136 else if (y < (ROW0_TILESIZE - (ROW1_TILESIZE >> 1)))
137 src_y = (ROW1_TILESIZE >> 1);
138 else
139 src_y = y - (ROW0_TILESIZE - ROW1_TILESIZE);
140
141 for (x = 0; x < ROW0_TILESIZE; x++) {
142 if (x < (ROW1_TILESIZE >> 1))
143 src_x = x;
144 else if (x < (ROW0_TILESIZE - (ROW1_TILESIZE >> 1)))
145 src_x = (ROW1_TILESIZE >> 1);
146 else
147 src_x = x - (ROW0_TILESIZE - ROW1_TILESIZE);
148
149 *DestPtr++ = SrcPtr[src_y * ROW1_TILESIZE + src_x];
150 }
151 }
152 }
153
154 // non-selected background images
155 SelectionImages[1] = egCreateFilledImage(ROW0_TILESIZE, ROW0_TILESIZE, FALSE, &MenuBackgroundPixel);
156 SelectionImages[3] = egCreateFilledImage(ROW1_TILESIZE, ROW1_TILESIZE, FALSE, &MenuBackgroundPixel);
157 }
158
159 //
160 // Scrolling functions
161 //
162
163 static VOID InitScroll(OUT SCROLL_STATE *State, IN UINTN ItemCount, IN UINTN VisibleSpace)
164 {
165 State->PreviousSelection = State->CurrentSelection = 0;
166 State->MaxIndex = (INTN)ItemCount - 1;
167 State->FirstVisible = 0;
168 if (AllowGraphicsMode) {
169 State->MaxVisible = UGAWidth / (ROW0_TILESIZE + TILE_XSPACING) - 1;
170 } else
171 State->MaxVisible = ConHeight - 4;
172 if ((VisibleSpace > 0) && (VisibleSpace < State->MaxVisible))
173 State->MaxVisible = (INTN)VisibleSpace;
174 State->PaintAll = TRUE;
175 State->PaintSelection = FALSE;
176
177 State->LastVisible = State->FirstVisible + State->MaxVisible - 1;
178 }
179
180 // Adjust variables relating to the scrolling of tags, for when a selected icon isn't
181 // visible given the current scrolling condition....
182 static VOID AdjustScrollState(IN SCROLL_STATE *State) {
183 if (State->CurrentSelection > State->LastVisible) {
184 State->LastVisible = State->CurrentSelection;
185 State->FirstVisible = 1 + State->CurrentSelection - State->MaxVisible;
186 if (State->FirstVisible < 0) // shouldn't happen, but just in case....
187 State->FirstVisible = 0;
188 State->PaintAll = TRUE;
189 } // Scroll forward
190 if (State->CurrentSelection < State->FirstVisible) {
191 State->FirstVisible = State->CurrentSelection;
192 State->LastVisible = State->CurrentSelection + State->MaxVisible - 1;
193 State->PaintAll = TRUE;
194 } // Scroll backward
195 } // static VOID AdjustScrollState
196
197 static VOID UpdateScroll(IN OUT SCROLL_STATE *State, IN UINTN Movement)
198 {
199 State->PreviousSelection = State->CurrentSelection;
200
201 switch (Movement) {
202 case SCROLL_LINE_LEFT:
203 if (State->CurrentSelection > 0) {
204 State->CurrentSelection --;
205 }
206 break;
207
208 case SCROLL_LINE_RIGHT:
209 if (State->CurrentSelection < State->MaxIndex) {
210 State->CurrentSelection ++;
211 }
212 break;
213
214 case SCROLL_LINE_UP:
215 if (State->ScrollMode == SCROLL_MODE_ICONS) {
216 if (State->CurrentSelection >= State->InitialRow1) {
217 if (State->MaxIndex > State->InitialRow1) { // avoid division by 0!
218 State->CurrentSelection = State->FirstVisible + (State->LastVisible - State->FirstVisible) *
219 (State->CurrentSelection - State->InitialRow1) /
220 (State->MaxIndex - State->InitialRow1);
221 } else {
222 State->CurrentSelection = State->FirstVisible;
223 } // if/else
224 } // if in second row
225 } else {
226 if (State->CurrentSelection > 0)
227 State->CurrentSelection--;
228 } // if/else
229 break;
230
231 case SCROLL_LINE_DOWN:
232 if (State->ScrollMode == SCROLL_MODE_ICONS) {
233 if (State->CurrentSelection <= State->FinalRow0) {
234 if (State->LastVisible > State->FirstVisible) { // avoid division by 0!
235 State->CurrentSelection = State->InitialRow1 + (State->MaxIndex - State->InitialRow1) *
236 (State->CurrentSelection - State->FirstVisible) /
237 (State->LastVisible - State->FirstVisible);
238 } else {
239 State->CurrentSelection = State->InitialRow1;
240 } // if/else
241 } // if in first row
242 } else {
243 if (State->CurrentSelection < State->MaxIndex)
244 State->CurrentSelection++;
245 } // if/else
246 break;
247
248 case SCROLL_PAGE_UP:
249 if (State->CurrentSelection <= State->FinalRow0)
250 State->CurrentSelection -= State->MaxVisible;
251 else if (State->CurrentSelection == State->InitialRow1)
252 State->CurrentSelection = State->FinalRow0;
253 else
254 State->CurrentSelection = State->InitialRow1;
255 if (State->CurrentSelection < 0)
256 State->CurrentSelection = 0;
257 break;
258
259 case SCROLL_FIRST:
260 if (State->CurrentSelection > 0) {
261 State->PaintAll = TRUE;
262 State->CurrentSelection = 0;
263 }
264 break;
265
266 case SCROLL_PAGE_DOWN:
267 if (State->CurrentSelection < State->FinalRow0) {
268 State->CurrentSelection += State->MaxVisible;
269 if (State->CurrentSelection > State->FinalRow0)
270 State->CurrentSelection = State->FinalRow0;
271 } else if (State->CurrentSelection == State->FinalRow0) {
272 State->CurrentSelection++;
273 } else {
274 State->CurrentSelection = State->MaxIndex;
275 }
276 if (State->CurrentSelection > State->MaxIndex)
277 State->CurrentSelection = State->MaxIndex;
278 break;
279
280 case SCROLL_LAST:
281 if (State->CurrentSelection < State->MaxIndex) {
282 State->PaintAll = TRUE;
283 State->CurrentSelection = State->MaxIndex;
284 }
285 break;
286
287 case SCROLL_NONE:
288 break;
289
290 }
291 if (State->ScrollMode == SCROLL_MODE_TEXT)
292 AdjustScrollState(State);
293
294 if (!State->PaintAll && State->CurrentSelection != State->PreviousSelection)
295 State->PaintSelection = TRUE;
296 State->LastVisible = State->FirstVisible + State->MaxVisible - 1;
297 } // static VOID UpdateScroll()
298
299 //
300 // menu helper functions
301 //
302
303 VOID AddMenuInfoLine(IN REFIT_MENU_SCREEN *Screen, IN CHAR16 *InfoLine)
304 {
305 AddListElement((VOID ***) &(Screen->InfoLines), &(Screen->InfoLineCount), InfoLine);
306 }
307
308 VOID AddMenuEntry(IN REFIT_MENU_SCREEN *Screen, IN REFIT_MENU_ENTRY *Entry)
309 {
310 AddListElement((VOID ***) &(Screen->Entries), &(Screen->EntryCount), Entry);
311 }
312
313
314 static INTN FindMenuShortcutEntry(IN REFIT_MENU_SCREEN *Screen, IN CHAR16 *Shortcut)
315 {
316 UINTN i;
317
318 if (Shortcut == NULL)
319 return (-1);
320
321 if (StrLen(Shortcut) == 1) {
322 if (Shortcut[0] >= 'a' && Shortcut[0] <= 'z')
323 Shortcut[0] -= ('a' - 'A');
324 if (Shortcut[0]) {
325 for (i = 0; i < Screen->EntryCount; i++) {
326 if (Screen->Entries[i]->ShortcutDigit == Shortcut[0] || Screen->Entries[i]->ShortcutLetter == Shortcut[0]) {
327 return i;
328 } // if
329 } // for
330 } // if
331 } else if (StrLen(Shortcut) > 1) {
332 for (i = 0; i < Screen->EntryCount; i++) {
333 if (StriSubCmp(Shortcut, Screen->Entries[i]->Title))
334 return i;
335 } // for
336 }
337 return -1;
338 }
339
340 // Identify the end of row 0 and the beginning of row 1; store the results in the
341 // appropriate fields in State. Also reduce MaxVisible if that value is greater
342 // than the total number of row-0 tags and if we're in an icon-based screen
343 static VOID IdentifyRows(IN SCROLL_STATE *State, IN REFIT_MENU_SCREEN *Screen) {
344 UINTN i;
345
346 State->FinalRow0 = 0;
347 State->InitialRow1 = State->MaxIndex;
348 for (i = 0; i < State->MaxIndex; i++) {
349 if (Screen->Entries[i]->Row == 0) {
350 State->FinalRow0 = i;
351 } else if ((Screen->Entries[i]->Row == 1) && (State->InitialRow1 > i)) {
352 State->InitialRow1 = i;
353 } // if/else
354 } // for
355 if ((State->ScrollMode == SCROLL_MODE_ICONS) && (State->MaxVisible > (State->FinalRow0 + 1)))
356 State->MaxVisible = State->FinalRow0 + 1;
357 } // static VOID IdentifyRows()
358
359 //
360 // generic menu function
361 //
362 static UINTN RunGenericMenu(IN REFIT_MENU_SCREEN *Screen, IN MENU_STYLE_FUNC StyleFunc, IN OUT INTN *DefaultEntryIndex,
363 OUT REFIT_MENU_ENTRY **ChosenEntry)
364 {
365 SCROLL_STATE State;
366 EFI_STATUS Status;
367 EFI_INPUT_KEY key;
368 UINTN index;
369 INTN ShortcutEntry;
370 BOOLEAN HaveTimeout = FALSE;
371 UINTN TimeoutCountdown = 0;
372 CHAR16 TimeoutMessage[256];
373 CHAR16 KeyAsString[2];
374 UINTN MenuExit;
375
376 if (Screen->TimeoutSeconds > 0) {
377 HaveTimeout = TRUE;
378 TimeoutCountdown = Screen->TimeoutSeconds * 10;
379 }
380 MenuExit = 0;
381
382 StyleFunc(Screen, &State, MENU_FUNCTION_INIT, NULL);
383 IdentifyRows(&State, Screen);
384 // override the starting selection with the default index, if any
385 if (*DefaultEntryIndex >= 0 && *DefaultEntryIndex <= State.MaxIndex) {
386 State.CurrentSelection = *DefaultEntryIndex;
387 UpdateScroll(&State, SCROLL_NONE);
388 }
389 State.PaintAll = TRUE;
390
391 while (!MenuExit) {
392 // update the screen
393 if (State.PaintAll) {
394 StyleFunc(Screen, &State, MENU_FUNCTION_PAINT_ALL, NULL);
395 State.PaintAll = FALSE;
396 } else if (State.PaintSelection) {
397 StyleFunc(Screen, &State, MENU_FUNCTION_PAINT_SELECTION, NULL);
398 State.PaintSelection = FALSE;
399 }
400
401 if (HaveTimeout) {
402 SPrint(TimeoutMessage, 255, L"%s in %d seconds", Screen->TimeoutText, (TimeoutCountdown + 5) / 10);
403 StyleFunc(Screen, &State, MENU_FUNCTION_PAINT_TIMEOUT, TimeoutMessage);
404 }
405
406 // read key press (and wait for it if applicable)
407 Status = refit_call2_wrapper(ST->ConIn->ReadKeyStroke, ST->ConIn, &key);
408 if (Status == EFI_NOT_READY) {
409 if (HaveTimeout && TimeoutCountdown == 0) {
410 // timeout expired
411 MenuExit = MENU_EXIT_TIMEOUT;
412 break;
413 } else if (HaveTimeout) {
414 refit_call1_wrapper(BS->Stall, 100000);
415 TimeoutCountdown--;
416 } else
417 refit_call3_wrapper(BS->WaitForEvent, 1, &ST->ConIn->WaitForKey, &index);
418 continue;
419 }
420 if (HaveTimeout) {
421 // the user pressed a key, cancel the timeout
422 StyleFunc(Screen, &State, MENU_FUNCTION_PAINT_TIMEOUT, L"");
423 HaveTimeout = FALSE;
424 }
425
426 // react to key press
427 switch (key.ScanCode) {
428 case SCAN_UP:
429 UpdateScroll(&State, SCROLL_LINE_UP);
430 break;
431 case SCAN_LEFT:
432 UpdateScroll(&State, SCROLL_LINE_LEFT);
433 break;
434 case SCAN_DOWN:
435 UpdateScroll(&State, SCROLL_LINE_DOWN);
436 break;
437 case SCAN_RIGHT:
438 UpdateScroll(&State, SCROLL_LINE_RIGHT);
439 break;
440 case SCAN_HOME:
441 UpdateScroll(&State, SCROLL_FIRST);
442 break;
443 case SCAN_END:
444 UpdateScroll(&State, SCROLL_LAST);
445 break;
446 case SCAN_PAGE_UP:
447 UpdateScroll(&State, SCROLL_PAGE_UP);
448 break;
449 case SCAN_PAGE_DOWN:
450 UpdateScroll(&State, SCROLL_PAGE_DOWN);
451 break;
452 case SCAN_ESC:
453 MenuExit = MENU_EXIT_ESCAPE;
454 break;
455 case SCAN_INSERT:
456 case SCAN_F2:
457 MenuExit = MENU_EXIT_DETAILS;
458 break;
459 case SCAN_F10:
460 egScreenShot();
461 break;
462 case 0x0016: // F12
463 if (EjectMedia())
464 MenuExit = MENU_EXIT_ESCAPE;
465 break;
466 }
467 switch (key.UnicodeChar) {
468 case CHAR_LINEFEED:
469 case CHAR_CARRIAGE_RETURN:
470 case ' ':
471 MenuExit = MENU_EXIT_ENTER;
472 break;
473 case '+':
474 MenuExit = MENU_EXIT_DETAILS;
475 break;
476 default:
477 KeyAsString[0] = key.UnicodeChar;
478 KeyAsString[1] = 0;
479 ShortcutEntry = FindMenuShortcutEntry(Screen, KeyAsString);
480 if (ShortcutEntry >= 0) {
481 State.CurrentSelection = ShortcutEntry;
482 MenuExit = MENU_EXIT_ENTER;
483 }
484 break;
485 }
486 }
487
488 StyleFunc(Screen, &State, MENU_FUNCTION_CLEANUP, NULL);
489
490 if (ChosenEntry)
491 *ChosenEntry = Screen->Entries[State.CurrentSelection];
492 *DefaultEntryIndex = State.CurrentSelection;
493 return MenuExit;
494 } /* static UINTN RunGenericMenu() */
495
496 //
497 // text-mode generic style
498 //
499
500 static VOID TextMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, IN UINTN Function, IN CHAR16 *ParamText)
501 {
502 INTN i;
503 UINTN MenuWidth, ItemWidth, MenuHeight;
504 static UINTN MenuPosY;
505 static CHAR16 **DisplayStrings;
506 CHAR16 TimeoutMessage[256];
507
508 State->ScrollMode = SCROLL_MODE_TEXT;
509 switch (Function) {
510
511 case MENU_FUNCTION_INIT:
512 // vertical layout
513 MenuPosY = 4;
514 if (Screen->InfoLineCount > 0)
515 MenuPosY += Screen->InfoLineCount + 1;
516 MenuHeight = ConHeight - MenuPosY - 3;
517 if (Screen->TimeoutSeconds > 0)
518 MenuHeight -= 2;
519 InitScroll(State, Screen->EntryCount, MenuHeight);
520
521 // determine width of the menu
522 MenuWidth = 20; // minimum
523 for (i = 0; i <= State->MaxIndex; i++) {
524 ItemWidth = StrLen(Screen->Entries[i]->Title);
525 if (MenuWidth < ItemWidth)
526 MenuWidth = ItemWidth;
527 }
528 MenuWidth += 2;
529 if (MenuWidth > ConWidth - 3)
530 MenuWidth = ConWidth - 3;
531
532 // prepare strings for display
533 DisplayStrings = AllocatePool(sizeof(CHAR16 *) * Screen->EntryCount);
534 for (i = 0; i <= State->MaxIndex; i++) {
535 // Note: Theoretically, SPrint() is a cleaner way to do this; but the
536 // description of the StrSize parameter to SPrint implies it's measured
537 // in characters, but in practice both TianoCore and GNU-EFI seem to
538 // use bytes instead, resulting in truncated displays. I could just
539 // double the size of the StrSize parameter, but that seems unsafe in
540 // case a future library change starts treating this as characters, so
541 // I'm doing it the hard way in this instance.
542 // TODO: Review the above and possibly change other uses of SPrint()
543 DisplayStrings[i] = AllocateZeroPool(2 * sizeof(CHAR16));
544 DisplayStrings[i][0] = L' ';
545 MergeStrings(&DisplayStrings[i], Screen->Entries[i]->Title, 0);
546 if (StrLen(DisplayStrings[i]) > MenuWidth)
547 DisplayStrings[i][MenuWidth - 1] = 0;
548 // TODO: use more elaborate techniques for shortening too long strings (ellipses in the middle)
549 // TODO: account for double-width characters
550 } // for
551
552 // initial painting
553 BeginTextScreen(Screen->Title);
554 if (Screen->InfoLineCount > 0) {
555 refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_BASIC);
556 for (i = 0; i < (INTN)Screen->InfoLineCount; i++) {
557 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 3, 4 + i);
558 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, Screen->InfoLines[i]);
559 }
560 }
561
562 break;
563
564 case MENU_FUNCTION_CLEANUP:
565 // release temporary memory
566 for (i = 0; i <= State->MaxIndex; i++)
567 MyFreePool(DisplayStrings[i]);
568 MyFreePool(DisplayStrings);
569 break;
570
571 case MENU_FUNCTION_PAINT_ALL:
572 // paint the whole screen (initially and after scrolling)
573 for (i = 0; i <= State->MaxIndex; i++) {
574 if (i >= State->FirstVisible && i <= State->LastVisible) {
575 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 2, MenuPosY + (i - State->FirstVisible));
576 if (i == State->CurrentSelection)
577 refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_CHOICE_CURRENT);
578 else
579 refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_CHOICE_BASIC);
580 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, DisplayStrings[i]);
581 }
582 }
583 // scrolling indicators
584 refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_SCROLLARROW);
585 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 0, MenuPosY);
586 if (State->FirstVisible > 0)
587 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, ArrowUp);
588 else
589 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, L" ");
590 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 0, MenuPosY + State->MaxVisible);
591 if (State->LastVisible < State->MaxIndex)
592 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, ArrowDown);
593 else
594 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, L" ");
595 if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HINTS)) {
596 if (Screen->Hint1 != NULL) {
597 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 0, ConHeight - 2);
598 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, Screen->Hint1);
599 }
600 if (Screen->Hint2 != NULL) {
601 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 0, ConHeight - 1);
602 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, Screen->Hint2);
603 }
604 }
605 break;
606
607 case MENU_FUNCTION_PAINT_SELECTION:
608 // redraw selection cursor
609 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 2,
610 MenuPosY + (State->PreviousSelection - State->FirstVisible));
611 refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_CHOICE_BASIC);
612 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, DisplayStrings[State->PreviousSelection]);
613 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 2,
614 MenuPosY + (State->CurrentSelection - State->FirstVisible));
615 refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_CHOICE_CURRENT);
616 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, DisplayStrings[State->CurrentSelection]);
617 break;
618
619 case MENU_FUNCTION_PAINT_TIMEOUT:
620 if (ParamText[0] == 0) {
621 // clear message
622 refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_BASIC);
623 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 0, ConHeight - 3);
624 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, BlankLine + 1);
625 } else {
626 // paint or update message
627 refit_call2_wrapper(ST->ConOut->SetAttribute, ST->ConOut, ATTR_ERROR);
628 refit_call3_wrapper(ST->ConOut->SetCursorPosition, ST->ConOut, 3, ConHeight - 3);
629 SPrint(TimeoutMessage, 255, L"%s ", ParamText);
630 refit_call2_wrapper(ST->ConOut->OutputString, ST->ConOut, TimeoutMessage);
631 }
632 break;
633
634 }
635 }
636
637 //
638 // graphical generic style
639 //
640
641
642 static VOID DrawMenuText(IN CHAR16 *Text, IN UINTN SelectedWidth, IN UINTN XPos, IN UINTN YPos)
643 {
644 if (TextBuffer == NULL)
645 TextBuffer = egCreateImage(LAYOUT_TEXT_WIDTH, TEXT_LINE_HEIGHT, FALSE);
646
647 egFillImage(TextBuffer, &MenuBackgroundPixel);
648 if (SelectedWidth > 0) {
649 // draw selection bar background
650 egFillImageArea(TextBuffer, 0, 0, SelectedWidth, TextBuffer->Height,
651 &SelectionBackgroundPixel);
652 }
653
654 // render the text
655 egRenderText(Text, TextBuffer, TEXT_XMARGIN, TEXT_YMARGIN);
656 BltImage(TextBuffer, XPos, YPos);
657 }
658
659 // Displays sub-menus
660 static VOID GraphicsMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, IN UINTN Function, IN CHAR16 *ParamText)
661 {
662 INTN i;
663 UINTN ItemWidth;
664 static UINTN MenuWidth, EntriesPosX, EntriesPosY, TimeoutPosY;
665
666 State->ScrollMode = SCROLL_MODE_TEXT;
667 switch (Function) {
668
669 case MENU_FUNCTION_INIT:
670 InitScroll(State, Screen->EntryCount, 0);
671
672 // determine width of the menu
673 MenuWidth = 20; // minimum
674 for (i = 0; i < (INTN)Screen->InfoLineCount; i++) {
675 ItemWidth = StrLen(Screen->InfoLines[i]);
676 if (MenuWidth < ItemWidth)
677 MenuWidth = ItemWidth;
678 }
679 for (i = 0; i <= State->MaxIndex; i++) {
680 ItemWidth = StrLen(Screen->Entries[i]->Title);
681 if (MenuWidth < ItemWidth)
682 MenuWidth = ItemWidth;
683 }
684 MenuWidth = TEXT_XMARGIN * 2 + MenuWidth * FONT_CELL_WIDTH;
685 if (MenuWidth > LAYOUT_TEXT_WIDTH)
686 MenuWidth = LAYOUT_TEXT_WIDTH;
687
688 if (Screen->TitleImage)
689 EntriesPosX = (UGAWidth + (Screen->TitleImage->Width + TITLEICON_SPACING) - MenuWidth) >> 1;
690 else
691 EntriesPosX = (UGAWidth - MenuWidth) >> 1;
692 EntriesPosY = ComputeRow0PosX() + TEXT_LINE_HEIGHT * 2;
693 TimeoutPosY = EntriesPosY + (Screen->EntryCount + 1) * TEXT_LINE_HEIGHT;
694
695 // initial painting
696 SwitchToGraphicsAndClear();
697 egMeasureText(Screen->Title, &ItemWidth, NULL);
698 DrawMenuText(Screen->Title, 0, ((UGAWidth - ItemWidth) >> 1) - TEXT_XMARGIN, EntriesPosY - TEXT_LINE_HEIGHT * 2);
699 if (Screen->TitleImage)
700 BltImageAlpha(Screen->TitleImage,
701 EntriesPosX - (Screen->TitleImage->Width + TITLEICON_SPACING), EntriesPosY,
702 &MenuBackgroundPixel);
703 if (Screen->InfoLineCount > 0) {
704 for (i = 0; i < (INTN)Screen->InfoLineCount; i++) {
705 DrawMenuText(Screen->InfoLines[i], 0, EntriesPosX, EntriesPosY);
706 EntriesPosY += TEXT_LINE_HEIGHT;
707 }
708 EntriesPosY += TEXT_LINE_HEIGHT; // also add a blank line
709 }
710
711 break;
712
713 case MENU_FUNCTION_CLEANUP:
714 // nothing to do
715 break;
716
717 case MENU_FUNCTION_PAINT_ALL:
718 for (i = 0; i <= State->MaxIndex; i++) {
719 DrawMenuText(Screen->Entries[i]->Title, (i == State->CurrentSelection) ? MenuWidth : 0,
720 EntriesPosX, EntriesPosY + i * TEXT_LINE_HEIGHT);
721 }
722 if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HINTS)) {
723 if ((Screen->Hint1 != NULL) && (StrLen(Screen->Hint1) > 0)) {
724 DrawMenuText(Screen->Hint1, 0, (UGAWidth - (StrLen(Screen->Hint1) * FONT_CELL_WIDTH)) / 2,
725 UGAHeight - (FONT_CELL_HEIGHT * 3));
726 }
727 if ((Screen->Hint2 != NULL) && (StrLen(Screen->Hint2) > 0)) {
728 DrawMenuText(Screen->Hint2, 0, (UGAWidth - (StrLen(Screen->Hint2) * FONT_CELL_WIDTH)) / 2,
729 UGAHeight - (FONT_CELL_HEIGHT * 2));
730 } // if
731 } // if
732 break;
733
734 case MENU_FUNCTION_PAINT_SELECTION:
735 // redraw selection cursor
736 DrawMenuText(Screen->Entries[State->PreviousSelection]->Title, 0,
737 EntriesPosX, EntriesPosY + State->PreviousSelection * TEXT_LINE_HEIGHT);
738 DrawMenuText(Screen->Entries[State->CurrentSelection]->Title, MenuWidth,
739 EntriesPosX, EntriesPosY + State->CurrentSelection * TEXT_LINE_HEIGHT);
740 break;
741
742 case MENU_FUNCTION_PAINT_TIMEOUT:
743 DrawMenuText(ParamText, 0, EntriesPosX, TimeoutPosY);
744 break;
745
746 }
747 } // static VOID GraphicsMenuStyle()
748
749 //
750 // graphical main menu style
751 //
752
753 static VOID DrawMainMenuEntry(REFIT_MENU_ENTRY *Entry, BOOLEAN selected, UINTN XPos, UINTN YPos)
754 {
755 UINTN ImageNum;
756
757 ImageNum = ((Entry->Row == 0) ? 0 : 2) + (selected ? 0 : 1);
758 if (SelectionImages != NULL)
759 BltImageCompositeBadge(SelectionImages[ImageNum],
760 Entry->Image, Entry->BadgeImage, XPos, YPos);
761 }
762
763 static VOID DrawMainMenuText(IN CHAR16 *Text, IN UINTN XPos, IN UINTN YPos)
764 {
765 UINTN TextWidth, TextPosX;
766
767 if (TextBuffer == NULL)
768 TextBuffer = egCreateImage(LAYOUT_TEXT_WIDTH, TEXT_LINE_HEIGHT, FALSE);
769
770 egFillImage(TextBuffer, &MenuBackgroundPixel);
771
772 // render the text
773 egMeasureText(Text, &TextWidth, NULL);
774 if (TextWidth > TextBuffer->Width)
775 TextPosX = 0;
776 else
777 TextPosX = (TextBuffer->Width - TextWidth) / 2;
778 egRenderText(Text, TextBuffer, TextPosX, 0);
779 // egRenderText(Text, TextBuffer, (TextBuffer->Width - TextWidth) >> 1, 0);
780 BltImage(TextBuffer, XPos, YPos);
781 }
782
783 static VOID PaintAll(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, UINTN *itemPosX,
784 UINTN row0PosY, UINTN row1PosY, UINTN textPosY) {
785 INTN i;
786
787 if (Screen->Entries[State->CurrentSelection]->Row == 0)
788 AdjustScrollState(State);
789 for (i = State->FirstVisible; i <= State->MaxIndex; i++) {
790 if (Screen->Entries[i]->Row == 0) {
791 if (i <= State->LastVisible) {
792 DrawMainMenuEntry(Screen->Entries[i], (i == State->CurrentSelection) ? TRUE : FALSE,
793 itemPosX[i - State->FirstVisible], row0PosY);
794 } // if
795 } else {
796 DrawMainMenuEntry(Screen->Entries[i], (i == State->CurrentSelection) ? TRUE : FALSE, itemPosX[i], row1PosY);
797 }
798 }
799 if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_LABEL))
800 DrawMainMenuText(Screen->Entries[State->CurrentSelection]->Title,
801 (UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY);
802
803 if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_HINTS)) {
804 DrawMainMenuText(Screen->Hint1, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 3));
805 DrawMainMenuText(Screen->Hint2, (UGAWidth - LAYOUT_TEXT_WIDTH) / 2, UGAHeight - (FONT_CELL_HEIGHT * 2));
806 } // if
807 } // static VOID PaintAll()
808
809 // Move the selection to State->CurrentSelection, adjusting icon row if necessary...
810 static VOID PaintSelection(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, UINTN *itemPosX,
811 UINTN row0PosY, UINTN row1PosY, UINTN textPosY) {
812 UINTN XSelectPrev, XSelectCur, YPosPrev, YPosCur;
813
814 if (((State->CurrentSelection <= State->LastVisible) && (State->CurrentSelection >= State->FirstVisible)) ||
815 (State->CurrentSelection >= State->InitialRow1) ) {
816 if (Screen->Entries[State->PreviousSelection]->Row == 0) {
817 XSelectPrev = State->PreviousSelection - State->FirstVisible;
818 YPosPrev = row0PosY;
819 } else {
820 XSelectPrev = State->PreviousSelection;
821 YPosPrev = row1PosY;
822 } // if/else
823 if (Screen->Entries[State->CurrentSelection]->Row == 0) {
824 XSelectCur = State->CurrentSelection - State->FirstVisible;
825 YPosCur = row0PosY;
826 } else {
827 XSelectCur = State->CurrentSelection;
828 YPosCur = row1PosY;
829 } // if/else
830 DrawMainMenuEntry(Screen->Entries[State->PreviousSelection], FALSE, itemPosX[XSelectPrev], YPosPrev);
831 DrawMainMenuEntry(Screen->Entries[State->CurrentSelection], TRUE, itemPosX[XSelectCur], YPosCur);
832 if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_LABEL))
833 DrawMainMenuText(Screen->Entries[State->CurrentSelection]->Title,
834 (UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY);
835 } else { // Current selection not visible; must redraw the menu....
836 MainMenuStyle(Screen, State, MENU_FUNCTION_PAINT_ALL, NULL);
837 }
838 } // static VOID MoveSelection(VOID)
839
840 // Display an icon at the specified location. Uses the image specified by
841 // ExternalFilename if it's available, or BuiltInImage if it's not. The
842 // Y position is specified as the center value, and so is adjusted by half
843 // the icon's height. The X position is set along the icon's left
844 // edge if Alignment == ALIGN_LEFT, and along the right edge if
845 // Alignment == ALIGN_RIGHT
846 static VOID PaintIcon(IN EG_EMBEDDED_IMAGE *BuiltInIcon, IN CHAR16 *ExternalFilename, UINTN PosX, UINTN PosY, UINTN Alignment) {
847 EG_IMAGE *Icon = NULL;
848
849 if (FileExists(SelfDir, ExternalFilename))
850 Icon = egLoadIcon(SelfDir, ExternalFilename, 48);
851 if (Icon == NULL)
852 Icon = egPrepareEmbeddedImage(BuiltInIcon, TRUE);
853 if (Icon != NULL) {
854 if (Alignment == ALIGN_RIGHT)
855 PosX -= Icon->Width;
856 BltImageAlpha(Icon, PosX, PosY - (Icon->Height / 2), &MenuBackgroundPixel);
857 }
858 } // static VOID PaintIcon()
859
860 inline UINTN ComputeRow0PosX(VOID) {
861 return ((UGAHeight / 2) - (5 * ROW0_TILESIZE / 6));
862 } // UINTN ComputeRow0PosX()
863
864 // Display main menu in graphics mode
865 VOID MainMenuStyle(IN REFIT_MENU_SCREEN *Screen, IN SCROLL_STATE *State, IN UINTN Function, IN CHAR16 *ParamText)
866 {
867 INTN i;
868 static UINTN row0PosX, row0PosXRunning, row1PosY, row0Loaders;
869 UINTN row0Count, row1Count, row1PosX, row1PosXRunning;
870 static UINTN *itemPosX;
871 static UINTN row0PosY, textPosY;
872 CHAR16 FileName[256];
873
874 State->ScrollMode = SCROLL_MODE_ICONS;
875 switch (Function) {
876
877 case MENU_FUNCTION_INIT:
878 InitScroll(State, Screen->EntryCount, GlobalConfig.MaxTags);
879
880 // layout
881 row0Count = 0;
882 row1Count = 0;
883 row0Loaders = 0;
884 for (i = 0; i <= State->MaxIndex; i++) {
885 if (Screen->Entries[i]->Row == 1) {
886 row1Count++;
887 } else {
888 row0Loaders++;
889 if (row0Count < State->MaxVisible)
890 row0Count++;
891 }
892 }
893 row0PosX = (UGAWidth + TILE_XSPACING - (ROW0_TILESIZE + TILE_XSPACING) * row0Count) >> 1;
894 row0PosY = ComputeRow0PosX();
895 // row0PosY = ((UGAHeight - LAYOUT_TOTAL_HEIGHT) >> 1) + LAYOUT_BANNER_YOFFSET;
896 row1PosX = (UGAWidth + TILE_XSPACING - (ROW1_TILESIZE + TILE_XSPACING) * row1Count) >> 1;
897 row1PosY = row0PosY + ROW0_TILESIZE + TILE_YSPACING;
898 if (row1Count > 0)
899 textPosY = row1PosY + ROW1_TILESIZE + TILE_YSPACING;
900 else
901 textPosY = row1PosY;
902
903 itemPosX = AllocatePool(sizeof(UINTN) * Screen->EntryCount);
904 row0PosXRunning = row0PosX;
905 row1PosXRunning = row1PosX;
906 for (i = 0; i <= State->MaxIndex; i++) {
907 if (Screen->Entries[i]->Row == 0) {
908 itemPosX[i] = row0PosXRunning;
909 row0PosXRunning += ROW0_TILESIZE + TILE_XSPACING;
910 } else {
911 itemPosX[i] = row1PosXRunning;
912 row1PosXRunning += ROW1_TILESIZE + TILE_XSPACING;
913 }
914 }
915 // initial painting
916 InitSelection();
917 SwitchToGraphicsAndClear();
918 break;
919
920 case MENU_FUNCTION_CLEANUP:
921 MyFreePool(itemPosX);
922 break;
923
924 case MENU_FUNCTION_PAINT_ALL:
925 BltClearScreen(TRUE);
926 PaintAll(Screen, State, itemPosX, row0PosY, row1PosY, textPosY);
927 // For PaintIcon() calls, the starting Y position is moved to the midpoint
928 // of the surrounding row; PaintIcon() adjusts this back up by half the
929 // icon's height to properly center it.
930 if ((State->FirstVisible > 0) && (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_ARROWS))) {
931 SPrint(FileName, 255, L"%s\\arrow_left.icns", GlobalConfig.IconsDir ? GlobalConfig.IconsDir : DEFAULT_ICONS_DIR);
932 PaintIcon(&egemb_arrow_left, FileName, row0PosX - TILE_XSPACING,
933 row0PosY + (ROW0_TILESIZE / 2), ALIGN_RIGHT);
934 } // if
935 if ((State->LastVisible < (row0Loaders - 1)) && (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_ARROWS))) {
936 SPrint(FileName, 255, L"%s\\arrow_right.icns", GlobalConfig.IconsDir ? GlobalConfig.IconsDir : DEFAULT_ICONS_DIR);
937 PaintIcon(&egemb_arrow_right, FileName,
938 (UGAWidth + (ROW0_TILESIZE + TILE_XSPACING) * State->MaxVisible) / 2 + TILE_XSPACING,
939 row0PosY + (ROW0_TILESIZE / 2), ALIGN_LEFT);
940 } // if
941 break;
942
943 case MENU_FUNCTION_PAINT_SELECTION:
944 PaintSelection(Screen, State, itemPosX, row0PosY, row1PosY, textPosY);
945 break;
946
947 case MENU_FUNCTION_PAINT_TIMEOUT:
948 if (!(GlobalConfig.HideUIFlags & HIDEUI_FLAG_LABEL))
949 DrawMainMenuText(ParamText, (UGAWidth - LAYOUT_TEXT_WIDTH) >> 1, textPosY + TEXT_LINE_HEIGHT);
950 break;
951
952 }
953 } // VOID MainMenuStyle()
954
955 // Enable the user to edit boot loader options.
956 // Returns TRUE if the user exited with edited options; FALSE if the user
957 // pressed Esc to terminate the edit.
958 static BOOLEAN EditOptions(LOADER_ENTRY *MenuEntry) {
959 UINTN x_max, y_max;
960 CHAR16 *EditedOptions;
961 BOOLEAN retval = FALSE;
962
963 if (GlobalConfig.HideUIFlags & HIDEUI_FLAG_EDITOR) {
964 return FALSE;
965 }
966
967 refit_call4_wrapper(ST->ConOut->QueryMode, ST->ConOut, ST->ConOut->Mode->Mode, &x_max, &y_max);
968
969 if (!GlobalConfig.TextOnly)
970 SwitchToText(TRUE);
971
972 if (line_edit(MenuEntry->LoadOptions, &EditedOptions, x_max)) {
973 MyFreePool(MenuEntry->LoadOptions);
974 MenuEntry->LoadOptions = EditedOptions;
975 retval = TRUE;
976 } // if
977 if (!GlobalConfig.TextOnly)
978 SwitchToGraphics();
979 return retval;
980 } // VOID EditOptions()
981
982 //
983 // user-callable dispatcher functions
984 //
985
986 UINTN RunMenu(IN REFIT_MENU_SCREEN *Screen, OUT REFIT_MENU_ENTRY **ChosenEntry)
987 {
988 INTN DefaultEntry = -1;
989 MENU_STYLE_FUNC Style = TextMenuStyle;
990
991 if (AllowGraphicsMode)
992 Style = GraphicsMenuStyle;
993
994 return RunGenericMenu(Screen, Style, &DefaultEntry, ChosenEntry);
995 }
996
997 UINTN RunMainMenu(IN REFIT_MENU_SCREEN *Screen, IN CHAR16* DefaultSelection, OUT REFIT_MENU_ENTRY **ChosenEntry)
998 {
999 MENU_STYLE_FUNC Style = TextMenuStyle;
1000 MENU_STYLE_FUNC MainStyle = TextMenuStyle;
1001 REFIT_MENU_ENTRY *TempChosenEntry;
1002 UINTN MenuExit = 0;
1003 INTN DefaultEntryIndex = -1;
1004 INTN DefaultSubmenuIndex = -1;
1005
1006 if (DefaultSelection != NULL) {
1007 // Find a menu entry that includes *DefaultSelection as a substring
1008 DefaultEntryIndex = FindMenuShortcutEntry(Screen, DefaultSelection);
1009 }
1010
1011 if (AllowGraphicsMode) {
1012 Style = GraphicsMenuStyle;
1013 MainStyle = MainMenuStyle;
1014 }
1015
1016 while (!MenuExit) {
1017 MenuExit = RunGenericMenu(Screen, MainStyle, &DefaultEntryIndex, &TempChosenEntry);
1018 Screen->TimeoutSeconds = 0;
1019
1020 if (MenuExit == MENU_EXIT_DETAILS) {
1021 if (TempChosenEntry->SubScreen != NULL) {
1022 MenuExit = RunGenericMenu(TempChosenEntry->SubScreen, Style, &DefaultSubmenuIndex, &TempChosenEntry);
1023 if (MenuExit == MENU_EXIT_ESCAPE || TempChosenEntry->Tag == TAG_RETURN)
1024 MenuExit = 0;
1025 if (MenuExit == MENU_EXIT_DETAILS) {
1026 if (!EditOptions((LOADER_ENTRY *) TempChosenEntry))
1027 MenuExit = 0;
1028 } // if
1029 } else { // no sub-screen; ignore keypress
1030 MenuExit = 0;
1031 }
1032 } // Enter sub-screen
1033 }
1034
1035 if (ChosenEntry)
1036 *ChosenEntry = TempChosenEntry;
1037 return MenuExit;
1038 } /* UINTN RunMainMenu() */