1overlay(3XCURSES) X/Open Curses Library Functions overlay(3XCURSES)
2
3
4
6 overlay, overwrite - copy overlapped windows
7
9 cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib \
10 -R /usr/xpg4/lib -lcurses [ library... ]
11
12 c89 [ flag... ] file... -lcurses [ library... ]
13
14 #include <curses.h>
15
16 int overlay(const WINDOW *srcwin, WINDOW *dstwin);
17
18
19 int overwrite(const WINDOW *srcwin, WINDOW *dstwin);
20
21
23 srcwin Is a pointer to the source window to be copied.
24
25
26 dstwin Is a pointer to the destination window to be overlayed or
27 overwritten.
28
29
31 The overwrite() and overlay() functions overlay srcwin on top of dest‐
32 win. The srcwin and dstwin arguments do not have to be the same size;
33 only text where the two windows overlap is copied.
34
35
36 The overwrite() function copies characters as though a sequence of
37 win_wch(3XCURSES) and wadd_wch(3XCURSES) were performed with the desti‐
38 nation window's attributes and background attributes cleared.
39
40
41 The overlay() function does the same thing, except that, whenever a
42 character to be copied is the background character of the source win‐
43 dow, overlay() does not copy the character but merely moves the desti‐
44 nation cursor the width of the source background character.
45
46
47 If any portion of the overlaying window border is not the first column
48 of a multi-column character, then all the column positions will be
49 replaced with the background character and rendition before the overlay
50 is done. If the default background character is a multi-column charac‐
51 ter when this occurs, then these functions fail.
52
54 Upon successful completion, these functions return OK. Otherwise, they
55 return ERR.
56
58 No errors are defined.
59
61 Example 1 Implement a pop-up dialog
62
63
64 The following example demonstrates the use of overwrite() to implement
65 a pop-up dialog box.
66
67
68 #include <curses.h>
69 /*
70 * Pop-up a window on top of curscr. If row and/or col
71 * are -1 then that dimension will be centered within
72 * curscr. Return 0 for success or -1 if malloc() failed.
73 * Pass back the working window and the saved window for the
74 * pop-up. The saved window should not be modified.
75 */
76 int
77 popup(work, save, nrows, ncols, row, col)
78 WINDOW **work, **save;
79 int nrows, ncols, row, col;
80 {
81 int mr, mc;
82 getmaxyx(curscr, mr, mc);
83 /* Windows are limited to the size of curscr. */
84 if (mr < nrows)
85 nrows = mr;
86 if (mc < ncols)
87 ncols = mc;
88 /* Center dimensions. */
89 if (row == -1)
90 row = (mr-nrows)/2;
91 if (col == -1)
92 col = (mc-ncols)/2;
93 /* The window must fit entirely in curscr. */
94 if (mr < row+nrows)
95 row = 0;
96 if (mc < col+ncols)
97 col = 0;
98 *work = newwin(nrows, ncols, row, col);
99 if (*work == NULL)
100 return (-1);
101 if ((*save = dupwin(*work)) == NULL) {
102 delwin(*work);
103 return (-1);
104 }
105 overwrite(curscr, *save);
106 return (0);
107 }
108 /*
109 * Restore the region covered by a pop-up window.
110 * Delete the working window and the saved window.
111 * This function is the complement to popup(). Return
112 * 0 for success or -1 for an error.
113 */
114 int
115 popdown(work, save)
116 WINDOW *work, *save;
117 {
118 (void) wnoutrefresh(save);
119 (void) delwin(save);
120 (void) delwin(work);
121 return (0);
122 }
123 /*
124 * Compute the size of a dialog box that would fit around
125 * the string.
126 */
127 void
128 dialsize(str, nrows, ncols)
129 char *str;
130 int *nrows, *ncols;
131 {
132 int rows, cols, col;
133 for (rows = 1, cols = col = 0; *str != '\0'; ++str) {
134 if (*str == '\n') {
135 if (cols < col)
136 cols = col;
137 col = 0;
138 ++rows;
139 } else {
140 ++col;
141 }
142 }
143 if (cols < col)
144 cols = col;
145 *nrows = rows;
146 *ncols = cols;
147 }
148 /*
149 * Write a string into a dialog box.
150 */
151 void
152 dialfill(w, s)
153 WINDOW *w;
154 char *s;
155 {
156 int row;
157 (void) wmove(w, 1, 1);
158 for (row = 1; *s != '\0'; ++s) {
159 (void) waddch(w, *((unsigned char*) s));
160 if (*s == '\n')
161 wmove(w, ++row, 1);
162 }
163 box(w, 0, 0);
164 }
165 void
166 dialog(str)
167 char *str;
168 {
169 WINDOW *work, *save;
170 int nrows, ncols, row, col;
171 /* Figure out size of window. */
172 dialsize(str, &nrows, &ncols);
173 /* Create a centered working window with extra */
174 /* room for a border. */
175 (void) popup(&work, &save, nrows+2, ncols+2, -1, -1);
176 /* Write text into the working window. */
177 dialfill(work, str);
178 /* Pause. Remember that wgetch() will do a wrefresh() */
179 /* for us. */
180 (void) wgetch(work);
181 /* Restore curscr and free windows. */
182 (void) popdown(work, save);
183 /* Redraw curscr to remove window from physical screen. */
184 (void) doupdate();
185 }
186
187
189 See attributes(5) for descriptions of the following attributes:
190
191
192
193
194 ┌─────────────────────────────┬─────────────────────────────┐
195 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
196 ├─────────────────────────────┼─────────────────────────────┤
197 │Interface Stability │Standard │
198 ├─────────────────────────────┼─────────────────────────────┤
199 │MT-Level │Unsafe │
200 └─────────────────────────────┴─────────────────────────────┘
201
203 copywin(3XCURSES), libcurses(3XCURSES), wadd_wch(3XCURSES),
204 win_wch(3XCURSES), attributes(5), standards(5)
205
206
207
208SunOS 5.11 5 Jun 2002 overlay(3XCURSES)