home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.windows.x
- Path: sparky!uunet!munnari.oz.au!uniwa!nodecg.ncc.telecomwa.oz.au!schnepp
- From: schnepp@nodecg.ncc.telecomwa.oz.au (Tom Schnepple)
- Subject: Validating Text Widgets
- Organization: Network Computer Centre
- Date: Thu, 23 Jul 1992 12:40:18 GMT
- Message-ID: <1992Jul23.124018.23513@nodecg.ncc.telecomwa.oz.au>
- Lines: 72
-
- Problem: Validating Text Widgets
-
- My application uses the MOTIF library and run under X. It has several text
- entry forms, and each text field needs to be validated and acted upon.
- What I want to do is to implement a text entry validation routine for
- these text widgets.
-
- The only appropriate callback resource for text widgets in my application
- is XmNlosingFocusCallback, so I have attached a callback to each of my text
- widgets as follow:
-
- XtAddCallback(text_widget, XmNlosingFocusCallback,
- text_callback, callback_data);
-
- In the callback routine (text_callback), I would check to see if the
- entered text is valid, if not, I would output an error message.
- After outputing the error message, I also want to put the focus back on
- the text widget that has called the callback routine so that the user
- can re-enter the text:
-
- void text_callback
- (
- Widget widget,
- caddr_t client_data,
- caddr_t call_data
- )
- {
- char ascii_text[10];
-
- /* get the text entered in the text widget and
- ** initialise the text in the ascii_text array
- */
- strcpy(ascii_text, XmTextGetString(widget));
-
- /* validate the entered text
- ** validate text are either "YES" or "NO"
- */
- if ((strcmp(ascii_text, "YES") != 0) or
- (strcmp(ascii_text, "NO") != 0))
- {
- /* outputing error messages
- */
- /* ...., code too complicated to add here */
-
- /* setting the focus at the widget so that
- ** the user can re-enter the text
- */
- XmProcessTraversal(widget,
- XmTRAVERSE_CURRENT);
- }
- }
-
- PROBLEM: I can't seem to be able to place the focus back to the text widget
- which is being validated. Since to be able to invoke the callback
- the user has to hit a Tab key to move to the next field
- (ie: callback is called when the text field has lost its focus).
- Thus, after the user has finished entering the text and hit the Tab
- key to move to the next field, the callback function was called and
- the focus was set back to the text field, but after the callback
- has finished, the Tab key action is processed and the focus is set
- to the next field.
-
- HELP Does anyone know how I can set the focus back the the text widget
- that is being validated?? Any help would be much appreciated!!
-
- Thanks in advance!!
-
-
- _--_|\ Tom Schnepple (schnepp@telecomwa.oz.au)
- / \ Perth, Western Australia
- --> *_.--._/
- v
-