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