xref: /openbsd-src/lib/libpanel/panel.priv.h (revision 46035553bfdd96e63c94e32da0210227ec2e3cf1)
1 /*	$OpenBSD: panel.priv.h,v 1.10 2015/01/23 22:48:51 krw Exp $	*/
2 /****************************************************************************
3  * Copyright (c) 1998-2005,2008 Free Software Foundation, Inc.              *
4  *                                                                          *
5  * Permission is hereby granted, free of charge, to any person obtaining a  *
6  * copy of this software and associated documentation files (the            *
7  * "Software"), to deal in the Software without restriction, including      *
8  * without limitation the rights to use, copy, modify, merge, publish,      *
9  * distribute, distribute with modifications, sublicense, and/or sell       *
10  * copies of the Software, and to permit persons to whom the Software is    *
11  * furnished to do so, subject to the following conditions:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23  *                                                                          *
24  * Except as contained in this notice, the name(s) of the above copyright   *
25  * holders shall not be used in advertising or otherwise to promote the     *
26  * sale, use or other dealings in this Software without prior written       *
27  * authorization.                                                           *
28  ****************************************************************************/
29 
30 /* $Id: panel.priv.h,v 1.10 2015/01/23 22:48:51 krw 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 #include "curses.priv.h"
44 #include "panel.h"
45 #include <nc_panel.h>
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_RETURN(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 #define _nc_stdscr_pseudo_panel _nc_panelhook()->stdscr_pseudo_panel
88 #define _nc_top_panel _nc_panelhook()->top_panel
89 #define _nc_bottom_panel _nc_panelhook()->bottom_panel
90 
91 #define EMPTY_STACK() (_nc_top_panel==_nc_bottom_panel)
92 #define Is_Bottom(p)  (((p)!=(PANEL*)0) && !EMPTY_STACK() && (_nc_bottom_panel->above==(p)))
93 #define Is_Top(p) (((p)!=(PANEL*)0) && !EMPTY_STACK() && (_nc_top_panel==(p)))
94 #define Is_Pseudo(p) ((p) && ((p)==_nc_bottom_panel))
95 
96 /*+-------------------------------------------------------------------------
97 	IS_LINKED(pan) - check to see if panel is in the stack
98 --------------------------------------------------------------------------*/
99 /* This works! The only case where it would fail is, when the list has
100    only one element. But this could only be the pseudo panel at the bottom */
101 #define IS_LINKED(p) (((p)->above || (p)->below ||((p)==_nc_bottom_panel)) ? TRUE : FALSE)
102 
103 #define PSTARTX(pan) ((pan)->win->_begx)
104 #define PENDX(pan)   ((pan)->win->_begx + getmaxx((pan)->win) - 1)
105 #define PSTARTY(pan) ((pan)->win->_begy)
106 #define PENDY(pan)   ((pan)->win->_begy + getmaxy((pan)->win) - 1)
107 
108 /*+-------------------------------------------------------------------------
109 	PANELS_OVERLAPPED(pan1,pan2) - check panel overlapped
110 ---------------------------------------------------------------------------*/
111 #define PANELS_OVERLAPPED(pan1,pan2) \
112 (( !(pan1) || !(pan2) || \
113        PSTARTY(pan1) > PENDY(pan2) || PENDY(pan1) < PSTARTY(pan2) ||\
114        PSTARTX(pan1) > PENDX(pan2) || PENDX(pan1) < PSTARTX(pan2) ) \
115      ? FALSE : TRUE)
116 
117 
118 /*+-------------------------------------------------------------------------
119 	Compute the intersection rectangle of two overlapping rectangles
120 ---------------------------------------------------------------------------*/
121 #define COMPUTE_INTERSECTION(pan1,pan2,ix1,ix2,iy1,iy2)\
122    ix1 = (PSTARTX(pan1) < PSTARTX(pan2)) ? PSTARTX(pan2) : PSTARTX(pan1);\
123    ix2 = (PENDX(pan1)   < PENDX(pan2))   ? PENDX(pan1)   : PENDX(pan2);\
124    iy1 = (PSTARTY(pan1) < PSTARTY(pan2)) ? PSTARTY(pan2) : PSTARTY(pan1);\
125    iy2 = (PENDY(pan1)   < PENDY(pan2))   ? PENDY(pan1)   : PENDY(pan2);\
126    assert((ix1<=ix2) && (iy1<=iy2));\
127 
128 
129 /*+-------------------------------------------------------------------------
130 	Walk through the panel stack starting at the given location and
131         check for intersections; overlapping panels are "touched", so they
132         are incrementally overwriting cells that should be hidden.
133         If the "touch" flag is set, the panel gets touched before it is
134         updated.
135 ---------------------------------------------------------------------------*/
136 #define PANEL_UPDATE(pan,panstart)\
137 {  PANEL* pan2 = ((panstart) ? (panstart) : _nc_bottom_panel);\
138    while(pan2) {\
139       if ((pan2 != pan) && PANELS_OVERLAPPED(pan,pan2)) {\
140         int y,ix1,ix2,iy1,iy2;\
141         COMPUTE_INTERSECTION(pan,pan2,ix1,ix2,iy1,iy2);\
142 	for(y = iy1; y <= iy2; y++) {\
143 	  if (is_linetouched(pan->win,y - PSTARTY(pan))) {\
144             struct ldat* line = &(pan2->win->_line[y - PSTARTY(pan2)]);\
145             CHANGED_RANGE(line,ix1-PSTARTX(pan2),ix2-PSTARTX(pan2));\
146           }\
147 	}\
148       }\
149       pan2 = pan2->above;\
150    }\
151 }
152 
153 /*+-------------------------------------------------------------------------
154 	Remove panel from stack.
155 ---------------------------------------------------------------------------*/
156 #define PANEL_UNLINK(pan,err) \
157 {  err = ERR;\
158    if (pan) {\
159      if (IS_LINKED(pan)) {\
160        if ((pan)->below)\
161          (pan)->below->above = (pan)->above;\
162        if ((pan)->above)\
163          (pan)->above->below = (pan)->below;\
164        if ((pan) == _nc_bottom_panel) \
165          _nc_bottom_panel = (pan)->above;\
166        if ((pan) == _nc_top_panel) \
167          _nc_top_panel = (pan)->below;\
168        err = OK;\
169      }\
170      (pan)->above = (pan)->below = (PANEL*)0;\
171    }\
172 }
173 
174 #define HIDE_PANEL(pan,err,err_if_unlinked)\
175   if (IS_LINKED(pan)) {\
176     Touchpan(pan);\
177     PANEL_UPDATE(pan,(PANEL*)0);\
178     PANEL_UNLINK(pan,err);\
179   } \
180   else {\
181       err = err_if_unlinked;\
182   }
183 
184 #endif /* NCURSES_PANEL_PRIV_H */
185