code indentation
[midnight-commander.git] / src / editor / editdraw.c
blob53030b2dbc912f55621faf68eba4a1faffbda26d
1 /*
2 Editor text drawing.
4 Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006,
5 2007, 2011
6 The Free Software Foundation, Inc.
8 Written by:
9 Paul Sheer, 1996, 1997
11 This file is part of the Midnight Commander.
13 The Midnight Commander is free software: you can redistribute it
14 and/or modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation, either version 3 of the License,
16 or (at your option) any later version.
18 The Midnight Commander is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 /** \file
28 * \brief Source: editor text drawing
29 * \author Paul Sheer
30 * \date 1996, 1997
33 #include <config.h>
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <stdarg.h>
37 #include <sys/types.h>
38 #include <unistd.h>
39 #include <string.h>
40 #include <ctype.h>
41 #include <errno.h>
42 #include <sys/stat.h>
44 #include "lib/global.h"
45 #include "lib/tty/tty.h" /* tty_printf() */
46 #include "lib/tty/key.h" /* is_idle() */
47 #include "lib/skin.h"
48 #include "lib/strutil.h" /* utf string functions */
49 #include "lib/util.h" /* is_printable() */
50 #include "lib/widget.h" /* buttonbar_redraw() */
51 #ifdef HAVE_CHARSET
52 #include "lib/charsets.h"
53 #endif
55 #include "src/setup.h" /* edit_tab_spacing */
56 #include "src/main.h" /* macro_index */
58 #include "edit-impl.h"
59 #include "editwidget.h"
61 /*** global variables ****************************************************************************/
63 /* Toggles statusbar draw style */
64 int simple_statusbar = 0;
66 int visible_tabs = 1, visible_tws = 1;
68 /*** file scope macro definitions ****************************************************************/
70 #define MAX_LINE_LEN 1024
72 /* Text styles */
73 #define MOD_ABNORMAL (1 << 8)
74 #define MOD_BOLD (1 << 9)
75 #define MOD_MARKED (1 << 10)
76 #define MOD_CURSOR (1 << 11)
77 #define MOD_WHITESPACE (1 << 12)
79 #define edit_move(x,y) widget_move(edit, y, x);
81 #define key_pending(x) (!is_idle())
83 #define EDITOR_MINIMUM_TERMINAL_WIDTH 30
85 /*** file scope type declarations ****************************************************************/
87 struct line_s
89 unsigned int ch;
90 unsigned int style;
93 /*** file scope variables ************************************************************************/
95 /*** file scope functions ************************************************************************/
96 /* --------------------------------------------------------------------------------------------- */
98 static inline void
99 status_string (WEdit * edit, char *s, int w)
101 char byte_str[16];
104 * If we are at the end of file, print <EOF>,
105 * otherwise print the current character as is (if printable),
106 * as decimal and as hex.
108 if (edit->curs1 < edit->last_byte)
110 unsigned char cur_byte = 0;
112 #ifdef HAVE_CHARSET
113 int cw = 1;
115 if (!edit->utf8)
117 cur_byte = edit_get_byte (edit, edit->curs1);
119 g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X",
120 (int) cur_byte, (unsigned) cur_byte);
122 else
124 unsigned int cur_utf = 0;
126 cur_utf = edit_get_utf (edit, edit->curs1, &cw);
127 if (cw > 0)
129 g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
130 (unsigned) cur_utf, (unsigned) cur_utf);
132 else
133 #endif
135 cur_byte = edit_get_byte (edit, edit->curs1);
136 g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
137 (int) cur_byte, (unsigned) cur_utf);
141 else
143 strcpy (byte_str, "<EOF> ");
146 /* The field lengths just prevent the status line from shortening too much */
147 if (simple_statusbar)
148 g_snprintf (s, w,
149 "%c%c%c%c %3ld %5ld/%ld %6ld/%ld %s %s",
150 edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-',
151 edit->modified ? 'M' : '-',
152 macro_index < 0 ? '-' : 'R',
153 edit->overwrite == 0 ? '-' : 'O',
154 edit->curs_col + edit->over_col,
155 edit->curs_line + 1,
156 edit->total_lines + 1, (long) edit->curs1, (long) edit->last_byte, 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->curs_line + 1,
172 edit->total_lines + 1, (long) edit->curs1, (long) edit->last_byte, byte_str,
173 #ifdef HAVE_CHARSET
174 mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) :
175 #endif
176 "");
179 /* --------------------------------------------------------------------------------------------- */
181 static inline void
182 printwstr (const char *s, int len)
184 if (len > 0)
185 tty_printf ("%-*.*s", len, len, s);
188 /* --------------------------------------------------------------------------------------------- */
190 static inline void
191 print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
192 long end_col, struct line_s line[], char *status, int bookmarked)
194 struct line_s *p;
196 int x = start_col_real;
197 int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
198 int y = row + EDIT_TEXT_VERTICAL_OFFSET;
199 int cols_to_skip = abs (x);
200 int i;
201 int wrap_start;
202 int len;
204 tty_setcolor (EDITOR_NORMAL_COLOR);
205 if (bookmarked != 0)
206 tty_setcolor (bookmarked);
208 len = end_col + 1 - start_col;
209 wrap_start = option_word_wrap_line_length + edit->start_col;
211 if (len > 0 && edit->widget.y + y >= 0)
213 if (!show_right_margin || wrap_start > end_col)
214 tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len);
215 else if (wrap_start < 0)
217 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
218 tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len);
220 else
222 if (wrap_start > 0)
223 tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', wrap_start);
225 len -= wrap_start;
226 if (len > 0)
228 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
229 tty_draw_hline (edit->widget.y + y, edit->widget.x + x1 + wrap_start, ' ', len);
234 if (option_line_state)
236 tty_setcolor (LINE_STATE_COLOR);
237 for (i = 0; i < LINE_STATE_WIDTH; i++)
239 edit_move (x1 + i - option_line_state_width, y);
240 if (status[i] == '\0')
241 status[i] = ' ';
242 tty_print_char (status[i]);
246 edit_move (x1, y);
247 i = 1;
248 for (p = line; p->ch != 0; p++)
250 int style;
251 unsigned int textchar;
252 int color;
254 if (cols_to_skip != 0)
256 cols_to_skip--;
257 continue;
260 style = p->style & 0xFF00;
261 textchar = p->ch;
262 color = p->style >> 16;
264 if (style & MOD_ABNORMAL)
266 /* Non-printable - use black background */
267 color = 0;
270 if (style & MOD_WHITESPACE)
272 if (style & MOD_MARKED)
274 textchar = ' ';
275 tty_setcolor (EDITOR_MARKED_COLOR);
277 else
278 tty_setcolor (EDITOR_WHITESPACE_COLOR);
280 else if (style & MOD_BOLD)
281 tty_setcolor (EDITOR_BOLD_COLOR);
282 else if (style & MOD_MARKED)
283 tty_setcolor (EDITOR_MARKED_COLOR);
284 else
285 tty_lowlevel_setcolor (color);
287 if (show_right_margin)
289 if (i > option_word_wrap_line_length + edit->start_col)
290 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
291 i++;
294 tty_print_anychar (textchar);
298 /* --------------------------------------------------------------------------------------------- */
299 /** b is a pointer to the beginning of the line */
301 static void
302 edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_col)
304 struct line_s line[MAX_LINE_LEN];
305 struct line_s *p = line;
307 off_t m1 = 0, m2 = 0, q;
308 long c1, c2;
309 int col, start_col_real;
310 unsigned int c;
311 int color;
312 int abn_style;
313 int i;
314 unsigned int cur_line = 0;
315 int book_mark = 0;
316 char line_stat[LINE_STATE_WIDTH + 1] = "\0";
318 if (row > edit->widget.lines - 1 - EDIT_TEXT_VERTICAL_OFFSET)
319 return;
321 if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_COLOR))
322 book_mark = BOOK_MARK_COLOR;
323 else if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_FOUND_COLOR))
324 book_mark = BOOK_MARK_FOUND_COLOR;
326 if (book_mark)
327 abn_style = book_mark << 16;
328 else
329 abn_style = MOD_ABNORMAL;
331 end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
333 edit_get_syntax_color (edit, b - 1, &color);
334 q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
335 start_col_real = (col = (int) edit_move_forward3 (edit, b, 0, q)) + edit->start_col;
337 if (option_line_state)
339 cur_line = edit->start_line + row;
340 if (cur_line <= (unsigned int) edit->total_lines)
342 g_snprintf (line_stat, LINE_STATE_WIDTH + 1, "%7i ", cur_line + 1);
344 else
346 memset (line_stat, ' ', LINE_STATE_WIDTH);
347 line_stat[LINE_STATE_WIDTH] = '\0';
349 if (book_mark_query_color (edit, cur_line, BOOK_MARK_COLOR))
351 g_snprintf (line_stat, 2, "*");
355 if (col + 16 > -edit->start_col)
357 eval_marks (edit, &m1, &m2);
359 if (row <= edit->total_lines - edit->start_line)
361 off_t tws = 0;
362 if (tty_use_colors () && visible_tws)
364 tws = edit_eol (edit, b);
365 while (tws > b && ((c = edit_get_byte (edit, tws - 1)) == ' ' || c == '\t'))
366 tws--;
369 while (col <= end_col - edit->start_col)
371 int cw = 1;
372 int tab_over = 0;
373 gboolean wide_width_char = FALSE;
374 gboolean control_char = FALSE;
376 p->ch = 0;
377 p->style = 0;
378 if (q == edit->curs1)
379 p->style |= MOD_CURSOR;
380 if (q >= m1 && q < m2)
382 if (edit->column_highlight)
384 long x;
386 x = (long) edit_move_forward3 (edit, b, 0, q);
387 c1 = min (edit->column1, edit->column2);
388 c2 = max (edit->column1, edit->column2);
389 if (x >= c1 && x < c2)
390 p->style |= MOD_MARKED;
392 else
393 p->style |= MOD_MARKED;
395 if (q == edit->bracket)
396 p->style |= MOD_BOLD;
397 if (q >= edit->found_start && q < (off_t) (edit->found_start + edit->found_len))
398 p->style |= MOD_BOLD;
400 #ifdef HAVE_CHARSET
401 if (edit->utf8)
402 c = edit_get_utf (edit, q, &cw);
403 else
404 #endif
405 c = edit_get_byte (edit, q);
406 /* we don't use bg for mc - fg contains both */
407 if (book_mark)
409 p->style |= book_mark << 16;
411 else
413 edit_get_syntax_color (edit, q, &color);
414 p->style |= color << 16;
416 switch (c)
418 case '\n':
419 col = end_col - edit->start_col + 1; /* quit */
420 break;
421 case '\t':
422 i = TAB_SIZE - ((int) col % TAB_SIZE);
423 tab_over = (end_col - edit->start_col) - (col + i - 1);
424 if (tab_over < 0)
425 i += tab_over;
426 col += i;
427 if (tty_use_colors () &&
428 ((visible_tabs || (visible_tws && q >= tws)) && enable_show_tabs_tws))
430 if (p->style & MOD_MARKED)
431 c = p->style;
432 else if (book_mark)
433 c |= book_mark << 16;
434 else
435 c = p->style | MOD_WHITESPACE;
436 if (i > 2)
438 p->ch = '<';
439 p->style = c;
440 p++;
441 while (--i > 1)
443 p->ch = '-';
444 p->style = c;
445 p++;
447 p->ch = '>';
448 p->style = c;
449 p++;
451 else if (i > 1)
453 p->ch = '<';
454 p->style = c;
455 p++;
456 p->ch = '>';
457 p->style = c;
458 p++;
460 else
462 p->ch = '>';
463 p->style = c;
464 p++;
467 else if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws)
469 p->ch = '.';
470 p->style |= MOD_WHITESPACE;
471 c = p->style & ~MOD_CURSOR;
472 p++;
473 while (--i)
475 p->ch = ' ';
476 p->style = c;
477 p++;
480 else
482 p->ch |= ' ';
483 c = p->style & ~MOD_CURSOR;
484 p++;
485 while (--i)
487 p->ch = ' ';
488 p->style = c;
489 p++;
492 break;
493 case ' ':
494 if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws)
496 p->ch = '.';
497 p->style |= MOD_WHITESPACE;
498 p++;
499 col++;
500 break;
502 /* fallthrough */
503 default:
504 #ifdef HAVE_CHARSET
505 if (mc_global.utf8_display)
507 if (!edit->utf8)
509 c = convert_from_8bit_to_utf_c ((unsigned char) c, edit->converter);
511 else
513 if (g_unichar_iswide (c))
515 wide_width_char = TRUE;
516 col++;
520 else if (edit->utf8)
521 c = convert_from_utf_to_current_c (c, edit->converter);
522 else
523 c = convert_to_display_c (c);
524 #endif
526 /* Caret notation for control characters */
527 if (c < 32)
529 p->ch = '^';
530 p->style = abn_style;
531 p++;
532 p->ch = c + 0x40;
533 p->style = abn_style;
534 p++;
535 col += 2;
536 control_char = TRUE;
537 break;
539 if (c == 127)
541 p->ch = '^';
542 p->style = abn_style;
543 p++;
544 p->ch = '?';
545 p->style = abn_style;
546 p++;
547 col += 2;
548 control_char = TRUE;
549 break;
551 #ifdef HAVE_CHARSET
552 if (edit->utf8)
554 if (g_unichar_isprint (c))
555 p->ch = c;
556 else
558 p->ch = '.';
559 p->style = abn_style;
561 p++;
563 else
564 #endif
566 if ((mc_global.utf8_display && g_unichar_isprint (c)) ||
567 (!mc_global.utf8_display && is_printable (c)))
569 p->ch = c;
570 p++;
572 else
574 p->ch = '.';
575 p->style = abn_style;
576 p++;
579 col++;
580 break;
581 } /* case */
583 q++;
584 if (cw > 1)
586 q += cw - 1;
589 if (col > (end_col - edit->start_col + 1))
591 if (wide_width_char)
593 p--;
594 break;
596 if (control_char)
598 p -= 2;
599 break;
605 else
607 start_col_real = start_col = 0;
610 p->ch = 0;
612 print_to_widget (edit, row, start_col, start_col_real, end_col, line, line_stat, book_mark);
615 /* --------------------------------------------------------------------------------------------- */
617 static inline void
618 edit_draw_this_char (WEdit * edit, off_t curs, long row, long start_column, long end_column)
620 off_t b = edit_bol (edit, curs);
622 edit_draw_this_line (edit, b, row, start_column, end_column);
625 /* --------------------------------------------------------------------------------------------- */
626 /** cursor must be in screen for other than REDRAW_PAGE passed in force */
628 static inline void
629 render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, long end_column)
631 static long prev_curs_row = 0;
632 static off_t prev_curs = 0;
634 Widget *w = (Widget *) edit;
635 Dlg_head *h = w->owner;
637 long row = 0, curs_row;
638 int force = edit->force;
639 long b;
640 int y1, x1, y2, x2;
642 int last_line;
643 int last_column;
645 /* draw only visible region */
647 last_line = h->y + h->lines - 1;
649 y1 = w->y;
650 if (y1 > last_line - 1 /* buttonbar */ )
651 return;
653 last_column = h->x + h->cols - 1;
655 x1 = w->x;
656 if (x1 > last_column)
657 return;
659 y2 = w->y + w->lines - 1;
660 if (y2 < h->y + 1 /* menubar */ )
661 return;
663 x2 = w->x + w->cols - 1;
664 if (x2 < h->x)
665 return;
667 if ((force & REDRAW_IN_BOUNDS) == 0)
669 /* !REDRAW_IN_BOUNDS means to ignore bounds and redraw whole rows */
670 /* draw only visible region */
672 if (y2 <= last_line - 1 /* buttonbar */ )
673 end_row = w->lines - 1;
674 else if (y1 >= h->y + 1 /* menubar */ )
675 end_row = h->lines - 1 - y1 - 1;
676 else
677 end_row = start_row + h->lines - 1 - 1;
679 if (x2 <= last_column)
680 end_column = w->cols - 1;
681 else if (x1 >= h->x)
682 end_column = h->cols - 1 - x1;
683 else
684 end_column = start_column + h->cols - 1;
688 * If the position of the page has not moved then we can draw the cursor
689 * character only. This will prevent line flicker when using arrow keys.
691 if ((force & REDRAW_CHAR_ONLY) == 0 || (force & REDRAW_PAGE) != 0)
693 if ((force & REDRAW_PAGE) != 0)
695 row = start_row;
696 b = edit_move_forward (edit, edit->start_display, start_row, 0);
697 while (row <= end_row)
699 if (key_pending (edit))
700 return;
701 edit_draw_this_line (edit, b, row, start_column, end_column);
702 b = edit_move_forward (edit, b, 1, 0);
703 row++;
706 else
708 curs_row = edit->curs_row;
710 if ((force & REDRAW_BEFORE_CURSOR) != 0 && start_row < curs_row)
712 long upto = curs_row - 1 <= end_row ? curs_row - 1 : end_row;
714 row = start_row;
715 b = edit->start_display;
716 while (row <= upto)
718 if (key_pending (edit))
719 return;
720 edit_draw_this_line (edit, b, row, start_column, end_column);
721 b = edit_move_forward (edit, b, 1, 0);
725 /* if (force & REDRAW_LINE) ---> default */
726 b = edit_bol (edit, edit->curs1);
727 if (curs_row >= start_row && curs_row <= end_row)
729 if (key_pending (edit))
730 return;
731 edit_draw_this_line (edit, b, curs_row, start_column, end_column);
734 if ((force & REDRAW_AFTER_CURSOR) != 0 && end_row > curs_row)
736 row = curs_row + 1 < start_row ? start_row : curs_row + 1;
737 b = edit_move_forward (edit, b, 1, 0);
738 while (row <= end_row)
740 if (key_pending (edit))
741 return;
742 edit_draw_this_line (edit, b, row, start_column, end_column);
743 b = edit_move_forward (edit, b, 1, 0);
744 row++;
748 if ((force & REDRAW_LINE_ABOVE) != 0 && curs_row >= 1)
750 row = curs_row - 1;
751 b = edit_move_backward (edit, edit_bol (edit, edit->curs1), 1);
752 if (row >= start_row && row <= end_row)
754 if (key_pending (edit))
755 return;
756 edit_draw_this_line (edit, b, row, start_column, end_column);
760 if ((force & REDRAW_LINE_BELOW) != 0 && row < edit->widget.lines - 1)
762 row = curs_row + 1;
763 b = edit_bol (edit, edit->curs1);
764 b = edit_move_forward (edit, b, 1, 0);
765 if (row >= start_row && row <= end_row)
767 if (key_pending (edit))
768 return;
769 edit_draw_this_line (edit, b, row, start_column, end_column);
774 else if (prev_curs_row < edit->curs_row)
776 /* with the new text highlighting, we must draw from the top down */
777 edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);
778 edit_draw_this_char (edit, edit->curs1, edit->curs_row, start_column, end_column);
780 else
782 edit_draw_this_char (edit, edit->curs1, edit->curs_row, start_column, end_column);
783 edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);
786 edit->force = 0;
788 prev_curs_row = edit->curs_row;
789 prev_curs = edit->curs1;
792 /* --------------------------------------------------------------------------------------------- */
794 static inline void
795 edit_render (WEdit * edit, int page, int row_start, int col_start, int row_end, int col_end)
797 if (page) /* if it was an expose event, 'page' would be set */
798 edit->force |= REDRAW_PAGE | REDRAW_IN_BOUNDS;
800 if (edit->force & REDRAW_COMPLETELY)
801 buttonbar_redraw (find_buttonbar (edit->widget.owner));
802 render_edit_text (edit, row_start, col_start, row_end, col_end);
804 * edit->force != 0 means a key was pending and the redraw
805 * was halted, so next time we must redraw everything in case stuff
806 * was left undrawn from a previous key press.
808 if (edit->force)
809 edit->force |= REDRAW_PAGE;
812 /* --------------------------------------------------------------------------------------------- */
813 /*** public functions ****************************************************************************/
814 /* --------------------------------------------------------------------------------------------- */
816 /** Draw the status line at the top of the screen. The size of the filename
817 * field varies depending on the width of the screen and the length of
818 * the filename. */
819 void
820 edit_status (WEdit * edit)
822 const int w = edit->widget.owner->cols;
823 const size_t status_size = w + 1;
824 char *const status = g_malloc (status_size);
825 int status_len;
826 const char *fname = "";
827 int fname_len;
828 const int gap = 3; /* between the filename and the status */
829 const int right_gap = 5; /* at the right end of the screen */
830 const int preferred_fname_len = 16;
832 status_string (edit, status, status_size);
833 status_len = (int) str_term_width1 (status);
835 if (edit->filename_vpath != NULL)
836 fname = vfs_path_get_last_path_str (edit->filename_vpath);
838 fname_len = str_term_width1 (fname);
839 if (fname_len < preferred_fname_len)
840 fname_len = preferred_fname_len;
842 if (fname_len + gap + status_len + right_gap >= w)
844 if (preferred_fname_len + gap + status_len + right_gap >= w)
845 fname_len = preferred_fname_len;
846 else
847 fname_len = w - (gap + status_len + right_gap);
848 fname = str_trunc (fname, fname_len);
851 dlg_move (edit->widget.owner, 0, 0);
852 tty_setcolor (STATUSBAR_COLOR);
853 printwstr (fname, fname_len + gap);
854 printwstr (status, w - (fname_len + gap));
856 if (simple_statusbar && w > EDITOR_MINIMUM_TERMINAL_WIDTH)
858 size_t percent = 100;
860 if (edit->total_lines + 1 != 0)
861 percent = (edit->curs_line + 1) * 100 / (edit->total_lines + 1);
862 dlg_move (edit->widget.owner, 0, w - 5);
863 tty_printf (" %3d%%", percent);
866 g_free (status);
869 /* --------------------------------------------------------------------------------------------- */
870 /** this scrolls the text so that cursor is on the screen */
871 void
872 edit_scroll_screen_over_cursor (WEdit * edit)
874 long p;
875 long outby;
876 int b_extreme, t_extreme, l_extreme, r_extreme;
878 if (edit->widget.lines <= 0 || edit->widget.cols <= 0)
879 return;
881 edit->widget.cols -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
882 edit->widget.lines -= EDIT_TEXT_VERTICAL_OFFSET;
884 r_extreme = EDIT_RIGHT_EXTREME;
885 l_extreme = EDIT_LEFT_EXTREME;
886 b_extreme = EDIT_BOTTOM_EXTREME;
887 t_extreme = EDIT_TOP_EXTREME;
888 if (edit->found_len != 0)
890 b_extreme = max (edit->widget.lines / 4, b_extreme);
891 t_extreme = max (edit->widget.lines / 4, t_extreme);
893 if (b_extreme + t_extreme + 1 > edit->widget.lines)
895 int n;
897 n = b_extreme + t_extreme;
898 if (n == 0)
899 n = 1;
900 b_extreme = (b_extreme * (edit->widget.lines - 1)) / n;
901 t_extreme = (t_extreme * (edit->widget.lines - 1)) / n;
903 if (l_extreme + r_extreme + 1 > edit->widget.cols)
905 int n;
907 n = l_extreme + t_extreme;
908 if (n == 0)
909 n = 1;
910 l_extreme = (l_extreme * (edit->widget.cols - 1)) / n;
911 r_extreme = (r_extreme * (edit->widget.cols - 1)) / n;
913 p = edit_get_col (edit) + edit->over_col;
914 edit_update_curs_row (edit);
915 outby = p + edit->start_col - edit->widget.cols + 1 + (r_extreme + edit->found_len);
916 if (outby > 0)
917 edit_scroll_right (edit, outby);
918 outby = l_extreme - p - edit->start_col;
919 if (outby > 0)
920 edit_scroll_left (edit, outby);
921 p = edit->curs_row;
922 outby = p - edit->widget.lines + 1 + b_extreme;
923 if (outby > 0)
924 edit_scroll_downward (edit, outby);
925 outby = t_extreme - p;
926 if (outby > 0)
927 edit_scroll_upward (edit, outby);
928 edit_update_curs_row (edit);
930 edit->widget.lines += EDIT_TEXT_VERTICAL_OFFSET;
931 edit->widget.cols += EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
934 /* --------------------------------------------------------------------------------------------- */
936 void
937 edit_render_keypress (WEdit * edit)
939 edit_render (edit, 0, 0, 0, 0, 0);
942 /* --------------------------------------------------------------------------------------------- */