void VXAddInputCallback (VXInputType input_type, VXInputCallback callback, VPointer client_data) { VXInputCb *icb; XtEventHandler event_handler = NULL; EventMask event_mask = 0; if (! VX_App.initialized) VError ("VXAddInputCallback: VX not initialized"); if (VX_App.in_main_loop) VError ("VXAddInputCallback: Main event loop already started"); /* Check if callback is NULL: */ if (callback == NULL) VError ("VXAddInputCallback: Callback function cannot be NULL"); /* Check validity of input_type: */ if (input_type < 0 || input_type >= VXnInputTypes) VError ("VXAddInputCallback: Invalid input type %d", input_type); /* Allocate a structure to store callback and client_data: */ icb = VMalloc (sizeof (VXInputCb)); icb->callback = callback; icb->client_data = client_data; /* If the appropriate callback list is NULL, allocate space for the list and register the appropriate event handler */ if (l_input.input_cb_list[input_type] == NULL) { l_input.input_cb_list[input_type] = VListCreate (); switch (input_type) { case VXIkeyPress: event_handler = (XtEventHandler) DispatchKeyPress; event_mask = KeyPressMask; break; case VXIbuttonPress: event_handler = (XtEventHandler) DispatchButtonPress; event_mask = ButtonPressMask; break; case VXIbuttonRelease: event_handler = (XtEventHandler) DispatchButtonRelease; event_mask = ButtonReleaseMask; break; case VXIpointerMotion: event_handler = (XtEventHandler) DispatchPointerMotion; event_mask = PointerMotionMask | PointerMotionHintMask; break; default: break; } XtAddEventHandler (VX_App.x.imageView, event_mask, FALSE, event_handler, (XtPointer) l_input.input_cb_list[input_type]); } /* Add the callback structure to the appropriate list: */ VListAppend (l_input.input_cb_list[input_type], (VPointer) icb); }
VBoolean VWriteFile (FILE *f, VAttrList list) { DataBlock *db; VBundle b; VTypeMethods *methods; VRepnKind repn; VPointer value, ptr; VBoolean result, free_it; VList data_list; /* Write the FIL_Vista data file header, attribute list, and delimeter while queuing on data_list any binary data blocks to be written: */ long offset = 0; data_list = VListCreate (); FailTest (fprintf (f, "%s %d ", VFileHeader, VFileVersion)); if (! WriteAttrList (f, list, 1, &data_list, &offset)) { VListDestroy (data_list, VFree); return FALSE; } FailTest (fputs ("\n" VFileDelimiter, f)); fflush (f); /* Traverse data_list to write the binary data blocks: */ for (db = VListFirst (data_list); db; db = VListNext (data_list)) { repn = VGetAttrRepn (& db->posn); if (repn == VBundleRepn) { /* A typed value includes its binary data block explicitly: */ VGetAttrValue (& db->posn, NULL, VBundleRepn, & b); ptr = b->data; free_it = FALSE; } else { /* For any other representation, obtain the binary data block from its encode_data method: */ VGetAttrValue (& db->posn, NULL, repn, & value); methods = VRepnMethods (repn); ptr = (methods->encode_data) (value, db->list, db->length, & free_it); if (! ptr) goto Fail; } /* Write the binary data and free the buffer containing it if it was allocated temporarily by an encode_data method: */ if (db->length > 0) { result = fwrite (ptr, 1, db->length, f) == db->length; if (free_it) VFree (ptr); if (! result) goto Fail; } } VListDestroy (data_list, VFree); return TRUE; Fail: VWarning ("VWriteFile: Write to stream failed"); VListDestroy (data_list, VFree); return FALSE; }