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