📄 button.c
字号:
/**********************************************************
*
*Copyright ? 2001 National ASIC Center, All right Reserved
*
* FILE NAME: button.c
* PROGRAMMER: ZengXianWei
* Date of Creation: 2001/2/12
*
*DESCRIPTION: button.c and button.h accomodate several functions which will be used in creating a button contral
*
*NOTE: every function in this file can only be directly quoted by CreatWindow(),DestroyWindow(),EnableWindow(),DefWindowProc(),
* WindowCaption(),WindowInformation(),etc.Application programmer must use these functions to call the following function
* indirectly.
*
*FUNCTIONS LIST:
*the following define eight member function.
*STATUS (*Btn_creat)(char *caption,U32 style,U16 x,U16 y,U16 width,U16 hight,U32 parent,U32 menu,void **ctrl_str,void *exdata);
* _caption is the string of the button caption ,it will be divided into two part by '\' .
* at the front of it is the caption of the button,and the back of it is the caption of the tag
* _style specified the style of the button which will be draw,the low 16 bit will be used in button control,the high 16 bits was used by system
* _x specified the top_x of the button.
* _y specified the top_y of the button.
* _width specified the width of the button.
* _hight specified the hight of the button.
* _parent is the parent wndid of the button.
* _menu specified the width and the hight of the bitmap which will be draw on the surface of the button,the high 16 bits specified the hight of
* the bitmap,and the low 16 bits specified the width of the bitmap.
* _ctrl_str is a export parameter,it point to the ctrl_structure ,it was defined in button.h
* _exdata specified the bitmap which will be drew on the button.
*STATUS (*Btn_destroy)(void *ctrl_str);
* _ctrl_str is the only inport parameter of this function.
*STATUS (*Btn_msg_trans)(void *ctrl_str, U16 msg_type, U32 areaId, P_U16 data, U32 size, PMSG trans_msg);
* _ctrl_str is the inport parameter of the button.
* _msg_type is the message type.
* _areaid.
* _size.
* _trans_msg is a export parameter in this function.
*STATUS (*Btn_msg_proc)(U16 msg_type,U32 areaid,void data,U32 size,void *reserved);
* _msg_type is a inport parameter of this function,
* _areaid.
* _size.
* _reserved is a reserved parameter maybe will be used later.
*STATUS (*Btn_repaint)(vid *ctrl_str,U32 Btn_lparam);
*STATUS (*Btn_enable)(void *ctrl_str,U32 Btn_indes,U32 Btn_lparam);
*STATUS (*Btn_caption)(void *ctrl_str,char *caption,void *Btn_exdata,U32 Btn_lparam);
*the following two function is two sub_function
*static STATUS drawbutton( S16 xSrc,S16 ySrc,S16 xDest,S16 yDest,U32 btn_style,char *caption,P_U8 bitmap,S16 bitmap_width,S16 bitmap_hight );
* _xSrc specified the topleft_x of the button.
* _ySrc specified the topleft_y fo the button.
* _xDest specified the bottomright_x of the button.
* _yDest specified the bottomright_y of the button.
* _btn_style specified the style of the button which will be draw.
* _caption specified the caption of the button if the button has a tag the caption of the tag will be seprated by '\'.
* _bitmap specified the bitmap of the button if it will be drew a icon button.
* _bitmapwidth specified the width fo the button.
* _bitmaphight specified the hight of the button.
*static STATUS drawdownbutton( void *ctrl_str,S16 xSrc,S16 ySrc,S16 xDest,S16 yDest,U32 btn_style,char *caption,P_U8 tagbk_saved,P_U8 bitmap,S16 bitmap_width,S16 bitmap_hight );
* _ctrl_str is the pointer of the ctrl structure.
* _xSrc specified the topleft_x of the button.
* _ySrc specified the topleft_y of the button.
* _xDest specified the bottomright_x of the button.
* _yDest specified the bottomright_y of the button.
* _btn_style specified the style of the button which will be draw.
* _caption specified the caption of the button if the button has a tag the caption of the tag will be seprated by '\'.
* _tagbk_saved point to the background which will be drew a tag.
* _bitmap specified the bitmap of the button if it will be drew a icon button.
* _bitmapwidth specified the width fo the button.
* _bitmaphight specified the hight of the button.
*GLOBAL VARS LIST:
*
*********************************************************
*MODIFICATION HISTORY
*
*
* 2001/2/12 by ZengXianWei Description of the changes mode to the file
* changes should be listed in the reverse order
* 2001/11/27by Lingming Add msg filtering in Btn_msg_proc()
* 2002/3/26 by Pessia When enable button, do not clear rectangle(for new shell)
***********************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <asixwin.h>
#include <asixapp.h>
//#include <hc.h>
#include <sys\keydef.h>
#include<asixwin\disp.h>// add this header to where?
//#include"bitmap.h"
#include <asixwin\button.h>
//#include"help.h"
#define SCREENWIDTH ASIX_LCD_W
#define SCREENHIGHT ASIX_LCD_H
static STATUS drawbutton( void *ctrl_str, S16 xSrc, S16 ySrc,S16 xDest,S16 yDest,U32 btn_style,char *caption,P_U8 bitmap,S16 bitmap_width,S16 bitmap_hight );
static STATUS drawdownbutton( void *ctrl_str,S16 xSrc,S16 ySrc,S16 xDest,S16 yDest,U32 btn_style,char *caption,P_U8 tagbk_saved,P_U8 bitmap,S16 bitmap_width,S16 bitmap_hight );
static STATUS drawbuttontag( struct bt_ctrl_str *ctrl_ptr, char *caption_tag );
//the following helps to realize button(include draw the figure of the button and create the bt_ctrl_str construction)
STATUS Btn_create(char *caption,U32 style,U16 x,U16 y,U16 width,U16 hight,U32 parent,U32 menu,void **ctrl_str,void *exdata)
{
//U8 grey;
U32 Btn_areaid;
//S16 bitmap_hight;
//S16 bitmap_width;
struct bt_ctrl_str *pbcs;
U32 pGC;
//modified by xuanhui 2002/4/3
if ( (U16)(x+width-1)>=ASIX_LCD_W || (U16)(y+hight-1)>=ASIX_LCD_H ) return ASIX_ERROR;
Btn_areaid = 0;
*ctrl_str = NULL;
pGC = GetGC();
asix_bt_memdbgprintf( "## create button ##" );
//allocate a piece of memory and it will be free untill the button be destroyed
// longn_qi 2002/01/25 for monitor memory leak
asix_bt_memdbgprintf( "button appeal mem for itself" );
if( (pbcs = (struct bt_ctrl_str *)Lcalloc( sizeof(struct bt_ctrl_str) )) == NULL )
return ASIX_NO_MEM;
//initiate the ctrl_str
pbcs->classid = WNDCLASS_BUTTON;
pbcs->wndid = parent;
pbcs->bt_style = style;
pbcs->bt_caption = caption;
pbcs->bt_icon = (P_U8)exdata;
//PenIrptDisable();
if( ActiveAreaEnable( &Btn_areaid,ICON_AREA,STROKE_MODE,(S16)x,(S16)y,(S16)(x+width-1),(S16)(y+hight-1), pbcs->wndid ) == PPSM_ERROR )
{
//PenIrptEnable();
// longn_qi 2002/01/25 for monitor memory leak
asix_bt_memdbgprintf( "button free mem of itself" );
Lfree(pbcs);
asix_bt_memdbgprintf( "## create button error ##" );
return ASIX_ERROR;//here maybe need free
}
//PenIrptEnable();
pbcs->bt_id = Btn_areaid;
if( style & WS_DISABLED )
{
//pbcs->bt_state = FALSE;
ActiveAreaSuspend( Btn_areaid,AREA_SUSPEND );
} else {
//pbcs->bt_state = TRUE;
}
//save the background of the rectangle which will creat a button
if( style & WS_SAVESCREEN )
{
// bitmap pixel is 2 bytes (longn_qi 2001/11/15 revised )
// if( ( ( pbcs->bt_back_saved) = Lmalloc( (width*hight*2+2)*sizeof(U8) ) ) == NULL )
if( ( ( pbcs->bt_back_saved) = (P_U8)GetBlock( width, hight ) ) == NULL )
{
// longn_qi 2002/01/25 for monitor memory leak
asix_bt_memdbgprintf( "button free mem of itself" );
Lfree(pbcs);
ActiveAreaDisable( Btn_areaid ); //modified by xuanhui 2002/4/4
asix_bt_memdbgprintf( "## create button error ##" );
return ASIX_NO_MEM;
}
// longn_qi 2002/01/25 for monitor memory leak
asix_bt_memdbgprintf( "button appeal mem for bt_back_saved" );
if( SaveRec( pGC, (P_U16)pbcs->bt_back_saved, x, y, width,hight,0 ) != PPSM_OK )
{
// longn_qi 2002/01/25 for monitor memory leak
asix_bt_memdbgprintf( "button free mem of bt_back_saved" );
Lfree(pbcs->bt_back_saved);
// longn_qi 2002/01/25 for monitor memory leak
asix_bt_memdbgprintf( "button free mem of itself" );
Lfree(pbcs);
ActiveAreaDisable( Btn_areaid ); //modified by xuanhui 2002/4/4
asix_bt_memdbgprintf( "## create button error ##" );
return ASIX_ERROR;
}
}
//if( exdata != NULL )
/*User must specificate the bitmap w and h even the button
do not have bitmap at the creation time. LM 01/08/11*/
//{
//bitmap_hight = HIWORD( menu );
pbcs->bt_icon_hight = HIWORD( menu ); //bitmap_hight;
//bitmap_width = LOWORD( menu );
pbcs->bt_icon_width = LOWORD( menu ); //bitmap_width;
//}
//draw button
if( drawbutton( pbcs, (S16)x,(S16)y,(S16)(x+width-1),(S16)(y+hight-1), style, caption,
exdata,(S16) pbcs->bt_icon_width,(S16) pbcs->bt_icon_hight ) != ASIX_OK )
{
// longn_qi 2002/01/25 for monitor memory leak
asix_bt_memdbgprintf( "button free mem of bt_back_saved" );
Lfree(pbcs->bt_back_saved);
// longn_qi 2002/01/25 for monitor memory leak
asix_bt_memdbgprintf( "button free mem of itself" );
Lfree(pbcs);
ActiveAreaDisable( Btn_areaid ); //modified by xuanhui 2002/4/4
asix_bt_memdbgprintf( "## create button error ##" );
return ASIX_ERROR;
}
*ctrl_str = (void *)pbcs; //let ctrl_str point to pbcs;
asix_bt_memdbgprintf( "## create button successfully ##" );
return ASIX_OK;
}
//the function Btn_destroy() helps to destroy a button(include the figure of the button and the bt_ctrl_str construction)
STATUS Btn_destroy( void *ctrl_str )
{
S16 x;
S16 y;
S16 xdest;
S16 ydest;
STATUS rv;
struct bt_ctrl_str *ctrl_ptr;
U32 pGC;
pGC = GetGC();
ctrl_ptr = (struct bt_ctrl_str *)ctrl_str;
if ( ctrl_ptr == NULL || ctrl_ptr->bt_id == 0 )
return ASIX_ERROR;
//clear the surface of the button
/*if( ctrl_ptr->bt_state == FALSE )
{
ActiveAreaSuspend( ctrl_ptr->bt_id,AREA_REENABLE );
}*/
asix_bt_memdbgprintf( "## destroy button ##" );
PenIrptDisable();
if( (rv = ActiveAreaRead( ctrl_ptr->bt_id, &x, &y, &xdest, &ydest ))!= PPSM_OK )
{
goto destroy;
}
//refresh the background of the button
if( ctrl_ptr->bt_back_saved != NULL )
{
//modified by xuanhui 2002/3/14
//PutRec(pGC, (P_U16)ctrl_ptr->bt_back_saved,(U16) x, (U16) y, (U16)(xdest-x+1), (U16)(ydest-y+1),GPC_REPLACE_STYLE, 0);
if ( PutRec(pGC, (P_U16)ctrl_ptr->bt_back_saved,(U16)x, (U16)y, (U16)(xdest-x+1), (U16)(ydest-y+1),GPC_REPLACE_STYLE, 0) != PPSM_OK )
{
asix_bt_memdbgprintf( "## destroy button error ##" );
return ASIX_ERROR;
}
// longn_qi 2002/01/25 for monitor memory leak
asix_bt_memdbgprintf( "button free mem of bt_back_saved" );
Lfree( ctrl_ptr->bt_back_saved );
} else {
//modified by xuanhui 2002/3/14
//ClearRec( pGC, ColorTheme.form_client, (U16)x, (U16)y, (U16)(xdest-x+1), (U16)(ydest-y+1), GPC_REPLACE_STYLE );
ClearRec( pGC, ColorTheme.form_backcolor, (U16)x, (U16)y, (U16)(xdest-x+1), (U16)(ydest-y+1), GPC_REPLACE_STYLE );
}
// disable the active area
rv = ActiveAreaDisable(ctrl_ptr->bt_id);
destroy:
PenIrptEnable();
//free the block of memory which were allocated
// Lfree(ctrl_ptr->bt_face_saved);
if( ctrl_ptr->bt_back_saved != NULL )
{
// longn_qi 2002/01/25 for monitor memory leak
asix_bt_memdbgprintf( "button free mem of bt_back_saved" );
Lfree(ctrl_ptr->bt_back_saved);
}
if( ctrl_ptr->bt_tag_saved != NULL )
{
// longn_qi 2002/01/25 for monitor memory leak
asix_bt_memdbgprintf( "button free mem of bt_tag_saved" );
Lfree(ctrl_ptr->bt_tag_saved);
}
// longn_qi 2002/01/25 for monitor memory leak
asix_bt_memdbgprintf( "button free mem of itself" );
Lfree((void *)ctrl_ptr);
asix_bt_memdbgprintf( "## destroy button successfully ##" );
return rv;
}
//the function bt_msg_trans() helps to translate the message of PPSM into the message of ASIXWIN
STATUS Btn_msg_trans(void *ctrl_str, U16 msg_type, U32 areaid, P_U16 data, U32 size, PMSG trans_msg)
{
//void *memmsg;
struct bt_ctrl_str *pbtctrl;
pbtctrl = (struct bt_ctrl_str *)ctrl_str;
if ( msg_type != ASIX_ICON && msg_type != ASIX_KEY ) return ASIX_NO_MSG;//it is not for me By Lingming 2001/11/27
if ( pbtctrl == NULL )
return ASIX_ERROR;
if ( pbtctrl->bt_id != areaid && pbtctrl->wndid != areaid ) return ASIX_NO_MSG;
//allocate memory for MSG struct
memset( (void *)trans_msg, 0x0, sizeof (MSG) );
//trans_msg = (PMSG)memmsg;
//the following will fill the message struct
switch( msg_type )
{
case ASIX_ICON:
{
// switch( *data )
switch( size )
{
case PPSM_ICON_DRAG_UP:
{
trans_msg->message = WM_PENDRAGUP;
break;
}
case PPSM_ICON_PEN_UP:
{
trans_msg->message = WM_PENUP;
break;
}
case PPSM_ICON_TOUCH:
{
trans_msg->message = WM_PENDOWN;
break;
}
case PPSM_ICON_DRAG:
{
trans_msg->message = WM_PENDRAG;
break;
}
default: return ASIX_ERROR;
}
trans_msg->messageType = ASIX_MESSAGE;
trans_msg->lparam = pbtctrl->wndid;
trans_msg->data = (void *)pbtctrl;
break;
}
case ASIX_KEY:
trans_msg->messageType = ASIX_MESSAGE;
trans_msg->message = WM_KEYUP;
trans_msg->lparam = pbtctrl->wndid;
trans_msg->wparam = size + ASIX_CONTROL_KEY_CODE_BEGIN;
trans_msg->data = (void *)pbtctrl;
break;
/*case WM_COMMAND:
{
trans_msg->message = WM_COMMAND;
trans_msg->messageType = ASIX_MESSAGE;
trans_msg->lparam = pbtctrl->wndid;
trans_msg->data = pbtctrl;
break;
}*/
default:
return ASIX_NO_MSG;
}
return ASIX_OK;
}
//the function Btn_nsg_proc helps to do the default message process
//in this function bt_areaId take the place of lparam,bt_size take the place of wparam
STATUS Btn_msg_proc( U32 win_id, U16 bt_msg_type, U32 lparam, void *data, U16 wparam, void *reserved )
{
U32 Btn_style;
S16 xSrc;
S16 ySrc;
S16 xDest;
S16 yDest;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -