/*
 * -- $Header: /cec/src/nestor/servers/R3/shXlib/XCrWindow.c,v 1.1.1.1 90/04/23 09:55:03 spanachi Exp $
 */

#include "copyright.h"

/* $XConsortium: XCrWindow.c,v 11.12 88/09/06 16:06:05 jim Exp $ */
/* Copyright    Massachusetts Institute of Technology    1986	*/

/* -- MULTIPLEX Extension -- */

#include "Xlibint.h"

/* -- additional includes -- */
#include "resources.h"
#include "ApplCtx.h"

Window XCreateSimpleWindow(dpy, parent, x, y, width, height, 
                      borderWidth, border, background)
    register Display *dpy;
    Window parent;
    int x, y;
    unsigned int width, height, borderWidth;
    unsigned long border;
    unsigned long background;

{
    Window wid;
    register xCreateWindowReq *req;
    /* -- additional variables -- */
    Bool mux_add_events ;
    long mux_event_mask , mux_specific_mask ;
    int  mux_extra ;

    /*
     * -- There is one problem with this "simple" routine: If the application
     * -- creates a simple top-level window, we will have to add the XmuXmask;
     * -- Fortunately, the original mask is 0L
     */

    /* -- find out if we must alter the event mask -- */
    mux_add_events = XmuXMustAddEvents( dpy , parent , XmuXCreate ) ;

    if( mux_add_events )
    {
	mux_extra = 12 ;
	mux_specific_mask = XmuXMask ;
	mux_event_mask    = XmuXMask ;
    }
    else
	mux_extra = 8 ;
    
    LockDisplay(dpy);
    GetReqExtra(CreateWindow, mux_extra, req);
    req->parent = parent;
    req->x = x;
    req->y = y;
    req->width = width;
    req->height = height;
    req->borderWidth = borderWidth;
    req->depth = 0;
    req->class = CopyFromParent;
    req->visual = CopyFromParent;
    wid = req->wid = XAllocID(dpy);
    req->mask = ( mux_add_events ) 
                ? CWEventMask | CWBackPixel | CWBorderPixel
                : CWBackPixel | CWBorderPixel ;
#ifdef MUSTCOPY
    {
	unsigned long lbackground = background, lborder = border;
	dpy->bufptr -= mux_extra ;
	Data32 (dpy, (long *) &lbackground, 4);
	Data32 (dpy, (long *) &lborder, 4);
	if( mux_add_events )
	    Data32( dpy, ( long * ) &mux_event_mask, 4 ) ;
    }
#else
    {
	register unsigned long *valuePtr =
	  (unsigned long *) NEXTPTR(req,xCreateWindowReq);
	*valuePtr++ = background;
	*valuePtr = border;
	if( mux_add_events )
	{
	    valuePtr++ ;
	    *valuePtr = mux_event_mask ;
	}
    }
#endif /* MUSTCOPY */


    /* -- store the new resource if it is necessary -- */
    if(  XmuXStoreResources( dpy ) )
    {   XSetWindowAttributes attributes ;

	XmuXInsertWindowInfo( dpy , wid , parent , CopyFromParent , 
			      req->depth ) ;
	/*
	 * -- These attributes may contain values that we cannot retrieve
	 * -- via XGetWindowAttributes. We must keep track of these values,
	 * -- since they have a strong impact on duplicating resources 
	 * -- (see multiplex.c for further information).
	 */
	attributes.background_pixel = background ;
	attributes.border_pixel     = border ;
	XmuXUpdateWindowInfo( dpy , wid , req->mask , &attributes ) ;
	if( mux_add_events )
	    XmuXAddToplevelInfo( dpy , wid , mux_specific_mask ) ;
    }
    UnlockDisplay(dpy);
    SyncHandle();
    return (wid);
    }
