#include <stdio.h>
#include <X11/Xatom.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <X11/StringDefs.h>

#include <Xint/EditTable.h>

/*
This is a simplistic prototype converter for the INT EditTable widget
that is included as an example of how to record and replay from custom
widgets, without having to map to and from (x,y) coordinates.

For the INT EditTable widget, the preferred method is to use the
XIntTableGetCellGeometry() call to integrate the widget properly.
*/


int
intEditTableXYToName( widget, x, y, namep, attrp)
	Widget widget;
	int x, y;
	char ** namep;
	char ** attrp;
{
	static char col[15];
	static char row[15];

	int tcol = 0;
	int trow = 0;

	if (!XintEditTableGetCellPointerPosition( widget, &tcol, &trow)) {
		(void) fprintf ( stderr, "cannot get pointer position\n");
		return 0;
	}

	(void) sprintf ( col, "col-%d", tcol);
	(void) sprintf ( row, "row-%d", trow);

	*namep = row;
	*attrp = col;

	return 1;
}

int
intEditTableNameToXY( widget, name, attr, xp, yp)
	Widget widget;
	char * name;
	char * attr;
	int * xp;
	int * yp;
{
	int rowval = atoi(name+4);
	int colval = atoi(attr+4);

	if (!XintEditTableSetCellPointerPosition( widget, colval, rowval)) {
		(void) fprintf ( stderr, "cannot set pointer position\n");
		return 0;
	}

	XintEditTableSetSelection(widget,colval,1,rowval,1,XintSELECT_CELL);

	*xp = -1;   /* this is cheating. We're not replaying the events, */
	*yp = -1;
		    /* if the converter returns NEGATIVE values it means D-I-Y */

	return 1;
}
