Exemple #1
0
/*
 * Print menu item
 */
static void
print_item(WINDOW *win,
           const char **items,
           int choice, int selected)
{
    int i;

    /* Clear 'residue' of last item */
    wattrset(win, menubox_attr);
    (void) wmove(win, choice, 0);
    for (i = 0; i < menu_width; i++)
        (void) waddch(win, ' ');

    (void) wmove(win, choice, tag_x);
    wattrset(win, selected ? tag_key_selected_attr : tag_key_attr);
    (void) waddch(win, CharOf(ItemName(0)[0]));
    wattrset(win, selected ? tag_selected_attr : tag_attr);
    (void) wprintw(win, "%.*s", item_x - tag_x - 2, ItemName(0) + 1);

    (void) wmove(win, choice, item_x);
    wattrset(win, selected ? item_selected_attr : item_attr);
    (void) wprintw(win, "%.*s", getmaxx(win) - item_x, ItemText(0));

    if (selected) {
        dlg_item_help(ItemHelp(0));
    }
}
/*
 * Print list item
 */
static void
print_item(WINDOW *win, char **items, int status,
	   int choice, int selected)
{
    int i;
    chtype attr = A_NORMAL;
    const int *indx;
    int limit;

    /* Clear 'residue' of last item */
    wattrset(win, menubox_attr);
    (void) wmove(win, choice, 0);
    for (i = 0; i < list_width; i++)
	(void) waddch(win, ' ');

    (void) wmove(win, choice, check_x);
    wattrset(win, selected ? check_selected_attr : check_attr);
    (void) wprintw(win,
		   (checkflag == FLAG_CHECK) ? "[%c]" : "(%c)",
		   status ? 'X' : ' ');
    wattrset(win, menubox_attr);
    (void) waddch(win, ' ');

    if (strlen(ItemName(0)) != 0) {

	indx = dlg_index_wchars(ItemName(0));
	limit = dlg_count_wchars(ItemName(0));

	wattrset(win, selected ? tag_key_selected_attr : tag_key_attr);
	(void) waddnstr(win, ItemName(0), indx[1]);

	if ((int) strlen(ItemName(0)) > indx[1]) {
	    limit = dlg_limit_columns(ItemName(0), (item_x - check_x - 6), 1);
	    if (limit > 1) {
		wattrset(win, selected ? tag_selected_attr : tag_attr);
		(void) waddnstr(win,
				ItemName(0) + indx[1],
				indx[limit] - indx[1]);
	    }
	}
    }

    if (strlen(ItemText(0)) != 0) {
	indx = dlg_index_wchars(ItemText(0));
	limit = dlg_limit_columns(ItemText(0), (getmaxx(win) - item_x - 1), 0);

	if (limit > 0) {
	    (void) wmove(win, choice, item_x);
	    wattrset(win, selected ? item_selected_attr : item_attr);
	    dlg_print_text(win, ItemText(0), indx[limit], &attr);
	}
    }

    if (selected) {
	dlg_item_help(ItemHelp(0));
    }
}
/*
 * Print menu item
 */
static void
print_item(WINDOW *win,
	   char **items,
	   int choice, int selected)
{
    int n;
    int my_width = menu_width;
    int my_x = item_x;
    int my_y = ItemToRow(choice);
    chtype attr = A_NORMAL;

    if (items == 0)
	return;

    /* Clear 'residue' of last item and mark current current item */
    if (dialog_vars.input_menu) {
	wattrset(win, selected ? item_selected_attr : item_attr);
	for (n = my_y - 1; n < my_y + INPUT_ROWS - 1; n++) {
	    wmove(win, n, 0);
	    wprintw(win, "%*s", my_width, " ");
	}
    } else {
	wattrset(win, menubox_attr);
	wmove(win, my_y, 0);
	wprintw(win, "%*s", my_width, " ");
    }

    print_tag(win, items, choice, selected);

    /* Draw the input field box (only for inputmenu) */
    (void) wmove(win, my_y, my_x);
    if (dialog_vars.input_menu) {
	my_width -= 1;
	draw_box(win, my_y - 1, my_x, INPUT_ROWS, my_width - my_x - tag_x,
		 selected ? item_selected_attr : item_attr,
		 selected ? item_selected_attr : item_attr);
	my_width -= 1;
	++my_x;
    }

    /* print actual item */
    wmove(win, my_y, my_x);
    wattrset(win, selected ? item_selected_attr : item_attr);
    dlg_print_text(win, ItemText(0), my_width - my_x, &attr);

    if (selected) {
	dlg_item_help(ItemHelp(0));
    }
}
Exemple #4
0
/*
 * Print list item.  The 'selected' parameter is true if 'choice' is the
 * current item.  That one is colored differently from the other items.
 */
static void
print_item(ALL_DATA * data,
	   WINDOW *win,
	   DIALOG_LISTITEM * item,
	   const char *states,
	   int choice,
	   int selected)
{
    chtype save = dlg_get_attrs(win);
    int i;
    bool both = (!dialog_vars.no_tags && !dialog_vars.no_items);
    bool first = TRUE;
    int climit = (getmaxx(win) - data->check_x + 1);
    const char *show = (dialog_vars.no_items
			? item->name
			: item->text);

    /* Clear 'residue' of last item */
    (void) wattrset(win, menubox_attr);
    (void) wmove(win, choice, 0);
    for (i = 0; i < data->use_width; i++)
	(void) waddch(win, ' ');

    (void) wmove(win, choice, data->check_x);
    (void) wattrset(win, selected ? check_selected_attr : check_attr);
    (void) wprintw(win,
		   (data->checkflag == FLAG_CHECK) ? "[%c]" : "(%c)",
		   states[item->state]);
    (void) wattrset(win, menubox_attr);
    (void) waddch(win, ' ');

    if (both) {
	dlg_print_listitem(win, item->name, climit, first, selected);
	first = FALSE;
    }

    (void) wmove(win, choice, data->item_x);
    dlg_print_listitem(win, show, climit, first, selected);

    if (selected) {
	dlg_item_help(item->help);
    }
    (void) wattrset(win, save);
}
Exemple #5
0
int
diskeditor_show(const char *title, const char *cprompt,
    struct partedit_item *items, int nitems, int *selected, int *nscroll)
{
	WINDOW *dialog, *partitions;
	char *prompt;
	const char *buttons[] =
	    { "Create", "Delete", "Modify", "Revert", "Auto", "Finish", NULL };
	const char *help_text[] = {
	    "Add a new partition", "Delete selected partition or partitions",
	    "Change partition type or mountpoint",
	    "Revert changes to disk setup", "Use guided partitioning tool",
	    "Exit partitioner (will ask whether to save changes)", NULL };
	int x, y;
	int i;
	int height, width, min_width;
	int partlist_height, partlist_width;
	int cur_scroll = 0;
	int key, fkey;
	int cur_button = 5, cur_part = 0;
	int result = DLG_EXIT_UNKNOWN;

	static DLG_KEYS_BINDING binding[] = {
		ENTERKEY_BINDINGS,
		DLG_KEYS_DATA( DLGK_ENTER,      ' ' ),
		DLG_KEYS_DATA( DLGK_ITEM_NEXT, KEY_DOWN ),
		DLG_KEYS_DATA( DLGK_ITEM_PREV, KEY_UP ),
		DLG_KEYS_DATA( DLGK_FIELD_NEXT, KEY_RIGHT ),
		DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ),
		DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ),
		DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_LEFT ),

		SCROLLKEY_BINDINGS,
		END_KEYS_BINDING
	};

	/*
	 * Set up editor window.
	 */
	prompt = dlg_strclone(cprompt);

	min_width = 50;
	height = width = 0;
	partlist_height = 10;
	dlg_tab_correct_str(prompt);
	dlg_button_layout(buttons, &min_width);
	dlg_auto_size(title, prompt, &height, &width, 2, min_width);
	height += partlist_height;
	partlist_width = width - 2*MARGIN;
	dlg_print_size(height, width);
	dlg_ctl_size(height, width);

	x = dlg_box_x_ordinate(width);
	y = dlg_box_y_ordinate(height);

	dialog = dlg_new_window(height, width, y, x);
	dlg_register_window(dialog, "diskeditorbox", binding);
	dlg_register_buttons(dialog, "diskeditorbox", buttons);

	dlg_draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
	dlg_draw_bottom_box(dialog);
	dlg_draw_title(dialog, title);
	wattrset(dialog, dialog_attr);

	/* Partition list sub-window */
	partitions = dlg_sub_window(dialog, partlist_height, partlist_width,
	    y + 3, x + 1);
	dlg_register_window(partitions, "partlist", binding);
	dlg_register_buttons(partitions, "partlist", buttons);
	wattrset(partitions, menubox_attr);

	dlg_item_help(help_text[cur_button]);
	dlg_draw_buttons(dialog, height - 2*MARGIN, 0, buttons,
	    cur_button, FALSE, width);
	dlg_print_autowrap(dialog, prompt, height, width);

	if (selected != NULL)
		cur_part = *selected;
	if (nscroll != NULL)
		cur_scroll = *nscroll;
	if (cur_part - cur_scroll >= partlist_height - 2 ||
	    cur_part - cur_scroll < 0)
		cur_scroll = cur_part;

repaint:
	dlg_draw_box(dialog, 3, 1,  partlist_height, partlist_width,
	    menubox_border_attr, menubox_attr);
	for (i = cur_scroll; i < MIN(cur_scroll + partlist_height - 2, nitems);
	    i++)
		print_partedit_item(partitions, items, i, cur_scroll,
		    i == cur_part);
	if (nitems > partlist_height - 2)
		dlg_draw_arrows(partitions, cur_scroll > 0,
		    nitems > cur_scroll + partlist_height - 2,
		    partlist_width - 5, 0, partlist_height - 1);
	wrefresh(partitions);

	while (result == DLG_EXIT_UNKNOWN) {
		key = dlg_mouse_wgetch(dialog, &fkey);
		if ((i = dlg_char_to_button(key, buttons)) >= 0) {
			cur_button = i;
			dlg_item_help(help_text[cur_button]);
			dlg_draw_buttons(dialog, height - 2*MARGIN, 0, buttons,
			    cur_button, FALSE, width);
			break;
		}

		if (!fkey)
			continue;

		switch (key) {
		case DLGK_FIELD_NEXT:
			cur_button = dlg_next_button(buttons, cur_button);
			if (cur_button < 0)
				cur_button = 0;
			dlg_item_help(help_text[cur_button]);
			dlg_draw_buttons(dialog, height - 2*MARGIN, 0, buttons,
			    cur_button, FALSE, width);
			break;
		case DLGK_FIELD_PREV:
			cur_button = dlg_prev_button(buttons, cur_button);
			if (cur_button < 0)
				cur_button = 0;
			dlg_item_help(help_text[cur_button]);
			dlg_draw_buttons(dialog, height - 2*MARGIN, 0, buttons,
			    cur_button, FALSE, width);
			break;
		case DLGK_ITEM_NEXT:
			if (cur_part == nitems - 1)
				break; /* End of list */

			/* Deselect old item */
			print_partedit_item(partitions, items, cur_part,
			    cur_scroll, 0);
			/* Select new item */
			cur_part++;
			if (cur_part - cur_scroll >= partlist_height - 2) {
				cur_scroll = cur_part;
				goto repaint;
			}
			print_partedit_item(partitions, items, cur_part,
			    cur_scroll, 1);
			wrefresh(partitions);
			break;
		case DLGK_ITEM_PREV:
			if (cur_part == 0)
				break; /* Start of list */

			/* Deselect old item */
			print_partedit_item(partitions, items, cur_part,
			    cur_scroll, 0);
			/* Select new item */
			cur_part--;
			if (cur_part - cur_scroll < 0) {
				cur_scroll = cur_part;
				goto repaint;
			}
			print_partedit_item(partitions, items, cur_part,
			    cur_scroll, 1);
			wrefresh(partitions);
			break;
		case DLGK_PAGE_NEXT:
			cur_scroll += (partlist_height - 2);
			if (cur_scroll + partlist_height - 2 >= nitems)
				cur_scroll = nitems - (partlist_height - 2);
			if (cur_scroll < 0)
				cur_scroll = 0;
			if (cur_part < cur_scroll)
				cur_part = cur_scroll;
			goto repaint;
		case DLGK_PAGE_PREV:
			cur_scroll -= (partlist_height - 2);
			if (cur_scroll < 0)
				cur_scroll = 0;
			if (cur_part >= cur_scroll + partlist_height - 2)
				cur_part = cur_scroll;
			goto repaint;
		case DLGK_PAGE_FIRST:
			cur_scroll = 0;
			cur_part = cur_scroll;
			goto repaint;
		case DLGK_PAGE_LAST:
			cur_scroll = nitems - (partlist_height - 2);
			if (cur_scroll < 0)
				cur_scroll = 0;
			cur_part = cur_scroll;
			goto repaint;
		case DLGK_ENTER:
			goto done;
		default:
			if (is_DLGK_MOUSE(key)) {
				cur_button = key - M_EVENT;
				dlg_item_help(help_text[cur_button]);
				dlg_draw_buttons(dialog, height - 2*MARGIN, 0,
				    buttons, cur_button, FALSE, width);
				goto done;
			}
			break;
		}
	}

done:
	if (selected != NULL)
		*selected = cur_part;
	if (nscroll != NULL)
		*nscroll = cur_scroll;

	dlg_del_window(partitions);
	dlg_del_window(dialog);
	dlg_mouse_free_regions();

	return (cur_button);
}
Exemple #6
0
/*
 * Print list item.  The 'selected' parameter is true if 'choice' is the
 * current item.  That one is colored differently from the other items.
 */
static void
print_item(WINDOW *win,
	   DIALOG_LISTITEM * item,
	   const char *states,
	   int choice,
	   int selected)
{
    chtype save = dlg_get_attrs(win);
    int i;
    chtype attr = A_NORMAL;
    const int *cols;
    const int *indx;
    int limit;

    /* Clear 'residue' of last item */
    wattrset(win, menubox_attr);
    (void) wmove(win, choice, 0);
    for (i = 0; i < list_width; i++)
	(void) waddch(win, ' ');

    (void) wmove(win, choice, check_x);
    wattrset(win, selected ? check_selected_attr : check_attr);
    (void) wprintw(win,
		   (checkflag == FLAG_CHECK) ? "[%c]" : "(%c)",
		   states[item->state]);
    wattrset(win, menubox_attr);
    (void) waddch(win, ' ');

    if (strlen(item->name) != 0) {

	indx = dlg_index_wchars(item->name);

	wattrset(win, selected ? tag_key_selected_attr : tag_key_attr);
	(void) waddnstr(win, item->name, indx[1]);

	if ((int) strlen(item->name) > indx[1]) {
	    limit = dlg_limit_columns(item->name, (item_x - check_x - 6), 1);
	    if (limit > 1) {
		wattrset(win, selected ? tag_selected_attr : tag_attr);
		(void) waddnstr(win,
				item->name + indx[1],
				indx[limit] - indx[1]);
	    }
	}
    }

    if (strlen(item->text) != 0) {
	cols = dlg_index_columns(item->text);
	limit = dlg_limit_columns(item->text, (getmaxx(win) - item_x + 1), 0);

	if (limit > 0) {
	    (void) wmove(win, choice, item_x);
	    wattrset(win, selected ? item_selected_attr : item_attr);
	    dlg_print_text(win, item->text, cols[limit], &attr);
	}
    }

    if (selected) {
	dlg_item_help(item->help);
    }
    wattrset(win, save);
}