1 /* $OpenBSD: panel.priv.h,v 1.8 2001/02/28 22:58:53 millert Exp $ */ 2 3 /**************************************************************************** 4 * Copyright (c) 2000 Free Software Foundation, Inc. * 5 * * 6 * Permission is hereby granted, free of charge, to any person obtaining a * 7 * copy of this software and associated documentation files (the * 8 * "Software"), to deal in the Software without restriction, including * 9 * without limitation the rights to use, copy, modify, merge, publish, * 10 * distribute, distribute with modifications, sublicense, and/or sell * 11 * copies of the Software, and to permit persons to whom the Software is * 12 * furnished to do so, subject to the following conditions: * 13 * * 14 * The above copyright notice and this permission notice shall be included * 15 * in all copies or substantial portions of the Software. * 16 * * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 24 * * 25 * Except as contained in this notice, the name(s) of the above copyright * 26 * holders shall not be used in advertising or otherwise to promote the * 27 * sale, use or other dealings in this Software without prior written * 28 * authorization. * 29 ****************************************************************************/ 30 31 /* $From: panel.priv.h,v 1.17 2001/02/24 23:47:05 tom Exp $ */ 32 33 #ifndef _PANEL_PRIV_H 34 #define _PANEL_PRIV_H 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 #if HAVE_LIBDMALLOC 45 # include <dmalloc.h> /* Gray Watson's library */ 46 #endif 47 48 #if HAVE_LIBDBMALLOC 49 # include <dbmalloc.h> /* Conor Cahill's library */ 50 #endif 51 52 #include "panel.h" 53 #include <nc_panel.h> 54 55 #if ( CC_HAS_INLINE_FUNCS && !defined(TRACE) ) 56 # define INLINE inline 57 #else 58 # define INLINE 59 #endif 60 61 #if USE_RCS_IDS 62 # define MODULE_ID(id) static const char Ident[] = id; 63 #else 64 # define MODULE_ID(id) /*nothing*/ 65 #endif 66 67 68 #ifdef TRACE 69 extern NCURSES_EXPORT(const char *) _nc_my_visbuf (const void *); 70 # ifdef TRACE_TXT 71 # define USER_PTR(ptr) _nc_visbuf((const char *)ptr) 72 # else 73 # define USER_PTR(ptr) _nc_my_visbuf((const char *)ptr) 74 # endif 75 76 extern NCURSES_EXPORT(void) _nc_dPanel (const char*, const PANEL*); 77 extern NCURSES_EXPORT(void) _nc_dStack (const char*, int, const PANEL*); 78 extern NCURSES_EXPORT(void) _nc_Wnoutrefresh (const PANEL*); 79 extern NCURSES_EXPORT(void) _nc_Touchpan (const PANEL*); 80 extern NCURSES_EXPORT(void) _nc_Touchline (const PANEL*, int, int); 81 82 # define dBug(x) _tracef x 83 # define dPanel(text,pan) _nc_dPanel(text,pan) 84 # define dStack(fmt,num,pan) _nc_dStack(fmt,num,pan) 85 # define Wnoutrefresh(pan) _nc_Wnoutrefresh(pan) 86 # define Touchpan(pan) _nc_Touchpan(pan) 87 # define Touchline(pan,start,count) _nc_Touchline(pan,start,count) 88 #else /* !TRACE */ 89 # define dBug(x) 90 # define dPanel(text,pan) 91 # define dStack(fmt,num,pan) 92 # define Wnoutrefresh(pan) wnoutrefresh((pan)->win) 93 # define Touchpan(pan) touchwin((pan)->win) 94 # define Touchline(pan,start,count) touchline((pan)->win,start,count) 95 #endif 96 97 #define _nc_stdscr_pseudo_panel _nc_panelhook()->stdscr_pseudo_panel 98 #define _nc_top_panel _nc_panelhook()->top_panel 99 #define _nc_bottom_panel _nc_panelhook()->bottom_panel 100 101 #define EMPTY_STACK() (_nc_top_panel==_nc_bottom_panel) 102 #define Is_Bottom(p) (((p)!=(PANEL*)0) && !EMPTY_STACK() && (_nc_bottom_panel->above==(p))) 103 #define Is_Top(p) (((p)!=(PANEL*)0) && !EMPTY_STACK() && (_nc_top_panel==(p))) 104 #define Is_Pseudo(p) ((p) && ((p)==_nc_bottom_panel)) 105 106 /* borrowed from curses.priv.h */ 107 #define CHANGED_RANGE(line,start,end) \ 108 if (line->firstchar == _NOCHANGE \ 109 || line->firstchar > (start)) \ 110 line->firstchar = start; \ 111 if (line->lastchar == _NOCHANGE \ 112 || line->lastchar < (end)) \ 113 line->lastchar = end 114 115 /*+------------------------------------------------------------------------- 116 IS_LINKED(pan) - check to see if panel is in the stack 117 --------------------------------------------------------------------------*/ 118 /* This works! The only case where it would fail is, when the list has 119 only one element. But this could only be the pseudo panel at the bottom */ 120 #define IS_LINKED(p) (((p)->above || (p)->below ||((p)==_nc_bottom_panel)) ? TRUE : FALSE) 121 122 #define PSTARTX(pan) ((pan)->win->_begx) 123 #define PENDX(pan) ((pan)->win->_begx + getmaxx((pan)->win) - 1) 124 #define PSTARTY(pan) ((pan)->win->_begy) 125 #define PENDY(pan) ((pan)->win->_begy + getmaxy((pan)->win) - 1) 126 127 /*+------------------------------------------------------------------------- 128 PANELS_OVERLAPPED(pan1,pan2) - check panel overlapped 129 ---------------------------------------------------------------------------*/ 130 #define PANELS_OVERLAPPED(pan1,pan2) \ 131 (( !(pan1) || !(pan2) || \ 132 PSTARTY(pan1) > PENDY(pan2) || PENDY(pan1) < PSTARTY(pan2) ||\ 133 PSTARTX(pan1) > PENDX(pan2) || PENDX(pan1) < PSTARTX(pan2) ) \ 134 ? FALSE : TRUE) 135 136 137 /*+------------------------------------------------------------------------- 138 Compute the intersection rectangle of two overlapping rectangles 139 ---------------------------------------------------------------------------*/ 140 #define COMPUTE_INTERSECTION(pan1,pan2,ix1,ix2,iy1,iy2)\ 141 ix1 = (PSTARTX(pan1) < PSTARTX(pan2)) ? PSTARTX(pan2) : PSTARTX(pan1);\ 142 ix2 = (PENDX(pan1) < PENDX(pan2)) ? PENDX(pan1) : PENDX(pan2);\ 143 iy1 = (PSTARTY(pan1) < PSTARTY(pan2)) ? PSTARTY(pan2) : PSTARTY(pan1);\ 144 iy2 = (PENDY(pan1) < PENDY(pan2)) ? PENDY(pan1) : PENDY(pan2);\ 145 assert((ix1<=ix2) && (iy1<=iy2));\ 146 147 148 /*+------------------------------------------------------------------------- 149 Walk through the panel stack starting at the given location and 150 check for intersections; overlapping panels are "touched", so they 151 are incrementally overwriting cells that should be hidden. 152 If the "touch" flag is set, the panel gets touched before it is 153 updated. 154 ---------------------------------------------------------------------------*/ 155 #define PANEL_UPDATE(pan,panstart)\ 156 { PANEL* pan2 = ((panstart) ? (panstart) : _nc_bottom_panel);\ 157 while(pan2) {\ 158 if ((pan2 != pan) && PANELS_OVERLAPPED(pan,pan2)) {\ 159 int y,ix1,ix2,iy1,iy2;\ 160 COMPUTE_INTERSECTION(pan,pan2,ix1,ix2,iy1,iy2);\ 161 for(y = iy1; y <= iy2; y++) {\ 162 if (is_linetouched(pan->win,y - PSTARTY(pan))) {\ 163 struct ldat* line = &(pan2->win->_line[y - PSTARTY(pan2)]);\ 164 CHANGED_RANGE(line,ix1-PSTARTX(pan2),ix2-PSTARTX(pan2));\ 165 }\ 166 }\ 167 }\ 168 pan2 = pan2->above;\ 169 }\ 170 } 171 172 /*+------------------------------------------------------------------------- 173 Remove panel from stack. 174 ---------------------------------------------------------------------------*/ 175 #define PANEL_UNLINK(pan,err) \ 176 { err = ERR;\ 177 if (pan) {\ 178 if (IS_LINKED(pan)) {\ 179 if ((pan)->below)\ 180 (pan)->below->above = (pan)->above;\ 181 if ((pan)->above)\ 182 (pan)->above->below = (pan)->below;\ 183 if ((pan) == _nc_bottom_panel) \ 184 _nc_bottom_panel = (pan)->above;\ 185 if ((pan) == _nc_top_panel) \ 186 _nc_top_panel = (pan)->below;\ 187 err = OK;\ 188 }\ 189 (pan)->above = (pan)->below = (PANEL*)0;\ 190 }\ 191 } 192 193 #define HIDE_PANEL(pan,err,err_if_unlinked)\ 194 if (IS_LINKED(pan)) {\ 195 Touchpan(pan);\ 196 PANEL_UPDATE(pan,(PANEL*)0);\ 197 PANEL_UNLINK(pan,err);\ 198 } \ 199 else {\ 200 err = err_if_unlinked;\ 201 } 202 203 #endif /* _PANEL_PRIV_H */ 204