NCURSES_SP_NAME(new_form) (NCURSES_SP_DCLx FIELD **fields) { int err = E_SYSTEM_ERROR; FORM *form = (FORM *)0; T((T_CALLED("new_form(%p,%p)"), (void *)SP_PARM, (void *)fields)); if (IsValidScreen(SP_PARM)) { form = typeMalloc(FORM, 1); if (form) { T((T_CREATE("form %p"), (void *)form)); *form = *_nc_Default_Form; /* This ensures win and sub are always non-null, so we can derive always the SCREEN that this form is running on. */ form->win = StdScreen(SP_PARM); form->sub = StdScreen(SP_PARM); if ((err = Associate_Fields(form, fields)) != E_OK) { free_form(form); form = (FORM *)0; } } } if (!form) SET_ERROR(err); returnForm(form); }
NCURSES_SP_NAME(slk_clear) (NCURSES_SP_DCL0) { int rc = ERR; T((T_CALLED("slk_clear(%p)"), (void *) SP_PARM)); if (SP_PARM != 0 && SP_PARM->_slk != 0) { SP_PARM->_slk->hidden = TRUE; /* For simulated SLK's it looks much more natural to inherit those attributes from the standard screen */ SP_PARM->_slk->win->_nc_bkgd = StdScreen(SP_PARM)->_nc_bkgd; WINDOW_ATTRS(SP_PARM->_slk->win) = WINDOW_ATTRS(StdScreen(SP_PARM)); if (SP_PARM->_slk->win == StdScreen(SP_PARM)) { rc = OK; } else { werase(SP_PARM->_slk->win); rc = wrefresh(SP_PARM->_slk->win); } } returnCode(rc); }
set_term(SCREEN *screenp) { SCREEN *oldSP; SCREEN *newSP; T((T_CALLED("set_term(%p)"), (void *) screenp)); _nc_lock_global(curses); oldSP = CURRENT_SCREEN; _nc_set_screen(screenp); newSP = screenp; if (newSP != 0) { TINFO_SET_CURTERM(newSP, newSP->_term); #if !USE_REENTRANT curscr = CurScreen(newSP); newscr = NewScreen(newSP); stdscr = StdScreen(newSP); COLORS = newSP->_color_count; COLOR_PAIRS = newSP->_pair_count; #endif } else { TINFO_SET_CURTERM(oldSP, 0); #if !USE_REENTRANT curscr = 0; newscr = 0; stdscr = 0; COLORS = 0; COLOR_PAIRS = 0; #endif } _nc_unlock_global(curses); T((T_RETURN("%p"), (void *) oldSP)); return (oldSP); }
NCURSES_PUBLIC_VAR(stdscr) (void) { return CURRENT_SCREEN ? StdScreen(CURRENT_SCREEN) : 0; }
delscreen(SCREEN *sp) { int i; T((T_CALLED("delscreen(%p)"), (void *) sp)); _nc_lock_global(curses); if (delink_screen(sp)) { #ifdef USE_SP_RIPOFF ripoff_t *rop; if (safe_ripoff_sp && safe_ripoff_sp != safe_ripoff_stack) { for (rop = safe_ripoff_stack; rop != safe_ripoff_sp && (rop - safe_ripoff_stack) < N_RIPS; rop++) { if (rop->win) { (void) delwin(rop->win); rop->win = 0; } } } #endif (void) _nc_freewin(CurScreen(sp)); (void) _nc_freewin(NewScreen(sp)); (void) _nc_freewin(StdScreen(sp)); if (sp->_slk != 0) { if (sp->_slk->ent != 0) { for (i = 0; i < sp->_slk->labcnt; ++i) { FreeIfNeeded(sp->_slk->ent[i].ent_text); FreeIfNeeded(sp->_slk->ent[i].form_text); } free(sp->_slk->ent); } free(sp->_slk); sp->_slk = 0; } _nc_free_keytry(sp->_keytry); sp->_keytry = 0; _nc_free_keytry(sp->_key_ok); sp->_key_ok = 0; FreeIfNeeded(sp->_current_attr); FreeIfNeeded(sp->_color_table); FreeIfNeeded(sp->_color_pairs); FreeIfNeeded(sp->oldhash); FreeIfNeeded(sp->newhash); FreeIfNeeded(sp->hashtab); FreeIfNeeded(sp->_acs_map); FreeIfNeeded(sp->_screen_acs_map); NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG); NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx sp->_term); free(sp); /* * If this was the current screen, reset everything that the * application might try to use (except cur_term, which may have * multiple references in different screens). */ if (sp == CURRENT_SCREEN) { #if !USE_REENTRANT curscr = 0; newscr = 0; stdscr = 0; COLORS = 0; COLOR_PAIRS = 0; #endif _nc_set_screen(0); } } _nc_unlock_global(curses); returnVoid; }
/* * Write the soft labels to the soft-key window. */ static void slk_intern_refresh(SCREEN *sp) { int i; int fmt; SLK *slk; int numlab; if (sp == 0) return; slk = sp->_slk; fmt = sp->slk_format; numlab = NumLabels; if (slk->hidden) return; for (i = 0; i < slk->labcnt; i++) { if (slk->dirty || slk->ent[i].dirty) { if (slk->ent[i].visible) { if (numlab > 0 && SLK_STDFMT(fmt)) { #ifdef USE_TERM_DRIVER CallDriver_2(sp, hwlabel, i + 1, slk->ent[i].form_text); #else if (i < num_labels) { TPUTS_TRACE("plab_norm"); putp(TPARM_2(plab_norm, i + 1, slk->ent[i].form_text)); } #endif } else { if (fmt == 4) slk_paint_info(slk->win); wmove(slk->win, SLK_LINES(fmt) - 1, slk->ent[i].ent_x); if (sp->_slk) { (void) wattrset(slk->win, AttrOf(sp->_slk->attr)); } waddstr(slk->win, slk->ent[i].form_text); /* if we simulate SLK's, it's looking much more natural to use the current ATTRIBUTE also for the label window */ (void) wattrset(slk->win, WINDOW_ATTRS(StdScreen(sp))); } } slk->ent[i].dirty = FALSE; } } slk->dirty = FALSE; if (numlab > 0) { #ifdef USE_TERM_DRIVER CallDriver_1(sp, hwlabelOnOff, slk->hidden ? FALSE : TRUE); #else if (slk->hidden) { TPUTS_TRACE("label_off"); putp(label_off); } else { TPUTS_TRACE("label_on"); putp(label_on); } #endif } }
NCURSES_SP_NAME(newterm) (NCURSES_SP_DCLx NCURSES_CONST char *name, FILE *ofp, FILE *ifp) { int value; int errret; SCREEN *result = 0; SCREEN *current; TERMINAL *its_term; FILE *_ofp = ofp ? ofp : stdout; FILE *_ifp = ifp ? ifp : stdin; int cols; int slk_format; int filter_mode; TERMINAL *new_term = 0; START_TRACE(); T((T_CALLED("newterm(%p, \"%s\", %p,%p)"), (void *) SP_PARM, name, (void *) ofp, (void *) ifp)); #if NCURSES_SP_FUNCS assert(SP_PARM != 0); if (SP_PARM == 0) returnSP(SP_PARM); #endif _nc_init_pthreads(); _nc_lock_global(curses); current = CURRENT_SCREEN; its_term = (current ? current->_term : 0); INIT_TERM_DRIVER(); /* this loads the capability entry, then sets LINES and COLS */ if ( #if NCURSES_SP_FUNCS SP_PARM->_prescreen && #endif TINFO_SETUP_TERM(&new_term, name, fileno(_ofp), &errret, FALSE) != ERR) { _nc_set_screen(0); #ifdef USE_TERM_DRIVER assert(new_term != 0); #endif #if NCURSES_SP_FUNCS slk_format = SP_PARM->slk_format; filter_mode = SP_PARM->_filtered; #else slk_format = _nc_globals.slk_format; filter_mode = _nc_prescreen.filter_mode; #endif /* * This actually allocates the screen structure, and saves the original * terminal settings. */ if (NCURSES_SP_NAME(_nc_setupscreen) ( #if NCURSES_SP_FUNCS &SP_PARM, #endif *(ptrLines(SP_PARM)), *(ptrCols(SP_PARM)), _ofp, filter_mode, slk_format) == ERR) { _nc_set_screen(current); result = 0; } else { #ifdef USE_TERM_DRIVER TERMINAL_CONTROL_BLOCK *TCB; #elif !NCURSES_SP_FUNCS SP_PARM = CURRENT_SCREEN; #endif assert(SP_PARM != 0); cols = *(ptrCols(SP_PARM)); #ifdef USE_TERM_DRIVER _nc_set_screen(SP_PARM); TCB = (TERMINAL_CONTROL_BLOCK *) new_term; TCB->csp = SP_PARM; #endif /* * In setupterm() we did a set_curterm(), but it was before we set * CURRENT_SCREEN. So the "current" screen's terminal pointer was * overwritten with a different terminal. Later, in * _nc_setupscreen(), we set CURRENT_SCREEN and the terminal * pointer in the new screen. * * Restore the terminal-pointer for the pre-existing screen, if * any. */ if (current) current->_term = its_term; #ifdef USE_TERM_DRIVER SP_PARM->_term = new_term; #else new_term = SP_PARM->_term; #endif /* allow user to set maximum escape delay from the environment */ if ((value = _nc_getenv_num("ESCDELAY")) >= 0) { NCURSES_SP_NAME(set_escdelay) (NCURSES_SP_ARGx value); } /* if the terminal type has real soft labels, set those up */ if (slk_format && NumLabels > 0 && SLK_STDFMT(slk_format)) _nc_slk_initialize(StdScreen(SP_PARM), cols); SP_PARM->_ifd = fileno(_ifp); NCURSES_SP_NAME(typeahead) (NCURSES_SP_ARGx fileno(_ifp)); #ifdef TERMIOS SP_PARM->_use_meta = ((new_term->Ottyb.c_cflag & CSIZE) == CS8 && !(new_term->Ottyb.c_iflag & ISTRIP)); #else SP_PARM->_use_meta = FALSE; #endif SP_PARM->_endwin = FALSE; #ifndef USE_TERM_DRIVER /* * Check whether we can optimize scrolling under dumb terminals in * case we do not have any of these capabilities, scrolling * optimization will be useless. */ SP_PARM->_scrolling = ((scroll_forward && scroll_reverse) || ((parm_rindex || parm_insert_line || insert_line) && (parm_index || parm_delete_line || delete_line))); #endif NCURSES_SP_NAME(baudrate) (NCURSES_SP_ARG); /* sets a field in the screen structure */ SP_PARM->_keytry = 0; /* compute movement costs so we can do better move optimization */ #ifdef USE_TERM_DRIVER TCBOf(SP_PARM)->drv->scinit(SP_PARM); #else /* * Check for mismatched graphic-rendition capabilities. Most SVr4 * terminfo trees contain entries that have rmul or rmso equated to * sgr0 (Solaris curses copes with those entries). We do this only * for curses, since many termcap applications assume that * smso/rmso and smul/rmul are paired, and will not function * properly if we remove rmso or rmul. Curses applications * shouldn't be looking at this detail. */ #define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode)) SP_PARM->_use_rmso = SGR0_TEST(exit_standout_mode); SP_PARM->_use_rmul = SGR0_TEST(exit_underline_mode); /* compute movement costs so we can do better move optimization */ _nc_mvcur_init(); /* initialize terminal to a sane state */ _nc_screen_init(); #endif /* Initialize the terminal line settings. */ _nc_initscr(NCURSES_SP_ARG); _nc_signal_handler(TRUE); result = SP_PARM; } } _nc_unlock_global(curses); returnSP(result); }