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