# include "Ximage.h"

int 
InterpretPresses (graphic, layout, event)
Graphic        graphic[];
Layout         layout[];
XButtonEvent   event[];
{

  int             status, done, this_button, x, y, old_cursor;
  KeySym          keysym;
  Button         *button;

  status = TRUE;
  this_button = event[0].button;
  
  if ((event[0].type == ButtonPress) && InPicture (event, &layout[0].picture)) {
    Reorient (graphic, layout, event);
  }

  if ((event[0].type == ButtonPress) && InPicture (event, &layout[0].cmapbar)) {
    DragColorbar (graphic, layout, event);
  }

  /* if on an exisiting button, Invert, wait for release, then go (or not) */
  if ((button = CheckButtons (event, layout)) != (Button *) NULL) {
    InvertButton (graphic, button); 
    done = FALSE;
    while (!done) { /* wait for release of this button */
      XNextEvent (graphic[0].display, (XEvent *) event);
      if ((event[0].type == ButtonRelease) && (event[0].button == this_button)) {
	done = TRUE;
      }
    }
    DrawButton (graphic, button);
    if (InButton (event, button)) {
      switch (event[0].button) {
      case 1:
	status = button[0].function_1(graphic, layout);
	break;
      case 2:
	status = button[0].function_2(graphic, layout);
	break;
      case 3:
	status = button[0].function_3(graphic, layout);
	break;
      }
    }
    else {
      return (status);
    }
  }

  return (status);

}

