[comp.sources.x] v12i029: tgif, Part13/23

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

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

---------------------------------> 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 13 (of 23)."
# Contents:  scroll.c select.c setup.c
# Wrapped by william@oahu on Wed Mar  6 09:57:40 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'scroll.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'scroll.c'\"
else
echo shar: Extracting \"'scroll.c'\" \(11280 characters\)
sed "s/^X//" >'scroll.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/scroll.c,v 2.0 91/03/05 12:48:17 william Exp $";
X#endif
X
X#include <X11/Xlib.h>
X#include "const.h"
X#include "types.h"
X
X#include "drawing.e"
X#include "msg.e"
X#include "obj.e"
X#include "raster.e"
X#include "ruler.e"
X#include "setup.e"
X#include "text.e"
X
X#include "xbm/uparrow.xbm"
X#include "xbm/downarrow.xbm"
X#include "xbm/rightarrow.xbm"
X#include "xbm/leftarrow.xbm"
X
Xchar	* upData, * downData, * rightData, * leftData;
X
XGC	scrollGC;
XPixmap	scrollPixmap;
XXImage	* scrollImage;
X
Xstatic int	scrollAreaH, scrollAreaW;
X
Xvoid UpdScrollWinWH ()
X{
X   scrollAreaH = vSBarH - 2 * scrollBarW;
X   scrollAreaW = hSBarW - 2 * scrollBarW;
X}
X
Xvoid InitScroll ()
X{
X   XGCValues	values;
X
X   upData = uparrow_bits;
X   downData = downarrow_bits;
X   rightData = rightarrow_bits;
X   leftData = leftarrow_bits;
X
X   UpdScrollWinWH ();
X
X   scrollPixmap = XCreatePixmap (mainDisplay, mainWindow, scrollBarW,
X         scrollBarW, mainDepth);
X   values.foreground = myFgPixel;
X   values.background = myBgPixel;
X   values.fill_style = FillTiled;
X   values.tile = scrollPixmap;
X   scrollGC = XCreateGC (mainDisplay, mainWindow,
X         GCForeground | GCBackground | GCFillStyle | GCTile, &values);
X   scrollImage = XCreateImage (mainDisplay, mainVisual, 1, XYBitmap,
X         0, uparrow_bits, scrollBarW, scrollBarW, 8, 2);
X   scrollImage->byte_order = LSBFirst;
X   scrollImage->bitmap_bit_order = LSBFirst;
X}
X
Xstatic
Xvoid RedrawVScrollWindow ()
X{
X   double	frac, start_frac;
X   int		block_h, block_start;
X   XGCValues	values;
X   XEvent	ev;
X
X   XSync (mainDisplay, FALSE);
X   while (XCheckWindowEvent (mainDisplay, vSBarWindow, ExposureMask, &ev)) ;
X
X   start_frac = (double)((double)(drawOrigY)/(double)(paperHeight));
X   block_start = (int)(scrollAreaH * start_frac);
X
X   if (paperHeight > drawWinH)
X      frac = (double)((double)drawWinH / (double)(paperHeight));
X   else
X      frac = 1.0;
X
X   block_h = (int)(scrollAreaH * frac);
X
X   values.foreground = myBgPixel;
X   values.background = myFgPixel;
X   values.function = GXcopy;
X   values.fill_style = FillSolid;
X   XChangeGC (mainDisplay, scrollGC,
X         GCForeground | GCBackground | GCFunction | GCFillStyle,
X         &values);
X   XFillRectangle (mainDisplay, vSBarWindow, scrollGC, 0, scrollBarW,
X         scrollBarW, scrollAreaH);
X
X   values.foreground = myFgPixel;
X   values.background = myBgPixel;
X   values.fill_style = FillOpaqueStippled;
X   values.stipple = patPixmap[SCROLLPAT];
X   XChangeGC (mainDisplay, scrollGC,
X         GCForeground | GCBackground | GCFillStyle | GCStipple,
X         &values);
X   XFillRectangle (mainDisplay, vSBarWindow, scrollGC, 0,
X         scrollBarW+block_start, scrollBarW, block_h);
X
X   scrollImage->data = upData;
X   XPutImage (mainDisplay, vSBarWindow, scrollGC, scrollImage, 0, 0, 0, 0,
X         scrollBarW, scrollBarW);
X   scrollImage->data = downData;
X   XPutImage (mainDisplay, vSBarWindow, scrollGC, scrollImage, 0, 0,
X         0, scrollBarW+scrollAreaH, scrollBarW, scrollBarW);
X}
X
Xstatic
Xvoid RedrawHScrollWindow ()
X{
X   double	frac, start_frac;
X   int		block_w, block_start;
X   XGCValues	values;
X   XEvent	ev;
X
X   XSync (mainDisplay, FALSE);
X   while (XCheckWindowEvent (mainDisplay, hSBarWindow, ExposureMask, &ev)) ;
X
X   start_frac = (double)((double)(drawOrigX)/(double)(paperWidth));
X   block_start = (int)(scrollAreaW * start_frac);
X
X   if (paperWidth > drawWinW)
X      frac = (double)((double)drawWinW / (double)(paperWidth));
X   else
X      frac = 1.0;
X
X   block_w = (int)(scrollAreaW * frac);
X
X   values.foreground = myBgPixel;
X   values.background = myFgPixel;
X   values.function = GXcopy;
X   values.fill_style = FillSolid;
X   XChangeGC (mainDisplay, scrollGC,
X         GCForeground | GCBackground | GCFunction | GCFillStyle,
X         &values);
X   XFillRectangle (mainDisplay, hSBarWindow, scrollGC, scrollBarW, 0,
X         scrollAreaW, scrollBarW);
X
X   values.foreground = myFgPixel;
X   values.background = myBgPixel;
X   values.fill_style = FillOpaqueStippled;
X   values.stipple = patPixmap[SCROLLPAT];
X   XChangeGC (mainDisplay, scrollGC,
X         GCForeground | GCBackground | GCFillStyle | GCStipple,
X         &values);
X   XFillRectangle (mainDisplay, hSBarWindow, scrollGC, scrollBarW+block_start,
X         0, block_w, scrollBarW);
X
X   scrollImage->data = leftData;
X   XPutImage (mainDisplay, hSBarWindow, scrollGC, scrollImage, 0, 0, 0, 0,
X         scrollBarW, scrollBarW);
X   scrollImage->data = rightData;
X   XPutImage (mainDisplay, hSBarWindow, scrollGC, scrollImage, 0, 0,
X         scrollBarW+scrollAreaW, 0, scrollBarW, scrollBarW);
X}
X
Xvoid RedrawScrollBars ()
X{
X   RedrawVScrollWindow ();
X   RedrawHScrollWindow ();
X}
X
Xvoid ScrollUp ()
X{
X   if (drawOrigY != 0)
X   {
X      drawOrigY -= HALF_INCH<<zoomScale;
X      RedrawVScrollWindow ();
X      UpdDrawWinBBox ();
X      AdjSplineVs ();
X      AdjustCurText (0, HALF_INCH);
X      ClearAndRedrawDrawWindow ();
X      XClearWindow (mainDisplay, vRuleWindow);
X      RedrawVRuler ();
X   }
X}
X
Xvoid ScrollDown ()
X{
X   if (paperHeight <= drawWinH) return;
X
X   if (drawOrigY+drawWinH < paperHeight)
X   {
X      drawOrigY += HALF_INCH<<zoomScale;
X      RedrawVScrollWindow ();
X      UpdDrawWinBBox ();
X      AdjSplineVs ();
X      AdjustCurText (0, -HALF_INCH);
X      ClearAndRedrawDrawWindow ();
X      XClearWindow (mainDisplay, vRuleWindow);
X      RedrawVRuler ();
X   }
X}
X
Xstatic
Xvoid VSBarHandler (button_ev)
X   XButtonEvent	* button_ev;
X{
X   double	frac, start_frac;
X   int		block_h, block_start, adjustment, new_start, saved_y;
X
X   if (button_ev->button == Button1)
X   {
X      if (button_ev->y < scrollBarW)
X         ScrollUp (); /* clicked in the uparrow */
X      else if (button_ev->y >= scrollBarW+scrollAreaH)
X         ScrollDown (); /* clicked in the downarrow */
X      else /* clicked in the middle region */
X      {
X         frac = (double)((double)drawWinH / (double)(paperHeight));
X         if (frac > 1.0) frac = 1.0;
X         block_h = (int)(scrollAreaH * frac);
X         block_start = button_ev->y - scrollBarW;
X         start_frac = (double)((double)(block_start)/(double)(scrollAreaH));
X         if (block_start+block_h >= scrollAreaH)
X         {
X            saved_y = drawOrigY;
X
X            if (paperHeight <= drawWinH)
X               drawOrigY = 0;
X            else
X            {
X               if ((paperHeight-drawWinH) % (HALF_INCH<<zoomScale) == 0)
X                  drawOrigY = paperHeight-drawWinH;
X               else
X                  drawOrigY = ((int)((paperHeight-drawWinH)/
X                        (HALF_INCH<<zoomScale)) + 1) *
X                        (HALF_INCH<<zoomScale);
X            }
X
X            adjustment = drawOrigY - saved_y;
X            if (adjustment != 0)
X            {
X               RedrawVScrollWindow ();
X               UpdDrawWinBBox ();
X               AdjSplineVs ();
X               AdjustCurText (0, adjustment);
X               ClearAndRedrawDrawWindow ();
X               RedrawVRuler ();
X            }
X            return;
X         }
X         else
X         {
X            new_start = ((int)(paperHeight*start_frac/(HALF_INCH<<zoomScale)))*
X                  (HALF_INCH<<zoomScale);
X            adjustment = drawOrigY - new_start;
X            if (adjustment != 0)
X            {
X               drawOrigY = new_start;
X               RedrawVScrollWindow ();
X               UpdDrawWinBBox ();
X               AdjSplineVs ();
X               AdjustCurText (0, adjustment);
X               ClearAndRedrawDrawWindow ();
X               RedrawVRuler ();
X            }
X            return;
X         }
X      }
X   }
X}
X
Xvoid ScrollLeft ()
X{
X   if (drawOrigX != 0)
X   {
X      drawOrigX -= HALF_INCH<<zoomScale;
X      RedrawHScrollWindow ();
X      UpdDrawWinBBox ();
X      AdjSplineVs ();
X      AdjustCurText (HALF_INCH, 0);
X      ClearAndRedrawDrawWindow ();
X      XClearWindow (mainDisplay, hRuleWindow);
X      RedrawHRuler ();
X   }
X}
X
Xvoid ScrollRight ()
X{
X   if (paperWidth <= drawWinW) return;
X
X   if (drawOrigX+drawWinW < paperWidth)
X   {
X      drawOrigX += HALF_INCH<<zoomScale;
X      RedrawHScrollWindow ();
X      UpdDrawWinBBox ();
X      AdjSplineVs ();
X      AdjustCurText (-HALF_INCH, 0);
X      ClearAndRedrawDrawWindow ();
X      XClearWindow (mainDisplay, hRuleWindow);
X      RedrawHRuler ();
X   }
X}
X
Xstatic
Xvoid HSBarHandler (button_ev)
X   XButtonEvent	* button_ev;
X{
X   double	frac, start_frac;
X   int		block_w, block_start, adjustment, new_start, saved_x;
X
X   if (button_ev->button == Button1)
X   {
X      if (button_ev->x < scrollBarW)
X         ScrollLeft (); /* clicked in the leftarrow */
X      else if (button_ev->x >= scrollBarW+scrollAreaW)
X         ScrollRight (); /* clicked in the rightarrow */
X      else /* clicked in the middle region */
X      {
X         frac = (double)((double)drawWinW / (double)(paperWidth));
X         if (frac > 1.0) frac = 1.0;
X         block_w = (int)(scrollAreaW * frac);
X         block_start = button_ev->x - scrollBarW;
X         start_frac = (double)((double)(block_start)/(double)(scrollAreaW));
X         if (block_start+block_w >= scrollAreaW)
X         {
X            saved_x = drawOrigX;
X
X            if (paperWidth <= drawWinW)
X                drawOrigX = 0;
X            {
X               if ((paperWidth-drawWinW) % (HALF_INCH<<zoomScale) == 0)
X                  drawOrigX = paperWidth-drawWinW;
X               else
X                  drawOrigX = ((int)((paperWidth-drawWinW)/
X                        (HALF_INCH<<zoomScale)) + 1) *
X                        (HALF_INCH<<zoomScale);
X            }
X
X            adjustment = drawOrigX - saved_x;
X            if (adjustment != 0)
X            {
X               RedrawHScrollWindow ();
X               UpdDrawWinBBox ();
X               AdjSplineVs ();
X               AdjustCurText (adjustment, 0);
X               ClearAndRedrawDrawWindow ();
X               RedrawHRuler ();
X            }
X            return;
X         }
X         else
X         {
X            new_start = ((int)(paperWidth*start_frac/(HALF_INCH<<zoomScale)))*
X                  (HALF_INCH<<zoomScale);
X            adjustment = drawOrigX - new_start;
X            if (adjustment != 0)
X            {
X               drawOrigX = new_start;
X               RedrawHScrollWindow ();
X               UpdDrawWinBBox ();
X               AdjSplineVs ();
X               AdjustCurText (adjustment, 0);
X               ClearAndRedrawDrawWindow ();
X               RedrawHRuler ();
X            }
X            return;
X         }
X      }
X   }
X}
X
Xvoid ScrollEventHandler (input)
X   XEvent	* input;
X{
X   if (input->xany.window == vSBarWindow)
X   {
X      if (input->type == Expose)
X      {
X         XSync (mainDisplay, FALSE);
X         RedrawVScrollWindow ();
X         return;
X      }
X
X      Msg (""); 
X      VSBarHandler (&(input->xbutton));
X      return;
X   }
X   else if (input->xany.window == hSBarWindow)
X   {
X      if (input->type == Expose)
X      {
X         XSync (mainDisplay, FALSE);
X         RedrawHScrollWindow ();
X         return;
X      }
X
X      Msg (""); 
X      HSBarHandler (&(input->xbutton));
X      return;
X   }
X}
X
Xvoid CleanUpScrolls ()
X{
X   XFreePixmap (mainDisplay, scrollPixmap);
X   XFreeGC (mainDisplay, scrollGC);
X/* XDestroyImage (scrollImage); */
X}
END_OF_FILE
if test 11280 -ne `wc -c <'scroll.c'`; then
    echo shar: \"'scroll.c'\" unpacked with wrong size!
fi
# end of 'scroll.c'
fi
if test -f 'select.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'select.c'\"
else
echo shar: Extracting \"'select.c'\" \(20158 characters\)
sed "s/^X//" >'select.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/select.c,v 2.0 91/03/05 12:48:20 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 "choice.e"
X#include "cursor.e"
X#include "drawing.e"
X#include "dup.e"
X#include "grid.e"
X#include "group.e"
X#include "mark.e"
X#include "move.e"
X#include "obj.e"
X#include "raster.e"
X#include "rect.e"
X#include "ruler.e"
X#include "setup.e"
X#include "stretch.e"
X
X#define FORWARD 0
X#define REVERSE 1
X
Xint		selLtX, selLtY, selRbX, selRbY;
Xint		selObjLtX, selObjLtY, selObjRbX, selObjRbY;
Xstruct SelRec	* topSel = NULL, * botSel = NULL;
X
Xstatic struct SelRec	* topCutSel = NULL, * botCutSel = NULL;
X
Xvoid CalcBBox (X1, Y1, X2, Y2, LtX, LtY, RbX, RbY)
X   int X1, Y1, X2, Y2, * LtX, * LtY, * RbX, * RbY;
X{
X   if (X1 < X2)
X      if (Y1 < Y2)
X      {
X         *LtX = X1; *LtY = Y1; *RbX = X2; *RbY = Y2;
X      }
X      else
X      {
X         *LtX = X1; *LtY = Y2; *RbX = X2; *RbY = Y1;
X      }
X   else
X      if (Y1 < Y2)
X      {
X         *LtX = X2; *LtY = Y1; *RbX = X1; *RbY = Y2;
X      }
X      else
X      {
X         *LtX = X2; *LtY = Y2; *RbX = X1; *RbY = Y1;
X      }
X}
X
Xvoid RemoveAllSel ()
X{
X   while (topSel != NULL)
X   {
X      cfree (topSel);
X      topSel = topSel->next;
X   }
X   botSel = NULL;
X}
X
Xstatic
Xstruct ObjRec * FindAnObj (X, Y)
X   int	X, Y;
X   /* X and Y are absolute coordinates */
X{
X   register struct ObjRec	* obj_ptr;
X
X   for (obj_ptr = topObj; obj_ptr != NULL; obj_ptr = obj_ptr->next)
X      if (X >= obj_ptr->bbox.ltx-(3<<zoomScale) &&
X            X <= obj_ptr->bbox.rbx+(3<<zoomScale) &&
X            Y >= obj_ptr->bbox.lty-(3<<zoomScale) &&
X            Y <= obj_ptr->bbox.rby+(3<<zoomScale))
X      {
X         switch (obj_ptr->type)
X         {
X            case OBJ_TEXT: return (obj_ptr);
X            case OBJ_XBM: return (obj_ptr);
X            case OBJ_BOX:
X               if (FindGoodBox (X, Y, obj_ptr)) return (obj_ptr); break;
X            case OBJ_OVAL:
X               if (FindGoodOval (X, Y, obj_ptr)) return (obj_ptr); break;
X            case OBJ_POLY:
X               if (FindGoodPoly (X, Y, obj_ptr)) return (obj_ptr); break;
X            case OBJ_POLYGON:
X               if (FindGoodPolygon (X, Y, obj_ptr)) return (obj_ptr); break;
X            case OBJ_ARC:
X               if (FindGoodArc (X, Y, obj_ptr)) return (obj_ptr); break;
X            case OBJ_RCBOX:
X               if (FindGoodRCBox (X, Y, obj_ptr)) return (obj_ptr); break;
X
X            case OBJ_GROUP:
X            case OBJ_SYM:
X            case OBJ_ICON:
X               if (FindGoodObj (X, Y, obj_ptr->detail.r->first))
X                  return (obj_ptr);
X         }
X      }
X   return (NULL);
X}
X
Xstatic
Xstruct SelRec * AlreadySelected (ObjPtr)
X   register struct ObjRec	* ObjPtr;
X{
X   register struct SelRec	* sel_ptr;
X
X   for (sel_ptr = topSel; sel_ptr != NULL; sel_ptr = sel_ptr->next)
X      if (sel_ptr->obj == ObjPtr)
X         return (sel_ptr);
X   return (NULL);
X}
X
Xvoid AddSel (PrevPtr, NextPtr, SelPtr)
X   struct SelRec	* PrevPtr, * NextPtr, * SelPtr;
X   /* add SelPtr between PrevPtr and NextPtr */
X{
X   SelPtr->prev = PrevPtr;
X   SelPtr->next = NextPtr;
X
X   if (PrevPtr == NULL)
X      topSel = SelPtr;
X   else
X      PrevPtr->next = SelPtr;
X
X   if (NextPtr == NULL)
X      botSel = SelPtr;
X   else
X      NextPtr->prev = SelPtr;
X}
X
Xvoid AddNewSelObj (ObjPtr)
X   register struct ObjRec	* ObjPtr;
X{
X   register struct ObjRec	* obj_ptr = topObj;
X   register struct SelRec	* sel_ptr = topSel, * new_sel_ptr;
X
X   new_sel_ptr = (struct SelRec *) calloc (1, sizeof(struct SelRec));
X   new_sel_ptr->obj = ObjPtr;
X
X   for ( ; sel_ptr != NULL && obj_ptr != ObjPtr; obj_ptr = obj_ptr->next)
X      if (obj_ptr == sel_ptr->obj)
X         sel_ptr = sel_ptr->next;
X
X   if (sel_ptr == NULL)
X   {  /* the object is below the last selected object */
X      if (botSel == NULL)
X         topSel = new_sel_ptr;
X      else
X         botSel->next = new_sel_ptr;
X
X      new_sel_ptr->prev = botSel;
X      new_sel_ptr->next = NULL;
X      botSel = new_sel_ptr;
X   }
X   else
X   {  /* the object is between sel_ptr and sel_ptr->prev */
X      if (sel_ptr->prev == NULL)
X         topSel = new_sel_ptr;
X      else
X         sel_ptr->prev->next = new_sel_ptr;
X
X      new_sel_ptr->next = sel_ptr;
X      new_sel_ptr->prev = sel_ptr->prev;
X      sel_ptr->prev = new_sel_ptr;
X   }
X}
X
Xvoid UpdSelBBox ()
X   /* update selLtX, selLtY, selRbX, selRbY */
X{
X   register struct ObjRec	* obj_ptr;
X   register struct SelRec	* sel_ptr;
X
X   if ((sel_ptr = topSel) == NULL) return;
X
X   selLtX = sel_ptr->obj->bbox.ltx;
X   selLtY = sel_ptr->obj->bbox.lty;
X   selRbX = sel_ptr->obj->bbox.rbx;
X   selRbY = sel_ptr->obj->bbox.rby;
X   selObjLtX = sel_ptr->obj->obbox.ltx;
X   selObjLtY = sel_ptr->obj->obbox.lty;
X   selObjRbX = sel_ptr->obj->obbox.rbx;
X   selObjRbY = sel_ptr->obj->obbox.rby;
X
X   for (sel_ptr = topSel->next; sel_ptr != NULL; sel_ptr = sel_ptr->next)
X   {
X      obj_ptr = sel_ptr->obj;
X      if (obj_ptr->bbox.ltx < selLtX) selLtX = obj_ptr->bbox.ltx;
X      if (obj_ptr->bbox.lty < selLtY) selLtY = obj_ptr->bbox.lty;
X      if (obj_ptr->bbox.rbx > selRbX) selRbX = obj_ptr->bbox.rbx;
X      if (obj_ptr->bbox.rby > selRbY) selRbY = obj_ptr->bbox.rby;
X      if (obj_ptr->obbox.ltx < selObjLtX) selObjLtX = obj_ptr->obbox.ltx;
X      if (obj_ptr->obbox.lty < selObjLtY) selObjLtY = obj_ptr->obbox.lty;
X      if (obj_ptr->obbox.rbx > selObjRbX) selObjRbX = obj_ptr->obbox.rbx;
X      if (obj_ptr->obbox.rby > selObjRbY) selObjRbY = obj_ptr->obbox.rby;
X   }
X}
X 
Xstatic
Xstruct SelRec * SelectOneObj (X, Y)
X   int	X, Y;
X   /* X and Y are absolute coordinates */
X{
X   register struct ObjRec	* obj_ptr;
X
X   RemoveAllSel ();
X   if ((obj_ptr = FindAnObj (X, Y)) == NULL) return (NULL);
X
X   topSel = (struct SelRec *) calloc (1, sizeof(struct SelRec));
X   topSel->next = NULL;
X   topSel->obj = obj_ptr;
X   topSel->prev = NULL;
X   botSel = topSel;
X   UpdSelBBox ();
X
X   return (topSel);
X}
X
Xstatic
Xstruct SelRec * FindObjects (X1, Y1, X2, Y2, TopSel, BotSel)
X   int	X1, Y1, X2, Y2;
X   struct SelRec	* * TopSel, * * BotSel;
X   /* X1, Y1, X2, Y2 are absolute coordinates */
X{
X   register struct ObjRec	* obj_ptr;
X   register struct SelRec	* sel_ptr;
X
X   *TopSel = *BotSel = NULL;
X
X   for (obj_ptr = botObj; obj_ptr != NULL; obj_ptr = obj_ptr->prev)
X      if (X1 <= obj_ptr->bbox.ltx && X2 >= obj_ptr->bbox.rbx &&
X            Y1 <= obj_ptr->bbox.lty && Y2 >= obj_ptr->bbox.rby)
X      {
X         sel_ptr = (struct SelRec *) calloc (1, sizeof(struct SelRec));
X         sel_ptr->next = *TopSel;
X         sel_ptr->obj = obj_ptr;
X         sel_ptr->prev = NULL;
X         if (*TopSel == NULL)
X            *BotSel = sel_ptr;
X         else
X            (*TopSel)->prev = sel_ptr;
X         *TopSel = sel_ptr;
X      }
X
X   return (*TopSel);
X}
X 
Xstatic XPoint sv[5];
X
Xvoid SelBox (window, gc, x1, y1, x2, y2)
X   Window	window;
X   GC		gc;
X   int		x1, y1, x2, y2;
X{
X   sv[0].x = (short)x1; sv[0].y = (short)y1;
X   sv[1].x = (short)x1; sv[1].y = (short)y2;
X   sv[2].x = (short)x2; sv[2].y = (short)y2;
X   sv[3].x = (short)x2; sv[3].y = (short)y1;
X   sv[4].x = (short)x1; sv[4].y = (short)y1;
X   XDrawLines (mainDisplay, window, gc, sv, 5, CoordModeOrigin);
X}
X
Xstatic
Xstruct ObjRec * PtInObjList (X, Y, FirstObjPtr)
X   int			X, Y;
X   struct ObjRec	* FirstObjPtr;
X   /* X and Y are absolute coordinates */
X{
X   register struct ObjRec	* obj_ptr, * obj_ptr1;
X
X   for (obj_ptr = FirstObjPtr; obj_ptr != NULL; obj_ptr = obj_ptr->next)
X   {
X      if (X >= obj_ptr->bbox.ltx-(3<<zoomScale) &&
X            X <= obj_ptr->bbox.rbx+(3<<zoomScale) &&
X            Y >= obj_ptr->bbox.lty-(3<<zoomScale) &&
X            Y <= obj_ptr->bbox.rby+(3<<zoomScale))
X      {
X         switch (obj_ptr->type)
X         {
X            case OBJ_TEXT: return (obj_ptr);
X            case OBJ_XBM: return (obj_ptr);
X            case OBJ_BOX:
X               if (FindGoodBox (X, Y, obj_ptr)) return (obj_ptr); break;
X            case OBJ_OVAL:
X               if (FindGoodOval (X, Y, obj_ptr)) return (obj_ptr); break;
X            case OBJ_POLY:
X               if (FindGoodPoly (X, Y, obj_ptr)) return (obj_ptr); break;
X            case OBJ_POLYGON:
X               if (FindGoodPolygon (X, Y, obj_ptr)) return (obj_ptr); break;
X            case OBJ_ARC:
X               if (FindGoodArc (X, Y, obj_ptr)) return (obj_ptr); break;
X            case OBJ_RCBOX:
X               if (FindGoodRCBox (X, Y, obj_ptr)) return (obj_ptr); break;
X
X            case OBJ_GROUP:
X            case OBJ_SYM:
X            case OBJ_ICON:
X               obj_ptr1 = PtInObjList (X, Y, obj_ptr->detail.r->first);
X               if (obj_ptr1 != NULL) return (obj_ptr1);
X               break;
X         }
X      }
X   }
X   return (NULL);
X}
X
Xstatic
Xstruct ObjRec * PtInSelected (X, Y)
X   int	X, Y;
X   /* X and Y are absolute coordinates */
X{
X   register struct SelRec	* sel_ptr;
X   register struct ObjRec	* obj_ptr, * obj_ptr1;
X
X   for (sel_ptr = topSel; sel_ptr != NULL; sel_ptr = sel_ptr->next)
X   {
X      obj_ptr = sel_ptr->obj;
X      if (X >= obj_ptr->bbox.ltx-(3<<zoomScale) &&
X            X <= obj_ptr->bbox.rbx+(3<<zoomScale) &&
X            Y >= obj_ptr->bbox.lty-(3<<zoomScale) &&
X            Y <= obj_ptr->bbox.rby+(3<<zoomScale))
X      {
X         switch (obj_ptr->type)
X         {
X            case OBJ_TEXT: return (obj_ptr);
X            case OBJ_XBM: return (obj_ptr);
X            case OBJ_BOX:
X               if (FindGoodBox (X, Y, obj_ptr)) return (obj_ptr); break;
X            case OBJ_OVAL:
X               if (FindGoodOval (X, Y, obj_ptr)) return (obj_ptr); break;
X            case OBJ_POLY:
X               if (FindGoodPoly (X, Y, obj_ptr)) return (obj_ptr); break;
X            case OBJ_POLYGON:
X               if (FindGoodPolygon (X, Y, obj_ptr)) return (obj_ptr); break;
X            case OBJ_ARC:
X               if (FindGoodArc (X, Y, obj_ptr)) return (obj_ptr); break;
X            case OBJ_RCBOX:
X               if (FindGoodRCBox (X, Y, obj_ptr)) return (obj_ptr); break;
X
X            case OBJ_GROUP:
X            case OBJ_SYM:
X            case OBJ_ICON:
X               obj_ptr1 = PtInObjList (X, Y, obj_ptr->detail.r->first);
X               if (obj_ptr1 != NULL) return (obj_ptr1);
X               break;
X         }
X      }
X   }
X   return (NULL);
X}
X
Xstatic
Xvoid ToggleSelectedObjIfSelectedAlready (ObjPtr)
X   register struct ObjRec	* ObjPtr;
X{
X   register struct SelRec	* sel_ptr;
X
X   if ((sel_ptr = AlreadySelected (ObjPtr)) != NULL)
X   {  /* de-select an object */
X      HighLightAnObj (ObjPtr);
X
X      if (sel_ptr->prev == NULL)
X         topSel = sel_ptr->next;
X      else
X         sel_ptr->prev->next = sel_ptr->next;
X
X      if (sel_ptr->next == NULL)
X         botSel = sel_ptr->prev;
X      else
X         sel_ptr->next->prev = sel_ptr->prev;
X
X      cfree (sel_ptr);
X   }
X   else
X   {  /* add a newly selected object */
X      AddNewSelObj (ObjPtr);
X      HighLightAnObj (ObjPtr);
X   }
X}
X
Xstatic
Xvoid ContinueSel (XOff, YOff, ShiftKeyDown)
X   int 	XOff, YOff, ShiftKeyDown;
X   /* XOff and YOff are screen offsets, and they are not on grid */
X{
X   int 			end_x, end_y;
X   int 			done = FALSE, ltx, lty, rbx, rby, dx, dy;
X   int 			new_end_x, new_end_y;
X   XEvent		input;
X   XMotionEvent		* motion_ev;
X   struct SelRec	* sel_ptr, * top_sel_ptr, * bot_sel_ptr;
X   struct ObjRec	* obj_ptr;
X
X   end_x = XOff;
X   end_y = YOff; 
X
X   SelBox (drawWindow, revDefaultGC, XOff, YOff, end_x, end_y);
X   XGrabPointer (mainDisplay, drawWindow, False,
X         PointerMotionMask | ButtonReleaseMask,
X         GrabModeAsync, GrabModeAsync, None, handCursor, CurrentTime);
X   
X   while (!done)
X   {
X      XNextEvent (mainDisplay, &input);
X      if (input.type == ButtonRelease)
X      {
X         XUngrabPointer (mainDisplay, CurrentTime);
X         SelBox (drawWindow, revDefaultGC, XOff, YOff, end_x, end_y);
X         done = TRUE;
X      }
X      else if (input.type == MotionNotify)
X      {
X         motion_ev = &(input.xmotion);
X         new_end_x = motion_ev->x;
X         new_end_y = motion_ev->y;
X
X         SelBox (drawWindow, revDefaultGC, XOff, YOff, end_x, end_y);
X         end_x = new_end_x; end_y = new_end_y;
X         SelBox (drawWindow, revDefaultGC, XOff, YOff, end_x, end_y);
X
X         MarkRulers (end_x, end_y);
X      }
X   }
X
X   dx = abs (XOff - end_x);
X   dy = abs (YOff - end_y);
X   if (dx <= 2 && dy <= 2)
X   {
X      if (ShiftKeyDown)
X      {
X         obj_ptr = FindAnObj ((XOff<<zoomScale)+drawOrigX,
X               (YOff<<zoomScale)+drawOrigY);
X         if (obj_ptr != NULL)
X         {
X            ToggleSelectedObjIfSelectedAlready (obj_ptr);
X            UpdSelBBox ();
X         }
X      }
X      else
X      {
X         if (topSel != NULL) HighLightReverse ();
X
X         if (SelectOneObj ((XOff<<zoomScale)+drawOrigX,
X               (YOff<<zoomScale)+drawOrigY) != NULL)
X            HighLightForward ();
X      }
X   }
X   else
X   {
X      CalcBBox (XOff, YOff, end_x, end_y, &ltx, &lty, &rbx, &rby);
X      if (ShiftKeyDown)
X      {
X         if (FindObjects ((ltx<<zoomScale)+drawOrigX,
X               (lty<<zoomScale)+drawOrigY, (rbx<<zoomScale)+drawOrigX,
X               (rby<<zoomScale)+drawOrigY, &top_sel_ptr, &bot_sel_ptr) != NULL)
X         {
X            for (sel_ptr=top_sel_ptr; sel_ptr!=NULL; sel_ptr=sel_ptr->next)
X            {
X               obj_ptr = sel_ptr->obj;
X               ToggleSelectedObjIfSelectedAlready (obj_ptr);
X               cfree(sel_ptr);
X            }
X            UpdSelBBox ();
X         }
X      }
X      else
X      {
X         if (topSel != NULL) HighLightReverse ();
X         RemoveAllSel ();
X         if (FindObjects ((ltx<<zoomScale)+drawOrigX,
X               (lty<<zoomScale)+drawOrigY, (rbx<<zoomScale)+drawOrigX,
X               (rby<<zoomScale)+drawOrigY, &top_sel_ptr, &bot_sel_ptr) != NULL)
X         {
X            topSel = top_sel_ptr;
X            botSel = bot_sel_ptr;
X            UpdSelBBox ();
X            HighLightForward ();
X         }
X      }
X   }
X}
X
Xvoid Select (input)
X   XEvent	* input;
X{
X   XButtonEvent		* button_ev;
X   struct SelRec	* sel_ptr;
X   struct ObjRec	* obj_ptr;
X   int			mouse_x, mouse_y, grid_x, grid_y, corner;
X
X   if (input->type != ButtonPress) return;
X
X   button_ev = &(input->xbutton);
X   if (button_ev->button == Button1)
X   {
X      mouse_x = button_ev->x;
X      mouse_y = button_ev->y;
X      GridXY (mouse_x, mouse_y, &grid_x, &grid_y);
X
X      if (button_ev->state & ShiftMask)
X      {
X         ContinueSel (mouse_x, mouse_y, TRUE);
X         justDupped = FALSE;
X         return;
X      }
X      if (topSel != NULL)
X      {
X         if ((sel_ptr = PtInSelMark (mouse_x, mouse_y, &corner)) != NULL)
X         {
X            StretchSel (grid_x, grid_y, sel_ptr->obj, corner);
X            justDupped = FALSE;
X            return;
X         }
X         else if ((obj_ptr = PtInSelected ((mouse_x<<zoomScale)+drawOrigX,
X               (mouse_y<<zoomScale)+drawOrigY)) != NULL)
X         {
X            MoveSel (grid_x, grid_y, obj_ptr);
X            return;
X         }
X      }
X      ContinueSel (mouse_x, mouse_y, FALSE);
X      justDupped = FALSE;
X   }
X}
X
Xvoid SelAllObj ()
X{
X   register struct SelRec	* sel_ptr;
X   register struct ObjRec	* obj_ptr;
X
X   TieLooseEnds ();
X   SetCurChoice (NOTHING);
X
X   if (topSel != NULL)
X   {
X      HighLightReverse ();
X      RemoveAllSel ();
X   }
X   for (obj_ptr = botObj; obj_ptr != NULL; obj_ptr = obj_ptr->prev)
X   {
X      sel_ptr = (struct SelRec *) calloc (1, sizeof(struct SelRec));
X      sel_ptr->next = topSel;
X      sel_ptr->obj = obj_ptr;
X      sel_ptr->prev = NULL;
X      if (topSel == NULL)
X         botSel = sel_ptr;
X      else
X         topSel->prev = sel_ptr;
X      topSel = sel_ptr;
X   }
X   UpdSelBBox ();
X   HighLightForward ();
X   justDupped = FALSE;
X}
X
Xstatic struct ObjRec	* tmpTopObj, * tmpBotObj;
X
Xstatic
Xvoid PushTmpObj (ObjPtr)
X   struct ObjRec	* ObjPtr;
X{
X   ObjPtr->next = tmpTopObj;
X   ObjPtr->prev = NULL;
X
X   if (tmpBotObj == NULL)
X      tmpBotObj = ObjPtr;
X   else
X      tmpTopObj->prev = ObjPtr;
X
X   tmpTopObj = ObjPtr;
X}
X
Xstatic
Xvoid BreakSel ()
X   /* break off selected objects from the main stream objects           */
X   /* when returns, tmpTopObj points to the top of the selected objects */
X   /*    and tmpBotObj points to the bottom of the selected objects     */
X{
X   register struct SelRec	* sel_ptr;
X
X   for (sel_ptr = botSel; sel_ptr != NULL; sel_ptr = sel_ptr->prev)
X   {
X      UnlinkObj (sel_ptr->obj);
X      PushTmpObj (sel_ptr->obj);
X   }
X}
X
Xvoid MoveSelToTop ()
X{
X   if (topSel == NULL) return;
X
X   tmpTopObj = tmpBotObj = NULL;
X
X   BreakSel ();
X   tmpBotObj->next = topObj;
X   if (topObj == NULL)
X      botObj = tmpBotObj;
X   else
X      topObj->prev = tmpBotObj;
X   topObj = tmpTopObj;
X}
X
Xvoid MoveSelToBot ()
X{
X   if (topSel == NULL) return;
X
X   tmpTopObj = tmpBotObj = NULL;
X
X   BreakSel ();
X   tmpTopObj->prev = botObj;
X   if (topObj == NULL)
X      topObj = tmpTopObj;
X   else
X      botObj->next = tmpTopObj;
X   botObj = tmpBotObj;
X}
X
Xvoid DelAllCutSel ()
X{
X   register struct SelRec	* sel_ptr;
X
X   while (topCutSel != NULL)
X   {
X      for (sel_ptr = topCutSel->next; sel_ptr != NULL; sel_ptr = sel_ptr->next)
X      {
X         FreeObj (sel_ptr->obj);
X         cfree (sel_ptr);
X      }
X      topCutSel = topCutSel->prev; /* prev is used as the stack chaser */
X      botCutSel = botCutSel->prev; /* prev is used as the stack chaser */
X   }
X}
X
Xvoid UndoDelete ()
X{
X   if (topCutSel == NULL)
X   {
X      Msg ("Un-delete buffer empty!");
X      return;
X   }
X
X   HighLightReverse ();
X   RemoveAllSel ();
X
X   topSel = topCutSel->next;
X   botSel = botCutSel->next;
X
X   botSel->obj->next = topObj;
X   if (topObj == NULL)
X      botObj = botSel->obj;
X   else
X      topObj->prev = botSel->obj;
X   topObj = topSel->obj;
X
X   cfree (topCutSel);
X   cfree (botCutSel);
X   topCutSel = topCutSel->prev; /* prev is used as the stack chaser */
X   botCutSel = botCutSel->prev; /* prev is used as the stack chaser */
X
X   UpdSelBBox ();
X   RedrawAnArea (botObj, selLtX-(1<<zoomScale), selLtY-(1<<zoomScale),
X         selRbX+(1<<zoomScale), selRbY+(1<<zoomScale));
X   HighLightForward ();
X   SetCurChoice (NOTHING);
X   SetFileModified (TRUE);
X   justDupped = FALSE;
X}
X
Xvoid PushToCutBuffer (TopSelPtr, BotSelPtr)
X   struct SelRec	* TopSelPtr, * BotSelPtr;
X{
X   register struct SelRec	* top_cut_ptr, * bot_cut_ptr;
X
X   top_cut_ptr = (struct SelRec *) calloc (2, sizeof (struct SelRec));
X   bot_cut_ptr = &top_cut_ptr[1];
X   top_cut_ptr->next = TopSelPtr; bot_cut_ptr->next = BotSelPtr;
X   top_cut_ptr->prev = topCutSel; bot_cut_ptr->prev = botCutSel;
X   topCutSel = top_cut_ptr; botCutSel = bot_cut_ptr;
X}
X
Xvoid CopySelToCut ()
X{
X   struct SelRec	* top_sel_ptr, * bot_sel_ptr;
X
X   if (topSel == NULL) return;
X
X   JustDupSelObj (&top_sel_ptr, &bot_sel_ptr);
X   PushToCutBuffer (top_sel_ptr, bot_sel_ptr);
X}
X
Xvoid DelAllSelObj ()
X{
X   if (topSel == NULL) { Msg ("No object selected!"); return; }
X
X   HighLightReverse ();
X   tmpTopObj = tmpBotObj = NULL;
X   BreakSel ();
X
X   PushToCutBuffer (topSel, botSel);
X
X   topSel = botSel = NULL;
X   RedrawAnArea (botObj, selLtX-(1<<zoomScale), selLtY-(1<<zoomScale),
X         selRbX+(1<<zoomScale), selRbY+(1<<zoomScale));
X   SetFileModified (TRUE);
X   justDupped = FALSE;
X}
X
Xvoid GroupSelObj ()
X{
X   if (topSel == NULL) { Msg ("No object to group!"); return; }
X   if (topSel == botSel)
X   {
X      Msg ("Can not group a single object!  Abort!");
X      return;
X   }
X
X   tmpTopObj = tmpBotObj = NULL;
X
X   HighLightReverse ();
X   BreakSel ();
X
X   CreateGroupObj (tmpTopObj, tmpBotObj);
X
X   RemoveAllSel ();
X   topSel = botSel = (struct SelRec *) calloc (1, sizeof(struct SelRec));
X   topSel->obj = topObj;
X   topSel->next = topSel->prev = NULL;
X
X   RedrawAnArea (botObj, selLtX-(1<<zoomScale), selLtY-(1<<zoomScale),
X         selRbX+(1<<zoomScale), selRbY+(1<<zoomScale));
X   HighLightForward ();
X   SetFileModified (TRUE);
X   justDupped = FALSE;
X}
X
Xvoid SelectTopObj ()
X{
X   if (topObj == NULL) return;
X
X   topSel = botSel = (struct SelRec *) calloc (1, sizeof(struct SelRec));
X   topSel->obj = topObj;
X   topSel->next = topSel->prev = NULL;
X   UpdSelBBox ();
X
X   HighLightForward ();
X   justDupped = FALSE;
X}
END_OF_FILE
if test 20158 -ne `wc -c <'select.c'`; then
    echo shar: \"'select.c'\" unpacked with wrong size!
fi
# end of 'select.c'
fi
if test -f 'setup.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'setup.c'\"
else
echo shar: Extracting \"'setup.c'\" \(13850 characters\)
sed "s/^X//" >'setup.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/setup.c,v 2.0 91/03/05 12:48:23 william Exp $";
X#endif
X
X#include <X11/Xlib.h>
X#include <X11/Xutil.h>
X#include "const.h"
X#include "types.h"
X
X#include "choice.e"
X#include "color.e"
X#include "cursor.e"
X#include "drawing.e"
X#include "font.e"
X#include "mainloop.e"
X#include "menu.e"
X#include "names.e"
X#include "raster.e"
X#include "ruler.e"
X#include "scroll.e"
X#include "stk.e"
X#include "xbitmap.e"
X
Xextern	char	* getenv ();
X
X#define MENU_IMAGE_W 64
X#define MENU_IMAGE_H 20
X#define CHOICE_IMAGE_W 32
X#define CHOICE_IMAGE_H 20
X#define SCROLLBAR_W 16
X#define RULER_W 20
X#define BRDR_W 1
X
X#define DRAW_WINDOW_W (5*PIX_PER_INCH)
X#define DRAW_WINDOW_H (5*PIX_PER_INCH)
X#define CHOICE_WINDOW_W (8*CHOICE_IMAGE_W)
X#define CHOICE_WINDOW_H (2*CHOICE_IMAGE_H)
X#define VSBAR_H (DRAW_WINDOW_H+RULER_W+2*BRDR_W)
X#define HSBAR_W (DRAW_WINDOW_W+RULER_W+2*BRDR_W)
X#define TITLE_WINDOW_W (HSBAR_W+SCROLLBAR_W+2*BRDR_W)
X#define TITLE_WINDOW_H (MENU_IMAGE_H*2)
X#define TOOL_WINDOW_W (TITLE_WINDOW_W+2*BRDR_W)
X#define TOOL_WINDOW_H (TITLE_WINDOW_H+CHOICE_WINDOW_H+VSBAR_H+SCROLLBAR_W+8*BRDR_W)
X#define MSG_WINDOW_W (TITLE_WINDOW_W-CHOICE_WINDOW_W-2*BRDR_W)
X#define MSG_WINDOW_H (CHOICE_WINDOW_H)
X#define ICON_WINDOW_W 64
X#define ICON_WINDOW_H 80
X
Xunsigned int	mainWinW = 0;
Xunsigned int	mainWinH = 0;
Xint	vSBarH = VSBAR_H;
Xint	hSBarW = HSBAR_W;
Xint	scrollBarW = SCROLLBAR_W;
Xint	rulerW = RULER_W;
Xint	brdrW = BRDR_W;
Xint	msgWindowW = MSG_WINDOW_W;
Xint	msgWindowH = MSG_WINDOW_H;
Xint	choiceImageW = CHOICE_IMAGE_W;
Xint	choiceImageH = CHOICE_IMAGE_H;
Xint	choiceWindowW = CHOICE_WINDOW_W;
Xint	choiceWindowH = CHOICE_WINDOW_H;
Xint	menuImageW = MENU_IMAGE_W;
Xint	menuImageH = MENU_IMAGE_H;
Xint	titleWindowW = TITLE_WINDOW_W;
Xint	titleWindowH = TITLE_WINDOW_H;
Xint	iconWindowW = ICON_WINDOW_W;
Xint	iconWindowH = ICON_WINDOW_H;
X
XDisplay		* mainDisplay;
XColormap	mainColormap;
Xunsigned int	mainDepth;
Xint		mainScreen;
XVisual		* mainVisual;
X
XWindow	rootWindow;
XWindow	mainWindow;
XWindow	drawWindow;
XWindow	choiceWindow;
XWindow	titleWindow;
XWindow	msgWindow;
XWindow	vSBarWindow;
XWindow	hSBarWindow;
XWindow	vRuleWindow;
XWindow	hRuleWindow;
XWindow	iconWindow;
XWindow	iconBaseWindow;
X
Xint	paperWidth = (75*PIX_PER_INCH)/10;
Xint	paperHeight = 10*PIX_PER_INCH;
Xint	drawOrigX = 0;
Xint	drawOrigY = 0;
Xint	drawWinW = DRAW_WINDOW_W;
Xint	drawWinH = DRAW_WINDOW_H;
X
Xint	zoomScale = 0;
X
Xstruct BBRec	drawWinBBox;
X
Xint	colorDisplay;
Xint	fileModified = FALSE;
Xint	objId = 0;
X
Xint	myBgPixel;
Xint	myFgPixel;
Xint	myBorderPixel;
Xint	reverseVideo = FALSE;
X
Xchar	drawPath[MAXPATHLENGTH];
Xchar	bootDir[MAXPATHLENGTH];
Xchar	homeDir[MAXPATHLENGTH];
X
Xint	symPathNumEntries = INVALID;
Xchar	* * symPath;
X
Xint	initDrawWinW, initDrawWinH;
X
Xstatic Window	dummyWindow1, dummyWindow2;
X
Xvoid UpdDrawWinWH ()
X{
X   drawWinW = initDrawWinW << zoomScale;
X   drawWinH = initDrawWinH << zoomScale;
X}
X
Xvoid UpdDrawWinBBox ()
X{
X   drawWinBBox.ltx = drawOrigX;
X   drawWinBBox.lty = drawOrigY;
X   drawWinBBox.rbx = drawOrigX + drawWinW-1;
X   drawWinBBox.rby = drawOrigY + drawWinH-1;
X}
X
Xstatic
Xvoid InitWinSizes ()
X{
X   initDrawWinW = drawWinW;
X   initDrawWinH = drawWinH;
X   hSBarW = drawWinW+rulerW+2*brdrW;
X   vSBarH = drawWinH+rulerW+2*brdrW;
X   titleWindowW = hSBarW+scrollBarW+2*brdrW;
X   msgWindowW = titleWindowW-choiceWindowW-2*brdrW;
X   mainWinW = titleWindowW+2*brdrW;
X   mainWinH = titleWindowH+choiceWindowH+vSBarH+scrollBarW+8*brdrW;
X}
X
Xstatic
Xvoid InverseInitWinSizes ()
X   /* derive other win sizes from mainWinW and mainWinH */
X{
X   titleWindowW = mainWinW-2*brdrW;
X   msgWindowW = titleWindowW-choiceWindowW-2*brdrW;
X   vSBarH = mainWinH-titleWindowH-choiceWindowH-scrollBarW-8*brdrW;
X   hSBarW = titleWindowW-scrollBarW-2*brdrW;
X   drawWinH = initDrawWinH = vSBarH-rulerW-2*brdrW;
X   drawWinW = initDrawWinW = hSBarW-rulerW-2*brdrW;
X}
X
Xvoid mainWinEventHandler (input)
X   XEvent	* input;
X{
X   Window	root_win;
X   int		win_x, win_y;
X   unsigned int	win_w, win_h, win_brdr_w, win_d;
X
X   if (input->type == UnmapNotify)
X      Iconify ();
X   else if (input->type == MapNotify)
X   {
X      if (iconWindowShown) UnIconify ();
X   }
X   else if (input->type == ConfigureNotify)
X   {
X      XGetGeometry (mainDisplay, mainWindow, &root_win, &win_x, &win_y, &win_w,
X            &win_h, &win_brdr_w, &win_d);
X      if (win_w == mainWinW && win_h == mainWinH) return;
X
X      mainWinW = win_w;
X      mainWinH = win_h;
X      initDrawWinW = mainWinW - rulerW - scrollBarW - 6*brdrW;
X      initDrawWinH = mainWinH - titleWindowH - choiceWindowH - rulerW -
X            scrollBarW - 10*brdrW;
X      drawWinW = initDrawWinW;
X      drawWinH = initDrawWinH;
X      hSBarW = initDrawWinW + rulerW + 2*brdrW;
X      vSBarH = initDrawWinH + rulerW + 2*brdrW;
X      titleWindowW = hSBarW + scrollBarW + 2*brdrW;
X      msgWindowW = titleWindowW - choiceWindowW - 2*brdrW;
X      XResizeWindow (mainDisplay, titleWindow, titleWindowW, titleWindowH);
X      XResizeWindow (mainDisplay, msgWindow, msgWindowW, msgWindowH);
X      XMoveWindow (mainDisplay, choiceWindow, msgWindowW+2*brdrW,
X            titleWindowH+2*brdrW);
X      XResizeWindow (mainDisplay, hRuleWindow, drawWinW, rulerW);
X      XResizeWindow (mainDisplay, vRuleWindow, rulerW, drawWinH);
X      XResizeWindow (mainDisplay, drawWindow, drawWinW, drawWinH);
X      XMoveResizeWindow (mainDisplay, vSBarWindow, drawWinW+rulerW+4*brdrW,
X            titleWindowH+choiceWindowH+4*brdrW, scrollBarW, vSBarH);
X      XMoveResizeWindow (mainDisplay, hSBarWindow, 0,
X            titleWindowH+choiceWindowH+rulerW+drawWinH+8*brdrW, hSBarW,
X            scrollBarW);
X      XMoveWindow (mainDisplay, dummyWindow1, drawWinW+rulerW+4*brdrW,
X         titleWindowH+choiceWindowH+rulerW+drawWinH+8*brdrW);
X      UpdDrawWinWH ();
X      UpdDrawWinBBox ();
X      UpdScrollWinWH ();
X      SetDefaultDrawWinClipRecs ();
X   }
X}
X
Xvoid Setup ()
X{
X   int		bitmask = 0;
X   char		* c_ptr;
X   Window	root_win;
X   int		win_x, win_y;
X   unsigned int	win_brdr_w, win_d;
X   XWMHints	wmhints;
X   XSizeHints	sizehints;
X
X   if ((c_ptr = XGetDefault (mainDisplay, TOOL_NAME, "Synchronize")) != NULL)
X      if ((strcmp (c_ptr, "on") == 0) || (strcmp (c_ptr, "On") == 0))
X         XSynchronize (mainDisplay, True);
X
X   colorDisplay = (DisplayPlanes (mainDisplay, mainScreen) == 1) ? FALSE : TRUE;
X
X   InitColor ();
X
X   if ((c_ptr = getenv ("TGIFPATH")) == NULL)
X      strcpy (drawPath, TGIF_PATH);
X   else
X      if (strlen (c_ptr) >= 255)
X         strcpy (drawPath, TGIF_PATH);
X      else
X         strcpy (drawPath, c_ptr);
X
X   if ((c_ptr = getenv ("HOME")) == NULL)
X      strcpy (homeDir, "/");
X   else
X      if (strlen (c_ptr) >= MAXPATHLENGTH-1)
X         strcpy (homeDir, "/");
X      else
X         strcpy (homeDir, c_ptr);
X
X   if (getwd (bootDir) == NULL) strcpy (bootDir, ".");
X
X   sizehints.flags = PPosition | PSize | PMinSize;
X   sizehints.x = 0;
X   sizehints.y = 0;
X   sizehints.width = mainWinW;
X   sizehints.height = mainWinH;
X
X   if ((c_ptr = XGetDefault (mainDisplay, TOOL_NAME, "Geometry")) != NULL)
X   {
X      bitmask = XParseGeometry (c_ptr, &(sizehints.x), &(sizehints.y),
X            (unsigned int *)&(sizehints.width),
X            (unsigned int *)&(sizehints.height));
X      if (bitmask & (XValue | YValue)) sizehints.flags |= USPosition;
X      if (bitmask & (WidthValue | HeightValue))
X      {
X         sizehints.flags |= USSize;
X         drawWinW = sizehints.width;
X         drawWinH = sizehints.height;
X      }
X   }
X
X   if (geometrySpecified && *geometrySpec != '\0')
X   {
X      bitmask = XParseGeometry (geometrySpec, &(sizehints.x), &(sizehints.y),
X            (unsigned int *)&(sizehints.width),
X            (unsigned int *)&(sizehints.height));
X      if (bitmask & (XValue | YValue)) sizehints.flags |= USPosition;
X      if (bitmask & (WidthValue | HeightValue))
X      {
X         sizehints.flags |= USSize;
X         drawWinW = sizehints.width;
X         drawWinH = sizehints.height;
X      }
X   }
X
X   InitWinSizes ();
X   InitFonts ();
X
X   sizehints.min_width = choiceWindowW+4*brdrW+defaultFontWidth;
X   sizehints.min_height =
X         titleWindowH+choiceWindowH+PIX_PER_INCH+rulerW+scrollBarW+10*brdrW;
X   if (mainWinW > sizehints.min_width)
X      sizehints.width = mainWinW;
X   else
X      mainWinW = sizehints.width = sizehints.min_width;
X   if (mainWinH > sizehints.min_height)
X      sizehints.height = mainWinH;
X   else
X      mainWinH = sizehints.height = sizehints.min_height;
X
X   InverseInitWinSizes ();
X
X   if (bitmask & XNegative)
X      sizehints.x += DisplayWidth (mainDisplay, mainScreen) - mainWinW - 1;
X   if (bitmask & YNegative)
X      sizehints.y += DisplayHeight (mainDisplay, mainScreen) - mainWinH - 1;
X
X   if ((mainWindow = XCreateSimpleWindow (mainDisplay, rootWindow,
X         sizehints.x, sizehints.y, sizehints.width, sizehints.height,
X         brdrW, myBorderPixel, myBgPixel)) == 0)
X   { printf ("Could not create main window!\n"); exit(1); }
X
X   XSetNormalHints (mainDisplay, mainWindow, &sizehints);
X   XStoreName (mainDisplay, mainWindow, TOOL_NAME);
X   XGetGeometry (mainDisplay, mainWindow, &root_win, &win_x, &win_y, &mainWinW,
X         &mainWinH, &win_brdr_w, &win_d);
X
X   CreateCursor ();
X   InitScroll ();
X   InitPattern ();
X   InitRuler ();
X   InitMenu ();
X   InitNames ();
X   InitStk ();
X   InitXBm ();
X
X   if ((titleWindow = XCreateSimpleWindow (mainDisplay, mainWindow, 0, 0,
X         titleWindowW, titleWindowH, brdrW, myBorderPixel, myBgPixel)) == 0) 
X   { printf ("Could not create menu window!\n"); exit(1); }
X
X   if ((msgWindow = XCreateSimpleWindow (mainDisplay, mainWindow, 0,
X         titleWindowH+2*brdrW, msgWindowW, msgWindowH, brdrW, myBorderPixel,
X         myBgPixel)) == 0)
X   { printf ("Could not create message window!\n"); exit(1); }
X
X   if ((choiceWindow = XCreateSimpleWindow (mainDisplay, mainWindow,
X         msgWindowW+2*brdrW, titleWindowH+2*brdrW, choiceWindowW, choiceWindowH,
X         brdrW, myBorderPixel, myBgPixel)) == 0)
X   { printf ("Could not create choice window!\n"); exit(1); }
X
X   InitChoice ();
X
X   if ((hRuleWindow = XCreateSimpleWindow (mainDisplay, mainWindow,
X         rulerW+2*brdrW, titleWindowH+choiceWindowH+4*brdrW, drawWinW, rulerW,
X         brdrW, myBorderPixel, myBgPixel)) == 0)
X   { printf ("Could not create horizontal ruler window!\n"); exit(1); }
X
X   if ((vRuleWindow = XCreateSimpleWindow (mainDisplay, mainWindow, 0,
X         titleWindowH+rulerW+choiceWindowH+6*brdrW, rulerW, drawWinH,
X         brdrW, myBorderPixel, myBgPixel)) == 0)
X   { printf ("Could not create vertical ruler window!\n"); exit(1); }
X
X   if ((drawWindow = XCreateSimpleWindow (mainDisplay, mainWindow,
X         rulerW+2*brdrW, titleWindowH+rulerW+choiceWindowH+6*brdrW,
X         drawWinW, drawWinH, brdrW, myBorderPixel, myBgPixel)) == 0) 
X   { printf ("Could not create draw window!\n"); exit(1); }
X
X   if ((vSBarWindow = XCreateSimpleWindow (mainDisplay, mainWindow,
X         4*brdrW+rulerW+drawWinW, titleWindowH+choiceWindowH+4*brdrW,
X         scrollBarW, vSBarH, brdrW, myBorderPixel, myBgPixel)) == 0) 
X   { printf ("Could not create vertical scrollbar window!\n"); exit(1); }
X
X   if ((hSBarWindow = XCreateSimpleWindow (mainDisplay, mainWindow, 0,
X         titleWindowH+rulerW+drawWinH+choiceWindowH+8*brdrW,
X         hSBarW, scrollBarW, brdrW, myBorderPixel, myBgPixel)) == 0) 
X   { printf ("Could not create horizontal scrollbar window!\n"); exit(1); }
X
X   if ((dummyWindow1 = XCreateSimpleWindow (mainDisplay, mainWindow,
X         rulerW+drawWinW+4*brdrW,
X         titleWindowH+choiceWindowH+rulerW+drawWinH+8*brdrW,
X         scrollBarW, scrollBarW, brdrW, myBorderPixel, myBgPixel)) == 0) 
X   { printf ("Could not create dummy window!\n"); exit(1); }
X
X   if ((dummyWindow2 = XCreateSimpleWindow (mainDisplay, mainWindow, 0,
X         titleWindowH+choiceWindowH+4*brdrW, rulerW, rulerW,
X         brdrW, myBorderPixel, myBgPixel)) == 0) 
X   { printf ("Could not create dummy window!\n"); exit(1); }
X
X   UpdDrawWinBBox ();
X   InitTitle ();
X   SetCanvasFont ();
X
X   XMapWindow (mainDisplay, mainWindow);
X   XSelectInput (mainDisplay, mainWindow, KeyPressMask | StructureNotifyMask);
X   XDefineCursor (mainDisplay, mainWindow, defaultCursor);
X
X   XMapWindow (mainDisplay, titleWindow);
X   XSelectInput (mainDisplay, titleWindow, ExposureMask);
X
X   XMapWindow (mainDisplay, msgWindow);
X   XSelectInput (mainDisplay, msgWindow, ButtonPressMask | ExposureMask);
X
X   XMapWindow (mainDisplay, choiceWindow);
X   XSelectInput (mainDisplay, choiceWindow,
X         ButtonReleaseMask | ButtonPressMask | ExposureMask);
X
X   XMapWindow (mainDisplay, hRuleWindow);
X   XSelectInput (mainDisplay, hRuleWindow, ExposureMask);
X   XMapWindow (mainDisplay, vRuleWindow);
X   XSelectInput (mainDisplay, vRuleWindow, ExposureMask);
X
X   XMapWindow (mainDisplay, drawWindow); 
X   XSelectInput (mainDisplay, drawWindow, ButtonReleaseMask |
X         ButtonPressMask | PointerMotionMask | KeyPressMask | ExposureMask);
X
X   XMapWindow (mainDisplay, vSBarWindow);
X   XSelectInput (mainDisplay, vSBarWindow, ButtonPressMask | ExposureMask);
X   XMapWindow (mainDisplay, hSBarWindow);
X   XSelectInput (mainDisplay, hSBarWindow, ButtonPressMask | ExposureMask);
X   XMapWindow (mainDisplay, dummyWindow1);
X   XMapWindow (mainDisplay, dummyWindow2);
X
X   wmhints.flags = InputHint;
X   wmhints.input = True;
X   XSetWMHints (mainDisplay, mainWindow, &wmhints);
X   XSetWMHints (mainDisplay, drawWindow, &wmhints);
X}
X
Xint TieLooseEnds ()
X   /* returns TRUE if something got created */
X   /* returns FALSE otherwise */
X{
X   if (curChoice == DRAWTEXT) return (CreateTextObj ());
X   return (FALSE);
X}
X
Xvoid SetFileModified (modified)
X   int	modified;
X{
X   if (modified != fileModified)
X   {
X      fileModified = modified;
X      RedrawTitleWindow ();
X   }
X}
END_OF_FILE
if test 13850 -ne `wc -c <'setup.c'`; then
    echo shar: \"'setup.c'\" unpacked with wrong size!
fi
# end of 'setup.c'
fi
echo shar: End of archive 13 \(of 23\).
cp /dev/null ark13isdone
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

--
Dan Heller
------------------------------------------------
O'Reilly && Associates		 Z-Code Software
Senior Writer			       President
argv@ora.com			argv@zipcode.com
------------------------------------------------
General Email: argv@sun.com
Comp-sources-x stuff: comp-sources.x@uunet.uu.net