[comp.windows.x.motif] Forcing upper case on input

dennis@rs20dev.UUCP (Dennis Warheit) (01/09/91)

I am working on an application under SCO's OpenDeskTop version of Motif 1.0.
We are doing a fair amount of data entry for a database.  As a part of that I
am using XmText.  I want to force entry of some XmText characters to upper case.

I created the XmNmodifyVerifyCallback and in the callback I accessed the text
to be inserted via

	 XmTextVerifyPtr->XmTextBlock->ptr

and made that text all upper case.  I was able to access the text and seemed
to be able to change its case but when the callback completed the original
lower case text was displayed.  I am left to assume that that text is a copy
of the actual text to be inserted.

Two questions:

	1. Is my assumption about the nature of the insert text provided by
	the callback correct?

	2. How should (can) I go about forcing the input to upper case?

Thanks,

Dennis Warheit			dennis@rs20dev.uunet	uunet!rs20dev!dennis
Universal Instruments Corp

pjp@sloth.mlb.semi.harris.com (Pat J. Pinchera) (01/15/91)

In article <195@rs20dev.UUCP> dennis@rs20dev.UUCP (Dennis Warheit) writes:
>I am working on an application under SCO's OpenDeskTop version of Motif 1.0.
>We are doing a fair amount of data entry for a database.  As a part of that I
>am using XmText.  I want to force entry of some XmText characters to upper case.
>
>I created the XmNmodifyVerifyCallback and in the callback I accessed the text
>to be inserted via
>
>	 XmTextVerifyPtr->XmTextBlock->ptr
>
>and made that text all upper case.  I was able to access the text and seemed
>to be able to change its case but when the callback completed the original
>lower case text was displayed.  I am left to assume that that text is a copy
>of the actual text to be inserted.
>
>Two questions:
>
>	1. Is my assumption about the nature of the insert text provided by
>	the callback correct?
>

Yes, I believe so.

>	2. How should (can) I go about forcing the input to upper case?
>

Change the input character to upper case (i.e. upcase).

I tried to do something similar with the XmText widgets; I wanted to only
allow digits in a text field. Seems there is a field in the structure
called 'doit' that if set to False will not put the character in the text 
field.  You could enhance the following example for your application. 
Look at the currInsert, newInsert, startPos, and endPos position fields. 
Hope this helps.

Example follows:


After creating the text widget, in this case 'textWidget', 
add the modify callback:

XtAddCallback(textWidget, XmNmodifyVerifyCallback, ItzaNumberCB, NULL);

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
** ItzaNumber - will do a validation on text entries;
**		reference OSF/Motif Programmers Reference 1-846 to 847 
**		(Prentice-Hall)
**		take a look at the character that was entered by the user;
**		this entails casting three levels into the Motif structures
**		use the 'isdigit' system call to verify the entry.
**		Check the character for NULL (i.e. backspace) before performing
**		isdigit call (otherwise you get core dump!)
**		If character is NOT a digit, then set 'doit' to FALSE;
**		this will negate the action.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void ItzaNumberCB (Widget w, 
		    int client_data, 
		    XmTextVerifyCallbackStruct *callData)
{
	XmTextVerifyCal*kStruct 	*theText;
	XmTextBlock					theBlock;
	char						*theChar;

    theText = (XmTextVerifyCallbackStruct *)callData;
    theBlock = (XmTextBlock)theText->text;
    theChar = (char *)theBlock->ptr;

    if (theChar != NULL)				/* check for NULL */
    	if (!isdigit(*theChar) )
	{
    		printf("\007");				/* ring the BELL */
		theText->doit = FALSE;
	}
}


Patrick Pinchera
Interface & Control Systems
Melbourne, FL