home *** CD-ROM | disk | FTP | other *** search
- // Copyright: © 1993-94 Apple Computer, Inc. All rights reserved.
- // Author: Scott Searle (original)
- // Victor J. Hnyp (extensions)
- // Dave Lyons (maintenance)
- // Date: 3-Mar-94
-
- // Revisions
- //
- // 03/03/94 DAL 3.01 Moved from Dialog context: isFindDialog, isFindMoreDialog,
- // isAnyDialogActive. Cleaned up the code some.
- //
- // 11/05/93 JJ 2.08 Added isFrontWinCollapsed(), and isCollapsed case to main(),
- // backed out revision 2.07
- //
- // 11/05/93 JJ 2.07 Added TestWinCollapsed(), and isCollapsed case to IsWindowWithName()
- //
- // 04/08/93 VJH 2.06 Moved isFindDialog, isFindMoreDialog back to Dialog module
- //
- // 03/13/93 VJH 2.05 Moved isFindDialog, isFindMoreDialog here temporarily
- //
- // 03/09/93 VJH 2.04 Fixed: isFront, isOpen containsAnything
- //
- // 03/03/93 VJH 2.03 Fixed: Patch to ignore "Desktop" within the windowlist
- //
- // 02/24/93 VJH 2.02 Fixed: Added isShareWindowOpen and isShareWindowActive context checks
- /*
-
- 1.0d1e4 22-May-92 Removed window pointer selector.
- Removed dialog ID selector (will be separate module.)
- removed inSize >= sizeof(WindowState).
- 1.0d1e5 13-Jul-92 change creator from 'ctxt' to 'reno'
-
- */
-
-
- #pragma load "AllHeaders.dump"
-
- #include "Utility.h"
- #include "Proto.h"
- #include "Context.h"
- #include "Window.h"
-
-
- /* ------------------ Forward Declaration ---------------- */
-
- pascal Boolean IsWindowWithName(WindowStatePtr wMessage);
- pascal Boolean IsShareWindowOpen(void);
- pascal Boolean IsShareWindowActive(void);
- pascal Boolean AreAnyDialogsActive(void);
- pascal Boolean IsFindDialogActive(void);
- pascal Boolean IsFindMoreDialogActive(void);
- WindowPtr GetWindowPtr(WindowSpecPtr wSpec);
- Boolean TestWindowVisible(WindowPtr wPtr);
- Boolean TestWindowNotVisible(WindowPtr wPtr);
- Boolean TestWindowFront(WindowPtr wPtr);
- Boolean IsFrontWinCollapsed(void);
-
-
- pascal OSErr main(ContextSelectorPtr msg, Size inSize,
- void* outMessage, Size* outSize, Handle /*startGlobals*/)
- {
- Boolean ret = false;
- OSErr err = errAECorruptData;
-
- if(inSize < sizeof(ContextSelector)) /* If inSize is < length of selector (a long), */
- return(err); /* return an error. Would be nice to have a specific error # */
-
- switch (msg->selector)
- {
- case isFront:
- case isOpen:
- case isInvisible:
- ret = IsWindowWithName( (WindowStatePtr) msg );
- break;
-
- case isShareWindowOpen:
- ret = IsShareWindowOpen();
- break;
-
- case isShareWindowActive:
- ret = IsShareWindowActive();
- break;
-
- case isCollapsed:
- ret = IsFrontWinCollapsed();
- break;
-
- case isFindDialog:
- ret = IsFindDialogActive();
- break;
-
- case isFindMoreDialog:
- ret = IsFindMoreDialogActive();
- break;
-
- case isAnyDialogActive:
- ret = AreAnyDialogsActive();
- break;
-
- default: /* None of the pre-defined types. Exit with error */
- break; /* Would be nice to have a specific error # */
- }
-
- err = SetContextResult(&ret, sizeof(Boolean), outMessage, outSize);
- return(err);
- }
-
-
- pascal Boolean IsWindowWithName(WindowStatePtr wMessage)
- {
- WindowPtr wPtr;
- Boolean ret = false;
-
- if (wPtr = GetWindowPtr(&wMessage->wSpec))
- {
- switch (wMessage->selector)
- {
- case isFront:
- ret = TestWindowFront(wPtr);
- break;
-
- case isOpen:
- ret = TestWindowVisible(wPtr);
- break;
-
- case isInvisible:
- ret = TestWindowNotVisible(wPtr);
- break;
- }
- }
-
- return ret;
- }
-
-
- // The "Share" window contains the name of the item to be shared as the window
- // title, and thus this is a static name which can't be located through the
- // normal window context checks.
-
- pascal Boolean IsShareWindowOpen(void)
- {
- Boolean ret = false;
- WindowPeek wp;
-
- for (wp = (WindowPeek) WindowList; wp; wp = wp->nextWindow)
- {
- if (((wp)->port.portRect.top == 0 ) &&
- ((wp)->port.portRect.left == 0 ) &&
- ((wp)->port.portRect.bottom == 222 ) &&
- ((wp)->port.portRect.right == 304 ) &&
- ((wp)->windowKind == 0x14 )) // Windowkind must be 20
- {
- ret = true;
- break;
- }
- }
-
- return ret;
- }
-
-
-
- // The "Share" window contains the name of the item to be shared as the window
- // title, and thus this is a static name which can't be located through the
- // normal window context checks.
-
- pascal Boolean IsShareWindowActive(void)
- {
- WindowPtr theWind;
- Boolean ret = false;
-
- if(theWind = FrontWindow())
- {
- if ((((WindowPeek)theWind)->port.portRect.top == 0 ) &&
- (((WindowPeek)theWind)->port.portRect.left == 0 ) &&
- (((WindowPeek)theWind)->port.portRect.bottom == 222 ) &&
- (((WindowPeek)theWind)->port.portRect.right == 304 ) &&
- (((WindowPeek)theWind)->windowKind == 0x14 )) // Windowkind must be 20
- {
- ret = true;
- }
- }
-
- return ret;
- }
-
-
- pascal Boolean AreAnyDialogsActive(void)
- {
- Boolean ret = false;
- WindowPeek wp;
-
- for (wp = (WindowPeek) WindowList; wp; wp = wp->nextWindow)
- {
- if(( wp->windowKind == dialogKind )
- && ( wp->visible )
- && ( wp->hilited ))
- {
- ret = true;
- break;
- }
- }
-
- return ret;
- }
-
-
- // The "Find" dialog is not loaded through a GetNewDialog call, and so
- // can't be found through the general process of patching that ATrap. Instead,
- // we go through the entire window list and check for the known coordinates of
- // the window that belongs to the dialog. To be double-sure, we check the title
- // and windowKind.
-
- pascal Boolean IsFindDialogActive(void)
- {
- WindowPtr theWind;
- Boolean ret = false;
- Str255 winTitle;
-
- if(theWind = FrontWindow())
- {
- GetWTitle(theWind, winTitle);
- if ((((WindowPeek)theWind)->port.portRect.top == 0 ) &&
- (((WindowPeek)theWind)->port.portRect.left == 0 ) &&
- (((WindowPeek)theWind)->port.portRect.bottom == 80 ) &&
- (((WindowPeek)theWind)->port.portRect.right == 320 ) &&
- (((WindowPeek)theWind)->windowKind == 0x14 ) && // Windowkind must be 20
- (EQString(winTitle, "\pFind")))
- {
- ret = true;
- }
- }
-
- return ret;
- }
-
-
- // The "Find (more choices)" dialog is not loaded through a GetNewDialog call,
- // and so can not be found through the general process of patching that ATrap.
- // Instead, we go through the entire window list and check for the known
- // coordinates of the window that belongs to the dialog. To be double-sure, we
- // check the title and windowKind.
-
- pascal Boolean IsFindMoreDialogActive(void)
- {
- WindowPtr theWind;
- Boolean ret = false;
- Str255 winTitle;
-
- if(theWind = FrontWindow())
- {
- GetWTitle(theWind, winTitle);
- if ((((WindowPeek)theWind)->port.portRect.top == 0 ) &&
- (((WindowPeek)theWind)->port.portRect.left == 0 ) &&
- (((WindowPeek)theWind)->port.portRect.bottom == 159 ) &&
- (((WindowPeek)theWind)->port.portRect.right == 444 ) &&
- (((WindowPeek)theWind)->windowKind == 0x14 ) && // Windowkind must be 20
- (EQString(winTitle, "\pFind")))
- {
- ret = true;
- }
- }
-
- return ret;
- }
-
-
-
- // Return WindowPtr for the given WSpecPtr.
-
- WindowPtr GetWindowPtr(WindowSpecPtr wSpec)
- {
- WindowPeek wp;
- Str255 title;
- WindowPtr wPtr = nil;
-
- 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 (CompareStringSpec(title, &wSpec->wName))
- {
- wPtr = (WindowPtr)wp;
- break;
- }
- }
-
- return wPtr;
- }
-
-
- // TRUE if the window is visible and hilited
- Boolean TestWindowVisible(WindowPtr wPtr)
- {
- if (wPtr)
- return( ((WindowPeek) wPtr)->visible );
- else
- return false;
- }
-
-
- // TRUE if the specified window is not visible
- Boolean TestWindowNotVisible(WindowPtr wPtr)
- {
- if (wPtr)
- return ( !((WindowPeek) wPtr)->visible );
- else
- return false;
- }
-
-
- // TRUE if the specified window is the front window
- Boolean TestWindowFront(WindowPtr wPtr)
- {
- if (wPtr)
- return (wPtr == FrontWindow());
- else
- return false;
- }
-
-
- // TRUE if the front window is collapsed (i.e. via WindowShade )
- Boolean IsFrontWinCollapsed(void)
- {
- return EmptyRgn( ((WindowPeek) WindowList)->contRgn );
- }
-