home *** CD-ROM | disk | FTP | other *** search
- /*
- deskpat.c
-
- Getting Desktop and Utilities Pattern snippet
- Albert Hui -- MacDTS
-
- This snippet how you can access the "Desktop Pattern" and
- the "Set Utilities Pattern" pattern.(This pattern is set by holding down \
- the option key in the Desktop Patterns Control Panel.)
-
- This control panel uses resources of type 'ppat' to store
- this pattern. The `ppat' resource is stored in the System file
- in your System Folder; the desktop pattern has an ID of 16 and
- the utilities pattern has an ID of 42. Since this is not
- documented, it could be subject to change at any moment.
- You should be careful when using this.
-
- This sample is built with CW 9.
-
-
- */
-
-
- #include "main.h"
-
- void MainLoop(void);
- void HandleKeyDown (EventRecord *);
- void MacInits(void);
- void FinishUp(void);
- void HandleUpdates(EventRecord *);
- void HandleMouseDown(EventRecord *);
-
- Boolean gDone = false;
- Boolean gInBackground = false;
- WindowPtr gWindow1 = NULL;
- WindowPtr gWindow2 = NULL;
- static PixPatHandle ppatHandle;
-
-
- void main()
- {
- MacInits();
-
- gWindow1 = GetNewCWindow (128, NULL, (WindowPtr) -1);
- gWindow2 = GetNewCWindow (129, NULL, (WindowPtr) -1);
- SelectWindow(gWindow1);
- SetPort (gWindow1);
-
- MainLoop();
- FinishUp();
- }
-
- void MacInits()
- {
- MaxApplZone();
- MoreMasters();
- MoreMasters();
-
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- FlushEvents (everyEvent, 0);
- InitCursor();
- }
-
-
- void MainLoop(void)
- {
- EventRecord theEvent;
-
- while(!gDone) {
- if (WaitNextEvent (everyEvent, &theEvent, 30, 0L)) {
- switch (theEvent.what) {
- case mouseDown:
- HandleMouseDown(&theEvent);
- break;
-
- case autoKey:
- case keyDown:
- HandleKeyDown(&theEvent);
- break;
-
- case updateEvt:
- HandleUpdates(&theEvent);
- break;
-
- case activateEvt:
- gInBackground = false;
- break;
- }
- }
- }
- }
-
-
-
- void HandleKeyDown (EventRecord *evt)
- {
- char theChar;
-
- theChar = (evt->message & charCodeMask);
-
- if ((evt->modifiers & cmdKey) != 0) {
- switch (theChar) {
- case 'q': case 'Q':
- gDone = true;
- break;
- }
- }
- }
-
-
- void HandleMouseDown(EventRecord *theEvent)
- {
- WindowPtr whichWindow;
- short thePart, controlCode;
- short x, y;
- ControlHandle whichControl;
- Point myPoint;
-
- thePart = FindWindow (theEvent->where, &whichWindow);
-
- switch (thePart) {
- case inSysWindow:
- SystemClick (theEvent, whichWindow);
- break;
-
- case inDrag:
- DragWindow(whichWindow, theEvent->where, &qd.screenBits.bounds);
- break;
-
- case inContent:
- SetPort (whichWindow);
- if (whichWindow != FrontWindow())
- SelectWindow(whichWindow);
- break;
-
- case inGoAway:
- if (whichWindow == gWindow1 &&
- TrackGoAway(gWindow1, theEvent->where) )
- HideWindow(gWindow1);
- gDone = true;
- break;
- }
- }
-
- void HandleUpdates(EventRecord *theEventPtr)
- {
- GrafPtr savedPort;
- WindowPtr windowPtr;
- Rect destRect;
-
- GetPort(&savedPort);
-
- windowPtr = (WindowPtr) theEventPtr->message;
-
- BeginUpdate(windowPtr);
-
- if(!EmptyRgn(windowPtr->visRgn))
- {
- SetPort(windowPtr);
-
- if (windowPtr == gWindow2) {
- ppatHandle = (PixPatHandle) GetPixPat(16);
- if (ppatHandle != NULL) {
- SetRect(&destRect, 15, 125, 197, 164);
- FrameRect(&destRect);
- FillCRect(&destRect, ppatHandle);
- DisposePixPat(ppatHandle);
- }
- }
- if (windowPtr == gWindow1) {
- ppatHandle = (PixPatHandle) GetPixPat(42);
- if (ppatHandle != NULL) {
- SetRect(&destRect, 15, 125, 197, 164);
- FrameRect(&destRect);
- FillCRect(&destRect, ppatHandle);
- DisposePixPat(ppatHandle);
- }
- }
- }
-
- EndUpdate(windowPtr);
- SetPort(savedPort);
- }
-
-
-
- void FinishUp()
- {
- if (gWindow2)
- DisposeWindow(gWindow2);
-
- if (gWindow1)
- DisposeWindow(gWindow1);
-
- ExitToShell();
- }
-
-