summaryrefslogtreecommitdiff
path: root/EDK/MiniSetup/TseLite/application.c
blob: 0ede072df1656f8649bcde3972180ff15d59ddc0 (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
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
//**                                                             **//
//**         (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/application.c $
//
// $Author: Arunsb $
//
// $Revision: 12 $
//
// $Date: 5/03/14 4:33p $
//
//*****************************************************************//
//*****************************************************************//
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseLite/application.c $
// 
// 12    5/03/14 4:33p Arunsb
// Build error rectified
// 
// 11    5/03/14 3:38p Arunsb
// [TAG]	EIP154569
// [Category]	Improvement
// [Description]	Handling clicks in application level for 80*25 mode also.
// [Files]	LegacyBin.sdl. EzportBin.sdl, EzportPlusBin.sdl and
// application.c
// 
// 10    9/19/13 8:01a Arunsb
// [TAG]	EIP127375
// [Category]	Bug Fix
// [Severity:]	Critical
// [Symptom:]	Legacy boot doesn't work after UEFI Shell is launched from
// LaunchAppHotkey menu. The system hangs
// [Root Cause]	If ShowPostMsgBoxEx is invoked through postmgr protcol
// then gMsgBoxAction will be NULL initially,
// so this time action is assigned and used. 
// ACTION_DATA *action = gMsgBoxAction; so accessing NULL pointer leads to
// hang.
// [Solution]	gMsgBoxAction is created again inside ShowPostMsgBoxEx, 
// reassign gMsgBoxAction to action.
// [Files]	TseAdvanced.c
// 
// 9     5/22/13 10:40a Arunsb
// [TAG]  		EIP122907
// [Category]  	Improvement
// [Description]  	For getting name value offset preserving page number
// then it will be easy to find handle of the hii which published name
// value.
// 
// 8     10/18/12 6:01a 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
// 
// 7     6/29/11 6:21p Rajashakerg
// Updated the file for Hotkey and hotclicks to return their exact status
// 
// 6     6/29/11 12:52p Rajashakerg
// [TAG]  		EIP47086
// [Category]  	New Feature
// [Description]  	Right clicking from the Main page is not exiting from
// BIOS setup.
// 
// [Files]  		minisetup.h, Ezport\style.h,Ezport\EzportBin.sdl,
// Ezport\EzportBin.mak, Ezport\ezport.c, Ezport\EzportBin.cif,
// EzportPlus\style.h, EzportPlus\EzportPlusBin.sdl, EzportPlusBin.mak,
// EzportPlus\EzportPlusBin.cif, EzportPlus\ezportplus.c, Legacy\style.h,
// Legacy\EzportPlusBin.sdl, Legacy\LegacyBin.mak, Legacy\LegacyBin.cif,
// Legacy\legacy.c, TseLiteBin.sdl, TseLite.cif, Memo.c, frame.c,
// application.h, application.c, commonoem.h, CommonHelper.c
// 
// 5     3/26/10 5:06p Madhans
// EIP 36704 : Fix for Making sure to make the Variable to NULL after it
// is Freed up.
// 
// 4     2/19/10 1:04p Madhans
// Updated for TSE 2.01. Refer Changelog.log for File change history.
// 
// 6     2/19/10 8:18a Mallikarjunanv
// updated year in copyright message
// 
// 5     1/09/10 6:25a Mallikarjunanv
// Updated TSE2.01 Release sources with coding standards
// 
// 4     8/19/09 12:58p Madhans
// To handle ToggleStateKeys
// 
// 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:04p 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:		Application.c
//
// Description:	This file contains code to handle Application.
//
//----------------------------------------------------------------------------
//<AMI_FHDR_END>

#include "minisetup.h"

APPLICATION_METHODS gApplication =
{
	ApplicationCreate,
	ApplicationDestroy,
	ApplicationInitialize,
	ApplicationEmptyMethod,
	ApplicationHandleAction,
	ApplicationSetCallback,
	ApplicationAddPage
};

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	ApplicationCreate
//
// Description:	Function to create an application, which uses the Object functions.
//
// Input:	APPLICATION_DATA **object
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS ApplicationCreate( APPLICATION_DATA **object )
{
	EFI_STATUS Status = EFI_SUCCESS;

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

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

	Status = gObject.Create( object );
	if ( EFI_ERROR( Status ) )
	{
		MemFreePointer( (VOID **)object );
		return Status;
	}

	(*object)->Methods = &gApplication;
	(*object)->CompleteRedraw = TRUE;

	return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	ApplicationDestroy
//
// Description:	Function to destroy an application, which uses the Object functions.
//
// Input:	APPLICATION_DATA *app, BOOLEAN freeMem
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS ApplicationDestroy( APPLICATION_DATA *app, BOOLEAN freeMem )
{
	UINT32 i;

	if ( app->Action )
		gAction.Destroy( app->Action, TRUE );

	app->Action = NULL;
	gMsgBoxAction = NULL;			//EIP127375, if not made NULL here, then TSE will try to use the freed memory in above step.

	for ( i = 0; i < app->PageCount; i++ )
		if(app->PageList[i] !=NULL)
			gPage.Destroy( app->PageList[i], TRUE );

	if ( app->PageList )
		MemFreePointer( (VOID **)&app->PageList );

	for ( i = 0; i < app->HotKeyCount; i++ )
		gHotKey.Destroy( app->HotKeyList[i], TRUE );
	
//EIP:47086 - Right clicking from the Main page is not exiting from BIOS setup.
	for ( i = 0; i < app->HotClickCount; i++ )
		gHotClick.Destroy( app->HotClickList[i], TRUE );

	if ( app->HotKeyList )
		MemFreePointer( (VOID **)&app->HotKeyList );
	
//EIP:47086 - Right clicking from the Main page is not exiting from BIOS setup.
	if ( app->HotClickList )
		MemFreePointer( (VOID **)&app->HotClickList );
	

	gObject.Destroy( app, FALSE );

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

	return EFI_SUCCESS;
}

EFI_STATUS ApplicationEmptyMethod( APPLICATION_DATA *app )
{
	return EFI_SUCCESS;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	ApplicationInitialize
//
// Description:	Function to initialize an application, which uses the Object functions.
//
// Input:	APPLICATION_DATA *app, VOID *data
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
extern UINT32	gtempCurrentPage;
EFI_STATUS ApplicationInitialize( APPLICATION_DATA *app, VOID *data )
{
	EFI_STATUS Status;

	UINT32 i;

	Status = gAction.Create( &app->Action );
	if ( EFI_ERROR( Status ) )
		return Status;

	if ( gPages->PageCount == 0 )
		return EFI_OUT_OF_RESOURCES;

	for ( i = 0; i < gPages->PageCount; i++ )
	{
		if (NULL == gApp)
		{
			gtempCurrentPage = i;					//Will be used in UefiGetQuestionOffset. Since gApp will not be filled but we need handle to find name value variable so
		}												//saving current page
		else
		{
			gApp->CurrentPage = i;
		}
		ApplicationAddPage( app, (UINT8 *)data + gPages->PageList[i] );
	}

	app->HotKeyList = EfiLibAllocateZeroPool( sizeof(HOTKEY_DATA *) * gHotKeyCount );
	
//EIP:47086 - Right clicking from the Main page is not exiting from BIOS setup.
	app->HotClickList = EfiLibAllocateZeroPool( sizeof(HOTCLICK_DATA *) * gHotClickCount );

	if ( app->HotKeyList == NULL )
		return Status;
	
//EIP:47086 - Right clicking from the Main page is not exiting from BIOS setup.
	if ( app->HotClickList == NULL )
		return Status;

	app->HotKeyCount = gHotKeyCount;
	
//EIP:47086 - Right clicking from the Main page is not exiting from BIOS setup.
	app->HotClickCount = gHotClickCount;

	for ( i = 0; i < app->HotKeyCount; i++ )
	{
		if ( gHotKey.Create( &app->HotKeyList[i] ) != EFI_SUCCESS )
			continue;

		gHotKey.Initialize( app->HotKeyList[i], &gHotKeyInfo[i] );
		gHotKey.SetCallback( app->HotKeyList[i], app, gHotKeyInfo[i].Callback, NULL );
	}

//EIP:47086 - Right clicking from the Main page is not exiting from BIOS setup.
	for ( i = 0; i < app->HotClickCount; i++ )
	{
		if ( gHotClick.Create( &app->HotClickList[i] ) != EFI_SUCCESS )
			continue;

		gHotClick.Initialize( app->HotClickList[i], &gHotClickInfo[i] );
		gHotClick.SetCallback( app->HotClickList[i], app, gHotClickInfo[i].Callback, NULL );
	}

	return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	ApplicationHandleAction
//
// Description:	Function to handle the application actions.
//
// Input:	APPLICATION_DATA *app, ACTION_DATA *action
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS ApplicationHandleAction( APPLICATION_DATA *app, ACTION_DATA *action )
{
	EFI_STATUS Status = EFI_UNSUPPORTED;
	UINT32 i;

	for ( i = 0; i < app->HotKeyCount; i++ )
	{
		Status = gHotKey.HandleAction( app->HotKeyList[i], action );

		if ( ! EFI_ERROR(Status) )
			goto DONE;
	}
	
//EIP:47086 - Right clicking from the Main page is not exiting from BIOS setup.
	if ((31 == gMaxRows) && (100 == gMaxCols))
	{
		for ( i = 0; i < app->HotClickCount/2; i++ )
		{
			Status = gHotClick.HandleAction( app->HotClickList[i], action );
	
			if ( ! EFI_ERROR(Status) )
				return Status;
		}
	}
	else if ((24 == gMaxRows) && (80 == gMaxCols))
	{
		for ( i = (UINT32)(app->HotClickCount/2); i < (app->HotClickCount-1); i++ )
		{
			Status = gHotClick.HandleAction( app->HotClickList[i], action );
	
			if ( ! EFI_ERROR(Status) )
				return Status;
		}
	}
DONE:
	if(Status!=EFI_SUCCESS && IsToggleStateKey(action))	
		Status = EFI_SUCCESS;

	return Status;
}

EFI_STATUS ApplicationSetCallback( APPLICATION_DATA *app, OBJECT_DATA *container, OBJECT_CALLBACK callback, VOID *cookie )
{
	return gObject.SetCallback( app, container, callback, cookie );
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	ApplicationAddPage
//
// Description:	Function to add a page to the application.
//
// Input:	APPLICATION_DATA *app, VOID *data
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS ApplicationAddPage( APPLICATION_DATA *app, VOID *data )
{
	EFI_STATUS Status = EFI_OUT_OF_RESOURCES;
	PAGE_DATA **page;
	UINT32 count = app->PageCount;

	page = MemReallocateZeroPool( app->PageList, count * sizeof(PAGE_DATA *), (count + 1) * sizeof(PAGE_DATA *) );
	if ( page == NULL )
		return Status;

	app->PageList = page;
	page = &app->PageList[ count ];

	if( ((PAGE_INFO*)data)->PageHandle == 0)
	{
        app->PageCount++;
		//return EFI_SUCCESS , page space left , but no page to create.
		return EFI_SUCCESS;
	}

	Status = gPage.Create( page );
	if ( ! EFI_ERROR( Status ) )
	{
		Status = gPage.Initialize( *page, data );
		if ( ! EFI_ERROR( Status ) )
			app->PageCount++;
		else
		{
			gPage.Destroy( *page, TRUE );
			*page = NULL;
		}
	}

	return Status;
}


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