/*

typedef struct {
int errnum;
char errmess[252];
} os_error;

typedef struct {
int handle, x0,y0,x1,y1,scx,scy, bhandle; } wimp_openstr;

typedef struct {
int handle, x0,y0,x1,y1,scx,scy, bhandle, flags; } wimp_wstate;

typedef int wimp_w;        /* window handle */

typedef enum {
wimp_ENULL = 0,
wimp_EREDRAW = 1,
wimp_EOPEN = 2,
wimp_ECLOSE = 3,
wimp_EPTRLEAVING = 4,
wimp_EPTRENTERING = 5,
/* etc. */
} wimp_eventcode;

typedef union {
wimp_redrawstr redraw;
wimp_openstr open;
wimp_w close;
wimp_w ptrleaving;
wimp_w ptrentering;
/* etc. */
} wimp_eventstr;

/*

extern os_error * wimp_openwindow(wimp_openstr * openblk); extern os_error * wimp_closewindow(wimp_w handle); extern os_error * wimp_getwindowstate(wimp_w handle, wimp_wstate * result); extern os_error * wimp_poll(wimp_eventstr * e, wimp_eventcode * result); extern void wimp_reporterror(os_error * err, int flags, char * taskname);

/*

int main(void)
{
os _error * err;
wimp_eventstr event;
wimp_eventcode reason;

/*

/* simplified polling loop */

do {
if (err != NULL) wimp_reporterror(err,1,"The task name"); err = wimp_poll(&event, &reason);

if (err == NULL) {

      switch(reason) {
        /*  etc. */
        case wimp_EOPEN: err = event_openwindow(&event.open);
                                 break;
        case wimp_ECLOSE: err = event_closewindow(event.close);
        /*  etc. */
      }
}
} while (1); /* program exits when message 0 is sent to it */

return(0);
}

/*

/* Note: the following routine does not check all error cases, in the os_error * event_openwindow(wimp_openstr * open) {
wimp_wstate panestate;
wimp_wstate toolstate;

if (open->handle == tool) {
wimp_getwindowstate(pane, &panestate); if (panestate.bhandle == open->bhandle) open->bhandle = pane; wimp_getwindowstate(tool, &toolstate); if (open->y1 > toolstate.y1) openpane(open, pane); /* open pane first */

    wimp_openwindow(open);               /* coords written back into block */
if (open->bhandle == -2) {
      wimp_getwindowstate(tool, &toolstate);           /* sent to the back */
      open->bhandle = toolstate.bhandle;
}
    return(openpane(open));                            /* open pane again */
} else {
    return(wimp_openwindow(open));                     /* normal window */
}
}

/*

os_error * openpane(wimp_openstr *open, wimp_w panehandle) {
wimp_openstr o;

o.handle = panehandle;
o.x0 = open->x0;
o.y0 = open->y1 - 100; /* assume pane window height = 100 OS units */ o.x1 = open->x1;
o.y1 = open->y1;

  o.scx = open->scx;       /* scroll sideways in step with tool window */
  o.scy = 0;               /* don't scroll vertically! */
o.bhandle = open->bhandle;
return(wimp_openwindow(&o));
}

os_error * event_closewindow(wimp_w handle) {
if (handle == tool) wimp_closewindow(pane); /* close pane as well */ return(wimp_closewindow(handle));
}