This source file includes following definitions.
- mcview_scroll_to_cursor
- mcview_movement_fixups
- mcview_move_up
- mcview_move_down
- mcview_move_left
- mcview_move_right
- mcview_moveto_top
- mcview_moveto_bottom
- mcview_moveto_bol
- mcview_moveto_eol
- mcview_moveto_offset
- mcview_moveto
- mcview_coord_to_offset
- mcview_offset_to_coord
- mcview_place_cursor
- mcview_moveto_match
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 #include <config.h>
53
54 #include "lib/global.h"
55 #include "lib/tty/tty.h"
56 #include "internal.h"
57
58
59
60
61
62
63
64
65
66
67
68
69
70 static void
71 mcview_scroll_to_cursor (WView * view)
72 {
73 if (view->mode_flags.hex)
74 {
75 off_t bytes = view->bytes_per_line;
76 off_t cursor = view->hex_cursor;
77 off_t topleft = view->dpy_start;
78 off_t displaysize;
79
80 displaysize = view->data_area.lines * bytes;
81 if (topleft + displaysize <= cursor)
82 topleft = mcview_offset_rounddown (cursor, bytes) - (displaysize - bytes);
83 if (cursor < topleft)
84 topleft = mcview_offset_rounddown (cursor, bytes);
85 view->dpy_start = topleft;
86 view->dpy_paragraph_skip_lines = 0;
87 view->dpy_wrap_dirty = TRUE;
88 }
89 }
90
91
92
93 static void
94 mcview_movement_fixups (WView * view, gboolean reset_search)
95 {
96 mcview_scroll_to_cursor (view);
97 if (reset_search)
98 {
99 view->search_start = view->mode_flags.hex ? view->hex_cursor : view->dpy_start;
100 view->search_end = view->search_start;
101 }
102 view->dirty++;
103 }
104
105
106
107
108
109 void
110 mcview_move_up (WView * view, off_t lines)
111 {
112 if (view->mode_flags.hex)
113 {
114 off_t bytes = lines * view->bytes_per_line;
115
116 if (view->hex_cursor >= bytes)
117 {
118 view->hex_cursor -= bytes;
119 if (view->hex_cursor < view->dpy_start)
120 {
121 view->dpy_start = DOZ (view->dpy_start, bytes);
122 view->dpy_paragraph_skip_lines = 0;
123 view->dpy_wrap_dirty = TRUE;
124 }
125 }
126 else
127 {
128 view->hex_cursor %= view->bytes_per_line;
129 }
130 }
131 else
132 {
133 mcview_ascii_move_up (view, lines);
134 }
135 mcview_movement_fixups (view, TRUE);
136 }
137
138
139
140 void
141 mcview_move_down (WView * view, off_t lines)
142 {
143 off_t last_byte;
144
145 last_byte = mcview_get_filesize (view);
146
147 if (view->mode_flags.hex)
148 {
149 off_t i, limit;
150
151 limit = DOZ (last_byte, (off_t) view->bytes_per_line);
152
153 for (i = 0; i < lines && view->hex_cursor < limit; i++)
154 {
155 view->hex_cursor += view->bytes_per_line;
156 if (lines != 1)
157 {
158 view->dpy_start += view->bytes_per_line;
159 view->dpy_paragraph_skip_lines = 0;
160 view->dpy_wrap_dirty = TRUE;
161 }
162 }
163 }
164 else
165 {
166 mcview_ascii_move_down (view, lines);
167 }
168 mcview_movement_fixups (view, TRUE);
169 }
170
171
172
173 void
174 mcview_move_left (WView * view, off_t columns)
175 {
176 if (view->mode_flags.hex)
177 {
178 off_t old_cursor = view->hex_cursor;
179
180 g_assert (columns == 1);
181
182 if (view->hexview_in_text || !view->hexedit_lownibble)
183 {
184 if (view->hex_cursor > 0)
185 view->hex_cursor--;
186 }
187 if (!view->hexview_in_text)
188 if (old_cursor > 0 || view->hexedit_lownibble)
189 view->hexedit_lownibble = !view->hexedit_lownibble;
190 }
191 else if (!view->mode_flags.wrap)
192 view->dpy_text_column = DOZ (view->dpy_text_column, columns);
193 mcview_movement_fixups (view, FALSE);
194 }
195
196
197
198 void
199 mcview_move_right (WView * view, off_t columns)
200 {
201 if (view->mode_flags.hex)
202 {
203 off_t last_byte;
204 off_t old_cursor = view->hex_cursor;
205
206 last_byte = mcview_get_filesize (view);
207 last_byte = DOZ (last_byte, 1);
208
209 g_assert (columns == 1);
210
211 if (view->hexview_in_text || view->hexedit_lownibble)
212 {
213 if (view->hex_cursor < last_byte)
214 view->hex_cursor++;
215 }
216 if (!view->hexview_in_text)
217 if (old_cursor < last_byte || !view->hexedit_lownibble)
218 view->hexedit_lownibble = !view->hexedit_lownibble;
219 }
220 else if (!view->mode_flags.wrap)
221 {
222 view->dpy_text_column += columns;
223 }
224 mcview_movement_fixups (view, FALSE);
225 }
226
227
228
229 void
230 mcview_moveto_top (WView * view)
231 {
232 view->dpy_start = 0;
233 view->dpy_paragraph_skip_lines = 0;
234 mcview_state_machine_init (&view->dpy_state_top, 0);
235 view->hex_cursor = 0;
236 view->dpy_text_column = 0;
237 mcview_movement_fixups (view, TRUE);
238 }
239
240
241
242 void
243 mcview_moveto_bottom (WView * view)
244 {
245 off_t filesize;
246
247 mcview_update_filesize (view);
248
249 if (view->growbuf_in_use)
250 mcview_growbuf_read_all_data (view);
251
252 filesize = mcview_get_filesize (view);
253
254 if (view->mode_flags.hex)
255 {
256 view->hex_cursor = DOZ (filesize, 1);
257 mcview_movement_fixups (view, TRUE);
258 }
259 else
260 {
261 view->dpy_start = filesize;
262 view->dpy_paragraph_skip_lines = 0;
263 view->dpy_wrap_dirty = TRUE;
264 mcview_move_up (view, view->data_area.lines);
265 }
266 }
267
268
269
270 void
271 mcview_moveto_bol (WView * view)
272 {
273 if (view->mode_flags.hex)
274 {
275 view->hex_cursor -= view->hex_cursor % view->bytes_per_line;
276 view->dpy_text_column = 0;
277 }
278 else
279 {
280 mcview_ascii_moveto_bol (view);
281 }
282 mcview_movement_fixups (view, TRUE);
283 }
284
285
286
287 void
288 mcview_moveto_eol (WView * view)
289 {
290 off_t bol;
291
292 if (view->mode_flags.hex)
293 {
294 off_t filesize;
295
296 bol = mcview_offset_rounddown (view->hex_cursor, view->bytes_per_line);
297 if (mcview_get_byte_indexed (view, bol, view->bytes_per_line - 1, NULL) == TRUE)
298 {
299 view->hex_cursor = bol + view->bytes_per_line - 1;
300 }
301 else
302 {
303 filesize = mcview_get_filesize (view);
304 view->hex_cursor = DOZ (filesize, 1);
305 }
306 }
307 else
308 {
309 mcview_ascii_moveto_eol (view);
310 }
311 mcview_movement_fixups (view, FALSE);
312 }
313
314
315
316 void
317 mcview_moveto_offset (WView * view, off_t offset)
318 {
319 if (view->mode_flags.hex)
320 {
321 view->hex_cursor = offset;
322 view->dpy_start = offset - offset % view->bytes_per_line;
323 view->dpy_paragraph_skip_lines = 0;
324 view->dpy_wrap_dirty = TRUE;
325 }
326 else
327 {
328 view->dpy_start = offset;
329 view->dpy_paragraph_skip_lines = 0;
330 view->dpy_wrap_dirty = TRUE;
331 }
332 mcview_movement_fixups (view, TRUE);
333 }
334
335
336
337 void
338 mcview_moveto (WView * view, off_t line, off_t col)
339 {
340 off_t offset;
341
342 mcview_coord_to_offset (view, &offset, line, col);
343 mcview_moveto_offset (view, offset);
344 }
345
346
347
348 void
349 mcview_coord_to_offset (WView * view, off_t * ret_offset, off_t line, off_t column)
350 {
351 coord_cache_entry_t coord;
352
353 coord.cc_line = line;
354 coord.cc_column = column;
355 coord.cc_nroff_column = column;
356 mcview_ccache_lookup (view, &coord, CCACHE_OFFSET);
357 *ret_offset = coord.cc_offset;
358 }
359
360
361
362 void
363 mcview_offset_to_coord (WView * view, off_t * ret_line, off_t * ret_column, off_t offset)
364 {
365 coord_cache_entry_t coord;
366
367 coord.cc_offset = offset;
368 mcview_ccache_lookup (view, &coord, CCACHE_LINECOL);
369
370 *ret_line = coord.cc_line;
371 *ret_column = view->mode_flags.nroff ? coord.cc_nroff_column : coord.cc_column;
372 }
373
374
375
376 void
377 mcview_place_cursor (WView * view)
378 {
379 const WRect *r = &view->data_area;
380 int col = view->cursor_col;
381
382 if (!view->hexview_in_text && view->hexedit_lownibble)
383 col++;
384 widget_gotoyx (view, r->y + view->cursor_row, r->x + col);
385 }
386
387
388
389
390
391
392 void
393 mcview_moveto_match (WView * view)
394 {
395 if (view->mode_flags.hex)
396 {
397 view->hex_cursor = view->search_start;
398 view->hexedit_lownibble = FALSE;
399 view->dpy_start = view->search_start - view->search_start % view->bytes_per_line;
400 view->dpy_end = view->search_end - view->search_end % view->bytes_per_line;
401 view->dpy_paragraph_skip_lines = 0;
402 view->dpy_wrap_dirty = TRUE;
403 }
404 else
405 {
406 view->dpy_start = mcview_bol (view, view->search_start, 0);
407 view->dpy_paragraph_skip_lines = 0;
408 view->dpy_wrap_dirty = TRUE;
409 }
410
411 mcview_scroll_to_cursor (view);
412 view->dirty++;
413 }
414
415