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

📄 html_gr.c

📁 ELinks is an advanced and well-established feature-rich text mode web (HTTP/FTP/..) browser. ELinks
💻 C
📖 第 1 页 / 共 3 页
字号:
	}	if (0) {		int nn;		found:		n += !ptr;		l2 = mem_calloc(sizeof(struct g_object_line) + (p->line->n_entries - n) * sizeof(struct g_object_text *));		l2->mouse_event = g_line_mouse;		l2->draw = g_line_draw;		l2->destruct = g_line_destruct;		l2->get_list = g_line_get_list;		l2->bg = p->root->bg;		l2->n_entries = p->line->n_entries - n;		l2->entries[0] = (struct g_object *)t2;		memcpy(&l2->entries[!!ptr], p->line->entries + n + !!ptr, (l2->n_entries - !!ptr) * sizeof(struct g_object_text *));		p->line->n_entries = n + !!ptr;		flush_pending_line_to_obj(p, 0);		p->line = l2;		if (ptr) {			t2->xw = g_text_width(t2->style, t2->text);			t2->yw = text->yw;			p->w.pos = 0;		}		for (nn = 0; nn < l2->n_entries; nn++) {			p->w.pos += l2->entries[nn]->xw;	/* !!! FIXME: nastav last_wrap */			/*debug("a1: %d (%s)", l2->entries[nn]->xw, tt->text);*/		}		wwww:		if (p->text) p->w.pos += g_text_width(p->text->style, p->text->text);		/*debug("%d", p->w.pos);*/	} else {		flush_pending_text_to_line(p);		flush_pending_line_to_obj(p, 0);		p->line = NULL;		t2->xw = g_text_width(t2->style, t2->text);		t2->yw = text->yw;		p->text = t2;		p->pending_text_len = -1;		p->w.pos = t2->xw;		p->cx += g_char_width(t2->style, ' ');	}	p->w.last_wrap = NULL;	p->w.last_wrap_obj = NULL;	t2 = p->text;	if (t2 && *t2->text && t2->text[strlen(t2->text) - 1] == ' ') {		p->w.last_wrap = &t2->text[strlen(t2->text) - 1];		p->w.last_wrap_obj = t2;	}}void add_object(struct g_part *p, struct g_object *o){	g_nobreak = 0;	flush_pending_text_to_line(p);	p->w.width = rm(par_format) - par_format.leftmargin * G_HTML_MARGIN;	if (p->w.pos + o->xw > p->w.width) flush_pending_line_to_obj(p, 0);	add_object_to_line(p, &p->line, o);	p->w.last_wrap = NULL;	p->w.last_wrap_obj = o;	p->w.pos += o->xw;	/*	if (p->w.pos > p->w.width && p->w.last_wrap_obj) {		split_line_object(p, p->w.last_wrap_obj, p->w.last_wrap);	}	*/}void g_line_break(struct g_part *p){	if (g_nobreak) {		g_nobreak = 0;		return;	}	flush_pending_text_to_line(p);	if (!p->line) {		add_object_to_line(p, &p->line, NULL);		flush_pending_line_to_obj(p, get_real_font_size(format.fontsize));	} else /*if (p->w.pos || par_format.align == AL_NO)*/ {		flush_pending_line_to_obj(p, 0);	}	if (p->cx > p->xmax) p->xmax = p->cx;	p->cx = -1;}/* SHADOWED IN html_form_control */void g_html_form_control(struct g_part *p, struct form_control *fc){	if (!p->data) {		/*destroy_fc(fc);		mem_free(fc);*/		add_to_list(p->uf, fc);		return;	}	fc->g_ctrl_num = g_ctrl_num++;	if (fc->type == FC_TEXT || fc->type == FC_PASSWORD || fc->type == FC_TEXTAREA) {		unsigned char *dv = convert_string(convert_table, fc->default_value, strlen(fc->default_value), d_opt);		if (dv) {			mem_free(fc->default_value);			fc->default_value = dv;		}		/*		for (i = 0; i < fc->nvalues; i++) if ((dv = convert_string(convert_table, fc->values[i], strlen(fc->values[i]), d_opt))) {			mem_free(fc->values[i]);			fc->values[i] = dv;		}		*/	}	if (fc->type == FC_TEXTAREA) {		unsigned char *p;		for (p = fc->default_value; p[0]; p++) if (p[0] == '\r') {			if (p[1] == '\n') memmove(p, p + 1, strlen(p)), p--;			else p[0] = '\n';		}	}	add_to_list(p->data->forms, fc);}struct link **putchars_link_ptr = NULL;/* Probably releases clickable map */void release_image_map(struct image_map *map){	int i;	if (!map) return;	for (i = 0; i < map->n_areas; i++) mem_free(map->area[i].coords);	mem_free(map);}int is_in_area(struct map_area *a, int x, int y){	int i;	int over;	switch (a->shape) {		case SHAPE_DEFAULT:			return 1;		case SHAPE_RECT:			return a->ncoords >= 4 && x >= a->coords[0] && y >= a->coords[1] && x < a->coords[2] && y < a->coords[3];		case SHAPE_CIRCLE:			return a->ncoords >= 3 && (a->coords[0]-x)*(a->coords[0]-x)+(a->coords[1]-y)*(a->coords[1]-y) <= a->coords[2]*a->coords[2];		case SHAPE_POLY:			over = 0;			if (a->ncoords >= 4) for (i = 0; i + 1 < a->ncoords; i += 2) {				int x1, x2, y1, y2;				x1 = a->coords[i];				y1 = a->coords[i + 1];				x2 = a->coords[0];				y2 = a->coords[1];				if (i + 3 < a->ncoords) {					x2 = a->coords[i + 2];					y2 = a->coords[i + 3];				}				if (y1 > y2) {					int sw;					sw = x1; x1 = x2; x2 = sw;					sw = y1; y1 = y2; y2 = sw;				}				if (y >= y1 && y < y2) {					int po = 10000 * (y - y1) / (y2 - y1);					int xs = x1 + (x2 - x1) * po / 10000;					if (xs >= x) over++;				}			}			return over & 1;		default:			internal("is_in_area: bad shape: %d", a->shape);	}	return 0;}/* The size is requested in im->xsize and im->ysize. <0 means * not specified. Autoscale is requested in im->autoscale. * If autoscale is specified, im->xsize and im->ysize must * be >0. */void do_image(struct g_part *p, struct image_description *im){	struct g_object_image *io;	struct link *link;	link = NULL;	putchars_link_ptr = &link;	g_put_chars(p, NULL, 0);	putchars_link_ptr = NULL;	if (!link) im->link_num = -1;	else {		im->link_num = link - p->data->links;		im->link_order = link->obj_order++;		if (link->img_alt) mem_free(link->img_alt);		link->img_alt = stracpy(im->alt);	}	io = insert_image(p, im);	if (!io) goto ab;	io->ismap = im->ismap;	add_object(p, (struct g_object *)io);	if (im->usemap && p->data) {		unsigned char *tag = extract_position(im->usemap);		struct additional_file *af = request_additional_file(current_f_data, im->usemap);		af->need_reparse = 1;		if (af->rq && (af->rq->state == O_LOADING || af->rq->state == O_INCOMPLETE || af->rq->state == O_OK) && af->rq->ce) {			struct memory_list *ml;			struct menu_item *menu;			struct cache_entry *ce = af->rq->ce;			unsigned char *start, *end;			int i;			struct image_map *map;			if (get_file(af->rq, &start, &end)) goto ft;			if (start == end) goto ft;			if (get_image_map(ce->head, start, end, tag, &menu, &ml, format.href_base, format.target_base, 0, 0, 0, 1)) goto ft;			map = mem_alloc(sizeof(struct image_map));			map->n_areas = 0;			for (i = 0; menu[i].text; i++) {				struct link_def *ld = menu[i].data;				struct map_area *a;				struct link *link;				int shape = !ld->shape || !*ld->shape ? SHAPE_RECT : !strcasecmp(ld->shape, "default") ? SHAPE_DEFAULT : !strcasecmp(ld->shape, "rect") ? SHAPE_RECT : !strcasecmp(ld->shape, "circle") ? SHAPE_CIRCLE : !strcasecmp(ld->shape, "poly") || !strcasecmp(ld->shape, "polygon") ? SHAPE_POLY : -1;				if (shape == -1) continue;				if ((unsigned)map->n_areas > (MAXINT - sizeof(struct image_map)) / sizeof(struct map_area) - 1) overalloc();				map = mem_realloc(map, sizeof(struct image_map) + (map->n_areas + 1) * sizeof(struct map_area));				a = &map->area[map->n_areas++];				a->shape = shape;				a->coords = DUMMY;				a->ncoords = 0;				if (ld->coords) {					unsigned char *p = ld->coords;					int num;					next_coord:					num = 0;					while (*p && (*p < '0' || *p > '9')) p++;					if (!*p) goto noc;					while (*p >= '0' && *p <= '9' && num < 10000000) num = num * 10 + *p - '0', p++;					if (*p == '.') {						p++;						while (*p >= '0' && *p <= '9') p++;					}					if (*p == '%' && num < 1000) {						int m = io->xw < io->yw ? io->xw : io->yw;						num = num * m / 100;						p++;					} else num = num * d_opt->image_scale / 100;					if ((unsigned)a->ncoords > MAXINT / sizeof(int) - 1) overalloc();					a->coords = mem_realloc(a->coords, (a->ncoords + 1) * sizeof(int));					a->coords[a->ncoords++] = num;					goto next_coord;				}				noc:				if (!(link = new_link(p->data))) a->link_num = -1;				else {					link->pos = DUMMY;					link->type = L_LINK;					link->where = stracpy(ld->link);					link->target = stracpy(ld->target);					link->img_alt = stracpy(ld->label);					link->where_img = stracpy(im->url);#ifdef JS					if (ld->onclick || ld->ondblclick || ld->onmousedown || ld->onmouseup || ld->onmouseover || ld->onmouseout || ld->onmousemove) {						create_js_event_spec(&link->js_event);						link->js_event->click_code = stracpy(ld->onclick);						link->js_event->dbl_code = stracpy(ld->ondblclick);						link->js_event->down_code = stracpy(ld->onmousedown);						link->js_event->up_code = stracpy(ld->onmouseup);						link->js_event->over_code = stracpy(ld->onmouseover);						link->js_event->out_code = stracpy(ld->onmouseout);						link->js_event->move_code = stracpy(ld->onmousemove);					}#endif					a->link_num = link - p->data->links;				}				if (last_link) mem_free(last_link), last_link = NULL;			}			io->map = map;			freeml(ml);			ft:;		}		if (tag) mem_free(tag);	}	ab:;}void g_hr(struct g_part *gp, struct hr_param *hr){	unsigned char bgstr[8];	struct g_object_line *o;	o = mem_calloc(sizeof(struct g_object_line));	o->mouse_event = g_line_mouse;	o->draw = g_line_draw;	o->destruct = g_line_bg_destruct;	o->get_list = g_line_get_list;	/*o->x = 0;	o->y = 0;*/	o->xw = hr->width;	o->yw = hr->size;	table_bg(&format, bgstr);	o->bg = get_background(NULL, bgstr);	o->n_entries = 0;	flush_pending_text_to_line(gp);	/*flush_pending_line_to_obj(gp, get_real_font_size(format.fontsize));*/	add_object_to_line(gp, &gp->line, (struct g_object *)o);	line_breax = 0;	gp->cx = -1;}void *g_html_special(struct g_part *p, int c, ...){	va_list l;	unsigned char *t;	struct form_control *fc;	struct frameset_param *fsp;	struct frame_param *fp;	struct image_description *im;	struct g_object_tag *tag;	struct refresh_param *rp;	struct hr_param *hr;	va_start(l, c);	switch (c) {		case SP_TAG:			t = va_arg(l, unsigned char *);			va_end(l);			/* not needed to convert %AB here because html_tag will be called anyway */			tag = mem_calloc(sizeof(struct g_object_tag) + strlen(t) + 1);			tag->mouse_event = g_dummy_mouse;			tag->draw = g_dummy_draw;			tag->destruct = g_tag_destruct;			strcpy(tag->name, t);			flush_pending_text_to_line(p);			add_object_to_line(p, &p->line, (struct g_object *)tag);			break;		case SP_CONTROL:			fc = va_arg(l, struct form_control *);			va_end(l);			g_html_form_control(p, fc);			break;		case SP_TABLE:			va_end(l);			return convert_table;		case SP_USED:			va_end(l);			return (void *)(my_intptr_t)!!p->data;		case SP_FRAMESET:			fsp = va_arg(l, struct frameset_param *);			va_end(l);			return create_frameset(p->data, fsp);		case SP_FRAME:			fp = va_arg(l, struct frame_param *);			va_end(l);			create_frame(fp);			break;		case SP_SCRIPT:			t = va_arg(l, unsigned char *);			va_end(l);			if (p->data) process_script(p->data, t);			break;		case SP_IMAGE:			im = va_arg(l, struct image_description *);			va_end(l);			do_image(p, im);			break;		case SP_NOWRAP:			va_end(l);			break;		case SP_REFRESH:			rp = va_arg(l, struct refresh_param *);			va_end(l);			html_process_refresh(p->data, rp->url, rp->time);			break;		case SP_SET_BASE:			t = va_arg(l, unsigned char *);			va_end(l);			if (p->data) set_base(p->data, t);			break;		case SP_HR:			hr = va_arg(l, struct hr_param *);			va_end(l);			g_hr(p, hr);			break;		default:			va_end(l);			internal("html_special: unknown code %d", c);	}	return NULL;}unsigned char to_je_ale_prasarna[] = "";unsigned char *cached_font_face = to_je_ale_prasarna;struct text_attrib_beginning ta_cache = { -1, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, 0, 0 };

⌨️ 快捷键说明

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