keymap files: unification of Fxx keys: move to lower case.
[midnight-commander.git] / src / editor / editdraw.c
bloba3aed51ee1bb1592148cffa2ba396e13a4495ed1
1 /* editor text drawing.
3 Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006,
4 2007 Free Software Foundation, Inc.
6 Authors: 1996, 1997 Paul Sheer
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA.
24 /** \file
25 * \brief Source: editor text drawing
26 * \author Paul Sheer
27 * \date 1996, 1997
30 #include <config.h>
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <stdarg.h>
34 #include <sys/types.h>
35 #include <unistd.h>
36 #include <string.h>
37 #include <ctype.h>
38 #include <errno.h>
39 #include <sys/stat.h>
41 #include "lib/global.h"
42 #include "lib/tty/tty.h" /* tty_printf() */
43 #include "lib/tty/key.h" /* is_idle() */
44 #include "lib/skin.h"
45 #include "lib/strutil.h" /* utf string functions */
46 #include "lib/util.h" /* is_printable() */
47 #include "lib/widget.h" /* buttonbar_redraw() */
48 #include "lib/charsets.h"
50 #include "src/setup.h" /* edit_tab_spacing */
52 #include "edit-impl.h"
53 #include "edit-widget.h"
55 /*** global variables ****************************************************************************/
57 /* Toggles statusbar draw style */
58 int simple_statusbar = 0;
60 int visible_tabs = 1, visible_tws = 1;
62 /*** file scope macro definitions ****************************************************************/
64 #define MAX_LINE_LEN 1024
66 /* Text styles */
67 #define MOD_ABNORMAL (1 << 8)
68 #define MOD_BOLD (1 << 9)
69 #define MOD_MARKED (1 << 10)
70 #define MOD_CURSOR (1 << 11)
71 #define MOD_WHITESPACE (1 << 12)
73 #define FONT_OFFSET_X 0
74 #define FONT_OFFSET_Y 0
75 #define FIXED_FONT 1
76 #define FONT_PIX_PER_LINE 1
77 #define FONT_MEAN_WIDTH 1
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
86 /*** file scope type declarations ****************************************************************/
88 struct line_s
90 unsigned int ch;
91 unsigned int style;
94 /*** file scope variables ************************************************************************/
96 /*** file scope functions ************************************************************************/
97 /* --------------------------------------------------------------------------------------------- */
99 static inline void
100 status_string (WEdit * edit, char *s, int w)
102 char byte_str[16];
103 unsigned char cur_byte = 0;
104 unsigned int cur_utf = 0;
105 int cw = 1;
108 * If we are at the end of file, print <EOF>,
109 * otherwise print the current character as is (if printable),
110 * as decimal and as hex.
112 if (edit->curs1 < edit->last_byte)
114 if (!edit->utf8)
116 cur_byte = edit_get_byte (edit, edit->curs1);
118 g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X",
119 (int) cur_byte, (unsigned) cur_byte);
121 else
123 cur_utf = edit_get_utf (edit, edit->curs1, &cw);
124 if (cw > 0)
126 g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
127 (unsigned) cur_utf, (unsigned) cur_utf);
129 else
131 cur_utf = edit_get_byte (edit, edit->curs1);
132 g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
133 (int) cur_utf, (unsigned) cur_utf);
138 else
140 strcpy (byte_str, "<EOF> ");
143 /* The field lengths just prevent the status line from shortening too much */
144 if (simple_statusbar)
145 g_snprintf (s, w,
146 "%c%c%c%c %3ld %5ld/%ld %6ld/%ld %s %s",
147 edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-',
148 edit->modified ? 'M' : '-',
149 macro_index < 0 ? '-' : 'R',
150 edit->overwrite == 0 ? '-' : 'O',
151 edit->curs_col + edit->over_col,
152 edit->curs_line + 1,
153 edit->total_lines + 1, edit->curs1, edit->last_byte, byte_str,
154 #ifdef HAVE_CHARSET
155 mc_global.source_codepage >=
156 0 ? get_codepage_id (mc_global.source_codepage) : ""
157 #else
159 #endif
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, edit->curs1, edit->last_byte, byte_str,
173 #ifdef HAVE_CHARSET
174 mc_global.source_codepage >=
175 0 ? get_codepage_id (mc_global.source_codepage) : ""
176 #else
178 #endif
182 /* --------------------------------------------------------------------------------------------- */
184 static inline void
185 printwstr (const char *s, int len)
187 if (len > 0)
188 tty_printf ("%-*.*s", len, len, s);
191 /* --------------------------------------------------------------------------------------------- */
193 static inline void
194 print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
195 long end_col, struct line_s line[], char *status, int bookmarked)
197 struct line_s *p;
199 int x = start_col_real;
200 int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
201 int y = row + EDIT_TEXT_VERTICAL_OFFSET;
202 int cols_to_skip = abs (x);
203 int i;
204 int wrap_start;
205 int len;
207 tty_setcolor (EDITOR_NORMAL_COLOR);
208 if (bookmarked != 0)
209 tty_setcolor (bookmarked);
211 len = end_col + 1 - start_col;
212 wrap_start = option_word_wrap_line_length + edit->start_col;
214 if (len > 0 && edit->widget.y + y >= 0)
216 if (!show_right_margin || wrap_start > end_col)
217 tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len);
218 else if (wrap_start < 0)
220 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
221 tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len);
223 else
225 if (wrap_start > 0)
226 tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', wrap_start);
228 len -= wrap_start;
229 if (len > 0)
231 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
232 tty_draw_hline (edit->widget.y + y, edit->widget.x + x1 + wrap_start, ' ', len);
237 if (option_line_state)
239 tty_setcolor (LINE_STATE_COLOR);
240 for (i = 0; i < LINE_STATE_WIDTH; i++)
242 edit_move (x1 + i + FONT_OFFSET_X - option_line_state_width, y + FONT_OFFSET_Y);
243 if (status[i] == '\0')
244 status[i] = ' ';
245 tty_print_char (status[i]);
249 edit_move (x1 + FONT_OFFSET_X, y + FONT_OFFSET_Y);
250 p = line;
251 i = 1;
252 while (p->ch)
254 int style;
255 unsigned int textchar;
256 int color;
258 if (cols_to_skip)
260 p++;
261 cols_to_skip--;
262 continue;
265 style = p->style & 0xFF00;
266 textchar = p->ch;
267 color = p->style >> 16;
269 if (style & MOD_ABNORMAL)
271 /* Non-printable - use black background */
272 color = 0;
275 if (style & MOD_WHITESPACE)
277 if (style & MOD_MARKED)
279 textchar = ' ';
280 tty_setcolor (EDITOR_MARKED_COLOR);
282 else
284 #if 0
285 if (color != EDITOR_NORMAL_COLOR)
287 textchar = ' ';
288 tty_lowlevel_setcolor (color);
290 else
291 #endif
292 tty_setcolor (EDITOR_WHITESPACE_COLOR);
295 else
297 if (style & MOD_BOLD)
299 tty_setcolor (EDITOR_BOLD_COLOR);
301 else if (style & MOD_MARKED)
303 tty_setcolor (EDITOR_MARKED_COLOR);
305 else
307 tty_lowlevel_setcolor (color);
310 if (show_right_margin)
312 if (i > option_word_wrap_line_length + edit->start_col)
313 tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
314 i++;
316 tty_print_anychar (textchar);
317 p++;
321 /* --------------------------------------------------------------------------------------------- */
322 /** b is a pointer to the beginning of the line */
324 static void
325 edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_col)
327 struct line_s line[MAX_LINE_LEN];
328 struct line_s *p = line;
330 long m1 = 0, m2 = 0, q, c1, c2;
331 int col, start_col_real;
332 unsigned int c;
333 int color;
334 int abn_style;
335 int i;
336 int utf8lag = 0;
337 unsigned int cur_line = 0;
338 int book_mark = 0;
339 char line_stat[LINE_STATE_WIDTH + 1] = "\0";
341 if (row > edit->widget.lines - 1 - EDIT_TEXT_VERTICAL_OFFSET)
342 return;
344 if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_COLOR))
345 book_mark = BOOK_MARK_COLOR;
346 else if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_FOUND_COLOR))
347 book_mark = BOOK_MARK_FOUND_COLOR;
349 if (book_mark)
350 abn_style = book_mark << 16;
351 else
352 abn_style = MOD_ABNORMAL;
354 end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
356 edit_get_syntax_color (edit, b - 1, &color);
357 q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
358 start_col_real = (col = (int) edit_move_forward3 (edit, b, 0, q)) + edit->start_col;
359 if (option_line_state)
361 cur_line = edit->start_line + row;
362 if (cur_line <= (unsigned int) edit->total_lines)
364 g_snprintf (line_stat, LINE_STATE_WIDTH + 1, "%7i ", cur_line + 1);
366 else
368 memset (line_stat, ' ', LINE_STATE_WIDTH);
369 line_stat[LINE_STATE_WIDTH] = '\0';
371 if (book_mark_query_color (edit, cur_line, BOOK_MARK_COLOR))
373 g_snprintf (line_stat, 2, "*");
377 if (col + 16 > -edit->start_col)
379 eval_marks (edit, &m1, &m2);
381 if (row <= edit->total_lines - edit->start_line)
383 long tws = 0;
384 if (tty_use_colors () && visible_tws)
386 tws = edit_eol (edit, b);
387 while (tws > b && ((c = edit_get_byte (edit, tws - 1)) == ' ' || c == '\t'))
388 tws--;
391 while (col <= end_col - edit->start_col)
393 int cw = 1;
395 p->ch = 0;
396 p->style = 0;
397 if (q == edit->curs1)
398 p->style |= MOD_CURSOR;
399 if (q >= m1 && q < m2)
401 if (edit->column_highlight)
403 int x;
404 x = edit_move_forward3 (edit, b, 0, q);
405 c1 = min (edit->column1, edit->column2);
406 c2 = max (edit->column1, edit->column2);
407 if (x >= c1 && x < c2)
408 p->style |= MOD_MARKED;
410 else
411 p->style |= MOD_MARKED;
413 if (q == edit->bracket)
414 p->style |= MOD_BOLD;
415 if (q >= edit->found_start && q < edit->found_start + edit->found_len)
416 p->style |= MOD_BOLD;
418 if (!edit->utf8)
420 c = edit_get_byte (edit, q);
422 else
424 c = edit_get_utf (edit, q, &cw);
426 /* we don't use bg for mc - fg contains both */
427 if (book_mark)
429 p->style |= book_mark << 16;
431 else
433 edit_get_syntax_color (edit, q, &color);
434 p->style |= color << 16;
436 switch (c)
438 case '\n':
439 col = (end_col + utf8lag) - edit->start_col + 1; /* quit */
440 break;
441 case '\t':
442 i = TAB_SIZE - ((int) col % TAB_SIZE);
443 col += i;
444 if (tty_use_colors () &&
445 ((visible_tabs || (visible_tws && q >= tws)) && enable_show_tabs_tws))
447 if (p->style & MOD_MARKED)
448 c = p->style;
449 else if (book_mark)
450 c |= book_mark << 16;
451 else
452 c = p->style | MOD_WHITESPACE;
453 if (i > 2)
455 p->ch = '<';
456 p->style = c;
457 p++;
458 while (--i > 1)
460 p->ch = '-';
461 p->style = c;
462 p++;
464 p->ch = '>';
465 p->style = c;
466 p++;
468 else if (i > 1)
470 p->ch = '<';
471 p->style = c;
472 p++;
473 p->ch = '>';
474 p->style = c;
475 p++;
477 else
479 p->ch = '>';
480 p->style = c;
481 p++;
484 else if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws)
486 p->ch = '.';
487 p->style |= MOD_WHITESPACE;
488 c = p->style & ~MOD_CURSOR;
489 p++;
490 while (--i)
492 p->ch = ' ';
493 p->style = c;
494 p++;
497 else
499 p->ch |= ' ';
500 c = p->style & ~MOD_CURSOR;
501 p++;
502 while (--i)
504 p->ch = ' ';
505 p->style = c;
506 p++;
509 break;
510 case ' ':
511 if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws)
513 p->ch = '.';
514 p->style |= MOD_WHITESPACE;
515 p++;
516 col++;
517 break;
519 /* fallthrough */
520 default:
521 #ifdef HAVE_CHARSET
522 if (mc_global.utf8_display)
524 if (!edit->utf8)
526 c = convert_from_8bit_to_utf_c ((unsigned char) c, edit->converter);
529 else if (edit->utf8)
530 c = convert_from_utf_to_current_c (c, edit->converter);
531 else
532 #endif
533 c = convert_to_display_c (c);
535 /* Caret notation for control characters */
536 if (c < 32)
538 p->ch = '^';
539 p->style = abn_style;
540 p++;
541 p->ch = c + 0x40;
542 p->style = abn_style;
543 p++;
544 col += 2;
545 break;
547 if (c == 127)
549 p->ch = '^';
550 p->style = abn_style;
551 p++;
552 p->ch = '?';
553 p->style = abn_style;
554 p++;
555 col += 2;
556 break;
558 if (!edit->utf8)
560 if ((mc_global.utf8_display && g_unichar_isprint (c)) ||
561 (!mc_global.utf8_display && is_printable (c)))
563 p->ch = c;
564 p++;
566 else
568 p->ch = '.';
569 p->style = abn_style;
570 p++;
573 else
575 if (g_unichar_isprint (c))
577 p->ch = c;
578 p++;
580 else
582 p->ch = '.';
583 p->style = abn_style;
584 p++;
587 col++;
588 break;
589 } /* case */
591 q++;
592 if (cw > 1)
594 q += cw - 1;
599 else
601 start_col_real = start_col = 0;
604 p->ch = '\0';
606 print_to_widget (edit, row, start_col, start_col_real, end_col, line, line_stat, book_mark);
609 /* --------------------------------------------------------------------------------------------- */
611 static inline void
612 edit_draw_this_char (WEdit * edit, long curs, long row, long start_column, long end_column)
614 int b = edit_bol (edit, curs);
615 edit_draw_this_line (edit, b, row, start_column, end_column);
618 /* --------------------------------------------------------------------------------------------- */
619 /** cursor must be in screen for other than REDRAW_PAGE passed in force */
621 static inline void
622 render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, long end_column)
624 static long prev_curs_row = 0;
625 static long prev_curs = 0;
627 Widget *w = (Widget *) edit;
628 Dlg_head *h = w->owner;
630 long row = 0, curs_row;
631 int force = edit->force;
632 long b;
633 int y1, x1, y2, x2;
635 int last_line;
636 int last_column;
638 /* draw only visible region */
640 last_line = h->y + h->lines - 1;
642 y1 = w->y;
643 if (y1 > last_line - 1 /* buttonbar */ )
644 return;
646 last_column = h->x + h->cols - 1;
648 x1 = w->x;
649 if (x1 > last_column)
650 return;
652 y2 = w->y + w->lines - 1;
653 if (y2 < h->y + 1 /* menubar */ )
654 return;
656 x2 = w->x + w->cols - 1;
657 if (x2 < h->x)
658 return;
660 if ((force & REDRAW_IN_BOUNDS) == 0)
662 /* !REDRAW_IN_BOUNDS means to ignore bounds and redraw whole rows */
663 /* draw only visible region */
665 if (y2 <= last_line - 1 /* buttonbar */ )
666 end_row = w->lines - 1;
667 else if (y1 >= h->y + 1 /* menubar */ )
668 end_row = h->lines - 1 - y1 - 1;
669 else
670 end_row = start_row + h->lines - 1 - 1;
672 if (x2 <= last_column)
673 end_column = w->cols - 1;
674 else if (x1 >= h->x)
675 end_column = h->cols - 1 - x1;
676 else
677 end_column = start_column + h->cols - 1;
681 * If the position of the page has not moved then we can draw the cursor
682 * character only. This will prevent line flicker when using arrow keys.
684 if ((force & REDRAW_CHAR_ONLY) == 0 || (force & REDRAW_PAGE) != 0)
686 if ((force & REDRAW_PAGE) != 0)
688 row = start_row;
689 b = edit_move_forward (edit, edit->start_display, start_row, 0);
690 while (row <= end_row)
692 if (key_pending (edit))
693 return;
694 edit_draw_this_line (edit, b, row, start_column, end_column);
695 b = edit_move_forward (edit, b, 1, 0);
696 row++;
699 else
701 curs_row = edit->curs_row;
703 if ((force & REDRAW_BEFORE_CURSOR) != 0 && start_row < curs_row)
705 long upto = curs_row - 1 <= end_row ? curs_row - 1 : end_row;
707 row = start_row;
708 b = edit->start_display;
709 while (row <= upto)
711 if (key_pending (edit))
712 return;
713 edit_draw_this_line (edit, b, row, start_column, end_column);
714 b = edit_move_forward (edit, b, 1, 0);
718 /* if (force & REDRAW_LINE) ---> default */
719 b = edit_bol (edit, edit->curs1);
720 if (curs_row >= start_row && curs_row <= end_row)
722 if (key_pending (edit))
723 return;
724 edit_draw_this_line (edit, b, curs_row, start_column, end_column);
727 if ((force & REDRAW_AFTER_CURSOR) != 0 && end_row > curs_row)
729 row = curs_row + 1 < start_row ? start_row : curs_row + 1;
730 b = edit_move_forward (edit, b, 1, 0);
731 while (row <= end_row)
733 if (key_pending (edit))
734 return;
735 edit_draw_this_line (edit, b, row, start_column, end_column);
736 b = edit_move_forward (edit, b, 1, 0);
737 row++;
741 if ((force & REDRAW_LINE_ABOVE) != 0 && curs_row >= 1)
743 row = curs_row - 1;
744 b = edit_move_backward (edit, edit_bol (edit, edit->curs1), 1);
745 if (row >= start_row && row <= end_row)
747 if (key_pending (edit))
748 return;
749 edit_draw_this_line (edit, b, row, start_column, end_column);
753 if ((force & REDRAW_LINE_BELOW) != 0 && row < edit->widget.lines - 1)
755 row = curs_row + 1;
756 b = edit_bol (edit, edit->curs1);
757 b = edit_move_forward (edit, b, 1, 0);
758 if (row >= start_row && row <= end_row)
760 if (key_pending (edit))
761 return;
762 edit_draw_this_line (edit, b, row, start_column, end_column);
767 else if (prev_curs_row < edit->curs_row)
769 /* with the new text highlighting, we must draw from the top down */
770 edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);
771 edit_draw_this_char (edit, edit->curs1, edit->curs_row, start_column, end_column);
773 else
775 edit_draw_this_char (edit, edit->curs1, edit->curs_row, start_column, end_column);
776 edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);
779 edit->force = 0;
781 prev_curs_row = edit->curs_row;
782 prev_curs = edit->curs1;
785 /* --------------------------------------------------------------------------------------------- */
787 static inline void
788 edit_render (WEdit * edit, int page, int row_start, int col_start, int row_end, int col_end)
790 if (page) /* if it was an expose event, 'page' would be set */
791 edit->force |= REDRAW_PAGE | REDRAW_IN_BOUNDS;
793 if (edit->force & REDRAW_COMPLETELY)
794 buttonbar_redraw (find_buttonbar (edit->widget.owner));
795 render_edit_text (edit, row_start, col_start, row_end, col_end);
797 * edit->force != 0 means a key was pending and the redraw
798 * was halted, so next time we must redraw everything in case stuff
799 * was left undrawn from a previous key press.
801 if (edit->force)
802 edit->force |= REDRAW_PAGE;
805 /* --------------------------------------------------------------------------------------------- */
806 /*** public functions ****************************************************************************/
807 /* --------------------------------------------------------------------------------------------- */
809 /** Draw the status line at the top of the screen. The size of the filename
810 * field varies depending on the width of the screen and the length of
811 * the filename. */
812 void
813 edit_status (WEdit * edit)
815 const int w = edit->widget.owner->cols;
816 const size_t status_size = w + 1;
817 char *const status = g_malloc (status_size);
818 int status_len;
819 const char *fname = "";
820 int fname_len;
821 const int gap = 3; /* between the filename and the status */
822 const int right_gap = 5; /* at the right end of the screen */
823 const int preferred_fname_len = 16;
825 status_string (edit, status, status_size);
826 status_len = (int) str_term_width1 (status);
828 if (edit->filename)
829 fname = edit->filename;
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 /* --------------------------------------------------------------------------------------------- */