1 /****************************************************************************
2 * Copyright (c) 1998 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 ****************************************************************************/
37 ** The routine set_term().
41 #include <curses.priv.h>
43 #include <term.h> /* cur_term */
45 MODULE_ID("$Id: lib_set_term.c,v 1.46 1999/07/24 20:05:49 tom Exp $")
47 SCREEN * set_term(SCREEN *screenp)
51 T((T_CALLED("set_term(%p)"), screenp));
54 _nc_set_screen(screenp);
56 set_curterm(SP->_term);
60 COLORS = SP->_color_count;
61 COLOR_PAIRS = SP->_pair_count;
62 memcpy(acs_map, SP->_acs_map, sizeof(chtype)*ACS_LEN);
64 T((T_RETURN("%p"), oldSP));
68 static void _nc_free_keytry(struct tries *kt)
71 _nc_free_keytry(kt->child);
72 _nc_free_keytry(kt->sibling);
78 * Free the storage associated with the given SCREEN sp.
80 void delscreen(SCREEN *sp)
82 SCREEN **scan = &_nc_screen_chain;
84 T((T_CALLED("delscreen(%p)"), sp));
90 *scan = sp->_next_screen;
93 scan = &(*scan)->_next_screen;
96 _nc_freewin(sp->_curscr);
97 _nc_freewin(sp->_newscr);
98 _nc_freewin(sp->_stdscr);
99 _nc_free_keytry(sp->_keytry);
100 _nc_free_keytry(sp->_key_ok);
102 FreeIfNeeded(sp->_color_table);
103 FreeIfNeeded(sp->_color_pairs);
105 FreeIfNeeded(sp->oldhash);
106 FreeIfNeeded(sp->newhash);
108 del_curterm(sp->_term);
113 * If this was the current screen, reset everything that the
114 * application might try to use (except cur_term, which may have
115 * multiple references in different screens).
128 static ripoff_t rippedoff[5];
129 static ripoff_t *rsp = rippedoff;
130 #define N_RIPS SIZEOF(rippedoff)
132 static bool no_mouse_event (SCREEN *sp GCC_UNUSED) { return FALSE; }
133 static bool no_mouse_inline(SCREEN *sp GCC_UNUSED) { return FALSE; }
134 static bool no_mouse_parse (int code GCC_UNUSED) { return TRUE; }
135 static void no_mouse_resume(SCREEN *sp GCC_UNUSED) { }
136 static void no_mouse_wrap (SCREEN *sp GCC_UNUSED) { }
138 int _nc_setupscreen(short slines, short const scolumns, FILE *output)
139 /* OS-independent screen initializations */
141 int bottom_stolen = 0;
144 assert(SP==0); /* has been reset in newterm() ! */
145 if (!_nc_alloc_screen())
148 SP->_next_screen = _nc_screen_chain;
149 _nc_screen_chain = SP;
151 _nc_set_buffer(output, TRUE);
152 SP->_term = cur_term;
154 SP->_lines_avail = slines;
155 SP->_columns = scolumns;
165 SP->_cursor = -1; /* cannot know real cursor shape */
166 #ifdef NCURSES_NO_PADDING
167 SP->_no_padding = getenv("NCURSES_NO_PADDING") != 0;
170 SP->_maxclick = DEFAULT_MAXCLICK;
171 SP->_mouse_event = no_mouse_event;
172 SP->_mouse_inline = no_mouse_inline;
173 SP->_mouse_parse = no_mouse_parse;
174 SP->_mouse_resume = no_mouse_resume;
175 SP->_mouse_wrap = no_mouse_wrap;
178 /* initialize the panel hooks */
179 SP->_panelHook.top_panel = (struct panel*)0;
180 SP->_panelHook.bottom_panel = (struct panel*)0;
181 SP->_panelHook.stdscr_pseudo_panel = (struct panel*)0;
184 * If we've no magic cookie support, we suppress attributes that xmc
185 * would affect, i.e., the attributes that affect the rendition of a
186 * space. Note that this impacts the alternate character set mapping
189 if (magic_cookie_glitch > 0) {
191 SP->_xmc_triggers = termattrs() & (
199 SP->_xmc_suppress = SP->_xmc_triggers & (chtype)~(A_BOLD);
201 T(("magic cookie attributes %s", _traceattr(SP->_xmc_suppress)));
204 * To keep this simple, suppress all of the optimization hooks
205 * except for clear_screen and the cursor addressing.
211 magic_cookie_glitch = -1;
216 memcpy(SP->_acs_map, acs_map, sizeof(chtype)*ACS_LEN);
221 _nc_windows = 0; /* no windows yet */
226 T(("creating newscr"));
227 if ((newscr = newwin(slines, scolumns, 0, 0)) == 0)
230 T(("creating curscr"));
231 if ((curscr = newwin(slines, scolumns, 0, 0)) == 0)
234 SP->_newscr = newscr;
235 SP->_curscr = curscr;
237 SP->_resize = resizeterm;
240 newscr->_clear = TRUE;
241 curscr->_clear = FALSE;
243 for (i=0, rsp = rippedoff; rsp->line && (i < N_RIPS); rsp++, i++) {
246 int count = (rsp->line < 0) ? -rsp->line : rsp->line;
249 w = newwin(count,scolumns,SP->_lines_avail - count,0);
252 rsp->hook(w, scolumns);
253 bottom_stolen += count;
258 w = newwin(count,scolumns, 0, 0);
261 rsp->hook(w, scolumns);
262 SP->_topstolen += count;
267 SP->_lines_avail -= count;
271 /* reset the stack */
274 T(("creating stdscr"));
275 assert ((SP->_lines_avail + SP->_topstolen + bottom_stolen) == slines);
276 if ((stdscr = newwin(LINES = SP->_lines_avail, scolumns, 0, 0)) == 0)
278 SP->_stdscr = stdscr;
286 /* The internal implementation interprets line as the number of
287 lines to rip off from the top or bottom.
290 _nc_ripoffline(int line, int (*init)(WINDOW *,int))
295 if (rsp >= rippedoff + N_RIPS)
307 ripoffline(int line, int (*init)(WINDOW *, int))
309 T((T_CALLED("ripoffline(%d,%p)"), line, init));
314 returnCode(_nc_ripoffline ((line<0) ? -1 : 1, init));