# include "Ximage.h"

void Reorient (Graphic *graphic, Layout *layout, double X, double Y, int mode) {

  if (layout[0].expand == 0)
    layout[0].expand = 1;

  switch (mode) {
  case 0:
    if ((layout[0].X != X) || (layout[0].Y != Y)) {
      layout[0].X = X;
      layout[0].Y = Y;
    }
    break;
  case -1: 
    layout[0].expand--;
    if ((layout[0].expand == 0) || (layout[0].expand == -1))
      layout[0].expand = -2;
    if (layout[0].expand < -30) {
      fprintf (stderr, "can't get smaller!\n");
      layout[0].expand = -30;
      return;
    }
    layout[0].X = X;
    layout[0].Y = Y;
    break;
  case +1:
    layout[0].expand++;
    if ((layout[0].expand == 0) || (layout[0].expand == -1))
      layout[0].expand = 1;
    if (layout[0].expand > 30) {
      fprintf (stderr, "can't get bigger!\n");
      layout[0].expand = 30;
      return;
    }
    layout[0].X = X;
    layout[0].Y = Y;
    break;
  }

  Remap (graphic, layout, &layout[0].matrix);
  Refresh (graphic, layout, 0);
 
  XFlush (graphic[0].display);
}

# if (0) /* the "warp" function seems to be a problem on SUNs for some reason */
  XQueryPointer (graphic[0].display, graphic[0].window, &dummy1, &dummy1, &dummy2, &dummy2, &x, &y, &dummy3); 
  if ((x > layout[0].picture.x) && (x < layout[0].picture.x + layout[0].picture.dx) &&
      (y > layout[0].picture.y) && (y < layout[0].picture.y + layout[0].picture.dy) &&
      ((mouse_event[0].button == 2) || (mouse_event[0].button == 3))) {
    XWarpPointer (graphic[0].display, None, graphic[0].window, 0, 0, 0, 0, 
		  layout[0].picture.x + 0.5*layout[0].picture.dx,
		  layout[0].picture.y + 0.5*layout[0].picture.dy);
  }
# endif

