1 /****************************************************************************
2 * Copyright (c) 2000 Free Software Foundation, Inc. *
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: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
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. *
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 *
27 ****************************************************************************/
29 /* $Id: panel.priv.h,v 1.14 2000/09/02 18:22:23 tom Exp $ */
35 # include <ncurses_cfg.h>
43 # include <dmalloc.h> /* Gray Watson's library */
47 # include <dbmalloc.h> /* Conor Cahill's library */
53 #if ( CC_HAS_INLINE_FUNCS && !defined(TRACE) )
54 # define INLINE inline
60 # define MODULE_ID(id) static const char Ident[] = id;
62 # define MODULE_ID(id) /*nothing*/
67 extern const char *_nc_my_visbuf(const void *);
69 # define USER_PTR(ptr) _nc_visbuf((const char *)ptr)
71 # define USER_PTR(ptr) _nc_my_visbuf((const char *)ptr)
74 extern void _nc_dPanel(const char*, const PANEL*);
75 extern void _nc_dStack(const char*, int, const PANEL*);
76 extern void _nc_Wnoutrefresh(const PANEL*);
77 extern void _nc_Touchpan(const PANEL*);
78 extern void _nc_Touchline(const PANEL*, int, int);
80 # define dBug(x) _tracef x
81 # define dPanel(text,pan) _nc_dPanel(text,pan)
82 # define dStack(fmt,num,pan) _nc_dStack(fmt,num,pan)
83 # define Wnoutrefresh(pan) _nc_Wnoutrefresh(pan)
84 # define Touchpan(pan) _nc_Touchpan(pan)
85 # define Touchline(pan,start,count) _nc_Touchline(pan,start,count)
88 # define dPanel(text,pan)
89 # define dStack(fmt,num,pan)
90 # define Wnoutrefresh(pan) wnoutrefresh((pan)->win)
91 # define Touchpan(pan) touchwin((pan)->win)
92 # define Touchline(pan,start,count) touchline((pan)->win,start,count)
95 #define _nc_stdscr_pseudo_panel _nc_panelhook()->stdscr_pseudo_panel
96 #define _nc_top_panel _nc_panelhook()->top_panel
97 #define _nc_bottom_panel _nc_panelhook()->bottom_panel
99 #define EMPTY_STACK() (_nc_top_panel==_nc_bottom_panel)
100 #define Is_Bottom(p) (((p)!=(PANEL*)0) && !EMPTY_STACK() && (_nc_bottom_panel->above==(p)))
101 #define Is_Top(p) (((p)!=(PANEL*)0) && !EMPTY_STACK() && (_nc_top_panel==(p)))
102 #define Is_Pseudo(p) ((p) && ((p)==_nc_bottom_panel))
104 /* borrowed from curses.priv.h */
105 #define CHANGED_RANGE(line,start,end) \
106 if (line->firstchar == _NOCHANGE \
107 || line->firstchar > (start)) \
108 line->firstchar = start; \
109 if (line->lastchar == _NOCHANGE \
110 || line->lastchar < (end)) \
113 /*+-------------------------------------------------------------------------
114 IS_LINKED(pan) - check to see if panel is in the stack
115 --------------------------------------------------------------------------*/
116 /* This works! The only case where it would fail is, when the list has
117 only one element. But this could only be the pseudo panel at the bottom */
118 #define IS_LINKED(p) (((p)->above || (p)->below ||((p)==_nc_bottom_panel)) ? TRUE : FALSE)
120 #define PSTARTX(pan) ((pan)->win->_begx)
121 #define PENDX(pan) ((pan)->win->_begx + getmaxx((pan)->win) - 1)
122 #define PSTARTY(pan) ((pan)->win->_begy)
123 #define PENDY(pan) ((pan)->win->_begy + getmaxy((pan)->win) - 1)
125 /*+-------------------------------------------------------------------------
126 PANELS_OVERLAPPED(pan1,pan2) - check panel overlapped
127 ---------------------------------------------------------------------------*/
128 #define PANELS_OVERLAPPED(pan1,pan2) \
129 (( !(pan1) || !(pan2) || \
130 PSTARTY(pan1) > PENDY(pan2) || PENDY(pan1) < PSTARTY(pan2) ||\
131 PSTARTX(pan1) > PENDX(pan2) || PENDX(pan1) < PSTARTX(pan2) ) \
135 /*+-------------------------------------------------------------------------
136 Compute the intersection rectangle of two overlapping rectangles
137 ---------------------------------------------------------------------------*/
138 #define COMPUTE_INTERSECTION(pan1,pan2,ix1,ix2,iy1,iy2)\
139 ix1 = (PSTARTX(pan1) < PSTARTX(pan2)) ? PSTARTX(pan2) : PSTARTX(pan1);\
140 ix2 = (PENDX(pan1) < PENDX(pan2)) ? PENDX(pan1) : PENDX(pan2);\
141 iy1 = (PSTARTY(pan1) < PSTARTY(pan2)) ? PSTARTY(pan2) : PSTARTY(pan1);\
142 iy2 = (PENDY(pan1) < PENDY(pan2)) ? PENDY(pan1) : PENDY(pan2);\
143 assert((ix1<=ix2) && (iy1<=iy2));\
146 /*+-------------------------------------------------------------------------
147 Walk through the panel stack starting at the given location and
148 check for intersections; overlapping panels are "touched", so they
149 are incrementally overwriting cells that should be hidden.
150 If the "touch" flag is set, the panel gets touched before it is
152 ---------------------------------------------------------------------------*/
153 #define PANEL_UPDATE(pan,panstart,touch)\
154 { PANEL* pan2 = ((panstart) ? (panstart) : _nc_bottom_panel);\
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));\
172 /*+-------------------------------------------------------------------------
173 Remove panel from stack.
174 ---------------------------------------------------------------------------*/
175 #define PANEL_UNLINK(pan,err) \
178 if (IS_LINKED(pan)) {\
180 (pan)->below->above = (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;\
189 (pan)->above = (pan)->below = (PANEL*)0;\
193 #define HIDE_PANEL(pan,err,err_if_unlinked)\
194 if (IS_LINKED(pan)) {\
195 PANEL_UPDATE(pan,(PANEL*)0,TRUE);\
196 PANEL_UNLINK(pan,err);\
199 if (err_if_unlinked)\
203 #endif /* _PANEL_PRIV_H */