[comp.sources.x] v12i023: tgif, Part07/23

william@CS.UCLA.EDU (William Cheng) (03/11/91)

Submitted-by: william@CS.UCLA.EDU (William Cheng)
Posting-number: Volume 12, Issue 23
Archive-name: tgif/part07

---------------------------------> cut here <---------------------------------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 7 (of 23)."
# Contents:  menu.c move.c msg.c
# Wrapped by william@oahu on Wed Mar  6 09:57:19 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'menu.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'menu.c'\"
else
echo shar: Extracting \"'menu.c'\" \(22340 characters\)
sed "s/^X//" >'menu.c' <<'END_OF_FILE'
X/*
X * Author:	William Chia-Wei Cheng (william@cs.ucla.edu)
X *
X * Copyright (C) 1990, 1991, William Cheng.
X */
X#ifndef lint
Xstatic char RCSid[] =
X      "@(#)$Header: /tmp_mnt/n/kona/tangram/u/william/X11/TGIF2/RCS/menu.c,v 2.0 91/03/05 12:47:32 william Exp $";
X#endif
X
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include <X11/Xutil.h>
X#include "const.h"
X#include "types.h"
X
X#include "box.e"
X#include "choice.e"
X#include "color.e"
X#include "cursor.e"
X#include "dialog.e"
X#include "drawing.e"
X#include "edit.e"
X#include "file.e"
X#include "font.e"
X#include "grid.e"
X#include "msg.e"
X#include "names.e"
X#include "obj.e"
X#include "pattern.e"
X#include "raster.e"
X#include "select.e"
X#include "setup.e"
X#include "special.e"
X#include "text.e"
X#include "version.e"
X
Xint	iconWindowCreated = FALSE;
Xint	iconWindowShown = FALSE;
X
Xextern char	* getenv ();
X
Xstatic int	savedZoomScale = 0, savedDrawOrigX = 0, savedDrawOrigY = 0;
Xstatic int	savedDrawWinW = 0, savedDrawWinH = 0, savedFileModified = FALSE;
X
Xstatic GC	textMenuGC;
Xstatic GC	pixmapMenuGC;
X
Xint TextMenuLoop (OrigX, OrigY, Strings, Entries, ForeColors, Valid, MultiColor)
X   int		OrigX, OrigY, Entries, * ForeColors, * Valid, MultiColor;
X   char		* Strings[];
X{
X   Window	window, root_win, child_win;
X   register int	i, max_len, menuing = TRUE;
X   int		x, y, rc = INVALID, old_selected, new_selected;
X   int		* len, dsp_w, dsp_h, menu_w, menu_h;
X   unsigned int	status;
X   int		root_x, root_y;
X   XEvent	input;
X   XSetWindowAttributes	win_attrs;
X
X   dsp_w = DisplayWidth (mainDisplay, mainScreen);
X   dsp_h = DisplayHeight (mainDisplay, mainScreen);
X
X   len = (int *) calloc (Entries, sizeof(int));
X   for(i = 0, max_len = 0; i < Entries; i++)
X   {
X      len[i] = strlen (Strings[i]);
X      if (len[i] > max_len) max_len = len[i];
X   }
X   menu_w = defaultFontWidth * max_len + 1;
X   menu_h = defaultFontHeight * Entries;
X
X   if (OrigX+menu_w >= dsp_w-1-2*brdrW)
X      OrigX = dsp_w - 1 - 2*brdrW - menu_w;
X   if (OrigY+menu_h >= dsp_h-1-2*brdrW)
X      OrigY = dsp_h - 1 - 2*brdrW - menu_h;
X
X   if ((window = XCreateSimpleWindow (mainDisplay, rootWindow, OrigX, OrigY,
X         menu_w, menu_h, 2*brdrW, myBorderPixel, myBgPixel)) == 0)
X   { printf ("Could not create desired menu window!\n"); exit (-1); }
X
X   win_attrs.save_under = True;
X   win_attrs.override_redirect = True;
X   XChangeWindowAttributes (mainDisplay, window,
X         CWSaveUnder | CWOverrideRedirect, &win_attrs);
X
X   old_selected = INVALID;
X
X   XSetTransientForHint (mainDisplay, window, mainWindow);
X   XMapWindow (mainDisplay, window);
X   XSelectInput (mainDisplay, window, ExposureMask);
X   XWarpPointer (mainDisplay, None, rootWindow, 0, 0, 0, 0, OrigX-2, OrigY-2);
X
X   XSync (mainDisplay, False);
X
X   XQueryPointer (mainDisplay, window, &root_win, &child_win, &root_x,
X         &root_y, &x, &y, &status);
X   if (!(menuing = ((status & BUTTONSMASK) != 0)))
X      while (XCheckWindowEvent (mainDisplay, window, ExposureMask, &input)) ;
X 
X   y = defaultFontAsc;
X   if (MultiColor)
X   {
X      for (i = 0; i < Entries; i++, y += defaultFontHeight)
X      {
X         XSetForeground (mainDisplay, textMenuGC, ForeColors[i]);
X         XDrawString (mainDisplay, window, textMenuGC, 0, y,
X               Strings[i], len[i]);
X      }
X   }
X   else
X   {
X      XSetForeground (mainDisplay, textMenuGC, ForeColors[0]);
X      for (i = 0; i < Entries; i++, y += defaultFontHeight)
X         XDrawString (mainDisplay, window, textMenuGC, 0, y,
X               Strings[i], len[i]);
X   }
X   XGrabPointer (mainDisplay, window, FALSE, None,
X         GrabModeAsync, GrabModeAsync, None, handCursor, CurrentTime);
X
X   while (menuing)
X   {
X      XQueryPointer (mainDisplay, window, &root_win, &child_win, &root_x,
X            &root_y, &x, &y, &status);
X      if ((status & BUTTONSMASK) == 0)
X      {
X         menuing = FALSE;
X         if (x >= 0 && x < menu_w && y >= 0 && y < menu_h)
X         {
X            rc = (int)(y / defaultFontHeight);
X            if (!Valid[rc]) rc = INVALID;
X         }
X         else
X            rc = INVALID;
X         XUngrabPointer (mainDisplay, CurrentTime);
X         break;
X      }
X      else if (x >= 0 && x < menu_w && y >=0 && y < menu_h)
X      {
X         new_selected = (int)(y / defaultFontHeight);
X         if (old_selected != new_selected )
X         {
X            if (old_selected != INVALID && Valid[old_selected])
X            {
X               XSetForeground (mainDisplay, textMenuGC, myBgPixel);
X               XFillRectangle (mainDisplay, window, textMenuGC, 0,
X                     old_selected*defaultFontHeight, menu_w, defaultFontHeight);
X               XSetForeground (mainDisplay, textMenuGC,
X                     ForeColors[old_selected]);
X               XDrawString (mainDisplay, window, textMenuGC, 0,
X                     defaultFontAsc+old_selected*defaultFontHeight,
X                     Strings[old_selected], len[old_selected]);
X            }
X            if (Valid[new_selected])
X            {
X               XSetForeground (mainDisplay, textMenuGC,
X                     ForeColors[new_selected]);
X               XFillRectangle (mainDisplay, window, textMenuGC, 0,
X                     new_selected*defaultFontHeight, menu_w, defaultFontHeight);
X               XSetForeground (mainDisplay, textMenuGC, myBgPixel);
X               XDrawString (mainDisplay, window, textMenuGC, 0,
X                     defaultFontAsc+new_selected*defaultFontHeight,
X                     Strings[new_selected], len[new_selected]);
X            }
X            old_selected = new_selected;
X         }
X      }
X      else if (old_selected != INVALID)
X      {
X         if (Valid[old_selected])
X         {
X            XSetForeground (mainDisplay, textMenuGC, myBgPixel);
X            XFillRectangle (mainDisplay, window, textMenuGC, 0,
X                  old_selected*defaultFontHeight, menu_w, defaultFontHeight);
X            XSetForeground (mainDisplay, textMenuGC, ForeColors[old_selected]);
X            XDrawString (mainDisplay, window, textMenuGC, 0,
X                  defaultFontAsc+old_selected*defaultFontHeight,
X                  Strings[old_selected], len[old_selected]);
X         }
X         old_selected = INVALID;
X      }
X   }
X   cfree (len);
X   cfree (ForeColors);
X   cfree (Valid);
X   XDestroyWindow (mainDisplay, window);
X
X   XSync (mainDisplay, False);
X   return (rc);
X}
X
Xint PxMpMenuLoop (OrigX, OrigY, W, H, Rows, Cols, Entries, ForeColors, PxMp,
X      MultiColor)
X   int		OrigX, OrigY, W, H, Rows, Cols, Entries;
X   int		* ForeColors, MultiColor;
X   Pixmap	PxMp[];
X{
X   register int	i, j, menuing = TRUE;
X   Window	window, root_win, child_win;
X   int		x, y, old_selected, new_selected, menu_w, menu_h;
X   int		rc = INVALID, old_i = 0, old_j = 0, k, toggle = 0, dsp_w, dsp_h;
X   unsigned int	status;
X   int		root_x, root_y;
X   XGCValues	values;
X   XEvent	input;
X   XSetWindowAttributes	win_attrs;
X
X   dsp_w = DisplayWidth (mainDisplay, mainScreen);
X   dsp_h = DisplayHeight (mainDisplay, mainScreen);
X
X   menu_w = W * Cols;
X   menu_h = H * Rows;
X
X   if (OrigX+menu_w >= dsp_w-1-2*brdrW)
X      OrigX = dsp_w - 1 - 2*brdrW - menu_w;
X   if (OrigY+menu_h >= dsp_h-1-2*brdrW)
X      OrigY = dsp_h - 1 - 2*brdrW - menu_h;
X
X   if ((window = XCreateSimpleWindow (mainDisplay, rootWindow, OrigX, OrigY,
X         menu_w, menu_h, 2*brdrW, myBorderPixel, myBgPixel)) == 0)
X   { printf ("Could not create desired menu window!\n"); exit (-1); }
X
X   win_attrs.save_under = True;
X   win_attrs.override_redirect = True;
X   XChangeWindowAttributes (mainDisplay, window,
X         CWSaveUnder | CWOverrideRedirect, &win_attrs);
X
X   old_selected = INVALID;
X
X   XSetTransientForHint (mainDisplay, window, mainWindow);
X   XMapWindow (mainDisplay, window);
X   XSelectInput (mainDisplay, window, ExposureMask);
X   XWarpPointer (mainDisplay, None, rootWindow, 0, 0, 0, 0, OrigX-2, OrigY-2);
X
X   XSync (mainDisplay, False);
X
X   XQueryPointer (mainDisplay, window, &root_win, &child_win, &root_x,
X         &root_y, &x, &y, &status);
X   if (!(menuing = ((status & BUTTONSMASK) != 0)))
X      while (XCheckWindowEvent (mainDisplay, window, ExposureMask, &input)) ;
X
X   for (i = 0; i < Rows; i++)
X      for (j = 0; j < Cols; j++)
X      {
X         k = i + j * Rows;
X         if (MultiColor)
X         {
X            if (k >= Entries)
X               values.foreground = myBgPixel;
X            else
X               values.foreground = ForeColors[k];
X            values.stipple = patPixmap[1];
X            XChangeGC (mainDisplay, rasterGC,
X                  GCForeground | GCStipple, &values);
X            XFillRectangle (mainDisplay, window, rasterGC, j*W, i*H, W, H);
X         }
X         else
X         {
X            XSetStipple (mainDisplay, rasterGC, PxMp[k]);
X            XFillRectangle (mainDisplay, window, rasterGC, j*W, i*H, W, H);
X         }
X      }
X
X   XGrabPointer (mainDisplay, window, FALSE, ButtonReleaseMask,
X         GrabModeAsync, GrabModeAsync, None, handCursor, CurrentTime);
X
X   while (menuing)
X   {
X      XQueryPointer (mainDisplay, window, &root_win, &child_win, &root_x,
X            &root_y, &x, &y, &status);
X      if ((status & BUTTONSMASK) == 0)
X      {
X         menuing = FALSE;
X         if (x >= 0 && x < menu_w && y >= 0 && y < menu_h)
X         {
X            i = (int)(y / H);
X            j = (int)(x / W);
X            rc = i + j * Rows;
X            if (rc >= Entries) rc = INVALID;
X         }
X         else
X            rc = INVALID;
X         XUngrabPointer (mainDisplay, CurrentTime);
X         break;
X      }
X      else if (x >= 0 && x < menu_w && y >=0 && y < menu_h)
X      {
X         i = (int)(y / H);
X         j = (int)(x / W);
X         new_selected = i + j * Rows;
X         if (old_selected != new_selected )
X         {
X            if (old_selected != INVALID)
X            {
X               if (MultiColor)
X               {
X                  if (old_selected >= Entries)
X                     values.foreground = myBgPixel;
X                  else
X                     values.foreground = ForeColors[old_selected];
X                  values.stipple = patPixmap[1];
X                  XChangeGC (mainDisplay, rasterGC,
X                        GCForeground | GCStipple, &values);
X                  XFillRectangle (mainDisplay, window, rasterGC,
X                        old_j*W, old_i*H, W, H);
X               }
X               else
X               {
X                  values.foreground = myFgPixel;
X                  values.stipple = PxMp[old_selected];
X                  XChangeGC (mainDisplay, rasterGC,
X                        GCForeground | GCStipple, &values);
X                  XFillRectangle (mainDisplay, window, rasterGC,
X                        old_j*W, old_i*H, W, H);
X               }
X            }
X            toggle = 0;
X            old_selected = new_selected;
X            old_i = i;
X            old_j = j;
X         }
X         else
X         {
X            toggle = !toggle;
X            values.foreground = toggle;
X            values.stipple = patPixmap[1];
X            XChangeGC (mainDisplay, rasterGC,
X                  GCForeground | GCStipple, &values);
X            MyBox (window, rasterGC, j*W, i*H, (j+1)*W-1, (i+1)*H-1);
X         }
X      }
X      else if (old_selected != INVALID)
X      {
X         if (MultiColor)
X         {
X            if (old_selected >= Entries)
X               values.foreground = myBgPixel;
X            else
X               values.foreground = ForeColors[old_selected];
X            values.stipple = patPixmap[1];
X            XChangeGC (mainDisplay, rasterGC,
X                  GCForeground | GCStipple, &values);
X            XFillRectangle (mainDisplay, window, rasterGC,
X                  old_j*W, old_i*H, W, H);
X         }
X         else
X         {
X            values.foreground = myFgPixel;
X            values.stipple = PxMp[old_selected];
X            XChangeGC (mainDisplay, rasterGC,
X                  GCForeground | GCStipple, &values);
X            XFillRectangle (mainDisplay, window, rasterGC,
X                  old_j*W, old_i*H, W, H);
X         }
X         old_selected = INVALID;
X      }
X   }
X   values.foreground = myFgPixel;
X   XChangeGC (mainDisplay, rasterGC, GCForeground, &values);
X
X   cfree (ForeColors);
X   XDestroyWindow (mainDisplay, window);
X
X   XSync (mainDisplay, False);
X   return (rc);
X}
X
Xstatic char * opStr[] =
X{
X   "more", "update", "vi", "init", "quit", "mainmenu", "animate",
X   "upd_attr_val", "green", "yellow"
X};
X#define MAXOP 10
X
Xvoid Prompt (PromptStr, OpName, FileName)
X   char	* PromptStr, * OpName, * FileName;
X{
X   char	inbuf[80];
X 
X   while (TRUE)
X   {
X      printf (PromptStr);
X      fgets (inbuf, 80, stdin);
X      sscanf (inbuf, "%s%s", OpName, FileName);
X      return;
X   }
X}
X
X#define MENU_MODE 0
X#define MENU_FILE 1
X#define MENU_EDIT 2
X#define MENU_STYLE 3
X#define MENU_SIZE 4
X#define MENU_FONT 5
X#define MENU_FONTDPI 6
X#define MENU_LAYOUT 7
X#define MENU_ARRANGE 8
X#define MENU_FILL 9
X#define MENU_LINESTYLE 10
X#define MENU_PEN 11
X#define MENU_COLOR 12
X#define MENU_SPECIAL 13
X
X#define MAXMENUS 14
X
Xstatic char	* mainMenuStr[MAXMENUS] =
X{
X   "Mode", "File", "Edit", "TextStyle", "TextSize", "Font", "FontDPI",
X   "Layout", "Arrange", "Fill", "LineStyle", "Pen", "Color", "Special"
X};
X
Xint MainMenu (Input)
X   XButtonEvent	* Input;
X{
X   int		rc = INVALID, index, * fore_colors, * valid, x, y;
X   Window	root_win, child_win;
X   unsigned int	status;
X   int		root_x, root_y;
X
X   Msg ("");
X   XQueryPointer (mainDisplay, rootWindow, &root_win, &child_win, &root_x,
X         &root_y, &x, &y, &status);
X
X   DefaultColorArrays (MAXMENUS, &fore_colors, &valid);
X   index = TextMenuLoop (x, y, mainMenuStr, MAXMENUS, fore_colors, valid,
X         SINGLECOLOR);
X
X   if (index == INVALID) return (INVALID);
X
X   if (index == MENU_COLOR && !colorDisplay)
X   {
X      Msg ("No color menu available for non-color displays.");
X      return (INVALID);
X   }
X
X   CornerLoop (&x, &y);
X   switch (index)
X   {
X      case MENU_MODE: ModeMenu (x, y); break;
X      case MENU_FILE: rc = FileMenu (x, y); break;
X      case MENU_EDIT: EditMenu (x, y); break;
X      case MENU_STYLE: StyleMenu (x, y); break;
X      case MENU_SIZE: SizeMenu (x, y); break;
X      case MENU_FONT: FontMenu (x, y); break;
X      case MENU_FONTDPI: FontDPIMenu (x, y); break;
X      case MENU_LAYOUT: LayoutMenu (x, y); break;
X      case MENU_ARRANGE: ArrangeMenu (x, y); break;
X      case MENU_FILL: FillMenu (x, y); break;
X      case MENU_LINESTYLE: LineStyleMenu (x, y); break;
X      case MENU_PEN: PenMenu (x, y); break;
X      case MENU_SPECIAL: SpecialMenu (x, y); break;
X      case MENU_COLOR: ColorMenu (x, y); break;
X   }
X   return (rc);
X}
X
Xvoid RedrawTitleWindow ()
X{
X   int	y, len, amount, left;
X   char	s[MAXPATHLENGTH];
X
X   strcpy (s, TOOL_NAME);
X   strcat (s, "-");
X   strcat (s, version_string);
X
X   len = strlen (s);
X   amount = defaultFontWidth * len;
X   left = (titleWindowW - amount) / 2;
X
X   XDrawString (mainDisplay, titleWindow, defaultGC, left, defaultFontAsc+2, s,
X         len);
X
X   for (y = 4; y < titleWindowH/2-4; y += 2)
X   {
X      XDrawLine (mainDisplay, titleWindow, defaultGC, 2, y,
X            left-defaultFontWidth, y);
X      XDrawLine (mainDisplay, titleWindow, defaultGC,
X            left+amount+defaultFontWidth, y, titleWindowW-3, y);
X   }
X
X   s[0] = '\0';
X   XClearArea (mainDisplay, titleWindow, 0, titleWindowH/2, titleWindowW,
X         titleWindowH/2, FALSE);
X   if (curFileDefined)
X   {
X      if (*curSymDir == '\0')
X         sprintf (s, "%s:%s/%s", curDomainName, curDir, curFileName);
X      else
X         sprintf (s, "%s:%s/%s", curDomainName, curSymDir, curFileName);
X   }
X   else
X      sprintf (s, "%s:[Unnamed]", curDomainName);
X
X   if (fileModified) strcat (s, " [Modified]");
X
X   if (s[0] != '\0')
X   {
X      len = strlen (s);
X      XDrawString (mainDisplay, titleWindow, defaultGC, 2,
X            titleWindowH/2+defaultFontAsc+2, s, len);
X   }
X}
X
Xstatic struct ObjRec	* iconTopObj = NULL, * iconBotObj = NULL;
X
Xvoid RedrawIconWindow ()
X{
X   register struct ObjRec	* obj_ptr;
X
X   for (obj_ptr = iconBotObj; obj_ptr != NULL; obj_ptr = obj_ptr->prev)
X      DrawObj (iconWindow, obj_ptr);
X}
X
Xstatic char iconFileName[] = "tgificon";
X
Xstatic
Xvoid InitIcon ()
X{
X   struct ObjRec	* obj_ptr;
X   char			s[MAXPATHLENGTH], * c_ptr;
X   FILE			* fp;
X   int			ltx = 0, lty = 0, rbx = 0, rby = 0, seen_obj = FALSE;
X   int			dx, dy, w, h;
X
X   strcpy (s, drawPath);
X   strcat (s, "/");
X   if ((c_ptr = getenv ("TGIFICON")) == NULL)
X      strcat (s, iconFileName);
X   else
X      if (strlen (c_ptr) >= 200)
X         /* too long, must be an error */
X         strcat (s, iconFileName);
X      else if (*c_ptr == '/')
X         strcpy (s, c_ptr);
X      else
X         strcat (s, c_ptr);
X   strcat (s, ".obj");
X
X   if ((fp = fopen (s, "r")) == NULL)
X   {
X      Msg ("Can not open the tangram icon file.");
X      return;
X   }
X
X   importingFile = TRUE; /* ignore the 'state' predicate */
X   while (ReadObj (fp, &obj_ptr, FALSE))
X      if (obj_ptr != NULL)
X      {
X         AddObj (NULL, topObj, obj_ptr);
X         if (!seen_obj)
X         {
X            seen_obj = TRUE;
X            ltx = obj_ptr->bbox.ltx; lty = obj_ptr->bbox.lty;
X            rbx = obj_ptr->bbox.rbx; rby = obj_ptr->bbox.rby;
X         }
X         else
X         {
X            if (obj_ptr->bbox.ltx < ltx) ltx = obj_ptr->bbox.ltx;
X            if (obj_ptr->bbox.lty < lty) lty = obj_ptr->bbox.lty;
X            if (obj_ptr->bbox.rbx > rbx) rbx = obj_ptr->bbox.rbx;
X            if (obj_ptr->bbox.rby > rby) rby = obj_ptr->bbox.rby;
X         }
X      }
X   importingFile = FALSE;
X
X   fclose (fp);
X
X   w = rbx - ltx;
X   h = rby - lty;
X   if (w > iconWindowW)
X   {
X      dx = -ltx;
X      iconWindowW = w;
X   }
X   else
X      dx = -ltx+(iconWindowW-w)/2;
X
X   if (h > iconWindowH)
X   {
X      dy = -lty;
X      iconWindowH = h;
X   }
X   else
X      dy = -lty+(iconWindowH-h)/2;
X
X   for (obj_ptr = topObj; obj_ptr != NULL; obj_ptr = obj_ptr->next)
X      MoveObj (obj_ptr, dx, dy);
X
X   iconTopObj = topObj;
X   iconBotObj = botObj;
X   topObj = botObj = NULL;
X}
X
Xvoid InitTitle ()
X{
X   InitIcon ();
X}
X
Xvoid InitMenu ()
X{
X   XGCValues	values;
X
X   values.foreground = myFgPixel;
X   values.background = myBgPixel;
X   values.fill_style = FillSolid;
X   values.font = defaultFontPtr->fid;
X   textMenuGC = XCreateGC (mainDisplay, rootWindow,
X         GCForeground | GCBackground | GCFillStyle | GCFont, &values);
X
X   values.fill_style = FillStippled;
X   pixmapMenuGC = XCreateGC (mainDisplay, rootWindow,
X         GCForeground | GCBackground | GCFillStyle, &values);
X}
X
Xvoid CleanUpMenu ()
X{
X   XFreeGC (mainDisplay, textMenuGC);
X   XFreeGC (mainDisplay, pixmapMenuGC);
X}
X
Xvoid SaveDrawWinInfo ()
X{
X   savedZoomScale = zoomScale;
X   savedDrawOrigX = drawOrigX;
X   savedDrawOrigY = drawOrigY;
X   savedDrawWinW = drawWinW;
X   savedDrawWinH = drawWinH;
X   savedFileModified = fileModified;
X}
X
Xvoid UnIconify ()
X{
X   if (!iconWindowShown) return;
X
X   XUnmapWindow (mainDisplay, iconBaseWindow);
X   iconWindowShown = FALSE;
X
X   zoomScale = savedZoomScale;
X   drawOrigX = savedDrawOrigX;
X   drawOrigY = savedDrawOrigY;
X   drawWinW = savedDrawWinW;
X   drawWinH = savedDrawWinH;
X   fileModified = savedFileModified;
X   UpdDrawWinBBox ();
X   XMapWindow (mainDisplay, mainWindow);
X   SetDefaultDrawWinClipRecs ();
X}
X
Xvoid Iconify ()
X{
X   XSizeHints	sizehints;
X   char		* c_ptr;
X   int		x, y, bitmask;
X   unsigned int	w, h;
X
X   if (iconWindowShown) return;
X   XUnmapWindow (mainDisplay, mainWindow);
X
X   if (!iconWindowCreated)
X   {
X      sizehints.flags = PPosition | PSize | PMinSize | PMaxSize;
X      sizehints.x = 0;
X      sizehints.y = 0;
X      sizehints.width = sizehints.min_width = sizehints.max_width =
X            iconWindowW+2*brdrW;
X      sizehints.height = sizehints.min_height = sizehints.max_height =
X            iconWindowH+2*brdrW;
X
X      if ((c_ptr = XGetDefault (mainDisplay, "Tgif", "IconGeometry")) != NULL)
X      {
X         bitmask = XParseGeometry (c_ptr, &x, &y, &w, &h);
X         if (bitmask & (XValue | YValue))
X         {
X            sizehints.flags |= USPosition;
X            if (bitmask & XValue) sizehints.x = x;
X            if (bitmask & YValue) sizehints.y = y;
X            if (bitmask & XNegative) sizehints.x += DisplayWidth (mainDisplay,
X                  mainScreen) - iconWindowW - 2*brdrW - 1;
X            if (bitmask & YNegative) sizehints.y += DisplayHeight (mainDisplay,
X                  mainScreen) - iconWindowH - 2*brdrW - 1;
X         }
X      }
X
X      if ((iconBaseWindow = XCreateSimpleWindow (mainDisplay, rootWindow,
X            sizehints.x, sizehints.y, iconWindowW+2*brdrW, iconWindowH+2*brdrW,
X            brdrW, myBorderPixel, myBgPixel)) == 0)
X      { printf ("Could not create icon window!\n"); exit(1); }
X
X      if ((iconWindow = XCreateSimpleWindow (mainDisplay, iconBaseWindow, 0, 0,
X            iconWindowW, iconWindowH, brdrW, myBorderPixel, myBgPixel)) == 0)
X      { printf ("Could not create icon window!\n"); exit(1); }
X
X      XSetNormalHints (mainDisplay, iconBaseWindow, &sizehints);
X
X      XSetTransientForHint (mainDisplay, iconBaseWindow, mainWindow);
X      iconWindowCreated = TRUE;
X   }
X
X   SaveDrawWinInfo ();
X   zoomScale = 0;
X   drawOrigX = 0;
X   drawOrigY = 0;
X   drawWinW = iconWindowW;
X   drawWinH = iconWindowH;
X   UpdDrawWinBBox ();
X
X   XMapWindow (mainDisplay, iconBaseWindow);
X   XSelectInput (mainDisplay, iconBaseWindow, StructureNotifyMask);
X   XMapWindow (mainDisplay, iconWindow);
X   XSelectInput (mainDisplay, iconWindow, ButtonPressMask | ExposureMask);
X   XSync (mainDisplay, False);
X   iconWindowShown = TRUE;
X
X   SetDefaultIconWinClipRecs ();
X}
X
Xvoid IconEventHandler (input)
X   XEvent	* input;
X{
X   XEvent	ev;
X
X   if ((input->xany.window == iconBaseWindow && input->type == UnmapNotify) ||
X         (input->xany.window == iconWindow && input->type == ButtonPress))
X      UnIconify ();
X   else if (input->xany.window == iconBaseWindow && input->type == MapNotify)
X      Iconify ();
X   else if (input->xany.window == iconWindow && input->type == Expose)
X   {
X      XSync (mainDisplay, False);
X      while (XCheckWindowEvent (mainDisplay, iconWindow, ExposureMask, &ev)) ;
X      while (XCheckWindowEvent (mainDisplay, iconBaseWindow,
X            StructureNotifyMask, &ev)) ;
X      RedrawIconWindow ();
X   }
X}
X
Xvoid TitleEventHandler (input)
X   XEvent	* input;
X{
X   XEvent	ev;
X
X   if (input->type == Expose)
X   {
X      XSync (mainDisplay, False);
X      while (XCheckWindowEvent (mainDisplay, titleWindow, ExposureMask, &ev)) ;
X      RedrawTitleWindow ();
X   }
X}
END_OF_FILE
if test 22340 -ne `wc -c <'menu.c'`; then
    echo shar: \"'menu.c'\" unpacked with wrong size!
fi
# end of 'menu.c'
fi
if test -f 'move.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'move.c'\"
else
echo shar: Extracting \"'move.c'\" \(14883 characters\)
sed "s/^X//" >'move.c' <<'END_OF_FILE'
X/*
X * Author:	William Chia-Wei Cheng (william@cs.ucla.edu)
X *
X * Copyright (C) 1990, 1991, William Cheng.
X */
X
X#ifndef lint
Xstatic char RCSid[] =
X      "@(#)$Header: /tmp_mnt/n/kona/tangram/u/william/X11/TGIF2/RCS/move.c,v 2.0 91/03/05 12:47:35 william Exp $";
X#endif
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include "const.h"
X#include "types.h"
X
X#include "arc.e"
X#include "attr.e"
X#include "cursor.e"
X#include "drawing.e"
X#include "dup.e"
X#include "grid.e"
X#include "obj.e"
X#include "oval.e"
X#include "raster.e"
X#include "rcbox.e"
X#include "ruler.e"
X#include "select.e"
X#include "setup.e"
X
Xstatic
Xvoid MovePoly (ObjPtr, Dx, Dy)
X   struct ObjRec	* ObjPtr;
X   int			Dx, Dy;
X{
X   register int	i;
X
X   for (i = 0; i < ObjPtr->detail.p->n; i++)
X   {
X      ObjPtr->detail.p->vlist[i].x += Dx;
X      ObjPtr->detail.p->vlist[i].y += Dy;
X   }
X   if (ObjPtr->detail.p->curved)
X      for (i = 0; i < ObjPtr->detail.p->sn; i++)
X      {
X         ObjPtr->detail.p->svlist[i].x += (Dx>>zoomScale);
X         ObjPtr->detail.p->svlist[i].y += (Dy>>zoomScale);
X      }
X}
X
Xstatic
Xvoid MovePolygon (ObjPtr, Dx, Dy)
X   struct ObjRec	* ObjPtr;
X   int			Dx, Dy;
X{
X   register int	i;
X
X   for (i = 0; i < ObjPtr->detail.g->n; i++)
X   {
X      ObjPtr->detail.g->vlist[i].x += Dx;
X      ObjPtr->detail.g->vlist[i].y += Dy;
X   }
X   if (ObjPtr->detail.g->curved)
X      for (i = 0; i < ObjPtr->detail.g->sn; i++)
X      {
X         ObjPtr->detail.g->svlist[i].x += (Dx>>zoomScale);
X         ObjPtr->detail.g->svlist[i].y += (Dy>>zoomScale);
X      }
X}
X
Xstatic
Xvoid MoveArc (ObjPtr, Dx, Dy)
X   struct ObjRec	* ObjPtr;
X   register int		Dx, Dy;
X{
X   register struct ArcRec	* arc_ptr = ObjPtr->detail.a;
X
X   arc_ptr->xc += Dx;  arc_ptr->yc += Dy;
X   arc_ptr->x1 += Dx;  arc_ptr->y1 += Dy;
X   arc_ptr->x2 += Dx;  arc_ptr->y2 += Dy;
X   arc_ptr->ltx += Dx; arc_ptr->lty += Dy;
X}
X
Xvoid MoveObj (ObjPtr, Dx, Dy)
X   struct ObjRec	* ObjPtr;
X   int			Dx, Dy;
X{
X   struct ObjRec	* ptr;
X
X   ObjPtr->x += Dx;
X   ObjPtr->y += Dy;
X   ObjPtr->bbox.ltx += Dx;
X   ObjPtr->bbox.lty += Dy;
X   ObjPtr->bbox.rbx += Dx;
X   ObjPtr->bbox.rby += Dy;
X   ObjPtr->obbox.ltx += Dx;
X   ObjPtr->obbox.lty += Dy;
X   ObjPtr->obbox.rbx += Dx;
X   ObjPtr->obbox.rby += Dy;
X   switch (ObjPtr->type)
X   {
X      case OBJ_POLY:
X         MoveAttrs(ObjPtr->fattr, Dx, Dy);
X         MovePoly (ObjPtr, Dx, Dy); 
X         break;
X      case OBJ_BOX : MoveAttrs(ObjPtr->fattr, Dx, Dy); break;
X      case OBJ_OVAL: MoveAttrs(ObjPtr->fattr, Dx, Dy); break;
X      case OBJ_TEXT: break;
X      case OBJ_POLYGON:
X         MoveAttrs(ObjPtr->fattr, Dx, Dy);
X         MovePolygon (ObjPtr, Dx, Dy);
X         break;
X      case OBJ_ARC:
X         MoveAttrs(ObjPtr->fattr, Dx, Dy);
X         MoveArc(ObjPtr, Dx, Dy);
X         break;
X      case OBJ_RCBOX: MoveAttrs(ObjPtr->fattr, Dx, Dy); break;
X      case OBJ_XBM: MoveAttrs(ObjPtr->fattr, Dx, Dy); break;
X      case OBJ_SYM:
X      case OBJ_ICON:
X      case OBJ_GROUP:
X         MoveAttrs(ObjPtr->fattr, Dx, Dy);
X         for (ptr = ObjPtr->detail.r->first; ptr != NULL; ptr = ptr->next)
X            MoveObj (ptr, Dx, Dy);
X         break;
X   }
X}
X
Xvoid MoveAllSel (Dx, Dy)
X   register int	Dx, Dy;
X{
X   register struct SelRec	* sel_ptr;
X
X   for (sel_ptr = topSel; sel_ptr != NULL; sel_ptr = sel_ptr->next)
X      MoveObj (sel_ptr->obj, Dx, Dy);
X}
X
Xvoid MoveSel (OrigX, OrigY, ObjPtr)
X   int 			OrigX, OrigY;
X   struct ObjRec	* ObjPtr;
X{
X   register int		i, num_pts = 0;
X   struct OvalRec	* oval_ptr;
X   struct PolyRec	* poly_ptr;
X   struct PolygonRec	* polygon_ptr;
X   struct ArcRec	* arc_ptr = NULL;
X   struct ObjRec	* arc_obj_ptr = NULL;
X   struct BBRec		bbox, o_bbox;
X   XPoint		* v = NULL;
X   int 			ltx = 0, lty = 0, rbx = 0, rby = 0;
X   int			sel_ltx, sel_lty, sel_rbx, sel_rby;
X   int			x, y, moving = TRUE, dx, dy;
X   int			w = 0, h = 0, angle1 = 0, angle2 = 0;
X   int			xc = 0, yc = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
X   int			grid_x = OrigX, grid_y = OrigY, radius = 0;
X   int			saved_xc = 0, saved_yc = 0, saved_x1 = 0, saved_y1 = 0;
X   int			saved_x2 = 0, saved_y2 = 0;
X   int			saved_ltx = 0, saved_lty = 0;
X   XEvent		input;
X
X   sel_ltx = OFFSET_X(selLtX) - 1; sel_lty = OFFSET_Y(selLtY) - 1;
X   sel_rbx = OFFSET_X(selRbX) + 1; sel_rby = OFFSET_Y(selRbY) + 1;
X
X   SelBox (drawWindow, revDefaultGC, sel_ltx, sel_lty, sel_rbx, sel_rby);
X
X   switch (ObjPtr->type)
X   {
X      case OBJ_BOX:
X      case OBJ_XBM:
X      case OBJ_TEXT:
X         ltx = OFFSET_X(ObjPtr->obbox.ltx); lty = OFFSET_Y(ObjPtr->obbox.lty);
X         rbx = OFFSET_X(ObjPtr->obbox.rbx); rby = OFFSET_Y(ObjPtr->obbox.rby);
X         SelBox (drawWindow, revDefaultGC, ltx, lty, rbx, rby);
X         break;
X      case OBJ_RCBOX:
X         ltx = OFFSET_X(ObjPtr->obbox.ltx); lty = OFFSET_Y(ObjPtr->obbox.lty);
X         rbx = OFFSET_X(ObjPtr->obbox.rbx); rby = OFFSET_Y(ObjPtr->obbox.rby);
X         radius = ObjPtr->detail.rcb->radius;
X         SetRCBoxVertex (ltx, lty, rbx, rby, radius);
X         MyRCBox (drawWindow, revDefaultGC, ltx, lty, rbx, rby, radius);
X         break;
X      case OBJ_ARC:
X         arc_obj_ptr = DupObj (ObjPtr);
X         arc_ptr = arc_obj_ptr->detail.a;
X         ltx = OFFSET_X(arc_ptr->ltx); lty = OFFSET_Y(arc_ptr->lty);
X         w = (arc_ptr->w)>>zoomScale; h = (arc_ptr->h)>>zoomScale;
X         angle1 = arc_ptr->angle1; angle2 = arc_ptr->angle2;
X         xc = OFFSET_X(arc_ptr->xc); yc = OFFSET_Y(arc_ptr->yc);
X         x1 = OFFSET_X(arc_ptr->x1); y1 = OFFSET_Y(arc_ptr->y1);
X         ArcRealX2Y2 (arc_ptr, &x2, &y2);
X         x2 = OFFSET_X(x2); y2 = OFFSET_Y(y2);
X         saved_xc = xc; saved_yc = yc;
X         saved_x1 = x1; saved_y1 = y1;
X         saved_x2 = x2; saved_y2 = y2;
X         saved_ltx = ltx; saved_lty = lty;
X         if (arc_ptr->fill != NONEPAT)
X         {
X            XDrawLine (mainDisplay, drawWindow, revDefaultGC, xc, yc, x1, y1);
X            XDrawLine (mainDisplay, drawWindow, revDefaultGC, xc, yc, x2, y2);
X         }
X         XDrawArc (mainDisplay, drawWindow, revDefaultGC, ltx, lty, w, h,
X               angle1, angle2);
X         break;
X      case OBJ_OVAL:
X         oval_ptr = ObjPtr->detail.o;
X         num_pts = 13;
X         bbox.ltx = OFFSET_X(ObjPtr->obbox.ltx);
X         bbox.lty = OFFSET_Y(ObjPtr->obbox.lty);
X         bbox.rbx = OFFSET_X(ObjPtr->obbox.rbx);
X         bbox.rby = OFFSET_Y(ObjPtr->obbox.rby);
X         MyOval (drawWindow, revDefaultGC, bbox);
X         break;
X      case OBJ_POLY:
X         poly_ptr = ObjPtr->detail.p;
X         num_pts = poly_ptr->n;
X         v = (XPoint *) calloc (poly_ptr->n, sizeof(XPoint));
X         for (i = 0; i < num_pts; i++)
X         {
X            v[i].x = OFFSET_X(poly_ptr->vlist[i].x);
X            v[i].y = OFFSET_Y(poly_ptr->vlist[i].y);
X         }
X         XDrawLines (mainDisplay, drawWindow, revDefaultGC, v, num_pts,
X               CoordModeOrigin);
X         break;
X      case OBJ_POLYGON:
X         polygon_ptr = ObjPtr->detail.g;
X         num_pts = polygon_ptr->n;
X         v = (XPoint *) calloc (polygon_ptr->n, sizeof(XPoint));
X         for (i = 0; i < num_pts; i++)
X         {
X            v[i].x = OFFSET_X(polygon_ptr->vlist[i].x);
X            v[i].y = OFFSET_Y(polygon_ptr->vlist[i].y);
X         }
X         XDrawLines (mainDisplay, drawWindow, revDefaultGC, v, num_pts,
X               CoordModeOrigin);
X         break;
X      case OBJ_GROUP:
X      case OBJ_SYM:
X      case OBJ_ICON:
X         ltx = OFFSET_X(ObjPtr->obbox.ltx); lty = OFFSET_Y(ObjPtr->obbox.lty);
X         rbx = OFFSET_X(ObjPtr->obbox.rbx); rby = OFFSET_Y(ObjPtr->obbox.rby);
X         SelBox (drawWindow, revDefaultGC, ltx, lty, rbx, rby);
X         break;
X   }
X
X   XGrabPointer (mainDisplay, drawWindow, FALSE,
X         PointerMotionMask | ButtonReleaseMask,
X         GrabModeAsync, GrabModeAsync, None, handCursor, CurrentTime);
X
X   dx = dy = 0;
X
X   while (moving)
X   {
X      XNextEvent (mainDisplay, &input);
X      if (input.type == ButtonRelease)
X      {
X         XUngrabPointer (mainDisplay, CurrentTime);
X         MarkRulers (grid_x, grid_y);
X         moving = FALSE;
X
X         switch (ObjPtr->type)
X         {
X            case OBJ_BOX:
X            case OBJ_XBM:
X            case OBJ_TEXT:
X               SelBox (drawWindow,revDefaultGC,ltx+dx,lty+dy,rbx+dx,rby+dy);
X               break;
X            case OBJ_RCBOX:
X               MyRCBox (drawWindow,revDefaultGC,ltx+dx,lty+dy,rbx+dx,rby+dy,
X                     radius);
X               break;
X            case OBJ_OVAL:
X               o_bbox.ltx = bbox.ltx + dx; o_bbox.lty = bbox.lty + dy;
X               o_bbox.rbx = bbox.rbx + dx; o_bbox.rby = bbox.rby + dy;
X               MyOval (drawWindow, revDefaultGC, o_bbox);
X               break;
X            case OBJ_ARC:
X               XDrawArc (mainDisplay, drawWindow, revDefaultGC, ltx, lty, w, h,
X                     angle1, angle2);
X               if (arc_ptr->fill != NONEPAT)
X               {
X                  XDrawLine (mainDisplay,drawWindow,revDefaultGC,xc,yc,x1,y1);
X                  XDrawLine (mainDisplay,drawWindow,revDefaultGC,xc,yc,x2,y2);
X               }
X               break;
X            case OBJ_POLY:
X            case OBJ_POLYGON:
X               for (i = 0; i < num_pts; i++)
X               {
X                  v[i].x += dx;
X                  v[i].y += dy;
X               }
X               XDrawLines (mainDisplay, drawWindow, revDefaultGC, v, num_pts,
X                     CoordModeOrigin);
X               for (i = 0; i < num_pts; i++)
X               {
X                  v[i].x -= dx;
X                  v[i].y -= dy;
X               }
X               break;
X            case OBJ_GROUP:
X            case OBJ_SYM:
X            case OBJ_ICON:
X               SelBox (drawWindow,revDefaultGC,ltx+dx,lty+dy,rbx+dx,rby+dy);
X               break;
X         }
X         SelBox (drawWindow, revDefaultGC, sel_ltx+dx, sel_lty+dy, sel_rbx+dx,
X               sel_rby+dy);
X
X         dx = grid_x - OrigX;
X         dy = grid_y - OrigY;
X
X         switch (ObjPtr->type)
X         {
X            case OBJ_ARC: FreeArcObj (arc_obj_ptr); break;
X            case OBJ_POLY:
X            case OBJ_POLYGON: cfree(v); break;
X         }
X         if (dx != 0 || dy != 0)
X         {
X            HighLightReverse ();
X            dx <<= zoomScale;
X            dy <<= zoomScale;
X            MoveAllSel (dx, dy);
X            RedrawAreas (botObj, selLtX-(1<<zoomScale), selLtY-(1<<zoomScale),
X                  selRbX+(1<<zoomScale), selRbY+(1<<zoomScale),
X                  selLtX-(1<<zoomScale)+dx, selLtY-(1<<zoomScale)+dy,
X                  selRbX+(1<<zoomScale)+dx, selRbY+(1<<zoomScale)+dy);
X            HighLightForward ();
X            UpdSelBBox ();
X            if (justDupped)
X            {
X               dupDx += dx;
X               dupDy += dy;
X            }
X            SetFileModified (TRUE);
X         }
X      }
X      else if (input.type == MotionNotify)
X      {
X         x = input.xmotion.x;
X         y = input.xmotion.y;
X         GridXY (x, y, &grid_x, &grid_y);
X
X         switch (ObjPtr->type)
X         {
X            case OBJ_BOX:
X            case OBJ_XBM:
X            case OBJ_TEXT:
X               SelBox (drawWindow,revDefaultGC,ltx+dx,lty+dy,rbx+dx,rby+dy);
X               break;
X            case OBJ_RCBOX:
X               MyRCBox (drawWindow,revDefaultGC,ltx+dx,lty+dy,rbx+dx,rby+dy,
X                     radius);
X               break;
X            case OBJ_ARC:
X               XDrawArc (mainDisplay, drawWindow, revDefaultGC, ltx, lty, w, h,
X                     angle1, angle2);
X               if (arc_ptr->fill != NONEPAT)
X               {
X                  XDrawLine (mainDisplay,drawWindow,revDefaultGC,xc,yc,x1,y1);
X                  XDrawLine (mainDisplay,drawWindow,revDefaultGC,xc,yc,x2,y2);
X               }
X               break;
X            case OBJ_OVAL:
X               o_bbox.ltx = bbox.ltx + dx; o_bbox.lty = bbox.lty + dy;
X               o_bbox.rbx = bbox.rbx + dx; o_bbox.rby = bbox.rby + dy;
X               MyOval (drawWindow, revDefaultGC, o_bbox);
X               break;
X            case OBJ_POLY:
X            case OBJ_POLYGON:
X               for (i = 0; i < num_pts; i++)
X               {
X                  v[i].x += dx;
X                  v[i].y += dy;
X               }
X               XDrawLines (mainDisplay, drawWindow, revDefaultGC, v, num_pts,
X                     CoordModeOrigin);
X               for (i = 0; i < num_pts; i++)
X               {
X                  v[i].x -= dx;
X                  v[i].y -= dy;
X               }
X               break;
X            case OBJ_GROUP:
X            case OBJ_SYM:
X            case OBJ_ICON:
X               SelBox (drawWindow,revDefaultGC,ltx+dx,lty+dy,rbx+dx,rby+dy);
X               break;
X         }
X         SelBox (drawWindow, revDefaultGC, sel_ltx+dx, sel_lty+dy, sel_rbx+dx,
X               sel_rby+dy);
X
X         dx = grid_x - OrigX;
X         dy = grid_y - OrigY;
X
X         MarkRulers (grid_x, grid_y);
X         SelBox (drawWindow, revDefaultGC, sel_ltx+dx, sel_lty+dy, sel_rbx+dx,
X               sel_rby+dy);
X         switch (ObjPtr->type)
X         {
X            case OBJ_BOX:
X            case OBJ_XBM:
X            case OBJ_TEXT:
X               SelBox (drawWindow,revDefaultGC,ltx+dx,lty+dy,rbx+dx,rby+dy);
X               break;
X            case OBJ_RCBOX:
X               SetRCBoxVertex (ltx+dx, lty+dy, rbx+dx, rby+dy, radius);
X               MyRCBox (drawWindow,revDefaultGC,ltx+dx,lty+dy,rbx+dx,rby+dy,
X                     radius);
X               break;
X            case OBJ_OVAL:
X               o_bbox.ltx = bbox.ltx + dx; o_bbox.lty = bbox.lty + dy;
X               o_bbox.rbx = bbox.rbx + dx; o_bbox.rby = bbox.rby + dy;
X               MyOval (drawWindow, revDefaultGC, o_bbox);
X               break;
X            case OBJ_ARC:
X               xc = saved_xc+dx; yc = saved_yc+dy;
X               x1 = saved_x1+dx; y1 = saved_y1+dy;
X               x2 = saved_x2+dx; y2 = saved_y2+dy;
X               ltx = saved_ltx+dx; lty = saved_lty+dy;
X               if (arc_ptr->fill != NONEPAT)
X               {
X                  XDrawLine (mainDisplay,drawWindow,revDefaultGC,xc,yc,x1,y1);
X                  XDrawLine (mainDisplay,drawWindow,revDefaultGC,xc,yc,x2,y2);
X               }
X               XDrawArc (mainDisplay, drawWindow, revDefaultGC, ltx, lty, w, h,
X                     angle1, angle2);
X               break;
X            case OBJ_POLY:
X            case OBJ_POLYGON:
X               for (i = 0; i < num_pts; i++)
X               {
X                  v[i].x += dx;
X                  v[i].y += dy;
X               }
X               XDrawLines (mainDisplay, drawWindow, revDefaultGC, v, num_pts,
X                     CoordModeOrigin);
X               for (i = 0; i < num_pts; i++)
X               {
X                  v[i].x -= dx;
X                  v[i].y -= dy;
X               }
X               break;
X            case OBJ_GROUP:
X            case OBJ_SYM:
X            case OBJ_ICON:
X               SelBox (drawWindow,revDefaultGC,ltx+dx,lty+dy,rbx+dx,rby+dy);
X               break;
X         }
X      }
X   }
X}
END_OF_FILE
if test 14883 -ne `wc -c <'move.c'`; then
    echo shar: \"'move.c'\" unpacked with wrong size!
fi
# end of 'move.c'
fi
if test -f 'msg.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'msg.c'\"
else
echo shar: Extracting \"'msg.c'\" \(3697 characters\)
sed "s/^X//" >'msg.c' <<'END_OF_FILE'
X/*
X * Author:	William Chia-Wei Cheng (william@cs.ucla.edu)
X *
X * Copyright (C) 1990, 1991, William Cheng.
X */
X#ifndef lint
Xstatic char RCSid[] =
X      "@(#)$Header: /tmp_mnt/n/kona/tangram/u/william/X11/TGIF2/RCS/msg.c,v 2.0 91/03/05 14:17:49 william Exp $";
X#endif
X
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include "const.h"
X#include "types.h"
X
X#include "font.e"
X#include "raster.e"
X#include "setup.e"
X
X#define MSG_ROWS 2
X
Xstruct MsgRec {
X   char			* s;
X   struct MsgRec	* next, * prev;
X};
X
Xstatic struct MsgRec	* topMsg = NULL, * botMsg = NULL;
Xstatic struct MsgRec	* mostRecentTopMsgPtr = NULL;
Xstatic int		msgCount = 0;
Xstatic int		topMsgNumber = 0, mostRecentTopMsgNumber = INVALID;
X
Xstatic
Xvoid AddMsg (Msg)
X   char	* Msg;
X{
X   char			* s;
X   struct MsgRec	* msg_ptr;
X
X   if (*Msg == '\0') { topMsgNumber = msgCount; return; }
X
X   s = (char *) calloc (strlen (Msg), sizeof(char));
X   msg_ptr = (struct MsgRec *) calloc (1, sizeof(struct MsgRec));
X
X   strcpy (s, Msg);
X   msg_ptr->s = s;
X
X   ++msgCount;
X   if (msgCount > topMsgNumber+MSG_ROWS) topMsgNumber = msgCount-MSG_ROWS;
X
X   msg_ptr->prev = botMsg;
X   msg_ptr->next = NULL;
X
X   if (botMsg == NULL)
X      topMsg = msg_ptr;
X   else
X      botMsg->next = msg_ptr;
X
X   botMsg = msg_ptr;
X}
X
Xvoid CleanUpMsg ()
X{
X   register struct MsgRec	* msg_ptr;
X
X   for (msg_ptr = botMsg; msg_ptr != NULL; msg_ptr = msg_ptr->prev)
X   {
X      cfree (msg_ptr->s);
X      cfree (msg_ptr);
X   }
X   topMsg = botMsg = mostRecentTopMsgPtr = NULL;
X   msgCount = topMsgNumber = 0;
X   mostRecentTopMsgNumber = INVALID;
X}
X
Xstatic
Xstruct MsgRec * FindMsg (Number)
X   int	Number;
X{
X   register int			i;
X   register struct MsgRec	* ptr = NULL;
X
X   if (Number >= msgCount)
X      return (botMsg);
X   else if (Number < 0)
X      return (topMsg);
X   else if (Number > (int)(msgCount/2))
X      for (i = msgCount-1, ptr = botMsg; i != Number; i--, ptr = ptr->prev) ;
X   else
X      for (i = 0, ptr = topMsg; i != Number; i++, ptr = ptr->next) ;
X
X   return (ptr);
X}
X
Xvoid RedrawMsg ()
X{
X   int			i, x, y;
X   XEvent       	ev;
X   struct MsgRec	* msg_ptr;
X
X   XClearWindow (mainDisplay, msgWindow);
X   XSync (mainDisplay, FALSE);
X   while (XCheckWindowEvent (mainDisplay, msgWindow, ExposureMask, &ev)) ;
X
X   if (topMsgNumber == msgCount) return;
X
X   x = 2;
X   y = 2 + defaultFontAsc;
X
X   mostRecentTopMsgPtr = msg_ptr = (topMsgNumber == mostRecentTopMsgNumber) ?
X         mostRecentTopMsgPtr : FindMsg (topMsgNumber);
X   mostRecentTopMsgNumber = topMsgNumber;
X
X   for (i = topMsgNumber; i < min(msgCount,topMsgNumber+MSG_ROWS); i++)
X   {
X      XDrawString (mainDisplay, msgWindow, defaultGC, x, y, msg_ptr->s,
X            strlen(msg_ptr->s));
X      msg_ptr = msg_ptr->next;
X      y += defaultFontHeight;
X   }
X   XSync (mainDisplay, FALSE);
X}
X
Xvoid Msg (Message)
X   char	* Message;
X{
X   AddMsg (Message);
X   RedrawMsg ();
X}
X
Xvoid TwoLineMsg (Msg1, Msg2)
X   char	* Msg1, * Msg2;
X{
X   AddMsg (Msg1);
X   AddMsg (Msg2);
X   RedrawMsg ();
X}
X
Xvoid MsgEventHandler (input)
X   XEvent	* input;
X{
X   XButtonEvent	* button_ev;
X   double	frac;
X
X   if (input->type == Expose)
X      RedrawMsg ();
X   else if (input->type == ButtonPress)
X   {
X      button_ev = &(input->xbutton);
X      if (button_ev->button == Button1)
X      {
X         if (topMsgNumber+1 >= msgCount) return;
X
X         topMsgNumber++;
X         RedrawMsg ();
X      }
X      else if (button_ev->button == Button2)
X      {
X         frac = ((double)button_ev->y) / ((double)msgWindowH);
X         topMsgNumber = max(0,round (msgCount * frac));
X         RedrawMsg ();
X      }
X      else if (button_ev->button == Button3)
X      {
X         if (topMsgNumber == 0) return;
X
X         topMsgNumber--;
X         RedrawMsg ();
X      }
X   }
X}
END_OF_FILE
if test 3697 -ne `wc -c <'msg.c'`; then
    echo shar: \"'msg.c'\" unpacked with wrong size!
fi
# end of 'msg.c'
fi
echo shar: End of archive 7 \(of 23\).
cp /dev/null ark7isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 23 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
---------------------------------> cut here <---------------------------------
-- 
Bill Cheng // UCLA Computer Science Department // (213) 206-7135
3277 Boelter Hall // Los Angeles, California 90024 // USA
william@CS.UCLA.EDU      ...!{uunet|ucbvax}!cs.ucla.edu!william