home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / windows / x / 14253 < prev    next >
Encoding:
Text File  |  1992-07-23  |  2.7 KB  |  82 lines

  1. Newsgroups: comp.windows.x
  2. Path: sparky!uunet!munnari.oz.au!uniwa!nodecg.ncc.telecomwa.oz.au!schnepp
  3. From: schnepp@nodecg.ncc.telecomwa.oz.au (Tom Schnepple)
  4. Subject: Validating Text Widgets
  5. Organization: Network Computer Centre
  6. Date: Thu, 23 Jul 1992 12:40:18 GMT
  7. Message-ID: <1992Jul23.124018.23513@nodecg.ncc.telecomwa.oz.au>
  8. Lines: 72
  9.  
  10. Problem: Validating Text Widgets 
  11.  
  12. My application uses the MOTIF library and run under X. It has several text
  13. entry forms, and each text field needs to be validated and acted upon.
  14. What I want to do is to implement a text entry validation routine for
  15. these text widgets.
  16.  
  17. The only appropriate callback resource for text widgets in my application
  18. is XmNlosingFocusCallback, so I have attached a callback to each of my text
  19. widgets as follow:
  20.  
  21. XtAddCallback(text_widget, XmNlosingFocusCallback,
  22.         text_callback, callback_data);
  23.  
  24. In the callback routine (text_callback), I would check to see if the 
  25. entered text is valid, if not, I would output an error message. 
  26. After outputing the error message, I also want to put the focus back on 
  27. the text widget that has called the callback routine so that the user 
  28. can re-enter the text:
  29.  
  30.     void   text_callback
  31.     (
  32.         Widget            widget,
  33.         caddr_t        client_data,
  34.         caddr_t         call_data
  35.     )
  36.     {
  37.           char          ascii_text[10];
  38.  
  39.         /* get the text entered in the text widget and
  40.         ** initialise the text in the ascii_text array
  41.         */
  42.           strcpy(ascii_text, XmTextGetString(widget));
  43.  
  44.         /* validate the entered text
  45.         ** validate text are either "YES" or "NO"
  46.         */
  47.           if ((strcmp(ascii_text, "YES") != 0) or
  48.             (strcmp(ascii_text, "NO")  != 0))
  49.             {
  50.                 /* outputing error messages
  51.                 */
  52.                   /* ...., code too complicated to add here */
  53.  
  54.                 /* setting the focus at the widget so that
  55.                 ** the user can re-enter the text
  56.                 */
  57.                   XmProcessTraversal(widget, 
  58.                             XmTRAVERSE_CURRENT);
  59.             }
  60.     }
  61.  
  62. PROBLEM: I can't seem to be able to place the focus back to the text widget 
  63.     which is being validated. Since to be able to invoke the callback 
  64.     the user has to hit a Tab key to move to the next field 
  65.     (ie: callback is called when the text field has lost its focus). 
  66.     Thus, after the user has finished entering the text and hit the Tab 
  67.     key to move to the next field, the callback function was called and 
  68.     the focus was set back to the text field, but after the callback 
  69.     has finished, the Tab key action is processed and the focus is set 
  70.     to the next field.
  71.             
  72. HELP    Does anyone know how I can set the focus back the the text widget 
  73.     that is being validated?? Any help would be much appreciated!!
  74.  
  75. Thanks in advance!!
  76.  
  77.  
  78.      _--_|\    Tom Schnepple  (schnepp@telecomwa.oz.au) 
  79.     /      \   Perth, Western Australia
  80. --> *_.--._/ 
  81.           v 
  82.