1 /* $Id: mac.c,v 1.1.2.5 1999/02/20 23:55:55 ben Exp $ */
3 * mac.c -- miscellaneous Mac-specific routines
9 #include <MacWindows.h>
15 #include <ToolUtils.h>
19 #include <stdlib.h> /* putty.h needs size_t */
28 static void mac_startup(void);
29 static void mac_eventloop(void);
30 static void mac_event(EventRecord *);
31 static void mac_contentclick(WindowPtr, EventRecord *);
32 static void mac_updatewindow(WindowPtr);
33 static void mac_keypress(EventRecord *);
34 static int mac_windowtype(WindowPtr);
35 static void mac_menucommand(long);
36 static void mac_adjustcursor(void);
37 static void mac_adjustmenus(void);
38 static void mac_closewindow(WindowPtr);
39 static void mac_zoomwindow(WindowPtr, short);
40 static void mac_shutdown(void);
42 static void mac_newsession(void);
44 int main (int argc, char **argv) {
50 static void mac_startup(void) {
54 InitGraf(&qd.thePort);
55 /* Init Font Manager */
57 /* Init Window Manager */
59 /* Init Menu Manager */
63 /* Init Dialog Manager */
67 menuBar = GetNewMBar(128);
69 fatalbox("Unable to create menu bar.");
71 AppendResMenu(GetMenuHandle(mApple), 'DRVR');
77 static void mac_eventloop(void) {
84 gotevent = WaitNextEvent(everyEvent, &event, LONG_MAX, NULL);
91 static void mac_event(EventRecord *event) {
96 switch (event->what) {
98 part = FindWindow(event->where, &window);
102 mac_menucommand(MenuSelect(event->where));
105 SystemClick(event, window);
108 if (window != FrontWindow())
109 /* XXX: check for movable modal dboxes? */
110 SelectWindow(window);
112 mac_contentclick(window, event);
115 if (TrackGoAway(window, event->where))
116 mac_closewindow(window);
119 /* XXX: moveable modal check? */
120 DragWindow(window, event->where, &qd.screenBits.bounds);
126 if (TrackBox(window, event->where, part))
127 mac_zoomwindow(window, part);
136 /* FIXME: Do something */
139 mac_updatewindow((WindowPtr)event->message);
142 if (HiWord(event->message) != noErr) {
143 SetPt(&pt, 120, 120);
144 DIBadMount(pt, event->message);
150 static void mac_contentclick(WindowPtr window, EventRecord *event) {
153 switch (mac_windowtype(window)) {
155 /* XXX: Do something. */
158 if (DialogSelect(event, &(DialogPtr)window, &item))
161 mac_closewindow(window);
164 /* XXX: Do something */
171 static void mac_updatewindow(WindowPtr window) {
173 switch (mac_windowtype(window)) {
175 /* XXX: DO something */
179 UpdateDialog(window, window->visRgn);
186 * Work out what kind of window we're dealing with.
187 * Concept shamelessly nicked from SurfWriter.
189 static int mac_windowtype(WindowPtr window) {
194 kind = ((WindowPeek)window)->windowKind;
197 else if (kind == userKind)
200 return GetWRefCon(window);
206 static void mac_keypress(EventRecord *event) {
209 if (event->what == keyDown && (event->modifiers & cmdKey)) {
211 mac_menucommand(MenuKey(event->message & charCodeMask));
215 static void mac_menucommand(long result) {
219 menu = HiWord(result);
220 item = LoWord(result);
225 GetNewDialog(wAbout, NULL, (GrafPort *)-1);
228 GetMenuItemText(GetMenuHandle(mApple), item, da);
239 mac_closewindow(FrontWindow());
250 static void mac_closewindow(WindowPtr window) {
252 switch (mac_windowtype(window)) {
254 CloseDeskAcc(((WindowPeek)window)->windowKind);
257 /* FIXME: end session and stuff */
265 static void mac_zoomwindow(WindowPtr window, short part) {
267 /* FIXME: do something */
271 * Make the menus look right before the user gets to see them.
273 static void mac_adjustmenus(void) {
278 * Make sure the right cursor's being displayed.
280 static void mac_adjustcursor(void) {
282 SetCursor(&qd.arrow);
285 static void mac_shutdown(void) {
290 void fatalbox(const char *fmt, ...) {
295 /* We'd like stuff to be a Pascal string */
296 stuff[0] = vsprintf((char *)(&stuff[1]), fmt, ap);
298 ParamText(stuff, NULL, NULL, NULL);