home *** CD-ROM | disk | FTP | other *** search
- /*======================================================*/
- /* UIMSHOW.C */
- /* */
- /* (c) Copyright 1988 Ralf Brown. All Rights Reserved. */
- /*======================================================*/
-
- #include <string.h>
- #include "tvapi.h"
- #include "tvstream.h"
- #include "tvui.h"
-
- #define HEADER_SIZE 4
-
- /*======================================================*/
- /*======================================================*/
-
- static int default_test_function(OBJECT win,int status,char *fields)
- {
- (void) win ; /* prevent "unused parameter" warnings */
- (void) status ;
- (void) fields ;
- return MA_DONE ;
- }
-
- /*======================================================*/
- /*======================================================*/
-
- int pascal UImenu_show(void *menu,int reset,int (*test)(OBJECT,int,char *),char *result)
- {
- OBJECT window, kbd ;
- PARMLIST2 parms ;
- char *menu_values ;
- int num_fields = ((int *)menu)[1] ;
- int status, action ;
- int i ;
-
- /* start by sending the stream containing the menu setup, and storing away */
- /* the created window */
- window = TVwin_new(NIL,((char *)menu)[HEADER_SIZE+6],((char *)menu)[HEADER_SIZE+7]) ;
- TVwin_disallow(window,TV_HSIZE) ;
- TVwin_disallow(window,TV_VSIZE) ;
- parms.num_args = 2 ;
- parms.arg[0] = (DWORD)((char far *)menu) + HEADER_SIZE ; /* the stream starts here */
- parms.arg[1] = (DWORD) *((int *)menu) ; /* and is this long */
- TVsendmsg(WRITE_MSG,TOS,window,(PARMLIST *)&parms) ;
- if (reset)
- TVfld_reset(window) ;
- /* now get some storage for the flags indicating whether fields are selected */
- /* or not */
- if ((menu_values = (char *)malloc(num_fields+1)) == NULL)
- return NULL ;
- /* set up default test function if necessary */
- if (test == NULL)
- test = default_test_function ;
- /* create and connect keyboard to window containing menu, and go into field mode */
- kbd = TVkbd_new() ;
- TVkbd_open(kbd,window) ;
- TVkbd_setflags(kbd,KBD_FIELDMODE) ; /* don't want keyboard active */
- /* run through the menu until the user's test function says we're done */
- do {
- TVkbd_read(kbd,menu_values,num_fields+1) ;
- status = TVkbd_status(kbd) ;
- strcpy(result,menu_values) ; /* copy for return & comparison if changes */
- /* are to be made in the selected bits */
- action = (*test)(window,status,menu_values) ;
- if (action & MA_BEEP)
- TVsound(1000,4) ; /* same note DV uses, but only 1/4 second */
- if (action & MA_RESET)
- TVfld_reset(window) ;
- if (action & MA_SELECT)
- {
- for (i = 0 ; i < num_fields; i++)
- if (result[i] != menu_values[i])
- TVfld_type(window,i+1,(TVqry_type(window,i+1) & ~ F_SELECTED) |
- ((menu_values[i] == 'Y') ? F_SELECTED : 0)) ;
- }
- } while ((action & MA_DONE) == 0) ;
- /* leave field mode and reconnect default keyboard to task's main window */
- TVkbd_clrflags(kbd,KBD_FIELDMODE) ;
- TVkbd_close(kbd) ;
- TVkbd_setflags(NIL,KBD_ACTIVE) ;
- /* and finally clean up and return the results */
- free(menu_values) ;
- TVkbd_free(kbd) ;
- TVwin_free(window) ;
- return status ;
- }
-
-