"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "bfu.c" between
links-1.03.tar.gz and links-1.04.tar.gz

About: Links is a Lynx-like text WWW browser (table support and pop-up dialog boxes).

bfu.c  (links-1.03):bfu.c  (links-1.04)
skipping to change at line 64 skipping to change at line 64
for (i = 0; i < ml->n; i++) mem_free(ml->p[i]); for (i = 0; i < ml->n; i++) mem_free(ml->p[i]);
mem_free(ml); mem_free(ml);
} }
unsigned char m_bar = 0; unsigned char m_bar = 0;
void menu_func(struct window *, struct event *, int); void menu_func(struct window *, struct event *, int);
void mainmenu_func(struct window *, struct event *, int); void mainmenu_func(struct window *, struct event *, int);
void dialog_func(struct window *, struct event *, int); void dialog_func(struct window *, struct event *, int);
void do_menu_selected(struct terminal *term, struct menu_item *items, void *data , int selected) unsigned char select_hotkey(struct terminal *term, unsigned char *text, unsigned char *hotkey, unsigned char *hotkeys, int n)
{ {
unsigned char c;
if (hotkey == M_BAR) return 0;
if (text) {
text = stracpy(_(text, term));
charset_upcase_string(&text, term->spec->charset);
}
hotkey = _(hotkey, term);
while (1) {
int i;
c = *hotkey++;
if (!c) break;
c = charset_upcase(c, term->spec->charset);
for (i = 0; i < n; i++) if (hotkeys[i] == c) goto cont;
if (!text || strchr(text, c)) break;
cont:;
}
if (text) mem_free(text);
return c;
}
void do_menu_selected(struct terminal *term, struct menu_item *items, void *data
, int selected, void (*free_function)(void *), void *free_data)
{
int i;
struct menu *menu; struct menu *menu;
menu = mem_alloc(sizeof(struct menu)); for (i = 0; items[i].text; i++) if (i == MAXINT - sizeof(struct menu)) ov
eralloc();
menu = mem_alloc(sizeof(struct menu) + (!i ? 0 : i - 1));
menu->selected = selected; menu->selected = selected;
menu->view = 0; menu->view = 0;
menu->ni = i;
menu->items = items; menu->items = items;
menu->data = data; menu->data = data;
menu->free_function = free_function;
menu->free_data = free_data;
for (i = 0; i < menu->ni; i++)
menu->hotkeys[i] = select_hotkey(term, items[i].text, items[i].ho
tkey, menu->hotkeys, i);
add_window(term, menu_func, menu); add_window(term, menu_func, menu);
} }
void do_menu(struct terminal *term, struct menu_item *items, void *data) void do_menu(struct terminal *term, struct menu_item *items, void *data)
{ {
do_menu_selected(term, items, data, 0); do_menu_selected(term, items, data, 0, NULL, NULL);
} }
void select_menu(struct terminal *term, struct menu *menu) void select_menu(struct terminal *term, struct menu *menu)
{ {
/*int x = menu->x + 4; struct menu_item *it;
int y = menu->y + menu->selected - menu->view + 2;*/ void (*func)(struct terminal *, void *, void *);
struct menu_item *it = &menu->items[menu->selected]; void *data1;
void (*func)(struct terminal *, void *, void *) = it->func; void *data2;
void *data1 = it->data; if (menu->selected < 0 || menu->selected >= menu->ni) return;
void *data2 = menu->data; it = &menu->items[menu->selected];
if (menu->selected < 0 || menu->selected >= menu->ni || it->hotkey == M_B func = it->func;
AR) return; data1 = it->data;
data2 = menu->data;
if (it->hotkey == M_BAR) return;
if (!it->in_m) { if (!it->in_m) {
struct window *win, *win1; struct window *win, *win1;
for (win = term->windows.next; (void *)win != &term->windows && ( win->handler == menu_func || win->handler == mainmenu_func); win1 = win->next, d elete_window(win), win = win1) ; for (win = term->windows.next; (void *)win != &term->windows && ( win->handler == menu_func || win->handler == mainmenu_func); win1 = win->next, d elete_window(win), win = win1) ;
} }
func(term, data1, data2); func(term, data1, data2);
} }
void count_menu_size(struct terminal *term, struct menu *menu) void count_menu_size(struct terminal *term, struct menu *menu)
{ {
int sx = term->x; int sx = term->x;
int sy = term->y; int sy = term->y;
int mx = 4; int mx = 4;
int my; int my;
for (my = 0; menu->items[my].text; my++) { for (my = 0; my < menu->ni; my++) {
int s = strlen(_(menu->items[my].text, term)) + strlen(_(menu->it ems[my].rtext, term)) + MENU_HOTKEY_SPACE * (_(menu->items[my].rtext, term)[0] ! = 0) + 4; int s = strlen(_(menu->items[my].text, term)) + strlen(_(menu->it ems[my].rtext, term)) + MENU_HOTKEY_SPACE * (_(menu->items[my].rtext, term)[0] ! = 0) + 4;
if (s > mx) mx = s; if (s > mx) mx = s;
} }
menu->ni = my;
my += 2; my += 2;
if (mx > sx) mx = sx; if (mx > sx) mx = sx;
if (my > sy) my = sy; if (my > sy) my = sy;
menu->xw = mx; menu->xw = mx;
menu->yw = my; menu->yw = my;
if ((menu->x = menu->xp) < 0) menu->x = 0; if ((menu->x = menu->xp) < 0) menu->x = 0;
if ((menu->y = menu->yp) < 0) menu->y = 0; if ((menu->y = menu->yp) < 0) menu->y = 0;
if (menu->x + mx > sx) menu->x = sx - mx; if (menu->x + mx > sx) menu->x = sx - mx;
if (menu->y + my > sy) menu->y = sy - my; if (menu->y + my > sy) menu->y = sy - my;
} }
skipping to change at line 150 skipping to change at line 180
if (menu->selected < menu->view + scr_i) menu->view = menu->selected - sc r_i; if (menu->selected < menu->view + scr_i) menu->view = menu->selected - sc r_i;
if (menu->selected >= menu->view + w - scr_i - 1) menu->view = menu->sele cted - w + scr_i + 1; if (menu->selected >= menu->view + w - scr_i - 1) menu->view = menu->sele cted - w + scr_i + 1;
if (menu->view > menu->ni - w) menu->view = menu->ni - w; if (menu->view > menu->ni - w) menu->view = menu->ni - w;
if (menu->view < 0) menu->view = 0; if (menu->view < 0) menu->view = 0;
/*debug("2:%d %d %d %d", menu->ni, w, menu->view, menu->selected);*/ /*debug("2:%d %d %d %d", menu->ni, w, menu->view, menu->selected);*/
} }
void display_menu(struct terminal *term, struct menu *menu) void display_menu(struct terminal *term, struct menu *menu)
{ {
int p, s; int p, s;
fill_area(term, menu->x+1, menu->y+1, menu->xw-2, menu->yw-2, COLOR_MENU) ; fill_area(term, menu->x+1, menu->y+1, menu->xw-2, menu->yw-2, COLOR_MENU_ TEXT | ' ');
draw_frame(term, menu->x, menu->y, menu->xw, menu->yw, COLOR_MENU_FRAME, 1); draw_frame(term, menu->x, menu->y, menu->xw, menu->yw, COLOR_MENU_FRAME, 1);
for (p = menu->view, s = menu->y + 1; p < menu->ni && p < menu->view + me nu->yw - 2; p++, s++) { for (p = menu->view, s = menu->y + 1; p < menu->ni && p < menu->view + me nu->yw - 2; p++, s++) {
int x; int x;
int h = 0; int h = 0;
unsigned char c; unsigned char c;
unsigned char *tmptext = _(menu->items[p].text, term); unsigned char *tmptext = _(menu->items[p].text, term);
int co = p == menu->selected ? h = 1, COLOR_MENU_SELECTED : COLOR _MENU; int co = p == menu->selected ? h = 1, COLOR_MENU_SELECTED : COLOR _MENU_TEXT;
if (h) { if (h) {
set_cursor(term, menu->x+1, s, term->x - 1, term->y - 1); set_cursor(term, menu->x+1, s, term->x - 1, term->y - 1);
/*set_window_ptr(menu->win, menu->x+3, s+1);*/ /*set_window_ptr(menu->win, menu->x+3, s+1);*/
set_window_ptr(menu->win, menu->x+menu->xw, s); set_window_ptr(menu->win, menu->x+menu->xw, s);
fill_area(term, menu->x+1, s, menu->xw-2, 1, co); fill_area(term, menu->x+1, s, menu->xw-2, 1, co | ' ');
} }
if (menu->items[p].hotkey != M_BAR || (tmptext && tmptext[0])) { if (menu->items[p].hotkey != M_BAR || (tmptext && tmptext[0])) {
int l = strlen(_(menu->items[p].rtext, term)); int l = strlen(_(menu->items[p].rtext, term));
for (x = l - 1; x >= 0 && menu->xw - 4 >= l - x && (c = _ (menu->items[p].rtext, term)[x]); x--) for (x = l - 1; x >= 0 && menu->xw - 4 >= l - x && (c = _ (menu->items[p].rtext, term)[x]); x--)
set_char(term, menu->x + menu->xw - 2 - l + x, s, c | co); set_char(term, menu->x + menu->xw - 2 - l + x, s, c | co);
for (x = 0; x < menu->xw - 4 && (c = tmptext[x]); x++) for (x = 0; x < menu->xw - 4 && (c = tmptext[x]); x++)
set_char(term, menu->x + x + 2, s, !h && strchr(_ (menu->items[p].hotkey, term), upcase(c)) ? h = 1, COLOR_MENU_HOTKEY | c : co | c); set_char(term, menu->x + x + 2, s, !h && charset_ upcase(c, term->spec->charset) == menu->hotkeys[p] ? h = 1, COLOR_MENU_HOTKEY | c : co | c);
} else { } else {
set_char(term, menu->x, s, COLOR_MENU_FRAME | ATTR_FRAME | 0xc3); set_char(term, menu->x, s, COLOR_MENU_FRAME | ATTR_FRAME | 0xc3);
fill_area(term, menu->x+1, s, menu->xw-2, 1, COLOR_MENU_F RAME | ATTR_FRAME | 0xc4); fill_area(term, menu->x+1, s, menu->xw-2, 1, COLOR_MENU_F RAME | ATTR_FRAME | 0xc4);
set_char(term, menu->x+menu->xw-1, s, COLOR_MENU_FRAME | ATTR_FRAME | 0xb4); set_char(term, menu->x+menu->xw-1, s, COLOR_MENU_FRAME | ATTR_FRAME | 0xb4);
} }
} }
redraw_from_window(menu->win); redraw_from_window(menu->win);
} }
void menu_func(struct window *win, struct event *ev, int fwd) void menu_func(struct window *win, struct event *ev, int fwd)
skipping to change at line 259 skipping to change at line 289
mm: mm:
delete_window_ev(win, ev); delete_window_ev(win, ev);
goto break2; goto break2;
} }
if (ev->x == KBD_ESC) { if (ev->x == KBD_ESC) {
delete_window_ev(win, (void *)win ->next != &win->term->windows && win->next->handler == mainmenu_func ? ev : NULL ); delete_window_ev(win, (void *)win ->next != &win->term->windows && win->next->handler == mainmenu_func ? ev : NULL );
goto break2; goto break2;
} }
if (ev->x > ' ' && ev->x < 256) { if (ev->x > ' ' && ev->x < 256) {
int i; int i;
for (i = 0; i < menu->ni; i++) for (i = 0; i < menu->ni; i++) {
if (strchr(_(menu->items[ if (charset_upcase(ev->x,
i].hotkey, win->term), upcase(ev->x))) { win->term->spec->charset) == menu->hotkeys[i]) {
menu->selected = i; menu->selected = i;
scroll_menu(menu, 0); scroll_menu(menu, 0);
s = 1; s = 1;
} }
}
} }
break; break;
} }
display_menu(win->term, menu); display_menu(win->term, menu);
if (s || ev->x == KBD_ENTER || ev->x == ' ') { if (s || ev->x == KBD_ENTER || ev->x == ' ') {
enter: enter:
select_menu(win->term, menu); select_menu(win->term, menu);
} }
break2: break2:
break; break;
case EV_ABORT: case EV_ABORT:
if (menu->items->free_i) { if (menu->items->free_i) {
int i; int i;
for (i = 0; menu->items[i].text; i++) { for (i = 0; i < menu->ni; i++) {
if (menu->items[i].free_i & 2) mem_free(m enu->items[i].text); if (menu->items[i].free_i & 2) mem_free(m enu->items[i].text);
if (menu->items[i].free_i & 4) mem_free(m enu->items[i].rtext); if (menu->items[i].free_i & 4) mem_free(m enu->items[i].rtext);
} }
mem_free(menu->items); mem_free(menu->items);
} }
if (menu->free_function)
register_bottom_half(menu->free_function, menu->f
ree_data);
break; break;
} }
} }
void do_mainmenu(struct terminal *term, struct menu_item *items, void *data, int sel) void do_mainmenu(struct terminal *term, struct menu_item *items, void *data, int sel)
{ {
int i;
struct mainmenu *menu; struct mainmenu *menu;
menu = mem_alloc(sizeof(struct mainmenu)); for (i = 0; items[i].text; i++) if (i == MAXINT - sizeof(struct mainmenu)
) overalloc();
menu = mem_alloc(sizeof(struct mainmenu) + (!i ? 0 : i - 1));
menu->selected = sel == -1 ? 0 : sel; menu->selected = sel == -1 ? 0 : sel;
menu->ni = i;
menu->items = items; menu->items = items;
menu->data = data; menu->data = data;
for (i = 0; i < menu->ni; i++)
menu->hotkeys[i] = select_hotkey(term, NULL, items[i].hotkey, men
u->hotkeys, i);
add_window(term, mainmenu_func, menu); add_window(term, mainmenu_func, menu);
if (sel != -1) { if (sel != -1) {
struct event ev = {EV_KBD, KBD_ENTER, 0, 0}; struct event ev = {EV_KBD, KBD_ENTER, 0, 0};
struct window *win = term->windows.next; struct window *win = term->windows.next;
win->handler(win, &ev, 0); win->handler(win, &ev, 0);
} }
} }
void display_mainmenu(struct terminal *term, struct mainmenu *menu) void display_mainmenu(struct terminal *term, struct mainmenu *menu)
{ {
int i; int i;
int p = 2; int p = 2;
fill_area(term, 0, 0, term->x, 1, COLOR_MAINMENU | ' '); fill_area(term, 0, 0, term->x, 1, COLOR_MAINMENU | ' ');
for (i = 0; menu->items[i].text; i++) { for (i = 0; i < menu->ni; i++) {
int s = 0; int s = 0;
int j; int j;
unsigned char c; unsigned char c;
unsigned char *tmptext = _(menu->items[i].text, term); unsigned char *tmptext = _(menu->items[i].text, term);
int co = i == menu->selected ? s = 1, COLOR_MAINMENU_SELECTED : C OLOR_MAINMENU; int co = i == menu->selected ? s = 1, COLOR_MAINMENU_SELECTED : C OLOR_MAINMENU;
if (s) { if (s) {
fill_area(term, p, 0, 2, 1, co); fill_area(term, p, 0, 2, 1, co | ' ');
fill_area(term, p+strlen(tmptext)+2, 0, 2, 1, co); fill_area(term, p+strlen(tmptext)+2, 0, 2, 1, co | ' ');
menu->sp = p; menu->sp = p;
set_cursor(term, p, 0, term->x - 1, term->y - 1); set_cursor(term, p, 0, term->x - 1, term->y - 1);
set_window_ptr(menu->win, p, 1); set_window_ptr(menu->win, p, 1);
} }
p += 2; p += 2;
for (j = 0; (c = tmptext[j]); j++, p++) for (j = 0; (c = tmptext[j]); j++, p++)
set_char(term, p, 0, (!s && strchr(_(menu->items[i].hotke y, term), upcase(c)) ? s = 1, COLOR_MAINMENU_HOTKEY : co) | c); set_char(term, p, 0, (!s && charset_upcase(c, term->spec- >charset) == menu->hotkeys[i] ? s = 1, COLOR_MAINMENU_HOTKEY : co) | c);
p += 2; p += 2;
} }
menu->ni = i;
redraw_from_window(menu->win); redraw_from_window(menu->win);
} }
void select_mainmenu(struct terminal *term, struct mainmenu *menu) void select_mainmenu(struct terminal *term, struct mainmenu *menu)
{ {
struct menu_item *it = &menu->items[menu->selected]; struct menu_item *it;
if (menu->selected < 0 || menu->selected >= menu->ni || it->hotkey == M_B if (menu->selected < 0 || menu->selected >= menu->ni) return;
AR) return; it = &menu->items[menu->selected];
if (it->hotkey == M_BAR) return;
if (!it->in_m) { if (!it->in_m) {
struct window *win, *win1; struct window *win, *win1;
for (win = term->windows.next; (void *)win != &term->windows && ( win->handler == menu_func || win->handler == mainmenu_func); win1 = win->next, d elete_window(win), win = win1) ; for (win = term->windows.next; (void *)win != &term->windows && ( win->handler == menu_func || win->handler == mainmenu_func); win1 = win->next, d elete_window(win), win = win1) ;
} }
it->func(term, it->data, menu->data); it->func(term, it->data, menu->data);
} }
void mainmenu_func(struct window *win, struct event *ev, int fwd) void mainmenu_func(struct window *win, struct event *ev, int fwd)
{ {
int s = 0; int s = 0;
skipping to change at line 399 skipping to change at line 438
s = 1; s = 1;
} }
if ((ev->x == KBD_LEFT || ev->x == KBD_RIGHT) && fwd) { if ((ev->x == KBD_LEFT || ev->x == KBD_RIGHT) && fwd) {
display_mainmenu(win->term, menu); display_mainmenu(win->term, menu);
select_mainmenu(win->term, menu); select_mainmenu(win->term, menu);
break; break;
} }
if (ev->x > ' ' && ev->x < 256) { if (ev->x > ' ' && ev->x < 256) {
int i; int i;
s = 1; s = 1;
for (i = 0; i < menu->ni; i++) for (i = 0; i < menu->ni; i++) {
if (strchr(_(menu->items[i].hotkey, win-> if (charset_upcase(ev->x, win->term->spec
term), upcase(ev->x))) { ->charset) == menu->hotkeys[i]) {
menu->selected = i; menu->selected = i;
s = 2; s = 2;
} }
}
} else if (!s) { } else if (!s) {
delete_window_ev(win, (ev->x >= KBD_F1 && ev->x < = KBD_F12) || ev->y & KBD_ALT ? ev : NULL); delete_window_ev(win, (ev->x >= KBD_F1 && ev->x < = KBD_F12) || ev->y & KBD_ALT ? ev : NULL);
break; break;
} }
display_mainmenu(win->term, menu); display_mainmenu(win->term, menu);
if (s == 2) select_mainmenu(win->term, menu); if (s == 2) select_mainmenu(win->term, menu);
break; break;
case EV_ABORT: case EV_ABORT:
break; break;
} }
skipping to change at line 478 skipping to change at line 518
if (sel) { if (sel) {
set_cursor(term, di->x + 1, di->y, di->x + 1, di- >y); set_cursor(term, di->x + 1, di->y, di->x + 1, di- >y);
set_window_ptr(dlg->win, di->x, di->y); set_window_ptr(dlg->win, di->x, di->y);
} }
break; break;
case D_FIELD_PASS: case D_FIELD_PASS:
case D_FIELD: case D_FIELD:
if (di->vpos + di->l <= di->cpos) di->vpos = di->cpos - d i->l + 1; if (di->vpos + di->l <= di->cpos) di->vpos = di->cpos - d i->l + 1;
if (di->vpos > di->cpos) di->vpos = di->cpos; if (di->vpos > di->cpos) di->vpos = di->cpos;
if (di->vpos < 0) di->vpos = 0; if (di->vpos < 0) di->vpos = 0;
fill_area(term, di->x, di->y, di->l, 1, COLOR_DIALOG_FIEL D); fill_area(term, di->x, di->y, di->l, 1, COLOR_DIALOG_FIEL D | ' ');
if (di->item->type == D_FIELD) { if (di->item->type == D_FIELD) {
print_text(term, di->x, di->y, strlen(di->cdata + di->vpos) <= (size_t)di->l ? (int)strlen(di->cdata + di->vpos) : di->l, di->cda ta + di->vpos, COLOR_DIALOG_FIELD_TEXT); print_text(term, di->x, di->y, strlen(di->cdata + di->vpos) <= (size_t)di->l ? (int)strlen(di->cdata + di->vpos) : di->l, di->cda ta + di->vpos, COLOR_DIALOG_FIELD_TEXT);
} else { } else {
fill_area(term, di->x, di->y, strlen(di->cdata + di->vpos) <= (size_t)di->l ? (int)strlen(di->cdata + di->vpos) : di->l, 1, COLOR _DIALOG_FIELD_TEXT | '*'); fill_area(term, di->x, di->y, strlen(di->cdata + di->vpos) <= (size_t)di->l ? (int)strlen(di->cdata + di->vpos) : di->l, 1, COLOR _DIALOG_FIELD_TEXT | '*');
} }
if (sel) { if (sel) {
set_cursor(term, di->x + di->cpos - di->vpos, di- >y, di->x + di->cpos - di->vpos, di->y); set_cursor(term, di->x + di->cpos - di->vpos, di- >y, di->x + di->cpos - di->vpos, di->y);
set_window_ptr(dlg->win, di->x, di->y); set_window_ptr(dlg->win, di->x, di->y);
} }
break; break;
skipping to change at line 532 skipping to change at line 572
di->checked = 1; di->checked = 1;
} }
display_dlg_item(dlg, di, 1); display_dlg_item(dlg, di, 1);
} }
else if (di->item->type == D_BUTTON) di->item->fn(dlg, di); else if (di->item->type == D_BUTTON) di->item->fn(dlg, di);
} }
void dlg_set_history(struct dialog_item_data *di) void dlg_set_history(struct dialog_item_data *di)
{ {
unsigned char *s = ""; unsigned char *s = "";
int l; size_t l;
if ((void *)di->cur_hist != &di->history) s = di->cur_hist->d; if ((void *)di->cur_hist != &di->history) s = di->cur_hist->d;
if ((l = strlen(s)) > di->item->dlen) l = di->item->dlen - 1; if ((l = strlen(s)) >= (size_t)di->item->dlen) l = di->item->dlen - 1;
memcpy(di->cdata, s, l); memcpy(di->cdata, s, l);
di->cdata[l] = 0; di->cdata[l] = 0;
di->cpos = l; di->cpos = l;
di->vpos = 0; di->vpos = 0;
} }
int dlg_mouse(struct dialog_data *dlg, struct dialog_item_data *di, struct event *ev) int dlg_mouse(struct dialog_data *dlg, struct dialog_item_data *di, struct event *ev)
{ {
switch (di->item->type) { switch (di->item->type) {
case D_BUTTON: case D_BUTTON:
skipping to change at line 600 skipping to change at line 640
print_text(term, (dlg->xw - i) / 2 + dlg->x, dlg->y + DIALOG_TOP_BORDER, i, _(dlg->dlg->title, term), COLOR_DIALOG_TITLE); print_text(term, (dlg->xw - i) / 2 + dlg->x, dlg->y + DIALOG_TOP_BORDER, i, _(dlg->dlg->title, term), COLOR_DIALOG_TITLE);
print_text(term, (dlg->xw - i) / 2 + dlg->x + i, dlg->y + DIALOG_TOP_BORD ER, 1, " ", COLOR_DIALOG_TITLE); print_text(term, (dlg->xw - i) / 2 + dlg->x + i, dlg->y + DIALOG_TOP_BORD ER, 1, " ", COLOR_DIALOG_TITLE);
for (i = 0; i < dlg->n; i++) display_dlg_item(dlg, &dlg->items[i], i == d lg->selected); for (i = 0; i < dlg->n; i++) display_dlg_item(dlg, &dlg->items[i], i == d lg->selected);
redraw_from_window(dlg->win); redraw_from_window(dlg->win);
} }
void tab_compl(struct terminal *term, unsigned char *item, struct window *win) void tab_compl(struct terminal *term, unsigned char *item, struct window *win)
{ {
struct event ev = {EV_REDRAW, 0, 0, 0}; 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]; struct dialog_item_data *di = &((struct dialog_data*)win->data)->items[(( struct dialog_data*)win->data)->selected];
int l = strlen(item); size_t l = strlen(item);
if (l >= di->item->dlen) l = di->item->dlen - 1; if (l >= (size_t)di->item->dlen) l = di->item->dlen - 1;
memcpy(di->cdata, item, l); memcpy(di->cdata, item, l);
di->cdata[l] = 0; di->cdata[l] = 0;
di->cpos = l; di->cpos = l;
di->vpos = 0; di->vpos = 0;
ev.x = term->x; ev.x = term->x;
ev.y = term->y; ev.y = term->y;
dialog_func(win, &ev, 0); dialog_func(win, &ev, 0);
} }
void do_tab_compl(struct terminal *term, struct list_head *history, struct windo w *win) void do_tab_compl(struct terminal *term, struct list_head *history, struct windo w *win)
skipping to change at line 640 skipping to change at line 680
if (n == MAXINT) overalloc(); if (n == MAXINT) overalloc();
n++; n++;
} }
if (n == 1) { if (n == 1) {
tab_compl(term, items->data, win); tab_compl(term, items->data, win);
mem_free(items); mem_free(items);
return; return;
} }
if (n) { if (n) {
memset(&items[n], 0, sizeof(struct menu_item)); memset(&items[n], 0, sizeof(struct menu_item));
do_menu_selected(term, items, win, n - 1); do_menu_selected(term, items, win, n - 1, NULL, NULL);
} }
} }
void dialog_func(struct window *win, struct event *ev, int fwd) void dialog_func(struct window *win, struct event *ev, int fwd)
{ {
int i; int i;
struct terminal *term = win->term; struct terminal *term = win->term;
struct dialog_data *dlg = win->data; struct dialog_data *dlg = win->data;
struct dialog_item_data *di; struct dialog_item_data *di;
skipping to change at line 686 skipping to change at line 726
((struct dlg_data_item_data_box*)di->cdat a)->box_top = 0; ((struct dlg_data_item_data_box*)di->cdat a)->box_top = 0;
((struct dlg_data_item_data_box*)di->cdat a)->list_len = -1; ((struct dlg_data_item_data_box*)di->cdat a)->list_len = -1;
init_list(((struct dlg_data_item_data_box *)di->cdata)->items); init_list(((struct dlg_data_item_data_box *)di->cdata)->items);
} }
init_list(di->history); init_list(di->history);
di->cur_hist = (struct history_item *)&di->histor y; di->cur_hist = (struct history_item *)&di->histor y;
if (di->item->type == D_FIELD || di->item->type = = D_FIELD_PASS) { if (di->item->type == D_FIELD || di->item->type = = D_FIELD_PASS) {
if (di->item->history) { if (di->item->history) {
struct history_item *j; struct history_item *j;
/*int l = di->item->dlen;*/
foreach(j, di->item->history->ite ms) { foreach(j, di->item->history->ite ms) {
struct history_item *hi; struct history_item *hi;
hi = mem_alloc(sizeof(str uct history_item) + strlen(j->d) + 1); hi = mem_alloc(sizeof(str uct history_item) + strlen(j->d) + 1);
strcpy(hi->d, j->d); strcpy(hi->d, j->d);
add_to_list(di->history, hi); add_to_list(di->history, hi);
} }
} }
di->cpos = strlen(di->cdata); di->cpos = strlen(di->cdata);
} }
} }
dlg->selected = 0; dlg->selected = 0;
/*-fallthrough*/
case EV_RESIZE: case EV_RESIZE:
case EV_REDRAW: case EV_REDRAW:
dlg->dlg->fn(dlg); dlg->dlg->fn(dlg);
redraw_dialog(dlg); redraw_dialog(dlg);
break; break;
case EV_MOUSE: case EV_MOUSE:
for (i = 0; i < dlg->n; i++) if (dlg_mouse(dlg, &dlg->ite ms[i], ev)) break; for (i = 0; i < dlg->n; i++) if (dlg_mouse(dlg, &dlg->ite ms[i], ev)) break;
break; break;
case EV_KBD: case EV_KBD:
di = &dlg->items[dlg->selected]; di = &dlg->items[dlg->selected];
skipping to change at line 765 skipping to change at line 805
set_clipboard_text(di->cdata); set_clipboard_text(di->cdata);
break; /* We don't need to redra w */ break; /* We don't need to redra w */
case ACT_CUT_CLIPBOARD: case ACT_CUT_CLIPBOARD:
/* Cut to clipboard */ /* Cut to clipboard */
set_clipboard_text(di->cdata); set_clipboard_text(di->cdata);
di->cdata[0] = 0; di->cdata[0] = 0;
di->cpos = 0; di->cpos = 0;
goto dsp_f; goto dsp_f;
case ACT_PASTE_CLIPBOARD: { case ACT_PASTE_CLIPBOARD: {
/* Paste from clipboard */ /* Paste from clipboard */
unsigned char * clipboard = get_c lipboard_text(); unsigned char *clipboard = get_cl ipboard_text();
if (clipboard) { if (clipboard) {
unsigned char *nl = clipb
oard;
while ((nl = strchr(nl, '
\n'))) *nl = ' ';
safe_strncpy(di->cdata, c lipboard, di->item->dlen); safe_strncpy(di->cdata, c lipboard, di->item->dlen);
di->cpos = strlen(di->cda ta); di->cpos = strlen(di->cda ta);
mem_free(clipboard); mem_free(clipboard);
} }
goto dsp_f; goto dsp_f;
} }
case ACT_AUTO_COMPLETE: case ACT_AUTO_COMPLETE:
do_tab_compl(term, &di->history, win); do_tab_compl(term, &di->history, win);
goto dsp_f; goto dsp_f;
default: default:
skipping to change at line 797 skipping to change at line 839
display_dlg_item(dlg, di, 1); display_dlg_item(dlg, di, 1);
redraw_from_window(dlg->win); redraw_from_window(dlg->win);
break; break;
} }
if ((ev->x == KBD_ENTER && di->item->type == D_BUTTON) || ev->x == ' ') { if ((ev->x == KBD_ENTER && di->item->type == D_BUTTON) || ev->x == ' ') {
dlg_select_item(dlg, di); dlg_select_item(dlg, di);
break; break;
} }
gh: gh:
if (ev->x > ' ' && ev->x < 0x100) for (i = 0; i < dlg->n; i++) if (ev->x > ' ' && ev->x < 0x100) 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)) { if (dlg->dlg->items[i].type == D_BUTTON && charse t_upcase(_(dlg->dlg->items[i].text, term)[0], term->spec->charset) == charset_up case(ev->x, term->spec->charset)) {
sel: sel:
if (dlg->selected != i) { if (dlg->selected != i) {
display_dlg_item(dlg, &dlg->items [dlg->selected], 0); display_dlg_item(dlg, &dlg->items [dlg->selected], 0);
display_dlg_item(dlg, &dlg->items [i], 1); display_dlg_item(dlg, &dlg->items [i], 1);
dlg->selected = i; dlg->selected = i;
} }
dlg_select_item(dlg, &dlg->items[i]); dlg_select_item(dlg, &dlg->items[i]);
goto bla; goto bla;
} }
if (ev->x == KBD_ENTER) for (i = 0; i < dlg->n; i++) if (ev->x == KBD_ENTER) for (i = 0; i < dlg->n; i++)
skipping to change at line 914 skipping to change at line 956
} }
void center_dlg(struct dialog_data *dlg) void center_dlg(struct dialog_data *dlg)
{ {
dlg->x = (dlg->win->term->x - dlg->xw) / 2; dlg->x = (dlg->win->term->x - dlg->xw) / 2;
dlg->y = (dlg->win->term->y - dlg->yw) / 2; dlg->y = (dlg->win->term->y - dlg->yw) / 2;
} }
void draw_dlg(struct dialog_data *dlg) void draw_dlg(struct dialog_data *dlg)
{ {
fill_area(dlg->win->term, dlg->x, dlg->y, dlg->xw, dlg->yw, COLOR_DIALOG) ; fill_area(dlg->win->term, dlg->x, dlg->y, dlg->xw, dlg->yw, COLOR_DIALOG | ' ');
} }
void max_text_width(struct terminal *term, unsigned char *text, int *width) void max_text_width(struct terminal *term, unsigned char *text, int *width)
{ {
text = _(text, term); text = _(text, term);
do { do {
int c = 0; int c = 0;
while (*text && *text != '\n') text++, c++; while (*text && *text != '\n') text++, c++;
if (c > *width) *width = c; if (c > *width) *width = c;
} while (*(text++)); } while (*(text++));
skipping to change at line 1051 skipping to change at line 1093
*w += 4; *w += 4;
texts++; texts++;
} }
} }
void dlg_format_field(struct terminal *term, struct terminal *t2, struct dialog_ item_data *item, int x, int *y, int w, int *rw, int align) void dlg_format_field(struct terminal *term, struct terminal *t2, struct dialog_ item_data *item, int x, int *y, int w, int *rw, int align)
{ {
item->x = x; item->x = x;
item->y = *y; item->y = *y;
item->l = w; item->l = w;
/*if ((item->l = w) > item->item->dlen - 1) item->l = item->item->dlen - 1;*/
if (rw && item->l > *rw) if ((*rw = item->l) > w) *rw = w; if (rw && item->l > *rw) if ((*rw = item->l) > w) *rw = w;
(*y)++; (*y)++;
} }
/* Layout for generic boxes */ /* Layout for generic boxes */
void dlg_format_box(struct terminal *term, struct terminal *t2, struct dialog_it em_data *item, int x, int *y, int w, int *rw, int align) { void dlg_format_box(struct terminal *term, struct terminal *t2, struct dialog_it em_data *item, int x, int *y, int w, int *rw, int align) {
item->x = x; item->x = x;
item->y = *y; item->y = *y;
item->l = w; item->l = w;
if (rw && item->l > *rw) if ((*rw = item->l) > w) *rw = w; if (rw && item->l > *rw) if ((*rw = item->l) > w) *rw = w;
skipping to change at line 1222 skipping to change at line 1263
int msg_box_button(struct dialog_data *dlg, struct dialog_item_data *di) int msg_box_button(struct dialog_data *dlg, struct dialog_item_data *di)
{ {
void (*fn)(void *) = (void (*)(void *))di->item->udata; void (*fn)(void *) = (void (*)(void *))di->item->udata;
void *data = dlg->dlg->udata2; void *data = dlg->dlg->udata2;
/*struct dialog *dl = dlg->dlg;*/ /*struct dialog *dl = dlg->dlg;*/
if (fn) fn(data); if (fn) fn(data);
cancel_dialog(dlg, di); cancel_dialog(dlg, di);
return 0; return 0;
} }
/* coverity[+free : arg-1] */
void msg_box(struct terminal *term, struct memory_list *ml, unsigned char *title , int align, /*unsigned char *text, void *data, int n,*/ ...) void msg_box(struct terminal *term, struct memory_list *ml, unsigned char *title , int align, /*unsigned char *text, void *data, int n,*/ ...)
{ {
struct dialog *dlg; struct dialog *dlg;
int i; int i;
int n; int n;
unsigned char *text; unsigned char *text;
unsigned char **udata; unsigned char **udata;
void *udata2; void *udata2;
int udatan; int udatan;
va_list ap; va_list ap;
skipping to change at line 1364 skipping to change at line 1406
dlg->yw = y + 2 * DIALOG_TB; dlg->yw = y + 2 * DIALOG_TB;
center_dlg(dlg); center_dlg(dlg);
draw_dlg(dlg); draw_dlg(dlg);
y = dlg->y + DIALOG_TB; y = dlg->y + DIALOG_TB;
dlg_format_text(term, term, dlg->dlg->udata, dlg->x + DIALOG_LB, &y, w, N ULL, COLOR_DIALOG_TEXT, AL_LEFT); dlg_format_text(term, term, dlg->dlg->udata, dlg->x + DIALOG_LB, &y, w, N ULL, COLOR_DIALOG_TEXT, AL_LEFT);
dlg_format_field(term, term, dlg->items, dlg->x + DIALOG_LB, &y, w, NULL, AL_LEFT); dlg_format_field(term, term, dlg->items, dlg->x + DIALOG_LB, &y, w, NULL, AL_LEFT);
y++; y++;
dlg_format_buttons(term, term, dlg->items + 1, 2, dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER); dlg_format_buttons(term, term, dlg->items + 1, 2, dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
} }
/* coverity[+free : arg-1] */
void input_field(struct terminal *term, struct memory_list *ml, unsigned char *t itle, unsigned char *text, unsigned char *okbutton, unsigned char *cancelbutton, void *data, struct history *history, int l, unsigned char *def, int min, int ma x, int (*check)(struct dialog_data *, struct dialog_item_data *), void (*fn)(voi d *, unsigned char *), void (*cancelfn)(void *)) void input_field(struct terminal *term, struct memory_list *ml, unsigned char *t itle, unsigned char *text, unsigned char *okbutton, unsigned char *cancelbutton, void *data, struct history *history, int l, unsigned char *def, int min, int ma x, int (*check)(struct dialog_data *, struct dialog_item_data *), void (*fn)(voi d *, unsigned char *), void (*cancelfn)(void *))
{ {
struct dialog *dlg; struct dialog *dlg;
unsigned char *field; unsigned char *field;
if ((unsigned)l > MAXINT - sizeof(struct dialog) + 4 * sizeof(struct dial og_item)) overalloc(); if ((unsigned)l > MAXINT - sizeof(struct dialog) - 4 * sizeof(struct dial og_item)) overalloc();
dlg = mem_alloc(sizeof(struct dialog) + 4 * sizeof(struct dialog_item) + l); dlg = mem_alloc(sizeof(struct dialog) + 4 * sizeof(struct dialog_item) + l);
memset(dlg, 0, sizeof(struct dialog) + 4 * sizeof(struct dialog_item) + l ); memset(dlg, 0, sizeof(struct dialog) + 4 * sizeof(struct dialog_item) + l );
*(field = (unsigned char *)dlg + sizeof(struct dialog) + 4 * sizeof(struc t dialog_item)) = 0; *(field = (unsigned char *)dlg + sizeof(struct dialog) + 4 * sizeof(struc t dialog_item)) = 0;
if (def) { if (def) {
if (strlen(def) + 1 > (size_t)l) memcpy(field, def, l - 1); if (strlen(def) + 1 > (size_t)l) memcpy(field, def, l - 1);
else strcpy(field, def); else strcpy(field, def);
} }
dlg->title = title; dlg->title = title;
dlg->fn = input_field_fn; dlg->fn = input_field_fn;
dlg->udata = text; dlg->udata = text;
skipping to change at line 1469 skipping to change at line 1512
void show_dlg_item_box(struct dialog_data *dlg, struct dialog_item_data *box_ite m_data) { void show_dlg_item_box(struct dialog_data *dlg, struct dialog_item_data *box_ite m_data) {
struct terminal *term = dlg->win->term; struct terminal *term = dlg->win->term;
struct dlg_data_item_data_box *box; struct dlg_data_item_data_box *box;
struct box_item *citem; /* Item currently being shown */ struct box_item *citem; /* Item currently being shown */
int n; /* Index of item currently being displayed */ int n; /* Index of item currently being displayed */
box = (struct dlg_data_item_data_box *)(box_item_data->item->data); box = (struct dlg_data_item_data_box *)(box_item_data->item->data);
/* FIXME: Counting here SHOULD be unnecessary */ /* FIXME: Counting here SHOULD be unnecessary */
n = 0; n = 0;
fill_area(term, box_item_data->x, box_item_data->y, box_item_data->l, box _item_data->item->gid, COLOR_DIALOG_FIELD); fill_area(term, box_item_data->x, box_item_data->y, box_item_data->l, box _item_data->item->gid, COLOR_DIALOG_FIELD | ' ');
foreach (citem, box->items) { foreach (citem, box->items) {
int len; /* Length of the current text field. */ int len; /* Length of the current text field. */
len = strlen(citem->text); len = strlen(citem->text);
if (len > box_item_data->l) { if (len > box_item_data->l) {
len = box_item_data->l; len = box_item_data->l;
} }
/* Is the current item in the region to be displayed? */ /* Is the current item in the region to be displayed? */
if ( (n >= box->box_top) && (n < (box->box_top + box_item_data->i tem->gid)) ) { if ( (n >= box->box_top) && (n < (box->box_top + box_item_data->i tem->gid)) ) {
 End of changes. 44 change blocks. 
46 lines changed or deleted 95 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)