1 /* $NetBSD: insdelln.c,v 1.16 2009/07/22 16:57:15 roy Exp $ */
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
34 __RCSID("$NetBSD: insdelln.c,v 1.16 2009/07/22 16:57:15 roy Exp $");
38 * Based on deleteln.c and insertln.c -
39 * Copyright (c) 1981, 1993, 1994
40 * The Regents of the University of California. All rights reserved.
47 #include "curses_private.h"
49 #ifndef _CURSES_USE_MACROS
53 * Insert or delete lines on stdscr, leaving (cury, curx) unchanged.
58 return winsdelln(stdscr
, nlines
);
65 * Insert or delete lines on the window, leaving (cury, curx) unchanged.
68 winsdelln(WINDOW
*win
, int nlines
)
74 #endif /* HAVE_WCHAR */
78 __CTRACE(__CTRACE_LINE
,
79 "winsdelln: (%p) cury=%d lines=%d\n", win
, win
->cury
, nlines
);
85 if (__using_color
&& win
!= curscr
)
86 attr
= win
->battr
& __COLOR
;
92 if (win
->cury
< win
->scr_t
|| win
->cury
> win
->scr_b
) {
93 /* Outside scrolling region */
94 if (nlines
> win
->maxy
- win
->cury
)
95 nlines
= win
->maxy
- win
->cury
;
98 /* Inside scrolling region */
99 if (nlines
> win
->scr_b
+ 1 - win
->cury
)
100 nlines
= win
->scr_b
+ 1 - win
->cury
;
103 for (y
= last
- nlines
; y
>= win
->cury
; --y
) {
104 win
->alines
[y
]->flags
&= ~__ISPASTEOL
;
105 win
->alines
[y
+ nlines
]->flags
&= ~__ISPASTEOL
;
106 if (win
->orig
== NULL
) {
107 temp
= win
->alines
[y
+ nlines
];
108 win
->alines
[y
+ nlines
] = win
->alines
[y
];
109 win
->alines
[y
] = temp
;
111 (void) memcpy(win
->alines
[y
+ nlines
]->line
,
112 win
->alines
[y
]->line
,
113 (size_t) win
->maxx
* __LDATASIZE
);
116 for (y
= win
->cury
- 1 + nlines
; y
>= win
->cury
; --y
)
117 for (i
= 0; i
< win
->maxx
; i
++) {
118 win
->alines
[y
]->line
[i
].ch
= win
->bch
;
119 win
->alines
[y
]->line
[i
].attr
= attr
;
121 win
->alines
[y
]->line
[i
].ch
= win
->bch
;
123 win
->alines
[y
]->line
[i
].ch
124 = ( wchar_t )btowc(( int ) win
->bch
);
125 lp
= &win
->alines
[y
]->line
[i
];
126 if (_cursesi_copy_nsp(win
->bnsp
, lp
) == ERR
)
129 #endif /* HAVE_WCHAR */
131 for (y
= last
; y
>= win
->cury
; --y
)
132 __touchline(win
, y
, 0, (int) win
->maxx
- 1);
136 if (win
->cury
< win
->scr_t
|| win
->cury
> win
->scr_b
) {
137 /* Outside scrolling region */
138 if (nlines
> win
->maxy
- win
->cury
)
139 nlines
= win
->maxy
- win
->cury
;
142 /* Inside scrolling region */
143 if (nlines
> win
->scr_b
+ 1 - win
->cury
)
144 nlines
= win
->scr_b
+ 1 - win
->cury
;
145 last
= win
->scr_b
+ 1;
147 for (y
= win
->cury
; y
< last
- nlines
; y
++) {
148 win
->alines
[y
]->flags
&= ~__ISPASTEOL
;
149 win
->alines
[y
+ nlines
]->flags
&= ~__ISPASTEOL
;
150 if (win
->orig
== NULL
) {
151 temp
= win
->alines
[y
];
152 win
->alines
[y
] = win
->alines
[y
+ nlines
];
153 win
->alines
[y
+ nlines
] = temp
;
155 (void) memcpy(win
->alines
[y
]->line
,
156 win
->alines
[y
+ nlines
]->line
,
157 (size_t) win
->maxx
* __LDATASIZE
);
160 for (y
= last
- nlines
; y
< last
; y
++)
161 for (i
= 0; i
< win
->maxx
; i
++) {
162 win
->alines
[y
]->line
[i
].ch
= win
->bch
;
163 win
->alines
[y
]->line
[i
].attr
= attr
;
165 win
->alines
[y
]->line
[i
].ch
= win
->bch
;
167 win
->alines
[y
]->line
[i
].ch
168 = (wchar_t)btowc((int) win
->bch
);
169 lp
= &win
->alines
[y
]->line
[i
];
171 if (_cursesi_copy_nsp(win
->bnsp
, lp
) == ERR
)
173 #endif /* HAVE_WCHAR */
175 for (y
= win
->cury
; y
< last
; y
++)
176 __touchline(win
, y
, 0, (int) win
->maxx
- 1);
178 if (win
->orig
!= NULL
)
179 __id_subwins(win
->orig
);