64 |
64 |
65 // bind value |
65 // bind value |
66 if(value) { |
66 if(value) { |
67 value->get = ui_textarea_get; |
67 value->get = ui_textarea_get; |
68 value->set = ui_textarea_set; |
68 value->set = ui_textarea_set; |
|
69 value->getsubstr = ui_textarea_getsubstr; |
|
70 value->insert = ui_textarea_insert; |
69 value->value = NULL; |
71 value->value = NULL; |
70 GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_area)); |
72 GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_area)); |
71 value->obj = buf; |
73 value->obj = buf; |
72 if(!value->undomgr) { |
74 if(!value->undomgr) { |
73 value->undomgr = ui_create_undomgr(); |
75 value->undomgr = ui_create_undomgr(); |
103 } |
105 } |
104 |
106 |
105 void ui_textarea_set(UiText *text, char *str) { |
107 void ui_textarea_set(UiText *text, char *str) { |
106 if(text->value) { |
108 if(text->value) { |
107 g_free(text->value); |
109 g_free(text->value); |
108 text->value = NULL; |
110 } |
109 } |
111 text->value = NULL; |
110 gtk_text_buffer_set_text((GtkTextBuffer*)text->obj, str, -1); |
112 gtk_text_buffer_set_text((GtkTextBuffer*)text->obj, str, -1); |
|
113 } |
|
114 |
|
115 char* ui_textarea_getsubstr(UiText *text, int begin, int end) { |
|
116 if(text->value) { |
|
117 g_free(text->value); |
|
118 } |
|
119 GtkTextBuffer *buf = text->obj; |
|
120 GtkTextIter ib; |
|
121 GtkTextIter ie; |
|
122 gtk_text_buffer_get_iter_at_offset(text->obj, &ib, begin); |
|
123 gtk_text_buffer_get_iter_at_offset(text->obj, &ie, end); |
|
124 char *str = gtk_text_buffer_get_text(buf, &ib, &ie, FALSE); |
|
125 text->value = str; |
|
126 return str; |
|
127 } |
|
128 |
|
129 void ui_textarea_insert(UiText *text, int pos, char *str) { |
|
130 if(text->value) { |
|
131 g_free(text->value); |
|
132 } |
|
133 text->value = NULL; |
|
134 GtkTextIter offset; |
|
135 gtk_text_buffer_get_iter_at_offset(text->obj, &offset, pos); |
|
136 gtk_text_buffer_insert(text->obj, &offset, str, -1); |
111 } |
137 } |
112 |
138 |
113 void ui_textarea_realize_event(GtkWidget *widget, gpointer data) { |
139 void ui_textarea_realize_event(GtkWidget *widget, gpointer data) { |
114 gtk_widget_grab_focus(widget); |
140 gtk_widget_grab_focus(widget); |
115 } |
141 } |