1 /* $Id: mac.c,v 1.1.2.8 1999/02/28 02:38:40 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
35 static void mac_startup(void);
36 static void mac_eventloop(void);
37 static void mac_event(EventRecord *);
38 static void mac_contentclick(WindowPtr, EventRecord *);
39 static void mac_activatewindow(WindowPtr, Boolean);
40 static void mac_updatewindow(WindowPtr);
41 static void mac_keypress(EventRecord *);
42 static int mac_windowtype(WindowPtr);
43 static void mac_menucommand(long);
44 static void mac_adjustcursor(void);
45 static void mac_adjustmenus(void);
46 static void mac_closewindow(WindowPtr);
47 static void mac_zoomwindow(WindowPtr, short);
48 static void mac_shutdown(void);
50 static void mac_newsession(void);
52 int main (int argc, char **argv) {
58 static void mac_startup(void) {
62 InitGraf(&qd.thePort);
63 /* Init Font Manager */
65 /* Init Window Manager */
67 /* Init Menu Manager */
71 /* Init Dialog Manager */
75 /* Find out if we've got Color Quickdraw */
76 if (Gestalt(gestaltQuickdrawVersion, &mac_qdversion) != noErr)
77 mac_qdversion = gestaltOriginalQD;
78 /* ... and the Appearance Manager? */
79 if (Gestalt(gestaltAppearanceVersion, &mac_apprversion) != noErr)
80 if (Gestalt(gestaltAppearanceAttr, NULL) == noErr)
81 mac_apprversion = 0x0100;
85 /* We've been tested with the Appearance Manager */
86 if (mac_apprversion != 0)
87 RegisterAppearanceClient();
89 menuBar = GetNewMBar(128);
91 fatalbox("Unable to create menu bar.");
93 AppendResMenu(GetMenuHandle(mApple), 'DRVR');
99 static void mac_eventloop(void) {
106 gotevent = WaitNextEvent(everyEvent, &event, LONG_MAX, NULL);
113 static void mac_event(EventRecord *event) {
118 switch (event->what) {
120 part = FindWindow(event->where, &window);
124 mac_menucommand(MenuSelect(event->where));
127 SystemClick(event, window);
130 if (window != FrontWindow())
131 /* XXX: check for movable modal dboxes? */
132 SelectWindow(window);
134 mac_contentclick(window, event);
137 if (TrackGoAway(window, event->where))
138 mac_closewindow(window);
141 /* XXX: moveable modal check? */
142 DragWindow(window, event->where, &qd.screenBits.bounds);
148 if (TrackBox(window, event->where, part))
149 mac_zoomwindow(window, part);
158 mac_activatewindow((WindowPtr)event->message,
159 (event->modifiers & activeFlag) != 0);
162 mac_updatewindow((WindowPtr)event->message);
165 if (HiWord(event->message) != noErr) {
166 SetPt(&pt, 120, 120);
167 DIBadMount(pt, event->message);
173 static void mac_contentclick(WindowPtr window, EventRecord *event) {
176 switch (mac_windowtype(window)) {
178 /* XXX: Do something. */
181 if (DialogSelect(event, &(DialogPtr)window, &item))
184 /* XXX: Do something */
191 static void mac_activatewindow(WindowPtr window, Boolean active) {
193 switch (mac_windowtype(window)) {
195 mac_activateterm(window, active);
200 static void mac_updatewindow(WindowPtr window) {
202 switch (mac_windowtype(window)) {
204 mac_updateterm(window);
208 UpdateDialog(window, window->visRgn);
218 * Work out what kind of window we're dealing with.
219 * Concept shamelessly nicked from SurfWriter.
221 static int mac_windowtype(WindowPtr window) {
226 kind = ((WindowPeek)window)->windowKind;
229 if (GetWVariant(window) == zoomDocProc)
231 return GetWRefCon(window);
237 static void mac_keypress(EventRecord *event) {
240 if (event->what == keyDown && (event->modifiers & cmdKey)) {
242 mac_menucommand(MenuKey(event->message & charCodeMask));
246 static void mac_menucommand(long result) {
250 menu = HiWord(result);
251 item = LoWord(result);
256 GetNewDialog(wAbout, NULL, (GrafPort *)-1);
259 GetMenuItemText(GetMenuHandle(mApple), item, da);
270 mac_closewindow(FrontWindow());
281 static void mac_closewindow(WindowPtr window) {
283 switch (mac_windowtype(window)) {
285 CloseDeskAcc(((WindowPeek)window)->windowKind);
288 /* FIXME: end session and stuff */
296 static void mac_zoomwindow(WindowPtr window, short part) {
298 /* FIXME: do something */
302 * Make the menus look right before the user gets to see them.
304 static void mac_adjustmenus(void) {
309 * Make sure the right cursor's being displayed.
311 static void mac_adjustcursor(void) {
313 SetCursor(&qd.arrow);
316 static void mac_shutdown(void) {
321 void fatalbox(const char *fmt, ...) {
326 /* We'd like stuff to be a Pascal string */
327 stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap);
329 ParamText(stuff, NULL, NULL, NULL);