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

📄 asixwin.c

📁 C 语言进阶
💻 C
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************
*
* Copyright  2000 National ASIC Center, All right Reserved
*
* FILE NAME:			asixwin.c
* PROGRAMMER:			Lingming
* Date of Creation:		2001/02/13
* 
* DESCRIPTION: 			The upper part of asix window system. Include the
*						Initial and Creating ,Destroy, DefWindowProc and
*						so on. this file offers the Application Programmer
*                       the ASIX Window API.
*
* NOTE:			 		 
*						 
*
* FUNCTIONS LIST:
* -------------------------------------------------------------------------
* STATUS ASIXInit(void)
* U32 CreateWindow(U8 ClassName, char *Caption, U32 Style, 
*				 	U16 x, U16 y, U16 Width, U16 Height,
*				 	U32 Parent, U32 hMenu, void *exdata)
* STATUS DestroyWindow(U32 Wndid)
* STATUS ASIXGetMessage(PMSG pMessage, U32 *pWnd_id, U16 Reserved1, U16 Reserved2)
* STATUS DefWindowProc(U16 MsgCmd, U32 lparam, P_U16 data, U16 wparam) 
* STATUS IsMyWindow(U32 Wndid, U32 Head)
* STATUS SetWindowText(U32 Wndid, P_U8 Caption, void *exdata);
* STATUS EnableWindow(U32 Wndid, U8 Enable);
* STATUS RepaintWindow(U32 wndid, U32 lparam);
* STATUS PopUpWindow(U32 wndid, U32 reserved );
* STATUS GetWindowStatus(U32 Wndid, P_U32 Status);
*
* GLOBAL VARS LIST:
* 
* WindowClass[]			the window class description const table,which
* 						defines the obj's relevent functions pointer
*
*
**************************************************************************
* MODIFICATION HISTORY
*
* 2001/02/13	by Lingming		Creation of this file
* 2001/05/07	by Lingming		Support window focus
* 2001/08/11	by Lingming		support dynamic shell 										
* 2001/08/29	by Lingming 	seperate task related funs to asixapp.c							
* 2001/09/10	by Lingming		in DefWindowProc(),we filter out the user defined msg
* 2001/10/26	by Lingming 	insert new created win at the list head rather than 
*								at the end that implemented in the old version
* 2001/11/23	by Lingming		bug fixing in CreateWindow, for the failure of the first 
*								win creation of the task.								
* 2001/11/27    by Lingming		add wnd id validation checking in IsMyWindow()
* 2001/11/28    by Lingming		send focus message to related controls in SetFocus()
* 2002/03/09    by Lingming		We add GetCurWindow() to replace the old PPSM version's 
*								CurWindow. This has two advantages: first, we donot need 
*								to handle a gloabl var which is good for a mutitasking 
*								environment and program structure; second, we now can 
*								handle window in backend.
* 2002/3/12     by Xuanhui&Zhuli change [Color Theme Init]
* 2002/03/19	by Lingming		Add group operation during destroy repaint
* 2002/03/20   	by Lingming		discard FocusWindow gloabl var
* 2002/03/22  	by Lingming		Add Repaint Message when destroy a window so that user can
*								repaint their client area.
* 2002/04/03	by longn_qi		bug fixxing in CreateWindow() "winptr->status |= WST_NORMAL;"
*								modification in IsMyMessage() and ASIXGetMessage()
* 2002/09/09	by longn_qi		added function "PopUpWindow"
*************************************************************************/

/* ANSI C lib */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


/* asix window include file*/
#include "asixwin.h"
#include "xlmalloc.h"

// The controls head file
/*
#include <asixwin\button.h>
#include <asixwin\select.h>
#include <asixwin\asix_wn.h>
#include <asixwin\asix_mn.h>
#include <asixwin\asix_sb.h>
#include <asixwin\asix_lb.h>
#include <asixwin\asix_st.h>
#include <asixwin\alarm_q.h>
#include <asixwin\asix_ed.h>
#include <asixwin\asix_key.h>
#include <asixwin\asix_kb.h>
#include <asixwin\asix_tb.h>
*/


static STATUS PushWindow(void);
static STATUS PopWindow(void);
//static STATUS IsMyMessage(ASIX_WINDOW *Head,PMSG pMessage, P_MESSAGE pOldmsg);


/* Timers */ 
static void DoEveryMinute(void *arg);
static void DoEveryHour(void *arg);
static void DoEveryDay(void *arg);


/*check the timer*/
//STATUS AsixTimerCheck(void);

extern STATUS AnswerCall(void);


WNDCLASS			WindowClass[] = {
/* 	id,				create,			destroy,		msg_proc,		msg_trans,
	repaint,		move,			enable,			caption,		information,*/				
// for the course 5, we will just demonstrate how to construct the window link list
// we will use the tst WINCLASS to implementate all other WINCLASSes
// Lingming 2006/04/15

	{WNDCLASS_WIN,	tst_create,		tst_destroy,		tst_msgproc,	tst_msgtrans,
	NULL,			NULL,			NULL,			NULL,			NULL},
	
	{WNDCLASS_BUTTON,tst_create,		tst_destroy,		tst_msgproc,	tst_msgtrans,
	NULL,			NULL,			NULL,			NULL,			NULL},
	
	{WNDCLASS_SELECT,tst_create,		tst_destroy,		tst_msgproc,	tst_msgtrans,
	NULL,			NULL,			NULL,			NULL,			NULL},
	
	{WNDCLASS_SELECTCARD,NULL,  	NULL,			NULL,			NULL,
	NULL,			NULL,			NULL,			NULL,			NULL},

	{WNDCLASS_MENU,tst_create,		tst_destroy,		tst_msgproc,	tst_msgtrans,
	NULL,			NULL,			NULL,			NULL,			NULL},
	
	{WNDCLASS_LIST,	tst_create,		tst_destroy,		tst_msgproc,	tst_msgtrans,
	NULL,			NULL,			NULL,			NULL,			NULL},
	
// modified by dsa 2002/04/17	
//	{WNDCLASS_COMBO,	NULL,		NULL,			NULL,			NULL,
//	NULL,			NULL,			NULL,			NULL,			NULL},
	{WNDCLASS_KEYBD,tst_create,		tst_destroy,		tst_msgproc,	tst_msgtrans,
	NULL,			NULL,			NULL,			NULL,			NULL},	
	
	{WNDCLASS_PROCESS,NULL,			NULL,			NULL,			NULL,
	NULL,			NULL,			NULL,			NULL,			NULL},
	
	{WNDCLASS_SCROLL,tst_create,		tst_destroy,		tst_msgproc,	tst_msgtrans,
	NULL,			NULL,			NULL,			NULL,			NULL},
	
	{WNDCLASS_KEYBAR,tst_create,		tst_destroy,		tst_msgproc,	tst_msgtrans,
	NULL,			NULL,			NULL,			NULL,			NULL},
	
	{WNDCLASS_EDITOR,tst_create,		tst_destroy,		tst_msgproc,	tst_msgtrans,
	NULL,			NULL,			NULL,			NULL,			NULL},
	
//	{WNDCLASS_MUTIEDIT,NULL,		NULL,			NULL,			NULL,
//	NULL,			NULL,			NULL,			NULL,			NULL},
	
	{WNDCLASS_READER,tst_create,	tst_destroy,		tst_msgproc,	tst_msgtrans,
	NULL,			NULL,			NULL,			NULL,			NULL},
		
	{WNDCLASS_STATIC,tst_create,		tst_destroy,		tst_msgproc,	tst_msgtrans,
	NULL,			NULL,			NULL,			NULL,			NULL},
	{WNDCLASS_TSKBAR,tst_create,		tst_destroy,		tst_msgproc,	tst_msgtrans,
	NULL,			NULL,			NULL,			NULL,			NULL},

//#ifdef ASIX_DEBUG	
	{WNDCLASS_TEST,tst_create,		tst_destroy,		tst_msgproc,	tst_msgtrans,
	NULL,			NULL,			NULL,			NULL,			NULL}
//#endif	
	
};

char	*WinClassName[] = 
{
	"Form",
	"Button",
	"Select",
	"SelectCard",
	"Menu",
	"ListBox",
	"KeyBoard",
	"Process",
	"ScrollBar",
	"KeyBar",
	"Editor",
	"Reader",
	"Static",
	"TaskBar",
	"TestControl"
};


ASIX_WINDOW			*CurWindow = NULL;		//point to current window entry	

////////////////////////////////////////////////////////////////////////////
//CurTask is not the real task control block, we use this for the course
//Lingming 2006/4/15
////////////////////////////////////////////////////////////////////////////
SYSTCB				CurTask;

									
/* we set the font size as var now , so that we 
 * can update the font size at run time 
 * By Lingming 2001/5/08 */

/* In Iris Phone Project the font size changed
 * By Lingming 2001/11/07	
 */ 
extern U8		CHINESE_CHAR_HEIGHT;
extern U8		CHINESE_CHAR_WIDTH;
extern U8		ENGLISH_CHAR_WIDTH;
extern U8		ENGLISH_CHAR_HEIGHT;


/* The seconds left before we run into doze or sleep */
S16	  	PowerSavingTimeOut;

/* The flag that define whether our own UART irpt driver should be used*/
/* We do have our own irpt handler, but in order to compatibal with old 
 * program the programer can select whether the new irpt handler or the 
 * PPSM's handler should be used. The default selection is PPSM's handler 
 */
U8		AsixOwnUartDriver = 0; //FALSE;




/**************************************************************************
 * 创建窗口函数
 * 入口参数说明:
 * className            所创建的窗口类,参见WindowClass[]数组
 * Caption              窗口标题
 * Style                窗口风格,参见asixwin.h中的定义
 * x,y,width,Height     窗口的左上角坐标,以及窗口的宽度与高度,单位pixel
 * Parent               窗口的父窗口ID
 * hMenu                该参数是为了同MS Win32 API兼容,本函数忽略该参数
 * exdata               传递给具体创建函数的其他数据
 * 返回值:              所创建窗口的ID,如果创建失败则返回值为0
 ***************************************************************************/

U32 CreateWindow(U8 ClassName, char *Caption, U32 Style, 
				 U16 x, U16 y, U16 Width, U16 Height,
				 U32 Parent, U32 hMenu, void *exdata)
{
	
	void		 	*ctrl_str = NULL;
	ASIX_WINDOW		*parent_win, *winptr; //*kbwndptr;
	ASIX_WINDOW		*winlist;
	ASIX_WINDOW		*curwin; 
	SYSTCB			*curtask;				
	U32				old_curwindow = 0;
	//U16				padx=0,pady=0;
	U16				cursor;
	

	curwin =(ASIX_WINDOW *)GetCurWindow();	//获得当前窗口ID
	curtask = GetCurTask();			//获得当前任务控制块指针	

	// Only in the Current window can we create the sub win
	// if task_id is 0, it maybe the recurse entry, so we donot check. 
	if (Parent!=0 && ((ASIX_WINDOW *)Parent)->task_id != 0 )
		if ( IsMyWindow(Parent, (U32)curwin)!= ASIX_OK) 
			return (U32)NULL;
	
	parent_win = (ASIX_WINDOW *)Parent;
	
	if ( ClassName >= WNDCLASS_MAX ) return (U32)NULL; //如果所创建的窗口类不存在,返回
	
	printf( "\n### Create %s ###\n", WinClassName[ClassName] );
	// allocate the window structure
	if ( (winptr = (ASIX_WINDOW *)SysLcalloc( sizeof(ASIX_WINDOW) ))==NULL )
	{
		printf( "### Create %s Error ###\n", WinClassName[ClassName] );
		return (U32)NULL;
	}
	
	if ( parent_win == NULL ) {
		// 父窗口为空,则我们创建的窗口类一定是Form或则测试窗口类
		if ( ClassName != WNDCLASS_WIN && ClassName != WNDCLASS_TEST ) {
			SysLfree(winptr); //释放已申请的窗口数据结构
			printf( "### Create %s Error ###\n", WinClassName[ClassName] );
			return (U32)NULL;
		}
		if ( curwin !=NULL ) //如果当前窗口不为空,我们必须将其压如窗口栈
		{
			
			PushWindow(); //压栈

			old_curwindow = (U32)curwin; //保留原来的当前窗口

			CurWindow = curwin = winptr; //更新当前窗口为所创建的新窗口
			
		}	
			
	} else {
		// the sub win's class can not be WNDCLASS_WIN
		// the sub win must has the WS_CHILD style
		if ( ClassName == WNDCLASS_WIN || !(Style & WS_CHILD) ){
			SysLfree(winptr);	
			printf( "### Create %s Error ###\n", WinClassName[ClassName] );
			return (U32)NULL;
		}	
	}	
	//窗口数据结构的填写
	winptr->wndclass = &WindowClass[ClassName];
	winptr->wnd_id = (U32)winptr;
	winptr->parent_id = Parent;
	winptr->x = x;
	winptr->y = y;
	winptr->width = Width;
	winptr->hight = Height;
	winptr->caption = Caption;
	winptr->tag = NULL; 
	winptr->style = Style;
	winptr->hmenu = hMenu;
	winptr->exdata = exdata;
	
	//调用属于该窗口类的具体创建函数
	if ( (*WindowClass[ClassName].create)(Caption, Style, x, y, Width,
	 Height, (U32)winptr, hMenu,(void **)&ctrl_str, exdata) != ASIX_OK )
	{
		if ( parent_win == NULL ){/* Only WNDCLASS_WIN creation failure should restore*/
			/* we will restore the old CurWindow and pop it */
			CurWindow = curwin = (ASIX_WINDOW *)old_curwindow;	
			
			if (curwin != NULL)
				PopWindow();//原来的老窗口出栈
			else { 	//The creation of first window of this task failed
				//we have no choice but exit this task. By Lingming 2001/11/23
				SysLfree(winptr);
				//EndofTask();
				printf( "### Create %s Error ###\n", WinClassName[ClassName] );
				return (U32)NULL; 
			}
							
						
		} //if ( parent_win == NULL )	
		
		SysLfree(winptr); //释放窗口数据结构
		printf( "### Create %s Error ###\n", WinClassName[ClassName] );
		return (U32)NULL;
	}

	winptr->task_id = curtask->id; //窗口的任务ID付值	
 	winptr->ctrl_str = ctrl_str;   //窗口的私有数据
	winptr->status |= WST_NORMAL | WST_EN_FOCUS; //for Destroy audit. 
								
	//将新创建的窗口数据结构加入到窗口链表	
	
	if ( parent_win == NULL ) {
	//如果父窗口为空,所创建的窗口一定是Form	
		winlist = curtask->wnd_ptr;	//获得当前任务的窗口链入口
		curtask->wnd_ptr = winptr; 	//将当前窗口作为当前任务的窗口链入口
		winptr->next = winlist;		//将原来的窗口链连接到新窗口之后  
		if (winlist != NULL)		//如果原来的窗口链不为空
		{
			winptr->prev = winlist->prev; 	//则将新创建窗口的前指针指向原来的 
			winlist->prev = winptr;		//而将原来窗口链的前指针指向新创建窗口
		}
		else
		{
			winptr->prev = winptr;		//否则我们是第一个Form窗口
		}					//将前指针指向自己,构建双向链表
			
		
		CurWindow = curwin = winptr;		//当前窗口指向我们
		
		SetFocus((U32)curwin); 			//Initaily, we set the container focus
		
	} else {
	//否则,我们创建的窗口一定是其他控件,他们一定有自己的父窗口	
			
		winlist = parent_win->child;	//获得父窗口的子窗口链表
		parent_win->child = winptr;	//子窗口链表的入口指向新创建窗口
		winptr->next = winlist;		//将原来的窗口链连接到新窗口之后
		if (winlist != NULL)
		{//如果原来的子窗口链表不为空
			winptr->prev = winlist->prev;	//则将新创建窗口的前指针指向原来的
			winlist->prev = winptr;		//而将原来窗口链的前指针指向新创建窗口
		}
		else
		{
			winptr->prev = winptr;		//将前指针指向自己,构建双向链表
		}
				
	}
	
								  
	if ( (!(Style & WS_DISABLED)) && (ClassName != WNDCLASS_STATIC) )
		winptr->status |= WST_ENABLE;
	
	printf( "### Create %s 0x%x OK ###\n", WinClassName[ClassName], winptr );
	return (U32)winptr;		
	
}



STATUS DestroyWindow(U32 Wndid)
{
	ASIX_WINDOW				*wndptr;
	ASIX_WINDOW				*curwin;
	ASIX_WINDOW				*parent;
	
	SYSTCB					*curtask;
	U32						pGC;
	
	U32						repaint_id = 0;	//the window id we will repaint
	//MSG					msg;
	

	curwin = (ASIX_WINDOW *)GetCurWindow();//获得当前窗口与当前任务
	curtask = GetCurTask();

	/* 只有当前窗口可以删除自己或则其所属的子窗口*/
	if ( IsMyWindow(Wndid, (U32)curwin) != ASIX_OK ) return ASIX_ERROR; 
	
	wndptr = (ASIX_WINDOW *)Wndid;
	
	/* if we are destroying a control with children, we will 
	 * not repaint it when destroying the children.
	 * By Lingming 2002/03/20*/
	if (wndptr->child != NULL)	
		wndptr->status |= WST_FORM_REPAINT;
	
	printf( "### Destroy %s 0x%x ###\n", WinClassName[wndptr->wndclass->wndclass_id], wndptr );
	//下面的代码涉及图形操作,我们暂时不用考虑
	//pGC = GetGC();
	//GroupOn( pGC );
	
	//如果所删除的窗口有子窗口,我们先通过递归删除所有子窗口
	while (wndptr->child!=NULL) {
		
		if (DestroyWindow((U32)wndptr->child) != ASIX_OK ) {
			//删除失败,忽略这个子窗口,删除下一个
			wndptr->child = wndptr->child->next;
			if (wndptr->child != NULL ) wndptr->child->prev = NULL;		
		}
	}
			
	//所有所属的子窗口删除完毕,调用具体的删除函数删除自己
	if ( (*wndptr->wndclass->destroy)(wndptr->ctrl_str) != ASIX_OK )
	{
		//GroupOff( pGC, wndptr->x, wndptr->y, wndptr->x + wndptr->width - 1, wndptr->y + wndptr->hight -1 );
		printf( "### Destroy %s Error ###\n", WinClassName[wndptr->wndclass->wndclass_id] );
		return ASIX_ERROR;
	}
			
	if (wndptr->style & WS_CHILD) /*如果是一个子窗口*/
	{
		
		if( wndptr->next == NULL )	// 如果是窗口链的最后一个
			// 将窗口链的首结点的前指针指向本窗口的前一个节点,构建双向链表,把自己
			// 从窗口链中取下来
			( (ASIX_WINDOW *)(wndptr->parent_id) )->child->prev = wndptr->prev;
		else
			//将这个窗口数据结构从链表中取下来
			wndptr->next->prev = wndptr->prev;

		if( wndptr->prev->next == NULL )// 如果是窗口连的第一个节点
			//将窗口链的入口指向我们的后一个节点	
			( (ASIX_WINDOW *)(wndptr->parent_id) )->child = wndptr->next;
		else
			//将这个窗口数据结构从链表中取下来
			wndptr->prev->next = wndptr->next;//
			
	} else {	/* 如果是Form窗口*/
		
		if (wndptr->next == NULL) /*It is the only one*/
		{
			curtask->wnd_ptr = NULL;
			
			CurWindow = curwin = NULL;//It seems we donot need this either!!
			
			//we will return now Lingming 2002/03/20
			wndptr->status = WST_DESTROYED;//for destroy audit. by Lingming 2001/11/27
			
			printf( "### Destroy %s 0x%x OK ###\n", WinClassName[wndptr->wndclass->wndclass_id], wndptr );
			SysLfree(wndptr);	
	
			//printf( "### Destroy %s OK ###\n", WinClassName[wndptr->wndclass->wndclass_id] );
			return ASIX_OK;
					
		} else {  /* CurWindow must be the first one */
			//当前窗口变成我们后面的那个窗口
			CurWindow = curwin = wndptr->next;
			curwin->prev = wndptr->prev;

⌨️ 快捷键说明

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