home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume2 / xscope / part01 / CanvasSelected.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-28  |  1.5 KB  |  57 lines

  1. #include "xsignal.h"
  2.  
  3. /* Set up callback proc for canvas label so that the sigpane structure
  4.    can be determined.  How to get the event data back ?  Lets try a
  5.    global variable - this code is not re-enterable or recursive ! */
  6.  
  7. void canvas_selected(canvas, event, params, nparams)
  8.     Widget        canvas;
  9.     XButtonEvent    *event;
  10.     String        *params;
  11.     Cardinal    *nparams;
  12. {
  13.     register int    x, y, t;
  14.     int nsamp, value;
  15.     char        buf[1], labval[40];
  16.     XButtonPressedEvent    *be = (XButtonPressedEvent *)event;
  17.     XKeyPressedEvent    *ke = (XKeyPressedEvent *)event;
  18.     Arg arg[10];
  19.     sigbox *pane;
  20.  
  21.     pane = panefromcanvas(canvas);
  22.         if( pane->s == NULL ) return;
  23.     x = event->x;
  24.     y = event->y;
  25.     switch (event->type)
  26.     {
  27.     case MotionNotify:
  28.         /* Canvas moved */
  29.         /* fprintf(stderr,"Mouse moved, x=%d y=%d\n",x,y); */
  30.         break;
  31.     case ButtonPress:
  32.         if (be->button == Button1) {
  33.             MapSample(pane,x,y,&nsamp, &value);
  34.             if( nsamp > pane->rmark ) return;
  35.             UnMark(pane,pane->lmark);
  36.             pane->lmark=nsamp;
  37.             Mark(pane,pane->lmark);
  38.         } else if (be->button == Button2) {
  39.             MapSample(pane,x,y,&nsamp, &value);
  40.             sprintf(&labval[0],"Sample %d Value %d",nsamp,value);
  41.                 XtSetArg( arg[0], XtNlabel, &labval[0]);
  42.             XtSetValues(pane->picksamp, arg, ONE);
  43.         } else if (be->button == Button3) {
  44.             MapSample(pane,x,y,&nsamp, &value);
  45.             if( nsamp < pane->lmark ) return;
  46.             UnMark(pane,pane->rmark);
  47.             pane->rmark=nsamp;
  48.             Mark(pane,pane->rmark);
  49.         }
  50.         break;
  51.     case KeyPress:
  52.         if (XLookupString(ke, buf, sizeof(buf), NULL, NULL) > 0)
  53.             fprintf(stderr,"Key '%c' pressed\n",buf[0]);
  54.         break;
  55.     }
  56. }
  57.