summaryrefslogtreecommitdiff
path: root/EDK/MiniSetup/TseLite/popup.c
blob: 39ec33d6fd31250463e1753fa7270cdd3ade26e2 (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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
//**                                                             **//
//**         (C)Copyright 2014, 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/popup.c $
//
// $Author: Premkumara $
//
// $Revision: 14 $
//
// $Date: 5/03/14 6:22p $
//
//*****************************************************************//
//*****************************************************************//
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseLite/popup.c $
// 
// 14    5/03/14 6:22p Premkumara
// [TAG]	EIP135665
// [Category]	Bug Fix
// Corrected condtion to display multi-line string
// 
// 13    5/03/14 4:01p Premkumara
// [TAG]	                EIP135665
// [Category]	Bug Fix
// [Severity:]	                Important
// [Symptom:]	TSE get hangs, when long string is given as title for
// password
// [Root Cause]	TSE is not handling properl when PasswordTitle length
// exceeds screen width 
// [Solution]	Handled password title length based on screen width and
// given support to display title in multiple lines.
// [Files]	postmgmtext.c, Popup.c, PopupEdit.c, PopupPassword.c 
// 
// 12    5/02/14 1:03p Premkumara
// [TAG]  		EIP154407
// [Category]  	Bug Fix
// [Severity]  	Normal
// [Symptom]  	NVMe Driver - AddBootOption Hang
// [RootCause]  	System hangs When popup->width(NvMe driver path) is more
// than 
// gmaxcol.
// [Solution]  	Added condition to initialize the popup->width =
// gmaxcol-10 when
// it exceeds gmaxcol.
// [Files]  		popup.c
// 
// 11    2/11/14 9:01p Arunsb
// Changes reverted for 2.16.1243 label
// 
// 10    12/06/13 4:49a Premkumara
// [TAG]	EIP135665
// [Category]	Bug Fix
// [Comments]             Corrected condtion properly for password and
// string type control
// 
// 9     12/03/13 9:02a Premkumara
// [TAG]	EIP135665
// [Category]	Bug Fix
// [Severity:]	Important
// [Symptom:]	TSE get hangs, when long string is given as title for
// password
// [Root Cause]	TSE is not handling properl when PasswordTitle length
// exceeds screen width 
// [Solution]	Handled password title length based on screen width and
// given support to display title in multiple lines.
// [Files]	postmgmtext.c, Popup.c, PopupEdit.c, PopupPassword.c 
// 
// 8     10/18/12 6:02a Arunsb
// Updated for 2.16.1235 QA submission
// 
// 10    10/10/12 12:38p Arunsb
// Synched the source for v2.16.1232, backup with Aptio
// 
// 7     12/01/11 1:39a Premkumara
// [TAG]  		EIP73236
// [Category]  	Improvement
// [Description]  	Large amounts of allocated memory are not freed
// [Files]  		Expression.c, PopupEdit.c, Popup.c, MessageBox.c, Menu.c,
// Memo.c,
// 
// 6     11/21/11 8:55a 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, PopupSel.c, PopupString.c, SubMenu.c, Text.c.
// 
// 5     6/28/11 10:14a Madhans
// To remove ";" in unwanted case.
// 
// 4     4/16/10 5:13p Madhans
// Changes for Tse 2.02. Please see Changelog.log for more details.
// 
// 3     2/19/10 1:04p Madhans
// Updated for TSE 2.01. Refer Changelog.log for File change history.
// 
// 4     2/19/10 8:18a Mallikarjunanv
// updated year in copyright message
// 
// 3     6/23/09 6:52p 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
// 
// 1     4/28/09 11:05p 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:58p Madhans
// Intial version of TSE Lite sources
//*****************************************************************//
//*****************************************************************//

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

#include "minisetup.h"

POPUP_METHODS gPopup =
{
	PopupCreate,
	PopupDestroy,
	PopupInitialize,
	PopupDraw,
	PopupHandleAction,
	PopupSetCallback,
	PopupSetFocus,
	PopupSetPosition,
	PopupSetDimensions,
	PopupSetAttributes,
	PopupGetControlHight
};

extern BOOLEAN	IsShowPromptStringAsTitle(VOID);//EIP-116315 password string
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupCreate
//
// Description:	this function uses the create function of control
//					and creates the Popup menu
//
// Input:	POPUP_DATA **object
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupCreate( POPUP_DATA **object )
{
	EFI_STATUS Status = EFI_OUT_OF_RESOURCES;

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

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

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

	return Status;
}

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

	gControl.Destroy( popup, FALSE );

    if( freeMem ){
        MemFreePointer( (VOID **)&popup->Title );//EIP-73236
        MemFreePointer( (VOID **)&popup->Help1 );
        MemFreePointer( (VOID **)&popup->Help2 );
        MemFreePointer( (VOID **)&popup->Help3 );
		MemFreePointer( (VOID **)&popup );
    }

	return EFI_SUCCESS;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupInitialize
//
// Description:	this function uses the initialize function of control
//					and initializes the Popup menu
//
// Input:	POPUP_DATA *popup, VOID *data
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupInitialize( POPUP_DATA *popup, VOID *data )
{
	EFI_STATUS Status = EFI_SUCCESS;

	Status = gControl.Initialize( (CONTROL_DATA *)popup, data );
	if (EFI_ERROR(Status))
		return Status;

	// add extra initialization here...
	popup->PopupBorder = POPUP_SINGLE_BORDER; //Default border

	return Status;
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	GetLineCount
//
// Description:	function to get line count and max width.
//
// Input:	CHAR16 *line, UINT8 *Width 
//					
//
// Output:	UINTN
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
UINTN PopupGetLineCount(CHAR16 *line)
{
	CHAR16 * text;
	UINTN i=1;
	CHAR16 * String=line;
	

	while(1)
	{
		CHAR16 save;

		text = String;
		if ( *String == L'\0' )
			break;

		while ( ( *String != L'\n' ) &&( *String != L'\r' ) && ( *String != L'\0' ) )
			String++;

		save = *String;
		*String = L'\0';

		
		if ( ( *String = save ) != L'\0' )
		{
			if ( *String == L'\r' )
			{	String++;
				i--;
			}
			if ( *String == L'\n' )
			{
				String++;

				if ( *(String - sizeof(CHAR16)) == L'\r' )
					i++;
			}
		}
		else
			break;
		i++;
	}
	return i;
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupDrawString
//
// Description:	function to draw string in a popup menu with attributes
//
// Input:	POPUP_DATA *popup, CHAR16 *Str,UINT16 Top
//
// Output:	void
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID PopupDrawString(POPUP_DATA *popup, CHAR16 *Str,UINT16 Top)
{
	CHAR16 *PadTitle = NULL;
	UINTN Height = 0;
	UINT16 OpCode = 0xFF;


	if ((EFI_IFR_OP_HEADER*)popup->ControlData.ControlPtr) //If it has valid control pointer
	{
		//Skipping ESC code color not to print title in color for Popup controls like OneOf,CheckBox,String,Password(based on token IsShowPromptStringAsTitle)
		if( (popup->ControlData.ControlType == CONTROL_TYPE_POPUPSEL) || 
			 (((EFI_IFR_OP_HEADER *)popup->ControlData.ControlPtr)->OpCode == EFI_IFR_STRING_OP) ||
			 (((EFI_IFR_OP_HEADER *)popup->ControlData.ControlPtr)->OpCode == CONTROL_TYPE_ORDERED_LIST) ||
			 ( IsShowPromptStringAsTitle() && ((EFI_IFR_OP_HEADER *)popup->ControlData.ControlPtr)->OpCode == EFI_IFR_PASSWORD_OP )
			)
		{
			Str = TseSkipEscCode(Str);
		}
	}

	if ((EFI_IFR_OP_HEADER*)popup->ControlData.ControlPtr) //If it has valid control pointer
		OpCode = ((EFI_IFR_OP_HEADER*)popup->ControlData.ControlPtr)->OpCode;

	//If control is of Password OR String type, and Multiline is supported
	if ( ( (OpCode == EFI_IFR_PASSWORD_OP ) || (EFI_IFR_STRING_OP == OpCode) ) && IsTSEMultilineControlSupported() )
	{
		if (Str)
		{
			Height=(EfiStrLen(Str) / popup->Width)+(((EfiStrLen(Str) % popup->Width) > 0)?1:0);
			DrawMultiLineStringWithAttribute (popup->Left+2, Top, popup->Width-3, Height, Str, 0);
		}
	}

	else
	{
		if ( Str != NULL )
		{
			PadTitle = EfiLibAllocateZeroPool( (popup->Width + 3) * sizeof(CHAR16) );

			//If no multiline support truncating the long string and showing ... at last
			if((TestPrintLength( Str) / (NG_SIZE)) > popup->Width)
			{
				UINTN  Index=HiiFindStrPrintBoundary(Str ,popup->Width);
				Str[Index-4] = L'\0';
				Str[Index-5] = L'.';
				Str[Index-6] = L'.';
				Str[Index-7] = L'.';
			}

			if ( PadTitle != NULL )
				SPrint( PadTitle, (EfiStrLen(Str)) * sizeof(CHAR16), L" %s ",Str );
		}
	
		if ( PadTitle )
		{
			DrawStringJustified( 0, gMaxCols, Top, JUSTIFY_CENTER, PadTitle );
			MemFreePointer((VOID **)&PadTitle);
		}
	}
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupDraw
//
// Description:	function to draw popup menu with attributes
//
// Input:	POPUP_DATA *popup
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupDraw( POPUP_DATA *popup )
{
	UINTN NumOfHelpLines = 0, NumOfTitleLines = 0;
	CHAR16 *String = NULL, *text = NULL;
	UINTN i=0;
	

	BOOLEAN bShadow = StyleGetShadowSupport() ;
	popup->Top = (UINT16)(gMaxRows - popup->Height) / 2;
	popup->Left = (UINT16)(gMaxCols - popup->Width) / 2;

   //EIP154407 System hangs if popup->Width is more than gMaxCols  
   if( popup->Width > gMaxCols)
   {
    popup->Width = (UINT16)(gMaxCols - 10);
   }

	
	if(popup->Style == POPUP_STYLE_NORMAL)
	{
		DrawWindow( popup->Left, popup->Top, popup->Width, popup->Height, 
				(UINT8)(popup->BGColor | popup->FGColor) , popup->Border, bShadow );
	
		if ( popup->Title != NULL )
			PopupDrawString(popup,popup->Title,popup->Top);
	}
	else
	{
#define TITLE_LINES	1
#define HELP_LINES	3
	
			
		if ( popup->Title != NULL )
			NumOfTitleLines = 2 ;

		if ( popup->Help1 != NULL )
			NumOfHelpLines = PopupGetLineCount(popup->Help1)+1 ;


		DrawWindow( popup->Left, popup->Top-NumOfTitleLines, popup->Width, popup->Height+NumOfHelpLines+NumOfTitleLines, 
				(UINT8)(popup->BGColor | popup->FGColor), FALSE, FALSE );

		if(NumOfTitleLines)
			DrawBorder( popup->Left, popup->Top-NumOfTitleLines, popup->Width, NumOfTitleLines+1 );
		if(NumOfHelpLines)
			DrawBorder( popup->Left, popup->Top+popup->Height-1, popup->Width, NumOfHelpLines+1);
		DrawBorder( popup->Left, popup->Top-NumOfTitleLines, popup->Width, popup->Height+NumOfHelpLines+NumOfTitleLines );

		if ( popup->Title != NULL )
			PopupDrawString(popup,popup->Title,popup->Top-1);

		//if ( popup->Help1 != NULL )
		//	PopupDrawString(popup,popup->Help1,popup->Top+popup->Height);

		String = popup->Help1 ;

		for(i=0;i<NumOfHelpLines;i++)
		{
			CHAR16 save;

			text = String;
			if ( *String == L'\0' )
				break;

			while ( ( *String != L'\n' ) &&( *String != L'\r' ) && ( *String != L'\0' ) )
				String++;

			save = *String;
			*String = L'\0';

			if((TestPrintLength( text ) / (NG_SIZE)) > (UINTN)(popup->Width-2))
					EfiStrCpy( &text[HiiFindStrPrintBoundary(text,(UINTN)(popup->Width-5))],L"...");
	
			PopupDrawString(popup, text, (UINT16)(popup->Top+popup->Height+i));
			

			if ( ( *String = save ) != L'\0' )
			{
				String++;
				if ( ( *String == L'\r' ) || ( *String == L'\n' ) )
					String++;
			}
		}
	}

	return gControl.Draw( popup );
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSetCallback
//
// Description:	Function to set the Popup callback
//
// Input:		POPUP_DATA *popup, OBJECT_DATA *container, OBJECT_CALLBACK callback, VOID *cookie
//
// Output:		STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupSetCallback( POPUP_DATA *popup, OBJECT_DATA *container, OBJECT_CALLBACK callback, VOID *cookie )
{
	return gControl.SetCallback( popup, container, callback, cookie );
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupHandleAction
//
// Description:	Function to handle the Popup Edit actions
//
// Input:	POPUP_DATA *popup, ACTION_DATA *Data
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupHandleAction( POPUP_DATA *popup, ACTION_DATA *Data)
{
	//do nothing here, the action is handled on the child class either listbox or messagebox
	return EFI_UNSUPPORTED;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSetFocus
//
// Description:	Function to set focus
//
// Input:		POPUP_DATA *popup, BOOLEAN focus
//
// Output:		Status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupSetFocus( POPUP_DATA *popup, BOOLEAN focus)
{
	return EFI_SUCCESS;
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSetPosition
//
// Description:	Function to set focus
//
// Input:		POPUP_DATA *popup, UINT16 Left, UINT16 Top 
//
// Output:		Status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupSetPosition( POPUP_DATA *popup, UINT16 Left, UINT16 Top )
{
	return gControl.SetPosition( popup, Left, Top );
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSetDimensions
//
// Description:	Function to set the dimentions of the editable popup menu
//
// Input:		POPUP_DATA *popup, UINT16 Width, UINT16 Height
//
// Output:		status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupSetDimensions( POPUP_DATA *popup, UINT16 Width, UINT16 Height )
{
	return gControl.SetDimensions( popup, Width, Height );
}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSetAttributes
//
// Description:	Function to set the dimentions of the editable popup menu
//
// Input:		POPUP_DATA *popup, UINT8 FGColor, UINT8 BGColor
//
// Output:		status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupSetAttributes( POPUP_DATA *popup, UINT8 FGColor, UINT8 BGColor )
{
	return gControl.SetAttributes( popup, FGColor, BGColor );
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupGetControlHight
//
// Description:	Function unsuppored.
//
// Input:		VOID *object,VOID *frame, UINT16 *height
//
// Output:		status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupGetControlHight( VOID *object,VOID *frame, UINT16 *height )
{
	return EFI_UNSUPPORTED;
}


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