Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | /**************************************************************************** |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 2 | * Copyright 2020,2021 Thomas E. Dickey * |
| 3 | * Copyright 1998-2013,2014 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 4 | * * |
| 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 Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 42 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 43 | #ifndef CUR |
| 44 | #define CUR SP_TERMTYPE |
| 45 | #endif |
| 46 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 47 | MODULE_ID("$Id: lib_slkrefr.c,v 1.32 2021/09/04 10:54:35 tom Exp $") |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 48 | |
| 49 | #ifdef USE_TERM_DRIVER |
| 50 | #define NumLabels InfoOf(SP_PARM).numlabels |
| 51 | #else |
| 52 | #define NumLabels num_labels |
| 53 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | * Paint the info line for the PC style SLK emulation. |
| 57 | */ |
| 58 | static void |
| 59 | slk_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 Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 66 | (void) mvwhline(win, 0, 0, 0, getmaxx(win)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 67 | 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 | */ |
| 78 | static void |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 79 | slk_intern_refresh(SCREEN *sp) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 80 | { |
| 81 | int i; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 82 | 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 Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 95 | |
| 96 | for (i = 0; i < slk->labcnt; i++) { |
| 97 | if (slk->dirty || slk->ent[i].dirty) { |
| 98 | if (slk->ent[i].visible) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 99 | 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 Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 103 | if (i < num_labels) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 104 | NCURSES_PUTP2("plab_norm", |
| 105 | TPARM_2(plab_norm, |
| 106 | i + 1, |
| 107 | slk->ent[i].form_text)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 108 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 109 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 110 | } 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 Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 114 | (void) wattrset(slk->win, (int) AttrOf(slk->attr)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 115 | waddstr(slk->win, slk->ent[i].form_text); |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 116 | /* if we simulate SLK's, it is looking much more |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 117 | natural to use the current ATTRIBUTE also |
| 118 | for the label window */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 119 | (void) wattrset(slk->win, (int) WINDOW_ATTRS(StdScreen(sp))); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | slk->ent[i].dirty = FALSE; |
| 123 | } |
| 124 | } |
| 125 | slk->dirty = FALSE; |
| 126 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 127 | if (numlab > 0) { |
| 128 | #ifdef USE_TERM_DRIVER |
| 129 | CallDriver_1(sp, td_hwlabelOnOff, slk->hidden ? FALSE : TRUE); |
| 130 | #else |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 131 | if (slk->hidden) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 132 | NCURSES_PUTP2("label_off", label_off); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 133 | } else { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 134 | NCURSES_PUTP2("label_on", label_on); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 135 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 136 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * Refresh the soft labels. |
| 142 | */ |
| 143 | NCURSES_EXPORT(int) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 144 | NCURSES_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 |
| 158 | NCURSES_EXPORT(int) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 159 | slk_noutrefresh(void) |
| 160 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 161 | return NCURSES_SP_NAME(slk_noutrefresh) (CURRENT_SCREEN); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 162 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 163 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 164 | |
| 165 | /* |
| 166 | * Refresh the soft labels. |
| 167 | */ |
| 168 | NCURSES_EXPORT(int) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 169 | NCURSES_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 |
| 183 | NCURSES_EXPORT(int) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 184 | slk_refresh(void) |
| 185 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 186 | return NCURSES_SP_NAME(slk_refresh) (CURRENT_SCREEN); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 187 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 188 | #endif |