7 typedef struct View View
;
8 typedef struct Cursor Cursor
;
9 typedef struct Selection Selection
;
15 char data
[16]; /* utf8 encoded character displayed in this cell (might be more than
16 one Unicode codepoint. might also not be the same as in the
17 underlying text, for example tabs get expanded */
18 size_t len
; /* number of bytes the character displayed in this cell uses, for
19 characters which use more than 1 column to display, their length
20 is stored in the leftmost cell whereas all following cells
21 occupied by the same character have a length of 0. */
22 int width
; /* display width i.e. number of columns occupied by this character */
23 CellStyle style
; /* colors and attributes used to display this cell */
26 typedef struct Line Line
;
27 struct Line
{ /* a line on the screen, *not* in the file */
28 Line
*prev
, *next
; /* pointer to neighbouring screen lines */
29 size_t len
; /* line length in terms of bytes */
30 size_t lineno
; /* line number from start of file */
31 int width
; /* zero based position of last used column cell */
32 Cell cells
[]; /* win->width cells storing information about the displayed characters */
35 View
*view_new(Text
*);
36 void view_ui(View
*, UiWin
*);
37 /* change associated text displayed in this window */
38 void view_reload(View
*, Text
*);
39 void view_free(View
*);
41 bool view_resize(View
*, int width
, int height
);
42 int view_height_get(View
*);
43 int view_width_get(View
*);
44 void view_invalidate(View
*);
45 void view_draw(View
*);
46 bool view_update(View
*);
47 /* changes how many spaces are used for one tab (must be >0), redraws the window */
48 void view_tabwidth_set(View
*, int tabwidth
);
50 /* cursor movements which also update selection if one is active.
51 * they return new cursor postion */
52 size_t view_line_down(Cursor
*);
53 size_t view_line_up(Cursor
*);
54 size_t view_screenline_down(Cursor
*);
55 size_t view_screenline_up(Cursor
*);
56 size_t view_screenline_begin(Cursor
*);
57 size_t view_screenline_middle(Cursor
*);
58 size_t view_screenline_end(Cursor
*);
60 /* move window content up/down, but keep cursor position unchanged unless it is
61 * on a now invisible line in which case we try to preserve the column position */
62 size_t view_slide_up(View
*, int lines
);
63 size_t view_slide_down(View
*, int lines
);
64 /* scroll window contents up/down by lines, place the cursor on the newly
65 * visible line, try to preserve the column position */
66 size_t view_scroll_up(View
*, int lines
);
67 size_t view_scroll_down(View
*, int lines
);
68 size_t view_scroll_page_up(View
*);
69 size_t view_scroll_page_down(View
*);
70 size_t view_scroll_halfpage_up(View
*);
71 size_t view_scroll_halfpage_down(View
*);
72 /* place the cursor at the start ot the n-th window line, counting from 1 */
73 size_t view_screenline_goto(View
*, int n
);
75 Line
*view_lines_first(View
*);
76 Line
*view_lines_last(View
*);
77 Line
*view_cursors_line_get(Cursor
*);
78 /* redraw current cursor line at top/center/bottom of window */
79 void view_redraw_top(View
*);
80 void view_redraw_center(View
*);
81 void view_redraw_bottom(View
*);
82 /* get the currently displayed area in bytes from the start of the file */
83 Filerange
view_viewport_get(View
*);
84 /* move visible viewport n-lines up/down, redraws the view but does not change
85 * cursor position which becomes invalid and should be corrected by calling
86 * view_cursor_to. the return value indicates wether the visible area changed.
88 bool view_viewport_up(View
*view
, int n
);
89 bool view_viewport_down(View
*view
, int n
);
91 void view_options_set(View
*, enum UiOption options
);
92 enum UiOption
view_options_get(View
*);
93 void view_colorcolumn_set(View
*, int col
);
94 int view_colorcolumn_get(View
*);
96 bool view_coord_get(View
*, size_t pos
, Line
**retline
, int *retrow
, int *retcol
);
97 /* A view can manage multiple cursors, one of which (the main cursor) is always
98 * placed within the visible viewport. All functions named view_cursor_* operate
99 * on this cursor. Additional cursor can be created and manipulated using the
100 * functions named view_cursors_* */
102 /* get main cursor position in bytes from start of the file */
103 size_t view_cursor_get(View
*);
104 /* get selection associated with primary cursor */
105 Filerange
view_selection_get(View
*);
106 /* moves window viewport in direction until pos is visible. should only be
107 * used for short distances between current cursor position and destination */
108 void view_scroll_to(View
*, size_t pos
);
109 /* move cursor to a given position. changes the viewport to make sure that
110 * position is visible. if the position is in the middle of a line, try to
111 * adjust the viewport in such a way that the whole line is displayed */
112 void view_cursor_to(View
*, size_t pos
);
113 /* create a new cursor at given position, fails if there already
114 * exists a cursor at the same position */
115 Cursor
*view_cursors_new(View
*, size_t pos
);
116 /* create a new cursor even if there already is one located at the
117 * same position, this should only be used if the one of the two
118 * cursors will later be disposed */
119 Cursor
*view_cursors_new_force(View
*, size_t pos
);
120 /* get number of active cursors */
121 int view_cursors_count(View
*);
122 /* get index/relative order at time of creation of a cursor [0,count-1] */
123 int view_cursors_number(Cursor
*);
124 /* exist there more than 1 cursor */
125 bool view_cursors_multiple(View
*);
126 /* dispose an existing cursor with its associated selection (if any),
127 * not applicaple for the last existing cursor */
128 bool view_cursors_dispose(Cursor
*);
129 /* if called for the last existing cursor its selection is destroyed
130 * and the cursor is marked for destruction and will be disposed as
131 * soon as a new cursor is created. */
132 bool view_cursors_dispose_force(Cursor
*);
133 /* if the primary cursor was marked for destruction (by means of
134 * view_cursors_dispose_force) return it and clear descruction flag */
135 Cursor
*view_cursor_disposed(View
*);
136 /* only keep the main cursor, release all others together with their
137 * selections (if any) */
138 void view_cursors_clear(View
*);
139 /* get the first cursor */
140 Cursor
*view_cursors(View
*);
141 /* get other cursors, no ordering is guaranteed */
142 Cursor
*view_cursors_prev(Cursor
*);
143 Cursor
*view_cursors_next(Cursor
*);
144 /* get the primary cursor which is always in the visible viewport */
145 Cursor
*view_cursors_primary_get(View
*);
146 void view_cursors_primary_set(Cursor
*);
147 /* get current position of cursor in bytes from the start of the file */
148 size_t view_cursors_pos(Cursor
*);
149 /* get 1-based line number of cursor location */
150 size_t view_cursors_line(Cursor
*);
151 /* get 1-based column (number of graphemes on line) cursor postion */
152 size_t view_cursors_col(Cursor
*);
153 /* get/set zero based index of cell on which cursor currently resides,
154 * -1 if cursor is currently not visible */
155 int view_cursors_cell_get(Cursor
*);
156 int view_cursors_cell_set(Cursor
*, int cell
);
157 /* place cursor at `pos' which should be in the interval [0, text-size] */
158 void view_cursors_to(Cursor
*, size_t pos
);
159 void view_cursors_scroll_to(Cursor
*, size_t pos
);
160 /* place cursor on given (line, column) pair, both values are 1-based */
161 void view_cursors_place(Cursor
*, size_t line
, size_t col
);
162 /* start selected area at current cursor position. further cursor movements
163 * will affect the selected region. */
164 void view_cursors_selection_start(Cursor
*);
165 /* detach cursor from selection, further cursor movements will not affect
166 * the selected region. */
167 void view_cursors_selection_stop(Cursor
*);
168 /* clear selection associated with this cursor (if any) */
169 void view_cursors_selection_clear(Cursor
*);
170 /* move cursor position from one end of the selection to the other */
171 void view_cursors_selection_swap(Cursor
*);
172 /* move cursor to the end/boundary of the associated selection */
173 void view_cursors_selection_sync(Cursor
*);
174 /* restore previous used selection of this cursor */
175 void view_cursors_selection_restore(Cursor
*);
176 /* get/set the selected region associated with this cursor */
177 Filerange
view_cursors_selection_get(Cursor
*);
178 void view_cursors_selection_set(Cursor
*, const Filerange
*);
180 Selection
*view_selections_new(View
*, Cursor
*);
181 void view_selections_free(Selection
*);
182 void view_selections_clear(View
*);
183 void view_selections_swap(Selection
*);
184 Selection
*view_selections(View
*);
185 Selection
*view_selections_prev(Selection
*);
186 Selection
*view_selections_next(Selection
*);
187 Filerange
view_selections_get(Selection
*);
188 void view_selections_set(Selection
*, const Filerange
*);
189 Text
*view_text(View
*);
191 /* get number of columns, that is maximal number of cursors on a line */
192 int view_cursors_column_count(View
*);
193 /* get first cursor in zero based column */
194 Cursor
*view_cursors_column(View
*, int column
);
195 /* get next cursor (i.e. on another line) in zero based column */
196 Cursor
*view_cursors_column_next(Cursor
*, int column
);
198 bool view_style_define(View
*, enum UiStyle
, const char *style
);
199 void view_style(View
*, enum UiStyle
, size_t start
, size_t end
);