panel.priv.h revision 262629
1218885Sdim/**************************************************************************** 2218885Sdim * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc. * 3218885Sdim * * 4218885Sdim * Permission is hereby granted, free of charge, to any person obtaining a * 5218885Sdim * copy of this software and associated documentation files (the * 6218885Sdim * "Software"), to deal in the Software without restriction, including * 7218885Sdim * without limitation the rights to use, copy, modify, merge, publish, * 8218885Sdim * distribute, distribute with modifications, sublicense, and/or sell * 9218885Sdim * copies of the Software, and to permit persons to whom the Software is * 10218885Sdim * furnished to do so, subject to the following conditions: * 11218885Sdim * * 12218885Sdim * The above copyright notice and this permission notice shall be included * 13218885Sdim * in all copies or substantial portions of the Software. * 14218885Sdim * * 15218885Sdim * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 16218885Sdim * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 17218885Sdim * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 18218885Sdim * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 19218885Sdim * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 20218885Sdim * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 21218885Sdim * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 22234353Sdim * * 23218885Sdim * Except as contained in this notice, the name(s) of the above copyright * 24234353Sdim * holders shall not be used in advertising or otherwise to promote the * 25218885Sdim * sale, use or other dealings in this Software without prior written * 26234353Sdim * authorization. * 27234353Sdim ****************************************************************************/ 28234353Sdim 29234353Sdim/* $Id: panel.priv.h,v 1.23 2009/04/11 20:33:55 tom Exp $ */ 30218885Sdim 31218885Sdim#ifndef NCURSES_PANEL_PRIV_H 32218885Sdim#define NCURSES_PANEL_PRIV_H 1 33218885Sdim 34218885Sdim#if HAVE_CONFIG_H 35218885Sdim# include <ncurses_cfg.h> 36234353Sdim#endif 37226633Sdim 38234353Sdim#include <stdlib.h> 39234353Sdim#include <string.h> 40234353Sdim#include <assert.h> 41218885Sdim 42218885Sdimstruct screen; /* forward declaration */ 43218885Sdim 44218885Sdim#include "curses.priv.h" /* includes nc_panel.h */ 45218885Sdim#include "panel.h" 46234353Sdim 47218885Sdim 48218885Sdim#if USE_RCS_IDS 49218885Sdim# define MODULE_ID(id) static const char Ident[] = id; 50218885Sdim#else 51218885Sdim# define MODULE_ID(id) /*nothing*/ 52234353Sdim#endif 53218885Sdim 54218885Sdim 55224145Sdim#ifdef TRACE 56218885Sdim extern NCURSES_EXPORT(const char *) _nc_my_visbuf (const void *); 57218885Sdim# ifdef TRACE_TXT 58218885Sdim# define USER_PTR(ptr) _nc_visbuf((const char *)ptr) 59218885Sdim# else 60218885Sdim# define USER_PTR(ptr) _nc_my_visbuf((const char *)ptr) 61234353Sdim# endif 62234353Sdim 63218885Sdim# define returnPanel(code) TRACE_RETURN(code,panel) 64234353Sdim 65218885Sdim extern NCURSES_EXPORT(PANEL *) _nc_retrace_panel (PANEL *); 66218885Sdim extern NCURSES_EXPORT(void) _nc_dPanel (const char*, const PANEL*); 67218885Sdim extern NCURSES_EXPORT(void) _nc_dStack (const char*, int, const PANEL*); 68218885Sdim extern NCURSES_EXPORT(void) _nc_Wnoutrefresh (const PANEL*); 69218885Sdim extern NCURSES_EXPORT(void) _nc_Touchpan (const PANEL*); 70218885Sdim extern NCURSES_EXPORT(void) _nc_Touchline (const PANEL*, int, int); 71218885Sdim 72218885Sdim# define dBug(x) _tracef x 73218885Sdim# define dPanel(text,pan) _nc_dPanel(text,pan) 74# define dStack(fmt,num,pan) _nc_dStack(fmt,num,pan) 75# define Wnoutrefresh(pan) _nc_Wnoutrefresh(pan) 76# define Touchpan(pan) _nc_Touchpan(pan) 77# define Touchline(pan,start,count) _nc_Touchline(pan,start,count) 78#else /* !TRACE */ 79# define returnPanel(code) return code 80# define dBug(x) 81# define dPanel(text,pan) 82# define dStack(fmt,num,pan) 83# define Wnoutrefresh(pan) wnoutrefresh((pan)->win) 84# define Touchpan(pan) touchwin((pan)->win) 85# define Touchline(pan,start,count) touchline((pan)->win,start,count) 86#endif 87 88#if NCURSES_SP_FUNCS 89#define GetScreenHook(sp) \ 90 struct panelhook* ph = NCURSES_SP_NAME(_nc_panelhook)(sp) 91#define GetPanelHook(pan) \ 92 GetScreenHook(_nc_screen_of((pan)->win)) 93#define GetWindowHook(win) \ 94 SCREEN* sp = _nc_screen_of(win); \ 95 GetScreenHook(sp) 96#define GetHook(pan) SCREEN* sp = _nc_screen_of(pan->win); \ 97 GetScreenHook(sp) 98 99#define _nc_stdscr_pseudo_panel ((ph)->stdscr_pseudo_panel) 100#define _nc_top_panel ((ph)->top_panel) 101#define _nc_bottom_panel ((ph)->bottom_panel) 102 103#else /* !NCURSES_SP_FUNCS */ 104 105#define GetScreenHook(sp) /* nothing */ 106#define GetPanelHook(pan) /* nothing */ 107#define GetWindowHook(win) /* nothing */ 108#define GetHook(pan) /* nothing */ 109 110#define _nc_stdscr_pseudo_panel _nc_panelhook()->stdscr_pseudo_panel 111#define _nc_top_panel _nc_panelhook()->top_panel 112#define _nc_bottom_panel _nc_panelhook()->bottom_panel 113 114#endif /* NCURSES_SP_FUNCS */ 115 116#define EMPTY_STACK() (_nc_top_panel == _nc_bottom_panel) 117#define Is_Bottom(p) (((p) != (PANEL*)0) && !EMPTY_STACK() && (_nc_bottom_panel->above == (p))) 118#define Is_Top(p) (((p) != (PANEL*)0) && !EMPTY_STACK() && (_nc_top_panel == (p))) 119#define Is_Pseudo(p) (((p) != (PANEL*)0) && ((p) == _nc_bottom_panel)) 120 121/*+------------------------------------------------------------------------- 122 IS_LINKED(pan) - check to see if panel is in the stack 123--------------------------------------------------------------------------*/ 124/* This works! The only case where it would fail is, when the list has 125 only one element. But this could only be the pseudo panel at the bottom */ 126#define IS_LINKED(p) (((p)->above || (p)->below ||((p)==_nc_bottom_panel)) ? TRUE : FALSE) 127 128#define PSTARTX(pan) ((pan)->win->_begx) 129#define PENDX(pan) ((pan)->win->_begx + getmaxx((pan)->win) - 1) 130#define PSTARTY(pan) ((pan)->win->_begy) 131#define PENDY(pan) ((pan)->win->_begy + getmaxy((pan)->win) - 1) 132 133/*+------------------------------------------------------------------------- 134 PANELS_OVERLAPPED(pan1,pan2) - check panel overlapped 135---------------------------------------------------------------------------*/ 136#define PANELS_OVERLAPPED(pan1,pan2) \ 137(( !(pan1) || !(pan2) || \ 138 PSTARTY(pan1) > PENDY(pan2) || PENDY(pan1) < PSTARTY(pan2) ||\ 139 PSTARTX(pan1) > PENDX(pan2) || PENDX(pan1) < PSTARTX(pan2) ) \ 140 ? FALSE : TRUE) 141 142 143/*+------------------------------------------------------------------------- 144 Compute the intersection rectangle of two overlapping rectangles 145---------------------------------------------------------------------------*/ 146#define COMPUTE_INTERSECTION(pan1,pan2,ix1,ix2,iy1,iy2)\ 147 ix1 = (PSTARTX(pan1) < PSTARTX(pan2)) ? PSTARTX(pan2) : PSTARTX(pan1);\ 148 ix2 = (PENDX(pan1) < PENDX(pan2)) ? PENDX(pan1) : PENDX(pan2);\ 149 iy1 = (PSTARTY(pan1) < PSTARTY(pan2)) ? PSTARTY(pan2) : PSTARTY(pan1);\ 150 iy2 = (PENDY(pan1) < PENDY(pan2)) ? PENDY(pan1) : PENDY(pan2);\ 151 assert((ix1<=ix2) && (iy1<=iy2)) 152 153 154/*+------------------------------------------------------------------------- 155 Walk through the panel stack starting at the given location and 156 check for intersections; overlapping panels are "touched", so they 157 are incrementally overwriting cells that should be hidden. 158 If the "touch" flag is set, the panel gets touched before it is 159 updated. 160---------------------------------------------------------------------------*/ 161#define PANEL_UPDATE(pan,panstart)\ 162{ PANEL* pan2 = ((panstart) ? (panstart) : _nc_bottom_panel);\ 163 while(pan2) {\ 164 if ((pan2 != pan) && PANELS_OVERLAPPED(pan,pan2)) {\ 165 int y, ix1, ix2, iy1, iy2;\ 166 COMPUTE_INTERSECTION(pan, pan2, ix1, ix2, iy1, iy2);\ 167 for(y = iy1; y <= iy2; y++) {\ 168 if (is_linetouched(pan->win,y - PSTARTY(pan))) {\ 169 struct ldat* line = &(pan2->win->_line[y - PSTARTY(pan2)]);\ 170 CHANGED_RANGE(line, ix1 - PSTARTX(pan2), ix2 - PSTARTX(pan2));\ 171 }\ 172 }\ 173 }\ 174 pan2 = pan2->above;\ 175 }\ 176} 177 178/*+------------------------------------------------------------------------- 179 Remove panel from stack. 180---------------------------------------------------------------------------*/ 181#define PANEL_UNLINK(pan,err) \ 182{ err = ERR;\ 183 if (pan) {\ 184 if (IS_LINKED(pan)) {\ 185 if ((pan)->below)\ 186 (pan)->below->above = (pan)->above;\ 187 if ((pan)->above)\ 188 (pan)->above->below = (pan)->below;\ 189 if ((pan) == _nc_bottom_panel) \ 190 _nc_bottom_panel = (pan)->above;\ 191 if ((pan) == _nc_top_panel) \ 192 _nc_top_panel = (pan)->below;\ 193 err = OK;\ 194 }\ 195 (pan)->above = (pan)->below = (PANEL*)0;\ 196 }\ 197} 198 199#define HIDE_PANEL(pan,err,err_if_unlinked)\ 200 if (IS_LINKED(pan)) {\ 201 Touchpan(pan);\ 202 PANEL_UPDATE(pan,(PANEL*)0);\ 203 PANEL_UNLINK(pan,err);\ 204 } \ 205 else {\ 206 err = err_if_unlinked;\ 207 } 208 209#if NCURSES_SP_FUNCS 210/* These may become later renamed and part of panel.h and the public API */ 211extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_update_panels)(SCREEN*); 212#endif 213 214#endif /* NCURSES_PANEL_PRIV_H */ 215