New Resources Specific to XmNspinboxType of XmSPINBOX_USER_DEFINED

Name Class Type Default Access
XmNgetValueProc XmCGetValueProc SpinboxGetValueProc dynamic CSG
XmNgetValueData XmCGetValueData XtPointer NULL CSG
XmNshowValueProc XmCShowValueProc SpinboxShowValueProc dynamic CSG
XmNshowValueData XmCShowValueData XtPointer NULL CSG

all of the built-in types have built-in get and show functions, so the user need not set them except when setting XmNspinboxType to XmSPINBOX_USER_DEFINED.


XmNgetValueProc
If the built-in types don't fit the data you want to show, you can set XmNshowValueProc and XmNgetValueProc to show and get the value in the textfield. The XmNgetValueProc function converts a string in the programmer-specified format into a long.

typedef Boolean (SpinboxGetValueProc) (
   Widget spinbox,
   XtPointer client_data,
   const char *buffer,
   size_t buffer_len,
   long *num );
XmNgetValueProc takes a SpinboxGetValueProc function. Its parameters are:
  1. the spinbox (Widget).
  2. a user-defined pointer specified by XmNgetValueData. (XtPointer)
  3. a buffer holding the value of the textfield. (const char *)
  4. the length of the string in buffer. (size_t)
  5. a long* to store the converted value (long*).

If the conversion is successful, it should return True. If it fails, it should return False. If the function fails, the value will not be set and the spinbox's XmNvalueChangedCallbacks will not be called.

As a basic example, if the get_value function for XmSPINBOX_NUMBER had no decimal places, it could read:

Boolean default_get_value (
   Widget w,
   XtPointer client_data,
   const char *buffer,
   size_t buflen,
   long *value )
{
   errno = 0;
   *value = strtol ( buffer, NULL, 10 );
   return ( !errno );
}

and the get_value function for XmSPINBOX_CLOCK might read

Boolean clock_get_value (
   Widget w,
   XtPointer client_data,
   const char *buffer,
   size_t buflen,
   int *value )
{
   long hr, min=0;
   char *pchar;
   errno = 0;
   hr = strtol ( buffer, &pchar, 10 );
   if ( *pchar=':' )
      min = strtol ( ++pchar, &pchar, 10 );
   *value = hr*60 + min;
   return ( !errno );

Note that the checks to see if the value is within XmNminimum and XmNmaximum are handled by the Spinbox widget, so the XmNgetValueProc doesn't need to check for that.

XmNgetValueData
A pointer to data that the application can attach to the widget. The spinbox only uses this resource as the second parameter to the XmNgetValueProc function.

XmNshowValueProc
If the built-in types don't fit the data you want to show, you can set XmNshowValueProc and XmNgetValueProc to show and get the value in the textfield. The XmNshowValueProc function converts an integer into a programmer-specified format.

typedef void (SpinboxShowValueProc) (
   Widget spinbox,
   XtPointer client_data,
   long num,
   char *buffer,
   size_t maxlen );
XmNshowValueProc takes a SpinboxShowValueProc function. Its parameters are:
  1. the spinbox (Widget).
  2. a user-defined pointer specified by XmNshowValueData. (XtPointer)
  3. the value that needs to be converted to text for the textfield (long).
  4. a buffer to store the converted value (char*).
  5. the number of characters that buffer will hold, including zero terminator (size_t).

In practice, the maxlen will be no less than 128 characters, so space should never be a problem.

As an example, if the show_value function for XmSPINBOX_NUMBER had no decimal places, it might read:

void default_show_value (
   Widget w,
   XtPointer client_data,
   long value,
   char *buffer,
   size_t maxlen )
{
   (void) sprintf ( buffer "%ld", value );
}

and the show_value function for XmSPINBOX_CLOCK_HM might read:

void clock_show_value (
   Widget w,
   XtPointer client_data,
   long value,
   char *buffer,
   size_t maxlen )
{
   (void) sprintf ( buffer, "%02ld:%02ld", value/60, value%60 );
}

XmNshowValueData
A pointer to data that the application can attach to the widget. The spinbox only uses this resource as the second parameter to the XmNshowValueProc function.