editdraw.c: removed unused defines.
[midnight-commander.git] / src / editor / editdraw.c
blob2ceeb3d87824d41e64f0cc3b6d6b28806f8c9b05
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 #include "lib/charsets.h"
53 #include "src/setup.h" /* edit_tab_spacing */
54 #include "src/main.h" /* macro_index */
56 #include "edit-impl.h"
57 #include "edit-widget.h"
59 /*** global variables ****************************************************************************/
61 /* Toggles statusbar draw style */
62 int simple_statusbar = 0;
64 int visible_tabs = 1, visible_tws = 1;
66 /*** file scope macro definitions ****************************************************************/
68 #define MAX_LINE_LEN 1024
70 /* Text styles */
71 #define MOD_ABNORMAL (1 << 8)
72 #define MOD_BOLD (1 << 9)
73 #define MOD_MARKED (1 << 10)
74 #define MOD_CURSOR (1 << 11)
75 #define MOD_WHITESPACE (1 << 12)
77 #define edit_move(x,y) widget_move(edit, y, x);
79 #define key_pending(x) (!is_idle())
81 #define EDITOR_MINIMUM_TERMINAL_WIDTH 30
83 /*** file scope type declarations ****************************************************************/
85 struct line_s
87 unsigned int ch;
88 unsigned int style;
91 /*** file scope variables ************************************************************************/
93 /*** file scope functions ************************************************************************/
94 /* --------------------------------------------------------------------------------------------- */
96 static inline void
97 status_string (WEdit * edit, char *s, int w)
99 char byte_str[16];
100 unsigned char cur_byte = 0;
101 unsigned int cur_utf = 0;
102 int cw = 1;
105 * If we are at the end of file, print <EOF>,
106 * otherwise print the current character as is (if printable),
107 * as decimal and as hex.
109 if (edit->curs1 < edit->last_byte)
111 if (!edit->utf8)
113 cur_byte = edit_get_byte (edit, edit->curs1);
115 g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X",
116 (int) cur_byte, (unsigned) cur_byte);
118 else
120 cur_utf = edit_get_utf (edit, edit->curs1, &cw);
121 if (cw > 0)
123 g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
124 (unsigned) cur_utf, (unsigned) cur_utf);
126 else
128 cur_utf = edit_get_byte (edit, edit->curs1);
129 g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
130 (int) cur_utf, (unsigned) cur_utf);
135 else
137 strcpy (byte_str, "<EOF> ");
140 /* The field lengths just prevent the status line from shortening too much */
141 if (simple_statusbar)
142 g_snprintf (s, w,
143 "%c%c%c%c %3ld %5ld/%ld %6ld/%ld %s %s",
144 edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-',
145 edit->modified ? 'M' : '-',
146 macro_index < 0 ? '-' : 'R',
147 edit->overwrite == 0 ? '-' : 'O',
148 edit->curs_col + edit->over_col,
149 edit->curs_line + 1,
150 edit->total_lines + 1, edit->curs1, edit->last_byte, byte_str,
151 #ifdef HAVE_CHARSET
152 mc_global.source_codepage >=
153 0 ? get_codepage_id (mc_global.source_codepage) : ""
154 #else
156 #endif
158 else
159 g_snprintf (s, w,
160 "[%c%c%c%c] %2ld L:[%3ld+%2ld %3ld/%3ld] *(%-4ld/%4ldb) %s %s",
161 edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-',
162 edit->modified ? 'M' : '-',
163 macro_index < 0 ? '-' : 'R',
164 edit->overwrite == 0 ? '-' : 'O',
165 edit->curs_col + edit->over_col,
166 edit->start_line + 1,
167 edit->curs_row,
168 edit->curs_line + 1,
169 edit->total_lines + 1, edit->curs1, edit->last_byte, byte_str,
170 #ifdef HAVE_CHARSET
171 mc_global.source_codepage >=
172 0 ? get_codepage_id (mc_global.source_codepage) : ""
173 #else
175 #endif
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 p = line;
248 i = 1;
249 while (p->ch)
251 int style;
252 unsigned int textchar;
253 int color;
255 if (cols_to_skip)
257 p++;
258 cols_to_skip--;
259 continue;
262 style = p->style & 0xFF00;
263 textchar = p->ch;
264 color = p->style >> 16;
266 if (style & MOD_ABNORMAL)
268 /* Non-printable - use black background */
269 color = 0;
272 if (style & MOD_WHITESPACE)
274 if (style & MOD_MARKED)
276 textchar = ' ';
277 tty_setcolor (EDITOR_MARKED_COLOR);
279 else
281 #if 0
282 if (color != EDITOR_NORMAL_COLOR)
284 textchar = ' ';
285 tty_lowlevel_setcolor (color);
287 else
288 #endif
289 tty_setcolor (EDITOR_WHITESPACE_COLOR);
292 else
294 if (style & MOD_BOLD)
296 tty_setcolor (EDITOR_BOLD_COLOR);
298 else if (style & MOD_MARKED)
300 tty_setcolor (EDITOR_MARKED_COLOR);
302 else
304 tty_lowlevel_setcolor (color);
307 if (show_right_margin)
309 if (i > option_word_wrap_line_length + edit->start_col)
310 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
311 i++;
313 tty_print_anychar (textchar);
314 p++;
318 /* --------------------------------------------------------------------------------------------- */
319 /** b is a pointer to the beginning of the line */
321 static void
322 edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_col)
324 struct line_s line[MAX_LINE_LEN];
325 struct line_s *p = line;
327 long m1 = 0, m2 = 0, q, c1, c2;
328 int col, start_col_real;
329 unsigned int c;
330 int color;
331 int abn_style;
332 int i;
333 int utf8lag = 0;
334 unsigned int cur_line = 0;
335 int book_mark = 0;
336 char line_stat[LINE_STATE_WIDTH + 1] = "\0";
338 if (row > edit->widget.lines - 1 - EDIT_TEXT_VERTICAL_OFFSET)
339 return;
341 if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_COLOR))
342 book_mark = BOOK_MARK_COLOR;
343 else if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_FOUND_COLOR))
344 book_mark = BOOK_MARK_FOUND_COLOR;
346 if (book_mark)
347 abn_style = book_mark << 16;
348 else
349 abn_style = MOD_ABNORMAL;
351 end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
353 edit_get_syntax_color (edit, b - 1, &color);
354 q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
355 start_col_real = (col = (int) edit_move_forward3 (edit, b, 0, q)) + edit->start_col;
356 if (option_line_state)
358 cur_line = edit->start_line + row;
359 if (cur_line <= (unsigned int) edit->total_lines)
361 g_snprintf (line_stat, LINE_STATE_WIDTH + 1, "%7i ", cur_line + 1);
363 else
365 memset (line_stat, ' ', LINE_STATE_WIDTH);
366 line_stat[LINE_STATE_WIDTH] = '\0';
368 if (book_mark_query_color (edit, cur_line, BOOK_MARK_COLOR))
370 g_snprintf (line_stat, 2, "*");
374 if (col + 16 > -edit->start_col)
376 eval_marks (edit, &m1, &m2);
378 if (row <= edit->total_lines - edit->start_line)
380 long tws = 0;
381 if (tty_use_colors () && visible_tws)
383 tws = edit_eol (edit, b);
384 while (tws > b && ((c = edit_get_byte (edit, tws - 1)) == ' ' || c == '\t'))
385 tws--;
388 while (col <= end_col - edit->start_col)
390 int cw = 1;
392 p->ch = 0;
393 p->style = 0;
394 if (q == edit->curs1)
395 p->style |= MOD_CURSOR;
396 if (q >= m1 && q < m2)
398 if (edit->column_highlight)
400 int x;
401 x = edit_move_forward3 (edit, b, 0, q);
402 c1 = min (edit->column1, edit->column2);
403 c2 = max (edit->column1, edit->column2);
404 if (x >= c1 && x < c2)
405 p->style |= MOD_MARKED;
407 else
408 p->style |= MOD_MARKED;
410 if (q == edit->bracket)
411 p->style |= MOD_BOLD;
412 if (q >= edit->found_start && q < edit->found_start + edit->found_len)
413 p->style |= MOD_BOLD;
415 if (!edit->utf8)
417 c = edit_get_byte (edit, q);
419 else
421 c = edit_get_utf (edit, q, &cw);
423 /* we don't use bg for mc - fg contains both */
424 if (book_mark)
426 p->style |= book_mark << 16;
428 else
430 edit_get_syntax_color (edit, q, &color);
431 p->style |= color << 16;
433 switch (c)
435 case '\n':
436 col = (end_col + utf8lag) - edit->start_col + 1; /* quit */
437 break;
438 case '\t':
439 i = TAB_SIZE - ((int) col % TAB_SIZE);
440 col += i;
441 if (tty_use_colors () &&
442 ((visible_tabs || (visible_tws && q >= tws)) && enable_show_tabs_tws))
444 if (p->style & MOD_MARKED)
445 c = p->style;
446 else if (book_mark)
447 c |= book_mark << 16;
448 else
449 c = p->style | MOD_WHITESPACE;
450 if (i > 2)
452 p->ch = '<';
453 p->style = c;
454 p++;
455 while (--i > 1)
457 p->ch = '-';
458 p->style = c;
459 p++;
461 p->ch = '>';
462 p->style = c;
463 p++;
465 else if (i > 1)
467 p->ch = '<';
468 p->style = c;
469 p++;
470 p->ch = '>';
471 p->style = c;
472 p++;
474 else
476 p->ch = '>';
477 p->style = c;
478 p++;
481 else if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws)
483 p->ch = '.';
484 p->style |= MOD_WHITESPACE;
485 c = p->style & ~MOD_CURSOR;
486 p++;
487 while (--i)
489 p->ch = ' ';
490 p->style = c;
491 p++;
494 else
496 p->ch |= ' ';
497 c = p->style & ~MOD_CURSOR;
498 p++;
499 while (--i)
501 p->ch = ' ';
502 p->style = c;
503 p++;
506 break;
507 case ' ':
508 if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws)
510 p->ch = '.';
511 p->style |= MOD_WHITESPACE;
512 p++;
513 col++;
514 break;
516 /* fallthrough */
517 default:
518 #ifdef HAVE_CHARSET
519 if (mc_global.utf8_display)
521 if (!edit->utf8)
523 c = convert_from_8bit_to_utf_c ((unsigned char) c, edit->converter);
526 else if (edit->utf8)
527 c = convert_from_utf_to_current_c (c, edit->converter);
528 else
529 #endif
530 c = convert_to_display_c (c);
532 /* Caret notation for control characters */
533 if (c < 32)
535 p->ch = '^';
536 p->style = abn_style;
537 p++;
538 p->ch = c + 0x40;
539 p->style = abn_style;
540 p++;
541 col += 2;
542 break;
544 if (c == 127)
546 p->ch = '^';
547 p->style = abn_style;
548 p++;
549 p->ch = '?';
550 p->style = abn_style;
551 p++;
552 col += 2;
553 break;
555 if (!edit->utf8)
557 if ((mc_global.utf8_display && g_unichar_isprint (c)) ||
558 (!mc_global.utf8_display && is_printable (c)))
560 p->ch = c;
561 p++;
563 else
565 p->ch = '.';
566 p->style = abn_style;
567 p++;
570 else
572 if (g_unichar_isprint (c))
574 p->ch = c;
575 p++;
577 else
579 p->ch = '.';
580 p->style = abn_style;
581 p++;
584 col++;
585 break;
586 } /* case */
588 q++;
589 if (cw > 1)
591 q += cw - 1;
596 else
598 start_col_real = start_col = 0;
601 p->ch = '\0';
603 print_to_widget (edit, row, start_col, start_col_real, end_col, line, line_stat, book_mark);
606 /* --------------------------------------------------------------------------------------------- */
608 static inline void
609 edit_draw_this_char (WEdit * edit, long curs, long row, long start_column, long end_column)
611 int b = edit_bol (edit, curs);
612 edit_draw_this_line (edit, b, row, start_column, end_column);
615 /* --------------------------------------------------------------------------------------------- */
616 /** cursor must be in screen for other than REDRAW_PAGE passed in force */
618 static inline void
619 render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, long end_column)
621 static long prev_curs_row = 0;
622 static long prev_curs = 0;
624 Widget *w = (Widget *) edit;
625 Dlg_head *h = w->owner;
627 long row = 0, curs_row;
628 int force = edit->force;
629 long b;
630 int y1, x1, y2, x2;
632 int last_line;
633 int last_column;
635 /* draw only visible region */
637 last_line = h->y + h->lines - 1;
639 y1 = w->y;
640 if (y1 > last_line - 1 /* buttonbar */ )
641 return;
643 last_column = h->x + h->cols - 1;
645 x1 = w->x;
646 if (x1 > last_column)
647 return;
649 y2 = w->y + w->lines - 1;
650 if (y2 < h->y + 1 /* menubar */ )
651 return;
653 x2 = w->x + w->cols - 1;
654 if (x2 < h->x)
655 return;
657 if ((force & REDRAW_IN_BOUNDS) == 0)
659 /* !REDRAW_IN_BOUNDS means to ignore bounds and redraw whole rows */
660 /* draw only visible region */
662 if (y2 <= last_line - 1 /* buttonbar */ )
663 end_row = w->lines - 1;
664 else if (y1 >= h->y + 1 /* menubar */ )
665 end_row = h->lines - 1 - y1 - 1;
666 else
667 end_row = start_row + h->lines - 1 - 1;
669 if (x2 <= last_column)
670 end_column = w->cols - 1;
671 else if (x1 >= h->x)
672 end_column = h->cols - 1 - x1;
673 else
674 end_column = start_column + h->cols - 1;
678 * If the position of the page has not moved then we can draw the cursor
679 * character only. This will prevent line flicker when using arrow keys.
681 if ((force & REDRAW_CHAR_ONLY) == 0 || (force & REDRAW_PAGE) != 0)
683 if ((force & REDRAW_PAGE) != 0)
685 row = start_row;
686 b = edit_move_forward (edit, edit->start_display, start_row, 0);
687 while (row <= end_row)
689 if (key_pending (edit))
690 return;
691 edit_draw_this_line (edit, b, row, start_column, end_column);
692 b = edit_move_forward (edit, b, 1, 0);
693 row++;
696 else
698 curs_row = edit->curs_row;
700 if ((force & REDRAW_BEFORE_CURSOR) != 0 && start_row < curs_row)
702 long upto = curs_row - 1 <= end_row ? curs_row - 1 : end_row;
704 row = start_row;
705 b = edit->start_display;
706 while (row <= upto)
708 if (key_pending (edit))
709 return;
710 edit_draw_this_line (edit, b, row, start_column, end_column);
711 b = edit_move_forward (edit, b, 1, 0);
715 /* if (force & REDRAW_LINE) ---> default */
716 b = edit_bol (edit, edit->curs1);
717 if (curs_row >= start_row && curs_row <= end_row)
719 if (key_pending (edit))
720 return;
721 edit_draw_this_line (edit, b, curs_row, start_column, end_column);
724 if ((force & REDRAW_AFTER_CURSOR) != 0 && end_row > curs_row)
726 row = curs_row + 1 < start_row ? start_row : curs_row + 1;
727 b = edit_move_forward (edit, b, 1, 0);
728 while (row <= end_row)
730 if (key_pending (edit))
731 return;
732 edit_draw_this_line (edit, b, row, start_column, end_column);
733 b = edit_move_forward (edit, b, 1, 0);
734 row++;
738 if ((force & REDRAW_LINE_ABOVE) != 0 && curs_row >= 1)
740 row = curs_row - 1;
741 b = edit_move_backward (edit, edit_bol (edit, edit->curs1), 1);
742 if (row >= start_row && row <= end_row)
744 if (key_pending (edit))
745 return;
746 edit_draw_this_line (edit, b, row, start_column, end_column);
750 if ((force & REDRAW_LINE_BELOW) != 0 && row < edit->widget.lines - 1)
752 row = curs_row + 1;
753 b = edit_bol (edit, edit->curs1);
754 b = edit_move_forward (edit, b, 1, 0);
755 if (row >= start_row && row <= end_row)
757 if (key_pending (edit))
758 return;
759 edit_draw_this_line (edit, b, row, start_column, end_column);
764 else if (prev_curs_row < edit->curs_row)
766 /* with the new text highlighting, we must draw from the top down */
767 edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);
768 edit_draw_this_char (edit, edit->curs1, edit->curs_row, start_column, end_column);
770 else
772 edit_draw_this_char (edit, edit->curs1, edit->curs_row, start_column, end_column);
773 edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);
776 edit->force = 0;
778 prev_curs_row = edit->curs_row;
779 prev_curs = edit->curs1;
782 /* --------------------------------------------------------------------------------------------- */
784 static inline void
785 edit_render (WEdit * edit, int page, int row_start, int col_start, int row_end, int col_end)
787 if (page) /* if it was an expose event, 'page' would be set */
788 edit->force |= REDRAW_PAGE | REDRAW_IN_BOUNDS;
790 if (edit->force & REDRAW_COMPLETELY)
791 buttonbar_redraw (find_buttonbar (edit->widget.owner));
792 render_edit_text (edit, row_start, col_start, row_end, col_end);
794 * edit->force != 0 means a key was pending and the redraw
795 * was halted, so next time we must redraw everything in case stuff
796 * was left undrawn from a previous key press.
798 if (edit->force)
799 edit->force |= REDRAW_PAGE;
802 /* --------------------------------------------------------------------------------------------- */
803 /*** public functions ****************************************************************************/
804 /* --------------------------------------------------------------------------------------------- */
806 /** Draw the status line at the top of the screen. The size of the filename
807 * field varies depending on the width of the screen and the length of
808 * the filename. */
809 void
810 edit_status (WEdit * edit)
812 const int w = edit->widget.owner->cols;
813 const size_t status_size = w + 1;
814 char *const status = g_malloc (status_size);
815 int status_len;
816 const char *fname = "";
817 int fname_len;
818 const int gap = 3; /* between the filename and the status */
819 const int right_gap = 5; /* at the right end of the screen */
820 const int preferred_fname_len = 16;
822 status_string (edit, status, status_size);
823 status_len = (int) str_term_width1 (status);
825 if (edit->filename_vpath != NULL)
826 fname = vfs_path_get_last_path_str (edit->filename_vpath);
828 fname_len = str_term_width1 (fname);
829 if (fname_len < preferred_fname_len)
830 fname_len = preferred_fname_len;
832 if (fname_len + gap + status_len + right_gap >= w)
834 if (preferred_fname_len + gap + status_len + right_gap >= w)
835 fname_len = preferred_fname_len;
836 else
837 fname_len = w - (gap + status_len + right_gap);
838 fname = str_trunc (fname, fname_len);
841 dlg_move (edit->widget.owner, 0, 0);
842 tty_setcolor (STATUSBAR_COLOR);
843 printwstr (fname, fname_len + gap);
844 printwstr (status, w - (fname_len + gap));
846 if (simple_statusbar && w > EDITOR_MINIMUM_TERMINAL_WIDTH)
848 size_t percent = 100;
850 if (edit->total_lines + 1 != 0)
851 percent = (edit->curs_line + 1) * 100 / (edit->total_lines + 1);
852 dlg_move (edit->widget.owner, 0, w - 5);
853 tty_printf (" %3d%%", percent);
856 g_free (status);
859 /* --------------------------------------------------------------------------------------------- */
860 /** this scrolls the text so that cursor is on the screen */
861 void
862 edit_scroll_screen_over_cursor (WEdit * edit)
864 int p;
865 int outby;
866 int b_extreme, t_extreme, l_extreme, r_extreme;
868 if (edit->widget.lines <= 0 || edit->widget.cols <= 0)
869 return;
871 edit->widget.cols -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
872 edit->widget.lines -= EDIT_TEXT_VERTICAL_OFFSET;
874 r_extreme = EDIT_RIGHT_EXTREME;
875 l_extreme = EDIT_LEFT_EXTREME;
876 b_extreme = EDIT_BOTTOM_EXTREME;
877 t_extreme = EDIT_TOP_EXTREME;
878 if (edit->found_len)
880 b_extreme = max (edit->widget.lines / 4, b_extreme);
881 t_extreme = max (edit->widget.lines / 4, t_extreme);
883 if (b_extreme + t_extreme + 1 > edit->widget.lines)
885 int n;
887 n = b_extreme + t_extreme;
888 if (n == 0)
889 n = 1;
890 b_extreme = (b_extreme * (edit->widget.lines - 1)) / n;
891 t_extreme = (t_extreme * (edit->widget.lines - 1)) / n;
893 if (l_extreme + r_extreme + 1 > edit->widget.cols)
895 int n;
897 n = l_extreme + t_extreme;
898 if (n == 0)
899 n = 1;
900 l_extreme = (l_extreme * (edit->widget.cols - 1)) / n;
901 r_extreme = (r_extreme * (edit->widget.cols - 1)) / n;
903 p = edit_get_col (edit) + edit->over_col;
904 edit_update_curs_row (edit);
905 outby = p + edit->start_col - edit->widget.cols + 1 + (r_extreme + edit->found_len);
906 if (outby > 0)
907 edit_scroll_right (edit, outby);
908 outby = l_extreme - p - edit->start_col;
909 if (outby > 0)
910 edit_scroll_left (edit, outby);
911 p = edit->curs_row;
912 outby = p - edit->widget.lines + 1 + b_extreme;
913 if (outby > 0)
914 edit_scroll_downward (edit, outby);
915 outby = t_extreme - p;
916 if (outby > 0)
917 edit_scroll_upward (edit, outby);
918 edit_update_curs_row (edit);
920 edit->widget.lines += EDIT_TEXT_VERTICAL_OFFSET;
921 edit->widget.cols += EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
924 /* --------------------------------------------------------------------------------------------- */
926 void
927 edit_render_keypress (WEdit * edit)
929 edit_render (edit, 0, 0, 0, 0, 0);
932 /* --------------------------------------------------------------------------------------------- */