1
/* $Id: display.c,v 1.70 2007/05/29 12:07:02 inu Exp $ */
8
#define EFFECT_ANCHOR_START effect_anchor_start()
9
#define EFFECT_ANCHOR_END effect_anchor_end()
10
#define EFFECT_IMAGE_START effect_image_start()
11
#define EFFECT_IMAGE_END effect_image_end()
12
#define EFFECT_FORM_START effect_form_start()
13
#define EFFECT_FORM_END effect_form_end()
14
#define EFFECT_ACTIVE_START effect_active_start()
15
#define EFFECT_ACTIVE_END effect_active_end()
16
#define EFFECT_VISITED_START effect_visited_start()
17
#define EFFECT_VISITED_END effect_visited_end()
18
#define EFFECT_MARK_START effect_mark_start()
19
#define EFFECT_MARK_END effect_mark_end()
33
#define EFFECT_ANCHOR_START_C setfcolor(anchor_color)
34
#define EFFECT_IMAGE_START_C setfcolor(image_color)
35
#define EFFECT_FORM_START_C setfcolor(form_color)
36
#define EFFECT_ACTIVE_START_C (setfcolor(active_color), underline())
37
#define EFFECT_VISITED_START_C setfcolor(visited_color)
39
#define EFFECT_MARK_START_C setbcolor(mark_color)
41
#define EFFECT_MARK_START_C standout()
44
#define EFFECT_IMAGE_END_C setfcolor(basic_color)
45
#define EFFECT_ANCHOR_END_C setfcolor(basic_color)
46
#define EFFECT_FORM_END_C setfcolor(basic_color)
47
#define EFFECT_ACTIVE_END_C (setfcolor(basic_color), underlineend())
48
#define EFFECT_VISITED_END_C setfcolor(basic_color)
50
#define EFFECT_MARK_END_C setbcolor(bg_color)
52
#define EFFECT_MARK_END_C standend()
55
#define EFFECT_ANCHOR_START_M underline()
56
#define EFFECT_ANCHOR_END_M underlineend()
57
#define EFFECT_IMAGE_START_M standout()
58
#define EFFECT_IMAGE_END_M standend()
59
#define EFFECT_FORM_START_M standout()
60
#define EFFECT_FORM_END_M standend()
61
#define EFFECT_ACTIVE_START_NC underline()
62
#define EFFECT_ACTIVE_END_NC underlineend()
63
#define EFFECT_ACTIVE_START_M bold()
64
#define EFFECT_ACTIVE_END_M boldend()
65
#define EFFECT_VISITED_START_M /**/
66
#define EFFECT_VISITED_END_M /**/
67
#define EFFECT_MARK_START_M standout()
68
#define EFFECT_MARK_END_M standend()
69
#define define_effect(name_start,name_end,color_start,color_end,mono_start,mono_end) \
70
static void name_start { if (useColor) { color_start; } else { mono_start; }}\
71
static void name_end { if (useColor) { color_end; } else { mono_end; }}
73
define_effect(EFFECT_ANCHOR_START, EFFECT_ANCHOR_END, EFFECT_ANCHOR_START_C,
74
EFFECT_ANCHOR_END_C, EFFECT_ANCHOR_START_M, EFFECT_ANCHOR_END_M)
75
define_effect(EFFECT_IMAGE_START, EFFECT_IMAGE_END, EFFECT_IMAGE_START_C,
76
EFFECT_IMAGE_END_C, EFFECT_IMAGE_START_M, EFFECT_IMAGE_END_M)
77
define_effect(EFFECT_FORM_START, EFFECT_FORM_END, EFFECT_FORM_START_C,
78
EFFECT_FORM_END_C, EFFECT_FORM_START_M, EFFECT_FORM_END_M)
79
define_effect(EFFECT_MARK_START, EFFECT_MARK_END, EFFECT_MARK_START_C,
80
EFFECT_MARK_END_C, EFFECT_MARK_START_M, EFFECT_MARK_END_M)
89
if(!getenv("WINDOWID"))
90
setfcolor(active_color);
94
EFFECT_ACTIVE_START_C;
97
EFFECT_ACTIVE_START_NC;
100
EFFECT_ACTIVE_START_M;
108
if (useActiveColor) {
111
EFFECT_ACTIVE_END_NC;
121
if (useVisitedColor) {
123
EFFECT_VISITED_START_C;
125
EFFECT_VISITED_START_M;
133
if (useVisitedColor) {
135
EFFECT_VISITED_END_C;
137
EFFECT_VISITED_END_M;
142
#else /* not USE_COLOR */
144
#define EFFECT_ANCHOR_START underline()
145
#define EFFECT_ANCHOR_END underlineend()
146
#define EFFECT_IMAGE_START standout()
147
#define EFFECT_IMAGE_END standend()
148
#define EFFECT_FORM_START standout()
149
#define EFFECT_FORM_END standend()
150
#define EFFECT_ACTIVE_START bold()
151
#define EFFECT_ACTIVE_END boldend()
152
#define EFFECT_VISITED_START /**/
153
#define EFFECT_VISITED_END /**/
154
#define EFFECT_MARK_START standout()
155
#define EFFECT_MARK_END standend()
156
#endif /* not USE_COLOR */
168
loadImage(NULL, IMG_FLAG_STOP);
173
#endif /* USE_MOUSE */
175
fmInitialized = FALSE;
181
* Initialize routine.
186
if (!fmInitialized) {
195
fmInitialized = TRUE;
199
* Display some lines.
201
static Line *cline = NULL;
202
static int ccolumn = -1;
204
static int ulmode = 0, somode = 0, bomode = 0;
205
static int anch_mode = 0, emph_mode = 0, imag_mode = 0, form_mode = 0,
206
active_mode = 0, visited_mode = 0, mark_mode = 0, graph_mode = 0;
207
#ifdef USE_ANSI_COLOR
208
static Linecolor color_mode = 0;
212
static Buffer *save_current_buf = NULL;
215
static char *delayed_msg = NULL;
217
static void drawAnchorCursor(Buffer *buf);
218
#define redrawBuffer(buf) redrawNLine(buf, LASTLINE)
219
static void redrawNLine(Buffer *buf, int n);
220
static Line *redrawLine(Buffer *buf, Line *l, int i);
222
static int image_touch = 0;
223
static int draw_image_flag = FALSE;
224
static Line *redrawLineImage(Buffer *buf, Line *l, int i);
226
static int redrawLineRegion(Buffer *buf, Line *l, int i, int bpos, int epos);
227
static void do_effects(Lineprop m);
228
#ifdef USE_ANSI_COLOR
229
static void do_color(Linecolor c);
233
make_lastline_link(Buffer *buf, char *title, char *url)
243
if (title && *title) {
244
s = Strnew_m_charp("[", title, "]", NULL);
245
for (p = s->ptr; *p; p++) {
246
if (IS_CNTRL(*p) || IS_SPACE(*p))
250
Strcat_charp(s, " ");
251
l -= get_Str_strwidth(s);
257
parseURL2(url, &pu, baseURL(buf));
258
u = parsedURL2Str(&pu);
260
u = Strnew_charp(url_unquote_conv(u->ptr, buf->document_charset));
262
u = checkType(u, &pr, NULL);
264
if (l <= 4 || l >= get_Str_strwidth(u)) {
271
s = Strnew_size(COLS);
274
while (i && pr[i] & PC_WCHAR2)
277
Strcat_charp_n(s, u->ptr, i);
278
Strcat_charp(s, "..");
279
i = get_Str_strwidth(u) - (COLS - 1 - get_Str_strwidth(s));
281
while (i < u->length && pr[i] & PC_WCHAR2)
284
Strcat_charp(s, &u->ptr[i]);
289
make_lastline_message(Buffer *buf)
296
MapArea *a = retrieveCurrentMapArea(buf);
298
s = make_lastline_link(buf, a->alt, a->url);
302
Anchor *a = retrieveCurrentAnchor(buf);
304
if (a && a->title && *a->title)
307
Anchor *a_img = retrieveCurrentImg(buf);
308
if (a_img && a_img->title && *a_img->title)
312
s = make_lastline_link(buf, p, a ? a->url : NULL);
315
sl = get_Str_strwidth(s);
322
if (use_mouse && mouse_action.lastline_str)
323
msg = Strnew_charp(mouse_action.lastline_str);
325
#endif /* not USE_MOUSE */
327
if (displayLineInfo && buf->currentLine != NULL && buf->lastLine != NULL) {
328
int cl = buf->currentLine->real_linenumber;
329
int ll = buf->lastLine->real_linenumber;
330
int r = (int)((double)cl * 100.0 / (double)(ll ? ll : 1) + 0.5);
331
Strcat(msg, Sprintf("%d/%d (%d%%)", cl, ll, r));
334
/* FIXME: gettextize? */
335
Strcat_charp(msg, "Viewing");
337
if (buf->ssl_certificate)
338
Strcat_charp(msg, "[SSL]");
340
Strcat_charp(msg, " <");
341
Strcat_charp(msg, buf->buffername);
344
int l = COLS - 3 - sl;
345
if (get_Str_strwidth(msg) > l) {
348
for (p = msg->ptr; *p; p += get_mclen(p)) {
357
Strcat_charp(msg, "> ");
361
Strcat_charp(msg, ">");
367
displayBuffer(Buffer *buf, int mode)
374
if (buf->topLine == NULL && readBufferCache(buf) == 0) { /* clear_buffer */
375
mode = B_FORCE_REDRAW;
379
buf->width = INIT_BUFFER_WIDTH;
380
if (buf->height == 0)
381
buf->height = LASTLINE + 1;
382
if ((buf->width != INIT_BUFFER_WIDTH &&
383
((buf->type && !strcmp(buf->type, "text/html")) || FoldLine))
384
|| buf->need_reshape) {
385
buf->need_reshape = TRUE;
389
if (buf->lastLine && buf->lastLine->real_linenumber > 0)
390
buf->rootX = (int)(log(buf->lastLine->real_linenumber + 0.1)
394
if (buf->rootX > COLS)
399
buf->COLS = COLS - buf->rootX;
402
|| mouse_action.menu_str
405
if (mode == B_FORCE_REDRAW || mode == B_REDRAW_IMAGE)
411
if (buf->rootY != ny || buf->LINES != LASTLINE - ny) {
413
buf->LINES = LASTLINE - ny;
415
mode = B_REDRAW_IMAGE;
417
if (mode == B_FORCE_REDRAW || mode == B_SCROLL || mode == B_REDRAW_IMAGE ||
418
cline != buf->topLine || ccolumn != buf->currentColumn) {
419
#ifdef USE_RAW_SCROLL
422
!(activeImage && displayImage && draw_image_flag) &&
424
mode == B_SCROLL && cline && buf->currentColumn == ccolumn) {
425
int n = buf->topLine->linenumber - cline->linenumber;
426
if (n > 0 && n < buf->LINES) {
432
else if (n < 0 && n > -buf->LINES) {
433
#if 0 /* defined(__CYGWIN__) */
434
move(LASTLINE + n + 1, 0);
437
#endif /* defined(__CYGWIN__) */
447
(mode == B_REDRAW_IMAGE ||
448
cline != buf->topLine || ccolumn != buf->currentColumn)) {
452
loadImage(buf, IMG_FLAG_STOP);
454
draw_image_flag = FALSE;
459
cline = buf->topLine;
460
ccolumn = buf->currentColumn;
462
if (buf->topLine == NULL)
463
buf->topLine = buf->firstLine;
466
if (buf->need_reshape) {
467
displayBuffer(buf, B_FORCE_REDRAW);
472
drawAnchorCursor(buf);
474
msg = make_lastline_message(buf);
475
if (buf->firstLine == NULL) {
476
/* FIXME: gettextize? */
477
Strcat_charp(msg, "\tNo Line");
479
if (delayed_msg != NULL) {
480
disp_message(delayed_msg, FALSE);
485
message(msg->ptr, buf->cursorX + buf->rootX, buf->cursorY + buf->rootY);
487
term_title(conv_to_system(buf->buffername));
490
if (activeImage && displayImage && buf->img) {
495
if (buf != save_current_buf) {
497
save_current_buf = buf;
503
drawAnchorCursor0(Buffer *buf, AnchorList *al, int hseq, int prevhseq,
504
int tline, int eline, int active)
511
for (j = 0; j < al->nanchor; j++) {
512
an = &al->anchors[j];
513
if (an->start.line < tline)
515
if (an->start.line >= eline)
517
for (;; l = l->next) {
520
if (l->linenumber == an->start.line)
523
if (hseq >= 0 && an->hseq == hseq) {
524
for (i = an->start.pos; i < an->end.pos; i++) {
525
if (l->propBuf[i] & (PE_IMAGE | PE_ANCHOR | PE_FORM)) {
527
l->propBuf[i] |= PE_ACTIVE;
529
l->propBuf[i] &= ~PE_ACTIVE;
533
redrawLineRegion(buf, l, l->linenumber - tline + buf->rootY,
534
an->start.pos, an->end.pos);
536
else if (prevhseq >= 0 && an->hseq == prevhseq) {
538
redrawLineRegion(buf, l, l->linenumber - tline + buf->rootY,
539
an->start.pos, an->end.pos);
545
drawAnchorCursor(Buffer *buf)
551
if (!buf->firstLine || !buf->hmarklist)
553
if (!buf->href && !buf->formitem)
556
an = retrieveCurrentAnchor(buf);
558
an = retrieveCurrentMap(buf);
563
tline = buf->topLine->linenumber;
564
eline = tline + buf->LINES;
565
prevhseq = buf->hmarklist->prevhseq;
568
drawAnchorCursor0(buf, buf->href, hseq, prevhseq, tline, eline, 1);
569
drawAnchorCursor0(buf, buf->href, hseq, -1, tline, eline, 0);
572
drawAnchorCursor0(buf, buf->formitem, hseq, prevhseq, tline, eline, 1);
573
drawAnchorCursor0(buf, buf->formitem, hseq, -1, tline, eline, 0);
575
buf->hmarklist->prevhseq = hseq;
579
redrawNLine(Buffer *buf, int n)
589
#endif /* USE_BG_COLOR */
591
#endif /* USE_COLOR */
594
|| mouse_action.menu_str
602
if (mouse_action.menu_str)
603
addstr(mouse_action.menu_str);
606
for (t = FirstTab; t; t = t->nextTab) {
611
l = t->x2 - t->x1 - 1 - get_strwidth(t->currentBuffer->buffername);
615
addnstr_sup(" ", l / 2);
618
addnstr(t->currentBuffer->buffername, t->x2 - t->x1 - l);
622
addnstr_sup(" ", (l + 1) / 2);
632
move(LastTab->y + 1, 0);
633
for (i = 0; i < COLS; i++)
636
for (i = 0, l = buf->topLine; i < buf->LINES; i++, l = l->next) {
637
if (i >= buf->LINES - n || i < -n)
638
l = redrawLine(buf, l, i + buf->rootY);
643
move(i + buf->rootY, 0);
648
if (!(activeImage && displayImage && buf->img))
650
move(buf->cursorY + buf->rootY, buf->cursorX + buf->rootX);
651
for (i = 0, l = buf->topLine; i < buf->LINES && l; i++, l = l->next) {
652
if (i >= buf->LINES - n || i < -n)
653
redrawLineImage(buf, l, i + buf->rootY);
660
redrawLine(Buffer *buf, Line *l, int i)
662
int j, pos, rcol, ncol, delta = 1;
663
int column = buf->currentColumn;
666
#ifdef USE_ANSI_COLOR
676
if (buf->pagerSource) {
677
l = getNextPage(buf, buf->LINES + buf->rootY - i);
688
if (buf->lastLine->real_linenumber > 0)
689
buf->rootX = (int)(log(buf->lastLine->real_linenumber + 0.1)
693
if (buf->rootX > COLS)
695
buf->COLS = COLS - buf->rootX;
697
if (l->real_linenumber && !l->bpos)
698
sprintf(tmp, "%*ld:", buf->rootX - 1, l->real_linenumber);
700
sprintf(tmp, "%*s ", buf->rootX - 1, "");
705
l->width = COLPOS(l, l->len);
706
if (l->len == 0 || l->width - 1 < column) {
710
/* need_clrtoeol(); */
711
pos = columnPos(l, column);
712
p = &(l->lineBuf[pos]);
713
pr = &(l->propBuf[pos]);
714
#ifdef USE_ANSI_COLOR
715
if (useColor && l->colorBuf)
716
pc = &(l->colorBuf[pos]);
720
rcol = COLPOS(l, pos);
722
for (j = 0; rcol - column < buf->COLS && pos + j < l->len; j += delta) {
724
if (useVisitedColor && vpos <= pos + j && !(pr[j] & PE_VISITED)) {
725
a = retrieveAnchor(buf->href, l->linenumber, pos + j);
727
parseURL2(a->url, &url, baseURL(buf));
728
if (getHashHist(URLHist, parsedURL2Str(&url)->ptr)) {
729
for (k = a->start.pos; k < a->end.pos; k++)
730
pr[k - pos] |= PE_VISITED;
737
delta = wtf_len((wc_uchar *) & p[j]);
739
ncol = COLPOS(l, pos + j + delta);
740
if (ncol - column > buf->COLS)
742
#ifdef USE_ANSI_COLOR
747
for (rcol = column; rcol < ncol; rcol++)
752
for (; rcol < ncol; rcol++)
757
addMChar(&p[j], pr[j], delta);
759
addChar(p[j], pr[j]);
794
visited_mode = FALSE;
809
#ifdef USE_ANSI_COLOR
813
if (rcol - column < buf->COLS)
820
redrawLineImage(Buffer *buf, Line *l, int i)
823
int column = buf->currentColumn;
825
int x, y, sx, sy, w, h;
830
l->width = COLPOS(l, l->len);
831
if (l->len == 0 || l->width - 1 < column)
833
pos = columnPos(l, column);
834
rcol = COLPOS(l, pos);
835
for (j = 0; rcol - column < buf->COLS && pos + j < l->len; j++) {
836
if (rcol - column < 0) {
837
rcol = COLPOS(l, pos + j + 1);
840
a = retrieveAnchor(buf->img, l->linenumber, pos + j);
841
if (a && a->image && a->image->touch < image_touch) {
842
Image *image = a->image;
845
cache = image->cache = getImage(image, baseURL(buf),
848
if ((image->width < 0 && cache->width > 0) ||
849
(image->height < 0 && cache->height > 0)) {
850
image->width = cache->width;
851
image->height = cache->height;
852
buf->need_reshape = TRUE;
854
x = (int)((rcol - column + buf->rootX) * pixel_per_char);
855
y = (int)(i * pixel_per_line);
856
sx = (int)((rcol - COLPOS(l, a->start.pos)) * pixel_per_char);
857
sy = (int)((l->linenumber - image->y) * pixel_per_line);
858
if (sx == 0 && x + image->xoffset >= 0)
861
sx -= image->xoffset;
862
if (sy == 0 && y + image->yoffset >= 0)
865
sy -= image->yoffset;
866
if (image->width > 0)
867
w = image->width - sx;
869
w = (int)(8 * pixel_per_char - sx);
870
if (image->height > 0)
871
h = image->height - sy;
873
h = (int)(pixel_per_line - sy);
874
if (w > (int)((buf->rootX + buf->COLS) * pixel_per_char - x))
875
w = (int)((buf->rootX + buf->COLS) * pixel_per_char - x);
876
if (h > (int)(LASTLINE * pixel_per_line - y))
877
h = (int)(LASTLINE * pixel_per_line - y);
878
addImage(cache, x, y, sx, sy, w, h);
879
image->touch = image_touch;
880
draw_image_flag = TRUE;
883
rcol = COLPOS(l, pos + j + 1);
890
redrawLineRegion(Buffer *buf, Line *l, int i, int bpos, int epos)
892
int j, pos, rcol, ncol, delta = 1;
893
int column = buf->currentColumn;
896
#ifdef USE_ANSI_COLOR
908
pos = columnPos(l, column);
909
p = &(l->lineBuf[pos]);
910
pr = &(l->propBuf[pos]);
911
#ifdef USE_ANSI_COLOR
912
if (useColor && l->colorBuf)
913
pc = &(l->colorBuf[pos]);
917
rcol = COLPOS(l, pos);
921
for (j = 0; rcol - column < buf->COLS && pos + j < l->len; j += delta) {
923
if (useVisitedColor && vpos <= pos + j && !(pr[j] & PE_VISITED)) {
924
a = retrieveAnchor(buf->href, l->linenumber, pos + j);
926
parseURL2(a->url, &url, baseURL(buf));
927
if (getHashHist(URLHist, parsedURL2Str(&url)->ptr)) {
928
for (k = a->start.pos; k < a->end.pos; k++)
929
pr[k - pos] |= PE_VISITED;
936
delta = wtf_len((wc_uchar *) & p[j]);
938
ncol = COLPOS(l, pos + j + delta);
939
if (ncol - column > buf->COLS)
941
#ifdef USE_ANSI_COLOR
945
if (j >= bcol && j < ecol) {
948
for (rcol = column; rcol < ncol; rcol++)
952
move(i, rcol - column + buf->rootX);
954
for (; rcol < ncol; rcol++)
959
addMChar(&p[j], pr[j], delta);
961
addChar(p[j], pr[j]);
996
visited_mode = FALSE;
1000
active_mode = FALSE;
1011
#ifdef USE_ANSI_COLOR
1015
return rcol - column;
1018
#define do_effect1(effect,modeflag,action_start,action_end) \
1026
#define do_effect2(effect,modeflag,action_start,action_end) \
1033
do_effects(Lineprop m)
1036
do_effect2(PE_UNDER, ulmode, underline(), underlineend());
1037
do_effect2(PE_STAND, somode, standout(), standend());
1038
do_effect2(PE_BOLD, bomode, bold(), boldend());
1039
do_effect2(PE_EMPH, emph_mode, bold(), boldend());
1040
do_effect2(PE_ANCHOR, anch_mode, EFFECT_ANCHOR_START, EFFECT_ANCHOR_END);
1041
do_effect2(PE_IMAGE, imag_mode, EFFECT_IMAGE_START, EFFECT_IMAGE_END);
1042
do_effect2(PE_FORM, form_mode, EFFECT_FORM_START, EFFECT_FORM_END);
1043
do_effect2(PE_VISITED, visited_mode, EFFECT_VISITED_START,
1044
EFFECT_VISITED_END);
1045
do_effect2(PE_ACTIVE, active_mode, EFFECT_ACTIVE_START, EFFECT_ACTIVE_END);
1046
do_effect2(PE_MARK, mark_mode, EFFECT_MARK_START, EFFECT_MARK_END);
1053
do_effect1(PE_UNDER, ulmode, underline(), underlineend());
1054
do_effect1(PE_STAND, somode, standout(), standend());
1055
do_effect1(PE_BOLD, bomode, bold(), boldend());
1056
do_effect1(PE_EMPH, emph_mode, bold(), boldend());
1057
do_effect1(PE_ANCHOR, anch_mode, EFFECT_ANCHOR_START, EFFECT_ANCHOR_END);
1058
do_effect1(PE_IMAGE, imag_mode, EFFECT_IMAGE_START, EFFECT_IMAGE_END);
1059
do_effect1(PE_FORM, form_mode, EFFECT_FORM_START, EFFECT_FORM_END);
1060
do_effect1(PE_VISITED, visited_mode, EFFECT_VISITED_START,
1061
EFFECT_VISITED_END);
1062
do_effect1(PE_ACTIVE, active_mode, EFFECT_ACTIVE_START, EFFECT_ACTIVE_END);
1063
do_effect1(PE_MARK, mark_mode, EFFECT_MARK_START, EFFECT_MARK_END);
1066
#ifdef USE_ANSI_COLOR
1068
do_color(Linecolor c)
1072
else if (color_mode & 0x8)
1073
setfcolor(basic_color);
1076
setbcolor((c >> 4) & 0x7);
1077
else if (color_mode & 0x80)
1078
setbcolor(bg_color);
1086
addChar(char c, Lineprop mode)
1088
addMChar(&c, mode, 1);
1092
addMChar(char *p, Lineprop mode, size_t len)
1095
addChar(char c, Lineprop mode)
1098
Lineprop m = CharEffect(mode);
1102
if (mode & PC_WCHAR2)
1106
if (mode & PC_SYMBOL) {
1109
int w = (mode & PC_KANJI) ? 2 : 1;
1111
c = ((char)wtf_get_code((wc_uchar *) p) & 0x7f) - SYMBOL_BASE;
1115
if (graph_ok() && c < N_GRAPH_SYMBOL) {
1121
if (w == 2 && WcOption.use_wide)
1122
addstr(graph2_symbol[(int)c]);
1125
addch(*graph_symbol[(int)c]);
1129
symbol = get_symbol(DisplayCharset, &w);
1130
addstr(symbol[(int)c]);
1132
symbol = get_symbol();
1133
addch(*symbol[(int)c]);
1137
else if (mode & PC_CTRL) {
1157
else if (mode & PC_UNKNOWN) {
1159
sprintf(buf, "[%.2X]",
1160
(unsigned char)wtf_get_code((wc_uchar *) p) | 0x80);
1166
else if (0x80 <= (unsigned char)c && (unsigned char)c <= NBSP_CODE)
1173
static GeneralList *message_list = NULL;
1176
record_err_message(char *s)
1178
if (fmInitialized) {
1180
message_list = newGeneralList();
1181
if (message_list->nitem >= LINES)
1182
popValue(message_list);
1183
pushValue(message_list, allocStr(s, -1));
1188
* List of error messages
1191
message_list_panel(void)
1193
Str tmp = Strnew_size(LINES * COLS);
1196
/* FIXME: gettextize? */
1198
"<html><head><title>List of error messages</title></head><body>"
1199
"<h1>List of error messages</h1><table cellpadding=0>\n");
1201
for (p = message_list->last; p; p = p->prev)
1202
Strcat_m_charp(tmp, "<tr><td><pre>", html_quote(p->ptr),
1203
"</pre></td></tr>\n", NULL);
1205
Strcat_charp(tmp, "<tr><td>(no message recorded)</td></tr>\n");
1206
Strcat_charp(tmp, "</table></body></html>");
1207
return loadHTMLString(tmp);
1211
message(char *s, int return_x, int return_y)
1216
addnstr(s, COLS - 1);
1218
move(return_y, return_x);
1222
disp_err_message(char *s, int redraw_current)
1224
record_err_message(s);
1225
disp_message(s, redraw_current);
1229
disp_message_nsec(char *s, int redraw_current, int sec, int purge, int mouse)
1233
if (!fmInitialized) {
1234
fprintf(stderr, "%s\n", conv_to_system(s));
1237
if (CurrentTab != NULL && Currentbuf != NULL)
1238
message(s, Currentbuf->cursorX + Currentbuf->rootX,
1239
Currentbuf->cursorY + Currentbuf->rootY);
1241
message(s, LASTLINE, 0);
1244
if (mouse && use_mouse)
1247
sleep_till_anykey(sec, purge);
1249
if (mouse && use_mouse)
1252
if (CurrentTab != NULL && Currentbuf != NULL && redraw_current)
1253
displayBuffer(Currentbuf, B_NORMAL);
1257
disp_message(char *s, int redraw_current)
1259
disp_message_nsec(s, redraw_current, 10, FALSE, TRUE);
1263
disp_message_nomouse(char *s, int redraw_current)
1265
disp_message_nsec(s, redraw_current, 10, FALSE, FALSE);
1270
set_delayed_message(char *s)
1272
delayed_msg = allocStr(s, -1);
1276
cursorUp0(Buffer *buf, int n)
1278
if (buf->cursorY > 0)
1279
cursorUpDown(buf, -1);
1281
buf->topLine = lineSkip(buf, buf->topLine, -n, FALSE);
1282
if (buf->currentLine->prev != NULL)
1283
buf->currentLine = buf->currentLine->prev;
1289
cursorUp(Buffer *buf, int n)
1291
Line *l = buf->currentLine;
1292
if (buf->firstLine == NULL)
1294
while (buf->currentLine->prev && buf->currentLine->bpos)
1296
if (buf->currentLine == buf->firstLine) {
1297
gotoLine(buf, l->linenumber);
1302
while (buf->currentLine->prev && buf->currentLine->bpos &&
1303
buf->currentLine->bwidth >= buf->currentColumn + buf->visualpos)
1308
cursorDown0(Buffer *buf, int n)
1310
if (buf->cursorY < buf->LINES - 1)
1311
cursorUpDown(buf, 1);
1313
buf->topLine = lineSkip(buf, buf->topLine, n, FALSE);
1314
if (buf->currentLine->next != NULL)
1315
buf->currentLine = buf->currentLine->next;
1321
cursorDown(Buffer *buf, int n)
1323
Line *l = buf->currentLine;
1324
if (buf->firstLine == NULL)
1326
while (buf->currentLine->next && buf->currentLine->next->bpos)
1327
cursorDown0(buf, n);
1328
if (buf->currentLine == buf->lastLine) {
1329
gotoLine(buf, l->linenumber);
1333
cursorDown0(buf, n);
1334
while (buf->currentLine->next && buf->currentLine->next->bpos &&
1335
buf->currentLine->bwidth + buf->currentLine->width <
1336
buf->currentColumn + buf->visualpos)
1337
cursorDown0(buf, n);
1341
cursorUpDown(Buffer *buf, int n)
1343
Line *cl = buf->currentLine;
1345
if (buf->firstLine == NULL)
1347
if ((buf->currentLine = currentLineSkip(buf, cl, n, FALSE)) == cl)
1353
cursorRight(Buffer *buf, int n)
1355
int i, delta = 1, cpos, vpos2;
1356
Line *l = buf->currentLine;
1359
if (buf->firstLine == NULL)
1361
if (buf->pos == l->len && !(l->next && l->next->bpos))
1366
while (i + delta < l->len && p[i + delta] & PC_WCHAR2)
1369
if (i + delta < l->len) {
1370
buf->pos = i + delta;
1372
else if (l->len == 0) {
1375
else if (l->next && l->next->bpos) {
1376
cursorDown0(buf, 1);
1382
buf->pos = l->len - 1;
1384
while (buf->pos && p[buf->pos] & PC_WCHAR2)
1388
cpos = COLPOS(l, buf->pos);
1389
buf->visualpos = l->bwidth + cpos - buf->currentColumn;
1392
while (buf->pos + delta < l->len && p[buf->pos + delta] & PC_WCHAR2)
1395
vpos2 = COLPOS(l, buf->pos + delta) - buf->currentColumn - 1;
1396
if (vpos2 >= buf->COLS && n) {
1397
columnSkip(buf, n + (vpos2 - buf->COLS) - (vpos2 - buf->COLS) % n);
1398
buf->visualpos = l->bwidth + cpos - buf->currentColumn;
1400
buf->cursorX = buf->visualpos - l->bwidth;
1404
cursorLeft(Buffer *buf, int n)
1406
int i, delta = 1, cpos;
1407
Line *l = buf->currentLine;
1410
if (buf->firstLine == NULL)
1415
while (i - delta > 0 && p[i - delta] & PC_WCHAR2)
1419
buf->pos = i - delta;
1420
else if (l->prev && l->bpos) {
1422
buf->pos = buf->currentLine->len - 1;
1428
cpos = COLPOS(l, buf->pos);
1429
buf->visualpos = l->bwidth + cpos - buf->currentColumn;
1430
if (buf->visualpos - l->bwidth < 0 && n) {
1432
-n + buf->visualpos - l->bwidth - (buf->visualpos -
1434
buf->visualpos = l->bwidth + cpos - buf->currentColumn;
1436
buf->cursorX = buf->visualpos - l->bwidth;
1440
cursorHome(Buffer *buf)
1443
buf->cursorX = buf->cursorY = 0;
1448
* Arrange line,column and cursor position according to current line and
1452
arrangeCursor(Buffer *buf)
1456
if (buf == NULL || buf->currentLine == NULL)
1459
if (buf->currentLine->linenumber - buf->topLine->linenumber >= buf->LINES
1460
|| buf->currentLine->linenumber < buf->topLine->linenumber) {
1462
* buf->topLine = buf->currentLine;
1464
buf->topLine = lineSkip(buf, buf->currentLine, 0, FALSE);
1466
/* Arrange column */
1467
while (buf->pos < 0 && buf->currentLine->prev && buf->currentLine->bpos) {
1468
pos = buf->pos + buf->currentLine->prev->len;
1472
while (buf->pos >= buf->currentLine->len && buf->currentLine->next &&
1473
buf->currentLine->next->bpos) {
1474
pos = buf->pos - buf->currentLine->len;
1475
cursorDown0(buf, 1);
1478
if (buf->currentLine->len == 0 || buf->pos < 0)
1480
else if (buf->pos >= buf->currentLine->len)
1481
buf->pos = buf->currentLine->len - 1;
1483
while (buf->pos > 0 && buf->currentLine->propBuf[buf->pos] & PC_WCHAR2)
1486
col = COLPOS(buf->currentLine, buf->pos);
1488
while (buf->pos + delta < buf->currentLine->len &&
1489
buf->currentLine->propBuf[buf->pos + delta] & PC_WCHAR2)
1492
col2 = COLPOS(buf->currentLine, buf->pos + delta);
1493
if (col < buf->currentColumn || col2 > buf->COLS + buf->currentColumn) {
1494
buf->currentColumn = 0;
1495
if (col2 > buf->COLS)
1496
columnSkip(buf, col);
1498
/* Arrange cursor */
1499
buf->cursorY = buf->currentLine->linenumber - buf->topLine->linenumber;
1500
buf->visualpos = buf->currentLine->bwidth +
1501
COLPOS(buf->currentLine, buf->pos) - buf->currentColumn;
1502
buf->cursorX = buf->visualpos - buf->currentLine->bwidth;
1503
#ifdef DISPLAY_DEBUG
1505
"arrangeCursor: column=%d, cursorX=%d, visualpos=%d, pos=%d, len=%d\n",
1506
buf->currentColumn, buf->cursorX, buf->visualpos, buf->pos,
1507
buf->currentLine->len);
1512
arrangeLine(Buffer *buf)
1516
if (buf->firstLine == NULL)
1518
buf->cursorY = buf->currentLine->linenumber - buf->topLine->linenumber;
1519
i = columnPos(buf->currentLine, buf->currentColumn + buf->visualpos
1520
- buf->currentLine->bwidth);
1521
cpos = COLPOS(buf->currentLine, i) - buf->currentColumn;
1523
buf->cursorX = cpos;
1526
else if (buf->currentLine->len > i) {
1534
#ifdef DISPLAY_DEBUG
1536
"arrangeLine: column=%d, cursorX=%d, visualpos=%d, pos=%d, len=%d\n",
1537
buf->currentColumn, buf->cursorX, buf->visualpos, buf->pos,
1538
buf->currentLine->len);
1543
cursorXY(Buffer *buf, int x, int y)
1547
cursorUpDown(buf, y - buf->cursorY);
1549
if (buf->cursorX > x) {
1550
while (buf->cursorX > x)
1551
cursorLeft(buf, buf->COLS / 2);
1553
else if (buf->cursorX < x) {
1554
while (buf->cursorX < x) {
1555
oldX = buf->cursorX;
1557
cursorRight(buf, buf->COLS / 2);
1559
if (oldX == buf->cursorX)
1562
if (buf->cursorX > x)
1563
cursorLeft(buf, buf->COLS / 2);
1568
restorePosition(Buffer *buf, Buffer *orig)
1570
buf->topLine = lineSkip(buf, buf->firstLine, TOP_LINENUMBER(orig) - 1,
1572
gotoLine(buf, CUR_LINENUMBER(orig));
1573
buf->pos = orig->pos;
1574
if (buf->currentLine && orig->currentLine)
1575
buf->pos += orig->currentLine->bpos - buf->currentLine->bpos;
1576
buf->currentColumn = orig->currentColumn;
1580
/* Local Variables: */
1581
/* c-basic-offset: 4 */