home *** CD-ROM | disk | FTP | other *** search
- /*
- File: winRect.c
-
- Contains: AppleGuide Context Check
-
- Written by: Josh Jacobs, Panoramic Software
-
- Copyright: ©1993 Apple Computer, Inc., All Rights Reserved.
-
- Change History (most recent first):
-
- 1 04/16/94 JJ First version of code
- */
-
- #include "winRect.h"
-
- // prototypes
- WindowPtr GetWindowPtr(Str255 winName);
- Boolean DoesWindowsRectMatch(WindowPtr wp, Rect* rPtr);
- OSErr SetContextResult(void* theData, Size theSize, Ptr* outMessage, Size* outSize);
- void PStrCat (Str255 destination, Str255 source);
- void RectToString(Rect *aRect, Str255 s);
- Boolean isPressed(unsigned short k);
-
- pascal OSErr
- main(WinRectData* msg, Size inSize, void* outMessage,Size* outSize, Handle ignoreMe )
- {
- OSErr err = errAECorruptData; // the default
- Boolean result = false; // in case we have an error we can jusr return false
- WindowPtr wPtr = nil;
-
- wPtr = GetWindowPtr(msg->winName);
- if (wPtr)
- result = DoesWindowsRectMatch(wPtr,(Rect*)&(msg->compareTo));
-
- err = SetContextResult(&result, sizeof(Boolean), outMessage, outSize);
- return(err);
- }
-
-
- // GetWindowPtr returns a pointer to the author specified window
- WindowPtr GetWindowPtr(Str255 winName)
- {
- WindowPeek wp;
- Str255 title;
- WindowPtr wPtr = nil;
-
- // if it is the front window we do not need to walk the window list
- if (!IUEqualString("\pFront",winName))
- return(FrontWindow());
-
- for (wp = (WindowPeek)WindowList; wp; wp = wp->nextWindow)
- {
- GetWTitle((WindowPtr)wp, title);
-
- // if window title is "Desktop" ( == 0) pretend we didn't see it, else compare for this window
- if( IUEqualString(title, "\pDesktop") != 0 )
- if (!IUEqualString(title, winName))
- {
- wPtr = (WindowPtr)wp;
- break;
- }
- }
-
- return(wPtr);
- }
-
- Boolean DoesWindowsRectMatch(WindowPtr wp, Rect* rPtr)
- {
- Str255 debug;
-
- /* ••Only if we are doing a debug build, you do not want this code to ship!
- if( isPressed(56)) // the shift key
- {
- RectToString((&(((WindowPeek)wp)->port.portRect)),debug);
- DebugStr(debug);
- }
- */
- return(EqualRect((&(((WindowPeek)wp)->port.portRect)),rPtr));
- }
-
-
- // Setup the result the way Reno expects it
- OSErr SetContextResult(void* theData, Size theSize, Ptr* outMessage, Size* outSize)
- {
- Ptr p;
-
- if (p = NewPtr(theSize))
- {
- BlockMove(theData, p, theSize);
-
- *outSize = theSize;
- *outMessage = p;
-
- return(noErr);
- }
- else
- return(MemError());
- }
-
-
- void PStrCat (Str255 destination, Str255 source)
- {
- short index, t1, t2, max, newlen;
-
- t1 = destination[0] ;
- t2 = source[0] ;
-
- if (t1 + t2 > kMaxStringSize)
- {
- newlen = kMaxStringSize;
- max = kMaxStringSize - t1;
- }
- else
- {
- newlen = t1 + t2;
- max = t2;
- }
-
- for (index = 1; index <= max; index ++)
- destination[index + t1] = source[index];
-
- destination[0] = newlen;
- }
-
-
- void RectToString(Rect *aRect, Str255 s)
- {
- Str255 temp;
-
- NumToString((long)aRect->top,s);
- PStrCat(s,"\p,");
- NumToString((long)aRect->left,temp);
- PStrCat(s,temp);
- PStrCat(s,"\p,");
- NumToString((long)aRect->bottom,temp);
- PStrCat(s,temp);
- PStrCat(s,"\p,");
- NumToString((long)aRect->right,temp);
- PStrCat(s,temp);
- }
-
- Boolean isPressed(unsigned short k)
- {
- unsigned char km[16];
-
- GetKeys((long *)km);
- return(Boolean)( (km[ k>>3 ] >> (k & 7) ) & 1);
-
- }
-