home *** CD-ROM | disk | FTP | other *** search
- /*****
- * cTest.c
- *
- * A simple demonstration program to test my Calendar MDEF
- Darin Gurney, Aug '94 CompuServe 71620,2531
- *
- *
- *****/
-
- #include "cTestMenus.h"
- #include "cTestWindow.h"
- #include "CalendarMenu.h"
-
- unsigned long menuDate = 0xa9ff8000;
-
- extern WindowPtr cTestWindow;
- extern Rect dragRect;
-
- void InitMacintosh(void);
- void HandleMouseDown (EventRecord *theEvent);
- void HandleEvent(void);
-
- /****
- * InitMacintosh()
- *
- * Initialize all the managers & memory
- *
- ****/
-
- 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.
- *
- ****/
-
- void HandleMouseDown (EventRecord *theEvent)
-
- {
- WindowPtr theWindow;
- int windowCode = FindWindow (theEvent->where, &theWindow);
-
- switch (windowCode)
- {
- case inSysWindow:
- SystemClick (theEvent, theWindow);
- break;
-
- case inMenuBar:
- AdjustMenus();
- HandleMenu(MenuSelect(theEvent->where));
- break;
-
- case inDrag:
- if (theWindow == cTestWindow)
- DragWindow(cTestWindow, theEvent->where, &dragRect);
- break;
-
- case inContent:
- if (theWindow == cTestWindow)
- {
- if (theWindow != FrontWindow())
- SelectWindow(cTestWindow);
- else
- /* Actually should only respond to click in popup menu area,
- not entire window. */
- /* Note how popup menu will popup with border area under cursor
- if it can't fit on screen. prevents accidental changes. */
- PopupCalendarMenu( theEvent->where, &menuDate );
- InvalRect(&cTestWindow->portRect);
- }
- break;
-
- case inGoAway:
- if (theWindow == cTestWindow &&
- TrackGoAway(cTestWindow, theEvent->where))
- HideWindow(cTestWindow);
- break;
- }
- }
- /* end HandleMouseDown */
-
-
- /****
- * HandleEvent()
- *
- * The main event dispatcher. This routine should be called
- * repeatedly (it handles only one event).
- *
- *****/
-
- void HandleEvent(void)
-
- {
- int ok;
- EventRecord theEvent;
-
- HiliteMenu(0);
- SystemTask (); /* Handle desk accessories */
-
- ok = GetNextEvent (everyEvent, &theEvent);
- if (ok)
- switch (theEvent.what)
- {
- case mouseDown:
- HandleMouseDown(&theEvent);
- break;
-
- case keyDown:
- case autoKey:
- if ((theEvent.modifiers & cmdKey) != 0)
- {
- AdjustMenus();
- HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
- }
- break;
-
- case updateEvt:
- BeginUpdate(cTestWindow);
- DrawcTest(((WindowPeek) cTestWindow)->hilited);
- EndUpdate(cTestWindow);
- break;
-
- case activateEvt:
- InvalRect(&cTestWindow->portRect);
- break;
- }
- }
- /* end HandleEvent */
-
-
- /*****
- * main()
- *
- * This is where everything happens
- *
- *****/
-
-
- main()
-
- {
- InitMacintosh();
- SetUpMenus();
- SetUpWindow();
-
- for (;;)
- HandleEvent();
- }
- /* end main */