2 This file implements the protocol functions related to string package.
4 Copyright (c) 2006 - 2008, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "HiiDatabase.h"
19 Test if all of the characters in a string have corresponding font characters.
21 This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and
22 return EFI_UNSUPPORTED.
24 @param This A pointer to the EFI_HII_PROTOCOL instance.
25 @param StringToTest A pointer to a Unicode string.
26 @param FirstMissing A pointer to an index into the string. On input, the index of
27 the first character in the StringToTest to examine. On exit, the index
28 of the first character encountered for which a glyph is unavailable.
29 If all glyphs in the string are available, the index is the index of the terminator
31 @param GlyphBufferSize A pointer to a value. On output, if the function returns EFI_SUCCESS,
32 it contains the amount of memory that is required to store the string? glyph equivalent.
34 @retval EFI_UNSUPPORTED The function performs nothing and return EFI_UNSUPPORTED.
39 IN EFI_HII_PROTOCOL
*This
,
40 IN CHAR16
*StringToTest
,
41 IN OUT UINT32
*FirstMissing
,
42 OUT UINT32
*GlyphBufferSize
47 return EFI_UNSUPPORTED
;
52 Find the corressponding TAG GUID from a Framework HII Handle given.
54 @param Private The HII Thunk Module Private context.
55 @param FwHiiHandle The Framemwork HII Handle.
56 @param TagGuid The output of TAG GUID found.
58 @return NULL If Framework HII Handle is invalid.
59 @return The corresponding HII Thunk Context.
62 GetTagGuidByFwHiiHandle (
63 IN CONST HII_THUNK_PRIVATE_DATA
*Private
,
64 IN FRAMEWORK_EFI_HII_HANDLE FwHiiHandle
,
69 HII_THUNK_CONTEXT
*ThunkContext
;
71 ASSERT (TagGuid
!= NULL
);
73 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
74 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
76 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
78 if (FwHiiHandle
== ThunkContext
->FwHiiHandle
) {
79 CopyGuid (TagGuid
, &ThunkContext
->TagGuid
);
83 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
90 Create or update the String given a new string and String ID.
92 @param ThunkContext The Thunk Context.
93 @param Rfc4646AsciiLanguage The RFC 4646 Language code in ASCII string format.
94 @param NewString The new string.
95 @param StringId The String ID. If StringId is 0, a new String Token
96 is created. Otherwise, the String Token StringId is
100 @retval EFI_SUCCESS The new string is created or updated successfully.
101 The new String Token ID is returned in StringId if
102 *StringId is 0 on input.
103 @return Others The update of string failed.
108 IN CONST HII_THUNK_CONTEXT
*ThunkContext
,
109 IN CONST CHAR8
*Rfc4646AsciiLanguage
,
110 IN CHAR16
*NewString
,
111 IN OUT STRING_REF
*StringId
114 EFI_STRING_ID NewStringId
;
116 NewStringId
= HiiSetString (ThunkContext
->UefiHiiHandle
, *StringId
, NewString
, Rfc4646AsciiLanguage
);
117 *StringId
= NewStringId
;
118 if (NewStringId
== 0) {
120 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.
122 return EFI_INVALID_PARAMETER
;
129 Create or update a String Token in a String Package.
131 If *Reference == 0, a new String Token is created.
133 @param This A pointer to the EFI_HII_PROTOCOL instance.
134 @param Language Pointer to a NULL-terminated string containing a single ISO 639-2 language
135 identifier, indicating the language to print. A string consisting of
136 all spaces indicates that the string is applicable to all languages.
137 @param Handle The handle of the language pack to which the string is to be added.
138 @param Token The string token assigned to the string.
139 @param NewString The string to be added.
142 @retval EFI_SUCCESS The string was effectively registered.
143 @retval EFI_INVALID_PARAMETER The Handle was unknown. The string is not created or updated in the
150 IN EFI_HII_PROTOCOL
*This
,
152 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
153 IN OUT STRING_REF
*Reference
,
158 HII_THUNK_PRIVATE_DATA
*Private
;
161 HII_THUNK_CONTEXT
*ThunkContext
;
162 HII_THUNK_CONTEXT
*StringPackThunkContext
;
163 EFI_STRING_ID StringId
;
164 EFI_STRING_ID LastStringId
;
165 CHAR8 AsciiLanguage
[ISO_639_2_ENTRY_SIZE
+ 1];
166 CHAR16 LanguageCopy
[ISO_639_2_ENTRY_SIZE
+ 1];
167 CHAR8
*Rfc4646AsciiLanguage
;
169 LastStringId
= (EFI_STRING_ID
) 0;
170 StringId
= (EFI_STRING_ID
) 0;
171 Rfc4646AsciiLanguage
= NULL
;
173 if (Language
!= NULL
) {
174 ZeroMem (AsciiLanguage
, sizeof (AsciiLanguage
));;
175 ZeroMem (LanguageCopy
, sizeof (LanguageCopy
));
176 CopyMem (LanguageCopy
, Language
, ISO_639_2_ENTRY_SIZE
* sizeof (CHAR16
));
177 UnicodeStrToAsciiStr (LanguageCopy
, AsciiLanguage
);
178 Rfc4646AsciiLanguage
= ConvertLanguagesIso639ToRfc4646 (AsciiLanguage
);
179 ASSERT (Rfc4646AsciiLanguage
!= NULL
);
182 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
184 StringPackThunkContext
= FwHiiHandleToThunkContext (Private
, Handle
);
185 if (StringPackThunkContext
== NULL
) {
186 return EFI_INVALID_PARAMETER
;
189 if (StringPackThunkContext
->SharingStringPack
) {
190 Status
= GetTagGuidByFwHiiHandle (Private
, Handle
, &TagGuid
);
191 ASSERT_EFI_ERROR (Status
);
193 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
194 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
195 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
197 if (CompareGuid (&TagGuid
, &ThunkContext
->TagGuid
)) {
198 if (ThunkContext
->SharingStringPack
) {
199 StringId
= *Reference
;
200 Status
= UpdateString (ThunkContext
, Rfc4646AsciiLanguage
, NewString
, &StringId
);
201 if (EFI_ERROR (Status
)) {
206 if (*Reference
== 0) {
208 // When creating new string token, make sure all created token is the same
209 // for all string packages registered using FW HII interface.
211 if (LastStringId
== (EFI_STRING_ID
) 0) {
212 LastStringId
= StringId
;
214 if (LastStringId
!= StringId
) {
224 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
227 StringId
= *Reference
;
228 Status
= UpdateString (StringPackThunkContext
, Rfc4646AsciiLanguage
, NewString
, &StringId
);
231 if (!EFI_ERROR (Status
)) {
232 if (*Reference
== 0) {
233 *Reference
= StringId
;
237 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.
239 Status
= EFI_INVALID_PARAMETER
;
246 This function removes any new strings that were added after the initial string export for this handle.
247 UEFI HII String Protocol does not have Reset String function. This function perform nothing.
249 @param This A pointer to the EFI_HII_PROTOCOL instance.
250 @param Handle The HII handle on which the string resides.
252 @retval EFI_SUCCESS This function is a NOP and always return EFI_SUCCESS.
258 IN EFI_HII_PROTOCOL
*This
,
259 IN FRAMEWORK_EFI_HII_HANDLE Handle
266 This function extracts a string from a package already registered with the EFI HII database.
268 @param This A pointer to the EFI_HII_PROTOCOL instance.
269 @param Handle The HII handle on which the string resides.
270 @param Token The string token assigned to the string.
271 @param Raw If TRUE, the string is returned unedited in the internal storage format described
272 above. If false, the string returned is edited by replacing <cr> with <space>
273 and by removing special characters such as the <wide> prefix.
274 @param LanguageString Pointer to a NULL-terminated string containing a single ISO 639-2 language
275 identifier, indicating the language to print. If the LanguageString is empty (starts
276 with a NULL), the default system language will be used to determine the language.
277 @param BufferLength Length of the StringBuffer. If the status reports that the buffer width is too
278 small, this parameter is filled with the length of the buffer needed.
279 @param StringBuffer The buffer designed to receive the characters in the string. Type EFI_STRING is
282 @retval EFI_INVALID_PARAMETER If input parameter is invalid.
283 @retval EFI_BUFFER_TOO_SMALL If the *BufferLength is too small.
284 @retval EFI_SUCCESS Operation is successful.
290 IN EFI_HII_PROTOCOL
*This
,
291 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
294 IN CHAR16
*LanguageString
,
295 IN OUT UINTN
*BufferLengthTemp
,
296 OUT EFI_STRING StringBuffer
299 HII_THUNK_PRIVATE_DATA
*Private
;
300 CHAR8
*Iso639AsciiLanguage
;
301 CHAR8
*Rfc4646AsciiLanguage
;
302 CHAR8
*SupportedLanguages
;
303 CHAR8
*PlatformLanguage
;
305 EFI_HII_HANDLE UefiHiiHandle
;
308 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
310 Rfc4646AsciiLanguage
= NULL
;
312 if (LanguageString
!= NULL
) {
313 Iso639AsciiLanguage
= AllocateZeroPool (StrLen (LanguageString
) + 1);
314 if (Iso639AsciiLanguage
== NULL
) {
315 return EFI_OUT_OF_RESOURCES
;
317 UnicodeStrToAsciiStr (LanguageString
, Iso639AsciiLanguage
);
320 // Caller of Framework HII Interface uses the Language Identification String defined
321 // in Iso639. So map it to the Language Identifier defined in RFC4646.
323 Rfc4646AsciiLanguage
= ConvertLanguagesIso639ToRfc4646 (Iso639AsciiLanguage
);
324 FreePool (Iso639AsciiLanguage
);
327 // If Rfc4646AsciiLanguage is NULL, more language mapping must be added to
328 // Iso639ToRfc4646Map.
330 ASSERT (Rfc4646AsciiLanguage
!= NULL
);
334 UefiHiiHandle
= FwHiiHandleToUefiHiiHandle (Private
, Handle
);
335 if (UefiHiiHandle
== NULL
) {
336 Status
= EFI_NOT_FOUND
;
341 // Get the languages that the package specified by HiiHandle supports
343 SupportedLanguages
= HiiGetSupportedLanguages (UefiHiiHandle
);
344 if (SupportedLanguages
== NULL
) {
349 // Get the current platform language setting
351 PlatformLanguage
= GetEfiGlobalVariable (L
"PlatformLang");
352 if (PlatformLanguage
== NULL
) {
357 // Get the best matching language from SupportedLanguages
359 BestLanguage
= GetBestLanguage (
361 FALSE
, // RFC 4646 mode
362 (Rfc4646AsciiLanguage
!= NULL
) ? Rfc4646AsciiLanguage
: "",
363 PlatformLanguage
, // Next highest priority
364 SupportedLanguages
, // Lowest priority
367 if (BestLanguage
== NULL
) {
368 FreePool (PlatformLanguage
);
370 FreePool (SupportedLanguages
);
372 Status
= EFI_INVALID_PARAMETER
;
376 Status
= mHiiStringProtocol
->GetString (
385 FreePool (BestLanguage
);
388 if (Rfc4646AsciiLanguage
!= NULL
) {
389 FreePool (Rfc4646AsciiLanguage
);
397 This function allows a program to extract a part of a string of not more than a given width.
398 With repeated calls, this allows a calling program to extract "lines" of text that fit inside
399 columns. The effort of measuring the fit of strings inside columns is localized to this call.
401 This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and
402 return EFI_UNSUPPORTED.
404 @param This A pointer to the EFI_HII_PROTOCOL instance.
405 @param Handle The HII handle on which the string resides.
406 @param Token The string token assigned to the string.
407 @param Raw If TRUE, the string is returned unedited in the internal storage format described
408 above. If false, the string returned is edited by replacing <cr> with <space>
409 and by removing special characters such as the <wide> prefix.
410 @param LanguageString Pointer to a NULL-terminated string containing a single ISO 639-2 language
411 identifier, indicating the language to print. If the LanguageString is empty (starts
412 with a NULL), the default system language will be used to determine the language.
413 @param BufferLength Length of the StringBuffer. If the status reports that the buffer width is too
414 small, this parameter is filled with the length of the buffer needed.
415 @param StringBuffer The buffer designed to receive the characters in the string. Type EFI_STRING is
418 @retval EFI_UNSUPPORTED.
423 IN EFI_HII_PROTOCOL
*This
,
424 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
426 IN OUT UINT16
*Index
,
428 IN CHAR16
*LanguageString
,
429 IN OUT UINT16
*BufferLength
,
430 OUT EFI_STRING StringBuffer
434 return EFI_UNSUPPORTED
;