150276Speter/****************************************************************************
2184989Srafan * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc.              *
350276Speter *                                                                          *
450276Speter * Permission is hereby granted, free of charge, to any person obtaining a  *
550276Speter * copy of this software and associated documentation files (the            *
650276Speter * "Software"), to deal in the Software without restriction, including      *
750276Speter * without limitation the rights to use, copy, modify, merge, publish,      *
850276Speter * distribute, distribute with modifications, sublicense, and/or sell       *
950276Speter * copies of the Software, and to permit persons to whom the Software is    *
1050276Speter * furnished to do so, subject to the following conditions:                 *
1150276Speter *                                                                          *
1250276Speter * The above copyright notice and this permission notice shall be included  *
1350276Speter * in all copies or substantial portions of the Software.                   *
1450276Speter *                                                                          *
1550276Speter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
1650276Speter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
1750276Speter * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
1850276Speter * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
1950276Speter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
2050276Speter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
2150276Speter * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2250276Speter *                                                                          *
2350276Speter * Except as contained in this notice, the name(s) of the above copyright   *
2450276Speter * holders shall not be used in advertising or otherwise to promote the     *
2550276Speter * sale, use or other dealings in this Software without prior written       *
2650276Speter * authorization.                                                           *
2750276Speter ****************************************************************************/
2850276Speter
2950276Speter/****************************************************************************
3050276Speter *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
3150276Speter *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32166124Srafan *     and: Juergen Pfeifer                         1996-on                 *
33166124Srafan *     and: Thomas E. Dickey                                                *
3450276Speter ****************************************************************************/
3550276Speter
3650276Speter/*
3750276Speter *	lib_slkrefr.c
3850276Speter *	Write SLK window to the (virtual) screen.
3950276Speter */
4050276Speter#include <curses.priv.h>
4176726Speter#include <term.h>		/* num_labels, label_*, plab_norm */
4250276Speter
43184989SrafanMODULE_ID("$Id: lib_slkrefr.c,v 1.17 2008/09/27 14:07:53 juergen Exp $")
4450276Speter
4550276Speter/*
46184989Srafan * Paint the info line for the PC style SLK emulation.
47184989Srafan */
48184989Srafanstatic void
49184989Srafanslk_paint_info(WINDOW *win)
50184989Srafan{
51184989Srafan    SCREEN *sp = _nc_screen_of(win);
52184989Srafan
53184989Srafan    if (win && sp && (sp->slk_format == 4)) {
54184989Srafan	int i;
55184989Srafan
56184989Srafan	mvwhline(win, 0, 0, 0, getmaxx(win));
57184989Srafan	wmove(win, 0, 0);
58184989Srafan
59184989Srafan	for (i = 0; i < sp->_slk->maxlab; i++) {
60184989Srafan	    mvwprintw(win, 0, sp->_slk->ent[i].ent_x, "F%d", i + 1);
61184989Srafan	}
62184989Srafan    }
63184989Srafan}
64184989Srafan
65184989Srafan/*
6650276Speter * Write the soft labels to the soft-key window.
6750276Speter */
6850276Speterstatic void
6976726Speterslk_intern_refresh(SLK * slk)
7050276Speter{
7176726Speter    int i;
7276726Speter    int fmt = SP->slk_format;
7350276Speter
7476726Speter    for (i = 0; i < slk->labcnt; i++) {
7576726Speter	if (slk->dirty || slk->ent[i].dirty) {
7676726Speter	    if (slk->ent[i].visible) {
7776726Speter		if (num_labels > 0 && SLK_STDFMT(fmt)) {
7876726Speter		    if (i < num_labels) {
7976726Speter			TPUTS_TRACE("plab_norm");
80166124Srafan			putp(TPARM_2(plab_norm, i + 1, slk->ent[i].form_text));
8176726Speter		    }
8276726Speter		} else {
83184989Srafan		    if (fmt == 4)
84184989Srafan			slk_paint_info(slk->win);
85166124Srafan		    wmove(slk->win, SLK_LINES(fmt) - 1, slk->ent[i].ent_x);
86184989Srafan		    if (SP->_slk) {
87166124Srafan			wattrset(slk->win, AttrOf(SP->_slk->attr));
88166124Srafan		    }
89166124Srafan		    waddstr(slk->win, slk->ent[i].form_text);
9076726Speter		    /* if we simulate SLK's, it's looking much more
9176726Speter		       natural to use the current ATTRIBUTE also
9276726Speter		       for the label window */
93166124Srafan		    wattrset(slk->win, WINDOW_ATTRS(stdscr));
9450276Speter		}
9576726Speter	    }
9676726Speter	    slk->ent[i].dirty = FALSE;
9750276Speter	}
9876726Speter    }
9976726Speter    slk->dirty = FALSE;
10050276Speter
10176726Speter    if (num_labels > 0) {
10276726Speter	if (slk->hidden) {
10376726Speter	    TPUTS_TRACE("label_off");
10476726Speter	    putp(label_off);
10576726Speter	} else {
10676726Speter	    TPUTS_TRACE("label_on");
10776726Speter	    putp(label_on);
10850276Speter	}
10976726Speter    }
11050276Speter}
11150276Speter
11250276Speter/*
11350276Speter * Refresh the soft labels.
11450276Speter */
11576726SpeterNCURSES_EXPORT(int)
11650276Speterslk_noutrefresh(void)
11750276Speter{
11876726Speter    T((T_CALLED("slk_noutrefresh()")));
11950276Speter
12076726Speter    if (SP == NULL || SP->_slk == NULL)
12176726Speter	returnCode(ERR);
12276726Speter    if (SP->_slk->hidden)
12376726Speter	returnCode(OK);
12476726Speter    slk_intern_refresh(SP->_slk);
12550276Speter
12676726Speter    returnCode(wnoutrefresh(SP->_slk->win));
12750276Speter}
12850276Speter
12950276Speter/*
13050276Speter * Refresh the soft labels.
13150276Speter */
13276726SpeterNCURSES_EXPORT(int)
13350276Speterslk_refresh(void)
13450276Speter{
13576726Speter    T((T_CALLED("slk_refresh()")));
13650276Speter
13776726Speter    if (SP == NULL || SP->_slk == NULL)
13876726Speter	returnCode(ERR);
13976726Speter    if (SP->_slk->hidden)
14076726Speter	returnCode(OK);
14176726Speter    slk_intern_refresh(SP->_slk);
14250276Speter
14376726Speter    returnCode(wrefresh(SP->_slk->win));
14450276Speter}
145