summaryrefslogtreecommitdiff
path: root/EDK/MiniSetup/TseLite/Text.c
blob: a597287643cbc19affa150276af206178ac62399 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
//**                                                             **//
//**         (C)Copyright 2011, American Megatrends, Inc.        **//
//**                                                             **//
//**                     All Rights Reserved.                    **//
//**                                                             **//
//**   5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093  **//
//**                                                             **//
//**                     Phone (770)-246-8600                    **//
//**                                                             **//
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseLite/Text.c $
//
// $Author: Arunsb $
//
// $Revision: 15 $
//
// $Date: 2/11/14 8:34p $
//
//*****************************************************************//
//*****************************************************************//
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseLite/Text.c $
// 
// 15    2/11/14 8:34p Arunsb
// [TAG]		EIP147142
// [Category]	Bug Fix
// [Severity]	Normal
// [Symptom]	text gets truncated
// [Root Cause]	The controls SetText function is called from the function
// TextDraw to update the properties [text->Label and text->text] using
// HiiGetString. However, FrameDraw will call each
// controls->getControlHeight before calling each controls->draw function.
// It is during this time when text->getControlHeight attempts to use the
// properties [text->Label and text->text] to compute the height [for
// multiline] which will be incorrect
// [Solution]	Call the controls SetText function from within the function
// getControlHeight 
// to ensure the text controls properties [text->Label and text->text]
// always has valid updated Hii text.
// [Files]	Text.c
// 
// 14    6/10/13 10:02a Arunsb
// String retrieval success check in TextInitialize is commented.
// 
// 13    10/18/12 6:02a Arunsb
// Updated for 2.16.1235 QA submission
// 
// 9     10/10/12 12:38p Arunsb
// Synched the source for v2.16.1232, backup with Aptio
// 
// 12    2/01/12 5:54p Blaines
// Rollback to Revision 10
// 
// 10    11/21/11 10:59a Premkumara
// [TAG]  		EIP72610
// [Category]  	Improvement
// [Description]  	Moving TSE_MULTILINE_CONTROLS to Binary
// [Files]  		AMITSE-CommonHelper.c, AMITSE.sdl, 
// TSELITE-UefiAction.c, TseLite.sdl, Time.h, Text.c,
// SubMenu.c, ResetButton.c, PopupString.c, PopupSel.h, PopupSel.c, 
// PopupPassword.c, OrderListBox.c, Numeric.c, Label.c, Frame.c, Edit.c, 
// Date.h, Date.c, 
// LEGACY-Legacy.c,
// BOOTONLY- Minisetup.h
// 
// 9     11/21/11 8:59a Rajashakerg
// [TAG]  		EIP69104 
// [Category]  	Improvement
// [Description]  	Not to destroy the controls if it is NULL
// [Files]  		control.c, edit.c, Label.c, memo.c, menu.c, ordlistbox.c,
// popup.c, PopupString.c, SubMenu.c, Text.c.
// 
// 8     11/15/11 2:28a Rajashakerg
// [TAG]  		EIP73391 
// [Category]  	Improvement
// [Description]  	Information displayed in SETUP gets truncated.
// [Files]  		Text.c
// 
// 7     11/14/11 6:55p Blaines
// [TAG] - EIP 75486 
// [Category]- Function Request
// [Synopsis]- Support grayout condition for readonly controls.
// [Description] - Display readonly controls as grayout, non-selectable.
// [Files]
// AMITSE.sdl, CommonHelper.c, Minisetupext.h, stylecommon.c, Legacy.c,
// date.c, edit.c, label.c, memo.c, menu.c,, numeric.c, ordlistbox.c,
// PopupPassword.c, 
// PopupSel.c, PopupString.c, ResetButton.c, SubMenu.c, Text.c, Time.c,
// UefiAction.c, ctrlcond.c,   
// 
// 6     9/16/10 8:38p Madhans
// Update for TSE 2.10. Refer Changelog.log for more details.
// 
// 7     8/18/10 7:17p Madhans
// [TAG]    	EIP42199
// [Category]	BUG FIX
// [Symptom]	Text Control does not disply the full string even with
// multiline TSE support.
// [RootCause]	Bug in TextGetControlHeight()
// [Solution]	Take the Frame width in account instead if Text->Width.
// [Files]		text.c
// 
// 6     3/26/10 6:53p Madhans
// Support to Map the do the Control Mapping from gTseControlMap Table. So
// no changes need in Frame.c, With this feature gTseControlMap Can be
// customized to add/customize the TSE controls.
// 
// 5     2/19/10 8:18a Mallikarjunanv
// updated year in copyright message
// 
// 4     8/13/09 1:21p Blaines
// EIP #24980 Fix to properly display right area text
// 
// 3     6/23/09 6:53p Blaines
// Coding standard update, 
// Remove spaces from file header to allow proper chm function list
// creation.
// 
// 2     6/12/09 7:44p Presannar
// Initial implementation of coding standards for AMITSE2.0
// 
// 1     6/04/09 8:05p Madhans
// 
// 2     5/07/09 10:36a Madhans
// Changes after Bin module
// 
// 1     4/28/09 11:06p Madhans
// Tse 2.0 Code complete Checkin.
// 
// 3     4/28/09 9:40p Madhans
// Tse 2.0 Code complete Checkin.
// 
// 2     1/30/09 6:06p Madhans
// Function headers added. 
// 
// 1     12/18/08 7:59p Madhans
// Intial version of TSE Lite sources
//*****************************************************************//
//*****************************************************************//

//<AMI_FHDR_START>
//----------------------------------------------------------------------------
//
// Name:		text.c
//
// Description:	This file contains code to handle text operations
//
//----------------------------------------------------------------------------
//<AMI_FHDR_END>

#include "minisetup.h"

TEXT_METHODS gText =
{
	TextCreate,
	TextDestroy,
	TextInitialize,
	TextDraw,
	TextHandleAction,
	TextSetCallback,
	TextSetFocus,
	TextSetPosition,
	TextSetDimensions,
	TextSetAttributes,
    TextGetControlHeight,
	TextSetText
};

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	TextCreate
//
// Description:	this function uses the create function of control
//					and creates text
//
// Input:	TEXT_DATA **object
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS TextCreate( TEXT_DATA **object )
{
	EFI_STATUS Status = EFI_OUT_OF_RESOURCES;

	if ( *object == NULL )
	{
		*object = EfiLibAllocateZeroPool( sizeof(TEXT_DATA) );

		if ( *object == NULL )
			return Status;
	}

	Status = gControl.Create( object );
	if ( ! EFI_ERROR(Status) )
		(*object)->Methods = &gText;

	return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	TextDestroy
//
// Description:	this function uses the destroy function of control
//					and destroys the text
//
// Input:	TEXT_DATA *text, BOOLEAN freeMem
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS TextDestroy( TEXT_DATA *text, BOOLEAN freeMem )
{
	if(NULL == text)
	  return EFI_SUCCESS;

	gControl.Destroy( text, FALSE );

	MemFreePointer( (VOID **)&text->LabelText );
	MemFreePointer( (VOID **)&text->Text );

	if ( freeMem )
		MemFreePointer( (VOID **)&text );

	return EFI_SUCCESS;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	TextDestroy
//
// Description:	this function uses the initialize function of control
//					and initializes the text
//
// Input:	TEXT_DATA *text, VOID *data
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS TextInitialize( TEXT_DATA *text, VOID *data )
{
	EFI_STATUS Status = EFI_UNSUPPORTED;

	Status = gControl.Initialize( text, data );
	if (EFI_ERROR(Status))
		return Status;

	SetControlColorsHook(&(text->BGColor), &(text->FGColor), 
						NULL, NULL, 
						NULL, NULL,
	                    			NULL, NULL,
						NULL, NULL,
						NULL, 
						NULL, NULL,
						NULL,NULL);

	// add extra initialization here...
	text->ControlData.ControlHelp = UefiGetHelpField ((VOID*)text->ControlData.ControlPtr);
	//text->FGColor= EFI_DARKGRAY;
	StyleGetSpecialColor( CONTROL_TYPE_TEXT, &(text->FGColor)) ;

	text->LabelMargin = (UINT8)gControlLeftMargin;


	text->Interval = (UINT8)text->ControlData.ControlFlags.ControlRefresh;
	text->LabelText = HiiGetString( text->ControlData.ControlHandle, UefiGetTextField((VOID*)text->ControlData.ControlPtr));
//	if ( text->LabelText == NULL )						//EIP122907 In some case in init hiigetstring is failing but in draw its passing so commented this check.
//		return EFI_OUT_OF_RESOURCES;

	text->Text = HiiGetString( text->ControlData.ControlHandle, UefiGetTextTwoField((VOID *)text->ControlData.ControlPtr));
//	if ( text->Text == NULL )
//		return EFI_OUT_OF_RESOURCES;

	return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	TextDraw
//
// Description:	function to draw the text with attributes.
//
// Input:	TEXT_DATA *text
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS TextDraw( TEXT_DATA *text )
{
	CHAR16 *txt =NULL, *txt2 = NULL;
	EFI_STATUS Status = EFI_SUCCESS;
	UINT8 ColorText = text->FGColor ;


	// check conditional ptr if necessary
    //EIP 75486 Support grayout condition for readonly controls
	//if( text->ControlData.ControlConditionalPtr != 0x0)
	//{
		switch( CheckControlCondition( &text->ControlData ) )
		{
			case COND_NONE:
				break;
			case COND_GRAYOUT:
				Status = EFI_WARN_WRITE_FAILURE;
				ColorText = CONTROL_GRAYOUT_COLOR;
				break;
			default:
				return EFI_UNSUPPORTED;
				break;
		}
	//}

	txt = HiiGetString( text->ControlData.ControlHandle, UefiGetTextField((VOID*)text->ControlData.ControlPtr));
	if ( txt == NULL )
		return EFI_OUT_OF_RESOURCES;

 	txt2 = HiiGetString( text->ControlData.ControlHandle, UefiGetTextTwoField((VOID*)text->ControlData.ControlPtr));
	if ( txt2 == NULL )
		return EFI_OUT_OF_RESOURCES;

	gText.SetText(text,txt,txt2);
	MemFreePointer ((VOID **)&txt);
	MemFreePointer ((VOID **)&txt2);

	if ( text->LabelText == NULL )
	{ 
		Status = EFI_UNSUPPORTED;
		return Status;
	}

		// labeltext boundary overflow  check	
	if(text->Height>1 && IsTSEMultilineControlSupported())//EIP-72610 TSE_MULTILINE_CONTROLS moved to binary
	{
		DrawMultiLineStringWithAttribute( (UINTN)text->Left, (UINTN) text->Top, 
					(UINTN)(text->LabelMargin - text->Left),(UINTN)text->Height,
					text->LabelText, text->BGColor |ColorText );
	}
	else
	{
		if ( (TestPrintLength( text->LabelText ) / (NG_SIZE)) > (UINTN)(text->LabelMargin - text->Left  )/*21*/ )
				text->LabelText[HiiFindStrPrintBoundary(text->LabelText ,(UINTN)(text->LabelMargin - text->Left  ))] = L'\0';
	
		DrawStringWithAttribute( text->Left , text->Top, text->LabelText, text->BGColor |  ColorText /*text->FGColor*/  );
	}

	if ( text->Text != NULL )
	{
		//EIP-72610 TSE_MULTILINE_CONTROLS moved to binary
		if(text->Height>1 && IsTSEMultilineControlSupported())
		{
				DrawMultiLineStringWithAttribute( (UINTN)text->Left + text->LabelMargin, (UINTN) text->Top, 
						(UINTN)((text->Width + text->Left)  - text->LabelMargin -2),(UINTN)text->Height,
						text->Text, text->BGColor |ColorText );//EIP 73391 : Adjusted the cordinates to show maximum string in control left area

						
		}
		else
		{
			// text boundary overflow check
			//EIP 73391 : Adjusted the cordinates to show maximum string in control left area
	        if ( (TestPrintLength( text->Text ) / (NG_SIZE)) >= (UINTN)((text->Width + text->Left) - text->LabelMargin -2) )
	            text->Text[HiiFindStrPrintBoundary(text->Text ,(UINTN)((text->Width + text->Left) - text->LabelMargin -2))] = L'\0';
	        DrawStringWithAttribute( text->Left + text->LabelMargin , text->Top, text->Text, text->BGColor |ColorText );
		}
	}

	//EIP-72610 if TSE_MULTILINE_CONTROLS moved to binary
	if(IsTSEMultilineControlSupported())
	{
		FlushLines(text->Top, text->Top + text->Height - 1);
	}
	else
	{
		FlushLines(text->Top, text->Top);
	}

	return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	TextHandleAction
//
// Description:	function to handle the text actions
//
// Input:	TEXT_DATA *text, ACTION_DATA *Data
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS TextHandleAction( TEXT_DATA *text, ACTION_DATA *Data)
{
	EFI_STATUS Status = EFI_UNSUPPORTED;

	if ( (Data->Input.Type == ACTION_TYPE_TIMER) && ((UINT8)text->ControlData.ControlFlags.ControlRefresh != 0))
	{
		Status = CallTextCallBack(text, Data);
	}

	return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	TextSetCallback
//
// Description:	Function to set callback.
//
// Input:		TEXT_DATA *text, OBJECT_DATA *container, OBJECT_CALLBACK callback, VOID *cookie 
//
// Output:		STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS TextSetCallback( TEXT_DATA *text, OBJECT_DATA *container, OBJECT_CALLBACK callback, VOID *cookie )
{
	return gControl.SetCallback( text, container, callback, cookie );
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	TextSetFocus
//
// Description:	Function to set focus.
//
// Input:		TEXT_DATA *text, BOOLEAN focus
//
// Output:		STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS TextSetFocus(TEXT_DATA *text, BOOLEAN focus)
{
	return EFI_UNSUPPORTED;
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	TextSetPosition
//
// Description:	Function to set position.
//
// Input:		TEXT_DATA *text, UINT16 Left, UINT16 Top
//
// Output:		STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS TextSetPosition(TEXT_DATA *text, UINT16 Left, UINT16 Top )
{
	return gControl.SetPosition( text, Left, Top );
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	TextSetDimensions
//
// Description:	Function to set text dimension.
//
// Input:		TEXT_DATA *text, UINT16 Width, UINT16 Height
//
// Output:		STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS TextSetDimensions(TEXT_DATA *text, UINT16 Width, UINT16 Height )
{
	return gControl.SetDimensions( text, Width, Height );
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	TextSetAttributes
//
// Description:	Function to set text attributes.
//
// Input:		TEXT_DATA *text, UINT8 FGColor, UINT8 BGColor
//
// Output:		STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS TextSetAttributes(TEXT_DATA *text, UINT8 FGColor, UINT8 BGColor )
{
	return gControl.SetAttributes( text, FGColor, BGColor );
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	TextSetText
//
// Description:	function to set the text
//
// Input:	TEXT_DATA *text, CHAR16 *label, CHAR16 *value
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS TextSetText( TEXT_DATA *text, CHAR16 *label, CHAR16 *value )
{
	if ( label != NULL )
	{
		MemFreePointer( &text->LabelText );
		text->LabelText = StrDup( label );
	}

	if ( value != NULL )
	{
		MemFreePointer( &text->Text );
		text->Text = StrDup( value );
	}

	return EFI_SUCCESS;
}


//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	TextGetControlHeight
//
// Description:	function to get the text height
//
// Input:	TEXT_DATA *text, Frame,  UINT16 *height
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS TextGetControlHeight( TEXT_DATA *text, VOID* frame,  UINT16 *height )
{
	//EIP-72610 if TSE_MULTILINE_CONTROLS moved to binary
	if(IsTSEMultilineControlSupported())
	{
		CHAR16 *newText = NULL;
		UINT16 tmpHeight=0;
		UINT16 Width;
	
		//EIP-147142  
		//Make sure text->Label and text->text are updated before computing the control height 		
		gText.SetText(text,
		        HiiGetString( text->ControlData.ControlHandle, UefiGetTextField((VOID*)text->ControlData.ControlPtr)),
		        HiiGetString( text->ControlData.ControlHandle, UefiGetTextTwoField((VOID*)text->ControlData.ControlPtr))
		        );
    
		Width = (UINT16)(text->LabelMargin - (((FRAME_DATA*)frame)->FrameData.Left + (UINT8)gLabelLeftMargin));
		newText = StringWrapText( text->Text, (UINT16)(((FRAME_DATA *)frame)->FrameData.Width - text->LabelMargin -2), &tmpHeight );
		*height = tmpHeight;
	    MemFreePointer( (VOID **)&newText );
	
		newText = StringWrapText( text->LabelText, Width, &tmpHeight );
	
		if(tmpHeight > *height)
			*height = tmpHeight;
	
		(*height) = (*height) ? (*height):1;
	
	    MemFreePointer( (VOID **)&newText );
	}
	else
	{
		*height = 1;
	}
	return EFI_SUCCESS;
}


//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**     5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093     **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************