v12i018: tgif, Part02/23
William Cheng
william at CS.UCLA.EDU
Mon Mar 11 08:38:04 AEST 1991
Submitted-by: william at CS.UCLA.EDU (William Cheng)
Posting-number: Volume 12, Issue 18
Archive-name: tgif/part02
---------------------------------> 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 2 (of 23)."
# Contents: box.c button.c choice.c color.c copypaste.c cursor.c
# dialog.c
# Wrapped by william at oahu on Wed Mar 6 09:56:59 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'box.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'box.c'\"
else
echo shar: Extracting \"'box.c'\" \(13586 characters\)
sed "s/^X//" >'box.c' <<'END_OF_FILE'
X/*
X * Author: William Chia-Wei Cheng (william at 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/box.c,v 2.0 91/03/05 12:46:45 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 "color.e"
X#include "cursor.e"
X#include "file.e"
X#include "grid.e"
X#include "obj.e"
X#include "pattern.e"
X#include "poly.e"
X#include "raster.e"
X#include "ruler.e"
X#include "setup.e"
X
Xint boxDrawn = FALSE;
X
Xstatic XPoint bv[5];
X
Xvoid MyBox (window, gc, x1, y1, x2, y2)
X /* Hollow box, solid outline with width=1 */
X Window window;
X GC gc;
X int x1, y1, x2, y2;
X{
X bv[0].x = (short)x1; bv[0].y = (short)y1;
X bv[1].x = (short)x1; bv[1].y = (short)y2;
X bv[2].x = (short)x2; bv[2].y = (short)y2;
X bv[3].x = (short)x2; bv[3].y = (short)y1;
X bv[4].x = (short)x1; bv[4].y = (short)y1;
X XDrawLines (mainDisplay, window, gc, bv, 5, CoordModeOrigin);
X}
X
Xvoid DumpBoxObj (FP, ObjPtr)
X FILE * FP;
X struct ObjRec * ObjPtr;
X{
X register int ltx, lty, rbx, rby, i;
X int fill, width, pen, dash, color_index;
X
X ltx = ObjPtr->obbox.ltx;
X lty = ObjPtr->obbox.lty;
X rbx = ObjPtr->obbox.rbx;
X rby = ObjPtr->obbox.rby;
X
X fill = ObjPtr->detail.b->fill;
X pen = ObjPtr->detail.b->pen;
X width = ObjPtr->detail.b->width;
X dash = ObjPtr->detail.b->dash;
X
X if (fill == NONEPAT && pen == NONEPAT) return;
X
X color_index = ObjPtr->color;
X if (colorDump)
X fprintf (FP, "%.3f %.3f %.3f setrgbcolor\n",
X ((float)tgifColors[color_index].red/maxRGB),
X ((float)tgifColors[color_index].green/maxRGB),
X ((float)tgifColors[color_index].blue/maxRGB));
X
X switch (fill)
X {
X case NONEPAT: break;
X case SOLIDPAT:
X /* solid black object */
X fprintf (FP, "newpath\n %1d %1d moveto\n", ltx, lty);
X fprintf (FP, " %1d %1d lineto\n", rbx, lty);
X fprintf (FP, " %1d %1d lineto\n", rbx, rby);
X fprintf (FP, " %1d %1d lineto\n", ltx, rby);
X fprintf (FP, "closepath fill\n");
X break;
X case BACKPAT:
X /* solid white object */
X fprintf (FP, "newpath\n %1d %1d moveto\n", ltx, lty);
X fprintf (FP, " %1d %1d lineto\n", rbx, lty);
X fprintf (FP, " %1d %1d lineto\n", rbx, rby);
X fprintf (FP, " %1d %1d lineto\n", ltx, rby);
X fprintf (FP, "closepath 1 setgray fill\n");
X if (colorDump)
X fprintf (FP, "%.3f %.3f %.3f setrgbcolor\n",
X ((float)tgifColors[color_index].red/maxRGB),
X ((float)tgifColors[color_index].green/maxRGB),
X ((float)tgifColors[color_index].blue/maxRGB));
X else
X fprintf (FP, "0 setgray\n");
X break;
X default:
X /* patterned */
X fprintf (FP, "gsave\n");
X if (!colorDump)
X fprintf (FP, " pat%1d 8 1 0 72 300 32 div div setpattern\n",
X fill);
X fprintf (FP, " newpath\n %1d %1d moveto\n", ltx, lty);
X fprintf (FP, " %1d %1d lineto\n", rbx, lty);
X fprintf (FP, " %1d %1d lineto\n", rbx, rby);
X fprintf (FP, " %1d %1d lineto\n", ltx, rby);
X if (colorDump)
X {
X fprintf (FP, " closepath eoclip\n");
X DumpPatFill (FP, fill, 8, ObjPtr->bbox, " ");
X }
X else
X fprintf (FP, " closepath fill\n");
X fprintf (FP, "grestore\n");
X break;
X }
X
X fprintf (FP, "%1d setlinewidth\n", widthOfLine[width]);
X if (dash != 0)
X {
X fprintf (FP, "[");
X for (i = 0; i < dashListLength[dash]-1; i++)
X fprintf (FP, "%1d ", (int)(dashList[dash][i]));
X fprintf (FP, "%1d] 0 setdash\n",
X (int)(dashList[dash][dashListLength[dash]-1]));
X }
X
X switch (pen)
X {
X case NONEPAT: break;
X case SOLIDPAT:
X /* solid black object */
X fprintf (FP, "newpath\n %1d %1d moveto\n", ltx, lty);
X fprintf (FP, " %1d %1d lineto\n", rbx, lty);
X fprintf (FP, " %1d %1d lineto\n", rbx, rby);
X fprintf (FP, " %1d %1d lineto\n", ltx, rby);
X fprintf (FP, "closepath stroke\n");
X break;
X case BACKPAT:
X /* solid white object */
X fprintf (FP, "newpath\n %1d %1d moveto\n", ltx, lty);
X fprintf (FP, " %1d %1d lineto\n", rbx, lty);
X fprintf (FP, " %1d %1d lineto\n", rbx, rby);
X fprintf (FP, " %1d %1d lineto\n", ltx, rby);
X fprintf (FP, "closepath 1 setgray stroke 0 setgray\n");
X break;
X default:
X /* patterned */
X fprintf (FP, "gsave\n");
X if (!colorDump)
X fprintf (FP, " pat%1d 8 1 0 72 300 32 div div setpattern\n", pen);
X fprintf (FP, " newpath\n %1d %1d moveto\n", ltx, lty);
X fprintf (FP, " %1d %1d lineto\n", rbx, lty);
X fprintf (FP, " %1d %1d lineto\n", rbx, rby);
X fprintf (FP, " %1d %1d lineto\n", ltx, rby);
X if (colorDump)
X {
X fprintf (FP, " closepath strokepath clip\n");
X DumpPatFill (FP, pen, 8, ObjPtr->bbox, " ");
X }
X else
X fprintf (FP, " closepath stroke\n");
X fprintf (FP, "grestore\n");
X break;
X }
X if (dash != 0) fprintf (FP, "[] 0 setdash\n");
X fprintf (FP, "1 setlinewidth\n\n");
X}
X
Xvoid DrawBoxObj (win, XOff, YOff, ObjPtr)
X Window win;
X struct ObjRec * ObjPtr;
X{
X struct BoxRec * box_ptr = ObjPtr->detail.b;
X int fill, pen, pixel, func, ltx, lty, rbx, rby, width, dash;
X int real_x_off, real_y_off;
X XGCValues values;
X
X pen = box_ptr->pen;
X fill = box_ptr->fill;
X width = box_ptr->width;
X dash = box_ptr->dash;
X pixel = colorPixels[ObjPtr->color];
X
X if (fill == 0 && pen == 0) return;
X
X real_x_off = (XOff >> zoomScale) << zoomScale;
X real_y_off = (YOff >> zoomScale) << zoomScale;
X ltx = (ObjPtr->obbox.ltx - real_x_off) >> zoomScale;
X lty = (ObjPtr->obbox.lty - real_y_off) >> zoomScale;
X rbx = (ObjPtr->obbox.rbx - real_x_off) >> zoomScale;
X rby = (ObjPtr->obbox.rby - real_y_off) >> zoomScale;
X func = GXcopy;
X
X if (fill != 0)
X {
X values.foreground = (fill == 2) ? myBgPixel : pixel;
X values.function = GXcopy;
X values.fill_style = FillOpaqueStippled;
X values.stipple = patPixmap[fill];
X XChangeGC (mainDisplay, drawGC,
X GCForeground | GCFunction | GCFillStyle | GCStipple, &values);
X XFillRectangle (mainDisplay, win, drawGC, ltx, lty, rbx-ltx, rby-lty);
X }
X
X if (pen != 0)
X {
X values.foreground = (pen == 2) ? myBgPixel : pixel;
X values.function = GXcopy;
X values.fill_style = FillOpaqueStippled;
X values.stipple = patPixmap[pen];
X values.line_width = widthOfLine[width] >> zoomScale;
X if (dash != 0)
X {
X XSetDashes (mainDisplay, drawGC, 0, dashList[dash],
X dashListLength[dash]);
X values.line_style = LineOnOffDash;
X }
X else
X values.line_style = LineSolid;
X XChangeGC (mainDisplay, drawGC,
X GCForeground | GCFunction | GCFillStyle | GCStipple | GCLineWidth |
X GCLineStyle, &values);
X XDrawRectangle (mainDisplay, win, drawGC, ltx, lty, rbx-ltx, rby-lty);
X }
X}
X
Xstatic
Xvoid CreateBoxObj (X1, Y1, X2, Y2)
X int X1, Y1, X2, Y2;
X{
X struct BoxRec * box_ptr;
X struct ObjRec * obj_ptr;
X int w, ltx, lty, rbx, rby;
X
X box_ptr = (struct BoxRec *) calloc (1, sizeof(struct BoxRec));
X box_ptr->fill = objFill;
X box_ptr->width = lineWidth;
X box_ptr->pen = penPat;
X box_ptr->dash = curDash;
X
X obj_ptr = (struct ObjRec *) calloc (1, sizeof(struct ObjRec));
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 obj_ptr->bbox.ltx = obj_ptr->obbox.ltx = obj_ptr->x = (ltx << zoomScale) +
X drawOrigX;
X obj_ptr->bbox.lty = obj_ptr->obbox.lty = obj_ptr->y = (lty << zoomScale) +
X drawOrigY;
X obj_ptr->bbox.rbx = obj_ptr->obbox.rbx = (rbx << zoomScale) + drawOrigX;
X obj_ptr->bbox.rby = obj_ptr->obbox.rby = (rby << zoomScale) + drawOrigY;
X w = widthOfLine[lineWidth];
X obj_ptr->bbox.ltx -= w;
X obj_ptr->bbox.lty -= w;
X obj_ptr->bbox.rbx += w;
X obj_ptr->bbox.rby += w;
X obj_ptr->type = OBJ_BOX;
X obj_ptr->color = colorIndex;
X obj_ptr->id = objId++;
X obj_ptr->dirty = FALSE;
X obj_ptr->detail.b = box_ptr;
X obj_ptr->fattr = obj_ptr->lattr = NULL;
X AddObj (NULL, topObj, obj_ptr);
X}
X
Xstatic
Xvoid ContinueBox (OrigX, OrigY)
X int OrigX, OrigY;
X{
X int end_x, end_y, grid_x, grid_y, saved_x, saved_y;
X int done = FALSE;
X int pixel, xor_pixel;
X XGCValues values;
X XEvent input;
X XMotionEvent * motion_ev;
X
X pixel = colorPixels[colorIndex];
X xor_pixel = xorColorPixels[colorIndex];
X
X values.foreground = xor_pixel;
X values.function = GXxor;
X values.fill_style = FillSolid;
X values.line_width = 0;
X values.line_style = LineSolid;
X
X XChangeGC (mainDisplay, drawGC,
X GCForeground | GCFunction | GCFillStyle | GCLineWidth | GCLineStyle,
X &values);
X
X saved_x = grid_x = OrigX;
X saved_y = grid_y = OrigY;
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 MyBox (drawWindow, drawGC, OrigX, OrigY, saved_x, saved_y);
X done = TRUE;
X }
X else if (input.type == MotionNotify)
X {
X motion_ev = &(input.xmotion);
X end_x = motion_ev->x;
X end_y = motion_ev->y;
X GridXY (end_x, end_y, &grid_x, &grid_y);
X if (grid_x != saved_x || grid_y != saved_y)
X {
X MyBox (drawWindow, drawGC, OrigX, OrigY, saved_x, saved_y);
X saved_x = grid_x;
X saved_y = grid_y;
X MyBox (drawWindow, drawGC, OrigX, OrigY, saved_x, saved_y);
X }
X MarkRulers (grid_x, grid_y);
X }
X }
X if (OrigX != grid_x && OrigY != grid_y)
X {
X CreateBoxObj (OrigX, OrigY, grid_x, grid_y);
X DrawBoxObj (drawWindow, drawOrigX, drawOrigY, topObj);
X boxDrawn = TRUE;
X SetFileModified (TRUE);
X }
X}
X
Xvoid DrawBox (input)
X XEvent * input;
X{
X XButtonEvent * button_ev;
X int mouse_x, mouse_y, grid_x, grid_y;
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 ContinueBox (grid_x, grid_y);
X }
X}
X
Xvoid SaveBoxObj (FP, ObjPtr)
X FILE * FP;
X struct ObjRec * ObjPtr;
X{
X fprintf (FP, "box('%s',", colorMenuItems[ObjPtr->color]);
X fprintf (FP, "%1d,%1d,%1d,%1d,%1d,%1d,%1d,%1d,%1d,", ObjPtr->obbox.ltx,
X ObjPtr->obbox.lty, ObjPtr->obbox.rbx, ObjPtr->obbox.rby,
X ObjPtr->detail.b->fill, ObjPtr->detail.b->width,
X ObjPtr->detail.b->pen, ObjPtr->id, ObjPtr->detail.b->dash);
X SaveAttrs (FP, ObjPtr->lattr);
X fprintf (FP, ")");
X}
X
Xvoid ReadBoxObj (Inbuf, ObjPtr)
X char * Inbuf;
X struct ObjRec * * ObjPtr;
X{
X struct BoxRec * box_ptr;
X char color_str[20], * s;
X int ltx, lty, rbx, rby, fill, width, pen, dash, w;
X
X *ObjPtr = (struct ObjRec *) calloc (1, sizeof(struct ObjRec));
X s = FindChar ('(', Inbuf);
X s = ParseStr (s, ',', color_str);
X box_ptr = (struct BoxRec *) calloc (1, sizeof(struct BoxRec));
X
X if (fileVersion <= 5)
X {
X sscanf (s, "%d , %d , %d , %d , %d , %d , %d",
X <x, <y, &rbx, &rby, &fill, &width, &pen);
X switch (width)
X {
X case 1: width = 3; break;
X case 2: width = 6; break;
X }
X (*ObjPtr)->id = objId++;
X dash = 0;
X }
X else if (fileVersion <= 7)
X {
X sscanf (s, "%d , %d , %d , %d , %d , %d , %d",
X <x, <y, &rbx, &rby, &fill, &width, &pen);
X (*ObjPtr)->id = objId++;
X dash = 0;
X }
X else if (fileVersion <= 8)
X {
X sscanf (s, "%d , %d , %d , %d , %d , %d , %d , %d",
X <x, <y, &rbx, &rby, &fill, &width, &pen, &((*ObjPtr)->id));
X if ((*ObjPtr)->id >= objId) objId = (*ObjPtr)->id + 1;
X dash = 0;
X }
X else
X {
X sscanf (s, "%d , %d , %d , %d , %d , %d , %d , %d , %d",
X <x, <y, &rbx, &rby, &fill, &width, &pen, &((*ObjPtr)->id),
X &dash);
X if ((*ObjPtr)->id >= objId) objId = (*ObjPtr)->id + 1;
X }
X
X box_ptr->fill = fill;
X box_ptr->width = width;
X box_ptr->pen = pen;
X box_ptr->dash = dash;
X (*ObjPtr)->x = ltx;
X (*ObjPtr)->y = lty;
X (*ObjPtr)->color = FindColorIndex (color_str);
X (*ObjPtr)->dirty = FALSE;
X (*ObjPtr)->type = OBJ_BOX;
X (*ObjPtr)->obbox.ltx = ltx;
X (*ObjPtr)->obbox.lty = lty;
X (*ObjPtr)->obbox.rbx = rbx;
X (*ObjPtr)->obbox.rby = rby;
X w = widthOfLine[width];
X (*ObjPtr)->bbox.ltx = ltx - w;
X (*ObjPtr)->bbox.lty = lty - w;
X (*ObjPtr)->bbox.rbx = rbx + w;
X (*ObjPtr)->bbox.rby = rby + w;
X (*ObjPtr)->detail.b = box_ptr;
X}
X
Xvoid FreeBoxObj (ObjPtr)
X struct ObjRec * ObjPtr;
X{
X cfree (ObjPtr->detail.b);
X cfree (ObjPtr);
X}
END_OF_FILE
if test 13586 -ne `wc -c <'box.c'`; then
echo shar: \"'box.c'\" unpacked with wrong size!
fi
# end of 'box.c'
fi
if test -f 'button.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'button.c'\"
else
echo shar: Extracting \"'button.c'\" \(6011 characters\)
sed "s/^X//" >'button.c' <<'END_OF_FILE'
X/*
X * Author: William Chia-Wei Cheng (william at 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/button.c,v 2.0 91/03/05 12:46:48 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 "cursor.e"
X#include "font.e"
X#include "mainloop.e"
X#include "raster.e"
X#include "rect.e"
X#include "setup.e"
X
Xint ButtonWidth(Str, Len)
X char * Str;
X{
X return (defaultFontWidth * max(strlen (Str) + 2, Len));
X}
X
Xvoid DisplayButton (Win, Str, Len, BBox, Normal)
X Window Win;
X char * Str;
X struct BBRec * BBox;
X short Normal;
X int Len;
X /* display a button in Win at location ((*BBox).ltx,(*BBox).lty), Str is */
X /* centered in the button. The width of the button is the width of */
X /* Str + 2 character widths or the width of Len number of characters, */
X /* whichever is bigger. *BBox will be set with the bounding */
X /* box of the button. */
X{
X int button_w, button_h, len_of_str, left;
X
X len_of_str = strlen (Str);
X button_w = defaultFontWidth * max(len_of_str+2,Len);
X left = (button_w - defaultFontWidth * len_of_str) / 2;
X button_h = defaultFontHeight + 4;
X (*BBox).rbx = (*BBox).ltx + button_w - 1;
X (*BBox).rby = (*BBox).lty + button_h - 1;
X
X if (Normal)
X {
X XDrawRectangle (mainDisplay, Win, defaultGC, (*BBox).ltx, (*BBox).lty,
X button_w, button_h);
X XDrawString (mainDisplay, Win, defaultGC, (*BBox).ltx+left,
X (*BBox).lty+defaultFontAsc+2, Str, len_of_str);
X }
X else
X {
X XFillRectangle (mainDisplay, Win, revDefaultGC, (*BBox).ltx, (*BBox).lty,
X button_w, button_h);
X }
X}
X
Xstatic char * confirmStr[] = { "YES", "NO", "CANCEL" };
X
Xint YesNoCancel (Str)
X char * Str;
X /* Create a window with Str centered. This window also has 3 buttons */
X /* in it, labeled YES, NO, and CANCEL. The window has an origin at */
X /* (100,100) relative to the origin of RootWindow. */
X{
X int w, h, str_start, button_start, top;
X int str_width, button_widths, dsp_w, dsp_h;
X Window confirm_win;
X struct BBRec button_bbox[MAX_CONFIRMS];
X XEvent input;
X XButtonEvent * button_ev;
X XKeyEvent * key_ev;
X int i, confirming = TRUE, choice = CONFIRM_YES;
X int win_x, win_y;
X char buf[80];
X KeySym key_sym;
X XComposeStatus c_stat;
X XSetWindowAttributes win_attrs;
X
X top = defaultFontAsc+2;
X
X button_widths = ButtonWidth("YES", 8) + ButtonWidth("NO", 8) +
X ButtonWidth("CANCEL", 8) + 2 * defaultFontWidth;
X str_width = defaultFontWidth * strlen (Str);
X
X if (str_width > button_widths)
X {
X w = str_width + 4 * defaultFontWidth;
X str_start = 2 * defaultFontWidth;
X button_start = (w - button_widths) / 2;
X }
X else
X {
X w = button_widths + 4 * defaultFontWidth;
X str_start = (w - str_width) / 2;
X button_start = 2 * defaultFontWidth;
X }
X
X h = 5 * defaultFontHeight;
X
X dsp_w = DisplayWidth (mainDisplay, mainScreen);
X dsp_h = DisplayHeight (mainDisplay, mainScreen);
X
X win_x = (w > dsp_w) ? 0 : (dsp_w - w)/2;
X win_y = (h > dsp_h) ? 0 : (dsp_h - h)/3;
X
X if ((confirm_win = XCreateSimpleWindow (mainDisplay, rootWindow,
X win_x, win_y, w, h, brdrW, myBorderPixel, myBgPixel)) == 0)
X { printf ("Could not create yes-no-okay window!\n"); exit (-1); }
X
X win_attrs.save_under = True;
X XChangeWindowAttributes (mainDisplay, confirm_win, CWSaveUnder, &win_attrs);
X
X XSetTransientForHint (mainDisplay, confirm_win, mainWindow);
X XMapWindow (mainDisplay, confirm_win);
X XSelectInput (mainDisplay, confirm_win,
X KeyPressMask | ButtonPressMask | ExposureMask);
X
X while (confirming)
X {
X XNextEvent (mainDisplay, &input);
X if (input.type == Expose)
X {
X XDrawRectangle (mainDisplay, confirm_win, defaultGC, 0, 0, w-1, h-1);
X XDrawString (mainDisplay, confirm_win, defaultGC, str_start,
X defaultFontHeight+top, Str, strlen(Str));
X
X button_bbox[0].lty = button_bbox[1].lty = button_bbox[2].lty =
X 3 * defaultFontHeight;
X button_bbox[CONFIRM_YES].ltx = button_start;
X DisplayButton (confirm_win, "YES", 8, &button_bbox[CONFIRM_YES],
X BUTTON_NORMAL);
X button_bbox[CONFIRM_NO].ltx =
X button_bbox[CONFIRM_YES].rbx + 1 + defaultFontWidth;
X DisplayButton (confirm_win, "NO", 8, &button_bbox[CONFIRM_NO],
X BUTTON_NORMAL);
X button_bbox[CONFIRM_CANCEL].ltx =
X button_bbox[CONFIRM_NO].rbx + 1 + defaultFontWidth;
X DisplayButton (confirm_win, "CANCEL", 8, &button_bbox[CONFIRM_CANCEL],
X BUTTON_NORMAL);
X
X continue;
X }
X else if (input.type == KeyPress)
X {
X key_ev = &(input.xkey);
X XLookupString (key_ev, buf, 80, &key_sym, &c_stat);
X
X if (buf[0] == 'c' || buf[0] == 'C' || buf[0] == '\033')
X {
X confirming = FALSE;
X choice = CONFIRM_CANCEL;
X }
X else if (buf[0]=='y' || buf[0]=='Y' || buf[0]=='\r' || buf[0]=='\n')
X {
X confirming = FALSE;
X choice = CONFIRM_YES;
X }
X else if (buf[0] == 'n' || buf[0] == 'N')
X {
X confirming = FALSE;
X choice = CONFIRM_NO;
X }
X }
X else if (input.type == ButtonPress)
X {
X button_ev = &(input.xbutton);
X for (i = 0; i < MAX_CONFIRMS; i++)
X if (PointInBBox (button_ev->x, button_ev->y, button_bbox[i]))
X {
X confirming = FALSE;
X choice = i;
X }
X }
X }
X
X DisplayButton (confirm_win, confirmStr[choice], 8, &button_bbox[choice],
X BUTTON_INVERT);
X
X XDestroyWindow (mainDisplay, confirm_win);
X XSync (mainDisplay, FALSE);
X while (XCheckMaskEvent (mainDisplay, ExposureMask, &input)) ;
X return (choice);
X}
END_OF_FILE
if test 6011 -ne `wc -c <'button.c'`; then
echo shar: \"'button.c'\" unpacked with wrong size!
fi
# end of 'button.c'
fi
if test -f 'choice.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'choice.c'\"
else
echo shar: Extracting \"'choice.c'\" \(15091 characters\)
sed "s/^X//" >'choice.c' <<'END_OF_FILE'
X/*
X * Author: William Chia-Wei Cheng (william at 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/choice.c,v 2.0 91/03/05 12:46:49 william Exp $";
X#endif
X
X#include <X11/Xlib.h>
X#include "const.h"
X#include "types.h"
X
X#include "align.e"
X#include "arc.e"
X#include "box.e"
X#include "color.e"
X#include "cursor.e"
X#include "font.e"
X#include "grid.e"
X#include "mark.e"
X#include "msg.e"
X#include "oval.e"
X#include "pattern.e"
X#include "poly.e"
X#include "polygon.e"
X#include "raster.e"
X#include "rcbox.e"
X#include "select.e"
X#include "setup.e"
X#include "text.e"
X
Xint curChoice = NOTHING;
X
Xstatic GC choiceGC;
Xstatic Pixmap choiceBackingPixmap;
X
Xvoid InitChoice ()
X{
X XGCValues values;
X
X values.foreground = 1;
X values.background = 0;
X values.font = defaultFontPtr->fid;
X choiceGC = XCreateGC (mainDisplay, choiceWindow,
X GCForeground | GCBackground | GCFont, &values);
X
X choiceBackingPixmap = XCreatePixmap (mainDisplay, choiceWindow,
X choiceWindowW, choiceWindowH, mainDepth);
X}
X
Xvoid CleanUpChoices ()
X{
X XFreeGC (mainDisplay, choiceGC);
X XFreePixmap (mainDisplay, choiceBackingPixmap);
X}
X
Xvoid ShowMode ()
X{
X XSetStipple (mainDisplay, rasterGC, choicePixmap[curChoice]);
X XFillRectangle (mainDisplay, choiceWindow, rasterGC, 0, 0, choiceImageW,
X choiceImageH);
X}
X
Xvoid ShowWhereToPrint ()
X{
X if (colorDump)
X XSetForeground (mainDisplay, rasterGC, colorPixels[colorIndex]);
X XSetStipple (mainDisplay, rasterGC, whereToPrintPixmap[whereToPrint]);
X XFillRectangle (mainDisplay, choiceWindow, rasterGC, 6*choiceImageW, 0,
X choiceImageW, choiceImageH);
X if (colorDump) XSetForeground (mainDisplay, rasterGC, myFgPixel);
X}
X
Xvoid ShowColor (PropagateWhereToPrint)
X int PropagateWhereToPrint;
X{
X XGCValues values;
X
X if (colorDisplay)
X {
X values.foreground = colorPixels[colorIndex];
X values.function = GXcopy;
X values.fill_style = FillOpaqueStippled;
X values.stipple = patPixmap[1];
X XChangeGC (mainDisplay, patGC,
X GCForeground | GCFunction | GCFillStyle | GCStipple, &values);
X
X XFillRectangle (mainDisplay, choiceWindow, patGC,
X 0, choiceImageH, choiceImageW, choiceImageH);
X }
X if (PropagateWhereToPrint) ShowWhereToPrint ();
X}
X
Xvoid ShowHoriAlign ()
X{
X XSetStipple (mainDisplay, rasterGC, alignHoriPixmap[horiAlign]);
X XFillRectangle (mainDisplay, choiceWindow, rasterGC, choiceImageW, 0,
X choiceImageW, choiceImageH);
X}
X
Xvoid ShowVertAlign ()
X{
X XSetStipple (mainDisplay, rasterGC, alignVertPixmap[vertAlign]);
X XFillRectangle (mainDisplay, choiceWindow, rasterGC, choiceImageW,
X choiceImageH, choiceImageW, choiceImageH);
X}
X
Xvoid ShowJust ()
X{
X XSetStipple (mainDisplay, rasterGC, justPixmap[textJust]);
X XFillRectangle (mainDisplay, choiceWindow, rasterGC, 2*choiceImageW, 0,
X choiceImageW, choiceImageH);
X}
X
Xvoid ShowCurFont ()
X{
X int x, y, w, h;
X XRectangle recs[1];
X XGCValues values;
X
X recs[0].x = 2*choiceImageW;
X recs[0].y = choiceImageH;
X recs[0].width = choiceImageW;
X recs[0].height = choiceImageH;
X
X w = XTextWidth (canvasFontPtr, "W", 1);
X h = canvasFontHeight;
X
X x = (w > choiceImageW) ?
X 2*choiceImageW - (w-choiceImageW)/2 :
X 2*choiceImageW + (choiceImageW-w)/2;
X y = (h > choiceImageH) ?
X choiceImageH + (canvasFontAsc-(h-choiceImageH)/2) :
X choiceImageH + (canvasFontAsc+(choiceImageH-h)/2);
X
X XClearArea (mainDisplay, choiceWindow, 2*choiceImageW, choiceImageH,
X choiceImageW, choiceImageH, FALSE);
X
X XSetFont (mainDisplay, choiceGC, canvasFontPtr->fid);
X XSetClipRectangles (mainDisplay, choiceGC, 0, 0, recs, 1, YXBanded);
X
X values.foreground = myFgPixel;
X values.background = myBgPixel;
X XChangeGC (mainDisplay, choiceGC, GCForeground | GCBackground, &values);
X
X XDrawString (mainDisplay, choiceWindow, choiceGC, x, y, "W", 1);
X
X values.foreground = 1;
X values.background = 0;
X XChangeGC (mainDisplay, choiceGC, GCForeground | GCBackground, &values);
X
X recs[0].x = 0;
X recs[0].y = 0;
X recs[0].width = choiceWindowW;
X recs[0].height = choiceWindowH;
X XSetClipRectangles (mainDisplay, choiceGC, 0, 0, recs, 1, YXBanded);
X}
X
Xvoid ShowRotate ()
X{
X XSetStipple (mainDisplay, rasterGC, rotatePixmap[curRotate]);
X XFillRectangle (mainDisplay, choiceWindow, rasterGC, 3*choiceImageW, 0,
X choiceImageW, choiceImageH);
X}
X
Xvoid ShowSpecial ()
X{
X XSetStipple (mainDisplay, rasterGC, specialPixmap);
X XFillRectangle (mainDisplay, choiceWindow, rasterGC, 3*choiceImageW,
X choiceImageH, choiceImageW, choiceImageH);
X}
X
Xvoid ShowLineWidth ()
X{
X XSetStipple (mainDisplay, rasterGC, shortLineWidthPixmap[lineWidth]);
X XFillRectangle (mainDisplay, choiceWindow, rasterGC, 4*choiceImageW, 0,
X choiceImageW, choiceImageH);
X}
X
Xvoid ShowLineStyle ()
X{
X XSetStipple (mainDisplay, rasterGC, shortLineStylePixmap[lineStyle]);
X XFillRectangle (mainDisplay, choiceWindow, rasterGC, 4*choiceImageW,
X choiceImageH, choiceImageW, choiceImageH);
X}
X
Xvoid ShowLineType ()
X{
X XSetStipple (mainDisplay, rasterGC, shortLineTypePixmap[curSpline]);
X XFillRectangle (mainDisplay, choiceWindow, rasterGC, 5*choiceImageW, 0,
X choiceImageW, choiceImageH);
X}
X
Xvoid ShowDash ()
X{
X XSetStipple (mainDisplay, rasterGC, shortDashPixmap[curDash]);
X XFillRectangle (mainDisplay, choiceWindow, rasterGC, 5*choiceImageW,
X choiceImageH, choiceImageW, choiceImageH);
X}
X
Xvoid ShowFile ()
X{
X XSetStipple (mainDisplay, rasterGC, filePixmap);
X XFillRectangle (mainDisplay, choiceWindow, rasterGC, 6*choiceImageW,
X choiceImageH, choiceImageW, choiceImageH);
X}
X
Xvoid ShowFill ()
X{
X XGCValues values;
X
X values.foreground = myFgPixel;
X values.background = myBgPixel;
X values.function = GXcopy;
X values.fill_style = FillOpaqueStippled;
X values.stipple = patPixmap[objFill];
X XChangeGC (mainDisplay, patGC,
X GCForeground | GCBackground | GCFunction | GCFillStyle | GCStipple,
X &values);
X
X XFillRectangle (mainDisplay, choiceWindow, patGC,
X 7*choiceImageW, 0, choiceImageW, choiceImageH);
X}
X
Xvoid ShowPen ()
X{
X XGCValues values;
X
X values.foreground = myFgPixel;
X values.background = myBgPixel;
X values.function = GXcopy;
X values.fill_style = FillOpaqueStippled;
X values.stipple = patPixmap[penPat];
X XChangeGC (mainDisplay, patGC,
X GCForeground | GCBackground | GCFunction | GCFillStyle | GCStipple,
X &values);
X
X XFillRectangle (mainDisplay, choiceWindow, patGC,
X 7*choiceImageW, choiceImageH, choiceImageW, choiceImageH);
X}
X
Xvoid SetCurChoice (NewChoice)
X int NewChoice;
X{
X if (curChoice == NewChoice) return;
X
X switch (curChoice)
X {
X case NOTHING:
X if (topSel != NULL)
X {
X HighLightReverse ();
X RemoveAllSel ();
X }
X break;
X case DRAWTEXT:
X CreateTextObj ();
X if (NewChoice == NOTHING && textDrawn) HighLightJustDrawnText ();
X textDrawn = FALSE;
X SetDefaultCursor (drawWindow);
X textCursorShown = FALSE;
X break;
X case DRAWBOX:
X if (NewChoice == NOTHING && boxDrawn) SelectTopObj ();
X boxDrawn = FALSE;
X break;
X case DRAWCIRCLE:
X if (NewChoice == NOTHING && ovalDrawn) SelectTopObj ();
X ovalDrawn = FALSE;
X break;
X case DRAWPOLY:
X if (NewChoice == NOTHING && polyDrawn) SelectTopObj ();
X polyDrawn = FALSE;
X break;
X case DRAWPOLYGON:
X if (NewChoice == NOTHING && polygonDrawn) SelectTopObj ();
X polygonDrawn = FALSE;
X break;
X case DRAWARC:
X if (NewChoice == NOTHING && arcDrawn) SelectTopObj ();
X arcDrawn = FALSE;
X break;
X case DRAWRCBOX:
X if (NewChoice == NOTHING && rcBoxDrawn) SelectTopObj ();
X rcBoxDrawn = FALSE;
X break;
X }
X
X curChoice = NewChoice;
X
X if (curChoice == DRAWTEXT)
X {
X SetTextCursor (drawWindow);
X textCursorShown = FALSE;
X }
X
X ShowMode ();
X}
X
Xvoid ChoiceEventHandler (input)
X XEvent * input;
X{
X XEvent ev;
X XButtonEvent * button_ev;
X int xindex, yindex, delta = 0, root_x, root_y, x = 0, y = 0;
X Window root_win, child_win;
X unsigned int status;
X
X if (input->type == Expose)
X {
X XSync (mainDisplay, FALSE);
X while (XCheckWindowEvent (mainDisplay, choiceWindow, ExposureMask, &ev)) ;
X RedrawChoiceWindow ();
X }
X else if (input->type == ButtonPress)
X {
X button_ev = &(input->xbutton);
X switch (button_ev->button)
X {
X case Button1: delta = 1; break;
X case Button2:
X XQueryPointer (mainDisplay, rootWindow, &root_win, &child_win,
X &root_x, &root_y, &x, &y, &status);
X break;
X case Button3: delta = -1; break;
X default: return;
X }
X xindex = (int)(button_ev->x / choiceImageW);
X yindex = (int)(button_ev->y / choiceImageH);
X switch (xindex)
X {
X case 0:
X if (yindex == 0)
X {
X if (delta == 0)
X ModeMenu (x, y);
X else
X SetCurChoice ((curChoice+MAXCHOICES+delta) % MAXCHOICES);
X }
X else if (colorDisplay)
X {
X if (delta == 0)
X ColorMenu (x, y);
X else
X {
X if (curChoice != NOTHING) SetCurChoice (NOTHING);
X colorIndex = (colorIndex+maxColors+delta) % maxColors;
X ShowColor (TRUE);
X if (topSel != NULL) ChangeAllSelColor (colorIndex);
X }
X }
X break;
X case 1:
X if (yindex == 0)
X {
X if (delta == 0)
X SizeMenu (x, y);
X else
X {
X horiAlign = (horiAlign+MAXALIGNS+delta) % MAXALIGNS;
X ShowHoriAlign ();
X }
X }
X else
X {
X if (delta == 0)
X FontDPIMenu (x, y);
X else
X {
X vertAlign = (vertAlign+MAXALIGNS+delta) % MAXALIGNS;
X ShowVertAlign ();
X }
X }
X break;
X case 2:
X if (yindex == 0)
X {
X if (delta == 0)
X StyleMenu (x, y);
X else
X {
X if (curChoice != NOTHING) SetCurChoice (NOTHING);
X textJust = (textJust+MAXJUSTS+delta) % MAXJUSTS;
X ShowJust ();
X if (topSel != NULL) ChangeFontJust (textJust);
X }
X }
X else
X {
X if (delta == 0)
X FontMenu (x, y);
X else
X {
X if (curChoice != NOTHING) SetCurChoice (NOTHING);
X curFont = (curFont+MAXFONTS+delta) % MAXFONTS;
X SetCanvasFont ();
X ShowCurFont ();
X if (topSel != NULL) ChangeFont (curFont);
X }
X }
X break;
X case 3:
X if (yindex == 0)
X {
X if (delta == 0)
X ArrangeMenu (x, y);
X else
X {
X if (curChoice != NOTHING) SetCurChoice (NOTHING);
X curRotate = (curRotate+4+delta) % 4;
X ShowRotate ();
X if (topSel != NULL)
X {
X if (delta == 1)
X RotateClockWise ();
X else
X RotateCounter ();
X }
X }
X }
X else
X {
X if (delta == 0)
X SpecialMenu (x, y);
X }
X break;
X case 4:
X if (yindex == 0)
X {
X if (delta == 0)
X LineStyleMenu (x, y);
X else
X {
X if (curChoice != NOTHING) SetCurChoice (NOTHING);
X lineWidth = (lineWidth+MAXLINEWIDTHS+delta) % MAXLINEWIDTHS;
X ShowLineWidth ();
X if (topSel != NULL) ChangeAllSelLineWidth (lineWidth);
X }
X }
X else
X {
X if (delta == 0)
X LineStyleMenu (x, y);
X else
X {
X if (curChoice != NOTHING) SetCurChoice (NOTHING);
X lineStyle = (lineStyle+MAXLINESTYLES+delta) % MAXLINESTYLES;
X ShowLineStyle ();
X if (topSel != NULL) ChangeAllSelLineStyle (lineStyle);
X }
X }
X break;
X case 5:
X if (yindex == 0)
X {
X if (delta == 0)
X LineStyleMenu (x, y);
X else
X {
X if (curChoice != NOTHING) SetCurChoice (NOTHING);
X curSpline = (curSpline+MAXLINETYPES+delta) % MAXLINETYPES;
X ShowLineType ();
X if (topSel != NULL) ChangeAllSelLineType (curSpline);
X }
X }
X else
X {
X if (delta == 0)
X LineStyleMenu (x, y);
X else
X {
X if (curChoice != NOTHING) SetCurChoice (NOTHING);
X curDash = (curDash+MAXDASHES+delta) % MAXDASHES;
X ShowDash ();
X if (topSel != NULL) ChangeAllSelDashes (curDash);
X }
X }
X break;
X case 6:
X if (yindex == 0)
X {
X if (delta == 0)
X LayoutMenu (x, y);
X else
X {
X whereToPrint = (whereToPrint+MAXWHERETOPRINT+delta) %
X MAXWHERETOPRINT-1;
X ToggleWhereToPrint ();
X }
X }
X else
X {
X if (delta == 0)
X FileMenu (x, y);
X }
X break;
X case 7:
X if (yindex == 0)
X {
X if (delta == 0)
X FillMenu (x, y);
X else
X {
X if (curChoice != NOTHING) SetCurChoice (NOTHING);
X objFill = (objFill+MAXPATTERNS+delta) % MAXPATTERNS;
X ShowFill ();
X if (topSel != NULL) ChangeAllSelFill (objFill);
X }
X }
X else
X {
X if (delta == 0)
X PenMenu (x, y);
X else
X {
X if (curChoice != NOTHING) SetCurChoice (NOTHING);
X penPat = (penPat+MAXPATTERNS+delta) % MAXPATTERNS;
X ShowPen ();
X if (topSel != NULL) ChangeAllSelPen (penPat);
X }
X }
X break;
X }
X }
X}
END_OF_FILE
if test 15091 -ne `wc -c <'choice.c'`; then
echo shar: \"'choice.c'\" unpacked with wrong size!
fi
# end of 'choice.c'
fi
if test -f 'color.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'color.c'\"
else
echo shar: Extracting \"'color.c'\" \(12182 characters\)
sed "s/^X//" >'color.c' <<'END_OF_FILE'
X/*
X * Author: William Chia-Wei Cheng (william at 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/color.c,v 2.0 91/03/05 14:17:36 william Exp $";
X#endif
X
X#include <X11/Xlib.h>
X#include "const.h"
X#include "types.h"
X
X#include "choice.e"
X#include "mark.e"
X#include "menu.e"
X#include "obj.e"
X#include "raster.e"
X#include "select.e"
X#include "setup.e"
X#include "text.e"
X
X#define COLORSTRLEN 80
X
Xint maxColors = MAXCOLORS;
Xint defaultColorIndex = 4;
Xint colorIndex = 0;
Xint * colorPixels = NULL;
Xint * xorColorPixels = NULL;
Xchar myFgColorStr[COLORSTRLEN];
Xchar myBgColorStr[COLORSTRLEN];
Xchar * * colorMenuItems = NULL;
XXColor * tgifColors;
Xint maxRGB = 0;
Xint colorDump = FALSE;
X
Xstatic int allocatedMaxColors = MAXCOLORS;
X
Xstatic char * defaultColorMenuItems[MAXCOLORS] =
X{
X "magenta", "red", "green", "blue", "yellow", "pink", "cyan", "CadetBlue",
X "white", "DarkSlateGray"
X};
X
Xvoid DefaultColorArrays (Entries, ForePixels, Valid)
X int Entries, * * ForePixels, * * Valid;
X{
X register int i, * fore_pixels, pixel, * valid;
X
X pixel = myFgPixel;
X *ForePixels = fore_pixels = (int *) calloc (Entries, sizeof(int));
X *Valid = valid = (int *) calloc (Entries, sizeof(int));
X for (i = 0; i < Entries; i++)
X {
X *fore_pixels++ = pixel;
X *valid++ = TRUE;
X }
X}
X
Xint FindColorIndex (s)
X char * s;
X{
X register int i;
X
X if (colorMenuItems == NULL) return (0);
X
X for (i = 0; i < maxColors; i++)
X if (strcmp(s, colorMenuItems[i]) == 0)
X break;
X if (i == maxColors)
X {
X printf ("Can not find color '%s', use '%s' instead.\n", s,
X colorMenuItems[defaultColorIndex]);
X return (defaultColorIndex);
X }
X return (i);
X}
X
Xvoid InitColor ()
X{
X register int i, index;
X XColor color, exact_def;
X char buf[80], * c_ptr, fg_color[80], bg_color[80], brdr_color[80];
X int num, color_in_x_default = FALSE;
X int bg_allocated=FALSE, fg_allocated=FALSE, brdr_allocated=FALSE;
X int tmp_max;
X
X if ((c_ptr = XGetDefault (mainDisplay, TOOL_NAME, "ReverseVideo")) != NULL)
X reverseVideo = (strcmp (c_ptr, "on") == 0);
X
X if (colorDisplay)
X {
X if ((c_ptr = XGetDefault (mainDisplay, TOOL_NAME, "Foreground")) != NULL)
X strcpy (fg_color, c_ptr);
X else
X strcpy (fg_color, "white");
X if ((c_ptr = XGetDefault (mainDisplay, TOOL_NAME, "Background")) != NULL)
X strcpy (bg_color, c_ptr);
X else
X strcpy (bg_color, "black");
X if ((c_ptr = XGetDefault (mainDisplay, TOOL_NAME, "BorderColor")) != NULL)
X strcpy (brdr_color, c_ptr);
X else
X strcpy (brdr_color, "white");
X
X if ((c_ptr = XGetDefault (mainDisplay, TOOL_NAME, "MaxColors")) != NULL)
X {
X color_in_x_default = TRUE;
X maxColors = atoi (c_ptr);
X if ((c_ptr = XGetDefault (mainDisplay, TOOL_NAME, "DefaultColorIndex"))
X != NULL)
X {
X num = atoi (c_ptr);
X if (num < maxColors)
X defaultColorIndex = num;
X else
X {
X printf ("Warning: DefaultColorIndex >= MaxColors, ");
X printf ("Use 0 for DefaultColorIndex\n");
X defaultColorIndex = 0;
X }
X }
X else
X defaultColorIndex = 0;
X }
X else
X {
X if ((c_ptr = XGetDefault (mainDisplay, TOOL_NAME, "DefaultColorIndex"))
X != NULL)
X {
X num = atoi (c_ptr);
X if (num < maxColors) defaultColorIndex = num;
X }
X }
X }
X else
X {
X if (reverseVideo)
X {
X strcpy (fg_color, "white");
X strcpy (bg_color, "black");
X strcpy (brdr_color, "white");
X }
X else
X {
X strcpy (fg_color, "black");
X strcpy (bg_color, "white");
X strcpy (brdr_color, "black");
X }
X }
X
X colorIndex = defaultColorIndex;
X
X colorPixels = (int *) calloc (maxColors, sizeof (int));
X xorColorPixels = (int *) calloc (maxColors, sizeof (int));
X colorMenuItems = (char * *) calloc (maxColors, sizeof (char *));
X
X tgifColors = (XColor *) calloc (maxColors, sizeof (XColor));
X
X allocatedMaxColors = maxColors;
X for (i = 0; i < allocatedMaxColors; i++)
X colorMenuItems[i] = (char *) calloc (COLORSTRLEN, sizeof(char));
X
X if (color_in_x_default)
X {
X for (i = 0; i < maxColors; i++)
X {
X sprintf (buf, "Color%1d", i);
X if ((c_ptr = XGetDefault (mainDisplay, TOOL_NAME, buf)) != NULL)
X strcpy (colorMenuItems[i], c_ptr);
X else
X {
X printf ("Could not GetDefault %s*%s\n", TOOL_NAME, buf);
X exit (-1);
X }
X }
X }
X else
X for (i = 0; i < maxColors; i++)
X strcpy (colorMenuItems[i], defaultColorMenuItems[i]);
X
X if (colorDisplay)
X {
X index = 0;
X for (i = 0; i < maxColors; i++)
X {
X if (!XAllocNamedColor(mainDisplay, mainColormap, colorMenuItems[i],
X &color, &exact_def))
X continue;
X
X if (i != index) strcpy (colorMenuItems[index], colorMenuItems[i]);
X
X colorPixels[index] = color.pixel;
X
X tgifColors[index].red = color.red;
X tgifColors[index].green = color.green;
X tgifColors[index].blue = color.blue;
X
X if (strcmp (colorMenuItems[i], fg_color) == 0)
X {
X if (reverseVideo)
X {
X myBgPixel = color.pixel;
X strcpy (myBgColorStr, fg_color);
X }
X else
X {
X myFgPixel = color.pixel;
X strcpy (myFgColorStr, fg_color);
X }
X
X fg_allocated = TRUE;
X }
X if (strcmp (colorMenuItems[i], bg_color) == 0)
X {
X if (reverseVideo)
X {
X myFgPixel = color.pixel;
X strcpy (myFgColorStr, bg_color);
X }
X else
X {
X myBgPixel = color.pixel;
X strcpy (myBgColorStr, bg_color);
X }
X
X bg_allocated = TRUE;
X }
X if (strcmp (colorMenuItems[i], brdr_color) == 0)
X {
X myBorderPixel = color.pixel;
X brdr_allocated = TRUE;
X }
X index++;
X }
X
X maxColors = index;
X
X if (!fg_allocated)
X {
X XAllocNamedColor(mainDisplay, mainColormap, fg_color, &color,
X &exact_def);
X if (reverseVideo)
X {
X myBgPixel = color.pixel;
X strcpy (myBgColorStr, fg_color);
X }
X else
X {
X myFgPixel = color.pixel;
X strcpy (myFgColorStr, fg_color);
X }
X }
X if (!bg_allocated)
X {
X XAllocNamedColor(mainDisplay, mainColormap, bg_color, &color,
X &exact_def);
X if (reverseVideo)
X {
X myFgPixel = color.pixel;
X strcpy (myFgColorStr, bg_color);
X }
X else
X {
X myBgPixel = color.pixel;
X strcpy (myBgColorStr, bg_color);
X }
X }
X if (!brdr_allocated)
X {
X XAllocNamedColor(mainDisplay, mainColormap, brdr_color, &color,
X &exact_def);
X myBorderPixel = color.pixel;
X }
X
X for (i = 0; i < maxColors; i++)
X xorColorPixels[i] = colorPixels[i] ^ myBgPixel;
X }
X else
X {
X XAllocNamedColor(mainDisplay,mainColormap,fg_color,&color,&exact_def);
X myFgPixel = color.pixel;
X strcpy (myFgColorStr, fg_color);
X
X XAllocNamedColor(mainDisplay,mainColormap,bg_color,&color,&exact_def);
X myBgPixel = color.pixel;
X strcpy (myBgColorStr, bg_color);
X
X XAllocNamedColor(mainDisplay,mainColormap,brdr_color,&color,&exact_def);
X myBorderPixel = color.pixel;
X
X for (i = 0; i < maxColors; i++)
X {
X colorPixels[i] = myFgPixel;
X xorColorPixels[i] = myFgPixel ^ myBgPixel;
X }
X colorIndex = 0;
X }
X XAllocNamedColor(mainDisplay, mainColormap, "black", &color, &exact_def);
X tmp_max = max(color.red,max(color.green,color.blue));
X if (tmp_max > maxRGB) maxRGB = tmp_max;
X XAllocNamedColor(mainDisplay, mainColormap, "white", &color, &exact_def);
X tmp_max = max(color.red,max(color.green,color.blue));
X if (tmp_max > maxRGB) maxRGB = tmp_max;
X if (tmp_max == 0)
X printf ("Warning: Unexpected maximum RGB intensity 0.");
X}
X
Xstatic
Xint ChangeObjColor (ObjPtr, ColorIndex)
X struct ObjRec * ObjPtr;
X int ColorIndex;
X{
X register struct ObjRec * obj_ptr;
X int changed = FALSE;
X
X for (obj_ptr = ObjPtr; obj_ptr != NULL; obj_ptr = obj_ptr->prev)
X switch (obj_ptr->type)
X {
X case OBJ_POLY:
X case OBJ_BOX:
X case OBJ_OVAL:
X case OBJ_TEXT:
X case OBJ_POLYGON:
X case OBJ_ARC:
X case OBJ_RCBOX:
X case OBJ_XBM:
X if (obj_ptr->color != ColorIndex)
X {
X obj_ptr->color = ColorIndex;
X changed = TRUE;
X }
X break;
X
X case OBJ_GROUP:
X case OBJ_SYM:
X case OBJ_ICON:
X if (ChangeObjColor (obj_ptr->detail.r->last, ColorIndex))
X changed = TRUE;
X break;
X }
X return (changed);
X}
X
Xvoid ChangeAllSelColor (ColorIndex)
X int ColorIndex;
X{
X register struct SelRec * sel_ptr;
X register struct ObjRec * obj_ptr;
X int text_obj_created = FALSE, text_cursor_shown;
X int changed = FALSE;
X XGCValues values;
X
X if (topSel == NULL)
X {
X text_cursor_shown = textCursorShown;
X text_obj_created = TieLooseEnds ();
X colorIndex = ColorIndex;
X ShowColor (TRUE);
X if (!text_obj_created && curChoice == DRAWTEXT && text_cursor_shown)
X {
X NewCurText ();
X RedrawCurText ();
X }
X else
X textCursorShown = FALSE;
X return;
X }
X
X values.foreground = colorPixels[ColorIndex];
X values.function = GXcopy;
X values.fill_style = FillSolid;
X XChangeGC (mainDisplay, drawGC,
X GCForeground | GCFunction | GCFillStyle, &values);
X
X for (sel_ptr = botSel; sel_ptr != NULL; sel_ptr = sel_ptr->prev)
X {
X obj_ptr = sel_ptr->obj;
X switch (obj_ptr->type)
X {
X case OBJ_POLY:
X case OBJ_BOX:
X case OBJ_OVAL:
X case OBJ_TEXT:
X case OBJ_POLYGON:
X case OBJ_ARC:
X case OBJ_RCBOX:
X case OBJ_XBM:
X if (obj_ptr->color != ColorIndex)
X {
X obj_ptr->color = ColorIndex;
X changed = TRUE;
X }
X break;
X
X case OBJ_GROUP:
X case OBJ_SYM:
X case OBJ_ICON:
X if (ChangeObjColor (obj_ptr->detail.r->last, ColorIndex))
X changed = TRUE;
X break;
X }
X }
X
X if (changed)
X {
X HighLightReverse ();
X SetFileModified (TRUE);
X RedrawAnArea (botObj, selLtX-(1<<zoomScale), selLtY-(1<<zoomScale),
X selRbX+(1<<zoomScale), selRbY+(1<<zoomScale));
X HighLightForward ();
X }
X}
X
Xvoid ColorMenu (X, Y)
X int X, Y;
X{
X register int i, index, * fore_colors;
X Pixmap * pixmap;
X int w;
X
X if (!colorDisplay) return;
X
X pixmap = (Pixmap *) calloc (maxColors, sizeof (Pixmap));
X fore_colors = (int *) calloc (maxColors, sizeof(int));
X for (i = 0; i < maxColors; i++)
X {
X pixmap[i] = patPixmap[1];
X fore_colors[i] = colorPixels[i];
X }
X if ((maxColors % 10) == 0)
X w = (int)(maxColors / 10);
X else
X w = (int)(maxColors / 10) + 1;
X if (maxColors <= 10)
X index = PxMpMenuLoop (X, Y, choiceImageW, choiceImageH, maxColors, w,
X maxColors, fore_colors, pixmap, MULTICOLOR);
X else
X index = PxMpMenuLoop (X, Y, choiceImageW, choiceImageH, 10, w,
X maxColors, fore_colors, pixmap, MULTICOLOR);
X
X if (index != INVALID) ChangeAllSelColor (index);
X cfree (pixmap);
X}
X
Xvoid CleanUpColors ()
X{
X register int i;
X
X cfree (colorPixels);
X cfree (xorColorPixels);
X for (i = 0; i < allocatedMaxColors; i++) cfree (colorMenuItems[i]);
X cfree (colorMenuItems);
X
X maxColors = MAXCOLORS;
X defaultColorIndex = 4;
X colorIndex = 0;
X}
END_OF_FILE
if test 12182 -ne `wc -c <'color.c'`; then
echo shar: \"'color.c'\" unpacked with wrong size!
fi
# end of 'color.c'
fi
if test -f 'copypaste.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'copypaste.c'\"
else
echo shar: Extracting \"'copypaste.c'\" \(8528 characters\)
sed "s/^X//" >'copypaste.c' <<'END_OF_FILE'
X/*
X * Author: Kou1 Ma2da (matsuda at ccs.mt.nec.co.jp)
X * Modified By: William Chia-Wei Cheng (william at 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/copypaste.c,v 2.0 91/03/05 12:46:54 william Exp $";
X#endif
X
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include "const.h"
X#include "types.h"
X
X#include "choice.e"
X#include "color.e"
X#include "dup.e"
X#include "file.e"
X#include "font.e"
X#include "move.e"
X#include "obj.e"
X#include "pattern.e"
X#include "select.e"
X#include "setup.e"
X#include "special.e"
X#include "text.e"
X
X#define TGIF_HEADER 0x80
X
Xextern char * mktemp();
X
Xstatic char * cutBuffer = NULL;
X
Xvoid CopyToCutBuffer ()
X{
X FILE * fp;
X register struct SelRec * sel_ptr;
X struct ObjRec * obj_ptr, * top_obj, * bot_obj;
X char * tmpfile, message[MAXSTRING];
X struct stat stat;
X unsigned char header = TGIF_HEADER;
X
X if (topSel == NULL)
X {
X Msg ("No object selected for the COPY operation.");
X return;
X }
X tmpfile = mktemp ("/tmp/TgifXXXXXX");
X if ((fp = fopen (tmpfile, "w+")) == NULL)
X {
X sprintf (message, "Can not open %s.", tmpfile);
X Msg (message);
X return;
X }
X
X write (fileno(fp), &header, 1);
X
X top_obj = bot_obj = NULL;
X for (sel_ptr = botSel; sel_ptr != NULL; sel_ptr = sel_ptr->prev)
X {
X obj_ptr = DupObj (sel_ptr->obj);
X
X obj_ptr->prev = NULL;
X obj_ptr->next = top_obj;
X
X if (top_obj == NULL)
X bot_obj = obj_ptr;
X else
X top_obj->prev = obj_ptr;
X top_obj = obj_ptr;
X }
X Save (fp, bot_obj, 0);
X
X fflush (fp);
X if (fstat (fileno(fp), &stat) < 0)
X {
X fclose (fp);
X unlink (tmpfile);
X sprintf (message, "FSTAT error in %s. Copy aborted!", tmpfile);
X Msg (message);
X return;
X }
X
X if (cutBuffer != NULL) cfree (cutBuffer);
X cutBuffer = (char *) calloc (stat.st_size, sizeof(char));
X
X rewind(fp);
X if (read (fileno(fp), cutBuffer, stat.st_size) < stat.st_size)
X {
X sprintf (message, "READ error in %s. Copy aborted!", tmpfile);
X Msg (message);
X }
X else
X {
X XStoreBytes (mainDisplay, cutBuffer, stat.st_size);
X Msg ("Copy buffer updated.");
X }
X fclose (fp);
X unlink (tmpfile);
X}
X
Xstatic
Xvoid PasteString (CutBuffer)
X char * CutBuffer;
X{
X register char * c_ptr, * dest_c_ptr;
X int x, y, w, num_lines, char_count, max_len = 0;
X int root_x, root_y, grid_x, grid_y;
X unsigned int status;
X char msg[MAXSTRING];
X struct StrRec * first_str, * last_str, *str_ptr;
X struct ObjRec * obj_ptr;
X struct TextRec * text_ptr;
X Window root_win, child_win;
X
X if (*CutBuffer == '\0') { Msg ("Cut buffer is empty"); return; }
X
X TieLooseEnds ();
X SetCurChoice (NOTHING);
X if (topSel != NULL) { HighLightReverse (); RemoveAllSel (); }
X
X Msg ("Paste from a non-tgif tool.");
X
X XQueryPointer (mainDisplay, drawWindow, &root_win, &child_win,
X &root_x, &root_y, &x, &y, &status);
X GridXY (x, y, &grid_x, &grid_y);
X
X text_ptr = (struct TextRec *) calloc (1, sizeof(struct TextRec));
X text_ptr->font = curFont;
X text_ptr->dpi = curFontDPI;
X text_ptr->style = curStyle;
X text_ptr->attr = NULL;
X text_ptr->size = curSize;
X text_ptr->just = textJust;
X text_ptr->rotate = curRotate;
X text_ptr->pen = penPat;
X text_ptr->asc = canvasFontAsc;
X text_ptr->des = canvasFontDes;
X
X first_str = last_str = NULL;
X for (c_ptr = CutBuffer, num_lines = 0; *c_ptr != '\0'; num_lines++)
X {
X str_ptr = (struct StrRec *) calloc (1, sizeof(struct StrRec));
X
X char_count = 0;
X dest_c_ptr = str_ptr->s;
X while (*c_ptr != '\0' && *c_ptr != '\n' && *c_ptr != '\r')
X {
X *dest_c_ptr++ = *c_ptr++;
X if (++char_count == MAXSTRING)
X {
X sprintf (msg, "String length exceeds $1d. String truncated.",
X MAXSTRING);
X Msg (msg);
X while (*c_ptr != '\0' && *c_ptr != '\n' && *c_ptr != '\r') c_ptr++;
X break;
X }
X }
X *dest_c_ptr = '\0';
X
X str_ptr->prev = last_str;
X str_ptr->next = NULL;
X if (last_str == NULL)
X first_str = str_ptr;
X else
X last_str->next = str_ptr;
X last_str = str_ptr;
X
X w = XTextWidth (canvasFontPtr, str_ptr->s, strlen (str_ptr->s));
X if (w > max_len) max_len = w;
X
X if (*c_ptr == '\n' || *c_ptr == '\r') c_ptr++;
X }
X
X text_ptr->lines = num_lines;
X text_ptr->first = first_str;
X text_ptr->last = last_str;
X
X obj_ptr = (struct ObjRec *) calloc (1, sizeof(struct ObjRec));
X obj_ptr->x = grid_x;
X obj_ptr->y = grid_y;
X obj_ptr->type = OBJ_TEXT;
X obj_ptr->color = colorIndex;
X obj_ptr->id = objId++;;
X obj_ptr->dirty = FALSE;
X obj_ptr->detail.t = text_ptr;
X obj_ptr->fattr = obj_ptr->lattr = NULL;
X
X SetTextBBox (obj_ptr, textJust, max_len, num_lines*textCursorH, curRotate);
X
X AddObj (NULL, topObj, obj_ptr);
X AdjObjBBox (obj_ptr);
X PlaceTopObj ();
X SelectTopObj ();
X SetFileModified (TRUE);
X justDupped = FALSE;
X}
X
Xstatic
Xvoid CreateTmpBoxObj (LtX, LtY, RbX, RbY)
X int LtX, LtY, RbX, RbY;
X{
X register struct BoxRec * box_ptr;
X register struct ObjRec * obj_ptr;
X
X box_ptr = (struct BoxRec *) calloc (1, sizeof(struct BoxRec));
X box_ptr->fill = NONEPAT;
X box_ptr->width = 0;
X box_ptr->pen = NONEPAT;
X box_ptr->dash = 0;
X
X obj_ptr = (struct ObjRec *) calloc (1, sizeof(struct ObjRec));
X
X obj_ptr->bbox.ltx = obj_ptr->obbox.ltx = obj_ptr->x = LtX;
X obj_ptr->bbox.lty = obj_ptr->obbox.lty = obj_ptr->y = LtY;
X obj_ptr->bbox.rbx = obj_ptr->obbox.rbx = RbX;
X obj_ptr->bbox.rby = obj_ptr->obbox.rby = RbY;
X obj_ptr->type = OBJ_BOX;
X obj_ptr->color = colorIndex;
X obj_ptr->id = 0;
X obj_ptr->dirty = FALSE;
X obj_ptr->detail.b = box_ptr;
X obj_ptr->fattr = obj_ptr->lattr = NULL;
X AddObj (NULL, topObj, obj_ptr);
X}
X
Xvoid PasteFromCutBuffer ()
X{
X FILE * fp;
X int len, ltx, lty, rbx, rby, dx, dy;
X char * tmpfile, * cut_buffer, message[MAXSTRING];
X unsigned char header = TGIF_HEADER;
X struct ObjRec * obj_ptr, * saved_top_obj, * saved_bot_obj;
X
X cut_buffer = (char *) XFetchBytes (mainDisplay, &len);
X if (len == 0)
X {
X Msg ("Cut buffer is empty");
X return;
X }
X if (((unsigned char)(*cut_buffer)) != header)
X {
X PasteString (cut_buffer);
X return;
X }
X cut_buffer++;
X len--;
X
X tmpfile = mktemp ("/tmp/TgifXXXXXX");
X if ((fp = fopen (tmpfile, "w+")) == NULL)
X {
X sprintf (message, "Can not open %s for write.", tmpfile);
X Msg (message);
X return;
X }
X if (write (fileno(fp), cut_buffer, len) < len)
X {
X fclose (fp);
X unlink (tmpfile);
X sprintf (message, "FWRITE error in writing to %s. Paste aborted!",
X tmpfile);
X Msg (message);
X return;
X }
X fflush (fp);
X rewind (fp);
X
X TieLooseEnds ();
X SetCurChoice (NOTHING);
X if (topSel != NULL) { HighLightReverse (); RemoveAllSel (); }
X
X saved_top_obj = topObj;
X saved_bot_obj = botObj;
X topObj = botObj = NULL;
X
X importingFile = TRUE;
X while (ReadObj (fp, &obj_ptr, FALSE))
X if (obj_ptr != NULL)
X AddObj (NULL, topObj, obj_ptr);
X
X fclose (fp);
X importingFile = FALSE;
X if (topObj != NULL) SetFileModified (TRUE);
X
X ltx = topObj->obbox.ltx;
X lty = topObj->obbox.lty;
X rbx = topObj->obbox.rbx;
X rby = topObj->obbox.rby;
X for (obj_ptr = topObj->next; obj_ptr != NULL; obj_ptr = obj_ptr->next)
X {
X if (obj_ptr->obbox.ltx < ltx) ltx = obj_ptr->obbox.ltx;
X if (obj_ptr->obbox.lty < lty) lty = obj_ptr->obbox.lty;
X if (obj_ptr->obbox.rbx > rbx) rbx = obj_ptr->obbox.rbx;
X if (obj_ptr->obbox.rby > rby) rby = obj_ptr->obbox.rby;
X }
X CreateTmpBoxObj (ltx, lty, rbx, rby);
X PlaceTopObj ();
X dx = topObj->obbox.ltx - ltx;
X dy = topObj->obbox.lty - lty;
X DelObj (topObj);
X for (obj_ptr = topObj; obj_ptr != NULL; obj_ptr = obj_ptr->next)
X MoveObj (obj_ptr, dx, dy);
X
X RedrawDrawWindow (botObj);
X SelAllObj ();
X
X if (botObj != NULL)
X botObj->next = saved_top_obj;
X else
X topObj = saved_top_obj;
X
X if (saved_top_obj != NULL)
X {
X saved_top_obj->prev = botObj;
X botObj = saved_bot_obj;
X }
X unlink (tmpfile);
X Msg ("Objects pasted from tgif.");
X}
X
Xvoid CleanUpCutBuffer ()
X{
X if (cutBuffer != NULL)
X {
X *cutBuffer = '\0';
X cfree (cutBuffer);
X cutBuffer = NULL;
X }
X}
END_OF_FILE
if test 8528 -ne `wc -c <'copypaste.c'`; then
echo shar: \"'copypaste.c'\" unpacked with wrong size!
fi
# end of 'copypaste.c'
fi
if test -f 'cursor.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'cursor.c'\"
else
echo shar: Extracting \"'cursor.c'\" \(3247 characters\)
sed "s/^X//" >'cursor.c' <<'END_OF_FILE'
X/*
X * Author: William Chia-Wei Cheng (william at 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/cursor.c,v 2.0 91/03/05 12:46:56 william Exp $";
X#endif
X
X#include <X11/Xlib.h>
X#include <X11/cursorfont.h>
X#include "const.h"
X#include "types.h"
X
X#include "choice.e"
X#include "setup.e"
X
X#include "xbm/null.xbm"
X#include "xbm/nullmask.xbm"
X#include "xbm/text_cur_image.xbm"
X
XCursor nullCursor;
XCursor cornerCursor;
XCursor defaultCursor;
XCursor handCursor;
X
Xstatic GC textCursorGC;
Xstatic Cursor textCursor;
Xstatic Pixmap textPixmap;
Xstatic Pixmap nullPixmap;
Xstatic Pixmap nullMaskPixmap;
X
Xstatic XImage * textCursorImage;
X
Xvoid SetTextCursor (window)
X Window window;
X{
X XDefineCursor (mainDisplay, window, textCursor);
X}
X
Xvoid SetNullCursor (window)
X Window window;
X{
X XDefineCursor (mainDisplay, window, nullCursor);
X}
X
Xvoid SetDefaultCursor (window)
X Window window;
X{
X XUndefineCursor (mainDisplay, window);
X}
X
Xvoid ShowCursor ()
X{
X if (curChoice == DRAWTEXT)
X SetTextCursor (drawWindow);
X else
X SetDefaultCursor (drawWindow);
X}
X
Xvoid CreateCursor ()
X{
X XGCValues values;
X XColor color;
X
X textPixmap = XCreateBitmapFromData (mainDisplay, mainWindow,
X text_cur_image_bits, text_cur_image_width, text_cur_image_height);
X
X values.foreground = myFgPixel;
X values.background = myBgPixel;
X values.fill_style = FillOpaqueStippled;
X values.stipple = textPixmap;
X textCursorGC = XCreateGC (mainDisplay, mainWindow,
X GCForeground | GCBackground | GCFillStyle | GCStipple, &values);
X
X textCursorImage = XCreateImage (mainDisplay, mainVisual, 1, XYBitmap, 0,
X text_cur_image_bits, text_cur_image_width, text_cur_image_height, 8,
X 2);
X textCursorImage->byte_order = LSBFirst;
X textCursorImage->bitmap_bit_order = LSBFirst;
X textCursorImage->data = text_cur_image_bits;
X
X textCursor = XCreateFontCursor (mainDisplay, XC_xterm);
X cornerCursor = XCreateFontCursor (mainDisplay, XC_ul_angle);
X defaultCursor = XCreateFontCursor (mainDisplay, XC_arrow);
X handCursor = XCreateFontCursor (mainDisplay, XC_hand2);
X
X nullPixmap = XCreatePixmap (mainDisplay, mainWindow, null_width,
X null_height, 1);
X nullMaskPixmap = XCreatePixmap (mainDisplay, mainWindow, nullmask_width,
X nullmask_height, 1);
X nullCursor = XCreatePixmapCursor (mainDisplay, nullPixmap, nullMaskPixmap,
X &color, &color, 0, 0);
X}
X
Xvoid PutCursor (window, x, y, foreground)
X Window window;
X int x, y, foreground;
X{
X XSetForeground (mainDisplay, textCursorGC, foreground);
X XPutImage (mainDisplay, window, textCursorGC, textCursorImage, 0, 0, x, y,
X text_cur_image_width, text_cur_image_height);
X}
X
Xvoid CleanUpCursors ()
X{
X XFreePixmap (mainDisplay, textPixmap);
X XFreeGC (mainDisplay, textCursorGC);
X/* XDestroyImage (textCursorImage); */
X
X XFreeCursor (mainDisplay, textCursor);
X XFreeCursor (mainDisplay, cornerCursor);
X XFreeCursor (mainDisplay, defaultCursor);
X XFreeCursor (mainDisplay, handCursor);
X
X XFreePixmap (mainDisplay, nullPixmap);
X XFreePixmap (mainDisplay, nullMaskPixmap);
X XFreeCursor (mainDisplay, nullCursor);
X}
END_OF_FILE
if test 3247 -ne `wc -c <'cursor.c'`; then
echo shar: \"'cursor.c'\" unpacked with wrong size!
fi
# end of 'cursor.c'
fi
if test -f 'dialog.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'dialog.c'\"
else
echo shar: Extracting \"'dialog.c'\" \(5028 characters\)
sed "s/^X//" >'dialog.c' <<'END_OF_FILE'
X/*
X * Author: William Chia-Wei Cheng (william at 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/dialog.c,v 2.0 91/03/05 12:46:58 william Exp $";
X#endif
X
X#include <X11/Xlib.h>
X#include <X11/Xutil.h>
X#include "const.h"
X
X#include "box.e"
X#include "cursor.e"
X#include "font.e"
X#include "mainloop.e"
X#include "raster.e"
X#include "setup.e"
X
Xstatic int curX, curY;
Xstatic Window dialogWindow;
X
Xunsigned int CornerLoop (OrigX, OrigY)
X int * OrigX, * OrigY;
X{
X XEvent input;
X
X XGrabPointer (mainDisplay, rootWindow, False, ButtonPressMask,
X GrabModeAsync, GrabModeAsync, None, cornerCursor, CurrentTime);
X
X for (;;)
X {
X XNextEvent (mainDisplay, &input);
X if (input.type == ButtonPress)
X {
X XUngrabPointer (mainDisplay, CurrentTime);
X *OrigX = input.xbutton.x;
X *OrigY = input.xbutton.y;
X return (input.xbutton.button);
X }
X }
X}
X
Xvoid Dialog (Message, ReturnStr)
X char * Message, * ReturnStr;
X{
X int w, h, str_w, left, top, fore_draw_pixel, fore_erase_pixel;
X XEvent input;
X int win_x, win_y;
X int dialoging = TRUE, index = 0, dsp_w, dsp_h;
X char buf[80];
X XKeyEvent * key_ev;
X KeyCode key_code;
X KeySym key_sym;
X XComposeStatus c_stat;
X XSetWindowAttributes win_attrs;
X
X h = 7 * defaultFontHeight;
X str_w = defaultFontWidth * strlen (Message);
X w = max(str_w+6*defaultFontWidth,600);
X left = (w - str_w) / 2;
X top = 2 * defaultFontHeight;
X
X fore_draw_pixel = myFgPixel;
X fore_erase_pixel = myBgPixel;
X
X dsp_w = DisplayWidth (mainDisplay, mainScreen);
X dsp_h = DisplayHeight (mainDisplay, mainScreen);
X
X win_x = (w > dsp_w) ? 0 : (dsp_w - w)/2;
X win_y = (h > dsp_h) ? 0 : (dsp_h - h)/3;
X
X if (w > dsp_w-2*(brdrW+1)) w = dsp_w-2*(brdrW+1);
X
X if ((dialogWindow = XCreateSimpleWindow (mainDisplay, rootWindow, win_x,
X win_y, w, h, brdrW, myBorderPixel, myBgPixel)) == 0)
X { printf ("Could not create dialog window!\n"); exit (-1); }
X
X win_attrs.save_under = True;
X XChangeWindowAttributes (mainDisplay, dialogWindow, CWSaveUnder, &win_attrs);
X
X XSetTransientForHint (mainDisplay, dialogWindow, mainWindow);
X XMapWindow (mainDisplay, dialogWindow);
X XSelectInput (mainDisplay, dialogWindow, KeyPressMask | ExposureMask);
X
X curX = 200;
X curY = 4 * defaultFontHeight;
X
X while (dialoging)
X {
X XNextEvent (mainDisplay, &input);
X if (input.type == Expose)
X {
X XDrawRectangle (mainDisplay, dialogWindow, defaultGC, 0, 0, w-1, h-1);
X MyBox (dialogWindow, defaultGC, 10, 10, w-9, h-9);
X MyBox (dialogWindow, defaultGC, 11, 11, w-10, h-10);
X MyBox (dialogWindow, defaultGC, 12, 12, w-11, h-11);
X XDrawString (mainDisplay, dialogWindow, defaultGC, left, top, Message,
X strlen(Message));
X
X PutCursor (dialogWindow, curX, curY, fore_draw_pixel);
X
X continue;
X }
X if (input.type == KeyPress)
X {
X /* erase the old cursor */
X PutCursor (dialogWindow, curX, curY, fore_erase_pixel);
X
X key_ev = &(input.xkey);
X key_code = key_ev->keycode;
X XLookupString (key_ev, buf, 80, &key_sym, &c_stat);
X if ((buf[0]=='\033' && (key_sym & 0xff)=='\033') ||
X (buf[0]=='\r' && (key_sym & 0xff)=='\r') ||
X (buf[0]=='\n' && (key_sym & 0xff)=='\n') ||
X (buf[0]=='\b' && (key_sym & 0xff)=='\b') ||
X (buf[0]=='\b' && (key_sym & 0xff)=='h' &&
X (key_ev->state & ControlMask)) ||
X (buf[0]=='\177' && (key_sym & 0x7f)=='\177') ||
X (key_sym>='\040' && key_sym<='\177'))
X {
X switch (buf[0])
X {
X case '\033':
X ReturnStr[0] = '\0';
X dialoging = FALSE;
X break;
X case '\r':
X case '\n':
X ReturnStr[index] = '\0';
X dialoging = FALSE;
X break;
X case '\177': /* <DEL> */
X case '\b': /* <BS> */
X if (index != 0)
X {
X index--;
X curX -= defaultFontWidth + 1;
X PutCursor (dialogWindow, curX, curY, fore_erase_pixel);
X }
X break;
X default:
X if (buf[0] >= '\040' && index < 80)
X {
X XDrawString (mainDisplay, dialogWindow, defaultGC, curX,
X curY+defaultFontAsc, buf, 1);
X curX += defaultFontWidth + 1;
X ReturnStr[index++] = buf[0];
X }
X break;
X }
X }
X PutCursor (dialogWindow, curX, curY, fore_draw_pixel);
X }
X }
X
X XDestroyWindow (mainDisplay, dialogWindow);
X XSync (mainDisplay, FALSE);
X while (XCheckMaskEvent (mainDisplay, ExposureMask, &input)) ;
X}
END_OF_FILE
if test 5028 -ne `wc -c <'dialog.c'`; then
echo shar: \"'dialog.c'\" unpacked with wrong size!
fi
# end of 'dialog.c'
fi
echo shar: End of archive 2 \(of 23\).
cp /dev/null ark2isdone
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 at CS.UCLA.EDU ...!{uunet|ucbvax}!cs.ucla.edu!william
More information about the Comp.sources.x
mailing list