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
71
72 static void
73 mcview_scroll_to_cursor (WView *view)
74 {
75 if (view->mode_flags.hex)
76 {
77 off_t bytes = view->bytes_per_line;
78 off_t cursor = view->hex_cursor;
79 off_t topleft = view->dpy_start;
80 off_t displaysize;
81
82 displaysize = view->data_area.lines * bytes;
83 if (topleft + displaysize <= cursor)
84 topleft = mcview_offset_rounddown (cursor, bytes) - (displaysize - bytes);
85 if (cursor < topleft)
86 topleft = mcview_offset_rounddown (cursor, bytes);
87 view->dpy_start = topleft;
88 view->dpy_paragraph_skip_lines = 0;
89 view->dpy_wrap_dirty = TRUE;
90 }
91 }
92
93
94
95 static void
96 mcview_movement_fixups (WView *view, gboolean reset_search)
97 {
98 mcview_scroll_to_cursor (view);
99
100 if (reset_search)
101 {
102 view->search_start = view->mode_flags.hex ? view->hex_cursor : view->dpy_start;
103 view->search_end = view->search_start;
104 }
105
106 view->dirty++;
107 }
108
109
110
111
112
113 void
114 mcview_move_up (WView *view, off_t lines)
115 {
116 if (!view->mode_flags.hex)
117 mcview_ascii_move_up (view, lines);
118 else
119 {
120 off_t bytes;
121
122 bytes = lines * view->bytes_per_line;
123
124 if (view->hex_cursor < bytes)
125 view->hex_cursor %= view->bytes_per_line;
126 else
127 {
128 view->hex_cursor -= bytes;
129 if (view->hex_cursor < view->dpy_start)
130 {
131 view->dpy_start = DOZ (view->dpy_start, bytes);
132 view->dpy_paragraph_skip_lines = 0;
133 view->dpy_wrap_dirty = TRUE;
134 }
135 }
136 }
137
138 mcview_movement_fixups (view, TRUE);
139 }
140
141
142
143 void
144 mcview_move_down (WView *view, off_t lines)
145 {
146 off_t last_byte;
147
148 last_byte = mcview_get_filesize (view);
149
150 if (!view->mode_flags.hex)
151 mcview_ascii_move_down (view, lines);
152 else
153 {
154 off_t i, limit;
155
156 limit = DOZ (last_byte, (off_t) view->bytes_per_line);
157
158 for (i = 0; i < lines && view->hex_cursor < limit; i++)
159 {
160 view->hex_cursor += view->bytes_per_line;
161
162 if (lines != 1)
163 {
164 view->dpy_start += view->bytes_per_line;
165 view->dpy_paragraph_skip_lines = 0;
166 view->dpy_wrap_dirty = TRUE;
167 }
168 }
169 }
170
171 mcview_movement_fixups (view, TRUE);
172 }
173
174
175
176 void
177 mcview_move_left (WView *view, off_t columns)
178 {
179 if (view->mode_flags.hex)
180 {
181 off_t old_cursor = view->hex_cursor;
182
183 g_assert (columns == 1);
184
185 if (view->hexview_in_text || !view->hexedit_lownibble)
186 if (view->hex_cursor > 0)
187 view->hex_cursor--;
188
189 if (!view->hexview_in_text)
190 if (old_cursor > 0 || view->hexedit_lownibble)
191 view->hexedit_lownibble = !view->hexedit_lownibble;
192 }
193 else if (!view->mode_flags.wrap)
194 view->dpy_text_column = DOZ (view->dpy_text_column, columns);
195
196 mcview_movement_fixups (view, FALSE);
197 }
198
199
200
201 void
202 mcview_move_right (WView *view, off_t columns)
203 {
204 if (view->mode_flags.hex)
205 {
206 off_t last_byte;
207 off_t old_cursor = view->hex_cursor;
208
209 last_byte = mcview_get_filesize (view);
210 last_byte = DOZ (last_byte, 1);
211
212 g_assert (columns == 1);
213
214 if (view->hexview_in_text || view->hexedit_lownibble)
215 if (view->hex_cursor < last_byte)
216 view->hex_cursor++;
217
218 if (!view->hexview_in_text)
219 if (old_cursor < last_byte || !view->hexedit_lownibble)
220 view->hexedit_lownibble = !view->hexedit_lownibble;
221 }
222 else if (!view->mode_flags.wrap)
223 view->dpy_text_column += columns;
224
225 mcview_movement_fixups (view, FALSE);
226 }
227
228
229
230 void
231 mcview_moveto_top (WView *view)
232 {
233 view->dpy_start = 0;
234 view->dpy_paragraph_skip_lines = 0;
235 mcview_state_machine_init (&view->dpy_state_top, 0);
236 view->hex_cursor = 0;
237 view->dpy_text_column = 0;
238 mcview_movement_fixups (view, TRUE);
239 }
240
241
242
243 void
244 mcview_moveto_bottom (WView *view)
245 {
246 off_t filesize;
247
248 mcview_update_filesize (view);
249
250 if (view->growbuf_in_use)
251 mcview_growbuf_read_all_data (view);
252
253 filesize = mcview_get_filesize (view);
254
255 if (view->mode_flags.hex)
256 {
257 view->hex_cursor = DOZ (filesize, 1);
258 mcview_movement_fixups (view, TRUE);
259 }
260 else
261 {
262 view->dpy_start = filesize;
263 view->dpy_paragraph_skip_lines = 0;
264 view->dpy_wrap_dirty = TRUE;
265 mcview_move_up (view, view->data_area.lines);
266 }
267 }
268
269
270
271 void
272 mcview_moveto_bol (WView *view)
273 {
274 if (!view->mode_flags.hex)
275 mcview_ascii_moveto_bol (view);
276 else
277 {
278 view->hex_cursor -= view->hex_cursor % view->bytes_per_line;
279 view->dpy_text_column = 0;
280 }
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 mcview_ascii_moveto_eol (view);
294 else
295 {
296 off_t filesize;
297
298 bol = mcview_offset_rounddown (view->hex_cursor, view->bytes_per_line);
299
300 if (mcview_get_byte_indexed (view, bol, view->bytes_per_line - 1, NULL))
301 view->hex_cursor = bol + view->bytes_per_line - 1;
302 else
303 {
304 filesize = mcview_get_filesize (view);
305 view->hex_cursor = DOZ (filesize, 1);
306 }
307 }
308
309 mcview_movement_fixups (view, FALSE);
310 }
311
312
313
314 void
315 mcview_moveto_offset (WView *view, off_t offset)
316 {
317 if (view->mode_flags.hex)
318 {
319 view->hex_cursor = offset;
320 view->dpy_start = offset - offset % view->bytes_per_line;
321 view->dpy_paragraph_skip_lines = 0;
322 view->dpy_wrap_dirty = TRUE;
323 }
324 else
325 {
326 view->dpy_start = offset;
327 view->dpy_paragraph_skip_lines = 0;
328 view->dpy_wrap_dirty = TRUE;
329 }
330
331 mcview_movement_fixups (view, TRUE);
332 }
333
334
335
336 void
337 mcview_moveto (WView *view, off_t line, off_t col)
338 {
339 off_t offset;
340
341 mcview_coord_to_offset (view, &offset, line, col);
342 mcview_moveto_offset (view, offset);
343 }
344
345
346
347 void
348 mcview_coord_to_offset (WView *view, off_t *ret_offset, off_t line, off_t column)
349 {
350 coord_cache_entry_t coord;
351
352 coord.cc_line = line;
353 coord.cc_column = column;
354 coord.cc_nroff_column = column;
355 mcview_ccache_lookup (view, &coord, CCACHE_OFFSET);
356 *ret_offset = coord.cc_offset;
357 }
358
359
360
361 void
362 mcview_offset_to_coord (WView *view, off_t *ret_line, off_t *ret_column, off_t offset)
363 {
364 coord_cache_entry_t coord;
365
366 coord.cc_offset = offset;
367 mcview_ccache_lookup (view, &coord, CCACHE_LINECOL);
368
369 *ret_line = coord.cc_line;
370 *ret_column = view->mode_flags.nroff ? coord.cc_nroff_column : coord.cc_column;
371 }
372
373
374
375 void
376 mcview_place_cursor (WView *view)
377 {
378 const WRect *r = &view->data_area;
379 int col = view->cursor_col;
380
381 if (!view->hexview_in_text && view->hexedit_lownibble)
382 col++;
383
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