⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 view_gr.c

📁 ELinks is an advanced and well-established feature-rich text mode web (HTTP/FTP/..) browser. ELinks
💻 C
📖 第 1 页 / 共 4 页
字号:
	l1 = g_find_line((struct g_object **)(void *)&a->lines, a->n_lines, y1);	l2 = g_find_line((struct g_object **)(void *)&a->lines, a->n_lines, y2);	root_x = xx, root_y = yy;	if (!l1) {		if (y1 > a->yw) return;		else l1 = (struct g_object **)&a->lines[0];	}	if (!l2) {		if (y2 < 0) return;		else l2 = (struct g_object **)&a->lines[a->n_lines - 1];	}	for (i = l1; i <= l2; i++) {		struct g_object *o = *i;		o->draw(fd, o, xx + o->x, yy + o->y);	}	/* !!! FIXME: floating objects */	root_x = rx, root_y = ry;}void g_area_destruct(struct g_object_area *a){	int i;	g_release_background(a->bg);	for (i = 0; i < a->n_lfo; i++) a->lfo[i]->destruct(a->lfo[i]);	mem_free(a->lfo);	for (i = 0; i < a->n_rfo; i++) a->rfo[i]->destruct(a->rfo[i]);	mem_free(a->rfo);	for (i = 0; i < a->n_lines; i++) a->lines[i]->destruct(a->lines[i]);	mem_free(a);}void g_area_get_list(struct g_object_area *a, void (*f)(struct g_object *parent, struct g_object *child)){	int i;	for (i = 0; i < a->n_lfo; i++) f((struct g_object *)a, a->lfo[i]);	for (i = 0; i < a->n_rfo; i++) f((struct g_object *)a, a->rfo[i]);	for (i = 0; i < a->n_lines; i++) f((struct g_object *)a, (struct g_object *)a->lines[i]);}/* * dsize - size of scrollbar * total - total data * vsize - visible data * vpos - position of visible data */void get_scrollbar_pos(int dsize, int total, int vsize, int vpos, int *start, int *end){	int ssize;	if (!total) {		*start = *end = 0;		return;	}	ssize = (double)dsize * vsize / total;	if (ssize < G_SCROLL_BAR_MIN_SIZE) ssize = G_SCROLL_BAR_MIN_SIZE;	if (total == vsize) {		*start = 0; *end = dsize;		return;	}	*start = (double)(dsize - ssize) * vpos / (total - vsize);	*end = *start + ssize;	if (*start > dsize) *start = dsize;	if (*start < 0) *start = 0;	if (*end > dsize) *end = dsize;	if (*end < 0) *end = 0;	/*	else {		*start = (double)vpos * dsize / total;		*end = (double)(vpos + vsize) * dsize / total;	}	if (*end > dsize) *end = dsize;	*/}long scroll_bar_frame_color;long scroll_bar_area_color;long scroll_bar_bar_color;void draw_vscroll_bar(struct graphics_device *dev, int x, int y, int yw, int total, int view, int pos){	int spos, epos;	drv->draw_hline(dev, x, y, x + G_SCROLL_BAR_WIDTH, scroll_bar_frame_color);	drv->draw_vline(dev, x, y, y + yw, scroll_bar_frame_color);	drv->draw_vline(dev, x + G_SCROLL_BAR_WIDTH - 1, y, y + yw, scroll_bar_frame_color);	drv->draw_hline(dev, x, y + yw - 1, x + G_SCROLL_BAR_WIDTH, scroll_bar_frame_color);	drv->draw_vline(dev, x + 1, y + 1, y + yw - 1, scroll_bar_area_color);	drv->draw_vline(dev, x + G_SCROLL_BAR_WIDTH - 2, y + 1, y + yw - 1, scroll_bar_area_color);	get_scrollbar_pos(yw - 4, total, view, pos, &spos, &epos);	drv->fill_area(dev, x + 2, y + 1, x + G_SCROLL_BAR_WIDTH - 2, y + 2 + spos, scroll_bar_area_color);	drv->fill_area(dev, x + 2, y + 2 + spos, x + G_SCROLL_BAR_WIDTH - 2, y + 2 + epos, scroll_bar_bar_color);	drv->fill_area(dev, x + 2, y + 2 + epos, x + G_SCROLL_BAR_WIDTH - 2, y + yw - 1, scroll_bar_area_color);}void draw_hscroll_bar(struct graphics_device *dev, int x, int y, int xw, int total, int view, int pos){	int spos, epos;	drv->draw_vline(dev, x, y, y + G_SCROLL_BAR_WIDTH, scroll_bar_frame_color);	drv->draw_hline(dev, x, y, x + xw, scroll_bar_frame_color);	drv->draw_hline(dev, x, y + G_SCROLL_BAR_WIDTH - 1, x + xw, scroll_bar_frame_color);	drv->draw_vline(dev, x + xw - 1, y, y + G_SCROLL_BAR_WIDTH, scroll_bar_frame_color);	drv->draw_hline(dev, x + 1, y + 1, x + xw - 1, scroll_bar_area_color);	drv->draw_hline(dev, x + 1, y + G_SCROLL_BAR_WIDTH - 2, x + xw - 1, scroll_bar_area_color);	get_scrollbar_pos(xw - 4, total, view, pos, &spos, &epos);	drv->fill_area(dev, x + 1, y + 2, x + 2 + spos, y + G_SCROLL_BAR_WIDTH - 2, scroll_bar_area_color);	drv->fill_area(dev, x + 2 + spos, y + 2, x + 2 + epos, y + G_SCROLL_BAR_WIDTH - 2, scroll_bar_bar_color);	drv->fill_area(dev, x + 2 + epos, y + 2, x + xw - 1, y + G_SCROLL_BAR_WIDTH - 2, scroll_bar_area_color);}void g_get_search(struct f_data *f, unsigned char *s){	int i;	if (!s || !*s) return;	if (f->last_search && !strcmp(f->last_search, s)) return;	mem_free(f->search_positions);	mem_free(f->search_lengths);	f->search_positions = DUMMY, f->search_lengths = DUMMY, f->n_search_positions = 0;	if (f->last_search) mem_free(f->last_search);	if (!(f->last_search = stracpy(s))) return;	for (i = 0; i < f->srch_string_size; i++) {		int len;		/*debug("%d: %d", i, f->srch_string[i]);*/		if ((s[0] | f->srch_string[i]) < 0x80) {			if ((f->srch_string[i] ^ s[0]) & 0xdf) continue;			if (s[1] != 0 && (s[1] ^ f->srch_string[i + 1]) < 0x80) {				if ((f->srch_string[i + 1] ^ s[1]) & 0xdf) continue;			}		}		len = compare_case_utf8(f->srch_string + i, s);		if (!len) continue;		if (!(f->n_search_positions & (ALLOC_GR - 1))) {			if ((unsigned)f->n_search_positions > MAXINT / sizeof(int) - ALLOC_GR) overalloc();			f->search_positions = mem_realloc(f->search_positions, (f->n_search_positions + ALLOC_GR) * sizeof(int));			f->search_lengths = mem_realloc(f->search_lengths, (f->n_search_positions + ALLOC_GR) * sizeof(int));		}		f->search_positions[f->n_search_positions] = i;		f->search_lengths[f->n_search_positions] = len;		f->n_search_positions++;	}}void draw_graphical_doc(struct terminal *t, struct f_data_c *scr, int active){	int r = 0;	struct rect old;	struct view_state *vs = scr->vs;	struct rect_set *rs;	int xw = scr->xw;	int yw = scr->yw;	int vx, vy;	if (active) {		if (scr->ses->search_word && scr->ses->search_word[0]) {			g_get_search_data(scr->f_data);			g_get_search(scr->f_data, scr->ses->search_word);			highlight_positions = scr->f_data->search_positions;			highlight_lengths = scr->f_data->search_lengths;			n_highlight_positions = scr->f_data->n_search_positions;		}	}	if (vs->view_pos > scr->f_data->y - scr->yw + scr->f_data->hsb * G_SCROLL_BAR_WIDTH) vs->view_pos = scr->f_data->y - scr->yw + scr->f_data->hsb * G_SCROLL_BAR_WIDTH;	if (vs->view_pos < 0) vs->view_pos = 0;	if (vs->view_posx > scr->f_data->x - scr->xw + scr->f_data->vsb * G_SCROLL_BAR_WIDTH) vs->view_posx = scr->f_data->x - scr->xw + scr->f_data->vsb * G_SCROLL_BAR_WIDTH;	if (vs->view_posx < 0) vs->view_posx = 0;	vx = vs->view_posx;	vy = vs->view_pos;	restrict_clip_area(t->dev, &old, scr->xp, scr->yp, scr->xp + xw, scr->yp + yw);	if (scr->f_data->vsb) draw_vscroll_bar(t->dev, scr->xp + xw - G_SCROLL_BAR_WIDTH, scr->yp, yw - scr->f_data->hsb * G_SCROLL_BAR_WIDTH, scr->f_data->y, yw - scr->f_data->hsb * G_SCROLL_BAR_WIDTH, vs->view_pos);	if (scr->f_data->hsb) draw_hscroll_bar(t->dev, scr->xp, scr->yp + yw - G_SCROLL_BAR_WIDTH, xw - scr->f_data->vsb * G_SCROLL_BAR_WIDTH, scr->f_data->x, xw - scr->f_data->vsb * G_SCROLL_BAR_WIDTH, vs->view_posx);	if (scr->f_data->vsb && scr->f_data->hsb) drv->fill_area(t->dev, scr->xp + xw - G_SCROLL_BAR_WIDTH, scr->yp + yw - G_SCROLL_BAR_WIDTH, scr->xp + xw, scr->yp + yw, scroll_bar_frame_color);	restrict_clip_area(t->dev, NULL, scr->xp, scr->yp, scr->xp + xw - scr->f_data->vsb * G_SCROLL_BAR_WIDTH, scr->yp + yw - scr->f_data->hsb * G_SCROLL_BAR_WIDTH);	/*debug("buu: %d %d %d, %d %d %d", scr->xl, vx, xw, scr->yl, vy, yw);*/	if (drv->flags & GD_DONT_USE_SCROLL) goto rrr;	if (scr->xl == -1 || scr->yl == -1) goto rrr;	if (is_rect_valid(&scr->ses->win->redr)) goto rrr;	if (scr->xl - vx > xw || vx - scr->xl > xw ||	    scr->yl - vy > yw || vy - scr->yl > yw) {		goto rrr;	}	if (scr->xl != vx) {		rs = NULL;		r |= drv->hscroll(t->dev, &rs, scr->xl - vx);		if (rs) {			int j;			for (j = 0; j < rs->m; j++) {				struct rect *r = &rs->r[j];				struct rect clip1;				/*fprintf(stderr, "scroll: %d,%d %d,%d\n", r->x1, r->y1, r->x2, r->y2);*/				restrict_clip_area(t->dev, &clip1, r->x1, r->y1, r->x2, r->y2);				scr->f_data->root->draw(scr, scr->f_data->root, scr->xp - vs->view_posx, scr->yp - vs->view_pos - (scr->yl - vy));				drv->set_clip_area(t->dev, &clip1);			}			mem_free(rs);		}	}		if (scr->yl != vy) {		rs = NULL;		r |= drv->vscroll(t->dev, &rs, scr->yl - vy);		if (rs) {			int j;			for (j = 0; j < rs->m; j++) {				struct rect *r = &rs->r[j];				struct rect clip1;				/*fprintf(stderr, "scroll: %d,%d %d,%d\n", r->x1, r->y1, r->x2, r->y2);*/				restrict_clip_area(t->dev, &clip1, r->x1, r->y1, r->x2, r->y2);				scr->f_data->root->draw(scr, scr->f_data->root, scr->xp - vs->view_posx, scr->yp - vs->view_pos);				drv->set_clip_area(t->dev, &clip1);			}			mem_free(rs);		}	}		if (r) {		struct rect clip1;		if (scr->xl < vx)  {			if (scr->yl < vy) {				restrict_clip_area(t->dev, &clip1, scr->xp + xw - scr->f_data->vsb * G_SCROLL_BAR_WIDTH - (vx - scr->xl), scr->yp, scr->xp + xw - scr->f_data->vsb * G_SCROLL_BAR_WIDTH, scr->yp + yw - scr->f_data->hsb * G_SCROLL_BAR_WIDTH - (vy - scr->yl));			} else {				restrict_clip_area(t->dev, &clip1, scr->xp + xw - scr->f_data->vsb * G_SCROLL_BAR_WIDTH - (vx - scr->xl), scr->yp + (scr->yl - vy), scr->xp + xw - scr->f_data->vsb * G_SCROLL_BAR_WIDTH, scr->yp + yw - scr->f_data->hsb * G_SCROLL_BAR_WIDTH);			}		} else {			if (scr->yl < vy) {				restrict_clip_area(t->dev, &clip1, scr->xp, scr->yp, scr->xp + (scr->xl - vx), scr->yp + yw - scr->f_data->hsb * G_SCROLL_BAR_WIDTH - (vy - scr->yl));			} else {				restrict_clip_area(t->dev, &clip1, scr->xp, scr->yp + (scr->yl - vy), scr->xp + (scr->xl - vx), scr->yp + yw - scr->f_data->hsb * G_SCROLL_BAR_WIDTH);			}		}		scr->f_data->root->draw(scr, scr->f_data->root, scr->xp - vs->view_posx, scr->yp - vs->view_pos);		drv->set_clip_area(t->dev, &clip1);		if (scr->yl < vy) {			restrict_clip_area(t->dev, NULL, scr->xp, scr->yp + yw - scr->f_data->hsb * G_SCROLL_BAR_WIDTH - (vy - scr->yl), scr->xp + xw - scr->f_data->vsb * G_SCROLL_BAR_WIDTH, scr->yp + yw - scr->f_data->hsb * G_SCROLL_BAR_WIDTH);		} else {			restrict_clip_area(t->dev, NULL, scr->xp, scr->yp, scr->xp + xw - scr->f_data->vsb * G_SCROLL_BAR_WIDTH, scr->yp + (scr->yl - vy));		}		scr->f_data->root->draw(scr, scr->f_data->root, scr->xp - vs->view_posx, scr->yp - vs->view_pos);	}	goto eee;	rrr:	scr->f_data->root->draw(scr, scr->f_data->root, scr->xp - vs->view_posx, scr->yp - vs->view_pos);	eee:	scr->xl = vx;	scr->yl = vy;	drv->set_clip_area(t->dev, &old);	highlight_positions = NULL;	highlight_lengths = NULL;	n_highlight_positions = 0;}int g_forward_mouse(struct f_data_c *fd, struct g_object *a, int x, int y, int b){	if (x >= a->x && x < a->x + a->xw && y >= a->y && y < a->y + a->yw) {		a->mouse_event(fd, a, x - a->x, y - a->y, b);		return 1;	}	return 0;}struct draw_data {	struct f_data_c *fd;	struct g_object *o;};void draw_one_object_fn(struct terminal *, struct draw_data *);  /* prototype */void draw_one_object_fn(struct terminal *t, struct draw_data *d){	struct rect clip;	struct f_data_c *scr = d->fd;	struct g_object *o = d->o;	int x, y;	restrict_clip_area(t->dev, &clip, scr->xp, scr->yp, scr->xp + scr->xw - scr->f_data->vsb * G_SCROLL_BAR_WIDTH, scr->yp + scr->yw - scr->f_data->hsb * G_SCROLL_BAR_WIDTH);	get_object_pos(o, &x, &y);	o->draw(scr, o, scr->xp - scr->vs->view_posx + x, scr->yp - scr->vs->view_pos + y);	drv->set_clip_area(t->dev, &clip);}void draw_one_object(struct f_data_c *scr, struct g_object *o){	struct draw_data d;	int *h1, *h2, h3;	d.fd = scr;	d.o = o;	h1 = highlight_positions;	h2 = highlight_lengths;	h3 = n_highlight_positions;	if (scr->ses->search_word && scr->ses->search_word[0]) {		g_get_search_data(scr->f_data);		g_get_search(scr->f_data, scr->ses->search_word);		highlight_positions = scr->f_data->search_positions;		highlight_lengths = scr->f_data->search_lengths;		n_highlight_positions = scr->f_data->n_search_positions;	}	draw_to_window(scr->ses->win, (void (*)(struct terminal *, void *))draw_one_object_fn, &d);	highlight_positions = h1;	highlight_lengths = h2;	n_highlight_positions = h3;}void g_area_mouse(struct f_data_c *fd, struct g_object_area *a, int x, int y, int b){	int i;	for (i = 0; i < a->n_lines; i++) if (g_forward_mouse(fd, (struct g_object *)a->lines[i], x, y, b)) return;}void g_line_mouse(struct f_data_c *fd, struct g_object_line *a, int x, int y, int b){	int i;	for (i = 0; i < a->n_entries; i++) if (g_forward_mouse(fd, (struct g_object *)a->entries[i], x, y, b)) return;}struct f_data *ffff;void get_parents_sub(struct g_object *p, struct g_object *c){	c->parent = p;	if (c->get_list) c->get_list(c, get_parents_sub);	if (c->destruct == g_tag_destruct) {		int x = 0, y = 0;		struct g_object *o;		c->y -= c->parent->yw;		for (o = c; o; o = o->parent) x += o->x, y += o->y;		html_tag(ffff, ((struct g_object_tag *)c)->name, x, y);	}	if (c->mouse_event == (void (*)(struct f_data_c *, struct g_object *, int, int, int))g_text_mouse) {		int l = ((struct g_object_text *)c)->link_num;		if (l >= 0) {			struct link *link = &ffff->links[l];			int x = 0, y = 0;			struct g_object *o;			for (o = c; o; o = o->parent) x += o->x, y += o->y;			if (x < link->r.x1) link->r.x1 = x;			if (y < link->r.y1) link->r.y1 = y;			if (x + c->xw > link->r.x2) link->r.x2 = x + c->xw;			if (y + c->yw > link->r.y2) link->r.y2 = y + c->yw;			link->obj = c;		}	}}void get_parents(struct f_data *f, struct g_object *a){	ffff = f;	a->parent = NULL;	if (a->get_list) a->get_list(a, get_parents_sub);}void get_object_pos(struct g_object *o, int *x, int *y){	*x = *y = 0;	while (o) {		*x += o->x;		*y += o->y;		o = o->parent;	}}void redraw_link(struct f_data_c *fd, int nl);/* if set_position is 1 sets cursor position in FIELD/AREA elements */void g_set_current_link(struct f_data_c *fd, struct g_object_text *a, int x, int y, int set_position){	if (a->map) {		int i;		for (i = 0; i < a->map->n_areas; i++) {			if (is_in_area(&a->map->area[i], x, y) && a->map->area[i].link_num >= 0) {				fd->vs->current_link = a->map->area[i].link_num;				fd->vs->orig_link = fd->vs->current_link;				return;			}		}	}	fd->vs->current_link = -1;	fd->vs->orig_link = fd->vs->current_link;	if (a->link_num >= 0) {		fd->vs->current_link = a->link_num;		fd->vs->orig_link = fd->vs->current_link;		/* if link is a field, set cursor position */		if (set_position&&a->link_num>=0&&a->link_num<fd->f_data->nlinks) /* valid link */		{			struct link *l=&fd->f_data->links[a->link_num];			struct form_state *fs;			int xx,yy;						if (!l->form)return;			if (l->type==L_AREA)			{				struct line_info *ln;				if (!(fs=find_form_state(fd,l->form)))return;				if (g_char_width(a->style,' ')) {					xx=x/g_char_width(a->style,' ');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -