xref: /freebsd/contrib/ncurses/panel/panel.c (revision f7c32ed617858bcd22f8d1b03199099d50125721)
1 /****************************************************************************
2  * Copyright 2020 Thomas E. Dickey                                          *
3  * Copyright 1998-2010,2012 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 /****************************************************************************
31  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1995                    *
32  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
33  *     and: Juergen Pfeifer                         1996-1999,2008          *
34  *     and: Thomas E. Dickey                                                *
35  ****************************************************************************/
36 
37 /* panel.c -- implementation of panels library, some core routines */
38 #include "panel.priv.h"
39 
40 MODULE_ID("$Id: panel.c,v 1.30 2020/09/26 18:05:17 tom Exp $")
41 
42 /*+-------------------------------------------------------------------------
43 	_nc_retrace_panel (pan)
44 --------------------------------------------------------------------------*/
45 #ifdef TRACE
46 PANEL_EXPORT(PANEL *)
47 _nc_retrace_panel(PANEL * pan)
48 {
49   T((T_RETURN("%p"), (void *)pan));
50   return pan;
51 }
52 #endif
53 
54 /*+-------------------------------------------------------------------------
55 	_nc_my_visbuf(ptr)
56 --------------------------------------------------------------------------*/
57 #ifdef TRACE
58 #ifndef TRACE_TXT
59 PANEL_EXPORT(const char *)
60 _nc_my_visbuf(const void *ptr, int n)
61 {
62   char temp[32];
63 
64   if (ptr != 0)
65     _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp)) "%p", ptr);
66   else
67     _nc_STRCPY(temp, "<null>", sizeof(temp));
68   return _nc_visbuf2(n, temp);
69 }
70 #endif
71 #endif
72 
73 /*+-------------------------------------------------------------------------
74 	dPanel(text,pan)
75 --------------------------------------------------------------------------*/
76 #ifdef TRACE
77 PANEL_EXPORT(void)
78 _nc_dPanel(const char *text, const PANEL * pan)
79 {
80   _tracef("%s id=%s b=%s a=%s y=%d x=%d",
81 	  text, USER_PTR(pan->user, 1),
82 	  (pan->below) ? USER_PTR(pan->below->user, 2) : "--",
83 	  (pan->above) ? USER_PTR(pan->above->user, 3) : "--",
84 	  PSTARTY(pan), PSTARTX(pan));
85 }
86 #endif
87 
88 /*+-------------------------------------------------------------------------
89 	dStack(fmt,num,pan)
90 --------------------------------------------------------------------------*/
91 #ifdef TRACE
92 PANEL_EXPORT(void)
93 _nc_dStack(const char *fmt, int num, const PANEL * pan)
94 {
95   char s80[80];
96 
97   GetPanelHook(pan);
98 
99   _nc_SPRINTF(s80, _nc_SLIMIT(sizeof(s80)) fmt, num, pan);
100   _tracef("%s b=%s t=%s", s80,
101 	  (_nc_bottom_panel) ? USER_PTR(_nc_bottom_panel->user, 1) : "--",
102 	  (_nc_top_panel) ? USER_PTR(_nc_top_panel->user, 2) : "--");
103   if (pan)
104     _tracef("pan id=%s", USER_PTR(pan->user, 1));
105   pan = _nc_bottom_panel;
106   while (pan)
107     {
108       dPanel("stk", pan);
109       pan = pan->above;
110     }
111 }
112 #endif
113 
114 /*+-------------------------------------------------------------------------
115 	Wnoutrefresh(pan) - debugging hook for wnoutrefresh
116 --------------------------------------------------------------------------*/
117 #ifdef TRACE
118 PANEL_EXPORT(void)
119 _nc_Wnoutrefresh(const PANEL * pan)
120 {
121   dPanel("wnoutrefresh", pan);
122   wnoutrefresh(pan->win);
123 }
124 #endif
125 
126 /*+-------------------------------------------------------------------------
127 	Touchpan(pan)
128 --------------------------------------------------------------------------*/
129 #ifdef TRACE
130 PANEL_EXPORT(void)
131 _nc_Touchpan(const PANEL * pan)
132 {
133   dPanel("Touchpan", pan);
134   touchwin(pan->win);
135 }
136 #endif
137 
138 /*+-------------------------------------------------------------------------
139 	Touchline(pan,start,count)
140 --------------------------------------------------------------------------*/
141 #ifdef TRACE
142 PANEL_EXPORT(void)
143 _nc_Touchline(const PANEL * pan, int start, int count)
144 {
145   char s80[80];
146 
147   _nc_SPRINTF(s80, _nc_SLIMIT(sizeof(s80)) "Touchline s=%d c=%d", start, count);
148   dPanel(s80, pan);
149   touchline(pan->win, start, count);
150 }
151 #endif
152 
153 #ifndef TRACE
154 #  ifndef __GNUC__
155      /* Some C compilers need something defined in a source file */
156 extern void _nc_dummy_panel(void);
157 void
158 _nc_dummy_panel(void)
159 {
160 }
161 #  endif
162 #endif
163