+overlap_helpitem(int state, int item, char *message)
+{
+ int row = (item / 2);
+ int col = ((item % 2) ? COLS / 2 : 0);
+
+ move(LINES - 6 + row, col);
+ printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
+ clrtoeol();
+}
+
+static void
+overlap_test_1_attr(WINDOW *win, int flavor, int col)
+{
+ NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (1 + (flavor * 2) + col);
+
+ switch (flavor) {
+ case 0:
+ (void) wattrset(win, A_NORMAL);
+ break;
+ case 1:
+ (void) wattrset(win, A_BOLD);
+ break;
+ case 2:
+ init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
+ (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_NORMAL));
+ break;
+ case 3:
+ init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
+ (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_BOLD));
+ break;
+ }
+}
+
+static void
+overlap_test_2_attr(WINDOW *win, int flavor, int col)
+{
+ NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (9 + (flavor * 2) + col);
+
+ switch (flavor) {
+ case 0:
+ /* no effect */
+ break;
+ case 1:
+ /* no effect */
+ break;
+ case 2:
+ init_pair(cpair, COLOR_RED, COLOR_GREEN);
+ wbkgdset(win, colored_chtype(' ', A_BLINK, cpair));
+ break;
+ case 3:
+ wbkgdset(win, ' ' | A_NORMAL);
+ break;
+ }
+}
+
+static int
+overlap_help(int state, int flavors[OVERLAP_FLAVORS])
+{
+ int row;
+ int col;
+ int item;
+ const char *ths, *tht;
+ char msg[80];
+
+ if (state < 0)
+ state += OVERLAP_FLAVORS;
+ state = state % OVERLAP_FLAVORS;
+ assert(state >= 0 && state < OVERLAP_FLAVORS);
+
+ for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
+ row = item / 2;
+ col = item % 2;
+ ths = col ? "B" : "A";
+ tht = col ? "A" : "B";
+
+ switch (row) {
+ case 0:
+ flavors[row] = 0;
+ sprintf(msg, "refresh %s, then %s, then doupdate.", ths, tht);
+ break;
+ case 1:
+ if (use_colors) {
+ flavors[row] %= 4;
+ } else {
+ flavors[row] %= 2;
+ }
+ overlap_test_1_attr(stdscr, flavors[row], col);
+ sprintf(msg, "fill window %s with letter %s.", ths, ths);
+ break;
+ case 2:
+ if (use_colors) {
+ flavors[row] %= 4;
+ } else {
+ flavors[row] %= 2;
+ }
+ switch (flavors[row]) {
+ case 0:
+ sprintf(msg, "cross pattern in window %s.", ths);
+ break;
+ case 1:
+ sprintf(msg, "draw box in window %s.", ths);
+ break;
+ case 2:
+ sprintf(msg, "set background of window %s.", ths);
+ break;
+ case 3:
+ sprintf(msg, "reset background of window %s.", ths);
+ break;
+ }
+ break;
+ case 3:
+ flavors[row] = 0;
+ sprintf(msg, "clear window %s.", ths);
+ break;
+ case 4:
+ flavors[row] %= 4;
+ switch (flavors[row]) {
+ case 0:
+ sprintf(msg, "overwrite %s onto %s.", ths, tht);
+ break;
+ case 1:
+ sprintf(msg, "copywin(FALSE) %s onto %s.", ths, tht);
+ break;
+ case 2:
+ sprintf(msg, "copywin(TRUE) %s onto %s.", ths, tht);
+ break;
+ case 3:
+ sprintf(msg, "overlay %s onto %s.", ths, tht);
+ break;
+ }
+ break;
+ }
+ overlap_helpitem(state, item, msg);
+ (void) wattrset(stdscr, A_NORMAL);
+ wbkgdset(stdscr, ' ' | A_NORMAL);
+ }
+ move(LINES - 1, 0);
+ printw("^Q/ESC = terminate test. Up/down/space select test variations (%d %d).",
+ state, flavors[state]);
+
+ return state;
+}
+
+static void
+overlap_test_0(WINDOW *a, WINDOW *b)
+{
+ touchwin(a);
+ touchwin(b);
+ wnoutrefresh(a);
+ wnoutrefresh(b);
+ doupdate();
+}
+
+static void
+overlap_test_1(int flavor, int col, WINDOW *a, char fill)
+{
+ overlap_test_1_attr(a, flavor, col);
+ fillwin(a, fill);
+ (void) wattrset(a, A_NORMAL);
+}
+
+static void
+overlap_test_2(int flavor, int col, WINDOW *a, char fill)
+{
+ overlap_test_2_attr(a, flavor, col);
+ switch (flavor) {
+ case 0:
+ crosswin(a, fill);
+ break;
+ case 1:
+ box(a, 0, 0);
+ break;
+ case 2:
+ /* done in overlap_test_2_attr */
+ break;
+ case 3:
+ /* done in overlap_test_2_attr */
+ break;
+ }
+}
+
+static void
+overlap_test_3(WINDOW *a)
+{
+ wclear(a);
+ wmove(a, 0, 0);
+}
+
+static void
+overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
+{
+ switch (flavor) {
+ case 0:
+ overwrite(a, b);
+ break;
+ case 1:
+ copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
+ break;
+ case 2:
+ copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
+ break;
+ case 3:
+ overlay(a, b);
+ break;
+ }
+}
+