editdraw.c 19 KB

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