1 | /* stderr */ |
---|
2 | /* Interface |
---|
3 | version 3.5c. (c) Copyright 1992-2000 by the University of Washington. |
---|
4 | Written by Sean T. Lamont and Michal Palczewski. |
---|
5 | For use with the Macintosh version of the Phylogeny Inference Package, |
---|
6 | Permission is granted to copy and use this program provided no fee is |
---|
7 | charged for it and provided that this copyright notice is not removed. |
---|
8 | |
---|
9 | Functions you need to know how to use: |
---|
10 | macsetup(char *name): initializes the interface, brings up a window of |
---|
11 | the name of the argument, for I/O. |
---|
12 | textmode(); hides the graphics window |
---|
13 | gfxmode(); shows the graphics window. |
---|
14 | */ |
---|
15 | |
---|
16 | #include <sioux.h> |
---|
17 | #include <ctype.h> |
---|
18 | #include <string.h> |
---|
19 | #include <stdarg.h> |
---|
20 | #include <stdio.h> |
---|
21 | #include "draw.h" |
---|
22 | #include "interface.h" |
---|
23 | #define MAX(a,b) (a) > (b) ? (a) : (b) |
---|
24 | |
---|
25 | #define TEXT 0 |
---|
26 | #define GFX 1 |
---|
27 | |
---|
28 | extern winactiontype winaction; |
---|
29 | |
---|
30 | extern long winheight; |
---|
31 | extern long winwidth; |
---|
32 | Rect rect = { 0, 0, 16000, 16000 }; /* a nice big rect very convenient */ |
---|
33 | |
---|
34 | /* These are all external variables from other files that this program needs |
---|
35 | to access in order to draw and resize */ |
---|
36 | #define boolean char |
---|
37 | extern long strpbottom,strptop,strpwide,strpdeep,strpdiv,hpresolution; |
---|
38 | extern boolean dotmatrix,empty,preview,previewing,pictbold,pictitalic, |
---|
39 | pictshadow,pictoutline; |
---|
40 | extern double expand,xcorner,xnow,xsize,xscale,xunitspercm, |
---|
41 | ycorner,ynow,ysize,yscale,yunitspercm,labelrotation, |
---|
42 | labelheight,xmargin,ymargin,pagex,pagey,paperx,papery, |
---|
43 | hpmargin,vpmargin; |
---|
44 | extern long filesize; |
---|
45 | extern growth grows; |
---|
46 | extern enum {yes,no} penchange,oldpenchange; |
---|
47 | extern FILE *plotfile; |
---|
48 | extern plottertype plotter,oldplotter,previewer; |
---|
49 | extern striptype stripe; |
---|
50 | extern char resopts; |
---|
51 | |
---|
52 | extern double oldx, oldy; |
---|
53 | |
---|
54 | extern boolean didloadmetric; |
---|
55 | extern long nmoves,oldpictint,pagecount; |
---|
56 | extern double labelline,linewidth,oldxhigh,oldxlow,oldyhigh,oldylow, |
---|
57 | raylinewidth,treeline,oldxsize,oldysize,oldxunitspercm, |
---|
58 | oldyunitspercm,oldxcorner,oldycorner,oldxmargin,oldymargin, |
---|
59 | oldhpmargin,oldvpmargin,clipx0,clipx1,clipy0,clipy1,userxsize,userysize; |
---|
60 | extern long rootmatrix[51][51]; |
---|
61 | extern long HiMode,GraphDriver,GraphMode,LoMode,bytewrite; |
---|
62 | |
---|
63 | |
---|
64 | void handlemouse(WindowPtr win,EventRecord ev); |
---|
65 | |
---|
66 | /* Global variables used in many functions*/ |
---|
67 | int mode = TEXT; |
---|
68 | int quitmac; |
---|
69 | WindowPtr gfx_window; |
---|
70 | ControlHandle plot_button; |
---|
71 | ControlHandle change_button; |
---|
72 | ControlHandle quit_button; |
---|
73 | ControlHandle about_button; |
---|
74 | Rect gfxBounds = { 50, 10, 400, 260 }; /* position and size of gfx_window */ |
---|
75 | Rect resizeBounds = {100+MAC_OFFSET,340,16000,16000}; /* how much the window can be resized*/ |
---|
76 | |
---|
77 | RGBColor background; |
---|
78 | RGBColor foreground; |
---|
79 | |
---|
80 | /* saved parameters needed to make a call to makebox*/ |
---|
81 | mpreviewparams macpreviewparms; |
---|
82 | |
---|
83 | /* initialize general stuff*/ |
---|
84 | void |
---|
85 | macsetup (char *tname, char *gname) |
---|
86 | { |
---|
87 | |
---|
88 | Str255 buf1, buf2; |
---|
89 | Str255 title = ""; |
---|
90 | Rect plot_rec={10,10,30,110}; |
---|
91 | Rect change_rec={10,120,60,220}; |
---|
92 | Rect quit_rec={40,10,60,110}; |
---|
93 | Rect about_rec={10,230,30,330}; |
---|
94 | unsigned char* plot=(unsigned char*)"\4Plot"; |
---|
95 | unsigned char* change=(unsigned char*)"\7Change\rParameters"; |
---|
96 | unsigned char* quit=(unsigned char*)"\4Quit"; |
---|
97 | unsigned char* about=(unsigned char*)"\5About"; |
---|
98 | change[0]=0x11; |
---|
99 | |
---|
100 | background.red=0xcc00; /* #ccffff phylip color */ |
---|
101 | background.green=0xffff; |
---|
102 | background.blue=0xffff; |
---|
103 | |
---|
104 | #undef fontsize |
---|
105 | SIOUXSettings.fontsize= log(qd.screenBits.bounds.right); |
---|
106 | SIOUXSettings.autocloseonquit = true; |
---|
107 | |
---|
108 | putchar('\n'); /* initialize sioux and let sioux initialize the toolbox and menus*/ |
---|
109 | |
---|
110 | |
---|
111 | strcpy ((char *) buf1 + 1, tname); |
---|
112 | strcpy ((char *) buf2 + 1, gname); |
---|
113 | buf1[0] = strlen (tname); |
---|
114 | buf2[0] = strlen (gname); |
---|
115 | |
---|
116 | |
---|
117 | gfxBounds.bottom=qd.screenBits.bounds.bottom*.7; |
---|
118 | gfxBounds.right=MAX((gfxBounds.bottom-MAC_OFFSET)*.7,340); |
---|
119 | winheight=gfxBounds.bottom-gfxBounds.top-MAC_OFFSET; |
---|
120 | winwidth=gfxBounds.right-gfxBounds.left; |
---|
121 | |
---|
122 | |
---|
123 | gfx_window = NewCWindow (0L, &gfxBounds, buf2, false, documentProc, |
---|
124 | (WindowPtr) - 1L, true, 0); |
---|
125 | plot_button = NewControl(gfx_window,&plot_rec,plot,1,0,0,1,pushButProc,0); |
---|
126 | change_button = NewControl(gfx_window,&change_rec,change,1,0,0,1,pushButProc,0); |
---|
127 | quit_button = NewControl(gfx_window,&quit_rec,quit,1,0,0,1,pushButProc,0); |
---|
128 | about_button = NewControl(gfx_window,&about_rec,about,1,0,0,1,pushButProc,0); |
---|
129 | |
---|
130 | foreground.red=0x0000; /* black foreground */ |
---|
131 | foreground.green=0x0000; |
---|
132 | foreground.blue=0x0000; |
---|
133 | |
---|
134 | } |
---|
135 | |
---|
136 | /* event loop for the preview window */ |
---|
137 | void |
---|
138 | eventloop () |
---|
139 | { |
---|
140 | int status=1; |
---|
141 | quitmac=0; |
---|
142 | |
---|
143 | while (status > 0 && quitmac == 0) |
---|
144 | { |
---|
145 | status = handleevent (); |
---|
146 | if (status <= 0 || quitmac) |
---|
147 | textmode(); |
---|
148 | |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | |
---|
153 | /* event handler */ |
---|
154 | int |
---|
155 | handleevent () |
---|
156 | { |
---|
157 | EventRecord ev; |
---|
158 | WindowPtr win; |
---|
159 | int SIOUXDidEvent,where, ok; |
---|
160 | ok = GetNextEvent (everyEvent, &ev); |
---|
161 | if (!ok) return 1; |
---|
162 | where = FindWindow (ev.where, &win); |
---|
163 | if (win != gfx_window || where == inMenuBar) { |
---|
164 | SIOUXDidEvent = SIOUXHandleOneEvent(&ev); |
---|
165 | if (SIOUXDidEvent) return 1; |
---|
166 | } |
---|
167 | if (win != gfx_window) return 1; |
---|
168 | |
---|
169 | if ((ev.what == keyDown) && |
---|
170 | (ev.modifiers & cmdKey) && |
---|
171 | (toupper ((char) (ev.message & charCodeMask)) == 'W')) |
---|
172 | return 0; |
---|
173 | else if (ev.what == activateEvt) { |
---|
174 | InvalRect(&rect); |
---|
175 | } |
---|
176 | else if (ev.what == updateEvt && win == gfx_window ) |
---|
177 | paint_gfx_window(); |
---|
178 | else if (ev.what == mouseDown && where == inContent) |
---|
179 | handlemouse(win,ev); |
---|
180 | else if (ev.what == mouseDown && where == inSysWindow) |
---|
181 | SystemClick (&ev, win); |
---|
182 | else if (ev.what == mouseDown && where == inDrag) |
---|
183 | DragWindow (win, ev.where, &rect); |
---|
184 | else if (ev.what == mouseDown && where == inGrow) |
---|
185 | resize_gfx_window(ev); |
---|
186 | else if (ev.what == mouseDown && where == inGoAway) |
---|
187 | if ( TrackGoAway( win, ev.where ) ) { |
---|
188 | winaction = changeparms; |
---|
189 | return 0; |
---|
190 | } |
---|
191 | if (ev.what == mouseDown ) { |
---|
192 | SelectWindow(win); |
---|
193 | } |
---|
194 | |
---|
195 | return 1; |
---|
196 | } |
---|
197 | |
---|
198 | /*Handle mouse down event */ |
---|
199 | void handlemouse(WindowPtr win,EventRecord ev) { |
---|
200 | Point mouse; |
---|
201 | ControlHandle control; |
---|
202 | int part; |
---|
203 | |
---|
204 | |
---|
205 | mouse=ev.where; |
---|
206 | GlobalToLocal(&mouse); |
---|
207 | part=FindControl(mouse,win,&control); |
---|
208 | if (part != 10) return; |
---|
209 | TrackControl(control,mouse,NULL); |
---|
210 | if (control == plot_button) { |
---|
211 | quitmac=1; |
---|
212 | winaction=plotnow; |
---|
213 | } else if (control == quit_button){ |
---|
214 | quitmac=1; |
---|
215 | winaction=quitnow; |
---|
216 | } else if (control == change_button) { |
---|
217 | winaction = changeparms; |
---|
218 | quitmac=1; |
---|
219 | } |
---|
220 | } |
---|
221 | |
---|
222 | /* Draw a string to the graphics window */ |
---|
223 | void |
---|
224 | putstring (string) |
---|
225 | char *string; |
---|
226 | { |
---|
227 | unsigned char buf[256]; |
---|
228 | strncpy ((char *) buf + 1, string, 253); |
---|
229 | buf[0] = strlen (string); |
---|
230 | DrawString (buf); |
---|
231 | } |
---|
232 | |
---|
233 | /* go into text mode */ |
---|
234 | void |
---|
235 | textmode () |
---|
236 | { |
---|
237 | HideWindow (gfx_window); |
---|
238 | mode = TEXT; |
---|
239 | } |
---|
240 | |
---|
241 | /* go into graphics mode */ |
---|
242 | void |
---|
243 | gfxmode () |
---|
244 | { |
---|
245 | InitCursor(); |
---|
246 | SetPort (gfx_window); |
---|
247 | ShowWindow (gfx_window); |
---|
248 | SelectWindow (gfx_window); |
---|
249 | |
---|
250 | mode = GFX; |
---|
251 | } |
---|
252 | |
---|
253 | |
---|
254 | /*call this function to paint the graphics window*/ |
---|
255 | void paint_gfx_window () { |
---|
256 | |
---|
257 | BeginUpdate(gfx_window); |
---|
258 | RGBBackColor(&background); |
---|
259 | RGBForeColor(&foreground); |
---|
260 | EraseRect(&rect); |
---|
261 | |
---|
262 | PenSize(1,1); |
---|
263 | makebox(macpreviewparms.fn, |
---|
264 | macpreviewparms.xo, |
---|
265 | macpreviewparms.yo, |
---|
266 | macpreviewparms.scale, |
---|
267 | macpreviewparms.nt); |
---|
268 | PenSize(linewidth/5,linewidth/5); |
---|
269 | plottree(macpreviewparms.root, macpreviewparms.root); |
---|
270 | plotlabels(macpreviewparms.fn); |
---|
271 | UpdateControls(gfx_window,gfx_window->visRgn); |
---|
272 | EndUpdate(gfx_window); |
---|
273 | |
---|
274 | penchange = oldpenchange; |
---|
275 | xsize = oldxsize; |
---|
276 | ysize = oldysize; |
---|
277 | xunitspercm = oldxunitspercm; |
---|
278 | yunitspercm = oldyunitspercm; |
---|
279 | xscale = xunitspercm; |
---|
280 | yscale = yunitspercm; |
---|
281 | plotter = oldplotter; |
---|
282 | xcorner = oldxcorner; |
---|
283 | ycorner = oldycorner; |
---|
284 | xmargin = oldxmargin; |
---|
285 | ymargin = oldymargin; |
---|
286 | hpmargin = oldhpmargin; |
---|
287 | vpmargin = oldvpmargin; |
---|
288 | |
---|
289 | } |
---|
290 | |
---|
291 | /* resize the graphics window*/ |
---|
292 | void resize_gfx_window(EventRecord ev) { |
---|
293 | long windowsize; |
---|
294 | windowsize=GrowWindow(gfx_window,ev.where,&resizeBounds); |
---|
295 | if (windowsize != 0 ) { |
---|
296 | SizeWindow(gfx_window,LoWord(windowsize),HiWord(windowsize),TRUE); |
---|
297 | winheight=HiWord(windowsize)-MAC_OFFSET; |
---|
298 | winwidth=LoWord(windowsize); |
---|
299 | InvalRect(&rect); |
---|
300 | } |
---|
301 | } |
---|