home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWOSMisc / Sources / FWMacOS.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  5.8 KB  |  189 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMacOS.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifdef FW_BUILD_MAC
  13.  
  14. #ifndef FWMACOS_H
  15. #include "FWMacOS.h"
  16. #endif
  17.  
  18. #ifndef FWRECT_H
  19. #include "FWRect.h"
  20. #endif
  21.  
  22. #ifndef FWCFMRES_H
  23. #include "FWCFMRes.h"
  24. #endif
  25.  
  26. #if defined(FW_BUILD_MAC) & !defined(__RESOURCES__)
  27. #include <Resources.h>
  28. #endif
  29.  
  30. //========================================================================================
  31. //    Runtime Informations
  32. //========================================================================================
  33.  
  34. #if FW_LIB_EXPORT_PRAGMAS
  35. #pragma lib_export on
  36. #endif
  37.  
  38. #ifdef FW_BUILD_MAC    
  39. #pragma segment fwosmisc
  40. #endif
  41.  
  42. //========================================================================================
  43. //    Mac OS Utlities
  44. //========================================================================================
  45.  
  46. //----------------------------------------------------------------------------------------
  47. //    FW_MacBuildWindowRegions
  48. //----------------------------------------------------------------------------------------
  49. //    Calculate window size including structure region (i.e. title bar). To do this we need,
  50. //    if the window isn't shown, to force the window to compute its structure region by
  51. //    calling its defproc. If build is FALSE, set the regions back to empty regions, so
  52. //    as not to confuse the window manager. Return the previous state of the regions.
  53.  
  54. typedef pascal long(*WDefProcType)(short varCode,
  55.                                     WindowPtr theWindow,
  56.                                     short message,
  57.                                     long param);
  58.  
  59. typedef WDefProcType *WDefProcTypeHandle;
  60.  
  61. static Handle MacGetAndLoadWDefProc(Handle windowDefProc)
  62. {
  63.     if ((*windowDefProc))                        // if Master Ptr is NULL => resource is purged
  64.         return windowDefProc;
  65.     else
  66.     {
  67.         FW_CAcquireCFMResourceAccess qr;
  68.         ::LoadResource(windowDefProc);
  69.         if (::ResError() == noErr)                // only return it if the LoadResource worked
  70.             return windowDefProc;
  71.         else
  72.             return NULL;
  73.     }
  74. }
  75.  
  76. FW_Boolean FW_MacBuildWindowRegions(WindowPtr windowPtr, FW_Boolean build)
  77. {
  78.     FW_ASSERT(windowPtr != NULL);
  79.  
  80.     WindowRecord &theWindowRecord = *((WindowPeek)windowPtr);
  81.  
  82.     // The regions are considered to be built if either:
  83.     //  a) the window is shown; or
  84.     //  b) the structure rgn is not empty.
  85.  
  86.     if (theWindowRecord.visible || !::EmptyRgn(theWindowRecord.strucRgn))
  87.     {
  88.         if ((build != TRUE) && !theWindowRecord.visible)
  89.         {
  90.             ::SetEmptyRgn(theWindowRecord.strucRgn);
  91.             ::SetEmptyRgn(theWindowRecord.contRgn);
  92.         }
  93.         return TRUE;
  94.     }
  95.     else
  96.     {
  97.         if (build == TRUE)
  98.         {
  99.             WDefProcTypeHandle wDefProc = (WDefProcTypeHandle)MacGetAndLoadWDefProc(theWindowRecord.windowDefProc);
  100.             if (wDefProc)
  101.             {
  102.                 SignedByte savedState = ::HGetState((Handle)wDefProc);
  103.                 ::HLock((Handle)wDefProc);
  104. //                WindowDefUPP windowDefUPP = NewWindowDefProc(*wDefProc);
  105.                 WindowDefUPP windowDefUPP = (WindowDefUPP) NewRoutineDescriptor((ProcPtr)(*wDefProc), uppWindowDefProcInfo, ((ISAType) kM68kISA));
  106.                 CallUniversalProc(windowDefUPP, uppWindowDefProcInfo, ::GetWVariant(windowPtr), windowPtr, wCalcRgns, 0);
  107.                 DisposeRoutineDescriptor(windowDefUPP);
  108.                 ::HSetState((Handle)wDefProc, savedState);
  109.             }
  110.         }
  111.         return FALSE;
  112.     }
  113. }
  114.  
  115. //----------------------------------------------------------------------------------------
  116. // FW_MacGetMaxIntersectedDevice
  117. //----------------------------------------------------------------------------------------
  118.  
  119. GDHandle FW_MacGetMaxIntersectedDevice(WindowPtr windowPtr, FW_CRect& screenRect)
  120. {
  121.     FW_ASSERT(windowPtr != NULL);
  122.     
  123.     FW_Boolean rgnsWereBuilt = FW_MacBuildWindowRegions(windowPtr, TRUE);
  124.     Rect globalStrucRect = (*(((WindowPeek)windowPtr)->strucRgn))->rgnBBox;
  125.     FW_MacBuildWindowRegions(windowPtr, rgnsWereBuilt);
  126.     
  127.     long maxSectArea = 0;
  128.     Rect moveBounds = (*(GetGrayRgn()))->rgnBBox;
  129.     InsetRect(&moveBounds, 4, 4);
  130.  
  131.     GDHandle aGDHandle = ::GetDeviceList();
  132.     GDHandle maxSectGD = ::GetMainDevice();    // Set as best choice default 
  133.     while (aGDHandle)
  134.     {                                        // calc which scrn intersects largest part of window
  135.         if (::TestDeviceAttribute(aGDHandle, screenDevice) && ::TestDeviceAttribute(aGDHandle, screenActive))
  136.         {
  137.             Rect aGDScreenRect = (*aGDHandle)->gdRect;
  138.             Rect gdSectRect;
  139.             Rect dontCare;
  140.             if (::SectRect(&aGDScreenRect, &moveBounds, &dontCare) && ::SectRect(&globalStrucRect, &aGDScreenRect, &gdSectRect))
  141.             {
  142.                 long sectArea = (gdSectRect.bottom - gdSectRect.top) * (gdSectRect.right - gdSectRect.left);
  143.                 if (sectArea > maxSectArea)    // do we have a new winner? 
  144.                 {
  145.                     maxSectArea = sectArea;
  146.                     maxSectGD = aGDHandle;
  147.                 }
  148.             }
  149.         }
  150.         aGDHandle = ::GetNextDevice(aGDHandle);
  151.     }
  152.  
  153.     if (maxSectGD != ::GetMainDevice())
  154.         screenRect = (*maxSectGD)->gdRect;
  155.     else
  156.     {                                        // Account for menu bar on the main screen.
  157.         // Don't just assume that its at the fTop of
  158.         // the screen!
  159.         Rect gdRect = (*maxSectGD)->gdRect;
  160.  
  161.         RgnHandle tempRgn = ::NewRgn();
  162.         ::RectRgn(tempRgn, &gdRect);        // main screen with menubar 
  163.         ::SectRgn(tempRgn, GetGrayRgn(), tempRgn);// GetGrayRgn == desktop rgn w/o menubar 
  164.         screenRect = (*tempRgn)->rgnBBox;    // => main screen w/o menubar 
  165.         ::DisposeRgn(tempRgn);
  166.     }
  167.     
  168.     return maxSectGD;
  169. }
  170.  
  171. //----------------------------------------------------------------------------------------
  172. // FW_MacZoomWindow: 
  173. //----------------------------------------------------------------------------------------
  174.  
  175. void FW_MacZoomWindow(WindowPtr windowPtr, FW_Boolean zoomIn)
  176. {
  177.     GrafPtr curGrafPort;
  178.     ::GetPort(&curGrafPort);
  179.     ::SetPort(windowPtr);                                // The ROM requires that thePort be the window being zoomed.
  180.  
  181.     ::ClipRect(&windowPtr->portRect);
  182.     ::EraseRect(&windowPtr->portRect);
  183.     ::ZoomWindow(windowPtr, zoomIn ? inZoomIn : inZoomOut, TRUE);
  184.  
  185.     ::SetPort(curGrafPort);
  186. }
  187.  
  188. #endif
  189.