inline void select_form() { pos_form_cursor(url_form); form_driver(url_form, ' '); form_driver(url_form, REQ_LEFT_CHAR); form_driver(url_form, REQ_DEL_CHAR); wrefresh(input_window); }
/* * sends command to the form */ static int wdg_input_driver(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) { WDG_WO_EXT(struct wdg_input_handle, ww); int c, v; /* variable currently not used */ (void) mouse; WDG_DEBUG_MSG("keypress driver: %d", key); /* virtualize the command */ c = form_driver(ww->form, (v = wdg_input_virtualize(wo, key)) ); set_field_back(current_field(ww->form), A_REVERSE); /* one item has been selected */ if (c == E_UNKNOWN_COMMAND) { /* send a command to the form in order to validate the current field */ form_driver(ww->form, REQ_NEXT_FIELD); /* * put the temp buffer in the real one * call the callback * and destroy the object */ wdg_input_consolidate(wo); return WDG_EFINISHED; } wnoutrefresh(ww->fwin); return WDG_E_SUCCESS; }
/* * Move using the given form driver request. * De-highlights the old selection and highlights the new one. */ void ListBox::selectField(int formDriverReq) { //Unhighlight cur field set_field_back(current_field(m_pForm), A_NORMAL); form_driver(m_pForm, formDriverReq); form_driver(m_pForm, REQ_BEG_LINE); set_field_back(current_field(m_pForm), A_STANDOUT); }
static void on_form_key(int key) { static const struct { int key; int request; } key_map[] = { { KEY_LEFT, REQ_PREV_CHAR }, { KEY_RIGHT, REQ_NEXT_CHAR }, { KEY_HOME, REQ_BEG_FIELD }, { KEY_BACKSPACE, REQ_DEL_PREV }, { KEY_DC, REQ_DEL_CHAR }, { KEY_BEG, REQ_BEG_FIELD }, { KEY_END, REQ_END_FIELD }, }; unsigned int i; if (key >= 32 && key < 256) { form_driver(form, key); return; } for (i = 0; i < ARRAY_SIZE(key_map); ++i) if (key_map[i].key == key) { form_driver(form, key_map[i].request); break; } }
void respuesta(FORM *formulario){ while((ch = getch()) != KEY_F(1)) { switch(ch) { case KEY_DOWN: /* Go to next field */ form_driver(formulario, REQ_NEXT_FIELD); /* Go to the end of the present buffer */ /* Leaves nicely at the last character */ form_driver(formulario, REQ_END_LINE); break; case KEY_UP: /* Go to previous field */ form_driver(formulario, REQ_PREV_FIELD); form_driver(formulario, REQ_END_LINE); break; default: /* If this is a normal character, it gets */ /*formulario Printed */ form_driver(formulario, ch); break; } } }
void ListBox::setCurRow(int r) { set_field_back(current_field(m_pForm), A_NORMAL); form_driver(m_pForm, REQ_FIRST_FIELD); for (int i = 0; i < r; i++) { form_driver(m_pForm, REQ_NEXT_FIELD); } form_driver(m_pForm, REQ_BEG_LINE); set_field_back(current_field(m_pForm), A_STANDOUT); m_curRow = r; }
static void reset_query(void) { clear_menu(True); strcpy(query, ""); query_len = 0; form_driver(form, REQ_CLR_FIELD); form_driver(form, REQ_VALIDATION); g_list_free(results); results = NULL; show_recent_apps(); prepare_for_new_results(False); }
bool InputForm::Init() { field = (FIELD **)calloc(choices*2+1, sizeof(FIELD *)); for (int i = 0; i < choices; ++i) { field[2*i] = new_field(1, 30, 4+i*2, 2, 02, 02); field[2*i+1] = new_field(1, 20, 4+i*2, 30, 02, 02); set_field_back(field[2*i+1], A_UNDERLINE); field_opts_off(field[2*i+1], O_AUTOSKIP); set_field_buffer(field[2*i], 0, itemNames[i].c_str()); set_field_back(field[2*i], O_EDIT); } field[choices*2] = NULL; form = new_form(field); scale_form(form, &formRows, &formCols); win = newwin(formRows+8, formCols+20, LINES/2-formRows/2 -6, COLS/2-10-formCols/2); keypad(win, TRUE); set_form_win(form, win); set_form_sub(form, derwin(win, formRows, formCols, 2, 2)); box(win, 0, 0); wattron(win, COLOR_PAIR(1)); mvwprintw(win, 0, formCols/2+8-title.size()/2, "%s", title.c_str()); wattroff(win, COLOR_PAIR(1)); post_form(form); panel = new_panel(win); switchOkCancle(); update_panels(); doupdate(); form_driver(form, REQ_NEXT_FIELD); return true; }
static char const* brsh_get_input(void) { /* get the field content */ form_driver(frm_input, REQ_VALIDATION); char *fld_buffer = field_buffer(fld_input, 0); /* trim the left-hand side */ while (isspace(*fld_buffer)) fld_buffer++; /* copy the buffer */ static char *input_buffer = NULL; if (input_buffer) free(input_buffer); long size = strlen(fld_buffer); input_buffer = malloc(size + 1); if (!input_buffer) brain_fatal_("Not enough memory\n"); strcpy(input_buffer, fld_buffer); /* trim the right-hand side */ for (long i = size-1; i >= 0; i--) { if (!isspace(input_buffer[i])) { input_buffer[i+1] = 0; break; } } return input_buffer; }
/* * Switch from field to buttons. * This change the foreground color of the button so the user think the cursor * is on the first button. */ static void switch_to_buttons(void) { form_driver(popup_form, REQ_VALIDATION); menu_driver(popup_menu, REQ_FIRST_ITEM); is_on_button = true; set_menu_fore(popup_menu, A_REVERSE); // "show" the button }
int save_draw(ui_t *ui) { char field_value[80]; // Get panel information save_info_t *info = save_info(ui); // Get filter stats sip_stats_t stats = sip_calls_stats(); mvwprintw(ui->win, 7, 3, "( ) all dialogs "); mvwprintw(ui->win, 8, 3, "( ) selected dialogs [%d]", call_group_count(info->group)); mvwprintw(ui->win, 9, 3, "( ) filtered dialogs [%d]", stats.displayed); // Print 'current SIP message' field label if required if (info->msg != NULL) mvwprintw(ui->win, 10, 3, "( ) current SIP message"); mvwprintw(ui->win, 7, 35, "( ) .pcap (SIP)"); mvwprintw(ui->win, 8, 35, "( ) .pcap (SIP + RTP)"); mvwprintw(ui->win, 9, 35, "( ) .txt"); // Get filename field value. memset(field_value, 0, sizeof(field_value)); strcpy(field_value, field_buffer(info->fields[FLD_SAVE_FILE], 0)); strtrim(field_value); mvwprintw(ui->win, 4, 60, " "); if (strstr(field_value, ".pcap")) { info->saveformat = (setting_enabled(SETTING_CAPTURE_RTP))? SAVE_PCAP_RTP : SAVE_PCAP; } else if (strstr(field_value, ".txt")) { info->saveformat = SAVE_TXT; } else { if (info->saveformat == SAVE_PCAP || info->saveformat == SAVE_PCAP_RTP) mvwprintw(ui->win, 4, 60, ".pcap"); else mvwprintw(ui->win, 4, 60, ".txt "); } set_field_buffer(info->fields[FLD_SAVE_ALL], 0, (info->savemode == SAVE_ALL) ? "*" : " "); set_field_buffer(info->fields[FLD_SAVE_SELECTED], 0, (info->savemode == SAVE_SELECTED) ? "*" : " "); set_field_buffer(info->fields[FLD_SAVE_DISPLAYED], 0, (info->savemode == SAVE_DISPLAYED) ? "*" : " "); set_field_buffer(info->fields[FLD_SAVE_MESSAGE], 0, (info->savemode == SAVE_MESSAGE) ? "*" : " "); set_field_buffer(info->fields[FLD_SAVE_PCAP], 0, (info->saveformat == SAVE_PCAP) ? "*" : " "); set_field_buffer(info->fields[FLD_SAVE_PCAP_RTP], 0, (info->saveformat == SAVE_PCAP_RTP) ? "*" : " "); set_field_buffer(info->fields[FLD_SAVE_TXT], 0, (info->saveformat == SAVE_TXT) ? "*" : " "); // Show disabled options with makers if (!setting_enabled(SETTING_CAPTURE_RTP)) set_field_buffer(info->fields[FLD_SAVE_PCAP_RTP], 0, "-"); set_current_field(info->form, current_field(info->form)); form_driver(info->form, REQ_VALIDATION); return 0; }
static int my_form_driver(FORM * form, int c) { static bool insert_mode = TRUE; FIELD *field; switch (c) { case MY_QUIT: if (form_driver(form, REQ_VALIDATION) == E_OK) return (TRUE); break; case MY_HELP: help_edit_field(); break; case MY_EDT_MODE: if ((field = current_field(form)) != 0) { set_current_field(form, another_field(form, field)); if ((unsigned) field_opts(field) & O_EDIT) { field_opts_off(field, O_EDIT); set_field_status(field, 0); } else { field_opts_on(field, O_EDIT); } set_current_field(form, field); } break; case MY_INS_MODE: /* there should be a form_status() function, but there is none */ if (!insert_mode) { if (form_driver(form, REQ_INS_MODE) == E_OK) { insert_mode = TRUE; } } else { if (form_driver(form, REQ_OVL_MODE) == E_OK) { insert_mode = FALSE; } } show_insert_mode(insert_mode); refresh(); break; default: beep(); break; } return (FALSE); }
int main() { FIELD *f1[2]; FORM *frm1; chtype ch; int error; HOOK fptr=getbuf; initscr(); f1[0]=new_field(24,80,0,0,1,1); assert(f1[0]!=NULL); f1[1]=NULL; frm1=new_form(f1); assert(frm1!=NULL); set_field_fore(f1[0],A_REVERSE); field_opts_off(f1[0],O_STATIC); //set_field_buffer(f1[0],0,"Sajid"); set_field_type(f1[0],TYPE_ALPHA,80); set_field_term(f1[0],fptr); post_form(frm1); wrefresh(stdscr); keypad(stdscr,TRUE); while((ch=getch())!=KEY_F(3)) { switch(ch) { case KEY_LEFT: error=form_driver(frm1,REQ_PREV_CHAR); if(error==E_REQUEST_DENIED) form_driver(frm1,REQ_SCR_BCHAR); break; case KEY_RIGHT: form_driver(frm1,REQ_NEXT_CHAR); break; default: form_driver(frm1,ch); break; } } unpost_form(frm1); free_form(frm1); free_field(f1[0]); getch(); printw(ptr); endwin(); }
void AddProjectForm::eventhandle(NEvent* ev) //обработчик событий { if ( ev->done ) return; NMouseEvent* mevent = (NMouseEvent*)ev; if ( ev->type == NEvent::evMOUSE) { NForm::eventhandle(ev); //предок } if ( ev->type == NEvent::evKB ) { ev->done = true; switch(ev->keycode) { case KEY_ENTER: case '\n': //ENTER { form_driver(frm, REQ_NEXT_FIELD); //костыль чтобы текущее поле не потеряло значение char* email = strlowcase(rtrim(field_buffer(fields[emailfield],0))); char* passw = rtrim(field_buffer(fields[passwfield],0)); kLogPrintf("AddProjectForm OK name=[%s] url=[%s] email=[%s]\n passw=[%s]\n", projname.c_str(), projurl.c_str(), email, passw); if (srv!=NULL) { std::string errmsg; bool success = true; if (!userexist) //если аккаунта еще нет то создаем { char* username = strlowcase(rtrim(field_buffer(fields[usernamefield],0))); char* teamname = rtrim(field_buffer(fields[teamfield],0)); success = srv->createaccount(projurl.c_str(),email,passw, username, teamname, errmsg); } if (success) success = srv->projectattach(projurl.c_str(), projname.c_str(), email, passw, errmsg); //подключить проект if (success) putevent(new TuiEvent(evADDPROJECT)); //создаем событие чтобы закрыть форму else { //СООБЩЕНИЕ ОБ ОШИБКЕ errmsg = " Error: " + errmsg; set_field_buffer(fields[errmsgfield], 0, errmsg.c_str()); field_opts_on(fields[errmsgfield], O_VISIBLE); //делаем видимой строку ошибки this->refresh(); } } break; } case 27: putevent(new TuiEvent(evADDPROJECT)); //код закрытия окна break; default: kLogPrintf("AddProjectForm::KEYCODE=%d\n", ev->keycode); ev->done = false; NForm::eventhandle(ev); //предок break; } //switch } }
void DialogForm::draw() { box(m_pWindow, 0, 0); //Draw title mvwprintw(m_pWindow, 1, 1, getTitle().data()); WindowUtil::drawHLine(m_pWindow, 1, 2, m_cols + 1); drawComponents(); //Draw cancel / ok commands mvwprintw(m_pWindow, m_rows + 4, 1, "Cancel: F3"); mvwprintw(m_pWindow, m_rows + 4, m_cols - 9, "Continue: F2"); form_driver(m_pForm, REQ_FIRST_FIELD); form_driver(m_pForm, REQ_END_LINE); wrefresh(m_pWindow); }
void ListBox::setSelected(bool sel) { Component::setSelected(sel); if (sel) { selectField(REQ_FIRST_FIELD); } else { set_field_back(current_field(m_pForm), A_NORMAL); form_driver(m_pForm, REQ_BEG_LINE); } m_curRow = 0; wrefresh(m_pPanel->getWindow()); }
void InputForm::delAchar() { if (itemTypes[index].compare("checklist") == 0) { return; } int n = itemInputs[index].size(); if (n == 0) return ; form_driver(form, REQ_DEL_PREV); itemInputs[index].erase(itemInputs[index].end()-1); }
void InputForm::fillField() { int n = itemInputs[index].size(); if (itemTypes[index].compare("checklist") == 0) { fillCheckList(itemInputs[index].compare("y") == 0); } else if (itemTypes[index].compare("password") == 0) { for (int i = 0; i < n; i++) { form_driver(form, '*'); } } else { for (int i = 0; i < n; i++) { form_driver(form, itemInputs[index][i]); } } }
static void brsh_runloop(void) { timeout(0); /* don't wait for input characters; also allows us to do other things while the user isn't typing */ for (;;) { int input_chr = getch(); switch (input_chr) { case KEY_LEFT: form_driver(frm_input, REQ_LEFT_CHAR); break; case KEY_RIGHT: form_driver(frm_input, REQ_RIGHT_CHAR); break; case KEY_DOWN: form_driver(frm_input, REQ_DOWN_CHAR); break; case KEY_UP: form_driver(frm_input, REQ_UP_CHAR); break; case KEY_ENTER: case '\n': case '\r': brsh_handle_input(brsh_get_input()); brsh_clear_input(); break; case KEY_BACKSPACE: case KEY_DC: case 127: form_driver(frm_input, REQ_LEFT_CHAR); form_driver(frm_input, REQ_DEL_CHAR); break; case 27: /* ESC */ brsh_clear_input(); break; case KEY_F(1): brsh_handle_input("help"); break; case ERR: break; case KEY_RESIZE: break; default: form_driver(frm_input, input_chr); break; } brsh_handle_io(); usleep(BRSH_RUNLOOP_SLEEP_USEC); } }
gint viper_form_driver(FORM *form,gint request,guint32 flags, chtype active,chtype normal,gshort cursor_color) { WINDOW *window; chtype eraser; chtype temp_ch; gint x,y; gint retval; gshort fg,bg; if(form==NULL) return ERR; if(form_sub(form)!=form_win(form)) window=form_sub(form); else window=form_win(form); getyx(window,y,x); eraser=field_back(current_field(form)); mvwchgat(window,y,x,1,(eraser & A_ATTRIBUTES), PAIR_NUMBER(eraser & A_COLOR),NULL); retval=form_driver(form,request); if(flags & FORM_COLORIZE) viper_form_colorize(form,active,normal,active,normal); if(flags & FORM_CURSOR_NONE) return retval; temp_ch=termattrs(); if((flags & FORM_CURSOR_ULINE) && !(temp_ch & A_UNDERLINE)) return ERR; getyx(window,y,x); temp_ch=field_fore(current_field(form)); if(flags & FORM_CURSOR_ULINE) mvwchgat(window,y,x,1,(temp_ch & A_ATTRIBUTES) | A_UNDERLINE, PAIR_NUMBER(temp_ch & A_COLOR),NULL); else { pair_content(PAIR_NUMBER(temp_ch & A_COLOR),&fg,&bg); if(cursor_color!=-1) { bg=cursor_color; mvwchgat(window,y,x,1,A_NORMAL,viper_color_pair(fg,bg),NULL); } else mvwchgat(window,y,x,1,A_REVERSE,viper_color_pair(fg,bg),NULL); } return E_OK; }
static char *dup_current_name(void) { int rows, cols, max, i; char *s; if (form_driver(form, REQ_VALIDATION) == E_OK) { dynamic_field_info(fields[1], &rows, &cols, &max); s = ccalloc(1, cols + 1); memcpy(s, field_buffer(fields[1], 0), cols); for (i = strlen(s) - 1; i >= 0 && s[i] == ' '; --i) s[i] = '\0'; return s; } else { return cstrdup(""); } }
void InputForm::fillCheckList(bool choose) { form_driver(form, REQ_CLR_FIELD); form_driver(form, '['); if (choose) { form_driver(form, '*'); } else { form_driver(form, ' '); } form_driver(form, ']'); form_driver(form, REQ_PREV_CHAR); form_driver(form, REQ_PREV_CHAR); }
static void on_window_size_changed(void) { form_driver(form, REQ_VALIDATION); /* save field value */ unpost_form(form); if (!create()) return; /* * This call fails because ncurses does not allow changing options of * the current field, and we cannot change the current field because * there is only one. The only way to make this work would be to throw * away and recreate all fields. */ field_opts_off(fields[1], O_BLANK); post_form(form); }
/*--------------------------------------------------------------------------- | Facility : libnform | Function : static int Associate_Fields(FORM *form, FIELD **fields) | | Description : Set association between form and array of fields. | If there are fields, position to first active field. | | Return Values : E_OK - success | any other - error occurred +--------------------------------------------------------------------------*/ INLINE static int Associate_Fields(FORM *form, FIELD **fields) { int res = Connect_Fields(form,fields); if (res == E_OK) { if (form->maxpage>0) { form->curpage = 0; form_driver(form,FIRST_ACTIVE_MAGIC); } else { form->curpage = -1; form->current = (FIELD *)0; } } return(res); }
void ListBox::createForm() { if (m_pForm != 0) { unpost_form(m_pForm); free_form(m_pForm); } m_pForm = new_form(m_pFields); int rows, cols; scale_form(m_pForm, &rows, &cols); set_form_win(m_pForm, m_pPanel->getWindow()); set_form_sub(m_pForm, derwin(m_pPanel->getWindow(), getHeight() - 2, getWidth() - 2, getY() + 1, getX() + 1)); post_form(m_pForm); form_driver(m_pForm, REQ_LAST_FIELD); if (isSelected()) { selectField(REQ_PREV_FIELD); } }
bool DialogForm::isFieldValid() { FIELD* pField = current_field(m_pForm); if (pField == 0) { return true; } //Get field type /*void* usrPtr = field_userptr(pField); FieldType type = usrPtr == 0 ? FIELDTYPE_NONE : *(FieldType*)usrPtr; //Get field text std::string fieldText = field_buffer(pField, 0); StringUtil::trimEnd(fieldText);*/ //Check if field is valid if (form_driver(m_pForm, REQ_VALIDATION) == E_INVALID_FIELD/* || (type == FIELDTYPE_EMAIL && !isValidEmail(fieldText)) || (type == FIELDTYPE_NAME && !isValidName(fieldText))*/) { //Field is invalid, highlight it set_field_back(current_field(m_pForm), A_STANDOUT); return false; } set_field_back(current_field(m_pForm), A_UNDERLINE); return true; }
char* get_filename() { int size, i; char *dirname, *filename, *absname; inputted = 0; create_input_form(); dirname = getcwd(NULL, 0); filename = strrchr(http_url.abs_path, '/') + 1; if (strlen(filename) == 0) { size = strlen(dirname) + strlen(http_url.host) + 2; absname = (char*) malloc(size); sprintf(absname, "%s/%s", dirname, http_url.host); } else { size = strlen(dirname) + strlen(filename) + 2; absname = (char*) malloc(size); sprintf(absname, "%s/%s", dirname, filename); } free(dirname); wclear(input_window); wprintw(input_window, "File: "); wrefresh(input_window); /* Should use set_field_buffer, but it doesn't work */ for (i = 0; i < size; i++) form_driver(url_form, absname[i]); free(absname); select_form(); set_input_action(FILE_INPUTTING); pthread_create(&input_thread, NULL, open_input_thread, NULL); pthread_join(input_thread, NULL); return file; }
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; }
void call_list_form_activate(PANEL *panel, int active) { call_list_info_t *info = call_list_info(panel); // Store form state info->form_active = active; if (active) { set_current_field(info->form, info->fields[FLD_LIST_FILTER]); // Show cursor curs_set(1); // Change current field background set_field_back(info->fields[FLD_LIST_FILTER], A_REVERSE); } else { set_current_field(info->form, NULL); // Hide cursor curs_set(0); // Change current field background set_field_back(info->fields[FLD_LIST_FILTER], A_NORMAL); } post_form(info->form); form_driver(info->form, REQ_END_LINE); }
void exec_action_context_service_config(int ch) { FIELD *field; int cur_page = form_page(my_form); switch (ch) { case KEY_DOWN: form_driver(my_form, REQ_NEXT_FIELD); form_driver(my_form, REQ_END_LINE); break; case KEY_UP: form_driver(my_form, REQ_PREV_FIELD); form_driver(my_form, REQ_END_LINE); break; case KEY_NPAGE: form_driver(my_form, REQ_NEXT_PAGE); set_form_page(my_form, ++cur_page); __renderers_services_config_paging(); break; case KEY_PPAGE: form_driver(my_form, REQ_PREV_PAGE); set_form_page(my_form, --cur_page); __renderers_services_config_paging(); break; case KEY_ENTER: case 10: field = current_field(my_form); __ncurses_print_info_in_footer(false, field_buffer(field, 0)); break; } }