1 /**************************************************************************** 2 * Copyright 2020 Thomas E. Dickey * 3 * Copyright 1998-2014,2017 Free Software Foundation, Inc. * 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 /* $Id: panel.priv.h,v 1.30 2020/09/26 18:05:32 tom Exp $ */ 31 32 #ifndef NCURSES_PANEL_PRIV_H 33 #define NCURSES_PANEL_PRIV_H 1 34 /* *INDENT-OFF* */ 35 36 #if HAVE_CONFIG_H 37 # include <ncurses_cfg.h> 38 #endif 39 40 #include <stdlib.h> 41 #include <string.h> 42 #include <assert.h> 43 44 struct screen; /* forward declaration */ 45 46 #include "curses.priv.h" /* includes nc_panel.h */ 47 48 #define NCURSES_OPAQUE_PANEL 0 49 50 #include "panel.h" 51 52 #ifdef TRACE 53 extern PANEL_EXPORT(const char *) _nc_my_visbuf (const void *, int); 54 # ifdef TRACE_TXT 55 # define USER_PTR(ptr,n) _nc_visbuf2(n, (const char *)ptr) 56 # else 57 # define USER_PTR(ptr,n) _nc_my_visbuf((const char *)ptr, n) 58 # endif 59 60 # define returnPanel(code) TRACE_RETURN1(code,panel) 61 62 extern PANEL_EXPORT(PANEL *) _nc_retrace_panel (PANEL *); 63 extern PANEL_EXPORT(void) _nc_dPanel (const char*, const PANEL*); 64 extern PANEL_EXPORT(void) _nc_dStack (const char*, int, const PANEL*); 65 extern PANEL_EXPORT(void) _nc_Wnoutrefresh (const PANEL*); 66 extern PANEL_EXPORT(void) _nc_Touchpan (const PANEL*); 67 extern PANEL_EXPORT(void) _nc_Touchline (const PANEL*, int, int); 68 69 # define dBug(x) _tracef x 70 # define dPanel(text,pan) _nc_dPanel(text,pan) 71 # define dStack(fmt,num,pan) _nc_dStack(fmt,num,pan) 72 # define Wnoutrefresh(pan) _nc_Wnoutrefresh(pan) 73 # define Touchpan(pan) _nc_Touchpan(pan) 74 # define Touchline(pan,start,count) _nc_Touchline(pan,start,count) 75 #else /* !TRACE */ 76 # define returnPanel(code) return code 77 # define dBug(x) 78 # define dPanel(text,pan) 79 # define dStack(fmt,num,pan) 80 # define Wnoutrefresh(pan) wnoutrefresh((pan)->win) 81 # define Touchpan(pan) touchwin((pan)->win) 82 # define Touchline(pan,start,count) touchline((pan)->win,start,count) 83 #endif 84 85 #if NCURSES_SP_FUNCS 86 #define GetScreenHook(sp) \ 87 struct panelhook* ph = NCURSES_SP_NAME(_nc_panelhook)(sp) 88 #define GetPanelHook(pan) \ 89 GetScreenHook(pan ? _nc_screen_of((pan)->win) : 0) 90 #define GetWindowHook(win) \ 91 SCREEN* sp = _nc_screen_of(win); \ 92 GetScreenHook(sp) 93 #define GetHook(pan) SCREEN* sp = _nc_screen_of(pan->win); \ 94 GetScreenHook(sp) 95 96 #define _nc_stdscr_pseudo_panel ((ph)->stdscr_pseudo_panel) 97 #define _nc_top_panel ((ph)->top_panel) 98 #define _nc_bottom_panel ((ph)->bottom_panel) 99 100 #else /* !NCURSES_SP_FUNCS */ 101 102 #define GetScreenHook(sp) /* nothing */ 103 #define GetPanelHook(pan) /* nothing */ 104 #define GetWindowHook(win) /* nothing */ 105 #define GetHook(pan) /* nothing */ 106 107 #define _nc_stdscr_pseudo_panel _nc_panelhook()->stdscr_pseudo_panel 108 #define _nc_top_panel _nc_panelhook()->top_panel 109 #define _nc_bottom_panel _nc_panelhook()->bottom_panel 110 111 #endif /* NCURSES_SP_FUNCS */ 112 113 #define EMPTY_STACK() (_nc_top_panel == _nc_bottom_panel) 114 #define Is_Bottom(p) (((p) != (PANEL*)0) && !EMPTY_STACK() && (_nc_bottom_panel->above == (p))) 115 #define Is_Top(p) (((p) != (PANEL*)0) && !EMPTY_STACK() && (_nc_top_panel == (p))) 116 #define Is_Pseudo(p) (((p) != (PANEL*)0) && ((p) == _nc_bottom_panel)) 117 118 /*+------------------------------------------------------------------------- 119 IS_LINKED(pan) - check to see if panel is in the stack 120 --------------------------------------------------------------------------*/ 121 /* This works! The only case where it would fail is, when the list has 122 only one element. But this could only be the pseudo panel at the bottom */ 123 #define IS_LINKED(p) (((p)->above || (p)->below ||((p)==_nc_bottom_panel)) ? TRUE : FALSE) 124 125 #define PSTARTX(pan) ((pan)->win->_begx) 126 #define PENDX(pan) ((pan)->win->_begx + getmaxx((pan)->win) - 1) 127 #define PSTARTY(pan) ((pan)->win->_begy) 128 #define PENDY(pan) ((pan)->win->_begy + getmaxy((pan)->win) - 1) 129 130 /*+------------------------------------------------------------------------- 131 PANELS_OVERLAPPED(pan1,pan2) - check panel overlapped 132 ---------------------------------------------------------------------------*/ 133 #define PANELS_OVERLAPPED(pan1,pan2) \ 134 (( !(pan1) || !(pan2) || \ 135 PSTARTY(pan1) > PENDY(pan2) || PENDY(pan1) < PSTARTY(pan2) ||\ 136 PSTARTX(pan1) > PENDX(pan2) || PENDX(pan1) < PSTARTX(pan2) ) \ 137 ? FALSE : TRUE) 138 139 140 /*+------------------------------------------------------------------------- 141 Compute the intersection rectangle of two overlapping rectangles 142 ---------------------------------------------------------------------------*/ 143 #define COMPUTE_INTERSECTION(pan1,pan2,ix1,ix2,iy1,iy2)\ 144 ix1 = (PSTARTX(pan1) < PSTARTX(pan2)) ? PSTARTX(pan2) : PSTARTX(pan1);\ 145 ix2 = (PENDX(pan1) < PENDX(pan2)) ? PENDX(pan1) : PENDX(pan2);\ 146 iy1 = (PSTARTY(pan1) < PSTARTY(pan2)) ? PSTARTY(pan2) : PSTARTY(pan1);\ 147 iy2 = (PENDY(pan1) < PENDY(pan2)) ? PENDY(pan1) : PENDY(pan2);\ 148 assert((ix1<=ix2) && (iy1<=iy2)) 149 150 151 /*+------------------------------------------------------------------------- 152 Walk through the panel stack starting at the given location and 153 check for intersections; overlapping panels are "touched", so they 154 are incrementally overwriting cells that should be hidden. 155 If the "touch" flag is set, the panel gets touched before it is 156 updated. 157 ---------------------------------------------------------------------------*/ 158 #define PANEL_UPDATE(pan,panstart)\ 159 { PANEL* pan2 = ((panstart) ? (panstart) : _nc_bottom_panel);\ 160 while(pan2 && pan2->win) {\ 161 if ((pan2 != pan) && PANELS_OVERLAPPED(pan,pan2)) {\ 162 int y, ix1, ix2, iy1, iy2;\ 163 COMPUTE_INTERSECTION(pan, pan2, ix1, ix2, iy1, iy2);\ 164 for(y = iy1; y <= iy2; y++) {\ 165 if (is_linetouched(pan->win,y - PSTARTY(pan))) {\ 166 struct ldat* line = &(pan2->win->_line[y - PSTARTY(pan2)]);\ 167 CHANGED_RANGE(line, ix1 - PSTARTX(pan2), ix2 - PSTARTX(pan2));\ 168 }\ 169 }\ 170 }\ 171 pan2 = pan2->above;\ 172 }\ 173 } 174 175 /*+------------------------------------------------------------------------- 176 Remove panel from stack. 177 ---------------------------------------------------------------------------*/ 178 #define PANEL_UNLINK(pan,err) \ 179 { err = ERR;\ 180 if (pan) {\ 181 if (IS_LINKED(pan)) {\ 182 if ((pan)->below)\ 183 (pan)->below->above = (pan)->above;\ 184 if ((pan)->above)\ 185 (pan)->above->below = (pan)->below;\ 186 if ((pan) == _nc_bottom_panel) \ 187 _nc_bottom_panel = (pan)->above;\ 188 if ((pan) == _nc_top_panel) \ 189 _nc_top_panel = (pan)->below;\ 190 err = OK;\ 191 }\ 192 (pan)->above = (pan)->below = (PANEL*)0;\ 193 }\ 194 } 195 196 #define HIDE_PANEL(pan,err,err_if_unlinked)\ 197 if (IS_LINKED(pan)) {\ 198 Touchpan(pan);\ 199 PANEL_UPDATE(pan,(PANEL*)0);\ 200 PANEL_UNLINK(pan,err);\ 201 } \ 202 else {\ 203 err = err_if_unlinked;\ 204 } 205 206 #if NCURSES_SP_FUNCS 207 /* These may become later renamed and part of panel.h and the public API */ 208 extern PANEL_EXPORT(void) NCURSES_SP_NAME(_nc_update_panels)(SCREEN*); 209 #endif 210 /* *INDENT-ON* */ 211 212 #endif /* NCURSES_PANEL_PRIV_H */ 213