]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/SetupBrowserDxe/Ui.h
Change the FormBrowser behavior of "Pressing ESC":
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Ui.h
1 /** @file
2 Private structure, MACRO and function definitions for User Interface related functionalities.
3
4 Copyright (c) 2004 - 2009, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef _UI_H_
16 #define _UI_H_
17
18 #include "Setup.h"
19
20 //
21 // Globals
22 //
23 #define REGULAR_NUMERIC 0
24 #define TIME_NUMERIC 1
25 #define DATE_NUMERIC 2
26
27 #define SUBTITLE_INDENT 2
28
29
30 //
31 // It take 23 characters including the NULL to print a 64 bits number with "[" and "]".
32 // pow(2, 64) = [18446744073709551616]
33 //
34 #define MAX_NUMERIC_INPUT_WIDTH 23
35
36 typedef enum {
37 UiNoOperation,
38 UiDefault,
39 UiSelect,
40 UiUp,
41 UiDown,
42 UiLeft,
43 UiRight,
44 UiReset,
45 UiSave,
46 UiPrevious,
47 UiPageUp,
48 UiPageDown,
49 UiMaxOperation
50 } UI_SCREEN_OPERATION;
51
52 typedef enum {
53 CfInitialization,
54 CfCheckSelection,
55 CfRepaint,
56 CfRefreshHighLight,
57 CfUpdateHelpString,
58 CfPrepareToReadKey,
59 CfReadKey,
60 CfScreenOperation,
61 CfUiSelect,
62 CfUiReset,
63 CfUiLeft,
64 CfUiRight,
65 CfUiUp,
66 CfUiPageUp,
67 CfUiPageDown,
68 CfUiDown,
69 CfUiSave,
70 CfUiDefault,
71 CfUiNoOperation,
72 CfExit,
73 CfMaxControlFlag
74 } UI_CONTROL_FLAG;
75
76 #define UI_ACTION_NONE 0
77 #define UI_ACTION_REFRESH_FORM 1
78 #define UI_ACTION_REFRESH_FORMSET 2
79 #define UI_ACTION_EXIT 3
80
81 typedef struct {
82 EFI_HII_HANDLE Handle;
83
84 //
85 // Target formset/form/Question information
86 //
87 EFI_GUID FormSetGuid;
88 UINT16 FormId;
89 UINT16 QuestionId;
90
91 UINTN TopRow;
92 UINTN BottomRow;
93 UINTN PromptCol;
94 UINTN OptionCol;
95 UINTN CurrentRow;
96
97 //
98 // Ation for Browser to taken:
99 // UI_ACTION_NONE - navigation inside a form
100 // UI_ACTION_REFRESH_FORM - re-evaluate expressions and repaint form
101 // UI_ACTION_REFRESH_FORMSET - re-parse formset IFR binary
102 //
103 UINTN Action;
104
105 //
106 // Current selected fomset/form/Question
107 //
108 FORM_BROWSER_FORMSET *FormSet;
109 FORM_BROWSER_FORM *Form;
110 FORM_BROWSER_STATEMENT *Statement;
111 } UI_MENU_SELECTION;
112
113 #define UI_MENU_OPTION_SIGNATURE SIGNATURE_32 ('u', 'i', 'm', 'm')
114 #define UI_MENU_LIST_SIGNATURE SIGNATURE_32 ('u', 'i', 'm', 'l')
115
116 typedef struct {
117 UINTN Signature;
118 LIST_ENTRY Link;
119
120 EFI_HII_HANDLE Handle;
121 FORM_BROWSER_STATEMENT *ThisTag;
122 UINT16 EntryNumber;
123
124 UINTN Row;
125 UINTN Col;
126 UINTN OptCol;
127 CHAR16 *Description;
128 UINTN Skip; // Number of lines
129
130 //
131 // Display item sequence for date/time
132 // Date: Month/Day/Year
133 // Sequence: 0 1 2
134 //
135 // Time: Hour : Minute : Second
136 // Sequence: 0 1 2
137 //
138 //
139 UINTN Sequence;
140
141 BOOLEAN GrayOut;
142 BOOLEAN ReadOnly;
143 } UI_MENU_OPTION;
144
145 #define MENU_OPTION_FROM_LINK(a) CR (a, UI_MENU_OPTION, Link, UI_MENU_OPTION_SIGNATURE)
146
147 typedef struct _UI_MENU_LIST UI_MENU_LIST;
148
149 struct _UI_MENU_LIST {
150 UINTN Signature;
151 LIST_ENTRY Link;
152
153 EFI_GUID FormSetGuid;
154 UINT16 FormId;
155 UINT16 QuestionId;
156
157 UI_MENU_LIST *Parent;
158 LIST_ENTRY ChildListHead;
159 };
160
161 #define UI_MENU_LIST_FROM_LINK(a) CR (a, UI_MENU_LIST, Link, UI_MENU_LIST_SIGNATURE)
162
163 typedef struct _MENU_REFRESH_ENTRY {
164 struct _MENU_REFRESH_ENTRY *Next;
165 UI_MENU_OPTION *MenuOption; // Describes the entry needing an update
166 UI_MENU_SELECTION *Selection;
167 UINTN CurrentColumn;
168 UINTN CurrentRow;
169 UINTN CurrentAttribute;
170 } MENU_REFRESH_ENTRY;
171
172 typedef struct {
173 UINT16 ScanCode;
174 UI_SCREEN_OPERATION ScreenOperation;
175 } SCAN_CODE_TO_SCREEN_OPERATION;
176
177 typedef struct {
178 UI_SCREEN_OPERATION ScreenOperation;
179 UI_CONTROL_FLAG ControlFlag;
180 } SCREEN_OPERATION_T0_CONTROL_FLAG;
181
182
183 extern MENU_REFRESH_ENTRY *gMenuRefreshHead;
184 extern UI_MENU_SELECTION *gCurrentSelection;
185 extern BOOLEAN mHiiPackageListUpdated;
186
187 //
188 // Global Functions
189 //
190 /**
191 Initialize Menu option list.
192
193 **/
194 VOID
195 UiInitMenu (
196 VOID
197 );
198
199 /**
200 Initialize Menu option list.
201
202 **/
203 VOID
204 UiInitMenuList (
205 VOID
206 );
207
208 /**
209 Free Menu option linked list.
210
211 **/
212 VOID
213 UiFreeMenu (
214 VOID
215 );
216
217 /**
218 Create a menu with specified formset GUID and form ID, and add it as a child
219 of the given parent menu.
220
221 @param Parent The parent of menu to be added.
222 @param FormSetGuid The Formset Guid of menu to be added.
223 @param FormId The Form ID of menu to be added.
224
225 @return A pointer to the newly added menu or NULL if memory is insufficient.
226
227 **/
228 UI_MENU_LIST *
229 UiAddMenuList (
230 IN OUT UI_MENU_LIST *Parent,
231 IN EFI_GUID *FormSetGuid,
232 IN UINT16 FormId
233 );
234
235 /**
236 Search Menu with given FormId in the parent menu and all its child menus.
237
238 @param Parent The parent of menu to search.
239 @param FormId The Form ID of menu to search.
240
241 @return A pointer to menu found or NULL if not found.
242
243 **/
244 UI_MENU_LIST *
245 UiFindChildMenuList (
246 IN UI_MENU_LIST *Parent,
247 IN UINT16 FormId
248 );
249
250 /**
251 Search Menu with given FormSetGuid and FormId in all cached menu list.
252
253 @param FormSetGuid The Formset GUID of the menu to search.
254 @param FormId The Form ID of menu to search.
255
256 @return A pointer to menu found or NULL if not found.
257
258 **/
259 UI_MENU_LIST *
260 UiFindMenuList (
261 IN EFI_GUID *FormSetGuid,
262 IN UINT16 FormId
263 );
264
265 /**
266 Free Menu option linked list.
267
268 **/
269 VOID
270 UiFreeRefreshList (
271 VOID
272 );
273
274 /**
275 Add one menu option by specified description and context.
276
277 @param String String description for this option.
278 @param Handle Hii handle for the package list.
279 @param Statement Statement of this Menu Option.
280 @param NumberOfLines Display lines for this Menu Option.
281 @param MenuItemCount The index for this Option in the Menu.
282
283 **/
284 VOID
285 UiAddMenuOption (
286 IN CHAR16 *String,
287 IN EFI_HII_HANDLE Handle,
288 IN FORM_BROWSER_STATEMENT *Statement,
289 IN UINT16 NumberOfLines,
290 IN UINT16 MenuItemCount
291 );
292
293 /**
294 Display menu and wait for user to select one menu option, then return it.
295 If AutoBoot is enabled, then if user doesn't select any option,
296 after period of time, it will automatically return the first menu option.
297
298 @param Selection Menu selection.
299
300 @return Return the pointer of the menu which selected,
301 @return otherwise return NULL.
302
303 **/
304 EFI_STATUS
305 UiDisplayMenu (
306 IN OUT UI_MENU_SELECTION *Selection
307 );
308
309 /**
310 Free up the resource allocated for all strings required
311 by Setup Browser.
312
313 **/
314 VOID
315 FreeBrowserStrings (
316 VOID
317 );
318
319 /**
320 The worker function that send the displays to the screen. On output,
321 the selection made by user is returned.
322
323 @param Selection On input, Selection tell setup browser the information
324 about the Selection, form and formset to be displayed.
325 On output, Selection return the screen item that is selected
326 by user.
327
328 @retval EFI_SUCCESS The page is displayed successfully.
329 @return Other value if the page failed to be diplayed.
330
331 **/
332 EFI_STATUS
333 SetupBrowser (
334 IN OUT UI_MENU_SELECTION *Selection
335 );
336
337 /**
338 VSPrint worker function that prints a Value as a decimal number in Buffer.
339
340 @param Buffer Location to place ascii decimal number string of Value.
341 @param Flags Flags to use in printing decimal string, see file header for
342 details.
343 @param Value Decimal value to convert to a string in Buffer.
344
345 @return Number of characters printed.
346
347 **/
348 VOID
349 ValueToString (
350 IN CHAR16 *Buffer,
351 IN BOOLEAN Flags,
352 IN INT64 Value
353 );
354
355 /**
356 Set Buffer to Value for Size bytes.
357
358 @param Buffer Memory to set.
359 @param Size Number of bytes to set
360 @param Value Value of the set operation.
361
362 **/
363 VOID
364 SetUnicodeMem (
365 IN VOID *Buffer,
366 IN UINTN Size,
367 IN CHAR16 Value
368 );
369
370 /**
371 Wait for a given event to fire, or for an optional timeout to expire.
372
373 @param Event The event to wait for
374 @param Timeout An optional timeout value in 100 ns units.
375 @param RefreshInterval Menu refresh interval (in seconds).
376
377 @retval EFI_SUCCESS Event fired before Timeout expired.
378 @retval EFI_TIME_OUT Timout expired before Event fired.
379
380 **/
381 EFI_STATUS
382 UiWaitForSingleEvent (
383 IN EFI_EVENT Event,
384 IN UINT64 Timeout, OPTIONAL
385 IN UINT8 RefreshInterval OPTIONAL
386 );
387
388 /**
389 Draw a pop up windows based on the dimension, number of lines and
390 strings specified.
391
392 @param ScreenWidth The width of the pop-up.
393 @param NumberOfLines The number of lines.
394 @param ... A series of text strings that displayed in the pop-up.
395
396 **/
397 VOID
398 CreateMultiStringPopUp (
399 IN UINTN ScreenWidth,
400 IN UINTN NumberOfLines,
401 ...
402 );
403
404 /**
405 Get string or password input from user.
406
407 @param MenuOption Pointer to the current input menu.
408 @param Prompt The prompt string shown on popup window.
409 @param StringPtr Destination for use input string.
410
411 @retval EFI_SUCCESS If string input is read successfully
412 @retval EFI_DEVICE_ERROR If operation fails
413
414 **/
415 EFI_STATUS
416 ReadString (
417 IN UI_MENU_OPTION *MenuOption,
418 IN CHAR16 *Prompt,
419 OUT CHAR16 *StringPtr
420 );
421
422 /**
423 Get selection for OneOf and OrderedList (Left/Right will be ignored).
424
425 @param Selection Pointer to current selection.
426 @param MenuOption Pointer to the current input menu.
427
428 @retval EFI_SUCCESS If Option input is processed successfully
429 @retval EFI_DEVICE_ERROR If operation fails
430
431 **/
432 EFI_STATUS
433 GetSelectionInputPopUp (
434 IN UI_MENU_SELECTION *Selection,
435 IN UI_MENU_OPTION *MenuOption
436 );
437
438 /**
439 This routine reads a numeric value from the user input.
440
441 @param Selection Pointer to current selection.
442 @param MenuOption Pointer to the current input menu.
443
444 @retval EFI_SUCCESS If numerical input is read successfully
445 @retval EFI_DEVICE_ERROR If operation fails
446
447 **/
448 EFI_STATUS
449 GetNumericInput (
450 IN UI_MENU_SELECTION *Selection,
451 IN UI_MENU_OPTION *MenuOption
452 );
453
454 /**
455 Update status bar on the bottom of menu.
456
457 @param MessageType The type of message to be shown.
458 @param Flags The flags in Question header.
459 @param State Set or clear.
460
461 **/
462 VOID
463 UpdateStatusBar (
464 IN UINTN MessageType,
465 IN UINT8 Flags,
466 IN BOOLEAN State
467 );
468
469 /**
470 Process Question Config.
471
472 @param Selection The UI menu selection.
473 @param Question The Question to be peocessed.
474
475 @retval EFI_SUCCESS Question Config process success.
476 @retval Other Question Config process fail.
477
478 **/
479 EFI_STATUS
480 ProcessQuestionConfig (
481 IN UI_MENU_SELECTION *Selection,
482 IN FORM_BROWSER_STATEMENT *Question
483 );
484
485 /**
486 Print Question Value according to it's storage width and display attributes.
487
488 @param Question The Question to be printed.
489 @param FormattedNumber Buffer for output string.
490 @param BufferSize The FormattedNumber buffer size in bytes.
491
492 @retval EFI_SUCCESS Print success.
493 @retval EFI_BUFFER_TOO_SMALL Buffer size is not enough for formatted number.
494
495 **/
496 EFI_STATUS
497 PrintFormattedNumber (
498 IN FORM_BROWSER_STATEMENT *Question,
499 IN OUT CHAR16 *FormattedNumber,
500 IN UINTN BufferSize
501 );
502
503 /**
504 Search an Option of a Question by its value.
505
506 @param Question The Question
507 @param OptionValue Value for Option to be searched.
508
509 @retval Pointer Pointer to the found Option.
510 @retval NULL Option not found.
511
512 **/
513 QUESTION_OPTION *
514 ValueToOption (
515 IN FORM_BROWSER_STATEMENT *Question,
516 IN EFI_HII_VALUE *OptionValue
517 );
518
519 /**
520 Process a Question's Option (whether selected or un-selected).
521
522 @param Selection Pointer to UI_MENU_SELECTION.
523 @param MenuOption The MenuOption for this Question.
524 @param Selected TRUE: if Question is selected.
525 @param OptionString Pointer of the Option String to be displayed.
526
527 @retval EFI_SUCCESS Question Option process success.
528 @retval Other Question Option process fail.
529
530 **/
531 EFI_STATUS
532 ProcessOptions (
533 IN UI_MENU_SELECTION *Selection,
534 IN UI_MENU_OPTION *MenuOption,
535 IN BOOLEAN Selected,
536 OUT CHAR16 **OptionString
537 );
538
539 /**
540 Process the help string: Split StringPtr to several lines of strings stored in
541 FormattedString and the glyph width of each line cannot exceed gHelpBlockWidth.
542
543 @param StringPtr The entire help string.
544 @param FormattedString The oupput formatted string.
545 @param RowCount TRUE: if Question is selected.
546
547 **/
548 VOID
549 ProcessHelpString (
550 IN CHAR16 *StringPtr,
551 OUT CHAR16 **FormattedString,
552 IN UINTN RowCount
553 );
554
555 /**
556 Update key's help imformation.
557
558 @param MenuOption The Menu option
559 @param Selected Whether or not a tag be selected
560
561 **/
562 VOID
563 UpdateKeyHelp (
564 IN UI_MENU_OPTION *MenuOption,
565 IN BOOLEAN Selected
566 );
567
568 /**
569 Clear retangle with specified text attribute.
570
571 @param LeftColumn Left column of retangle.
572 @param RightColumn Right column of retangle.
573 @param TopRow Start row of retangle.
574 @param BottomRow End row of retangle.
575 @param TextAttribute The character foreground and background.
576
577 **/
578 VOID
579 ClearLines (
580 UINTN LeftColumn,
581 UINTN RightColumn,
582 UINTN TopRow,
583 UINTN BottomRow,
584 UINTN TextAttribute
585 );
586
587 /**
588 Count the storage space of a Unicode string.
589
590 This function handles the Unicode string with NARROW_CHAR
591 and WIDE_CHAR control characters. NARROW_HCAR and WIDE_CHAR
592 does not count in the resultant output. If a WIDE_CHAR is
593 hit, then 2 Unicode character will consume an output storage
594 space with size of CHAR16 till a NARROW_CHAR is hit.
595
596 @param String The input string to be counted.
597
598 @return Storage space for the input string.
599
600 **/
601 UINTN
602 GetStringWidth (
603 CHAR16 *String
604 );
605
606 /**
607 Will copy LineWidth amount of a string in the OutputString buffer and return the
608 number of CHAR16 characters that were copied into the OutputString buffer.
609
610 @param InputString String description for this option.
611 @param LineWidth Width of the desired string to extract in CHAR16
612 characters
613 @param Index Where in InputString to start the copy process
614 @param OutputString Buffer to copy the string into
615
616 @return Returns the number of CHAR16 characters that were copied into the OutputString buffer.
617
618 **/
619 UINT16
620 GetLineByWidth (
621 IN CHAR16 *InputString,
622 IN UINT16 LineWidth,
623 IN OUT UINTN *Index,
624 OUT CHAR16 **OutputString
625 );
626
627 /**
628 Get the supported width for a particular op-code
629
630 @param Statement The FORM_BROWSER_STATEMENT structure passed in.
631 @param Handle The handle in the HII database being used
632
633 @return Returns the number of CHAR16 characters that is support.
634
635 **/
636 UINT16
637 GetWidth (
638 IN FORM_BROWSER_STATEMENT *Statement,
639 IN EFI_HII_HANDLE Handle
640 );
641
642 /**
643 Concatenate a narrow string to another string.
644
645 @param Destination The destination string.
646 @param Source The source string. The string to be concatenated.
647 to the end of Destination.
648
649 **/
650 VOID
651 NewStrCat (
652 CHAR16 *Destination,
653 CHAR16 *Source
654 );
655
656 /**
657 Wait for a key to be pressed by user.
658
659 @param Key The key which is pressed by user.
660
661 @retval EFI_SUCCESS The function always completed successfully.
662
663 **/
664 EFI_STATUS
665 WaitForKeyStroke (
666 OUT EFI_INPUT_KEY *Key
667 );
668
669 /**
670 Reset stack pointer to begin of the stack.
671
672 **/
673 VOID
674 ResetScopeStack (
675 VOID
676 );
677
678 /**
679 Push an Operand onto the Stack
680
681 @param Operand Operand to push.
682
683 @retval EFI_SUCCESS The value was pushed onto the stack.
684 @retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the
685 stack.
686
687 **/
688 EFI_STATUS
689 PushScope (
690 IN UINT8 Operand
691 );
692
693 /**
694 Pop an Operand from the Stack
695
696 @param Operand Operand to pop.
697
698 @retval EFI_SUCCESS The value was pushed onto the stack.
699 @retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the
700 stack.
701
702 **/
703 EFI_STATUS
704 PopScope (
705 OUT UINT8 *Operand
706 );
707
708 /**
709 Get Form given its FormId.
710
711 @param FormSet The formset which contains this form.
712 @param FormId Id of this form.
713
714 @retval Pointer The form.
715 @retval NULL Specified Form is not found in the formset.
716
717 **/
718 FORM_BROWSER_FORM *
719 IdToForm (
720 IN FORM_BROWSER_FORMSET *FormSet,
721 IN UINT16 FormId
722 );
723
724 /**
725 Search a Question in Formset scope using its QuestionId.
726
727 @param FormSet The formset which contains this form.
728 @param Form The form which contains this Question.
729 @param QuestionId Id of this Question.
730
731 @retval Pointer The Question.
732 @retval NULL Specified Question not found in the form.
733
734 **/
735 FORM_BROWSER_STATEMENT *
736 IdToQuestion (
737 IN FORM_BROWSER_FORMSET *FormSet,
738 IN FORM_BROWSER_FORM *Form,
739 IN UINT16 QuestionId
740 );
741
742 /**
743 Zero extend integer/boolean/date/time to UINT64 for comparing.
744
745 @param Value HII Value to be converted.
746
747 **/
748 VOID
749 ExtendValueToU64 (
750 IN EFI_HII_VALUE *Value
751 );
752
753 /**
754 Compare two Hii value.
755
756 @param Value1 Expression value to compare on left-hand.
757 @param Value2 Expression value to compare on right-hand.
758 @param HiiHandle Only required for string compare.
759
760 @retval EFI_INVALID_PARAMETER Could not perform comparation on two values.
761 @retval 0 Two operators equeal.
762 @return Positive value if Value1 is greater than Value2.
763 @retval Negative value if Value1 is less than Value2.
764
765 **/
766 INTN
767 CompareHiiValue (
768 IN EFI_HII_VALUE *Value1,
769 IN EFI_HII_VALUE *Value2,
770 IN EFI_HII_HANDLE HiiHandle OPTIONAL
771 );
772
773 /**
774 Evaluate the result of a HII expression
775
776 If Expression is NULL, then ASSERT.
777
778 @param FormSet FormSet associated with this expression.
779 @param Form Form associated with this expression.
780 @param Expression Expression to be evaluated.
781
782 @retval EFI_SUCCESS The expression evaluated successfuly
783 @retval EFI_NOT_FOUND The Question which referenced by a QuestionId
784 could not be found.
785 @retval EFI_OUT_OF_RESOURCES There is not enough system memory to grow the
786 stack.
787 @retval EFI_ACCESS_DENIED The pop operation underflowed the stack
788 @retval EFI_INVALID_PARAMETER Syntax error with the Expression
789
790 **/
791 EFI_STATUS
792 EvaluateExpression (
793 IN FORM_BROWSER_FORMSET *FormSet,
794 IN FORM_BROWSER_FORM *Form,
795 IN OUT FORM_EXPRESSION *Expression
796 );
797
798 #endif // _UI_H