]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/base/lib_slkrefr.c
ncurses 5.7 - patch 20090803
[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
42 #ifndef CUR
43 #define CUR SP_TERMTYPE
44 #endif
45
46 MODULE_ID("$Id: lib_slkrefr.c,v 1.21 2009/06/06 20:26:17 tom Exp $")
47
48 /*
49  * Paint the info line for the PC style SLK emulation.
50  */
51 static void
52 slk_paint_info(WINDOW *win)
53 {
54     SCREEN *sp = _nc_screen_of(win);
55
56     if (win && sp && (sp->slk_format == 4)) {
57         int i;
58
59         mvwhline(win, 0, 0, 0, getmaxx(win));
60         wmove(win, 0, 0);
61
62         for (i = 0; i < sp->_slk->maxlab; i++) {
63             mvwprintw(win, 0, sp->_slk->ent[i].ent_x, "F%d", i + 1);
64         }
65     }
66 }
67
68 /*
69  * Write the soft labels to the soft-key window.
70  */
71 static void
72 slk_intern_refresh(SCREEN *sp)
73 {
74     int i;
75     int fmt;
76     SLK *slk;
77     int numlab;
78
79     if (sp == 0)
80         return;
81
82     slk = sp->_slk;
83     fmt = sp->slk_format;
84     numlab = InfoOf(sp).numlabels;
85
86     if (slk->hidden)
87         return;
88
89     for (i = 0; i < slk->labcnt; i++) {
90         if (slk->dirty || slk->ent[i].dirty) {
91             if (slk->ent[i].visible) {
92                 if (numlab > 0 && SLK_STDFMT(fmt)) {
93 #ifdef USE_TERM_DRIVER
94                     CallDriver_2(sp, hwlabel, i + 1, slk->ent[i].form_text);
95 #else
96                     if (i < num_labels) {
97                         TPUTS_TRACE("plab_norm");
98                         putp(TPARM_2(plab_norm, i + 1, slk->ent[i].form_text));
99                     }
100 #endif
101                 } else {
102                     if (fmt == 4)
103                         slk_paint_info(slk->win);
104                     wmove(slk->win, SLK_LINES(fmt) - 1, slk->ent[i].ent_x);
105                     if (sp->_slk) {
106                         wattrset(slk->win, AttrOf(sp->_slk->attr));
107                     }
108                     waddstr(slk->win, slk->ent[i].form_text);
109                     /* if we simulate SLK's, it's looking much more
110                        natural to use the current ATTRIBUTE also
111                        for the label window */
112                     wattrset(slk->win, WINDOW_ATTRS(StdScreen(sp)));
113                 }
114             }
115             slk->ent[i].dirty = FALSE;
116         }
117     }
118     slk->dirty = FALSE;
119
120     if (numlab > 0) {
121 #ifdef USE_TERM_DRIVER
122         CallDriver_1(sp, hwlabelOnOff, slk->hidden ? FALSE : TRUE);
123 #else
124         if (slk->hidden) {
125             TPUTS_TRACE("label_off");
126             putp(label_off);
127         } else {
128             TPUTS_TRACE("label_on");
129             putp(label_on);
130         }
131 #endif
132     }
133 }
134
135 /*
136  * Refresh the soft labels.
137  */
138 NCURSES_EXPORT(int)
139 NCURSES_SP_NAME(slk_noutrefresh) (NCURSES_SP_DCL0)
140 {
141     T((T_CALLED("slk_noutrefresh(%p)"), SP_PARM));
142
143     if (SP_PARM == 0 || SP_PARM->_slk == 0)
144         returnCode(ERR);
145     if (SP_PARM->_slk->hidden)
146         returnCode(OK);
147     slk_intern_refresh(SP_PARM);
148
149     returnCode(wnoutrefresh(SP_PARM->_slk->win));
150 }
151
152 #if NCURSES_SP_FUNCS
153 NCURSES_EXPORT(int)
154 slk_noutrefresh(void)
155 {
156     return NCURSES_SP_NAME(slk_noutrefresh) (CURRENT_SCREEN);
157 }
158 #endif
159
160 /*
161  * Refresh the soft labels.
162  */
163 NCURSES_EXPORT(int)
164 NCURSES_SP_NAME(slk_refresh) (NCURSES_SP_DCL0)
165 {
166     T((T_CALLED("slk_refresh(%p)"), SP_PARM));
167
168     if (SP_PARM == 0 || SP_PARM->_slk == 0)
169         returnCode(ERR);
170     if (SP_PARM->_slk->hidden)
171         returnCode(OK);
172     slk_intern_refresh(SP_PARM);
173
174     returnCode(wrefresh(SP_PARM->_slk->win));
175 }
176
177 #if NCURSES_SP_FUNCS
178 NCURSES_EXPORT(int)
179 slk_refresh(void)
180 {
181     return NCURSES_SP_NAME(slk_refresh) (CURRENT_SCREEN);
182 }
183 #endif