Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!veritas!amdcad!sun!exodus!argv From: argv@turnpike.Eng.Sun.COM (Dan Heller) Newsgroups: comp.windows.x Subject: Re: Picture fields and Text Widgets Keywords: Picture fields Text widget Message-ID: <3758@exodus.Eng.Sun.COM> Date: 30 Nov 90 09:25:34 GMT References: Sender: news@exodus.Eng.Sun.COM Distribution: usa Organization: O'Reilly && Associates Lines: 49 In article emuleomo@paul.rutgers.edu (Emuleomo) writes: > Hi Xworld, interesting thought :-) > I need the ability to force every letter typed into a text widget to > UPPERCASE or force the text widget to accept only digits 0-9, or to coerce > data entry to be a telephone number in the style (999) 999-9999 etc.. > I need this to be done AS THE USER ENTERS THE DIGITS. So that the user > can enter 8005551212 and it will appear as (800) 555-1212. > Can this be done? text_w = XtVaCreateManagedWidget("name", xmTextWidgetClass, parent, XmNverifyBell, False, /* shouldn't this be the default? */ ... /* fill in other resource-values here */ NULL); ... XtAddCallback(text_w, XmNmodifyVerifyCallback, my_func, "data"); ... void my_func(text_w, data, cbs) Widget textsw; int *file_saved; XmTextVerifyCallbackStruct *cbs; { char c; if (cbs->reason == XmCR_MODIFYING_TEXT_VALUE) { c = cbs->text->ptr[0]; if (isupper(c)) cbs->doit = True; /* already upper case, let it go */ else { /* don't let the text widget do this one - we'll handle it */ cbs->doit = False; XmTextInsert(text_w, cbs->currInsert, toupper(c)); } } } You can figure out the rest. Note, #include for the isupper() and toupper() macros. > Please E-mail. stay tuned to the newsgroup :-) -- dan ---------------------------------------------------- O'Reilly && Associates argv@sun.com / argv@ora.com Opinions expressed reflect those of the author only.