示例#1
0
文件: VXInput.c 项目: Rollmops/via
static void DispatchKeyPress (Widget w, VList callback_list,
			      XKeyPressedEvent *event,
			      Boolean *continue_to_dispatch)
{
    VXInputDataRec input_data;
    double row, column;
    VXInputCb *icb;
    char key[256];
    KeySym keySym;
    XComposeStatus compose;

    /* Determine the image coordinate of the user input: */
    if (VX_App.v.image == NULL ||
	!VImageViewClipToImage (VX_App.x.imageView, event->x, event->y,
				& row, & column)) {
	return;
    } else {
	input_data.row = (int) row;
	input_data.column = (int) column;
    }

    /* Set the input type: */
    input_data.input_type = VXIkeyPress;

    /* Find the ASCII code of the key being pressed: */
    (void) XLookupString(event, key, sizeof (key), &keySym, &compose);
    input_data.value =
	(keySym < XK_space || keySym > XK_asciitilde) ? 0 : key[0];

    /* Set the modifiers field: */
    /* ==> This relies on a correspondence between X and VX definitions. */
    input_data.modifiers = event->state;

    /* call each callback associated with the user input */
    icb = (VXInputCb *) VListFirst (callback_list);
    while (icb != NULL) {
	/* Call the callback function: */
	(icb->callback)(&input_data, icb->client_data);
	icb = (VXInputCb *) VListNext (callback_list);
    }
}
示例#2
0
文件: VXInput.c 项目: Rollmops/via
static void DispatchPointerMotion (Widget w, VList callback_list,
				   XMotionEvent *event,
				   Boolean *continue_to_dispatch)
{
    VXInputDataRec input_data;
    double row, column;
    VXInputCb *icb;
    int root_x, root_y, win_x, win_y;
    unsigned int keys_buttons;
    Window root, child;

    /* Only want hints: */
    XQueryPointer (XtDisplay(VX_App.x.imageView), XtWindow(VX_App.x.imageView),
		   &root, &child, &root_x, &root_y, &win_x, &win_y,
		   &keys_buttons);

    /* Determine the image coordinate of the user input: */
    if (VX_App.v.image == NULL ||
	!VImageViewClipToImage (VX_App.x.imageView, win_x, win_y,
				&row, &column)) {
	return;
    } else {
	input_data.row = (int) row;
	input_data.column = (int) column;
    }

    /* Set the input type: */
    input_data.input_type = VXIpointerMotion;

    /* Set the modifier field: */
    input_data.modifiers = (VXModifierMask) (event->state);

    /* Call each callback associated with the VXIpointerMotion user input: */
    icb = (VXInputCb *) VListFirst (callback_list);
    while (icb != NULL) {
	/* Call the callback function: */
	(icb->callback)(&input_data, icb->client_data);
	icb = (VXInputCb *) VListNext (callback_list);
    }
}
示例#3
0
文件: VXInput.c 项目: Rollmops/via
static void DispatchButtonPress (Widget w, VList callback_list,
				 XButtonPressedEvent *event,
				 Boolean *continue_to_dispatch)
{
    VXInputDataRec input_data;
    double row, column;
    VXInputCb *icb;

    /* Determine the image coordinate of the user input: */
    if (VX_App.v.image == NULL ||
	!VImageViewClipToImage (VX_App.x.imageView, event->x, event->y,
				&row, &column)) {
	return;
    } else {
	input_data.row = (int) row;
	input_data.column = (int) column;
    }

    /* Set the input type: */
    /* ==> This relies on a correspondence between X and VX definitions. */
    input_data.input_type = VXIbuttonPress;

    /* Set the value field to the button number: */
    /* ==> This relies on a correspondence between X and VX definitions. */
    input_data.value = event->button;

    /* Set the modifer field: */
    input_data.modifiers = event->state;

    /* call each callback associated with the VXIbuttonPress user input */
    icb = (VXInputCb *) VListFirst (callback_list);
    while (icb != NULL) {
	/* Call the callback function: */
	(icb->callback)(&input_data, icb->client_data);
	icb = (VXInputCb *) VListNext (callback_list);
    }
}
示例#4
0
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;
}