summaryrefslogtreecommitdiffstats
path: root/lib/libncurses/TESTS/over.c
blob: 5681916ee4d8c7a56be111ff8a6d87d5e2fd01c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*********************************************************************
 * [program]   overwrite() - Play with overwrite() function to       *
 *             attempt pop-up windows.                               *
 * ----------------------------------------------------------------- *
 * [written]   1-Feb-1993 by Neal Ensor (ensor@cs.utk.edu)           *
 * ----------------------------------------------------------------- *
 * [notes]     Originally written on SVR4 UNIX, then recompiled on   *
 *             Linux (Slackware 1.1.1, ncurses 1.8.1)                *
 * ----------------------------------------------------------------- *
 * [problem]   On ncurses, the overwrite() function doesn't seem to  *
 *             overwrite.  Maybe I'm missing something, but this     *
 *             program in SVR4 displays three windows, waits for a   *
 *             keypress, then removes the top window.  With ncurses, *
 *             nothing changes on the display.                       *
 *********************************************************************/

#  include <ncurses.h>         /* ncurses include lives here */

main()
{
    /****************************************************************
     * Declare three little window pointers...                      *
     ****************************************************************/
    WINDOW *win, *win1, *win2;

    /****************************************************************
     * Set up the screen...                                         *
     ****************************************************************/
    initscr();
    /* traceon(); */
    noecho();
    nonl();
    cbreak();
    refresh();

    /****************************************************************
     * Draw three overlapping windows.                              *
     ****************************************************************/
    win=newwin(6,45, 6,6);
    win1=newwin(10,20,5,5);
    win2=newwin(10,30,7,7);

    /****************************************************************
     * Box them, and print a hidden message...                      *
     ****************************************************************/
    box(win,  0, 0);
    box(win1, 0, 0);
    box(win2, 0, 0);
    mvwprintw(win1, 6,6, "Hey!");
    mvwaddch(win, 1, 1, '0');
    mvwaddch(win1, 1, 1, '1');
    mvwaddch(win2, 1, 1, '2');
    wnoutrefresh(win);
    wnoutrefresh(win1);
    wnoutrefresh(win2);
    doupdate();

    /****************************************************************
     * Await a keypress to show what we've done so far.             *
     ****************************************************************/
    getch();

    /****************************************************************
     * Now, overwrite win2 with contents of all lower windows IN    *
     * ORDER from the stdscr up...                                  *
     ****************************************************************/
    if (overwrite(stdscr, win2) == ERR)
      fprintf(stderr, "overwrite(stdscr, win2) failed!\n");

    touchwin(stdscr); wnoutrefresh(stdscr);
    touchwin(win); wnoutrefresh(win);
    touchwin(win1); wnoutrefresh(win1);
    touchwin(win2); wnoutrefresh(win2);
    doupdate();

    getch();
    if (overwrite(win, win2) == ERR)
      fprintf(stderr, "overwrite(win, win2) failed!\n");

    touchwin(stdscr); wnoutrefresh(stdscr);
    touchwin(win); wnoutrefresh(win);
    touchwin(win1); wnoutrefresh(win1);
    touchwin(win2); wnoutrefresh(win2);
    doupdate();

    getch();
    if (overwrite(win1, win2) == ERR)
      fprintf(stderr, "overwrite(win1, win2) failed!\n");

    /****************************************************************
     * Perform touches, and hidden refreshes on each window.        *
     * ------------------------------------------------------------ *
     * NOTE:  If you replace the wnoutrefresh() call with wrefresh()*
     * you can see all windows being redrawn untouched.             *
     ****************************************************************/
    touchwin(stdscr); wnoutrefresh(stdscr);
    touchwin(win); wnoutrefresh(win);
    touchwin(win1); wnoutrefresh(win1);
    touchwin(win2); wnoutrefresh(win2);
    doupdate();

    /****************************************************************
     * At this point, win2 should be "destroyed"; having all other  *
     * window contents overwritten onto it.  The doupdate() should  *
     * effectively remove it from the screen, leaving the others    *
     * untouched.  On SVR4, this happens, but not with ncurses.     *
     * I'd suspect something in overwrite() causes this, as nothing *
     * appears to be overwritten after the calls, with no errors    *
     * being reported.  This was compiled on my Linux from Slackware*
     * 1.1.1, with ncurses1.8.1 recompiled on it, using the console *
     * entry from the "new" terminfo from ncurses1.8.1.             *
     ****************************************************************/
    getch();

    /****************************************************************
     * Clean up our act and exit.                                   *
     ****************************************************************/
    endwin();
}

OpenPOWER on IntegriCloud