XMSPINBOXVALIDATEPOSITION(3)

πŸ“¦
version 2.5.2 Β· 2 versions
, in alpine 3.24, arch rolling, centos-stream 9, epel 10, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0

πŸ’– XmSpinBoxValidatePosition πŸ’–

okay bestie, we're in the library call section of the manual and today's main character is XmSpinBoxValidatePosition β€” the little utility that takes whatever chaotic thing a user typed into an XmSpinBox child and translates it into a valid position. no cap. let's get into it ✨


✨ NAME ✨

XmSpinBoxValidatePosition β€” translate the current value of the specified XmSpinBox child into a valid position πŸŽ€


🌸 SYNOPSIS 🌸

#include <Xm/SpinBox.h>
int XmSpinBoxValidatePosition(
Widget textfield,
int *position);

πŸ¦‹ DESCRIPTION πŸ¦‹

So XmSpinBoxValidatePosition is a utility function, and it's there for apps that wanna implement their own policy for tracking user modifications to editable XmSpinBox children of type XmNUMERIC. The specifics of when and how the user's modifications actually take effect? that's entirely up to the application, bestie. it's giving "you're on your own, but here's a helper" πŸ’…

  • text_field β€” this argument specifies the widget ID of the child of the XmSpinBox that's being modified. the requirement on text_field is that it holds the accessTextual trait (which is already a requirement for children of XmSpinBox anyway). this way, XmSpinBox can extract the string out of the text_field widget β€” even if it is not an XmTextField. iconic, honestly.
  • position β€” the location pointed to by the position argument gets assigned the result of the translation done by XmSpinBoxValidatePosition. first, XmSpinBoxValidatePosition checks to make sure this is an XmNUMERIC XmSpinBox child. if it is not, XSmpinBoxValidatePosition sets position to the current position and returns XmCURRENT_VALUE.

XmSpinBoxValidatePosition attempts to translate the input string to a floating point number. if this translation fails, XmSpinBoxValidatePosition sets position to the current position and returns XmCURRENT_VALUE. 😭

XmSpinBoxValidatePosition converts the floating point number to an integer using the XmNdecimalPoints resource. extra decimal places are truncated. the resulting integer is range checked to make sure it falls within the valid range defined by XmNminimumValue and XmNmaximumValue inclusive. if the input falls outside this range, XmSpinBoxValidatePosition sets position to the nearest limit and returns either XmMINIMUM_VALUE or XmMAXIMUM_VALUE. πŸ”₯

finally, XmSpinBoxValidatePosition checks the integer to make sure it belongs to the series defined by XmNminimumValue ... XmNminimumValue + ((n - 1) * XmNincrementValue). if the integer does not belong to this series, XmSpinBoxValidatePosition sets position to the nearest element which is less than or equal to the integer and returns XmINCREMENT_VALUE.

otherwise, XmSpinBoxValidatePosition assigns the integer to position and returns XmVALID_VALUE. slay ✨


πŸ‘‘ RETURN VALUE πŸ‘‘

XmSpinBoxValidatePosition returns the status of the validation. the set of possible values returned is as follows:

  • XmCURRENT_VALUE β€” Cannot convert, returning current position_value.
  • XmMINIMUM_VALUE β€” Less than min.
  • XmMAXIMUM_VALUE β€” More than max.
  • XmINCREMENT_VALUE β€” Not on increment.
  • XmVALID_VALUE β€” Okay. 🫢

πŸŽ€ EXAMPLES πŸŽ€

this first example demonstrates how the XmSpinBoxValidatePosition function could be used from inside an XmNmodifyVerifyCallback callback installed on the XmSpinBox or the XmSimpleSpinBox:

/*
 * Install a callback on a spin box arrow press.
 */
 XtAddCallback(sb, XmNmodifyVerifyCallback, ModifyVerifyCB, NULL);
 XtAddCallback(simple_sb, XmNmodifyVerifyCallback, ModifyVerifyCB, NULL);

with the callback doing:

void ModifyVerifyCB(widget, call_data, client_data) {
    XmSpinBoxCallbackStruct *cbs = (XmSpinBoxCallbackStruct*) call_data;
    int position;
    Widget textual = NULL;
    if (XtIsSubclass(w, xmSimpleSpinBoxWidgetClass))
    {
        Arg args[1];
        XtSetArg(args[0], XmNtextField, &textual);
        XtGetValues(w, args, 1);
    }
    else if (XtIsSubclass(w, xmSpinBoxWidgetClass))
      textual = cbs->widget;
    else
      textual = (Widget) NULL;

    ...

    if (XmSpinBoxValidatePosition(textual, &position) == XmCURRENT_VALUE)
      XBell(XtDisplay(w), 0);
    else
      cbs->position = position;
}

this second example demonstrates how the XmSpinBoxValidatePosition function could be used from inside an XmNactivateCallback callback installed on the TextField child of the XmSpinBox:

/*
 * Install a callback on a spin box arrow press.
 */
XtAddCallback(tf, XmNactivateCallback, ModifyVerifyChildCB, NULL);

with the callback doing:

void ModifyVerifyChildCB(widget, call_data, client_data) {
    int     position;
    Widget  textual = widget;
    Arg     args[1];

    if (XmSpinBoxValidatePosition (textual, &position) == XmCURRENT_VALUE)
      XBell(XtDisplay(widget), 0);

    /* Set the position constraint resource of the textfield */

    XtSetArg(args[0], XmNposition, position);
    XtSetValues(textual, args, 1);
}

🌈 SEE ALSO 🌈

XmSpinBox(3), XmCreateSpinBox(3)


and that's the whole page, bestie!! πŸ’œ this was the library call manual, filed under XmSpinBoxValidatePosition β€” go forth and validate those positions, you absolute icon πŸ‘‘πŸŒΈβœ¨