89 if(value) { |
89 if(value) { |
90 value->get = ui_textarea_get; |
90 value->get = ui_textarea_get; |
91 value->set = ui_textarea_set; |
91 value->set = ui_textarea_set; |
92 value->getsubstr = ui_textarea_getsubstr; |
92 value->getsubstr = ui_textarea_getsubstr; |
93 value->insert = ui_textarea_insert; |
93 value->insert = ui_textarea_insert; |
|
94 value->position = ui_textarea_position; |
|
95 value->selection = ui_textarea_selection; |
94 value->value = NULL; |
96 value->value = NULL; |
95 value->obj = textview; |
97 value->obj = textview; |
96 |
98 |
97 TextChangeMgr *delegate = [[TextChangeMgr alloc]initWithValue:value context:obj->ctx]; |
99 TextChangeMgr *delegate = [[TextChangeMgr alloc]initWithValue:value context:obj->ctx]; |
98 [textview setDelegate:delegate]; |
100 [textview setDelegate:delegate]; |
152 |
154 |
153 void ui_textarea_insert(UiText *text, int pos, char *str) { |
155 void ui_textarea_insert(UiText *text, int pos, char *str) { |
154 if(text->value) { |
156 if(text->value) { |
155 free(text->value); |
157 free(text->value); |
156 } |
158 } |
157 if(text->value) { |
|
158 free(text->value); |
|
159 } |
|
160 NSTextView *textview = (NSTextView*)text->obj; |
159 NSTextView *textview = (NSTextView*)text->obj; |
161 NSString *s = [[NSString alloc]initWithUTF8String:str]; |
160 NSString *s = [[NSString alloc]initWithUTF8String:str]; |
162 NSAttributedString *as = [[NSAttributedString alloc]initWithString:s]; |
161 NSAttributedString *as = [[NSAttributedString alloc]initWithString:s]; |
163 [[textview textStorage] insertAttributedString:as atIndex: pos]; |
162 [[textview textStorage] insertAttributedString:as atIndex: pos]; |
164 text->value = NULL; |
163 text->value = NULL; |
|
164 } |
|
165 |
|
166 int ui_textarea_position(UiText *text) { |
|
167 return [[[(NSTextView*)text->obj selectedRanges] objectAtIndex:0] rangeValue].location; |
|
168 } |
|
169 |
|
170 void ui_textarea_selection(UiText *text, int *begin, int *end) { |
|
171 NSRange range = [[[(NSTextView*)text->obj selectedRanges] objectAtIndex:0] rangeValue]; |
|
172 *begin = range.location; |
|
173 *end = range.location + range.length; |
165 } |
174 } |
166 |
175 |
167 void ui_text_undo(UiText *text) { |
176 void ui_text_undo(UiText *text) { |
168 [(NSUndoManager*)text->undomgr undo]; |
177 [(NSUndoManager*)text->undomgr undo]; |
169 } |
178 } |