1/****************************************************************************
2 * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc.              *
3 *                                                                          *
4 * Permission is hereby granted, free of charge, to any person obtaining a  *
5 * copy of this software and associated documentation files (the            *
6 * "Software"), to deal in the Software without restriction, including      *
7 * without limitation the rights to use, copy, modify, merge, publish,      *
8 * distribute, distribute with modifications, sublicense, and/or sell       *
9 * copies of the Software, and to permit persons to whom the Software is    *
10 * furnished to do so, subject to the following conditions:                 *
11 *                                                                          *
12 * The above copyright notice and this permission notice shall be included  *
13 * in all copies or substantial portions of the Software.                   *
14 *                                                                          *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22 *                                                                          *
23 * Except as contained in this notice, the name(s) of the above copyright   *
24 * holders shall not be used in advertising or otherwise to promote the     *
25 * sale, use or other dealings in this Software without prior written       *
26 * authorization.                                                           *
27 ****************************************************************************/
28/*
29 * Test lower-right-hand corner access
30 *
31 * originally by Eric S. Raymond <esr@thyrsus.com>, written for animation
32 * and resizing -T.Dickey
33 *
34 * This can't be part of the ncurses test-program, because ncurses rips off the
35 * bottom line to do labels.
36 *
37 * $Id: lrtest.c,v 1.21 2005/12/31 16:51:53 tom Exp $
38 */
39
40#include <test.priv.h>
41
42typedef struct {
43    int y, x, mode, dir, inc;
44    chtype value;
45} MARK;
46
47/*
48 * Make a couple of markers go 'round the border to demonstrate that we can
49 * really write to all positions properly.
50 */
51static void
52show(MARK *m)
53{
54    mvaddch(m->y, m->x, m->value);
55    if (m->mode == 0) {		/* along the x-direction */
56	m->x += m->inc;
57	if (m->x >= COLS) {
58	    m->x = COLS - 1;
59	    m->inc = -m->dir * m->inc;
60	    m->y += m->inc;
61	    m->mode = 1;
62	} else if (m->x < 0) {
63	    m->x = 0;
64	    m->inc = -m->dir * m->inc;
65	    m->y += m->inc;
66	    m->mode = 1;
67	}
68    } else {			/* along the y-direction */
69	m->y += m->inc;
70	if (m->y >= LINES) {
71	    m->y = LINES - 1;
72	    m->inc = m->dir * m->inc;
73	    m->x += m->inc;
74	    m->mode = 0;
75	} else if (m->y < 0) {
76	    m->y = 0;
77	    m->inc = m->dir * m->inc;
78	    m->x += m->inc;
79	    m->mode = 0;
80	}
81    }
82}
83
84int
85main(
86	int argc GCC_UNUSED,
87	char *argv[]GCC_UNUSED)
88{
89    static MARK marks[] =
90    {
91	{0, 0, 0, -1, 1, '+' | A_BOLD},
92	{0, 0, 1, 1, 2, 'X'},
93	{0, 0, 1, -1, 3, 'Y'},
94	{0, 8, 0, -1, 1, '+' | A_BOLD},
95	{0, 9, 0, -1, 1, '+' | A_BOLD},
96	{1, 0, 1, 1, 1, '*' | A_REVERSE},
97	{2, 0, 1, 1, 1, '*' | A_REVERSE}
98    };
99
100    setlocale(LC_ALL, "");
101
102    initscr();
103    noecho();
104    cbreak();
105    nodelay(stdscr, TRUE);
106    curs_set(0);
107
108#ifdef KEY_RESIZE
109    keypad(stdscr, TRUE);
110  restart:
111#endif
112    move(LINES / 2 - 1, 4);
113    if (!(has_ic()
114#if HAVE_SETUPTERM
115    /* see PutCharLR() */
116	  || auto_right_margin
117	  || (enter_am_mode && exit_am_mode)
118#endif
119	)) {
120	addstr("Your terminal lacks the capabilities needed to address the\n");
121	move(LINES / 2, 4);
122	addstr("lower-right-hand corner of the screen.\n");
123    } else {
124	addstr("This is a test of access to the lower right corner.\n");
125	move(LINES / 2, 4);
126	addstr("If the top of the box is missing, the test failed.\n");
127	move(LINES / 2 + 1, 4);
128	addstr("Please report this (with a copy of your terminfo entry).\n");
129	move(LINES / 2 + 2, 4);
130	addstr("to the ncurses maintainers, at bug-ncurses@gnu.org.\n");
131    }
132
133    for (;;) {
134	int ch;
135	unsigned n;
136
137	box(stdscr, 0, 0);
138	for (n = 0; n < SIZEOF(marks); n++) {
139	    show(&marks[n]);
140	}
141
142	if ((ch = getch()) > 0) {
143	    if (ch == 'q')
144		break;
145	    else if (ch == 's')
146		nodelay(stdscr, FALSE);
147	    else if (ch == ' ')
148		nodelay(stdscr, TRUE);
149#ifdef TRACE
150	    else if (ch == 'T')
151		trace(0);
152	    else if (ch == 't')
153		trace(TRACE_CALLS | TRACE_ICALLS | TRACE_UPDATE);
154#endif
155#ifdef KEY_RESIZE
156	    else if (ch == KEY_RESIZE) {
157		for (n = 0; n < SIZEOF(marks); n++) {
158		    if (marks[n].mode == 0) {	/* moving along x-direction */
159			if (marks[n].y)
160			    marks[n].y = LINES - 1;
161		    } else {
162			if (marks[n].x)
163			    marks[n].x = COLS - 1;
164		    }
165		}
166		flash();
167		erase();
168		wrefresh(curscr);
169		goto restart;
170	    }
171#endif
172	}
173	napms(50);
174	refresh();
175    }
176
177    curs_set(1);
178    endwin();
179    ExitProgram(EXIT_SUCCESS);
180}
181
182/* lrtest.c ends here */
183