editdraw.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /* editor text drawing.
  2. Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006,
  3. 2007 Free Software Foundation, Inc.
  4. Authors: 1996, 1997 Paul Sheer
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301, USA.
  17. */
  18. /** \file
  19. * \brief Source: editor text drawing
  20. * \author Paul Sheer
  21. * \date 1996, 1997
  22. */
  23. #include <config.h>
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <stdarg.h>
  27. #include <sys/types.h>
  28. #include <unistd.h>
  29. #include <string.h>
  30. #include <ctype.h>
  31. #include <errno.h>
  32. #include <sys/stat.h>
  33. #include "../src/global.h"
  34. #include "edit-impl.h"
  35. #include "edit-widget.h"
  36. #define MAX_LINE_LEN 1024
  37. #include "../src/tty/tty.h" /* tty_printf() */
  38. #include "../src/tty/color.h"
  39. #include "../src/tty/key.h" /* is_idle() */
  40. #include "../src/widget.h" /* buttonbar_redraw() */
  41. #include "../src/charsets.h"
  42. #include "../src/strutil.h" /* utf string functions */
  43. #include "../src/main.h" /* source_codepage */
  44. /* Text styles */
  45. #define MOD_ABNORMAL (1 << 8)
  46. #define MOD_BOLD (1 << 9)
  47. #define MOD_MARKED (1 << 10)
  48. #define MOD_CURSOR (1 << 11)
  49. #define MOD_WHITESPACE (1 << 12)
  50. #define FONT_OFFSET_X 0
  51. #define FONT_OFFSET_Y 0
  52. #define FIXED_FONT 1
  53. #define FONT_PIX_PER_LINE 1
  54. #define FONT_MEAN_WIDTH 1
  55. /* Toggles statusbar draw style */
  56. int simple_statusbar = 0;
  57. static void status_string (WEdit * edit, char *s, int w)
  58. {
  59. char byte_str[16];
  60. unsigned char cur_byte = 0;
  61. unsigned int cur_utf = 0;
  62. int cw = 1;
  63. /*
  64. * If we are at the end of file, print <EOF>,
  65. * otherwise print the current character as is (if printable),
  66. * as decimal and as hex.
  67. */
  68. if (edit->curs1 < edit->last_byte) {
  69. if ( !edit->utf8 ) {
  70. cur_byte = edit_get_byte (edit, edit->curs1);
  71. g_snprintf (byte_str, sizeof (byte_str), "%4d 0x%03X",
  72. (int) cur_byte,
  73. (unsigned) cur_byte);
  74. } else {
  75. cur_utf = edit_get_utf (edit, edit->curs1, &cw);
  76. if ( cw > 0 ) {
  77. g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
  78. (unsigned) cur_utf,
  79. (unsigned) cur_utf);
  80. } else {
  81. cur_utf = edit_get_byte (edit, edit->curs1);
  82. g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
  83. (int) cur_utf,
  84. (unsigned) cur_utf);
  85. }
  86. }
  87. } else {
  88. strcpy (byte_str, "<EOF> ");
  89. }
  90. /* The field lengths just prevent the status line from shortening too much */
  91. if (simple_statusbar)
  92. g_snprintf (s, w,
  93. "[%c%c%c%c] %2ld %3ld/%3ld (%-4ld/%4ldb)= %s cp:%s",
  94. edit->mark1 != edit->mark2 ? ( column_highlighting ? 'C' : 'B') : '-',
  95. edit->modified ? 'M' : '-',
  96. edit->macro_i < 0 ? '-' : 'R',
  97. edit->overwrite == 0 ? '-' : 'O',
  98. edit->curs_col,
  99. edit->curs_line + 1,
  100. edit->total_lines + 1,
  101. edit->curs1,
  102. edit->last_byte,
  103. byte_str,
  104. #ifdef HAVE_CHARSET
  105. source_codepage >= 0 ? get_codepage_id (source_codepage) : ""
  106. #else
  107. ""
  108. #endif
  109. );
  110. else
  111. g_snprintf (s, w,
  112. "[%c%c%c%c] %2ld L:[%3ld+%2ld %3ld/%3ld] *(%-4ld/%4ldb)= %s %s",
  113. edit->mark1 != edit->mark2 ? ( column_highlighting ? 'C' : 'B') : '-',
  114. edit->modified ? 'M' : '-',
  115. edit->macro_i < 0 ? '-' : 'R',
  116. edit->overwrite == 0 ? '-' : 'O',
  117. edit->curs_col,
  118. edit->start_line + 1,
  119. edit->curs_row,
  120. edit->curs_line + 1,
  121. edit->total_lines + 1,
  122. edit->curs1,
  123. edit->last_byte,
  124. byte_str,
  125. #ifdef HAVE_CHARSET
  126. source_codepage >= 0 ? get_codepage_id (source_codepage) : ""
  127. #else
  128. ""
  129. #endif
  130. );
  131. }
  132. static inline void
  133. printwstr (const char *s, int len)
  134. {
  135. if (len > 0)
  136. tty_printf ("%-*.*s", len, len, s);
  137. }
  138. /* Draw the status line at the top of the widget. The size of the filename
  139. * field varies depending on the width of the screen and the length of
  140. * the filename. */
  141. void
  142. edit_status (WEdit *edit)
  143. {
  144. const int w = edit->widget.cols;
  145. const size_t status_size = w + 1;
  146. char * const status = g_malloc (status_size);
  147. int status_len;
  148. const char *fname = "";
  149. int fname_len;
  150. const int gap = 3; /* between the filename and the status */
  151. const int right_gap = 2; /* at the right end of the screen */
  152. const int preferred_fname_len = 16;
  153. status_string (edit, status, status_size);
  154. status_len = (int) str_term_width1 (status);
  155. if (edit->filename)
  156. fname = edit->filename;
  157. fname_len = str_term_width1 (fname);
  158. if (fname_len < preferred_fname_len)
  159. fname_len = preferred_fname_len;
  160. if (fname_len + gap + status_len + right_gap >= w) {
  161. if (preferred_fname_len + gap + status_len + right_gap >= w)
  162. fname_len = preferred_fname_len;
  163. else
  164. fname_len = w - (gap + status_len + right_gap);
  165. fname = str_trunc (fname, fname_len);
  166. }
  167. widget_move (edit, 0, 0);
  168. tty_setcolor (SELECTED_COLOR);
  169. printwstr (fname, fname_len + gap);
  170. printwstr (status, w - (fname_len + gap));
  171. tty_setcolor (EDITOR_NORMAL_COLOR);
  172. g_free (status);
  173. }
  174. /* this scrolls the text so that cursor is on the screen */
  175. void edit_scroll_screen_over_cursor (WEdit * edit)
  176. {
  177. int p;
  178. int outby;
  179. int b_extreme, t_extreme, l_extreme, r_extreme;
  180. if (edit->num_widget_lines <= 0 || edit->num_widget_columns <= 0)
  181. return;
  182. edit->num_widget_columns -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
  183. edit->num_widget_lines -= EDIT_TEXT_VERTICAL_OFFSET - 1;
  184. r_extreme = EDIT_RIGHT_EXTREME;
  185. l_extreme = EDIT_LEFT_EXTREME;
  186. b_extreme = EDIT_BOTTOM_EXTREME;
  187. t_extreme = EDIT_TOP_EXTREME;
  188. if (edit->found_len) {
  189. b_extreme = max (edit->num_widget_lines / 4, b_extreme);
  190. t_extreme = max (edit->num_widget_lines / 4, t_extreme);
  191. }
  192. if (b_extreme + t_extreme + 1 > edit->num_widget_lines) {
  193. int n;
  194. n = b_extreme + t_extreme;
  195. b_extreme = (b_extreme * (edit->num_widget_lines - 1)) / n;
  196. t_extreme = (t_extreme * (edit->num_widget_lines - 1)) / n;
  197. }
  198. if (l_extreme + r_extreme + 1 > edit->num_widget_columns) {
  199. int n;
  200. n = l_extreme + t_extreme;
  201. l_extreme = (l_extreme * (edit->num_widget_columns - 1)) / n;
  202. r_extreme = (r_extreme * (edit->num_widget_columns - 1)) / n;
  203. }
  204. p = edit_get_col (edit) + edit->over_col;
  205. edit_update_curs_row (edit);
  206. outby = p + edit->start_col - edit->num_widget_columns + 1 + (r_extreme + edit->found_len);
  207. if (outby > 0)
  208. edit_scroll_right (edit, outby);
  209. outby = l_extreme - p - edit->start_col;
  210. if (outby > 0)
  211. edit_scroll_left (edit, outby);
  212. p = edit->curs_row;
  213. outby = p - edit->num_widget_lines + 1 + b_extreme;
  214. if (outby > 0)
  215. edit_scroll_downward (edit, outby);
  216. outby = t_extreme - p;
  217. if (outby > 0)
  218. edit_scroll_upward (edit, outby);
  219. edit_update_curs_row (edit);
  220. edit->num_widget_lines += EDIT_TEXT_VERTICAL_OFFSET - 1;
  221. edit->num_widget_columns += EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
  222. }
  223. #define edit_move(x,y) widget_move(edit, y, x);
  224. struct line_s {
  225. unsigned int ch;
  226. unsigned int style;
  227. };
  228. static void
  229. print_to_widget (WEdit *edit, long row, int start_col, int start_col_real,
  230. long end_col, struct line_s line[], char *status)
  231. {
  232. struct line_s *p;
  233. int x = start_col_real;
  234. int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
  235. int y = row + EDIT_TEXT_VERTICAL_OFFSET;
  236. int cols_to_skip = abs (x);
  237. tty_setcolor (EDITOR_NORMAL_COLOR);
  238. tty_draw_hline (edit->widget.y + y, edit->widget.x + x1,
  239. ' ', end_col + 1 - start_col);
  240. if (option_line_state) {
  241. int i;
  242. for (i = 0; i < LINE_STATE_WIDTH; i++)
  243. if (status[i] == '\0')
  244. status[i] = ' ';
  245. tty_setcolor (LINE_STATE_COLOR);
  246. edit_move (x1 + FONT_OFFSET_X - option_line_state_width, y + FONT_OFFSET_Y);
  247. tty_print_string (status);
  248. }
  249. edit_move (x1 + FONT_OFFSET_X, y + FONT_OFFSET_Y);
  250. p = line;
  251. while (p->ch) {
  252. int style;
  253. unsigned int textchar;
  254. int color;
  255. if (cols_to_skip) {
  256. p++;
  257. cols_to_skip--;
  258. continue;
  259. }
  260. style = p->style & 0xFF00;
  261. textchar = p->ch;
  262. color = p->style >> 16;
  263. if (style & MOD_ABNORMAL) {
  264. /* Non-printable - use black background */
  265. color = 0;
  266. }
  267. if (style & MOD_WHITESPACE) {
  268. if (style & MOD_MARKED) {
  269. textchar = ' ';
  270. tty_setcolor (EDITOR_MARKED_COLOR);
  271. } else {
  272. #if 0
  273. if (color != EDITOR_NORMAL_COLOR) {
  274. textchar = ' ';
  275. tty_lowlevel_setcolor (color);
  276. } else
  277. #endif
  278. tty_setcolor (EDITOR_WHITESPACE_COLOR);
  279. }
  280. } else {
  281. if (style & MOD_BOLD) {
  282. tty_setcolor (EDITOR_BOLD_COLOR);
  283. } else if (style & MOD_MARKED) {
  284. tty_setcolor (EDITOR_MARKED_COLOR);
  285. } else {
  286. tty_lowlevel_setcolor (color);
  287. }
  288. }
  289. tty_print_anychar (textchar);
  290. p++;
  291. }
  292. }
  293. int visible_tabs = 1, visible_tws = 1;
  294. /* b is a pointer to the beginning of the line */
  295. static void
  296. edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
  297. long end_col)
  298. {
  299. struct line_s line[MAX_LINE_LEN];
  300. struct line_s *p = line;
  301. long m1 = 0, m2 = 0, q, c1, c2;
  302. int col, start_col_real;
  303. int cw;
  304. unsigned int c;
  305. int color;
  306. int abn_style;
  307. int i;
  308. int utf8lag = 0;
  309. unsigned int cur_line = 0;
  310. int book_mark = 0;
  311. char line_stat[LINE_STATE_WIDTH + 1];
  312. if (row > edit->num_widget_lines - EDIT_TEXT_VERTICAL_OFFSET) {
  313. return;
  314. }
  315. if (book_mark_query_color(edit, edit->start_line + row, BOOK_MARK_COLOR)) {
  316. book_mark = BOOK_MARK_COLOR;
  317. } else if (book_mark_query_color(edit, edit->start_line + row, BOOK_MARK_FOUND_COLOR)) {
  318. book_mark = BOOK_MARK_FOUND_COLOR;
  319. }
  320. if (book_mark)
  321. abn_style = book_mark << 16;
  322. else
  323. abn_style = MOD_ABNORMAL;
  324. end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
  325. edit_get_syntax_color (edit, b - 1, &color);
  326. q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
  327. start_col_real = (col =
  328. (int) edit_move_forward3 (edit, b, 0,
  329. q)) + edit->start_col;
  330. if ( option_line_state ) {
  331. cur_line = edit->start_line + row;
  332. if ( cur_line <= edit->total_lines ) {
  333. g_snprintf (line_stat, LINE_STATE_WIDTH + 1, "%7i ", cur_line + 1);
  334. } else {
  335. memset(line_stat, ' ', LINE_STATE_WIDTH);
  336. line_stat[LINE_STATE_WIDTH] = '\0';
  337. }
  338. if (book_mark_query_color (edit, cur_line, BOOK_MARK_COLOR)){
  339. g_snprintf (line_stat, 2, "*");
  340. }
  341. }
  342. if (col + 16 > -edit->start_col) {
  343. eval_marks (edit, &m1, &m2);
  344. if (row <= edit->total_lines - edit->start_line) {
  345. long tws = 0;
  346. if (tty_use_colors () && visible_tws) {
  347. tws = edit_eol (edit, b);
  348. while (tws > b && ((c = edit_get_byte (edit, tws - 1)) == ' '
  349. || c == '\t'))
  350. tws--;
  351. }
  352. while (col <= end_col - edit->start_col) {
  353. p->ch = 0;
  354. p->style = 0;
  355. if (q == edit->curs1)
  356. p->style |= MOD_CURSOR;
  357. if (q >= m1 && q < m2) {
  358. if (column_highlighting) {
  359. int x;
  360. x = edit_move_forward3 (edit, b, 0, q);
  361. c1 = min (edit->column1, edit->column2);
  362. c2 = max (edit->column1, edit->column2);
  363. if (x >= c1 && x < c2)
  364. p->style |= MOD_MARKED;
  365. } else
  366. p->style |= MOD_MARKED;
  367. }
  368. if (q == edit->bracket)
  369. p->style |= MOD_BOLD;
  370. if (q >= edit->found_start
  371. && q < edit->found_start + edit->found_len)
  372. p->style |= MOD_BOLD;
  373. cw = 1;
  374. if ( !edit->utf8 ) {
  375. c = edit_get_byte (edit, q);
  376. } else {
  377. c = edit_get_utf (edit, q, &cw);
  378. }
  379. /* we don't use bg for mc - fg contains both */
  380. if (book_mark) {
  381. p->style |= book_mark << 16;
  382. } else {
  383. edit_get_syntax_color (edit, q, &color);
  384. p->style |= color << 16;
  385. }
  386. switch (c) {
  387. case '\n':
  388. col = (end_col + utf8lag) - edit->start_col + 1; /* quit */
  389. break;
  390. case '\t':
  391. i = TAB_SIZE - ((int) col % TAB_SIZE);
  392. col += i;
  393. if (tty_use_colors() &&
  394. ((visible_tabs || (visible_tws && q >= tws)) && enable_show_tabs_tws)) {
  395. if (p->style & MOD_MARKED)
  396. c = p->style;
  397. else if (book_mark)
  398. c |= book_mark << 16;
  399. else
  400. c = p->style | MOD_WHITESPACE;
  401. if (i > 2) {
  402. p->ch = '<';
  403. p->style = c;
  404. p++;
  405. while (--i > 1) {
  406. p->ch = '-';
  407. p->style = c;
  408. p++;
  409. }
  410. p->ch = '>';
  411. p->style = c;
  412. p++;
  413. } else if (i > 1) {
  414. p->ch = '<';
  415. p->style = c;
  416. p++;
  417. p->ch = '>';
  418. p->style = c;
  419. p++;
  420. } else {
  421. p->ch = '>';
  422. p->style = c;
  423. p++;
  424. }
  425. } else if (tty_use_colors() && visible_tws && q >= tws && enable_show_tabs_tws) {
  426. p->ch = '.';
  427. p->style |= MOD_WHITESPACE;
  428. c = p->style & ~MOD_CURSOR;
  429. p++;
  430. while (--i) {
  431. p->ch = ' ';
  432. p->style = c;
  433. p++;
  434. }
  435. } else {
  436. p->ch |= ' ';
  437. c = p->style & ~MOD_CURSOR;
  438. p++;
  439. while (--i) {
  440. p->ch = ' ';
  441. p->style = c;
  442. p++;
  443. }
  444. }
  445. break;
  446. case ' ':
  447. if (tty_use_colors() && visible_tws && q >= tws && enable_show_tabs_tws) {
  448. p->ch = '.';
  449. p->style |= MOD_WHITESPACE;
  450. p++;
  451. col++;
  452. break;
  453. }
  454. /* fallthrough */
  455. default:
  456. #ifdef HAVE_CHARSET
  457. if ( utf8_display ) {
  458. if ( !edit->utf8 ) {
  459. c = convert_from_8bit_to_utf_c ((unsigned char) c, edit->converter);
  460. }
  461. } else {
  462. if ( edit->utf8 ) {
  463. c = convert_from_utf_to_current_c (c, edit->converter);
  464. } else {
  465. #endif
  466. c = convert_to_display_c (c);
  467. #ifdef HAVE_CHARSET
  468. }
  469. }
  470. #endif
  471. /* Caret notation for control characters */
  472. if (c < 32) {
  473. p->ch = '^';
  474. p->style = abn_style;
  475. p++;
  476. p->ch = c + 0x40;
  477. p->style = abn_style;
  478. p++;
  479. col += 2;
  480. break;
  481. }
  482. if (c == 127) {
  483. p->ch = '^';
  484. p->style = abn_style;
  485. p++;
  486. p->ch = '?';
  487. p->style = abn_style;
  488. p++;
  489. col += 2;
  490. break;
  491. }
  492. #ifndef HAVE_CHARSET
  493. int utf8_display = 0;
  494. #endif
  495. if (!edit->utf8) {
  496. if ( ( utf8_display && g_unichar_isprint (c) ) ||
  497. ( utf8_display == 0 && is_printable (c) ) ) {
  498. p->ch = c;
  499. p++;
  500. } else {
  501. p->ch = '.';
  502. p->style = abn_style;
  503. p++;
  504. }
  505. } else {
  506. if ( g_unichar_isprint (c) ) {
  507. p->ch = c;
  508. p++;
  509. } else {
  510. p->ch = '.';
  511. p->style = abn_style;
  512. p++;
  513. }
  514. }
  515. col++;
  516. break;
  517. }
  518. q++;
  519. if ( cw > 1) {
  520. q += cw - 1;
  521. }
  522. }
  523. }
  524. } else {
  525. start_col_real = start_col = 0;
  526. }
  527. p->ch = 0;
  528. print_to_widget (edit, row, start_col, start_col_real, end_col, line, line_stat);
  529. }
  530. #define key_pending(x) (!is_idle())
  531. static void edit_draw_this_char (WEdit * edit, long curs, long row)
  532. {
  533. int b = edit_bol (edit, curs);
  534. edit_draw_this_line (edit, b, row, 0, edit->num_widget_columns - 1);
  535. }
  536. /* cursor must be in screen for other than REDRAW_PAGE passed in force */
  537. static void
  538. render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
  539. long end_column)
  540. {
  541. long row = 0, curs_row;
  542. static int prev_curs_row = 0;
  543. static long prev_curs = 0;
  544. int force = edit->force;
  545. long b;
  546. /*
  547. * If the position of the page has not moved then we can draw the cursor
  548. * character only. This will prevent line flicker when using arrow keys.
  549. */
  550. if ((!(force & REDRAW_CHAR_ONLY)) || (force & REDRAW_PAGE)) {
  551. if (!(force & REDRAW_IN_BOUNDS)) { /* !REDRAW_IN_BOUNDS means to ignore bounds and redraw whole rows */
  552. start_row = 0;
  553. end_row = edit->num_widget_lines - 1;
  554. start_column = 0;
  555. end_column = edit->num_widget_columns - 1;
  556. }
  557. if (force & REDRAW_PAGE) {
  558. row = start_row;
  559. b = edit_move_forward (edit, edit->start_display, start_row, 0);
  560. while (row <= end_row) {
  561. if (key_pending (edit))
  562. goto exit_render;
  563. edit_draw_this_line (edit, b, row, start_column, end_column);
  564. b = edit_move_forward (edit, b, 1, 0);
  565. row++;
  566. }
  567. } else {
  568. curs_row = edit->curs_row;
  569. if (force & REDRAW_BEFORE_CURSOR) {
  570. if (start_row < curs_row) {
  571. long upto = curs_row - 1 <= end_row ? curs_row - 1 : end_row;
  572. row = start_row;
  573. b = edit->start_display;
  574. while (row <= upto) {
  575. if (key_pending (edit))
  576. goto exit_render;
  577. edit_draw_this_line (edit, b, row, start_column, end_column);
  578. b = edit_move_forward (edit, b, 1, 0);
  579. }
  580. }
  581. }
  582. /* if (force & REDRAW_LINE) ---> default */
  583. b = edit_bol (edit, edit->curs1);
  584. if (curs_row >= start_row && curs_row <= end_row) {
  585. if (key_pending (edit))
  586. goto exit_render;
  587. edit_draw_this_line (edit, b, curs_row, start_column, end_column);
  588. }
  589. if (force & REDRAW_AFTER_CURSOR) {
  590. if (end_row > curs_row) {
  591. row = curs_row + 1 < start_row ? start_row : curs_row + 1;
  592. b = edit_move_forward (edit, b, 1, 0);
  593. while (row <= end_row) {
  594. if (key_pending (edit))
  595. goto exit_render;
  596. edit_draw_this_line (edit, b, row, start_column, end_column);
  597. b = edit_move_forward (edit, b, 1, 0);
  598. row++;
  599. }
  600. }
  601. }
  602. if (force & REDRAW_LINE_ABOVE && curs_row >= 1) {
  603. row = curs_row - 1;
  604. b = edit_move_backward (edit, edit_bol (edit, edit->curs1), 1);
  605. if (row >= start_row && row <= end_row) {
  606. if (key_pending (edit))
  607. goto exit_render;
  608. edit_draw_this_line (edit, b, row, start_column, end_column);
  609. }
  610. }
  611. if (force & REDRAW_LINE_BELOW && row < edit->num_widget_lines - 1) {
  612. row = curs_row + 1;
  613. b = edit_bol (edit, edit->curs1);
  614. b = edit_move_forward (edit, b, 1, 0);
  615. if (row >= start_row && row <= end_row) {
  616. if (key_pending (edit))
  617. goto exit_render;
  618. edit_draw_this_line (edit, b, row, start_column, end_column);
  619. }
  620. }
  621. }
  622. } else {
  623. if (prev_curs_row < edit->curs_row) { /* with the new text highlighting, we must draw from the top down */
  624. edit_draw_this_char (edit, prev_curs, prev_curs_row);
  625. edit_draw_this_char (edit, edit->curs1, edit->curs_row);
  626. } else {
  627. edit_draw_this_char (edit, edit->curs1, edit->curs_row);
  628. edit_draw_this_char (edit, prev_curs, prev_curs_row);
  629. }
  630. }
  631. edit->force = 0;
  632. prev_curs_row = edit->curs_row;
  633. prev_curs = edit->curs1;
  634. exit_render:
  635. edit->screen_modified = 0;
  636. return;
  637. }
  638. static void
  639. edit_render (WEdit * edit, int page, int row_start, int col_start, int row_end, int col_end)
  640. {
  641. if (page) /* if it was an expose event, 'page' would be set */
  642. edit->force |= REDRAW_PAGE | REDRAW_IN_BOUNDS;
  643. if (edit->force & REDRAW_COMPLETELY)
  644. buttonbar_redraw (edit->widget.parent);
  645. render_edit_text (edit, row_start, col_start, row_end, col_end);
  646. /*
  647. * edit->force != 0 means a key was pending and the redraw
  648. * was halted, so next time we must redraw everything in case stuff
  649. * was left undrawn from a previous key press.
  650. */
  651. if (edit->force)
  652. edit->force |= REDRAW_PAGE;
  653. }
  654. void edit_render_keypress (WEdit * edit)
  655. {
  656. edit_render (edit, 0, 0, 0, 0, 0);
  657. }