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

📄 select.c

📁 基于东南大学开发的SEP3203的ARM7中的所有驱动
💻 C
📖 第 1 页 / 共 4 页
字号:
		//modified by xuanhui 2002/3/20
		//SetDotWidth( pGC, 9,0 );		// 点宽现无法使用,只能用点宽为1的线 	
		//DrawDot( pGC, GPC_LIGHTGREY,x+width/2,y+hight/2,GPC_REPLACE_STYLE );
		//DrawDot( pGC, ColorTheme.form_disablecolor,x+width/2,y+hight/2,GPC_REPLACE_STYLE );
		//SetDotWidth( pGC, 1,0 );		//modified by xuanhui 2002/3/20

		if( state == SL_CHECKED )
		{
			ClearRec( pGC, ColorTheme.form_disablecolor,x+width/2-1,y+hight/2-1,3,3,GPC_REPLACE_STYLE );
		}
	}
	
}

//the function sl_create() will helps create a selectbox include the ctrl structure 
STATUS sl_create(char *caption,U32 style,U16 x,U16 y,U16 width,U16 hight,U32 parent,U32 menu,void  **ctrl_str,void *exdata)
{
	struct	sl_ctrl_str			*ctrl_ptr;
	struct	sl_tempdata		*curradio_ptr;
	struct	sl_tempdata		*nextradio_ptr;
	struct	sl_item			*exdata_ptr;
	U32		*itemareaid;
	U8		i;
	U8		j;
	U8		rownum;
	U16		startx;
	U16		starty;
	U16		interval;
	
	//modified by xuanhui 2002/4/4
	U16		text_starty;
	char		*scaption = NULL;		
//	int 		k;
	int		string_len;
	U16		y_frame;		//modified by xuanhui 2002/4/9
		
	U8		enable;
	U32		pGC;

	pGC = GetGC( );
	
	//check these parameters
	//if ( ((style&SLS_CHECKBOX)==0) && ((style&SLS_RADIOBOX)==0) ) return ASIX_ERROR;//modified by xuanhui 2002/3/20

	//modified by xuanhui 2002/4/3
	//if ( (x+width)>ASIX_LCD_W || (y+hight)>ASIX_LCD_H ) return ASIX_ERROR;
	if ( (U16)(x+width-1)>=ASIX_LCD_W || (U16)(y+hight-1)>=ASIX_LCD_H ) return ASIX_ERROR;
	
	//allocate memory for ctrl_str
	//we should init the mem allocted before we can use it, so we use Lcalloc to do this job
	//By Lingmimg 2001/11/19
	if( (ctrl_ptr = (struct sl_ctrl_str *)Lcalloc( sizeof(struct sl_ctrl_str) )) == NULL )
		return ASIX_NO_MEM;
	
	*ctrl_str = (void *)ctrl_ptr; 
	
	if (style & WS_SAVESCREEN) {
//		ctrl_ptr->sl_bk_saved = (U8 *)Lcalloc(width * hight*2+2);//Now in 4K LCD modual, we have 2 bypt per pixel
		ctrl_ptr->sl_bk_saved = (U8 *)GetBlock( width, hight );//Now in 4K LCD modual, we have 2 bypt per pixel
		if (ctrl_ptr->sl_bk_saved == NULL)
		{
			//modified by xuanhui 2002/3/20
			//Lfree ( (P_VOID)ctrl_ptr);
			Lfree (ctrl_ptr);
			return ASIX_NO_MEM;
		}
	
		//modified by xuanhui 2002/3/20
		//SaveRec( pGC, ctrl_ptr->sl_bk_saved, x, y, width, hight, 0);
		if ( SaveRec( pGC, (P_U16)ctrl_ptr->sl_bk_saved, x, y, width, hight, 0) == PPSM_ERROR )
		{
			Lfree (ctrl_ptr->sl_bk_saved);
			Lfree (ctrl_ptr);
			return ASIX_ERROR;
		}
	}else{	
		ctrl_ptr->sl_bk_saved = NULL;	//modified by xh 02/11/5
	}
	
	//allocate memory for ctrl_ptr->sl_curradio  
	if( (curradio_ptr = (struct sl_tempdata *)Lcalloc( sizeof(struct sl_tempdata)) ) == NULL )
	{
		Lfree(ctrl_ptr->sl_bk_saved);
		Lfree( ctrl_ptr );
		return ASIX_NO_MEM;
	}
	ctrl_ptr->sl_curradio = curradio_ptr;
	
	//allocate memory for ctrl_ptr->sl_nextradio,and set NULL
	if( (nextradio_ptr = (struct sl_tempdata *)Lcalloc( sizeof(struct sl_tempdata)) ) == NULL )
	{
		Lfree(ctrl_ptr->sl_bk_saved);
		Lfree( curradio_ptr );
		Lfree( ctrl_ptr );
		return ASIX_NO_MEM;
	}
	ctrl_ptr->sl_nextradio = nextradio_ptr;
	nextradio_ptr->index = 0;
	nextradio_ptr->state = SL_UNCHECKED;
	nextradio_ptr->caption = NULL;
	
	//initiate the other member in the ctrl_str
	ctrl_ptr->classid = WNDCLASS_SELECT;
	ctrl_ptr->wndid = parent;
	ctrl_ptr->sl_style = style;
	ctrl_ptr->sl_caption = caption;
	ctrl_ptr->sl_exdata = (struct sl_item *)exdata;
	//ctrl_ptr->sl_bk_saved = NULL;
	ctrl_ptr->sl_x = x;
	ctrl_ptr->sl_y = y;
	ctrl_ptr->sl_width = width;
	ctrl_ptr->sl_hight = hight;
	
	//initiate sl_curradio,sl_rownum in the ctrl_str
	//modified by xuanhui 2002/3/20
	exdata_ptr = ctrl_ptr->sl_exdata;
	for( i=0;exdata_ptr[i].caption != NULL;i++ )
	{
		if( exdata_ptr[i].state == SL_CHECKED )
		{
			curradio_ptr->state = exdata_ptr[i].state;
			curradio_ptr->caption = exdata_ptr[i].caption;
		}
	}
	ctrl_ptr->sl_rownum = i;
	rownum = ctrl_ptr->sl_rownum;
	
	//allocate memory for id_index array
	if( ( itemareaid = (U32 *)Lmalloc( rownum*sizeof( U32 ) ) ) == NULL )
	{
		Lfree(ctrl_ptr->sl_bk_saved);
		Lfree( curradio_ptr );
		Lfree( nextradio_ptr );
//		Lfree( exdata_ptr );		//modified by xuanhui 2002/4/4
		Lfree( ctrl_ptr );
		return ASIX_NO_MEM;
	}
	ctrl_ptr->id_index = itemareaid;
	
	/*-------- the following will draw the select control --------*/
	startx = x + 3;				//startx is the start x coordinate of the checkbox or radiobox
								//LM change the offset from 18 to 2 2001/07/06

	//modified by xuanhui 2002/4/4
	//starty = y + interval/2-SL_DISPLAY_TEXT_HEIGHT/2;		//starty is the start y coordiante of the checkbox or radiobox

	if ( width < (U16)(SL_DISTANCE+3*2+ENGLISH_CHAR_WIDTH) )
		return ASIX_ERROR;
	//draw the frame and its caption
	if (style & SLS_FRAME) 
	{	//modified by xuanhui 2002/3/28
		if (  caption != NULL )	//modified by xuanhui 2002/4/4
		{
			if ( width < (U16)(SL_FRAME_TEXT_X_INTERVAL*2+ENGLISH_CHAR_WIDTH+2) 
			|| hight < (U16)(SL_FRAME_TEXT_HEIGHT+ CHINESE_CHAR_HEIGHT+2) )
				return ASIX_ERROR;
				
			interval = (hight-SL_FRAME_TEXT_HEIGHT-3)/rownum;		//modified by xuanhui 2002/4/9
			y_frame = (U16)(y + SL_FRAME_TEXT_HEIGHT);				//modified by xuanhui 2002/4/9
			starty = y_frame + interval/2-SL_DIAMETER/2;			//starty is the start y coordiante of the checkbox or radiobox
			text_starty = y_frame + interval/2-CHINESE_CHAR_HEIGHT/2;		//starty is the start y coordiante of caption of the checkbox or radiobox
			
			if ( interval < CHINESE_CHAR_HEIGHT || interval < SL_DIAMETER  )	
				return ASIX_ERROR;
			
			//modified by xuanhui 2002/4/4	
			//draw3dframe( x,y,width,hight,style,caption );
			string_len = (U16)( width-SL_FRAME_TEXT_X_INTERVAL*2-2 )/ENGLISH_CHAR_WIDTH;
			scaption = Lcalloc( ( string_len+1)*sizeof(char) );	//allocate a buffer to store the string that can be displayed on the button surface
			if ( scaption == NULL ) 	
			{
				Lfree(ctrl_ptr->sl_bk_saved);
				Lfree( curradio_ptr );
				Lfree( nextradio_ptr );
				Lfree( ctrl_ptr );
				return ASIX_ERROR;
			}
			if( (U16)strlen(caption) > string_len  )
			{
				memcpy( scaption, caption, string_len - 1 );	//modified by xh 02/11/5
//				for( k=0;k<string_len;k++ )
//					scaption[k] = caption[k];
				scaption[string_len - 1] = '\0';
			}
			else
//				scaption = caption;
				memcpy( scaption, caption, string_len );		//modified by xh 02/11/5
//			draw3dframe( x,y_frame,width,hight,style,scaption );
//			ClearRec( pGC, GPC_WHITE, (U16)(x+3), y_frame, (U16)(width-4), (U16)(hight-SL_FRAME_TEXT_HEIGHT-3), GPC_REPLACE_STYLE);
		}else{
			interval = (hight-3*2)/rownum;		//modified by xuanhui 2002/4/9
			y_frame = (U16)(y+3); 
			starty = y_frame + interval/2-SL_DIAMETER/2;		//starty is the start y coordiante of the checkbox or radiobox
			text_starty = y_frame + interval/2-CHINESE_CHAR_HEIGHT/2;		//starty is the start y coordiante of caption of the checkbox or radiobox
			if ( interval < CHINESE_CHAR_HEIGHT || interval < SL_DIAMETER  )	
				return ASIX_ERROR;
//			draw3dframe( x,y_frame,width,hight,style,NULL );
//			ClearRec( pGC, GPC_WHITE, x+3, y+3, width-4, hight-4, GPC_REPLACE_STYLE);
		}
		draw3dframe( x,y,width,hight,style,scaption );
		Lfree( scaption );//modified by xh 02/11/5
	}
	else 		//modified by xuanhui 2002/3/28
	{
		interval = hight/rownum;		//modified by xuanhui 2002/4/9
		y_frame = y; 
		starty = y_frame + interval/2-SL_DIAMETER/2;		//starty is the start y coordiante of the checkbox or radiobox
		text_starty = y_frame + interval/2-CHINESE_CHAR_HEIGHT/2;		//starty is the start y coordiante of caption of the checkbox or radiobox
		
		if ( width < (U16)(SL_DISTANCE+2*2+ENGLISH_CHAR_WIDTH) 
		//modified by xuanhui 2002/4/4
//		|| interval < SL_DISPLAY_TEXT_HEIGHT 
//		|| SL_DIAMETER < CHINESE_CHAR_HEIGHT )	
		|| interval < CHINESE_CHAR_HEIGHT
		|| interval < SL_DIAMETER  )	
			return ASIX_ERROR;
//		ClearRec( pGC, GPC_WHITE, x, y, width, hight, GPC_REPLACE_STYLE);
	}
	
	//modified by xuanhui 2002/4/4	
	string_len = (U16)( width-3*2-SL_DISTANCE )/ENGLISH_CHAR_WIDTH;
	
	//draw the radio box or checkbox
	for( i=0; i < rownum; i++ )
	{
		//modified by xuanhui 2002/4/4
		scaption = Lcalloc( ( string_len+1)*sizeof(char) );	//allocate a buffer to store the string that can be displayed on the button surface
		if ( scaption == NULL ) 	
		{
			Lfree(ctrl_ptr->sl_bk_saved);
			Lfree( curradio_ptr );
			Lfree( nextradio_ptr );
			Lfree( ctrl_ptr );
			return ASIX_ERROR;
		}
		if( (U16)strlen(exdata_ptr[i].caption) > string_len  )
		{
			memcpy( scaption, exdata_ptr[i].caption, string_len - 1 );	//modified by xh 02/11/5
//			for( k=0;k<string_len;k++ )
//				scaption[k] = exdata_ptr[i].caption[k];
			scaption[string_len - 1] = '\0';	//modified by xh 02/11/5
		}
		else
//			scaption = exdata_ptr[i].caption;
			memcpy( scaption, exdata_ptr[i].caption, string_len );
			
		//draw checkbox with its style
		if( style&SLS_CHECKBOX )
		{
			//modified by xuanhui 2002/4/4
			//if( ActiveAreaEnable( &itemareaid[i],ICON_AREA,CONTINUOUS_MODE,startx,starty,startx+SL_DISTANCE+ENGLISH_CHAR_WIDTH*strlen(exdata_ptr->caption),starty+SL_DISPLAY_TEXT_HEIGHT, ctrl_ptr->wndid ) == PPSM_ERROR )
			if( ActiveAreaEnable( &itemareaid[i],ICON_AREA,CONTINUOUS_MODE,startx,y_frame,startx+SL_DISTANCE+ENGLISH_CHAR_WIDTH*strlen(scaption),(y_frame+interval-1), ctrl_ptr->wndid ) == PPSM_ERROR )
			{
				for( j = 0; j < i; j++ )
				{
					ActiveAreaDisable( itemareaid[j] );
				}
				
				//restor the screen 
				if (ctrl_ptr->sl_bk_saved != NULL ){
					//modified by xuanhui 2002/3/20
					//PutRec( pGC, ctrl_ptr->sl_bk_saved, x, y, width, hight,GPC_REPLACE_STYLE,0);
					if ( PutRec( pGC, (P_U16)ctrl_ptr->sl_bk_saved, (U16)(x+2), y, (U16)(width-4), hight,GPC_REPLACE_STYLE,0) != PPSM_OK )
						return ASIX_ERROR;
						
					Lfree(ctrl_ptr->sl_bk_saved);
				}
/*				 else 
					//modified by xuanhui 2002/3/20
					//ClearRec( pGC, GPC_WHITE, x, y, width, hight, GPC_REPLACE_STYLE);
					ClearRec( pGC, ColorTheme.form_backcolor, (U16)(x+2), y_frame, (U16)(width-4), (U16)(hight-(y-y_frame)-2), GPC_REPLACE_STYLE);
*/				
				//ClearRec( pGC, pGC, GPC_WHITE,x,y-8,width,hight+8,GPC_REPLACE_STYLE );
				//need put back the background
				//Lfree(ctrl_ptr->sl_bk_saved);
				
				Lfree( curradio_ptr );
				Lfree( nextradio_ptr );
				Lfree( ctrl_ptr );

⌨️ 快捷键说明

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