[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: moving nested subwins

From: Thomas Dickey
Subject: Re: moving nested subwins
Date: Thu, 7 Jun 2007 06:59:29 -0400 (EDT)

On Thu, 7 Jun 2007, Clive Nicolson wrote:

Oops I forgot to attach the code.


here is some code which demonstrates how to fix the "menu subwin moving"
problem for mvwin. This code is nonrecursive and I think will not break user code which traverses the window parent tree and recalculates _begy
and _begx. It also fixes the "form subwin moving" problem!

mvderwin needs a somewhat slightly different fix.

Anyone want a patch?

not exactly. Let's go back to the top of the discussion. What's needed is a concise proposal for

(a) an identifiable mismatch between ncurses behavior that leads to a fix or

(b) an example of how to provide the functionality without modifying ncurses or

(c) a new feature which could be used to provide the functionality, e.g., an extension

(extensions can't make it harder to port applications between flavors of curses...)

#include <stdlib.h>
#include <stdio.h>

typedef struct _win_st WINDOW;
struct _win_st {
 int _begy;
 int _begx;
 WINDOW *_parent;
 /* New fields */
 WINDOW *_nc_lastchild;
 WINDOW *_nc_lastsibling;
 /* Test fields */
 char name[16+1];
 int moved;

static int i;

/* Move all descendants of root */
static void
moveall(WINDOW *root, int dy, int dx) {
 WINDOW *window;

 window = root;
 while (window->_nc_lastchild)
   window = window->_nc_lastchild;
 while (window != root) {
     printf("%s 1: %p %p %p",
             (void *)window->_parent,
             (void *)window->_nc_lastchild, (void *)window->_nc_lastsibling);
     if (window->moved)
        printf(" ****");
        window->moved = 1;
   window->_begy += dy;
   window->_begx += dx;

   if (window->_nc_lastsibling) {
     window = window->_nc_lastsibling;
     goto loop;
   } else
     window = window->_parent;

static void
addsubwindow(WINDOW *parent, WINDOW *window) {
 window->_parent = parent;
 window->_nc_lastchild = NULL;
 window->_nc_lastsibling = parent->_nc_lastchild;

 parent->_nc_lastchild = window;

static void
delwindow(WINDOW *window) {
 WINDOW *child;

 child = window->_nc_lastchild;
 while (child) {
   WINDOW *temp;

   temp = child->_nc_lastsibling;

   child->_parent = NULL;
   child->_nc_lastsibling = NULL;

   child = temp;

 if (window->_parent) {
   WINDOW *parent;

   parent = window->_parent;
   if (parent->_nc_lastchild) {
     if (parent->_nc_lastchild == window)
        parent->_nc_lastchild = window->_nc_lastsibling;
     else {
        WINDOW *sibling;

        sibling = parent->_nc_lastchild;
        while (sibling && sibling->_nc_lastsibling != window)
          sibling = sibling->_nc_lastsibling;

        if (sibling)
          sibling->_nc_lastsibling = window->_nc_lastsibling;


static WINDOW *
build(WINDOW *parent) {
 WINDOW *win;

 win = malloc(sizeof(*win));
 win->_begy = 0;
 win->_begx = 0;
 win->_parent = parent;
 win->_nc_lastchild = (random() <= (RAND_MAX-1)/2) ? NULL : build(win);
 win->_nc_lastsibling = (random() <= (RAND_MAX-1)/2) ? NULL : build(parent);
 sprintf(win->name, "%p", (void *)win);
 win->moved = 0;
 printf("%s 0\n", win->name);


 return win;

main(int argc, char **argv) {
 WINDOW *root;

 i = 0;
 root = build(NULL);
 moveall(root, 2, 4);
 printf("i=%i\n", i);

 if (0) {
   addsubwindow(root, NULL);

 return (EXIT_SUCCESS);

Bug-ncurses mailing list

Thomas E. Dickey

reply via email to

[Prev in Thread] Current Thread [Next in Thread]