* Makefile.in: Converted to ...
[midnight-commander.git] / edit / editdraw.c
blobaad37632a16d3067d5df8644e39affda6f8a21e9
1 /* editor text drawing.
3 Copyright (C) 1996, 1997 the Free Software Foundation
5 Authors: 1996, 1997 Paul Sheer
7 $Id$
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 02111-1307, USA.
25 #include <config.h>
26 #include "edit.h"
28 #define MAX_LINE_LEN 1024
30 #if ! defined (MIDNIGHT) && ! defined (GTK)
31 #include "app_glob.c"
32 #include "coollocal.h"
33 #include "mad.h"
34 #endif
36 #ifdef HAVE_CHARSET
37 #include "../src/charsets.h"
38 #endif
40 extern int column_highlighting;
42 #if defined (MIDNIGHT) || defined (GTK)
44 static void status_string (WEdit * edit, char *s, int w, int fill, int font_width)
46 char byte_str[16];
49 * If we are at the end of file, print <EOF>,
50 * otherwise print the current character as is (if printable),
51 * as decimal and as hex.
53 if (edit->curs1 < edit->last_byte) {
54 unsigned char cur_byte = edit_get_byte (edit, edit->curs1);
55 g_snprintf (byte_str, sizeof(byte_str), "%c %3d 0x%02X",
56 is_printable(cur_byte) ? cur_byte : '.',
57 cur_byte,
58 cur_byte);
59 } else {
60 strcpy(byte_str, "<EOF>");
63 /* The field lengths just prevent the status line from shortening too much */
64 g_snprintf (s, w,
65 "[%c%c%c%c] %2ld L:[%3ld+%2ld %3ld/%3ld] *(%-4ld/%4ldb)= %s",
66 edit->mark1 != edit->mark2 ? ( column_highlighting ? 'C' : 'B') : '-',
67 edit->modified ? 'M' : '-',
68 edit->macro_i < 0 ? '-' : 'R',
69 edit->overwrite == 0 ? '-' : 'O',
70 edit->curs_col / font_width,
72 edit->start_line + 1,
73 edit->curs_row,
74 edit->curs_line + 1,
75 edit->total_lines + 1,
77 edit->curs1,
78 edit->last_byte,
79 byte_str);
82 #endif /* MIDNIGHT || GTK */
84 #ifdef MIDNIGHT
86 /* how to get as much onto the status line as is numerically possible :) */
87 void edit_status (WEdit * edit)
89 int w, i, t;
90 char *s;
91 w = edit->widget.cols - (edit->have_frame * 2);
92 s = malloc (w + 15);
93 if (w < 4)
94 w = 4;
95 memset (s, ' ', w);
96 attrset (SELECTED_COLOR);
97 if (w > 4) {
98 widget_move (edit, edit->have_frame, edit->have_frame);
99 i = w > 24 ? 18 : w - 6;
100 i = i < 13 ? 13 : i;
101 strcpy (s, (char *) name_trunc (edit->filename ? edit->filename : "", i));
102 i = strlen (s);
103 s[i] = ' ';
104 t = w - 20;
105 if (t < 0)
106 t = 0;
107 status_string (edit, s + 20, t, ' ', 1);
109 s[w] = 0;
111 printw ("%-*s", w, s);
112 attrset (NORMAL_COLOR);
113 free (s);
116 #else
119 void render_status (CWidget * wdt, int expose);
121 #ifdef GTK
123 void edit_status (WEdit *edit)
125 GtkEntry *entry;
126 int w, i, t;
127 char s[160];
128 w = edit->num_widget_columns - 1;
129 if (w > 150)
130 w = 150;
131 if (w < 0)
132 w = 0;
133 memset (s, 0, w);
134 if (w > 1) {
135 i = w > 24 ? 18 : w - 6;
136 i = i < 13 ? 13 : i;
137 strcpy (s, (char *) name_trunc (edit->filename ? edit->filename : "", i));
138 i = strlen (s);
139 s[i] = ' ';
140 s[i + 1] = ' ';
141 t = w - i - 2;
142 if (t < 0)
143 t = 0;
144 status_string (edit, s + i + 2, t, 0, FONT_MEAN_WIDTH);
146 s[w] = 0;
147 entry = GTK_ENTRY (edit->widget->status);
148 if (strcmp (s, gtk_entry_get_text (entry)))
149 gtk_entry_set_text (entry, s);
152 #else
154 void edit_status (WEdit * edit)
156 long start_mark, end_mark;
157 CWidget *wdt;
158 mode_t m;
159 char *p;
160 char id[33];
161 char s[256];
162 if (eval_marks (edit, &start_mark, &end_mark))
163 end_mark = start_mark = 0;
164 if ((COptionsOf (edit->widget) & EDITOR_NO_TEXT))
165 return;
166 CPushFont ("editor", 0);
167 m = edit->stat.st_mode;
168 p = edit->filename ? edit->filename : "";
169 sprintf (s, "\034%c%s\033\035 \034-%c%c%c%c%c%c%c%c%c\035 \034%s%s%s%c\035 \034\030%02ld\033\035 \034%-4ld+%2ld=\030%4ld\033/%3ld\035 \034*%-5ld/%5ldb=%c%3d\035%c \034\001%ld\033\035",
170 *p ? '\033' : '\003', *p ? (char *) name_trunc (p, max (edit->num_widget_lines / 3, 16)) : _ ("<unnamed>"),
171 m & S_IRUSR ? 'r' : '-',
172 m & S_IWUSR ? 'w' : '-',
173 m & S_IXUSR ? 'x' : '-',
174 m & S_IRGRP ? 'r' : '-',
175 m & S_IWGRP ? 'w' : '-',
176 m & S_IXGRP ? 'x' : '-',
177 m & S_IROTH ? 'r' : '-',
178 m & S_IWOTH ? 'w' : '-',
179 m & S_IXOTH ? 'x' : '-',
180 end_mark - start_mark || (edit->mark2 == -1 && !edit->highlight) ? (column_highlighting ? "\032C\033" : "\001B\033") : "-",
181 edit->modified ? "\012M\033" : "-", edit->macro_i < 0 ? "-" : "\023R\033",
182 edit->overwrite == 0 ? '-' : 'O',
183 edit->curs_col / FONT_MEAN_WIDTH, edit->start_line + 1, edit->curs_row,
184 edit->curs_line + 1, edit->total_lines + 1, edit->curs1,
185 edit->last_byte, edit->curs1 == edit->last_byte ? '\014' : '\033', edit->curs1 < edit->last_byte
186 ? edit_get_byte (edit, edit->curs1) : -1,
187 end_mark - start_mark && !column_highlighting ? ' ' : '\0',
188 end_mark - start_mark);
189 strcpy (id, CIdentOf (edit->widget));
190 strcat (id, ".text");
191 wdt = CIdent (id);
192 free (wdt->text);
193 wdt->text = (char *) strdup (s);
194 CSetWidgetSize (id, CWidthOf (edit->widget), CHeightOf (wdt));
195 render_status (wdt, 0);
196 CPopFont ();
199 #endif /* GTK */
201 #endif /* !MIDNIGHT */
204 /* result is boolean */
205 int cursor_in_screen (WEdit * edit, long row)
207 if (row < 0 || row >= edit->num_widget_lines)
208 return 0;
209 else
210 return 1;
213 /* returns rows from the first displayed line to the cursor */
214 int cursor_from_display_top (WEdit * edit)
216 if (edit->curs1 < edit->start_display)
217 return -edit_move_forward (edit, edit->curs1, 0, edit->start_display);
218 else
219 return edit_move_forward (edit, edit->start_display, 0, edit->curs1);
222 /* returns how far the cursor is out of the screen */
223 int cursor_out_of_screen (WEdit * edit)
225 int row = cursor_from_display_top (edit);
226 if (row >= edit->num_widget_lines)
227 return row - edit->num_widget_lines + 1;
228 if (row < 0)
229 return row;
230 return 0;
233 #ifndef MIDNIGHT
234 int edit_width_of_long_printable (int c);
235 #endif
237 /* this scrolls the text so that cursor is on the screen */
238 void edit_scroll_screen_over_cursor (WEdit * edit)
240 int p;
241 int outby;
242 int b_extreme, t_extreme, l_extreme, r_extreme;
243 r_extreme = EDIT_RIGHT_EXTREME;
244 l_extreme = EDIT_LEFT_EXTREME;
245 b_extreme = EDIT_BOTTOM_EXTREME;
246 t_extreme = EDIT_TOP_EXTREME;
247 if (edit->found_len) {
248 b_extreme = max (edit->num_widget_lines / 4, b_extreme);
249 t_extreme = max (edit->num_widget_lines / 4, t_extreme);
251 if (b_extreme + t_extreme + 1 > edit->num_widget_lines) {
252 int n;
253 n = b_extreme + t_extreme;
254 b_extreme = (b_extreme * (edit->num_widget_lines - 1)) / n;
255 t_extreme = (t_extreme * (edit->num_widget_lines - 1)) / n;
257 if (l_extreme + r_extreme + 1 > edit->num_widget_columns) {
258 int n;
259 n = l_extreme + t_extreme;
260 l_extreme = (l_extreme * (edit->num_widget_columns - 1)) / n;
261 r_extreme = (r_extreme * (edit->num_widget_columns - 1)) / n;
263 p = edit_get_col (edit);
264 edit_update_curs_row (edit);
265 #ifdef MIDNIGHT
266 outby = p + edit->start_col - edit->num_widget_columns + 1 + (r_extreme + edit->found_len);
267 #else
268 outby = p + edit->start_col - CWidthOf (edit->widget) + 7 + (r_extreme + edit->found_len) * FONT_MEAN_WIDTH + edit_width_of_long_printable (edit_get_byte (edit, edit->curs1));
269 #endif
270 if (outby > 0)
271 edit_scroll_right (edit, outby);
272 #ifdef MIDNIGHT
273 outby = l_extreme - p - edit->start_col;
274 #else
275 outby = l_extreme * FONT_MEAN_WIDTH - p - edit->start_col;
276 #endif
277 if (outby > 0)
278 edit_scroll_left (edit, outby);
279 p = edit->curs_row;
280 outby = p - edit->num_widget_lines + 1 + b_extreme;
281 if (outby > 0)
282 edit_scroll_downward (edit, outby);
283 outby = t_extreme - p;
284 if (outby > 0)
285 edit_scroll_upward (edit, outby);
286 edit_update_curs_row (edit);
290 #ifndef MIDNIGHT
292 #define CACHE_WIDTH 256
293 #define CACHE_HEIGHT 128
295 int EditExposeRedraw = 0;
296 int EditClear = 0;
299 * background colors: marked is refers to mouse highlighting,
300 * highlighted refers to a found string.
302 unsigned long edit_abnormal_color, edit_marked_abnormal_color;
303 unsigned long edit_highlighted_color, edit_marked_color;
304 unsigned long edit_normal_background_color;
306 /* foreground colors */
307 unsigned long edit_normal_foreground_color, edit_bold_color;
308 unsigned long edit_italic_color;
310 /* cursor color */
311 unsigned long edit_cursor_color;
313 void edit_set_foreground_colors (unsigned long normal, unsigned long bold, unsigned long italic)
315 edit_normal_foreground_color = normal;
316 edit_bold_color = bold;
317 edit_italic_color = italic;
320 void edit_set_background_colors (unsigned long normal, unsigned long abnormal, unsigned long marked, unsigned long marked_abnormal, unsigned long highlighted)
322 edit_abnormal_color = abnormal;
323 edit_marked_abnormal_color = marked_abnormal;
324 edit_marked_color = marked;
325 edit_highlighted_color = highlighted;
326 edit_normal_background_color = normal;
329 void edit_set_cursor_color (unsigned long c)
331 edit_cursor_color = c;
334 #else
336 #define set_color(font) attrset (font)
338 #define edit_move(x,y) widget_move(edit, y, x);
340 static void print_to_widget (WEdit * edit, long row, int start_col, float start_col_real, long end_col, unsigned int line[])
342 int x = (float) start_col_real + EDIT_TEXT_HORIZONTAL_OFFSET;
343 int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET;
344 int y = row + EDIT_TEXT_VERTICAL_OFFSET;
346 set_color (EDITOR_NORMAL_COLOR);
347 edit_move (x1, y);
348 hline (' ', end_col + 1 - EDIT_TEXT_HORIZONTAL_OFFSET - x1);
350 edit_move (x + FONT_OFFSET_X, y + FONT_OFFSET_Y);
352 unsigned int *p = line;
353 int textchar = ' ';
354 long style;
356 while (*p) {
357 style = *p >> 8;
358 textchar = *p & 0xFF;
359 #ifdef HAVE_SYNTAXH
360 if (!(style & (0xFF - MOD_ABNORMAL - MOD_CURSOR)))
361 SLsmg_set_color ((*p & 0x007F0000) >> 16);
362 #endif
363 if (style & MOD_ABNORMAL)
364 textchar = '.';
365 if (style & MOD_HIGHLIGHTED) {
366 set_color (EDITOR_BOLD_COLOR);
367 } else if (style & MOD_MARKED) {
368 set_color (EDITOR_MARKED_COLOR);
370 if (style & MOD_UNDERLINED) {
371 set_color (EDITOR_UNDERLINED_COLOR);
373 if (style & MOD_BOLD) {
374 set_color (EDITOR_BOLD_COLOR);
376 addch (textchar);
377 p++;
382 /* b is a pointer to the beginning of the line */
383 static void edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_col)
385 static unsigned int line[MAX_LINE_LEN];
386 unsigned int *p = line;
387 long m1 = 0, m2 = 0, q, c1, c2;
388 int col, start_col_real;
389 unsigned int c;
390 int fg, bg;
391 int i, book_mark = -1;
393 #if 0
394 if (!book_mark_query (edit, edit->start_line + row, &book_mark))
395 book_mark = -1;
396 #endif
398 edit_get_syntax_color (edit, b - 1, &fg, &bg);
399 q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
400 start_col_real = (col = (int) edit_move_forward3 (edit, b, 0, q)) + edit->start_col;
401 c1 = min (edit->column1, edit->column2);
402 c2 = max (edit->column1, edit->column2);
404 if (col + 16 > -edit->start_col) {
405 eval_marks (edit, &m1, &m2);
407 if (row <= edit->total_lines - edit->start_line) {
408 while (col <= end_col - edit->start_col) {
409 *p = 0;
410 if (q == edit->curs1)
411 *p |= MOD_CURSOR * 256;
412 if (q >= m1 && q < m2) {
413 if (column_highlighting) {
414 int x;
415 x = edit_move_forward3 (edit, b, 0, q);
416 if (x >= c1 && x < c2)
417 *p |= MOD_MARKED * 256;
418 } else
419 *p |= MOD_MARKED * 256;
421 if (q == edit->bracket)
422 *p |= MOD_BOLD * 256;
423 if (q >= edit->found_start && q < edit->found_start + edit->found_len)
424 *p |= MOD_HIGHLIGHTED * 256;
425 c = edit_get_byte (edit, q);
426 /* we don't use bg for mc - fg contains both */
427 if (book_mark == -1) {
428 edit_get_syntax_color (edit, q, &fg, &bg);
429 *p |= fg << 16;
430 } else {
431 *p |= book_mark << 16;
433 q++;
434 switch (c) {
435 case '\n':
436 col = end_col - edit->start_col + 1; /* quit */
437 *(p++) |= ' ';
438 break;
439 case '\t':
440 i = TAB_SIZE - ((int) col % TAB_SIZE);
441 *p |= ' ';
442 c = *(p++) & (0xFFFFFFFF - MOD_CURSOR * 256);
443 col += i;
444 while (--i)
445 *(p++) = c;
446 break;
447 case '\r':
448 break;
449 default:
450 #ifdef HAVE_CHARSET
451 if (c >= 0 && c <= 255)
452 c = conv_displ[ c ];
453 #endif
454 if (is_printable (c)) {
455 *(p++) |= c;
456 } else {
457 *(p++) = '.';
458 *p |= (256 * MOD_ABNORMAL);
460 col++;
461 break;
465 } else {
466 start_col_real = start_col = 0;
468 *p = 0;
470 print_to_widget (edit, row, start_col, start_col_real, end_col, line);
473 #endif
475 #ifdef MIDNIGHT
477 #define key_pending(x) (!is_idle())
479 #else
481 #define edit_draw_this_line edit_draw_this_line_proportional
483 int option_smooth_scrolling = 0;
485 static int key_pending (WEdit * edit)
487 #ifdef GTK
488 /* ******* */
489 #else
490 static int flush = 0, line = 0;
491 if (!edit) {
492 flush = line = 0;
493 } else if (!(edit->force & REDRAW_COMPLETELY) && !EditExposeRedraw && !option_smooth_scrolling) {
494 /* this flushes the display in logarithmic intervals - so both fast and
495 slow machines will get good performance vs nice-refreshing */
496 if ((1 << flush) == ++line) {
497 flush++;
498 return CKeyPending ();
501 #endif
502 return 0;
505 #endif
508 static void edit_draw_this_char (WEdit * edit, long curs, long row)
510 int b = edit_bol (edit, curs);
511 #ifdef MIDNIGHT
512 edit_draw_this_line (edit, b, row, 0, edit->num_widget_columns - 1);
513 #else
514 edit_draw_this_line (edit, b, row, 0, CWidthOf (edit->widget));
515 #endif
518 /* cursor must be in screen for other than REDRAW_PAGE passed in force */
519 void render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
520 long end_column)
522 long row = 0, curs_row;
523 static int prev_curs_row = 0;
524 static int prev_start_col = 0;
525 static long prev_curs = 0;
526 static long prev_start = -1;
528 #ifndef MIDNIGHT
529 static unsigned long prev_win = 0;
530 #endif
532 int force = edit->force;
533 long b;
535 CPushFont ("editor", 0);
537 #ifndef MIDNIGHT
538 key_pending (0);
539 #endif
542 * If the position of the page has not moved then we can draw the cursor
543 * character only. This will prevent line flicker when using arrow keys.
545 if ((!(force & REDRAW_CHAR_ONLY)) || (force & REDRAW_PAGE)
546 #ifndef MIDNIGHT
547 #ifdef GTK
548 || prev_win != ((GdkWindowPrivate *) CWindowOf (edit->widget)->text_area)->xwindow
549 #else
550 || prev_win != CWindowOf (edit->widget)
551 #endif
552 #endif
554 #if !defined(MIDNIGHT) && !defined(GTK)
555 int time_division = 5;
556 #if 0
557 if (CPending ())
558 time_division--;
559 #endif
560 if (prev_start < 0)
561 prev_start = edit->start_line;
562 if (option_smooth_scrolling && prev_win == CWindowOf (edit->widget) && !edit->screen_modified) {
563 int i, t;
564 int pos1, pos2;
565 i = edit->start_line - prev_start;
566 if (i <= time_division && i > 0) {
567 edit_draw_proportional (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
568 for (pos2 = 0, t = 0; t < time_division; t++) {
569 int move;
570 pos1 = FONT_PIX_PER_LINE * i * (t + 1) / time_division;
571 move = pos1 - pos2;
572 pos2 += move;
573 XCopyArea (CDisplay, edit->widget->winid, edit->widget->winid, CGC,
574 EDIT_TEXT_HORIZONTAL_OFFSET,
575 EDIT_TEXT_VERTICAL_OFFSET + move,
576 edit->widget->width - EDIT_FRAME_W,
577 edit->widget->height - EDIT_FRAME_H - move,
578 EDIT_TEXT_HORIZONTAL_OFFSET, EDIT_TEXT_VERTICAL_OFFSET);
579 XClearArea (CDisplay, edit->widget->winid, EDIT_TEXT_HORIZONTAL_OFFSET,
580 edit->widget->height - EDIT_FRAME_H +
581 EDIT_TEXT_VERTICAL_OFFSET - move,
582 edit->widget->width - EDIT_FRAME_W, move, 0);
583 XFlush (CDisplay);
584 pause ();
586 } else if (i >= -time_division && i < 0) {
587 edit_draw_proportional (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
588 i = -i;
589 for (pos2 = 0, t = 0; t < time_division; t++) {
590 int move;
591 pos1 = FONT_PIX_PER_LINE * i * (t + 1) / time_division;
592 move = pos1 - pos2;
593 pos2 += move;
594 XCopyArea (CDisplay, edit->widget->winid, edit->widget->winid, CGC,
595 EDIT_TEXT_HORIZONTAL_OFFSET, EDIT_TEXT_VERTICAL_OFFSET,
596 edit->widget->width - EDIT_FRAME_W,
597 edit->widget->height - EDIT_FRAME_H -
598 move, EDIT_TEXT_HORIZONTAL_OFFSET, EDIT_TEXT_VERTICAL_OFFSET + move);
599 XClearArea (CDisplay, edit->widget->winid, EDIT_TEXT_HORIZONTAL_OFFSET,
600 EDIT_TEXT_VERTICAL_OFFSET,
601 edit->widget->width - EDIT_FRAME_W, move, 0);
602 XFlush (CDisplay);
603 pause ();
607 #endif
608 if (!(force & REDRAW_IN_BOUNDS)) { /* !REDRAW_IN_BOUNDS means to ignore bounds and redraw whole rows */
609 start_row = 0;
610 end_row = edit->num_widget_lines - 1;
611 start_column = 0;
612 #ifdef MIDNIGHT
613 end_column = edit->num_widget_columns - 1;
614 #else
615 end_column = CWidthOf (edit->widget);
616 #endif
618 if (force & REDRAW_PAGE) {
619 row = start_row;
620 b = edit_move_forward (edit, edit->start_display, start_row, 0);
621 while (row <= end_row) {
622 if (key_pending (edit))
623 goto exit_render;
624 edit_draw_this_line (edit, b, row, start_column, end_column);
625 b = edit_move_forward (edit, b, 1, 0);
626 row++;
628 } else {
629 curs_row = edit->curs_row;
631 if (force & REDRAW_BEFORE_CURSOR) {
632 if (start_row < curs_row) {
633 long upto = curs_row - 1 <= end_row ? curs_row - 1 : end_row;
634 row = start_row;
635 b = edit->start_display;
636 while (row <= upto) {
637 if (key_pending (edit))
638 goto exit_render;
639 edit_draw_this_line (edit, b, row, start_column, end_column);
640 b = edit_move_forward (edit, b, 1, 0);
644 /* if (force & REDRAW_LINE) ---> default */
645 b = edit_bol (edit, edit->curs1);
646 if (curs_row >= start_row && curs_row <= end_row) {
647 if (key_pending (edit))
648 goto exit_render;
649 edit_draw_this_line (edit, b, curs_row, start_column, end_column);
651 if (force & REDRAW_AFTER_CURSOR) {
652 if (end_row > curs_row) {
653 row = curs_row + 1 < start_row ? start_row : curs_row + 1;
654 b = edit_move_forward (edit, b, 1, 0);
655 while (row <= end_row) {
656 if (key_pending (edit))
657 goto exit_render;
658 edit_draw_this_line (edit, b, row, start_column, end_column);
659 b = edit_move_forward (edit, b, 1, 0);
660 row++;
664 if (force & REDRAW_LINE_ABOVE && curs_row >= 1) {
665 row = curs_row - 1;
666 b = edit_move_backward (edit, edit_bol (edit, edit->curs1), 1);
667 if (row >= start_row && row <= end_row) {
668 if (key_pending (edit))
669 goto exit_render;
670 edit_draw_this_line (edit, b, row, start_column, end_column);
673 if (force & REDRAW_LINE_BELOW && row < edit->num_widget_lines - 1) {
674 row = curs_row + 1;
675 b = edit_bol (edit, edit->curs1);
676 b = edit_move_forward (edit, b, 1, 0);
677 if (row >= start_row && row <= end_row) {
678 if (key_pending (edit))
679 goto exit_render;
680 edit_draw_this_line (edit, b, row, start_column, end_column);
684 } else {
685 if (prev_curs_row < edit->curs_row) { /* with the new text highlighting, we must draw from the top down */
686 edit_draw_this_char (edit, prev_curs, prev_curs_row);
687 edit_draw_this_char (edit, edit->curs1, edit->curs_row);
688 } else {
689 edit_draw_this_char (edit, edit->curs1, edit->curs_row);
690 edit_draw_this_char (edit, prev_curs, prev_curs_row);
694 edit->force = 0;
696 prev_curs_row = edit->curs_row;
697 prev_curs = edit->curs1;
698 prev_start_col = edit->start_col;
699 #ifndef MIDNIGHT
700 #ifdef GTK
701 prev_win = ((GdkWindowPrivate *) CWindowOf (edit->widget)->text_area)->xwindow;
702 #else
703 prev_win = CWindowOf (edit->widget);
704 #endif
705 #endif
706 exit_render:
707 edit->screen_modified = 0;
708 prev_start = edit->start_line;
709 CPopFont ();
710 return;
715 #ifndef MIDNIGHT
717 void edit_convert_expose_to_area (XExposeEvent * xexpose, int *row1, int *col1, int *row2, int *col2)
719 *col1 = xexpose->x - EDIT_TEXT_HORIZONTAL_OFFSET;
720 *row1 = (xexpose->y - EDIT_TEXT_VERTICAL_OFFSET) / FONT_PIX_PER_LINE;
721 *col2 = xexpose->x + xexpose->width + EDIT_TEXT_HORIZONTAL_OFFSET + 3;
722 *row2 = (xexpose->y + xexpose->height - EDIT_TEXT_VERTICAL_OFFSET) / FONT_PIX_PER_LINE;
725 #ifdef GTK
727 void edit_render_tidbits (GtkEdit * edit)
729 gtk_widget_draw_focus (GTK_WIDGET (edit));
732 #else
734 void edit_render_tidbits (CWidget * wdt)
736 int isfocussed;
737 int w = wdt->width, h = wdt->height;
738 Window win;
740 win = wdt->winid;
741 isfocussed = (win == CGetFocus ());
742 CSetColor (COLOR_FLAT);
743 #ifdef NEXT_LOOK
744 render_bevel (win, 0, 0, w - 1, h - 1, 1, 1); /*most outer border bevel */
745 #else
746 if (isfocussed) {
747 render_bevel (win, 0, 0, w - 1, h - 1, 3, 1); /*most outer border bevel */
748 } else {
749 render_bevel (win, 2, 2, w - 3, h - 3, 1, 1); /*border bevel */
750 render_bevel (win, 0, 0, w - 1, h - 1, 2, 0); /*most outer border bevel */
752 #endif
755 #endif
757 void edit_set_space_width (int s);
758 extern int option_long_whitespace;
760 #endif
762 void edit_render (WEdit * edit, int page, int row_start, int col_start, int row_end, int col_end)
764 int f = 0;
765 #ifdef GTK
766 GtkEdit *win;
767 #endif
768 if (page) /* if it was an expose event, 'page' would be set */
769 edit->force |= REDRAW_PAGE | REDRAW_IN_BOUNDS;
770 f = edit->force & (REDRAW_PAGE | REDRAW_COMPLETELY);
772 #ifdef MIDNIGHT
773 if (edit->force & REDRAW_COMPLETELY)
774 redraw_labels (edit->widget.parent, (Widget *) edit);
775 #else
776 if (option_long_whitespace)
777 edit_set_space_width (FONT_PER_CHAR[' '] * 2);
778 else
779 edit_set_space_width (FONT_PER_CHAR[' ']);
780 #ifdef GTK
781 win = (GtkEdit *) edit->widget;
782 #endif
783 edit_set_foreground_colors (
784 color_palette (option_editor_fg_normal),
785 color_palette (option_editor_fg_bold),
786 color_palette (option_editor_fg_italic)
788 edit_set_background_colors (
789 color_palette (option_editor_bg_normal),
790 color_palette (option_editor_bg_abnormal),
791 color_palette (option_editor_bg_marked),
792 color_palette (option_editor_bg_marked_abnormal),
793 color_palette (option_editor_bg_highlighted)
795 edit_set_cursor_color (
796 color_palette (option_editor_fg_cursor)
799 #ifdef GTK
800 /* *********** */
801 #else
802 if (!EditExposeRedraw)
803 set_cursor_position (0, 0, 0, 0, 0, 0, 0, 0, 0);
804 #endif
805 #endif
806 render_edit_text (edit, row_start, col_start, row_end, col_end);
808 * edit->force != 0 means a key was pending and the redraw
809 * was halted, so next time we must redraw everything in case stuff
810 * was left undrawn from a previous key press.
812 if (edit->force)
813 edit->force |= REDRAW_PAGE;
814 #ifndef MIDNIGHT
815 if (f) {
816 edit_render_tidbits (edit->widget);
817 #ifdef GTK
818 /* ***************** */
819 #else
820 #ifndef NEXT_LOOK
821 CSetColor (edit_normal_background_color);
822 CLine (CWindowOf (edit->widget), 3, 3, 3, CHeightOf (edit->widget) - 4);
823 #endif
824 #endif
826 #endif
829 #ifndef MIDNIGHT
830 void edit_render_expose (WEdit * edit, XExposeEvent * xexpose)
832 int row_start, col_start, row_end, col_end;
833 CPushFont ("editor", 0);
834 EditExposeRedraw = 1;
835 edit->num_widget_lines = (CHeightOf (edit->widget) - EDIT_FRAME_H) / FONT_PIX_PER_LINE;
836 edit->num_widget_columns = (CWidthOf (edit->widget) - EDIT_FRAME_W) / FONT_MEAN_WIDTH;
837 if (edit->force & (REDRAW_PAGE | REDRAW_COMPLETELY)) {
838 edit->force |= REDRAW_PAGE | REDRAW_COMPLETELY;
839 edit_render_keypress (edit);
840 } else {
841 edit_convert_expose_to_area (xexpose, &row_start, &col_start, &row_end, &col_end);
842 edit_render (edit, 1, row_start, col_start, row_end, col_end);
844 CPopFont ();
845 EditExposeRedraw = 0;
848 void edit_render_keypress (WEdit * edit)
850 CPushFont ("editor", 0);
851 edit_render (edit, 0, 0, 0, 0, 0);
852 CPopFont ();
855 #else
857 void edit_render_keypress (WEdit * edit)
859 edit_render (edit, 0, 0, 0, 0, 0);
862 #endif