]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.c
Rollback the change 15021.
[mirror_edk2.git] / MdeModulePkg / Library / CustomizedDisplayLib / CustomizedDisplayLib.c
1 /** @file
2
3 This library class defines a set of interfaces to customize Display module
4
5 Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials are licensed and made available under
7 the terms and conditions of the BSD License that accompanies this distribution.
8 The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15 #include "CustomizedDisplayLibInternal.h"
16
17 EFI_GUID gCustomizedDisplayLibGuid = { 0x99fdc8fd, 0x849b, 0x4eba, { 0xad, 0x13, 0xfb, 0x96, 0x99, 0xc9, 0xa, 0x4d } };
18
19 EFI_HII_HANDLE mCDLStringPackHandle;
20 UINT16 gClassOfVfr; // Formset class information
21 BOOLEAN gLibIsFirstForm = TRUE;
22 BANNER_DATA *gBannerData;
23
24 UINTN gFooterHeight;
25
26 /**
27 +------------------------------------------------------------------------------+
28 | Setup Page |
29 +------------------------------------------------------------------------------+
30
31 Statement
32 Statement
33 Statement
34
35
36
37
38
39 +------------------------------------------------------------------------------+
40 | F9=Reset to Defaults F10=Save |
41 | ^"=Move Highlight <Spacebar> Toggles Checkbox Esc=Exit |
42 +------------------------------------------------------------------------------+
43 StatusBar
44 **/
45
46 /**
47 This funtion defines Page Frame and Backgroud.
48
49 Based on the above layout, it will be responsible for HeaderHeight, FooterHeight,
50 StatusBarHeight and Backgroud. And, it will reserve Screen for Statement.
51
52 @param[in] FormData Form Data to be shown in Page.
53 @param[out] ScreenForStatement Screen to be used for Statement. (Prompt, Value and Help)
54
55 @return Status
56 **/
57 EFI_STATUS
58 EFIAPI
59 DisplayPageFrame (
60 IN FORM_DISPLAY_ENGINE_FORM *FormData,
61 OUT EFI_SCREEN_DESCRIPTOR *ScreenForStatement
62 )
63 {
64 EFI_STATUS Status;
65
66 ASSERT (FormData != NULL && ScreenForStatement != NULL);
67 if (FormData == NULL || ScreenForStatement == NULL) {
68 return EFI_INVALID_PARAMETER;
69 }
70
71 Status = ScreenDiemensionInfoValidate (FormData);
72 if (EFI_ERROR (Status)) {
73 return Status;
74 }
75
76 gClassOfVfr = FORMSET_CLASS_PLATFORM_SETUP;
77
78 ProcessExternedOpcode(FormData);
79
80 //
81 // Calculate the ScreenForStatement.
82 //
83 ScreenForStatement->BottomRow = gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight;
84 if (gClassOfVfr == FORMSET_CLASS_FRONT_PAGE) {
85 ScreenForStatement->TopRow = gScreenDimensions.TopRow + FRONT_PAGE_HEADER_HEIGHT;
86 } else {
87 ScreenForStatement->TopRow = gScreenDimensions.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT;
88 }
89 ScreenForStatement->LeftColumn = gScreenDimensions.LeftColumn;
90 ScreenForStatement->RightColumn = gScreenDimensions.RightColumn;
91
92 if ((gLibIsFirstForm) || ((FormData->Attribute & HII_DISPLAY_MODAL) != 0)) {
93 //
94 // Ensure we are in Text mode
95 //
96 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
97 ClearLines (0, gScreenDimensions.RightColumn, 0, gScreenDimensions.BottomRow, KEYHELP_BACKGROUND);
98 gLibIsFirstForm = FALSE;
99 }
100
101 //
102 // Don't print frame for modal form.
103 //
104 if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
105 return EFI_SUCCESS;
106 }
107
108 if (gClassOfVfr == FORMSET_CLASS_FRONT_PAGE) {
109 PrintBannerInfo (FormData);
110 }
111
112 PrintFramework (FormData);
113
114 UpdateStatusBar(NV_UPDATE_REQUIRED, FormData->SettingChangedFlag);
115
116 return EFI_SUCCESS;
117 }
118
119 /**
120 This function updates customized key panel's help information.
121 The library will prepare those Strings for the basic key, ESC, Enter, Up/Down/Left/Right, +/-.
122 and arrange them in Footer panel.
123
124 @param[in] FormData Form Data to be shown in Page. FormData has the highlighted statement.
125 @param[in] Statement The statement current selected.
126 @param[in] Selected Whether or not a tag be selected. TRUE means Enter has hit this question.
127 **/
128 VOID
129 EFIAPI
130 RefreshKeyHelp (
131 IN FORM_DISPLAY_ENGINE_FORM *FormData,
132 IN FORM_DISPLAY_ENGINE_STATEMENT *Statement,
133 IN BOOLEAN Selected
134 )
135 {
136 UINTN SecCol;
137 UINTN ThdCol;
138 UINTN LeftColumnOfHelp;
139 UINTN RightColumnOfHelp;
140 UINTN TopRowOfHelp;
141 UINTN BottomRowOfHelp;
142 UINTN StartColumnOfHelp;
143 EFI_IFR_NUMERIC *NumericOp;
144 EFI_IFR_DATE *DateOp;
145 EFI_IFR_TIME *TimeOp;
146 BOOLEAN HexDisplay;
147 UINTN ColumnWidth1;
148 UINTN ColumnWidth2;
149 UINTN ColumnWidth3;
150 CHAR16 *ColumnStr1;
151 CHAR16 *ColumnStr2;
152 CHAR16 *ColumnStr3;
153
154 ASSERT (FormData != NULL);
155 if (FormData == NULL) {
156 return;
157 }
158
159 gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_TEXT | KEYHELP_BACKGROUND);
160
161 if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
162 return;
163 }
164
165 SecCol = gScreenDimensions.LeftColumn + (gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn) / 3;
166 ThdCol = gScreenDimensions.LeftColumn + (gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn) / 3 * 2;
167
168 StartColumnOfHelp = gScreenDimensions.LeftColumn + 2;
169 LeftColumnOfHelp = gScreenDimensions.LeftColumn + 1;
170 RightColumnOfHelp = gScreenDimensions.RightColumn - 1;
171 TopRowOfHelp = gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight + 1;
172 BottomRowOfHelp = gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - 2;
173
174 ColumnWidth1 = SecCol - StartColumnOfHelp;
175 ColumnWidth2 = ThdCol - SecCol;
176 ColumnWidth3 = RightColumnOfHelp - ThdCol;
177 ColumnStr1 = gLibEmptyString;
178 ColumnStr2 = gLibEmptyString;
179 ColumnStr3 = gLibEmptyString;
180
181 if (Statement == NULL) {
182 //
183 // Print Key for Form without showable statement.
184 //
185 PrintHotKeyHelpString (FormData, TRUE);
186 PrintStringAtWithWidth (StartColumnOfHelp, BottomRowOfHelp, gLibEmptyString, ColumnWidth1);
187 PrintStringAtWithWidth (SecCol, BottomRowOfHelp, gLibEmptyString, ColumnWidth2);
188 PrintStringAtWithWidth (StartColumnOfHelp, TopRowOfHelp, gLibEmptyString, ColumnWidth1);
189 PrintStringAtWithWidth (ThdCol, BottomRowOfHelp, gEscapeString, ColumnWidth3);
190
191 return;
192 }
193
194 HexDisplay = FALSE;
195 NumericOp = NULL;
196 DateOp = NULL;
197 TimeOp = NULL;
198 if (Statement->OpCode->OpCode == EFI_IFR_NUMERIC_OP) {
199 NumericOp = (EFI_IFR_NUMERIC *) Statement->OpCode;
200 HexDisplay = (NumericOp->Flags & EFI_IFR_DISPLAY_UINT_HEX) == EFI_IFR_DISPLAY_UINT_HEX;
201 } else if (Statement->OpCode->OpCode == EFI_IFR_DATE_OP) {
202 DateOp = (EFI_IFR_DATE *) Statement->OpCode;
203 HexDisplay = (DateOp->Flags & EFI_IFR_DISPLAY_UINT_HEX) == EFI_IFR_DISPLAY_UINT_HEX;
204 } else if (Statement->OpCode->OpCode == EFI_IFR_TIME_OP) {
205 TimeOp = (EFI_IFR_TIME *) Statement->OpCode;
206 HexDisplay = (TimeOp->Flags & EFI_IFR_DISPLAY_UINT_HEX) == EFI_IFR_DISPLAY_UINT_HEX;
207 }
208 switch (Statement->OpCode->OpCode) {
209 case EFI_IFR_ORDERED_LIST_OP:
210 case EFI_IFR_ONE_OF_OP:
211 case EFI_IFR_NUMERIC_OP:
212 case EFI_IFR_TIME_OP:
213 case EFI_IFR_DATE_OP:
214 if (!Selected) {
215 PrintHotKeyHelpString (FormData, TRUE);
216
217 if (gClassOfVfr == FORMSET_CLASS_PLATFORM_SETUP) {
218 ColumnStr3 = gEscapeString;
219 }
220 PrintStringAtWithWidth (ThdCol, BottomRowOfHelp, ColumnStr3, ColumnWidth3);
221
222 if ((Statement->OpCode->OpCode == EFI_IFR_DATE_OP) ||
223 (Statement->OpCode->OpCode == EFI_IFR_TIME_OP)) {
224 PrintAt (
225 ColumnWidth1,
226 StartColumnOfHelp,
227 BottomRowOfHelp,
228 L"%c%c%c%c%s",
229 ARROW_UP,
230 ARROW_DOWN,
231 ARROW_RIGHT,
232 ARROW_LEFT,
233 gMoveHighlight
234 );
235 PrintStringAtWithWidth (SecCol, BottomRowOfHelp, gEnterString, ColumnWidth2);
236 PrintStringAtWithWidth (StartColumnOfHelp, TopRowOfHelp, gAdjustNumber, ColumnWidth1);
237 } else {
238 PrintAt (ColumnWidth1, StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
239 if (Statement->OpCode->OpCode == EFI_IFR_NUMERIC_OP && NumericOp != NULL && LibGetFieldFromNum(Statement->OpCode) != 0) {
240 ColumnStr1 = gAdjustNumber;
241 }
242 PrintStringAtWithWidth (StartColumnOfHelp, TopRowOfHelp, ColumnStr1, ColumnWidth1);
243 PrintStringAtWithWidth (SecCol, BottomRowOfHelp, gEnterString, ColumnWidth2);
244 }
245 } else {
246 PrintHotKeyHelpString (FormData, FALSE);
247 PrintStringAtWithWidth (SecCol, BottomRowOfHelp, gEnterCommitString, ColumnWidth2);
248
249 //
250 // If it is a selected numeric with manual input, display different message
251 //
252 if ((Statement->OpCode->OpCode == EFI_IFR_NUMERIC_OP) ||
253 (Statement->OpCode->OpCode == EFI_IFR_DATE_OP) ||
254 (Statement->OpCode->OpCode == EFI_IFR_TIME_OP)) {
255 ColumnStr2 = HexDisplay ? gHexNumericInput : gDecNumericInput;
256 PrintStringAtWithWidth (StartColumnOfHelp, BottomRowOfHelp, gLibEmptyString, ColumnWidth1);
257 } else {
258 PrintAt (ColumnWidth1, StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
259 }
260
261 if (Statement->OpCode->OpCode == EFI_IFR_ORDERED_LIST_OP) {
262 ColumnStr1 = gPlusString;
263 ColumnStr3 = gMinusString;
264 }
265 PrintStringAtWithWidth (StartColumnOfHelp, TopRowOfHelp, ColumnStr1, ColumnWidth1);
266 PrintStringAtWithWidth (ThdCol, TopRowOfHelp, ColumnStr3, ColumnWidth3);
267 PrintStringAtWithWidth (SecCol, TopRowOfHelp, ColumnStr2, ColumnWidth2);
268
269 PrintStringAtWithWidth (ThdCol, BottomRowOfHelp, gEnterEscapeString, ColumnWidth3);
270 }
271 break;
272
273 case EFI_IFR_CHECKBOX_OP:
274 PrintHotKeyHelpString (FormData, TRUE);
275
276 if (gClassOfVfr == FORMSET_CLASS_PLATFORM_SETUP) {
277 ColumnStr3 = gEscapeString;
278 }
279 PrintStringAtWithWidth (ThdCol, BottomRowOfHelp, ColumnStr3, ColumnWidth3);
280
281 PrintAt (ColumnWidth1, StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
282 PrintStringAtWithWidth (SecCol, BottomRowOfHelp, gToggleCheckBox, ColumnWidth2);
283 PrintStringAtWithWidth (StartColumnOfHelp, TopRowOfHelp, gLibEmptyString, ColumnWidth1);
284 break;
285
286 case EFI_IFR_REF_OP:
287 case EFI_IFR_PASSWORD_OP:
288 case EFI_IFR_STRING_OP:
289 case EFI_IFR_TEXT_OP:
290 case EFI_IFR_ACTION_OP:
291 case EFI_IFR_RESET_BUTTON_OP:
292 case EFI_IFR_SUBTITLE_OP:
293 if (!Selected) {
294 PrintHotKeyHelpString (FormData, TRUE);
295
296 if (gClassOfVfr == FORMSET_CLASS_PLATFORM_SETUP) {
297 ColumnStr3 = gEscapeString;
298 }
299 PrintStringAtWithWidth (ThdCol, BottomRowOfHelp, ColumnStr3, ColumnWidth3);
300
301 PrintAt (ColumnWidth1, StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
302 if (Statement->OpCode->OpCode != EFI_IFR_TEXT_OP && Statement->OpCode->OpCode != EFI_IFR_SUBTITLE_OP) {
303 ColumnStr2 = gEnterString;
304 }
305 PrintStringAtWithWidth (SecCol, BottomRowOfHelp, ColumnStr2, ColumnWidth2);
306 PrintStringAtWithWidth (StartColumnOfHelp, TopRowOfHelp, ColumnStr1, ColumnWidth1);
307 } else {
308 PrintHotKeyHelpString (FormData, FALSE);
309 if (Statement->OpCode->OpCode != EFI_IFR_REF_OP) {
310 ColumnStr2 = gEnterCommitString;
311 ColumnStr3 = gEnterEscapeString;
312 }
313 PrintStringAtWithWidth (StartColumnOfHelp, TopRowOfHelp, ColumnStr1, ColumnWidth1);
314 PrintStringAtWithWidth (StartColumnOfHelp, BottomRowOfHelp, ColumnStr1, ColumnWidth1);
315 PrintStringAtWithWidth (SecCol, BottomRowOfHelp, ColumnStr2, ColumnWidth2);
316 PrintStringAtWithWidth (ThdCol, BottomRowOfHelp, ColumnStr3, ColumnWidth3);
317 }
318 break;
319
320 default:
321 break;
322 }
323 }
324
325 /**
326 Update status bar.
327
328 This function updates the status bar on the bottom of menu screen. It just shows StatusBar.
329 Original logic in this function should be splitted out.
330
331 @param[in] MessageType The type of message to be shown. InputError or Configuration Changed.
332 @param[in] State Show or Clear Message.
333 **/
334 VOID
335 EFIAPI
336 UpdateStatusBar (
337 IN UINTN MessageType,
338 IN BOOLEAN State
339 )
340 {
341 UINTN Index;
342 CHAR16 OptionWidth;
343
344 OptionWidth = (CHAR16) ((gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn) / 3);
345
346 switch (MessageType) {
347 case INPUT_ERROR:
348 if (State) {
349 gST->ConOut->SetAttribute (gST->ConOut, ERROR_TEXT);
350 PrintStringAt (
351 gScreenDimensions.LeftColumn + OptionWidth,
352 gScreenDimensions.BottomRow - 1,
353 gInputErrorMessage
354 );
355 } else {
356 gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_BACKGROUND);
357 for (Index = 0; Index < (LibGetStringWidth (gInputErrorMessage) - 2) / 2; Index++) {
358 PrintStringAt (gScreenDimensions.LeftColumn + OptionWidth + Index, gScreenDimensions.BottomRow - 1, L" ");
359 }
360 }
361 break;
362
363 case NV_UPDATE_REQUIRED:
364 //
365 // Global setting support. Show configuration change on every form.
366 //
367 if (State) {
368 gST->ConOut->SetAttribute (gST->ConOut, INFO_TEXT);
369 PrintStringAt (
370 gScreenDimensions.LeftColumn + OptionWidth * 2,
371 gScreenDimensions.BottomRow - 1,
372 gNvUpdateMessage
373 );
374 } else {
375 gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_BACKGROUND);
376 for (Index = 0; Index < (LibGetStringWidth (gNvUpdateMessage) - 2) / 2; Index++) {
377 PrintStringAt (
378 (gScreenDimensions.LeftColumn + OptionWidth * 2 + Index),
379 gScreenDimensions.BottomRow - 1,
380 L" "
381 );
382 }
383 }
384 break;
385
386 default:
387 break;
388 }
389 }
390
391 /**
392 Create popup window. It will replace CreateDialog().
393
394 This function draws OEM/Vendor specific pop up windows.
395
396 @param[out] Key User Input Key
397 @param ... String to be shown in Popup. The variable argument list is terminated by a NULL.
398
399 **/
400 VOID
401 EFIAPI
402 CreateDialog (
403 OUT EFI_INPUT_KEY *Key, OPTIONAL
404 ...
405 )
406 {
407 VA_LIST Marker;
408 EFI_INPUT_KEY KeyValue;
409 EFI_STATUS Status;
410 UINTN LargestString;
411 UINTN LineNum;
412 UINTN Index;
413 UINTN Count;
414 CHAR16 Character;
415 UINTN Start;
416 UINTN End;
417 UINTN Top;
418 UINTN Bottom;
419 CHAR16 *String;
420 UINTN DimensionsWidth;
421 UINTN DimensionsHeight;
422 UINTN CurrentAttribute;
423 BOOLEAN CursorVisible;
424
425 //
426 // If screen dimension info is not ready, get it from console.
427 //
428 if (gScreenDimensions.RightColumn == 0 || gScreenDimensions.BottomRow == 0) {
429 ZeroMem (&gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
430 gST->ConOut->QueryMode (
431 gST->ConOut,
432 gST->ConOut->Mode->Mode,
433 &gScreenDimensions.RightColumn,
434 &gScreenDimensions.BottomRow
435 );
436 }
437
438 DimensionsWidth = gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn;
439 DimensionsHeight = gScreenDimensions.BottomRow - gScreenDimensions.TopRow;
440
441 LargestString = 0;
442 LineNum = 0;
443 VA_START (Marker, Key);
444 while ((String = VA_ARG (Marker, CHAR16 *)) != NULL) {
445 LineNum ++;
446
447 if ((LibGetStringWidth (String) / 2) > LargestString) {
448 LargestString = (LibGetStringWidth (String) / 2);
449 }
450 }
451 VA_END (Marker);
452
453 if ((LargestString + 2) > DimensionsWidth) {
454 LargestString = DimensionsWidth - 2;
455 }
456
457 CurrentAttribute = gST->ConOut->Mode->Attribute;
458 CursorVisible = gST->ConOut->Mode->CursorVisible;
459 gST->ConOut->EnableCursor (gST->ConOut, FALSE);
460 gST->ConOut->SetAttribute (gST->ConOut, GetPopupColor ());
461
462 //
463 // Subtract the PopUp width from total Columns, allow for one space extra on
464 // each end plus a border.
465 //
466 Start = (DimensionsWidth - LargestString - 2) / 2 + gScreenDimensions.LeftColumn + 1;
467 End = Start + LargestString + 1;
468
469 Top = ((DimensionsHeight - LineNum - 2) / 2) + gScreenDimensions.TopRow - 1;
470 Bottom = Top + LineNum + 2;
471
472 Character = BOXDRAW_DOWN_RIGHT;
473 PrintCharAt (Start, Top, Character);
474 Character = BOXDRAW_HORIZONTAL;
475 for (Index = Start; Index + 2 < End; Index++) {
476 PrintCharAt ((UINTN)-1, (UINTN)-1, Character);
477 }
478
479 Character = BOXDRAW_DOWN_LEFT;
480 PrintCharAt ((UINTN)-1, (UINTN)-1, Character);
481 Character = BOXDRAW_VERTICAL;
482
483 Count = 0;
484 VA_START (Marker, Key);
485 for (Index = Top; Index + 2 < Bottom; Index++, Count++) {
486 String = VA_ARG (Marker, CHAR16*);
487
488 if (String[0] == CHAR_NULL) {
489 //
490 // Passing in a NULL results in a blank space
491 //
492 ClearLines (Start, End, Index + 1, Index + 1, GetPopupColor ());
493 } else if (String[0] == L' ') {
494 //
495 // Passing in a space results in the assumption that this is where typing will occur
496 //
497 ClearLines (Start + 1, End - 1, Index + 1, Index + 1, POPUP_INVERSE_TEXT | POPUP_INVERSE_BACKGROUND);
498 PrintStringAt (
499 ((DimensionsWidth - LibGetStringWidth (String) / 2) / 2) + gScreenDimensions.LeftColumn + 1,
500 Index + 1,
501 String + 1
502 );
503 } else {
504 //
505 // This will clear the background of the line - we never know who might have been
506 // here before us. This differs from the next clear in that it used the non-reverse
507 // video for normal printing.
508 //
509 ClearLines (Start, End, Index + 1, Index + 1, GetPopupColor ());
510 PrintStringAt (
511 ((DimensionsWidth - LibGetStringWidth (String) / 2) / 2) + gScreenDimensions.LeftColumn + 1,
512 Index + 1,
513 String
514 );
515 }
516
517 gST->ConOut->SetAttribute (gST->ConOut, GetPopupColor ());
518 PrintCharAt (Start, Index + 1, Character);
519 PrintCharAt (End - 1, Index + 1, Character);
520 }
521 VA_END (Marker);
522
523 Character = BOXDRAW_UP_RIGHT;
524 PrintCharAt (Start, Bottom - 1, Character);
525 Character = BOXDRAW_HORIZONTAL;
526 for (Index = Start; Index + 2 < End; Index++) {
527 PrintCharAt ((UINTN)-1, (UINTN) -1, Character);
528 }
529
530 Character = BOXDRAW_UP_LEFT;
531 PrintCharAt ((UINTN)-1, (UINTN) -1, Character);
532
533 if (Key != NULL) {
534 Status = WaitForKeyStroke (&KeyValue);
535 ASSERT_EFI_ERROR (Status);
536 CopyMem (Key, &KeyValue, sizeof (EFI_INPUT_KEY));
537 }
538
539 gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);
540 gST->ConOut->EnableCursor (gST->ConOut, CursorVisible);
541 }
542
543 /**
544 Confirm how to handle the changed data.
545
546 @return Action BROWSER_ACTION_SUBMIT, BROWSER_ACTION_DISCARD or other values.
547 **/
548 UINTN
549 EFIAPI
550 ConfirmDataChange (
551 VOID
552 )
553 {
554 CHAR16 YesResponse;
555 CHAR16 NoResponse;
556 EFI_INPUT_KEY Key;
557
558 gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
559
560 YesResponse = gYesResponse[0];
561 NoResponse = gNoResponse[0];
562
563 //
564 // If NV flag is up, prompt user
565 //
566 do {
567 CreateDialog (&Key, gLibEmptyString, gSaveChanges, gAreYouSure, gLibEmptyString, NULL);
568 } while
569 (
570 (Key.ScanCode != SCAN_ESC) &&
571 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (NoResponse | UPPER_LOWER_CASE_OFFSET)) &&
572 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (YesResponse | UPPER_LOWER_CASE_OFFSET))
573 );
574
575 if (Key.ScanCode == SCAN_ESC) {
576 return BROWSER_ACTION_NONE;
577 } else if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (YesResponse | UPPER_LOWER_CASE_OFFSET)) {
578 return BROWSER_ACTION_SUBMIT;
579 } else {
580 return BROWSER_ACTION_DISCARD;
581 }
582 }
583
584 /**
585 OEM specifies whether Setup exits Page by ESC key.
586
587 This function customized the behavior that whether Setup exits Page so that
588 system able to boot when configuration is not changed.
589
590 @retval TRUE Exits FrontPage
591 @retval FALSE Don't exit FrontPage.
592 **/
593 BOOLEAN
594 EFIAPI
595 FormExitPolicy (
596 VOID
597 )
598 {
599 return gClassOfVfr == FORMSET_CLASS_FRONT_PAGE ? FALSE : TRUE;
600 }
601
602 /**
603 Set Timeout value for a ceratain Form to get user response.
604
605 This function allows to set timeout value on a ceratain form if necessary.
606 If timeout is not zero, the form will exit if user has no response in timeout.
607
608 @param[in] FormData Form Data to be shown in Page
609
610 @return 0 No timeout for this form.
611 @return > 0 Timeout value in 100 ns units.
612 **/
613 UINT64
614 EFIAPI
615 FormExitTimeout (
616 IN FORM_DISPLAY_ENGINE_FORM *FormData
617 )
618 {
619 return 0;
620 }
621 //
622 // Print Functions
623 //
624 /**
625 Prints a unicode string to the default console, at
626 the supplied cursor position, using L"%s" format.
627
628 @param Column The cursor position to print the string at. When it is -1, use current Position.
629 @param Row The cursor position to print the string at. When it is -1, use current Position.
630 @param String String pointer.
631
632 @return Length of string printed to the console
633
634 **/
635 UINTN
636 EFIAPI
637 PrintStringAt (
638 IN UINTN Column,
639 IN UINTN Row,
640 IN CHAR16 *String
641 )
642 {
643 return PrintAt (0, Column, Row, L"%s", String);
644 }
645
646 /**
647 Prints a unicode string to the default console, at
648 the supplied cursor position, using L"%s" format.
649
650 @param Column The cursor position to print the string at. When it is -1, use current Position.
651 @param Row The cursor position to print the string at. When it is -1, use current Position.
652 @param String String pointer.
653 @param Width Width for String.
654
655 @return Length of string printed to the console
656
657 **/
658 UINTN
659 EFIAPI
660 PrintStringAtWithWidth (
661 IN UINTN Column,
662 IN UINTN Row,
663 IN CHAR16 *String,
664 IN UINTN Width
665 )
666 {
667 return PrintAt (Width, Column, Row, L"%s", String);
668 }
669
670 /**
671 Prints a chracter to the default console, at
672 the supplied cursor position, using L"%c" format.
673
674 @param Column The cursor position to print the string at. When it is -1, use current Position.
675 @param Row The cursor position to print the string at. When it is -1, use current Position.
676 @param Character Character to print.
677
678 @return Length of string printed to the console.
679
680 **/
681 UINTN
682 EFIAPI
683 PrintCharAt (
684 IN UINTN Column,
685 IN UINTN Row,
686 CHAR16 Character
687 )
688 {
689 return PrintAt (0, Column, Row, L"%c", Character);
690 }
691
692 /**
693 Clear retangle with specified text attribute.
694
695 @param LeftColumn Left column of retangle.
696 @param RightColumn Right column of retangle.
697 @param TopRow Start row of retangle.
698 @param BottomRow End row of retangle.
699 @param TextAttribute The character foreground and background.
700
701 **/
702 VOID
703 EFIAPI
704 ClearLines (
705 IN UINTN LeftColumn,
706 IN UINTN RightColumn,
707 IN UINTN TopRow,
708 IN UINTN BottomRow,
709 IN UINTN TextAttribute
710 )
711 {
712 CHAR16 *Buffer;
713 UINTN Row;
714
715 //
716 // For now, allocate an arbitrarily long buffer
717 //
718 Buffer = AllocateZeroPool (0x10000);
719 ASSERT (Buffer != NULL);
720
721 //
722 // Set foreground and background as defined
723 //
724 gST->ConOut->SetAttribute (gST->ConOut, TextAttribute);
725
726 //
727 // Much faster to buffer the long string instead of print it a character at a time
728 //
729 LibSetUnicodeMem (Buffer, RightColumn - LeftColumn, L' ');
730
731 //
732 // Clear the desired area with the appropriate foreground/background
733 //
734 for (Row = TopRow; Row <= BottomRow; Row++) {
735 PrintStringAt (LeftColumn, Row, Buffer);
736 }
737
738 gST->ConOut->SetCursorPosition (gST->ConOut, LeftColumn, TopRow);
739
740 FreePool (Buffer);
741 }
742
743 //
744 // Color Setting Functions
745 //
746
747 /**
748 Get OEM/Vendor specific popup attribute colors.
749
750 @retval Byte code color setting for popup color.
751 **/
752 UINT8
753 EFIAPI
754 GetPopupColor (
755 VOID
756 )
757 {
758 return POPUP_TEXT | POPUP_BACKGROUND;
759 }
760
761 /**
762 Get OEM/Vendor specific popup attribute colors.
763
764 @retval Byte code color setting for popup inverse color.
765 **/
766 UINT8
767 EFIAPI
768 GetPopupInverseColor (
769 VOID
770 )
771 {
772 return POPUP_INVERSE_TEXT | POPUP_INVERSE_BACKGROUND;
773 }
774
775 /**
776 Get OEM/Vendor specific PickList color attribute.
777
778 @retval Byte code color setting for pick list color.
779 **/
780 UINT8
781 EFIAPI
782 GetPickListColor (
783 VOID
784 )
785 {
786 return PICKLIST_HIGHLIGHT_TEXT | PICKLIST_HIGHLIGHT_BACKGROUND;
787 }
788
789 /**
790 Get OEM/Vendor specific arrow color attribute.
791
792 @retval Byte code color setting for arrow color.
793 **/
794 UINT8
795 EFIAPI
796 GetArrowColor (
797 VOID
798 )
799 {
800 return ARROW_TEXT | ARROW_BACKGROUND;
801 }
802
803 /**
804 Get OEM/Vendor specific info text color attribute.
805
806 @retval Byte code color setting for info text color.
807 **/
808 UINT8
809 EFIAPI
810 GetInfoTextColor (
811 VOID
812 )
813 {
814 return INFO_TEXT | FIELD_BACKGROUND;
815 }
816
817 /**
818 Get OEM/Vendor specific help text color attribute.
819
820 @retval Byte code color setting for help text color.
821 **/
822 UINT8
823 EFIAPI
824 GetHelpTextColor (
825 VOID
826 )
827 {
828 return HELP_TEXT | FIELD_BACKGROUND;
829 }
830
831 /**
832 Get OEM/Vendor specific grayed out text color attribute.
833
834 @retval Byte code color setting for grayed out text color.
835 **/
836 UINT8
837 EFIAPI
838 GetGrayedTextColor (
839 VOID
840 )
841 {
842 return FIELD_TEXT_GRAYED | FIELD_BACKGROUND;
843 }
844
845 /**
846 Get OEM/Vendor specific highlighted text color attribute.
847
848 @retval Byte code color setting for highlight text color.
849 **/
850 UINT8
851 EFIAPI
852 GetHighlightTextColor (
853 VOID
854 )
855 {
856 return PcdGet8 (PcdBrowserFieldTextHighlightColor) | PcdGet8 (PcdBrowserFieldBackgroundHighlightColor);
857 }
858
859 /**
860 Get OEM/Vendor specific field text color attribute.
861
862 @retval Byte code color setting for field text color.
863 **/
864 UINT8
865 EFIAPI
866 GetFieldTextColor (
867 VOID
868 )
869 {
870 return PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND;
871 }
872
873 /**
874 Get OEM/Vendor specific subtitle text color attribute.
875
876 @retval Byte code color setting for subtitle text color.
877 **/
878 UINT8
879 EFIAPI
880 GetSubTitleTextColor (
881 VOID
882 )
883 {
884 return PcdGet8 (PcdBrowserSubtitleTextColor) | FIELD_BACKGROUND;
885 }
886
887 /**
888 Clear Screen to the initial state.
889 **/
890 VOID
891 EFIAPI
892 ClearDisplayPage (
893 VOID
894 )
895 {
896 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
897 gST->ConOut->ClearScreen (gST->ConOut);
898 gLibIsFirstForm = TRUE;
899 }
900
901 /**
902 Constructor of Customized Display Library Instance.
903
904 @param ImageHandle The firmware allocated handle for the EFI image.
905 @param SystemTable A pointer to the EFI System Table.
906
907 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
908
909 **/
910 EFI_STATUS
911 EFIAPI
912 CustomizedDisplayLibConstructor (
913 IN EFI_HANDLE ImageHandle,
914 IN EFI_SYSTEM_TABLE *SystemTable
915 )
916 {
917 mCDLStringPackHandle = HiiAddPackages (&gCustomizedDisplayLibGuid, ImageHandle, CustomizedDisplayLibStrings, NULL);
918 ASSERT (mCDLStringPackHandle != NULL);
919
920 InitializeLibStrings();
921
922 return EFI_SUCCESS;
923 }
924
925 /**
926 Destructor of Customized Display Library Instance.
927
928 @param ImageHandle The firmware allocated handle for the EFI image.
929 @param SystemTable A pointer to the EFI System Table.
930
931 @retval EFI_SUCCESS The destructor completed successfully.
932 @retval Other value The destructor did not complete successfully.
933
934 **/
935 EFI_STATUS
936 EFIAPI
937 CustomizedDisplayLibDestructor (
938 IN EFI_HANDLE ImageHandle,
939 IN EFI_SYSTEM_TABLE *SystemTable
940 )
941 {
942 HiiRemovePackages(mCDLStringPackHandle);
943
944 FreeLibStrings ();
945
946 return EFI_SUCCESS;
947 }
948