Radix cross Linux

The main Radix cross Linux repository contains the build scripts of packages, which have the most complete and common functionality for desktop machines

452 Commits   2 Branches   1 Tag
     5         kx /*
     5         kx  *  $Id: treeview.c,v 1.43 2020/11/23 00:38:31 tom Exp $
     5         kx  *
     5         kx  *  treeview.c -- implements the treeview dialog
     5         kx  *
     5         kx  *  Copyright 2012-2019,2020	Thomas E. Dickey
     5         kx  *
     5         kx  *  This program is free software; you can redistribute it and/or modify
     5         kx  *  it under the terms of the GNU Lesser General Public License, version 2.1
     5         kx  *  as published by the Free Software Foundation.
     5         kx  *
     5         kx  *  This program is distributed in the hope that it will be useful, but
     5         kx  *  WITHOUT ANY WARRANTY; without even the implied warranty of
     5         kx  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     5         kx  *  Lesser General Public License for more details.
     5         kx  *
     5         kx  *  You should have received a copy of the GNU Lesser General Public
     5         kx  *  License along with this program; if not, write to
     5         kx  *	Free Software Foundation, Inc.
     5         kx  *	51 Franklin St., Fifth Floor
     5         kx  *	Boston, MA 02110, USA.
     5         kx  */
     5         kx 
     5         kx #include <dlg_internals.h>
     5         kx #include <dlg_keys.h>
     5         kx 
     5         kx #define INDENT 3
     5         kx #define MIN_HIGH  (1 + (5 * MARGIN))
     5         kx 
     5         kx typedef struct {
     5         kx     /* the outer-window */
     5         kx     WINDOW *dialog;
     5         kx     bool is_check;
     5         kx     int box_y;
     5         kx     int box_x;
     5         kx     int check_x;
     5         kx     int item_x;
     5         kx     int use_height;
     5         kx     int use_width;
     5         kx     /* the inner-window */
     5         kx     WINDOW *list;
     5         kx     DIALOG_LISTITEM *items;
     5         kx     int item_no;
     5         kx     int *depths;
     5         kx     const char *states;
     5         kx } ALL_DATA;
     5         kx 
     5         kx /*
     5         kx  * Print list item.  The 'selected' parameter is true if 'choice' is the
     5         kx  * current item.  That one is colored differently from the other items.
     5         kx  */
     5         kx static void
     5         kx print_item(ALL_DATA * data,
     5         kx 	   DIALOG_LISTITEM * item,
     5         kx 	   const char *states,
     5         kx 	   int depths,
     5         kx 	   int choice,
     5         kx 	   int selected)
     5         kx {
     5         kx     WINDOW *win = data->list;
     5         kx     chtype save = dlg_get_attrs(win);
     5         kx     int i;
     5         kx     bool first = TRUE;
     5         kx     int climit = (getmaxx(win) - data->check_x + 1);
     5         kx     const char *show = (dialog_vars.no_items
     5         kx 			? item->name
     5         kx 			: item->text);
     5         kx 
     5         kx     /* Clear 'residue' of last item */
     5         kx     dlg_attrset(win, menubox_attr);
     5         kx     (void) wmove(win, choice, 0);
     5         kx     for (i = 0; i < data->use_width; i++)
     5         kx 	(void) waddch(win, ' ');
     5         kx 
     5         kx     (void) wmove(win, choice, data->check_x);
     5         kx     dlg_attrset(win, selected ? check_selected_attr : check_attr);
     5         kx     (void) wprintw(win,
     5         kx 		   data->is_check ? "[%c]" : "(%c)",
     5         kx 		   states[item->state]);
     5         kx     dlg_attrset(win, menubox_attr);
     5         kx 
     5         kx     dlg_attrset(win, selected ? item_selected_attr : item_attr);
     5         kx     for (i = 0; i < depths; ++i) {
     5         kx 	int j;
     5         kx 	(void) wmove(win, choice, data->item_x + INDENT * i);
     5         kx 	(void) waddch(win, ACS_VLINE);
     5         kx 	for (j = INDENT - 1; j > 0; --j)
     5         kx 	    (void) waddch(win, ' ');
     5         kx     }
     5         kx     (void) wmove(win, choice, data->item_x + INDENT * depths);
     5         kx 
     5         kx     dlg_print_listitem(win, show, climit, first, selected);
     5         kx 
     5         kx     if (selected) {
     5         kx 	dlg_item_help(item->help);
     5         kx     }
     5         kx     dlg_attrset(win, save);
     5         kx }
     5         kx 
     5         kx static void
     5         kx print_list(ALL_DATA * data,
     5         kx 	   int choice,
     5         kx 	   int scrollamt,
     5         kx 	   int max_choice)
     5         kx {
     5         kx     int i;
     5         kx     int cur_y, cur_x;
     5         kx 
     5         kx     getyx(data->dialog, cur_y, cur_x);
     5         kx 
     5         kx     for (i = 0; i < max_choice; i++) {
     5         kx 	print_item(data,
     5         kx 		   &data->items[scrollamt + i],
     5         kx 		   data->states,
     5         kx 		   data->depths[scrollamt + i],
     5         kx 		   i, i == choice);
     5         kx     }
     5         kx     (void) wnoutrefresh(data->list);
     5         kx 
     5         kx     dlg_draw_scrollbar(data->dialog,
     5         kx 		       (long) (scrollamt),
     5         kx 		       (long) (scrollamt),
     5         kx 		       (long) (scrollamt + max_choice),
     5         kx 		       (long) (data->item_no),
     5         kx 		       data->box_x + data->check_x,
     5         kx 		       data->box_x + data->use_width,
     5         kx 		       data->box_y,
     5         kx 		       data->box_y + data->use_height + 1,
     5         kx 		       menubox_border2_attr,
     5         kx 		       menubox_border_attr);
     5         kx 
     5         kx     (void) wmove(data->dialog, cur_y, cur_x);
     5         kx }
     5         kx 
     5         kx static bool
     5         kx check_hotkey(DIALOG_LISTITEM * items, int choice)
     5         kx {
     5         kx     bool result = FALSE;
     5         kx 
     5         kx     if (dlg_match_char(dlg_last_getc(),
     5         kx 		       (dialog_vars.no_tags
     5         kx 			? items[choice].text
     5         kx 			: items[choice].name))) {
     5         kx 	result = TRUE;
     5         kx     }
     5         kx     return result;
     5         kx }
     5         kx 
     5         kx /*
     5         kx  * This is an alternate interface to 'treeview' which allows the application
     5         kx  * to read the list item states back directly without putting them in the
     5         kx  * output buffer.
     5         kx  */
     5         kx int
     5         kx dlg_treeview(const char *title,
     5         kx 	     const char *cprompt,
     5         kx 	     int height,
     5         kx 	     int width,
     5         kx 	     int list_height,
     5         kx 	     int item_no,
     5         kx 	     DIALOG_LISTITEM * items,
     5         kx 	     const char *states,
     5         kx 	     int *depths,
     5         kx 	     int flag,
     5         kx 	     int *current_item)
     5         kx {
     5         kx     /* *INDENT-OFF* */
     5         kx     static DLG_KEYS_BINDING binding[] = {
     5         kx 	HELPKEY_BINDINGS,
     5         kx 	ENTERKEY_BINDINGS,
     5         kx 	DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_RIGHT ),
     5         kx 	DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ),
     5         kx 	DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ),
     5         kx 	DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_LEFT ),
     5         kx 	DLG_KEYS_DATA( DLGK_ITEM_FIRST, KEY_HOME ),
     5         kx 	DLG_KEYS_DATA( DLGK_ITEM_LAST,	KEY_END ),
     5         kx 	DLG_KEYS_DATA( DLGK_ITEM_LAST,	KEY_LL ),
     5         kx 	DLG_KEYS_DATA( DLGK_ITEM_NEXT,	'+' ),
     5         kx 	DLG_KEYS_DATA( DLGK_ITEM_NEXT,	KEY_DOWN ),
     5         kx 	DLG_KEYS_DATA( DLGK_ITEM_NEXT,  CHR_NEXT ),
     5         kx 	DLG_KEYS_DATA( DLGK_ITEM_PREV,	'-' ),
     5         kx 	DLG_KEYS_DATA( DLGK_ITEM_PREV,	KEY_UP ),
     5         kx 	DLG_KEYS_DATA( DLGK_ITEM_PREV,  CHR_PREVIOUS ),
     5         kx 	DLG_KEYS_DATA( DLGK_PAGE_NEXT,	KEY_NPAGE ),
     5         kx 	DLG_KEYS_DATA( DLGK_PAGE_NEXT,	DLGK_MOUSE(KEY_NPAGE) ),
     5         kx 	DLG_KEYS_DATA( DLGK_PAGE_PREV,	KEY_PPAGE ),
     5         kx 	DLG_KEYS_DATA( DLGK_PAGE_PREV,	DLGK_MOUSE(KEY_PPAGE) ),
     5         kx 	TOGGLEKEY_BINDINGS,
     5         kx 	END_KEYS_BINDING
     5         kx     };
     5         kx     /* *INDENT-ON* */
     5         kx 
     5         kx #ifdef KEY_RESIZE
     5         kx     int old_height = height;
     5         kx     int old_width = width;
     5         kx #endif
     5         kx     ALL_DATA all;
     5         kx     int i, j, key2, found, x, y, cur_y, box_x, box_y;
     5         kx     int key, fkey;
     5         kx     int button = dialog_state.visit_items ? -1 : dlg_default_button();
     5         kx     int choice = dlg_default_listitem(items);
     5         kx     int scrollamt = 0;
     5         kx     int max_choice;
     5         kx     int use_height;
     5         kx     int use_width, name_width, text_width, tree_width;
     5         kx     int result = DLG_EXIT_UNKNOWN;
     5         kx     int num_states;
     5         kx     WINDOW *dialog, *list;
     5         kx     char *prompt = dlg_strclone(cprompt);
     5         kx     const char **buttons = dlg_ok_labels();
     5         kx     const char *widget_name;
     5         kx 
     5         kx     /* we need at least two states */
     5         kx     if (states == 0 || strlen(states) < 2)
     5         kx 	states = " *";
     5         kx     num_states = (int) strlen(states);
     5         kx 
     5         kx     dialog_state.plain_buttons = TRUE;
     5         kx 
     5         kx     memset(&all, 0, sizeof(all));
     5         kx     all.items = items;
     5         kx     all.item_no = item_no;
     5         kx     all.states = states;
     5         kx     all.depths = depths;
     5         kx 
     5         kx     dlg_does_output();
     5         kx     dlg_tab_correct_str(prompt);
     5         kx 
     5         kx     /*
     5         kx      * If this is a radiobutton list, ensure that no more than one item is
     5         kx      * selected initially.  Allow none to be selected, since some users may
     5         kx      * wish to provide this flavor.
     5         kx      */
     5         kx     if (flag == FLAG_RADIO) {
     5         kx 	bool first = TRUE;
     5         kx 
     5         kx 	for (i = 0; i < item_no; i++) {
     5         kx 	    if (items[i].state) {
     5         kx 		if (first) {
     5         kx 		    first = FALSE;
     5         kx 		} else {
     5         kx 		    items[i].state = 0;
     5         kx 		}
     5         kx 	    }
     5         kx 	}
     5         kx     } else {
     5         kx 	all.is_check = TRUE;
     5         kx     }
     5         kx     widget_name = "treeview";
     5         kx #ifdef KEY_RESIZE
     5         kx   retry:
     5         kx #endif
     5         kx 
     5         kx     use_height = list_height;
     5         kx     use_width = dlg_calc_list_width(item_no, items) + 10;
     5         kx     use_width = MAX(26, use_width);
     5         kx     if (use_height == 0) {
     5         kx 	/* calculate height without items (4) */
     5         kx 	dlg_auto_size(title, prompt, &height, &width, MIN_HIGH, use_width);
     5         kx 	dlg_calc_listh(&height, &use_height, item_no);
     5         kx     } else {
     5         kx 	dlg_auto_size(title, prompt, &height, &width, MIN_HIGH + use_height, use_width);
     5         kx     }
     5         kx     dlg_button_layout(buttons, &width);
     5         kx     dlg_print_size(height, width);
     5         kx     dlg_ctl_size(height, width);
     5         kx 
     5         kx     x = dlg_box_x_ordinate(width);
     5         kx     y = dlg_box_y_ordinate(height);
     5         kx 
     5         kx     dialog = dlg_new_window(height, width, y, x);
     5         kx     dlg_register_window(dialog, widget_name, binding);
     5         kx     dlg_register_buttons(dialog, widget_name, buttons);
     5         kx 
     5         kx     dlg_mouse_setbase(x, y);
     5         kx 
     5         kx     dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr);
     5         kx     dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr);
     5         kx     dlg_draw_title(dialog, title);
     5         kx 
     5         kx     dlg_attrset(dialog, dialog_attr);
     5         kx     dlg_print_autowrap(dialog, prompt, height, width);
     5         kx 
     5         kx     all.use_width = width - 4;
     5         kx     cur_y = getcury(dialog);
     5         kx     box_y = cur_y + 1;
     5         kx     box_x = (width - all.use_width) / 2 - 1;
     5         kx 
     5         kx     /*
     5         kx      * After displaying the prompt, we know how much space we really have.
     5         kx      * Limit the list to avoid overwriting the ok-button.
     5         kx      */
     5         kx     if (use_height + MIN_HIGH > height - cur_y)
     5         kx         use_height = height - MIN_HIGH - cur_y;
     5         kx     if (use_height <= 0)
     5         kx 	use_height = 1;
     5         kx 
     5         kx     max_choice = MIN(use_height, item_no);
     5         kx 
     5         kx     /* create new window for the list */
     5         kx     list = dlg_sub_window(dialog, use_height, all.use_width,
     5         kx 			  y + box_y + 1, x + box_x + 1);
     5         kx 
     5         kx     /* draw a box around the list items */
     5         kx     dlg_draw_box(dialog, box_y, box_x,
     5         kx 		 use_height + 2 * MARGIN,
     5         kx 		 all.use_width + 2 * MARGIN,
     5         kx 		 menubox_border_attr, menubox_border2_attr);
     5         kx 
     5         kx     text_width = 0;
     5         kx     name_width = 0;
     5         kx     tree_width = 0;
     5         kx     /* Find length of longest item to center treeview */
     5         kx     for (i = 0; i < item_no; i++) {
     5         kx 	tree_width = MAX(tree_width, INDENT * depths[i]);
     5         kx 	text_width = MAX(text_width, dlg_count_columns(items[i].text));
     5         kx 	name_width = MAX(name_width, dlg_count_columns(items[i].name));
     5         kx     }
     5         kx     if (dialog_vars.no_tags && !dialog_vars.no_items) {
     5         kx 	tree_width += text_width;
     5         kx     } else if (dialog_vars.no_items) {
     5         kx 	tree_width += name_width;
     5         kx     } else {
     5         kx 	tree_width += (text_width + name_width);
     5         kx     }
     5         kx 
     5         kx     use_width = (all.use_width - 4);
     5         kx     tree_width = MIN(tree_width, all.use_width);
     5         kx 
     5         kx     all.check_x = (use_width - tree_width) / 2;
     5         kx     all.item_x = ((dialog_vars.no_tags
     5         kx 		   ? 0
     5         kx 		   : (dialog_vars.no_items
     5         kx 		      ? 0
     5         kx 		      : (2 + name_width)))
     5         kx 		  + all.check_x + 4);
     5         kx 
     5         kx     /* ensure we are scrolled to show the current choice */
     5         kx     if (choice >= (max_choice + scrollamt)) {
     5         kx 	scrollamt = choice - max_choice + 1;
     5         kx 	choice = max_choice - 1;
     5         kx     }
     5         kx 
     5         kx     /* register the new window, along with its borders */
     5         kx     dlg_mouse_mkbigregion(box_y + 1, box_x,
     5         kx 			  use_height, all.use_width + 2,
     5         kx 			  KEY_MAX, 1, 1, 1 /* by lines */ );
     5         kx 
     5         kx     all.dialog = dialog;
     5         kx     all.box_x = box_x;
     5         kx     all.box_y = box_y;
     5         kx     all.use_height = use_height;
     5         kx     all.list = list;
     5         kx     print_list(&all, choice, scrollamt, max_choice);
     5         kx 
     5         kx     dlg_draw_buttons(dialog, height - 2, 0, buttons, button, FALSE, width);
     5         kx 
     5         kx     dlg_trace_win(dialog);
     5         kx 
     5         kx     while (result == DLG_EXIT_UNKNOWN) {
     5         kx 	int was_mouse;
     5         kx 
     5         kx 	if (button < 0)		/* --visit-items */
     5         kx 	    wmove(dialog, box_y + choice + 1, box_x + all.check_x + 2);
     5         kx 
     5         kx 	key = dlg_mouse_wgetch(dialog, &fkey);
     5         kx 	if (dlg_result_key(key, fkey, &result)) {
     5         kx 	    if (!dlg_button_key(result, &button, &key, &fkey))
     5         kx 		break;
     5         kx 	}
     5         kx 
     5         kx 	was_mouse = (fkey && is_DLGK_MOUSE(key));
     5         kx 	if (was_mouse)
     5         kx 	    key -= M_EVENT;
     5         kx 
     5         kx 	if (was_mouse && (key >= KEY_MAX)) {
     5         kx 	    i = (key - KEY_MAX);
     5         kx 	    if (i < max_choice) {
     5         kx 		choice = (key - KEY_MAX);
     5         kx 		print_list(&all, choice, scrollamt, max_choice);
     5         kx 
     5         kx 		key = DLGK_TOGGLE;	/* force the selected item to toggle */
     5         kx 	    } else {
     5         kx 		beep();
     5         kx 		continue;
     5         kx 	    }
     5         kx 	    fkey = FALSE;
     5         kx 	} else if (was_mouse && key >= KEY_MIN) {
     5         kx 	    key = dlg_lookup_key(dialog, key, &fkey);
     5         kx 	}
     5         kx 
     5         kx 	/*
     5         kx 	 * A space toggles the item status.
     5         kx 	 */
     5         kx 	if (key == DLGK_TOGGLE) {
     5         kx 	    int current = scrollamt + choice;
     5         kx 	    int next = items[current].state + 1;
     5         kx 
     5         kx 	    if (next >= num_states)
     5         kx 		next = 0;
     5         kx 
     5         kx 	    if (flag == FLAG_CHECK) {	/* checklist? */
     5         kx 		items[current].state = next;
     5         kx 	    } else {
     5         kx 		for (i = 0; i < item_no; i++) {
     5         kx 		    if (i != current) {
     5         kx 			items[i].state = 0;
     5         kx 		    }
     5         kx 		}
     5         kx 		if (items[current].state) {
     5         kx 		    items[current].state = next ? next : 1;
     5         kx 		} else {
     5         kx 		    items[current].state = 1;
     5         kx 		}
     5         kx 	    }
     5         kx 	    print_list(&all, choice, scrollamt, max_choice);
     5         kx 	    continue;		/* wait for another key press */
     5         kx 	}
     5         kx 
     5         kx 	/*
     5         kx 	 * Check if key pressed matches first character of any item tag in
     5         kx 	 * list.  If there is more than one match, we will cycle through
     5         kx 	 * each one as the same key is pressed repeatedly.
     5         kx 	 */
     5         kx 	found = FALSE;
     5         kx 	if (!fkey) {
     5         kx 	    if (button < 0 || !dialog_state.visit_items) {
     5         kx 		for (j = scrollamt + choice + 1; j < item_no; j++) {
     5         kx 		    if (check_hotkey(items, j)) {
     5         kx 			found = TRUE;
     5         kx 			i = j - scrollamt;
     5         kx 			break;
     5         kx 		    }
     5         kx 		}
     5         kx 		if (!found) {
     5         kx 		    for (j = 0; j <= scrollamt + choice; j++) {
     5         kx 			if (check_hotkey(items, j)) {
     5         kx 			    found = TRUE;
     5         kx 			    i = j - scrollamt;
     5         kx 			    break;
     5         kx 			}
     5         kx 		    }
     5         kx 		}
     5         kx 		if (found)
     5         kx 		    dlg_flush_getc();
     5         kx 	    } else if ((j = dlg_char_to_button(key, buttons)) >= 0) {
     5         kx 		button = j;
     5         kx 		ungetch('\n');
     5         kx 		continue;
     5         kx 	    }
     5         kx 	}
     5         kx 
     5         kx 	/*
     5         kx 	 * A single digit (1-9) positions the selection to that line in the
     5         kx 	 * current screen.
     5         kx 	 */
     5         kx 	if (!found
     5         kx 	    && (key <= '9')
     5         kx 	    && (key > '0')
     5         kx 	    && (key - '1' < max_choice)) {
     5         kx 	    found = TRUE;
     5         kx 	    i = key - '1';
     5         kx 	}
     5         kx 
     5         kx 	if (!found) {
     5         kx 	    if (fkey) {
     5         kx 		found = TRUE;
     5         kx 		switch (key) {
     5         kx 		case DLGK_ITEM_FIRST:
     5         kx 		    i = -scrollamt;
     5         kx 		    break;
     5         kx 		case DLGK_ITEM_LAST:
     5         kx 		    i = item_no - 1 - scrollamt;
     5         kx 		    break;
     5         kx 		case DLGK_PAGE_PREV:
     5         kx 		    if (choice)
     5         kx 			i = 0;
     5         kx 		    else if (scrollamt != 0)
     5         kx 			i = -MIN(scrollamt, max_choice);
     5         kx 		    else
     5         kx 			continue;
     5         kx 		    break;
     5         kx 		case DLGK_PAGE_NEXT:
     5         kx 		    i = MIN(choice + max_choice, item_no - scrollamt - 1);
     5         kx 		    break;
     5         kx 		case DLGK_ITEM_PREV:
     5         kx 		    i = choice - 1;
     5         kx 		    if (choice == 0 && scrollamt == 0)
     5         kx 			continue;
     5         kx 		    break;
     5         kx 		case DLGK_ITEM_NEXT:
     5         kx 		    i = choice + 1;
     5         kx 		    if (scrollamt + choice >= item_no - 1)
     5         kx 			continue;
     5         kx 		    break;
     5         kx 		default:
     5         kx 		    found = FALSE;
     5         kx 		    break;
     5         kx 		}
     5         kx 	    }
     5         kx 	}
     5         kx 
     5         kx 	if (found) {
     5         kx 	    if (i != choice) {
     5         kx 		if (i < 0 || i >= max_choice) {
     5         kx 		    if (i < 0) {
     5         kx 			scrollamt += i;
     5         kx 			choice = 0;
     5         kx 		    } else {
     5         kx 			choice = max_choice - 1;
     5         kx 			scrollamt += (i - max_choice + 1);
     5         kx 		    }
     5         kx 		    print_list(&all, choice, scrollamt, max_choice);
     5         kx 		} else {
     5         kx 		    choice = i;
     5         kx 		    print_list(&all, choice, scrollamt, max_choice);
     5         kx 		}
     5         kx 	    }
     5         kx 	    continue;		/* wait for another key press */
     5         kx 	}
     5         kx 
     5         kx 	if (fkey) {
     5         kx 	    switch (key) {
     5         kx 	    case DLGK_ENTER:
     5         kx 		result = dlg_enter_buttoncode(button);
     5         kx 		break;
     5         kx 	    case DLGK_LEAVE:
     5         kx 		result = dlg_ok_buttoncode(button);
     5         kx 		break;
     5         kx 	    case DLGK_FIELD_PREV:
     5         kx 		button = dlg_prev_button(buttons, button);
     5         kx 		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
     5         kx 				 FALSE, width);
     5         kx 		break;
     5         kx 	    case DLGK_FIELD_NEXT:
     5         kx 		button = dlg_next_button(buttons, button);
     5         kx 		dlg_draw_buttons(dialog, height - 2, 0, buttons, button,
     5         kx 				 FALSE, width);
     5         kx 		break;
     5         kx #ifdef KEY_RESIZE
     5         kx 	    case KEY_RESIZE:
     5         kx 		dlg_will_resize(dialog);
     5         kx 		/* reset data */
     5         kx 		height = old_height;
     5         kx 		width = old_width;
     5         kx 		/* repaint */
     5         kx 		_dlg_resize_cleanup(dialog);
     5         kx 		goto retry;
     5         kx #endif
     5         kx 	    default:
     5         kx 		if (was_mouse) {
     5         kx 		    if ((key2 = dlg_ok_buttoncode(key)) >= 0) {
     5         kx 			result = key2;
     5         kx 			break;
     5         kx 		    }
     5         kx 		    beep();
     5         kx 		}
     5         kx 	    }
     5         kx 	} else if (key > 0) {
     5         kx 	    beep();
     5         kx 	}
     5         kx     }
     5         kx 
     5         kx     dlg_del_window(dialog);
     5         kx     dlg_mouse_free_regions();
     5         kx     free(prompt);
     5         kx     *current_item = (scrollamt + choice);
     5         kx     return result;
     5         kx }
     5         kx 
     5         kx /*
     5         kx  * Display a set of items as a tree.
     5         kx  */
     5         kx int
     5         kx dialog_treeview(const char *title,
     5         kx 		const char *cprompt,
     5         kx 		int height,
     5         kx 		int width,
     5         kx 		int list_height,
     5         kx 		int item_no,
     5         kx 		char **items,
     5         kx 		int flag)
     5         kx {
     5         kx     int result;
     5         kx     int i, j;
     5         kx     DIALOG_LISTITEM *listitems;
     5         kx     int *depths;
     5         kx     bool show_status = FALSE;
     5         kx     int current = 0;
     5         kx     char *help_result;
     5         kx 
     5         kx     DLG_TRACE(("# treeview args:\n"));
     5         kx     DLG_TRACE2S("title", title);
     5         kx     DLG_TRACE2S("message", cprompt);
     5         kx     DLG_TRACE2N("height", height);
     5         kx     DLG_TRACE2N("width", width);
     5         kx     DLG_TRACE2N("lheight", list_height);
     5         kx     DLG_TRACE2N("llength", item_no);
     5         kx     /* FIXME dump the items[][] too */
     5         kx     DLG_TRACE2N("flag", flag);
     5         kx 
     5         kx     listitems = dlg_calloc(DIALOG_LISTITEM, (size_t) item_no + 1);
     5         kx     assert_ptr(listitems, "dialog_treeview");
     5         kx 
     5         kx     depths = dlg_calloc(int, (size_t) item_no + 1);
     5         kx     assert_ptr(depths, "dialog_treeview");
     5         kx 
     5         kx     for (i = j = 0; i < item_no; ++i) {
     5         kx 	listitems[i].name = items[j++];
     5         kx 	listitems[i].text = (dialog_vars.no_items
     5         kx 			     ? dlg_strempty()
     5         kx 			     : items[j++]);
     5         kx 	listitems[i].state = !dlg_strcmp(items[j++], "on");
     5         kx 	depths[i] = atoi(items[j++]);
     5         kx 	listitems[i].help = ((dialog_vars.item_help)
     5         kx 			     ? items[j++]
     5         kx 			     : dlg_strempty());
     5         kx     }
     5         kx     dlg_align_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);
     5         kx 
     5         kx     result = dlg_treeview(title,
     5         kx 			  cprompt,
     5         kx 			  height,
     5         kx 			  width,
     5         kx 			  list_height,
     5         kx 			  item_no,
     5         kx 			  listitems,
     5         kx 			  NULL,
     5         kx 			  depths,
     5         kx 			  flag,
     5         kx 			  &current);
     5         kx 
     5         kx     switch (result) {
     5         kx     case DLG_EXIT_OK:		/* FALLTHRU */
     5         kx     case DLG_EXIT_EXTRA:
     5         kx 	show_status = TRUE;
     5         kx 	break;
     5         kx     case DLG_EXIT_HELP:
     5         kx 	dlg_add_help_listitem(&result, &help_result, &listitems[current]);
     5         kx 	if ((show_status = dialog_vars.help_status)) {
     5         kx 	    if (dialog_vars.separate_output) {
     5         kx 		dlg_add_string(help_result);
     5         kx 		dlg_add_separator();
     5         kx 	    } else {
     5         kx 		dlg_add_quoted(help_result);
     5         kx 	    }
     5         kx 	} else {
     5         kx 	    dlg_add_string(help_result);
     5         kx 	}
     5         kx 	break;
     5         kx     }
     5         kx 
     5         kx     if (show_status) {
     5         kx 	for (i = 0; i < item_no; i++) {
     5         kx 	    if (listitems[i].state) {
     5         kx 		if (dlg_need_separator())
     5         kx 		    dlg_add_separator();
     5         kx 		if (dialog_vars.separate_output) {
     5         kx 		    dlg_add_string(listitems[i].name);
     5         kx 		} else {
     5         kx 		    if (flag == FLAG_CHECK)
     5         kx 			dlg_add_quoted(listitems[i].name);
     5         kx 		    else
     5         kx 			dlg_add_string(listitems[i].name);
     5         kx 		}
     5         kx 	    }
     5         kx 	}
     5         kx 	AddLastKey();
     5         kx     }
     5         kx 
     5         kx     dlg_free_columns(&listitems[0].text, (int) sizeof(DIALOG_LISTITEM), item_no);
     5         kx     free(depths);
     5         kx     free(listitems);
     5         kx     return result;
     5         kx }