TextBox_Cursor_Update( LCUI_Widget *widget ) /* 更新文本框的光标,返回该光标的像素坐标 */ { LCUI_Pos pixel_pos; LCUI_Widget *cursor; LCUI_TextLayer *layer; LCUI_TextBox *textbox; LCUI_Size size; textbox = Widget_GetPrivData( widget ); layer = TextBox_GetTextLayer( widget ); /* 如果显示了占位符,那么就复位光标的位置 */ if( textbox->show_placeholder ) { TextLayer_Cursor_SetPos( layer, Pos(0,0) ); } cursor = TextBox_GetCursor( widget ); size.w = 1; size.h = TextLayer_CurRow_GetMaxHeight( layer ); pixel_pos = TextLayer_Cursor_GetPixelPos( layer ); Widget_Move( cursor, pixel_pos ); Widget_Resize( cursor, size ); /* 若当前文本框处于焦点状态,则让光标在更新时显示 */ if( active_textbox == widget ) { Widget_Show( cursor ); } return pixel_pos; }
TextLayer_Text_Backspace( LCUI_TextLayer *layer, int n ) /* 删除光标左边处n个字符 */ { int i, row_len; LCUI_Pos char_pos; Text_RowData *row_ptr; if( layer->read_only ) { return -1; } if( n <= 0 ) { return -2; } /* 计算当前光标所在字的位置 */ char_pos = TextLayer_Cursor_GetPos( layer ); DEBUG_MSG2( "before: %d,%d\n", char_pos.x, char_pos.y ); for( i=n; char_pos.y>=0; --char_pos.y ) { row_ptr = Queue_Get( &layer->rows_data, char_pos.y ); row_len = Queue_GetTotal( &row_ptr->string ); if( char_pos.x == -1 ) { char_pos.x = row_len; } for( ; char_pos.x>=0 && i>0; --char_pos.x,--i ); if( i<=0 && char_pos.x >= 0 ) { break; } } DEBUG_MSG2( "after: %d,%d\n", char_pos.x, char_pos.y ); if( i>0 ) { n -= i; } DEBUG_MSG2("start_pos: %d,%d, len: %d\n", char_pos.x, char_pos.y, n); /* 开始删除文字 */ _TextLayer_Text_Delete( layer, char_pos, n ); /* 删除完后,需要将光标向左移动一个位置 */ TextLayer_Cursor_SetPos( layer, char_pos ); return 0; }
TextBox_Cursor_Move( LCUI_Widget *widget, LCUI_Pos new_pos ) /* 移动文本框内的光标 */ { LCUI_Pos pixel_pos; LCUI_Widget *cursor; LCUI_TextLayer *layer; LCUI_Size size; layer = TextBox_GetTextLayer( widget ); cursor = TextBox_GetCursor( widget ); size.w = 1; size.h = TextLayer_CurRow_GetMaxHeight( layer ); pixel_pos = TextLayer_Cursor_SetPos( layer, new_pos ); Widget_Move( cursor, pixel_pos ); Widget_Resize( cursor, size ); if( active_textbox == widget ) { Widget_Show( cursor ); } /* 更新文本显示区域 */ TextBox_ViewArea_Update( widget ); return pixel_pos; }