コード例 #1
0
static void 
TextBox_TextLayer_Click( LCUI_Widget *widget, LCUI_WidgetEvent *event )
{
	static LCUI_Pos pos;
	static LCUI_TextBox *tb;
	static LCUI_TextLayer *layer;
	
	/* 保存当前已获得焦点的部件 */
	active_textbox = widget;
	layer = TextBox_GetTextLayer( widget );
	tb = Widget_GetPrivData( active_textbox );
	if( tb->show_placeholder ) {
		pos.x = pos.y = 0;
	} else {
		/* 全局坐标转换成相对坐标 */
		pos = GlobalPos_ConvTo_RelativePos( tb->text, event->drag.cursor_pos );
	}
	//printf("pos: %d,%d\n", pos.x, pos.y);
	/* 根据像素坐标,设定文本光标的位置 */
	TextLayer_Cursor_SetPixelPos( layer, pos );
	/* 获取光标的当前位置 */
	pos = TextLayer_Cursor_GetPos( layer );
	/* 主要是调用该函数更新当前文本浏览区域,以使光标处于显示区域内 */
	TextBox_Cursor_Move( widget, pos );
}
コード例 #2
0
/* 在光标处添加文本 */
static void 
__TextBox_Text_Add( LCUI_Widget *widget, wchar_t *new_text )
{
	LCUI_Pos cur_pos;
	LCUI_TextLayer *layer;
	
	layer = TextBox_GetTextLayer( widget );
	TextLayer_Text_AddW( layer, new_text );
	cur_pos = TextLayer_Cursor_GetPos( layer );
	TextBox_Cursor_Move( widget, cur_pos );
}
コード例 #3
0
ファイル: LCUI_TextBox.c プロジェクト: soar-penguin/LCUI
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 );
}
コード例 #4
0
TextBox_Text_Backspace(LCUI_Widget *widget, int n)
/* 删除光标左边处n个字符 */
{
	LCUI_Pos cur_pos;
	LCUI_TextLayer *layer;
	
	layer = TextBox_GetTextLayer( widget );
	TextLayer_Text_Backspace( layer, n );
	cur_pos = TextLayer_Cursor_GetPos( layer );
	TextBox_Cursor_Move( widget, cur_pos );
	Widget_Update( widget );
	return 0;
}
コード例 #5
0
static void
TextBox_Input( LCUI_Widget *widget, LCUI_WidgetEvent *event )
{
	static char buff[5];
	static int cols, flag, rows;
	static LCUI_Pos cur_pos;
	static LCUI_TextLayer *layer;
	static LCUI_TextBox *textbox;
	
	//_DEBUG_MSG("you input: %d\n", event->key.key_code);
	layer = TextBox_GetTextLayer( widget );
	textbox = Widget_GetPrivData( widget );
	cur_pos = TextLayer_Cursor_GetPos( layer );
	cols = TextLayer_GetRowLen( layer, cur_pos.y );
	rows = TextLayer_GetRows( layer ); 
	switch( event->key.key_code ) {
	    case LCUIKEY_HOMEPAGE: //home键移动光标至行首
		cur_pos.x = 0;
		goto mv_cur_pos;
		
	    case LCUIKEY_END: //end键移动光标至行尾
		cur_pos.x = cols;
		goto mv_cur_pos;
		
	    case LCUIKEY_LEFT:
		if( cur_pos.x > 0 ) {
			cur_pos.x--;
		} else if( cur_pos.y > 0 ) {
			cur_pos.y--;
			cur_pos.x = TextLayer_GetRowLen( layer, cur_pos.y );
		}
		goto mv_cur_pos;
		
	    case LCUIKEY_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 LCUIKEY_UP:
		if( cur_pos.y > 0 ) {
			cur_pos.y--;
		}
		goto mv_cur_pos;
		
	    case LCUIKEY_DOWN:
		if( cur_pos.y < rows-1 ) {
			cur_pos.y++;
		}
mv_cur_pos:;
		/* 移动光标位置 */
		if( textbox->show_placeholder ) {
			cur_pos.x = cur_pos.y = 0;
		}
		TextBox_Cursor_Move( widget,cur_pos );
		break;
		
	    case LCUIKEY_BACKSPACE: //删除光标左边的字符
		TextBox_Text_Backspace( widget, 1 );
		break;
		
	    case LCUIKEY_DELETE:
		//删除光标右边的字符
		
		break;
		
	    default:;
		if( textbox->limit_mode == 0 ) {
			flag = 1;
		} else {
			flag = 0;
		}
		/* 处理文本框的字符输入限制 */
		if( Check_Option( textbox->limit_mode, ONLY_0_TO_9 ) ) {
			if( event->key.key_code >= '0'
			 && event->key.key_code <= '9' ) {
				++flag;
			}
		}
		if( Check_Option( textbox->limit_mode, ONLY_a_TO_z ) ) {
			if( event->key.key_code >= 'a' 
			 && event->key.key_code <= 'z' ) {
				++flag;
			}
		}
		if( Check_Option( textbox->limit_mode, ONLY_A_TO_Z ) ) {
			if( event->key.key_code >= 'A'
			 && event->key.key_code <= 'Z' ) {
				++flag;
			}
		}
		if( Check_Option( textbox->limit_mode, ONLY_UNDERLINE ) ) {
			if( event->key.key_code == '_' ) {
				++flag;
			}
		}
		//_DEBUG_MSG("input char: %c, %d\n", event->key.key_code, flag);
		/* 如果该ASCII码代表的字符是可见的 */
		if( flag == 1 && (event->key.key_code == 10 || 
		 (event->key.key_code > 31
		  && event->key.key_code < 126)) ) {
			//wchar_t *text;
			buff[0] = event->key.key_code;
			buff[1] = 0;
			TextBox_Text_Add( widget, buff);
			//text = TextLayer_Get_Text( layer );
			//free( text );
		}
		
	    //向文本框中添加字符
		break;
	}
}