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); }
static VBoolean WriteAttr (FILE *f, VAttrListPosn *posn, int indent, VList *data_list, long *offset) { int i; char *str; VRepnKind repn; VAttrList sublist; VBundle b; DataBlock *db; VTypeMethods *methods; size_t length; VPointer value; VBoolean result; VAttrListPosn subposn; /* Indent by the specified amount: */ for (i = 0; i < indent; i++) FailTest (fputc ('\t', f)); indent++; /* Output the attribute's name: */ FailTest (fprintf (f, "%s: ", VGetAttrName (posn))); /* Ouput its value: */ switch (repn = VGetAttrRepn (posn)) { case VAttrListRepn: VGetAttrValue (posn, NULL, VAttrListRepn, (VPointer) & sublist); result = WriteAttrList (f, sublist, indent, data_list, offset); break; case VBundleRepn: VGetAttrValue (posn, NULL, VBundleRepn, (VBundle) & b); if (! WriteString (f, b->type_name)) return FALSE; FailTest (fputc (' ', f)); /* If it's a typed value with binary data... */ if (b->length > 0) { /* Include "data" and "length" attributes in its attribute list: */ VPrependAttr (b->list, VLengthAttr, NULL, VLongRepn, (VLong) b->length); VPrependAttr (b->list, VDataAttr, NULL, VLongRepn, (VLong) *offset); /* Add it to the queue of binary data blocks to be written: */ *offset += b->length; db = VNew (DataBlock); db->posn = *posn; db->list = b->list; db->length = b->length; VListAppend (*data_list, db); } /* Write the typed value's attribute list: */ result = WriteAttrList (f, b->list, indent, data_list, offset); /* Remove the "data" and "length" attributes added earlier: */ if (b->length > 0) { VFirstAttr (b->list, & subposn); VDeleteAttr (& subposn); VDeleteAttr (& subposn); } break; case VStringRepn: VGetAttrValue (posn, NULL, VStringRepn, (VPointer) & str); result = WriteString (f, str); break; default: if (! (methods = VRepnMethods (repn)) || ! methods->encode_attr || ! methods->encode_data) { VWarning ("VWriteFile: " "%s attribute has unwriteable representation: %s", VGetAttrName (posn), VRepnName (repn)); return FALSE; } /* Write the type name: */ if (! WriteString (f, VRepnName (repn))) return FALSE; FailTest (fputc (' ', f)); /* Invoke the object type's encode_attr method to obtain an attribute list: */ VGetAttrValue (posn, NULL, repn, & value); sublist = (methods->encode_attr) (value, & length); /* If binary data is indicated... */ if (length > 0) { /* Include "data" and "length" attributes in the attr list: */ VPrependAttr (sublist, VLengthAttr, NULL, VLongRepn, (VLong) length); VPrependAttr (sublist, VDataAttr, NULL, VLongRepn, (VLong) *offset); *offset += length; } /* Add the object to the queue of binary data blocks to be written: */ db = VNew (DataBlock); db->posn = *posn; db->list = sublist; db->length = length; VListAppend (*data_list, db); /* Write the typed value's attribute list: */ result = WriteAttrList (f, sublist, indent, data_list, offset); /* Remove the "data" and "length" attributes added earlier: */ if (length > 0) { VFirstAttr (sublist, & subposn); VDeleteAttr (& subposn); VDeleteAttr (& subposn); } } /* Output a trailing newline: */ if (result) FailTest (fputc ('\n', f)); return result; Fail: VWarning ("VWriteFile: Write to stream failed"); return FALSE; }