/*
 * Copyright 1990 by Baylor College of Medicine ALL RIGHTS RESERVED. 
 *
 * This program is subject to a license agreement between 
 * Baylor College of Medicine and MIT. Any use inconsistent with
 * said license and any use by persons other than the faculty, 
 * students and staff at MIT or any use on a computer not operated 
 * as part of the Athena Computing Environment (ACE) is expressly 
 * prohibited.
 */
/****************************************************************
 * File: util.c 
 * Date: 03/03/91
 *
 * Description:
 *   This file contains several utility functions.
 *
 * Revisions:
 ****************************************************************/
#include <stdio.h>
#include <Xm/Xm.h>
#include <X11/IntrinsicP.h>

#include "VtP.h"

PUBLIC
void
VtUnmanageChildren(w)
	Widget w ;
{
	if (XtIsComposite(w))
	{
		Widget *children = ((CompositeWidget)w)->composite.children ;
		int nchildren = ((CompositeWidget)w)->composite.num_children ;
		int i ;
		XtUnmanageChildren(children,(Cardinal)nchildren) ;
		for(i = 0; i < nchildren; i++)
		{
			VtUnmanageChildren(children[i]) ;
		}
	}
}

PUBLIC
void
VtManageChildren(w)
	Widget w ;
{
	if (XtIsComposite(w))
	{
		Widget *children = ((CompositeWidget)w)->composite.children ;
		int nchildren = ((CompositeWidget)w)->composite.num_children ;
		int i ;
		for(i = 0; i < nchildren; i++)
		{
			VtManageChildren(children[i]) ;
		}
		XtManageChildren(children,(Cardinal)nchildren) ;
	}
}

PUBLIC
void
VtFindCenter(dpy,w,h,x,y)
	Display *dpy;
	int w;
	int h;
	int *x;
	int *y;
{
	*x = (DisplayWidth(dpy,DefaultScreen(dpy)) - w) / 2;
	*y = (DisplayHeight(dpy,DefaultScreen(dpy)) - h) / 2;
}

PUBLIC
XtPointer
ToggleGetCurrent(w)
        Widget w ;
{
	int nchildren = ((CompositeWidget)w)->composite.num_children ;
	Widget *children = ((CompositeWidget)w)->composite.children ;
	int i ;
	for(i = 0; i < nchildren; i++)
	{
		Boolean set ;
		XtPointer data ;
        	XtVaGetValues(children[i],
			XmNuserData,&data,
			XmNset,&set,
			NULL) ;
		if (set)
		{
			return data ;
		}
	}
        return NULL ;
}

PUBLIC
XmFontList
def_font(f)
	XFontStruct *f ;
{
	return XmFontListCreate(f,XmSTRING_DEFAULT_CHARSET) ;
}

PUBLIC
char *
get_xm_string(s)
	XmString s ;
{
	char *text ;
	XmStringGetLtoR(s,XmSTRING_DEFAULT_CHARSET,&text) ;
	return text ;
}
