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