⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uiprgmgr_new.c

📁 嵌入工linux开发的源码
💻 C
📖 第 1 页 / 共 2 页
字号:

		case WIN_BACK_TO_PRG_MGR:
			//top window已经是 program manager
			if(((DWORD)gpTopWindow) == UIP->hMainWnd||((DWORD)gpTopWindow) == UIP->hSubWnd)
			{
#ifdef PM_HAVE_DIRECTORY
				if((HNDL)gpTopWindow==hSubWnd)
				{
					guiWindow_Show(hMainWnd);
					hCurWnd = hMainWnd;
					guiViewport_DeleteAllControl(hVport);
					freeDLinkList(&UIP->tLaunchableAppList);
				}
#endif
				// 有还在背景的AP,砍
				if (UIP->CurrentApp!=NULL)
				{
					//UIP->CurrentApp->currentWinHandle = NULL ;
#ifdef _DEBUG_PM_
					 remain=_debugDisplayMemInfo("before exit ap");
#endif
					exeWIN_APP_EXIT();
#ifdef _DEBUG_PM_
					 remain=_debugDisplayMemInfo("after exit ap");
#endif
				}
				break ;    // msg processed!!
			}

			//top window是其他AP,砍
			if (UIP->CurrentApp!=NULL)
			{
				UIP->CurrentApp->currentWinHandle = (DWORD)gpTopWindow ;
#ifdef _DEBUG_PM_
					 remain=_debugDisplayMemInfo("before exit ap");
#endif
				exeWIN_APP_EXIT();
#ifdef _DEBUG_PM_
					 remain=_debugDisplayMemInfo("after exit ap");
#endif
			}

			// empty message in system message queue
			guiEmptyQueue(SysMsgQueue) ;

			// empty message in PM message queue
			_guiEmptyQueue(pWnd->messageQueue) ;

			//if add or sub app,reflash launchableapplist
			if(UIP->ExtAppAdded==1)
			{
				guiViewport_DeleteAllControl(hVport);
				freeDLinkList(&UIP->tLaunchableAppList);
				UIP->ExtAppAdded=0;
				//InitLaunchableAppList(0);
				InitLaunchableAppList(NETCOM_TYPE);   // by zhang xue ping
			}

			// switch to main window of PrgMgr
			//guiWindow_Show(hSubWnd);
			guiWindow_Show(hCurWnd);
			//guiDrawLine(0,0,145,159,145,GUI_BLACK,GUI_HATCH);
			//guiDrawLine(0,0, GUI_SCREEN_HEIGHT-16,159, GUI_SCREEN_HEIGHT-16,GUI_BLACK,GUI_HATCH);

			break;

		case PRG_MGR_EXIT_APP:
			if (UIP->CurrentApp->handle!=message.handle)
			{
				guiKillApp(message.handle);
			}
			break;

		case WIN_IS_TOP :
			//if (UIP->hMainWnd!=guiWindow_QueryTop())
			hTopWnd = guiWindow_QueryTop();   // by zhangxp 2003/06/28
			if ((UIP->hMainWnd!=hTopWnd)&&(UIP->hSubWnd!=hTopWnd))
			{
				break;
			}

			// restore keypad callback
			guiRestoreKeyCallback();
			guiRestoreCustomAreaCallback();
			if(UIP->ExtAppAdded == 1)
			{
				UIP->ExtAppAdded = 0 ;
			}
			break ;

		case PRG_MGR_TO_MAIN_WND:

			if((HNDL)gpTopWindow==hMainWnd)
				break;
			
			if((HNDL)gpTopWindow==hSubWnd)
			{
				guiWindow_Show(hMainWnd);
				hCurWnd = hMainWnd;
				guiViewport_DeleteAllControl(hVport);
				freeDLinkList(&UIP->tLaunchableAppList);
#ifndef __WIN32__
				stop_MP3_proc();
#endif
				break;
			}

			if((gpTopWindow != NULL)&&(gpTopWindow->ownerThreadID > 2))
				sc_suspend(gpTopWindow->ownerThreadID);

			exeWIN_APP_EXIT();
			guiWindow_Show(hMainWnd);
			hCurWnd = hMainWnd;
			guiViewport_DeleteAllControl(hVport);
			freeDLinkList(&UIP->tLaunchableAppList);
#ifndef __WIN32__
			stop_MP3_proc();
#endif

/*
			tempMessage.messageType = WIN_BACK_TO_PRG_MGR ;
			_guiEnqueue(((TWindow *)(UIP->hMainWnd))->messageQueue,&tempMessage);
			if((gpTopWindow != NULL)&&(gpTopWindow->ownerThreadID > 2))
				sc_suspend(gpTopWindow->ownerThreadID);
*/
			break;

		case WIN_RETURN:

			if((HNDL)gpTopWindow==hMainWnd)
				break;

			guiWindow_Show(hMainWnd);
			hCurWnd = hMainWnd;
			guiViewport_DeleteAllControl(hVport);
			freeDLinkList(&UIP->tLaunchableAppList);
			break;

		default:
			break;
		}
	}

}

/*************************************************************/
//	Internal function
/*************************************************************/
static STATUS PrgmngUI_Init(void)
{
    // allocate common objects
	UIP=(struct tagPU_CommonObj *)sc_malloc(sizeof(struct tagPU_CommonObj));
	if (UIP==NULL)
		return STATUS_ERR;

	// initialize flags
	UIP->ExtAppAdded=0;

	// get application list
	UIP->pAppList = guiGetAppList();
	initDLinkList(&UIP->tLaunchableAppList);

	UIP->CurrentApp = NULL;

	return STATUS_OK;
}


STATUS InitLaunchableAppList(int iTypeID)
{
	int i=0;
	int classID;

	struct dLinkList *pAppList;
	TPM_APP *pTempApp;
	TLaunchableApp *pLaunchable;

	TBitmapCaption bitmapCaption;

	pAppList=UIP->pAppList->back;

	while(pAppList)
	{
		pTempApp=(TPM_APP *)pAppList->elementPointer;

		classID = (pTempApp->classs)/100;
		if(pTempApp&&(classID==iTypeID))
		//if(classID==iTypeID)
		{
			int x1, y1, x2, y2;

			x1 = PM_ICON_START_X_SUB+(i%2)*(PM_ICON_RANGE_WIDTH+PM_ICON_INTERVAL_X_SUB);
			y1 = PM_ICON_START_Y+(i/2)*(PM_ICON_RANGE_HEIGHT+PM_ICON_INTERVAL_Y);
			x2 = PM_ICON_START_X_SUB+(i%2)*(PM_ICON_RANGE_WIDTH+PM_ICON_INTERVAL_X_SUB)+PM_ICON_RANGE_WIDTH;
			y2 = PM_ICON_START_Y+(i/2)*(PM_ICON_RANGE_HEIGHT+PM_ICON_INTERVAL_Y)+PM_ICON_RANGE_HEIGHT;

			pLaunchable=(TLaunchableApp *)sc_malloc(sizeof(TLaunchableApp));
			if(pLaunchable==NULL)
			{
				return STATUS_ERR;
			}
			pLaunchable->pApp=pTempApp;
			#if 0
			//240*160
			pLaunchable->hBitmap=guiBitmap_Create(PM_ICON_START_X_SUB+(i%4)*(PM_ICON_RANGE_WIDTH+PM_ICON_INTERVAL_X_SUB),
									  PM_ICON_START_Y+(i/4)*(PM_ICON_RANGE_HEIGHT+PM_ICON_INTERVAL_Y),
									  PM_ICON_START_X_SUB+(i%4)*(PM_ICON_RANGE_WIDTH+PM_ICON_INTERVAL_X_SUB)+PM_ICON_RANGE_WIDTH,
									  PM_ICON_START_Y+(i/4)*(PM_ICON_RANGE_HEIGHT+PM_ICON_INTERVAL_Y)+PM_ICON_RANGE_HEIGHT,
									  pTempApp->iconBitmap,0);
			#else
			//160*160
			pLaunchable->hBitmap=guiBitmap_Create(x1, y1, x2, y2, pTempApp->iconBitmap,0);
			#endif

			//guiBitmap_SetString(pLaunchable->hBitmap,pTempApp->appName);
			strcpy(bitmapCaption.szCaption_ENG, pTempApp->appName[0]);
			strcpy(bitmapCaption.szCaption_CHT, pTempApp->appName[1]);
			strcpy(bitmapCaption.szCaption_CHS, pTempApp->appName[2]);
			guiBitmap_SetString(pLaunchable->hBitmap, &bitmapCaption);

			guiBitmap_SetPicLocation(pLaunchable->hBitmap,PM_ICON_DISPLAY_X,PM_ICON_DISPLAY_Y);
			guiViewport_AddControl(UIP->hVport,pLaunchable->hBitmap);
			guiControl_Enable(pLaunchable->hBitmap);
			insertTo(&UIP->tLaunchableAppList,pLaunchable);
			i++;

		}
		pAppList=pAppList->back;
	}

	return STATUS_OK;
}

/**************************************************************
    FUNCTION : exeWIN_APP_EXIT
    -
**************************************************************/
void exeWIN_APP_EXIT(void)
{
	int i;
	TGuiMessage tempMessage;

	// 纪录app中所注册之key的function pointer
	for(i=0;i<GUI_MAX_KEY_NUMBER;i++)
	{
		UIP->CurrentApp->keyFun[i] = gaKeyHandler[i] ;
	}

	tempMessage.messageType = WIN_APP_EXIT;
	tempMessage.handle = UIP->CurrentApp->handle;
	#ifdef CLEANUP_BY_APP
	// notify AP to cleanup
	_guiEnqueue(gpTopWindow->messageQueue, &tempMessage);
	#else
	// cleanup AP by PM
	UIP->CurrentApp->action(&tempMessage);
	#endif
	UIP->CurrentApp = NULL;
}


DLL_EXP(int) guiRegisterExApp(char *szFileName)
{
	int i,len,num;
	int hFile_Register;
	unsigned char Buffer[DL_FNAME_MAX_LEN];

	TPM_APP *hitApp;
	struct dLinkList * temp = &ApplicationList ;
	short found = 0 ;                // 0 : not found ; 1 : found

	char  fNull = 0;
                         
	//register file              
        
	hFile_Register=fs_open(FNAME_LOADEDAP,O_RDWR);
	if(hFile_Register<0) 
	{
    	hFile_Register=fs_open(FNAME_LOADEDAP,O_RDWR|O_CREATE);
	
	}

	//hFile_Register=fs_open(FNAME_LOADEDAP,O_CREATE);


	if(hFile_Register<0)
	{
		return STATUS_ERR;
	}

	len=fs_filelength(hFile_Register);
	num=len/DL_FNAME_MAX_LEN;
	len=num*DL_FNAME_MAX_LEN;
	for(i=0;i<num;i++)
	{
		fs_read(hFile_Register,Buffer,DL_FNAME_MAX_LEN);
		if(strcmp((char *)Buffer,szFileName)==0)
		{
			break;
			//fs_close(hFile_Register);
			//return STATUS_OK;
		}          

		if(!Buffer[0])    // by zhangxp  2003/06/21
		{
        	fNull = 1;
			break;
		}
	}
               
	if(fNull==1)   // by zhangxp  2003/06/21
	{
		fs_lseek(hFile_Register, i*DL_FNAME_MAX_LEN, SEEK_SET); 
		fs_write(hFile_Register,(unsigned char *)szFileName, DL_FNAME_MAX_LEN);
	}	              
	else if(i!=num)   // by zhangxp  2003/06/21
	{
		//remove from ApplicationList
		sc_disableInt() ;

		// find out which app should be deleted
		while(temp->back != NULL)
		{
			temp = temp->back ;
			hitApp = (TPM_APP *)(temp->elementPointer) ;
			if(strcmp(szFileName,(char *)hitApp->runtimeInfo.name)==0&&hitApp->type==PRG_MGR_EXTERNAL_APP)
			{
				found = 1 ;
				break ;
			}
		}

		if(found == 1)
		{
			if(hitApp->mainThreadID != -1)
			{
				deleteThreadTree(hitApp->mainThreadID) ;
			}

			//release icon buffer
			if(hitApp->iconBitmap!=icon_Gui_System)
			{
				sc_free(hitApp->iconBitmap);
			}

			// 将该app自applicatin list中移除
			sc_free((void *)(temp->elementPointer)) ;
			removeFrom(temp) ;
			UIP->ExtAppAdded = 1;
		}
		sc_enableInt() ;
                        
	}
	else
	{
		fs_lseek(hFile_Register, len, SEEK_SET);
		fs_write(hFile_Register,(unsigned char *)szFileName, DL_FNAME_MAX_LEN);
	}

	fs_close(hFile_Register);

	if(guiAddExternalApp(szFileName)!=STATUS_OK)
	{
		return STATUS_ERR;
	}
	UIP->ExtAppAdded = 1;

	return STATUS_OK;
}

DLL_EXP(int) guiUnRegisterExApp(char *szFileName)
{
	int i,len,len1,num;
	int hFile_Register;
	unsigned char Buffer[DL_FNAME_MAX_LEN];
	unsigned char *pBackup;

	TPM_APP *hitApp;
	struct dLinkList * temp = &ApplicationList ;
	short found = 0 ;                // 0 : not found ; 1 : found

	//register file
	hFile_Register=fs_open(FNAME_LOADEDAP,O_CREATE);
	if(hFile_Register<0)
	{
		return STATUS_ERR;
	}

	len=fs_filelength(hFile_Register);
	num=len/DL_FNAME_MAX_LEN;
	len=num*DL_FNAME_MAX_LEN;

	//find record
	for(i=0;i<num;i++)
	{
		fs_read(hFile_Register,Buffer,DL_FNAME_MAX_LEN);
		if(strcmp((char *)Buffer,szFileName)==0)
		{
			break;
		}
	}

	if(i==num)
	{
		//not find
		goto ERROR_RET;
	}

	//find,truncate file
	len1=(i+1)*DL_FNAME_MAX_LEN;
	fs_lseek(hFile_Register,len1,SEEK_SET);
	len1=len-len1;
	pBackup=(unsigned char *)sc_malloc(len1);
	if(pBackup==NULL)
	{
		goto ERROR_RET;
	}                                

	fs_read(hFile_Register, pBackup, len1);
	fs_lseek(hFile_Register, i*DL_FNAME_MAX_LEN, SEEK_SET);
	fs_write(hFile_Register,pBackup,len1);       
                                                    
	// by zhangxp, for fs_truncate() is invalid
	memset(pBackup, 0x00, DL_FNAME_MAX_LEN);
    fs_write(hFile_Register,pBackup,DL_FNAME_MAX_LEN);

	fs_truncate(hFile_Register,len-DL_FNAME_MAX_LEN);
	sc_free(pBackup);
	fs_close(hFile_Register);

	//remove from ApplicationList
	sc_disableInt() ;

	// find out which app should be deleted
	while(temp->back != NULL)
	{
		temp = temp->back ;
		hitApp = (TPM_APP *)(temp->elementPointer) ;
		if(strcmp(szFileName,(char *)hitApp->runtimeInfo.name)==0&&hitApp->type==PRG_MGR_EXTERNAL_APP)
		{
			found = 1 ;
			break ;
		}
	}

	if(found == 1)
	{
		if(hitApp->mainThreadID != -1)
		{
			deleteThreadTree(hitApp->mainThreadID) ;
		}

		//release icon buffer
		if(hitApp->iconBitmap!=icon_Gui_System)
		{
			sc_free(hitApp->iconBitmap);
		}

		// 将该app自applicatin list中移除
		sc_free((void *)(temp->elementPointer)) ;
		removeFrom(temp) ;
		UIP->ExtAppAdded = 1;
	}
	sc_enableInt() ;

	return STATUS_OK;

ERROR_RET:
	fs_close(hFile_Register);
	return STATUS_ERR;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -