?? asixwin.c.bak
字號:
/*************************************************************************
*
* 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;
/**************************************************************************
* 創(chuàng)建窗口函數(shù)
* 入口參數(shù)說明:
* className 所創(chuàng)建的窗口類,參見WindowClass[]數(shù)組
* Caption 窗口標題
* Style 窗口風格,參見asixwin.h中的定義
* x,y,width,Height 窗口的左上角坐標,以及窗口的寬度與高度,單位pixel
* Parent 窗口的父窗口ID
* hMenu 該參數(shù)是為了同MS Win32 API兼容,本函數(shù)忽略該參數(shù)
* exdata 傳遞給具體創(chuàng)建函數(shù)的其他數(shù)據(jù)
* 返回值: 所創(chuàng)建窗口的ID,如果創(chuàng)建失敗則返回值為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; //如果所創(chuàng)建的窗口類不存在,返回
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 ) {
// 父窗口為空,則我們創(chuàng)建的窗口類一定是Form或則測試窗口類
if ( ClassName != WNDCLASS_WIN && ClassName != WNDCLASS_TEST ) {
SysLfree(winptr); //釋放已申請的窗口數(shù)據(jù)結構
printf( "### Create %s Error ###\n", WinClassName[ClassName] );
return (U32)NULL;
}
if ( curwin !=NULL ) //如果當前窗口不為空,我們必須將其壓如窗口棧
{
PushWindow(); //壓棧
old_curwindow = (U32)curwin; //保留原來的當前窗口
CurWindow = curwin = winptr; //更新當前窗口為所創(chuàng)建的新窗口
}
} 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;
}
}
//窗口數(shù)據(jù)結構的填寫
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;
//調(diào)用屬于該窗口類的具體創(chuàng)建函數(shù)
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); //釋放窗口數(shù)據(jù)結構
printf( "### Create %s Error ###\n", WinClassName[ClassName] );
return (U32)NULL;
}
winptr->task_id = curtask->id; //窗口的任務ID付值
winptr->ctrl_str = ctrl_str; //窗口的私有數(shù)據(jù)
winptr->status |= WST_NORMAL | WST_EN_FOCUS; //for Destroy audit.
//將新創(chuàng)建的窗口數(shù)據(jù)結構加入到窗口鏈表
if ( parent_win == NULL ) {
//如果父窗口為空,所創(chuàng)建的窗口一定是Form
winlist = curtask->wnd_ptr; //獲得當前任務的窗口鏈入口
curtask->wnd_ptr = winptr; //將當前窗口作為當前任務的窗口鏈入口
winptr->next = winlist; //將原來的窗口鏈連接到新窗口之后
if (winlist != NULL) //如果原來的窗口鏈不為空
{
winptr->prev = winlist->prev; //則將新創(chuàng)建窗口的前指針指向原來的
winlist->prev = winptr; //而將原來窗口鏈的前指針指向新創(chuàng)建窗口
}
else
{
winptr->prev = winptr; //否則我們是第一個Form窗口
} //將前指針指向自己,構建雙向鏈表
CurWindow = curwin = winptr; //當前窗口指向我們
SetFocus((U32)curwin); //Initaily, we set the container focus
} else {
//否則,我們創(chuàng)建的窗口一定是其他控件,他們一定有自己的父窗口
winlist = parent_win->child; //獲得父窗口的子窗口鏈表
parent_win->child = winptr; //子窗口鏈表的入口指向新創(chuàng)建窗口
winptr->next = winlist; //將原來的窗口鏈連接到新窗口之后
if (winlist != NULL)
{//如果原來的子窗口鏈表不為空
winptr->prev = winlist->prev; //則將新創(chuàng)建窗口的前指針指向原來的
winlist->prev = winptr; //而將原來窗口鏈的前指針指向新創(chuàng)建窗口
}
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;
}
}
//所有所屬的子窗口刪除完畢,調(diào)用具體的刪除函數(shù)刪除自己
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 ) // 如果是窗口鏈的最后一個
// 將窗口鏈的首結點的前指針指向本窗口的前一個節(jié)點,構建雙向鏈表,把自己
// 從窗口鏈中取下來
( (ASIX_WINDOW *)(wndptr->parent_id) )->child->prev = wndptr->prev;
else
//將這個窗口數(shù)據(jù)結構從鏈表中取下來
wndptr->next->prev = wndptr->prev;
if( wndptr->prev->next == NULL )// 如果是窗口連的第一個節(jié)點
//將窗口鏈的入口指向我們的后一個節(jié)點
( (ASIX_WINDOW *)(wndptr->parent_id) )->child = wndptr->next;
else
//將這個窗口數(shù)據(jù)結構從鏈表中取下來
wndptr->prev->next = wndptr->next;//
} else { /* it is the container*/
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;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -