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