jgarb@CSD360B.ERIM.ORG (Joe Garbarino) (08/02/89)
In xpert the following was written: > I would like to scroll the child in the viewport widget (Athena widget set > R3) under program control... Here are some context diffs for the Viewport.c file. The changes allow translation table definitions for moving the currently pointed at position to the lower left, right, upper left, right, or middle of the viewport. An example definition might be /* Translation table to handle button 1, 2, and 3 pushes. This maps event * to translation string. */ static char translations[] = "<Btn1Down>:MoveChildTo(LeftUpper)\n\ <Btn2Down>:MoveChildTo(Middle)\ <Btn3Down>:MoveChildTo(RightLower)\ "; Pressing button one would move the current cursor location to the upper left corner, button two would center the current cursor location, and button three would move the current cursor location to the right lower corner. Joe Garbarino ERIM P.O. Box 8618 Ann Arbor, Mi. 48107 (313)994-1200 x2508 jgarb@csd360b.erim.org --------------------CUT HERE----------------------CUT HERE--------------------- *** Viewport.c.orig Tue Mar 7 10:54:58 1989 --- Viewport.c Tue Mar 7 10:55:15 1989 *************** *** 53,58 **** --- 53,72 ---- }; #undef offset + static void MoveChildTo(), MoveChild(); + + /* Define action routine which will allow movement of managed child + * widget when an event occurs. The action routine expects one + * argument which specifies where to move the child to. Choices are + * LeftUpper, RightUpper, LeftLower, RightLower, or Middle. If no + * argument is supplied, the routine moves the cursor to the middle of + * the viewport. + */ + static XtActionsRec actionTable[] = + { + {"MoveChildTo", MoveChildTo}, + }; + static void Initialize(), ConstraintInitialize(), Realize(), Resize(), ChangeManaged(); static Boolean SetValues(), DoLayout(); *************** *** 70,77 **** /* initialize */ Initialize, /* initialize_hook */ NULL, /* realize */ Realize, ! /* actions */ NULL, ! /* num_actions */ 0, /* resources */ resources, /* num_resources */ XtNumber(resources), /* xrm_class */ NULLQUARK, --- 84,91 ---- /* initialize */ Initialize, /* initialize_hook */ NULL, /* realize */ Realize, ! /* actions */ actionTable, ! /* num_actions */ XtNumber(actionTable), /* resources */ resources, /* num_resources */ XtNumber(resources), /* xrm_class */ NULLQUARK, *************** *** 358,364 **** --- 372,425 ---- clip->core.height, child->core.height ); } + static void MoveChildTo(widget, event, params, num_params) + Widget widget; + XEvent *event; + String *params; + Cardinal *num_params; + { + /* Restrict events allowed to ones with x and y location fields. */ + if ((event->type == ButtonPress) || + (event->type == ButtonRelease) || + (event->type == EnterNotify) || + (event->type == LeaveNotify) || + (event->type == KeyPress) || + (event->type == KeyRelease) || + (event->type == MotionNotify)) + { + ViewportWidget viewport = (ViewportWidget) widget->core.parent; + Widget clip = viewport->viewport.clip; + + /* Call MoveChild routine, using clip widget and event to calculate + * appropriate parameters. + */ + if ((*num_params == 0) || (strcmp(*params, "Middle") == 0)) + MoveChild(viewport, + (clip->core.width / 2) - event->xbutton.x, + (clip->core.height / 2) - event->xbutton.y); + + else if (strcmp(*params, "LeftUpper") == 0) + MoveChild(viewport, + -event->xbutton.x, + -event->xbutton.y); + + else if (strcmp(*params, "RightUpper") == 0) + MoveChild(viewport, + clip->core.width-event->xbutton.x, + -event->xbutton.y); + + else if (strcmp(*params, "LeftLower") == 0) + MoveChild(viewport, + -event->xbutton.x, + clip->core.height-event->xbutton.y); + + else if (strcmp(*params, "RightLower") == 0) + MoveChild(viewport, + clip->core.width-event->xbutton.x, + clip->core.height-event->xbutton.y); + } + } static void MoveChild(w, x, y) ViewportWidget w;