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

📄 uisw_kbd.c

📁 嵌入工linux开发的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************/
//	文 件 名:	uiSw_Kbd.cpp
//	程序说明:	键盘管理和键盘控件
//	程序设计:	党德华
//				2001.10.26		设计完成		说明文档:R004-S211-0001
//				2002.01.25		修改输入法结束时函数调用的错误和系统消息队列的名称	宋军霞
//				2002.02.02		增加键盘复位功能									宋军霞
//	程序审查:	宋军霞
//				2002.01.22		审查完成		说明文档:R004-S211-0001
//	项目编号:	R004-S211
//	版	  本:	V1.0
//	版    权:	Reality Plus Technology (ShenZhen) Co.,Ltd.
/*********************************************************************/
#include <uiWnd.h>
#include <uiSw_Kbd.h>
#include <uiHandWrite.h>
#include <string.h>
#include <uiSound.h>

extern TGuiMessageQueue* SysMsgQueue;	// 系统消息队列

TKbd_Info *gpKbd_Info;					// 键盘信息表

STATUS _guiSwKbd_Delete(HNDL handle);	// 删除一个键盘控件
STATUS _guiSwKbd_Show(HNDL handle);		// 显示键盘
void _guiSwKbd_Action(HNDL handle, WORD message, WORD x, WORD y);	// 键盘的消息响应函数
void VportHandling(WORD Kbd_topPos);

/*********************************************************************/
//dest: 初始化键盘信息
//para: void
//return:
//	fail:	STATUS_ERR
//	sucess: STATUS_OK
/*********************************************************************/
DLL_EXP(STATUS) guiKbd_Init(void)
{
	TKbd_Info tKbd_Info;
	int i;

	guiEnterWCS();
	gpKbd_Info=(TKbd_Info *)kernelMalloc(gGUI_MAX_KBD * sizeof(TKbd_Info));	//分配存储空间
	if(gpKbd_Info == NULL)
	{
		guiExitWCS();
		return STATUS_ERR;
	}
	
	tKbd_Info.bClass = 0;
	tKbd_Info.szName[0]='\0';
	tKbd_Info.checkFlag=0;
	tKbd_Info.paBmp=NULL;
	tKbd_Info.actionFun=NULL;
	tKbd_Info.startFun=NULL;
	tKbd_Info.endFun=NULL;
	tKbd_Info.showFun=NULL;

	for(i=0;i<gGUI_MAX_KBD;i++)
		gpKbd_Info[i]=tKbd_Info;	//清空所有键盘信息

	guiKbd_UserInit();		//调用用户键盘初始化函数,以安装用户键盘
	guiExitWCS();
	return STATUS_OK;
}

/*********************************************************************/
//dest: 安装一个新键盘
//para: 
//	pKbd_Info:	新键盘的相关信息
//return:
//	fail:	STATUS_ERR
//	sucess: STATUS_OK
/*********************************************************************/ 
DLL_EXP(STATUS) guiKbd_Add(TKbd_Info *pKbd_Info)
{
	int i;

	guiEnterWCS();

	for(i=0;i<gGUI_MAX_KBD;i++)		//检查是否有同类并且同名的键盘
	{
		if(gpKbd_Info[i].checkFlag != GUI_KBDINFO_CHECK_FLAG)
			continue;
		if(gpKbd_Info[i].bClass != pKbd_Info->bClass)
			continue;
		if( !strcmp(gpKbd_Info[i].szName,pKbd_Info->szName) )
		{
			gpKbd_Info[i]=*pKbd_Info;	//有同类并且同名的键盘时,以新键盘取代旧键盘
			gpKbd_Info[i].checkFlag=GUI_KBDINFO_CHECK_FLAG;	//新键盘有效
			guiExitWCS();
			return STATUS_OK;
		}
	}

	//没有同类并且同名的键盘时
	for(i=0;i<gGUI_MAX_KBD;i++)	
	{
		if(gpKbd_Info[i].checkFlag != GUI_KBDINFO_CHECK_FLAG)	//检查是否有空位置来安装新的键盘
		{
			gpKbd_Info[i]=*pKbd_Info;
			gpKbd_Info[i].checkFlag=GUI_KBDINFO_CHECK_FLAG;	//新键盘有效
			guiExitWCS();
			return STATUS_OK;
		}
	}

	guiExitWCS();
	return STATUS_ERR;
}

/*********************************************************************/
//dest: 获取键盘的宽度和高度
//para: 
//	type:	键盘的编号
//	width:	键盘的宽度
//	height:	键盘的高度
//return:
//	fail:	STATUS_ERR
//	sucess: STATUS_OK
/*********************************************************************/
DLL_EXP(STATUS) guiKbd_GetSize(WORD type, WORD *width, WORD *height)
{
	guiEnterWCS();
	if(type >= gGUI_MAX_KBD)
	{
		guiExitWCS();
		return STATUS_ERR;			// 键盘代码错误
	}

	if(gpKbd_Info[type].checkFlag != GUI_KBDINFO_CHECK_FLAG)
	{
		guiExitWCS();
		return STATUS_ERR;			// 空键盘
	}

	*width=guiGetImageWidth(gpKbd_Info[type].paBmp);		//位图的尺寸即为相应键盘的尺寸
	*height=guiGetImageHeight(gpKbd_Info[type].paBmp);

	guiExitWCS();
	return STATUS_OK;
}

/*********************************************************************/
//dest: 获取键盘名称
//para: 
//	type:	键盘的代号
//	name:	键盘的名称
//return:
//	fail:	STATUS_ERR
//	sucess: STATUS_OK
/*********************************************************************/
DLL_EXP(STATUS) guiKbd_GetName(WORD type,char *name)
{
	guiEnterWCS();
	if(type >= gGUI_MAX_KBD)
	{
		guiExitWCS();
		return STATUS_ERR;			// 键盘代码错误
	}

	if(gpKbd_Info[type].checkFlag != GUI_KBDINFO_CHECK_FLAG)
	{
		guiExitWCS();
		return STATUS_ERR;			// 空键盘
	}

	strcpy(name,gpKbd_Info[type].szName);

	guiExitWCS();
	return STATUS_OK;
}

/*********************************************************************/
//dest: 获取已安装的键盘数
//para: void
//return:已安装的键盘数
/*********************************************************************/
DLL_EXP(WORD) guiKbd_GetNum(void)
{
	WORD num,i;

	for(i=0,num=0;i<gGUI_MAX_KBD;i++)
	{
		if(gpKbd_Info[i].checkFlag == GUI_KBDINFO_CHECK_FLAG)
			num++;
	}

	return num;
}

/*********************************************************************/
//dest: 将键盘输入的有效代码送给系统
//para: 
//	handle:		键盘控件的handle值
//	sendCode:	输入的有效代码
//	mode:		添中到Edit中的模式
//return:	void
/*********************************************************************/
DLL_EXP(void)  guiKbd_SendMsg(HNDL handle,short sendCode,BYTE mode)
{
	TGuiMessage  message;

	guiEnterWCS();
	message.handle = handle;			// 键盘控件的handle值
	message.messageType=WIN_CHAR_INPUT;	// 消息类型
	message.x=sendCode;					// 输入的代码
	message.y=mode;						// 添加模式
	guiEnqueue(SysMsgQueue,&message);
	guiExitWCS();
}

/*********************************************************************/
//dest: 获取下一个有效键盘的编号
//para: 
//	oldType:	原来的键盘编号
//	newType:	新的键盘编号
//return:
//	fail:	STATUS_ERR
//	sucess: STATUS_OK
/*********************************************************************/
DLL_EXP(STATUS)  guiKbd_GetNext(WORD oldType,WORD *newType)
{
	WORD i;

	guiEnterWCS();
	if( oldType >= gGUI_MAX_KBD)
	{
		guiExitWCS();
		return STATUS_ERR;
	}

	for(i=0;i<gGUI_MAX_KBD;i++)
	{
		if( gpKbd_Info[(oldType+i)%gGUI_MAX_KBD].checkFlag == GUI_KBDINFO_CHECK_FLAG)
		{
			*newType=(oldType+i+1)%gGUI_MAX_KBD;
			guiExitWCS();
			return STATUS_OK;
		}
	}

	guiExitWCS();
	return STATUS_ERR;
}

/*********************************************************************/
//dest: 获取同类型的下一个键盘的编号
//para: 
//	oldType:	原来的键盘编号
//	newType:	新的键盘编号
//return:
//	fail:	STATUS_ERR
//	sucess: STATUS_OK
/*********************************************************************/
DLL_EXP(STATUS)  guiKbd_GetNextInType(WORD oldType,WORD *newType)
{
	WORD		i;

	guiEnterWCS();

	if( oldType >= gGUI_MAX_KBD)
	{
		guiExitWCS();
		return STATUS_ERR;
	}
	
	for(i=0;i<gGUI_MAX_KBD;i++)
	{
		if( gpKbd_Info[(oldType+i+1)%gGUI_MAX_KBD].checkFlag != GUI_KBDINFO_CHECK_FLAG)
			continue;
		if( gpKbd_Info[(oldType+i+1)%gGUI_MAX_KBD].bClass == gpKbd_Info[oldType].bClass)
		{
			*newType=(oldType+i+1)%gGUI_MAX_KBD;
			guiExitWCS();
			return STATUS_OK;
		}
	}

	guiExitWCS();
	return STATUS_ERR;
}

/*********************************************************************/
//dest: 获取某一类键盘中的第一个键盘编号
//para:
//	bClass:	键盘类型
//	type:	本类型第一个键盘的编号
//return:
//	fail:	STATUS_ERR
//	sucess: STATUS_OK
/*********************************************************************/
DLL_EXP(STATUS) guiKbd_GetType(BYTE bClass, WORD *type)
{
	WORD i;

	guiEnterWCS();
	for(i=0;i<gGUI_MAX_KBD;i++)
	{
		if(gpKbd_Info[i].checkFlag != GUI_KBDINFO_CHECK_FLAG)
			continue;
		if(gpKbd_Info[i].bClass == bClass)
		{
			*type=i;
			guiExitWCS();
			return STATUS_OK;
		}
	}

	guiExitWCS();
	return STATUS_ERR;
}

/*********************************************************************/
//dest: 获取键盘的类型
//para:
//	type:	本类型第一个键盘的编号
//	bClass:	键盘类型
//return:
//	fail:	STATUS_ERR
//	sucess: STATUS_OK
/*********************************************************************/
DLL_EXP(STATUS) guiKbd_GetClass(WORD type, BYTE *bClass )
{
	guiEnterWCS();

	if( type >= gGUI_MAX_KBD)
	{
		guiExitWCS();
		return STATUS_ERR;
	}

	if(gpKbd_Info[type].checkFlag == GUI_KBDINFO_CHECK_FLAG)
	{
		*bClass=gpKbd_Info[type].bClass;
		guiExitWCS();
		return STATUS_OK;
	}

	guiExitWCS();
	return STATUS_ERR;
}

/*********************************************************************/
//dest: 查询键盘是否有效
//para:
//	type:	键盘编号
//return:
//	无效:   STATUS_ERR
//	有效:	STATUS_OK
/*********************************************************************/
DLL_EXP(STATUS) guiKbd_CheckType(WORD type)
{
	guiEnterWCS();

	if(type >= gGUI_MAX_KBD)
	{
		guiExitWCS();
		return STATUS_ERR;
	}
	
	if(gpKbd_Info[type].checkFlag == GUI_KBDINFO_CHECK_FLAG)
	{
		guiExitWCS();
		return STATUS_OK;
	}

	guiExitWCS();
	return STATUS_ERR;
}

/*********************************************************************/
//dest: 获取键盘位图的指针
//para:
//	type:	键盘编号
//	paBmp:	位置指针
//return:
//	无效:   STATUS_ERR
//	有效:	STATUS_OK
/*********************************************************************/
DLL_EXP(STATUS) guiKbd_GetBmp(WORD type,int *paBmp)
{
	guiEnterWCS();
	if(type >= gGUI_MAX_KBD)
	{
		guiExitWCS();
		return STATUS_ERR;			// 键盘代码错误
	}

	if(gpKbd_Info[type].checkFlag != GUI_KBDINFO_CHECK_FLAG)
	{
		guiExitWCS();
		return STATUS_ERR;			// 空键盘
	}

	*paBmp=(int)gpKbd_Info[type].paBmp;

	guiExitWCS();
	return STATUS_OK;
}

/*********************************************************************/
//dest: 创建键盘控件
//para:
//	left,top:	左上角座标,均为0时表时缺省位置,即键盘位于屏幕的右下角
//	type:		缺省的键盘
//return:
//	fail:   NULL
//	sucess: return sw_kbd's handle
/*********************************************************************/
DLL_EXP(HNDL) guiSwKbd_Create(WORD left, WORD top, WORD type)
{
	WORD width,height;
	TGuiSw_Kbd  *pControl;
	
	guiEnterWCS();
	if(guiKbd_GetSize(type,&width,&height) == STATUS_ERR)	// 获取键盘尺寸
	{
        guiExitWCS();
		return NULL;		// 指定的键盘不存在
	}

	pControl=(TGuiSw_Kbd *)kernelMalloc(sizeof(TGuiSw_Kbd));	// 分配控件存储空间
	if(pControl == NULL)
	{
		guiExitWCS();
		return NULL;
	}

	pControl->base.handle =(HNDL)pControl;			// 控件数据存储地址
	pControl->base.type = CONTROL_SWKBD;			// 控件类型:键盘

	if( (left == 0) && (top == 0) )					// top和left均为0表示由自动确定键盘位置
	{
		pControl->base.left = GUI_SCREEN_WIDTH-width;	// 自动将键盘放置于屏幕的右下角
		pControl->base.top =  GUI_SCREEN_HEIGHT-height;
		pControl->base.right = GUI_SCREEN_WIDTH-1;
		pControl->base.bottom = GUI_SCREEN_HEIGHT-1;
	}
	else
	{
		pControl->base.left = left;
		pControl->base.top =  top;
		pControl->base.right = left+width-1;
		pControl->base.bottom =  top+height-1;
	}

	pControl->base.checkFlag = GUI_CONTROL_CHECK_FLAG;
	pControl->base.style = type;		//此参数表示键盘的编号
	pControl->base.status = 0;
	pControl->base.font  =  GUI_DEFAULT_FONT;

	pControl->base.vportHandle = NULL;
	pControl->base.container=NULL;

	pControl->base.actionFun =(PF_ACTION )_guiSwKbd_Action;
	pControl->base.showFun =(PF_SHOW)_guiSwKbd_Show;
	pControl->base.delFun =(PF_DELETE)_guiSwKbd_Delete;
	
	// 复位输入法使用的有关参数
	pControl->InputStr[0]='\0';
	pControl->Offset=0;
	pControl->TotalNum=0;
	pControl->StartPos=0;
	pControl->SelPos=-1;

	pControl->HWR_Buf1_Num=0;
	pControl->HWR_Buf2_Num=0;
	pControl->HWR_Buf1[0]='\0';
	pControl->HWR_Buf2[0]='\0';
	pControl->First_Stroke1=-1;
	pControl->First_Stroke2=-1;

	guiExitWCS();
	return (HNDL)pControl;
}

/*********************************************************************/
//dest: 键盘控件的消息响应
//para:
//	handle:	键盘控件的handle值
//	message:消息类型

⌨️ 快捷键说明

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