/*    getTKtext.c   						*/

#include <stdio.h>
#include <X10/Xlib.h>
#define AUX extern
#define READFILE extern
#define LKUPS extern
#include "prsdefs.h"
#include "structs.h"
#include "lkups.h"
#include "widgets.h"

/*  what should be done with this ? */
  TKtext  TKtextDefaults = {
  		0,
		(Window) NULL, (Window) NULL,
		0,0,100,20,200,4,
		1, 0, 1,
		(Pixmap)0,(Pixmap)0,(Pixmap)0,
		"text",
		"RootWindow",
		"no_file","blank_string","",
		0,
		0,0,2,
		NULL,
		XttextRead
	 };

int
getTKtext( fp, m )

	FILE 		*fp;
	Map		*m;
{
  static char 	*funcname = "gettext";
  Lkup_union 	lkp, *lkup = &lkp;
  TKtext	*t;
  int 		i, n;
  char 		*p1, *p2, *colon;
  char 		ln[Nchars], *line = ln;
  char		tname[Nchars],tval[Nchars];
  char 		*rindex(), *index();


  if((t = (TKtext *)calloc(1,sizeof(TKtext)))==NULL){
	      		printf("%s: Can't  allocate TKtext\n",funcname);
	      		return (NULL);
	 	     }

  bcopy( &TKtextDefaults, t, sizeof(TKtext) );

  printf("TESTING: parentname is %s\n",t->parentname);

  m->simple.w = (Window) t;

while((line = get_data_line(fp)) != NULL)
{

  sscanf(line,"%s %[^\n]\n",tname,tval);
 	 if( (colon = rindex(tname,':')) !=0 )
	 {
    		*colon = '\0';
  	  }

  if((n=lookup(tname)) != NULL  && n <= Primary_Keys)
  {
      	printf("%s: `%s'\n",funcname,t->name);
      	t->border_pixmap = XMakeTile(t->border);
	t->foreground_pixmap = XMakeTile(t->foreground);
	t->background_pixmap = XMakeTile(t->background);
	if((t->font = XOpenFont(t->fontname)) == NULL)
	{
	  	printf("%s: can't open font %s\n",funcname,t->fontname);
	 }
        return(n);
   }
   
 
    switch(n){

    	case POS_IN:
      		i = 0;
		p1 = tval;
		while ((p2 = index(p1,',')) != 0)
		{
	  		*p2 = '\0';
			m->simple.pos[InPoint][i++] = atoi(p1);
			p1 = ++p2;
      		 }
		m->simple.pos[InPoint][i] = atoi(p1);
      		break;
    	case POS_OUT:
      		i = 0;
		p1 = tval;
		while ((p2 = index(p1,',')) != 0)
		{
	  		*p2 = '\0';
			m->simple.pos[OutPoint][i++] = atoi(p1);
			p1 = ++p2;
      		 }
		m->simple.pos[OutPoint][i] = atoi(p1);
      		break;
      }

  if((n=TK_lookup(tname)) != NULL)
  {

    switch(n){


	case TK_NAME:
      		strcpy(t->name,tval);
      		break;
    	case TK_EDIT_TYPE:
      		strcpy(t->edit_type,tval);
      		break;
	case TK_TEXT_OPTIONS: /* this is type int, but choices are strings
				We can convert now or preferably in the 
				mapping */
		strcpy(t->options,tval);
		break;
	case TK_DISPLAY_POSITION:
		t->display_pos = atoi(tval);
		break;
	case TK_INSERT_POSITION:
		t->insert_pos = atoi(tval);
		break;
	case TK_LEFT_MARGIN: /* this is in pixels conversion to char spaces
			   	might be desired for user friendliness */
		t->left_margin = atoi(tval);
		break;
	case TK_FOREGROUND:
      		t->foreground = atoi(tval);
      		break;
    	case TK_BACKGROUND:
      		t->background = atoi(tval);
      		break;
    	case TK_BORDER:
 		t->border = atoi(tval);
      		break;  
	case TK_BORDERWIDTH:
      		t->borderwidth = atoi(tval);
      		break;
	case TK_FILE:
		strcpy(t->file,tval);
		break;
	case TK_STRING:
		strcpy(t->string,tval);
		break;	
    	case TK_LENGTH:
		t->length = atoi(tval);
		break;
	case TK_FONT:
		strcpy(t->font,tval);
      		break;
    	case TK_EVENT_BINDINGS:
		strcpy(t->event_bindings,tval);
		break;
      	case TK_WIDTH:
     		t->width = atoi (tval);
      		break;
    	case TK_HEIGHT:
      		t->height = atoi (tval);
           	break;
        case TK_X:
      		t->x = atoi (tval);
      		break;
    	case TK_Y:
      		t->y = atoi (tval);
		break;
    	default:
      		printf("%s: can't use `%s', line %d\n"
			,funcname,tname,linecount);
      } 						/* switch 	*/
     tval[0] = NULL;
   } 							/* if TK_lookup */
  else
  {
	 printf("%s: can't use `%s', line %d\n",funcname,tname,linecount);
   }
}  							/* while	*/
 
printf("%s: `%s`\n",funcname,t->name);
t->border_pixmap = XMakeTile(t->border);
t->foreground_pixmap = XMakeTile(t->foreground);
t->background_pixmap = XMakeTile(t->background);
if((t->font = XOpenFont(t->fontname)) == NULL)
{
  	printf("%s: can't open font %s\n",funcname,t->fontname);
 }
return(-1);

}


