예제 #1
0
파일: LCUI_TextBox.c 프로젝트: dwdcth/LCUI
int TextBox_Text_Add(LCUI_Widget *widget, char *new_text)
/* 在光标处添加文本 */
{
	LCUI_TextLayer *layer;
	layer = TextBox_Get_TextLayer( widget );
	return TextLayer_Text_Add( layer, new_text );
}
예제 #2
0
파일: LCUI_TextBox.c 프로젝트: dwdcth/LCUI
int TextBox_Cut_Select_Text(LCUI_Widget *widget)
/* 剪切文本框内被选中的文本 */
{
	LCUI_TextLayer *layer;
	layer = TextBox_Get_TextLayer( widget );
	return TextLayer_Cut_Select_Text( layer );
}
예제 #3
0
파일: LCUI_TextBox.c 프로젝트: dwdcth/LCUI
void TextBox_Using_StyleTags(LCUI_Widget *widget, BOOL flag)
/* 指定文本框是否处理控制符 */
{
	LCUI_TextLayer *layer;
	layer = TextBox_Get_TextLayer( widget );
	TextLayer_Using_StyleTags( layer, flag );
}
예제 #4
0
파일: LCUI_TextBox.c 프로젝트: dwdcth/LCUI
int TextBox_Get_Select_Text( LCUI_Widget *widget, char *out_text )
/* 获取文本框内被选中的文本 */
{
	LCUI_TextLayer *layer;
	layer = TextBox_Get_TextLayer( widget );
	return TextLayer_Get_Select_Text( layer, out_text );
}
예제 #5
0
static void 
__TextBox_Text_Append(LCUI_Widget *widget, char *new_text)
/* 在文本末尾追加文本 */
{
	LCUI_TextLayer *layer;
	layer = TextBox_Get_TextLayer( widget );
	TextLayer_Text_Append( layer, new_text );
}
예제 #6
0
static int
TextBox_ScrollBar_Update_Pos( LCUI_Widget *widget )
/* 更新滚动条的位置 */
{
	static ScrollBar_Data scrollbar_data;
	static LCUI_Pos area_pos;
	static LCUI_Size layer_size, area_size;
	static LCUI_Widget *scrollbar[2];
	static LCUI_TextLayer *layer;
	
	area_size = Get_Container_Size( widget ); 
	scrollbar[0] = TextBox_Get_Scrollbar( widget, 0 );
	scrollbar[1] = TextBox_Get_Scrollbar( widget, 1 ); 
	if( scrollbar[0]->visible ) {
		area_size.w -= Get_Widget_Width( scrollbar[0] );
	}
	if( scrollbar[1]->visible ) {
		area_size.h -= Get_Widget_Height( scrollbar[1] );
	}
	
	if( area_size.h <= 0 || area_size.w <= 0 ) {
		return -1;
	}
	
	layer = TextBox_Get_TextLayer( widget );
	if( !layer->enable_multiline ) {
		return 1;
	}
	layer_size = TextLayer_Get_Size( layer );
	if( layer_size.h <= 0 || layer_size.w <= 0 ) {
		return -2;
	}
	area_pos = TextBox_ViewArea_Get_Pos( widget );
	ScrollBar_Set_MaxNum( scrollbar[0], layer_size.h - area_size.h );
	
	if( area_pos.y + area_size.h > layer_size.h ) {
		area_pos.y = layer_size.h - area_size.h;
	}
	if( area_pos.x + area_size.w > layer_size.w ) {
		area_pos.x = layer_size.w - area_size.w;
	}
	if( area_pos.y < 0 ) {
		area_pos.y = 0;
	}
	if( area_pos.x < 0 ) {
		area_pos.x = 0;
	}
	ScrollBar_Set_CurrentNum( scrollbar[0], area_pos.y ); 
	scrollbar_data = ScrollBar_Get_Data( scrollbar[0] );
	TextBox_VertScroll_TextLayer( scrollbar_data, widget );
	
	ScrollBar_Set_MaxNum( scrollbar[1], layer_size.w - area_size.w );
	ScrollBar_Set_CurrentNum( scrollbar[1], area_pos.x );
	scrollbar_data = ScrollBar_Get_Data( scrollbar[1] );
	TextBox_HoriScroll_TextLayer( scrollbar_data, widget );
	return 0;
}
예제 #7
0
static void 
__TextBox_Text_Add(LCUI_Widget *widget, char *new_text)
/* 在光标处添加文本 */
{
	LCUI_Pos cur_pos;
	LCUI_TextLayer *layer;
	
	layer = TextBox_Get_TextLayer( widget );
	TextLayer_Text_Add( layer, new_text );
	cur_pos = TextLayer_Get_Cursor_Pos( layer );
	TextBox_Cursor_Move( widget, cur_pos );
}
예제 #8
0
LCUI_Pos
TextBox_ViewArea_Get_Pos( LCUI_Widget *widget )
/* 获取文本显示区域的位置 */
{
	LCUI_Pos pos;
	LCUI_TextLayer *layer;
	
	layer = TextBox_Get_TextLayer( widget );
	pos = layer->offset_pos;
	pos.x = -pos.x;
	pos.y = -pos.y;
	return pos;
}
예제 #9
0
static void 
TextBox_TextLayer_Click( LCUI_Widget *widget, LCUI_DragEvent *event )
{
	static LCUI_Pos pos;
	static LCUI_TextBox *tb;
	static LCUI_TextLayer *layer;
	
	/* 保存当前已获得焦点的部件 */
	active_textbox = widget;
	layer = TextBox_Get_TextLayer( widget );
	tb = Get_Widget_PrivData( active_textbox );
	/* 全局坐标转换成相对坐标 */
	pos = GlobalPos_ConvTo_RelativePos( tb->text, event->cursor_pos );
	//printf("pos: %d,%d\n", pos.x, pos.y);
	/* 根据像素坐标,设定文本光标的位置 */
	TextLayer_Set_Cursor_PixelPos( layer, pos );
	/* 获取光标的当前位置 */
	pos = TextLayer_Get_Cursor_Pos( layer );
	/* 主要是调用该函数更新当前文本浏览区域,以使光标处于显示区域内 */
	TextBox_Cursor_Move( widget, pos );
}
예제 #10
0
int
TextBox_ViewArea_Update( LCUI_Widget *widget )
/* 更新文本框的文本显示区域 */
{
	static int cursor_h;
	static ScrollBar_Data scrollbar_data;
	static LCUI_Pos cursor_pos, area_pos;
	static LCUI_Size layer_size, area_size;
	static LCUI_Widget *scrollbar[2];
	static LCUI_TextLayer *layer;
	//printf("TextBox_ViewArea_Update(): enter\n");
	/* 获取显示区域的尺寸 */
	area_size = Get_Container_Size( widget );
	/* 获取滚动条 */
	scrollbar[0] = TextBox_Get_Scrollbar( widget, 0 );
	scrollbar[1] = TextBox_Get_Scrollbar( widget, 1 );
	/* 如果滚动条可见,那么区域尺寸就需要减去滚动条占用的尺寸 */
	if( scrollbar[0]->visible ) {
		area_size.w -= Get_Widget_Width( scrollbar[0] );
	}
	if( scrollbar[1]->visible ) {
		area_size.h -= Get_Widget_Height( scrollbar[1] );
	}
	
	if( area_size.h <= 0 || area_size.w <= 0 ) {
		return -1;
	}
	
	layer = TextBox_Get_TextLayer( widget );
	layer_size = TextLayer_Get_Size( layer );
	if( layer_size.h <= 0 || layer_size.w <= 0 ) {
		return -2;
	}
	/* 获取显示区域的位置 */
	area_pos = TextBox_ViewArea_Get_Pos( widget );
	/* 获取光标的坐标 */
	cursor_pos = TextLayer_Get_Cursor_FixedPixelPos( layer );
	/* 获取当前行的最大高度作为光标的高度 */
	cursor_h = TextLayer_CurRow_Get_MaxHeight( layer );
	
	/* 设定滚动条的数据中的最大值 */
	ScrollBar_Set_MaxNum( scrollbar[0], layer_size.h - area_size.h );
	
	DEBUG_MSG("cursor_pos: %d,%d\n", cursor_pos.x, cursor_pos.y);
	DEBUG_MSG("area_rect: %d,%d,%d,%d\n", 
		area_pos.x, area_pos.y,area_size.w, area_size.h );
	DEBUG_MSG("layer_size: %d,%d\n", layer_size.w, layer_size.h);
	
	/* 检测光标Y轴坐标是否超出显示区域的范围 */
	if( cursor_pos.y < area_pos.y ) {
		area_pos.y = cursor_pos.y;
	}
	if(cursor_pos.y + cursor_h > area_pos.y + area_size.h ) {
		area_pos.y = cursor_pos.y + cursor_h - area_size.h;
	}
	/* 如果显示区域在Y轴上超过文本图层的范围 */
	if( area_pos.y + area_size.h > layer_size.h ) {
		area_pos.y = layer_size.h - area_size.h;
	}
	if( area_pos.y < 0 ) {
		area_pos.y = 0;
	}
	/* 设定滚动条的数据中的当前值 */
	ScrollBar_Set_CurrentNum( scrollbar[0], area_pos.y );
	/* 获取滚动条的数据,供滚动文本层利用 */
	scrollbar_data = ScrollBar_Get_Data( scrollbar[0] );
	
	//printf("scrollbar_data: size: %d / %d, num: %d / %d\n", 
	//scrollbar_data.current_size, scrollbar_data.max_size, 
	//scrollbar_data.current_num, scrollbar_data.max_num);
	/* 根据数据,滚动文本图层至响应的位置,也就是移动文本显示区域 */
	TextBox_VertScroll_TextLayer( scrollbar_data, widget );
	
	/* 设定滚动条的数据中的最大值 */
	ScrollBar_Set_MaxNum( scrollbar[1], layer_size.w - area_size.w );
	
	if( cursor_pos.x < area_pos.x ) {
		area_pos.x = cursor_pos.x;
	}
	if(cursor_pos.x +5 > area_pos.x + area_size.w ) {
		area_pos.x = cursor_pos.x+5 - area_size.w;
	}
	if( area_pos.x + area_size.w > layer_size.w ) {
		area_pos.x = layer_size.w - area_size.w;
	}
	if( area_pos.x < 0 ) {
		area_pos.x = 0;
	}
	/* 设定滚动条的数据中的当前值 */
	ScrollBar_Set_CurrentNum( scrollbar[1], area_pos.x );
	/* 获取滚动条的数据,供滚动文本层利用 */
	scrollbar_data = ScrollBar_Get_Data( scrollbar[1] );
	
	//printf("scrollbar_data: size: %d / %d, num: %d / %d\n", 
	//scrollbar_data.current_size, scrollbar_data.max_size, 
	//scrollbar_data.current_num, scrollbar_data.max_num);
	TextBox_HoriScroll_TextLayer( scrollbar_data, widget );
	//printf("TextBox_ViewArea_Update(): quit\n");
	return 0;
}
예제 #11
0
static void 
TextBox_ScrollBar_Update_Size( LCUI_Widget *widget )
/* 更新滚动条的长度 */
{
	int tmp;
	char size_str[15];
	LCUI_Size area_size, layer_size;
	LCUI_Widget *scrollbar[2], *label;
	LCUI_TextLayer *layer;
	
	label = TextBox_Get_Label( widget );
	/* 获取文本图层 */
	layer = TextBox_Get_TextLayer( widget );
	
	/* 获取文本图层和文本框区域的尺寸 */
	layer_size = TextLayer_Get_Size( layer );
	area_size = Get_Container_Size( widget );
	/* 获取纵向和横向滚动条 */
	scrollbar[0] = TextBox_Get_Scrollbar( widget, 0 );
	scrollbar[1] = TextBox_Get_Scrollbar( widget, 1 );
	
	/* 如果文本图层高度超过显示区域 */
	if( layer->enable_multiline && area_size.h > 0 
	  && layer_size.h > area_size.h ) {
		tmp = area_size.w - Get_Widget_Width( scrollbar[0] );
		snprintf( size_str, sizeof(size_str)-1, "%dpx", tmp );
		Set_Widget_Size( label, size_str, NULL );
		
		/* 修改滚动条中记录的最大值和当前值,让滚动条在更新后有相应的长度 */
		ScrollBar_Set_MaxSize( scrollbar[0], layer_size.h );
		ScrollBar_Set_CurrentSize( scrollbar[0], area_size.h );
		Show_Widget( scrollbar[0] );
		/* 如果横向滚动条可见 */
		if( scrollbar[1]->visible ) {
			tmp = area_size.h - Get_Widget_Height( scrollbar[1] );
			snprintf( size_str, sizeof(size_str)-1, "%dpx", tmp );
			Set_Widget_Size( scrollbar[0], NULL, size_str );
		} else {
			Set_Widget_Size( scrollbar[0], NULL, "100%" );
		}
	} else {
		/* 不需要显示滚动条 */
		Hide_Widget( scrollbar[0] );
		Set_Widget_Size( label, "100%", NULL );
	}
	/* 和上面的处理基本一样,这个是处理横向滚动条 */
	if( layer->enable_multiline &&
	 area_size.w > 0 && layer_size.w > area_size.w ) {
		tmp = area_size.h - Get_Widget_Height( scrollbar[1] );
		snprintf( size_str, sizeof(size_str)-1, "%dpx", tmp );
		Set_Widget_Size( label, NULL, size_str );
		
		ScrollBar_Set_MaxSize( scrollbar[1], layer_size.w );
		ScrollBar_Set_CurrentSize( scrollbar[1], area_size.w );
		Show_Widget( scrollbar[1] );
		
		if( scrollbar[0]->visible ) {
			tmp = area_size.w - Get_Widget_Width( scrollbar[0] );
			snprintf( size_str, sizeof(size_str)-1, "%dpx", tmp );
			Set_Widget_Size( scrollbar[1], size_str, NULL );
		} else {
			Set_Widget_Size( scrollbar[1], "100%", NULL );
		}
	} else {
		Set_Widget_Size( label, NULL, "100%" );
		Hide_Widget( scrollbar[1] );
	}
}
예제 #12
0
static void
TextBox_Input( LCUI_Widget *widget, LCUI_Key *key )
{
	static char buff[5];
	static int cols, flag, rows;
	static LCUI_Pos cur_pos;
	static LCUI_TextLayer *layer;
	static LCUI_TextBox *textbox;
	
	//printf("you input %d\n", key->code);
	layer = TextBox_Get_TextLayer( widget );
	textbox = Get_Widget_PrivData( widget );
	cur_pos = TextLayer_Get_Cursor_Pos( layer );
	cols = TextLayer_Get_RowLen( layer, cur_pos.y );
	rows = TextLayer_Get_Rows( layer ); 
	switch( key->code ) {
	    case KEY_HOMEPAGE: //home键移动光标至行首
		cur_pos.x = 0;
		goto mv_cur_pos;
		
	    case KEY_END: //end键移动光标至行尾
		cur_pos.x = cols;
		goto mv_cur_pos;
		
	    case KEY_LEFT:
		if( cur_pos.x > 0 ) {
			cur_pos.x--;
		} else if( cur_pos.y > 0 ) {
			cur_pos.y--;
			cur_pos.x = TextLayer_Get_RowLen( layer, cur_pos.y );
		}
		goto mv_cur_pos;
		
	    case KEY_RIGHT:
		if( cur_pos.x < cols ) {
			cur_pos.x++;
		} else if( cur_pos.y < rows-1 ) {
			cur_pos.y++;
			cur_pos.x = 0;
		}
		goto mv_cur_pos;
		
	    case KEY_UP:
		if( cur_pos.y > 0 ) {
			cur_pos.y--;
		}
		goto mv_cur_pos;
		
	    case KEY_DOWN:
		if( cur_pos.y < rows-1 ) {
			cur_pos.y++;
		}
		/* 移动光标位置 */
mv_cur_pos:;
		TextBox_Cursor_Move( widget,cur_pos );
		break;
		
	    case KEY_BACKSPACE: //删除光标左边的字符
		TextBox_Text_Backspace( widget, 1 );
		break;
		
	    case KEY_DELETE:
		//删除光标右边的字符
		
		break;
		
	    default:;
		if( textbox->limit_mode == 0 ) {
			flag = 1;
		} else {
			flag = 0;
		}
		/* 处理文本框的字符输入限制 */
		if( Check_Option( textbox->limit_mode, ONLY_0_TO_9 ) ) {
			if( key->code >= '0' && key->code <= '9' ) {
				++flag;
			}
		}
		if( Check_Option( textbox->limit_mode, ONLY_a_TO_z ) ) {
			if( key->code >= 'a' && key->code <= 'z' ) {
				++flag;
			}
		}
		if( Check_Option( textbox->limit_mode, ONLY_A_TO_Z ) ) {
			if( key->code >= 'A' && key->code <= 'Z' ) {
				++flag;
			}
		}
		if( Check_Option( textbox->limit_mode, ONLY_UNDERLINE ) ) {
			if( key->code == '_' ) {
				++flag;
			}
		}
		//_DEBUG_MSG("input char: %c, %d\n", key->code, flag);
		/* 如果该ASCII码代表的字符是可见的 */
		if( flag == 1 && (key->code == 10 || 
			(key->code > 31 && key->code < 126)) ) {
			//wchar_t *text;
			buff[0] = key->code;
			buff[1] = 0;
			TextBox_Text_Add( widget, buff);
			//text = TextLayer_Get_Text( layer );
			//free( text );
		}
		
	    //向文本框中添加字符
		break;
	}
}