geevi: set window default size
[geevi.git] / cursor.c
blob3ec94e8a6a2cfc3d71724e738ee2fb5164d21cb1
1 #include <gtk/gtk.h>
2 #include "geevi.h"
4 #define CURSOR_MARK "geevi_cursor"
5 #define CURSOR_TAG "geevi_tag"
7 void cursor_init(GtkTextView *view)
9 GtkTextBuffer *buffer = gtk_text_view_get_buffer(view);
10 GtkTextIter iter;
11 gtk_text_buffer_get_start_iter(buffer, &iter);
12 gtk_text_buffer_create_mark(buffer, CURSOR_MARK, &iter, FALSE);
13 gtk_text_buffer_create_tag(buffer, CURSOR_TAG,
14 "background", "#000000",
15 "foreground", "#FFFFFF", NULL);
16 cursor_place(view, &iter);
19 void cursor_redraw(GtkTextView *view)
21 GtkTextIter iter;
22 cursor_get(view, &iter);
23 cursor_place(view, &iter);
26 void cursor_place(GtkTextView *view, GtkTextIter *iter)
28 GtkTextIter old_start, old_end;
29 GtkTextIter end = *iter;
30 GtkTextBuffer *buffer = gtk_text_view_get_buffer(view);
31 GtkTextMark *mark = gtk_text_buffer_get_mark(buffer, CURSOR_MARK);
32 cursor_get(view, &old_start);
33 old_end = old_start;
34 gtk_text_iter_forward_char(&old_end);
35 gtk_text_buffer_remove_tag_by_name(buffer, CURSOR_TAG,
36 &old_start, &old_end);
37 if (gtk_text_iter_ends_line(iter)) {
38 /* cursor is hidden... do something! */
40 gtk_text_buffer_move_mark(buffer, mark, iter);
42 gtk_text_iter_forward_char(&end);
43 gtk_text_buffer_apply_tag_by_name(buffer, CURSOR_TAG, iter, &end);
44 gtk_text_buffer_place_cursor(buffer, iter);
45 gtk_text_view_scroll_mark_onscreen(view, mark);
48 void cursor_get(GtkTextView *view, GtkTextIter *iter)
50 GtkTextMark *mark;
51 GtkTextBuffer *buffer = gtk_text_view_get_buffer(view);
52 mark = gtk_text_buffer_get_mark(buffer, CURSOR_MARK);
53 gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);