add in FrameworkIfrSupportLib
[mirror_edk2.git] / IntelFrameworkPkg / Library / FrameworkIfrSupportLib / IfrOnTheFly.c
CommitLineData
5d01b0f7 1/*++\r
2Copyright (c) 2006, Intel Corporation \r
3All rights reserved. This program and the accompanying materials \r
4are licensed and made available under the terms and conditions of the BSD License \r
5which accompanies this distribution. The full text of the license may be found at \r
6http://opensource.org/licenses/bsd-license.php \r
7 \r
8THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
9WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
10\r
11Module Name:\r
12 IfrOnTheFly.c\r
13\r
14Abstract:\r
15\r
16 Library Routines to create IFR on-the-fly\r
17\r
18Revision History:\r
19\r
20--*/\r
21\r
22//\r
23// Include common header file for this module.\r
24//\r
25#include "CommonHeader.h"\r
26\r
27EFI_STATUS\r
28CreateFormSet (\r
29 IN CHAR16 *FormSetTitle,\r
30 IN EFI_GUID *Guid,\r
31 IN UINT8 Class,\r
32 IN UINT8 SubClass,\r
33 IN OUT VOID **FormBuffer,\r
34 IN OUT VOID **StringBuffer\r
35 )\r
36/*++\r
37\r
38Routine Description:\r
39\r
40 Create a formset\r
41 \r
42Arguments:\r
43 \r
44 FormSetTitle - Title of formset\r
45 \r
46 Guid - Guid of formset\r
47 \r
48 Class - Class of formset\r
49 \r
50 SubClass - Sub class of formset\r
51 \r
52 FormBuffer - Pointer of the formset created\r
53 \r
54 StringBuffer - Pointer of FormSetTitile string created\r
55 \r
56Returns: \r
57\r
58 EFI_OUT_OF_RESOURCES - No enough buffer to allocate\r
59 \r
60 EFI_SUCCESS - Formset successfully created\r
61\r
62--*/\r
63{\r
64 EFI_STATUS Status;\r
65 EFI_HII_IFR_PACK IfrPack;\r
66 EFI_IFR_FORM_SET FormSet;\r
67 EFI_IFR_END_FORM_SET EndFormSet;\r
68 UINT8 *Destination;\r
69 CHAR16 CurrentLanguage[4];\r
70 STRING_REF StringToken;\r
71\r
72 //\r
73 // Pre-allocate a buffer sufficient for us to work from.\r
74 //\r
75 FormBuffer = AllocateZeroPool (DEFAULT_FORM_BUFFER_SIZE);\r
76 if (FormBuffer == NULL) {\r
77 return EFI_OUT_OF_RESOURCES;\r
78 }\r
79\r
80 //\r
81 // Pre-allocate a buffer sufficient for us to work from.\r
82 //\r
83 StringBuffer = AllocateZeroPool (DEFAULT_STRING_BUFFER_SIZE);\r
84 if (StringBuffer == NULL) {\r
85 gBS->FreePool (FormBuffer);\r
86 return EFI_OUT_OF_RESOURCES;\r
87 }\r
88\r
89 //\r
90 // Obtain current language value\r
91 //\r
92 GetCurrentLanguage (CurrentLanguage);\r
93\r
94 //\r
95 // Add the FormSetTitle to the string buffer and get the StringToken\r
96 //\r
97 Status = AddString (*StringBuffer, CurrentLanguage, FormSetTitle, &StringToken);\r
98\r
99 if (EFI_ERROR (Status)) {\r
100 return Status;\r
101 }\r
102\r
103 //\r
104 // Initialize the Ifr Package header data\r
105 //\r
106 IfrPack.Header.Length = sizeof (EFI_HII_PACK_HEADER) + sizeof (EFI_IFR_FORM_SET) + sizeof (EFI_IFR_END_FORM_SET);\r
107 IfrPack.Header.Type = EFI_HII_IFR;\r
108\r
109 //\r
110 // Initialize FormSet with the appropriate information\r
111 //\r
112 FormSet.Header.OpCode = EFI_IFR_FORM_SET_OP;\r
113 FormSet.Header.Length = sizeof (EFI_IFR_FORM_SET);\r
114 FormSet.FormSetTitle = StringToken;\r
115 FormSet.Class = Class;\r
116 FormSet.SubClass = SubClass;\r
117 CopyMem (&FormSet.Guid, Guid, sizeof (EFI_GUID));\r
118\r
119 //\r
120 // Initialize the end formset data\r
121 //\r
122 EndFormSet.Header.Length = sizeof (EFI_IFR_END_FORM_SET);\r
123 EndFormSet.Header.OpCode = EFI_IFR_END_FORM_SET_OP;\r
124\r
125 Destination = (UINT8 *) *FormBuffer;\r
126\r
127 //\r
128 // Copy the formset/endformset data to the form buffer\r
129 //\r
130 CopyMem (Destination, &IfrPack, sizeof (EFI_HII_PACK_HEADER));\r
131\r
132 Destination = Destination + sizeof (EFI_HII_PACK_HEADER);\r
133\r
134 CopyMem (Destination, &FormSet, sizeof (EFI_IFR_FORM_SET));\r
135\r
136 Destination = Destination + sizeof (EFI_IFR_FORM_SET);\r
137\r
138 CopyMem (Destination, &EndFormSet, sizeof (EFI_IFR_END_FORM_SET));\r
139 return EFI_SUCCESS;\r
140}\r
141\r
142\r
143EFI_STATUS\r
144CreateForm (\r
145 IN CHAR16 *FormTitle,\r
146 IN UINT16 FormId,\r
147 IN OUT VOID *FormBuffer,\r
148 IN OUT VOID *StringBuffer\r
149 )\r
150/*++\r
151\r
152Routine Description:\r
153\r
154 Create a form\r
155 \r
156Arguments:\r
157 \r
158 FormTitle - Title of the form\r
159 \r
160 FormId - Id of the form\r
161 \r
162 FormBuffer - Pointer of the form created\r
163 \r
164 StringBuffer - Pointer of FormTitil string created\r
165 \r
166Returns: \r
167\r
168 EFI_SUCCESS - Form successfully created\r
169\r
170--*/\r
171{\r
172 EFI_STATUS Status;\r
173 EFI_IFR_FORM Form;\r
174 EFI_IFR_END_FORM EndForm;\r
175 CHAR16 CurrentLanguage[4];\r
176 STRING_REF StringToken;\r
177\r
178 //\r
179 // Obtain current language value\r
180 //\r
181 GetCurrentLanguage (CurrentLanguage);\r
182\r
183 Status = AddString (StringBuffer, CurrentLanguage, FormTitle, &StringToken);\r
184\r
185 if (EFI_ERROR (Status)) {\r
186 return Status;\r
187 }\r
188\r
189 Form.Header.OpCode = EFI_IFR_FORM_OP;\r
190 Form.Header.Length = sizeof (EFI_IFR_FORM);\r
191 Form.FormId = FormId;\r
192 Form.FormTitle = StringToken;\r
193\r
194 Status = AddOpCode (FormBuffer, &Form);\r
195\r
196 if (EFI_ERROR (Status)) {\r
197 return Status;\r
198 }\r
199\r
200 EndForm.Header.OpCode = EFI_IFR_END_FORM_OP;\r
201 EndForm.Header.Length = sizeof (EFI_IFR_END_FORM);\r
202\r
203 Status = AddOpCode (FormBuffer, &EndForm);\r
204\r
205 if (EFI_ERROR (Status)) {\r
206 return Status;\r
207 }\r
208\r
209 return EFI_SUCCESS;\r
210}\r
211\r
212\r
213EFI_STATUS\r
214CreateSubTitle (\r
215 IN CHAR16 *SubTitle,\r
216 IN OUT VOID *FormBuffer,\r
217 IN OUT VOID *StringBuffer\r
218 )\r
219/*++\r
220\r
221Routine Description:\r
222\r
223 Create a SubTitle\r
224 \r
225Arguments:\r
226 \r
227 SubTitle - Sub title to be created\r
228 \r
229 FormBuffer - Where this subtitle to add to\r
230 \r
231 StringBuffer - String buffer created for subtitle\r
232 \r
233Returns: \r
234\r
235 EFI_SUCCESS - Subtitle successfully created\r
236\r
237--*/\r
238{\r
239 EFI_STATUS Status;\r
240 EFI_IFR_SUBTITLE Subtitle;\r
241 CHAR16 CurrentLanguage[4];\r
242 STRING_REF StringToken;\r
243\r
244 //\r
245 // Obtain current language value\r
246 //\r
247 GetCurrentLanguage (CurrentLanguage);\r
248\r
249 Status = AddString (StringBuffer, CurrentLanguage, SubTitle, &StringToken);\r
250\r
251 if (EFI_ERROR (Status)) {\r
252 return Status;\r
253 }\r
254\r
255 Subtitle.Header.OpCode = EFI_IFR_SUBTITLE_OP;\r
256 Subtitle.Header.Length = sizeof (EFI_IFR_SUBTITLE);\r
257 Subtitle.SubTitle = StringToken;\r
258\r
259 Status = AddOpCode (FormBuffer, &Subtitle);\r
260\r
261 if (EFI_ERROR (Status)) {\r
262 return Status;\r
263 }\r
264\r
265 return EFI_SUCCESS;\r
266}\r
267\r
268\r
269EFI_STATUS\r
270CreateText (\r
271 IN CHAR16 *String,\r
272 IN CHAR16 *String2,\r
273 IN CHAR16 *String3,\r
274 IN UINT8 Flags,\r
275 IN UINT16 Key,\r
276 IN OUT VOID *FormBuffer,\r
277 IN OUT VOID *StringBuffer\r
278 )\r
279/*++\r
280\r
281Routine Description:\r
282\r
283 Create a line of text\r
284 \r
285Arguments:\r
286 \r
287 String - First string of the text\r
288 \r
289 String2 - Second string of the text\r
290 \r
291 String3 - Help string of the text\r
292 \r
293 Flags - Flag of the text\r
294 \r
295 Key - Key of the text\r
296 \r
297 FormBuffer - The form where this text adds to\r
298 \r
299 StringBuffer - String buffer created for String, String2 and String3\r
300 \r
301Returns: \r
302\r
303 EFI_SUCCESS - Text successfully created\r
304\r
305--*/\r
306{\r
307 EFI_STATUS Status;\r
308 EFI_IFR_TEXT Text;\r
309 CHAR16 CurrentLanguage[4];\r
310 STRING_REF StringToken;\r
311\r
312 //\r
313 // Obtain current language value\r
314 //\r
315 GetCurrentLanguage (CurrentLanguage);\r
316\r
317 //\r
318 // Add first string, get first string's token\r
319 //\r
320 Status = AddString (StringBuffer, CurrentLanguage, String, &StringToken);\r
321\r
322 if (EFI_ERROR (Status)) {\r
323 return Status;\r
324 }\r
325\r
326 Text.Header.OpCode = EFI_IFR_TEXT_OP;\r
327 Text.Header.Length = sizeof (EFI_IFR_TEXT);\r
328 Text.Text = StringToken;\r
329\r
330 //\r
331 // Add second string, get first string's token\r
332 //\r
333 Status = AddString (StringBuffer, CurrentLanguage, String2, &StringToken);\r
334\r
335 if (EFI_ERROR (Status)) {\r
336 return Status;\r
337 }\r
338\r
339 Text.TextTwo = StringToken;\r
340\r
341 Text.Flags = (UINT8) (Flags | EFI_IFR_FLAG_CREATED);\r
342 Text.Key = Key;\r
343\r
344 //\r
345 // Add second string, get first string's token\r
346 //\r
347 Status = AddString (StringBuffer, CurrentLanguage, String3, &StringToken);\r
348\r
349 if (EFI_ERROR (Status)) {\r
350 return Status;\r
351 }\r
352\r
353 Text.Help = StringToken;\r
354\r
355 Status = AddOpCode (FormBuffer, &Text);\r
356\r
357 if (EFI_ERROR (Status)) {\r
358 return Status;\r
359 }\r
360\r
361 return EFI_SUCCESS;\r
362}\r
363\r
364\r
365EFI_STATUS\r
366CreateGoto (\r
367 IN UINT16 FormId,\r
368 IN CHAR16 *Prompt,\r
369 IN OUT VOID *FormBuffer,\r
370 IN OUT VOID *StringBuffer\r
371 )\r
372/*++\r
373\r
374Routine Description:\r
375\r
376 Create a hyperlink\r
377 \r
378Arguments:\r
379 \r
380 FormId - Form ID of the hyperlink\r
381 \r
382 Prompt - Prompt of the hyperlink\r
383 \r
384 FormBuffer - The form where this hyperlink adds to\r
385 \r
386 StringBuffer - String buffer created for Prompt\r
387 \r
388Returns: \r
389\r
390 EFI_SUCCESS - Hyperlink successfully created\r
391\r
392--*/\r
393{\r
394 EFI_STATUS Status;\r
395 EFI_IFR_REF Hyperlink;\r
396 CHAR16 CurrentLanguage[4];\r
397 STRING_REF StringToken;\r
398\r
399 //\r
400 // Obtain current language value\r
401 //\r
402 GetCurrentLanguage (CurrentLanguage);\r
403\r
404 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);\r
405\r
406 if (EFI_ERROR (Status)) {\r
407 return Status;\r
408 }\r
409\r
410 Hyperlink.Header.OpCode = EFI_IFR_REF_OP;\r
411 Hyperlink.Header.Length = sizeof (EFI_IFR_REF);\r
412 Hyperlink.FormId = FormId;\r
413 Hyperlink.Prompt = StringToken;\r
414\r
415 Status = AddOpCode (FormBuffer, &Hyperlink);\r
416\r
417 if (EFI_ERROR (Status)) {\r
418 return Status;\r
419 }\r
420\r
421 return EFI_SUCCESS;\r
422}\r
423\r
424\r
425EFI_STATUS\r
426CreateOneOf (\r
427 IN UINT16 QuestionId,\r
428 IN UINT8 DataWidth,\r
429 IN CHAR16 *Prompt,\r
430 IN CHAR16 *Help,\r
431 IN IFR_OPTION *OptionsList,\r
432 IN UINTN OptionCount,\r
433 IN OUT VOID *FormBuffer,\r
434 IN OUT VOID *StringBuffer\r
435 )\r
436/*++\r
437\r
438Routine Description:\r
439\r
440 Create a one-of question with a set of options to choose from. The\r
441 OptionsList is a pointer to a null-terminated list of option descriptions.\r
442 \r
443Arguments:\r
444 \r
445 QuestionId - Question ID of the one-of box\r
446 \r
447 DataWidth - DataWidth of the one-of box\r
448 \r
449 Prompt - Prompt of the one-of box\r
450 \r
451 Help - Help of the one-of box\r
452 \r
453 OptionsList - Each string in it is an option of the one-of box\r
454 \r
455 OptionCount - Option string count\r
456 \r
457 FormBuffer - The form where this one-of box adds to\r
458 \r
459 StringBuffer - String buffer created for Prompt, Help and Option strings\r
460 \r
461Returns: \r
462\r
463 EFI_DEVICE_ERROR - DataWidth > 2\r
464\r
465 EFI_SUCCESS - One-Of box successfully created.\r
466\r
467--*/\r
468{\r
469 EFI_STATUS Status;\r
470 UINTN Index;\r
471 EFI_IFR_ONE_OF OneOf;\r
472 EFI_IFR_ONE_OF_OPTION OneOfOption;\r
473 EFI_IFR_END_ONE_OF EndOneOf;\r
474 CHAR16 CurrentLanguage[4];\r
475 STRING_REF StringToken;\r
476\r
477 //\r
478 // We do not create op-code storage widths for one-of in excess of 16 bits for now\r
479 //\r
480 if (DataWidth > 2) {\r
481 return EFI_DEVICE_ERROR;\r
482 }\r
483\r
484 //\r
485 // Obtain current language value\r
486 //\r
487 GetCurrentLanguage (CurrentLanguage);\r
488\r
489 //\r
490 // Add first string, get first string's token\r
491 //\r
492 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);\r
493\r
494 if (EFI_ERROR (Status)) {\r
495 return Status;\r
496 }\r
497\r
498 OneOf.Header.OpCode = EFI_IFR_ONE_OF_OP;\r
499 OneOf.Header.Length = sizeof (EFI_IFR_ONE_OF);\r
500 OneOf.QuestionId = QuestionId;\r
501 OneOf.Width = DataWidth;\r
502 OneOf.Prompt = StringToken;\r
503\r
504 //\r
505 // Add second string, get first string's token\r
506 //\r
507 Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);\r
508\r
509 if (EFI_ERROR (Status)) {\r
510 return Status;\r
511 }\r
512\r
513 OneOf.Help = StringToken;\r
514\r
515 Status = AddOpCode (FormBuffer, &OneOf);\r
516\r
517 if (EFI_ERROR (Status)) {\r
518 return Status;\r
519 }\r
520\r
521 for (Index = 0; Index < OptionCount; Index++) {\r
522 OneOfOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP;\r
523 OneOfOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION);\r
524\r
525 //\r
526 // Add string and get token back\r
527 //\r
528 Status = AddString (StringBuffer, CurrentLanguage, OptionsList[Index].OptionString, &StringToken);\r
529\r
530 OneOfOption.Option = StringToken;\r
531 OneOfOption.Value = OptionsList[Index].Value;\r
532 OneOfOption.Flags = (UINT8) (OptionsList[Index].Flags | EFI_IFR_FLAG_CREATED);\r
533 OneOfOption.Key = OptionsList[Index].Key;\r
534\r
535 Status = AddOpCode (FormBuffer, &OneOfOption);\r
536\r
537 if (EFI_ERROR (Status)) {\r
538 return Status;\r
539 }\r
540 }\r
541\r
542 EndOneOf.Header.Length = sizeof (EFI_IFR_END_ONE_OF);\r
543 EndOneOf.Header.OpCode = EFI_IFR_END_ONE_OF_OP;\r
544\r
545 Status = AddOpCode (FormBuffer, &EndOneOf);\r
546\r
547 if (EFI_ERROR (Status)) {\r
548 return Status;\r
549 }\r
550\r
551 return EFI_SUCCESS;\r
552}\r
553\r
554EFI_STATUS\r
555CreateOrderedList (\r
556 IN UINT16 QuestionId,\r
557 IN UINT8 MaxEntries,\r
558 IN CHAR16 *Prompt,\r
559 IN CHAR16 *Help,\r
560 IN IFR_OPTION *OptionsList,\r
561 IN UINTN OptionCount,\r
562 IN OUT VOID *FormBuffer,\r
563 IN OUT VOID *StringBuffer\r
564 )\r
565/*++\r
566\r
567Routine Description:\r
568\r
569 Create a one-of question with a set of options to choose from. The\r
570 OptionsList is a pointer to a null-terminated list of option descriptions.\r
571 \r
572Arguments:\r
573 \r
574 QuestionId - Question ID of the ordered list\r
575 \r
576 MaxEntries - MaxEntries of the ordered list\r
577 \r
578 Prompt - Prompt of the ordered list\r
579 \r
580 Help - Help of the ordered list\r
581 \r
582 OptionsList - Each string in it is an option of the ordered list\r
583 \r
584 OptionCount - Option string count\r
585 \r
586 FormBuffer - The form where this ordered list adds to\r
587 \r
588 StringBuffer - String buffer created for Prompt, Help and Option strings\r
589 \r
590Returns: \r
591\r
592 EFI_SUCCESS - Ordered list successfully created.\r
593\r
594--*/\r
595{\r
596 EFI_STATUS Status;\r
597 UINTN Index;\r
598 EFI_IFR_ORDERED_LIST OrderedList;\r
599 EFI_IFR_ONE_OF_OPTION OrderedListOption;\r
600 EFI_IFR_END_ONE_OF EndOrderedList;\r
601 CHAR16 CurrentLanguage[4];\r
602 STRING_REF StringToken;\r
603\r
604 //\r
605 // Obtain current language value\r
606 //\r
607 GetCurrentLanguage (CurrentLanguage);\r
608\r
609 //\r
610 // Add first string, get first string's token\r
611 //\r
612 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);\r
613\r
614 if (EFI_ERROR (Status)) {\r
615 return Status;\r
616 }\r
617\r
618 OrderedList.Header.OpCode = EFI_IFR_ORDERED_LIST_OP;\r
619 OrderedList.Header.Length = sizeof (EFI_IFR_ORDERED_LIST);\r
620 OrderedList.QuestionId = QuestionId;\r
621 OrderedList.MaxEntries = MaxEntries;\r
622 OrderedList.Prompt = StringToken;\r
623\r
624 //\r
625 // Add second string, get first string's token\r
626 //\r
627 Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);\r
628\r
629 if (EFI_ERROR (Status)) {\r
630 return Status;\r
631 }\r
632\r
633 OrderedList.Help = StringToken;\r
634\r
635 Status = AddOpCode (FormBuffer, &OrderedList);\r
636\r
637 if (EFI_ERROR (Status)) {\r
638 return Status;\r
639 }\r
640\r
641 for (Index = 0; Index < OptionCount; Index++) {\r
642 OrderedListOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP;\r
643 OrderedListOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION);\r
644\r
645 //\r
646 // Add string and get token back\r
647 //\r
648 Status = AddString (StringBuffer, CurrentLanguage, OptionsList[Index].OptionString, &StringToken);\r
649\r
650 OrderedListOption.Option = StringToken;\r
651 OrderedListOption.Value = OptionsList[Index].Value;\r
652 OrderedListOption.Flags = (UINT8) (OptionsList[Index].Flags | EFI_IFR_FLAG_CREATED);\r
653 OrderedListOption.Key = OptionsList[Index].Key;\r
654\r
655 Status = AddOpCode (FormBuffer, &OrderedListOption);\r
656\r
657 if (EFI_ERROR (Status)) {\r
658 return Status;\r
659 }\r
660 }\r
661\r
662 EndOrderedList.Header.Length = sizeof (EFI_IFR_END_ONE_OF);\r
663 EndOrderedList.Header.OpCode = EFI_IFR_END_ONE_OF_OP;\r
664\r
665 Status = AddOpCode (FormBuffer, &EndOrderedList);\r
666\r
667 if (EFI_ERROR (Status)) {\r
668 return Status;\r
669 }\r
670\r
671 return EFI_SUCCESS;\r
672}\r
673\r
674\r
675EFI_STATUS\r
676CreateCheckBox (\r
677 IN UINT16 QuestionId,\r
678 IN UINT8 DataWidth,\r
679 IN CHAR16 *Prompt,\r
680 IN CHAR16 *Help,\r
681 IN UINT8 Flags,\r
682 IN OUT VOID *FormBuffer,\r
683 IN OUT VOID *StringBuffer\r
684 )\r
685/*++\r
686\r
687Routine Description:\r
688\r
689 Create a checkbox\r
690 \r
691Arguments:\r
692 \r
693 QuestionId - Question ID of the check box\r
694 \r
695 DataWidth - DataWidth of the check box\r
696 \r
697 Prompt - Prompt of the check box\r
698 \r
699 Help - Help of the check box\r
700 \r
701 Flags - Flags of the check box\r
702 \r
703 FormBuffer - The form where this check box adds to\r
704 \r
705 StringBuffer - String buffer created for Prompt and Help.\r
706 \r
707Returns: \r
708\r
709 EFI_DEVICE_ERROR - DataWidth > 1\r
710\r
711 EFI_SUCCESS - Check box successfully created\r
712\r
713--*/\r
714{\r
715 EFI_STATUS Status;\r
716 EFI_IFR_CHECKBOX CheckBox;\r
717 CHAR16 CurrentLanguage[4];\r
718 STRING_REF StringToken;\r
719\r
720 //\r
721 // We do not create op-code storage widths for checkbox in excess of 8 bits for now\r
722 //\r
723 if (DataWidth > 1) {\r
724 return EFI_DEVICE_ERROR;\r
725 }\r
726\r
727 //\r
728 // Obtain current language value\r
729 //\r
730 GetCurrentLanguage (CurrentLanguage);\r
731\r
732 //\r
733 // Add first string, get first string's token\r
734 //\r
735 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);\r
736\r
737 if (EFI_ERROR (Status)) {\r
738 return Status;\r
739 }\r
740\r
741 CheckBox.Header.OpCode = EFI_IFR_CHECKBOX_OP;\r
742 CheckBox.Header.Length = sizeof (EFI_IFR_CHECKBOX);\r
743 CheckBox.QuestionId = QuestionId;\r
744 CheckBox.Width = DataWidth;\r
745 CheckBox.Prompt = StringToken;\r
746\r
747 //\r
748 // Add second string, get first string's token\r
749 //\r
750 Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);\r
751\r
752 if (EFI_ERROR (Status)) {\r
753 return Status;\r
754 }\r
755\r
756 CheckBox.Help = StringToken;\r
757 CheckBox.Flags = (UINT8) (Flags | EFI_IFR_FLAG_CREATED);\r
758\r
759 Status = AddOpCode (FormBuffer, &CheckBox);\r
760\r
761 if (EFI_ERROR (Status)) {\r
762 return Status;\r
763 }\r
764\r
765 return EFI_SUCCESS;\r
766}\r
767\r
768\r
769EFI_STATUS\r
770CreateNumeric (\r
771 IN UINT16 QuestionId,\r
772 IN UINT8 DataWidth,\r
773 IN CHAR16 *Prompt,\r
774 IN CHAR16 *Help,\r
775 IN UINT16 Minimum,\r
776 IN UINT16 Maximum,\r
777 IN UINT16 Step,\r
778 IN UINT16 Default,\r
779 IN UINT8 Flags,\r
780 IN UINT16 Key,\r
781 IN OUT VOID *FormBuffer,\r
782 IN OUT VOID *StringBuffer\r
783 )\r
784/*++\r
785\r
786Routine Description:\r
787\r
788 Create a numeric\r
789 \r
790Arguments:\r
791 \r
792 QuestionId - Question ID of the numeric\r
793 \r
794 DataWidth - DataWidth of the numeric\r
795 \r
796 Prompt - Prompt of the numeric\r
797 \r
798 Help - Help of the numeric\r
799 \r
800 Minimum - Minumun boundary of the numeric\r
801 \r
802 Maximum - Maximum boundary of the numeric\r
803 \r
804 Step - Step of the numeric\r
805 \r
806 Default - Default value\r
807 \r
808 Flags - Flags of the numeric\r
809 \r
810 Key - Key of the numeric\r
811 \r
812 FormBuffer - The form where this numeric adds to\r
813 \r
814 StringBuffer - String buffer created for Prompt and Help.\r
815 \r
816Returns: \r
817\r
818 EFI_DEVICE_ERROR - DataWidth > 2\r
819 \r
820 EFI_SUCCESS - Numeric is successfully created\r
821\r
822--*/\r
823{\r
824 EFI_STATUS Status;\r
825 EFI_IFR_NUMERIC Numeric;\r
826 CHAR16 CurrentLanguage[4];\r
827 STRING_REF StringToken;\r
828\r
829 //\r
830 // We do not create op-code storage widths for numerics in excess of 16 bits for now\r
831 //\r
832 if (DataWidth > 2) {\r
833 return EFI_DEVICE_ERROR;\r
834 }\r
835\r
836 //\r
837 // Obtain current language value\r
838 //\r
839 GetCurrentLanguage (CurrentLanguage);\r
840\r
841 //\r
842 // Add first string, get first string's token\r
843 //\r
844 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);\r
845\r
846 if (EFI_ERROR (Status)) {\r
847 return Status;\r
848 }\r
849\r
850 Numeric.Header.OpCode = EFI_IFR_NUMERIC_OP;\r
851 Numeric.Header.Length = sizeof (EFI_IFR_NUMERIC);\r
852 Numeric.QuestionId = QuestionId;\r
853 Numeric.Width = DataWidth;\r
854 Numeric.Prompt = StringToken;\r
855\r
856 //\r
857 // Add second string, get first string's token\r
858 //\r
859 Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);\r
860\r
861 if (EFI_ERROR (Status)) {\r
862 return Status;\r
863 }\r
864\r
865 Numeric.Help = StringToken;\r
866 Numeric.Minimum = Minimum;\r
867 Numeric.Maximum = Maximum;\r
868 Numeric.Step = Step;\r
869 Numeric.Default = Default;\r
870 Numeric.Flags = (UINT8) (Flags | EFI_IFR_FLAG_CREATED);\r
871 Numeric.Key = Key;\r
872\r
873 Status = AddOpCode (FormBuffer, &Numeric);\r
874\r
875 if (EFI_ERROR (Status)) {\r
876 return Status;\r
877 }\r
878\r
879 return EFI_SUCCESS;\r
880}\r
881\r
882\r
883EFI_STATUS\r
884CreateString (\r
885 IN UINT16 QuestionId,\r
886 IN UINT8 DataWidth,\r
887 IN CHAR16 *Prompt,\r
888 IN CHAR16 *Help,\r
889 IN UINT8 MinSize,\r
890 IN UINT8 MaxSize,\r
891 IN UINT8 Flags,\r
892 IN UINT16 Key,\r
893 IN OUT VOID *FormBuffer,\r
894 IN OUT VOID *StringBuffer\r
895 )\r
896/*++\r
897\r
898Routine Description:\r
899\r
900 Create a string\r
901 \r
902Arguments:\r
903 \r
904 QuestionId - Question ID of the string\r
905 \r
906 DataWidth - DataWidth of the string\r
907 \r
908 Prompt - Prompt of the string\r
909 \r
910 Help - Help of the string\r
911 \r
912 MinSize - Min size boundary of the string\r
913 \r
914 MaxSize - Max size boundary of the string\r
915 \r
916 Flags - Flags of the string\r
917 \r
918 Key - Key of the string\r
919 \r
920 FormBuffer - The form where this string adds to\r
921 \r
922 StringBuffer - String buffer created for Prompt and Help.\r
923 \r
924Returns: \r
925\r
926 EFI_SUCCESS - String successfully created.\r
927\r
928--*/\r
929{\r
930 EFI_STATUS Status;\r
931 EFI_IFR_STRING String;\r
932 CHAR16 CurrentLanguage[4];\r
933 STRING_REF StringToken;\r
934\r
935 //\r
936 // Obtain current language value\r
937 //\r
938 GetCurrentLanguage (CurrentLanguage);\r
939\r
940 //\r
941 // Add first string, get first string's token\r
942 //\r
943 Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);\r
944\r
945 if (EFI_ERROR (Status)) {\r
946 return Status;\r
947 }\r
948\r
949 String.Header.OpCode = EFI_IFR_STRING_OP;\r
950 String.Header.Length = sizeof (EFI_IFR_STRING);\r
951 String.QuestionId = QuestionId;\r
952 String.Width = DataWidth;\r
953 String.Prompt = StringToken;\r
954\r
955 //\r
956 // Add second string, get first string's token\r
957 //\r
958 Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);\r
959\r
960 if (EFI_ERROR (Status)) {\r
961 return Status;\r
962 }\r
963\r
964 String.Help = StringToken;\r
965 String.MinSize = MinSize;\r
966 String.MaxSize = MaxSize;\r
967 String.Flags = (UINT8) (Flags | EFI_IFR_FLAG_CREATED);\r
968 String.Key = Key;\r
969\r
970 Status = AddOpCode (FormBuffer, &String);\r
971\r
972 if (EFI_ERROR (Status)) {\r
973 return Status;\r
974 }\r
975\r
976 return EFI_SUCCESS;\r
977}\r