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

📄 asixwin.c

📁 基于东南大学开发的SEP3203的ARM7中的所有驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
}


U32 SetFocus(U32 Wndid)
{
	U32				oldfocus;
	ASIX_WINDOW 	*oldptr, *newptr;
	MSG				msg;
	U32  			curwin;
	SYSTCB		 	*curtask;	

	newptr = (ASIX_WINDOW *)Wndid;
	if( newptr == NULL || ( newptr->status & WST_NORMAL ) != WST_NORMAL )
		return 0;

	if( !( newptr->status & WST_EN_FOCUS ) )
		return 0;

	curwin = GetCurWindow();
	curtask = GetCurTask();
	
	if( IsMyWindow(Wndid, curwin) != ASIX_OK ) return 0;
	
	oldfocus = GetFocus(); //(U32)FocusWindow;we will discard the global var By Lingming 2002/03/20
	oldptr = (ASIX_WINDOW *)oldfocus;
	if( oldptr == newptr )
		return oldfocus;
	
	//we need use msg to tell the related controls the focus changed! 
	//By Lingming 2001/11/28	
	memset( (void *)&msg, 0x0, sizeof(MSG) );
	msg.messageType = ASIX_MESSAGE;
	msg.wparam =0;			
	
	
	if ( (oldptr != NULL) && (IsMyWindow(oldfocus, curwin) == ASIX_OK) )
	{
		oldptr->status &= ~WST_FOCUS;
		msg.message = WM_LOOSEFOCUS;//The old guy lost the focus, and tell it.By Lingming 2001/11/28
		msg.lparam = (U32)oldptr;
		msg.data = oldptr->ctrl_str;		
		AdvSendMessage(curtask->id, (P_MESSAGE)&msg, NO_SWAP_TASK);
	}
		
	newptr->status |= WST_FOCUS;
	msg.message = WM_GETFOCUS;//we got the focus, tell the control.By Lingming 2001/11/28
	msg.lparam = (U32)newptr;
	msg.data = newptr->ctrl_str;		

	AdvSendMessage(curtask->id, (P_MESSAGE)&msg, NO_SWAP_TASK);
	
	//FocusWindow = newptr;//we will discard the global var By Lingming 2002/03/20
	
	return oldfocus;
}

U32 GetFocus(void)
{
	
	ASIX_WINDOW  	*curwin;
	
//	curwin = (ASIX_WINDOW *)GetCurWindow();
	curwin = gSysTcbTbl[gLcdOwnerTskId-1].wnd_ptr;
	
	return (U32)FocusLookUp(curwin);
}

STATUS EnableFocus( U32 wndid, U8 state )
{
	ASIX_WINDOW  	*wnd = (ASIX_WINDOW *)wndid;
	
	if( wnd == NULL && ( wnd->status & WST_NORMAL ) != WST_NORMAL )
		return ASIX_ERROR;

	if( state == TRUE )
		wnd->status |= WST_EN_FOCUS;	// enable focus
	else
		wnd->status &= ~WST_EN_FOCUS;	// disable focus
	
	return ASIX_OK;
}

ASIX_WINDOW *FocusLookUp(ASIX_WINDOW *wndhead)
{
	ASIX_WINDOW *wndptr, *rv = NULL;
	
	wndptr = wndhead;
	
	if ( wndptr == NULL ) return NULL;
	
	if ( wndptr->status & WST_FOCUS ) return wndptr;
	
	if (wndptr->child==NULL)
		wndptr = wndptr->next;	//what if this is a empty form? the next
								//one would be the back_end form!!
	else 
		wndptr = wndptr->child;
	
	while(1)
	{
		if(wndptr == NULL) {
			rv = wndptr;
			break;
		}	
		
		if(wndptr->child==NULL)
		{
			if ( wndptr->status & WST_FOCUS) {
				rv = wndptr;
				break;
			}else{ 
				wndptr = wndptr->next;
				continue;
			}	
		}
		
		if( (rv = FocusLookUp(wndptr)) != NULL) 
			break;
		else 
			wndptr = wndptr->next;
	}
	
	
	return rv;	

}

/* CreateWindow calls this func*/
static STATUS PushWindow(void)
{
	/*we need to do this in the back end*/
	/*Test, modified by Lingming 2002/03/07*/
	/*ASIX_WINDOW *wndptr;
    ID			id;

	get_tid( &id );
	wndptr = ( ASIX_WINDOW *)gSysTcbTbl[id-1].wnd_ptr;
	*/
	/*------------------------------------*/

	ASIX_WINDOW *curwin;

	curwin = (ASIX_WINDOW *)GetCurWindow();
	
	if (curwin !=NULL && (!(curwin->status & WST_PUSHED)) )
	{
		ActiveListPush();
		curwin->status |= WST_PUSHED;
	} else 
		return ASIX_ERROR;
		
	return ASIX_OK;
	
}

/* Destroy Window calls this func*/
static STATUS PopWindow(void)
{
	/*we need to do this in the back end*/
	/*Test, modified by Lingming 2002/03/07*/
	/*ASIX_WINDOW *wndptr;
    ID			id;

	get_tid( &id );
	wndptr = ( ASIX_WINDOW *)gSysTcbTbl[id-1].wnd_ptr;
	*/
	ASIX_WINDOW *curwin;

	curwin = (ASIX_WINDOW *)GetCurWindow();

	
	if (curwin->status & WST_PUSHED)
		ActiveListPop();
	else 
		return ASIX_ERROR;
			
	curwin->status &= (~WST_PUSHED);
	return ASIX_OK;
}	
	
STATUS RepaintWindow(U32 Wndid, U32 lparam)
{
	register ASIX_WINDOW	*wndptr, *childlist;
	STATUS 					rv = ASIX_OK;
	U32		hGC;
	
	
	if ( IsMyWindow(Wndid, GetCurWindow() ) != ASIX_OK ) return ASIX_ERROR; 
	
	wndptr = (ASIX_WINDOW *)Wndid;
	
	if (wndptr->wndclass->repaint == NULL) return ASIX_OK;

	hGC = GetGC();
	GroupOn( hGC );

	rv = (*wndptr->wndclass->repaint)(wndptr->ctrl_str, lparam);
	
	if( wndptr->child == NULL )
	{	
		GroupOff( hGC, wndptr->x, wndptr->y, wndptr->x + wndptr->width -1, wndptr->y + wndptr->hight -1 );
		return rv;
	}

	childlist = wndptr->child->prev;
	do{
		rv = RepaintWindow((U32)childlist, lparam);
		childlist = childlist->prev;
		
	}while( childlist->next != NULL );
	
	GroupOff( hGC, wndptr->x, wndptr->y, wndptr->x + wndptr->width -1, wndptr->y + wndptr->hight -1 );

	return rv;
}	

// longn_qi	2002/09/09 added
STATUS PopUpWindow( U32 Wndid, U32 reserved )
{
	ID	tskid;
	ASIX_WINDOW	*wndptr;

	wndptr = (ASIX_WINDOW *)Wndid;

	if( wndptr == NULL || wndptr->wndclass == NULL )
		return ASIX_ERROR;
	
	if( wndptr->wndclass->wndclass_id != WNDCLASS_WIN )
		return ASIX_ERROR;

	get_tid( &tskid );

	if( tskid == gLcdOwnerTskId )
		return ASIX_OK;
	else
	{
		U16	xdes = wndptr->x + wndptr->width -1, ydes = wndptr->y + wndptr->hight -1;
		SYSTCB	*pHead;
		
		pHead = TaskHead;
		while( pHead != NULL && pHead->next != &gSysTcbTbl[tskid-1] )
			pHead = pHead->next;
		if( pHead != NULL )
		{
			pHead->next = gSysTcbTbl[tskid-1].next;
		}
		if( TaskHead != &gSysTcbTbl[tskid-1])
		{
			gSysTcbTbl[tskid-1].next = TaskHead;
			TaskHead = &gSysTcbTbl[tskid-1];
		}

		gLcdOwnerTskId = tskid;
		Write2LCD( wndptr->x, wndptr->y, xdes, ydes, gSysTcbTbl[tskid-1].gc->vram );
		{
			MSG	switchmsg;
			
			switchmsg.message = SM_SWITCH;
			switchmsg.wparam = SWAP_TO_FOREGROUND;
			switchmsg.lparam = gLcdOwnerTskId;
			SysSendMessage( gLcdOwnerTskId, &switchmsg );
		}
	}

	return ASIX_OK;
}

STATUS  IsMyWindow(U32 Wndid, U32 Head)
{
	register ASIX_WINDOW	*parent;
	
	///////////////////////////////////////////////
	//for muti task, we maybe can not use this func
	//just for debugging we donot check and just 
	//return ASIX_OK
	//return ASIX_OK;
	//////////////////////////////////////////////
	
	if ( Wndid == 0 || Head == 0 ) return ASIX_ERROR;
	if ( Wndid == Head ) return ASIX_OK;
	
	
	parent = (ASIX_WINDOW *)Wndid;

	/*Window id validation checking. By Lingming 2001/11/27*/
	/*we must do this, because the id user input maybe wrong or the window
	  has already be destroyed, it is just a invalid ghost!!*/	
	if ( (parent->status & WST_NORMAL) != WST_NORMAL) 
		return ASIX_ERROR;//the windows id is not valid or had been detroyed

	for ( parent = (ASIX_WINDOW *)(parent->parent_id);
	parent != NULL && parent != (ASIX_WINDOW *)Head;
	parent =(ASIX_WINDOW *)(parent->parent_id) );
	
	/*while ( parent != NULL && parent != (ASIX_WINDOW *)Head){
		parent =(ASIX_WINDOW *)(parent->parent_id);
		
	}*/
	
	if (parent == NULL) return ASIX_ERROR;
	
	return ASIX_OK;
	
	/*wndhead = (ASIX_WINDOW *)Head;
	
	if (wndptr == NULL || wndhead == NULL ) return ASIX_ERROR;
	
	if ( wndhead == wndptr )
		return ASIX_OK;
			
	if (wndhead->child == NULL)
		wndlist = wndhead->next;
	else
		wndlist = wndhead->child;
		
	while(1)
	{
		if(wndlist == NULL) 
			break;
		if(wndlist->child==NULL)
		{
			if ( wndlist== wndptr ) 
				break;
			else
			{ 
				wndlist = wndlist->next;
				continue;
			}	
		}
		
		if( IsMyWindow(Wndid, (U32)wndlist) == ASIX_OK ) 
			break;
		else 
			wndlist = wndlist->next;
	}
		
	if (wndlist==NULL)
		return ASIX_ERROR;
	
	return ASIX_OK;	*/		
	
}	

STATUS GetWindowStatus(U32 Wndid, P_U32 Status)
{
	
	ASIX_WINDOW		*wndptr;
	
	if ( Wndid == 0 ) return ASIX_ERROR;
	if ( IsMyWindow(Wndid, GetCurWindow() ) != ASIX_OK ) return ASIX_ERROR; 
	
	wndptr = (ASIX_WINDOW *)Wndid;	
	
	*Status = wndptr->status;
	
	return ASIX_OK;	
	
	
}

/*This function returns the toppest window of the current running task*/
U32 GetCurWindow( void )
{
     
     ID		id;

	get_tid( &id );
	return  ( U32 )gSysTcbTbl[id-1].wnd_ptr;
     
	
}



static STATUS IsMyMessage(ASIX_WINDOW *Head,PMSG pMessage, P_MESSAGE pOldmsg)
{
	register ASIX_WINDOW	*wndlist = NULL;
	STATUS 					rv = ASIX_NO_MSG;
	
	if ( Head==NULL || pMessage==NULL || pOldmsg==NULL) return ASIX_ERROR;
	if ( Head->wndclass->wndclass_id >= WNDCLASS_MAX ) return ASIX_ERROR;
	
	// we will do the recursive searching, which control I belong to?
	if ( Head->status & WST_ENABLE)
		rv = (*Head->wndclass->msg_trans)(Head->ctrl_str, pOldmsg->message,
				pOldmsg->misc, pOldmsg->data, pOldmsg->size, pMessage);
	
	if ( rv == ASIX_OK ) return ASIX_OK;
	

	if (Head->child==NULL)
		wndlist=Head->next;
	else 
		wndlist=Head->child;
	
	while(1)
	{
		if(wndlist == NULL) 
			break;
		if(wndlist->child==NULL)
		{
			if ( wndlist->status & WST_ENABLE)
				rv = (*wndlist->wndclass->msg_trans)(wndlist->ctrl_str,pOldmsg->message,
				pOldmsg->misc, pOldmsg->data, pOldmsg->size, pMessage);
			
			if ( rv == ASIX_OK ) 
				break;
			else
			{ 
				wndlist = wndlist->next;
				continue;
			}	
		}
		
		if(IsMyMessage(wndlist, pMessage, pOldmsg) == ASIX_OK) 
			break;
		else 
			wndlist = wndlist->next;
	}
	
	if (wndlist == NULL) 
		return ASIX_NO_MSG;
	
	return ASIX_OK;
	
}	

void AsixTransKeyMsg( MSG *asix_msg, KEYDATA *key )
{
	asix_msg->messageType = ASIX_MESSAGE;
	switch( key->flag )
	{
		case SM_KEYUP:
			asix_msg->message = WM_KEYUP;
			break;
		case SM_KEYDOWN:
			break;
	}
	asix_msg->lparam = GetFocus();
	asix_msg->wparam = key->keyvalue + ASIX_CONTROL_KEY_CODE_BEGIN;
}

void DoEveryMinute(void *arg)
{
	SYSTCB	*pHead;
	MSG		msg;

	msg.messageType = ASIX_MESSAGE;
	msg.message = WM_TIMER;
	msg.lparam = EveryMinuteTimer;
	msg.wparam = 0;
	msg.data = NULL;

	pHead = TaskHead;
//	while( pHead != NULL )
	{
		SysSendMessage( pHead->description->taskid, &msg );
//		pHead = pHead->next;
	}

	return;
}

void DoEveryHour(void *arg)
{
}

void DoEveryDay(void *arg)
{
}


	
#ifdef ASIX_DEBUG


/*WNDCLASS_TEST,	tst_create,		tst_destroy,	tst_msgproc,	tst_msgtrans,
  NULL,				NULL,			NULL,			NULL,			NULL,	*/

STATUS tst_create(char *caption, U32 style, U16 x, U16 y, U16 width, U16 hight,
				 U32 parent, U32 menu, void **ctrl_str, void *exdata)
{
	return ASIX_OK;
}
				 
STATUS tst_destroy(void *ctrl_str)
{
	return ASIX_OK;
}

STATUS tst_msgproc( U32 win_id, U16 asix_msg, U32 lparam, void *data, U16 wparam, void *reserved)
{
	return ASIX_OK;
}

STATUS tst_msgtrans(void *ctrl_str, U16 msg_type, U32 areaId, P_U16 data, U32 size, PMSG trans_msg)
{
	return ASIX_NO_MSG;
}

#endif 


	
	

	

⌨️ 快捷键说明

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