home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 April: Mac OS SDK / Dev.CD Apr 00 SDK1.toast / Development Kits / Mac OS / Apple Guide / Engineering / Context Check Modules / Standard CC Modules / Window Context / Window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  7.8 KB  |  330 lines  |  [TEXT/MPS ]

  1. //    Copyright:    © 1993-94 Apple Computer, Inc. All rights reserved.
  2. //    Author:        Scott Searle (original)
  3. //                Victor J. Hnyp (extensions)
  4. //                Dave Lyons (maintenance)
  5. //    Date:        3-Mar-94
  6.  
  7. // Revisions
  8. //
  9. //    03/03/94    DAL    3.01    Moved from Dialog context: isFindDialog, isFindMoreDialog,
  10. //                            isAnyDialogActive.  Cleaned up the code some.
  11. //
  12. //    11/05/93    JJ    2.08    Added isFrontWinCollapsed(), and isCollapsed case to main(),
  13. //                            backed out revision 2.07
  14. //
  15. //    11/05/93    JJ    2.07    Added TestWinCollapsed(), and isCollapsed case to IsWindowWithName()
  16. //
  17. //    04/08/93    VJH    2.06    Moved isFindDialog, isFindMoreDialog back to Dialog module
  18. //
  19. //    03/13/93    VJH    2.05    Moved isFindDialog, isFindMoreDialog here temporarily
  20. //
  21. //    03/09/93    VJH    2.04    Fixed:    isFront, isOpen containsAnything
  22. //
  23. //    03/03/93    VJH    2.03    Fixed:    Patch to ignore "Desktop" within the windowlist
  24. //
  25. //    02/24/93    VJH    2.02    Fixed:    Added isShareWindowOpen and isShareWindowActive context checks
  26. /*
  27.  
  28.     1.0d1e4 22-May-92        Removed window pointer selector.
  29.                                 Removed dialog ID selector (will be separate module.)
  30.                                 removed inSize >= sizeof(WindowState).
  31.     1.0d1e5 13-Jul-92        change creator from 'ctxt' to 'reno'
  32.  
  33. */
  34.  
  35.  
  36. #pragma    load "AllHeaders.dump"
  37.  
  38. #include "Utility.h"
  39. #include "Proto.h"
  40. #include "Context.h"
  41. #include "Window.h"
  42.  
  43.  
  44. /* ------------------ Forward Declaration ---------------- */
  45.  
  46. pascal Boolean IsWindowWithName(WindowStatePtr wMessage);
  47. pascal Boolean IsShareWindowOpen(void);
  48. pascal Boolean IsShareWindowActive(void);
  49. pascal Boolean AreAnyDialogsActive(void);
  50. pascal Boolean IsFindDialogActive(void);
  51. pascal Boolean IsFindMoreDialogActive(void);
  52. WindowPtr GetWindowPtr(WindowSpecPtr wSpec);
  53. Boolean TestWindowVisible(WindowPtr wPtr);
  54. Boolean TestWindowNotVisible(WindowPtr wPtr);
  55. Boolean TestWindowFront(WindowPtr wPtr);
  56. Boolean    IsFrontWinCollapsed(void);
  57.  
  58.  
  59. pascal OSErr main(ContextSelectorPtr msg, Size inSize,
  60.                     void* outMessage, Size* outSize, Handle /*startGlobals*/)
  61. {
  62.     Boolean        ret    =    false;
  63.     OSErr        err    =    errAECorruptData;
  64.     
  65.     if(inSize < sizeof(ContextSelector))                    /* If inSize is < length of selector (a long), */
  66.         return(err);                                        /* return an error. Would be nice to have a specific error # */
  67.     
  68.     switch (msg->selector)
  69.     {
  70.         case isFront:
  71.         case isOpen:
  72.         case isInvisible:
  73.             ret = IsWindowWithName( (WindowStatePtr) msg );
  74.             break;
  75.             
  76.         case isShareWindowOpen:
  77.             ret = IsShareWindowOpen();
  78.             break;
  79.             
  80.         case isShareWindowActive:
  81.             ret = IsShareWindowActive();
  82.             break;
  83.             
  84.         case isCollapsed:
  85.             ret = IsFrontWinCollapsed();
  86.             break;
  87.  
  88.         case isFindDialog:
  89.             ret = IsFindDialogActive();
  90.             break;
  91.             
  92.         case isFindMoreDialog:
  93.             ret = IsFindMoreDialogActive();
  94.             break;
  95.             
  96.         case isAnyDialogActive:
  97.             ret = AreAnyDialogsActive();
  98.             break;
  99.             
  100.         default:                                    /* None of the pre-defined types. Exit with error */
  101.             break;                                    /* Would be nice to have a specific error # */
  102.     }
  103.  
  104.     err    = SetContextResult(&ret, sizeof(Boolean), outMessage, outSize);
  105.     return(err);
  106. }
  107.  
  108.  
  109. pascal Boolean IsWindowWithName(WindowStatePtr wMessage)
  110. {
  111.     WindowPtr        wPtr;
  112.     Boolean            ret    =    false;
  113.  
  114.     if (wPtr = GetWindowPtr(&wMessage->wSpec))
  115.     {
  116.         switch (wMessage->selector)
  117.         {
  118.             case isFront:
  119.                 ret = TestWindowFront(wPtr);
  120.                 break;
  121.  
  122.             case isOpen:
  123.                 ret = TestWindowVisible(wPtr);
  124.                 break;
  125.  
  126.             case isInvisible:
  127.                 ret = TestWindowNotVisible(wPtr);
  128.                 break;
  129.         }
  130.     }
  131.     
  132.     return ret;
  133. }
  134.  
  135.  
  136. // The "Share" window contains the name of the item to be shared as the window
  137. // title, and thus this is a static name which can't be located through the
  138. // normal window context checks.
  139.  
  140. pascal Boolean IsShareWindowOpen(void)
  141. {
  142.     Boolean            ret    =    false;
  143.     WindowPeek        wp;
  144.  
  145.     for (wp = (WindowPeek) WindowList; wp; wp = wp->nextWindow)
  146.     {
  147.         if (((wp)->port.portRect.top == 0 ) &&
  148.             ((wp)->port.portRect.left == 0 ) &&
  149.             ((wp)->port.portRect.bottom == 222 ) &&
  150.             ((wp)->port.portRect.right == 304 ) &&
  151.             ((wp)->windowKind == 0x14 ))                            // Windowkind must be 20
  152.         {
  153.             ret = true;
  154.             break;
  155.         }
  156.     }
  157.  
  158.     return ret;
  159. }
  160.  
  161.  
  162.  
  163. // The "Share" window contains the name of the item to be shared as the window
  164. // title, and thus this is a static name which can't be located through the
  165. // normal window context checks.
  166.  
  167. pascal Boolean IsShareWindowActive(void)
  168. {
  169.     WindowPtr    theWind;
  170.     Boolean        ret    =    false;
  171.     
  172.     if(theWind = FrontWindow())
  173.     {
  174.         if ((((WindowPeek)theWind)->port.portRect.top == 0 ) &&
  175.             (((WindowPeek)theWind)->port.portRect.left == 0 ) &&
  176.             (((WindowPeek)theWind)->port.portRect.bottom == 222 ) &&
  177.             (((WindowPeek)theWind)->port.portRect.right == 304 ) &&
  178.             (((WindowPeek)theWind)->windowKind == 0x14 ))                    // Windowkind must be 20
  179.         {
  180.             ret = true;
  181.         }
  182.     }
  183.  
  184.     return ret;
  185. }
  186.  
  187.  
  188. pascal Boolean AreAnyDialogsActive(void)
  189. {
  190.     Boolean            ret    =    false;
  191.     WindowPeek        wp;
  192.     
  193.     for (wp = (WindowPeek) WindowList; wp; wp = wp->nextWindow)
  194.     {
  195.         if(( wp->windowKind == dialogKind )
  196.             && ( wp->visible )
  197.             && ( wp->hilited ))
  198.         {
  199.             ret = true;
  200.             break;
  201.         }
  202.     }
  203.  
  204.     return ret;
  205. }
  206.  
  207.  
  208. // The "Find" dialog is not loaded through a GetNewDialog call, and so
  209. // can't be found through the general process of patching that ATrap. Instead,
  210. // we go through the entire window list and check for the known coordinates of
  211. // the window that belongs to the dialog. To be double-sure, we check the title
  212. // and windowKind.
  213.  
  214. pascal Boolean IsFindDialogActive(void)
  215. {
  216.     WindowPtr    theWind;
  217.     Boolean        ret    =    false;
  218.     Str255        winTitle;
  219.     
  220.     if(theWind = FrontWindow())
  221.     {
  222.         GetWTitle(theWind, winTitle);
  223.         if ((((WindowPeek)theWind)->port.portRect.top == 0 ) &&
  224.             (((WindowPeek)theWind)->port.portRect.left == 0 ) &&
  225.             (((WindowPeek)theWind)->port.portRect.bottom == 80 ) &&
  226.             (((WindowPeek)theWind)->port.portRect.right == 320 ) &&
  227.             (((WindowPeek)theWind)->windowKind == 0x14 ) &&                    // Windowkind must be 20
  228.             (EQString(winTitle, "\pFind")))
  229.         {
  230.             ret = true;
  231.         }
  232.     }
  233.  
  234.     return ret;
  235. }
  236.  
  237.  
  238. // The "Find (more choices)" dialog is not loaded through a GetNewDialog call,
  239. // and so can not be found through the general process of patching that ATrap.
  240. // Instead, we go through the entire window list and check for the known
  241. // coordinates of the window that belongs to the dialog. To be double-sure, we
  242. // check the title and windowKind.
  243.  
  244. pascal Boolean IsFindMoreDialogActive(void)
  245. {
  246.     WindowPtr    theWind;
  247.     Boolean        ret    =    false;
  248.     Str255        winTitle;
  249.     
  250.     if(theWind = FrontWindow())
  251.     {
  252.         GetWTitle(theWind, winTitle);
  253.         if ((((WindowPeek)theWind)->port.portRect.top == 0 ) &&
  254.             (((WindowPeek)theWind)->port.portRect.left == 0 ) &&
  255.             (((WindowPeek)theWind)->port.portRect.bottom == 159 ) &&
  256.             (((WindowPeek)theWind)->port.portRect.right == 444 ) &&
  257.             (((WindowPeek)theWind)->windowKind == 0x14 ) &&                    // Windowkind must be 20
  258.             (EQString(winTitle, "\pFind")))
  259.         {
  260.             ret = true;
  261.         }
  262.     }
  263.  
  264.     return ret;
  265. }
  266.  
  267.  
  268.  
  269. //    Return WindowPtr for the given WSpecPtr.
  270.  
  271. WindowPtr GetWindowPtr(WindowSpecPtr wSpec)
  272. {
  273.     WindowPeek        wp;
  274.     Str255            title;
  275.     WindowPtr        wPtr    =    nil;
  276.  
  277.     for (wp = (WindowPeek) WindowList; wp; wp = wp->nextWindow)
  278.     {
  279.         GetWTitle( (WindowPtr) wp, title);
  280.         
  281.         // if window title is "Desktop" ( == 0) pretend we didn't see it, else compare for this window
  282.  
  283.         if( IUEqualString(title, "\pDesktop") != 0 )
  284.             if (CompareStringSpec(title, &wSpec->wName))
  285.             {
  286.                 wPtr = (WindowPtr)wp;
  287.                 break;
  288.             }
  289.     }
  290.  
  291.     return wPtr;
  292. }
  293.  
  294.  
  295. //    TRUE if the window is visible and hilited
  296. Boolean TestWindowVisible(WindowPtr wPtr)
  297. {
  298.     if (wPtr)
  299.         return( ((WindowPeek) wPtr)->visible );
  300.     else
  301.         return false;
  302. }
  303.  
  304.  
  305. //    TRUE if the specified window is not visible
  306. Boolean TestWindowNotVisible(WindowPtr wPtr)
  307. {
  308.     if (wPtr)
  309.         return ( !((WindowPeek) wPtr)->visible );
  310.     else
  311.         return false;
  312. }
  313.  
  314.  
  315. //    TRUE if the specified window is the front window
  316. Boolean TestWindowFront(WindowPtr wPtr)
  317. {
  318.     if (wPtr)
  319.         return (wPtr == FrontWindow());
  320.     else
  321.         return false;
  322. }
  323.  
  324.  
  325. //    TRUE if the front window is collapsed (i.e. via WindowShade )
  326. Boolean    IsFrontWinCollapsed(void)
  327. {
  328.     return EmptyRgn( ((WindowPeek) WindowList)->contRgn );
  329. }
  330.