#include <stdio.h>
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>


Boolean
xdsTextPutInput( widget, text)
	Widget widget;
	char * text;
{
	Arg args[2];
	Cardinal ac = 0;

	if (!widget)
		return False;

	XtSetArg( args[ac], XmNvalue, text); ac++;
	XtSetValues( widget, args, ac);

	return False;
}

char *
xdsTextGetInput( widget)
	Widget widget;
{
	Arg args[2];
	Cardinal ac = 0;
	char * value = (char*)0;

	if (!widget)
		return (char*)0;

	XtSetArg( args[ac], XmNvalue, &value); ac++;
	XtGetValues( widget, args, ac);

	return value;
}




/* this module is not compiled by default.

   For most test situations we have found that treating text fields
   as simple data entry fields, where you just REPLACE the text in it
   is the safest and most effective technique.

   This module is for specialised usage of the Text widget - eg for
   testing an editor
*/

#ifdef HANDLE_TEXT


int
xdsTextNameToXy( widget, name, attr, xp, yp)
	Widget widget;
	char * name;
	char * attr;
	int  * xp;
	int * yp;
{
	Position x = (Position)0;
	Position y = (Position)0;
	XmTextPosition pos = atoi(attr);

	XmTextShowPosition( widget, pos);
	if (!XmTextPosToXY( widget, pos, &x, &y))
		return 0;

	*xp = x;
	*yp = y;

	return 1;
}

int
xdsTextFieldNameToXy( widget, name, attr, xp, yp)
	Widget widget;
	char * name;
	char * attr;
	int  * xp;
	int * yp;
{
	Position x = (Position)0;
	Position y = (Position)0;
	XmTextPosition pos = atoi(attr);

	XmTextFieldShowPosition( widget, pos);
	if (!XmTextFieldPosToXY( widget, pos, &x, &y))
		return 0;

	*xp = x;
	*yp = y;

	return 1;
}

static
int
_xdsTextXYToName( widget, pos, namep, attrp)
	Widget widget;
	XmTextPosition pos;
	char ** namep;
	char ** attrp;
{
	static char posdata[20];

	(void) sprintf ( posdata, "%d", pos);

	*namep = "position";
	*attrp = posdata;

	return 1;
}

int
xdsTextXyToName( widget, x, y, namep, attrp)
	Widget widget;
	int x, y;
	char ** namep;
	char ** attrp;
{
	return _xdsTextXYToName( widget, XmTextXYToPos( widget, x, y), namep, attrp);
}

int
xdsTextFieldXyToName( widget, x, y, namep, attrp)
	Widget widget;
	int x, y;
	char ** namep;
	char ** attrp;
{
	return _xdsTextXYToName( widget, XmTextFieldXYToPos( widget, x, y), namep, attrp);
}


#endif
