📄 asix_sb.c
字号:
/*************************************************************************
*
* Copyright 2001 National ASIC Center, All right Reserved
*
* FILE NAME: asix_sb.c
* PROGRAMMER: Lingming
* Date of Creation: 2001/05/30
*
* DESCRIPTION: The asix scrollbar control implementation. this
* file defines the control related infomation.
*
* NOTE: The asixwin.c MUST include this file
*
*
* FUNCTIONS LIST:
* extern STATUS sb_create(char *caption, U32 style, U16 x, U16 y,
* U16 width, U16 height, U32 wndid, U32 menu,
* void **ctrl_str,void *exdata)
* extern STATUS sb_destroy(void *ctrl_str)
* extern STATUS sb_msgproc(U16 asix_msg, U32 lparam, void *data,
* U16 wparam, void *reserved)
* extern STATUS sb_msgtrans(void *ctrl_str, U16 msg_type, U32 areaId,
* P_U16 data, U32 size, PMSG trans_msg)
* extern STATUS sb_repaint(void *ctrl_str, U32 lparam);
* extern STATUS sb_enable(void *ctrl_str, U8 enable);
*
*
* extern STATUS SetScrollRange(U32 windowid,U16 minpos, U16 maxpos)
* extern STATUS GetScrollRange(U32 windowid, P_U16 minpos,P_U16 maxpos)
* extern S16 GetScrollPos(U32 windowid, U16 message, U16 wparam, U8 flag)
* extern STATUS SetScrollPos(U32 windowid, U16 wparam, U32 menu, U16 message)
*
* GLOBAL VARS LIST:
*
*
**************************************************************************
* MODIFICATION HISTORY
*
* 2001/05/30 by Lingming Creation of this file
* 2001/06/17 by Pessia Rewrite all functions except sb_msgtrans
* 2001/11/27 by Lingming Add some param checking in sb_msgproc()
* for msg filtering the wparam item of
* Scroll control's msg should be
* WNDCLASS_SCROLL instead of WNDCLASS_TEST
* 2002/3/14 by Pessia Clean some bugs
* 2002/3/15 by Pessia Fix usage of sbctrl->slider_map
* 2002/3/16 by Pessia ADD clearing slider bar when min==max
* 2002/4/4 by Pessia in sb_create,
* use Lcalloc while not Lmalloc
* check value of x and y
* 2002/4/5 by Pessia Change scrollbar's color
*************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "asixwin.h"
#include "asixapp.h"
#include "disp.h"
#include "asix_sb.h"
#include "bitmap.h"
#include "gpc.h"
/*STATUS sb_create()
* char *caption, :it is always NULL;
* U32 style, :SBS_VERT , SBS_HORZ and WS_SAVESCREEN ...
* U16 x,y,width,height, :size of the whole scroll bar window
* U32 wndid, :id of the scroll bar window which is created
* just in front
* U32 menu, :LOWORD is logical min, HIWORD is logical max
* void **ctrl_str,
* void *exdata :reserved!
*/
STATUS sb_create(char *caption, U32 style, U16 x, U16 y, U16 width,
U16 height, U32 wndid, U32 menu, void **ctrl_str,void *exdata)
{
U32 pGC;
struct sb_ctrl *sbctrl;
U16 lcdh,lcdw;
/* min : min logical rows of user field
* max : max logical rows of user field
*/
U16 min, max;
lcdh = ASIX_LCD_H; lcdw = ASIX_LCD_W;
min = LOWORD(menu); max = HIWORD(menu);
/* Check these parameters */
/* if scrollbar to be created goes out of lcd screen, error */
if ( x > lcdw || y > lcdh ) /* added 2002/4/4 */
return ASIX_ERROR;
if ( (x+width)>lcdw || (y+height)>lcdh )
return ASIX_ERROR;
if ( min > max ) return ASIX_ERROR;
/* scrollbar should have only one style */
if ( (style & SBS_HORZ) && (style & SBS_VERT) )
return ASIX_ERROR;
/* check scrollbar's min width or height */
if ( (style & SBS_HORZ) &&
(height < MIN_SBHEIGHT || width <(2*height) ) )
return ASIX_ERROR;
if ( (style & SBS_VERT) &&
(width < MIN_SBWIDTH || height < (2*width ) ) )
return ASIX_ERROR;
// longn_qi 2002/01/25 for monitor memory leak
asix_sb_memdbgprintf( "### Create Scrollbar ###" );
asix_sb_memdbgprintf( "scrollbar appeal mem for itself" );
sbctrl = (struct sb_ctrl *)Lcalloc( sizeof(struct sb_ctrl) );
if (sbctrl == NULL )
{
asix_sb_memdbgprintf( "### Create Scrollbar Error ###" );
return ASIX_NO_MEM;
}
sbctrl->classid = (U32)WNDCLASS_SCROLL;
sbctrl->windowid = wndid;
sbctrl->style = style;
sbctrl->x = x;
sbctrl->y = y;
sbctrl->width = width;
sbctrl->height = height;
sbctrl->start = (style & SBS_HORZ)?(x):(y);
sbctrl->end = (style & SBS_HORZ)?(x+width-1):(y+height-1);
sbctrl->boxw = (style & SBS_HORZ)?(height-2):(width-2);
sbctrl->slider_area_start = sbctrl->start + sbctrl->boxw;
sbctrl->slider_area_end = sbctrl->end - sbctrl->boxw;
sbctrl->slider_area_range = sbctrl->slider_area_end -
sbctrl->slider_area_start - 1;
/* Initial the slider bar's position (note : the bar is static!!!) */
sbctrl->curpos = sbctrl->slider_area_start + 1;//initial
if( (sbctrl->thumblen= sbctrl->slider_area_range/4 ) < MIN_SLIDERBAR )
sbctrl->thumblen = MIN_SLIDERBAR;//initial
sbctrl->thumbend = sbctrl->curpos + sbctrl->thumblen - 1;//initial
sbctrl->minpos = min;//logical min
sbctrl->maxpos = max;//logical max
sbctrl->logcurpos = min;
sbctrl->logrange = max-min+1;
sbctrl->enablescroll = 0;
sbctrl->keepscroll = 0;
sbctrl->haveinversed = 0;
//pessia2002/3/16:
//when maxpos==minpos, scrollbar is disabled,
//and do not create slider bar(thumb )
if(sbctrl->maxpos == sbctrl->minpos)
sbctrl->scrollstatus = 0;
else
sbctrl->scrollstatus = 1;
/* Initial value:
* They are very important,
* because they're used to judge if first touch or not */
sbctrl->oldpenx=-1000;
sbctrl->oldpeny=-1000;
pGC =GetGC();
/* If scrollbar uses WS_SAVESCREEN style,
* field covered by it should be saved. */
if ( style & WS_SAVESCREEN)
{
asix_sb_memdbgprintf( "scrollbar appeal mem for coveredmap" );
// sbctrl->sb_coveredmap = (U8 *)Lmalloc(width * height*2+2);
sbctrl->sb_coveredmap = (U8 *)GetBlock( width, height );
if (sbctrl->sb_coveredmap == NULL)
{
Lfree ( (P_VOID)sbctrl);
asix_sb_memdbgprintf( "### Create Scrollbar Error ###" );
return ASIX_NO_MEM;
}
SaveRec( pGC, sbctrl->sb_coveredmap, x, y, width, height, 0);
} else {
/* Pessia2002/3/18:
* If scrollbar do not uses WS_SAVESCREEN style,
* sbctrl->sb_coveredmap should be set NULL*/
sbctrl->sb_coveredmap = NULL;
}
/* Create three activeareas : two ICON_AREA and one INPUT_AREA */
if ( ActiveAreaEnable( (P_U32)&(sbctrl->upright_id), ICON_AREA, CONTINUOUS_MODE,
x+1, y+1, x+sbctrl->boxw, y+sbctrl->boxw, sbctrl->windowid ) != PPSM_OK )
goto ErrHandle;
if ( ActiveAreaEnable( (P_U32)&(sbctrl->downleft_id), ICON_AREA, CONTINUOUS_MODE,
x+((style&SBS_HORZ)?(width-sbctrl->boxw-1):1),
y+((style&SBS_VERT)?(height-sbctrl->boxw-1):1),
x+width-2,
y+height-2,
sbctrl->windowid) != PPSM_OK )
goto ErrHandle;
if ( ActiveAreaEnable( (P_U32)&(sbctrl->slider_id), INPUT_AREA, CONTINUOUS_MODE,
x+1+((style&SBS_HORZ)?sbctrl->boxw:0),
y+1+((style&SBS_VERT)?sbctrl->boxw:0),
x+((style&SBS_HORZ)?(width-sbctrl->boxw-2):sbctrl->boxw),
y+((style&SBS_VERT)?(height-sbctrl->boxw-2):sbctrl->boxw),
sbctrl->windowid) != PPSM_OK )
goto ErrHandle;
ClearRec( pGC,ColorTheme.form_backcolor,
x, y, width, height, GPC_REPLACE_STYLE);
/* Draw two icons */
if (style & SBS_VERT) {
// DrawMonoImage( pGC, up10X10,
// x +width/2 - BMP_WIDTH/2,
// y + sbctrl->boxw/2 - BMP_HEIGHT/2,
// BMP_WIDTH,
// BMP_HEIGHT,
// ColorTheme.form_frontcolor, ColorTheme.form_backcolor);
{
U32 hbmp;
//U32 trColor;
U16 lx = x +width/2 - BMP_WIDTH/2;
U16 ly = y + sbctrl->boxw/2 - BMP_HEIGHT/2;
U32 palette[2];
palette[0] = ColorTheme.form_client;
palette[1] = ColorTheme.form_frontcolor;
hbmp = LoadBitmap( up10X10, palette );
if( hbmp != 0 )
{
SetBMPPalette( hbmp, palette, NULL );
//SetBkFillMode( pGC, MAKELONG( GPC_REPLACE_STYLE, GPC_TRANSPARENT_STYLE ) );
//GetBMPPixel( pGC, 0, 0, hbmp, &trColor );
//DisplayBMPEx( pGC, x, y, hbmp, GPC_TRANSPARENT_STYLE, trColor );
DisplayBMP( pGC, lx, ly, hbmp );
FreeBitmap( hbmp );
}
}
// DrawMonoImage( pGC,down10X10,
// x +width/2 - BMP_WIDTH/2,
// y + height-sbctrl->boxw/2-BMP_HEIGHT/2,
// BMP_WIDTH,
// BMP_HEIGHT,
// ColorTheme.form_frontcolor, ColorTheme.form_backcolor);
{
U32 hbmp;
//U32 trColor;
U16 lx = x +width/2 - BMP_WIDTH/2;
U16 ly = y + height-sbctrl->boxw/2-BMP_HEIGHT/2;
U32 palette[2];
palette[0] = ColorTheme.form_client;
palette[1] = ColorTheme.form_frontcolor;
hbmp = LoadBitmap( down10X10, palette );
if( hbmp != 0 )
{
SetBMPPalette( hbmp, palette, NULL );
//SetBkFillMode( pGC, MAKELONG( GPC_REPLACE_STYLE, GPC_TRANSPARENT_STYLE ) );
//GetBMPPixel( pGC, 0, 0, hbmp, &trColor );
//DisplayBMPEx( pGC, x, y, hbmp, GPC_TRANSPARENT_STYLE, trColor );
DisplayBMP( pGC, lx, ly, hbmp );
FreeBitmap( hbmp );
}
}
} else {
// DrawMonoImage( pGC, left10X10,
// x +sbctrl->boxw/2 - BMP_WIDTH/2,
// y + height/2 - BMP_HEIGHT/2,
// BMP_WIDTH,
// BMP_HEIGHT,
// ColorTheme.form_frontcolor, ColorTheme.form_backcolor);
{
U32 hbmp;
//U32 trColor;
U16 lx = x +sbctrl->boxw/2 - BMP_WIDTH/2;
U16 ly = y + height/2 - BMP_HEIGHT/2;
U32 palette[2];
palette[0] = ColorTheme.form_client;
palette[1] = ColorTheme.form_frontcolor;
hbmp = LoadBitmap( left10X10, palette );
if( hbmp != 0 )
{
SetBMPPalette( hbmp, palette, NULL );
//SetBkFillMode( pGC, MAKELONG( GPC_REPLACE_STYLE, GPC_TRANSPARENT_STYLE ) );
//GetBMPPixel( pGC, 0, 0, hbmp, &trColor );
//DisplayBMPEx( pGC, x, y, hbmp, GPC_TRANSPARENT_STYLE, trColor );
DisplayBMP( pGC, lx, ly, hbmp );
FreeBitmap( hbmp );
}
}
// DrawMonoImage( pGC, right10X10,
// x +width - sbctrl->boxw/2- BMP_WIDTH/2,
// y + height/2-BMP_HEIGHT/2,
// BMP_WIDTH,
// BMP_HEIGHT,
// ColorTheme.form_frontcolor, ColorTheme.form_backcolor);
{
U32 hbmp;
//U32 trColor;
U16 lx = x +width - sbctrl->boxw/2- BMP_WIDTH/2;
U16 ly = y + height/2-BMP_HEIGHT/2;
U32 palette[2];
palette[0] = ColorTheme.form_client;
palette[1] = ColorTheme.form_frontcolor;
hbmp = LoadBitmap( right10X10, palette );
if( hbmp != 0 )
{
SetBMPPalette( hbmp, palette, NULL );
//SetBkFillMode( pGC, MAKELONG( GPC_REPLACE_STYLE, GPC_TRANSPARENT_STYLE ) );
//GetBMPPixel( pGC, 0, 0, hbmp, &trColor );
//DisplayBMPEx( pGC, x, y, hbmp, GPC_TRANSPARENT_STYLE, trColor );
DisplayBMP( pGC, lx, ly, hbmp );
FreeBitmap( hbmp );
}
}
}
//pessia2002/3/16:
//when maxpos==minpos, scrollbar is disabled,
//and do not create slider bar(thumb )
if(sbctrl->maxpos != sbctrl->minpos)
{
/* Save the slider bar's bitmap */
asix_sb_memdbgprintf( "scrollbar appeal mem for slidermap" );
// sbctrl->slider_map = (U8 *)Lmalloc(sbctrl->thumblen*
// ((style&SBS_HORZ)?(height-2):(width-2))*2+2);
// sbctrl->slider_map = (U8 *)GetBlock( sbctrl->thumblen, ((style&SBS_HORZ)?(height-2):(width-2)) );
sbctrl->slider_map = (U8 *)GetBlock( sbctrl->boxw, sbctrl->thumblen );
if( sbctrl->slider_map == NULL )
{
asix_sb_memdbgprintf( "scrollbar free mem of itself" );
Lfree ( (P_VOID)sbctrl);
asix_sb_memdbgprintf( "### Create Scrollbar Error ###" );
return ASIX_NO_MEM;
}
/* Draw slider bar */
DrawRec( pGC, ColorTheme.form_line,
(style&SBS_HORZ)?(x+1+sbctrl->boxw):(x+1),
(style&SBS_HORZ)?(y+1):(y+sbctrl->boxw+1),
(style&SBS_HORZ)?sbctrl->thumbend:(x+sbctrl->boxw),
(style&SBS_HORZ)?(y+sbctrl->boxw):sbctrl->thumbend,
GPC_SOLID_LINE, GPC_REPLACE_STYLE);
ClearRec( pGC,ColorTheme.obj3D,
(style&SBS_HORZ)?(x+sbctrl->boxw+2):(x+2),
(style&SBS_HORZ)?(y+2):(y+sbctrl->boxw+2),
(style&SBS_HORZ)?(sbctrl->thumblen-2):(sbctrl->boxw-2),
(style&SBS_HORZ)?(sbctrl->boxw-2):(sbctrl->thumblen-2),
GPC_REPLACE_STYLE);
SaveRec( pGC, sbctrl->slider_map,
(style&SBS_HORZ)?(x+1+sbctrl->boxw):(x+1),
(style&SBS_HORZ)?(y+1):(y+sbctrl->boxw+1),
(style&SBS_HORZ)?sbctrl->thumblen:(sbctrl->boxw),
(style&SBS_HORZ)?(sbctrl->boxw):sbctrl->thumblen, 0);
}
else
sbctrl->slider_map = NULL;
/* Draw the border of the whole window */
DrawRec( pGC, ColorTheme.form_line, x, y, x+width-1, y+height-1,
GPC_SOLID_LINE, GPC_REPLACE_STYLE);
(void *)*ctrl_str = (void *)sbctrl;
asix_sb_memdbgprintf( "### Create Scrollbar Successfully ###" );
return ASIX_OK;
ErrHandle:
if (sbctrl->upright_id!=0)
ActiveAreaDisable(sbctrl->upright_id);
if (sbctrl->downleft_id!=0)
ActiveAreaDisable(sbctrl->downleft_id);
if (sbctrl->slider_id!=0)
ActiveAreaDisable(sbctrl->slider_id);
if (sbctrl->sb_coveredmap != NULL) {
PutRec( pGC,sbctrl->sb_coveredmap,
x, y, width, height, GPC_REPLACE_STYLE, 0);
asix_sb_memdbgprintf( "scrollbar free mem of coveredmap" );
Lfree(sbctrl->sb_coveredmap);
}
asix_sb_memdbgprintf( "scrollbar free mem of itself" );
Lfree(sbctrl);
asix_sb_memdbgprintf( "### Create Scrollbar Error ###" );
return ASIX_ERROR;
}
/*STATUS sb_msgtrans()
void *ctrl_str, :pointer to control structure
U16 msg_type, :type of the message waiting to be translate
U32 areaId, :which area the message come from
P_U16 data, :message's data
U32 size, :not used!
PMSG trans_msg :return translated-message
*/
STATUS sb_msgtrans(void *ctrl_str, U16 msg_type, U32 areaId, P_U16 data,
U32 size, PMSG trans_msg)
{
register struct sb_ctrl *sbctrl;
/* 01-11-25 type case error modifed by pessia*/
sbctrl = (struct sb_ctrl *)ctrl_str;
//pessia2002/3/16:
//if Scroll bar is disabled , return.
//and this Scroll bar's sb_msgproc() will not be called.
//so status-checking in sb_msgproc() is needn't.
if ( sbctrl->scrollstatus==0 ) return ASIX_NO_MSG;
if ( msg_type != ASIX_ICON && msg_type != ASIX_INPUT_STATUS &&
msg_type != ASIX_PEN)
return ASIX_NO_MSG;
if (sbctrl==NULL || trans_msg==NULL)
return ASIX_ERROR;
// longn_qi 2001/11/28 delete (1)
//memset( (void *)trans_msg, 0x0, sizeof (MSG) );
//the type of all the ASIX win messages are ASIX_MESSAGE
trans_msg->messageType = ASIX_MESSAGE;
switch( msg_type )
{
case ASIX_ICON:
if (areaId == sbctrl->upright_id) {
sbctrl->areaselect = SB_UPRIGHT;
} else if (areaId == sbctrl->downleft_id ) {
sbctrl->areaselect = SB_DOWNLEFT;
} else
return ASIX_NO_MSG;
trans_msg->lparam = sbctrl->windowid;
trans_msg->data = (void *)sbctrl;
trans_msg->wparam = (U16)WNDCLASS_SCROLL;
// longn_qi 2002/02/23 replace "*data" with "size"
if ( size == PPSM_ICON_TOUCH ) trans_msg->message = WM_PENDOWN;
else if ( size == PPSM_ICON_DRAG ) trans_msg->message = WM_PENDRAG;
else if ( size == PPSM_ICON_DRAG_UP ) trans_msg->message = WM_PENDRAGUP;
else if ( size == PPSM_ICON_PEN_UP ) trans_msg->message = WM_PENUP;
//else trans_msg->message is equal to zero ;
break;
case ASIX_INPUT_STATUS:
if ( areaId == sbctrl->slider_id ) {
sbctrl->areaselect = SB_SLIDER;
} else
return ASIX_NO_MSG;
trans_msg->lparam = sbctrl->windowid;
trans_msg->data = (void *)sbctrl;
trans_msg->wparam = (U16)WNDCLASS_SCROLL; //Debugging state
// longn_qi 2002/02/23 replace "*data" with "size"
if ( size == PPSM_INPUT_TOUCH ) trans_msg->message = WM_PENDOWN;
else if ( size == PPSM_INPUT_DRAG ) trans_msg->message = WM_PENDRAG;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -