-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMandyWindow.c
More file actions
163 lines (135 loc) · 4.51 KB
/
Copy pathMandyWindow.c
File metadata and controls
163 lines (135 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*****
* MandyWindow.c
*
* A simple fractal generator
*
*
*****/
#include "mwMenus.h"
#include "mwWindow.h"
#include <GestaltEqu.h>
extern WindowPtr mwWindow;
extern Rect dragRect;
Boolean gHasColorQD;
void InitMacintosh(void);
void HandleMouseDown (EventRecord *theEvent);
void HandleEvent(void);
static Boolean HasColorQuickDraw(void);
/* InitMacintosh()
Initialize all the managers & memory */
void InitMacintosh(void) {
MaxApplZone();
InitGraf(&thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
InitCursor();
gHasColorQD = HasColorQuickDraw();
}
/* HasColorQuickDraw()
This gates not just RGBForeColor()/PaintRect()/NewCWindow() (which
only need basic Color QuickDraw, gestalt8BitQD) but also NewGWorld()
and friends, which are a distinct, later capability - "32-Bit
QuickDraw" - that a real machine can lack even with basic colour
present (an early colour Mac on a System without that extension,
for instance). Checking gestalt32BitQD covers both, since it
implies gestalt8BitQD. Calling a GWorld routine on a system that
only has basic Color QuickDraw is exactly the kind of thing that
can crash instead of failing gracefully, since the call may not
exist as a real trap at all rather than returning an error.
The SysEnvirons() fallback is for systems old enough to predate the
Gestalt Manager - in practice that's early System 6 on 68000 Macs,
which never had colour hardware anyway, so this branch is mostly
defensive completeness. It can only report basic colour presence,
not 32-Bit QuickDraw specifically, so it's a narrower guarantee
than the Gestalt check above - accepted here since a real machine
old enough to lack Gestalt but with a GWorld-capable colour card is
vanishingly unlikely to exist. */
static Boolean HasColorQuickDraw(void) {
long qdVersion;
if (Gestalt(gestaltQuickdrawVersion, &qdVersion) == noErr)
return qdVersion >= gestalt32BitQD;
{
SysEnvRec environment;
if (SysEnvirons(1, &environment) == noErr)
return environment.hasColorQD;
}
return false;
}
void HandleMouseDown (EventRecord *theEvent) {
WindowPtr theWindow;
int windowCode = FindWindow (theEvent->where, &theWindow);
switch (windowCode) {
case inSysWindow:
SystemClick (theEvent, theWindow);
break;
case inMenuBar:
AdjustMenus();
HandleMenu(MenuSelect(theEvent->where));
break;
case inDrag:
if (theWindow == mwWindow)
DragWindow(mwWindow, theEvent->where, &dragRect);
break;
case inContent:
if (theWindow == mwWindow) {
if (theWindow != FrontWindow())
SelectWindow(mwWindow);
else
InvalRect(&mwWindow->portRect);
}
break;
case inGoAway:
if (theWindow == mwWindow &&
TrackGoAway(mwWindow, theEvent->where))
HideWindow(mwWindow);
break;
}
}
void HandleEvent(void) {
int ok;
EventRecord theEvent;
HiliteMenu(0);
SystemTask (); /* Handle desk accessories */
ok = GetNextEvent (everyEvent, &theEvent);
if (ok) {
switch (theEvent.what) {
case mouseDown:
HandleMouseDown(&theEvent);
break;
case keyDown:
case autoKey:
if ((theEvent.modifiers & cmdKey) != 0) {
char keyChar = (char) (theEvent.message & charCodeMask);
if (keyChar == '.') {
AbortFractalRender();
} else {
AdjustMenus();
HandleMenu(MenuKey(keyChar));
}
}
break;
case updateEvt:
BeginUpdate(mwWindow);
DrawContent(((WindowPeek) mwWindow)->hilited);
EndUpdate(mwWindow);
break;
case activateEvt:
InvalRect(&mwWindow->portRect);
break;
}
} else {
AdvanceFractalRender();
}
}
void main(void) {
InitMacintosh();
SetUpMenus();
SetUpWindow();
for (;;) {
HandleEvent();
}
}