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]
22 /* Copyright (c) 1988 AT&T */
23 /* All Rights Reserved */
27 * Copyright (c) 1997, by Sun Microsystems, Inc.
28 * All rights reserved.
31 #pragma ident "%Z%%M% %I% %E% SMI"
35 #include <sys/types.h>
36 #include "curses_inc.h"
39 * Clear the space occupied by a multicolumn character
43 _mbclrch(WINDOW
*win
, int y
, int x
)
45 chtype
*wcp
, *ep
, *wp
, wc
;
47 /* ASSERT(_scrmax > 1); */
52 /* compute the bounds for the character */
54 for (; wp
>= wcp
; --wp
)
61 ep
= wp
+ _curs_scrwidth
[TYPE(wc
)];
62 if (ep
> wcp
+ win
->_maxx
)
65 /* update the change structure */
67 if ((x
= (int)(wp
- wcp
)) < win
->_firstch
[y
])
69 win
->_firstch
[y
] = (short)x
;
71 if ((x
= (int)(ep
- wcp
) - 1) > win
->_lastch
[y
])
73 win
->_lastch
[y
] = (short)x
;
75 /* clear the character */
84 * Make sure the window cursor point to a valid place.
85 * If win->_insmode or isedge, the cursor has to
86 * point to the start of a whole character; otherwise, the
87 * cursor has to point to a part of a whole character.
93 chtype
*wp
, *wcp
, *ecp
, wc
;
97 /* ASSERT(_scrmax > 1); */
100 wcp
= win
->_y
[win
->_cury
];
105 ecp
= wcp
+ win
->_maxx
;
108 /* make wp points to the start column of a mb-character */
110 for (; wp
>= wcp
; --wp
)
114 for (wp
= wcp
+ x
+ 1; wp
< ecp
; ++wp
)
123 /* make sure that wp points to a whole character */
125 if (wp
+ _curs_scrwidth
[TYPE(wc
)] > ecp
) {
126 for (wp
-= 1; wp
>= wcp
; --wp
)
134 if (isedge
|| win
->_insmode
)
136 win
->_curx
= (short)(wp
-wcp
);
143 * Add/insert multi-byte characters
147 _mbaddch(WINDOW
*win
, chtype a
, chtype c
)
149 int n
, x
, y
, nc
, m
, len
, nbyte
, ty
;
153 /* ASSERT(_mbtrue); */
155 /* decode the character into a sequence of bytes */
159 rc
[nc
++] = (char)(LBYTE(c
)|MBIT
);
162 rc
[nc
++] = (char)RBYTE(c
);
166 /* add the sequence to the image */
167 for (n
= 0; n
< nc
; ++n
) {
172 /* first byte of a multi-byte character */
173 if (ty
> 0 || win
->_nbyte
< 0) {
176 win
->_nbyte
= cswidth
[ty
] + (ty
== 0 ? 0 : 1);
181 wch
[win
->_index
] = (char)wc
;
185 /* if character is not ready to process */
186 if (win
->_index
< win
->_nbyte
)
189 /* begin processing the character */
193 len
= _curs_scrwidth
[TYPE(wc
)];
195 /* window too small or char cannot be stored */
196 if (len
> win
->_maxx
|| 2*len
< nbyte
)
199 /* if the character won't fit into the line */
200 if ((win
->_curx
+ len
) > win
->_maxx
&&
201 (win
->_insmode
|| waddch(win
, '\n') == ERR
))
206 wcp
= win
->_y
[y
] + x
;
209 /* perform the right shift */
210 if (_mbinsshift(win
, len
) == ERR
)
212 } else if (_scrmax
> 1) {
213 /* clear any multi-byte char about to be overwritten */
214 for (m
= 0; m
< len
; ++m
)
215 if (ISMBIT(wcp
[m
]) &&
216 _mbclrch(win
, y
, x
+ m
) == ERR
)
222 /* pack two bytes at a time */
223 for (m
= nbyte
/2; m
> 0; m
-= 1, wch
+= 2)
224 *wcp
++ = _CHAR((RBYTE(wch
[1]) << 8) |
225 RBYTE(wch
[0])) | CBIT
| a
;
227 /* do the remaining byte if any */
229 *wcp
++ = RBYTE(wch
[0]) | CBIT
| a
;
231 /* fill-in for remaining display columns */
232 for (m
= (nbyte
/ 2) + (nbyte
% 2); m
< len
; ++m
)
233 *wcp
++ = (CBIT
|MBIT
) | a
;
235 /* the first column has Continue BIT off */
236 win
->_y
[y
][x
] &= ~CBIT
;
238 if (win
->_insmode
== FALSE
) {
239 if (x
< win
->_firstch
[y
])
241 win
->_firstch
[y
] = (short)x
;
242 if ((x
+= len
-1) >= win
->_maxx
)
244 if (x
> win
->_lastch
[y
])
246 win
->_lastch
[y
] = (short)x
;
248 if ((win
->_curx
+= len
) >= win
->_maxx
) {
249 if (y
>= (win
->_maxy
-1) || y
== win
->_bmarg
) {
250 win
->_curx
= win
->_maxx
-1;
251 if (wscrl(win
, 1) == ERR
)