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

📄 bfu.c

📁 ELinks is an advanced and well-established feature-rich text mode web (HTTP/FTP/..) browser. ELinks
💻 C
📖 第 1 页 / 共 5 页
字号:
void tab_compl(struct terminal *term, unsigned char *item, struct window *win){	struct event ev = {EV_REDRAW, 0, 0, 0};	struct dialog_item_data *di = &((struct dialog_data*)win->data)->items[((struct dialog_data*)win->data)->selected];	int l = strlen(item);	if (l >= di->item->dlen) l = di->item->dlen - 1;	memcpy(di->cdata, item, l);	di->cdata[l] = 0;	di->cpos = l;	di->vpos = 0;	ev.x = term->x;	ev.y = term->y;	dialog_func(win, &ev, 0);}void do_tab_compl(struct terminal *term, struct list_head *history, struct window *win){	unsigned char *cdata = ((struct dialog_data*)win->data)->items[((struct dialog_data*)win->data)->selected].cdata;	int l = strlen(cdata), n = 0;	struct history_item *hi;	struct menu_item *items = DUMMY;	foreach(hi, *history) if (!strncmp(cdata, hi->d, l)) {		if (!(n & (ALLOC_GR - 1))) {			if ((unsigned)n > MAXINT / sizeof(struct menu_item) - ALLOC_GR - 1) overalloc();			items = mem_realloc(items, (n + ALLOC_GR + 1) * sizeof(struct menu_item));		}		items[n].text = hi->d;		items[n].rtext = "";		items[n].hotkey = "";		items[n].func = (void(*)(struct terminal *, void *, void *))tab_compl;		items[n].rtext = "";		items[n].data = hi->d;		items[n].in_m = 0;		items[n].free_i = 1;		if (n == MAXINT) overalloc();		n++;	}	if (n == 1) {		tab_compl(term, items->data, win);		mem_free(items);		return;	}	if (n) {		memset(&items[n], 0, sizeof(struct menu_item));		do_menu_selected(term, items, win, n - 1);	}}void dialog_func(struct window *win, struct event *ev, int fwd){	int i;	struct terminal *term = win->term;	struct dialog_data *dlg = win->data;	struct dialog_item_data *di;	dlg->win = win;	/* Use nonstandard event handlers */	if (dlg->dlg->handle_event && ((dlg->dlg->handle_event)(dlg, ev) == EVENT_PROCESSED) ) {		return;	}		switch ((int)ev->ev) {		case EV_INIT:			for (i = 0; i < dlg->n; i++) {				struct dialog_item_data *di = &dlg->items[i];				memset(di, 0, sizeof(struct dialog_item_data));				di->item = &dlg->dlg->items[i];				di->cdata = mem_alloc(di->item->dlen);				memcpy(di->cdata, di->item->data, di->item->dlen);				if (di->item->type == D_CHECKBOX) {					if (di->item->gid) {						if (*(int *)di->cdata == di->item->gnum) di->checked = 1;					} else if (*(int *)di->cdata) di->checked = 1;				} 				init_list(di->history);				di->cur_hist = (struct history_item *)(void *)&di->history;				if (di->item->type == D_FIELD || di->item->type == D_FIELD_PASS) {					if (di->item->history) {						struct history_item *j;						/*int l = di->item->dlen;*/						foreach(j, di->item->history->items) {							struct history_item *hi;							hi = mem_alloc(sizeof(struct history_item) + strlen(j->d) + 1);							strcpy(hi->d, j->d);							add_to_list(di->history, hi);						}					}					di->cpos = strlen(di->cdata);				}			}			dlg->selected = 0;		case EV_RESIZE:				/* this must be really called twice !!! */			draw_to_window(dlg->win, (void (*)(struct terminal *, void *))redraw_dialog, dlg);		case EV_REDRAW:			redraw:			draw_to_window(dlg->win, (void (*)(struct terminal *, void *))redraw_dialog, dlg);			break;		case EV_MOUSE:			if ((ev->b & BM_ACT) == B_MOVE) break;			for (i = 0; i < dlg->n; i++) if (dlg_mouse(dlg, &dlg->items[i], ev)) break;			if ((ev->b & BM_ACT) == B_DOWN && (ev->b & BM_BUTT) == B_MIDDLE) {				di = &dlg->items[dlg->selected];  /* don't delete this!!! it's here because of jump from mouse event */				if (di->item->type == D_FIELD || di->item->type == D_FIELD_PASS) goto clipbd_paste;			}			break;		case EV_KBD:			if (ev->x == KBD_UP && dlg_is_braille_moving(dlg)) {				if (dlg->brl_y) dlg->brl_y--;				goto redraw;			}			if (ev->x == KBD_DOWN && dlg_is_braille_moving(dlg)) {				if (dlg->brl_y < dlg->items[0].y - 3) dlg->brl_y++;				goto redraw;			}			if ((ev->x == KBD_HOME || (upcase(ev->x) == 'A' && ev->y & KBD_CTRL) || ev->x == KBD_PAGE_UP || (upcase(ev->x) == 'B' && ev->y & KBD_CTRL)) && dlg_is_braille_moving(dlg)) {				dlg->brl_y = 0;				goto redraw;			}			if ((ev->x == KBD_END || (upcase(ev->x) == 'E' && ev->y & KBD_CTRL)) && dlg_is_braille_moving(dlg)) {				dlg->brl_y = dlg->items[0].y - 4;				goto redraw;			}			if ((ev->x == KBD_PAGE_DOWN || (upcase(ev->x) == 'F' && ev->y & KBD_CTRL)) && dlg_is_braille_moving(dlg)) {				dlg->brl_y = dlg->items[0].y - 3;				goto redraw;			}			di = &dlg->items[dlg->selected];			if (di->item->type == D_FIELD || di->item->type == D_FIELD_PASS) {				if (ev->x == KBD_UP && (void *)di->cur_hist->prev != &di->history) {					di->cur_hist = di->cur_hist->prev;					dlg_set_history(di);					goto dsp_f;				}				if (ev->x == KBD_DOWN && (void *)di->cur_hist != &di->history) {					di->cur_hist = di->cur_hist->next;					dlg_set_history(di);					goto dsp_f;				}				if (ev->x == KBD_RIGHT) {					if ((size_t)di->cpos < strlen(di->cdata)) {						if (!F) di->cpos++;#ifdef G						else {							int u;							unsigned char *p = di->cdata + di->cpos;							GET_UTF_8(p, u);							di->cpos = p - di->cdata;						}#endif					}					goto dsp_f;				}				if (ev->x == KBD_LEFT) {					if (di->cpos > 0) {						if (!F) di->cpos--;#ifdef G						else {							unsigned char *p = di->cdata + di->cpos;							BACK_UTF_8(p, di->cdata);							di->cpos = p - di->cdata;						}#endif					}					goto dsp_f;				}				if (ev->x == KBD_HOME || (upcase(ev->x) == 'A' && ev->y & KBD_CTRL)) {					di->cpos = 0;					goto dsp_f;				}				if (ev->x == KBD_END || (upcase(ev->x) == 'E' && ev->y & KBD_CTRL)) {					di->cpos = strlen(di->cdata);					goto dsp_f;				}				if (ev->x >= ' ' && !(ev->y & (KBD_CTRL | KBD_ALT))) {					unsigned char *u;					unsigned char p[2] = { 0, 0 };					if (!F) p[0] = ev->x, u = p;#ifdef G					else {						u = encode_utf_8(ev->x);					}#endif					if (strlen(di->cdata) < di->item->dlen - strlen(u)) {						memmove(di->cdata + di->cpos + strlen(u), di->cdata + di->cpos, strlen(di->cdata) - di->cpos + 1);						memcpy(&di->cdata[di->cpos], u, strlen(u));						di->cpos += strlen(u);					}					goto dsp_f;				}				if (ev->x == KBD_BS) {					if (di->cpos) {						int s = 1;#ifdef G						if (F) {							unsigned u;							unsigned char *p, *pp;							p = di->cdata;							a:							pp = p;							GET_UTF_8(p, u);							if (p < di->cdata + di->cpos) goto a;							s = p - pp;						}#endif						memmove(di->cdata + di->cpos - s, di->cdata + di->cpos, strlen(di->cdata) - di->cpos + s);						di->cpos -= s;					}					goto dsp_f;				}				if (ev->x == KBD_DEL || (upcase(ev->x) == 'D' && ev->y & KBD_CTRL)) {					if ((size_t)di->cpos < strlen(di->cdata)) {						int s = 1;#ifdef G						if (F) {							unsigned u;							unsigned char *p = di->cdata + di->cpos;							GET_UTF_8(p, u);							s = p - (di->cdata + di->cpos);						}#endif						memmove(di->cdata + di->cpos, di->cdata + di->cpos + s, strlen(di->cdata) - di->cpos + s);					}					goto dsp_f;				}				if (upcase(ev->x) == 'U' && ev->y & KBD_CTRL) {					char *a = memacpy(di->cdata, di->cpos);					if (a) {						set_clipboard_text(term, a);						mem_free(a);					}					memmove(di->cdata, di->cdata + di->cpos, strlen(di->cdata + di->cpos) + 1);					di->cpos = 0;					goto dsp_f;				}				if (upcase(ev->x) == 'K' && ev->y & KBD_CTRL) {					set_clipboard_text(term, di->cdata + di->cpos);					di->cdata[di->cpos] = 0;					goto dsp_f;				}				/* Copy to clipboard */				if ((ev->x == KBD_INS && ev->y & KBD_CTRL) || (upcase(ev->x) == 'Z' && ev->y & KBD_CTRL)) {					set_clipboard_text(term, di->cdata);					break;	/* We don't need to redraw */				}				/* FIXME -- why keyboard shortcuts with shift don't works??? */				/* Cut to clipboard */				if ((ev->x == KBD_DEL && ev->y & KBD_SHIFT) || (upcase(ev->x) == 'X' && ev->y & KBD_CTRL)) {					set_clipboard_text(term, di->cdata);					di->cdata[0] = 0;					di->cpos = 0;					goto dsp_f;				}				/* Paste from clipboard */				if ((ev->x == KBD_INS && ev->y & KBD_SHIFT) || (upcase(ev->x) == 'V' && ev->y & KBD_CTRL)) {					unsigned char * clipboard;clipbd_paste:					clipboard = get_clipboard_text(term);					if (clipboard) {						if (strlen(di->cdata) < di->item->dlen - strlen(clipboard)) {							memmove(di->cdata + di->cpos + strlen(clipboard), di->cdata + di->cpos, strlen(di->cdata) - di->cpos + 1);							memcpy(&di->cdata[di->cpos], clipboard, strlen(clipboard));							di->cpos += strlen(clipboard);						}						mem_free(clipboard);					}					goto dsp_f;				}				if (upcase(ev->x) == 'W' && ev->y & KBD_CTRL) {					do_tab_compl(term, &di->history, win);					goto dsp_f;				}				goto gh;				dsp_f:				x_display_dlg_item(dlg, di, 1);				break;			}			if ((ev->x == KBD_ENTER && di->item->type == D_BUTTON) || ev->x == ' ') {				dlg_select_item(dlg, di);				break;			}			gh:			if (ev->x > ' ') for (i = 0; i < dlg->n; i++)				if (dlg->dlg->items[i].type == D_BUTTON && upcase(_(dlg->dlg->items[i].text, term)[0]) == upcase(ev->x)) {					sel:					if (dlg->selected != i) {						x_display_dlg_item(dlg, &dlg->items[dlg->selected], 0);						x_display_dlg_item(dlg, &dlg->items[i], 1);						dlg->selected = i;					}					dlg_select_item(dlg, &dlg->items[i]);					goto bla;			}			if (ev->x == KBD_ENTER) for (i = 0; i < dlg->n; i++)				if (dlg->dlg->items[i].type == D_BUTTON && dlg->dlg->items[i].gid & B_ENTER) goto sel;			if (ev->x == KBD_ESC) for (i = 0; i < dlg->n; i++)				if (dlg->dlg->items[i].type == D_BUTTON && dlg->dlg->items[i].gid & B_ESC) goto sel;			if (((ev->x == KBD_TAB && !ev->y) || ev->x == KBD_DOWN || ev->x == KBD_RIGHT) && (dlg->n > 1 || term->spec->braille)) {				if (term->spec->braille) dlg->brl_y = dlg->items[0].y - 3;				x_display_dlg_item(dlg, &dlg->items[dlg->selected], 0);				if ((++dlg->selected) >= dlg->n) dlg->selected = 0;				x_display_dlg_item(dlg, &dlg->items[dlg->selected], 1);				break;			}			if (((ev->x == KBD_TAB && ev->y) || ev->x == KBD_UP || ev->x == KBD_LEFT) && (dlg->n > 1 || term->spec->braille)) {				if (term->spec->braille) dlg->brl_y = dlg->items[0].y - 3;				x_display_dlg_item(dlg, &dlg->items[dlg->selected], 0);				if ((--dlg->selected) < 0) dlg->selected = dlg->n - 1;				x_display_dlg_item(dlg, &dlg->items[dlg->selected], 1);				break;			}			break;		case EV_ABORT:		/* Moved this line up so that the dlg would have access to its 		   member vars before they get freed. */ 			if (dlg->dlg->abort) dlg->dlg->abort(dlg);			for (i = 0; i < dlg->n; i++) {				struct dialog_item_data *di = &dlg->items[i];				if (di->cdata) mem_free(di->cdata);				free_list(di->history);			}			freeml(dlg->ml);	}	bla:;}/* gid and gnum are 100 times greater than boundaries (e.g. if gid==1 boundary is 0.01) */int check_float(struct dialog_data *dlg, struct dialog_item_data *di){	unsigned char *end;	double d = strtod(di->cdata, (char **)(void *)&end);	if (!*di->cdata || *end) {		msg_box(dlg->win->term, NULL, TEXT(T_BAD_NUMBER), AL_CENTER, TEXT(T_NUMBER_EXPECTED), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);		return 1;	}	if (100*d < di->item->gid || 100*d > 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_number(struct dialog_data *dlg, struct dialog_item_data *di){	unsigned char *end;	long l = strtol(di->cdata, (char **)(void *)&end, 10);	if (!*di->cdata || *end) {		msg_box(dlg->win->term, NULL, TEXT(T_BAD_NUMBER), AL_CENTER, TEXT(T_NUMBER_EXPECTED), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);		return 1;	}	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_hex_number(struct dialog_data *dlg, struct dialog_item_data *di){	unsigned char *end;	long l = strtol(di->cdata, (char **)(void *)&end, 16);	if (!*di->cdata || *end) {		msg_box(dlg->win->term, NULL, TEXT(T_BAD_NUMBER), AL_CENTER, TEXT(T_NUMBER_EXPECTED), NULL, 1, TEXT(T_CANCEL), NULL, B_ENTER | B_ESC);		return 1;

⌨️ 快捷键说明

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