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