📄 shell.c
字号:
/*************************************************************************
*
* Copyright 2000 National ASIC Center, All right Reserved
*
* FILE NAME: shell.c
* PROGRAMMER: Lingming
* Date of Creation: 2000/02/14
*
* DESCRIPTION: The essential declarations for ASIX Windows system
* including MACRO define, global var declaration and
* public functions prototypes.
*
* NOTE: The application C file MUST include this file if
* this application will use ASIX Windows GUI API
*
**************************************************************************
* MODIFICATION HISTORY
*
* 2000/02/14 by Lingming Creation of this file
* 2002/03/13 by Pessia move AsixTaskInit() to asixapp.c
*
*************************************************************************/
/* SDS C lib */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* asix window include file*/
#include <asixwin.h>
#include <asixapp.h>
#include <sys\keydef.h>
#include <asixwin\asix_mn.h>
#include <asixwin\asix_lb.h>
#include <resource\bitmap.h>
#include <service\audio\audiosvr.h>
#define DISP_MAX_NUM 6
#define APPLICATION 0
#define SETTINGS 1
#define COMMUNICATION 2
#define GAMES 3
extern void NewShell(void);
TASKDESCRIPTION ShellTskDesp =
{
// name, mode
"我的PDA", ASIX_SHELL,
// group, icon
NOT_IN_ANYGROUP,NULL,
// stk, screen
4096, 1,
// scr_w, scr_h
LCD_WIDTH, LCD_HEIGHT,
// func, priority
NewShell, APP_PRI
};
//extern void SysGpcTest( DWORD pGC );
void NewShell(void)
{
U32 hGC;
//窗口和控件ID
U32 shellwin;
U32 sortlist;
U32 tskbar;
U32 prev;
U32 next;
U32 itementry[DISP_MAX_NUM];
//函数用变量
MSG msg, switchmsg;
TASKDESCRIPTIONLIST *desplst;
TASKDESCRIPTION *taskptr;
APP_ENTRY AppEntry[MAX_GROUP][MAX_APPENTRY];
BYTE i, j;
char inforstr[50];
BYTE nowgroup = APPLICATION; //默认当前组是第一组应用程序
BYTE nownum; //当前组的应用程序个数
BYTE pagenum; //当前组显示所需的页数
BYTE pageno; //当前页号
BYTE first = 0; //当前页的第一个应用程序
SYSTCB *tskptr;
// BYTE result;
// WORD info_y;
// void (*x)();
struct LBOX_ITEM sortitem[]=
{
ICON_ENABLE, UNDERLINE, "应用",
ICON_ENABLE, UNDERLINE, "游戏",
ICON_ENABLE, UNDERLINE, "系统",
ICON_END, UNDERLINE, NULL
};
hGC = GetGC();
// SysGpcTest( hGC );
memset(AppEntry, 0x0, MAX_GROUP*MAX_APPENTRY*sizeof(APP_ENTRY));
for( desplst = TaskDescription; desplst != NULL; desplst = desplst->next)
{
taskptr = desplst->desp;
if (taskptr->mode == ASIX_SHELL || taskptr->mode == ASIX_DEAMON)
continue;// Shell and Daemon will not be displayed in shell
if (taskptr->group>=MAX_GROUP)
{
sprintf(inforstr, "应用程序 %s\n属于不存在的程序组!",taskptr->name);
MessageBox( GetFocus(), inforstr, "错误",MB_OK | MB_ICONERROR);
continue;
}
else
{
for (i=0; (AppEntry[taskptr->group][i].tskdes != NULL) && (i<MAX_APPENTRY); i++)
;//looking for the empty entry
if ( i== MAX_APPENTRY )
continue; //here ,should we notice the user?
AppEntry[taskptr->group][i].tskdes = desplst;
}
}
shellwin = CreateWindow(WNDCLASS_WIN, NULL, WS_CAPTION | WS_BORDER|WS_SYSMENU, 0, 0, PHY_LCD_W, PHY_LCD_H, 0, 0, NULL);
sortlist = CreateWindow(WNDCLASS_LIST, "", WS_CHILD|LBS_POPUP, 20, 25, LCD_WIDTH-100, 20, shellwin, 0, sortitem);
prev = CreateWindow(WNDCLASS_BUTTON, "\\前一页", WS_CHILD|BS_ICON|BS_FLAT, 20+LCD_WIDTH-100+10, 25, 20, 20, shellwin, 0, (void *)zi_prev);
next = CreateWindow(WNDCLASS_BUTTON, "\\后一页", WS_CHILD|BS_ICON|BS_FLAT, 20+LCD_WIDTH-100+10+20+5, 25, 20, 20, shellwin, 0, (void *)zi_next);
// prev = CreateWindow(WNDCLASS_BUTTON, "<<", WS_CHILD|BS_ICON|BS_FLAT, 100, 25, 20, 20, shellwin, 0, NULL);
// next = CreateWindow(WNDCLASS_BUTTON, ">>", WS_CHILD|BS_ICON|BS_FLAT, 125, 25, 20, 20, shellwin, 0, NULL);
tskbar = CreateWindow(WNDCLASS_TSKBAR, NULL, WS_CHILD|TBS_TYPICAL, 0, 0, 0, 0,shellwin, 0, NULL);
for(i = 0; (AppEntry[nowgroup][i].tskdes != NULL) && (i < MAX_APPENTRY); i++) //得出当前组的项目个数
;
nownum = i;
if(nownum%DISP_MAX_NUM == 0)
pagenum = nownum/DISP_MAX_NUM;
else
pagenum = nownum/DISP_MAX_NUM + 1;
pageno = 1;
if(pagenum == 1)
{
EnableWindow(prev, FALSE);
EnableWindow(next, FALSE);
}
else
{
EnableWindow(prev, FALSE);
EnableWindow(next, TRUE);
}
PlayAudio( &SysAudioScheme.start );
GroupOn( hGC );
for(i = 0; i < DISP_MAX_NUM; i++)
{
j = i/2;
if(i < nownum)
{
if((i - 2*j) == 0)
{
itementry[i] = CreateWindow(WNDCLASS_BUTTON, NULL, WS_CHILD|BS_ICON|BS_FLAT, (LCD_WIDTH-96)/3, (U16)(52 + j*(48 + 7)), 48, 48, shellwin, 0x00300030, (U8 *)AppEntry[nowgroup][i].tskdes->desp->icon);
}
else
{
itementry[i] = CreateWindow(WNDCLASS_BUTTON, NULL, WS_CHILD|BS_ICON|BS_FLAT, (LCD_WIDTH-96)/3+48+(LCD_WIDTH-96)/3, (U16)(52 + j*(48 + 7)), 48, 48, shellwin, 0x00300030, (U8 *)AppEntry[nowgroup][i].tskdes->desp->icon);
}
}
else
{
if((i - 2*j) == 0)
{
itementry[i] = CreateWindow(WNDCLASS_BUTTON, NULL, WS_CHILD|BS_ICON|BS_FLAT, (LCD_WIDTH-96)/3, (U16)(52 + j*(48 + 7)), 48, 48, shellwin, 0, NULL);
EnableWindow(itementry[i], FALSE);
}
else
{
itementry[i] = CreateWindow(WNDCLASS_BUTTON, NULL, WS_CHILD|BS_ICON|BS_FLAT, (LCD_WIDTH-96)/3+48+(LCD_WIDTH-96)/3, (U16)(52 + j*(48 + 7)), 48, 48, shellwin, 0, NULL);
EnableWindow(itementry[i], FALSE);
}
}
}
if( nownum != 0 )
SetFocus( itementry[0] );
GroupOff( hGC, (LCD_WIDTH-96)/3, 52, LCD_WIDTH-(LCD_WIDTH-96)/3, 210 );
//消息循环
while(1)
{
ASIXGetMessage(&msg, NULL, 0, 0);
switch(msg.message)
{
case WM_COMMAND:
if(msg.lparam == prev)
{
first -= DISP_MAX_NUM;
pageno--;
if( pageno == 1 )
{
EnableWindow( prev, FALSE );
}
EnableWindow( next, TRUE );
// GroupOn( hGC );
// ClearRec( hGC, ColorTheme.form_backcolor, 20, 52, 120, 158, GPC_REPLACE_STYLE );
for( i = 0; i < DISP_MAX_NUM; i++ )
{
SetWindowText(itementry[i], NULL, (U8 *)AppEntry[nowgroup][first+i].tskdes->desp->icon);
EnableWindow(itementry[i], TRUE);
}
SetFocus( itementry[0] );
// GroupOff( hGC, 20, 52, 140, 210 );
}
else
if(msg.lparam == next)
{
BYTE disp_num;
first += DISP_MAX_NUM;
disp_num = nownum - first;
pageno++;
if( pageno == pagenum )
{
EnableWindow( next, FALSE );
}
EnableWindow( prev, TRUE );
GroupOn( hGC );
// ClearRec( hGC, ColorTheme.form_backcolor, 20, 52, 120, 158, GPC_REPLACE_STYLE );
for( i = 0; i < DISP_MAX_NUM; i++)
{
if( i < disp_num )
{
SetWindowText(itementry[i], NULL, (U8 *)AppEntry[nowgroup][first + i].tskdes->desp->icon);
EnableWindow(itementry[i], TRUE);
}
else
{
SetWindowText(itementry[i], NULL, NULL);
EnableWindow(itementry[i], FALSE);
}
}
SetFocus( itementry[0] );
GroupOff( hGC, (LCD_WIDTH-96)/3, 52, LCD_WIDTH-(LCD_WIDTH-96)/3, 210 );
}
else
for(i = 0; i <= DISP_MAX_NUM; i++)
{
if(msg.lparam == itementry[i])
{
//启动nowgroup中的第((pageno - 1)*DISP_MAX_NUM + i)的任务
i += (pageno - 1)*DISP_MAX_NUM;
switch(AppEntry[nowgroup][i].tskdes->desp->mode)
{
case ASIX_APP:
{
TASKDESCRIPTIONLIST *desplst;
TASKDESCRIPTION *desptr = AppEntry[nowgroup][i].tskdes->desp;
desplst = IsRegistered( desptr );
if( desplst != NULL ) // already registered
{
tskptr = &gSysTcbTbl[desplst->taskid-1];
if( tskptr->status == RUNNING ) // already run
{
switchmsg.message = SM_SWITCH;
switchmsg.wparam = SWAP_TO_FOREGROUND;
switchmsg.lparam = (U16)desplst->taskid;
SysSendMessage( SYSTASK_ID, &switchmsg );
break;
}
}
else
{
desplst = TaskRegist( desptr );
if( desplst == NULL )
{
MessageBox(GetFocus(), "任务启动失败!可能是内存不够,请关闭一些任务后再试。","任务启动失败",MB_OK | MB_ICONSTOP);
break;
}
}
ASIXStartTask( desplst->taskid );
}
break;
case ASIX_FUNC:
// x = AppEntry[i].tskdes->desp->entry;
// //x = DynamicCode;
// (*x)();
// //while(1){}
//
// // DispTimeLine(0);
//
break;
case ASIX_DYNAPP:
//AppEntry((APP_ENTRY *)entryhead[i].entryptr, entryhead[i].entryname);
break;
default:
break;
}
break;
}
}
break;
case WM_LISTBOX:
if(msg.lparam == sortlist)
{
switch(msg.wparam)
{
case 0:
nowgroup = APPLICATION;
break;
case 1:
nowgroup = SETTINGS;
break;
case 2:
nowgroup = COMMUNICATION;
break;
case 3:
nowgroup = GAMES;
break;
}
//得出当前组的项目个数
for(i = 0; (AppEntry[nowgroup][i].tskdes != NULL) && (i < MAX_APPENTRY); i++)
;
nownum = i;
if(nownum%DISP_MAX_NUM == 0)
pagenum = nownum/DISP_MAX_NUM;
else
pagenum = nownum/DISP_MAX_NUM + 1;
pageno = 1;
first = 0;
if( pagenum <= 1 ) // 应用程序个数不满一页
{
// 禁止前翻和后翻
EnableWindow(prev, FALSE);
EnableWindow(next, FALSE);
}
else // 应用程序个数超过一页
{
// 允许后翻禁止前翻
EnableWindow(prev, FALSE);
EnableWindow(next, TRUE);
}
// 更新所有图标
GroupOn( hGC );
// ClearRec( hGC, ColorTheme.form_backcolor, 20, 52, 120, 158, GPC_REPLACE_STYLE );
for(i = 0; i < DISP_MAX_NUM; i++)
{
if(i < nownum)
{
SetWindowText(itementry[i], NULL, (U8 *)AppEntry[nowgroup][i].tskdes->desp->icon);
EnableWindow(itementry[i], TRUE);
}
else
{
SetWindowText(itementry[i], "", NULL);
EnableWindow(itementry[i], FALSE);
}
}
if( nownum != 0 )
SetFocus( itementry[0] );
else
SetFocus( shellwin );
GroupOff( hGC, (LCD_WIDTH-96)/3, 52, LCD_WIDTH-(LCD_WIDTH-96)/3, 210 );
}
break;
case WM_KEYDOWN:
case WM_KEYUP:
for( i = 0; i < DISP_MAX_NUM; i++ )
{
if( msg.lparam == itementry[i] )
{
switch( msg.wparam )
{
case ASIX_KEY_UP:
case ASIX_KEY_LEFT:
{
BYTE flag;
if( msg.wparam == ASIX_KEY_UP )
{
if( i >= 2 )
{
j = i - 2;
flag = 0;
}
else
flag = 1;
}
else
{
if( i >= 1 )
{
j = i - 1;
flag = 0;
}
else
flag = 1;
}
if( flag )
{
MSG temp_msg;
if( first != 0 )
{
temp_msg.messageType = ASIX_MESSAGE;
temp_msg.message = WM_COMMAND;
temp_msg.lparam = prev;
temp_msg.wparam = MS_ICON_PEN_UP;
temp_msg.data = NULL;
AdvSendMessage( GetCurTask()->id, (P_MESSAGE)&temp_msg, NO_SWAP_TASK );
}
}
else
{
SetFocus( itementry[j] );
}
}
break;
case ASIX_KEY_DOWN:
case ASIX_KEY_RIGHT:
if( msg.wparam == ASIX_KEY_DOWN )
j = i + 2;
else
j = i + 1;
if( first + j < nownum )
{
if( j >= DISP_MAX_NUM )
{
MSG temp_msg;
temp_msg.messageType = ASIX_MESSAGE;
temp_msg.message = WM_COMMAND;
temp_msg.lparam = next;
temp_msg.wparam = MS_ICON_PEN_UP;
temp_msg.data = NULL;
AdvSendMessage( GetCurTask()->id, (P_MESSAGE)&temp_msg, NO_SWAP_TASK );
}
else
SetFocus( itementry[j] );
}
break;
case ASIX_KEY_OK:
{
MSG temp_msg;
temp_msg.messageType = ASIX_MESSAGE;
temp_msg.message = WM_COMMAND;
temp_msg.lparam = itementry[i];
temp_msg.wparam = MS_ICON_PEN_UP;
temp_msg.data = NULL;
SysSendMessage( GetCurTaskID(), &temp_msg );
}
break;
}
break;
}
}
break;
}
DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -