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