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