📄 view.c
字号:
for (; y < l->pos[0].y + yp - vy + form->rows; y++) { for (i = 0; i < form->cols; i++) { if (x+i >= xp && y >= yp && x+i < xp+xw && y < yp+yw) set_only_char(t, x+i, y, '_'); } } mem_free(lnx); break; case FC_CHECKBOX: if (l->n < 2) break; x = l->pos[1].x + xp - vx; y = l->pos[1].y + yp - vy; if (x >= xp && y >= yp && x < xp+xw && y < yp+yw) set_only_char(t, x, y, fs->state ? 'X' : ' '); break; case FC_RADIO: if (l->n < 2) break; x = l->pos[1].x + xp - vx; y = l->pos[1].y + yp - vy; if (x >= xp && y >= yp && x < xp+xw && y < yp+yw) set_only_char(t, x, y, fs->state ? 'X' : ' '); break; case FC_SELECT: fixup_select_state(form, fs); s = fs->state < form->nvalues ? form->labels[fs->state] : (unsigned char *)""; sl = s ? strlen(s) : 0; for (i = 0; i < l->n; i++) { x = l->pos[i].x + xp - vx; y = l->pos[i].y + yp - vy; if (x >= xp && y >= yp && x < xp+xw && y < yp+yw) set_only_char(t, x, y, i < sl ? s[i] : '_'); } break; case FC_SUBMIT: case FC_IMAGE: case FC_RESET: case FC_HIDDEN: case FC_BUTTON: break; }}struct xdfe { struct f_data_c *f; struct link *l;};/* prototypes */void y_draw_form_entry(struct terminal *, struct xdfe *);void y_draw_form_entry(struct terminal *t, struct xdfe *x){ draw_form_entry(t, x->f, x->l);}void x_draw_form_entry(struct session *ses, struct f_data_c *f, struct link *l){ struct xdfe x; x.f = f, x.l = l; draw_to_window(ses->win, (void (*)(struct terminal *, void *))y_draw_form_entry, &x);}void draw_forms(struct terminal *t, struct f_data_c *f){ struct link *l1 = get_first_link(f); struct link *l2 = get_last_link(f); if (!l1 || !l2) { if (l1 || l2) internal("get_first_link == %p, get_last_link == %p", l1, l2); return; } do { if (l1->type != L_LINK) draw_form_entry(t, f, l1); } while (l1++ < l2);}/* 0 -> 1 <- 2 v 3 ^ */unsigned char fr_trans[2][4] = {{0xb3, 0xc3, 0xb4, 0xc5}, {0xc4, 0xc2, 0xc1, 0xc5}};void set_xchar(struct terminal *t, int x, int y, unsigned dir){ unsigned c; if (x < 0 || x >= t->x || y < 0 || y >= t->y) return; c = get_char(t, x, y); if (!(c & ATTR_FRAME)) return; c &= 0xff; if (c == fr_trans[dir / 2][0]) set_only_char(t, x, y, fr_trans[dir / 2][1 + (dir & 1)] | ATTR_FRAME); else if (c == fr_trans[dir / 2][2 - (dir & 1)]) set_only_char(t, x, y, fr_trans[dir / 2][3] | ATTR_FRAME);}void draw_frame_lines(struct terminal *t, struct frameset_desc *fsd, int xp, int yp){ int i, j; int x, y; if (!fsd) return; y = yp - 1; for (j = 0; j < fsd->y; j++) { int wwy = fsd->f[j * fsd->x].yw; x = xp - 1; for (i = 0; i < fsd->x; i++) { int wwx = fsd->f[i].xw; if (i) { fill_area(t, x, y + 1, 1, wwy, 179 | ATTR_FRAME); if (j == fsd->y - 1) set_xchar(t, x, y + wwy + 1, 3); } else if (j) set_xchar(t, x, y, 0); if (j) { fill_area(t, x + 1, y, wwx, 1, 196 | ATTR_FRAME); if (i == fsd->x - 1) set_xchar(t, x + wwx + 1, y, 1); } else if (i) set_xchar(t, x, y, 2); if (i && j) set_char(t, x, y, 197 | ATTR_FRAME); /*if (fsd->f[j * fsd->x + i].subframe) { draw_frame_lines(t, fsd->f[j * fsd->x + i].subframe, x + 1, y + 1); }*/ x += wwx + 1; } y += wwy + 1; }}void set_brl_cursor(struct terminal *t, struct f_data_c *scr){ set_cursor(t, scr->xp + scr->vs->brl_x - scr->vs->view_posx, scr->yp + scr->vs->brl_y - scr->vs->view_pos, scr->xp + scr->vs->brl_x - scr->vs->view_posx, scr->yp + scr->vs->brl_y - scr->vs->view_pos); set_window_ptr(scr->ses->win, scr->xp + scr->vs->brl_x - scr->vs->view_posx, scr->yp + scr->vs->brl_y - scr->vs->view_pos);}void draw_doc(struct terminal *t, struct f_data_c *scr){ int active = scr->active; int y; int xp = scr->xp; int yp = scr->yp; int xw = scr->xw; int yw = scr->yw; struct view_state *vs; int vx, vy; if (!scr->vs || !scr->f_data) { if (!F) { if (active) { if (!scr->parent) set_cursor(t, 0, 0, 0, 0); else set_cursor(t, xp, yp, xp, yp); } fill_area(t, xp, yp, xw, yw, ' ');#ifdef G } else { long color = dip_get_color_sRGB(0x808080); drv->fill_area(t->dev, xp, yp, xp + xw, yp + yw, color);#endif } if (active) set_window_ptr(scr->ses->win, xp, yp); return; } if (active) { if (!F) { if (!t->spec->braille) { set_cursor(t, xp + xw - 1, yp + yw - 1, xp + xw - 1, yp + yw - 1); set_window_ptr(scr->ses->win, xp, yp); } else { set_brl_cursor(t, scr); } } } check_vs(scr); if (scr->f_data->frame_desc) { struct f_data_c *f; int n; if (!F) { fill_area(t, xp, yp, xw, yw, scr->f_data->y ? scr->f_data->bg : ' '); draw_frame_lines(t, scr->f_data->frame_desc, xp, yp); } n = 0; foreach(f, scr->subframes) { f->active = active && n++ == scr->vs->frame_pos; draw_doc(t, f); } return; } vs = scr->vs; if (scr->goto_position && (vy = find_tag(scr->f_data, scr->goto_position)) != -1) { if (vy > scr->f_data->y) vy = scr->f_data->y - 1; if (vy < 0) vy = 0; vs->view_pos = vy; vs->orig_view_pos = vy; vs->view_posx = 0; vs->orig_view_posx = 0; if (t->spec->braille) { vs->brl_y = vy; vs->brl_x = 0; vs->orig_brl_y = vy; vs->orig_brl_x = 0; } if (!F) set_link(scr); if (scr->went_to_position) mem_free(scr->went_to_position); scr->went_to_position = scr->goto_position; scr->goto_position = NULL; if (t->spec->braille) set_brl_cursor(t, scr); } if (vs->view_pos != vs->orig_view_pos || vs->view_posx != vs->orig_view_posx || vs->current_link != vs->orig_link || (t->spec->braille && (vs->brl_x != vs->orig_brl_x || vs->brl_y != vs->orig_brl_y))) { int ol; vs->view_pos = vs->orig_view_pos; vs->view_posx = vs->orig_view_posx; vs->brl_x = vs->orig_brl_x; vs->brl_y = vs->orig_brl_y; ol = vs->orig_link; if (ol < scr->f_data->nlinks) vs->current_link = ol; if (!F && !t->spec->braille) set_link(scr); check_vs(scr); if (!t->spec->braille) { vs->orig_link = ol; } else { vs->orig_link = vs->current_link; set_brl_cursor(t, scr); } } if (!F) { vx = vs->view_posx; vy = vs->view_pos; if (scr->xl == vx && scr->yl == vy && scr->xl != -1 && !scr->ses->search_word) { clear_link(t, scr); draw_forms(t, scr); if (active) draw_current_link(t, scr); return; } free_link(scr); scr->xl = vx; scr->yl = vy; fill_area(t, xp, yp, xw, yw, scr->f_data->y ? scr->f_data->bg : ' '); if (!scr->f_data->y) return; while (vs->view_pos >= scr->f_data->y) vs->view_pos -= yw ? yw : 1; if (vs->view_pos < 0) vs->view_pos = 0; if (vy != vs->view_pos) vy = vs->view_pos, check_vs(scr); for (y = vy <= 0 ? 0 : vy; y < (-vy + scr->f_data->y <= yw ? scr->f_data->y : yw + vy); y++) { int st = vx <= 0 ? 0 : vx; int en = -vx + scr->f_data->data[y].l <= xw ? scr->f_data->data[y].l : xw + vx; set_line(t, xp + st - vx, yp + y - vy, en - st, &scr->f_data->data[y].d[st]); } draw_forms(t, scr); if (active) draw_current_link(t, scr); if (scr->ses->search_word) scr->xl = scr->yl = -1;#ifdef G } else { draw_graphical_doc(t, scr, active);#endif }}void clr_xl(struct f_data_c *fd){ struct f_data_c *fdd; fd->xl = fd->yl = -1; foreach(fdd, fd->subframes) clr_xl(fdd);}void draw_doc_c(struct terminal *t, struct f_data_c *scr){ clr_xl(scr);#ifdef G if (F) if (scr == scr->ses->screen) draw_title(scr);#endif draw_doc(t, scr);}void draw_formatted(struct session *ses){ /*clr_xl(ses->screen);*/ ses->screen->active = 1; draw_to_window(ses->win, (void (*)(struct terminal *, void *))draw_doc_c, ses->screen); change_screen_status(ses); print_screen_status(ses);}int is_active_frame(struct session *ses, struct f_data_c *f);void draw_fd(struct f_data_c *f){ if (f->f_data) f->f_data->time_to_draw = -get_time(); f->active = is_active_frame(f->ses, f); draw_to_window(f->ses->win, (void (*)(struct terminal *, void *))draw_doc_c, f); change_screen_status(f->ses); print_screen_status(f->ses); if (f->f_data) f->f_data->time_to_draw += get_time();}void draw_fd_nrd(struct f_data_c *f){ f->active = is_active_frame(f->ses, f); draw_to_window(f->ses->win, (void (*)(struct terminal *, void *))draw_doc, f); change_screen_status(f->ses); print_screen_status(f->ses);}#define D_BUF 65536extern unsigned char frame_dumb[];int dump_to_file(struct f_data *fd, int h){ int x, y; unsigned char *buf; int bptr = 0; buf = mem_alloc(D_BUF); for (y = 0; y < fd->y; y++) for (x = 0; x <= fd->data[y].l; x++) { int c; if (x == fd->data[y].l) c = '\n'; else { if (((c = fd->data[y].d[x]) & 0xff) == 1) c += ' ' - 1; if ((c >> 15) && (c & 0xff) >= 176 && (c & 0xff) < 224) c = frame_dumb[(c & 0xff) - 176]; } buf[bptr++] = c; if (bptr >= D_BUF) { if (hard_write(h, buf, bptr) != bptr) goto fail; bptr = 0; } } if (hard_write(h, buf, bptr) != bptr) { fail: mem_free(buf); return -1; } mem_free(buf); if (fd->opt.num_links && fd->nlinks) { static char head[] = "\nLinks:\n"; int i; if ((int)hard_write(h, head, strlen(head)) != (int)strlen(head)) return -1; for (i = 0; i < fd->nlinks; i++) { struct link *lnk = &fd->links[i]; unsigned char *s = init_str(); int l = 0; add_num_to_str(&s, &l, i + 1); add_to_str(&s, &l, ". "); if (lnk->where) { add_to_str(&s, &l, lnk->where); } else if (lnk->where_img) { add_to_str(&s, &l, "Image: "); add_to_str(&s, &l, lnk->where_img); } else if (lnk->type == L_BUTTON) { struct form_control *fc = lnk->form; if (fc->type == FC_RESET) add_to_str(&s, &l, "Reset form"); else if (fc->type == FC_BUTTON || !fc->action) add_to_str(&s, &l, "Button"); else { if (!fc->method == FM_GET) add_to_str(&s, &l, "Submit form: "); else add_to_str(&s, &l, "Post form: "); add_to_str(&s, &l, fc->action); } } else if (lnk->type == L_CHECKBOX || lnk->type == L_SELECT || lnk->type == L_FIELD || lnk->type == L_AREA) { struct form_control *fc = lnk->form; if (fc->type == FC_RADIO) add_to_str(&s, &l, "Radio button"); else if (fc->type == FC_CHECKBOX) add_to_str(&s, &l, "Checkbox"); else if (fc->type == FC_SELECT) add_to_str(&s, &l, "Select field"); else if (fc->type == FC_TEXT) add_to_str(&s, &l, "Text field"); else if (fc->type == FC_TEXTAREA) add_to_str(&s, &l, "Text area"); else if (fc->type == FC_FILE) add_to_str(&s, &l, "File upload"); else if (fc->type == FC_PASSWORD) add_to_str(&s, &l, "Password field"); else goto unknown; if (fc->name && fc->name[0]) add_to_str(&s, &l, ", Name "), add_to_str(&s, &l, fc->name); if ((fc->type == FC_CHECKBOX || fc->type == FC_RADIO) && fc->default_value && fc->default_value[0]) add_to_str(&s, &l, ", Value "), add_to_str(&s, &l, fc->default_value); } unknown: add_to_str(&s, &l, "\n"); if (hard_write(h, s, l) != l) { mem_free(s); return -1; } mem_free(s); } } return 0;}int in_viewx(struct f_data_c *f, struct link *l){ int i; for (i = 0; i < l->n; i++) { if (l->pos[i].x >= f->vs->view_posx && l->pos[i].x < f->vs->view_posx + f->xw) return 1; } return 0;}int in_viewy(struct f_data_c *f, struct link *l){ int i; for (i = 0; i < l->n; i++) { if (l->pos[i].y >= f->vs->view_pos && l->pos[i].y < f->vs->view_pos + f->yw) return 1; } return 0;}int in_view(struct f_data_c *f, struct link *l){ return in_viewy(f, l) && in_viewx(f, l);}static inline int c_in_view(struct f_data_c *f){ return f->vs->current_link != -1 && in_view(f, &f->f_data->links[f->vs->current_link]);}int next_in_view(struct f_data_c *f, int p, int d, int (*fn)(struct f_data_c *, struct link *), void (*cntr)(struct f_data_c *, struct link *)){ int p1 = f->f_data->nlinks - 1; int p2 = 0; int y; int yl = f->vs->view_pos + f->yw; if (yl > f->f_data->y) yl = f->f_data->y; for (y = f->vs->view_pos < 0 ? 0 : f->vs->view_pos; y < yl; y++) { if (f->f_data->lines1[y] && f->f_data->lines1[y] - f->f_data->links < p1) p1 = f->f_data->lines1[y] - f->f_data->links; if (f->f_data->lines2[y] && f->f_data->lines2[y] - f->f_data->links > p2) p2 = f->f_data->lines2[y] - f->f_data->links; } /*while (p >= 0 && p < f->f_data->nlinks) {*/ while (p >= p1 && p <= p2) { if (fn(f, &f->f_data->links[p])) { f->vs->current_link = p; f->vs->orig_link = f->vs->current_link; if (cntr) cntr(f, &f->f_data->links[p]); return 1; } p += d; } f->vs->current_link = -1; f->vs->orig_link = f->vs->current_link; return 0;}void set_pos_x(struct f_data_c *f, struct link *l){ int i; int xm = 0; int xl = MAXINT; for (i = 0; i < l->n; i++) { if (l->pos[i].y >= f->vs->view_pos && l->pos[i].y < f->vs->view_pos + f->yw) { if (l->pos[i].x >= xm) xm = l->pos[i].x + 1; if (l->pos[i].x < xl) xl = l->pos[i].x; } } if (xl == MAXINT) return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -