5 * Copyright (c) 2006 Christoph Pfisterer
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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.
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.
37 * Modifications copyright (c) 2012 Roderick W. Smith
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.
52 #include "../include/refit_call_wrapper.h"
54 #include "../include/egemb_back_selected_small.h"
55 #include "../include/egemb_arrow_left.h"
56 #include "../include/egemb_arrow_right.h"
58 // other menu definitions
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)
67 typedef VOID (*MENU_STYLE_FUNC
)(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
);
69 static CHAR16 ArrowUp
[2] = { ARROW_UP
, 0 };
70 static CHAR16 ArrowDown
[2] = { ARROW_DOWN
, 0 };
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)
78 #define ROW0_TILESIZE (144)
79 #define ROW1_TILESIZE (64)
80 #define TILE_XSPACING (8)
81 #define TILE_YSPACING (16)
83 // Alignment values for PaintIcon()
87 static EG_IMAGE
*SelectionImages
[2] = { NULL
, NULL
};
88 static EG_PIXEL SelectionBackgroundPixel
= { 0xff, 0xff, 0xff, 0 };
91 // Graphics helper functions
94 static VOID
InitSelection(VOID
)
96 UINTN x
, y
, src_x
, src_y
;
97 EG_PIXEL
*DestPtr
, *SrcPtr
;
99 if (!AllowGraphicsMode
)
101 if (SelectionImages
[0] != NULL
)
104 // load small selection image
105 if (GlobalConfig
.SelectionSmallFileName
!= NULL
) {
106 SelectionImages
[1] = egLoadImage(SelfDir
, GlobalConfig
.SelectionSmallFileName
, TRUE
);
108 if (SelectionImages
[1] == NULL
)
109 SelectionImages
[1] = egPrepareEmbeddedImage(&egemb_back_selected_small
, TRUE
);
110 SelectionImages
[1] = egEnsureImageSize(SelectionImages
[1],
111 ROW1_TILESIZE
, ROW1_TILESIZE
, &MenuBackgroundPixel
);
112 if (SelectionImages
[1] == NULL
)
115 // load big selection image
116 if (GlobalConfig
.SelectionBigFileName
!= NULL
) {
117 SelectionImages
[0] = egLoadImage(SelfDir
, GlobalConfig
.SelectionBigFileName
, TRUE
);
118 SelectionImages
[0] = egEnsureImageSize(SelectionImages
[0],
119 ROW0_TILESIZE
, ROW0_TILESIZE
, &MenuBackgroundPixel
);
121 if (SelectionImages
[0] == NULL
) {
122 // calculate big selection image from small one
124 SelectionImages
[0] = egCreateImage(ROW0_TILESIZE
, ROW0_TILESIZE
, TRUE
);
125 if (SelectionImages
[0] == NULL
) {
126 egFreeImage(SelectionImages
[1]);
127 SelectionImages
[1] = NULL
;
131 DestPtr
= SelectionImages
[0]->PixelData
;
132 SrcPtr
= SelectionImages
[1]->PixelData
;
133 for (y
= 0; y
< ROW0_TILESIZE
; y
++) {
134 if (y
< (ROW1_TILESIZE
>> 1))
136 else if (y
< (ROW0_TILESIZE
- (ROW1_TILESIZE
>> 1)))
137 src_y
= (ROW1_TILESIZE
>> 1);
139 src_y
= y
- (ROW0_TILESIZE
- ROW1_TILESIZE
);
141 for (x
= 0; x
< ROW0_TILESIZE
; x
++) {
142 if (x
< (ROW1_TILESIZE
>> 1))
144 else if (x
< (ROW0_TILESIZE
- (ROW1_TILESIZE
>> 1)))
145 src_x
= (ROW1_TILESIZE
>> 1);
147 src_x
= x
- (ROW0_TILESIZE
- ROW1_TILESIZE
);
149 *DestPtr
++ = SrcPtr
[src_y
* ROW1_TILESIZE
+ src_x
];
153 } // VOID InitSelection()
156 // Scrolling functions
159 static VOID
InitScroll(OUT SCROLL_STATE
*State
, IN UINTN ItemCount
, IN UINTN VisibleSpace
)
161 State
->PreviousSelection
= State
->CurrentSelection
= 0;
162 State
->MaxIndex
= (INTN
)ItemCount
- 1;
163 State
->FirstVisible
= 0;
164 if (AllowGraphicsMode
) {
165 State
->MaxVisible
= UGAWidth
/ (ROW0_TILESIZE
+ TILE_XSPACING
) - 1;
167 State
->MaxVisible
= ConHeight
- 4;
168 if ((VisibleSpace
> 0) && (VisibleSpace
< State
->MaxVisible
))
169 State
->MaxVisible
= (INTN
)VisibleSpace
;
170 State
->PaintAll
= TRUE
;
171 State
->PaintSelection
= FALSE
;
173 State
->LastVisible
= State
->FirstVisible
+ State
->MaxVisible
- 1;
176 // Adjust variables relating to the scrolling of tags, for when a selected icon isn't
177 // visible given the current scrolling condition....
178 static VOID
AdjustScrollState(IN SCROLL_STATE
*State
) {
179 if (State
->CurrentSelection
> State
->LastVisible
) {
180 State
->LastVisible
= State
->CurrentSelection
;
181 State
->FirstVisible
= 1 + State
->CurrentSelection
- State
->MaxVisible
;
182 if (State
->FirstVisible
< 0) // shouldn't happen, but just in case....
183 State
->FirstVisible
= 0;
184 State
->PaintAll
= TRUE
;
186 if (State
->CurrentSelection
< State
->FirstVisible
) {
187 State
->FirstVisible
= State
->CurrentSelection
;
188 State
->LastVisible
= State
->CurrentSelection
+ State
->MaxVisible
- 1;
189 State
->PaintAll
= TRUE
;
191 } // static VOID AdjustScrollState
193 static VOID
UpdateScroll(IN OUT SCROLL_STATE
*State
, IN UINTN Movement
)
195 State
->PreviousSelection
= State
->CurrentSelection
;
198 case SCROLL_LINE_LEFT
:
199 if (State
->CurrentSelection
> 0) {
200 State
->CurrentSelection
--;
204 case SCROLL_LINE_RIGHT
:
205 if (State
->CurrentSelection
< State
->MaxIndex
) {
206 State
->CurrentSelection
++;
211 if (State
->ScrollMode
== SCROLL_MODE_ICONS
) {
212 if (State
->CurrentSelection
>= State
->InitialRow1
) {
213 if (State
->MaxIndex
> State
->InitialRow1
) { // avoid division by 0!
214 State
->CurrentSelection
= State
->FirstVisible
+ (State
->LastVisible
- State
->FirstVisible
) *
215 (State
->CurrentSelection
- State
->InitialRow1
) /
216 (State
->MaxIndex
- State
->InitialRow1
);
218 State
->CurrentSelection
= State
->FirstVisible
;
220 } // if in second row
222 if (State
->CurrentSelection
> 0)
223 State
->CurrentSelection
--;
227 case SCROLL_LINE_DOWN
:
228 if (State
->ScrollMode
== SCROLL_MODE_ICONS
) {
229 if (State
->CurrentSelection
<= State
->FinalRow0
) {
230 if (State
->LastVisible
> State
->FirstVisible
) { // avoid division by 0!
231 State
->CurrentSelection
= State
->InitialRow1
+ (State
->MaxIndex
- State
->InitialRow1
) *
232 (State
->CurrentSelection
- State
->FirstVisible
) /
233 (State
->LastVisible
- State
->FirstVisible
);
235 State
->CurrentSelection
= State
->InitialRow1
;
239 if (State
->CurrentSelection
< State
->MaxIndex
)
240 State
->CurrentSelection
++;
245 if (State
->CurrentSelection
<= State
->FinalRow0
)
246 State
->CurrentSelection
-= State
->MaxVisible
;
247 else if (State
->CurrentSelection
== State
->InitialRow1
)
248 State
->CurrentSelection
= State
->FinalRow0
;
250 State
->CurrentSelection
= State
->InitialRow1
;
251 if (State
->CurrentSelection
< 0)
252 State
->CurrentSelection
= 0;
256 if (State
->CurrentSelection
> 0) {
257 State
->PaintAll
= TRUE
;
258 State
->CurrentSelection
= 0;
262 case SCROLL_PAGE_DOWN
:
263 if (State
->CurrentSelection
< State
->FinalRow0
) {
264 State
->CurrentSelection
+= State
->MaxVisible
;
265 if (State
->CurrentSelection
> State
->FinalRow0
)
266 State
->CurrentSelection
= State
->FinalRow0
;
267 } else if (State
->CurrentSelection
== State
->FinalRow0
) {
268 State
->CurrentSelection
++;
270 State
->CurrentSelection
= State
->MaxIndex
;
272 if (State
->CurrentSelection
> State
->MaxIndex
)
273 State
->CurrentSelection
= State
->MaxIndex
;
277 if (State
->CurrentSelection
< State
->MaxIndex
) {
278 State
->PaintAll
= TRUE
;
279 State
->CurrentSelection
= State
->MaxIndex
;
287 if (State
->ScrollMode
== SCROLL_MODE_TEXT
)
288 AdjustScrollState(State
);
290 if (!State
->PaintAll
&& State
->CurrentSelection
!= State
->PreviousSelection
)
291 State
->PaintSelection
= TRUE
;
292 State
->LastVisible
= State
->FirstVisible
+ State
->MaxVisible
- 1;
293 } // static VOID UpdateScroll()
296 // menu helper functions
299 VOID
AddMenuInfoLine(IN REFIT_MENU_SCREEN
*Screen
, IN CHAR16
*InfoLine
)
301 AddListElement((VOID
***) &(Screen
->InfoLines
), &(Screen
->InfoLineCount
), InfoLine
);
304 VOID
AddMenuEntry(IN REFIT_MENU_SCREEN
*Screen
, IN REFIT_MENU_ENTRY
*Entry
)
306 AddListElement((VOID
***) &(Screen
->Entries
), &(Screen
->EntryCount
), Entry
);
310 static INTN
FindMenuShortcutEntry(IN REFIT_MENU_SCREEN
*Screen
, IN CHAR16
*Shortcut
)
314 if (Shortcut
== NULL
)
317 if (StrLen(Shortcut
) == 1) {
318 if (Shortcut
[0] >= 'a' && Shortcut
[0] <= 'z')
319 Shortcut
[0] -= ('a' - 'A');
321 for (i
= 0; i
< Screen
->EntryCount
; i
++) {
322 if (Screen
->Entries
[i
]->ShortcutDigit
== Shortcut
[0] || Screen
->Entries
[i
]->ShortcutLetter
== Shortcut
[0]) {
327 } else if (StrLen(Shortcut
) > 1) {
328 for (i
= 0; i
< Screen
->EntryCount
; i
++) {
329 if (StriSubCmp(Shortcut
, Screen
->Entries
[i
]->Title
))
336 // Identify the end of row 0 and the beginning of row 1; store the results in the
337 // appropriate fields in State. Also reduce MaxVisible if that value is greater
338 // than the total number of row-0 tags and if we're in an icon-based screen
339 static VOID
IdentifyRows(IN SCROLL_STATE
*State
, IN REFIT_MENU_SCREEN
*Screen
) {
342 State
->FinalRow0
= 0;
343 State
->InitialRow1
= State
->MaxIndex
;
344 for (i
= 0; i
< State
->MaxIndex
; i
++) {
345 if (Screen
->Entries
[i
]->Row
== 0) {
346 State
->FinalRow0
= i
;
347 } else if ((Screen
->Entries
[i
]->Row
== 1) && (State
->InitialRow1
> i
)) {
348 State
->InitialRow1
= i
;
351 if ((State
->ScrollMode
== SCROLL_MODE_ICONS
) && (State
->MaxVisible
> (State
->FinalRow0
+ 1)))
352 State
->MaxVisible
= State
->FinalRow0
+ 1;
353 } // static VOID IdentifyRows()
356 // generic menu function
358 static UINTN
RunGenericMenu(IN REFIT_MENU_SCREEN
*Screen
, IN MENU_STYLE_FUNC StyleFunc
, IN OUT INTN
*DefaultEntryIndex
,
359 OUT REFIT_MENU_ENTRY
**ChosenEntry
)
366 BOOLEAN HaveTimeout
= FALSE
;
367 UINTN TimeoutCountdown
= 0;
368 CHAR16 TimeoutMessage
[256];
369 CHAR16 KeyAsString
[2];
372 if (Screen
->TimeoutSeconds
> 0) {
374 TimeoutCountdown
= Screen
->TimeoutSeconds
* 10;
378 StyleFunc(Screen
, &State
, MENU_FUNCTION_INIT
, NULL
);
379 IdentifyRows(&State
, Screen
);
380 // override the starting selection with the default index, if any
381 if (*DefaultEntryIndex
>= 0 && *DefaultEntryIndex
<= State
.MaxIndex
) {
382 State
.CurrentSelection
= *DefaultEntryIndex
;
383 UpdateScroll(&State
, SCROLL_NONE
);
385 State
.PaintAll
= TRUE
;
389 if (State
.PaintAll
) {
390 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_ALL
, NULL
);
391 State
.PaintAll
= FALSE
;
392 } else if (State
.PaintSelection
) {
393 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_SELECTION
, NULL
);
394 State
.PaintSelection
= FALSE
;
398 SPrint(TimeoutMessage
, 255, L
"%s in %d seconds", Screen
->TimeoutText
, (TimeoutCountdown
+ 5) / 10);
399 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_TIMEOUT
, TimeoutMessage
);
402 // read key press (and wait for it if applicable)
403 Status
= refit_call2_wrapper(ST
->ConIn
->ReadKeyStroke
, ST
->ConIn
, &key
);
404 if (Status
== EFI_NOT_READY
) {
405 if (HaveTimeout
&& TimeoutCountdown
== 0) {
407 MenuExit
= MENU_EXIT_TIMEOUT
;
409 } else if (HaveTimeout
) {
410 refit_call1_wrapper(BS
->Stall
, 100000);
413 refit_call3_wrapper(BS
->WaitForEvent
, 1, &ST
->ConIn
->WaitForKey
, &index
);
417 // the user pressed a key, cancel the timeout
418 StyleFunc(Screen
, &State
, MENU_FUNCTION_PAINT_TIMEOUT
, L
"");
422 // react to key press
423 switch (key
.ScanCode
) {
425 UpdateScroll(&State
, SCROLL_LINE_UP
);
428 UpdateScroll(&State
, SCROLL_LINE_LEFT
);
431 UpdateScroll(&State
, SCROLL_LINE_DOWN
);
434 UpdateScroll(&State
, SCROLL_LINE_RIGHT
);
437 UpdateScroll(&State
, SCROLL_FIRST
);
440 UpdateScroll(&State
, SCROLL_LAST
);
443 UpdateScroll(&State
, SCROLL_PAGE_UP
);
446 UpdateScroll(&State
, SCROLL_PAGE_DOWN
);
449 MenuExit
= MENU_EXIT_ESCAPE
;
453 MenuExit
= MENU_EXIT_DETAILS
;
460 MenuExit
= MENU_EXIT_ESCAPE
;
463 switch (key
.UnicodeChar
) {
465 case CHAR_CARRIAGE_RETURN
:
467 MenuExit
= MENU_EXIT_ENTER
;
470 MenuExit
= MENU_EXIT_DETAILS
;
473 KeyAsString
[0] = key
.UnicodeChar
;
475 ShortcutEntry
= FindMenuShortcutEntry(Screen
, KeyAsString
);
476 if (ShortcutEntry
>= 0) {
477 State
.CurrentSelection
= ShortcutEntry
;
478 MenuExit
= MENU_EXIT_ENTER
;
484 StyleFunc(Screen
, &State
, MENU_FUNCTION_CLEANUP
, NULL
);
487 *ChosenEntry
= Screen
->Entries
[State
.CurrentSelection
];
488 *DefaultEntryIndex
= State
.CurrentSelection
;
490 } /* static UINTN RunGenericMenu() */
493 // text-mode generic style
496 static VOID
TextMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
499 UINTN MenuWidth
, ItemWidth
, MenuHeight
;
500 static UINTN MenuPosY
;
501 static CHAR16
**DisplayStrings
;
502 CHAR16 TimeoutMessage
[256];
504 State
->ScrollMode
= SCROLL_MODE_TEXT
;
507 case MENU_FUNCTION_INIT
:
510 if (Screen
->InfoLineCount
> 0)
511 MenuPosY
+= Screen
->InfoLineCount
+ 1;
512 MenuHeight
= ConHeight
- MenuPosY
- 3;
513 if (Screen
->TimeoutSeconds
> 0)
515 InitScroll(State
, Screen
->EntryCount
, MenuHeight
);
517 // determine width of the menu
518 MenuWidth
= 20; // minimum
519 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
520 ItemWidth
= StrLen(Screen
->Entries
[i
]->Title
);
521 if (MenuWidth
< ItemWidth
)
522 MenuWidth
= ItemWidth
;
525 if (MenuWidth
> ConWidth
- 3)
526 MenuWidth
= ConWidth
- 3;
528 // prepare strings for display
529 DisplayStrings
= AllocatePool(sizeof(CHAR16
*) * Screen
->EntryCount
);
530 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
531 // Note: Theoretically, SPrint() is a cleaner way to do this; but the
532 // description of the StrSize parameter to SPrint implies it's measured
533 // in characters, but in practice both TianoCore and GNU-EFI seem to
534 // use bytes instead, resulting in truncated displays. I could just
535 // double the size of the StrSize parameter, but that seems unsafe in
536 // case a future library change starts treating this as characters, so
537 // I'm doing it the hard way in this instance.
538 // TODO: Review the above and possibly change other uses of SPrint()
539 DisplayStrings
[i
] = AllocateZeroPool(2 * sizeof(CHAR16
));
540 DisplayStrings
[i
][0] = L
' ';
541 MergeStrings(&DisplayStrings
[i
], Screen
->Entries
[i
]->Title
, 0);
542 if (StrLen(DisplayStrings
[i
]) > MenuWidth
)
543 DisplayStrings
[i
][MenuWidth
- 1] = 0;
544 // TODO: use more elaborate techniques for shortening too long strings (ellipses in the middle)
545 // TODO: account for double-width characters
549 BeginTextScreen(Screen
->Title
);
550 if (Screen
->InfoLineCount
> 0) {
551 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_BASIC
);
552 for (i
= 0; i
< (INTN
)Screen
->InfoLineCount
; i
++) {
553 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 3, 4 + i
);
554 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->InfoLines
[i
]);
560 case MENU_FUNCTION_CLEANUP
:
561 // release temporary memory
562 for (i
= 0; i
<= State
->MaxIndex
; i
++)
563 MyFreePool(DisplayStrings
[i
]);
564 MyFreePool(DisplayStrings
);
567 case MENU_FUNCTION_PAINT_ALL
:
568 // paint the whole screen (initially and after scrolling)
569 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
570 if (i
>= State
->FirstVisible
&& i
<= State
->LastVisible
) {
571 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2, MenuPosY
+ (i
- State
->FirstVisible
));
572 if (i
== State
->CurrentSelection
)
573 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_CURRENT
);
575 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_BASIC
);
576 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[i
]);
579 // scrolling indicators
580 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_SCROLLARROW
);
581 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, MenuPosY
);
582 if (State
->FirstVisible
> 0)
583 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, ArrowUp
);
585 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, L
" ");
586 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, MenuPosY
+ State
->MaxVisible
);
587 if (State
->LastVisible
< State
->MaxIndex
)
588 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, ArrowDown
);
590 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, L
" ");
591 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
592 if (Screen
->Hint1
!= NULL
) {
593 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 2);
594 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->Hint1
);
596 if (Screen
->Hint2
!= NULL
) {
597 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 1);
598 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, Screen
->Hint2
);
603 case MENU_FUNCTION_PAINT_SELECTION
:
604 // redraw selection cursor
605 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2,
606 MenuPosY
+ (State
->PreviousSelection
- State
->FirstVisible
));
607 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_BASIC
);
608 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[State
->PreviousSelection
]);
609 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 2,
610 MenuPosY
+ (State
->CurrentSelection
- State
->FirstVisible
));
611 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_CHOICE_CURRENT
);
612 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, DisplayStrings
[State
->CurrentSelection
]);
615 case MENU_FUNCTION_PAINT_TIMEOUT
:
616 if (ParamText
[0] == 0) {
618 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_BASIC
);
619 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 0, ConHeight
- 3);
620 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, BlankLine
+ 1);
622 // paint or update message
623 refit_call2_wrapper(ST
->ConOut
->SetAttribute
, ST
->ConOut
, ATTR_ERROR
);
624 refit_call3_wrapper(ST
->ConOut
->SetCursorPosition
, ST
->ConOut
, 3, ConHeight
- 3);
625 SPrint(TimeoutMessage
, 255, L
"%s ", ParamText
);
626 refit_call2_wrapper(ST
->ConOut
->OutputString
, ST
->ConOut
, TimeoutMessage
);
634 // graphical generic style
639 static VOID
DrawSubmenuText(IN CHAR16
*Text
, IN BOOLEAN Selected
, IN UINTN FieldWidth
, IN UINTN XPos
, IN UINTN YPos
)
641 // UINTN TextWidth = TEXT_XMARGIN * 2 + StrLen(Text) * FONT_CELL_WIDTH;
642 EG_IMAGE
*TextBuffer
;
644 TextBuffer
= egCreateImage(FieldWidth
, TEXT_LINE_HEIGHT
, FALSE
);
646 egFillImage(TextBuffer
, &MenuBackgroundPixel
);
648 // draw selection bar background
649 egFillImageArea(TextBuffer
, 0, 0, FieldWidth
, TextBuffer
->Height
, &SelectionBackgroundPixel
);
653 egRenderText(Text
, TextBuffer
, TEXT_XMARGIN
, TEXT_YMARGIN
);
654 egDrawImageWithTransparency(TextBuffer
, NULL
, XPos
, YPos
, TextBuffer
->Width
, TextBuffer
->Height
);
655 // BltImage(TextBuffer, XPos, YPos);
658 static VOID
DrawMainMenuText(IN CHAR16
*Text
, IN UINTN XPos
, IN UINTN YPos
)
660 UINTN TextWidth
, TextPosX
;
661 EG_IMAGE
*TextBuffer
;
663 TextBuffer
= egCropImage(GlobalConfig
.ScreenBackground
, XPos
, YPos
, LAYOUT_TEXT_WIDTH
, TEXT_LINE_HEIGHT
);
666 egMeasureText(Text
, &TextWidth
, NULL
);
667 if (TextWidth
> TextBuffer
->Width
)
670 TextPosX
= (TextBuffer
->Width
- TextWidth
) / 2;
671 egRenderText(Text
, TextBuffer
, TextPosX
, 0);
672 egDrawImageWithTransparency(TextBuffer
, NULL
, XPos
, YPos
, TextBuffer
->Width
, TextBuffer
->Height
);
675 // Compute the size & position of the window that will hold a subscreen's information.
676 static VOID
ComputeSubScreenWindowSize(REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*XPos
, UINTN
*YPos
, UINTN
*Width
, UINTN
*Height
, UINTN
*LineWidth
) {
677 UINTN i
, ItemWidth
, HintTop
, BannerBottomEdge
, TitleWidth
, CenteredTop
;
681 TitleWidth
= StrLen(Screen
->Title
);
682 if ((Screen
->TitleImage
) && (TitleWidth
> (Screen
->TitleImage
->Width
/ FONT_CELL_WIDTH
))) {
683 TitleWidth
-= (Screen
->TitleImage
->Width
/ FONT_CELL_WIDTH
);
685 if (TitleWidth
> *Width
) {
688 for (i
= 0; i
< Screen
->InfoLineCount
; i
++) {
689 ItemWidth
= StrLen(Screen
->InfoLines
[i
]);
690 if (*Width
< ItemWidth
) {
695 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
696 ItemWidth
= StrLen(Screen
->Entries
[i
]->Title
);
697 if (*Width
< ItemWidth
) {
702 *Width
= TEXT_XMARGIN
* 2 + *Width
* FONT_CELL_WIDTH
;
704 if (Screen
->TitleImage
)
705 *Width
+= (Screen
->TitleImage
->Width
+ TITLEICON_SPACING
+ FONT_CELL_WIDTH
);
707 *Width
+= FONT_CELL_WIDTH
;
709 // Keep it within the bounds of the screen, or 2/3 of the screen's width
710 // for screens over 800 pixels wide
711 if (*Width
> UGAWidth
)
713 if ((*Width
> (2 * UGAWidth
) / 3) && (UGAWidth
> 800))
714 *Width
= (2 * UGAWidth
) / 3;
716 *XPos
= (UGAWidth
- *Width
) / 2;
718 HintTop
= UGAHeight
- (FONT_CELL_HEIGHT
* 3); // top of hint text
719 *Height
*= TEXT_LINE_HEIGHT
;
720 if (Screen
->TitleImage
&& (*Height
< (Screen
->TitleImage
->Height
+ TEXT_LINE_HEIGHT
* 3)))
721 *Height
= Screen
->TitleImage
->Height
+ TEXT_LINE_HEIGHT
* 3;
723 if (GlobalConfig
.BannerBottomEdge
>= HintTop
) { // probably a full-screen image; treat it as an empty banner
724 BannerBottomEdge
= 0;
726 BannerBottomEdge
= GlobalConfig
.BannerBottomEdge
;
728 if (*Height
> (HintTop
-BannerBottomEdge
- FONT_CELL_HEIGHT
* 2)) {
729 BannerBottomEdge
= 0;
731 if (*Height
> (HintTop
-BannerBottomEdge
- FONT_CELL_HEIGHT
* 2)) {
732 // TODO: Implement scrolling in text screen.
733 *Height
= (HintTop
- BannerBottomEdge
- FONT_CELL_HEIGHT
* 2);
735 *YPos
= BannerBottomEdge
+ FONT_CELL_HEIGHT
+ (HintTop
- BannerBottomEdge
- *Height
) / 2;
736 // Above often produces a text field that feels bottom-weighted, so adjust
737 // upward a bit, if possible....
738 CenteredTop
= ((UGAHeight
- *Height
) / 2);
739 if ((*YPos
> CenteredTop
) && (CenteredTop
> BannerBottomEdge
))
741 } // VOID ComputeSubScreenWindowSize()
743 // Displays sub-menus
744 static VOID
GraphicsMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
748 static UINTN LineWidth
, MenuWidth
, MenuHeight
, EntriesPosX
, EntriesPosY
, TimeoutPosY
;
750 EG_PIXEL
*BackgroundPixel
= &(GlobalConfig
.ScreenBackground
->PixelData
[0]);
752 State
->ScrollMode
= SCROLL_MODE_TEXT
;
755 case MENU_FUNCTION_INIT
:
756 InitScroll(State
, Screen
->EntryCount
, 0);
757 ComputeSubScreenWindowSize(Screen
, State
, &EntriesPosX
, &EntriesPosY
, &MenuWidth
, &MenuHeight
, &LineWidth
);
758 TimeoutPosY
= EntriesPosY
+ (Screen
->EntryCount
+ 1) * TEXT_LINE_HEIGHT
;
761 SwitchToGraphicsAndClear();
762 Window
= egCreateFilledImage(MenuWidth
, MenuHeight
, FALSE
, BackgroundPixel
);
763 egDrawImage(Window
, EntriesPosX
, EntriesPosY
);
764 egMeasureText(Screen
->Title
, &ItemWidth
, NULL
);
765 DrawSubmenuText(Screen
->Title
, FALSE
, (StrLen(Screen
->Title
) + 2) * FONT_CELL_WIDTH
,
766 EntriesPosX
+ (MenuWidth
- ItemWidth
) / 2, EntriesPosY
+= TEXT_LINE_HEIGHT
);
767 if (Screen
->TitleImage
) {
768 BltImageAlpha(Screen
->TitleImage
, EntriesPosX
, EntriesPosY
+ TEXT_LINE_HEIGHT
* 2, BackgroundPixel
);
769 EntriesPosX
+= (Screen
->TitleImage
->Width
+ TITLEICON_SPACING
);
771 EntriesPosY
+= (TEXT_LINE_HEIGHT
* 2);
772 if (Screen
->InfoLineCount
> 0) {
773 for (i
= 0; i
< (INTN
)Screen
->InfoLineCount
; i
++) {
774 DrawSubmenuText(Screen
->InfoLines
[i
], FALSE
, LineWidth
, EntriesPosX
, EntriesPosY
);
775 EntriesPosY
+= TEXT_LINE_HEIGHT
;
777 EntriesPosY
+= TEXT_LINE_HEIGHT
; // also add a blank line
782 case MENU_FUNCTION_CLEANUP
:
786 case MENU_FUNCTION_PAINT_ALL
:
787 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
788 DrawSubmenuText(Screen
->Entries
[i
]->Title
, (i
== State
->CurrentSelection
), LineWidth
,
789 EntriesPosX
, EntriesPosY
+ i
* TEXT_LINE_HEIGHT
);
791 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
792 if ((Screen
->Hint1
!= NULL
) && (StrLen(Screen
->Hint1
) > 0))
793 DrawMainMenuText(Screen
->Hint1
, (UGAWidth
- LAYOUT_TEXT_WIDTH
) / 2, UGAHeight
- (FONT_CELL_HEIGHT
* 3));
794 if ((Screen
->Hint2
!= NULL
) && (StrLen(Screen
->Hint2
) > 0))
795 DrawMainMenuText(Screen
->Hint2
, (UGAWidth
- LAYOUT_TEXT_WIDTH
) / 2, UGAHeight
- (FONT_CELL_HEIGHT
* 2));
799 case MENU_FUNCTION_PAINT_SELECTION
:
800 // redraw selection cursor
801 DrawSubmenuText(Screen
->Entries
[State
->PreviousSelection
]->Title
, FALSE
, LineWidth
,
802 EntriesPosX
, EntriesPosY
+ State
->PreviousSelection
* TEXT_LINE_HEIGHT
);
803 DrawSubmenuText(Screen
->Entries
[State
->CurrentSelection
]->Title
, TRUE
, LineWidth
,
804 EntriesPosX
, EntriesPosY
+ State
->CurrentSelection
* TEXT_LINE_HEIGHT
);
807 case MENU_FUNCTION_PAINT_TIMEOUT
:
808 DrawSubmenuText(ParamText
, FALSE
, LineWidth
, EntriesPosX
, TimeoutPosY
);
812 } // static VOID GraphicsMenuStyle()
815 // graphical main menu style
818 static VOID
DrawMainMenuEntry(REFIT_MENU_ENTRY
*Entry
, BOOLEAN selected
, UINTN XPos
, UINTN YPos
)
820 EG_IMAGE
*Background
;
822 if (SelectionImages
!= NULL
) {
824 Background
= egCropImage(GlobalConfig
.ScreenBackground
, XPos
, YPos
,
825 SelectionImages
[Entry
->Row
]->Width
, SelectionImages
[Entry
->Row
]->Height
);
826 egComposeImage(Background
, SelectionImages
[Entry
->Row
], 0, 0);
827 BltImageCompositeBadge(Background
, Entry
->Image
, Entry
->BadgeImage
, XPos
, YPos
);
828 } else { // Image not selected; copy background
829 egDrawImageWithTransparency(Entry
->Image
, Entry
->BadgeImage
, XPos
, YPos
,
830 SelectionImages
[Entry
->Row
]->Width
, SelectionImages
[Entry
->Row
]->Height
);
833 } // VOID DrawMainMenuEntry()
835 static VOID
PaintAll(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*itemPosX
,
836 UINTN row0PosY
, UINTN row1PosY
, UINTN textPosY
) {
839 if (Screen
->Entries
[State
->CurrentSelection
]->Row
== 0)
840 AdjustScrollState(State
);
841 for (i
= State
->FirstVisible
; i
<= State
->MaxIndex
; i
++) {
842 if (Screen
->Entries
[i
]->Row
== 0) {
843 if (i
<= State
->LastVisible
) {
844 DrawMainMenuEntry(Screen
->Entries
[i
], (i
== State
->CurrentSelection
) ? TRUE
: FALSE
,
845 itemPosX
[i
- State
->FirstVisible
], row0PosY
);
848 DrawMainMenuEntry(Screen
->Entries
[i
], (i
== State
->CurrentSelection
) ? TRUE
: FALSE
, itemPosX
[i
], row1PosY
);
851 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
))
852 DrawMainMenuText(Screen
->Entries
[State
->CurrentSelection
]->Title
,
853 (UGAWidth
- LAYOUT_TEXT_WIDTH
) >> 1, textPosY
);
855 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_HINTS
)) {
856 DrawMainMenuText(Screen
->Hint1
, (UGAWidth
- LAYOUT_TEXT_WIDTH
) / 2, UGAHeight
- (FONT_CELL_HEIGHT
* 3));
857 DrawMainMenuText(Screen
->Hint2
, (UGAWidth
- LAYOUT_TEXT_WIDTH
) / 2, UGAHeight
- (FONT_CELL_HEIGHT
* 2));
859 } // static VOID PaintAll()
861 // Move the selection to State->CurrentSelection, adjusting icon row if necessary...
862 static VOID
PaintSelection(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, UINTN
*itemPosX
,
863 UINTN row0PosY
, UINTN row1PosY
, UINTN textPosY
) {
864 UINTN XSelectPrev
, XSelectCur
, YPosPrev
, YPosCur
;
866 if (((State
->CurrentSelection
<= State
->LastVisible
) && (State
->CurrentSelection
>= State
->FirstVisible
)) ||
867 (State
->CurrentSelection
>= State
->InitialRow1
) ) {
868 if (Screen
->Entries
[State
->PreviousSelection
]->Row
== 0) {
869 XSelectPrev
= State
->PreviousSelection
- State
->FirstVisible
;
872 XSelectPrev
= State
->PreviousSelection
;
875 if (Screen
->Entries
[State
->CurrentSelection
]->Row
== 0) {
876 XSelectCur
= State
->CurrentSelection
- State
->FirstVisible
;
879 XSelectCur
= State
->CurrentSelection
;
882 DrawMainMenuEntry(Screen
->Entries
[State
->PreviousSelection
], FALSE
, itemPosX
[XSelectPrev
], YPosPrev
);
883 DrawMainMenuEntry(Screen
->Entries
[State
->CurrentSelection
], TRUE
, itemPosX
[XSelectCur
], YPosCur
);
884 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
))
885 DrawMainMenuText(Screen
->Entries
[State
->CurrentSelection
]->Title
,
886 (UGAWidth
- LAYOUT_TEXT_WIDTH
) >> 1, textPosY
);
887 } else { // Current selection not visible; must redraw the menu....
888 MainMenuStyle(Screen
, State
, MENU_FUNCTION_PAINT_ALL
, NULL
);
890 } // static VOID MoveSelection(VOID)
892 // Display an icon at the specified location. Uses the image specified by
893 // ExternalFilename if it's available, or BuiltInImage if it's not. The
894 // Y position is specified as the center value, and so is adjusted by half
895 // the icon's height. The X position is set along the icon's left
896 // edge if Alignment == ALIGN_LEFT, and along the right edge if
897 // Alignment == ALIGN_RIGHT
898 static VOID
PaintIcon(IN EG_EMBEDDED_IMAGE
*BuiltInIcon
, IN CHAR16
*ExternalFilename
, UINTN PosX
, UINTN PosY
, UINTN Alignment
) {
899 EG_IMAGE
*Icon
= NULL
;
901 if (FileExists(SelfDir
, ExternalFilename
))
902 Icon
= egLoadIcon(SelfDir
, ExternalFilename
, 48);
904 Icon
= egPrepareEmbeddedImage(BuiltInIcon
, TRUE
);
906 if (Alignment
== ALIGN_RIGHT
)
908 egDrawImageWithTransparency(Icon
, NULL
, PosX
, PosY
- (Icon
->Height
/ 2), Icon
->Width
, Icon
->Height
);
910 } // static VOID PaintIcon()
912 inline UINTN
ComputeRow0PosX(VOID
) {
913 // return ((UGAHeight / 2) - (5 * ROW0_TILESIZE / 6));
914 return ((UGAHeight
/ 2) - ROW0_TILESIZE
/ 2);
915 } // UINTN ComputeRow0PosX()
917 // Display (or erase) the arrow icons to the left and right of an icon's row,
919 static VOID
PaintArrows(SCROLL_STATE
*State
, UINTN PosX
, UINTN PosY
, UINTN row0Loaders
) {
920 CHAR16 FileName
[256];
922 UINTN Width
, Height
, RightX
, AdjPosY
;
924 // NOTE: Assume that left and right arrows are of the same size....
925 Width
= egemb_arrow_left
.Width
;
926 Height
= egemb_arrow_left
.Height
;
927 RightX
= (UGAWidth
+ (ROW0_TILESIZE
+ TILE_XSPACING
) * State
->MaxVisible
) / 2 + TILE_XSPACING
;
928 AdjPosY
= PosY
- (Height
/ 2);
930 // For PaintIcon() calls, the starting Y position is moved to the midpoint
931 // of the surrounding row; PaintIcon() adjusts this back up by half the
932 // icon's height to properly center it.
933 if ((State
->FirstVisible
> 0) && (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_ARROWS
))) {
934 SPrint(FileName
, 255, L
"%s\\arrow_left.icns", GlobalConfig
.IconsDir
? GlobalConfig
.IconsDir
: DEFAULT_ICONS_DIR
);
935 PaintIcon(&egemb_arrow_left
, FileName
, PosX
, PosY
, ALIGN_RIGHT
);
937 TempImage
= egCropImage(GlobalConfig
.ScreenBackground
, PosX
- Width
, AdjPosY
, Width
, Height
);
938 BltImage(TempImage
, PosX
- Width
, AdjPosY
);
939 egFreeImage(TempImage
);
942 if ((State
->LastVisible
< (row0Loaders
- 1)) && (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_ARROWS
))) {
943 SPrint(FileName
, 255, L
"%s\\arrow_right.icns", GlobalConfig
.IconsDir
? GlobalConfig
.IconsDir
: DEFAULT_ICONS_DIR
);
944 PaintIcon(&egemb_arrow_right
, FileName
, RightX
, PosY
, ALIGN_LEFT
);
946 TempImage
= egCropImage(GlobalConfig
.ScreenBackground
, RightX
, AdjPosY
, Width
, Height
);
947 BltImage(TempImage
, RightX
, AdjPosY
);
948 egFreeImage(TempImage
);
950 } // VOID PaintArrows()
952 // Display main menu in graphics mode
953 VOID
MainMenuStyle(IN REFIT_MENU_SCREEN
*Screen
, IN SCROLL_STATE
*State
, IN UINTN Function
, IN CHAR16
*ParamText
)
956 static UINTN row0PosX
, row0PosXRunning
, row1PosY
, row0Loaders
;
957 UINTN row0Count
, row1Count
, row1PosX
, row1PosXRunning
;
958 static UINTN
*itemPosX
;
959 static UINTN row0PosY
, textPosY
;
961 State
->ScrollMode
= SCROLL_MODE_ICONS
;
964 case MENU_FUNCTION_INIT
:
965 InitScroll(State
, Screen
->EntryCount
, GlobalConfig
.MaxTags
);
971 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
972 if (Screen
->Entries
[i
]->Row
== 1) {
976 if (row0Count
< State
->MaxVisible
)
980 row0PosX
= (UGAWidth
+ TILE_XSPACING
- (ROW0_TILESIZE
+ TILE_XSPACING
) * row0Count
) >> 1;
981 row0PosY
= ComputeRow0PosX();
982 row1PosX
= (UGAWidth
+ TILE_XSPACING
- (ROW1_TILESIZE
+ TILE_XSPACING
) * row1Count
) >> 1;
983 row1PosY
= row0PosY
+ ROW0_TILESIZE
+ TILE_YSPACING
;
985 textPosY
= row1PosY
+ ROW1_TILESIZE
+ TILE_YSPACING
;
989 itemPosX
= AllocatePool(sizeof(UINTN
) * Screen
->EntryCount
);
990 row0PosXRunning
= row0PosX
;
991 row1PosXRunning
= row1PosX
;
992 for (i
= 0; i
<= State
->MaxIndex
; i
++) {
993 if (Screen
->Entries
[i
]->Row
== 0) {
994 itemPosX
[i
] = row0PosXRunning
;
995 row0PosXRunning
+= ROW0_TILESIZE
+ TILE_XSPACING
;
997 itemPosX
[i
] = row1PosXRunning
;
998 row1PosXRunning
+= ROW1_TILESIZE
+ TILE_XSPACING
;
1003 SwitchToGraphicsAndClear();
1006 case MENU_FUNCTION_CLEANUP
:
1007 MyFreePool(itemPosX
);
1010 case MENU_FUNCTION_PAINT_ALL
:
1011 PaintAll(Screen
, State
, itemPosX
, row0PosY
, row1PosY
, textPosY
);
1012 // For PaintArrows(), the starting Y position is moved to the midpoint
1013 // of the surrounding row; PaintIcon() adjusts this back up by half the
1014 // icon's height to properly center it.
1015 PaintArrows(State
, row0PosX
- TILE_XSPACING
, row0PosY
+ (ROW0_TILESIZE
/ 2), row0Loaders
);
1018 case MENU_FUNCTION_PAINT_SELECTION
:
1019 PaintSelection(Screen
, State
, itemPosX
, row0PosY
, row1PosY
, textPosY
);
1022 case MENU_FUNCTION_PAINT_TIMEOUT
:
1023 if (!(GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_LABEL
))
1024 DrawMainMenuText(ParamText
, (UGAWidth
- LAYOUT_TEXT_WIDTH
) >> 1, textPosY
+ TEXT_LINE_HEIGHT
);
1028 } // VOID MainMenuStyle()
1030 // Enable the user to edit boot loader options.
1031 // Returns TRUE if the user exited with edited options; FALSE if the user
1032 // pressed Esc to terminate the edit.
1033 static BOOLEAN
EditOptions(LOADER_ENTRY
*MenuEntry
) {
1035 CHAR16
*EditedOptions
;
1036 BOOLEAN retval
= FALSE
;
1038 if (GlobalConfig
.HideUIFlags
& HIDEUI_FLAG_EDITOR
) {
1042 refit_call4_wrapper(ST
->ConOut
->QueryMode
, ST
->ConOut
, ST
->ConOut
->Mode
->Mode
, &x_max
, &y_max
);
1044 if (!GlobalConfig
.TextOnly
)
1047 if (line_edit(MenuEntry
->LoadOptions
, &EditedOptions
, x_max
)) {
1048 MyFreePool(MenuEntry
->LoadOptions
);
1049 MenuEntry
->LoadOptions
= EditedOptions
;
1052 if (!GlobalConfig
.TextOnly
)
1055 } // VOID EditOptions()
1058 // user-callable dispatcher functions
1061 UINTN
RunMenu(IN REFIT_MENU_SCREEN
*Screen
, OUT REFIT_MENU_ENTRY
**ChosenEntry
)
1063 INTN DefaultEntry
= -1;
1064 MENU_STYLE_FUNC Style
= TextMenuStyle
;
1066 if (AllowGraphicsMode
)
1067 Style
= GraphicsMenuStyle
;
1069 return RunGenericMenu(Screen
, Style
, &DefaultEntry
, ChosenEntry
);
1072 UINTN
RunMainMenu(IN REFIT_MENU_SCREEN
*Screen
, IN CHAR16
* DefaultSelection
, OUT REFIT_MENU_ENTRY
**ChosenEntry
)
1074 MENU_STYLE_FUNC Style
= TextMenuStyle
;
1075 MENU_STYLE_FUNC MainStyle
= TextMenuStyle
;
1076 REFIT_MENU_ENTRY
*TempChosenEntry
;
1078 INTN DefaultEntryIndex
= -1;
1079 INTN DefaultSubmenuIndex
= -1;
1081 if (DefaultSelection
!= NULL
) {
1082 // Find a menu entry that includes *DefaultSelection as a substring
1083 DefaultEntryIndex
= FindMenuShortcutEntry(Screen
, DefaultSelection
);
1086 if (AllowGraphicsMode
) {
1087 Style
= GraphicsMenuStyle
;
1088 MainStyle
= MainMenuStyle
;
1092 MenuExit
= RunGenericMenu(Screen
, MainStyle
, &DefaultEntryIndex
, &TempChosenEntry
);
1093 Screen
->TimeoutSeconds
= 0;
1095 if (MenuExit
== MENU_EXIT_DETAILS
) {
1096 if (TempChosenEntry
->SubScreen
!= NULL
) {
1097 MenuExit
= RunGenericMenu(TempChosenEntry
->SubScreen
, Style
, &DefaultSubmenuIndex
, &TempChosenEntry
);
1098 if (MenuExit
== MENU_EXIT_ESCAPE
|| TempChosenEntry
->Tag
== TAG_RETURN
)
1100 if (MenuExit
== MENU_EXIT_DETAILS
) {
1101 if (!EditOptions((LOADER_ENTRY
*) TempChosenEntry
))
1104 } else { // no sub-screen; ignore keypress
1107 } // Enter sub-screen
1111 *ChosenEntry
= TempChosenEntry
;
1113 } /* UINTN RunMainMenu() */