]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c
Fix form flash issue.
[mirror_edk2.git] / MdeModulePkg / Library / CustomizedDisplayLib / CustomizedDisplayLibInternal.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_SCREEN_DESCRIPTOR gScreenDimensions;
18 CHAR16 *mLibUnknownString;
19 extern EFI_HII_HANDLE mCDLStringPackHandle;
20 CHAR16 *mSpaceBuffer;
21 #define SPACE_BUFFER_SIZE 1000
22
23 //
24 // Browser Global Strings
25 //
26 CHAR16 *gEnterString;
27 CHAR16 *gEnterCommitString;
28 CHAR16 *gEnterEscapeString;
29 CHAR16 *gEscapeString;
30 CHAR16 *gMoveHighlight;
31 CHAR16 *gDecNumericInput;
32 CHAR16 *gHexNumericInput;
33 CHAR16 *gToggleCheckBox;
34 CHAR16 *gLibEmptyString;
35 CHAR16 *gAreYouSure;
36 CHAR16 *gYesResponse;
37 CHAR16 *gNoResponse;
38 CHAR16 *gPlusString;
39 CHAR16 *gMinusString;
40 CHAR16 *gAdjustNumber;
41 CHAR16 *gSaveChanges;
42 CHAR16 *gNvUpdateMessage;
43 CHAR16 *gInputErrorMessage;
44
45 /**
46
47 Print banner info for front page.
48
49 @param[in] FormData Form Data to be shown in Page
50
51 **/
52 VOID
53 PrintBannerInfo (
54 IN FORM_DISPLAY_ENGINE_FORM *FormData
55 )
56 {
57 UINT8 Line;
58 UINT8 Alignment;
59 CHAR16 *StrFrontPageBanner;
60 UINT8 RowIdx;
61 UINT8 ColumnIdx;
62
63 //
64 // ClearLines(0, LocalScreen.RightColumn, 0, BANNER_HEIGHT-1, BANNER_TEXT | BANNER_BACKGROUND);
65 //
66 ClearLines (
67 gScreenDimensions.LeftColumn,
68 gScreenDimensions.RightColumn,
69 gScreenDimensions.TopRow,
70 FRONT_PAGE_HEADER_HEIGHT - 1 + gScreenDimensions.TopRow,
71 BANNER_TEXT | BANNER_BACKGROUND
72 );
73
74 //
75 // for (Line = 0; Line < BANNER_HEIGHT; Line++) {
76 //
77 for (Line = (UINT8) gScreenDimensions.TopRow; Line < BANNER_HEIGHT + (UINT8) gScreenDimensions.TopRow; Line++) {
78 //
79 // for (Alignment = 0; Alignment < BANNER_COLUMNS; Alignment++) {
80 //
81 for (Alignment = (UINT8) gScreenDimensions.LeftColumn;
82 Alignment < BANNER_COLUMNS + (UINT8) gScreenDimensions.LeftColumn;
83 Alignment++
84 ) {
85 RowIdx = (UINT8) (Line - (UINT8) gScreenDimensions.TopRow);
86 ColumnIdx = (UINT8) (Alignment - (UINT8) gScreenDimensions.LeftColumn);
87
88 ASSERT (RowIdx < BANNER_HEIGHT && ColumnIdx < BANNER_COLUMNS);
89
90 if (gBannerData!= NULL && gBannerData->Banner[RowIdx][ColumnIdx] != 0x0000) {
91 StrFrontPageBanner = LibGetToken (gBannerData->Banner[RowIdx][ColumnIdx], FormData->HiiHandle);
92 } else {
93 continue;
94 }
95
96 switch (Alignment - gScreenDimensions.LeftColumn) {
97 case 0:
98 //
99 // Handle left column
100 //
101 PrintStringAt (gScreenDimensions.LeftColumn + BANNER_LEFT_COLUMN_INDENT, Line, StrFrontPageBanner);
102 break;
103
104 case 1:
105 //
106 // Handle center column
107 //
108 PrintStringAt (
109 gScreenDimensions.LeftColumn + (gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn) / 3,
110 Line,
111 StrFrontPageBanner
112 );
113 break;
114
115 case 2:
116 //
117 // Handle right column
118 //
119 PrintStringAt (
120 gScreenDimensions.LeftColumn + (gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn) * 2 / 3,
121 Line,
122 StrFrontPageBanner
123 );
124 break;
125 }
126
127 FreePool (StrFrontPageBanner);
128 }
129 }
130 }
131
132 /**
133 Print framework and form title for a page.
134
135 @param[in] FormData Form Data to be shown in Page
136 **/
137 VOID
138 PrintFramework (
139 IN FORM_DISPLAY_ENGINE_FORM *FormData
140 )
141 {
142 UINTN Index;
143 CHAR16 Character;
144 CHAR16 *Buffer;
145 UINTN Row;
146 CHAR16 *TitleStr;
147 UINTN TitleColumn;
148
149 if (gClassOfVfr != FORMSET_CLASS_PLATFORM_SETUP) {
150 //
151 // Only Setup page needs Framework
152 //
153 ClearLines (
154 gScreenDimensions.LeftColumn,
155 gScreenDimensions.RightColumn,
156 gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight,
157 gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - 1,
158 KEYHELP_TEXT | KEYHELP_BACKGROUND
159 );
160 return;
161 }
162
163 Buffer = AllocateZeroPool (0x10000);
164 ASSERT (Buffer != NULL);
165 Character = BOXDRAW_HORIZONTAL;
166 for (Index = 0; Index + 2 < (gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn); Index++) {
167 Buffer[Index] = Character;
168 }
169
170 //
171 // Print Top border line
172 // +------------------------------------------------------------------------------+
173 // ? ?
174 // +------------------------------------------------------------------------------+
175 //
176 gST->ConOut->SetAttribute (gST->ConOut, TITLE_TEXT | TITLE_BACKGROUND);
177 Character = BOXDRAW_DOWN_RIGHT;
178
179 PrintCharAt (gScreenDimensions.LeftColumn, gScreenDimensions.TopRow, Character);
180 PrintStringAt ((UINTN) -1, (UINTN) -1, Buffer);
181
182 Character = BOXDRAW_DOWN_LEFT;
183 PrintCharAt ((UINTN) -1, (UINTN) -1, Character);
184
185 Character = BOXDRAW_VERTICAL;
186 for (Row = gScreenDimensions.TopRow + 1; Row <= gScreenDimensions.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 2; Row++) {
187 PrintCharAt (gScreenDimensions.LeftColumn, Row, Character);
188 PrintCharAt (gScreenDimensions.RightColumn - 1, Row, Character);
189 }
190
191 //
192 // Print Form Title
193 //
194 TitleStr = LibGetToken (FormData->FormTitle, FormData->HiiHandle);
195 ASSERT (TitleStr != NULL);
196 TitleColumn = (gScreenDimensions.RightColumn + gScreenDimensions.LeftColumn - LibGetStringWidth (TitleStr) / 2) / 2;
197 PrintStringAtWithWidth (gScreenDimensions.LeftColumn + 1, gScreenDimensions.TopRow + 1, gLibEmptyString, TitleColumn - gScreenDimensions.LeftColumn - 1);
198 PrintStringAtWithWidth (
199 TitleColumn,
200 gScreenDimensions.TopRow + 1,
201 TitleStr,
202 gScreenDimensions.RightColumn - 1 - TitleColumn
203 );
204 FreePool (TitleStr);
205
206 Character = BOXDRAW_UP_RIGHT;
207 PrintCharAt (gScreenDimensions.LeftColumn, gScreenDimensions.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 1, Character);
208 PrintStringAt ((UINTN) -1, (UINTN) -1, Buffer);
209
210 Character = BOXDRAW_UP_LEFT;
211 PrintCharAt ((UINTN) -1, (UINTN) -1, Character);
212
213 //
214 // Print Bottom border line
215 // +------------------------------------------------------------------------------+
216 // ? ?
217 // +------------------------------------------------------------------------------+
218 //
219 Character = BOXDRAW_DOWN_RIGHT;
220 PrintCharAt (gScreenDimensions.LeftColumn, gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight, Character);
221
222 PrintStringAt ((UINTN) -1, (UINTN) -1, Buffer);
223
224 Character = BOXDRAW_DOWN_LEFT;
225 PrintCharAt ((UINTN) -1, (UINTN) -1, Character);
226 Character = BOXDRAW_VERTICAL;
227 for (Row = gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight + 1;
228 Row <= gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - 2;
229 Row++
230 ) {
231 PrintCharAt (gScreenDimensions.LeftColumn, Row, Character);
232 PrintCharAt (gScreenDimensions.RightColumn - 1, Row, Character);
233 }
234
235 Character = BOXDRAW_UP_RIGHT;
236 PrintCharAt (gScreenDimensions.LeftColumn, gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - 1, Character);
237
238 PrintStringAt ((UINTN) -1, (UINTN) -1, Buffer);
239
240 Character = BOXDRAW_UP_LEFT;
241 PrintCharAt ((UINTN) -1, (UINTN) -1, Character);
242
243 FreePool (Buffer);
244 }
245
246 /**
247 Process some op code which is not recognized by browser core.
248
249 @param OpCodeData The pointer to the op code buffer.
250
251 @return EFI_SUCCESS Pass the statement success.
252
253 **/
254 VOID
255 ProcessUserOpcode(
256 IN EFI_IFR_OP_HEADER *OpCodeData
257 )
258 {
259 switch (OpCodeData->OpCode) {
260 case EFI_IFR_GUID_OP:
261 if (CompareGuid (&gEfiIfrTianoGuid, (EFI_GUID *)((CHAR8*) OpCodeData + sizeof (EFI_IFR_OP_HEADER)))) {
262 //
263 // Tiano specific GUIDed opcodes
264 //
265 switch (((EFI_IFR_GUID_LABEL *) OpCodeData)->ExtendOpCode) {
266 case EFI_IFR_EXTEND_OP_LABEL:
267 //
268 // just ignore label
269 //
270 break;
271
272 case EFI_IFR_EXTEND_OP_BANNER:
273 //
274 // Only in front page form set, we care about the banner data.
275 //
276 if (gClassOfVfr == FORMSET_CLASS_FRONT_PAGE) {
277 //
278 // Initialize Driver private data
279 //
280 if (gBannerData == NULL) {
281 gBannerData = AllocateZeroPool (sizeof (BANNER_DATA));
282 ASSERT (gBannerData != NULL);
283 }
284
285 CopyMem (
286 &gBannerData->Banner[((EFI_IFR_GUID_BANNER *) OpCodeData)->LineNumber][
287 ((EFI_IFR_GUID_BANNER *) OpCodeData)->Alignment],
288 &((EFI_IFR_GUID_BANNER *) OpCodeData)->Title,
289 sizeof (EFI_STRING_ID)
290 );
291 }
292 break;
293
294 case EFI_IFR_EXTEND_OP_SUBCLASS:
295 if (((EFI_IFR_GUID_SUBCLASS *) OpCodeData)->SubClass == EFI_FRONT_PAGE_SUBCLASS) {
296 gClassOfVfr = FORMSET_CLASS_FRONT_PAGE;
297 }
298 break;
299
300 default:
301 break;
302 }
303 }
304 break;
305
306 default:
307 break;
308 }
309 }
310
311 /**
312 Process some op codes which is out side of current form.
313
314 @param FormData Pointer to the form data.
315
316 @return EFI_SUCCESS Pass the statement success.
317
318 **/
319 VOID
320 ProcessExternedOpcode (
321 IN FORM_DISPLAY_ENGINE_FORM *FormData
322 )
323 {
324 LIST_ENTRY *Link;
325 FORM_DISPLAY_ENGINE_STATEMENT *Statement;
326
327 Link = GetFirstNode (&FormData->StatementListOSF);
328 while (!IsNull (&FormData->StatementListOSF, Link)) {
329 Statement = FORM_DISPLAY_ENGINE_STATEMENT_FROM_LINK (Link);
330 Link = GetNextNode (&FormData->StatementListOSF, Link);
331
332 ProcessUserOpcode(Statement->OpCode);
333 }
334
335 Link = GetFirstNode (&FormData->StatementListHead);
336 while (!IsNull (&FormData->StatementListHead, Link)) {
337 Statement = FORM_DISPLAY_ENGINE_STATEMENT_FROM_LINK (Link);
338 Link = GetNextNode (&FormData->StatementListHead, Link);
339
340 ProcessUserOpcode(Statement->OpCode);
341 }
342 }
343
344 /**
345 Validate the input screen diemenstion info.
346
347 @param FormData The input form data info.
348
349 @return EFI_SUCCESS The input screen info is acceptable.
350 @return EFI_INVALID_PARAMETER The input screen info is not acceptable.
351
352 **/
353 EFI_STATUS
354 ScreenDiemensionInfoValidate (
355 IN FORM_DISPLAY_ENGINE_FORM *FormData
356 )
357 {
358 LIST_ENTRY *Link;
359 UINTN Index;
360
361 //
362 // Calculate total number of Register HotKeys.
363 //
364 Index = 0;
365 if (!IsListEmpty (&FormData->HotKeyListHead)){
366 Link = GetFirstNode (&FormData->HotKeyListHead);
367 while (!IsNull (&FormData->HotKeyListHead, Link)) {
368 Link = GetNextNode (&FormData->HotKeyListHead, Link);
369 Index ++;
370 }
371 }
372
373 //
374 // Show three HotKeys help information on one row.
375 //
376 gFooterHeight = FOOTER_HEIGHT + (Index / 3);
377
378
379 ZeroMem (&gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
380 gST->ConOut->QueryMode (
381 gST->ConOut,
382 gST->ConOut->Mode->Mode,
383 &gScreenDimensions.RightColumn,
384 &gScreenDimensions.BottomRow
385 );
386
387 //
388 // Check local dimension vs. global dimension.
389 //
390 if (FormData->ScreenDimensions != NULL) {
391 if ((gScreenDimensions.RightColumn < FormData->ScreenDimensions->RightColumn) ||
392 (gScreenDimensions.BottomRow < FormData->ScreenDimensions->BottomRow)
393 ) {
394 return EFI_INVALID_PARAMETER;
395 } else {
396 //
397 // Local dimension validation.
398 //
399 if ((FormData->ScreenDimensions->RightColumn > FormData->ScreenDimensions->LeftColumn) &&
400 (FormData->ScreenDimensions->BottomRow > FormData->ScreenDimensions->TopRow) &&
401 ((FormData->ScreenDimensions->RightColumn - FormData->ScreenDimensions->LeftColumn) > 2) &&
402 ((FormData->ScreenDimensions->BottomRow - FormData->ScreenDimensions->TopRow) > STATUS_BAR_HEIGHT +
403 FRONT_PAGE_HEADER_HEIGHT + gFooterHeight + 3)) {
404 CopyMem (&gScreenDimensions, (VOID *) FormData->ScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
405 } else {
406 return EFI_INVALID_PARAMETER;
407 }
408 }
409 }
410
411 return EFI_SUCCESS;
412 }
413
414 /**
415 Get the string based on the StringId and HII Package List Handle.
416
417 @param Token The String's ID.
418 @param HiiHandle The package list in the HII database to search for
419 the specified string.
420
421 @return The output string.
422
423 **/
424 CHAR16 *
425 LibGetToken (
426 IN EFI_STRING_ID Token,
427 IN EFI_HII_HANDLE HiiHandle
428 )
429 {
430 EFI_STRING String;
431
432 String = HiiGetString (HiiHandle, Token, NULL);
433 if (String == NULL) {
434 String = AllocateCopyPool (StrSize (mLibUnknownString), mLibUnknownString);
435 ASSERT (String != NULL);
436 }
437
438 return (CHAR16 *) String;
439 }
440
441
442 /**
443 Count the storage space of a Unicode string.
444
445 This function handles the Unicode string with NARROW_CHAR
446 and WIDE_CHAR control characters. NARROW_HCAR and WIDE_CHAR
447 does not count in the resultant output. If a WIDE_CHAR is
448 hit, then 2 Unicode character will consume an output storage
449 space with size of CHAR16 till a NARROW_CHAR is hit.
450
451 If String is NULL, then ASSERT ().
452
453 @param String The input string to be counted.
454
455 @return Storage space for the input string.
456
457 **/
458 UINTN
459 LibGetStringWidth (
460 IN CHAR16 *String
461 )
462 {
463 UINTN Index;
464 UINTN Count;
465 UINTN IncrementValue;
466
467 ASSERT (String != NULL);
468 if (String == NULL) {
469 return 0;
470 }
471
472 Index = 0;
473 Count = 0;
474 IncrementValue = 1;
475
476 do {
477 //
478 // Advance to the null-terminator or to the first width directive
479 //
480 for (;
481 (String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0);
482 Index++, Count = Count + IncrementValue
483 )
484 ;
485
486 //
487 // We hit the null-terminator, we now have a count
488 //
489 if (String[Index] == 0) {
490 break;
491 }
492 //
493 // We encountered a narrow directive - strip it from the size calculation since it doesn't get printed
494 // and also set the flag that determines what we increment by.(if narrow, increment by 1, if wide increment by 2)
495 //
496 if (String[Index] == NARROW_CHAR) {
497 //
498 // Skip to the next character
499 //
500 Index++;
501 IncrementValue = 1;
502 } else {
503 //
504 // Skip to the next character
505 //
506 Index++;
507 IncrementValue = 2;
508 }
509 } while (String[Index] != 0);
510
511 //
512 // Increment by one to include the null-terminator in the size
513 //
514 Count++;
515
516 return Count * sizeof (CHAR16);
517 }
518
519 /**
520 Show all registered HotKey help strings on bottom Rows.
521
522 @param FormData The curent input form data info.
523 @param SetState Set HotKey or Clear HotKey
524
525 **/
526 VOID
527 PrintHotKeyHelpString (
528 IN FORM_DISPLAY_ENGINE_FORM *FormData,
529 IN BOOLEAN SetState
530 )
531 {
532 UINTN CurrentCol;
533 UINTN CurrentRow;
534 UINTN BottomRowOfHotKeyHelp;
535 UINTN ColumnIndexWidth;
536 UINTN ColumnWidth;
537 UINTN ColumnIndex;
538 UINTN Index;
539 EFI_SCREEN_DESCRIPTOR LocalScreen;
540 LIST_ENTRY *Link;
541 BROWSER_HOT_KEY *HotKey;
542 CHAR16 BakChar;
543 CHAR16 *ColumnStr;
544
545 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
546 ColumnWidth = (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3;
547 BottomRowOfHotKeyHelp = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 3;
548 ColumnStr = gLibEmptyString;
549
550 //
551 // Calculate total number of Register HotKeys.
552 //
553 Index = 0;
554 Link = GetFirstNode (&FormData->HotKeyListHead);
555 while (!IsNull (&FormData->HotKeyListHead, Link)) {
556 HotKey = BROWSER_HOT_KEY_FROM_LINK (Link);
557 //
558 // Calculate help information Column and Row.
559 //
560 ColumnIndex = Index % 3;
561 if (ColumnIndex == 0) {
562 CurrentCol = LocalScreen.LeftColumn + 2 * ColumnWidth;
563 ColumnIndexWidth = ColumnWidth - 1;
564 } else if (ColumnIndex == 1) {
565 CurrentCol = LocalScreen.LeftColumn + ColumnWidth;
566 ColumnIndexWidth = ColumnWidth;
567 } else {
568 CurrentCol = LocalScreen.LeftColumn + 2;
569 ColumnIndexWidth = ColumnWidth - 2;
570 }
571 CurrentRow = BottomRowOfHotKeyHelp - Index / 3;
572
573 //
574 // Help string can't exceed ColumnWidth. One Row will show three Help information.
575 //
576 BakChar = L'\0';
577 if (StrLen (HotKey->HelpString) > ColumnIndexWidth) {
578 BakChar = HotKey->HelpString[ColumnIndexWidth];
579 HotKey->HelpString[ColumnIndexWidth] = L'\0';
580 }
581
582 //
583 // Print HotKey help string on bottom Row.
584 //
585 if (SetState) {
586 ColumnStr = HotKey->HelpString;
587 }
588 PrintStringAtWithWidth (CurrentCol, CurrentRow, ColumnStr, ColumnIndexWidth);
589
590 if (BakChar != L'\0') {
591 HotKey->HelpString[ColumnIndexWidth] = BakChar;
592 }
593 //
594 // Get Next Hot Key.
595 //
596 Link = GetNextNode (&FormData->HotKeyListHead, Link);
597 Index ++;
598 }
599
600 if (SetState) {
601 //
602 // Clear KeyHelp
603 //
604 CurrentRow = BottomRowOfHotKeyHelp - Index / 3;
605 ColumnIndex = Index % 3;
606 if (ColumnIndex == 0) {
607 CurrentCol = LocalScreen.LeftColumn + 2 * ColumnWidth;
608 ColumnIndexWidth = ColumnWidth - 1;
609 ColumnIndex ++;
610 PrintStringAtWithWidth (CurrentCol, CurrentRow, gLibEmptyString, ColumnIndexWidth);
611 }
612 if (ColumnIndex == 1) {
613 CurrentCol = LocalScreen.LeftColumn + ColumnWidth;
614 ColumnIndexWidth = ColumnWidth;
615 PrintStringAtWithWidth (CurrentCol, CurrentRow, gLibEmptyString, ColumnIndexWidth);
616 }
617 }
618
619 return;
620 }
621
622 /**
623 Get step info from numeric opcode.
624
625 @param[in] OpCode The input numeric op code.
626
627 @return step info for this opcode.
628 **/
629 UINT64
630 LibGetFieldFromNum (
631 IN EFI_IFR_OP_HEADER *OpCode
632 )
633 {
634 EFI_IFR_NUMERIC *NumericOp;
635 UINT64 Step;
636
637 NumericOp = (EFI_IFR_NUMERIC *) OpCode;
638
639 switch (NumericOp->Flags & EFI_IFR_NUMERIC_SIZE) {
640 case EFI_IFR_NUMERIC_SIZE_1:
641 Step = NumericOp->data.u8.Step;
642 break;
643
644 case EFI_IFR_NUMERIC_SIZE_2:
645 Step = NumericOp->data.u16.Step;
646 break;
647
648 case EFI_IFR_NUMERIC_SIZE_4:
649 Step = NumericOp->data.u32.Step;
650 break;
651
652 case EFI_IFR_NUMERIC_SIZE_8:
653 Step = NumericOp->data.u64.Step;
654 break;
655
656 default:
657 Step = 0;
658 break;
659 }
660
661 return Step;
662 }
663
664 /**
665 Initialize the HII String Token to the correct values.
666
667 **/
668 VOID
669 InitializeLibStrings (
670 VOID
671 )
672 {
673 mLibUnknownString = L"!";
674
675 gEnterString = LibGetToken (STRING_TOKEN (ENTER_STRING), mCDLStringPackHandle);
676 gEnterCommitString = LibGetToken (STRING_TOKEN (ENTER_COMMIT_STRING), mCDLStringPackHandle);
677 gEnterEscapeString = LibGetToken (STRING_TOKEN (ENTER_ESCAPE_STRING), mCDLStringPackHandle);
678 gEscapeString = LibGetToken (STRING_TOKEN (ESCAPE_STRING), mCDLStringPackHandle);
679 gMoveHighlight = LibGetToken (STRING_TOKEN (MOVE_HIGHLIGHT), mCDLStringPackHandle);
680 gDecNumericInput = LibGetToken (STRING_TOKEN (DEC_NUMERIC_INPUT), mCDLStringPackHandle);
681 gHexNumericInput = LibGetToken (STRING_TOKEN (HEX_NUMERIC_INPUT), mCDLStringPackHandle);
682 gToggleCheckBox = LibGetToken (STRING_TOKEN (TOGGLE_CHECK_BOX), mCDLStringPackHandle);
683
684 gAreYouSure = LibGetToken (STRING_TOKEN (ARE_YOU_SURE), mCDLStringPackHandle);
685 gYesResponse = LibGetToken (STRING_TOKEN (ARE_YOU_SURE_YES), mCDLStringPackHandle);
686 gNoResponse = LibGetToken (STRING_TOKEN (ARE_YOU_SURE_NO), mCDLStringPackHandle);
687 gPlusString = LibGetToken (STRING_TOKEN (PLUS_STRING), mCDLStringPackHandle);
688 gMinusString = LibGetToken (STRING_TOKEN (MINUS_STRING), mCDLStringPackHandle);
689 gAdjustNumber = LibGetToken (STRING_TOKEN (ADJUST_NUMBER), mCDLStringPackHandle);
690 gSaveChanges = LibGetToken (STRING_TOKEN (SAVE_CHANGES), mCDLStringPackHandle);
691
692 gLibEmptyString = LibGetToken (STRING_TOKEN (EMPTY_STRING), mCDLStringPackHandle);
693
694 gNvUpdateMessage = LibGetToken (STRING_TOKEN (NV_UPDATE_MESSAGE), mCDLStringPackHandle);
695 gInputErrorMessage = LibGetToken (STRING_TOKEN (INPUT_ERROR_MESSAGE), mCDLStringPackHandle);
696
697 //
698 // SpaceBuffer;
699 //
700 mSpaceBuffer = AllocatePool ((SPACE_BUFFER_SIZE + 1) * sizeof (CHAR16));
701 ASSERT (mSpaceBuffer != NULL);
702 LibSetUnicodeMem (mSpaceBuffer, SPACE_BUFFER_SIZE, L' ');
703 mSpaceBuffer[SPACE_BUFFER_SIZE] = L'\0';
704 }
705
706
707 /**
708 Free the HII String.
709
710 **/
711 VOID
712 FreeLibStrings (
713 VOID
714 )
715 {
716 FreePool (gEnterString);
717 FreePool (gEnterCommitString);
718 FreePool (gEnterEscapeString);
719 FreePool (gEscapeString);
720 FreePool (gMoveHighlight);
721 FreePool (gDecNumericInput);
722 FreePool (gHexNumericInput);
723 FreePool (gToggleCheckBox);
724
725 FreePool (gAreYouSure);
726 FreePool (gYesResponse);
727 FreePool (gNoResponse);
728 FreePool (gPlusString);
729 FreePool (gMinusString);
730 FreePool (gAdjustNumber);
731 FreePool (gSaveChanges);
732
733 FreePool (gLibEmptyString);
734
735 FreePool (gNvUpdateMessage);
736 FreePool (gInputErrorMessage);
737
738 FreePool (mSpaceBuffer);
739 }
740
741 /**
742 Wait for a key to be pressed by user.
743
744 @param Key The key which is pressed by user.
745
746 @retval EFI_SUCCESS The function always completed successfully.
747
748 **/
749 EFI_STATUS
750 WaitForKeyStroke (
751 OUT EFI_INPUT_KEY *Key
752 )
753 {
754 EFI_STATUS Status;
755 UINTN Index;
756
757 while (TRUE) {
758 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, Key);
759 if (!EFI_ERROR (Status)) {
760 break;
761 }
762
763 if (Status != EFI_NOT_READY) {
764 continue;
765 }
766
767 gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &Index);
768 }
769 return Status;
770 }
771
772
773 /**
774 Set Buffer to Value for Size bytes.
775
776 @param Buffer Memory to set.
777 @param Size Number of bytes to set
778 @param Value Value of the set operation.
779
780 **/
781 VOID
782 LibSetUnicodeMem (
783 IN VOID *Buffer,
784 IN UINTN Size,
785 IN CHAR16 Value
786 )
787 {
788 CHAR16 *Ptr;
789
790 Ptr = Buffer;
791 while ((Size--) != 0) {
792 *(Ptr++) = Value;
793 }
794 }
795
796 /**
797 The internal function prints to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
798 protocol instance.
799
800 @param Width Width of string to be print.
801 @param Column The position of the output string.
802 @param Row The position of the output string.
803 @param Out The EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.
804 @param Fmt The format string.
805 @param Args The additional argument for the variables in the format string.
806
807 @return Number of Unicode character printed.
808
809 **/
810 UINTN
811 PrintInternal (
812 IN UINTN Width,
813 IN UINTN Column,
814 IN UINTN Row,
815 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Out,
816 IN CHAR16 *Fmt,
817 IN VA_LIST Args
818 )
819 {
820 CHAR16 *Buffer;
821 CHAR16 *BackupBuffer;
822 UINTN Index;
823 UINTN PreviousIndex;
824 UINTN Count;
825 UINTN TotalCount;
826 UINTN PrintWidth;
827 UINTN CharWidth;
828
829 //
830 // For now, allocate an arbitrarily long buffer
831 //
832 Buffer = AllocateZeroPool (0x10000);
833 BackupBuffer = AllocateZeroPool (0x10000);
834 ASSERT (Buffer);
835 ASSERT (BackupBuffer);
836
837 if (Column != (UINTN) -1) {
838 Out->SetCursorPosition (Out, Column, Row);
839 }
840
841 UnicodeVSPrint (Buffer, 0x10000, Fmt, Args);
842
843 Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;
844
845 Out->SetAttribute (Out, Out->Mode->Attribute);
846
847 Index = 0;
848 PreviousIndex = 0;
849 Count = 0;
850 TotalCount = 0;
851 PrintWidth = 0;
852 CharWidth = 1;
853
854 do {
855 for (; (Buffer[Index] != NARROW_CHAR) && (Buffer[Index] != WIDE_CHAR) && (Buffer[Index] != 0); Index++) {
856 BackupBuffer[Index] = Buffer[Index];
857 }
858
859 if (Buffer[Index] == 0) {
860 break;
861 }
862
863 //
864 // Print this out, we are about to switch widths
865 //
866 Out->OutputString (Out, &BackupBuffer[PreviousIndex]);
867 Count = StrLen (&BackupBuffer[PreviousIndex]);
868 PrintWidth += Count * CharWidth;
869 TotalCount += Count;
870
871 //
872 // Preserve the current index + 1, since this is where we will start printing from next
873 //
874 PreviousIndex = Index + 1;
875
876 //
877 // We are at a narrow or wide character directive. Set attributes and strip it and print it
878 //
879 if (Buffer[Index] == NARROW_CHAR) {
880 //
881 // Preserve bits 0 - 6 and zero out the rest
882 //
883 Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;
884 Out->SetAttribute (Out, Out->Mode->Attribute);
885 CharWidth = 1;
886 } else {
887 //
888 // Must be wide, set bit 7 ON
889 //
890 Out->Mode->Attribute = Out->Mode->Attribute | EFI_WIDE_ATTRIBUTE;
891 Out->SetAttribute (Out, Out->Mode->Attribute);
892 CharWidth = 2;
893 }
894
895 Index++;
896
897 } while (Buffer[Index] != 0);
898
899 //
900 // We hit the end of the string - print it
901 //
902 Out->OutputString (Out, &BackupBuffer[PreviousIndex]);
903 Count = StrLen (&BackupBuffer[PreviousIndex]);
904 PrintWidth += Count * CharWidth;
905 TotalCount += Count;
906 if (PrintWidth < Width) {
907 Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;
908 Out->SetAttribute (Out, Out->Mode->Attribute);
909 Out->OutputString (Out, &mSpaceBuffer[SPACE_BUFFER_SIZE - Width + PrintWidth]);
910 }
911
912 FreePool (Buffer);
913 FreePool (BackupBuffer);
914 return TotalCount;
915 }
916
917 /**
918 Prints a formatted unicode string to the default console, at
919 the supplied cursor position.
920
921 @param Width Width of String to be printed.
922 @param Column The cursor position to print the string at.
923 @param Row The cursor position to print the string at.
924 @param Fmt Format string.
925 @param ... Variable argument list for format string.
926
927 @return Length of string printed to the console
928
929 **/
930 UINTN
931 EFIAPI
932 PrintAt (
933 IN UINTN Width,
934 IN UINTN Column,
935 IN UINTN Row,
936 IN CHAR16 *Fmt,
937 ...
938 )
939 {
940 VA_LIST Args;
941 UINTN LengthOfPrinted;
942
943 VA_START (Args, Fmt);
944 LengthOfPrinted = PrintInternal (Width, Column, Row, gST->ConOut, Fmt, Args);
945 VA_END (Args);
946 return LengthOfPrinted;
947 }
948