1 /**************************************************************************** 2 * Copyright (c) 1998-2001,2005 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 /* $Id: panel.priv.h,v 1.21 2005/11/26 15:27:00 tom Exp $ */ 30 31 #ifndef NCURSES_PANEL_PRIV_H 32 #define NCURSES_PANEL_PRIV_H 1 33 34 #if HAVE_CONFIG_H 35 # include <ncurses_cfg.h> 36 #endif 37 38 #include <stdlib.h> 39 #include <string.h> 40 #include <assert.h> 41 42 #if HAVE_LIBDMALLOC 43 # include <dmalloc.h> /* Gray Watson's library */ 44 #endif 45 46 #if HAVE_LIBDBMALLOC 47 # include <dbmalloc.h> /* Conor Cahill's library */ 48 #endif 49 50 #include "curses.priv.h" 51 #include "panel.h" 52 #include <nc_panel.h> 53 54 #if USE_RCS_IDS 55 # define MODULE_ID(id) static const char Ident[] = id; 56 #else 57 # define MODULE_ID(id) /*nothing*/ 58 #endif 59 60 61 #ifdef TRACE 62 extern NCURSES_EXPORT(const char *) _nc_my_visbuf (const void *); 63 # ifdef TRACE_TXT 64 # define USER_PTR(ptr) _nc_visbuf((const char *)ptr) 65 # else 66 # define USER_PTR(ptr) _nc_my_visbuf((const char *)ptr) 67 # endif 68 69 # define returnPanel(code) TRACE_RETURN(code,panel) 70 71 extern NCURSES_EXPORT(PANEL *) _nc_retrace_panel (PANEL *); 72 extern NCURSES_EXPORT(void) _nc_dPanel (const char*, const PANEL*); 73 extern NCURSES_EXPORT(void) _nc_dStack (const char*, int, const PANEL*); 74 extern NCURSES_EXPORT(void) _nc_Wnoutrefresh (const PANEL*); 75 extern NCURSES_EXPORT(void) _nc_Touchpan (const PANEL*); 76 extern NCURSES_EXPORT(void) _nc_Touchline (const PANEL*, int, int); 77 78 # define dBug(x) _tracef x 79 # define dPanel(text,pan) _nc_dPanel(text,pan) 80 # define dStack(fmt,num,pan) _nc_dStack(fmt,num,pan) 81 # define Wnoutrefresh(pan) _nc_Wnoutrefresh(pan) 82 # define Touchpan(pan) _nc_Touchpan(pan) 83 # define Touchline(pan,start,count) _nc_Touchline(pan,start,count) 84 #else /* !TRACE */ 85 # define returnPanel(code) return code 86 # define dBug(x) 87 # define dPanel(text,pan) 88 # define dStack(fmt,num,pan) 89 # define Wnoutrefresh(pan) wnoutrefresh((pan)->win) 90 # define Touchpan(pan) touchwin((pan)->win) 91 # define Touchline(pan,start,count) touchline((pan)->win,start,count) 92 #endif 93 94 #define _nc_stdscr_pseudo_panel _nc_panelhook()->stdscr_pseudo_panel 95 #define _nc_top_panel _nc_panelhook()->top_panel 96 #define _nc_bottom_panel _nc_panelhook()->bottom_panel 97 98 #define EMPTY_STACK() (_nc_top_panel==_nc_bottom_panel) 99 #define Is_Bottom(p) (((p)!=(PANEL*)0) && !EMPTY_STACK() && (_nc_bottom_panel->above==(p))) 100 #define Is_Top(p) (((p)!=(PANEL*)0) && !EMPTY_STACK() && (_nc_top_panel==(p))) 101 #define Is_Pseudo(p) ((p) && ((p)==_nc_bottom_panel)) 102 103 /*+------------------------------------------------------------------------- 104 IS_LINKED(pan) - check to see if panel is in the stack 105 --------------------------------------------------------------------------*/ 106 /* This works! The only case where it would fail is, when the list has 107 only one element. But this could only be the pseudo panel at the bottom */ 108 #define IS_LINKED(p) (((p)->above || (p)->below ||((p)==_nc_bottom_panel)) ? TRUE : FALSE) 109 110 #define PSTARTX(pan) ((pan)->win->_begx) 111 #define PENDX(pan) ((pan)->win->_begx + getmaxx((pan)->win) - 1) 112 #define PSTARTY(pan) ((pan)->win->_begy) 113 #define PENDY(pan) ((pan)->win->_begy + getmaxy((pan)->win) - 1) 114 115 /*+------------------------------------------------------------------------- 116 PANELS_OVERLAPPED(pan1,pan2) - check panel overlapped 117 ---------------------------------------------------------------------------*/ 118 #define PANELS_OVERLAPPED(pan1,pan2) \ 119 (( !(pan1) || !(pan2) || \ 120 PSTARTY(pan1) > PENDY(pan2) || PENDY(pan1) < PSTARTY(pan2) ||\ 121 PSTARTX(pan1) > PENDX(pan2) || PENDX(pan1) < PSTARTX(pan2) ) \ 122 ? FALSE : TRUE) 123 124 125 /*+------------------------------------------------------------------------- 126 Compute the intersection rectangle of two overlapping rectangles 127 ---------------------------------------------------------------------------*/ 128 #define COMPUTE_INTERSECTION(pan1,pan2,ix1,ix2,iy1,iy2)\ 129 ix1 = (PSTARTX(pan1) < PSTARTX(pan2)) ? PSTARTX(pan2) : PSTARTX(pan1);\ 130 ix2 = (PENDX(pan1) < PENDX(pan2)) ? PENDX(pan1) : PENDX(pan2);\ 131 iy1 = (PSTARTY(pan1) < PSTARTY(pan2)) ? PSTARTY(pan2) : PSTARTY(pan1);\ 132 iy2 = (PENDY(pan1) < PENDY(pan2)) ? PENDY(pan1) : PENDY(pan2);\ 133 assert((ix1<=ix2) && (iy1<=iy2));\ 134 135 136 /*+------------------------------------------------------------------------- 137 Walk through the panel stack starting at the given location and 138 check for intersections; overlapping panels are "touched", so they 139 are incrementally overwriting cells that should be hidden. 140 If the "touch" flag is set, the panel gets touched before it is 141 updated. 142 ---------------------------------------------------------------------------*/ 143 #define PANEL_UPDATE(pan,panstart)\ 144 { PANEL* pan2 = ((panstart) ? (panstart) : _nc_bottom_panel);\ 145 while(pan2) {\ 146 if ((pan2 != pan) && PANELS_OVERLAPPED(pan,pan2)) {\ 147 int y,ix1,ix2,iy1,iy2;\ 148 COMPUTE_INTERSECTION(pan,pan2,ix1,ix2,iy1,iy2);\ 149 for(y = iy1; y <= iy2; y++) {\ 150 if (is_linetouched(pan->win,y - PSTARTY(pan))) {\ 151 struct ldat* line = &(pan2->win->_line[y - PSTARTY(pan2)]);\ 152 CHANGED_RANGE(line,ix1-PSTARTX(pan2),ix2-PSTARTX(pan2));\ 153 }\ 154 }\ 155 }\ 156 pan2 = pan2->above;\ 157 }\ 158 } 159 160 /*+------------------------------------------------------------------------- 161 Remove panel from stack. 162 ---------------------------------------------------------------------------*/ 163 #define PANEL_UNLINK(pan,err) \ 164 { err = ERR;\ 165 if (pan) {\ 166 if (IS_LINKED(pan)) {\ 167 if ((pan)->below)\ 168 (pan)->below->above = (pan)->above;\ 169 if ((pan)->above)\ 170 (pan)->above->below = (pan)->below;\ 171 if ((pan) == _nc_bottom_panel) \ 172 _nc_bottom_panel = (pan)->above;\ 173 if ((pan) == _nc_top_panel) \ 174 _nc_top_panel = (pan)->below;\ 175 err = OK;\ 176 }\ 177 (pan)->above = (pan)->below = (PANEL*)0;\ 178 }\ 179 } 180 181 #define HIDE_PANEL(pan,err,err_if_unlinked)\ 182 if (IS_LINKED(pan)) {\ 183 Touchpan(pan);\ 184 PANEL_UPDATE(pan,(PANEL*)0);\ 185 PANEL_UNLINK(pan,err);\ 186 } \ 187 else {\ 188 err = err_if_unlinked;\ 189 } 190 191 #endif /* NCURSES_PANEL_PRIV_H */ 192