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