ui/gtk/text.c

changeset 33
458831c574f4
parent 29
c96169444d88
child 56
87e3a5dc66dd
equal deleted inserted replaced
32:9a5f47fbc5c3 33:458831c574f4
30 #include <stdlib.h> 30 #include <stdlib.h>
31 #include <string.h> 31 #include <string.h>
32 32
33 #include "text.h" 33 #include "text.h"
34 #include "container.h" 34 #include "container.h"
35 #include "../common/context.h"
36 #include "../common/document.h"
35 37
36 static void selection_handler( 38 static void selection_handler(
37 GtkTextBuffer *buf, 39 GtkTextBuffer *buf,
38 GtkTextIter *location, 40 GtkTextIter *location,
39 GtkTextMark *mark, 41 GtkTextMark *mark,
95 UiContainer *ct = uic_get_current_container(obj); 97 UiContainer *ct = uic_get_current_container(obj);
96 ct->add(ct, scroll_area); 98 ct->add(ct, scroll_area);
97 99
98 // bind value 100 // bind value
99 if(value) { 101 if(value) {
102 GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_area));
103
104 if(value->value) {
105 gtk_text_buffer_set_text(buf, value->value, -1);
106 }
107
100 value->get = ui_textarea_get; 108 value->get = ui_textarea_get;
101 value->set = ui_textarea_set; 109 value->set = ui_textarea_set;
102 value->getsubstr = ui_textarea_getsubstr; 110 value->getsubstr = ui_textarea_getsubstr;
103 value->insert = ui_textarea_insert; 111 value->insert = ui_textarea_insert;
104 value->position = ui_textarea_position; 112 value->position = ui_textarea_position;
105 value->selection = ui_textarea_selection; 113 value->selection = ui_textarea_selection;
106 value->length = ui_textarea_length; 114 value->length = ui_textarea_length;
115 value->remove = ui_textarea_remove;
107 value->value = NULL; 116 value->value = NULL;
108 GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_area));
109 value->obj = buf; 117 value->obj = buf;
110 if(!value->undomgr) { 118 if(!value->undomgr) {
111 value->undomgr = ui_create_undomgr(); 119 value->undomgr = ui_create_undomgr();
112 } 120 }
113 121
131 } 139 }
132 140
133 return scroll_area; 141 return scroll_area;
134 } 142 }
135 143
144 UIWIDGET ui_textarea_nv(UiObject *obj, char *varname) {
145 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_TEXT);
146 if(var) {
147 UiText *value = var->value;
148 return ui_textarea(obj, value);
149 } else {
150 // TODO: error
151 }
152 return NULL;
153 }
154
136 char* ui_textarea_get(UiText *text) { 155 char* ui_textarea_get(UiText *text) {
137 if(text->value) { 156 if(text->value) {
138 g_free(text->value); 157 g_free(text->value);
139 } 158 }
140 GtkTextBuffer *buf = text->obj; 159 GtkTextBuffer *buf = text->obj;
197 GtkTextBuffer *buf = text->obj; 216 GtkTextBuffer *buf = text->obj;
198 GtkTextIter start; 217 GtkTextIter start;
199 GtkTextIter end; 218 GtkTextIter end;
200 gtk_text_buffer_get_bounds(buf, &start, &end); 219 gtk_text_buffer_get_bounds(buf, &start, &end);
201 return gtk_text_iter_get_offset(&end); 220 return gtk_text_iter_get_offset(&end);
221 }
222
223 void ui_textarea_remove(UiText *text, int begin, int end) {
224 GtkTextBuffer *buf = text->obj;
225 GtkTextIter ib;
226 GtkTextIter ie;
227 gtk_text_buffer_get_iter_at_offset(buf, &ib, begin);
228 gtk_text_buffer_get_iter_at_offset(buf, &ie, end);
229 gtk_text_buffer_delete(buf, &ib, &ie);
202 } 230 }
203 231
204 void ui_textarea_realize_event(GtkWidget *widget, gpointer data) { 232 void ui_textarea_realize_event(GtkWidget *widget, gpointer data) {
205 gtk_widget_grab_focus(widget); 233 gtk_widget_grab_focus(widget);
206 } 234 }

mercurial