/**************************************************************************
 *
 *************************************************************************/

#include "gemfintl.h"

#ifndef LATTICE
short wind_newdesk(tree, obj)
	OBJECT *tree;
	short  obj;
{
	int upr, lwr;
	
	upr = (int)((long)tree >> 16);
	lwr = (int)((long)tree & 0x0000FFFF);
	
	return wind_set(0, WF_NEWDESK, upr, lwr, obj, 0);
}
#endif

void  frm_desktop(options, ptree)
	long			 options;
	register OBJECT  *ptree;
{
	register OBJECT  *pobj2;
	short			  fill;
	short			  color;
	long			  ospec;

	wind_update(BEG_UPDATE);
	if ((options & FRM_DTREMOVE) || ptree == NULL) {
		wind_newdesk(NULL, 0);
	} else {
		if (options & FRM_CENTER) {
			rc_copy(&gl_rwdesk, (GRECT*)&ptree->ob_x); /* copy desk xywh to tree	*/
			if (!(ptree->ob_flags & LASTOB)) { /* if there's another object */
				pobj2 = ptree + 1;			   /* center it on the screen	*/
				pobj2->ob_x = (ptree->ob_width	- pobj2->ob_width)	/ 2;
				pobj2->ob_y = (ptree->ob_height - pobj2->ob_height) / 2;
			}
		}
		apl_vshared();							   /* fill in gl_vwout[]  */
		if (gl_vwout[13] == 2) {				   /* monochrome monitor? */
			ospec  = (long)ptree->_Ob_spec; 	   /* if so, and the	  */
			fill  = (short)((ospec & 0x00000070L) >> 4);    /* desktop is a solid  */
			color = (short)(ospec & 0x0000000FL);  		    /* color, change it to */
			if (fill == 7 && color > 0) {		   /* halftone gray.	  */
				ptree->_Ob_spec = (_Ob_spec_t)((ospec & 0xFFFFFF00L) | 0x00000041L);
			}
		}
		wind_newdesk(ptree, 0);
	}
	wind_update(END_UPDATE);
	frmx_dial(FMD_FINISH, NULL, &gl_rwdesk);	/* paint the new desktop */
}

