2
Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
4
See the accompanying file LICENSE, version 2000-Apr-09 or later
5
(the contents of which are also included in unzip.h) for terms of use.
6
If, for some reason, all these files are missing, the Info-ZIP license
7
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
9
/*---------------------------------------------------------------------------
12
This file is only linked into the standalone version (not SIOUX) of unzip.
13
Macintosh-GUI routines.
15
---------------------------------------------------------------------------*/
18
/*****************************************************************************/
20
/*****************************************************************************/
22
#include <QuickDraw.h>
29
/*****************************************************************************/
30
/* Macros, typedefs */
31
/*****************************************************************************/
33
#define bufferSize 4096
35
#define screenWindow 128
37
#define pauseOption 0x0001
38
#define scrollOption 0x0002
41
/*****************************************************************************/
42
/* Module level Vars */
43
/*****************************************************************************/
45
static Rect scrollRect, pauseRect;
46
static WindowPtr theWindow;
47
static RgnHandle scrollRgn;
49
static short fontHeight, fontWidth, screenHeight, screenWidth;
50
static short currentPosition, maxPosition, pausePosition;
52
static short *screenLength, startLine, endLine;
53
static char *screenImage, **screenLine;
55
static int screenOptions;
59
/*****************************************************************************/
61
/*****************************************************************************/
63
void screenOpen(char *);
64
void screenControl(char *, int);
65
void screenClose(void);
66
void screenUpdate(WindowPtr);
67
void screenDisplay(char *);
68
void screenDump(char *, long);
70
char *macfgets(char *, int, FILE *);
71
int macfprintf(FILE *, char *, ...);
72
int macprintf(char *, ...);
76
/*****************************************************************************/
78
/*****************************************************************************/
80
void screenOpen(char *Title) {
85
theWindow = GetNewWindow(screenWindow, nil, (WindowPtr)(-1));
87
if ((Title != NULL) && (*Title != '\0')) {
89
SetWTitle(theWindow, (StringPtr)Title);
90
p2cstr((StringPtr)Title);
93
ShowWindow(theWindow);
96
GetFNum( "\pMonaco", &fontFamID );
100
GetFontInfo(&fontInfo);
101
fontHeight = fontInfo.ascent + fontInfo.descent + fontInfo.leading;
102
fontWidth = fontInfo.widMax;
104
scrollRgn = NewRgn();
106
screenWidth = (theWindow->portRect.right - theWindow->portRect.left - 10) /
108
screenHeight = (theWindow->portRect.bottom - theWindow->portRect.top) /
110
maxPosition = screenHeight * fontHeight;
111
pausePosition = maxPosition - (currentPosition = fontHeight);
113
SetRect(&scrollRect, theWindow->portRect.left,
114
theWindow->portRect.top + fontInfo.descent,
115
theWindow->portRect.right,
116
theWindow->portRect.bottom);
117
SetRect(&pauseRect, theWindow->portRect.left,
118
pausePosition + fontInfo.descent,
119
theWindow->portRect.right,
120
theWindow->portRect.bottom);
122
MoveTo(5, currentPosition);
124
n = (sizeof(char *) + sizeof(short) + screenWidth) * screenHeight;
126
screenLine = (char **)NewPtr(n);
128
screenLength = (short *)&screenLine[screenHeight];
129
screenImage = (char *)&screenLength[screenHeight];
131
for (n = 0; n < screenHeight; n++) {
132
screenLine[n] = &screenImage[n * screenWidth];
136
startLine = endLine = 0;
146
void screenControl(char *options, int setting) {
164
screenOptions &= (n ^ (-1));
168
if ((pausePosition = maxPosition - currentPosition) == 0)
169
pausePosition = maxPosition - fontHeight;
177
void screenClose(void) {
178
DisposePtr((Ptr)screenLine);
180
DisposeWindow(theWindow);
188
void screenUpdate(WindowPtr window) {
192
if (window == theWindow) {
194
if (!EmptyRgn(window->visRgn)) {
199
MoveTo(5, m * fontHeight);
200
if (screenLength[n] != 0)
201
DrawText(screenLine[n], 0, screenLength[n]);
202
if (n == endLine) break;
203
if ((n += 1) == screenHeight) n = 0;
216
static void screenNewline(void) {
217
MoveTo(5, currentPosition += fontHeight);
218
if (currentPosition > maxPosition) {
219
if (screenOptions & scrollOption) {
220
ScrollRect(&scrollRect, 0, -fontHeight, scrollRgn);
221
MoveTo(5, currentPosition = maxPosition);
222
if ((startLine += 1) == screenHeight) startLine = 0;
224
ScrollRect(&scrollRect, 0, -maxPosition + fontHeight, scrollRgn);
225
MoveTo(5, currentPosition = fontHeight + fontHeight);
229
pausePosition -= fontHeight;
231
if ((endLine += 1) == screenHeight) endLine = 0;
232
screenLength[endLine] = 0;
240
static char waitChar(void) {
241
WindowPtr whichWindow;
242
EventRecord theEvent;
246
if (GetNextEvent(everyEvent, &theEvent)) {
247
switch (theEvent.what) {
249
if ((theEvent.modifiers & cmdKey) &&
250
((theEvent.message & charCodeMask) == '.'))
252
return(theEvent.message & charCodeMask);
254
if (FindWindow(theEvent.where, &whichWindow) == inSysWindow)
255
SystemClick(&theEvent, whichWindow);
258
screenUpdate((WindowPtr)theEvent.message);
268
static void screenPause(void) {
269
if (pausePosition == 0) {
270
if (screenOptions & pauseOption) {
271
DrawText("Press any key to continue ...", 0, 29);
272
memcpy(screenLine[endLine], "Press any key to continue ...", 29);
273
screenLength[endLine] = 29;
277
EraseRect(&pauseRect);
278
MoveTo(5, currentPosition);
279
screenLength[endLine] = 0;
282
pausePosition = maxPosition - fontHeight;
291
void screenDisplay(char *s) {
302
for (t = s; (*s) && (*s != '\n') && (*s != '\r'); s++)
305
if ((n = s - t) > (m = screenWidth - screenLength[endLine])) n = m;
309
memcpy(screenLine[endLine] + screenLength[endLine], t, n);
310
screenLength[endLine] += n;
313
if ((*s == '\n') || (*s == '\r')) {
327
void screenDump(char *s, long n) {
338
for (t = s; (n) && (*s != '\n') && (*s != '\r'); s++, n--)
341
if ((k = s - t) > (m = screenWidth - screenLength[endLine])) k = m;
345
memcpy(screenLine[endLine] + screenLength[endLine], t, k);
346
screenLength[endLine] += k;
349
if ((*s == '\n') || (*s == '\r')) {
364
char *macfgets(char *s, int n, FILE *stream) {
373
for (n -= 1; (n > 0) && ((c = waitChar()) != '\r'); n -= 1) {
375
if (screenLength[endLine] < screenWidth)
376
screenLine[endLine][screenLength[endLine]++] = c;
379
if (c == '\r') screenNewline();
391
int macfprintf(FILE *stream, char *format, ...)
393
char buffer[bufferSize];
399
va_start(ap, format);
400
rc = vsprintf(buffer, format, ap);
403
screenDisplay(buffer);
411
int macprintf(char *format, ...)
413
char buffer[bufferSize];
417
va_start(ap, format);
418
rc = vsprintf(buffer, format, ap);
421
screenDisplay(buffer);
428
/***********************/
429
/* Function macgetch() */
430
/***********************/
434
WindowPtr whichWindow;
435
EventRecord theEvent;
436
char c; /* one-byte buffer for read() to use */
440
if (!GetNextEvent(everyEvent, &theEvent))
441
theEvent.what = nullEvent;
443
switch (theEvent.what) {
445
c = theEvent.message & charCodeMask;
448
if (FindWindow(theEvent.where, &whichWindow) ==
450
SystemClick(&theEvent, whichWindow);
453
screenUpdate((WindowPtr)theEvent.message);
457
} while (theEvent.what != keyDown);