1998-09-15 00:18:54 +04:00
|
|
|
/* propfont.c - editor text drawing for proportional fonts.
|
|
|
|
Copyright (C) 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
|
1999-03-21 04:56:20 +03:00
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
1998-09-15 00:18:54 +04:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include "edit.h"
|
1999-07-22 00:03:23 +04:00
|
|
|
#if defined (HAVE_MAD) && ! defined (MIDNIGHT) && ! defined (GTK)
|
|
|
|
#include "mad.h"
|
|
|
|
#endif
|
1998-09-15 00:18:54 +04:00
|
|
|
|
|
|
|
/* this file definatively relies on int being 32 bits or more */
|
|
|
|
|
|
|
|
int option_long_whitespace = 0;
|
|
|
|
|
|
|
|
#define MAX_LINE_LEN 1024
|
|
|
|
#define CACHE_WIDTH 256
|
|
|
|
#define CACHE_HEIGHT 128
|
|
|
|
|
|
|
|
|
|
|
|
struct cache_line {
|
|
|
|
int x0, x1;
|
|
|
|
cache_type data[CACHE_WIDTH];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* background colors: marked is refers to mouse highlighting, highlighted refers to a found string. */
|
|
|
|
extern unsigned long edit_abnormal_color, edit_marked_abnormal_color;
|
|
|
|
extern unsigned long edit_highlighted_color, edit_marked_color;
|
1998-09-16 04:20:01 +04:00
|
|
|
extern unsigned long edit_normal_background_color;
|
1998-09-15 00:18:54 +04:00
|
|
|
|
|
|
|
/* foreground colors */
|
1998-09-16 04:20:01 +04:00
|
|
|
extern unsigned long edit_normal_foreground_color, edit_bold_color;
|
1998-09-15 00:18:54 +04:00
|
|
|
extern unsigned long edit_italic_color;
|
|
|
|
|
|
|
|
/* cursor color */
|
|
|
|
extern unsigned long edit_cursor_color;
|
|
|
|
|
|
|
|
extern int EditExposeRedraw;
|
|
|
|
extern int EditClear;
|
|
|
|
|
1999-07-22 00:03:23 +04:00
|
|
|
int set_style_color (
|
1998-09-15 00:18:54 +04:00
|
|
|
#ifdef GTK
|
|
|
|
Window win,
|
|
|
|
#endif
|
|
|
|
cache_type s, unsigned long *fg, unsigned long *bg)
|
|
|
|
{
|
1999-07-22 00:03:23 +04:00
|
|
|
int fgp, bgp, underlined = 0;
|
1998-09-15 00:18:54 +04:00
|
|
|
fgp = (s & 0xFF000000UL) >> 24;
|
1999-03-21 04:56:20 +03:00
|
|
|
/* NO_COLOR would give fgp == 255 */
|
1999-07-22 00:03:23 +04:00
|
|
|
if (fgp < 0xFF)
|
1998-09-15 00:18:54 +04:00
|
|
|
*fg = color_palette (fgp);
|
|
|
|
else
|
|
|
|
*fg = edit_normal_foreground_color;
|
|
|
|
bgp = (s & 0x00FF0000) >> 16;
|
1999-07-22 00:03:23 +04:00
|
|
|
if (bgp == 0xFE)
|
|
|
|
underlined = 1;
|
|
|
|
if (bgp < 0xFD)
|
1998-09-15 00:18:54 +04:00
|
|
|
*bg = color_palette (bgp);
|
|
|
|
else
|
|
|
|
*bg = edit_normal_background_color;
|
|
|
|
if (!(s & 0xFFFFFF00UL)) /* check this first as an optimization */
|
1999-07-22 00:03:23 +04:00
|
|
|
return underlined;
|
1998-09-15 00:18:54 +04:00
|
|
|
if (s & (MOD_ABNORMAL * 256)) {
|
|
|
|
*bg = edit_abnormal_color;
|
|
|
|
if (s & (MOD_MARKED * 256))
|
|
|
|
*bg = edit_marked_abnormal_color;
|
|
|
|
} else if (s & (MOD_HIGHLIGHTED * 256)) {
|
|
|
|
*bg = edit_highlighted_color;
|
|
|
|
} else if (s & (MOD_MARKED * 256)) {
|
|
|
|
*bg = edit_marked_color;
|
|
|
|
}
|
|
|
|
if (s & (MOD_BOLD * 256))
|
|
|
|
*fg = edit_bold_color;
|
|
|
|
if (s & (MOD_ITALIC * 256))
|
|
|
|
*fg = edit_italic_color;
|
|
|
|
if (s & (MOD_INVERSE * 256)) {
|
|
|
|
unsigned long t;
|
|
|
|
t = *fg;
|
|
|
|
*fg = *bg;
|
|
|
|
*bg = t;
|
|
|
|
if (*bg == COLOR_BLACK)
|
|
|
|
*bg = color_palette (1);
|
|
|
|
}
|
1999-07-22 00:03:23 +04:00
|
|
|
return underlined;
|
1998-09-15 00:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GTK
|
|
|
|
#define set_style_color(s,f,b) set_style_color(win,s,f,b)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int tab_width = 1;
|
|
|
|
|
|
|
|
static inline int next_tab_pos (int x)
|
|
|
|
{
|
|
|
|
return x += tab_width - x % tab_width;
|
|
|
|
}
|
|
|
|
|
1999-07-22 00:03:23 +04:00
|
|
|
/* this now properly uses ctypes */
|
1998-09-15 00:18:54 +04:00
|
|
|
static inline int convert_to_long_printable (int c, unsigned char *t)
|
|
|
|
{
|
1999-07-22 00:03:23 +04:00
|
|
|
if (isgraph (c)) {
|
|
|
|
t[0] = c;
|
|
|
|
t[1] = 0;
|
2000-02-18 14:16:06 +03:00
|
|
|
return FONT_PER_CHAR[c];
|
1998-09-15 00:18:54 +04:00
|
|
|
}
|
|
|
|
if (c == ' ') {
|
|
|
|
if (option_long_whitespace) {
|
|
|
|
t[0] = ' ';
|
|
|
|
t[1] = ' ';
|
|
|
|
t[2] = 0;
|
2000-02-18 14:16:06 +03:00
|
|
|
return FONT_PER_CHAR[' '] + FONT_PER_CHAR[' '];
|
1998-09-15 00:18:54 +04:00
|
|
|
} else {
|
|
|
|
t[0] = ' ';
|
|
|
|
t[1] = 0;
|
2000-02-18 14:16:06 +03:00
|
|
|
return FONT_PER_CHAR[' '];
|
1998-09-15 00:18:54 +04:00
|
|
|
}
|
|
|
|
}
|
2000-02-18 14:16:06 +03:00
|
|
|
if (option_international_characters && FONT_PER_CHAR[c]) {
|
1999-07-22 00:03:23 +04:00
|
|
|
t[0] = c;
|
|
|
|
t[1] = 0;
|
2000-02-18 14:16:06 +03:00
|
|
|
return FONT_PER_CHAR[c];
|
1999-07-22 00:03:23 +04:00
|
|
|
}
|
|
|
|
if (c > '~') {
|
|
|
|
t[0] = ("0123456789ABCDEF")[c >> 4];
|
|
|
|
t[1] = ("0123456789ABCDEF")[c & 0xF];
|
|
|
|
t[2] = 'h';
|
|
|
|
t[3] = 0;
|
2000-02-18 14:16:06 +03:00
|
|
|
return FONT_PER_CHAR[t[0]] + FONT_PER_CHAR[t[1]] + FONT_PER_CHAR[t[2]];
|
1999-07-22 00:03:23 +04:00
|
|
|
}
|
1998-09-15 00:18:54 +04:00
|
|
|
t[0] = '^';
|
|
|
|
t[1] = c + '@';
|
|
|
|
t[2] = 0;
|
2000-02-18 14:16:06 +03:00
|
|
|
return FONT_PER_CHAR[t[0]] + FONT_PER_CHAR[t[1]];
|
1998-09-15 00:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* same as above but just gets the length */
|
|
|
|
static inline int width_of_long_printable (int c)
|
|
|
|
{
|
1999-07-22 00:03:23 +04:00
|
|
|
if (isgraph (c))
|
2000-02-18 14:16:06 +03:00
|
|
|
return FONT_PER_CHAR[c];
|
1998-09-15 00:18:54 +04:00
|
|
|
if (c == ' ') {
|
|
|
|
if (option_long_whitespace)
|
2000-02-18 14:16:06 +03:00
|
|
|
return FONT_PER_CHAR[' '] + FONT_PER_CHAR[' '];
|
1998-09-15 00:18:54 +04:00
|
|
|
else
|
2000-02-18 14:16:06 +03:00
|
|
|
return FONT_PER_CHAR[' '];
|
1998-09-15 00:18:54 +04:00
|
|
|
}
|
2000-02-18 14:16:06 +03:00
|
|
|
if (option_international_characters && FONT_PER_CHAR[c])
|
|
|
|
return FONT_PER_CHAR[c];
|
1999-07-22 00:03:23 +04:00
|
|
|
if (c > '~')
|
2000-02-18 14:16:06 +03:00
|
|
|
return FONT_PER_CHAR[(unsigned char) ("0123456789ABCDEF")[c >> 4]] + FONT_PER_CHAR[(unsigned char) ("0123456789ABCDEF")[c & 0xF]] + FONT_PER_CHAR[(unsigned char) 'h'];
|
|
|
|
return FONT_PER_CHAR['^'] + FONT_PER_CHAR[c + '@'];
|
1998-09-15 00:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int edit_width_of_long_printable (int c)
|
|
|
|
{
|
|
|
|
return width_of_long_printable (c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns x pixel pos of char at offset *q with x not more than l */
|
2000-02-18 14:16:06 +03:00
|
|
|
static int calc_text_pos (WEdit * edit, long b, long *q, int l)
|
1998-09-15 00:18:54 +04:00
|
|
|
{
|
|
|
|
int x = 0, c, xn;
|
|
|
|
for (;;) {
|
|
|
|
c = edit_get_byte (edit, b);
|
|
|
|
switch (c) {
|
|
|
|
case '\n':
|
|
|
|
*q = b;
|
|
|
|
if (x > edit->max_column)
|
|
|
|
edit->max_column = x;
|
|
|
|
return x;
|
|
|
|
case '\t':
|
|
|
|
xn = next_tab_pos (x);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
xn = x + width_of_long_printable (c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (xn > l)
|
|
|
|
break;
|
|
|
|
x = xn;
|
|
|
|
b++;
|
|
|
|
}
|
|
|
|
*q = b;
|
|
|
|
if (x > edit->max_column)
|
|
|
|
edit->max_column = x;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* calcs pixel length of the line beginning at b up to upto */
|
2000-02-18 14:16:06 +03:00
|
|
|
static int calc_text_len (WEdit * edit, long b, long upto)
|
1998-09-15 00:18:54 +04:00
|
|
|
{
|
|
|
|
int x = 0, c;
|
|
|
|
for (;;) {
|
|
|
|
if (b == upto) {
|
|
|
|
if (x > edit->max_column)
|
|
|
|
edit->max_column = x;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
c = edit_get_byte (edit, b);
|
|
|
|
switch (c) {
|
|
|
|
case '\n':{
|
|
|
|
if (x > edit->max_column)
|
|
|
|
edit->max_column = x;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
case '\t':
|
|
|
|
x = next_tab_pos (x);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
x += width_of_long_printable (c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
b++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If pixels is zero this returns the count of pixels from current to upto. */
|
|
|
|
/* If upto is zero returns index of pixels across from current. */
|
|
|
|
long edit_move_forward3 (WEdit * edit, long current, int pixels, long upto)
|
|
|
|
{
|
2000-02-18 14:16:06 +03:00
|
|
|
CPushFont ("editor", 0);
|
1998-09-15 00:18:54 +04:00
|
|
|
if (upto) {
|
2000-02-18 14:16:06 +03:00
|
|
|
current = calc_text_len (edit, current, upto);
|
1998-09-15 00:18:54 +04:00
|
|
|
} else if (pixels) {
|
|
|
|
long q;
|
|
|
|
calc_text_pos (edit, current, &q, pixels);
|
2000-02-18 14:16:06 +03:00
|
|
|
current = q;
|
1998-09-15 00:18:54 +04:00
|
|
|
}
|
2000-02-18 14:16:06 +03:00
|
|
|
CPopFont ();
|
1998-09-15 00:18:54 +04:00
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int column_highlighting;
|
|
|
|
|
1999-07-22 00:03:23 +04:00
|
|
|
/* gets the characters style (eg marked, highlighted) from its position in the edit buffer */
|
|
|
|
static inline cache_type get_style_fast (WEdit * edit, long q, int c)
|
|
|
|
{
|
|
|
|
cache_type s = 0;
|
|
|
|
unsigned int fg, bg;
|
2000-02-18 14:16:06 +03:00
|
|
|
if (!(isprint (c) || (option_international_characters && FONT_PER_CHAR[c])))
|
1999-07-22 00:03:23 +04:00
|
|
|
if (c != '\n' && c != '\t')
|
|
|
|
s |= MOD_ABNORMAL * 256;
|
|
|
|
edit_get_syntax_color (edit, q, (int *) &fg, (int *) &bg);
|
|
|
|
return s | ((fg & 0xFF) << 24) | ((bg & 0xFF) << 16);
|
|
|
|
}
|
|
|
|
|
1998-09-15 00:18:54 +04:00
|
|
|
/* gets the characters style (eg marked, highlighted) from its position in the edit buffer */
|
|
|
|
static inline cache_type get_style (WEdit * edit, long q, int c, long m1, long m2, int x)
|
|
|
|
{
|
|
|
|
cache_type s = 0;
|
|
|
|
unsigned int fg, bg;
|
|
|
|
if (q == edit->curs1)
|
|
|
|
s |= MOD_CURSOR * 256;
|
|
|
|
if (q >= m1 && q < m2) {
|
|
|
|
if (column_highlighting) {
|
|
|
|
if ((x >= edit->column1 && x < edit->column2)
|
|
|
|
|| (x >= edit->column2 && x < edit->column1))
|
|
|
|
s |= MOD_INVERSE * 256;
|
|
|
|
} else {
|
|
|
|
s |= MOD_MARKED * 256;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (q == edit->bracket)
|
|
|
|
s |= MOD_BOLD * 256;
|
|
|
|
if (q >= edit->found_start && q < edit->found_start + edit->found_len)
|
|
|
|
s |= MOD_HIGHLIGHTED * 256;
|
2000-02-18 14:16:06 +03:00
|
|
|
if (!(isprint (c) || (option_international_characters && FONT_PER_CHAR[c])))
|
1999-07-22 00:03:23 +04:00
|
|
|
if (c != '\n' && c != '\t')
|
1998-09-15 00:18:54 +04:00
|
|
|
s |= MOD_ABNORMAL * 256;
|
|
|
|
edit_get_syntax_color (edit, q, (int *) &fg, (int *) &bg);
|
|
|
|
return s | ((fg & 0xFF) << 24) | ((bg & 0xFF) << 16);
|
|
|
|
}
|
|
|
|
|
2000-02-18 14:16:06 +03:00
|
|
|
static void convert_text (WEdit * edit, long q, cache_type * p, int x, int x_max, int row)
|
1998-09-15 00:18:54 +04:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
cache_type s;
|
1999-07-22 00:03:23 +04:00
|
|
|
long m1, m2, last;
|
1998-09-15 00:18:54 +04:00
|
|
|
unsigned char *r, text[4];
|
1999-07-22 00:03:23 +04:00
|
|
|
int book_mark_colors[10], book_mark;
|
1998-09-15 00:18:54 +04:00
|
|
|
eval_marks (edit, &m1, &m2);
|
1999-03-21 04:56:20 +03:00
|
|
|
book_mark = book_mark_query_all (edit, edit->start_line + row, book_mark_colors);
|
1999-07-22 00:03:23 +04:00
|
|
|
last = q + (x_max - x) / 2 + 2; /* for optimization, we say that the last character
|
|
|
|
of this line cannot have an offset greater than this.
|
|
|
|
This can be used to rule out uncommon text styles,
|
|
|
|
like a character with a cursor, or selected text */
|
|
|
|
if (book_mark) {
|
|
|
|
int the_end = 0, book_mark_cycle = 0;
|
|
|
|
for (;;) {
|
|
|
|
c = edit_get_byte (edit, q);
|
|
|
|
if (!the_end)
|
|
|
|
*p = get_style (edit, q, c, m1, m2, x);
|
1999-03-21 04:56:20 +03:00
|
|
|
if (the_end)
|
|
|
|
*p = 0;
|
|
|
|
*p = (*p & 0x0000FFFF) | (book_mark_colors[book_mark_cycle++ % book_mark] << 16);
|
1999-07-22 00:03:23 +04:00
|
|
|
switch (c) {
|
|
|
|
case '\n':
|
1999-03-21 04:56:20 +03:00
|
|
|
the_end = 1;
|
|
|
|
c = ' ';
|
|
|
|
q--;
|
|
|
|
goto the_default;
|
1999-07-22 00:03:23 +04:00
|
|
|
case '\t':
|
2000-02-18 14:16:06 +03:00
|
|
|
if (FIXED_FONT) {
|
1999-07-22 00:03:23 +04:00
|
|
|
int t;
|
|
|
|
t = next_tab_pos (x);
|
|
|
|
t = min (t, x_max);
|
|
|
|
s = *p;
|
|
|
|
while (x < t) {
|
2000-02-18 14:16:06 +03:00
|
|
|
x += FONT_PER_CHAR[' '];
|
1999-07-22 00:03:23 +04:00
|
|
|
*p++ = s | ' ';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*p++ |= '\t';
|
|
|
|
x = next_tab_pos (x);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
the_default:
|
|
|
|
x += convert_to_long_printable (c, text);
|
|
|
|
r = text;
|
|
|
|
s = *p;
|
|
|
|
*p++ = s | *r++;
|
|
|
|
if (!*r)
|
|
|
|
break;
|
|
|
|
*p++ = s | *r++;
|
|
|
|
if (!*r)
|
|
|
|
break;
|
|
|
|
*p++ = s | *r++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (x >= x_max)
|
|
|
|
break;
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
} else if ((m2 < q || m1 > last) && (edit->curs1 < q || edit->curs1 > last) && \
|
|
|
|
(edit->found_start + edit->found_len < q || edit->found_start > last) &&
|
|
|
|
(edit->bracket < q || edit->bracket > last)) {
|
|
|
|
for (;;) {
|
|
|
|
c = edit_get_byte (edit, q);
|
|
|
|
*p = get_style_fast (edit, q, c);
|
|
|
|
switch (c) {
|
|
|
|
case '\n':
|
1999-03-21 04:56:20 +03:00
|
|
|
*p++ |= ' ';
|
|
|
|
*p = 0;
|
|
|
|
if (x > edit->max_column)
|
|
|
|
edit->max_column = x;
|
|
|
|
return;
|
1999-07-22 00:03:23 +04:00
|
|
|
case '\t':
|
2000-02-18 14:16:06 +03:00
|
|
|
if (FIXED_FONT) {
|
1999-07-22 00:03:23 +04:00
|
|
|
int t;
|
|
|
|
t = next_tab_pos (x);
|
|
|
|
t = min (t, x_max);
|
|
|
|
s = *p;
|
|
|
|
while (x < t) {
|
2000-02-18 14:16:06 +03:00
|
|
|
x += FONT_PER_CHAR[' '];
|
1999-07-22 00:03:23 +04:00
|
|
|
*p++ = s | ' ';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*p++ |= '\t';
|
|
|
|
x = next_tab_pos (x);
|
1998-09-15 00:18:54 +04:00
|
|
|
}
|
1999-07-22 00:03:23 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
x += convert_to_long_printable (c, text);
|
|
|
|
r = text;
|
|
|
|
s = *p;
|
|
|
|
*p++ = s | *r++;
|
|
|
|
if (!*r)
|
|
|
|
break;
|
|
|
|
*p++ = s | *r++;
|
|
|
|
if (!*r)
|
|
|
|
break;
|
|
|
|
*p++ = s | *r++;
|
|
|
|
break;
|
1998-09-15 00:18:54 +04:00
|
|
|
}
|
1999-07-22 00:03:23 +04:00
|
|
|
if (x >= x_max)
|
|
|
|
break;
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (;;) {
|
|
|
|
c = edit_get_byte (edit, q);
|
|
|
|
*p = get_style (edit, q, c, m1, m2, x);
|
|
|
|
switch (c) {
|
|
|
|
case '\n':
|
|
|
|
*p++ |= ' ';
|
|
|
|
*p = 0;
|
|
|
|
if (x > edit->max_column)
|
|
|
|
edit->max_column = x;
|
|
|
|
return;
|
|
|
|
case '\t':
|
2000-02-18 14:16:06 +03:00
|
|
|
if (FIXED_FONT) {
|
1999-07-22 00:03:23 +04:00
|
|
|
int t;
|
|
|
|
t = next_tab_pos (x);
|
|
|
|
t = min (t, x_max);
|
|
|
|
s = *p;
|
|
|
|
while (x < t) {
|
2000-02-18 14:16:06 +03:00
|
|
|
x += FONT_PER_CHAR[' '];
|
1999-07-22 00:03:23 +04:00
|
|
|
*p++ = s | ' ';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*p++ |= '\t';
|
|
|
|
x = next_tab_pos (x);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
x += convert_to_long_printable (c, text);
|
|
|
|
r = text;
|
|
|
|
s = *p;
|
1998-09-15 00:18:54 +04:00
|
|
|
*p++ = s | *r++;
|
1999-07-22 00:03:23 +04:00
|
|
|
if (!*r)
|
|
|
|
break;
|
|
|
|
*p++ = s | *r++;
|
|
|
|
if (!*r)
|
|
|
|
break;
|
|
|
|
*p++ = s | *r++;
|
|
|
|
break;
|
1998-09-15 00:18:54 +04:00
|
|
|
}
|
1999-07-22 00:03:23 +04:00
|
|
|
if (x >= x_max)
|
|
|
|
break;
|
|
|
|
q++;
|
1998-09-15 00:18:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (x > edit->max_column)
|
|
|
|
edit->max_column = x;
|
|
|
|
*p = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void edit_set_cursor (Window win, int x, int y, int bg, int fg, int width, char t)
|
|
|
|
{
|
|
|
|
#ifdef GTK
|
|
|
|
gdk_gc_set_foreground (win->gc, &win->color[18]);
|
|
|
|
gdk_draw_rectangle (win->text_area, win->gc, 0, x, y + FONT_OVERHEAD, width - 1, FONT_HEIGHT - 1);
|
|
|
|
#else
|
|
|
|
CSetColor (edit_cursor_color);
|
|
|
|
CLine (win, x, y + FONT_OVERHEAD,
|
|
|
|
x, y + FONT_HEIGHT - 1); /* non focussed cursor form */
|
|
|
|
CLine (win, x + 1, y + FONT_OVERHEAD,
|
|
|
|
x + width - 1, y + FONT_OVERHEAD);
|
|
|
|
set_cursor_position (win, x, y, width, FONT_HEIGHT, CURSOR_TYPE_EDITOR, t, bg, fg); /* widget library's flashing cursor */
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int next_tab (int x, int scroll_right)
|
|
|
|
{
|
|
|
|
return next_tab_pos (x - scroll_right - EDIT_TEXT_HORIZONTAL_OFFSET) - x + scroll_right + EDIT_TEXT_HORIZONTAL_OFFSET;
|
|
|
|
}
|
|
|
|
|
2000-02-18 14:16:06 +03:00
|
|
|
static int draw_tab (Window win, int x, int y, cache_type s, int scroll_right)
|
1998-09-15 00:18:54 +04:00
|
|
|
{
|
|
|
|
int l;
|
|
|
|
#ifdef GTK
|
|
|
|
GdkColor fg, bg;
|
|
|
|
#else
|
|
|
|
unsigned long fg, bg;
|
|
|
|
#endif
|
|
|
|
l = next_tab (x, scroll_right);
|
|
|
|
#ifdef GTK
|
|
|
|
set_style_color (s, &fg.pixel, &bg.pixel);
|
|
|
|
gdk_gc_set_foreground (win->gc, &bg);
|
|
|
|
gdk_draw_rectangle (win->text_area, win->gc, 1, x, y + FONT_OVERHEAD, l, FONT_HEIGHT);
|
|
|
|
/* if we printed a cursor: */
|
|
|
|
if (s & (MOD_CURSOR * 256))
|
2000-02-18 14:16:06 +03:00
|
|
|
edit_set_cursor (win, x, y, bg.pixel, fg.pixel, FONT_PER_CHAR[' '], ' ');
|
1998-09-15 00:18:54 +04:00
|
|
|
#else
|
|
|
|
set_style_color (s, &fg, &bg);
|
|
|
|
CSetColor (bg);
|
|
|
|
CRectangle (win, x, y + FONT_OVERHEAD, l, FONT_HEIGHT);
|
|
|
|
/* if we printed a cursor: */
|
|
|
|
if (s & (MOD_CURSOR * 256))
|
2000-02-18 14:16:06 +03:00
|
|
|
edit_set_cursor (win, x, y, bg, fg, FONT_PER_CHAR[' '], ' ');
|
1998-09-15 00:18:54 +04:00
|
|
|
#endif
|
|
|
|
return x + l;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GTK
|
|
|
|
#include <gdk/gdk.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline void draw_space (Window win, int x, int y, cache_type s, int l)
|
|
|
|
{
|
|
|
|
#ifdef GTK
|
|
|
|
GdkColor fg, bg;
|
|
|
|
#else
|
|
|
|
unsigned long fg, bg;
|
|
|
|
#endif
|
|
|
|
#ifdef GTK
|
|
|
|
set_style_color (s, &fg.pixel, &bg.pixel);
|
|
|
|
gdk_gc_set_foreground (win->gc, &bg);
|
|
|
|
gdk_draw_rectangle (win->text_area, win->gc, 1, x, y + FONT_OVERHEAD, l, FONT_HEIGHT);
|
|
|
|
#else
|
|
|
|
set_style_color (s, &fg, &bg);
|
|
|
|
CSetColor (bg);
|
|
|
|
CRectangle (win, x, y + FONT_OVERHEAD, l, FONT_HEIGHT);
|
|
|
|
/* if we printed a cursor: */
|
|
|
|
if (s & (MOD_CURSOR * 256))
|
2000-02-18 14:16:06 +03:00
|
|
|
edit_set_cursor (win, x, y, bg, fg, FONT_PER_CHAR[' '], ' ');
|
1998-09-15 00:18:54 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef GTK
|
|
|
|
|
|
|
|
void
|
|
|
|
gdk_draw_image_text (GdkDrawable *drawable,
|
|
|
|
GdkFont *font,
|
|
|
|
GdkGC *gc,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
const gchar *text,
|
|
|
|
gint text_length)
|
|
|
|
{
|
|
|
|
GdkWindowPrivate *drawable_private;
|
|
|
|
GdkFontPrivate *font_private;
|
|
|
|
GdkGCPrivate *gc_private;
|
|
|
|
|
|
|
|
g_return_if_fail (drawable != NULL);
|
|
|
|
g_return_if_fail (font != NULL);
|
|
|
|
g_return_if_fail (gc != NULL);
|
|
|
|
g_return_if_fail (text != NULL);
|
|
|
|
|
|
|
|
drawable_private = (GdkWindowPrivate*) drawable;
|
|
|
|
if (drawable_private->destroyed)
|
|
|
|
return;
|
|
|
|
gc_private = (GdkGCPrivate*) gc;
|
|
|
|
font_private = (GdkFontPrivate*) font;
|
|
|
|
|
|
|
|
if (font->type == GDK_FONT_FONT)
|
|
|
|
{
|
|
|
|
XFontStruct *xfont = (XFontStruct *) font_private->xfont;
|
|
|
|
XSetFont(drawable_private->xdisplay, gc_private->xgc, xfont->fid);
|
|
|
|
if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
|
|
|
|
{
|
|
|
|
XDrawImageString (drawable_private->xdisplay, drawable_private->xwindow,
|
|
|
|
gc_private->xgc, x, y, text, text_length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
XDrawImageString16 (drawable_private->xdisplay, drawable_private->xwindow,
|
|
|
|
gc_private->xgc, x, y, (XChar2b *) text, text_length / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (font->type == GDK_FONT_FONTSET)
|
|
|
|
{
|
|
|
|
XFontSet fontset = (XFontSet) font_private->xfont;
|
|
|
|
XmbDrawImageString (drawable_private->xdisplay, drawable_private->xwindow,
|
|
|
|
fontset, gc_private->xgc, x, y, text, text_length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_error("undefined font type\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2000-02-18 14:16:06 +03:00
|
|
|
static int draw_string (Window win, int x, int y, cache_type s, unsigned char *text, int length)
|
1998-09-15 00:18:54 +04:00
|
|
|
{
|
|
|
|
#ifdef GTK
|
|
|
|
GdkColor fg, bg;
|
|
|
|
#else
|
|
|
|
unsigned long fg, bg;
|
1999-07-22 00:03:23 +04:00
|
|
|
int underlined, l;
|
1998-09-15 00:18:54 +04:00
|
|
|
#endif
|
|
|
|
#ifdef GTK
|
|
|
|
set_style_color (s, &fg.pixel, &bg.pixel);
|
|
|
|
gdk_gc_set_background (win->gc, &bg);
|
|
|
|
gdk_gc_set_foreground (win->gc, &fg);
|
|
|
|
gdk_draw_image_text (win->text_area, GTK_WIDGET (win)->style->font, win->gc, x + FONT_OFFSET_X, y + FONT_OFFSET_Y, text, length);
|
|
|
|
#else
|
1999-07-22 00:03:23 +04:00
|
|
|
underlined = set_style_color (s, &fg, &bg);
|
1998-09-15 00:18:54 +04:00
|
|
|
CSetBackgroundColor (bg);
|
|
|
|
CSetColor (fg);
|
2000-02-18 14:16:06 +03:00
|
|
|
CImageText (win, x + FONT_OFFSET_X, y + FONT_OFFSET_Y, (char *) text, length);
|
|
|
|
l = CTextWidth ((char *) text, length);
|
1999-07-22 00:03:23 +04:00
|
|
|
if (underlined) {
|
|
|
|
int i, h, inc;
|
|
|
|
inc = FONT_MEAN_WIDTH * 2 / 3;
|
|
|
|
CSetColor (color_palette (18));
|
|
|
|
h = (x / inc) & 1;
|
|
|
|
CLine (win, x, y + FONT_HEIGHT + FONT_OVERHEAD - 1 - h, x + min (l, inc - (x % inc) - 1), y + FONT_HEIGHT + FONT_OVERHEAD - 1 - h);
|
|
|
|
h = h ^ 1;
|
|
|
|
for (i = inc - min (l, (x % inc)); i < l; i += inc) {
|
|
|
|
CLine (win, x + i, y + FONT_HEIGHT + FONT_OVERHEAD - 1 - h, x + min (l, i + inc - 1), y + FONT_HEIGHT + FONT_OVERHEAD - 1 - h);
|
|
|
|
h = h ^ 1;
|
|
|
|
}
|
|
|
|
}
|
1998-09-15 00:18:54 +04:00
|
|
|
#endif
|
|
|
|
/* if we printed a cursor: */
|
|
|
|
#ifdef GTK
|
|
|
|
if (s & (MOD_CURSOR * 256))
|
2000-02-18 14:16:06 +03:00
|
|
|
edit_set_cursor (win, x, y, bg.pixel, fg.pixel, FONT_PER_CHAR[*text], *text);
|
1998-09-15 00:18:54 +04:00
|
|
|
return x + gdk_text_width (GTK_WIDGET (win)->style->font, text, length);
|
|
|
|
#else
|
|
|
|
if (s & (MOD_CURSOR * 256))
|
2000-02-18 14:16:06 +03:00
|
|
|
edit_set_cursor (win, x, y, bg, fg, FONT_PER_CHAR[*text], *text);
|
1999-07-22 00:03:23 +04:00
|
|
|
return x + l;
|
1998-09-15 00:18:54 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-07-22 00:03:23 +04:00
|
|
|
#define STYLE_DIFF (*cache != *line \
|
|
|
|
|| ((*cache | *line) & (MOD_CURSOR * 256)) \
|
|
|
|
|| !*cache || !*line)
|
1998-09-15 00:18:54 +04:00
|
|
|
|
|
|
|
int get_ignore_length (cache_type *cache, cache_type *line)
|
|
|
|
{
|
|
|
|
int i;
|
1999-07-22 00:03:23 +04:00
|
|
|
for (i = 0; i < CACHE_WIDTH; i++, line++, cache++) {
|
1998-09-15 00:18:54 +04:00
|
|
|
if (STYLE_DIFF)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return CACHE_WIDTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t lwstrnlen (const cache_type *s, size_t count)
|
|
|
|
{
|
|
|
|
const cache_type *sc;
|
|
|
|
for (sc = s; count-- && *sc != 0; ++sc);
|
|
|
|
return sc - s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t lwstrlen (const cache_type *s)
|
|
|
|
{
|
|
|
|
const cache_type *sc;
|
|
|
|
for (sc = s; *sc != 0; ++sc);
|
|
|
|
return sc - s;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_ignore_trailer (cache_type *cache, cache_type *line, int length)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int cache_len, line_len;
|
|
|
|
cache_len = lwstrnlen (cache, CACHE_WIDTH);
|
|
|
|
line_len = lwstrlen (line);
|
|
|
|
|
|
|
|
if (line_len > cache_len)
|
|
|
|
for (i = line_len - 1; i >= cache_len && i >= length; i--)
|
|
|
|
if (line[i] != ' ')
|
|
|
|
return i + 1;
|
|
|
|
|
1999-07-22 00:03:23 +04:00
|
|
|
for (i = cache_len - 1, line = line + i, cache = cache + i; i > length; i--, line--, cache--)
|
1998-09-15 00:18:54 +04:00
|
|
|
if (STYLE_DIFF)
|
|
|
|
return i + 1;
|
|
|
|
|
|
|
|
return length + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* erases trailing bit of old line if a new line is printed over a longer old line */
|
1999-07-22 00:03:23 +04:00
|
|
|
static void cover_trail (Window win, int x_start, int x_new, int x_old, int y)
|
1998-09-15 00:18:54 +04:00
|
|
|
{
|
|
|
|
if (x_new < EDIT_TEXT_HORIZONTAL_OFFSET)
|
1999-07-22 00:03:23 +04:00
|
|
|
x_new = EDIT_TEXT_HORIZONTAL_OFFSET;
|
|
|
|
if (x_new < x_old) { /* no need to print */
|
|
|
|
#ifdef GTK
|
|
|
|
gdk_gc_set_foreground (win->gc, &win->color[1]);
|
|
|
|
gdk_draw_rectangle (win->text_area, win->gc, 1, x_new, y + FONT_OVERHEAD, x_old - x_new, FONT_HEIGHT);
|
|
|
|
#else
|
|
|
|
CSetColor (edit_normal_background_color);
|
2000-02-18 14:16:06 +03:00
|
|
|
CRectangle (win, x_new, y + FONT_OVERHEAD, x_old - x_new, FONT_HEIGHT + (FONT_OVERHEAD != 0 && !FIXED_FONT));
|
1999-07-22 00:03:23 +04:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
#ifdef GTK
|
|
|
|
gdk_gc_set_foreground (win->gc, &win->color[1]);
|
|
|
|
#else
|
|
|
|
CSetColor (edit_normal_background_color);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
/* true type fonts print stuff out of the bounding box (aaaaaaaaarrrgh!!) */
|
2000-02-18 14:16:06 +03:00
|
|
|
if (!FIXED_FONT)
|
1999-07-22 00:03:23 +04:00
|
|
|
if (FONT_OVERHEAD && x_new > EDIT_TEXT_HORIZONTAL_OFFSET)
|
1998-09-15 00:18:54 +04:00
|
|
|
#ifdef GTK
|
1999-07-22 00:03:23 +04:00
|
|
|
gdk_draw_line (win->text_area, win->gc, max (x_start, EDIT_TEXT_HORIZONTAL_OFFSET), y + FONT_HEIGHT + FONT_OVERHEAD, x_new - 1, y + FONT_HEIGHT + FONT_OVERHEAD);
|
1998-09-15 00:18:54 +04:00
|
|
|
#else
|
1999-07-22 00:03:23 +04:00
|
|
|
CLine (win, max (x_start, EDIT_TEXT_HORIZONTAL_OFFSET), y + FONT_HEIGHT + FONT_OVERHEAD, x_new - 1, y + FONT_HEIGHT + FONT_OVERHEAD);
|
1998-09-15 00:18:54 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
cache_type mode_spacing = 0;
|
|
|
|
|
|
|
|
#define NOT_VALID (-2000000000)
|
|
|
|
|
|
|
|
void edit_draw_proportional (void *data,
|
1999-03-21 04:56:20 +03:00
|
|
|
void (*converttext) (void *, long, cache_type *, int, int, int),
|
1998-09-15 00:18:54 +04:00
|
|
|
int calctextpos (void *, long, long *, int),
|
|
|
|
int scroll_right,
|
|
|
|
Window win,
|
|
|
|
int x_max,
|
|
|
|
long b,
|
|
|
|
int row,
|
|
|
|
int y,
|
|
|
|
int x_offset,
|
|
|
|
int tabwidth)
|
|
|
|
{
|
|
|
|
static struct cache_line lines[CACHE_HEIGHT];
|
|
|
|
static Window last = 0;
|
|
|
|
cache_type style, line[MAX_LINE_LEN], *p;
|
|
|
|
unsigned char text[128];
|
|
|
|
int x0, x, ignore_text = 0, ignore_trailer = 2000000000, j, i;
|
|
|
|
long q;
|
|
|
|
|
|
|
|
tab_width = tabwidth;
|
|
|
|
if (option_long_whitespace)
|
|
|
|
tab_width = tabwidth *= 2;
|
|
|
|
|
|
|
|
x_max -= 3;
|
|
|
|
|
|
|
|
/* if its not the same window, reset the screen rememberer */
|
2000-02-18 14:16:06 +03:00
|
|
|
if (last != win || !win) {
|
1998-09-15 00:18:54 +04:00
|
|
|
last = win;
|
|
|
|
for (i = 0; i < CACHE_HEIGHT; i++) {
|
|
|
|
lines[i].x0 = NOT_VALID;
|
|
|
|
lines[i].x1 = x_max;
|
|
|
|
}
|
2000-02-18 14:16:06 +03:00
|
|
|
if (!win)
|
|
|
|
return;
|
1998-09-15 00:18:54 +04:00
|
|
|
}
|
2000-02-18 14:16:06 +03:00
|
|
|
|
1998-09-15 00:18:54 +04:00
|
|
|
/* get point to start drawing */
|
|
|
|
x0 = (*calctextpos) (data, b, &q, -scroll_right + x_offset);
|
|
|
|
/* q contains the offset in the edit buffer */
|
|
|
|
|
|
|
|
/* translate this line into printable characters with a style (=color) high byte */
|
1999-03-21 04:56:20 +03:00
|
|
|
(*converttext) (data, q, line, x0, x_max - scroll_right - EDIT_TEXT_HORIZONTAL_OFFSET, row);
|
1998-09-15 00:18:54 +04:00
|
|
|
|
|
|
|
/* adjust for the horizontal scroll and border */
|
|
|
|
x0 += scroll_right + EDIT_TEXT_HORIZONTAL_OFFSET;
|
|
|
|
x = x0;
|
|
|
|
|
|
|
|
/* is some of the line identical to that already printed so that we can ignore it? */
|
|
|
|
if (!EditExposeRedraw) {
|
|
|
|
if (lines[row].x0 == x0 && row < CACHE_HEIGHT) { /* i.e. also && lines[row].x0 != NOT_VALID */
|
|
|
|
ignore_text = get_ignore_length (lines[row].data, line);
|
2000-02-18 14:16:06 +03:00
|
|
|
if (FIXED_FONT)
|
1998-09-15 00:18:54 +04:00
|
|
|
ignore_trailer = get_ignore_trailer (lines[row].data, line, ignore_text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p = line;
|
|
|
|
j = 0;
|
|
|
|
while (*p) {
|
|
|
|
if (mode_spacing) {
|
|
|
|
if ((*p & 0x80) && (*p & mode_spacing)) {
|
|
|
|
#ifdef STILL_TO_BE_SUPPORTED
|
|
|
|
x += edit_insert_pixmap (win, x, y, *p & 0x7F);
|
|
|
|
/* the pixmap will be clipped, if it's taller than the
|
|
|
|
current font, else centred top to bottom */
|
|
|
|
#endif
|
|
|
|
p++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
goto do_text;
|
|
|
|
}
|
|
|
|
if ((*p & 0xFF) == '\t') {
|
|
|
|
j++;
|
|
|
|
if (j > ignore_text && j < ignore_trailer + 1)
|
|
|
|
x = draw_tab (win, x, y, *p, scroll_right);
|
|
|
|
else
|
|
|
|
x += next_tab (x, scroll_right);
|
|
|
|
p++;
|
|
|
|
} else {
|
|
|
|
do_text:
|
|
|
|
style = *p & 0xFFFFFF00UL;
|
|
|
|
i = 0;
|
|
|
|
do {
|
|
|
|
text[i++] = (unsigned char) *p++;
|
|
|
|
j++;
|
|
|
|
if (j == ignore_text || j == ignore_trailer)
|
|
|
|
break;
|
|
|
|
} while (i < 128 && *p && style == (*p & 0xFFFFFF00UL) && (*p & 0xFF) != '\t');
|
|
|
|
|
|
|
|
if (style & mode_spacing) {
|
|
|
|
int k;
|
|
|
|
for (k = 0; k < i; k++) {
|
|
|
|
draw_space (win, x, y, (0xFFFFFF00UL - mode_spacing) & style, text[k]);
|
|
|
|
x += text[k];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (j > ignore_text && j < ignore_trailer + 1)
|
|
|
|
x = draw_string (win, x, y, style, text, i);
|
|
|
|
else
|
|
|
|
#ifdef GTK
|
|
|
|
x += gdk_text_width (GTK_WIDGET(win)->style->font, text, i);
|
|
|
|
#else
|
2000-02-18 14:16:06 +03:00
|
|
|
x += CTextWidth ((char *) text, i);
|
1998-09-15 00:18:54 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
x = min (x, x_max);
|
|
|
|
if (!EditExposeRedraw || EditClear)
|
1999-07-22 00:03:23 +04:00
|
|
|
cover_trail (win, x0, x, lines[row].x1, y);
|
1998-09-15 00:18:54 +04:00
|
|
|
memcpy (&(lines[row].data[ignore_text]),
|
|
|
|
&(line[ignore_text]),
|
|
|
|
(min (j, CACHE_WIDTH) - ignore_text) * sizeof (cache_type));
|
|
|
|
|
|
|
|
lines[row].data[min (j, CACHE_WIDTH)] = 0;
|
|
|
|
|
|
|
|
lines[row].x0 = x0;
|
|
|
|
lines[row].x1 = x;
|
|
|
|
if (EditExposeRedraw)
|
|
|
|
last = 0;
|
|
|
|
else
|
|
|
|
last = win;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void edit_draw_this_line_proportional (WEdit * edit, long b, int row, int start_column, int end_column)
|
|
|
|
{
|
|
|
|
int fg, bg;
|
|
|
|
if (row < 0 || row >= edit->num_widget_lines)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (row + edit->start_line > edit->total_lines)
|
1999-07-22 00:03:23 +04:00
|
|
|
b = edit->last_byte + 1; /* force b out of range of the edit buffer for blanks lines */
|
1998-09-15 00:18:54 +04:00
|
|
|
|
|
|
|
if (end_column > CWidthOf (edit->widget))
|
|
|
|
end_column = CWidthOf (edit->widget);
|
|
|
|
|
|
|
|
edit_get_syntax_color (edit, b - 1, &fg, &bg);
|
|
|
|
|
|
|
|
edit_draw_proportional (edit,
|
1999-03-21 04:56:20 +03:00
|
|
|
(void (*) (void *, long, cache_type *, int, int, int)) convert_text,
|
1998-09-15 00:18:54 +04:00
|
|
|
(int (*) (void *, long, long *, int)) calc_text_pos,
|
|
|
|
edit->start_col, CWindowOf (edit->widget),
|
|
|
|
end_column, b, row, row * FONT_PIX_PER_LINE + EDIT_TEXT_VERTICAL_OFFSET,
|
2000-02-18 14:16:06 +03:00
|
|
|
EditExposeRedraw ? start_column : 0, FONT_PER_CHAR[' '] * TAB_SIZE);
|
1998-09-15 00:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************************/
|
|
|
|
/* The remainder is for the text box widget */
|
|
|
|
/*********************************************************************************/
|
|
|
|
|
|
|
|
static inline int nroff_printable (int c)
|
|
|
|
{
|
1999-07-22 00:03:23 +04:00
|
|
|
return isprint (c);
|
1998-09-15 00:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-18 14:16:06 +03:00
|
|
|
static int calc_text_pos_str (unsigned char *text, long b, long *q, int l)
|
1998-09-15 00:18:54 +04:00
|
|
|
{
|
|
|
|
int x = 0, c = 0, xn = 0, d;
|
|
|
|
for (;;) {
|
|
|
|
d = c;
|
|
|
|
c = text[b];
|
|
|
|
switch (c) {
|
|
|
|
case '\0':
|
|
|
|
case '\n':
|
|
|
|
*q = b;
|
|
|
|
return x;
|
|
|
|
case '\t':
|
|
|
|
xn = next_tab_pos (x);
|
|
|
|
break;
|
|
|
|
case '\r':
|
|
|
|
break;
|
|
|
|
case '\b':
|
|
|
|
if (d)
|
2000-02-18 14:16:06 +03:00
|
|
|
xn = x - FONT_PER_CHAR[d];
|
1998-09-15 00:18:54 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!nroff_printable (c))
|
|
|
|
c = ' ';
|
2000-02-18 14:16:06 +03:00
|
|
|
xn = x + FONT_PER_CHAR[c];
|
1998-09-15 00:18:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (xn > l)
|
|
|
|
break;
|
|
|
|
x = xn;
|
|
|
|
b++;
|
|
|
|
}
|
|
|
|
*q = b;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
int prop_font_strcolmove (unsigned char *str, int i, int column)
|
|
|
|
{
|
|
|
|
long q;
|
2000-02-18 14:16:06 +03:00
|
|
|
CPushFont ("editor", 0);
|
1998-09-15 00:18:54 +04:00
|
|
|
calc_text_pos_str (str, i, &q, column * FONT_MEAN_WIDTH);
|
2000-02-18 14:16:06 +03:00
|
|
|
CPopFont ();
|
1998-09-15 00:18:54 +04:00
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef GTK
|
|
|
|
|
|
|
|
/* b is the beginning of the line. l is the length in pixels up to a point
|
|
|
|
on some character which is unknown. The character pos is returned in
|
|
|
|
*q and the characters pixel x pos from b is return'ed. */
|
|
|
|
int calc_text_pos2 (CWidget * w, long b, long *q, int l)
|
|
|
|
{
|
2000-02-18 14:16:06 +03:00
|
|
|
int r;
|
|
|
|
CPushFont ("editor", 0);
|
|
|
|
r = calc_text_pos_str ((unsigned char *) w->text, b, q, l);
|
|
|
|
CPopFont ();
|
|
|
|
return r;
|
1998-09-15 00:18:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int highlight_this_line;
|
|
|
|
|
|
|
|
/* this is for the text widget (i.e. nroff formatting) */
|
1999-03-21 04:56:20 +03:00
|
|
|
void convert_text2 (CWidget * w, long q, cache_type *line, int x, int x_max, int row)
|
1998-09-15 00:18:54 +04:00
|
|
|
{
|
|
|
|
int c = 0, d;
|
|
|
|
cache_type s, *p;
|
|
|
|
long m1, m2;
|
|
|
|
|
|
|
|
m1 = min (w->mark1, w->mark2);
|
|
|
|
m2 = max (w->mark1, w->mark2);
|
|
|
|
|
|
|
|
p = line;
|
|
|
|
*p = 0;
|
|
|
|
for (;;) {
|
|
|
|
d = c;
|
|
|
|
c = w->text[q];
|
|
|
|
*(p + 1) = 0;
|
|
|
|
*p |= 0xFFFF0000UL; /* default background colors */
|
|
|
|
if (highlight_this_line)
|
|
|
|
*p |= MOD_HIGHLIGHTED * 256;
|
|
|
|
if (q >= m1 && q < m2)
|
|
|
|
*p |= MOD_MARKED * 256;
|
|
|
|
switch (c) {
|
|
|
|
case '\0':
|
|
|
|
case '\n':
|
|
|
|
*p++ |= ' ';
|
|
|
|
if (highlight_this_line) {
|
|
|
|
q--;
|
2000-02-18 14:16:06 +03:00
|
|
|
x += FONT_PER_CHAR[' '];
|
1998-09-15 00:18:54 +04:00
|
|
|
} else
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case '\t':
|
2000-02-18 14:16:06 +03:00
|
|
|
if (FIXED_FONT) {
|
1998-09-15 00:18:54 +04:00
|
|
|
int i;
|
|
|
|
i = next_tab_pos (x) - x;
|
|
|
|
x += i;
|
|
|
|
s = *p;
|
|
|
|
while (i > 0) {
|
2000-02-18 14:16:06 +03:00
|
|
|
i -= FONT_PER_CHAR[' '];
|
1998-09-15 00:18:54 +04:00
|
|
|
*p++ = s | ' ';
|
|
|
|
*p = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*p++ |= '\t';
|
|
|
|
x = next_tab_pos (x);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '\r':
|
|
|
|
break;
|
|
|
|
case '\b':
|
|
|
|
if (d) {
|
|
|
|
--p;
|
2000-02-18 14:16:06 +03:00
|
|
|
x -= FONT_PER_CHAR[d];
|
1998-09-15 00:18:54 +04:00
|
|
|
if (d == '_')
|
|
|
|
*p |= MOD_ITALIC * 256;
|
|
|
|
else
|
|
|
|
*p |= MOD_BOLD * 256;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!nroff_printable (c)) {
|
|
|
|
c = ' ';
|
|
|
|
*p |= MOD_ABNORMAL * 256;
|
|
|
|
}
|
2000-02-18 14:16:06 +03:00
|
|
|
x += FONT_PER_CHAR[c];
|
1998-09-15 00:18:54 +04:00
|
|
|
*p &= 0xFFFFFF00UL;
|
|
|
|
*p |= c;
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (x > x_max)
|
|
|
|
break;
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
*p = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|