]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/base/lib_slkrefr.c
96ca6a6e48925aa18df70072d5a5f49d4b675036
[ncurses.git] / ncurses / base / lib_slkrefr.c
1 /****************************************************************************
2  * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
3  *                                                                          *
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:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
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.                               *
22  *                                                                          *
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       *
26  * authorization.                                                           *
27  ****************************************************************************/
28
29 /****************************************************************************
30  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32  *     and: Juergen Pfeifer                         1996-on                 *
33  *     and: Thomas E. Dickey                                                *
34  ****************************************************************************/
35
36 /*
37  *      lib_slkrefr.c
38  *      Write SLK window to the (virtual) screen.
39  */
40 #include <curses.priv.h>
41 #include <term.h>               /* num_labels, label_*, plab_norm */
42
43 #ifndef CUR
44 #define CUR SP_TERMTYPE 
45 #endif
46
47 MODULE_ID("$Id: lib_slkrefr.c,v 1.20 2009/05/10 00:48:29 tom Exp $")
48
49 /*
50  * Paint the info line for the PC style SLK emulation.
51  */
52 static void
53 slk_paint_info(WINDOW *win)
54 {
55     SCREEN *sp = _nc_screen_of(win);
56
57     if (win && sp && (sp->slk_format == 4)) {
58         int i;
59
60         mvwhline(win, 0, 0, 0, getmaxx(win));
61         wmove(win, 0, 0);
62
63         for (i = 0; i < sp->_slk->maxlab; i++) {
64             mvwprintw(win, 0, sp->_slk->ent[i].ent_x, "F%d", i + 1);
65         }
66     }
67 }
68
69 /*
70  * Write the soft labels to the soft-key window.
71  */
72 static void
73 slk_intern_refresh(SLK * slk)
74 {
75 #if NCURSES_SP_FUNCS
76     SCREEN *sp = CURRENT_SCREEN;
77 #endif
78     int i;
79     int fmt = SP->slk_format;
80
81     for (i = 0; i < slk->labcnt; i++) {
82         if (slk->dirty || slk->ent[i].dirty) {
83             if (slk->ent[i].visible) {
84                 if (num_labels > 0 && SLK_STDFMT(fmt)) {
85                     if (i < num_labels) {
86                         TPUTS_TRACE("plab_norm");
87                         putp(TPARM_2(plab_norm, i + 1, slk->ent[i].form_text));
88                     }
89                 } else {
90                     if (fmt == 4)
91                         slk_paint_info(slk->win);
92                     wmove(slk->win, SLK_LINES(fmt) - 1, slk->ent[i].ent_x);
93                     if (SP->_slk) {
94                         wattrset(slk->win, AttrOf(SP->_slk->attr));
95                     }
96                     waddstr(slk->win, slk->ent[i].form_text);
97                     /* if we simulate SLK's, it's looking much more
98                        natural to use the current ATTRIBUTE also
99                        for the label window */
100                     wattrset(slk->win, WINDOW_ATTRS(stdscr));
101                 }
102             }
103             slk->ent[i].dirty = FALSE;
104         }
105     }
106     slk->dirty = FALSE;
107
108     if (num_labels > 0) {
109         if (slk->hidden) {
110             TPUTS_TRACE("label_off");
111             putp(label_off);
112         } else {
113             TPUTS_TRACE("label_on");
114             putp(label_on);
115         }
116     }
117 }
118
119 /*
120  * Refresh the soft labels.
121  */
122 NCURSES_EXPORT(int)
123 NCURSES_SP_NAME(slk_noutrefresh) (NCURSES_SP_DCL0)
124 {
125     T((T_CALLED("slk_noutrefresh()")));
126
127     if (SP_PARM == NULL || SP_PARM->_slk == NULL)
128         returnCode(ERR);
129     if (SP_PARM->_slk->hidden)
130         returnCode(OK);
131     slk_intern_refresh(SP_PARM->_slk);
132
133     returnCode(wnoutrefresh(SP_PARM->_slk->win));
134 }
135
136 #if NCURSES_SP_FUNCS
137 NCURSES_EXPORT(int)
138 slk_noutrefresh(void)
139 {
140     return NCURSES_SP_NAME(slk_noutrefresh) (CURRENT_SCREEN);
141 }
142 #endif
143
144 /*
145  * Refresh the soft labels.
146  */
147 NCURSES_EXPORT(int)
148 NCURSES_SP_NAME(slk_refresh) (NCURSES_SP_DCL0)
149 {
150     T((T_CALLED("slk_refresh()")));
151
152     if (SP_PARM == NULL || SP_PARM->_slk == NULL)
153         returnCode(ERR);
154     if (SP_PARM->_slk->hidden)
155         returnCode(OK);
156     slk_intern_refresh(SP_PARM->_slk);
157
158     returnCode(wrefresh(SP_PARM->_slk->win));
159 }
160
161 #if NCURSES_SP_FUNCS
162 NCURSES_EXPORT(int)
163 slk_refresh(void)
164 {
165     return NCURSES_SP_NAME(slk_refresh) (CURRENT_SCREEN);
166 }
167 #endif