xref: /openbsd-src/lib/libpanel/panel.priv.h (revision c7ef0cfc17afcba97172c25e1e3a943e893bc632)
1*c7ef0cfcSnicm /*	$OpenBSD: panel.priv.h,v 1.11 2023/10/17 09:52:10 nicm Exp $	*/
291421ef5Smillert /****************************************************************************
3*c7ef0cfcSnicm  * Copyright 2020 Thomas E. Dickey                                          *
4*c7ef0cfcSnicm  * Copyright 1998-2014,2017 Free Software Foundation, Inc.                  *
591421ef5Smillert  *                                                                          *
691421ef5Smillert  * Permission is hereby granted, free of charge, to any person obtaining a  *
791421ef5Smillert  * copy of this software and associated documentation files (the            *
891421ef5Smillert  * "Software"), to deal in the Software without restriction, including      *
991421ef5Smillert  * without limitation the rights to use, copy, modify, merge, publish,      *
1091421ef5Smillert  * distribute, distribute with modifications, sublicense, and/or sell       *
1191421ef5Smillert  * copies of the Software, and to permit persons to whom the Software is    *
1291421ef5Smillert  * furnished to do so, subject to the following conditions:                 *
1391421ef5Smillert  *                                                                          *
1491421ef5Smillert  * The above copyright notice and this permission notice shall be included  *
1591421ef5Smillert  * in all copies or substantial portions of the Software.                   *
1691421ef5Smillert  *                                                                          *
1791421ef5Smillert  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
1891421ef5Smillert  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
1991421ef5Smillert  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
2091421ef5Smillert  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
2191421ef5Smillert  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
2291421ef5Smillert  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
2391421ef5Smillert  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2491421ef5Smillert  *                                                                          *
2591421ef5Smillert  * Except as contained in this notice, the name(s) of the above copyright   *
2691421ef5Smillert  * holders shall not be used in advertising or otherwise to promote the     *
2791421ef5Smillert  * sale, use or other dealings in this Software without prior written       *
2891421ef5Smillert  * authorization.                                                           *
2991421ef5Smillert  ****************************************************************************/
3091421ef5Smillert 
31*c7ef0cfcSnicm /* $Id: panel.priv.h,v 1.11 2023/10/17 09:52:10 nicm Exp $ */
3286c209c0Smillert 
3381d8c4e1Snicm #ifndef NCURSES_PANEL_PRIV_H
3481d8c4e1Snicm #define NCURSES_PANEL_PRIV_H 1
35*c7ef0cfcSnicm /* *INDENT-OFF* */
3686c209c0Smillert 
3786c209c0Smillert #if HAVE_CONFIG_H
3886c209c0Smillert #  include <ncurses_cfg.h>
3986c209c0Smillert #endif
4086c209c0Smillert 
4186c209c0Smillert #include <stdlib.h>
4215fe46beSmillert #include <string.h>
4386c209c0Smillert #include <assert.h>
4486c209c0Smillert 
45*c7ef0cfcSnicm struct screen;              /* forward declaration */
46*c7ef0cfcSnicm 
47*c7ef0cfcSnicm #include "curses.priv.h"    /* includes nc_panel.h */
48*c7ef0cfcSnicm 
49*c7ef0cfcSnicm #define NCURSES_OPAQUE_PANEL 0
50*c7ef0cfcSnicm 
5186c209c0Smillert #include "panel.h"
5286c209c0Smillert 
5315fe46beSmillert #ifdef TRACE
54*c7ef0cfcSnicm    extern PANEL_EXPORT(const char *) _nc_my_visbuf (const void *, int);
5515fe46beSmillert #  ifdef TRACE_TXT
56*c7ef0cfcSnicm #    define USER_PTR(ptr,n) _nc_visbuf2(n, (const char *)ptr)
5715fe46beSmillert #  else
58*c7ef0cfcSnicm #    define USER_PTR(ptr,n) _nc_my_visbuf((const char *)ptr, n)
5986c209c0Smillert #  endif
6015fe46beSmillert 
61*c7ef0cfcSnicm #  define returnPanel(code)	TRACE_RETURN1(code,panel)
6281d8c4e1Snicm 
63*c7ef0cfcSnicm    extern PANEL_EXPORT(PANEL *) _nc_retrace_panel (PANEL *);
64*c7ef0cfcSnicm    extern PANEL_EXPORT(void) _nc_dPanel (const char*, const PANEL*);
65*c7ef0cfcSnicm    extern PANEL_EXPORT(void) _nc_dStack (const char*, int, const PANEL*);
66*c7ef0cfcSnicm    extern PANEL_EXPORT(void) _nc_Wnoutrefresh (const PANEL*);
67*c7ef0cfcSnicm    extern PANEL_EXPORT(void) _nc_Touchpan (const PANEL*);
68*c7ef0cfcSnicm    extern PANEL_EXPORT(void) _nc_Touchline (const PANEL*, int, int);
6915fe46beSmillert 
7015fe46beSmillert #  define dBug(x) _tracef x
7115fe46beSmillert #  define dPanel(text,pan) _nc_dPanel(text,pan)
7215fe46beSmillert #  define dStack(fmt,num,pan) _nc_dStack(fmt,num,pan)
7315fe46beSmillert #  define Wnoutrefresh(pan) _nc_Wnoutrefresh(pan)
7415fe46beSmillert #  define Touchpan(pan) _nc_Touchpan(pan)
7515fe46beSmillert #  define Touchline(pan,start,count) _nc_Touchline(pan,start,count)
7615fe46beSmillert #else /* !TRACE */
7781d8c4e1Snicm #  define returnPanel(code)	return code
7815fe46beSmillert #  define dBug(x)
7915fe46beSmillert #  define dPanel(text,pan)
8015fe46beSmillert #  define dStack(fmt,num,pan)
8115fe46beSmillert #  define Wnoutrefresh(pan) wnoutrefresh((pan)->win)
8215fe46beSmillert #  define Touchpan(pan) touchwin((pan)->win)
8315fe46beSmillert #  define Touchline(pan,start,count) touchline((pan)->win,start,count)
8415fe46beSmillert #endif
8515fe46beSmillert 
86*c7ef0cfcSnicm #if NCURSES_SP_FUNCS
87*c7ef0cfcSnicm #define GetScreenHook(sp) \
88*c7ef0cfcSnicm 			struct panelhook* ph = NCURSES_SP_NAME(_nc_panelhook)(sp)
89*c7ef0cfcSnicm #define GetPanelHook(pan) \
90*c7ef0cfcSnicm 			GetScreenHook(pan ? _nc_screen_of((pan)->win) : 0)
91*c7ef0cfcSnicm #define GetWindowHook(win) \
92*c7ef0cfcSnicm 			SCREEN* sp = _nc_screen_of(win); \
93*c7ef0cfcSnicm 			GetScreenHook(sp)
94*c7ef0cfcSnicm #define GetHook(pan)	SCREEN* sp = _nc_screen_of(pan->win); \
95*c7ef0cfcSnicm 			GetScreenHook(sp)
96*c7ef0cfcSnicm 
97*c7ef0cfcSnicm #define _nc_stdscr_pseudo_panel ((ph)->stdscr_pseudo_panel)
98*c7ef0cfcSnicm #define _nc_top_panel           ((ph)->top_panel)
99*c7ef0cfcSnicm #define _nc_bottom_panel        ((ph)->bottom_panel)
100*c7ef0cfcSnicm 
101*c7ef0cfcSnicm #else	/* !NCURSES_SP_FUNCS */
102*c7ef0cfcSnicm 
103*c7ef0cfcSnicm #define GetScreenHook(sp) /* nothing */
104*c7ef0cfcSnicm #define GetPanelHook(pan) /* nothing */
105*c7ef0cfcSnicm #define GetWindowHook(win) /* nothing */
106*c7ef0cfcSnicm #define GetHook(pan) /* nothing */
107*c7ef0cfcSnicm 
10815fe46beSmillert #define _nc_stdscr_pseudo_panel _nc_panelhook()->stdscr_pseudo_panel
10915fe46beSmillert #define _nc_top_panel           _nc_panelhook()->top_panel
11015fe46beSmillert #define _nc_bottom_panel        _nc_panelhook()->bottom_panel
11115fe46beSmillert 
112*c7ef0cfcSnicm #endif	/* NCURSES_SP_FUNCS */
113*c7ef0cfcSnicm 
1149ee63291Smillert #define EMPTY_STACK() (_nc_top_panel == _nc_bottom_panel)
1159ee63291Smillert #define Is_Bottom(p)  (((p) != (PANEL*)0) && !EMPTY_STACK() && (_nc_bottom_panel->above == (p)))
1169ee63291Smillert #define Is_Top(p)     (((p) != (PANEL*)0) && !EMPTY_STACK() && (_nc_top_panel == (p)))
117*c7ef0cfcSnicm #define Is_Pseudo(p)  (((p) != (PANEL*)0) && ((p) == _nc_bottom_panel))
1189ee63291Smillert 
1199ee63291Smillert /*+-------------------------------------------------------------------------
1209ee63291Smillert 	IS_LINKED(pan) - check to see if panel is in the stack
1219ee63291Smillert --------------------------------------------------------------------------*/
1229ee63291Smillert /* This works! The only case where it would fail is, when the list has
1239ee63291Smillert    only one element. But this could only be the pseudo panel at the bottom */
1249ee63291Smillert #define IS_LINKED(p) (((p)->above || (p)->below ||((p)==_nc_bottom_panel)) ? TRUE : FALSE)
1259ee63291Smillert 
1269ee63291Smillert #define PSTARTX(pan) ((pan)->win->_begx)
1279ee63291Smillert #define PENDX(pan)   ((pan)->win->_begx + getmaxx((pan)->win) - 1)
1289ee63291Smillert #define PSTARTY(pan) ((pan)->win->_begy)
1299ee63291Smillert #define PENDY(pan)   ((pan)->win->_begy + getmaxy((pan)->win) - 1)
1309ee63291Smillert 
1319ee63291Smillert /*+-------------------------------------------------------------------------
1329ee63291Smillert 	PANELS_OVERLAPPED(pan1,pan2) - check panel overlapped
1339ee63291Smillert ---------------------------------------------------------------------------*/
1349ee63291Smillert #define PANELS_OVERLAPPED(pan1,pan2) \
1359ee63291Smillert (( !(pan1) || !(pan2) || \
1369ee63291Smillert        PSTARTY(pan1) > PENDY(pan2) || PENDY(pan1) < PSTARTY(pan2) ||\
1379ee63291Smillert        PSTARTX(pan1) > PENDX(pan2) || PENDX(pan1) < PSTARTX(pan2) ) \
1389ee63291Smillert      ? FALSE : TRUE)
1399ee63291Smillert 
1409ee63291Smillert 
1419ee63291Smillert /*+-------------------------------------------------------------------------
1429ee63291Smillert 	Compute the intersection rectangle of two overlapping rectangles
1439ee63291Smillert ---------------------------------------------------------------------------*/
1449ee63291Smillert #define COMPUTE_INTERSECTION(pan1,pan2,ix1,ix2,iy1,iy2)\
1459ee63291Smillert    ix1 = (PSTARTX(pan1) < PSTARTX(pan2)) ? PSTARTX(pan2) : PSTARTX(pan1);\
1469ee63291Smillert    ix2 = (PENDX(pan1)   < PENDX(pan2))   ? PENDX(pan1)   : PENDX(pan2);\
1479ee63291Smillert    iy1 = (PSTARTY(pan1) < PSTARTY(pan2)) ? PSTARTY(pan2) : PSTARTY(pan1);\
1489ee63291Smillert    iy2 = (PENDY(pan1)   < PENDY(pan2))   ? PENDY(pan1)   : PENDY(pan2);\
149*c7ef0cfcSnicm    assert((ix1<=ix2) && (iy1<=iy2))
1509ee63291Smillert 
1519ee63291Smillert 
1529ee63291Smillert /*+-------------------------------------------------------------------------
1539ee63291Smillert 	Walk through the panel stack starting at the given location and
1549ee63291Smillert         check for intersections; overlapping panels are "touched", so they
1559ee63291Smillert         are incrementally overwriting cells that should be hidden.
1569ee63291Smillert         If the "touch" flag is set, the panel gets touched before it is
1579ee63291Smillert         updated.
1589ee63291Smillert ---------------------------------------------------------------------------*/
1592f4721ffSmillert #define PANEL_UPDATE(pan,panstart)\
1606ac04242Smillert {  PANEL* pan2 = ((panstart) ? (panstart) : _nc_bottom_panel);\
161*c7ef0cfcSnicm    while(pan2 && pan2->win) {\
1629ee63291Smillert       if ((pan2 != pan) && PANELS_OVERLAPPED(pan,pan2)) {\
1636ac04242Smillert         int y, ix1, ix2, iy1, iy2;\
1649ee63291Smillert         COMPUTE_INTERSECTION(pan, pan2, ix1, ix2, iy1, iy2);\
1659ee63291Smillert 	for(y = iy1; y <= iy2; y++) {\
1669ee63291Smillert 	  if (is_linetouched(pan->win,y - PSTARTY(pan))) {\
1679ee63291Smillert             struct ldat* line = &(pan2->win->_line[y - PSTARTY(pan2)]);\
1689ee63291Smillert             CHANGED_RANGE(line, ix1 - PSTARTX(pan2), ix2 - PSTARTX(pan2));\
1699ee63291Smillert           }\
1709ee63291Smillert 	}\
1719ee63291Smillert       }\
1729ee63291Smillert       pan2 = pan2->above;\
1739ee63291Smillert    }\
1749ee63291Smillert }
1759ee63291Smillert 
1769ee63291Smillert /*+-------------------------------------------------------------------------
1779ee63291Smillert 	Remove panel from stack.
1789ee63291Smillert ---------------------------------------------------------------------------*/
1799ee63291Smillert #define PANEL_UNLINK(pan,err) \
1809ee63291Smillert {  err = ERR;\
1819ee63291Smillert    if (pan) {\
1829ee63291Smillert      if (IS_LINKED(pan)) {\
1839ee63291Smillert        if ((pan)->below)\
1849ee63291Smillert          (pan)->below->above = (pan)->above;\
1859ee63291Smillert        if ((pan)->above)\
1869ee63291Smillert          (pan)->above->below = (pan)->below;\
1879ee63291Smillert        if ((pan) == _nc_bottom_panel) \
1889ee63291Smillert          _nc_bottom_panel = (pan)->above;\
1899ee63291Smillert        if ((pan) == _nc_top_panel) \
1909ee63291Smillert          _nc_top_panel = (pan)->below;\
1919ee63291Smillert        err = OK;\
1929ee63291Smillert      }\
1939ee63291Smillert      (pan)->above = (pan)->below = (PANEL*)0;\
1949ee63291Smillert    }\
1959ee63291Smillert }
1969ee63291Smillert 
1979ee63291Smillert #define HIDE_PANEL(pan,err,err_if_unlinked)\
1989ee63291Smillert   if (IS_LINKED(pan)) {\
1992f4721ffSmillert     Touchpan(pan);\
2002f4721ffSmillert     PANEL_UPDATE(pan,(PANEL*)0);\
2019ee63291Smillert     PANEL_UNLINK(pan,err);\
2029ee63291Smillert   } \
2039ee63291Smillert   else {\
2042f4721ffSmillert       err = err_if_unlinked;\
2059ee63291Smillert   }
20615fe46beSmillert 
207*c7ef0cfcSnicm #if NCURSES_SP_FUNCS
208*c7ef0cfcSnicm /* These may become later renamed and part of panel.h and the public API */
209*c7ef0cfcSnicm extern PANEL_EXPORT(void) NCURSES_SP_NAME(_nc_update_panels)(SCREEN*);
210*c7ef0cfcSnicm #endif
211*c7ef0cfcSnicm /* *INDENT-ON* */
212*c7ef0cfcSnicm 
21381d8c4e1Snicm #endif /* NCURSES_PANEL_PRIV_H */
214