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