Added SILC Thread Queue API
[crypto.git] / apps / irssi / src / fe-text / textbuffer-view.h
1 #ifndef __TEXTBUFFER_VIEW_H
2 #define __TEXTBUFFER_VIEW_H
3
4 #include "textbuffer.h"
5 #include "term.h"
6
7 typedef struct _TEXT_BUFFER_VIEW_REC TEXT_BUFFER_VIEW_REC;
8
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);
12
13 typedef struct {
14         const unsigned char *start;
15         int indent;
16         INDENT_FUNC indent_func;
17         int color;
18
19         /* first word in line belong to the end of the last word in
20            previous line */
21         unsigned int continues:1;
22 } LINE_CACHE_SUB_REC;
23
24 typedef struct {
25         time_t last_access;
26
27         int count; /* number of real lines */
28
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];
32 } LINE_CACHE_REC;
33
34 typedef struct {
35         int refcount;
36         int width;
37
38         GHashTable *line_cache;
39
40         /* should contain the same value for each cache that uses the
41            same buffer */
42         unsigned char update_counter;
43         /* number of real lines used by the last line in buffer */
44         int last_linecount;
45 } TEXT_BUFFER_CACHE_REC;
46
47 struct _TEXT_BUFFER_VIEW_REC {
48         TEXT_BUFFER_REC *buffer;
49         GSList *siblings; /* other views that use the same buffer */
50
51         TERM_WINDOW *window;
52         int width, height;
53
54         int default_indent;
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 */
59
60         TEXT_BUFFER_CACHE_REC *cache;
61         int ypos; /* cursor position - visible area is 0..height-1 */
62
63         LINE_REC *startline; /* line at the top of the screen */
64         int subline; /* number of "real lines" to skip from `startline' */
65
66         /* marks the bottom of the text buffer */
67         LINE_REC *bottom_startline;
68         int bottom_subline;
69
70         /* how many empty lines are in screen. a screenful when started
71            or used /CLEAR */
72         int empty_linecount; 
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 */
78         unsigned int dirty:1;
79
80         /* Bookmarks to the lines in the buffer - removed automatically
81            when the line gets removed from buffer */
82         GHashTable *bookmarks;
83 };
84
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,
93                                         int default_indent,
94                                         int longword_noindent,
95                                         INDENT_FUNC indent_func);
96 void textbuffer_views_unregister_indent_func(INDENT_FUNC indent_func);
97
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);
100
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);
105
106 #define textbuffer_view_get_lines(view) \
107         ((view)->buffer->first_line)
108
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,
115                                                LINE_REC *line);
116
117 /*
118    Functions for manipulating the text buffer, using these commands update
119    all views that use the buffer.
120 */
121
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);
129
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,
135                                          const char *name);
136 /* Return the line for bookmark */
137 LINE_REC *textbuffer_view_get_bookmark(TEXT_BUFFER_VIEW_REC *view,
138                                        const char *name);
139
140 /* Specify window where the changes in view should be drawn,
141    NULL disables it. */
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);
146
147 void textbuffer_view_init(void);
148 void textbuffer_view_deinit(void);
149
150 #endif