* widget.c (listbox_new): Remove "action" argument. Listboxes

without callbacks default to closing the dialog.  Adjust all
users.  This fixes double click on completion listbox.
* widget.h: Use uppercase names for the return values of the
listbox callback.
This commit is contained in:
Pavel Roskin 2003-09-01 07:31:56 +00:00
parent ab427784c8
commit f8e00e7b6a
13 changed files with 47 additions and 37 deletions

View File

@ -2759,7 +2759,7 @@ edit_completion_dialog (WEdit *edit, int max_len, int word_len,
/* create the listbox */
compl_list =
listbox_new (1, 1, compl_dlg_w - 2, compl_dlg_h - 2, 0, NULL);
listbox_new (1, 1, compl_dlg_w - 2, compl_dlg_h - 2, NULL);
/* add the dialog */
add_widget (compl_dlg, compl_list);

View File

@ -1,5 +1,11 @@
2003-09-01 Pavel Roskin <proski@gnu.org>
* widget.c (listbox_new): Remove "action" argument. Listboxes
without callbacks default to closing the dialog. Adjust all
users. This fixes double click on completion listbox.
* widget.h: Use uppercase names for the return values of the
listbox callback.
* hotlist.c (update_path_name): Avoid using global variable.
(l_call): Likewise.

View File

@ -260,7 +260,7 @@ do_enter_key (Dlg_head * h, int f_pos)
"[Advanced Chown]", title, DLG_COMPACT);
/* get new listboxes */
chl_list = listbox_new (1, 1, 15, 11, 0, NULL);
chl_list = listbox_new (1, 1, 15, 11, NULL);
listbox_add_item (chl_list, 0, 0, "<Unknown>", NULL);

View File

@ -976,7 +976,7 @@ jobs_cmd (void)
"[Background jobs]", _("Background Jobs"),
DLG_CENTER);
bg_list = listbox_new (2, 3, JOBS_X-7, JOBS_Y-9, listbox_nothing, 0);
bg_list = listbox_new (2, 3, JOBS_X-7, JOBS_Y-9, 0);
add_widget (jobs_dlg, bg_list);
i = n_buttons;

View File

@ -171,8 +171,8 @@ init_chown (void)
}
/* get new listboxes */
l_user = listbox_new (UY + 1, UX + 1, 19, 10, 0, NULL);
l_group = listbox_new (GY + 1, GX + 1, 19, 10, 0, NULL);
l_user = listbox_new (UY + 1, UX + 1, 19, 10, NULL);
l_group = listbox_new (GY + 1, GX + 1, 19, 10, NULL);
/* add fields for unknown names (numbers) */
listbox_add_item (l_user, 0, 0, _("<Unknown user>"), NULL);

View File

@ -980,7 +980,7 @@ complete_engine (WInput *in, int what_to_do)
query_dlg = create_dlg (y, x, query_height, query_width,
dialog_colors, query_callback,
"[Completion]", NULL, DLG_COMPACT);
query_list = listbox_new (1, 1, w - 2, h - 2, 0, NULL);
query_list = listbox_new (1, 1, w - 2, h - 2, NULL);
add_widget (query_dlg, query_list);
for (p = in->completions + 1; *p; p++)
listbox_add_item (query_list, 0, 0, *p, NULL);

View File

@ -830,7 +830,7 @@ setup_gui (void)
add_widget (find_dlg, status_label);
find_list =
listbox_new (2, 2, FIND2_X - 4, FIND2_Y - 9, listbox_finish, 0);
listbox_new (2, 2, FIND2_X - 4, FIND2_Y - 9, 0);
add_widget (find_dlg, find_list);
}

View File

@ -486,22 +486,22 @@ static int l_call (WListbox *list)
if (hlp->type == HL_TYPE_ENTRY) {
dlg->ret_value = B_ENTER;
dlg_stop (dlg);
return listbox_finish;
return LISTBOX_DONE;
} else {
hotlist_button_callback (B_ENTER);
hotlist_callback (dlg, '\n', DLG_POST_KEY);
return listbox_nothing;
return LISTBOX_CONT;
}
} else {
dlg->ret_value = B_ENTER;
dlg_stop (dlg);
return listbox_finish;
return LISTBOX_DONE;
}
}
hotlist_button_callback (B_UP_GROUP);
hotlist_callback (dlg, 'u', DLG_POST_KEY);
return listbox_nothing;
return LISTBOX_CONT;
}
/*
@ -642,7 +642,7 @@ init_hotlist (int list_type)
/* get new listbox */
l_hotlist =
listbox_new (UY + 1, UX + 1, COLS - 2 * UX - 8, LINES - 14,
listbox_nothing, l_call);
l_call);
/* Fill the hotlist with the active VFS or the hotlist */
#ifdef USE_VFS
@ -690,7 +690,7 @@ init_movelist (int list_type, struct hotlist *item)
/* get new listbox */
l_movelist =
listbox_new (UY + 1, UX + 1, movelist_dlg->cols - 2 * UX - 2,
movelist_dlg->lines - 8, listbox_nothing, l_call);
movelist_dlg->lines - 8, l_call);
fill_listbox ();

View File

@ -192,7 +192,7 @@ init_listmode (char *oldlistformat)
radio_justify->sel = 1;
/* get new listbox */
l_listmode = listbox_new (UY + 5, UX + 1, 16, 9, 0, NULL);
l_listmode = listbox_new (UY + 5, UX + 1, 16, 9, NULL);
if (strncmp (oldlistformat, "full ", 5) == 0) {
format_width = 1;

View File

@ -170,7 +170,7 @@ init_panelize (void)
/* get new listbox */
l_panelize =
listbox_new (UY + 1, UX + 1, panelize_dlg->cols - 12, 10, 0, NULL);
listbox_new (UY + 1, UX + 1, panelize_dlg->cols - 12, 10, NULL);
while (current) {
listbox_add_item (l_panelize, 0, 0, current->label, current);

View File

@ -953,7 +953,7 @@ show_hist (GList *history, int widget_x, int widget_y)
query_dlg =
create_dlg (y, x, h, w, dialog_colors, NULL, "[History-query]",
i18n_htitle (), DLG_COMPACT);
query_list = listbox_new (1, 1, w - 2, h - 2, listbox_finish, 0);
query_list = listbox_new (1, 1, w - 2, h - 2, 0);
add_widget (query_dlg, query_list);
hi = z;
if (y < widget_y) {
@ -1969,9 +1969,9 @@ listbox_key (WListbox *l, int key)
static int
listbox_callback (WListbox *l, int msg, int par)
{
WLEntry *e;
/* int selected_color; Never used */
int ret_code;
WLEntry *e;
Dlg_head *h = l->widget.parent;
switch (msg) {
case WIDGET_INIT:
@ -1979,15 +1979,18 @@ listbox_callback (WListbox *l, int msg, int par)
case WIDGET_HOTKEY:
if ((e = listbox_check_hotkey (l, par)) != NULL) {
int action;
listbox_select_entry (l, e);
if (l->cback)
l->action = (*l->cback) (l);
action = (*l->cback) (l);
else
action = LISTBOX_DONE;
/* Take the appropriate action */
if (l->action == listbox_finish) {
l->widget.parent->running = 0;
l->widget.parent->ret_value = B_ENTER;
if (action == LISTBOX_DONE) {
h->ret_value = B_ENTER;
dlg_stop (h);
}
return 1;
} else
@ -2046,6 +2049,8 @@ listbox_event (Gpm_Event *event, WListbox *l)
/* Double click */
if ((event->type & (GPM_DOUBLE | GPM_UP)) == (GPM_UP | GPM_DOUBLE)) {
int action;
if (event->x < 0 || event->x >= l->width)
return MOU_NORMAL;
if (event->y < 1 || event->y > l->height)
@ -2057,9 +2062,11 @@ listbox_event (Gpm_Event *event, WListbox *l)
event->y - 1));
if (l->cback)
l->action = (*l->cback) (l);
action = (*l->cback) (l);
else
action = LISTBOX_DONE;
if (l->action == listbox_finish) {
if (action == LISTBOX_DONE) {
h->ret_value = B_ENTER;
dlg_stop (h);
return MOU_NORMAL;
@ -2083,8 +2090,7 @@ listbox_destroy (WListbox *l)
}
WListbox *
listbox_new (int y, int x, int width, int height, int action,
lcback callback)
listbox_new (int y, int x, int width, int height, lcback callback)
{
WListbox *l = g_new (WListbox, 1);
extern int slow_terminal;
@ -2104,7 +2110,6 @@ listbox_new (int y, int x, int width, int height, int action,
l->top = 0;
l->current = 0;
l->cback = callback;
l->action = action;
l->allow_duplicates = 1;
l->scrollbar = slow_terminal ? 0 : 1;
widget_want_hotkey (l->widget, 1);

View File

@ -91,16 +91,16 @@ typedef struct WLEntry {
struct WLEntry *prev;
} WLEntry;
/* Listbox actions when selecting an option: */
enum {
listbox_nothing,
listbox_finish /* finish dialog automatically */
};
struct WListbox;
typedef struct WListbox WListbox;
typedef int (*lcback) (WListbox *);
/* Callback should return one of the following values */
enum {
LISTBOX_CONT, /* continue */
LISTBOX_DONE /* finish dialog */
};
struct WListbox {
Widget widget;
WLEntry *list; /* Pointer to the circular double linked list. */
@ -110,7 +110,6 @@ struct WListbox {
int count; /* Number of items in the listbox */
int width;
int height; /* Size of the widget */
int action; /* Action type */
int allow_duplicates; /* Do we allow duplicates on the list? */
int scrollbar; /* Draw a scrollbar? */
lcback cback; /* The callback function */
@ -137,7 +136,7 @@ WCheck *check_new (int y, int x, int state, char *text);
WInput *input_new (int y, int x, int color, int len, const char *text, char *histname);
WLabel *label_new (int y, int x, const char *text);
WGauge *gauge_new (int y, int x, int shown, int max, int current);
WListbox *listbox_new (int x, int y, int width, int height, int action, lcback callback);
WListbox *listbox_new (int x, int y, int width, int height, lcback callback);
/* Input lines */
void winput_set_origin (WInput *i, int x, int field_len);

View File

@ -76,7 +76,7 @@ Listbox *create_listbox_window (int cols, int lines, char *title, char *help)
listbox->dlg = create_dlg (ypos, xpos, lines+6, cols+4, dialog_colors,
NULL, help, title, DLG_CENTER);
listbox->list = listbox_new (2, 2, cols, lines, listbox_finish, 0);
listbox->list = listbox_new (2, 2, cols, lines, 0);
add_widget (listbox->dlg,
button_new (lines+3, (cols/2 + 2) - len/2,