1
#ifndef __TEXTBUFFER_VIEW_H
2
#define __TEXTBUFFER_VIEW_H
4
#include "textbuffer.h"
7
typedef struct _TEXT_BUFFER_VIEW_REC TEXT_BUFFER_VIEW_REC;
9
/* if ypos == -1, don't print anything, just return the indent size */
10
typedef int (*INDENT_FUNC) (TEXT_BUFFER_VIEW_REC *view,
11
LINE_REC *line, int ypos);
14
const unsigned char *start;
16
INDENT_FUNC indent_func;
19
/* first word in line belong to the end of the last word in
21
unsigned int continues:1;
27
int count; /* number of real lines */
29
/* variable sized array, actually. starts from the second line,
30
so size of it is count-1 */
31
LINE_CACHE_SUB_REC lines[1];
38
GHashTable *line_cache;
40
/* should contain the same value for each cache that uses the
42
unsigned char update_counter;
43
/* number of real lines used by the last line in buffer */
45
} TEXT_BUFFER_CACHE_REC;
47
struct _TEXT_BUFFER_VIEW_REC {
48
TEXT_BUFFER_REC *buffer;
49
GSList *siblings; /* other views that use the same buffer */
55
INDENT_FUNC default_indent_func;
56
unsigned int longword_noindent:1;
57
unsigned int scroll:1; /* scroll down automatically when at bottom */
58
unsigned int utf8:1; /* use UTF8 in this view */
60
TEXT_BUFFER_CACHE_REC *cache;
61
int ypos; /* cursor position - visible area is 0..height-1 */
63
LINE_REC *startline; /* line at the top of the screen */
64
int subline; /* number of "real lines" to skip from `startline' */
66
/* marks the bottom of the text buffer */
67
LINE_REC *bottom_startline;
70
/* how many empty lines are in screen. a screenful when started
73
/* window is at the bottom of the text buffer */
74
unsigned int bottom:1;
75
/* if !bottom - new text has been printed since we were at bottom */
76
unsigned int more_text:1;
77
/* Window needs a redraw */
80
/* Bookmarks to the lines in the buffer - removed automatically
81
when the line gets removed from buffer */
82
GHashTable *bookmarks;
85
/* Create new view. */
86
TEXT_BUFFER_VIEW_REC *textbuffer_view_create(TEXT_BUFFER_REC *buffer,
87
int width, int height,
88
int scroll, int utf8);
89
/* Destroy the view. */
90
void textbuffer_view_destroy(TEXT_BUFFER_VIEW_REC *view);
91
/* Change the default indent position */
92
void textbuffer_view_set_default_indent(TEXT_BUFFER_VIEW_REC *view,
94
int longword_noindent,
95
INDENT_FUNC indent_func);
96
void textbuffer_views_unregister_indent_func(INDENT_FUNC indent_func);
98
void textbuffer_view_set_scroll(TEXT_BUFFER_VIEW_REC *view, int scroll);
99
void textbuffer_view_set_utf8(TEXT_BUFFER_VIEW_REC *view, int utf8);
101
/* Resize the view. */
102
void textbuffer_view_resize(TEXT_BUFFER_VIEW_REC *view, int width, int height);
103
/* Clear the view, don't actually remove any lines from buffer. */
104
void textbuffer_view_clear(TEXT_BUFFER_VIEW_REC *view);
106
#define textbuffer_view_get_lines(view) \
107
((view)->buffer->first_line)
109
/* Scroll the view up/down */
110
void textbuffer_view_scroll(TEXT_BUFFER_VIEW_REC *view, int lines);
111
/* Scroll to specified line */
112
void textbuffer_view_scroll_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line);
113
/* Return line cache */
114
LINE_CACHE_REC *textbuffer_view_get_line_cache(TEXT_BUFFER_VIEW_REC *view,
118
Functions for manipulating the text buffer, using these commands update
119
all views that use the buffer.
122
/* Update some line in the buffer which has been modified using
123
textbuffer_append() or textbuffer_insert(). */
124
void textbuffer_view_insert_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line);
125
/* Remove one line from buffer. */
126
void textbuffer_view_remove_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line);
127
/* Remove all lines from buffer. */
128
void textbuffer_view_remove_all_lines(TEXT_BUFFER_VIEW_REC *view);
130
/* Set a bookmark in view */
131
void textbuffer_view_set_bookmark(TEXT_BUFFER_VIEW_REC *view,
132
const char *name, LINE_REC *line);
133
/* Set a bookmark in view to the bottom line */
134
void textbuffer_view_set_bookmark_bottom(TEXT_BUFFER_VIEW_REC *view,
136
/* Return the line for bookmark */
137
LINE_REC *textbuffer_view_get_bookmark(TEXT_BUFFER_VIEW_REC *view,
140
/* Specify window where the changes in view should be drawn,
142
void textbuffer_view_set_window(TEXT_BUFFER_VIEW_REC *view,
143
TERM_WINDOW *window);
144
/* Redraw the view */
145
void textbuffer_view_redraw(TEXT_BUFFER_VIEW_REC *view);
147
void textbuffer_view_init(void);
148
void textbuffer_view_deinit(void);