This source file includes following definitions.
- printwstr
- status_string
- edit_status_fullscreen
- edit_status_window
- edit_draw_frame
- edit_draw_window_icons
- print_to_widget
- edit_draw_this_line
- edit_draw_this_char
- render_edit_text
- edit_render
- edit_status
- edit_scroll_screen_over_cursor
- edit_render_keypress
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 #include <config.h>
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <stdarg.h>
38 #include <sys/types.h>
39 #include <unistd.h>
40 #include <string.h>
41 #include <ctype.h>
42 #include <sys/stat.h>
43
44 #include "lib/global.h"
45 #include "lib/tty/tty.h"
46 #include "lib/tty/key.h"
47 #include "lib/skin.h"
48 #include "lib/strutil.h"
49 #include "lib/util.h"
50 #include "lib/widget.h"
51 #include "lib/charsets.h"
52
53 #include "edit-impl.h"
54 #include "editwidget.h"
55
56
57
58
59
60 #define MAX_LINE_LEN 1024
61
62
63 #define MOD_ABNORMAL (1 << 8)
64 #define MOD_BOLD (1 << 9)
65 #define MOD_MARKED (1 << 10)
66 #define MOD_CURSOR (1 << 11)
67 #define MOD_WHITESPACE (1 << 12)
68
69 #define edit_move(x, y) widget_gotoyx (edit, y, x);
70
71 #define key_pending(x) (!is_idle ())
72
73 #define EDITOR_MINIMUM_TERMINAL_WIDTH 30
74
75
76
77 typedef struct
78 {
79 unsigned int ch;
80 unsigned int style;
81 } line_s;
82
83
84
85
86
87
88
89 static inline void
90 printwstr (const char *s, int len)
91 {
92 if (len > 0)
93 tty_printf ("%-*.*s", len, len, s);
94 }
95
96
97
98 static inline void
99 status_string (WEdit *edit, char *s, int w)
100 {
101 char byte_str[16];
102
103
104
105
106
107
108 if (edit->buffer.curs1 >= edit->buffer.size)
109 strcpy (byte_str, "<EOF> ");
110 else if (edit->utf8)
111 {
112 unsigned int cur_utf;
113 int char_length = 1;
114
115 cur_utf = edit_buffer_get_utf (&edit->buffer, edit->buffer.curs1, &char_length);
116 if (char_length > 0)
117 g_snprintf (byte_str, sizeof (byte_str), "%04u 0x%03X", (unsigned) cur_utf,
118 (unsigned) cur_utf);
119 else
120 {
121 cur_utf = edit_buffer_get_current_byte (&edit->buffer);
122 g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X", (int) cur_utf,
123 (unsigned) cur_utf);
124 }
125 }
126 else
127 {
128 unsigned char cur_byte;
129
130 cur_byte = edit_buffer_get_current_byte (&edit->buffer);
131 g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X", (int) cur_byte, (unsigned) cur_byte);
132 }
133
134
135 if (edit_options.simple_statusbar)
136 g_snprintf (s, w, "%c%c%c%c %3ld %5ld/%ld %6ld/%ld %s %s",
137 edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-',
138 edit->modified != 0 ? 'M' : '-',
139 macro_index < 0 ? '-' : 'R',
140 edit->overwrite == 0 ? '-' : 'O',
141 edit->curs_col + edit->over_col,
142 edit->buffer.curs_line + 1,
143 edit->buffer.lines + 1,
144 (long) edit->buffer.curs1,
145 (long) edit->buffer.size,
146 byte_str,
147 mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage)
148 : "");
149 else
150 g_snprintf (s, w, "[%c%c%c%c] %2ld L:[%3ld+%2ld %3ld/%3ld] *(%-4ld/%4ldb) %s %s",
151 edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-',
152 edit->modified != 0 ? 'M' : '-',
153 macro_index < 0 ? '-' : 'R',
154 edit->overwrite == 0 ? '-' : 'O',
155 edit->curs_col + edit->over_col,
156 edit->start_line + 1,
157 edit->curs_row,
158 edit->buffer.curs_line + 1,
159 edit->buffer.lines + 1,
160 (long) edit->buffer.curs1,
161 (long) edit->buffer.size,
162 byte_str,
163 mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage)
164 : "");
165 }
166
167
168
169
170
171
172
173
174
175 static inline void
176 edit_status_fullscreen (WEdit *edit, int color)
177 {
178 Widget *h = WIDGET (WIDGET (edit)->owner);
179 const int w = h->rect.cols;
180 const int gap = 3;
181 const int right_gap = 5;
182 const int preferred_fname_len = 16;
183 char *status;
184 size_t status_size;
185 int status_len;
186 const char *fname = "";
187 int fname_len;
188
189 status_size = w + 1;
190 status = g_malloc (status_size);
191 status_string (edit, status, status_size);
192 status_len = (int) str_term_width1 (status);
193
194 if (edit->filename_vpath != NULL)
195 {
196 fname = vfs_path_get_last_path_str (edit->filename_vpath);
197
198 if (!edit_options.state_full_filename)
199 fname = x_basename (fname);
200 }
201
202 fname_len = str_term_width1 (fname);
203 if (fname_len < preferred_fname_len)
204 fname_len = preferred_fname_len;
205
206 if (fname_len + gap + status_len + right_gap >= w)
207 {
208 if (preferred_fname_len + gap + status_len + right_gap >= w)
209 fname_len = preferred_fname_len;
210 else
211 fname_len = w - (gap + status_len + right_gap);
212 fname = str_trunc (fname, fname_len);
213 }
214
215 widget_gotoyx (h, 0, 0);
216 tty_setcolor (color);
217 printwstr (fname, fname_len + gap);
218 printwstr (status, w - (fname_len + gap));
219
220 if (edit_options.simple_statusbar && w > EDITOR_MINIMUM_TERMINAL_WIDTH)
221 {
222 int percent;
223
224 percent = edit_buffer_calc_percent (&edit->buffer, edit->buffer.curs1);
225 widget_gotoyx (h, 0, w - 6 - 6);
226 tty_printf (" %3d%%", percent);
227 }
228
229 g_free (status);
230 }
231
232
233
234
235
236
237
238
239 static inline void
240 edit_status_window (WEdit *edit)
241 {
242 Widget *w = WIDGET (edit);
243 int y, x;
244 int cols = w->rect.cols;
245
246 tty_setcolor (STATUSBAR_COLOR);
247
248 if (cols > 5)
249 {
250 const char *fname = N_ ("NoName");
251
252 if (edit->filename_vpath != NULL)
253 {
254 fname = vfs_path_get_last_path_str (edit->filename_vpath);
255
256 if (!edit_options.state_full_filename)
257 fname = x_basename (fname);
258 }
259 #ifdef ENABLE_NLS
260 else
261 fname = _ (fname);
262 #endif
263
264 edit_move (2, 0);
265 tty_printf ("[%s]", str_term_trim (fname, w->rect.cols - 8 - 6));
266 }
267
268 tty_getyx (&y, &x);
269 x -= w->rect.x;
270 x += 4;
271 if (x + 6 <= cols - 2 - 6)
272 {
273 edit_move (x, 0);
274 tty_printf ("[%c%c%c%c]",
275 edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-',
276 edit->modified != 0 ? 'M' : '-', macro_index < 0 ? '-' : 'R',
277 edit->overwrite == 0 ? '-' : 'O');
278 }
279
280 if (cols > 30)
281 {
282 edit_move (2, w->rect.lines - 1);
283 tty_printf ("%3ld %5ld/%ld %6ld/%ld", edit->curs_col + edit->over_col,
284 edit->buffer.curs_line + 1, edit->buffer.lines + 1, (long) edit->buffer.curs1,
285 (long) edit->buffer.size);
286 }
287
288
289
290
291
292
293 if (cols > 46)
294 {
295 edit_move (32, w->rect.lines - 1);
296 if (edit->buffer.curs1 >= edit->buffer.size)
297 tty_print_string ("[<EOF> ]");
298 else if (edit->utf8)
299 {
300 unsigned int cur_utf;
301 int char_length = 1;
302
303 cur_utf = edit_buffer_get_utf (&edit->buffer, edit->buffer.curs1, &char_length);
304 if (char_length <= 0)
305 cur_utf = edit_buffer_get_current_byte (&edit->buffer);
306 tty_printf ("[%05u 0x%04X]", cur_utf, cur_utf);
307 }
308 else
309 {
310 unsigned char cur_byte;
311
312 cur_byte = edit_buffer_get_current_byte (&edit->buffer);
313 tty_printf ("[%05u 0x%04X]", (unsigned int) cur_byte, (unsigned int) cur_byte);
314 }
315 }
316 }
317
318
319
320
321
322
323
324
325
326
327 static inline void
328 edit_draw_frame (const WEdit *edit, int color, gboolean active)
329 {
330 const Widget *w = CONST_WIDGET (edit);
331
332
333 tty_setcolor (color);
334
335 tty_draw_box (w->rect.y, w->rect.x, w->rect.lines, w->rect.cols, !active);
336
337 if (edit->drag_state == MCEDIT_DRAG_NONE)
338 {
339 tty_setcolor (EDITOR_FRAME_DRAG);
340 widget_gotoyx (w, w->rect.lines - 1, w->rect.cols - 1);
341 tty_print_alt_char (ACS_LRCORNER, TRUE);
342 }
343 }
344
345
346
347
348
349
350
351
352
353 static inline void
354 edit_draw_window_icons (const WEdit *edit, int color)
355 {
356 const Widget *w = CONST_WIDGET (edit);
357 char tmp[17];
358
359 tty_setcolor (color);
360 if (edit->fullscreen != 0)
361 widget_gotoyx (w->owner, 0, WIDGET (w->owner)->rect.cols - 6);
362 else
363 widget_gotoyx (w, 0, w->rect.cols - 8);
364 g_snprintf (tmp, sizeof (tmp), "[%s][%s]", edit_window_state_char, edit_window_close_char);
365 tty_print_string (tmp);
366 }
367
368
369
370 static inline void
371 print_to_widget (WEdit *edit, long row, int start_col, int start_col_real, long end_col,
372 line_s line[], char *status, int bookmarked)
373 {
374 Widget *w = WIDGET (edit);
375 line_s *p;
376 int x, x1, y, cols_to_skip;
377 int i;
378 int wrap_start;
379 int len;
380
381 x = start_col_real;
382 x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width;
383 y = row + EDIT_TEXT_VERTICAL_OFFSET;
384 cols_to_skip = abs (x);
385
386 if (edit->fullscreen == 0)
387 {
388 x1++;
389 y++;
390 }
391
392 tty_setcolor (EDITOR_NORMAL_COLOR);
393 if (bookmarked != 0)
394 tty_setcolor (bookmarked);
395
396 len = end_col + 1 - start_col;
397 wrap_start = edit_options.word_wrap_line_length + edit->start_col;
398
399 if (len > 0 && w->rect.y + y >= 0)
400 {
401 if (!edit_options.show_right_margin || wrap_start > end_col)
402 tty_draw_hline (w->rect.y + y, w->rect.x + x1, ' ', len);
403 else if (wrap_start < 0)
404 {
405 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
406 tty_draw_hline (w->rect.y + y, w->rect.x + x1, ' ', len);
407 }
408 else
409 {
410 if (wrap_start > 0)
411 tty_draw_hline (w->rect.y + y, w->rect.x + x1, ' ', wrap_start);
412
413 len -= wrap_start;
414 if (len > 0)
415 {
416 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
417 tty_draw_hline (w->rect.y + y, w->rect.x + x1 + wrap_start, ' ', len);
418 }
419 }
420 }
421
422 if (edit_options.line_state)
423 {
424 tty_setcolor (LINE_STATE_COLOR);
425
426 for (i = 0; i < LINE_STATE_WIDTH; i++)
427 {
428 edit_move (x1 + i - edit_options.line_state_width, y);
429 if (status[i] == '\0')
430 status[i] = ' ';
431 tty_print_char (status[i]);
432 }
433 }
434
435 edit_move (x1, y);
436
437 i = 1;
438 for (p = line; p->ch != 0; p++)
439 {
440 int style;
441 unsigned int textchar;
442
443 if (cols_to_skip != 0)
444 {
445 cols_to_skip--;
446 continue;
447 }
448
449 style = p->style & 0xFF00;
450 textchar = p->ch;
451
452 if ((style & MOD_WHITESPACE) != 0)
453 {
454 if ((style & MOD_MARKED) == 0)
455 tty_setcolor (EDITOR_WHITESPACE_COLOR);
456 else
457 {
458 textchar = ' ';
459 tty_setcolor (EDITOR_MARKED_COLOR);
460 }
461 }
462 else if ((style & MOD_BOLD) != 0)
463 tty_setcolor (EDITOR_BOLD_COLOR);
464 else if ((style & MOD_MARKED) != 0)
465 tty_setcolor (EDITOR_MARKED_COLOR);
466 else if ((style & MOD_ABNORMAL) != 0)
467 tty_setcolor (EDITOR_NONPRINTABLE_COLOR);
468 else
469 tty_lowlevel_setcolor (p->style >> 16);
470
471 if (edit_options.show_right_margin)
472 {
473 if (i > edit_options.word_wrap_line_length + edit->start_col)
474 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
475 i++;
476 }
477
478 tty_print_anychar (textchar);
479 }
480 }
481
482
483
484
485 static void
486 edit_draw_this_line (WEdit *edit, off_t b, long row, long start_col, long end_col)
487 {
488 Widget *w = WIDGET (edit);
489 line_s line[MAX_LINE_LEN];
490 line_s *p = line;
491 off_t q;
492 int col, start_col_real;
493 int abn_style;
494 int book_mark = 0;
495 char line_stat[LINE_STATE_WIDTH + 1] = "\0";
496
497 if (row > w->rect.lines - 1 - EDIT_TEXT_VERTICAL_OFFSET - 2 * (edit->fullscreen != 0 ? 0 : 1))
498 return;
499
500 if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_COLOR))
501 book_mark = BOOK_MARK_COLOR;
502 else if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_FOUND_COLOR))
503 book_mark = BOOK_MARK_FOUND_COLOR;
504
505 if (book_mark != 0)
506 abn_style = book_mark << 16;
507 else
508 abn_style = MOD_ABNORMAL;
509
510 end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width;
511 if (edit->fullscreen == 0)
512 {
513 end_col--;
514 if (w->rect.x + w->rect.cols <= WIDGET (w->owner)->rect.cols)
515 end_col--;
516 }
517
518 q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
519 col = (int) edit_move_forward3 (edit, b, 0, q);
520 start_col_real = col + edit->start_col;
521
522 if (edit_options.line_state)
523 {
524 long cur_line;
525
526 cur_line = edit->start_line + row;
527 if (cur_line <= edit->buffer.lines)
528 g_snprintf (line_stat, sizeof (line_stat), "%7ld ", cur_line + 1);
529 else
530 {
531 memset (line_stat, ' ', LINE_STATE_WIDTH);
532 line_stat[LINE_STATE_WIDTH] = '\0';
533 }
534
535 if (book_mark_query_color (edit, cur_line, BOOK_MARK_COLOR))
536 g_snprintf (line_stat, 2, "*");
537 }
538
539 if (col <= -(edit->start_col + 16))
540 start_col_real = start_col = 0;
541 else
542 {
543 off_t m1 = 0, m2 = 0;
544
545 eval_marks (edit, &m1, &m2);
546
547 if (row <= edit->buffer.lines - edit->start_line)
548 {
549 off_t tws = 0;
550
551 if (edit_options.visible_tws && tty_use_colors ())
552 for (tws = edit_buffer_get_eol (&edit->buffer, b); tws > b; tws--)
553 {
554 unsigned int c;
555
556 c = edit_buffer_get_byte (&edit->buffer, tws - 1);
557 if (!whitespace (c))
558 break;
559 }
560
561 while (col <= end_col - edit->start_col)
562 {
563 int char_length = 1;
564 unsigned int c;
565 gboolean wide_width_char = FALSE;
566 gboolean control_char = FALSE;
567 gboolean printable;
568
569 p->ch = 0;
570 p->style = q == edit->buffer.curs1 ? MOD_CURSOR : 0;
571
572 if (q >= m1 && q < m2)
573 {
574 if (!edit->column_highlight)
575 p->style |= MOD_MARKED;
576 else
577 {
578 long x, cl;
579
580 x = (long) edit_move_forward3 (edit, b, 0, q);
581 cl = MIN (edit->column1, edit->column2);
582 if (x >= cl)
583 {
584 cl = MAX (edit->column1, edit->column2);
585 if (x < cl)
586 p->style |= MOD_MARKED;
587 }
588 }
589 }
590
591 if (q == edit->bracket)
592 p->style |= MOD_BOLD;
593 if (q >= edit->found_start && q < (off_t) (edit->found_start + edit->found_len))
594 p->style |= MOD_BOLD;
595
596 if (edit->utf8)
597 c = edit_buffer_get_utf (&edit->buffer, q, &char_length);
598 else
599 c = edit_buffer_get_byte (&edit->buffer, q);
600
601
602 if (book_mark != 0)
603 p->style |= book_mark << 16;
604 else
605 {
606 int color;
607
608 color = edit_get_syntax_color (edit, q);
609 p->style |= color << 16;
610 }
611
612 switch (c)
613 {
614 case '\n':
615 col = end_col - edit->start_col + 1;
616 break;
617
618 case '\t':
619 {
620 int tab_over;
621 int i;
622
623 i = TAB_SIZE - ((int) col % TAB_SIZE);
624 tab_over = (end_col - edit->start_col) - (col + i - 1);
625 if (tab_over < 0)
626 i += tab_over;
627 col += i;
628 if ((edit_options.visible_tabs || (edit_options.visible_tws && q >= tws))
629 && enable_show_tabs_tws && tty_use_colors ())
630 {
631 int style;
632
633 if ((p->style & MOD_MARKED) != 0)
634 style = p->style;
635 else if (book_mark != 0)
636 style = c | (book_mark << 16);
637 else
638 style = p->style | MOD_WHITESPACE;
639 if (i > 2)
640 {
641 p->ch = '<';
642 p->style = style;
643 p++;
644 while (--i > 1)
645 {
646 p->ch = '-';
647 p->style = style;
648 p++;
649 }
650 p->ch = '>';
651 p->style = style;
652 p++;
653 }
654 else if (i > 1)
655 {
656 p->ch = '<';
657 p->style = style;
658 p++;
659 p->ch = '>';
660 p->style = style;
661 p++;
662 }
663 else
664 {
665 p->ch = '>';
666 p->style = style;
667 p++;
668 }
669 }
670 else if (edit_options.visible_tws && q >= tws && enable_show_tabs_tws
671 && tty_use_colors ())
672 {
673 p->ch = '.';
674 p->style |= MOD_WHITESPACE;
675
676 const int style = p->style & ~MOD_CURSOR;
677
678 p++;
679 while (--i != 0)
680 {
681 p->ch = ' ';
682 p->style = style;
683 p++;
684 }
685 }
686 else
687 {
688 p->ch |= ' ';
689
690 const int style = p->style & ~MOD_CURSOR;
691
692 p++;
693 while (--i != 0)
694 {
695 p->ch = ' ';
696 p->style = style;
697 p++;
698 }
699 }
700 }
701 break;
702
703 case ' ':
704 if (edit_options.visible_tws && q >= tws && enable_show_tabs_tws
705 && tty_use_colors ())
706 {
707 p->ch = '.';
708 p->style |= MOD_WHITESPACE;
709 p++;
710 col++;
711 break;
712 }
713 MC_FALLTHROUGH;
714
715 default:
716 if (mc_global.utf8_display)
717 {
718 if (!edit->utf8)
719 c = convert_from_8bit_to_utf_c ((unsigned char) c, edit->converter);
720 else if (g_unichar_iswide (c))
721 {
722 wide_width_char = TRUE;
723 col++;
724 }
725 }
726 else if (edit->utf8)
727 c = convert_from_utf_to_current_c (c, edit->converter);
728 else
729 c = convert_to_display_c (c);
730
731
732 if (c < 32)
733 {
734 p->ch = '^';
735 p->style = abn_style;
736 p++;
737 p->ch = c + 0x40;
738 p->style = abn_style;
739 p++;
740 col += 2;
741 control_char = TRUE;
742 break;
743 }
744 if (c == 127)
745 {
746 p->ch = '^';
747 p->style = abn_style;
748 p++;
749 p->ch = '?';
750 p->style = abn_style;
751 p++;
752 col += 2;
753 control_char = TRUE;
754 break;
755 }
756
757 if (edit->utf8)
758 {
759 if (mc_global.utf8_display)
760
761 printable = g_unichar_isprint (c);
762 else
763
764 printable = is_printable (c);
765 }
766 else
767
768 printable = is_printable (c);
769
770 if (printable)
771 p->ch = c;
772 else
773 {
774 p->ch = '.';
775 p->style = abn_style;
776 }
777 p++;
778 col++;
779 break;
780 }
781
782 q++;
783 if (char_length > 1)
784 q += char_length - 1;
785
786 if (col > (end_col - edit->start_col + 1))
787 {
788 if (wide_width_char)
789 {
790 p--;
791 break;
792 }
793 if (control_char)
794 {
795 p -= 2;
796 break;
797 }
798 }
799 }
800 }
801 }
802
803 p->ch = 0;
804
805 print_to_widget (edit, row, start_col, start_col_real, end_col, line, line_stat, book_mark);
806 }
807
808
809
810 static inline void
811 edit_draw_this_char (WEdit *edit, off_t curs, long row, long start_column, long end_column)
812 {
813 off_t b;
814
815 b = edit_buffer_get_bol (&edit->buffer, curs);
816 edit_draw_this_line (edit, b, row, start_column, end_column);
817 }
818
819
820
821
822 static inline void
823 render_edit_text (WEdit *edit, long start_row, long start_column, long end_row, long end_column)
824 {
825 static long prev_curs_row = 0;
826 static off_t prev_curs = 0;
827
828 Widget *we = WIDGET (edit);
829 Widget *wh = WIDGET (we->owner);
830 WRect *w = &we->rect;
831
832 int force = edit->force;
833 int y1, x1, y2, x2;
834 int last_line, last_column;
835
836
837
838 last_line = wh->rect.y + wh->rect.lines - 1;
839
840 y1 = w->y;
841 if (y1 > last_line - 1)
842 return;
843
844 last_column = wh->rect.x + wh->rect.cols - 1;
845
846 x1 = w->x;
847 if (x1 > last_column)
848 return;
849
850 y2 = w->y + w->lines - 1;
851 if (y2 < wh->rect.y + 1)
852 return;
853
854 x2 = w->x + w->cols - 1;
855 if (x2 < wh->rect.x)
856 return;
857
858 if ((force & REDRAW_IN_BOUNDS) == 0)
859 {
860
861
862
863 if (y2 <= last_line - 1)
864 end_row = w->lines - 1;
865 else if (y1 >= wh->rect.y + 1)
866 end_row = wh->rect.lines - 1 - y1 - 1;
867 else
868 end_row = start_row + wh->rect.lines - 1 - 1;
869
870 if (x2 <= last_column)
871 end_column = w->cols - 1;
872 else if (x1 >= wh->rect.x)
873 end_column = wh->rect.cols - 1 - x1;
874 else
875 end_column = start_column + wh->rect.cols - 1;
876 }
877
878
879
880
881
882 if ((force & REDRAW_CHAR_ONLY) == 0 || (force & REDRAW_PAGE) != 0)
883 {
884 long row = 0;
885 long b;
886
887 if ((force & REDRAW_PAGE) != 0)
888 {
889 b = edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, start_row, 0);
890 for (row = start_row; row <= end_row; row++)
891 {
892 if (key_pending (edit))
893 return;
894 edit_draw_this_line (edit, b, row, start_column, end_column);
895 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0);
896 }
897 }
898 else
899 {
900 long curs_row = edit->curs_row;
901
902 if ((force & REDRAW_BEFORE_CURSOR) != 0 && start_row < curs_row)
903 {
904 long upto;
905
906 b = edit->start_display;
907 upto = MIN (curs_row - 1, end_row);
908 for (row = start_row; row <= upto; row++)
909 {
910 if (key_pending (edit))
911 return;
912 edit_draw_this_line (edit, b, row, start_column, end_column);
913 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0);
914 }
915 }
916
917
918 b = edit_buffer_get_current_bol (&edit->buffer);
919 if (curs_row >= start_row && curs_row <= end_row)
920 {
921 if (key_pending (edit))
922 return;
923 edit_draw_this_line (edit, b, curs_row, start_column, end_column);
924 }
925
926 if ((force & REDRAW_AFTER_CURSOR) != 0 && end_row > curs_row)
927 {
928 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0);
929 for (row = MAX (curs_row + 1, start_row); row <= end_row; row++)
930 {
931 if (key_pending (edit))
932 return;
933 edit_draw_this_line (edit, b, row, start_column, end_column);
934 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0);
935 }
936 }
937
938 if ((force & REDRAW_LINE_ABOVE) != 0 && curs_row >= 1)
939 {
940 row = curs_row - 1;
941 b = edit_buffer_get_current_bol (&edit->buffer);
942 b = edit_buffer_get_backward_offset (&edit->buffer, b, 1);
943 if (row >= start_row && row <= end_row)
944 {
945 if (key_pending (edit))
946 return;
947 edit_draw_this_line (edit, b, row, start_column, end_column);
948 }
949 }
950
951 if ((force & REDRAW_LINE_BELOW) != 0 && row < w->lines - 1)
952 {
953 row = curs_row + 1;
954 b = edit_buffer_get_current_bol (&edit->buffer);
955 b = edit_buffer_get_forward_offset (&edit->buffer, b, 1, 0);
956 if (row >= start_row && row <= end_row)
957 {
958 if (key_pending (edit))
959 return;
960 edit_draw_this_line (edit, b, row, start_column, end_column);
961 }
962 }
963 }
964 }
965 else if (prev_curs_row < edit->curs_row)
966 {
967
968 edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);
969 edit_draw_this_char (edit, edit->buffer.curs1, edit->curs_row, start_column, end_column);
970 }
971 else
972 {
973 edit_draw_this_char (edit, edit->buffer.curs1, edit->curs_row, start_column, end_column);
974 edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);
975 }
976
977 edit->force = 0;
978
979 prev_curs_row = edit->curs_row;
980 prev_curs = edit->buffer.curs1;
981 }
982
983
984
985 static inline void
986 edit_render (WEdit *edit, int page, int row_start, int col_start, int row_end, int col_end)
987 {
988 if (page != 0)
989 edit->force |= REDRAW_PAGE | REDRAW_IN_BOUNDS;
990
991 render_edit_text (edit, row_start, col_start, row_end, col_end);
992
993
994
995
996
997
998 if (edit->force != 0)
999 edit->force |= REDRAW_PAGE;
1000 }
1001
1002
1003
1004
1005
1006 void
1007 edit_status (WEdit *edit, gboolean active)
1008 {
1009 int color;
1010
1011 if (edit->fullscreen != 0)
1012 {
1013 color = STATUSBAR_COLOR;
1014 edit_status_fullscreen (edit, color);
1015 }
1016 else
1017 {
1018 color = edit->drag_state != MCEDIT_DRAG_NONE ? EDITOR_FRAME_DRAG
1019 : active ? EDITOR_FRAME_ACTIVE
1020 : EDITOR_FRAME;
1021 edit_draw_frame (edit, color, active);
1022 edit_status_window (edit);
1023 }
1024
1025 edit_draw_window_icons (edit, color);
1026 }
1027
1028
1029
1030
1031 void
1032 edit_scroll_screen_over_cursor (WEdit *edit)
1033 {
1034 WRect *w = &WIDGET (edit)->rect;
1035
1036 long p;
1037 long outby;
1038 int b_extreme, t_extreme, l_extreme, r_extreme;
1039
1040 if (w->lines <= 0 || w->cols <= 0)
1041 return;
1042
1043 rect_resize (w, -EDIT_TEXT_VERTICAL_OFFSET,
1044 -(EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width));
1045
1046 if (edit->fullscreen == 0)
1047 rect_grow (w, -1, -1);
1048
1049 r_extreme = EDIT_RIGHT_EXTREME;
1050 l_extreme = EDIT_LEFT_EXTREME;
1051 b_extreme = EDIT_BOTTOM_EXTREME;
1052 t_extreme = EDIT_TOP_EXTREME;
1053 if (edit->found_len != 0)
1054 {
1055 b_extreme = MAX (w->lines / 4, b_extreme);
1056 t_extreme = MAX (w->lines / 4, t_extreme);
1057 }
1058 if (b_extreme + t_extreme + 1 > w->lines)
1059 {
1060 int n;
1061
1062 n = b_extreme + t_extreme;
1063 if (n == 0)
1064 n = 1;
1065 b_extreme = (b_extreme * (w->lines - 1)) / n;
1066 t_extreme = (t_extreme * (w->lines - 1)) / n;
1067 }
1068 if (l_extreme + r_extreme + 1 > w->cols)
1069 {
1070 int n;
1071
1072 n = l_extreme + r_extreme;
1073 if (n == 0)
1074 n = 1;
1075 l_extreme = (l_extreme * (w->cols - 1)) / n;
1076 r_extreme = (r_extreme * (w->cols - 1)) / n;
1077 }
1078 p = edit_get_col (edit) + edit->over_col;
1079 edit_update_curs_row (edit);
1080 outby = p + edit->start_col - w->cols + 1 + (r_extreme + edit->found_len);
1081 if (outby > 0)
1082 edit_scroll_right (edit, outby);
1083 outby = l_extreme - p - edit->start_col;
1084 if (outby > 0)
1085 edit_scroll_left (edit, outby);
1086 p = edit->curs_row;
1087 outby = p - w->lines + 1 + b_extreme;
1088 if (outby > 0)
1089 edit_scroll_downward (edit, outby);
1090 outby = t_extreme - p;
1091 if (outby > 0)
1092 edit_scroll_upward (edit, outby);
1093 edit_update_curs_row (edit);
1094
1095 rect_resize (w, EDIT_TEXT_VERTICAL_OFFSET,
1096 EDIT_TEXT_HORIZONTAL_OFFSET + edit_options.line_state_width);
1097 if (edit->fullscreen == 0)
1098 rect_grow (w, 1, 1);
1099 }
1100
1101
1102
1103 void
1104 edit_render_keypress (WEdit *edit)
1105 {
1106 edit_render (edit, 0, 0, 0, 0, 0);
1107 }
1108
1109