Пример #1
0
DialogForm::~DialogForm() {
    unpost_form(m_pForm);
//    free_form(m_pForm); TODO: Fix segfault
    for (int i = 0; i < m_numFields; i++) {
        if (m_pFields[i] != 0) {
            void *usrPtr = field_userptr(m_pFields[i]);
            if (usrPtr != 0) {
                delete (FieldType*)usrPtr; //TODO: Fix potentially unsafe conversion
            }
            free_field(m_pFields[i]);
        }
    }
    curs_set(0);
    refresh();
}
Пример #2
0
/*
 * Define each field with an extra one, for reflecting "actual" text.
 */
static FIELD *
make_field(int frow, int fcol, int rows, int cols)
{
    FIELD *f = new_field(rows, cols, frow, fcol, o_value, 1);

    if (f) {
	FieldAttrs *ptr;

	set_field_back(f, A_UNDERLINE);
	/*
	 * If -j and -d options are combined, -j loses.  It is documented in
	 * "Character User Interface Programming", page 12-15 that setting
	 * O_STATIC off makes the form library ignore justification.
	 */
	set_field_just(f, j_value);
	if (d_option) {
	    if (has_colors()) {
		set_field_fore(f, (chtype) COLOR_PAIR(2));
		set_field_back(f, A_UNDERLINE | COLOR_PAIR(3));
	    } else {
		set_field_fore(f, A_BOLD);
	    }
	    /*
	     * The field_opts_off() call dumps core with Solaris curses,
	     * but that is a known bug in Solaris' form library -TD
	     */
	    field_opts_off(f, O_STATIC);
	    set_max_field(f, m_value);
	}

	/*
	 * The userptr is used in edit_field.c's inactive_field().
	 */
	ptr = (FieldAttrs *) field_userptr(f);
	if (ptr == 0) {
	    ptr = typeCalloc(FieldAttrs, 1);
	    ptr->background = field_back(f);
	}
	set_field_userptr(f, (void *) ptr);
	if (t_value)
	    set_field_buffer(f, 0, t_value);
    }
    return (f);
}
Пример #3
0
bool ListBox::handleKeyPress(int key) {
    if (key == KEY_UP) {
        //Move up a field
        selectField(REQ_PREV_FIELD);
        m_curRow = (m_curRow == 0) ? m_numRows - 1 : m_curRow - 1;
        return true;
    } else if (key == KEY_DOWN || key == 9) { //Tab key
        //Move down a field
        selectField(REQ_NEXT_FIELD);
        m_curRow = (m_curRow == m_numRows - 1) ? 0 : m_curRow + 1;
        return true;
    } else if (key == KEY_BACKSPACE || key == 127) {
        //Delete prev. char
//        form_driver(m_pForm, REQ_DEL_PREV);
        return true;
    } else if (key == 330) { //Delete key TODO: Fix this
        //Delete next char
//        form_driver(m_pForm, REQ_DEL_PREV);
        return true;
    } else {
        FIELD *pField = current_field(m_pForm);
        if (field_userptr(pField) != 0) {
#ifdef DEBUG
            dout << "Create new row" << std::endl;
#endif
            addRow("");
            if (key == CuTAES::KEY_ENT) {
                //Clear field
                set_field_buffer(pField, 0, "");
                return true;
            }
        }
        //Send key to form driver
        form_driver(m_pForm, key);
    }
    wrefresh(m_pPanel->getWindow());
    return false;
}
Пример #4
0
static void
inactive_field(FIELD * f)
{
    FieldAttrs *ptr = (FieldAttrs *) field_userptr(f);
    set_field_back(f, ptr->background);
}
Пример #5
0
static void
inactive_field(FIELD * f)
{
    void *ptr = field_userptr(f);
    set_field_back(f, (chtype) ptr);
}
Пример #6
0
static void
demo_forms(void)
{
    WINDOW *w;
    FORM *form;
    FIELD *f[100];		/* FIXME memset to zero */
    int finished = 0, c;
    unsigned n = 0;
    int pg;
    WINDOW *also;

#ifdef NCURSES_MOUSE_VERSION
    mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
#endif

    help_edit_field();

    MvAddStr(4, 57, "Forms Entry Test");
    show_insert_mode(TRUE);

    refresh();

    /* describe the form */
    memset(f, 0, sizeof(f));
    for (pg = 0; pg < 4; ++pg) {
	char label[80];
	sprintf(label, "Sample Form Page %d", pg + 1);
	f[n++] = make_label(0, 15, label);
	set_new_page(f[n - 1], TRUE);

	switch (pg) {
	default:
	    f[n++] = make_label(2, 0, "Last Name");
	    f[n++] = make_field(3, 0, 1, 18);
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);

	    f[n++] = make_label(2, 20, "First Name");
	    f[n++] = make_field(3, 20, 1, 12);
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);

	    f[n++] = make_label(2, 34, "Middle Name");
	    f[n++] = make_field(3, 34, 1, 12);
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);
	    break;
	case 1:
	    f[n++] = make_label(2, 0, "Last Name");
	    f[n++] = make_field(3, 0, 1, 18);
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);

	    f[n++] = make_label(2, 20, "First Name");
	    f[n++] = make_field(3, 20, 1, 12);
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);

	    f[n++] = make_label(2, 34, "MI");
	    f[n++] = make_field(3, 34, 1, 1);
	    set_field_pad(f[n - 1], '?');
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);
	    break;
	case 2:
	    f[n++] = make_label(2, 0, "Host Name");
	    f[n++] = make_field(3, 0, 1, 18);
	    set_field_type(f[n - 1], TYPE_ALNUM, 1);

#ifdef NCURSES_VERSION
	    f[n++] = make_label(2, 20, "IP Address");
	    f[n++] = make_field(3, 20, 1, 12);
	    set_field_type(f[n - 1], TYPE_IPV4, 1);
#endif

	    break;

	case 3:
	    f[n++] = make_label(2, 0, "Four digits");
	    f[n++] = make_field(3, 0, 1, 18);
	    set_field_type(f[n - 1], TYPE_INTEGER, 4, 0, 0);

	    f[n++] = make_label(2, 20, "Numeric");
	    f[n++] = make_field(3, 20, 1, 12);
	    set_field_type(f[n - 1], TYPE_NUMERIC, 3, -10000.0, 100000000.0);

	    break;
	}

	f[n++] = make_label(5, 0, "Comments");
	f[n++] = make_field(6, 0, 4, 46);
	set_field_buffer(f[n - 1], 0, "HELLO\nWORLD!");
	set_field_buffer(f[n - 1], 1, "Hello\nWorld!");
    }

    f[n] = (FIELD *) 0;

    if ((form = new_form(f)) != 0) {

	display_form(form);

	w = form_win(form);
	also = newwin(getmaxy(stdscr) - getmaxy(w), COLS, getmaxy(w), 0);
	show_current_field(also, form);

	while (!finished) {
	    switch (edit_field(form, &c)) {
	    case E_OK:
		break;
	    case E_UNKNOWN_COMMAND:
		finished = my_form_driver(form, c);
		break;
	    default:
		beep();
		break;
	    }
	    show_current_field(also, form);
	}

	erase_form(form);

	free_form(form);
    }
    for (c = 0; f[c] != 0; c++) {
	void *ptr = field_userptr(f[c]);
	free(ptr);
	free_field(f[c]);
    }
    noraw();
    nl();

#ifdef NCURSES_MOUSE_VERSION
    mousemask(0, (mmask_t *) 0);
#endif
}