1 /****************************************************************************
2 * Copyright (c) 1998,1999,2000 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 ****************************************************************************/
39 #include <curses.priv.h>
42 #include <term.h> /* num_labels, label_*, plab_norm */
44 MODULE_ID("$Id: lib_slk.c,v 1.20 2000/12/10 02:43:27 tom Exp $")
47 * We'd like to move these into the screen context structure, but cannot,
48 * because slk_init() is called before initscr()/newterm().
50 NCURSES_EXPORT_VAR(int)
51 _nc_slk_format = 0; /* one more than format specified in slk_init() */
54 * Paint the info line for the PC style SLK emulation.
58 slk_paint_info(WINDOW *win)
60 if (win && SP->slk_format == 4) {
63 mvwhline(win, 0, 0, 0, getmaxx(win));
66 for (i = 0; i < SP->_slk->maxlab; i++) {
67 if (win && SP->slk_format == 4) {
68 mvwaddch(win, 0, SP->_slk->ent[i].x, (chtype) 'F');
70 waddch(win, (chtype) '1' + i);
72 waddch(win, (chtype) '1');
73 waddch(win, (chtype) '0' + (i - 9));
81 * Initialize soft labels.
82 * Called from newterm()
85 _nc_slk_initialize(WINDOW *stwin, int cols)
91 T(("slk_initialize()"));
93 if (SP->_slk) { /* we did this already, so simply return */
95 } else if ((SP->_slk = typeCalloc(SLK, 1)) == 0)
99 SP->_slk->buffer = NULL;
100 SP->_slk->attr = A_STANDOUT;
102 SP->_slk->maxlab = (num_labels > 0) ?
103 num_labels : MAX_SKEY(_nc_slk_format);
104 SP->_slk->maxlen = (num_labels > 0) ?
105 label_width * label_height : MAX_SKEY_LEN(_nc_slk_format);
106 SP->_slk->labcnt = (SP->_slk->maxlab < MAX_SKEY(_nc_slk_format)) ?
107 MAX_SKEY(_nc_slk_format) : SP->_slk->maxlab;
109 SP->_slk->ent = typeCalloc(slk_ent, SP->_slk->labcnt);
110 if (SP->_slk->ent == NULL)
113 p = SP->_slk->buffer = (char *) calloc(2 * SP->_slk->labcnt, (1 + SP->_slk->maxlen));
114 if (SP->_slk->buffer == NULL)
117 for (i = 0; i < SP->_slk->labcnt; i++) {
118 SP->_slk->ent[i].text = p;
119 p += (1 + SP->_slk->maxlen);
120 SP->_slk->ent[i].form_text = p;
121 p += (1 + SP->_slk->maxlen);
122 memset(SP->_slk->ent[i].form_text, ' ', (unsigned) (SP->_slk->maxlen));
123 SP->_slk->ent[i].visible = (i < SP->_slk->maxlab);
125 if (_nc_slk_format >= 3) { /* PC style */
126 int gap = (cols - 3 * (3 + 4 * SP->_slk->maxlen)) / 2;
131 for (i = x = 0; i < SP->_slk->maxlab; i++) {
132 SP->_slk->ent[i].x = x;
133 x += SP->_slk->maxlen;
134 x += (i == 3 || i == 7) ? gap : 1;
136 if (_nc_slk_format == 4)
137 slk_paint_info(stwin);
139 if (_nc_slk_format == 2) { /* 4-4 */
140 int gap = cols - (SP->_slk->maxlab * SP->_slk->maxlen) - 6;
144 for (i = x = 0; i < SP->_slk->maxlab; i++) {
145 SP->_slk->ent[i].x = x;
146 x += SP->_slk->maxlen;
147 x += (i == 3) ? gap : 1;
150 if (_nc_slk_format == 1) { /* 1 -> 3-2-3 */
151 int gap = (cols - (SP->_slk->maxlab * SP->_slk->maxlen) - 5)
156 for (i = x = 0; i < SP->_slk->maxlab; i++) {
157 SP->_slk->ent[i].x = x;
158 x += SP->_slk->maxlen;
159 x += (i == 2 || i == 4) ? gap : 1;
165 SP->_slk->dirty = TRUE;
166 if ((SP->_slk->win = stwin) == NULL) {
169 FreeIfNeeded(SP->_slk->buffer);
170 FreeIfNeeded(SP->_slk->ent);
172 SP->_slk = (SLK *) 0;
177 /* We now reset the format so that the next newterm has again
178 * per default no SLK keys and may call slk_init again to
179 * define a new layout. (juergen 03-Mar-1999)
181 SP->slk_format = _nc_slk_format;
187 * Restore the soft labels on the screen.
192 T((T_CALLED("slk_restore()")));
194 if (SP->_slk == NULL)
196 SP->_slk->hidden = FALSE;
197 SP->_slk->dirty = TRUE;
198 /* we have to repaint info line eventually */
199 slk_paint_info(SP->_slk->win);
201 returnCode(slk_refresh());