blob: 7a40624b127662fac6e7dad1a17223075c4c7332 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002 * Copyright 2020,2021 Thomas E. Dickey *
3 * Copyright 1998-2013,2014 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304 * *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
12 * *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
15 * *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
27 * authorization. *
28 ****************************************************************************/
29
30/****************************************************************************
31 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
32 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
33 * and: Juergen Pfeifer 1996-on *
34 * and: Thomas E. Dickey *
35 ****************************************************************************/
36
37/*
38 * lib_slkrefr.c
39 * Write SLK window to the (virtual) screen.
40 */
41#include <curses.priv.h>
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053042
Steve Kondikae271bc2015-11-15 02:50:53 +010043#ifndef CUR
44#define CUR SP_TERMTYPE
45#endif
46
micky3879b9f5e72025-07-08 18:04:53 -040047MODULE_ID("$Id: lib_slkrefr.c,v 1.32 2021/09/04 10:54:35 tom Exp $")
Steve Kondikae271bc2015-11-15 02:50:53 +010048
49#ifdef USE_TERM_DRIVER
50#define NumLabels InfoOf(SP_PARM).numlabels
51#else
52#define NumLabels num_labels
53#endif
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053054
55/*
56 * Paint the info line for the PC style SLK emulation.
57 */
58static void
59slk_paint_info(WINDOW *win)
60{
61 SCREEN *sp = _nc_screen_of(win);
62
63 if (win && sp && (sp->slk_format == 4)) {
64 int i;
65
Steve Kondikae271bc2015-11-15 02:50:53 +010066 (void) mvwhline(win, 0, 0, 0, getmaxx(win));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053067 wmove(win, 0, 0);
68
69 for (i = 0; i < sp->_slk->maxlab; i++) {
70 mvwprintw(win, 0, sp->_slk->ent[i].ent_x, "F%d", i + 1);
71 }
72 }
73}
74
75/*
76 * Write the soft labels to the soft-key window.
77 */
78static void
Steve Kondikae271bc2015-11-15 02:50:53 +010079slk_intern_refresh(SCREEN *sp)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053080{
81 int i;
Steve Kondikae271bc2015-11-15 02:50:53 +010082 int fmt;
83 SLK *slk;
84 int numlab;
85
86 if (sp == 0)
87 return;
88
89 slk = sp->_slk;
90 fmt = sp->slk_format;
91 numlab = NumLabels;
92
93 if (slk->hidden)
94 return;
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053095
96 for (i = 0; i < slk->labcnt; i++) {
97 if (slk->dirty || slk->ent[i].dirty) {
98 if (slk->ent[i].visible) {
Steve Kondikae271bc2015-11-15 02:50:53 +010099 if (numlab > 0 && SLK_STDFMT(fmt)) {
100#ifdef USE_TERM_DRIVER
101 CallDriver_2(sp, td_hwlabel, i + 1, slk->ent[i].form_text);
102#else
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530103 if (i < num_labels) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100104 NCURSES_PUTP2("plab_norm",
105 TPARM_2(plab_norm,
106 i + 1,
107 slk->ent[i].form_text));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530108 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100109#endif
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530110 } else {
111 if (fmt == 4)
112 slk_paint_info(slk->win);
113 wmove(slk->win, SLK_LINES(fmt) - 1, slk->ent[i].ent_x);
Steve Kondikae271bc2015-11-15 02:50:53 +0100114 (void) wattrset(slk->win, (int) AttrOf(slk->attr));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530115 waddstr(slk->win, slk->ent[i].form_text);
micky3879b9f5e72025-07-08 18:04:53 -0400116 /* if we simulate SLK's, it is looking much more
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530117 natural to use the current ATTRIBUTE also
118 for the label window */
Steve Kondikae271bc2015-11-15 02:50:53 +0100119 (void) wattrset(slk->win, (int) WINDOW_ATTRS(StdScreen(sp)));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530120 }
121 }
122 slk->ent[i].dirty = FALSE;
123 }
124 }
125 slk->dirty = FALSE;
126
Steve Kondikae271bc2015-11-15 02:50:53 +0100127 if (numlab > 0) {
128#ifdef USE_TERM_DRIVER
129 CallDriver_1(sp, td_hwlabelOnOff, slk->hidden ? FALSE : TRUE);
130#else
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530131 if (slk->hidden) {
Steve Kondikae271bc2015-11-15 02:50:53 +0100132 NCURSES_PUTP2("label_off", label_off);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530133 } else {
Steve Kondikae271bc2015-11-15 02:50:53 +0100134 NCURSES_PUTP2("label_on", label_on);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530135 }
Steve Kondikae271bc2015-11-15 02:50:53 +0100136#endif
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530137 }
138}
139
140/*
141 * Refresh the soft labels.
142 */
143NCURSES_EXPORT(int)
Steve Kondikae271bc2015-11-15 02:50:53 +0100144NCURSES_SP_NAME(slk_noutrefresh) (NCURSES_SP_DCL0)
145{
146 T((T_CALLED("slk_noutrefresh(%p)"), (void *) SP_PARM));
147
148 if (SP_PARM == 0 || SP_PARM->_slk == 0)
149 returnCode(ERR);
150 if (SP_PARM->_slk->hidden)
151 returnCode(OK);
152 slk_intern_refresh(SP_PARM);
153
154 returnCode(wnoutrefresh(SP_PARM->_slk->win));
155}
156
157#if NCURSES_SP_FUNCS
158NCURSES_EXPORT(int)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530159slk_noutrefresh(void)
160{
Steve Kondikae271bc2015-11-15 02:50:53 +0100161 return NCURSES_SP_NAME(slk_noutrefresh) (CURRENT_SCREEN);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530162}
Steve Kondikae271bc2015-11-15 02:50:53 +0100163#endif
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530164
165/*
166 * Refresh the soft labels.
167 */
168NCURSES_EXPORT(int)
Steve Kondikae271bc2015-11-15 02:50:53 +0100169NCURSES_SP_NAME(slk_refresh) (NCURSES_SP_DCL0)
170{
171 T((T_CALLED("slk_refresh(%p)"), (void *) SP_PARM));
172
173 if (SP_PARM == 0 || SP_PARM->_slk == 0)
174 returnCode(ERR);
175 if (SP_PARM->_slk->hidden)
176 returnCode(OK);
177 slk_intern_refresh(SP_PARM);
178
179 returnCode(wrefresh(SP_PARM->_slk->win));
180}
181
182#if NCURSES_SP_FUNCS
183NCURSES_EXPORT(int)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530184slk_refresh(void)
185{
Steve Kondikae271bc2015-11-15 02:50:53 +0100186 return NCURSES_SP_NAME(slk_refresh) (CURRENT_SCREEN);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530187}
Steve Kondikae271bc2015-11-15 02:50:53 +0100188#endif