99 // bind value |
99 // bind value |
100 UiText *value = var->value; |
100 UiText *value = var->value; |
101 if(value) { |
101 if(value) { |
102 GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_area)); |
102 GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_area)); |
103 |
103 |
104 if(value->value) { |
104 if(value->value.ptr) { |
105 gtk_text_buffer_set_text(buf, value->value, -1); |
105 gtk_text_buffer_set_text(buf, value->value.ptr, -1); |
106 // TODO: free value |
106 value->value.free(value->value.ptr); |
107 } |
107 } |
108 |
108 |
109 value->get = ui_textarea_get; |
109 value->get = ui_textarea_get; |
110 value->set = ui_textarea_set; |
110 value->set = ui_textarea_set; |
111 value->getsubstr = ui_textarea_getsubstr; |
111 value->getsubstr = ui_textarea_getsubstr; |
113 value->setposition = ui_textarea_setposition; |
113 value->setposition = ui_textarea_setposition; |
114 value->position = ui_textarea_position; |
114 value->position = ui_textarea_position; |
115 value->selection = ui_textarea_selection; |
115 value->selection = ui_textarea_selection; |
116 value->length = ui_textarea_length; |
116 value->length = ui_textarea_length; |
117 value->remove = ui_textarea_remove; |
117 value->remove = ui_textarea_remove; |
118 value->value = NULL; |
118 value->value.ptr = NULL; |
|
119 value->value.free = NULL; |
119 value->obj = buf; |
120 value->obj = buf; |
120 if(!value->undomgr) { |
121 if(!value->undomgr) { |
121 value->undomgr = ui_create_undomgr(); |
122 value->undomgr = ui_create_undomgr(); |
122 } |
123 } |
123 |
124 |
167 } |
168 } |
168 return NULL; |
169 return NULL; |
169 } |
170 } |
170 |
171 |
171 char* ui_textarea_get(UiText *text) { |
172 char* ui_textarea_get(UiText *text) { |
172 if(text->value) { |
173 if(text->value.ptr) { |
173 g_free(text->value); |
174 text->value.free(text->value.ptr); |
174 } |
175 } |
175 GtkTextBuffer *buf = text->obj; |
176 GtkTextBuffer *buf = text->obj; |
176 GtkTextIter start; |
177 GtkTextIter start; |
177 GtkTextIter end; |
178 GtkTextIter end; |
178 gtk_text_buffer_get_bounds(buf, &start, &end); |
179 gtk_text_buffer_get_bounds(buf, &start, &end); |
179 char *str = gtk_text_buffer_get_text(buf, &start, &end, FALSE); |
180 char *str = gtk_text_buffer_get_text(buf, &start, &end, FALSE); |
180 text->value = str; |
181 text->value.ptr = g_strdup(str); |
|
182 text->value.free = (ui_freefunc)g_free; |
181 return str; |
183 return str; |
182 } |
184 } |
183 |
185 |
184 void ui_textarea_set(UiText *text, char *str) { |
186 void ui_textarea_set(UiText *text, char *str) { |
185 gtk_text_buffer_set_text((GtkTextBuffer*)text->obj, str, -1); |
187 gtk_text_buffer_set_text((GtkTextBuffer*)text->obj, str, -1); |
186 if(text->value) { |
188 if(text->value.ptr) { |
187 g_free(text->value); |
189 text->value.free(text->value.ptr); |
188 } |
190 } |
189 text->value = NULL; |
191 text->value.ptr = NULL; |
|
192 text->value.free = NULL; |
190 } |
193 } |
191 |
194 |
192 char* ui_textarea_getsubstr(UiText *text, int begin, int end) { |
195 char* ui_textarea_getsubstr(UiText *text, int begin, int end) { |
193 if(text->value) { |
196 if(text->value.ptr) { |
194 g_free(text->value); |
197 text->value.free(text->value.ptr); |
195 } |
198 } |
196 GtkTextBuffer *buf = text->obj; |
199 GtkTextBuffer *buf = text->obj; |
197 GtkTextIter ib; |
200 GtkTextIter ib; |
198 GtkTextIter ie; |
201 GtkTextIter ie; |
199 gtk_text_buffer_get_iter_at_offset(text->obj, &ib, begin); |
202 gtk_text_buffer_get_iter_at_offset(text->obj, &ib, begin); |
200 gtk_text_buffer_get_iter_at_offset(text->obj, &ie, end); |
203 gtk_text_buffer_get_iter_at_offset(text->obj, &ie, end); |
201 char *str = gtk_text_buffer_get_text(buf, &ib, &ie, FALSE); |
204 char *str = gtk_text_buffer_get_text(buf, &ib, &ie, FALSE); |
202 text->value = str; |
205 text->value.ptr = g_strdup(str); |
|
206 text->value.free = (ui_freefunc)g_free; |
203 return str; |
207 return str; |
204 } |
208 } |
205 |
209 |
206 void ui_textarea_insert(UiText *text, int pos, char *str) { |
210 void ui_textarea_insert(UiText *text, int pos, char *str) { |
207 if(text->value) { |
|
208 g_free(text->value); |
|
209 } |
|
210 text->value = NULL; |
|
211 GtkTextIter offset; |
211 GtkTextIter offset; |
212 gtk_text_buffer_get_iter_at_offset(text->obj, &offset, pos); |
212 gtk_text_buffer_get_iter_at_offset(text->obj, &offset, pos); |
213 gtk_text_buffer_insert(text->obj, &offset, str, -1); |
213 gtk_text_buffer_insert(text->obj, &offset, str, -1); |
|
214 if(text->value.ptr) { |
|
215 text->value.free(text->value.ptr); |
|
216 } |
|
217 text->value.ptr = NULL; |
|
218 text->value.free = NULL; |
214 } |
219 } |
215 |
220 |
216 void ui_textarea_setposition(UiText *text, int pos) { |
221 void ui_textarea_setposition(UiText *text, int pos) { |
217 GtkTextIter iter; |
222 GtkTextIter iter; |
218 gtk_text_buffer_get_iter_at_offset(text->obj, &iter, pos); |
223 gtk_text_buffer_get_iter_at_offset(text->obj, &iter, pos); |
506 UiContainer *ct = uic_get_current_container(obj); |
511 UiContainer *ct = uic_get_current_container(obj); |
507 ct->add(ct, textfield, FALSE); |
512 ct->add(ct, textfield, FALSE); |
508 |
513 |
509 if(var) { |
514 if(var) { |
510 UiString *value = var->value; |
515 UiString *value = var->value; |
511 if(value->value) { |
516 if(value->value.ptr) { |
512 gtk_entry_set_text(GTK_ENTRY(textfield), value->value); |
517 gtk_entry_set_text(GTK_ENTRY(textfield), value->value.ptr); |
513 g_free(value->value); |
518 value->value.free(value->value.ptr); |
514 value->value = NULL; |
519 value->value.ptr = NULL; |
|
520 value->value.free = NULL; |
515 } |
521 } |
516 |
522 |
517 value->get = ui_textfield_get; |
523 value->get = ui_textfield_get; |
518 value->set = ui_textfield_set; |
524 value->set = ui_textfield_set; |
519 value->value = NULL; |
525 value->value.ptr = NULL; |
|
526 value->value.free = NULL; |
520 value->obj = GTK_ENTRY(textfield); |
527 value->obj = GTK_ENTRY(textfield); |
521 } |
528 } |
522 |
529 |
523 return textfield; |
530 return textfield; |
524 } |
531 } |
587 UIWIDGET ui_passwordfield_wnv(UiObject *obj, int width, char *varname) { |
594 UIWIDGET ui_passwordfield_wnv(UiObject *obj, int width, char *varname) { |
588 return create_textfield_nv(obj, width, FALSE, TRUE, varname); |
595 return create_textfield_nv(obj, width, FALSE, TRUE, varname); |
589 } |
596 } |
590 |
597 |
591 char* ui_textfield_get(UiString *str) { |
598 char* ui_textfield_get(UiString *str) { |
592 if(str->value) { |
599 if(str->value.ptr) { |
593 g_free(str->value); |
600 str->value.free(str->value.ptr); |
594 } |
601 } |
595 str->value = g_strdup(gtk_entry_get_text(str->obj)); |
602 str->value.ptr = g_strdup(gtk_entry_get_text(str->obj)); |
596 return str->value; |
603 str->value.free = (ui_freefunc)g_free; |
|
604 return str->value.ptr; |
597 } |
605 } |
598 |
606 |
599 void ui_textfield_set(UiString *str, char *value) { |
607 void ui_textfield_set(UiString *str, char *value) { |
600 if(str->value) { |
|
601 g_free(str->value); |
|
602 } |
|
603 str->value = NULL; |
|
604 gtk_entry_set_text(str->obj, value); |
608 gtk_entry_set_text(str->obj, value); |
605 } |
609 if(str->value.ptr) { |
|
610 str->value.free(str->value.ptr); |
|
611 str->value.ptr = NULL; |
|
612 str->value.free = NULL; |
|
613 } |
|
614 } |