CURSES sub-windows bugs - correction to Mike Laman article

idallen at watmath.UUCP idallen at watmath.UUCP
Tue Aug 21 17:38:04 AEST 1984


> From: laman at sdcsvax.UUCP (Mike Laman)
> First of all let me point out that when sub windows are
> created, the window's text is SEPARATE from original window.

This is not true with the 4.2bsd curses dated June/July 1983.
Sub windows are merely edge vectors into their parent windows.
A change in either is reflected in both, since they are the same.

> As I mentioned earlier, the real killer is that EACH routine would be
> responsible for adding the information to each associated window.
> I suggest the correct solution be to have sub windows SHARE the window text
> with the information in the WINDOW header telling what part of the lines it
> "owns".

4.2 curses already does share window text.  The line-change flags are
not shared, and are not updated correctly by any of the erase or
clearing functions.

> As for the problem at hand, I guess you'll have to be happy with
> "overwrite()" (and "overlay()"), until you get a System V.2 to use.

I would be surprised if even V.2 got sub-windows right.  The fix to
making clear and erase affect all related window change flags is easy. 
CLEAR already calls ERASE.  Make ERASE and CLRTOBOT call CLRTOEOL for all
appropriate lines.  Make CLRTOEOL set change flags in all affected windows.

Here's a simple sub-windows test program.  See if V.2 passes the test.

/* Test curses to see if deleting a line in a parent window is
 * correctly represented in a sub-window.
 * Test curses to see if clearing part of a sub-window is correctly
 * represented in the parent window.
 * idallen at watmath.UUCP  Ian! D. Allen   University of Waterloo
 */
#include <curses.h>

WINDOW *win;
int bell = 007;
int i;

main()
{
    initscr();
    win = subwin( stdscr, 0, 0, 0, 0 );

    for( i=0; i<LINES; i++ )
    	mvwprintw( stdscr, i, 0, "This is Line %d\n", i );
    wrefresh( stdscr );

    /* Delete line ten.  All the lines thereafter move up one line.
     */
    sleep(5); write( 2, &bell, 1 );
    move( 10, 0 );
    deleteln();
    wrefresh( stdscr );

    /* See what the sub-window thinks the screen should look like.
     * If the sub-window bug is here, line ten will reappear as a blank
     * line and all the other lines will move back to where they were.
     */
    sleep(3); write( 2, &bell, 1 );
    touchwin( win );
    wrefresh( win );

    /* Recreate the parent-window version of the window.
     */
    sleep(3); write( 2, &bell, 1 );
    touchwin( stdscr );
    wrefresh( stdscr );

    /* Recreate the sub-window version of the window.
     */
    sleep(3); write( 2, &bell, 1 );
    touchwin( win );
    wrefresh( win );

    /* Now, clear part of the parent window and refresh the sub-window.
     * Because clearing doesn't use addch(), the change flags aren't
     * set for the sub-window and nothing happens.
     */
    sleep(3); write( 2, &bell, 1 );
    move( 5, 0 );
    clrtobot();
    wrefresh( win );	/* if you have the bug, nothing happens here */

    sleep(3); write( 2, &bell, 1 );
    wrefresh( stdscr );	/* now, the screen clears correctly */

    sleep(5);
    endwin();
}
-- 
        -IAN!  (Ian! D. Allen)      University of Waterloo



More information about the Comp.unix.wizards mailing list