@@ -64,18 +64,19 @@ typedef struct LCUI_TextEditRec_ {
64
64
LCUI_TextLayer layer_mask ; /**< 屏蔽后的文本层 */
65
65
LCUI_TextLayer layer_placeholder ; /**< 占位符的文本层 */
66
66
LCUI_TextLayer layer ; /**< 当前使用的文本层 */
67
- LCUI_Widget scrollbars [2 ]; /**< 两个滚动条 */
68
- LCUI_Widget caret ; /**< 文本插入符 */
69
- LCUI_BOOL is_read_only ; /**< 是否只读 */
70
- LCUI_BOOL is_multiline_mode ; /**< 是否为多行模式 */
71
- LCUI_BOOL is_placeholder_shown ; /**< 是否已经显示占位符 */
72
- wchar_t * allow_input_char ; /**< 允许输入的字符 */
73
- wchar_t password_char ; /**< 屏蔽符的副本 */
74
- size_t text_block_size ; /**< 块大小 */
75
- LinkedList text_blocks ; /**< 文本块缓冲区 */
76
- LinkedList text_tags ; /**< 当前处理的标签列表 */
77
- LCUI_BOOL tasks [TASK_TOTAL ]; /**< 待处理的任务 */
78
- LCUI_Mutex mutex ; /**< 互斥锁 */
67
+ LCUI_ObjectWatcher value_watcher ;
68
+ LCUI_Widget scrollbars [2 ]; /**< 两个滚动条 */
69
+ LCUI_Widget caret ; /**< 文本插入符 */
70
+ LCUI_BOOL is_read_only ; /**< 是否只读 */
71
+ LCUI_BOOL is_multiline_mode ; /**< 是否为多行模式 */
72
+ LCUI_BOOL is_placeholder_shown ; /**< 是否已经显示占位符 */
73
+ wchar_t * allow_input_char ; /**< 允许输入的字符 */
74
+ wchar_t password_char ; /**< 屏蔽符的副本 */
75
+ size_t text_block_size ; /**< 块大小 */
76
+ LinkedList text_blocks ; /**< 文本块缓冲区 */
77
+ LinkedList text_tags ; /**< 当前处理的标签列表 */
78
+ LCUI_BOOL tasks [TASK_TOTAL ]; /**< 待处理的任务 */
79
+ LCUI_Mutex mutex ; /**< 互斥锁 */
79
80
} LCUI_TextEditRec , * LCUI_TextEdit ;
80
81
81
82
typedef enum {
@@ -886,6 +887,7 @@ static void TextEdit_OnInit(LCUI_Widget w)
886
887
edit -> layer_source = TextLayer_New ();
887
888
edit -> layer_placeholder = TextLayer_New ();
888
889
edit -> layer = edit -> layer_source ;
890
+ edit -> value_watcher = NULL ;
889
891
edit -> text_block_size = TEXT_BLOCK_SIZE ;
890
892
edit -> caret = LCUIWidget_New ("textcaret" );
891
893
w -> computed_style .focusable = TRUE;
@@ -920,6 +922,10 @@ static void TextEdit_OnDestroy(LCUI_Widget widget)
920
922
TextLayer_Destroy (edit -> layer_mask );
921
923
CSSFontStyle_Destroy (& edit -> style );
922
924
TextBlocks_Clear (& edit -> text_blocks );
925
+ if (edit -> value_watcher ) {
926
+ ObjectWatcher_Delete (edit -> value_watcher );
927
+ edit -> value_watcher = NULL ;
928
+ }
923
929
}
924
930
925
931
static void TextEdit_OnPaint (LCUI_Widget w , LCUI_PaintContext paint ,
@@ -973,6 +979,36 @@ static void TextEdit_OnUpdate(LCUI_Widget w)
973
979
TextStyle_Destroy (& ts );
974
980
}
975
981
982
+ static void TextEdit_OnValueChanged (LCUI_Object value , void * arg )
983
+ {
984
+ LCUI_Widget w = arg ;
985
+
986
+ if (value -> type == LCUI_StringObject ) {
987
+ TextEdit_SetText (w , value -> value .string );
988
+ } else if (value -> type == LCUI_WStringObject ) {
989
+ TextEdit_SetTextW (w , value -> value .wstring );
990
+ }
991
+ }
992
+
993
+ void TextEdit_BindProperty (LCUI_Widget w , const char * name , LCUI_Object value )
994
+ {
995
+ LCUI_TextEdit edit = Widget_GetData (w , self .prototype );
996
+
997
+ if (strcmp (name , "value" ) == 0 ) {
998
+ if (edit -> value_watcher ) {
999
+ ObjectWatcher_Delete (edit -> value_watcher );
1000
+ edit -> value_watcher = NULL ;
1001
+ }
1002
+ if (value ) {
1003
+ edit -> value_watcher =
1004
+ Object_Watch (value , TextEdit_OnValueChanged , w );
1005
+ TextEdit_OnValueChanged (value , w );
1006
+ } else {
1007
+ TextEdit_ClearText (w );
1008
+ }
1009
+ }
1010
+ }
1011
+
976
1012
void LCUIWidget_AddTextEdit (void )
977
1013
{
978
1014
self .prototype = LCUIWidget_NewPrototype ("textedit" , NULL );
@@ -981,6 +1017,7 @@ void LCUIWidget_AddTextEdit(void)
981
1017
self .prototype -> destroy = TextEdit_OnDestroy ;
982
1018
self .prototype -> settext = TextEdit_OnParseText ;
983
1019
self .prototype -> setattr = TextEdit_SetAttr ;
1020
+ self .prototype -> bindprop = TextEdit_BindProperty ;
984
1021
self .prototype -> autosize = TextEdit_AutoSize ;
985
1022
self .prototype -> runtask = TextEdit_OnTask ;
986
1023
self .prototype -> update = TextEdit_OnUpdate ;
0 commit comments