/***** * FractalViewer.c * * Simple object-oriented application to draw 2D CGI, * mostly fractals, using QuickDraw * *****/ /* MacHeaders Included */ #include #include "FractalViewerMenus.h" #include "TFractalViewerWindow.h" /**** * InitMacintosh() * * Initialize all the managers & memory * ****/ static void InitMacintosh(void) { MaxApplZone(); InitGraf(&thePort); InitFonts(); FlushEvents(everyEvent, 0); InitWindows(); InitMenus(); TEInit(); InitDialogs(0L); InitCursor(); } /* end InitMacintosh */ /**** * HandleMouseDown (theEvent) * * Take care of mouseDown events. * ****/ static void HandleMouseDown(EventRecord *theEvent) { WindowPeek wp; short windowPart = FindWindow (theEvent->where, (WindowPtr*) &wp); switch (windowPart) { case inSysWindow: SystemClick (theEvent, (WindowPtr) wp); break; case inMenuBar: HandleMenu(MenuSelect(theEvent->where)); break; case inDrag: if (wp->windowKind == TWINDOWKIND) OBJ(wp)->Drag(theEvent->where); break; case inContent: if (wp->windowKind == TWINDOWKIND) { if (wp != (WindowPeek) FrontWindow()) OBJ(wp)->Select(); else OBJ(wp)->Hit(theEvent->where); } break; case inGoAway: if (wp->windowKind == TWINDOWKIND) OBJ(wp)->TrackClose(theEvent->where); break; case inGrow: if (wp->windowKind == TWINDOWKIND) OBJ(wp)->Grow(theEvent->where); break; case inZoomIn: case inZoomOut: if (wp->windowKind == TWINDOWKIND) OBJ(wp)->TrackZoom(theEvent->where, windowPart); } } /* end HandleMouseDown */ /**** * HandleEvent() * * The main event dispatcher. This routine should be called * repeatedly (it handles only one event). * *****/ static void HandleEvent(void) { short ok; EventRecord theEvent; HiliteMenu(0); SystemTask (); /* Handle desk accessories */ AdjustMenus(); ok = GetNextEvent (everyEvent, &theEvent); if (ok) { switch (theEvent.what) { case mouseDown: HandleMouseDown(&theEvent); break; case keyDown: case autoKey: if ((theEvent.modifiers & cmdKey) != 0) HandleMenu(MenuKey((char) (theEvent.message & charCodeMask))); break; case updateEvt: if (((WindowPeek) theEvent.message)->windowKind == TWINDOWKIND) OBJ(theEvent.message)->Update(); break; case activateEvt: if (((WindowPeek) theEvent.message)->windowKind == TWINDOWKIND) OBJ(theEvent.message)->Activate(theEvent.modifiers & 0x01); break; } } } /* end HandleEvent */ /***** * main() * * This is where everything happens * *****/ void main(void) { InitMacintosh(); SetUpMenus(); for (;;) HandleEvent(); } /* end main */