]>
Commit | Line | Data |
---|---|---|
c60a0616 | 1 | /** @file\r |
2 | Implementation for handling the User Interface option processing.\r | |
3 | \r | |
4 | \r | |
f0a1bf11 | 5 | Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 6 | This program and the accompanying materials\r |
c60a0616 | 7 | are licensed and made available under the terms and conditions of the BSD License\r |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
c60a0616 | 16 | #include "Setup.h"\r |
17 | \r | |
18 | \r | |
19 | /**\r | |
20 | Process Question Config.\r | |
21 | \r | |
22 | @param Selection The UI menu selection.\r | |
23 | @param Question The Question to be peocessed.\r | |
24 | \r | |
25 | @retval EFI_SUCCESS Question Config process success.\r | |
26 | @retval Other Question Config process fail.\r | |
27 | \r | |
28 | **/\r | |
29 | EFI_STATUS\r | |
30 | ProcessQuestionConfig (\r | |
31 | IN UI_MENU_SELECTION *Selection,\r | |
32 | IN FORM_BROWSER_STATEMENT *Question\r | |
33 | )\r | |
34 | {\r | |
35 | EFI_STATUS Status;\r | |
36 | CHAR16 *ConfigResp;\r | |
37 | CHAR16 *Progress;\r | |
38 | EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r | |
39 | \r | |
40 | if (Question->QuestionConfig == 0) {\r | |
41 | return EFI_SUCCESS;\r | |
42 | }\r | |
43 | \r | |
44 | //\r | |
45 | // Get <ConfigResp>\r | |
46 | //\r | |
47 | ConfigResp = GetToken (Question->QuestionConfig, Selection->FormSet->HiiHandle);\r | |
48 | if (ConfigResp == NULL) {\r | |
49 | return EFI_NOT_FOUND;\r | |
50 | }\r | |
51 | \r | |
52 | //\r | |
53 | // Send config to Configuration Driver\r | |
54 | //\r | |
55 | ConfigAccess = Selection->FormSet->ConfigAccess;\r | |
56 | if (ConfigAccess == NULL) {\r | |
57 | return EFI_UNSUPPORTED;\r | |
58 | }\r | |
59 | Status = ConfigAccess->RouteConfig (\r | |
60 | ConfigAccess,\r | |
61 | ConfigResp,\r | |
62 | &Progress\r | |
63 | );\r | |
64 | \r | |
65 | return Status;\r | |
66 | }\r | |
67 | \r | |
68 | \r | |
69 | /**\r | |
70 | Search an Option of a Question by its value.\r | |
71 | \r | |
72 | @param Question The Question\r | |
73 | @param OptionValue Value for Option to be searched.\r | |
74 | \r | |
75 | @retval Pointer Pointer to the found Option.\r | |
76 | @retval NULL Option not found.\r | |
77 | \r | |
78 | **/\r | |
79 | QUESTION_OPTION *\r | |
80 | ValueToOption (\r | |
81 | IN FORM_BROWSER_STATEMENT *Question,\r | |
82 | IN EFI_HII_VALUE *OptionValue\r | |
83 | )\r | |
84 | {\r | |
85 | LIST_ENTRY *Link;\r | |
86 | QUESTION_OPTION *Option;\r | |
87 | \r | |
88 | Link = GetFirstNode (&Question->OptionListHead);\r | |
89 | while (!IsNull (&Question->OptionListHead, Link)) {\r | |
90 | Option = QUESTION_OPTION_FROM_LINK (Link);\r | |
91 | \r | |
92 | if (CompareHiiValue (&Option->Value, OptionValue, NULL) == 0) {\r | |
93 | return Option;\r | |
94 | }\r | |
95 | \r | |
96 | Link = GetNextNode (&Question->OptionListHead, Link);\r | |
97 | }\r | |
98 | \r | |
99 | return NULL;\r | |
100 | }\r | |
101 | \r | |
102 | \r | |
d02847d3 | 103 | /**\r |
104 | Return data element in an Array by its Index.\r | |
105 | \r | |
106 | @param Array The data array.\r | |
107 | @param Type Type of the data in this array.\r | |
108 | @param Index Zero based index for data in this array.\r | |
109 | \r | |
110 | @retval Value The data to be returned\r | |
111 | \r | |
112 | **/\r | |
113 | UINT64\r | |
114 | GetArrayData (\r | |
115 | IN VOID *Array,\r | |
116 | IN UINT8 Type,\r | |
117 | IN UINTN Index\r | |
118 | )\r | |
119 | {\r | |
120 | UINT64 Data;\r | |
121 | \r | |
122 | ASSERT (Array != NULL);\r | |
123 | \r | |
124 | Data = 0;\r | |
125 | switch (Type) {\r | |
126 | case EFI_IFR_TYPE_NUM_SIZE_8:\r | |
127 | Data = (UINT64) *(((UINT8 *) Array) + Index);\r | |
128 | break;\r | |
129 | \r | |
130 | case EFI_IFR_TYPE_NUM_SIZE_16:\r | |
131 | Data = (UINT64) *(((UINT16 *) Array) + Index);\r | |
132 | break;\r | |
133 | \r | |
134 | case EFI_IFR_TYPE_NUM_SIZE_32:\r | |
135 | Data = (UINT64) *(((UINT32 *) Array) + Index);\r | |
136 | break;\r | |
137 | \r | |
138 | case EFI_IFR_TYPE_NUM_SIZE_64:\r | |
139 | Data = (UINT64) *(((UINT64 *) Array) + Index);\r | |
140 | break;\r | |
141 | \r | |
142 | default:\r | |
143 | break;\r | |
144 | }\r | |
145 | \r | |
146 | return Data;\r | |
147 | }\r | |
148 | \r | |
149 | \r | |
150 | /**\r | |
151 | Set value of a data element in an Array by its Index.\r | |
152 | \r | |
153 | @param Array The data array.\r | |
154 | @param Type Type of the data in this array.\r | |
155 | @param Index Zero based index for data in this array.\r | |
156 | @param Value The value to be set.\r | |
157 | \r | |
158 | **/\r | |
159 | VOID\r | |
160 | SetArrayData (\r | |
161 | IN VOID *Array,\r | |
162 | IN UINT8 Type,\r | |
163 | IN UINTN Index,\r | |
164 | IN UINT64 Value\r | |
165 | )\r | |
166 | {\r | |
167 | \r | |
168 | ASSERT (Array != NULL);\r | |
169 | \r | |
170 | switch (Type) {\r | |
171 | case EFI_IFR_TYPE_NUM_SIZE_8:\r | |
172 | *(((UINT8 *) Array) + Index) = (UINT8) Value;\r | |
173 | break;\r | |
174 | \r | |
175 | case EFI_IFR_TYPE_NUM_SIZE_16:\r | |
176 | *(((UINT16 *) Array) + Index) = (UINT16) Value;\r | |
177 | break;\r | |
178 | \r | |
179 | case EFI_IFR_TYPE_NUM_SIZE_32:\r | |
180 | *(((UINT32 *) Array) + Index) = (UINT32) Value;\r | |
181 | break;\r | |
182 | \r | |
183 | case EFI_IFR_TYPE_NUM_SIZE_64:\r | |
184 | *(((UINT64 *) Array) + Index) = (UINT64) Value;\r | |
185 | break;\r | |
186 | \r | |
187 | default:\r | |
188 | break;\r | |
189 | }\r | |
190 | }\r | |
191 | \r | |
192 | \r | |
c60a0616 | 193 | /**\r |
194 | Print Question Value according to it's storage width and display attributes.\r | |
195 | \r | |
196 | @param Question The Question to be printed.\r | |
197 | @param FormattedNumber Buffer for output string.\r | |
198 | @param BufferSize The FormattedNumber buffer size in bytes.\r | |
199 | \r | |
200 | @retval EFI_SUCCESS Print success.\r | |
201 | @retval EFI_BUFFER_TOO_SMALL Buffer size is not enough for formatted number.\r | |
202 | \r | |
203 | **/\r | |
204 | EFI_STATUS\r | |
205 | PrintFormattedNumber (\r | |
206 | IN FORM_BROWSER_STATEMENT *Question,\r | |
207 | IN OUT CHAR16 *FormattedNumber,\r | |
208 | IN UINTN BufferSize\r | |
209 | )\r | |
210 | {\r | |
211 | INT64 Value;\r | |
212 | CHAR16 *Format;\r | |
213 | EFI_HII_VALUE *QuestionValue;\r | |
214 | \r | |
215 | if (BufferSize < (21 * sizeof (CHAR16))) {\r | |
216 | return EFI_BUFFER_TOO_SMALL;\r | |
217 | }\r | |
218 | \r | |
219 | QuestionValue = &Question->HiiValue;\r | |
220 | \r | |
221 | Value = (INT64) QuestionValue->Value.u64;\r | |
222 | switch (Question->Flags & EFI_IFR_DISPLAY) {\r | |
223 | case EFI_IFR_DISPLAY_INT_DEC:\r | |
224 | switch (QuestionValue->Type) {\r | |
225 | case EFI_IFR_NUMERIC_SIZE_1:\r | |
226 | Value = (INT64) ((INT8) QuestionValue->Value.u8);\r | |
227 | break;\r | |
228 | \r | |
229 | case EFI_IFR_NUMERIC_SIZE_2:\r | |
230 | Value = (INT64) ((INT16) QuestionValue->Value.u16);\r | |
231 | break;\r | |
232 | \r | |
233 | case EFI_IFR_NUMERIC_SIZE_4:\r | |
234 | Value = (INT64) ((INT32) QuestionValue->Value.u32);\r | |
235 | break;\r | |
236 | \r | |
237 | case EFI_IFR_NUMERIC_SIZE_8:\r | |
238 | default:\r | |
239 | break;\r | |
240 | }\r | |
241 | \r | |
242 | if (Value < 0) {\r | |
243 | Value = -Value;\r | |
244 | Format = L"-%ld";\r | |
245 | } else {\r | |
246 | Format = L"%ld";\r | |
247 | }\r | |
248 | break;\r | |
249 | \r | |
250 | case EFI_IFR_DISPLAY_UINT_DEC:\r | |
251 | Format = L"%ld";\r | |
252 | break;\r | |
253 | \r | |
254 | case EFI_IFR_DISPLAY_UINT_HEX:\r | |
255 | Format = L"%lx";\r | |
256 | break;\r | |
257 | \r | |
258 | default:\r | |
259 | return EFI_UNSUPPORTED;\r | |
260 | break;\r | |
261 | }\r | |
262 | \r | |
263 | UnicodeSPrint (FormattedNumber, BufferSize, Format, Value);\r | |
264 | \r | |
265 | return EFI_SUCCESS;\r | |
266 | }\r | |
267 | \r | |
268 | \r | |
269 | /**\r | |
270 | Password may be stored as encrypted by Configuration Driver. When change a\r | |
271 | password, user will be challenged with old password. To validate user input old\r | |
272 | password, we will send the clear text to Configuration Driver via Callback().\r | |
273 | Configuration driver is responsible to check the passed in password and return\r | |
274 | the validation result. If validation pass, state machine in password Callback()\r | |
275 | will transit from BROWSER_STATE_VALIDATE_PASSWORD to BROWSER_STATE_SET_PASSWORD.\r | |
276 | After user type in new password twice, Callback() will be invoked to send the\r | |
277 | new password to Configuration Driver.\r | |
278 | \r | |
279 | @param Selection Pointer to UI_MENU_SELECTION.\r | |
280 | @param MenuOption The MenuOption for this password Question.\r | |
281 | @param String The clear text of password.\r | |
282 | \r | |
283 | @retval EFI_NOT_AVAILABLE_YET Callback() request to terminate password input.\r | |
284 | @return In state of BROWSER_STATE_VALIDATE_PASSWORD:\r | |
285 | @retval EFI_SUCCESS Password correct, Browser will prompt for new\r | |
286 | password.\r | |
287 | @retval EFI_NOT_READY Password incorrect, Browser will show error\r | |
288 | message.\r | |
289 | @retval Other Browser will do nothing.\r | |
290 | @return In state of BROWSER_STATE_SET_PASSWORD:\r | |
291 | @retval EFI_SUCCESS Set password success.\r | |
292 | @retval Other Set password failed.\r | |
293 | \r | |
294 | **/\r | |
295 | EFI_STATUS\r | |
296 | PasswordCallback (\r | |
297 | IN UI_MENU_SELECTION *Selection,\r | |
298 | IN UI_MENU_OPTION *MenuOption,\r | |
299 | IN CHAR16 *String\r | |
300 | )\r | |
301 | {\r | |
302 | EFI_STATUS Status;\r | |
303 | EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r | |
304 | EFI_BROWSER_ACTION_REQUEST ActionRequest;\r | |
e2100bfa | 305 | EFI_IFR_TYPE_VALUE IfrTypeValue;\r |
c60a0616 | 306 | \r |
c60a0616 | 307 | ConfigAccess = Selection->FormSet->ConfigAccess;\r |
308 | if (ConfigAccess == NULL) {\r | |
309 | return EFI_UNSUPPORTED;\r | |
310 | }\r | |
311 | \r | |
312 | //\r | |
313 | // Prepare password string in HII database\r | |
314 | //\r | |
315 | if (String != NULL) {\r | |
e2100bfa | 316 | IfrTypeValue.string = NewString (String, Selection->FormSet->HiiHandle);\r |
c60a0616 | 317 | } else {\r |
e2100bfa | 318 | IfrTypeValue.string = 0;\r |
c60a0616 | 319 | }\r |
320 | \r | |
321 | //\r | |
322 | // Send password to Configuration Driver for validation\r | |
323 | //\r | |
324 | Status = ConfigAccess->Callback (\r | |
325 | ConfigAccess,\r | |
326 | EFI_BROWSER_ACTION_CHANGING,\r | |
327 | MenuOption->ThisTag->QuestionId,\r | |
e2100bfa ED |
328 | MenuOption->ThisTag->HiiValue.Type,\r |
329 | &IfrTypeValue,\r | |
c60a0616 | 330 | &ActionRequest\r |
331 | );\r | |
332 | \r | |
333 | //\r | |
334 | // Remove password string from HII database\r | |
335 | //\r | |
336 | if (String != NULL) {\r | |
e2100bfa | 337 | DeleteString (IfrTypeValue.string, Selection->FormSet->HiiHandle);\r |
c60a0616 | 338 | }\r |
339 | \r | |
340 | return Status;\r | |
341 | }\r | |
342 | \r | |
343 | \r | |
344 | /**\r | |
345 | Display error message for invalid password.\r | |
346 | \r | |
347 | **/\r | |
348 | VOID\r | |
349 | PasswordInvalid (\r | |
350 | VOID\r | |
351 | )\r | |
352 | {\r | |
353 | EFI_INPUT_KEY Key;\r | |
354 | \r | |
355 | //\r | |
356 | // Invalid password, prompt error message\r | |
357 | //\r | |
358 | do {\r | |
359 | CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gPassowordInvalid, gPressEnter, gEmptyString);\r | |
360 | } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r | |
361 | }\r | |
362 | \r | |
363 | \r | |
364 | /**\r | |
365 | Process a Question's Option (whether selected or un-selected).\r | |
366 | \r | |
367 | @param Selection Pointer to UI_MENU_SELECTION.\r | |
368 | @param MenuOption The MenuOption for this Question.\r | |
369 | @param Selected TRUE: if Question is selected.\r | |
370 | @param OptionString Pointer of the Option String to be displayed.\r | |
371 | \r | |
372 | @retval EFI_SUCCESS Question Option process success.\r | |
373 | @retval Other Question Option process fail.\r | |
374 | \r | |
375 | **/\r | |
376 | EFI_STATUS\r | |
377 | ProcessOptions (\r | |
378 | IN UI_MENU_SELECTION *Selection,\r | |
379 | IN UI_MENU_OPTION *MenuOption,\r | |
380 | IN BOOLEAN Selected,\r | |
381 | OUT CHAR16 **OptionString\r | |
382 | )\r | |
383 | {\r | |
384 | EFI_STATUS Status;\r | |
385 | CHAR16 *StringPtr;\r | |
386 | CHAR16 *TempString;\r | |
387 | UINTN Index;\r | |
388 | FORM_BROWSER_STATEMENT *Question;\r | |
389 | CHAR16 FormattedNumber[21];\r | |
390 | UINT16 Number;\r | |
391 | CHAR16 Character[2];\r | |
392 | EFI_INPUT_KEY Key;\r | |
393 | UINTN BufferSize;\r | |
394 | QUESTION_OPTION *OneOfOption;\r | |
395 | LIST_ENTRY *Link;\r | |
396 | EFI_HII_VALUE HiiValue;\r | |
397 | EFI_HII_VALUE *QuestionValue;\r | |
398 | BOOLEAN Suppress;\r | |
399 | UINT16 Maximum;\r | |
8d00a0f1 | 400 | QUESTION_OPTION *Option;\r |
401 | UINTN Index2;\r | |
d02847d3 | 402 | UINT8 *ValueArray;\r |
403 | UINT8 ValueType;\r | |
e2100bfa | 404 | EFI_STRING_ID StringId;\r |
c60a0616 | 405 | \r |
406 | Status = EFI_SUCCESS;\r | |
407 | \r | |
408 | StringPtr = NULL;\r | |
409 | Character[1] = L'\0';\r | |
410 | *OptionString = NULL;\r | |
e2100bfa | 411 | StringId = 0;\r |
c60a0616 | 412 | \r |
413 | ZeroMem (FormattedNumber, 21 * sizeof (CHAR16));\r | |
414 | BufferSize = (gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow;\r | |
415 | \r | |
416 | Question = MenuOption->ThisTag;\r | |
417 | QuestionValue = &Question->HiiValue;\r | |
418 | Maximum = (UINT16) Question->Maximum;\r | |
419 | \r | |
d02847d3 | 420 | ValueArray = Question->BufferValue;\r |
421 | ValueType = Question->ValueType;\r | |
422 | \r | |
c60a0616 | 423 | switch (Question->Operand) {\r |
424 | case EFI_IFR_ORDERED_LIST_OP:\r | |
b86b413a LG |
425 | //\r |
426 | // Check whether there are Options of this OrderedList\r | |
427 | //\r | |
428 | if (IsListEmpty (&Question->OptionListHead)) {\r | |
429 | break;\r | |
430 | }\r | |
c60a0616 | 431 | //\r |
432 | // Initialize Option value array\r | |
433 | //\r | |
d02847d3 | 434 | if (GetArrayData (ValueArray, ValueType, 0) == 0) {\r |
c60a0616 | 435 | GetQuestionDefault (Selection->FormSet, Selection->Form, Question, 0);\r |
436 | }\r | |
437 | \r | |
438 | if (Selected) {\r | |
439 | //\r | |
440 | // Go ask for input\r | |
441 | //\r | |
442 | Status = GetSelectionInputPopUp (Selection, MenuOption);\r | |
443 | } else {\r | |
444 | //\r | |
445 | // We now know how many strings we will have, so we can allocate the\r | |
446 | // space required for the array or strings.\r | |
447 | //\r | |
448 | *OptionString = AllocateZeroPool (Question->MaxContainers * BufferSize);\r | |
449 | ASSERT (*OptionString);\r | |
450 | \r | |
d02847d3 | 451 | HiiValue.Type = ValueType;\r |
c60a0616 | 452 | HiiValue.Value.u64 = 0;\r |
453 | for (Index = 0; Index < Question->MaxContainers; Index++) {\r | |
d02847d3 | 454 | HiiValue.Value.u64 = GetArrayData (ValueArray, ValueType, Index);\r |
455 | if (HiiValue.Value.u64 == 0) {\r | |
c60a0616 | 456 | //\r |
457 | // Values for the options in ordered lists should never be a 0\r | |
458 | //\r | |
459 | break;\r | |
460 | }\r | |
461 | \r | |
462 | OneOfOption = ValueToOption (Question, &HiiValue);\r | |
463 | if (OneOfOption == NULL) {\r | |
8d00a0f1 | 464 | //\r |
465 | // Show error message\r | |
466 | //\r | |
467 | do {\r | |
468 | CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gOptionMismatch, gPressEnter, gEmptyString);\r | |
469 | } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r | |
470 | \r | |
471 | //\r | |
472 | // The initial value of the orderedlist is invalid, force to be valid value\r | |
473 | //\r | |
474 | Link = GetFirstNode (&Question->OptionListHead);\r | |
475 | Index2 = 0;\r | |
476 | while (!IsNull (&Question->OptionListHead, Link) && Index2 < Question->MaxContainers) {\r | |
477 | Option = QUESTION_OPTION_FROM_LINK (Link);\r | |
d02847d3 | 478 | SetArrayData (ValueArray, ValueType, Index2, Option->Value.Value.u64);\r |
479 | Index2++;\r | |
8d00a0f1 | 480 | Link = GetNextNode (&Question->OptionListHead, Link);\r |
481 | }\r | |
d02847d3 | 482 | SetArrayData (ValueArray, ValueType, Index2, 0);\r |
8d00a0f1 | 483 | \r |
484 | Status = SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r | |
b18e7050 | 485 | UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r |
8d00a0f1 | 486 | \r |
f4113e1f | 487 | FreePool (*OptionString);\r |
8d00a0f1 | 488 | *OptionString = NULL;\r |
c60a0616 | 489 | return EFI_NOT_FOUND;\r |
490 | }\r | |
491 | \r | |
492 | Suppress = FALSE;\r | |
493 | if ((OneOfOption->SuppressExpression != NULL) &&\r | |
494 | (OneOfOption->SuppressExpression->Result.Value.b)) {\r | |
495 | //\r | |
496 | // This option is suppressed\r | |
497 | //\r | |
498 | Suppress = TRUE;\r | |
499 | }\r | |
500 | \r | |
501 | if (!Suppress) {\r | |
502 | Character[0] = LEFT_ONEOF_DELIMITER;\r | |
503 | NewStrCat (OptionString[0], Character);\r | |
504 | StringPtr = GetToken (OneOfOption->Text, Selection->Handle);\r | |
04eb20aa | 505 | ASSERT (StringPtr != NULL);\r |
c60a0616 | 506 | NewStrCat (OptionString[0], StringPtr);\r |
507 | Character[0] = RIGHT_ONEOF_DELIMITER;\r | |
508 | NewStrCat (OptionString[0], Character);\r | |
509 | Character[0] = CHAR_CARRIAGE_RETURN;\r | |
510 | NewStrCat (OptionString[0], Character);\r | |
511 | \r | |
f4113e1f | 512 | FreePool (StringPtr);\r |
c60a0616 | 513 | }\r |
514 | }\r | |
515 | }\r | |
516 | break;\r | |
517 | \r | |
518 | case EFI_IFR_ONE_OF_OP:\r | |
b86b413a LG |
519 | //\r |
520 | // Check whether there are Options of this OneOf\r | |
521 | //\r | |
522 | if (IsListEmpty (&Question->OptionListHead)) {\r | |
523 | break;\r | |
524 | }\r | |
c60a0616 | 525 | if (Selected) {\r |
526 | //\r | |
527 | // Go ask for input\r | |
528 | //\r | |
529 | Status = GetSelectionInputPopUp (Selection, MenuOption);\r | |
530 | } else {\r | |
531 | *OptionString = AllocateZeroPool (BufferSize);\r | |
532 | ASSERT (*OptionString);\r | |
533 | \r | |
534 | OneOfOption = ValueToOption (Question, QuestionValue);\r | |
535 | if (OneOfOption == NULL) {\r | |
8d00a0f1 | 536 | //\r |
537 | // Show error message\r | |
538 | //\r | |
539 | do {\r | |
540 | CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gOptionMismatch, gPressEnter, gEmptyString);\r | |
541 | } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r | |
542 | \r | |
543 | //\r | |
544 | // Force the Question value to be valid\r | |
545 | //\r | |
546 | Link = GetFirstNode (&Question->OptionListHead);\r | |
547 | while (!IsNull (&Question->OptionListHead, Link)) {\r | |
548 | Option = QUESTION_OPTION_FROM_LINK (Link);\r | |
549 | \r | |
550 | if ((Option->SuppressExpression == NULL) ||\r | |
551 | !Option->SuppressExpression->Result.Value.b) {\r | |
552 | CopyMem (QuestionValue, &Option->Value, sizeof (EFI_HII_VALUE));\r | |
553 | SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r | |
b18e7050 | 554 | UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r |
8d00a0f1 | 555 | break;\r |
556 | }\r | |
557 | \r | |
558 | Link = GetNextNode (&Question->OptionListHead, Link);\r | |
559 | }\r | |
560 | \r | |
f4113e1f | 561 | FreePool (*OptionString);\r |
8d00a0f1 | 562 | *OptionString = NULL;\r |
40a06b0c | 563 | return EFI_NOT_FOUND;\r |
c60a0616 | 564 | }\r |
565 | \r | |
566 | if ((OneOfOption->SuppressExpression != NULL) &&\r | |
567 | (OneOfOption->SuppressExpression->Result.Value.b)) {\r | |
568 | //\r | |
569 | // This option is suppressed\r | |
570 | //\r | |
571 | Suppress = TRUE;\r | |
572 | } else {\r | |
573 | Suppress = FALSE;\r | |
574 | }\r | |
575 | \r | |
576 | if (Suppress) {\r | |
577 | //\r | |
578 | // Current selected option happen to be suppressed,\r | |
579 | // enforce to select on a non-suppressed option\r | |
580 | //\r | |
581 | Link = GetFirstNode (&Question->OptionListHead);\r | |
582 | while (!IsNull (&Question->OptionListHead, Link)) {\r | |
583 | OneOfOption = QUESTION_OPTION_FROM_LINK (Link);\r | |
584 | \r | |
585 | if ((OneOfOption->SuppressExpression == NULL) ||\r | |
586 | !OneOfOption->SuppressExpression->Result.Value.b) {\r | |
587 | Suppress = FALSE;\r | |
588 | CopyMem (QuestionValue, &OneOfOption->Value, sizeof (EFI_HII_VALUE));\r | |
589 | SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r | |
b18e7050 | 590 | UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r |
f0a1bf11 | 591 | gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND);\r |
c60a0616 | 592 | break;\r |
593 | }\r | |
594 | \r | |
595 | Link = GetNextNode (&Question->OptionListHead, Link);\r | |
596 | }\r | |
597 | }\r | |
598 | \r | |
599 | if (!Suppress) {\r | |
600 | Character[0] = LEFT_ONEOF_DELIMITER;\r | |
601 | NewStrCat (OptionString[0], Character);\r | |
602 | StringPtr = GetToken (OneOfOption->Text, Selection->Handle);\r | |
04eb20aa | 603 | ASSERT (StringPtr != NULL);\r |
c60a0616 | 604 | NewStrCat (OptionString[0], StringPtr);\r |
605 | Character[0] = RIGHT_ONEOF_DELIMITER;\r | |
606 | NewStrCat (OptionString[0], Character);\r | |
607 | \r | |
f4113e1f | 608 | FreePool (StringPtr);\r |
c60a0616 | 609 | }\r |
610 | }\r | |
611 | break;\r | |
612 | \r | |
613 | case EFI_IFR_CHECKBOX_OP:\r | |
614 | *OptionString = AllocateZeroPool (BufferSize);\r | |
615 | ASSERT (*OptionString);\r | |
616 | \r | |
617 | *OptionString[0] = LEFT_CHECKBOX_DELIMITER;\r | |
618 | \r | |
619 | if (Selected) {\r | |
620 | //\r | |
621 | // Since this is a BOOLEAN operation, flip it upon selection\r | |
622 | //\r | |
623 | QuestionValue->Value.b = (BOOLEAN) (QuestionValue->Value.b ? FALSE : TRUE);\r | |
624 | \r | |
625 | //\r | |
626 | // Perform inconsistent check\r | |
627 | //\r | |
628 | Status = ValidateQuestion (Selection->FormSet, Selection->Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF);\r | |
629 | if (EFI_ERROR (Status)) {\r | |
630 | //\r | |
631 | // Inconsistent check fail, restore Question Value\r | |
632 | //\r | |
633 | QuestionValue->Value.b = (BOOLEAN) (QuestionValue->Value.b ? FALSE : TRUE);\r | |
f4113e1f | 634 | FreePool (*OptionString);\r |
8d00a0f1 | 635 | *OptionString = NULL;\r |
c60a0616 | 636 | return Status;\r |
637 | }\r | |
638 | \r | |
639 | //\r | |
640 | // Save Question value\r | |
641 | //\r | |
642 | Status = SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r | |
b18e7050 | 643 | UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r |
c60a0616 | 644 | }\r |
645 | \r | |
646 | if (QuestionValue->Value.b) {\r | |
647 | *(OptionString[0] + 1) = CHECK_ON;\r | |
648 | } else {\r | |
649 | *(OptionString[0] + 1) = CHECK_OFF;\r | |
650 | }\r | |
651 | *(OptionString[0] + 2) = RIGHT_CHECKBOX_DELIMITER;\r | |
652 | break;\r | |
653 | \r | |
654 | case EFI_IFR_NUMERIC_OP:\r | |
655 | if (Selected) {\r | |
656 | //\r | |
657 | // Go ask for input\r | |
658 | //\r | |
659 | Status = GetNumericInput (Selection, MenuOption);\r | |
660 | } else {\r | |
661 | *OptionString = AllocateZeroPool (BufferSize);\r | |
662 | ASSERT (*OptionString);\r | |
663 | \r | |
664 | *OptionString[0] = LEFT_NUMERIC_DELIMITER;\r | |
665 | \r | |
666 | //\r | |
667 | // Formatted print\r | |
668 | //\r | |
669 | PrintFormattedNumber (Question, FormattedNumber, 21 * sizeof (CHAR16));\r | |
670 | Number = (UINT16) GetStringWidth (FormattedNumber);\r | |
671 | CopyMem (OptionString[0] + 1, FormattedNumber, Number);\r | |
672 | \r | |
673 | *(OptionString[0] + Number / 2) = RIGHT_NUMERIC_DELIMITER;\r | |
674 | }\r | |
675 | break;\r | |
676 | \r | |
677 | case EFI_IFR_DATE_OP:\r | |
678 | if (Selected) {\r | |
679 | //\r | |
680 | // This is similar to numerics\r | |
681 | //\r | |
682 | Status = GetNumericInput (Selection, MenuOption);\r | |
683 | } else {\r | |
684 | *OptionString = AllocateZeroPool (BufferSize);\r | |
685 | ASSERT (*OptionString);\r | |
686 | \r | |
687 | switch (MenuOption->Sequence) {\r | |
688 | case 0:\r | |
689 | *OptionString[0] = LEFT_NUMERIC_DELIMITER;\r | |
690 | UnicodeSPrint (OptionString[0] + 1, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.date.Month);\r | |
691 | *(OptionString[0] + 3) = DATE_SEPARATOR;\r | |
692 | break;\r | |
693 | \r | |
694 | case 1:\r | |
695 | SetUnicodeMem (OptionString[0], 4, L' ');\r | |
696 | UnicodeSPrint (OptionString[0] + 4, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.date.Day);\r | |
697 | *(OptionString[0] + 6) = DATE_SEPARATOR;\r | |
698 | break;\r | |
699 | \r | |
700 | case 2:\r | |
701 | SetUnicodeMem (OptionString[0], 7, L' ');\r | |
4a6876b7 | 702 | UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"%04d", QuestionValue->Value.date.Year);\r |
c60a0616 | 703 | *(OptionString[0] + 11) = RIGHT_NUMERIC_DELIMITER;\r |
704 | break;\r | |
705 | }\r | |
706 | }\r | |
707 | break;\r | |
708 | \r | |
709 | case EFI_IFR_TIME_OP:\r | |
710 | if (Selected) {\r | |
711 | //\r | |
712 | // This is similar to numerics\r | |
713 | //\r | |
714 | Status = GetNumericInput (Selection, MenuOption);\r | |
715 | } else {\r | |
716 | *OptionString = AllocateZeroPool (BufferSize);\r | |
717 | ASSERT (*OptionString);\r | |
718 | \r | |
719 | switch (MenuOption->Sequence) {\r | |
720 | case 0:\r | |
721 | *OptionString[0] = LEFT_NUMERIC_DELIMITER;\r | |
722 | UnicodeSPrint (OptionString[0] + 1, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Hour);\r | |
723 | *(OptionString[0] + 3) = TIME_SEPARATOR;\r | |
724 | break;\r | |
725 | \r | |
726 | case 1:\r | |
727 | SetUnicodeMem (OptionString[0], 4, L' ');\r | |
728 | UnicodeSPrint (OptionString[0] + 4, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Minute);\r | |
729 | *(OptionString[0] + 6) = TIME_SEPARATOR;\r | |
730 | break;\r | |
731 | \r | |
732 | case 2:\r | |
733 | SetUnicodeMem (OptionString[0], 7, L' ');\r | |
734 | UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Second);\r | |
735 | *(OptionString[0] + 9) = RIGHT_NUMERIC_DELIMITER;\r | |
736 | break;\r | |
737 | }\r | |
738 | }\r | |
739 | break;\r | |
740 | \r | |
741 | case EFI_IFR_STRING_OP:\r | |
742 | if (Selected) {\r | |
743 | StringPtr = AllocateZeroPool ((Maximum + 1) * sizeof (CHAR16));\r | |
744 | ASSERT (StringPtr);\r | |
da588638 | 745 | CopyMem(StringPtr, Question->BufferValue, Maximum * sizeof (CHAR16));\r |
c60a0616 | 746 | \r |
747 | Status = ReadString (MenuOption, gPromptForData, StringPtr);\r | |
748 | if (!EFI_ERROR (Status)) {\r | |
e2100bfa ED |
749 | HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, StringPtr, NULL);\r |
750 | Status = ValidateQuestion(Selection->FormSet, Selection->Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF);\r | |
751 | if (EFI_ERROR (Status)) {\r | |
752 | HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL);\r | |
753 | } else {\r | |
754 | CopyMem (Question->BufferValue, StringPtr, Maximum * sizeof (CHAR16));\r | |
755 | SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r | |
c60a0616 | 756 | \r |
b18e7050 | 757 | UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r |
e2100bfa | 758 | }\r |
c60a0616 | 759 | }\r |
760 | \r | |
f4113e1f | 761 | FreePool (StringPtr);\r |
c60a0616 | 762 | } else {\r |
763 | *OptionString = AllocateZeroPool (BufferSize);\r | |
764 | ASSERT (*OptionString);\r | |
765 | \r | |
766 | if (((CHAR16 *) Question->BufferValue)[0] == 0x0000) {\r | |
767 | *(OptionString[0]) = '_';\r | |
768 | } else {\r | |
769 | if ((Maximum * sizeof (CHAR16)) < BufferSize) {\r | |
770 | BufferSize = Maximum * sizeof (CHAR16);\r | |
771 | }\r | |
772 | CopyMem (OptionString[0], (CHAR16 *) Question->BufferValue, BufferSize);\r | |
773 | }\r | |
774 | }\r | |
775 | break;\r | |
776 | \r | |
777 | case EFI_IFR_PASSWORD_OP:\r | |
778 | if (Selected) {\r | |
779 | StringPtr = AllocateZeroPool ((Maximum + 1) * sizeof (CHAR16));\r | |
780 | ASSERT (StringPtr);\r | |
781 | \r | |
782 | //\r | |
783 | // For interactive passwords, old password is validated by callback\r | |
784 | //\r | |
785 | if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r | |
786 | //\r | |
787 | // Use a NULL password to test whether old password is required\r | |
788 | //\r | |
789 | *StringPtr = 0;\r | |
790 | Status = PasswordCallback (Selection, MenuOption, StringPtr);\r | |
13ad1def | 791 | if (Status == EFI_NOT_AVAILABLE_YET || Status == EFI_UNSUPPORTED) {\r |
c60a0616 | 792 | //\r |
13ad1def | 793 | // Callback is not supported, or\r |
c60a0616 | 794 | // Callback request to terminate password input\r |
795 | //\r | |
f4113e1f | 796 | FreePool (StringPtr);\r |
c60a0616 | 797 | return EFI_SUCCESS;\r |
798 | }\r | |
799 | \r | |
800 | if (EFI_ERROR (Status)) {\r | |
801 | //\r | |
802 | // Old password exist, ask user for the old password\r | |
803 | //\r | |
804 | Status = ReadString (MenuOption, gPromptForPassword, StringPtr);\r | |
805 | if (EFI_ERROR (Status)) {\r | |
f4113e1f | 806 | FreePool (StringPtr);\r |
c60a0616 | 807 | return Status;\r |
808 | }\r | |
809 | \r | |
810 | //\r | |
811 | // Check user input old password\r | |
812 | //\r | |
813 | Status = PasswordCallback (Selection, MenuOption, StringPtr);\r | |
814 | if (EFI_ERROR (Status)) {\r | |
815 | if (Status == EFI_NOT_READY) {\r | |
816 | //\r | |
817 | // Typed in old password incorrect\r | |
818 | //\r | |
819 | PasswordInvalid ();\r | |
820 | } else {\r | |
821 | Status = EFI_SUCCESS;\r | |
822 | }\r | |
823 | \r | |
f4113e1f | 824 | FreePool (StringPtr);\r |
c60a0616 | 825 | return Status;\r |
826 | }\r | |
827 | }\r | |
828 | } else {\r | |
829 | //\r | |
830 | // For non-interactive password, validate old password in local\r | |
831 | //\r | |
832 | if (*((CHAR16 *) Question->BufferValue) != 0) {\r | |
833 | //\r | |
834 | // There is something there! Prompt for password\r | |
835 | //\r | |
836 | Status = ReadString (MenuOption, gPromptForPassword, StringPtr);\r | |
837 | if (EFI_ERROR (Status)) {\r | |
f4113e1f | 838 | FreePool (StringPtr);\r |
c60a0616 | 839 | return Status;\r |
840 | }\r | |
841 | \r | |
842 | TempString = AllocateCopyPool ((Maximum + 1) * sizeof (CHAR16), Question->BufferValue);\r | |
40a06b0c | 843 | ASSERT (TempString != NULL);\r |
8b0fc5c1 | 844 | \r |
c60a0616 | 845 | TempString[Maximum] = L'\0';\r |
846 | \r | |
847 | if (StrCmp (StringPtr, TempString) != 0) {\r | |
848 | //\r | |
849 | // Typed in old password incorrect\r | |
850 | //\r | |
851 | PasswordInvalid ();\r | |
852 | \r | |
f4113e1f | 853 | FreePool (StringPtr);\r |
854 | FreePool (TempString);\r | |
c60a0616 | 855 | return Status;\r |
856 | }\r | |
857 | \r | |
f4113e1f | 858 | FreePool (TempString);\r |
c60a0616 | 859 | }\r |
860 | }\r | |
861 | \r | |
862 | //\r | |
863 | // Ask for new password\r | |
864 | //\r | |
865 | ZeroMem (StringPtr, (Maximum + 1) * sizeof (CHAR16));\r | |
866 | Status = ReadString (MenuOption, gPromptForNewPassword, StringPtr);\r | |
867 | if (EFI_ERROR (Status)) {\r | |
868 | //\r | |
869 | // Reset state machine for interactive password\r | |
870 | //\r | |
871 | if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r | |
872 | PasswordCallback (Selection, MenuOption, NULL);\r | |
873 | }\r | |
874 | \r | |
f4113e1f | 875 | FreePool (StringPtr);\r |
c60a0616 | 876 | return Status;\r |
877 | }\r | |
878 | \r | |
879 | //\r | |
880 | // Confirm new password\r | |
881 | //\r | |
882 | TempString = AllocateZeroPool ((Maximum + 1) * sizeof (CHAR16));\r | |
883 | ASSERT (TempString);\r | |
884 | Status = ReadString (MenuOption, gConfirmPassword, TempString);\r | |
885 | if (EFI_ERROR (Status)) {\r | |
886 | //\r | |
887 | // Reset state machine for interactive password\r | |
888 | //\r | |
889 | if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r | |
890 | PasswordCallback (Selection, MenuOption, NULL);\r | |
891 | }\r | |
892 | \r | |
f4113e1f | 893 | FreePool (StringPtr);\r |
894 | FreePool (TempString);\r | |
c60a0616 | 895 | return Status;\r |
896 | }\r | |
897 | \r | |
898 | //\r | |
899 | // Compare two typed-in new passwords\r | |
900 | //\r | |
901 | if (StrCmp (StringPtr, TempString) == 0) {\r | |
902 | //\r | |
e2100bfa | 903 | // Prepare the Question->HiiValue.Value.string for ValidateQuestion use.\r |
c60a0616 | 904 | //\r |
e2100bfa ED |
905 | if((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r |
906 | StringId = Question->HiiValue.Value.string;\r | |
907 | Question->HiiValue.Value.string = NewString (StringPtr, Selection->FormSet->HiiHandle);\r | |
c60a0616 | 908 | } else {\r |
e2100bfa ED |
909 | HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, StringPtr, NULL);\r |
910 | }\r | |
911 | \r | |
912 | Status = ValidateQuestion(Selection->FormSet, Selection->Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF);\r | |
913 | \r | |
914 | //\r | |
915 | // Researve the Question->HiiValue.Value.string.\r | |
916 | //\r | |
917 | if((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r | |
918 | DeleteString(Question->HiiValue.Value.string, Selection->FormSet->HiiHandle);\r | |
919 | Question->HiiValue.Value.string = StringId;\r | |
920 | } \r | |
921 | \r | |
922 | if (EFI_ERROR (Status)) {\r | |
923 | //\r | |
924 | // Reset state machine for interactive password\r | |
925 | //\r | |
926 | if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r | |
927 | PasswordCallback (Selection, MenuOption, NULL);\r | |
928 | } else {\r | |
929 | //\r | |
930 | // Researve the Question->HiiValue.Value.string.\r | |
931 | //\r | |
932 | HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL); \r | |
933 | }\r | |
934 | } else {\r | |
935 | //\r | |
936 | // Two password match, send it to Configuration Driver\r | |
937 | //\r | |
938 | if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r | |
939 | PasswordCallback (Selection, MenuOption, StringPtr);\r | |
940 | } else {\r | |
941 | CopyMem (Question->BufferValue, StringPtr, Maximum * sizeof (CHAR16));\r | |
942 | SetQuestionValue (Selection->FormSet, Selection->Form, Question, FALSE);\r | |
943 | }\r | |
c60a0616 | 944 | }\r |
945 | } else {\r | |
946 | //\r | |
947 | // Reset state machine for interactive password\r | |
948 | //\r | |
949 | if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r | |
950 | PasswordCallback (Selection, MenuOption, NULL);\r | |
951 | }\r | |
952 | \r | |
953 | //\r | |
954 | // Two password mismatch, prompt error message\r | |
955 | //\r | |
956 | do {\r | |
957 | CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gConfirmError, gPressEnter, gEmptyString);\r | |
958 | } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r | |
959 | }\r | |
960 | \r | |
f4113e1f | 961 | FreePool (TempString);\r |
962 | FreePool (StringPtr);\r | |
c60a0616 | 963 | }\r |
964 | break;\r | |
965 | \r | |
966 | default:\r | |
967 | break;\r | |
968 | }\r | |
969 | \r | |
970 | return Status;\r | |
971 | }\r | |
972 | \r | |
973 | \r | |
974 | /**\r | |
975 | Process the help string: Split StringPtr to several lines of strings stored in\r | |
976 | FormattedString and the glyph width of each line cannot exceed gHelpBlockWidth.\r | |
977 | \r | |
978 | @param StringPtr The entire help string.\r | |
979 | @param FormattedString The oupput formatted string.\r | |
980 | @param RowCount TRUE: if Question is selected.\r | |
981 | \r | |
982 | **/\r | |
983 | VOID\r | |
984 | ProcessHelpString (\r | |
985 | IN CHAR16 *StringPtr,\r | |
986 | OUT CHAR16 **FormattedString,\r | |
987 | IN UINTN RowCount\r | |
988 | )\r | |
989 | {\r | |
f4113e1f | 990 | UINTN BlockWidth;\r |
c60a0616 | 991 | UINTN AllocateSize;\r |
992 | //\r | |
993 | // [PrevCurrIndex, CurrIndex) forms a range of a screen-line\r | |
994 | //\r | |
995 | UINTN CurrIndex;\r | |
996 | UINTN PrevCurrIndex;\r | |
997 | UINTN LineCount;\r | |
998 | UINTN VirtualLineCount;\r | |
999 | //\r | |
1000 | // GlyphOffset stores glyph width of current screen-line\r | |
1001 | //\r | |
1002 | UINTN GlyphOffset;\r | |
1003 | //\r | |
1004 | // GlyphWidth equals to 2 if we meet width directive\r | |
1005 | //\r | |
1006 | UINTN GlyphWidth;\r | |
1007 | //\r | |
1008 | // during scanning, we remember the position of last space character\r | |
1009 | // in case that if next word cannot put in current line, we could restore back to the position\r | |
1010 | // of last space character\r | |
1011 | // while we should also remmeber the glyph width of the last space character for restoring\r | |
1012 | //\r | |
1013 | UINTN LastSpaceIndex;\r | |
1014 | UINTN LastSpaceGlyphWidth;\r | |
1015 | //\r | |
1016 | // every time we begin to form a new screen-line, we should remember glyph width of single character\r | |
1017 | // of last line\r | |
1018 | //\r | |
1019 | UINTN LineStartGlyphWidth;\r | |
1020 | UINTN *IndexArray;\r | |
1021 | UINTN *OldIndexArray;\r | |
1022 | \r | |
f4113e1f | 1023 | BlockWidth = (UINTN) gHelpBlockWidth - 1;\r |
8b0fc5c1 | 1024 | \r |
c60a0616 | 1025 | //\r |
1026 | // every three elements of IndexArray form a screen-line of string:[ IndexArray[i*3], IndexArray[i*3+1] )\r | |
1027 | // IndexArray[i*3+2] stores the initial glyph width of single character. to save this is because we want\r | |
1028 | // to bring the width directive of the last line to current screen-line.\r | |
1029 | // e.g.: "\wideabcde ... fghi", if "fghi" also has width directive but is splitted to the next screen-line\r | |
1030 | // different from that of "\wideabcde", we should remember the width directive.\r | |
1031 | //\r | |
1032 | AllocateSize = 0x20;\r | |
1033 | IndexArray = AllocatePool (AllocateSize * sizeof (UINTN) * 3);\r | |
40a06b0c | 1034 | ASSERT (IndexArray != NULL);\r |
c60a0616 | 1035 | \r |
1036 | if (*FormattedString != NULL) {\r | |
f4113e1f | 1037 | FreePool (*FormattedString);\r |
c60a0616 | 1038 | *FormattedString = NULL;\r |
1039 | }\r | |
1040 | \r | |
1041 | for (PrevCurrIndex = 0, CurrIndex = 0, LineCount = 0, LastSpaceIndex = 0,\r | |
1042 | IndexArray[0] = 0, GlyphWidth = 1, GlyphOffset = 0, LastSpaceGlyphWidth = 1, LineStartGlyphWidth = 1;\r | |
1043 | (StringPtr[CurrIndex] != CHAR_NULL);\r | |
1044 | CurrIndex ++) {\r | |
1045 | \r | |
1046 | if (LineCount == AllocateSize) {\r | |
1047 | AllocateSize += 0x10;\r | |
1048 | OldIndexArray = IndexArray;\r | |
1049 | IndexArray = AllocatePool (AllocateSize * sizeof (UINTN) * 3);\r | |
bc166db3 | 1050 | ASSERT (IndexArray != NULL);\r |
8b0fc5c1 | 1051 | \r |
c60a0616 | 1052 | CopyMem (IndexArray, OldIndexArray, LineCount * sizeof (UINTN) * 3);\r |
f4113e1f | 1053 | FreePool (OldIndexArray);\r |
c60a0616 | 1054 | }\r |
1055 | switch (StringPtr[CurrIndex]) {\r | |
1056 | \r | |
1057 | case NARROW_CHAR:\r | |
1058 | case WIDE_CHAR:\r | |
1059 | GlyphWidth = ((StringPtr[CurrIndex] == WIDE_CHAR) ? 2 : 1);\r | |
1060 | if (CurrIndex == 0) {\r | |
1061 | LineStartGlyphWidth = GlyphWidth;\r | |
1062 | }\r | |
1063 | break;\r | |
1064 | \r | |
1065 | //\r | |
1066 | // char is '\n'\r | |
1067 | // "\r\n" isn't handled here, handled by case CHAR_CARRIAGE_RETURN\r | |
1068 | //\r | |
1069 | case CHAR_LINEFEED:\r | |
1070 | //\r | |
1071 | // Store a range of string as a line\r | |
1072 | //\r | |
1073 | IndexArray[LineCount*3] = PrevCurrIndex;\r | |
1074 | IndexArray[LineCount*3+1] = CurrIndex;\r | |
1075 | IndexArray[LineCount*3+2] = LineStartGlyphWidth;\r | |
1076 | LineCount ++;\r | |
1077 | //\r | |
1078 | // Reset offset and save begin position of line\r | |
1079 | //\r | |
1080 | GlyphOffset = 0;\r | |
1081 | LineStartGlyphWidth = GlyphWidth;\r | |
1082 | PrevCurrIndex = CurrIndex + 1;\r | |
1083 | break;\r | |
1084 | \r | |
1085 | //\r | |
1086 | // char is '\r'\r | |
1087 | // "\r\n" and "\r" both are handled here\r | |
1088 | //\r | |
1089 | case CHAR_CARRIAGE_RETURN:\r | |
1090 | if (StringPtr[CurrIndex + 1] == CHAR_LINEFEED) {\r | |
1091 | //\r | |
1092 | // next char is '\n'\r | |
1093 | //\r | |
1094 | IndexArray[LineCount*3] = PrevCurrIndex;\r | |
1095 | IndexArray[LineCount*3+1] = CurrIndex;\r | |
1096 | IndexArray[LineCount*3+2] = LineStartGlyphWidth;\r | |
1097 | LineCount ++;\r | |
1098 | CurrIndex ++;\r | |
1099 | }\r | |
1100 | GlyphOffset = 0;\r | |
1101 | LineStartGlyphWidth = GlyphWidth;\r | |
1102 | PrevCurrIndex = CurrIndex + 1;\r | |
1103 | break;\r | |
1104 | \r | |
1105 | //\r | |
1106 | // char is space or other char\r | |
1107 | //\r | |
1108 | default:\r | |
1109 | GlyphOffset += GlyphWidth;\r | |
1110 | if (GlyphOffset >= BlockWidth) {\r | |
1111 | if (LastSpaceIndex > PrevCurrIndex) {\r | |
1112 | //\r | |
1113 | // LastSpaceIndex points to space inside current screen-line,\r | |
1114 | // restore to LastSpaceIndex\r | |
1115 | // (Otherwise the word is too long to fit one screen-line, just cut it)\r | |
1116 | //\r | |
1117 | CurrIndex = LastSpaceIndex;\r | |
1118 | GlyphWidth = LastSpaceGlyphWidth;\r | |
1119 | } else if (GlyphOffset > BlockWidth) {\r | |
1120 | //\r | |
1121 | // the word is too long to fit one screen-line and we don't get the chance\r | |
1122 | // of GlyphOffset == BlockWidth because GlyphWidth = 2\r | |
1123 | //\r | |
1124 | CurrIndex --;\r | |
1125 | }\r | |
1126 | \r | |
1127 | IndexArray[LineCount*3] = PrevCurrIndex;\r | |
1128 | IndexArray[LineCount*3+1] = CurrIndex + 1;\r | |
1129 | IndexArray[LineCount*3+2] = LineStartGlyphWidth;\r | |
1130 | LineStartGlyphWidth = GlyphWidth;\r | |
1131 | LineCount ++;\r | |
1132 | //\r | |
1133 | // Reset offset and save begin position of line\r | |
1134 | //\r | |
1135 | GlyphOffset = 0;\r | |
1136 | PrevCurrIndex = CurrIndex + 1;\r | |
1137 | }\r | |
1138 | \r | |
1139 | //\r | |
1140 | // LastSpaceIndex: remember position of last space\r | |
1141 | //\r | |
1142 | if (StringPtr[CurrIndex] == CHAR_SPACE) {\r | |
1143 | LastSpaceIndex = CurrIndex;\r | |
1144 | LastSpaceGlyphWidth = GlyphWidth;\r | |
1145 | }\r | |
1146 | break;\r | |
1147 | }\r | |
1148 | }\r | |
1149 | \r | |
1150 | if (GlyphOffset > 0) {\r | |
1151 | IndexArray[LineCount*3] = PrevCurrIndex;\r | |
1152 | IndexArray[LineCount*3+1] = CurrIndex;\r | |
1153 | IndexArray[LineCount*3+2] = GlyphWidth;\r | |
1154 | LineCount ++;\r | |
1155 | }\r | |
1156 | \r | |
1157 | if (LineCount == 0) {\r | |
1158 | //\r | |
1159 | // in case we meet null string\r | |
1160 | //\r | |
1161 | IndexArray[0] = 0;\r | |
1162 | IndexArray[1] = 1;\r | |
1163 | //\r | |
1164 | // we assume null string's glyph width is 1\r | |
1165 | //\r | |
1166 | IndexArray[1] = 1;\r | |
1167 | LineCount ++;\r | |
1168 | }\r | |
1169 | \r | |
1170 | VirtualLineCount = RowCount * (LineCount / RowCount + (LineCount % RowCount > 0));\r | |
1171 | *FormattedString = AllocateZeroPool (VirtualLineCount * (BlockWidth + 1) * sizeof (CHAR16) * 2);\r | |
40a06b0c | 1172 | ASSERT (*FormattedString != NULL);\r |
c60a0616 | 1173 | \r |
1174 | for (CurrIndex = 0; CurrIndex < LineCount; CurrIndex ++) {\r | |
1175 | *(*FormattedString + CurrIndex * 2 * (BlockWidth + 1)) = (CHAR16) ((IndexArray[CurrIndex*3+2] == 2) ? WIDE_CHAR : NARROW_CHAR);\r | |
1176 | StrnCpy (\r | |
1177 | *FormattedString + CurrIndex * 2 * (BlockWidth + 1) + 1,\r | |
1178 | StringPtr + IndexArray[CurrIndex*3],\r | |
1179 | IndexArray[CurrIndex*3+1]-IndexArray[CurrIndex*3]\r | |
1180 | );\r | |
1181 | }\r | |
1182 | \r | |
f4113e1f | 1183 | FreePool (IndexArray);\r |
c60a0616 | 1184 | }\r |