imported irssi.
[silc.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 "screen.h"
6
7 typedef struct {
8         unsigned char *start;
9         int indent;
10         int color;
11
12         /* first word in line belong to the end of the last word in
13            previous line */
14         unsigned int continues:1;
15 } LINE_CACHE_SUB_REC;
16
17 typedef struct {
18         time_t last_access;
19
20         int count; /* number of real lines */
21
22         /* variable sized array, actually. starts from the second line,
23            so size of it is count-1 */
24         LINE_CACHE_SUB_REC lines[1];
25 } LINE_CACHE_REC;
26
27 typedef struct {
28         int refcount;
29         int width;
30
31         GHashTable *line_cache;
32
33         /* should contain the same value for each cache that uses the
34            same buffer */
35         unsigned char update_counter;
36         /* number of real lines used by the last line in buffer */
37         int last_linecount;
38 } TEXT_BUFFER_CACHE_REC;
39
40 typedef struct {
41         TEXT_BUFFER_REC *buffer;
42         GSList *siblings; /* other views that use the same buffer */
43
44         WINDOW *window;
45         int width, height;
46
47         int default_indent;
48         int longword_noindent:1;
49
50         TEXT_BUFFER_CACHE_REC *cache;
51         int ypos; /* cursor position - visible area is 0..height-1 */
52
53         GList *startline; /* line at the top of the screen */
54         int subline; /* number of "real lines" to skip from `startline' */
55
56         /* marks the bottom of the text buffer */
57         GList *bottom_startline;
58         int bottom_subline;
59
60         /* how many empty lines are in screen. a screenful when started
61            or used /CLEAR */
62         int empty_linecount; 
63         /* window is at the bottom of the text buffer */
64         unsigned int bottom:1;
65
66         /* Bookmarks to the lines in the buffer - removed automatically
67            when the line gets removed from buffer */
68         GHashTable *bookmarks;
69 } TEXT_BUFFER_VIEW_REC;
70
71 /* Create new view. */
72 TEXT_BUFFER_VIEW_REC *textbuffer_view_create(TEXT_BUFFER_REC *buffer,
73                                              int width, int height,
74                                              int default_indent,
75                                              int longword_noindent);
76 /* Destroy the view. */
77 void textbuffer_view_destroy(TEXT_BUFFER_VIEW_REC *view);
78 /* Change the default indent position */
79 void textbuffer_view_set_default_indent(TEXT_BUFFER_VIEW_REC *view,
80                                         int default_indent,
81                                         int longword_noindent);
82
83 /* Resize the view. */
84 void textbuffer_view_resize(TEXT_BUFFER_VIEW_REC *view, int width, int height);
85 /* Clear the view, don't actually remove any lines from buffer. */
86 void textbuffer_view_clear(TEXT_BUFFER_VIEW_REC *view);
87
88 #define textbuffer_view_get_lines(view) \
89         ((view)->buffer->lines)
90
91 /* Scroll the view up/down */
92 void textbuffer_view_scroll(TEXT_BUFFER_VIEW_REC *view, int lines);
93 /* Scroll to specified line */
94 void textbuffer_view_scroll_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line);
95 /* Return line cache */
96 LINE_CACHE_REC *textbuffer_view_get_line_cache(TEXT_BUFFER_VIEW_REC *view,
97                                                LINE_REC *line);
98
99 /*
100    Functions for manipulating the text buffer, using these commands update
101    all views that use the buffer.
102 */
103
104 /* Update some line in the buffer which has been modified using
105    textbuffer_append() or textbuffer_insert(). */
106 void textbuffer_view_insert_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line);
107 /* Remove one line from buffer. */
108 void textbuffer_view_remove_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line);
109 /* Remove all lines from buffer. */
110 void textbuffer_view_remove_all_lines(TEXT_BUFFER_VIEW_REC *view);
111
112 /* Set a bookmark in view */
113 void textbuffer_view_set_bookmark(TEXT_BUFFER_VIEW_REC *view,
114                                   const char *name, LINE_REC *line);
115 /* Set a bookmark in view to the bottom line */
116 void textbuffer_view_set_bookmark_bottom(TEXT_BUFFER_VIEW_REC *view,
117                                          const char *name);
118 /* Return the line for bookmark */
119 LINE_REC *textbuffer_view_get_bookmark(TEXT_BUFFER_VIEW_REC *view,
120                                        const char *name);
121
122 /* Specify window where the changes in view should be drawn,
123    NULL disables it. */
124 void textbuffer_view_set_window(TEXT_BUFFER_VIEW_REC *view, WINDOW *window);
125 /* Redraw the view */
126 void textbuffer_view_redraw(TEXT_BUFFER_VIEW_REC *view);
127
128 void textbuffer_view_init(void);
129 void textbuffer_view_deinit(void);
130
131 #endif