text widgets - Motif

This is a discussion on text widgets - Motif ; Hi, I am using a text widget which must only display numbers and a possibly a decimal point in them (e.g. 1.233) If the user types a non numeric character then this character should not display in the text widget. ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: text widgets

  1. text widgets

    Hi, I am using a text widget which must only display numbers and a
    possibly a decimal point in them (e.g. 1.233) If the user types a non
    numeric character then this character should not display in the text
    widget. For example, at the moment the text widget may have keyboard
    focus and the user could type ctrl-s to perform some action - the
    action is performed but an unwanted 's' appears in the text widget
    which the user has to then delete.

    Any suggestions appreciated.


  2. Re: text widgets

    sallyroberts69@excite.com wrote:
    > Hi, I am using a text widget which must only display numbers and a
    > possibly a decimal point in them (e.g. 1.233) If the user types a non
    > numeric character then this character should not display in the text
    > widget. For example, at the moment the text widget may have keyboard
    > focus and the user could type ctrl-s to perform some action - the
    > action is performed but an unwanted 's' appears in the text widget
    > which the user has to then delete.


    Try sestting a custom modifyVerify callback for your text widget,
    for example modifyVerifyCallback: checkKbdInputCB(3)

    Then use this easily extensible function to check for anything you like.

    #define POSINTEGER 1
    #define INTEGER 2
    #define POSREAL 3
    #define REAL 4

    void checkKbdInputCB(Widget w, XtPointer clientData, XtPointer callData)
    {
    XmTextBlockRec *tblock;
    XmTextVerifyCallbackStruct *tvptr;
    int i, reason = atoi((char *) clientData);

    tvptr = (XmTextVerifyCallbackStruct *) callData;
    tblock = (XmTextBlockRec *) tvptr->text; switch (reason)
    switch (reason)
    {
    case POSINTEGER:
    for (i=0; ilength; i++)
    if (!isdigit(tblock->ptr[i]))
    tvptr->doit = FALSE;
    break;
    case INTEGER:
    for (i=0; ilength; i++)
    if (! (isdigit(tblock->ptr[i]) || (tblock->ptr[i]=='-') ))
    tvptr->doit = FALSE;
    break;
    case POSREAL:
    for (i=0; ilength; i++)
    if (! (isdigit(tblock->ptr[i]) || (tblock->ptr[i]=='.') ))
    tvptr->doit = FALSE;
    break;
    case REAL:
    for (i=0; ilength; i++)
    if (! (isdigit(tblock->ptr[i]) ||
    (tblock->ptr[i]=='.') ||
    (tblock->ptr[i]=='-') ))
    tvptr->doit = FALSE;
    break;
    }
    }

    But I am afraid that CTRL-S won't get through, either.
    You will have to work on that on your own, if that is
    important to you.

    Best regards,

    Dušan Peterc
    http://www.arahne.si

+ Reply to Thread