blob: d3d55c751444f4374467463a135250ddbee449e3 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301.\"***************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002.\" Copyright 2020-2023,2024 Thomas E. Dickey *
3.\" Copyright 1998-2015,2016 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304.\" *
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.\"
micky3879b9f5e72025-07-08 18:04:53 -040030.\" $Id: curs_window.3x,v 1.48 2024/04/20 21:20:07 tom Exp $
31.TH curs_window 3X 2024-04-20 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "Library calls"
32.de bP
33.ie n .IP \(bu 4
34.el .IP \(bu 2
35..
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053036.SH NAME
micky3879b9f5e72025-07-08 18:04:53 -040037\fB\%newwin\fP,
38\fB\%delwin\fP,
39\fB\%mvwin\fP,
40\fB\%subwin\fP,
41\fB\%derwin\fP,
42\fB\%mvderwin\fP,
43\fB\%dupwin\fP,
44\fB\%wsyncup\fP,
45\fB\%syncok\fP,
46\fB\%wcursyncup\fP,
47\fB\%wsyncdown\fP \-
48create and manipulate \fIcurses\fR windows
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053049.SH SYNOPSIS
micky3879b9f5e72025-07-08 18:04:53 -040050.nf
51\fB#include <curses.h>
52.PP
53\fBWINDOW *newwin(
54 \fBint \fInlines\fB, int \fIncols\fB,\fR
55 \fBint \fIbegin_y\fB, int \fIbegin_x\fB);\fR
56\fBint delwin(WINDOW *\fIwin\fB);\fR
57\fBint mvwin(WINDOW *\fIwin\fB, int \fIy\fB, int \fIx\fB);\fR
58\fBWINDOW *subwin(WINDOW *\fIorig\fB,\fR
59 \fBint \fInlines\fB, int \fIncols\fB,\fR
60 \fBint \fIbegin_y\fB, int \fIbegin_x\fB);\fR
61\fBWINDOW *derwin(WINDOW *\fIorig\fB,\fR
62 \fBint \fInlines\fB, int \fIncols\fB,\fR
63 \fBint \fIbegin_y\fB, int \fIbegin_x\fB);\fR
64\fBint mvderwin(WINDOW *\fIwin\fB, int \fIpar_y\fB, int \fIpar_x\fB);\fR
65\fBWINDOW *dupwin(WINDOW *\fIwin\fB);\fR
66\fBvoid wsyncup(WINDOW *\fIwin\fB);\fR
67\fBint syncok(WINDOW *\fIwin\fB, bool \fIbf\fB);\fR
68\fBvoid wcursyncup(WINDOW *\fIwin\fB);\fR
69\fBvoid wsyncdown(WINDOW *\fIwin\fB);\fR
70.fi
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053071.SH DESCRIPTION
Steve Kondikae271bc2015-11-15 02:50:53 +010072.SS newwin
micky3879b9f5e72025-07-08 18:04:53 -040073Calling \fBnewwin\fP creates and returns a pointer to a new window with the
Steve Kondikae271bc2015-11-15 02:50:53 +010074given number of lines and columns.
75The upper left-hand corner of the window is
76at
77.RS
micky3879b9f5e72025-07-08 18:04:53 -040078line \fIbegin\fR_\fIy\fP,
Steve Kondikae271bc2015-11-15 02:50:53 +010079.br
micky3879b9f5e72025-07-08 18:04:53 -040080column \fIbegin\fR_\fIx\fP
Steve Kondikae271bc2015-11-15 02:50:53 +010081.RE
82.PP
83If either
micky3879b9f5e72025-07-08 18:04:53 -040084\fInlines\fP or \fIncols\fP is zero, they default to
Steve Kondikae271bc2015-11-15 02:50:53 +010085.RS
micky3879b9f5e72025-07-08 18:04:53 -040086\fBLINES \-\fP \fIbegin\fR_\fIy\fP and
Steve Kondikae271bc2015-11-15 02:50:53 +010087.br
micky3879b9f5e72025-07-08 18:04:53 -040088\fBCOLS \-\fP \fIbegin\fR_\fIx\fP.
Steve Kondikae271bc2015-11-15 02:50:53 +010089.RE
90.PP
micky3879b9f5e72025-07-08 18:04:53 -040091A new full-screen window is created by calling \fBnewwin(0,0,0,0)\fP.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053092.PP
micky3879b9f5e72025-07-08 18:04:53 -040093Regardless of the function used for creating a new window
94(e.g., \fBnewwin\fP, \fBsubwin\fP, \fBderwin\fP, \fBnewpad\fP),
95rather than a duplicate (with \fBdupwin\fP),
96all of the window modes are initialized to the default values.
97These functions set window modes after a window is created:
98.RS
99.PP
100\fB\%idcok\fP
101\fB\%idlok\fP
102\fB\%immedok\fP
103\fB\%keypad\fP
104\fB\%leaveok\fP
105\fB\%nodelay\fP
106\fB\%scrollok\fP
107\fB\%setscrreg\fP
108\fB\%syncok\fP
109\fB\%wbkgdset\fP
110\fB\%wbkgrndset\fP and
111\fB\%wtimeout\fP.
112.RE
113.SS delwin
114Calling \fBdelwin\fP deletes the named window, freeing all memory
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530115associated with it (it does not actually erase the window's screen
Steve Kondikae271bc2015-11-15 02:50:53 +0100116image).
117Subwindows must be deleted before the main window can be deleted.
118.SS mvwin
micky3879b9f5e72025-07-08 18:04:53 -0400119Calling \fBmvwin\fP moves the window so that the upper left-hand
120corner is at position (\fIx\fP, \fIy\fP).
Steve Kondikae271bc2015-11-15 02:50:53 +0100121If the move would cause the window to be off the screen,
122it is an error and the window is not moved.
123Moving subwindows is allowed, but should be avoided.
124.SS subwin
micky3879b9f5e72025-07-08 18:04:53 -0400125Calling \fBsubwin\fP creates and returns a pointer to a new window
126with the given number of lines, \fInlines\fP, and columns, \fIncols\fP.
127The window is at position (\fIbegin\fR_\fIy\fP,
128\fIbegin\fR_\fIx\fP) on the screen.
129The subwindow shares memory with the window \fIorig\fP,
130its \fIancestor\fP,
Steve Kondikae271bc2015-11-15 02:50:53 +0100131so that changes made to one window
132will affect both windows.
133When using this routine, it is necessary to call
micky3879b9f5e72025-07-08 18:04:53 -0400134\fBtouchwin\fP or \fBtouchline\fP on \fIorig\fP before calling
135\fBwrefresh\fP on the subwindow.
Steve Kondikae271bc2015-11-15 02:50:53 +0100136.SS derwin
micky3879b9f5e72025-07-08 18:04:53 -0400137Calling \fBderwin\fP is the same as calling \fBsubwin,\fP except that
138\fIbegin\fR_\fIy\fP and \fIbegin\fR_\fIx\fP are relative to the origin
139of the window \fIorig\fP rather than the screen.
Steve Kondikae271bc2015-11-15 02:50:53 +0100140There is no difference between the subwindows and the derived windows.
micky3879b9f5e72025-07-08 18:04:53 -0400141.SS mvderwin
142Calling \fBmvderwin\fP moves a derived window (or subwindow)
Steve Kondikae271bc2015-11-15 02:50:53 +0100143inside its parent window.
144The screen-relative parameters of the window are not changed.
145This routine is used to display different
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530146parts of the parent window at the same physical position on the
147screen.
Steve Kondikae271bc2015-11-15 02:50:53 +0100148.SS dupwin
micky3879b9f5e72025-07-08 18:04:53 -0400149Calling \fBdupwin\fP creates an exact duplicate of the window \fIwin\fP.
Steve Kondikae271bc2015-11-15 02:50:53 +0100150.SS wsyncup
micky3879b9f5e72025-07-08 18:04:53 -0400151Calling \fBwsyncup\fP touches all locations in ancestors of \fIwin\fP that are
152changed in \fIwin\fP.
153If \fBsyncok\fP is called with second argument
154\fBTRUE\fP then \fBwsyncup\fP is called automatically whenever there is a
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530155change in the window.
Steve Kondikae271bc2015-11-15 02:50:53 +0100156.SS wsyncdown
micky3879b9f5e72025-07-08 18:04:53 -0400157The \fBwsyncdown\fP routine touches each location in \fIwin\fP that has been
Steve Kondikae271bc2015-11-15 02:50:53 +0100158touched in any of its ancestor windows.
159This routine is called by
micky3879b9f5e72025-07-08 18:04:53 -0400160\fBwrefresh\fP, so it should almost never be necessary to call it manually.
Steve Kondikae271bc2015-11-15 02:50:53 +0100161.SS wcursyncup
micky3879b9f5e72025-07-08 18:04:53 -0400162The routine \fBwcursyncup\fP updates the current cursor position of all the
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530163ancestors of the window to reflect the current cursor position of the
164window.
165.SH RETURN VALUE
micky3879b9f5e72025-07-08 18:04:53 -0400166Routines that return an integer return the integer \fBERR\fP upon failure and
167\fBOK\fP (SVr4 only specifies "an integer value other than \fBERR\fP") upon
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530168successful completion.
169.PP
micky3879b9f5e72025-07-08 18:04:53 -0400170Routines that return pointers return \fBNULL\fP on error.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530171.PP
172X/Open defines no error conditions.
173In this implementation
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530174.TP 5
micky3879b9f5e72025-07-08 18:04:53 -0400175\fBdelwin\fP
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530176returns an error if the window pointer is null, or
177if the window is the parent of another window.
Steve Kondikae271bc2015-11-15 02:50:53 +0100178.TP 5
179\fBderwin\fP
180returns an error if the parent window pointer is null, or
181if any of its ordinates or dimensions is negative, or
182if the resulting window does not fit inside the parent window.
183.TP 5
184\fBdupwin\fP
185returns an error if the window pointer is null.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530186.IP
187This implementation also maintains a list of windows,
188and checks that the pointer passed to \fBdelwin\fP is one that
189it created, returning an error if it was not..
190.TP 5
191\fBmvderwin\fP
192returns an error
193if the window pointer is null, or
194if some part of the window would be placed off-screen.
195.TP 5
196\fBmvwin\fP
197returns an error
198if the window pointer is null, or
199if the window is really a pad, or
200if some part of the window would be placed off-screen.
201.TP 5
Steve Kondikae271bc2015-11-15 02:50:53 +0100202\fBnewwin\fP
203will fail if either of its beginning ordinates is negative, or
204if either the number of lines or columns is negative.
205.TP 5
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530206\fBsyncok\fP
207returns an error
208if the window pointer is null.
Steve Kondikae271bc2015-11-15 02:50:53 +0100209.TP 5
210\fBsubwin\fP
211returns an error if the parent window pointer is null, or
212if any of its ordinates or dimensions is negative, or
213if the resulting window does not fit inside the parent window.
214.PP
215The functions which return a window pointer
216may also fail if there is insufficient memory for its data structures.
217Any of these functions will fail if the screen has not been initialized,
218i.e., with \fBinitscr\fP or \fBnewterm\fP.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530219.SH NOTES
micky3879b9f5e72025-07-08 18:04:53 -0400220If many small changes are made to the window, the \fBwsyncup\fP option could
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530221degrade performance.
222.PP
micky3879b9f5e72025-07-08 18:04:53 -0400223Note that \fBsyncok\fP may be a macro.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530224.SH PORTABILITY
micky3879b9f5e72025-07-08 18:04:53 -0400225X/Open Curses, Issue 4 describes these functions.
226.PP
227X/Open Curses states regarding \fBdelwin\fP:
228.bP
229It must delete subwindows before deleting their parent.
230.bP
231If \fBdelwin\fP is asked to delete a parent window,
232it can only succeed if the curses library keeps a list of the subwindows.
233SVr4 curses kept a count of the number of subwindows rather than a list.
234It simply returned \fBERR\fP when asked to delete a subwindow.
235Solaris X/Open curses does not even make that check,
236and will delete a parent window which still has subwindows.
237.bP
238Since release 4.0 (1996),
239\fI\%ncurses\fP maintains a list of windows for each screen,
240to ensure that a window has no subwindows before allowing deletion.
241.bP
242NetBSD copied this feature of \fI\%ncurses\fP in 2003.
243.br
244PDCurses follows the scheme used in Solaris X/Open curses.
245.SH BUGS
246The subwindow functions
247\fB\%subwin\fP,
248\fB\%derwin\fP,
249\fB\%mvderwin\fP,
250\fB\%wsyncup\fP,
251\fB\%wsyncdown\fP,
252\fB\%wcursyncup\fP,
253and
254\fB\%syncok\fP
255are flaky,
256incompletely implemented,
257and not well tested.
258.PP
259System\ V's \fIcurses\fP documentation is unclear about what
260\fB\%wsyncup\fP and \fB\%wsyncdown\fP actually do.
261It seems to imply that they are supposed to touch only those lines that
262are affected by changes to a window's ancestors.
263The language here,
264and behavior of \fI\%ncurses\fP,
265is patterned on the X/Open Curses standard;
266this approach may result in slower updates.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530267.SH SEE ALSO
micky3879b9f5e72025-07-08 18:04:53 -0400268\fB\%curses\fP(3X),
269\fB\%curs_initscr\fP(3X),
270\fB\%curs_refresh\fP(3X),
271\fB\%curs_touch\fP(3X),
272\fB\%curs_variables\fP(3X)