예제 #1
0
파일: arrows.c 프로젝트: 0mp/freebsd
void
dlg_draw_arrows2(WINDOW *win,
		 int top_arrow,
		 int bottom_arrow,
		 int x,
		 int top,
		 int bottom,
		 chtype attr,
		 chtype borderattr)
{
    chtype save = dlg_get_attrs(win);
    int cur_x, cur_y;
    int limit_x = getmaxx(win);
    bool draw_top = TRUE;
    bool is_toplevel = (wgetparent(win) == stdscr);

    getyx(win, cur_y, cur_x);

    /*
     * If we're drawing a centered title, do not overwrite with the arrows.
     */
    if (dialog_vars.title && is_toplevel && (top - getbegy(win)) < MARGIN) {
	int have = (limit_x - dlg_count_columns(dialog_vars.title)) / 2;
	int need = x + 5;
	if (need > have)
	    draw_top = FALSE;
    }

    if (draw_top) {
	(void) wmove(win, top, x);
	if (top_arrow) {
	    (void) wattrset(win, merge_colors(uarrow_attr, attr));
	    (void) add_acs(win, ACS_UARROW);
	    (void) waddstr(win, "(-)");
	} else {
	    (void) wattrset(win, attr);
	    (void) whline(win, dlg_boxchar(ACS_HLINE), ON_LEFT);
	}
    }
    mouse_mkbutton(top, x - 1, 6, KEY_PPAGE);

    (void) wmove(win, bottom, x);
    if (bottom_arrow) {
	(void) wattrset(win, merge_colors(darrow_attr, borderattr));
	(void) add_acs(win, ACS_DARROW);
	(void) waddstr(win, "(+)");
    } else {
	(void) wattrset(win, borderattr);
	(void) whline(win, dlg_boxchar(ACS_HLINE), ON_LEFT);
    }
    mouse_mkbutton(bottom, x - 1, 6, KEY_NPAGE);

    (void) wmove(win, cur_y, cur_x);
    wrefresh(win);

    (void) wattrset(win, save);
}
예제 #2
0
파일: checklist.c 프로젝트: 0mp/freebsd
/*
 * 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);
}
예제 #3
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);
}
예제 #4
0
파일: arrows.c 프로젝트: 0mp/freebsd
void
dlg_draw_scrollbar(WINDOW *win,
		   long first_data,
		   long this_data,
		   long next_data,
		   long total_data,
		   int left,
		   int right,
		   int top,
		   int bottom,
		   chtype attr,
		   chtype borderattr)
{
    char buffer[80];
    int percent;
    int len;
    int oldy, oldx;

    chtype save = dlg_get_attrs(win);
    int top_arrow = (first_data != 0);
    int bottom_arrow = (next_data < total_data);

    getyx(win, oldy, oldx);

    dlg_draw_helpline(win, TRUE);
    if (bottom_arrow || top_arrow || dialog_state.use_scrollbar) {
	percent = (!total_data
		   ? 100
		   : (int) ((next_data * 100)
			    / total_data));

	if (percent < 0)
	    percent = 0;
	else if (percent > 100)
	    percent = 100;

	(void) wattrset(win, position_indicator_attr);
	(void) sprintf(buffer, "%d%%", percent);
	(void) wmove(win, bottom, right - 7);
	(void) waddstr(win, buffer);
	if ((len = dlg_count_columns(buffer)) < 4) {
	    (void) wattrset(win, border_attr);
	    whline(win, dlg_boxchar(ACS_HLINE), 4 - len);
	}
    }
#define BARSIZE(num) (int) (0.5 + (double) ((all_high * (int) (num)) / (double) total_data))
#define ORDSIZE(num) (int) ((double) ((all_high * (int) (num)) / (double) all_diff))

    if (dialog_state.use_scrollbar) {
	int all_high = (bottom - top - 1);

	this_data = MAX(0, this_data);

	if (total_data > 0 && all_high > 0) {
	    int all_diff = (int) (total_data + 1);
	    int bar_diff = (int) (next_data + 1 - this_data);
	    int bar_high;
	    int bar_y;

	    bar_high = ORDSIZE(bar_diff);
	    if (bar_high <= 0)
		bar_high = 1;

	    if (bar_high < all_high) {
		int bar_last = BARSIZE(next_data);

		wmove(win, top + 1, right);

		(void) wattrset(win, save);
		wvline(win, ACS_VLINE | A_REVERSE, all_high);

		bar_y = ORDSIZE(this_data);
		if (bar_y >= bar_last && bar_y > 0)
		    bar_y = bar_last - 1;
		if (bar_last - bar_y > bar_high && bar_high > 1)
		    ++bar_y;
		bar_last = MIN(bar_last, all_high);

		wmove(win, top + 1 + bar_y, right);

		(void) wattrset(win, position_indicator_attr);
		wattron(win, A_REVERSE);
#if defined(WACS_BLOCK) && defined(NCURSES_VERSION) && defined(USE_WIDE_CURSES)
		wvline_set(win, WACS_BLOCK, bar_last - bar_y);
#else
		wvline(win, ACS_BLOCK, bar_last - bar_y);
#endif
	    }
	}
    }
    dlg_draw_arrows2(win,
		     top_arrow,
		     bottom_arrow,
		     left + ARROWS_COL,
		     top,
		     bottom,
		     attr,
		     borderattr);

    (void) wattrset(win, save);
    wmove(win, oldy, oldx);
}
예제 #5
0
/*
 * Print a list of buttons at the given position.
 */
void
dlg_draw_buttons(WINDOW *win,
		 int y, int x,
		 const char **labels,
		 int selected,
		 int vertical,
		 int limit)
{
    chtype save = dlg_get_attrs(win);
    int n;
    int step = 0;
    int length;
    int longest;
    int final_x;
    int final_y;
    int gap;
    int margin;
    size_t need;
    char *buffer;

    dlg_mouse_setbase(getbegx(win), getbegy(win));

    getyx(win, final_y, final_x);

    dlg_button_sizes(labels, vertical, &longest, &length);

    if (vertical) {
	y += 1;
	step = 1;
    } else {
	dlg_button_x_step(labels, limit, &gap, &margin, &step);
	x += margin;
    }

    /*
     * Allocate a buffer big enough for any label.
     */
    need = (size_t) longest;
    for (n = 0; labels[n] != 0; ++n) {
	need += strlen(labels[n]) + 1;
    }
    buffer = dlg_malloc(char, need);
    assert_ptr(buffer, "dlg_draw_buttons");

    /*
     * Draw the labels.
     */
    for (n = 0; labels[n] != 0; n++) {
	center_label(buffer, longest, labels[n]);
	mouse_mkbutton(y, x, dlg_count_columns(buffer), n);
	print_button(win, buffer, y, x,
		     (selected == n) || (n == 0 && selected < 0));
	if (selected == n)
	    getyx(win, final_y, final_x);

	if (vertical) {
	    if ((y += step) > limit)
		break;
	} else {
	    if ((x += step) > limit)
		break;
	}
    }
    (void) wmove(win, final_y, final_x);
    wrefresh(win);
    free(buffer);
    wattrset(win, save);
}