source: trunk/athena/lib/Xj/Drawing.c @ 12350

Revision 12350, 5.5 KB checked in by ghudson, 26 years ago (diff)
Some RCS ID cleanup: delete $Log$ and replace other RCS keywords with $Id$.
Line 
1/*
2 * $Id: Drawing.c,v 1.2 1999-01-22 23:16:51 ghudson Exp $
3 *
4 * Copyright 1990, 1991 by the Massachusetts Institute of Technology.
5 *
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
8 *
9 */
10
11#if  (!defined(lint))  &&  (!defined(SABER))
12static char rcsid[] =
13"$Id: Drawing.c,v 1.2 1999-01-22 23:16:51 ghudson Exp $";
14#endif
15
16#include "mit-copyright.h"
17#include <stdio.h>
18#include "Jets.h"
19#include "Drawing.h"
20
21extern int DEBUG;
22
23#define offset(field) XjOffset(DrawingJet,field)
24
25static XjResource resources[] = {
26  { XjNexposeProc, XjCExposeProc, XjRCallback, sizeof(XjCallback *),
27      offset(drawing.exposeProc), XjRString, NULL },
28  { XjNrealizeProc, XjCRealizeProc, XjRCallback, sizeof(XjCallback *),
29      offset(drawing.realizeProc), XjRString, NULL },
30  { XjNresizeProc, XjCResizeProc, XjRCallback, sizeof(XjCallback *),
31      offset(drawing.resizeProc), XjRString, NULL },
32  { XjNdestroyProc, XjCDestroyProc, XjRCallback, sizeof(XjCallback *),
33      offset(drawing.destroyProc), XjRString, NULL },
34  { XjNeventProc, XjCEventProc, XjRCallback, sizeof(XjCallback *),
35      offset(drawing.eventProc), XjRString, NULL },
36  { XjNx, XjCX, XjRInt, sizeof(int),
37      offset(core.x), XjRString, XjInheritValue },
38  { XjNy, XjCY, XjRInt, sizeof(int),
39      offset(core.y), XjRString, XjInheritValue },
40  { XjNwidth, XjCWidth, XjRInt, sizeof(int),
41      offset(core.width), XjRString, XjInheritValue },
42  { XjNheight, XjCHeight, XjRInt, sizeof(int),
43      offset(core.height), XjRString, XjInheritValue },
44  { XjNlineWidth, XjCLineWidth, XjRInt, sizeof(int),
45      offset(drawing.lineWidth), XjRString, "0" },
46  { XjNforeground, XjCForeground, XjRColor, sizeof(int),
47      offset(drawing.foreground), XjRString, XjDefaultForeground },
48  { XjNbackground, XjCBackground, XjRColor, sizeof(int),
49      offset(drawing.background), XjRString, XjDefaultBackground },
50  { XjNreverseVideo, XjCReverseVideo, XjRBoolean, sizeof(Boolean),
51      offset(drawing.reverseVideo), XjRBoolean, (caddr_t)False },
52  { XjNfont, XjCFont, XjRFontStruct, sizeof(XFontStruct *),
53      offset(drawing.font), XjRString, XjDefaultFont }
54};
55
56#undef offset
57
58static Boolean event_handler();
59static void realize(), querySize(), destroy();
60
61DrawingClassRec drawingClassRec = {
62  {
63    /* class name */            "Drawing",
64    /* jet size   */            sizeof(DrawingRec),
65    /* classInitialize */       NULL,
66    /* classInitialized? */     1,
67    /* initialize */            NULL,
68    /* prerealize */            NULL,
69    /* realize */               realize,
70    /* event */                 event_handler,
71    /* expose */                NULL,
72    /* querySize */             querySize,
73    /* move */                  NULL,
74    /* resize */                NULL,
75    /* destroy */               destroy,
76    /* resources */             resources,
77    /* number of 'em */         XjNumber(resources)
78  }
79};
80
81JetClass drawingJetClass = (JetClass)&drawingClassRec;
82
83/*
84 * Things are currently broken screenwise.
85 * It will be fun to fix later. :)
86 */
87static void realize(me)
88     DrawingJet me;
89{
90  unsigned long valuemask;
91  XGCValues values;
92
93  if (me->drawing.reverseVideo)
94    {
95      int temp;
96
97      temp = me->drawing.foreground;
98      me->drawing.foreground = me->drawing.background;
99      me->drawing.background = temp;
100    }
101
102  values.function = GXcopy;
103  values.foreground = me->drawing.foreground;
104  values.background = me->drawing.background;
105  values.line_width = me->drawing.lineWidth;
106  values.font = me->drawing.font->fid;
107  values.graphics_exposures = False;
108  valuemask = ( GCForeground | GCBackground | GCLineWidth | GCFunction
109               | GCFont | GCGraphicsExposures );
110
111  me->drawing.foreground_gc = XjCreateGC(me->core.display,
112                                         me->core.window,
113                                         valuemask,
114                                         &values);
115
116  values.foreground = me->drawing.background;
117
118  me->drawing.background_gc = XjCreateGC(me->core.display,
119                                         me->core.window,
120                                         valuemask,
121                                         &values);
122
123  values.function = GXxor;
124  values.foreground = (me->drawing.foreground ^
125                       me->drawing.background);
126
127  me->drawing.invert_gc = XjCreateGC(me->core.display,
128                                     me->core.window,
129                                     valuemask,
130                                     &values);
131  /*
132   * Usurp events for this window
133   */
134  XjRegisterWindow(me->core.window, (Jet) me);
135  XjSelectInput(me->core.display, me->core.window,
136                ExposureMask | EnterWindowMask | LeaveWindowMask |
137                StructureNotifyMask | ButtonPressMask | ButtonReleaseMask);
138  me->core.width = me->core.parent->core.width;
139  me->core.height = me->core.parent->core.height;
140  XjCallCallbacks((caddr_t) me, me->drawing.resizeProc, NULL);
141}
142
143static void destroy(me)
144     DrawingJet me;
145{
146  XjFreeGC(me->core.display, me->drawing.invert_gc);
147  XjFreeGC(me->core.display, me->drawing.foreground_gc);
148  XjFreeGC(me->core.display, me->drawing.background_gc);
149
150  XjUnregisterWindow(me->core.window, (Jet) me);
151}
152
153static void querySize(me, size)
154     DrawingJet me;
155     XjSize *size;
156{
157  size->width = me->core.width;
158  size->height = me->core.height;
159}
160
161static Boolean event_handler(me, event)
162     DrawingJet me;
163     XEvent *event;
164{
165  switch(event->type)
166    {
167    case GraphicsExpose:
168    case Expose:
169      if (event->xexpose.count != 0)
170        break;
171      XjCallCallbacks((caddr_t) me, me->drawing.exposeProc, event);
172      break;
173
174    case ConfigureNotify:
175      if (me->core.width != event->xconfigure.width  ||
176          me->core.height != event->xconfigure.height)
177        {
178          me->core.width = event->xconfigure.width;
179          me->core.height = event->xconfigure.height;
180          XjCallCallbacks((caddr_t) me, me->drawing.resizeProc, event);
181        }
182      break;
183
184    case ButtonPress:
185    case ButtonRelease:
186      XjCallCallbacks((caddr_t) me, me->drawing.eventProc, event);
187      break;
188
189    default:
190      return False;
191    }
192  return True;
193}
Note: See TracBrowser for help on using the repository browser.