blob: 75426e2728e6287fda14f5c426dd2dd1e6623331 [file] [log] [blame]
Patrick Georgi3b77b722011-07-07 15:41:53 +02001/* Public Domain Curses */
2
3#include <curspriv.h>
4
5RCSID("$Id: clear.c,v 1.35 2008/07/13 16:08:18 wmcbrine Exp $")
6
7/*man-start**************************************************************
8
9 Name: clear
10
11 Synopsis:
12 int clear(void);
13 int wclear(WINDOW *win);
14 int erase(void);
15 int werase(WINDOW *win);
16 int clrtobot(void);
17 int wclrtobot(WINDOW *win);
18 int clrtoeol(void);
19 int wclrtoeol(WINDOW *win);
20
21 Description:
Stefan Reinauere11835e2011-10-31 12:54:00 -070022 erase() and werase() copy blanks (i.e. the background chtype) to
Patrick Georgi3b77b722011-07-07 15:41:53 +020023 every cell of the window.
24
25 clear() and wclear() are similar to erase() and werase(), but
Stefan Reinauere11835e2011-10-31 12:54:00 -070026 they also call clearok() to ensure that the the window is
Patrick Georgi3b77b722011-07-07 15:41:53 +020027 cleared on the next wrefresh().
28
Stefan Reinauere11835e2011-10-31 12:54:00 -070029 clrtobot() and wclrtobot() clear the window from the current
Patrick Georgi3b77b722011-07-07 15:41:53 +020030 cursor position to the end of the window.
31
32 clrtoeol() and wclrtoeol() clear the window from the current
33 cursor position to the end of the current line.
34
35 Return Value:
36 All functions return OK on success and ERR on error.
37
38 Portability X/Open BSD SYS V
39 clear Y Y Y
40 wclear Y Y Y
41 erase Y Y Y
42 werase Y Y Y
43 clrtobot Y Y Y
44 wclrtobot Y Y Y
45 clrtoeol Y Y Y
46 wclrtoeol Y Y Y
47
48**man-end****************************************************************/
49
50int wclrtoeol(WINDOW *win)
51{
52 int x, y, minx;
53 chtype blank, *ptr;
54
55 PDC_LOG(("wclrtoeol() - called: Row: %d Col: %d\n",
56 win->_cury, win->_curx));
57
58 if (!win)
59 return ERR;
60
61 y = win->_cury;
62 x = win->_curx;
63
64 /* wrs (4/10/93) account for window background */
65
66 blank = win->_bkgd;
67
68 for (minx = x, ptr = &win->_y[y][x]; minx < win->_maxx; minx++, ptr++)
69 *ptr = blank;
70
71 if (x < win->_firstch[y] || win->_firstch[y] == _NO_CHANGE)
72 win->_firstch[y] = x;
73
74 win->_lastch[y] = win->_maxx - 1;
75
76 PDC_sync(win);
77 return OK;
78}
79
80int clrtoeol(void)
81{
82 PDC_LOG(("clrtoeol() - called\n"));
83
84 return wclrtoeol(stdscr);
85}
86
87int wclrtobot(WINDOW *win)
88{
Patrick Georgi3b77b722011-07-07 15:41:53 +020089 PDC_LOG(("wclrtobot() - called\n"));
90
91 if (!win)
92 return ERR;
93
Patrick Georgi8180d1a2014-12-29 19:57:14 +010094 int savey = win->_cury;
95 int savex = win->_curx;
96
Patrick Georgi3b77b722011-07-07 15:41:53 +020097 /* should this involve scrolling region somehow ? */
98
99 if (win->_cury + 1 < win->_maxy)
100 {
101 win->_curx = 0;
102 win->_cury++;
103 for (; win->_maxy > win->_cury; win->_cury++)
104 wclrtoeol(win);
105 win->_cury = savey;
106 win->_curx = savex;
107 }
108 wclrtoeol(win);
109
110 PDC_sync(win);
111 return OK;
112}
113
114int clrtobot(void)
115{
116 PDC_LOG(("clrtobot() - called\n"));
117
118 return wclrtobot(stdscr);
119}
120
121int werase(WINDOW *win)
122{
123 PDC_LOG(("werase() - called\n"));
124
125 if (wmove(win, 0, 0) == ERR)
126 return ERR;
127
128 return wclrtobot(win);
129}
130
131int erase(void)
132{
133 PDC_LOG(("erase() - called\n"));
134
135 return werase(stdscr);
136}
137
138int wclear(WINDOW *win)
139{
140 PDC_LOG(("wclear() - called\n"));
141
142 if (!win)
143 return ERR;
144
145 win->_clear = TRUE;
146 return werase(win);
147}
148
149int clear(void)
150{
151 PDC_LOG(("clear() - called\n"));
152
153 return wclear(stdscr);
154}