This source file includes following definitions.
- mcview_set_buttonbar
- mcview_display_percent
- mcview_display_status
- mcview_update
- mcview_display
- mcview_compute_areas
- mcview_update_bytes_per_line
- mcview_display_toggle_ruler
- mcview_display_clean
- mcview_display_ruler
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 #include <config.h>
37 #include <inttypes.h>
38
39 #include "lib/global.h"
40 #include "lib/skin.h"
41 #include "lib/tty/tty.h"
42 #include "lib/tty/key.h"
43 #include "lib/strutil.h"
44 #include "lib/util.h"
45 #include "lib/widget.h"
46 #ifdef HAVE_CHARSET
47 #include "lib/charsets.h"
48 #endif
49
50 #include "src/setup.h"
51 #include "src/keymap.h"
52
53 #include "internal.h"
54
55
56
57
58
59 #define BUF_TRUNC_LEN 5
60
61
62
63
64
65
66 static enum ruler_type
67 {
68 RULER_NONE,
69 RULER_TOP,
70 RULER_BOTTOM
71 } ruler = RULER_NONE;
72
73
74
75
76
77
78 static void
79 mcview_set_buttonbar (WView * view)
80 {
81 Widget *w = WIDGET (view);
82 WDialog *h = DIALOG (w->owner);
83 WButtonBar *b;
84 const global_keymap_t *keymap = view->mode_flags.hex ? view->hex_keymap : w->keymap;
85
86 b = find_buttonbar (h);
87 buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), keymap, w);
88
89 if (view->mode_flags.hex)
90 {
91 if (view->hexedit_mode)
92 buttonbar_set_label (b, 2, Q_ ("ButtonBar|View"), keymap, w);
93 else if (view->datasource == DS_FILE)
94 buttonbar_set_label (b, 2, Q_ ("ButtonBar|Edit"), keymap, w);
95 else
96 buttonbar_set_label (b, 2, "", keymap, WIDGET (view));
97
98 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Ascii"), keymap, w);
99 buttonbar_set_label (b, 6, Q_ ("ButtonBar|Save"), keymap, w);
100 buttonbar_set_label (b, 7, Q_ ("ButtonBar|HxSrch"), keymap, w);
101
102 }
103 else
104 {
105 buttonbar_set_label (b, 2, view->mode_flags.wrap ? Q_ ("ButtonBar|UnWrap")
106 : Q_ ("ButtonBar|Wrap"), keymap, w);
107 buttonbar_set_label (b, 4, Q_ ("ButtonBar|Hex"), keymap, w);
108 buttonbar_set_label (b, 6, "", keymap, WIDGET (view));
109 buttonbar_set_label (b, 7, Q_ ("ButtonBar|Search"), keymap, w);
110 }
111
112 buttonbar_set_label (b, 5, Q_ ("ButtonBar|Goto"), keymap, w);
113 buttonbar_set_label (b, 8, view->mode_flags.magic ? Q_ ("ButtonBar|Raw")
114 : Q_ ("ButtonBar|Parse"), keymap, w);
115
116 if (!mcview_is_in_panel (view))
117 {
118 buttonbar_set_label (b, 3, Q_ ("ButtonBar|Quit"), keymap, w);
119 buttonbar_set_label (b, 9, view->mode_flags.nroff ? Q_ ("ButtonBar|Unform")
120 : Q_ ("ButtonBar|Format"), keymap, w);
121 buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), keymap, w);
122 }
123 }
124
125
126
127 static void
128 mcview_display_percent (WView * view, off_t p)
129 {
130 int percent;
131
132 percent = mcview_calc_percent (view, p);
133 if (percent >= 0)
134 {
135 int top = view->status_area.y;
136 int right;
137
138 right = view->status_area.x + view->status_area.cols;
139 widget_gotoyx (view, top, right - 4);
140 tty_printf ("%3d%%", percent);
141
142 widget_gotoyx (view, top, right - 1);
143 }
144 }
145
146
147
148 static void
149 mcview_display_status (WView * view)
150 {
151 const WRect *r = &view->status_area;
152 const char *file_label;
153
154 if (r->lines < 1)
155 return;
156
157 tty_setcolor (STATUSBAR_COLOR);
158 tty_draw_hline (WIDGET (view)->rect.y + r->y, WIDGET (view)->rect.x + r->x, ' ', r->cols);
159
160 file_label =
161 view->filename_vpath != NULL ?
162 vfs_path_get_last_path_str (view->filename_vpath) : view->command != NULL ?
163 view->command : "";
164
165 if (r->cols > 40)
166 {
167 widget_gotoyx (view, r->y, r->cols - 32);
168 if (view->mode_flags.hex)
169 tty_printf ("0x%08" PRIxMAX, (uintmax_t) view->hex_cursor);
170 else
171 {
172 char buffer[BUF_TRUNC_LEN + 1];
173
174 size_trunc_len (buffer, BUF_TRUNC_LEN, mcview_get_filesize (view), 0,
175 panels_options.kilobyte_si);
176 tty_printf ("%9" PRIuMAX "/%s%s %s", (uintmax_t) view->dpy_end,
177 buffer, mcview_may_still_grow (view) ? "+" : " ",
178 #ifdef HAVE_CHARSET
179 mc_global.source_codepage >= 0 ?
180 get_codepage_id (mc_global.source_codepage) :
181 #endif
182 "");
183 }
184 }
185 widget_gotoyx (view, r->y, r->x);
186 if (r->cols > 40)
187 tty_print_string (str_fit_to_term (file_label, r->cols - 34, J_LEFT_FIT));
188 else
189 tty_print_string (str_fit_to_term (file_label, r->cols - 5, J_LEFT_FIT));
190 if (r->cols > 26)
191 mcview_display_percent (view, view->mode_flags.hex ? view->hex_cursor : view->dpy_end);
192 }
193
194
195
196
197
198 void
199 mcview_update (WView * view)
200 {
201 static int dirt_limit = 1;
202
203 if (view->dpy_bbar_dirty)
204 {
205 view->dpy_bbar_dirty = FALSE;
206 mcview_set_buttonbar (view);
207 widget_draw (WIDGET (find_buttonbar (DIALOG (WIDGET (view)->owner))));
208 }
209
210 if (view->dirty > dirt_limit)
211 {
212
213 mcview_display (view);
214 view->dirty = 0;
215
216 dirt_limit++;
217 if (dirt_limit > mcview_max_dirt_limit)
218 dirt_limit = mcview_max_dirt_limit;
219 }
220 else if (view->dirty > 0)
221 {
222 if (is_idle ())
223 {
224
225 mcview_display (view);
226 view->dirty = 0;
227 if (dirt_limit > 1)
228 dirt_limit--;
229 }
230 else
231 {
232
233
234 mcview_display_status (view);
235 }
236
237
238 }
239 }
240
241
242
243
244 void
245 mcview_display (WView * view)
246 {
247 if (view->mode_flags.hex)
248 mcview_display_hex (view);
249 else
250 mcview_display_text (view);
251 mcview_display_status (view);
252 }
253
254
255
256 void
257 mcview_compute_areas (WView * view)
258 {
259 WRect view_area;
260 int height, rest, y;
261
262
263
264
265
266
267 view_area.y = view->dpy_frame_size;
268 view_area.x = view->dpy_frame_size;
269 view_area.lines = DOZ (WIDGET (view)->rect.lines, 2 * view->dpy_frame_size);
270 view_area.cols = DOZ (WIDGET (view)->rect.cols, 2 * view->dpy_frame_size);
271
272
273 view->status_area = view_area;
274 view->ruler_area = view_area;
275 view->data_area = view_area;
276
277
278 rest = view_area.lines;
279
280 height = MIN (rest, 1);
281 view->status_area.lines = height;
282 rest -= height;
283
284 height = (ruler == RULER_NONE || view->mode_flags.hex) ? 0 : 2;
285 height = MIN (rest, height);
286 view->ruler_area.lines = height;
287 rest -= height;
288
289 view->data_area.lines = rest;
290
291
292 y = view_area.y;
293
294 view->status_area.y = y;
295 y += view->status_area.lines;
296
297 if (ruler == RULER_TOP)
298 {
299 view->ruler_area.y = y;
300 y += view->ruler_area.lines;
301 }
302
303 view->data_area.y = y;
304 y += view->data_area.lines;
305
306 if (ruler == RULER_BOTTOM)
307 view->ruler_area.y = y;
308 }
309
310
311
312 void
313 mcview_update_bytes_per_line (WView * view)
314 {
315 int cols = view->data_area.cols;
316 int bytes;
317
318 if (cols < 9 + 17)
319 bytes = 4;
320 else
321 bytes = 4 * ((cols - 9) / ((cols <= 80) ? 17 : 18));
322
323 g_assert (bytes != 0);
324
325 view->bytes_per_line = bytes;
326 view->dirty = mcview_max_dirt_limit + 1;
327 }
328
329
330
331 void
332 mcview_display_toggle_ruler (WView * view)
333 {
334 static const enum ruler_type next[3] =
335 {
336 RULER_TOP,
337 RULER_BOTTOM,
338 RULER_NONE
339 };
340
341 g_assert ((size_t) ruler < 3);
342
343 ruler = next[(size_t) ruler];
344 mcview_compute_areas (view);
345 view->dirty++;
346 }
347
348
349
350 void
351 mcview_display_clean (WView * view)
352 {
353 Widget *w = WIDGET (view);
354
355 tty_setcolor (VIEW_NORMAL_COLOR);
356 widget_erase (w);
357 if (view->dpy_frame_size != 0)
358 tty_draw_box (w->rect.y, w->rect.x, w->rect.lines, w->rect.cols, FALSE);
359 }
360
361
362
363 void
364 mcview_display_ruler (WView * view)
365 {
366 static const char ruler_chars[] = "|----*----";
367 const WRect *r = &view->ruler_area;
368 const int line_row = (ruler == RULER_TOP) ? 0 : 1;
369 const int nums_row = (ruler == RULER_TOP) ? 1 : 0;
370
371 char r_buff[10];
372 off_t cl;
373 int c;
374
375 if (ruler == RULER_NONE || r->lines < 1)
376 return;
377
378 tty_setcolor (VIEW_BOLD_COLOR);
379 for (c = 0; c < r->cols; c++)
380 {
381 cl = view->dpy_text_column + c;
382 if (line_row < r->lines)
383 {
384 widget_gotoyx (view, r->y + line_row, r->x + c);
385 tty_print_char (ruler_chars[cl % 10]);
386 }
387
388 if ((cl != 0) && (cl % 10) == 0)
389 {
390 g_snprintf (r_buff, sizeof (r_buff), "%" PRIuMAX, (uintmax_t) cl);
391 if (nums_row < r->lines)
392 {
393 widget_gotoyx (view, r->y + nums_row, r->x + c - 1);
394 tty_print_string (r_buff);
395 }
396 }
397 }
398 tty_setcolor (VIEW_NORMAL_COLOR);
399 }
400
401