2001-08-24 22:23:17 +04:00
|
|
|
/* editor text drawing.
|
|
|
|
|
2007-09-25 19:33:35 +04:00
|
|
|
Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006,
|
|
|
|
2007 Free Software Foundation, Inc.
|
2001-08-24 22:23:17 +04:00
|
|
|
|
|
|
|
Authors: 1996, 1997 Paul Sheer
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-05-27 07:35:10 +04:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
02110-1301, USA.
|
2001-08-24 22:23:17 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2004-11-10 17:11:27 +03:00
|
|
|
#include <stdlib.h>
|
2005-02-22 20:00:36 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include "../src/global.h"
|
|
|
|
|
2001-08-24 22:23:17 +04:00
|
|
|
#include "edit.h"
|
2002-11-29 06:01:06 +03:00
|
|
|
#include "edit-widget.h"
|
2001-08-24 22:23:17 +04:00
|
|
|
|
|
|
|
#define MAX_LINE_LEN 1024
|
|
|
|
|
2003-10-29 11:54:22 +03:00
|
|
|
#include "../src/color.h" /* EDITOR_NORMAL_COLOR */
|
|
|
|
#include "../src/tty.h" /* attrset() */
|
2005-02-08 12:50:16 +03:00
|
|
|
#include "../src/widget.h" /* buttonbar_redraw() */
|
2003-10-29 11:54:22 +03:00
|
|
|
#include "../src/key.h" /* is_idle() */
|
|
|
|
#include "../src/charsets.h"
|
2009-04-06 14:31:12 +04:00
|
|
|
#include "../src/strutil.h" /* utf string functions */
|
2009-04-09 12:40:59 +04:00
|
|
|
#include "../src/main.h" /* source_codepage */
|
2001-08-24 22:23:17 +04:00
|
|
|
|
2002-09-24 03:05:15 +04:00
|
|
|
/* Text styles */
|
|
|
|
#define MOD_ABNORMAL (1 << 8)
|
|
|
|
#define MOD_BOLD (1 << 9)
|
|
|
|
#define MOD_MARKED (1 << 10)
|
|
|
|
#define MOD_CURSOR (1 << 11)
|
2007-08-27 16:06:02 +04:00
|
|
|
#define MOD_WHITESPACE (1 << 12)
|
2002-09-24 03:05:15 +04:00
|
|
|
|
2002-11-30 22:59:02 +03:00
|
|
|
#define FONT_OFFSET_X 0
|
|
|
|
#define FONT_OFFSET_Y 0
|
|
|
|
#define FIXED_FONT 1
|
|
|
|
#define FONT_PIX_PER_LINE 1
|
|
|
|
#define FONT_MEAN_WIDTH 1
|
|
|
|
|
2002-09-24 03:05:15 +04:00
|
|
|
|
2004-09-24 15:13:11 +04:00
|
|
|
static void status_string (WEdit * edit, char *s, int w)
|
2001-08-24 22:23:17 +04:00
|
|
|
{
|
|
|
|
char byte_str[16];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we are at the end of file, print <EOF>,
|
|
|
|
* otherwise print the current character as is (if printable),
|
|
|
|
* as decimal and as hex.
|
|
|
|
*/
|
|
|
|
if (edit->curs1 < edit->last_byte) {
|
2009-04-15 22:14:17 +04:00
|
|
|
if ( !edit->utf8 ) {
|
|
|
|
unsigned char cur_byte = edit_get_byte (edit, edit->curs1);
|
|
|
|
g_snprintf (byte_str, sizeof (byte_str), "%c %3d 0x%02X",
|
|
|
|
is_printable (cur_byte) ? cur_byte : '.',
|
|
|
|
(int) cur_byte,
|
|
|
|
(unsigned) cur_byte);
|
|
|
|
} else {
|
|
|
|
int cw = 1;
|
|
|
|
unsigned int cur_utf = edit_get_utf (edit, edit->curs1, &cw);
|
|
|
|
if ( cw > 0 ) {
|
|
|
|
g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
|
|
|
|
(unsigned) cur_utf,
|
|
|
|
(unsigned) cur_utf);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2001-08-24 22:23:17 +04:00
|
|
|
} else {
|
2005-04-28 01:02:59 +04:00
|
|
|
strcpy (byte_str, "<EOF>");
|
2001-08-24 22:23:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The field lengths just prevent the status line from shortening too much */
|
2009-02-06 01:49:00 +03:00
|
|
|
g_snprintf (s, w,
|
2009-04-09 12:40:59 +04:00
|
|
|
"[%c%c%c%c] %2ld L:[%3ld+%2ld %3ld/%3ld] *(%-4ld/%4ldb)= %s C:%s",
|
2001-08-24 22:23:17 +04:00
|
|
|
edit->mark1 != edit->mark2 ? ( column_highlighting ? 'C' : 'B') : '-',
|
|
|
|
edit->modified ? 'M' : '-',
|
|
|
|
edit->macro_i < 0 ? '-' : 'R',
|
|
|
|
edit->overwrite == 0 ? '-' : 'O',
|
2002-09-20 19:15:43 +04:00
|
|
|
edit->curs_col,
|
2001-08-24 22:23:17 +04:00
|
|
|
|
|
|
|
edit->start_line + 1,
|
|
|
|
edit->curs_row,
|
|
|
|
edit->curs_line + 1,
|
|
|
|
edit->total_lines + 1,
|
|
|
|
|
|
|
|
edit->curs1,
|
2005-02-07 10:31:19 +03:00
|
|
|
edit->last_byte,
|
2009-04-09 12:40:59 +04:00
|
|
|
byte_str,
|
|
|
|
get_codepage_id( source_codepage ));
|
2001-08-24 22:23:17 +04:00
|
|
|
}
|
|
|
|
|
2005-09-05 06:14:29 +04:00
|
|
|
static inline void
|
|
|
|
printwstr (const char *s, int len)
|
|
|
|
{
|
|
|
|
if (len > 0)
|
|
|
|
tty_printf ("%-*.*s", len, len, s);
|
|
|
|
}
|
|
|
|
|
2005-01-28 01:14:58 +03:00
|
|
|
/* Draw the status line at the top of the widget. The size of the filename
|
|
|
|
* field varies depending on the width of the screen and the length of
|
|
|
|
* the filename. */
|
2002-12-15 21:55:53 +03:00
|
|
|
void
|
|
|
|
edit_status (WEdit *edit)
|
2001-08-24 22:23:17 +04:00
|
|
|
{
|
2004-09-24 15:13:11 +04:00
|
|
|
const int w = edit->widget.cols;
|
|
|
|
const size_t status_size = w + 1;
|
|
|
|
char * const status = g_malloc (status_size);
|
2005-01-28 04:34:48 +03:00
|
|
|
int status_len;
|
2004-09-24 15:13:11 +04:00
|
|
|
const char *fname = "";
|
2005-01-28 04:34:48 +03:00
|
|
|
int fname_len;
|
2004-09-24 15:13:11 +04:00
|
|
|
const int gap = 3; /* between the filename and the status */
|
2005-01-28 01:14:58 +03:00
|
|
|
const int right_gap = 2; /* at the right end of the screen */
|
|
|
|
const int preferred_fname_len = 16;
|
2004-09-24 15:13:11 +04:00
|
|
|
|
|
|
|
status_string (edit, status, status_size);
|
2009-04-06 14:31:12 +04:00
|
|
|
status_len = (int) str_term_width1 (status);
|
2004-09-24 15:13:11 +04:00
|
|
|
|
|
|
|
if (edit->filename)
|
|
|
|
fname = edit->filename;
|
2009-04-06 14:31:12 +04:00
|
|
|
fname_len = str_term_width1 (fname);
|
2005-01-28 01:14:58 +03:00
|
|
|
if (fname_len < preferred_fname_len)
|
|
|
|
fname_len = preferred_fname_len;
|
2004-09-24 15:13:11 +04:00
|
|
|
|
2005-01-28 01:14:58 +03:00
|
|
|
if (fname_len + gap + status_len + right_gap >= w) {
|
2005-02-07 23:32:17 +03:00
|
|
|
if (preferred_fname_len + gap + status_len + right_gap >= w)
|
|
|
|
fname_len = preferred_fname_len;
|
|
|
|
else
|
2005-01-28 01:14:58 +03:00
|
|
|
fname_len = w - (gap + status_len + right_gap);
|
2009-04-06 14:38:35 +04:00
|
|
|
fname = str_trunc (fname, fname_len);
|
2001-08-24 22:23:17 +04:00
|
|
|
}
|
|
|
|
|
2004-09-24 15:13:11 +04:00
|
|
|
widget_move (edit, 0, 0);
|
|
|
|
attrset (SELECTED_COLOR);
|
2005-01-28 01:14:58 +03:00
|
|
|
printwstr (fname, fname_len + gap);
|
|
|
|
printwstr (status, w - (fname_len + gap));
|
2002-07-14 10:17:02 +04:00
|
|
|
attrset (EDITOR_NORMAL_COLOR);
|
2004-09-24 15:13:11 +04:00
|
|
|
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (status);
|
2001-08-24 22:23:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this scrolls the text so that cursor is on the screen */
|
|
|
|
void edit_scroll_screen_over_cursor (WEdit * edit)
|
|
|
|
{
|
|
|
|
int p;
|
|
|
|
int outby;
|
|
|
|
int b_extreme, t_extreme, l_extreme, r_extreme;
|
2002-01-23 03:12:17 +03:00
|
|
|
|
|
|
|
if (edit->num_widget_lines <= 0 || edit->num_widget_columns <= 0)
|
|
|
|
return;
|
|
|
|
|
2001-08-24 22:23:17 +04:00
|
|
|
r_extreme = EDIT_RIGHT_EXTREME;
|
|
|
|
l_extreme = EDIT_LEFT_EXTREME;
|
|
|
|
b_extreme = EDIT_BOTTOM_EXTREME;
|
|
|
|
t_extreme = EDIT_TOP_EXTREME;
|
|
|
|
if (edit->found_len) {
|
|
|
|
b_extreme = max (edit->num_widget_lines / 4, b_extreme);
|
|
|
|
t_extreme = max (edit->num_widget_lines / 4, t_extreme);
|
|
|
|
}
|
|
|
|
if (b_extreme + t_extreme + 1 > edit->num_widget_lines) {
|
|
|
|
int n;
|
|
|
|
n = b_extreme + t_extreme;
|
|
|
|
b_extreme = (b_extreme * (edit->num_widget_lines - 1)) / n;
|
|
|
|
t_extreme = (t_extreme * (edit->num_widget_lines - 1)) / n;
|
|
|
|
}
|
|
|
|
if (l_extreme + r_extreme + 1 > edit->num_widget_columns) {
|
|
|
|
int n;
|
|
|
|
n = l_extreme + t_extreme;
|
|
|
|
l_extreme = (l_extreme * (edit->num_widget_columns - 1)) / n;
|
|
|
|
r_extreme = (r_extreme * (edit->num_widget_columns - 1)) / n;
|
|
|
|
}
|
|
|
|
p = edit_get_col (edit);
|
|
|
|
edit_update_curs_row (edit);
|
|
|
|
outby = p + edit->start_col - edit->num_widget_columns + 1 + (r_extreme + edit->found_len);
|
|
|
|
if (outby > 0)
|
|
|
|
edit_scroll_right (edit, outby);
|
|
|
|
outby = l_extreme - p - edit->start_col;
|
|
|
|
if (outby > 0)
|
|
|
|
edit_scroll_left (edit, outby);
|
|
|
|
p = edit->curs_row;
|
|
|
|
outby = p - edit->num_widget_lines + 1 + b_extreme;
|
|
|
|
if (outby > 0)
|
|
|
|
edit_scroll_downward (edit, outby);
|
|
|
|
outby = t_extreme - p;
|
|
|
|
if (outby > 0)
|
|
|
|
edit_scroll_upward (edit, outby);
|
|
|
|
edit_update_curs_row (edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define set_color(font) attrset (font)
|
|
|
|
|
|
|
|
#define edit_move(x,y) widget_move(edit, y, x);
|
|
|
|
|
2002-07-15 01:43:53 +04:00
|
|
|
/* Set colorpair by index, don't interpret S-Lang "emulated attributes" */
|
2002-07-14 11:49:24 +04:00
|
|
|
#ifdef HAVE_SLANG
|
|
|
|
#define lowlevel_set_color(x) SLsmg_set_color(x & 0x7F)
|
|
|
|
#else
|
2002-07-15 01:43:53 +04:00
|
|
|
#define lowlevel_set_color(x) attrset(MY_COLOR_PAIR(color))
|
2002-07-14 11:49:24 +04:00
|
|
|
#endif
|
|
|
|
|
2009-04-12 12:09:00 +04:00
|
|
|
struct line_s {
|
|
|
|
unsigned int ch;
|
|
|
|
unsigned int style;
|
|
|
|
};
|
|
|
|
|
2002-10-07 01:08:20 +04:00
|
|
|
static void
|
|
|
|
print_to_widget (WEdit *edit, long row, int start_col, int start_col_real,
|
2009-04-12 12:09:00 +04:00
|
|
|
long end_col, struct line_s line[])
|
2001-08-24 22:23:17 +04:00
|
|
|
{
|
2009-04-12 12:09:00 +04:00
|
|
|
struct line_s *p;
|
2002-10-07 01:08:20 +04:00
|
|
|
|
|
|
|
int x = start_col_real + EDIT_TEXT_HORIZONTAL_OFFSET;
|
2001-08-24 22:23:17 +04:00
|
|
|
int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET;
|
|
|
|
int y = row + EDIT_TEXT_VERTICAL_OFFSET;
|
2004-11-10 17:11:27 +03:00
|
|
|
int cols_to_skip = abs (x);
|
2001-08-24 22:23:17 +04:00
|
|
|
|
|
|
|
set_color (EDITOR_NORMAL_COLOR);
|
|
|
|
edit_move (x1, y);
|
|
|
|
hline (' ', end_col + 1 - EDIT_TEXT_HORIZONTAL_OFFSET - x1);
|
|
|
|
|
2004-11-10 17:11:27 +03:00
|
|
|
edit_move (x1 + FONT_OFFSET_X, y + FONT_OFFSET_Y);
|
2002-10-07 01:08:20 +04:00
|
|
|
p = line;
|
|
|
|
|
2009-04-12 12:09:00 +04:00
|
|
|
while (p->ch) {
|
2004-11-10 17:11:27 +03:00
|
|
|
int style;
|
2009-04-12 23:16:52 +04:00
|
|
|
unsigned int textchar;
|
2004-11-10 17:11:27 +03:00
|
|
|
int color;
|
|
|
|
|
|
|
|
if (cols_to_skip) {
|
|
|
|
p++;
|
|
|
|
cols_to_skip--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-04-12 12:09:00 +04:00
|
|
|
style = p->style & 0xFF00;
|
|
|
|
textchar = p->ch;
|
|
|
|
color = p->style >> 16;
|
2002-10-07 01:08:20 +04:00
|
|
|
|
|
|
|
if (style & MOD_ABNORMAL) {
|
|
|
|
/* Non-printable - use black background */
|
|
|
|
color = 0;
|
2001-08-24 22:23:17 +04:00
|
|
|
}
|
2002-10-07 01:08:20 +04:00
|
|
|
|
2007-08-27 16:06:02 +04:00
|
|
|
if (style & MOD_WHITESPACE) {
|
|
|
|
if (style & MOD_MARKED) {
|
|
|
|
textchar = ' ';
|
|
|
|
set_color (EDITOR_MARKED_COLOR);
|
|
|
|
} else {
|
|
|
|
#if 0
|
|
|
|
if (color != EDITOR_NORMAL_COLOR) {
|
|
|
|
textchar = ' ';
|
|
|
|
lowlevel_set_color (color);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
set_color (EDITOR_WHITESPACE_COLOR);
|
|
|
|
}
|
2002-10-07 01:08:20 +04:00
|
|
|
} else {
|
2007-08-27 16:06:02 +04:00
|
|
|
if (style & MOD_BOLD) {
|
|
|
|
set_color (EDITOR_BOLD_COLOR);
|
|
|
|
} else if (style & MOD_MARKED) {
|
|
|
|
set_color (EDITOR_MARKED_COLOR);
|
|
|
|
} else {
|
|
|
|
lowlevel_set_color (color);
|
|
|
|
}
|
2002-10-07 01:08:20 +04:00
|
|
|
}
|
|
|
|
addch (textchar);
|
|
|
|
p++;
|
2001-08-24 22:23:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-27 16:06:02 +04:00
|
|
|
int visible_tabs = 1, visible_tws = 1;
|
|
|
|
|
2001-08-24 22:23:17 +04:00
|
|
|
/* b is a pointer to the beginning of the line */
|
2002-10-07 01:08:20 +04:00
|
|
|
static void
|
|
|
|
edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
|
|
|
|
long end_col)
|
2001-08-24 22:23:17 +04:00
|
|
|
{
|
2009-04-12 12:09:00 +04:00
|
|
|
struct line_s line[MAX_LINE_LEN];
|
|
|
|
struct line_s *p = line;
|
|
|
|
|
2009-01-15 01:28:35 +03:00
|
|
|
long m1 = 0, m2 = 0, q, c1, c2;
|
2001-08-24 22:23:17 +04:00
|
|
|
int col, start_col_real;
|
2009-04-12 23:16:52 +04:00
|
|
|
int cw;
|
2001-08-24 22:23:17 +04:00
|
|
|
unsigned int c;
|
2002-07-14 21:56:47 +04:00
|
|
|
int color;
|
2006-12-05 01:44:50 +03:00
|
|
|
int i;
|
2009-04-13 13:28:07 +04:00
|
|
|
int utf8lag = 0;
|
2001-08-24 22:23:17 +04:00
|
|
|
|
2002-07-14 21:56:47 +04:00
|
|
|
edit_get_syntax_color (edit, b - 1, &color);
|
2001-08-24 22:23:17 +04:00
|
|
|
q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
|
2002-10-07 01:08:20 +04:00
|
|
|
start_col_real = (col =
|
|
|
|
(int) edit_move_forward3 (edit, b, 0,
|
|
|
|
q)) + edit->start_col;
|
2001-08-24 22:23:17 +04:00
|
|
|
c1 = min (edit->column1, edit->column2);
|
|
|
|
c2 = max (edit->column1, edit->column2);
|
|
|
|
|
|
|
|
if (col + 16 > -edit->start_col) {
|
|
|
|
eval_marks (edit, &m1, &m2);
|
|
|
|
|
|
|
|
if (row <= edit->total_lines - edit->start_line) {
|
2009-01-15 01:28:35 +03:00
|
|
|
long tws;
|
2007-08-27 16:06:02 +04:00
|
|
|
if (use_colors && visible_tws) {
|
|
|
|
tws = edit_eol (edit, b);
|
|
|
|
while (tws > b && ((c = edit_get_byte (edit, tws - 1)) == ' '
|
|
|
|
|| c == '\t'))
|
|
|
|
tws--;
|
|
|
|
}
|
|
|
|
|
2001-08-24 22:23:17 +04:00
|
|
|
while (col <= end_col - edit->start_col) {
|
2009-04-12 12:09:00 +04:00
|
|
|
p->ch = 0;
|
|
|
|
p->style = 0;
|
2001-08-24 22:23:17 +04:00
|
|
|
if (q == edit->curs1)
|
2009-04-12 12:09:00 +04:00
|
|
|
p->style |= MOD_CURSOR;
|
2001-08-24 22:23:17 +04:00
|
|
|
if (q >= m1 && q < m2) {
|
|
|
|
if (column_highlighting) {
|
|
|
|
int x;
|
|
|
|
x = edit_move_forward3 (edit, b, 0, q);
|
|
|
|
if (x >= c1 && x < c2)
|
2009-04-12 12:09:00 +04:00
|
|
|
p->style |= MOD_MARKED;
|
2001-08-24 22:23:17 +04:00
|
|
|
} else
|
2009-04-12 12:09:00 +04:00
|
|
|
p->style |= MOD_MARKED;
|
2001-08-24 22:23:17 +04:00
|
|
|
}
|
|
|
|
if (q == edit->bracket)
|
2009-04-12 12:09:00 +04:00
|
|
|
p->style |= MOD_BOLD;
|
2002-10-07 01:08:20 +04:00
|
|
|
if (q >= edit->found_start
|
|
|
|
&& q < edit->found_start + edit->found_len)
|
2009-04-12 12:09:00 +04:00
|
|
|
p->style |= MOD_BOLD;
|
2009-04-12 23:16:52 +04:00
|
|
|
cw = 1;
|
|
|
|
if ( !edit->utf8 ) {
|
|
|
|
c = edit_get_byte (edit, q);
|
|
|
|
} else {
|
|
|
|
c = edit_get_utf (edit, q, &cw);
|
|
|
|
}
|
|
|
|
/* we don't use bg for mc - fg contains both */
|
2006-12-05 01:44:50 +03:00
|
|
|
edit_get_syntax_color (edit, q, &color);
|
2009-04-12 12:09:00 +04:00
|
|
|
p->style |= color << 16;
|
2001-08-24 22:23:17 +04:00
|
|
|
switch (c) {
|
|
|
|
case '\n':
|
2009-04-13 13:28:07 +04:00
|
|
|
col = (end_col + utf8lag) - edit->start_col + 1; /* quit */
|
2009-04-12 12:09:00 +04:00
|
|
|
p->ch = ' ';
|
|
|
|
p++;
|
2001-08-24 22:23:17 +04:00
|
|
|
break;
|
|
|
|
case '\t':
|
|
|
|
i = TAB_SIZE - ((int) col % TAB_SIZE);
|
|
|
|
col += i;
|
2007-08-27 16:06:02 +04:00
|
|
|
if (use_colors && visible_tabs) {
|
2009-04-12 12:09:00 +04:00
|
|
|
c = 0;
|
2007-08-27 16:06:02 +04:00
|
|
|
if (i > 2) {
|
2009-04-12 12:09:00 +04:00
|
|
|
p->ch |= '<';
|
|
|
|
p->style = MOD_WHITESPACE;
|
|
|
|
p++;
|
|
|
|
while (--i > 1) {
|
|
|
|
p->ch = c | '-';
|
|
|
|
p->style = MOD_WHITESPACE;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
p->ch = c | '>';
|
|
|
|
p->style = MOD_WHITESPACE;
|
|
|
|
p++;
|
2007-08-27 16:06:02 +04:00
|
|
|
} else if (i > 1) {
|
2009-04-12 12:09:00 +04:00
|
|
|
p->ch |= '<';
|
|
|
|
p->style = MOD_WHITESPACE;
|
|
|
|
p++;
|
|
|
|
p->ch = c | '>';
|
|
|
|
p->style = MOD_WHITESPACE;
|
|
|
|
p++;
|
|
|
|
} else {
|
|
|
|
p->ch |= '>';
|
|
|
|
p->style = MOD_WHITESPACE;
|
|
|
|
p++;
|
|
|
|
}
|
2007-08-27 16:06:02 +04:00
|
|
|
} else if (use_colors && visible_tws && q >= tws) {
|
2009-04-12 12:09:00 +04:00
|
|
|
p->ch |= '.';
|
|
|
|
p->style = MOD_WHITESPACE;
|
|
|
|
c = p->style & ~MOD_CURSOR;
|
|
|
|
p++;
|
|
|
|
while (--i) {
|
|
|
|
p->ch = ' ';
|
|
|
|
p->style = c;
|
|
|
|
p++;
|
|
|
|
}
|
2007-08-27 16:06:02 +04:00
|
|
|
} else {
|
2009-04-12 12:09:00 +04:00
|
|
|
p->ch |= ' ';
|
|
|
|
c = p->style & ~MOD_CURSOR;
|
|
|
|
p++;
|
|
|
|
while (--i) {
|
|
|
|
p->ch = ' ';
|
|
|
|
p->style = c;
|
|
|
|
p++;
|
|
|
|
}
|
2007-08-27 16:06:02 +04:00
|
|
|
}
|
2001-08-24 22:23:17 +04:00
|
|
|
break;
|
2007-08-27 16:06:02 +04:00
|
|
|
case ' ':
|
|
|
|
if (use_colors && visible_tws && q >= tws) {
|
2009-04-12 12:09:00 +04:00
|
|
|
p->ch |= '.';
|
|
|
|
p->style = MOD_WHITESPACE;
|
|
|
|
p++;
|
2007-08-27 16:06:02 +04:00
|
|
|
col++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fallthrough */
|
2001-08-24 22:23:17 +04:00
|
|
|
default:
|
2009-04-12 12:09:00 +04:00
|
|
|
if (!edit->utf8) {
|
|
|
|
c = convert_to_display_c (c);
|
|
|
|
} else {
|
|
|
|
//FIXME: if need
|
|
|
|
}
|
2002-09-24 02:32:47 +04:00
|
|
|
/* Caret notation for control characters */
|
|
|
|
if (c < 32) {
|
2009-04-12 12:09:00 +04:00
|
|
|
p->ch = '^';
|
|
|
|
p->style = MOD_ABNORMAL;
|
|
|
|
p++;
|
|
|
|
p->ch = c + 0x40;
|
|
|
|
p->style = MOD_ABNORMAL;
|
|
|
|
p++;
|
2002-09-24 02:32:47 +04:00
|
|
|
col += 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (c == 127) {
|
2009-04-12 12:09:00 +04:00
|
|
|
p->ch = '^';
|
|
|
|
p->style = MOD_ABNORMAL;
|
|
|
|
p++;
|
|
|
|
p->ch = '?';
|
|
|
|
p->style = MOD_ABNORMAL;
|
|
|
|
p++;
|
2002-09-24 02:32:47 +04:00
|
|
|
col += 2;
|
|
|
|
break;
|
|
|
|
}
|
2009-04-12 12:09:00 +04:00
|
|
|
if (!edit->utf8) {
|
|
|
|
if (is_printable (c)) {
|
|
|
|
p->ch = c;
|
|
|
|
p++;
|
|
|
|
} else {
|
|
|
|
p->ch = '.';
|
|
|
|
p->style = MOD_ABNORMAL;
|
|
|
|
p++;
|
|
|
|
}
|
2001-08-24 22:23:17 +04:00
|
|
|
} else {
|
2009-04-13 13:28:07 +04:00
|
|
|
if ( g_unichar_isprint (c) ) {
|
|
|
|
p->ch = c;
|
|
|
|
p++;
|
|
|
|
} else {
|
|
|
|
p->ch = '.';
|
|
|
|
p->style = MOD_ABNORMAL;
|
|
|
|
p++;
|
|
|
|
}
|
2001-08-24 22:23:17 +04:00
|
|
|
}
|
|
|
|
col++;
|
|
|
|
break;
|
|
|
|
}
|
2007-08-27 16:06:02 +04:00
|
|
|
q++;
|
2009-04-13 10:55:43 +04:00
|
|
|
if ( cw > 1) {
|
|
|
|
q += cw - 1;
|
|
|
|
}
|
2001-08-24 22:23:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
start_col_real = start_col = 0;
|
|
|
|
}
|
2009-04-12 12:09:00 +04:00
|
|
|
p->ch = 0;
|
2001-08-24 22:23:17 +04:00
|
|
|
|
|
|
|
print_to_widget (edit, row, start_col, start_col_real, end_col, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define key_pending(x) (!is_idle())
|
|
|
|
|
|
|
|
static void edit_draw_this_char (WEdit * edit, long curs, long row)
|
|
|
|
{
|
|
|
|
int b = edit_bol (edit, curs);
|
|
|
|
edit_draw_this_line (edit, b, row, 0, edit->num_widget_columns - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cursor must be in screen for other than REDRAW_PAGE passed in force */
|
2002-11-13 07:32:00 +03:00
|
|
|
static void
|
|
|
|
render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
|
|
|
|
long end_column)
|
2001-08-24 22:23:17 +04:00
|
|
|
{
|
|
|
|
long row = 0, curs_row;
|
|
|
|
static int prev_curs_row = 0;
|
|
|
|
static long prev_curs = 0;
|
|
|
|
|
|
|
|
int force = edit->force;
|
|
|
|
long b;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the position of the page has not moved then we can draw the cursor
|
|
|
|
* character only. This will prevent line flicker when using arrow keys.
|
|
|
|
*/
|
2001-09-07 22:56:07 +04:00
|
|
|
if ((!(force & REDRAW_CHAR_ONLY)) || (force & REDRAW_PAGE)) {
|
2001-08-24 22:23:17 +04:00
|
|
|
if (!(force & REDRAW_IN_BOUNDS)) { /* !REDRAW_IN_BOUNDS means to ignore bounds and redraw whole rows */
|
|
|
|
start_row = 0;
|
|
|
|
end_row = edit->num_widget_lines - 1;
|
|
|
|
start_column = 0;
|
|
|
|
end_column = edit->num_widget_columns - 1;
|
|
|
|
}
|
|
|
|
if (force & REDRAW_PAGE) {
|
|
|
|
row = start_row;
|
|
|
|
b = edit_move_forward (edit, edit->start_display, start_row, 0);
|
|
|
|
while (row <= end_row) {
|
|
|
|
if (key_pending (edit))
|
|
|
|
goto exit_render;
|
|
|
|
edit_draw_this_line (edit, b, row, start_column, end_column);
|
|
|
|
b = edit_move_forward (edit, b, 1, 0);
|
|
|
|
row++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
curs_row = edit->curs_row;
|
|
|
|
|
|
|
|
if (force & REDRAW_BEFORE_CURSOR) {
|
|
|
|
if (start_row < curs_row) {
|
|
|
|
long upto = curs_row - 1 <= end_row ? curs_row - 1 : end_row;
|
|
|
|
row = start_row;
|
|
|
|
b = edit->start_display;
|
|
|
|
while (row <= upto) {
|
|
|
|
if (key_pending (edit))
|
|
|
|
goto exit_render;
|
|
|
|
edit_draw_this_line (edit, b, row, start_column, end_column);
|
|
|
|
b = edit_move_forward (edit, b, 1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* if (force & REDRAW_LINE) ---> default */
|
|
|
|
b = edit_bol (edit, edit->curs1);
|
|
|
|
if (curs_row >= start_row && curs_row <= end_row) {
|
|
|
|
if (key_pending (edit))
|
|
|
|
goto exit_render;
|
|
|
|
edit_draw_this_line (edit, b, curs_row, start_column, end_column);
|
|
|
|
}
|
|
|
|
if (force & REDRAW_AFTER_CURSOR) {
|
|
|
|
if (end_row > curs_row) {
|
|
|
|
row = curs_row + 1 < start_row ? start_row : curs_row + 1;
|
|
|
|
b = edit_move_forward (edit, b, 1, 0);
|
|
|
|
while (row <= end_row) {
|
|
|
|
if (key_pending (edit))
|
|
|
|
goto exit_render;
|
|
|
|
edit_draw_this_line (edit, b, row, start_column, end_column);
|
|
|
|
b = edit_move_forward (edit, b, 1, 0);
|
|
|
|
row++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (force & REDRAW_LINE_ABOVE && curs_row >= 1) {
|
|
|
|
row = curs_row - 1;
|
|
|
|
b = edit_move_backward (edit, edit_bol (edit, edit->curs1), 1);
|
|
|
|
if (row >= start_row && row <= end_row) {
|
|
|
|
if (key_pending (edit))
|
|
|
|
goto exit_render;
|
|
|
|
edit_draw_this_line (edit, b, row, start_column, end_column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (force & REDRAW_LINE_BELOW && row < edit->num_widget_lines - 1) {
|
|
|
|
row = curs_row + 1;
|
|
|
|
b = edit_bol (edit, edit->curs1);
|
|
|
|
b = edit_move_forward (edit, b, 1, 0);
|
|
|
|
if (row >= start_row && row <= end_row) {
|
|
|
|
if (key_pending (edit))
|
|
|
|
goto exit_render;
|
|
|
|
edit_draw_this_line (edit, b, row, start_column, end_column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (prev_curs_row < edit->curs_row) { /* with the new text highlighting, we must draw from the top down */
|
|
|
|
edit_draw_this_char (edit, prev_curs, prev_curs_row);
|
|
|
|
edit_draw_this_char (edit, edit->curs1, edit->curs_row);
|
|
|
|
} else {
|
|
|
|
edit_draw_this_char (edit, edit->curs1, edit->curs_row);
|
|
|
|
edit_draw_this_char (edit, prev_curs, prev_curs_row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
edit->force = 0;
|
|
|
|
|
|
|
|
prev_curs_row = edit->curs_row;
|
|
|
|
prev_curs = edit->curs1;
|
2005-08-16 01:37:34 +04:00
|
|
|
|
2001-08-24 22:23:17 +04:00
|
|
|
exit_render:
|
|
|
|
edit->screen_modified = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-11-13 07:32:00 +03:00
|
|
|
static void
|
|
|
|
edit_render (WEdit * edit, int page, int row_start, int col_start, int row_end, int col_end)
|
2001-08-24 22:23:17 +04:00
|
|
|
{
|
|
|
|
if (page) /* if it was an expose event, 'page' would be set */
|
|
|
|
edit->force |= REDRAW_PAGE | REDRAW_IN_BOUNDS;
|
|
|
|
|
|
|
|
if (edit->force & REDRAW_COMPLETELY)
|
2005-02-08 12:50:16 +03:00
|
|
|
buttonbar_redraw (edit->widget.parent);
|
2001-08-24 22:23:17 +04:00
|
|
|
render_edit_text (edit, row_start, col_start, row_end, col_end);
|
|
|
|
/*
|
2005-02-07 10:31:19 +03:00
|
|
|
* edit->force != 0 means a key was pending and the redraw
|
2001-08-24 22:23:17 +04:00
|
|
|
* was halted, so next time we must redraw everything in case stuff
|
|
|
|
* was left undrawn from a previous key press.
|
|
|
|
*/
|
|
|
|
if (edit->force)
|
|
|
|
edit->force |= REDRAW_PAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void edit_render_keypress (WEdit * edit)
|
|
|
|
{
|
|
|
|
edit_render (edit, 0, 0, 0, 0, 0);
|
|
|
|
}
|