]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c
Enhance HiiThunkGetString to handle the case that PlatformLanguage is not set.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiOnUefiHiiThunk / Strings.c
CommitLineData
4259256b 1/**@file\r
0368663f 2 This file implements the protocol functions related to string package.\r
3 \r
4259256b 4Copyright (c) 2006 - 2008, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15\r
16#include "HiiDatabase.h"\r
17\r
3321fa09 18/**\r
19 Test if all of the characters in a string have corresponding font characters.\r
20\r
21 This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and\r
22 return EFI_UNSUPPORTED.\r
133a9dfb 23\r
3321fa09 24 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
25 @param StringToTest A pointer to a Unicode string.\r
26 @param FirstMissing A pointer to an index into the string. On input, the index of \r
27 the first character in the StringToTest to examine. On exit, the index \r
28 of the first character encountered for which a glyph is unavailable. \r
29 If all glyphs in the string are available, the index is the index of the terminator \r
30 of the string. \r
31 @param GlyphBufferSize A pointer to a value. On output, if the function returns EFI_SUCCESS, \r
cb7d01c0 32 it contains the amount of memory that is required to store the string? glyph equivalent.\r
3321fa09 33\r
34 @retval EFI_UNSUPPORTED The function performs nothing and return EFI_UNSUPPORTED.\r
35**/\r
4259256b 36EFI_STATUS\r
37EFIAPI\r
38HiiTestString (\r
39 IN EFI_HII_PROTOCOL *This,\r
40 IN CHAR16 *StringToTest,\r
41 IN OUT UINT32 *FirstMissing,\r
42 OUT UINT32 *GlyphBufferSize\r
43 )\r
4259256b 44{\r
45 ASSERT (FALSE);\r
3321fa09 46 \r
47 return EFI_UNSUPPORTED;\r
4259256b 48}\r
49\r
133a9dfb 50\r
3321fa09 51/**\r
52 Find the corressponding TAG GUID from a Framework HII Handle given.\r
53\r
54 @param Private The HII Thunk Module Private context.\r
55 @param FwHiiHandle The Framemwork HII Handle.\r
56 @param TagGuid The output of TAG GUID found.\r
133a9dfb 57\r
3321fa09 58 @return NULL If Framework HII Handle is invalid.\r
59 @return The corresponding HII Thunk Context.\r
60**/\r
4259256b 61EFI_STATUS\r
0368663f 62GetTagGuidByFwHiiHandle (\r
63 IN CONST HII_THUNK_PRIVATE_DATA *Private,\r
64 IN FRAMEWORK_EFI_HII_HANDLE FwHiiHandle,\r
4259256b 65 OUT EFI_GUID *TagGuid\r
66 )\r
67{\r
0368663f 68 LIST_ENTRY *Link;\r
69 HII_THUNK_CONTEXT *ThunkContext;\r
4259256b 70\r
71 ASSERT (TagGuid != NULL);\r
72\r
0368663f 73 Link = GetFirstNode (&Private->ThunkContextListHead);\r
74 while (!IsNull (&Private->ThunkContextListHead, Link)) {\r
4259256b 75\r
0368663f 76 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);\r
4259256b 77\r
0368663f 78 if (FwHiiHandle == ThunkContext->FwHiiHandle) {\r
79 CopyGuid (TagGuid, &ThunkContext->TagGuid);\r
4259256b 80 return EFI_SUCCESS;\r
81 }\r
0368663f 82\r
83 Link = GetNextNode (&Private->ThunkContextListHead, Link);\r
4259256b 84 }\r
0368663f 85\r
4259256b 86 return EFI_NOT_FOUND;\r
87}\r
88\r
3321fa09 89/**\r
90 Create or update the String given a new string and String ID.\r
91\r
92 @param ThunkContext The Thunk Context.\r
8cf6dad8 93 @param Rfc4646AsciiLanguage The RFC 4646 Language code in ASCII string format.\r
3321fa09 94 @param NewString The new string.\r
95 @param StringId The String ID. If StringId is 0, a new String Token\r
96 is created. Otherwise, the String Token StringId is \r
97 updated.\r
98 \r
99\r
100 @retval EFI_SUCCESS The new string is created or updated successfully. \r
101 The new String Token ID is returned in StringId if\r
102 *StringId is 0 on input.\r
103 @return Others The update of string failed. \r
104 \r
105**/\r
106EFI_STATUS\r
107UpdateString (\r
108 IN CONST HII_THUNK_CONTEXT *ThunkContext,\r
8cf6dad8 109 IN CONST CHAR8 *Rfc4646AsciiLanguage,\r
3321fa09 110 IN CHAR16 *NewString,\r
111 IN OUT STRING_REF *StringId\r
112 )\r
113{\r
114 EFI_STRING_ID NewStringId;\r
3321fa09 115\r
8cf6dad8 116 NewStringId = HiiSetString (ThunkContext->UefiHiiHandle, *StringId, NewString, Rfc4646AsciiLanguage);\r
cb7d01c0 117 *StringId = NewStringId;\r
118 if (NewStringId == 0) {\r
3321fa09 119 //\r
120 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.\r
121 //\r
cb7d01c0 122 return EFI_INVALID_PARAMETER;\r
123 } else {\r
124 return EFI_SUCCESS;\r
3321fa09 125 }\r
3321fa09 126}\r
127\r
128/**\r
129 Create or update a String Token in a String Package.\r
130\r
131 If *Reference == 0, a new String Token is created.\r
132\r
133 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
134 @param Language Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
135 identifier, indicating the language to print. A string consisting of\r
136 all spaces indicates that the string is applicable to all languages.\r
137 @param Handle The handle of the language pack to which the string is to be added.\r
138 @param Token The string token assigned to the string.\r
139 @param NewString The string to be added.\r
140\r
0368663f 141\r
3321fa09 142 @retval EFI_SUCCESS The string was effectively registered.\r
143 @retval EFI_INVALID_PARAMETER The Handle was unknown. The string is not created or updated in the\r
144 the string package.\r
145**/\r
0368663f 146\r
4259256b 147EFI_STATUS\r
0368663f 148EFIAPI\r
149HiiNewString (\r
150 IN EFI_HII_PROTOCOL *This,\r
151 IN CHAR16 *Language,\r
152 IN FRAMEWORK_EFI_HII_HANDLE Handle,\r
153 IN OUT STRING_REF *Reference,\r
154 IN CHAR16 *NewString\r
4259256b 155 )\r
156{\r
157 EFI_STATUS Status;\r
0368663f 158 HII_THUNK_PRIVATE_DATA *Private;\r
159 EFI_GUID TagGuid;\r
160 LIST_ENTRY *Link;\r
161 HII_THUNK_CONTEXT *ThunkContext;\r
3321fa09 162 HII_THUNK_CONTEXT *StringPackThunkContext;\r
0368663f 163 EFI_STRING_ID StringId;\r
164 EFI_STRING_ID LastStringId;\r
133a9dfb 165 CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];\r
8ea58c07 166 CHAR16 LanguageCopy[ISO_639_2_ENTRY_SIZE + 1];\r
8cf6dad8 167 CHAR8 *Rfc4646AsciiLanguage;\r
4259256b 168\r
0368663f 169 LastStringId = (EFI_STRING_ID) 0;\r
170 StringId = (EFI_STRING_ID) 0;\r
8cf6dad8 171 Rfc4646AsciiLanguage = NULL;\r
4259256b 172\r
0368663f 173 if (Language != NULL) {\r
133a9dfb 174 ZeroMem (AsciiLanguage, sizeof (AsciiLanguage));;\r
8ea58c07 175 ZeroMem (LanguageCopy, sizeof (LanguageCopy));\r
176 CopyMem (LanguageCopy, Language, ISO_639_2_ENTRY_SIZE * sizeof (CHAR16));\r
177 UnicodeStrToAsciiStr (LanguageCopy, AsciiLanguage);\r
7c9d25ae 178 Rfc4646AsciiLanguage = ConvertLanguagesIso639ToRfc4646 (AsciiLanguage);\r
8cf6dad8 179 ASSERT (Rfc4646AsciiLanguage != NULL);\r
ea58467b 180 }\r
4259256b 181\r
3321fa09 182 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
4259256b 183\r
3321fa09 184 StringPackThunkContext = FwHiiHandleToThunkContext (Private, Handle);\r
185 if (StringPackThunkContext == NULL) {\r
186 return EFI_INVALID_PARAMETER;\r
187 }\r
188\r
189 if (StringPackThunkContext->SharingStringPack) {\r
190 Status = GetTagGuidByFwHiiHandle (Private, Handle, &TagGuid);\r
191 ASSERT_EFI_ERROR (Status);\r
192\r
193 Link = GetFirstNode (&Private->ThunkContextListHead);\r
194 while (!IsNull (&Private->ThunkContextListHead, Link)) {\r
195 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);\r
0368663f 196\r
3321fa09 197 if (CompareGuid (&TagGuid, &ThunkContext->TagGuid)) {\r
198 if (ThunkContext->SharingStringPack) {\r
199 StringId = *Reference;\r
8cf6dad8 200 Status = UpdateString (ThunkContext, Rfc4646AsciiLanguage, NewString, &StringId);\r
3321fa09 201 if (EFI_ERROR (Status)) {\r
202 break;\r
4259256b 203 }\r
3321fa09 204 \r
205 DEBUG_CODE_BEGIN ();\r
206 if (*Reference == 0) {\r
207 //\r
208 // When creating new string token, make sure all created token is the same\r
209 // for all string packages registered using FW HII interface.\r
210 //\r
211 if (LastStringId == (EFI_STRING_ID) 0) {\r
212 LastStringId = StringId;\r
213 } else {\r
214 if (LastStringId != StringId) {\r
215 ASSERT(FALSE);\r
216 }\r
217 }\r
218 }\r
219 DEBUG_CODE_END ();\r
220 \r
4259256b 221 }\r
222 }\r
0368663f 223\r
3321fa09 224 Link = GetNextNode (&Private->ThunkContextListHead, Link);\r
225 }\r
226 } else {\r
227 StringId = *Reference;\r
8cf6dad8 228 Status = UpdateString (StringPackThunkContext, Rfc4646AsciiLanguage, NewString, &StringId);\r
4259256b 229 }\r
230\r
3321fa09 231 if (!EFI_ERROR (Status)) {\r
0368663f 232 if (*Reference == 0) {\r
233 *Reference = StringId;\r
234 }\r
4259256b 235 } else {\r
0368663f 236 //\r
3321fa09 237 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.\r
0368663f 238 //\r
3321fa09 239 Status = EFI_INVALID_PARAMETER;\r
4259256b 240 }\r
241 \r
46b5ebc8 242 return Status;\r
4259256b 243}\r
244\r
3321fa09 245/**\r
246 This function removes any new strings that were added after the initial string export for this handle.\r
247 UEFI HII String Protocol does not have Reset String function. This function perform nothing.\r
248\r
249 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
250 @param Handle The HII handle on which the string resides.\r
251\r
252 @retval EFI_SUCCESS This function is a NOP and always return EFI_SUCCESS.\r
253\r
254**/\r
4259256b 255EFI_STATUS\r
256EFIAPI\r
257HiiResetStrings (\r
258 IN EFI_HII_PROTOCOL *This,\r
259 IN FRAMEWORK_EFI_HII_HANDLE Handle\r
260 )\r
4259256b 261{\r
0368663f 262 return EFI_SUCCESS;\r
4259256b 263}\r
264\r
3321fa09 265/**\r
266 This function extracts a string from a package already registered with the EFI HII database.\r
267\r
268 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
269 @param Handle The HII handle on which the string resides.\r
270 @param Token The string token assigned to the string.\r
271 @param Raw If TRUE, the string is returned unedited in the internal storage format described\r
272 above. If false, the string returned is edited by replacing <cr> with <space>\r
273 and by removing special characters such as the <wide> prefix.\r
274 @param LanguageString Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
275 identifier, indicating the language to print. If the LanguageString is empty (starts\r
276 with a NULL), the default system language will be used to determine the language.\r
277 @param BufferLength Length of the StringBuffer. If the status reports that the buffer width is too\r
278 small, this parameter is filled with the length of the buffer needed.\r
279 @param StringBuffer The buffer designed to receive the characters in the string. Type EFI_STRING is\r
280 defined in String.\r
281\r
282 @retval EFI_INVALID_PARAMETER If input parameter is invalid.\r
283 @retval EFI_BUFFER_TOO_SMALL If the *BufferLength is too small.\r
284 @retval EFI_SUCCESS Operation is successful.\r
285\r
286**/\r
4259256b 287EFI_STATUS\r
288EFIAPI\r
cdaf7905 289HiiThunkGetString (\r
133a9dfb 290 IN EFI_HII_PROTOCOL *This,\r
291 IN FRAMEWORK_EFI_HII_HANDLE Handle,\r
292 IN STRING_REF Token,\r
293 IN BOOLEAN Raw,\r
294 IN CHAR16 *LanguageString,\r
295 IN OUT UINTN *BufferLengthTemp,\r
296 OUT EFI_STRING StringBuffer\r
4259256b 297 )\r
4259256b 298{\r
0368663f 299 HII_THUNK_PRIVATE_DATA *Private;\r
cb7d01c0 300 CHAR8 *Iso639AsciiLanguage;\r
8cf6dad8 301 CHAR8 *Rfc4646AsciiLanguage;\r
cb7d01c0 302 CHAR8 *SupportedLanguages;\r
303 CHAR8 *PlatformLanguage;\r
304 CHAR8 *BestLanguage;\r
133a9dfb 305 EFI_HII_HANDLE UefiHiiHandle;\r
306 EFI_STATUS Status;\r
4259256b 307\r
0368663f 308 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
4259256b 309\r
8cf6dad8 310 Rfc4646AsciiLanguage = NULL;\r
43ffc47f
LG
311 SupportedLanguages = NULL;\r
312 PlatformLanguage = NULL;\r
313 Status = EFI_SUCCESS;\r
133a9dfb 314\r
315 if (LanguageString != NULL) {\r
316 Iso639AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1);\r
317 if (Iso639AsciiLanguage == NULL) {\r
4259256b 318 return EFI_OUT_OF_RESOURCES;\r
319 }\r
133a9dfb 320 UnicodeStrToAsciiStr (LanguageString, Iso639AsciiLanguage);\r
ea58467b 321\r
133a9dfb 322 //\r
323 // Caller of Framework HII Interface uses the Language Identification String defined \r
8cf6dad8 324 // in Iso639. So map it to the Language Identifier defined in RFC4646.\r
133a9dfb 325 //\r
7c9d25ae 326 Rfc4646AsciiLanguage = ConvertLanguagesIso639ToRfc4646 (Iso639AsciiLanguage);\r
f324bf4d 327 FreePool (Iso639AsciiLanguage);\r
1668bd49 328\r
329 //\r
8cf6dad8 330 // If Rfc4646AsciiLanguage is NULL, more language mapping must be added to \r
331 // Iso639ToRfc4646Map.\r
1668bd49 332 //\r
8cf6dad8 333 ASSERT (Rfc4646AsciiLanguage != NULL);\r
4259256b 334 }\r
335\r
133a9dfb 336 UefiHiiHandle = FwHiiHandleToUefiHiiHandle (Private, Handle);\r
337 if (UefiHiiHandle == NULL) {\r
338 Status = EFI_NOT_FOUND;\r
339 goto Done;\r
340 }\r
4259256b 341\r
f324bf4d 342 //\r
343 // Get the languages that the package specified by HiiHandle supports\r
344 //\r
345 SupportedLanguages = HiiGetSupportedLanguages (UefiHiiHandle);\r
346 if (SupportedLanguages == NULL) {\r
43ffc47f 347 goto Done;\r
f324bf4d 348 }\r
cb7d01c0 349\r
f324bf4d 350 //\r
351 // Get the current platform language setting\r
352 //\r
353 PlatformLanguage = GetEfiGlobalVariable (L"PlatformLang");\r
cb7d01c0 354\r
f324bf4d 355 //\r
356 // Get the best matching language from SupportedLanguages\r
357 //\r
358 BestLanguage = GetBestLanguage (\r
359 SupportedLanguages, \r
360 FALSE, // RFC 4646 mode\r
43ffc47f
LG
361 (Rfc4646AsciiLanguage != NULL) ? Rfc4646AsciiLanguage : "", // Highest priority \r
362 (PlatformLanguage != NULL) ? PlatformLanguage : "", // Next highest priority\r
f324bf4d 363 SupportedLanguages, // Lowest priority \r
364 NULL\r
365 );\r
43ffc47f
LG
366 if (BestLanguage != NULL) {\r
367 Status = mHiiStringProtocol->GetString (\r
368 mHiiStringProtocol,\r
369 BestLanguage,\r
370 UefiHiiHandle,\r
371 Token,\r
372 StringBuffer,\r
373 BufferLengthTemp,\r
374 NULL\r
375 );\r
376 FreePool (BestLanguage);\r
377 } else {\r
f324bf4d 378 Status = EFI_INVALID_PARAMETER;\r
4259256b 379 }\r
380\r
133a9dfb 381Done:\r
f324bf4d 382 if (Rfc4646AsciiLanguage != NULL) {\r
383 FreePool (Rfc4646AsciiLanguage);\r
7001eaf8 384 }\r
43ffc47f
LG
385\r
386 if (SupportedLanguages != NULL) {\r
387 FreePool (SupportedLanguages);\r
388 }\r
389\r
390 if (PlatformLanguage != NULL) {\r
391 FreePool (PlatformLanguage);\r
392 }\r
133a9dfb 393 return Status;\r
4259256b 394}\r
395\r
3321fa09 396/**\r
4259256b 397\r
398 This function allows a program to extract a part of a string of not more than a given width.\r
399 With repeated calls, this allows a calling program to extract "lines" of text that fit inside\r
400 columns. The effort of measuring the fit of strings inside columns is localized to this call.\r
401\r
3321fa09 402 This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and\r
403 return EFI_UNSUPPORTED.\r
404\r
405 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
406 @param Handle The HII handle on which the string resides.\r
407 @param Token The string token assigned to the string.\r
408 @param Raw If TRUE, the string is returned unedited in the internal storage format described\r
409 above. If false, the string returned is edited by replacing <cr> with <space>\r
410 and by removing special characters such as the <wide> prefix.\r
411 @param LanguageString Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
412 identifier, indicating the language to print. If the LanguageString is empty (starts\r
413 with a NULL), the default system language will be used to determine the language.\r
414 @param BufferLength Length of the StringBuffer. If the status reports that the buffer width is too\r
415 small, this parameter is filled with the length of the buffer needed.\r
416 @param StringBuffer The buffer designed to receive the characters in the string. Type EFI_STRING is\r
417 defined in String.\r
418\r
419 @retval EFI_UNSUPPORTED.\r
420**/\r
421EFI_STATUS\r
422EFIAPI\r
423HiiGetLine (\r
424 IN EFI_HII_PROTOCOL *This,\r
425 IN FRAMEWORK_EFI_HII_HANDLE Handle,\r
426 IN STRING_REF Token,\r
427 IN OUT UINT16 *Index,\r
428 IN UINT16 LineWidth,\r
429 IN CHAR16 *LanguageString,\r
430 IN OUT UINT16 *BufferLength,\r
431 OUT EFI_STRING StringBuffer\r
432 )\r
4259256b 433{\r
434 ASSERT (FALSE);\r
435 return EFI_UNSUPPORTED;\r
436}\r
437\r
1668bd49 438\r