1 /* $Id: mac.c,v 1.1.2.9 1999/02/28 17:05:10 ben Exp $ */
3 * mac.c -- miscellaneous Mac-specific routines
9 #include <MacWindows.h>
12 #include <Appearance.h>
17 #include <ToolUtils.h>
21 #include <stdlib.h> /* putty.h needs size_t */
23 #define PUTTY_DO_GLOBALS
32 struct mac_gestalts mac_gestalts;
34 static void mac_startup(void);
35 static void mac_eventloop(void);
36 static void mac_event(EventRecord *);
37 static void mac_contentclick(WindowPtr, EventRecord *);
38 static void mac_activatewindow(WindowPtr, Boolean);
39 static void mac_updatewindow(WindowPtr);
40 static void mac_keypress(EventRecord *);
41 static int mac_windowtype(WindowPtr);
42 static void mac_menucommand(long);
43 static void mac_adjustcursor(void);
44 static void mac_adjustmenus(void);
45 static void mac_closewindow(WindowPtr);
46 static void mac_zoomwindow(WindowPtr, short);
47 static void mac_shutdown(void);
49 static void mac_newsession(void);
51 int main (int argc, char **argv) {
57 static void mac_startup(void) {
61 InitGraf(&qd.thePort);
62 /* Init Font Manager */
64 /* Init Window Manager */
66 /* Init Menu Manager */
70 /* Init Dialog Manager */
74 /* Find out if we've got Color Quickdraw */
75 if (Gestalt(gestaltQuickdrawVersion, &mac_gestalts.qdvers) != noErr)
76 mac_gestalts.qdvers = gestaltOriginalQD;
77 /* ... and the Appearance Manager? */
78 if (Gestalt(gestaltAppearanceVersion, &mac_gestalts.apprvers) != noErr)
79 if (Gestalt(gestaltAppearanceAttr, NULL) == noErr)
80 mac_gestalts.apprvers = 0x0100;
82 mac_gestalts.apprvers = 0;
83 /* Mac OS 8.5 Control Manager (proportional scrollbars)? */
84 if (Gestalt(gestaltControlMgrAttr, &mac_gestalts.cntlattr) != noErr)
85 mac_gestalts.cntlattr = 0;
87 /* We've been tested with the Appearance Manager */
88 if (mac_gestalts.apprvers != 0)
89 RegisterAppearanceClient();
91 menuBar = GetNewMBar(128);
93 fatalbox("Unable to create menu bar.");
95 AppendResMenu(GetMenuHandle(mApple), 'DRVR');
101 static void mac_eventloop(void) {
108 gotevent = WaitNextEvent(everyEvent, &event, LONG_MAX, NULL);
115 static void mac_event(EventRecord *event) {
120 switch (event->what) {
122 part = FindWindow(event->where, &window);
126 mac_menucommand(MenuSelect(event->where));
129 SystemClick(event, window);
132 if (window != FrontWindow())
133 /* XXX: check for movable modal dboxes? */
134 SelectWindow(window);
136 mac_contentclick(window, event);
139 if (TrackGoAway(window, event->where))
140 mac_closewindow(window);
143 /* XXX: moveable modal check? */
144 DragWindow(window, event->where, &qd.screenBits.bounds);
150 if (TrackBox(window, event->where, part))
151 mac_zoomwindow(window, part);
160 mac_activatewindow((WindowPtr)event->message,
161 (event->modifiers & activeFlag) != 0);
164 mac_updatewindow((WindowPtr)event->message);
167 if (HiWord(event->message) != noErr) {
168 SetPt(&pt, 120, 120);
169 DIBadMount(pt, event->message);
175 static void mac_contentclick(WindowPtr window, EventRecord *event) {
178 switch (mac_windowtype(window)) {
180 /* XXX: Do something. */
183 if (DialogSelect(event, &(DialogPtr)window, &item))
186 /* XXX: Do something */
193 static void mac_activatewindow(WindowPtr window, Boolean active) {
195 switch (mac_windowtype(window)) {
197 mac_activateterm(window, active);
202 static void mac_updatewindow(WindowPtr window) {
204 switch (mac_windowtype(window)) {
206 mac_updateterm(window);
210 UpdateDialog(window, window->visRgn);
220 * Work out what kind of window we're dealing with.
221 * Concept shamelessly nicked from SurfWriter.
223 static int mac_windowtype(WindowPtr window) {
228 kind = ((WindowPeek)window)->windowKind;
231 if (GetWVariant(window) == zoomDocProc)
233 return GetWRefCon(window);
239 static void mac_keypress(EventRecord *event) {
242 if (event->what == keyDown && (event->modifiers & cmdKey)) {
244 mac_menucommand(MenuKey(event->message & charCodeMask));
248 static void mac_menucommand(long result) {
252 menu = HiWord(result);
253 item = LoWord(result);
258 GetNewDialog(wAbout, NULL, (GrafPort *)-1);
261 GetMenuItemText(GetMenuHandle(mApple), item, da);
272 mac_closewindow(FrontWindow());
283 static void mac_closewindow(WindowPtr window) {
285 switch (mac_windowtype(window)) {
287 CloseDeskAcc(((WindowPeek)window)->windowKind);
290 /* FIXME: end session and stuff */
298 static void mac_zoomwindow(WindowPtr window, short part) {
300 /* FIXME: do something */
304 * Make the menus look right before the user gets to see them.
306 static void mac_adjustmenus(void) {
311 * Make sure the right cursor's being displayed.
313 static void mac_adjustcursor(void) {
315 SetCursor(&qd.arrow);
318 static void mac_shutdown(void) {
323 void fatalbox(const char *fmt, ...) {
328 /* We'd like stuff to be a Pascal string */
329 stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap);
331 ParamText(stuff, NULL, NULL, NULL);