151 |
GtkWidget *text = NULL; |
GtkWidget *text = NULL; |
152 |
GtkTextBuffer *buf; |
GtkTextBuffer *buf; |
153 |
GtkTextIter iter; |
GtkTextIter iter; |
154 |
|
GtkTextMark *mark; |
155 |
|
GtkTextMark *oldmark; |
156 |
|
GtkTextIter olditer; |
157 |
|
int oldpos; |
158 |
|
|
159 |
ptr = NSA_GET_PTR (env, obj); |
ptr = NSA_GET_PTR (env, obj); |
160 |
|
|
178 |
if (text) |
if (text) |
179 |
{ |
{ |
180 |
buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); |
buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); |
181 |
|
|
182 |
|
/* Save old position. */ |
183 |
|
oldmark = gtk_text_buffer_get_insert (buf); |
184 |
|
gtk_text_buffer_get_iter_at_mark (buf, &olditer, oldmark); |
185 |
|
oldpos = gtk_text_iter_get_offset (&olditer); |
186 |
|
|
187 |
|
/* Move to new position. */ |
188 |
gtk_text_buffer_get_iter_at_offset (buf, &iter, pos); |
gtk_text_buffer_get_iter_at_offset (buf, &iter, pos); |
189 |
gtk_text_buffer_place_cursor (buf, &iter); |
gtk_text_buffer_place_cursor (buf, &iter); |
190 |
|
|
191 |
|
/* Scroll to new position. Alignment is determined |
192 |
|
comparing the new position to the old position. */ |
193 |
|
if (oldpos > pos) |
194 |
|
gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (text), |
195 |
|
&iter, 0, TRUE, 0, 0); |
196 |
|
else if (oldpos < pos) |
197 |
|
gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (text), |
198 |
|
&iter, 0, TRUE, 1, 1); |
199 |
} |
} |
200 |
} |
} |
201 |
|
|