4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
46 #include <sys/types.h>
47 #include "curses_inc.h"
52 * SS: calling makenew to allocate a new window is wastefull, since
53 * makenew initializes all the variables, and then we re-initialize
54 * the desired values to these variables.
61 int i
, ncolumns
= win
->_maxx
, nlines
= win
->_maxy
;
62 size_t line_size
= nlines
* sizeof (short);
63 chtype
**wincp
, **newcp
;
64 int ncolsav
= ncolumns
;
66 /* allocate storage for new window and do block copy of */
67 /* old one into new */
69 if ((new = (WINDOW
*) malloc(sizeof (WINDOW
))) == NULL
)
72 (void) memcpy(new, win
, sizeof (WINDOW
));
74 /* allocate storage for "malloced" fields of the new window */
76 if ((new->_firstch
= (short *)malloc((unsigned)2 * line_size
)) == NULL
)
79 win
->_lastch
= win
->_firstch
+ nlines
;
81 if ((new->_y
= (chtype
**) malloc(nlines
* sizeof (chtype
*))) ==
84 * We put the free's here rather than after the image call, this
85 * is because _image free's all the rest of the malloc'ed areas.
87 free((char *)new->_firstch
);
93 if (_image(new) == ERR
) {
95 curs_errno
= CURS_BAD_MALLOC
;
97 strcpy(curs_parm_err
, "dupwin");
100 return ((WINDOW
*) NULL
);
103 /* copy information from "malloced" areas of the old window into new */
107 for (i
= 0; i
< nlines
; ++i
, ++wincp
, ++newcp
) {
108 chtype
*ws
, *we
, *ns
, *ne
, wc
;
112 we
= ws
+ ncolsav
- 1;
113 /* skip partial characters */
114 for (; ws
<= we
; ++ws
)
117 for (; we
>= ws
; --we
)
122 n
= _curs_scrwidth
[TYPE(wc
)];
123 if ((we
+ n
) <= (*wincp
+ ncolsav
))
125 ns
= *newcp
+ (ws
- *wincp
);
126 ne
= *newcp
+ (we
- *wincp
);
127 (void) memcpy((char *)ns
, (char *)ws
,
128 (ne
-ns
)*sizeof (chtype
));
130 ns
= ne
= *newcp
+ ncolsav
;
131 /* fill the rest with background chars */
133 for (ws
= *newcp
; ws
< ns
; ++ws
)
135 for (ws
= *newcp
+ncolsav
-1; ws
>= ne
; --ws
)
139 (void) memcpy((char *)new->_firstch
, (char *)win
->_firstch
,
142 new->_flags
|= _WINCHANGED
;
145 * Just like we don't create this window as a subwin if the one
146 * sent is, we don't create a padwin. Besides, if the user
147 * calls p*refresh a padwin will be created then.
149 new->_padwin
= new->_parent
= (WINDOW
*) NULL
;
150 new->_pary
= new->_parx
= -1;
152 new->_index
= win
->_index
;
153 new->_nbyte
= win
->_nbyte
;
154 new->_insmode
= win
->_insmode
;
155 (void) memcpy((char *)new->_waitc
, (char *)win
->_waitc
,
156 _csmax
* sizeof (char));