/* Generated by wbuild from "EntrySB.w"
 * Copyright 1998, Jon A. Christopher
** (generator version $Revision: 1.3 $ of $Date: 1999/09/22 14:27:47 $)
*/
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#line 265 "EntrySB.w"
#include <Xm/RowColumn.h>
#line 266 "EntrySB.w"
#include <Xm/Scale.h>
#line 267 "EntrySB.w"
#include <Xm/TextF.h>
#line 268 "EntrySB.w"
#include <math.h>
#line 269 "EntrySB.w"
#include <stdio.h>
#include <./EntrySBP.h>
static void _resolve_inheritance(
#if NeedFunctionPrototypes
WidgetClass
#endif
);
#line 47 "EntrySB.w"
static void initialize(
#if NeedFunctionPrototypes
Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 153 "EntrySB.w"
static Boolean  set_values(
#if NeedFunctionPrototypes
Widget ,Widget ,Widget,ArgList ,Cardinal *
#endif
);
#line 196 "EntrySB.w"
static void activate_CB(
#if NeedFunctionPrototypes
Widget ,Widget,XtPointer 
#endif
);
#line 219 "EntrySB.w"
static void scroll_CB(
#if NeedFunctionPrototypes
Widget ,Widget,XmScaleCallbackStruct *
#endif
);
#line 234 "EntrySB.w"
static void focusCB(
#if NeedFunctionPrototypes
Widget ,XtPointer ,XmAnyCallbackStruct *
#endif
);
#line 244 "EntrySB.w"
static void update_display(
#if NeedFunctionPrototypes
Widget
#endif
);
#line 196 "EntrySB.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 196 "EntrySB.w"
static void activate_CB(Widget  w,Widget self,XtPointer  call)
#else
#line 196 "EntrySB.w"
static void activate_CB(w,self,call)Widget  w;Widget self;XtPointer  call;
#endif
#line 197 "EntrySB.w"
{
  /* this should check for a valid value, then
     1) change the scrollbar,
     2) call valueChanged 
     */
  float new_value;
  char *call_data = XmTextFieldGetString(w);

  if (!sscanf(call_data,"%f",&new_value)) 
    XBell(XtDisplay(self),100);
  else if ((new_value>=((XltEntrySBWidget)self)->xltEntrySB.internal_min && new_value<=((XltEntrySBWidget)self)->xltEntrySB.internal_max) ||
	   (((XltEntrySBWidget)self)->xltEntrySB.internal_min>((XltEntrySBWidget)self)->xltEntrySB.internal_max && 
	    (new_value<=((XltEntrySBWidget)self)->xltEntrySB.internal_min && new_value>=((XltEntrySBWidget)self)->xltEntrySB.internal_max))) {
    ((XltEntrySBWidget)self)->xltEntrySB.internal_value=new_value;
    XtCallCallbackList(self, ((XltEntrySBWidget)self)->xltEntrySB.valueChanged, (XtPointer)call_data); 
  }
  else 
    XBell(XtDisplay(self),100);

  update_display(self);
}
#line 219 "EntrySB.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 219 "EntrySB.w"
static void scroll_CB(Widget  w,Widget self,XmScaleCallbackStruct * call_data)
#else
#line 219 "EntrySB.w"
static void scroll_CB(w,self,call_data)Widget  w;Widget self;XmScaleCallbackStruct * call_data;
#endif
#line 220 "EntrySB.w"
{
  /* convert from fraction, update the text entry area,
     and call valueChanged */
  ((XltEntrySBWidget)self)->xltEntrySB.internal_value=((float)(call_data->value)/100.0)*
    (((XltEntrySBWidget)self)->xltEntrySB.internal_max-((XltEntrySBWidget)self)->xltEntrySB.internal_min)+((XltEntrySBWidget)self)->xltEntrySB.internal_min;
  update_display(self);
  XtCallCallbackList(self, ((XltEntrySBWidget)self)->xltEntrySB.valueChanged, (XtPointer)((XltEntrySBWidget)self)->xltEntrySB.value_buf);
}
#line 234 "EntrySB.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 234 "EntrySB.w"
static void focusCB(Widget  w,XtPointer  client,XmAnyCallbackStruct * call)
#else
#line 234 "EntrySB.w"
static void focusCB(w,client,call)Widget  w;XtPointer  client;XmAnyCallbackStruct * call;
#endif
#line 235 "EntrySB.w"
{
  XmTextFieldSetSelection(w,0,XmTextFieldGetLastPosition(w),
			  XtLastTimestampProcessed(XtDisplay(w)));
}
#line 244 "EntrySB.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 244 "EntrySB.w"
static void update_display(Widget self)
#else
#line 244 "EntrySB.w"
static void update_display(self)Widget self;
#endif
#line 245 "EntrySB.w"
{
  float new_val;
  char fmt[10];

  new_val=(((XltEntrySBWidget)self)->xltEntrySB.internal_value-((XltEntrySBWidget)self)->xltEntrySB.internal_min)/(((XltEntrySBWidget)self)->xltEntrySB.internal_max-((XltEntrySBWidget)self)->xltEntrySB.internal_min);
  if (new_val<0.0)
    new_val=0.0;
  if (new_val>1.0)
    new_val=1.0;
  XmScaleSetValue(((XltEntrySBWidget)self)->xltEntrySB.scrollbar, (int)floor((double)(0.5+(new_val*100.0f))));
  
  sprintf(fmt,"%%%d.%df",((XltEntrySBWidget)self)->xltEntrySB.textWidth,((XltEntrySBWidget)self)->xltEntrySB.decimals);
  ((XltEntrySBWidget)self)->xltEntrySB.value=((XltEntrySBWidget)self)->xltEntrySB.value_buf;
  sprintf(((XltEntrySBWidget)self)->xltEntrySB.value,fmt, ((XltEntrySBWidget)self)->xltEntrySB.internal_value);
  XmTextFieldSetString(((XltEntrySBWidget)self)->xltEntrySB.text,((XltEntrySBWidget)self)->xltEntrySB.value);
  XmTextFieldSetSelection(((XltEntrySBWidget)self)->xltEntrySB.text,0,strlen(((XltEntrySBWidget)self)->xltEntrySB.value),
			  XtLastTimestampProcessed(XtDisplay(self)));
}

static XtResource resources[] = {
#line 14 "EntrySB.w"
{XtNminval,XtCMinval,XtRString,sizeof(((XltEntrySBRec*)NULL)->xltEntrySB.minval),XtOffsetOf(XltEntrySBRec,xltEntrySB.minval),XtRImmediate,(XtPointer)"0.0"},
#line 15 "EntrySB.w"
{XtNmaxval,XtCMaxval,XtRString,sizeof(((XltEntrySBRec*)NULL)->xltEntrySB.maxval),XtOffsetOf(XltEntrySBRec,xltEntrySB.maxval),XtRImmediate,(XtPointer)"100.0"},
#line 16 "EntrySB.w"
{XtNdecimals,XtCDecimals,XtRInt,sizeof(((XltEntrySBRec*)NULL)->xltEntrySB.decimals),XtOffsetOf(XltEntrySBRec,xltEntrySB.decimals),XtRImmediate,(XtPointer)0 },
#line 18 "EntrySB.w"
{XtNvalue,XtCValue,XtRString,sizeof(((XltEntrySBRec*)NULL)->xltEntrySB.value),XtOffsetOf(XltEntrySBRec,xltEntrySB.value),XtRImmediate,(XtPointer)"0.0"},
#line 23 "EntrySB.w"
{XtNscrollWidth,XtCScrollWidth,XtRDimension,sizeof(((XltEntrySBRec*)NULL)->xltEntrySB.scrollWidth),XtOffsetOf(XltEntrySBRec,xltEntrySB.scrollWidth),XtRImmediate,(XtPointer)200 },
#line 26 "EntrySB.w"
{XtNheight,XtCHeight,XtRDimension,sizeof(((XltEntrySBRec*)NULL)->core.height),XtOffsetOf(XltEntrySBRec,core.height),XtRImmediate,(XtPointer)0 },
#line 28 "EntrySB.w"
{XtNtextWidth,XtCTextWidth,XtRInt,sizeof(((XltEntrySBRec*)NULL)->xltEntrySB.textWidth),XtOffsetOf(XltEntrySBRec,xltEntrySB.textWidth),XtRImmediate,(XtPointer)7 },
#line 30 "EntrySB.w"
{XtNlabel,XtCLabel,XtRString,sizeof(((XltEntrySBRec*)NULL)->xltEntrySB.label),XtOffsetOf(XltEntrySBRec,xltEntrySB.label),XtRImmediate,(XtPointer)NULL },
#line 34 "EntrySB.w"
{XtNvalueChanged,XtCValueChanged,XtRCallback,sizeof(((XltEntrySBRec*)NULL)->xltEntrySB.valueChanged),XtOffsetOf(XltEntrySBRec,xltEntrySB.valueChanged),XtRImmediate,(XtPointer)NULL },
};

XltEntrySBClassRec xltEntrySBClassRec = {
{ /* core_class part */
/* superclass   	*/  (WidgetClass) &xmManagerClassRec,
/* class_name   	*/  "XltEntrySB",
/* widget_size  	*/  sizeof(XltEntrySBRec),
/* class_initialize 	*/  NULL,
/* class_part_initialize*/  _resolve_inheritance,
/* class_inited 	*/  FALSE,
/* initialize   	*/  initialize,
/* initialize_hook 	*/  NULL,
/* realize      	*/  XtInheritRealize,
/* actions      	*/  NULL,
/* num_actions  	*/  0,
/* resources    	*/  resources,
/* num_resources 	*/  9,
/* xrm_class    	*/  NULLQUARK,
/* compres_motion 	*/  False ,
/* compress_exposure 	*/  FALSE ,
/* compress_enterleave 	*/  False ,
/* visible_interest 	*/  False ,
/* destroy      	*/  NULL,
/* resize       	*/  XtInheritResize,
/* expose       	*/  XtInheritExpose,
/* set_values   	*/  set_values,
/* set_values_hook 	*/  NULL,
/* set_values_almost 	*/  XtInheritSetValuesAlmost,
/* get_values+hook 	*/  NULL,
/* accept_focus 	*/  XtInheritAcceptFocus,
/* version      	*/  XtVersion,
/* callback_private 	*/  NULL,
/* tm_table      	*/  NULL,
/* query_geometry 	*/  XtInheritQueryGeometry,
/* display_acceleator 	*/  XtInheritDisplayAccelerator,
/* extension    	*/  NULL 
},
{ /* composite_class part */
XtInheritGeometryManager,
XtInheritChangeManaged,
XtInheritInsertChild,
XtInheritDeleteChild,
NULL
},
{ /* constraint_class part */
/* constraint_resources     */  NULL,
/* num_constraint_resources */  0,
/* constraint_size          */  sizeof(XltEntrySBConstraintRec),
/* constraint_initialize    */  NULL,
/* constraint_destroy       */  NULL,
/* constraint_set_values    */  NULL,
/* constraint_extension     */  NULL 
},
{ /* XmManager class part */
#define manager_extension extension
/* translations                 */  XtInheritTranslations ,
/* syn_resources                */  NULL ,
/* num_syn_resources            */  0 ,
/* syn_constraint_resources     */  NULL ,
/* num_syn_constraint_resources */  0 ,
/* parent_process               */  XmInheritParentProcess,
/* manager_extension            */  NULL ,
},
{ /* XltEntrySB_class part */
 /* dummy */  0
},
};
WidgetClass xltEntrySBWidgetClass = (WidgetClass) &xltEntrySBClassRec;
static void _resolve_inheritance(class)
WidgetClass class;
{
  XltEntrySBWidgetClass c = (XltEntrySBWidgetClass) class;
  XltEntrySBWidgetClass super;
  static CompositeClassExtensionRec extension_rec = {
    NULL, NULLQUARK, XtCompositeExtensionVersion,
    sizeof(CompositeClassExtensionRec), True};
  CompositeClassExtensionRec *ext;
  ext = (XtPointer)XtMalloc(sizeof(*ext));
  *ext = extension_rec;
  ext->next_extension = c->composite_class.extension;
  c->composite_class.extension = ext;
  if (class == xltEntrySBWidgetClass) return;
  super = (XltEntrySBWidgetClass)class->core_class.superclass;
}
#line 47 "EntrySB.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 47 "EntrySB.w"
static void initialize(Widget  request,Widget self,ArgList  args,Cardinal * num_args)
#else
#line 47 "EntrySB.w"
static void initialize(request,self,args,num_args)Widget  request;Widget self;ArgList  args;Cardinal * num_args;
#endif
#line 48 "EntrySB.w"
{
  /*
  char tmp[25];
  char fmt[10];
  */
  Widget rowcol;
  /*
  float init_val;
  Position x, y;
  */
  Dimension h,w,width,height,label_height;
  int direction, font_ascent, font_descent;
  XCharStruct overall;

  XmFontList font_list;
  XFontStruct *font, **FontList;
  XtPointer FontPtr;
#if (XmREVISION <= 1)
  XmStringCharSet CharSet;
  XmFontContext FontContext;
#else
  XmFontType FontType;
#endif
  int NrOfFonts;
  char **FontNameList;
  
  if (!sscanf(((XltEntrySBWidget)self)->xltEntrySB.value,"%f",&((XltEntrySBWidget)self)->xltEntrySB.internal_value))
    return;
  if (!sscanf(((XltEntrySBWidget)self)->xltEntrySB.minval,"%f",&((XltEntrySBWidget)self)->xltEntrySB.internal_min))
    return;
  if (!sscanf(((XltEntrySBWidget)self)->xltEntrySB.maxval,"%f",&((XltEntrySBWidget)self)->xltEntrySB.internal_max))
    return;

  sprintf(((XltEntrySBWidget)self)->xltEntrySB.value_buf,((XltEntrySBWidget)self)->xltEntrySB.value);
  rowcol = XtVaCreateManagedWidget
    ("box", xmRowColumnWidgetClass, self,
     XmNorientation, XmHORIZONTAL,
     NULL);
  
  ((XltEntrySBWidget)self)->xltEntrySB.scrollbar = XtVaCreateManagedWidget
    ("scrollbar", xmScaleWidgetClass, rowcol,
     XmNscaleWidth, ((XltEntrySBWidget)self)->xltEntrySB.scrollWidth,
     XmNscaleHeight, 20,
     XmNorientation, XmHORIZONTAL,
     NULL);
  XtAddCallback(((XltEntrySBWidget)self)->xltEntrySB.scrollbar, XmNvalueChangedCallback, (XtCallbackProc) scroll_CB, self);
  XtAddCallback(((XltEntrySBWidget)self)->xltEntrySB.scrollbar, XmNdragCallback, (XtCallbackProc) scroll_CB, self);
  
  if (((XltEntrySBWidget)self)->xltEntrySB.label) {
    XmString xmstr;
    xmstr=XmStringCreateSimple(((XltEntrySBWidget)self)->xltEntrySB.label);
    XtVaSetValues(((XltEntrySBWidget)self)->xltEntrySB.scrollbar,
		  XmNtitleString, xmstr,
		  NULL);
    XmStringFree(xmstr);
    ((XltEntrySBWidget)self)->xltEntrySB.label_widget=XtNameToWidget(((XltEntrySBWidget)self)->xltEntrySB.scrollbar,"Title");

    /* all this shit just to get the font from Motif?! What the fuck? */
    XtVaGetValues(((XltEntrySBWidget)self)->xltEntrySB.label_widget,
		  XmNfontList, &font_list,
		  NULL);
#if (XmREVISION <= 1)
    XmFontListInitFontContext(&FontContext, font_list);
    XmFontListGetNextFont(FontContext, &CharSet, &font);
    XtFree(CharSet);
    XmFontListFreeFontContext(FontContext);
#else
    FontPtr = XmFontListEntryGetFont(font_list, &FontType);
    if ( FontType == XmFONT_IS_FONT )
      font = (XFontStruct *) FontPtr;
    else {
      NrOfFonts = XFontsOfFontSet((XFontSet) FontPtr,
				  &FontList, &FontNameList);
      font = FontList[0];
    }
#endif
      /* get label width and height */
      XTextExtents(font, ((XltEntrySBWidget)self)->xltEntrySB.label, strlen(((XltEntrySBWidget)self)->xltEntrySB.label), &direction,
		   &font_ascent, &font_descent, &overall);
      label_height=overall.ascent+overall.descent+4;
      w=overall.width+4;
      height=(label_height>20?2*label_height:40); /* 2*max height */
      width=(((XltEntrySBWidget)self)->xltEntrySB.scrollWidth>w?((XltEntrySBWidget)self)->xltEntrySB.scrollWidth:w);
  }
  else {
    height=20; /* scrollbar height */
    width=((XltEntrySBWidget)self)->xltEntrySB.scrollWidth;
  }

  ((XltEntrySBWidget)self)->xltEntrySB.text = XtVaCreateManagedWidget
    ("text", xmTextFieldWidgetClass, rowcol,
     XmNcolumns, ((XltEntrySBWidget)self)->xltEntrySB.textWidth+1,
     NULL);
  XtVaGetValues(((XltEntrySBWidget)self)->xltEntrySB.text,
		XtNwidth, &w,
		XtNheight, &h,
		NULL);
  self->core.width=w+10+width;
  if (((XltEntrySBWidget)self)->core.height)
    self->core.height=((XltEntrySBWidget)self)->core.height;
  else 
    self->core.height=(h>height?h+10:height+10);
  XtAddCallback(((XltEntrySBWidget)self)->xltEntrySB.text, XmNactivateCallback, (XtCallbackProc) activate_CB, self);
  XtAddCallback(((XltEntrySBWidget)self)->xltEntrySB.text,XmNfocusCallback,(XtCallbackProc)focusCB,NULL);
  update_display(self);
  ((XltEntrySBWidget)self)->xltEntrySB.manual_update=False;
}
#line 153 "EntrySB.w"
/*ARGSUSED*/
#if NeedFunctionPrototypes
#line 153 "EntrySB.w"
static Boolean  set_values(Widget  old,Widget  request,Widget self,ArgList  args,Cardinal * num_args)
#else
#line 153 "EntrySB.w"
static Boolean  set_values(old,request,self,args,num_args)Widget  old;Widget  request;Widget self;ArgList  args;Cardinal * num_args;
#endif
#line 154 "EntrySB.w"
{
  /*
  float new_val;
  */
  Boolean need_redraw = False;

  if (((XltEntrySBWidget)old)->xltEntrySB.minval != ((XltEntrySBWidget)self)->xltEntrySB.minval) {
    if (!sscanf(((XltEntrySBWidget)self)->xltEntrySB.minval,"%f",&((XltEntrySBWidget)self)->xltEntrySB.internal_min)) {
      XtError("MmwSetValues called with invalid minval");
      return FALSE;
    }
    else {
      update_display(self);
      need_redraw=TRUE;
    }
  }
  if (((XltEntrySBWidget)old)->xltEntrySB.maxval != ((XltEntrySBWidget)self)->xltEntrySB.maxval) {
    if (!sscanf(((XltEntrySBWidget)self)->xltEntrySB.maxval,"%f",&((XltEntrySBWidget)self)->xltEntrySB.internal_max)) {
      XtError("MmwSetValues called with invalid maxval");
      return FALSE;
    }
    else {
      update_display(self);
      need_redraw=TRUE;
    }
  }
  if (((XltEntrySBWidget)old)->xltEntrySB.value != ((XltEntrySBWidget)self)->xltEntrySB.value) {
    if (!sscanf(((XltEntrySBWidget)self)->xltEntrySB.value,"%f",&((XltEntrySBWidget)self)->xltEntrySB.internal_value)) {
      XtError("MmwSetValues called with invalid maxval");
      return FALSE;
    }
    else {
      update_display(self);
      need_redraw=TRUE;
    }
  }
  if (((XltEntrySBWidget)old)->xltEntrySB.decimals != ((XltEntrySBWidget)self)->xltEntrySB.decimals) {
    update_display(self);
    need_redraw=TRUE;
  }
  return need_redraw;
}
