Ticket #2846: code cleanup before 4.8.1.4 release.
[midnight-commander.git] / src / editor / editdraw.c
blob3ee3e63c858425aa9ff391b820e7c6608826ad15
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];
102 unsigned char cur_byte = 0;
103 unsigned int cur_utf = 0;
104 int cw = 1;
107 * If we are at the end of file, print <EOF>,
108 * otherwise print the current character as is (if printable),
109 * as decimal and as hex.
111 if (edit->curs1 < edit->last_byte)
113 if (!edit->utf8)
115 cur_byte = edit_get_byte (edit, edit->curs1);
117 g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X",
118 (int) cur_byte, (unsigned) cur_byte);
120 else
122 cur_utf = edit_get_utf (edit, edit->curs1, &cw);
123 if (cw > 0)
125 g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
126 (unsigned) cur_utf, (unsigned) cur_utf);
128 else
130 cur_utf = edit_get_byte (edit, edit->curs1);
131 g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
132 (int) cur_utf, (unsigned) cur_utf);
137 else
139 strcpy (byte_str, "<EOF> ");
142 /* The field lengths just prevent the status line from shortening too much */
143 if (simple_statusbar)
144 g_snprintf (s, w,
145 "%c%c%c%c %3ld %5ld/%ld %6ld/%ld %s %s",
146 edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-',
147 edit->modified ? 'M' : '-',
148 macro_index < 0 ? '-' : 'R',
149 edit->overwrite == 0 ? '-' : 'O',
150 edit->curs_col + edit->over_col,
151 edit->curs_line + 1,
152 edit->total_lines + 1, edit->curs1, edit->last_byte, byte_str,
153 #ifdef HAVE_CHARSET
154 mc_global.source_codepage >=
155 0 ? get_codepage_id (mc_global.source_codepage) : ""
156 #else
158 #endif
160 else
161 g_snprintf (s, w,
162 "[%c%c%c%c] %2ld L:[%3ld+%2ld %3ld/%3ld] *(%-4ld/%4ldb) %s %s",
163 edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-',
164 edit->modified ? 'M' : '-',
165 macro_index < 0 ? '-' : 'R',
166 edit->overwrite == 0 ? '-' : 'O',
167 edit->curs_col + edit->over_col,
168 edit->start_line + 1,
169 edit->curs_row,
170 edit->curs_line + 1,
171 edit->total_lines + 1, edit->curs1, edit->last_byte, byte_str,
172 #ifdef HAVE_CHARSET
173 mc_global.source_codepage >=
174 0 ? get_codepage_id (mc_global.source_codepage) : ""
175 #else
177 #endif
181 /* --------------------------------------------------------------------------------------------- */
183 static inline void
184 printwstr (const char *s, int len)
186 if (len > 0)
187 tty_printf ("%-*.*s", len, len, s);
190 /* --------------------------------------------------------------------------------------------- */
192 static inline void
193 print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
194 long end_col, struct line_s line[], char *status, int bookmarked)
196 struct line_s *p;
198 int x = start_col_real;
199 int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
200 int y = row + EDIT_TEXT_VERTICAL_OFFSET;
201 int cols_to_skip = abs (x);
202 int i;
203 int wrap_start;
204 int len;
206 tty_setcolor (EDITOR_NORMAL_COLOR);
207 if (bookmarked != 0)
208 tty_setcolor (bookmarked);
210 len = end_col + 1 - start_col;
211 wrap_start = option_word_wrap_line_length + edit->start_col;
213 if (len > 0 && edit->widget.y + y >= 0)
215 if (!show_right_margin || wrap_start > end_col)
216 tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len);
217 else if (wrap_start < 0)
219 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
220 tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len);
222 else
224 if (wrap_start > 0)
225 tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', wrap_start);
227 len -= wrap_start;
228 if (len > 0)
230 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
231 tty_draw_hline (edit->widget.y + y, edit->widget.x + x1 + wrap_start, ' ', len);
236 if (option_line_state)
238 tty_setcolor (LINE_STATE_COLOR);
239 for (i = 0; i < LINE_STATE_WIDTH; i++)
241 edit_move (x1 + i - option_line_state_width, y);
242 if (status[i] == '\0')
243 status[i] = ' ';
244 tty_print_char (status[i]);
248 edit_move (x1, y);
249 p = line;
250 i = 1;
251 while (p->ch)
253 int style;
254 unsigned int textchar;
255 int color;
257 if (cols_to_skip)
259 p++;
260 cols_to_skip--;
261 continue;
264 style = p->style & 0xFF00;
265 textchar = p->ch;
266 color = p->style >> 16;
268 if (style & MOD_ABNORMAL)
270 /* Non-printable - use black background */
271 color = 0;
274 if (style & MOD_WHITESPACE)
276 if (style & MOD_MARKED)
278 textchar = ' ';
279 tty_setcolor (EDITOR_MARKED_COLOR);
281 else
283 #if 0
284 if (color != EDITOR_NORMAL_COLOR)
286 textchar = ' ';
287 tty_lowlevel_setcolor (color);
289 else
290 #endif
291 tty_setcolor (EDITOR_WHITESPACE_COLOR);
294 else
296 if (style & MOD_BOLD)
298 tty_setcolor (EDITOR_BOLD_COLOR);
300 else if (style & MOD_MARKED)
302 tty_setcolor (EDITOR_MARKED_COLOR);
304 else
306 tty_lowlevel_setcolor (color);
309 if (show_right_margin)
311 if (i > option_word_wrap_line_length + edit->start_col)
312 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
313 i++;
315 tty_print_anychar (textchar);
316 p++;
320 /* --------------------------------------------------------------------------------------------- */
321 /** b is a pointer to the beginning of the line */
323 static void
324 edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_col)
326 struct line_s line[MAX_LINE_LEN];
327 struct line_s *p = line;
329 long m1 = 0, m2 = 0, q, c1, c2;
330 int col, start_col_real;
331 unsigned int c;
332 int color;
333 int abn_style;
334 int i;
335 int utf8lag = 0;
336 unsigned int cur_line = 0;
337 int book_mark = 0;
338 char line_stat[LINE_STATE_WIDTH + 1] = "\0";
340 if (row > edit->widget.lines - 1 - EDIT_TEXT_VERTICAL_OFFSET)
341 return;
343 if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_COLOR))
344 book_mark = BOOK_MARK_COLOR;
345 else if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_FOUND_COLOR))
346 book_mark = BOOK_MARK_FOUND_COLOR;
348 if (book_mark)
349 abn_style = book_mark << 16;
350 else
351 abn_style = MOD_ABNORMAL;
353 end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
355 edit_get_syntax_color (edit, b - 1, &color);
356 q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
357 start_col_real = (col = (int) edit_move_forward3 (edit, b, 0, q)) + edit->start_col;
358 if (option_line_state)
360 cur_line = edit->start_line + row;
361 if (cur_line <= (unsigned int) edit->total_lines)
363 g_snprintf (line_stat, LINE_STATE_WIDTH + 1, "%7i ", cur_line + 1);
365 else
367 memset (line_stat, ' ', LINE_STATE_WIDTH);
368 line_stat[LINE_STATE_WIDTH] = '\0';
370 if (book_mark_query_color (edit, cur_line, BOOK_MARK_COLOR))
372 g_snprintf (line_stat, 2, "*");
376 if (col + 16 > -edit->start_col)
378 eval_marks (edit, &m1, &m2);
380 if (row <= edit->total_lines - edit->start_line)
382 long tws = 0;
383 if (tty_use_colors () && visible_tws)
385 tws = edit_eol (edit, b);
386 while (tws > b && ((c = edit_get_byte (edit, tws - 1)) == ' ' || c == '\t'))
387 tws--;
390 while (col <= end_col - edit->start_col)
392 int cw = 1;
394 p->ch = 0;
395 p->style = 0;
396 if (q == edit->curs1)
397 p->style |= MOD_CURSOR;
398 if (q >= m1 && q < m2)
400 if (edit->column_highlight)
402 int x;
403 x = edit_move_forward3 (edit, b, 0, q);
404 c1 = min (edit->column1, edit->column2);
405 c2 = max (edit->column1, edit->column2);
406 if (x >= c1 && x < c2)
407 p->style |= MOD_MARKED;
409 else
410 p->style |= MOD_MARKED;
412 if (q == edit->bracket)
413 p->style |= MOD_BOLD;
414 if (q >= edit->found_start && q < edit->found_start + edit->found_len)
415 p->style |= MOD_BOLD;
417 if (!edit->utf8)
419 c = edit_get_byte (edit, q);
421 else
423 c = edit_get_utf (edit, q, &cw);
425 /* we don't use bg for mc - fg contains both */
426 if (book_mark)
428 p->style |= book_mark << 16;
430 else
432 edit_get_syntax_color (edit, q, &color);
433 p->style |= color << 16;
435 switch (c)
437 case '\n':
438 col = (end_col + utf8lag) - edit->start_col + 1; /* quit */
439 break;
440 case '\t':
441 i = TAB_SIZE - ((int) col % TAB_SIZE);
442 col += i;
443 if (tty_use_colors () &&
444 ((visible_tabs || (visible_tws && q >= tws)) && enable_show_tabs_tws))
446 if (p->style & MOD_MARKED)
447 c = p->style;
448 else if (book_mark)
449 c |= book_mark << 16;
450 else
451 c = p->style | MOD_WHITESPACE;
452 if (i > 2)
454 p->ch = '<';
455 p->style = c;
456 p++;
457 while (--i > 1)
459 p->ch = '-';
460 p->style = c;
461 p++;
463 p->ch = '>';
464 p->style = c;
465 p++;
467 else if (i > 1)
469 p->ch = '<';
470 p->style = c;
471 p++;
472 p->ch = '>';
473 p->style = c;
474 p++;
476 else
478 p->ch = '>';
479 p->style = c;
480 p++;
483 else if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws)
485 p->ch = '.';
486 p->style |= MOD_WHITESPACE;
487 c = p->style & ~MOD_CURSOR;
488 p++;
489 while (--i)
491 p->ch = ' ';
492 p->style = c;
493 p++;
496 else
498 p->ch |= ' ';
499 c = p->style & ~MOD_CURSOR;
500 p++;
501 while (--i)
503 p->ch = ' ';
504 p->style = c;
505 p++;
508 break;
509 case ' ':
510 if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws)
512 p->ch = '.';
513 p->style |= MOD_WHITESPACE;
514 p++;
515 col++;
516 break;
518 /* fallthrough */
519 default:
520 #ifdef HAVE_CHARSET
521 if (mc_global.utf8_display)
523 if (!edit->utf8)
525 c = convert_from_8bit_to_utf_c ((unsigned char) c, edit->converter);
528 else if (edit->utf8)
529 c = convert_from_utf_to_current_c (c, edit->converter);
530 else
531 c = convert_to_display_c (c);
532 #endif
534 /* Caret notation for control characters */
535 if (c < 32)
537 p->ch = '^';
538 p->style = abn_style;
539 p++;
540 p->ch = c + 0x40;
541 p->style = abn_style;
542 p++;
543 col += 2;
544 break;
546 if (c == 127)
548 p->ch = '^';
549 p->style = abn_style;
550 p++;
551 p->ch = '?';
552 p->style = abn_style;
553 p++;
554 col += 2;
555 break;
557 if (!edit->utf8)
559 if ((mc_global.utf8_display && g_unichar_isprint (c)) ||
560 (!mc_global.utf8_display && is_printable (c)))
562 p->ch = c;
563 p++;
565 else
567 p->ch = '.';
568 p->style = abn_style;
569 p++;
572 else
574 if (g_unichar_isprint (c))
576 p->ch = c;
577 p++;
579 else
581 p->ch = '.';
582 p->style = abn_style;
583 p++;
586 col++;
587 break;
588 } /* case */
590 q++;
591 if (cw > 1)
593 q += cw - 1;
598 else
600 start_col_real = start_col = 0;
603 p->ch = '\0';
605 print_to_widget (edit, row, start_col, start_col_real, end_col, line, line_stat, book_mark);
608 /* --------------------------------------------------------------------------------------------- */
610 static inline void
611 edit_draw_this_char (WEdit * edit, long curs, long row, long start_column, long end_column)
613 int b = edit_bol (edit, curs);
614 edit_draw_this_line (edit, b, row, start_column, end_column);
617 /* --------------------------------------------------------------------------------------------- */
618 /** cursor must be in screen for other than REDRAW_PAGE passed in force */
620 static inline void
621 render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, long end_column)
623 static long prev_curs_row = 0;
624 static long prev_curs = 0;
626 Widget *w = (Widget *) edit;
627 Dlg_head *h = w->owner;
629 long row = 0, curs_row;
630 int force = edit->force;
631 long b;
632 int y1, x1, y2, x2;
634 int last_line;
635 int last_column;
637 /* draw only visible region */
639 last_line = h->y + h->lines - 1;
641 y1 = w->y;
642 if (y1 > last_line - 1 /* buttonbar */ )
643 return;
645 last_column = h->x + h->cols - 1;
647 x1 = w->x;
648 if (x1 > last_column)
649 return;
651 y2 = w->y + w->lines - 1;
652 if (y2 < h->y + 1 /* menubar */ )
653 return;
655 x2 = w->x + w->cols - 1;
656 if (x2 < h->x)
657 return;
659 if ((force & REDRAW_IN_BOUNDS) == 0)
661 /* !REDRAW_IN_BOUNDS means to ignore bounds and redraw whole rows */
662 /* draw only visible region */
664 if (y2 <= last_line - 1 /* buttonbar */ )
665 end_row = w->lines - 1;
666 else if (y1 >= h->y + 1 /* menubar */ )
667 end_row = h->lines - 1 - y1 - 1;
668 else
669 end_row = start_row + h->lines - 1 - 1;
671 if (x2 <= last_column)
672 end_column = w->cols - 1;
673 else if (x1 >= h->x)
674 end_column = h->cols - 1 - x1;
675 else
676 end_column = start_column + h->cols - 1;
680 * If the position of the page has not moved then we can draw the cursor
681 * character only. This will prevent line flicker when using arrow keys.
683 if ((force & REDRAW_CHAR_ONLY) == 0 || (force & REDRAW_PAGE) != 0)
685 if ((force & REDRAW_PAGE) != 0)
687 row = start_row;
688 b = edit_move_forward (edit, edit->start_display, start_row, 0);
689 while (row <= end_row)
691 if (key_pending (edit))
692 return;
693 edit_draw_this_line (edit, b, row, start_column, end_column);
694 b = edit_move_forward (edit, b, 1, 0);
695 row++;
698 else
700 curs_row = edit->curs_row;
702 if ((force & REDRAW_BEFORE_CURSOR) != 0 && start_row < curs_row)
704 long upto = curs_row - 1 <= end_row ? curs_row - 1 : end_row;
706 row = start_row;
707 b = edit->start_display;
708 while (row <= upto)
710 if (key_pending (edit))
711 return;
712 edit_draw_this_line (edit, b, row, start_column, end_column);
713 b = edit_move_forward (edit, b, 1, 0);
717 /* if (force & REDRAW_LINE) ---> default */
718 b = edit_bol (edit, edit->curs1);
719 if (curs_row >= start_row && curs_row <= end_row)
721 if (key_pending (edit))
722 return;
723 edit_draw_this_line (edit, b, curs_row, start_column, end_column);
726 if ((force & REDRAW_AFTER_CURSOR) != 0 && end_row > curs_row)
728 row = curs_row + 1 < start_row ? start_row : curs_row + 1;
729 b = edit_move_forward (edit, b, 1, 0);
730 while (row <= end_row)
732 if (key_pending (edit))
733 return;
734 edit_draw_this_line (edit, b, row, start_column, end_column);
735 b = edit_move_forward (edit, b, 1, 0);
736 row++;
740 if ((force & REDRAW_LINE_ABOVE) != 0 && curs_row >= 1)
742 row = curs_row - 1;
743 b = edit_move_backward (edit, edit_bol (edit, edit->curs1), 1);
744 if (row >= start_row && row <= end_row)
746 if (key_pending (edit))
747 return;
748 edit_draw_this_line (edit, b, row, start_column, end_column);
752 if ((force & REDRAW_LINE_BELOW) != 0 && row < edit->widget.lines - 1)
754 row = curs_row + 1;
755 b = edit_bol (edit, edit->curs1);
756 b = edit_move_forward (edit, b, 1, 0);
757 if (row >= start_row && row <= end_row)
759 if (key_pending (edit))
760 return;
761 edit_draw_this_line (edit, b, row, start_column, end_column);
766 else if (prev_curs_row < edit->curs_row)
768 /* with the new text highlighting, we must draw from the top down */
769 edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);
770 edit_draw_this_char (edit, edit->curs1, edit->curs_row, start_column, end_column);
772 else
774 edit_draw_this_char (edit, edit->curs1, edit->curs_row, start_column, end_column);
775 edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);
778 edit->force = 0;
780 prev_curs_row = edit->curs_row;
781 prev_curs = edit->curs1;
784 /* --------------------------------------------------------------------------------------------- */
786 static inline void
787 edit_render (WEdit * edit, int page, int row_start, int col_start, int row_end, int col_end)
789 if (page) /* if it was an expose event, 'page' would be set */
790 edit->force |= REDRAW_PAGE | REDRAW_IN_BOUNDS;
792 if (edit->force & REDRAW_COMPLETELY)
793 buttonbar_redraw (find_buttonbar (edit->widget.owner));
794 render_edit_text (edit, row_start, col_start, row_end, col_end);
796 * edit->force != 0 means a key was pending and the redraw
797 * was halted, so next time we must redraw everything in case stuff
798 * was left undrawn from a previous key press.
800 if (edit->force)
801 edit->force |= REDRAW_PAGE;
804 /* --------------------------------------------------------------------------------------------- */
805 /*** public functions ****************************************************************************/
806 /* --------------------------------------------------------------------------------------------- */
808 /** Draw the status line at the top of the screen. The size of the filename
809 * field varies depending on the width of the screen and the length of
810 * the filename. */
811 void
812 edit_status (WEdit * edit)
814 const int w = edit->widget.owner->cols;
815 const size_t status_size = w + 1;
816 char *const status = g_malloc (status_size);
817 int status_len;
818 const char *fname = "";
819 int fname_len;
820 const int gap = 3; /* between the filename and the status */
821 const int right_gap = 5; /* at the right end of the screen */
822 const int preferred_fname_len = 16;
824 status_string (edit, status, status_size);
825 status_len = (int) str_term_width1 (status);
827 if (edit->filename_vpath != NULL)
828 fname = vfs_path_get_last_path_str (edit->filename_vpath);
830 fname_len = str_term_width1 (fname);
831 if (fname_len < preferred_fname_len)
832 fname_len = preferred_fname_len;
834 if (fname_len + gap + status_len + right_gap >= w)
836 if (preferred_fname_len + gap + status_len + right_gap >= w)
837 fname_len = preferred_fname_len;
838 else
839 fname_len = w - (gap + status_len + right_gap);
840 fname = str_trunc (fname, fname_len);
843 dlg_move (edit->widget.owner, 0, 0);
844 tty_setcolor (STATUSBAR_COLOR);
845 printwstr (fname, fname_len + gap);
846 printwstr (status, w - (fname_len + gap));
848 if (simple_statusbar && w > EDITOR_MINIMUM_TERMINAL_WIDTH)
850 size_t percent = 100;
852 if (edit->total_lines + 1 != 0)
853 percent = (edit->curs_line + 1) * 100 / (edit->total_lines + 1);
854 dlg_move (edit->widget.owner, 0, w - 5);
855 tty_printf (" %3d%%", percent);
858 g_free (status);
861 /* --------------------------------------------------------------------------------------------- */
862 /** this scrolls the text so that cursor is on the screen */
863 void
864 edit_scroll_screen_over_cursor (WEdit * edit)
866 int p;
867 int outby;
868 int b_extreme, t_extreme, l_extreme, r_extreme;
870 if (edit->widget.lines <= 0 || edit->widget.cols <= 0)
871 return;
873 edit->widget.cols -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
874 edit->widget.lines -= EDIT_TEXT_VERTICAL_OFFSET;
876 r_extreme = EDIT_RIGHT_EXTREME;
877 l_extreme = EDIT_LEFT_EXTREME;
878 b_extreme = EDIT_BOTTOM_EXTREME;
879 t_extreme = EDIT_TOP_EXTREME;
880 if (edit->found_len)
882 b_extreme = max (edit->widget.lines / 4, b_extreme);
883 t_extreme = max (edit->widget.lines / 4, t_extreme);
885 if (b_extreme + t_extreme + 1 > edit->widget.lines)
887 int n;
889 n = b_extreme + t_extreme;
890 if (n == 0)
891 n = 1;
892 b_extreme = (b_extreme * (edit->widget.lines - 1)) / n;
893 t_extreme = (t_extreme * (edit->widget.lines - 1)) / n;
895 if (l_extreme + r_extreme + 1 > edit->widget.cols)
897 int n;
899 n = l_extreme + t_extreme;
900 if (n == 0)
901 n = 1;
902 l_extreme = (l_extreme * (edit->widget.cols - 1)) / n;
903 r_extreme = (r_extreme * (edit->widget.cols - 1)) / n;
905 p = edit_get_col (edit) + edit->over_col;
906 edit_update_curs_row (edit);
907 outby = p + edit->start_col - edit->widget.cols + 1 + (r_extreme + edit->found_len);
908 if (outby > 0)
909 edit_scroll_right (edit, outby);
910 outby = l_extreme - p - edit->start_col;
911 if (outby > 0)
912 edit_scroll_left (edit, outby);
913 p = edit->curs_row;
914 outby = p - edit->widget.lines + 1 + b_extreme;
915 if (outby > 0)
916 edit_scroll_downward (edit, outby);
917 outby = t_extreme - p;
918 if (outby > 0)
919 edit_scroll_upward (edit, outby);
920 edit_update_curs_row (edit);
922 edit->widget.lines += EDIT_TEXT_VERTICAL_OFFSET;
923 edit->widget.cols += EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
926 /* --------------------------------------------------------------------------------------------- */
928 void
929 edit_render_keypress (WEdit * edit)
931 edit_render (edit, 0, 0, 0, 0, 0);
934 /* --------------------------------------------------------------------------------------------- */