-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
189 lines (157 loc) · 4.1 KB
/
main.cpp
File metadata and controls
189 lines (157 loc) · 4.1 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include <Types.h>
#include <QuickDraw.h>
#include <Fonts.h>
#include <MacWindows.h>
#include <Memory.h>
#include <Devices.h>
#include <Events.h>
#include <ToolUtils.h>
#include <OSUtils.h>
#include <Sound.h>
#include <Resources.h>
#include "Main.h"
#include "LFiles.h"
#include "src/PMenu.h"
// ----------------------------------------------------------------------------
// Globals
Boolean gShouldQuit;
// ----------------------------------------------------------------------------
// Prototypes
void PHandleMenuClick(long mResult);
Boolean PInit(void);
void POpenIntroWindow(void);
void PMainEventLoop(void);
// ----------------------------------------------------------------------------
// Functions
/**
* @brief Handles menu clicks.
*/
void PHandleMenuClick(long mResult) {
short theItem, theMenu;
theMenu = HiWord(mResult);
theItem = LoWord(mResult);
PMenu::HandleMenuClick(theMenu, theItem);
// Small and neat!
}
/**
* @brief Initialise libraries.
*/
Boolean PInit(void) {
Handle theMenuBar;
MaxApplZone(); // 1
MoreMasters(); // 2
MoreMasters(); // 3
MoreMasters(); // 4
MoreMasters(); // 5
MoreMasters(); // 6
MoreMasters(); // 7
MoreMasters(); // 8
MoreMasters(); // 9 times!
// Initialise the various managers:
InitGraf(&qd.thePort); // QuickDraw
InitFonts();
FlushEvents(everyEvent, 0); // Clears stray event queues
InitWindows();
InitMenus();
TEInit(); // Text Edit
InitDialogs(NIL);
// Got our menu resources OK?
if ((theMenuBar = GetNewMBar(MENU_BAR_ID)) == NIL) {
return FALSE;
}
PMenu::InitMenuHandlers(); // Initialise menu actions
SetMenuBar(theMenuBar); // Add the menus to menu list
DisposeHandle(theMenuBar);
AppendResMenu(GetMenuHandle(MENU_APPLE), 'DRVR'); // Build Apple menu
DrawMenuBar();
InitCursor();
return TRUE;
}
/**
* @brief Handles mouse click events.
*/
void PHandleMouseDownEvent(EventRecord *eventStrucPtr) {
WindowRef windowRef;
WindowPartCode partCode;
partCode = FindWindow(eventStrucPtr->where, &windowRef);
switch(partCode) {
case inSysWindow:
SystemClick(eventStrucPtr, windowRef);
break;
case inMenuBar:
PHandleMenuClick(MenuSelect(eventStrucPtr->where));
break;
case inDrag: {
Rect greyRegionRect = (*GetGrayRgn())->rgnBBox; // Create a local copy of the Desktop rect
DragWindow(windowRef, eventStrucPtr->where, &greyRegionRect);
}
break;
case inGoAway:
if (TrackGoAway(windowRef, eventStrucPtr->where) == TRUE) {
DisposeWindow(windowRef);
}
break;
case inContent:
if (windowRef != FrontWindow()) {
SelectWindow(windowRef);
} else {
// PHandleInContentEvent(eventStrucPtr);
}
break;
}
}
/**
* @brief Handles actions from system events.
* @param eventStrucPtr Pointer to event struct.
*/
void PHandleEvents(EventRecord *eventStrucPtr) {
switch(eventStrucPtr->what) {
case mouseDown:
PHandleMouseDownEvent(eventStrucPtr);
break;
// Key down:
case keyDown:
case autoKey:
if ((eventStrucPtr->modifiers & cmdKey) != 0) {
PHandleMenuClick(
MenuKey((char) (eventStrucPtr->message & CHAR_CODE_MASK))
);
}
break;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Update the window:
case updateEvt:
// Activate event:
case activateEvt:
// gWhichWindow = (WindowPtr) eventStrucPtr->message;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
default:
break;
}
}
/**
* @brief Handles all system events.
*/
void PMainEventLoop(void) {
EventRecord eventStructure;
Point where;
// Clear out leftover events:
FlushEvents(everyEvent, 0);
gShouldQuit = FALSE;
do {
if (WaitNextEvent(everyEvent, &eventStructure, LONG_NAP, NO_CURSOR)) {
PHandleEvents(&eventStructure);
} else // Null event
; // Do idle or background stuff here
} while (gShouldQuit == FALSE);
}
/**
* @brief Point of entry for Pinax.
*/
int main() {
if (PInit()) {
PMainEventLoop();
} else {
SysBeep(30);
}
}