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

📄 bfu.c

📁 ELinks is an advanced and well-established feature-rich text mode web (HTTP/FTP/..) browser. ELinks
💻 C
📖 第 1 页 / 共 5 页
字号:
	}	if (l < di->item->gid || l > di->item->gnum) {		msg_box(dlg->win->term, NULL, TEXT(T_BAD_NUMBER), AL_CENTER, TEXT(T_NUMBER_OUT_OF_RANGE), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);		return 1;	}	return 0;}int check_nonempty(struct dialog_data *dlg, struct dialog_item_data *di){	unsigned char *p;	for (p = di->cdata; *p; p++) if (*p > ' ') return 0;	msg_box(dlg->win->term, NULL, TEXT(T_BAD_STRING), AL_CENTER, TEXT(T_EMPTY_STRING_NOT_ALLOWED), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);	return 1;}int cancel_dialog(struct dialog_data *dlg, struct dialog_item_data *di){	delete_window(dlg->win);	return 0;}int check_dialog(struct dialog_data *dlg){	int i;	for (i = 0; i < dlg->n; i++)		if (dlg->dlg->items[i].type == D_CHECKBOX || dlg->dlg->items[i].type == D_FIELD || dlg->dlg->items[i].type == D_FIELD_PASS)			if (dlg->dlg->items[i].fn && dlg->dlg->items[i].fn(dlg, &dlg->items[i])) {				dlg->selected = i;				draw_to_window(dlg->win, (void (*)(struct terminal *, void *))redraw_dialog_items, dlg);				return 1;			}	return 0;}void get_dialog_data(struct dialog_data *dlg){	int i;	for (i = 0; i < dlg->n; i++)		memcpy(dlg->dlg->items[i].data, dlg->items[i].cdata, dlg->dlg->items[i].dlen);}int ok_dialog(struct dialog_data *dlg, struct dialog_item_data *di){	int i;	void (*fn)(void *) = dlg->dlg->refresh;	void *data = dlg->dlg->refresh_data;	if (check_dialog(dlg)) return 1;	get_dialog_data(dlg);	if (fn) fn(data);	i = cancel_dialog(dlg, di);	return i;}void center_dlg(struct dialog_data *dlg){	if (!dlg->win->term->spec->braille) {		dlg->x = (dlg->win->term->x - dlg->xw) / 2;		dlg->y = (dlg->win->term->y - dlg->yw) / 2;	} else {		dlg->x = -6;		dlg->y = -1;		dlg->xw = dlg->win->term->x + 12;		dlg->yw = dlg->win->term->y + 3;	}}void draw_dlg(struct dialog_data *dlg){	if (!F) {		int i, tpos;		struct terminal *term = dlg->win->term;		fill_area(term, dlg->x, dlg->y, dlg->xw, dlg->yw, COLOR_DIALOG);		draw_frame(term, dlg->x + DIALOG_LEFT_BORDER, dlg->y + DIALOG_TOP_BORDER, dlg->xw - 2 * DIALOG_LEFT_BORDER, dlg->yw - 2 * DIALOG_TOP_BORDER, COLOR_DIALOG_FRAME, DIALOG_FRAME);		i = strlen(_(dlg->dlg->title, term));		tpos = (dlg->xw - i) / 2;		if (term->spec->braille) tpos = 9;		print_text(term, tpos + dlg->x - 1, dlg->y + DIALOG_TOP_BORDER, 1, " ", COLOR_DIALOG_TITLE);		print_text(term, tpos + dlg->x, dlg->y + DIALOG_TOP_BORDER, i, _(dlg->dlg->title, term), COLOR_DIALOG_TITLE);		print_text(term, tpos + dlg->x + i, dlg->y + DIALOG_TOP_BORDER, 1, " ", COLOR_DIALOG_TITLE);#ifdef G	} else {		struct graphics_device *dev = dlg->win->term->dev;		struct rect r;		struct rect rt;		unsigned char *text = _(dlg->dlg->title, dlg->win->term);		int xtl = txtlen(text);		int tl = xtl + 2 * G_DIALOG_TITLE_BORDER;		int TXT_X, TXT_Y;		if (tl > dlg->xw - 2 * G_DIALOG_LEFT_BORDER - 2 * G_DIALOG_VLINE_SPACE) tl = dlg->xw - 2 * G_DIALOG_LEFT_BORDER - 2 * G_DIALOG_VLINE_SPACE;		TXT_X = dlg->x + (dlg->xw - tl) / 2;		TXT_Y = dlg->y + G_DIALOG_TOP_BORDER + (G_DIALOG_HLINE_SPACE + 1) / 2 - G_BFU_FONT_SIZE / 2;		if (TXT_Y < dlg->y) TXT_Y = dlg->y;		if (TXT_Y < dlg->y + G_DIALOG_TOP_BORDER + G_DIALOG_HLINE_SPACE + 1 - G_BFU_FONT_SIZE) TXT_Y = dlg->y + G_DIALOG_TOP_BORDER + G_DIALOG_HLINE_SPACE + 1 - G_BFU_FONT_SIZE;		set_window_pos(dlg->win, dlg->x, dlg->y, dlg->x + dlg->xw, dlg->y + dlg->yw);		restrict_clip_area(dev, &r, TXT_X, TXT_Y, TXT_X + tl, TXT_Y + G_BFU_FONT_SIZE);		rt.x1 = TXT_X;		rt.x2 = TXT_X + tl;		rt.y1 = TXT_Y;		rt.y2 = TXT_Y + G_BFU_FONT_SIZE;		if (xtl > tl) g_print_text(drv, dev, TXT_X, TXT_Y, bfu_style_wb, text, NULL);		else {			drv->fill_area(dev, TXT_X, TXT_Y, TXT_X + (tl - xtl) / 2, TXT_Y + G_BFU_FONT_SIZE, bfu_fg_color);			g_print_text(drv, dev, TXT_X + (tl - xtl) / 2, TXT_Y, bfu_style_wb, text, NULL);			drv->fill_area(dev, TXT_X + (tl - xtl) / 2 + xtl, TXT_Y, TXT_X + tl, TXT_Y + G_BFU_FONT_SIZE, bfu_fg_color);		}		drv->set_clip_area(dev, &r);		drv->draw_hline(dev, dlg->x + G_DIALOG_LEFT_BORDER, dlg->y + G_DIALOG_TOP_BORDER, TXT_X, bfu_fg_color);		drv->draw_hline(dev, dlg->x + G_DIALOG_LEFT_BORDER + G_DIALOG_VLINE_SPACE, dlg->y + G_DIALOG_TOP_BORDER + G_DIALOG_HLINE_SPACE, TXT_X, bfu_fg_color);		drv->draw_hline(dev, TXT_X + tl, dlg->y + G_DIALOG_TOP_BORDER, dlg->x + dlg->xw - G_DIALOG_LEFT_BORDER, bfu_fg_color);		drv->draw_hline(dev, TXT_X + tl, dlg->y + G_DIALOG_TOP_BORDER + G_DIALOG_HLINE_SPACE, dlg->x + dlg->xw - G_DIALOG_LEFT_BORDER - G_DIALOG_VLINE_SPACE, bfu_fg_color);		drv->draw_hline(dev, dlg->x + G_DIALOG_LEFT_BORDER, dlg->y + dlg->yw - G_DIALOG_TOP_BORDER - 1, dlg->x + dlg->xw - G_DIALOG_LEFT_BORDER, bfu_fg_color);		drv->draw_hline(dev, dlg->x + G_DIALOG_LEFT_BORDER + G_DIALOG_VLINE_SPACE, dlg->y + dlg->yw - G_DIALOG_TOP_BORDER - G_DIALOG_HLINE_SPACE - 1, dlg->x + dlg->xw - G_DIALOG_LEFT_BORDER - G_DIALOG_VLINE_SPACE, bfu_fg_color);		drv->draw_vline(dev, dlg->x + G_DIALOG_LEFT_BORDER, dlg->y + G_DIALOG_TOP_BORDER + 1, dlg->y + dlg->yw - G_DIALOG_TOP_BORDER - 1, bfu_fg_color);		drv->draw_vline(dev, dlg->x + G_DIALOG_LEFT_BORDER + G_DIALOG_VLINE_SPACE, dlg->y + G_DIALOG_TOP_BORDER + G_DIALOG_HLINE_SPACE + 1, dlg->y + dlg->yw - G_DIALOG_TOP_BORDER - G_DIALOG_HLINE_SPACE - 1, bfu_fg_color);		drv->draw_vline(dev, dlg->x + dlg->xw - G_DIALOG_LEFT_BORDER - 1, dlg->y + G_DIALOG_TOP_BORDER + 1, dlg->y + dlg->yw - G_DIALOG_TOP_BORDER - 1, bfu_fg_color);		drv->draw_vline(dev, dlg->x + dlg->xw - G_DIALOG_LEFT_BORDER - G_DIALOG_VLINE_SPACE - 1, dlg->y + G_DIALOG_TOP_BORDER + G_DIALOG_HLINE_SPACE + 1, dlg->y + dlg->yw - G_DIALOG_TOP_BORDER - G_DIALOG_HLINE_SPACE - 1, bfu_fg_color);		drv->fill_area(dev, dlg->x, dlg->y, TXT_X, dlg->y + G_DIALOG_TOP_BORDER, bfu_bg_color);		drv->fill_area(dev, TXT_X, dlg->y, TXT_X + tl, TXT_Y, bfu_bg_color);		drv->fill_area(dev, TXT_X + tl, dlg->y, dlg->x + dlg->xw, dlg->y + G_DIALOG_TOP_BORDER, bfu_bg_color);		drv->fill_area(dev, dlg->x, dlg->y + G_DIALOG_TOP_BORDER, dlg->x + G_DIALOG_LEFT_BORDER, dlg->y + dlg->yw - G_DIALOG_TOP_BORDER, bfu_bg_color);		drv->fill_area(dev, dlg->x + dlg->xw - G_DIALOG_LEFT_BORDER, dlg->y + G_DIALOG_TOP_BORDER, dlg->x + dlg->xw, dlg->y + dlg->yw - G_DIALOG_TOP_BORDER, bfu_bg_color);		drv->fill_area(dev, dlg->x, dlg->y + dlg->yw - G_DIALOG_TOP_BORDER, dlg->x + dlg->xw, dlg->y + dlg->yw, bfu_bg_color);		drv->fill_area(dev, dlg->x + G_DIALOG_LEFT_BORDER + 1, dlg->y + G_DIALOG_TOP_BORDER + 1, TXT_X, dlg->y + G_DIALOG_TOP_BORDER + G_DIALOG_HLINE_SPACE, bfu_bg_color);		drv->fill_area(dev, TXT_X + tl, dlg->y + G_DIALOG_TOP_BORDER + 1, dlg->x + dlg->xw - G_DIALOG_LEFT_BORDER - 1, dlg->y + G_DIALOG_TOP_BORDER + + G_DIALOG_HLINE_SPACE, bfu_bg_color);		drv->fill_area(dev, dlg->x + G_DIALOG_LEFT_BORDER + 1, dlg->y + G_DIALOG_TOP_BORDER + G_DIALOG_HLINE_SPACE, dlg->x + G_DIALOG_LEFT_BORDER + G_DIALOG_VLINE_SPACE, dlg->y + dlg->yw - G_DIALOG_TOP_BORDER - G_DIALOG_HLINE_SPACE, bfu_bg_color);		drv->fill_area(dev, dlg->x + dlg->xw - G_DIALOG_LEFT_BORDER - G_DIALOG_VLINE_SPACE, dlg->y + G_DIALOG_TOP_BORDER + G_DIALOG_HLINE_SPACE, dlg->x + dlg->xw - G_DIALOG_LEFT_BORDER - 1, dlg->y + dlg->yw - G_DIALOG_TOP_BORDER - G_DIALOG_HLINE_SPACE, bfu_bg_color);		drv->fill_area(dev, dlg->x + G_DIALOG_LEFT_BORDER + 1, dlg->y + dlg->yw - G_DIALOG_TOP_BORDER - G_DIALOG_HLINE_SPACE, dlg->x + dlg->xw - G_DIALOG_LEFT_BORDER - 1, dlg->y + dlg->yw - G_DIALOG_TOP_BORDER - 1, bfu_bg_color);				/*		drv->fill_area(dev, dlg->x + G_DIALOG_LEFT_BORDER + G_DIALOG_VLINE_SPACE + 1, dlg->y + G_DIALOG_TOP_BORDER + G_DIALOG_HLINE_SPACE + 1, TXT_X, TXT_Y + G_BFU_FONT_SIZE, bfu_bg_color);		drv->fill_area(dev, TXT_X + tl, dlg->y + G_DIALOG_TOP_BORDER + G_DIALOG_HLINE_SPACE + 1, dlg->x + dlg->xw - G_DIALOG_LEFT_BORDER - G_DIALOG_VLINE_SPACE - 1, TXT_Y + G_BFU_FONT_SIZE, bfu_bg_color);		*/		dlg->s = init_rect_set();		dlg->rr.x1 = dlg->x + G_DIALOG_LEFT_BORDER + G_DIALOG_VLINE_SPACE + 1;		dlg->rr.x2 = dlg->x + dlg->xw - G_DIALOG_LEFT_BORDER - G_DIALOG_VLINE_SPACE - 1;		/*dlg->rr.y1 = TXT_Y + G_BFU_FONT_SIZE;*/		dlg->rr.y1 = dlg->y + G_DIALOG_TOP_BORDER + G_DIALOG_HLINE_SPACE + 1;		dlg->rr.y2 = dlg->y + dlg->yw - G_DIALOG_TOP_BORDER - G_DIALOG_HLINE_SPACE - 1;		add_to_rect_set(&dlg->s, &dlg->rr);		exclude_rect_from_set(&dlg->s, &rt);		restrict_clip_area(dev, &dlg->r, dlg->rr.x1, dlg->rr.y1, dlg->rr.x2, dlg->rr.y2);#endif	}}void max_text_width(struct terminal *term, unsigned char *text, int *width, int align){	if (term->spec->braille) *width = term->x;	text = _(text, term);	do {		int c = 0;		while (*text && *text != '\n') {			if (!F) text++, c++;#ifdef G			else {				int u;				GET_UTF_8(text, u);				c += g_char_width(align & AL_MONO ? bfu_style_wb_mono : bfu_style_wb, u);			}#endif		}		if (c > *width) *width = c;	} while (*(text++));}void min_text_width(struct terminal *term, unsigned char *text, int *width, int align){	if (term->spec->braille) *width = term->x;	text = _(text, term);	do {		int c = 0;		while (*text && *text != '\n' && *text != ' ') {			if (!F) text++, c++;#ifdef G			else {				int u;				GET_UTF_8(text, u);				c += g_char_width(align & AL_MONO ? bfu_style_wb_mono : bfu_style_wb, u);			}#endif		}		if (c > *width) *width = c;	} while (*(text++));}int dlg_format_text(struct dialog_data *dlg, struct terminal *term, unsigned char *text, int x, int *y, int w, int *rw, int co, int align){	int xx = x;#ifdef G	unsigned char *tx2;#endif	text = _(text, dlg->win->term);	if (dlg->win->term->spec->braille && !(align & AL_NOBRLEXP)) w = dlg->win->term->x;	if (!F) do {		unsigned char *tx;		unsigned char *tt = text;		int s;		xx = x;		do {			while (*text && *text != '\n' && *text != ' ') {				text++, xx++;			}			tx = ++text;			xx++;			if (*(text - 1) != ' ') break;			while (*tx && *tx != '\n' && *tx != ' ') tx++;		} while (tx - text + xx - x <= w);		s = (align & AL_MASK) == AL_CENTER && !dlg->win->term->spec->braille ? (w - (xx - 1 - x)) / 2 : 0;		if (s < 0) s = 0;		while (tt < text - 1) {			if (s >= w) {				s = 0, (*y)++;				if (rw) *rw = w;				rw = NULL;			}			if (term) set_char(term, x + s, *y, co | *tt);			s++, tt++;		}		if (rw && xx - 1 - x > *rw) *rw = xx - 1 - x;		(*y)++;	} while (*(text - 1));#ifdef G	else if ((tx2 = strchr(text, '\n'))) {		unsigned char *txt = stracpy(text);		unsigned char *tx1 = txt;		tx2 += txt - text;		do {			*tx2 = 0;			dlg_format_text(dlg, term, tx1, x, y, w, rw, co, align);			tx1 = tx2 + 1;		} while ((tx2 = strchr(tx1, '\n')));		dlg_format_text(dlg, term, tx1, x, y, w, rw, co, align);		mem_free(txt);	} else {		int www;		unsigned char *txt;		struct wrap_struct ww;		int r;		ww.style = align & AL_MONO ? bfu_style_bw_mono : bfu_style_bw;		ww.width = w;		new_ln:		ww.text = text;		ww.pos = 0;		ww.last_wrap = NULL;		ww.last_wrap_obj = NULL;		r = g_wrap_text(&ww);		if (!r) {			txt = memacpy(text, ww.last_wrap - text);			www = g_text_width(ww.style, txt);			if (!term) mem_free(txt);			text = ww.last_wrap;			if (*text == ' ') text++;			else if (term) add_to_strn(&txt, "-");		} else {			www = ww.pos;			txt = text;		}		if (term) {			int xx = (align & AL_MASK) == AL_CENTER ? x + (w - www) / 2 : x;			g_print_text(drv, dlg->win->term->dev, xx, *y, ww.style, txt, NULL);			if (dlg->s) exclude_from_set(&dlg->s, xx, *y, xx + www, *y + G_BFU_FONT_SIZE);			if (!r) mem_free(txt);		}		if (www > w) www = w;		if (rw && www > *rw) *rw = www;		*y += G_BFU_FONT_SIZE;		if (!r) goto new_ln;	}#endif	return xx - x;}void max_buttons_width(struct terminal *term, struct dialog_item_data *butt, int n, int *width){	int w = gf_val(-2, -G_DIALOG_BUTTON_SPACE);	int i;	if (term->spec->braille) *width = term->x;	for (i = 0; i < n; i++) w += txtlen(_((butt++)->item->text, term)) + gf_val(6, G_DIALOG_BUTTON_SPACE + txtlen(G_DIALOG_BUTTON_L) + txtlen(G_DIALOG_BUTTON_R));	if (w > *width) *width = w;}void min_buttons_width(struct terminal *term, struct dialog_item_data *butt, int n, int *width){	int i;	if (term->spec->braille) *width = term->x;	for (i = 0; i < n; i++) {		int w = txtlen(_((butt++)->item->text, term)) + gf_val(4, txtlen(G_DIALOG_BUTTON_L G_DIALOG_BUTTON_R));		if (w > *width) *width = w;	}}void dlg_format_buttons(struct dialog_data *dlg, struct terminal *term, struct dialog_item_data *butt, int n, int x, int *y, int w, int *rw, int align){	int i1 = 0;	if (dlg->win->term->spec->braille) w = dlg->win->term->x;	while (i1 < n) {		int i2 = i1 + 1;		int mw;		while (i2 < n) {			mw = 0;			max_buttons_width(dlg->win->term, butt + i1, i2 - i1 + 1, &mw);			if (mw <= w) i2++;			else break;		}		mw = 0;		max_buttons_width(dlg->win->term, butt + i1, i2 - i1, &mw);		if (rw && mw > *rw) if ((*rw = mw) > w) *rw = w;		if (term) {			int i;			int p = x + ((align & AL_MASK) == AL_CENTER ? (w - mw) / 2 : 0);			for (i = i1; i < i2; i++) {				butt[i].x = p;				butt[i].y = *y;				p += (butt[i].l = txtlen(_(butt[i].item->text, dlg->win->term)) + gf_val(4, txtlen(G_DIALOG_BUTTON_L G_DIALOG_BUTTON_R))) + gf_val(2, G_DIALOG_BUTTON_SPACE);			}		}		*y += gf_val(2, G_BFU_FONT_SIZE * 2);		i1 = i2;	}}void dlg_format_checkbox(struct dialog_data *dlg, struct terminal *term, struct dialog_item_data *chkb, int x, int *y, int w, int *rw, unsigned char *text){	int k = gf_val(4, txtlen(G_DIALOG_CHECKBOX_L G_DIALOG_CHECKBOX_X G_DIALOG_CHECKBOX_R) + G_DIALOG_CHECKBOX_SPACE);	if (term) {		chkb->x = x;		chkb->y = *y;	}	if (rw) *rw -= k;	dlg_format_text(dlg, term, text, x + k, y, w - k, rw, COLOR_DIALOG_CHECKBOX_TEXT, AL_LEFT | AL_NOBRLEXP);	if (rw) *rw += k;}void dlg_format_checkboxes(struct dialog_data *dlg, struct terminal *term, struct dialog_item_data *chkb, int n, int x, int *y, int w, int *rw, unsigned char **texts){	if (dlg->win->term->spec->braille) w = dlg->win->term->x;	while (n) {		dlg_format_checkbox(dlg, term, chkb, x, y, w, rw, texts[0]);		texts++; chkb++; n--;	}}void checkboxes_width(struct terminal *term, unsigned char **texts, int *w, void (*fn)(struct terminal *, unsigned char *, int *, int)){	int k = gf_val(4, txtlen(G_DIALOG_CHECKBOX_L G_DIALOG_CHECKBOX_X G_DIALOG_CHECKBOX_R) + G_DIALOG_CHECKBOX_SPACE);	while (texts[0]) {		*w -= k;		fn(term, _(texts[0], term), w, 0);		*w += k;		texts++;	}}void dlg_format_field(struct dialog_data *dlg, struct terminal *term, struct dialog_item_data *item, int x, int *y, int w, int *rw, int align){	if (dlg->win->term->spec->braille) w = dlg->win->

⌨️ 快捷键说明

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