home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 5.8 KB | 189 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWMacOS.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifdef FW_BUILD_MAC
-
- #ifndef FWMACOS_H
- #include "FWMacOS.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #if defined(FW_BUILD_MAC) & !defined(__RESOURCES__)
- #include <Resources.h>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwosmisc
- #endif
-
- //========================================================================================
- // Mac OS Utlities
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_MacBuildWindowRegions
- //----------------------------------------------------------------------------------------
- // Calculate window size including structure region (i.e. title bar). To do this we need,
- // if the window isn't shown, to force the window to compute its structure region by
- // calling its defproc. If build is FALSE, set the regions back to empty regions, so
- // as not to confuse the window manager. Return the previous state of the regions.
-
- typedef pascal long(*WDefProcType)(short varCode,
- WindowPtr theWindow,
- short message,
- long param);
-
- typedef WDefProcType *WDefProcTypeHandle;
-
- static Handle MacGetAndLoadWDefProc(Handle windowDefProc)
- {
- if ((*windowDefProc)) // if Master Ptr is NULL => resource is purged
- return windowDefProc;
- else
- {
- FW_CAcquireCFMResourceAccess qr;
- ::LoadResource(windowDefProc);
- if (::ResError() == noErr) // only return it if the LoadResource worked
- return windowDefProc;
- else
- return NULL;
- }
- }
-
- FW_Boolean FW_MacBuildWindowRegions(WindowPtr windowPtr, FW_Boolean build)
- {
- FW_ASSERT(windowPtr != NULL);
-
- WindowRecord &theWindowRecord = *((WindowPeek)windowPtr);
-
- // The regions are considered to be built if either:
- // a) the window is shown; or
- // b) the structure rgn is not empty.
-
- if (theWindowRecord.visible || !::EmptyRgn(theWindowRecord.strucRgn))
- {
- if ((build != TRUE) && !theWindowRecord.visible)
- {
- ::SetEmptyRgn(theWindowRecord.strucRgn);
- ::SetEmptyRgn(theWindowRecord.contRgn);
- }
- return TRUE;
- }
- else
- {
- if (build == TRUE)
- {
- WDefProcTypeHandle wDefProc = (WDefProcTypeHandle)MacGetAndLoadWDefProc(theWindowRecord.windowDefProc);
- if (wDefProc)
- {
- SignedByte savedState = ::HGetState((Handle)wDefProc);
- ::HLock((Handle)wDefProc);
- // WindowDefUPP windowDefUPP = NewWindowDefProc(*wDefProc);
- WindowDefUPP windowDefUPP = (WindowDefUPP) NewRoutineDescriptor((ProcPtr)(*wDefProc), uppWindowDefProcInfo, ((ISAType) kM68kISA));
- CallUniversalProc(windowDefUPP, uppWindowDefProcInfo, ::GetWVariant(windowPtr), windowPtr, wCalcRgns, 0);
- DisposeRoutineDescriptor(windowDefUPP);
- ::HSetState((Handle)wDefProc, savedState);
- }
- }
- return FALSE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MacGetMaxIntersectedDevice
- //----------------------------------------------------------------------------------------
-
- GDHandle FW_MacGetMaxIntersectedDevice(WindowPtr windowPtr, FW_CRect& screenRect)
- {
- FW_ASSERT(windowPtr != NULL);
-
- FW_Boolean rgnsWereBuilt = FW_MacBuildWindowRegions(windowPtr, TRUE);
- Rect globalStrucRect = (*(((WindowPeek)windowPtr)->strucRgn))->rgnBBox;
- FW_MacBuildWindowRegions(windowPtr, rgnsWereBuilt);
-
- long maxSectArea = 0;
- Rect moveBounds = (*(GetGrayRgn()))->rgnBBox;
- InsetRect(&moveBounds, 4, 4);
-
- GDHandle aGDHandle = ::GetDeviceList();
- GDHandle maxSectGD = ::GetMainDevice(); // Set as best choice default
- while (aGDHandle)
- { // calc which scrn intersects largest part of window
- if (::TestDeviceAttribute(aGDHandle, screenDevice) && ::TestDeviceAttribute(aGDHandle, screenActive))
- {
- Rect aGDScreenRect = (*aGDHandle)->gdRect;
- Rect gdSectRect;
- Rect dontCare;
- if (::SectRect(&aGDScreenRect, &moveBounds, &dontCare) && ::SectRect(&globalStrucRect, &aGDScreenRect, &gdSectRect))
- {
- long sectArea = (gdSectRect.bottom - gdSectRect.top) * (gdSectRect.right - gdSectRect.left);
- if (sectArea > maxSectArea) // do we have a new winner?
- {
- maxSectArea = sectArea;
- maxSectGD = aGDHandle;
- }
- }
- }
- aGDHandle = ::GetNextDevice(aGDHandle);
- }
-
- if (maxSectGD != ::GetMainDevice())
- screenRect = (*maxSectGD)->gdRect;
- else
- { // Account for menu bar on the main screen.
- // Don't just assume that its at the fTop of
- // the screen!
- Rect gdRect = (*maxSectGD)->gdRect;
-
- RgnHandle tempRgn = ::NewRgn();
- ::RectRgn(tempRgn, &gdRect); // main screen with menubar
- ::SectRgn(tempRgn, GetGrayRgn(), tempRgn);// GetGrayRgn == desktop rgn w/o menubar
- screenRect = (*tempRgn)->rgnBBox; // => main screen w/o menubar
- ::DisposeRgn(tempRgn);
- }
-
- return maxSectGD;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MacZoomWindow:
- //----------------------------------------------------------------------------------------
-
- void FW_MacZoomWindow(WindowPtr windowPtr, FW_Boolean zoomIn)
- {
- GrafPtr curGrafPort;
- ::GetPort(&curGrafPort);
- ::SetPort(windowPtr); // The ROM requires that thePort be the window being zoomed.
-
- ::ClipRect(&windowPtr->portRect);
- ::EraseRect(&windowPtr->portRect);
- ::ZoomWindow(windowPtr, zoomIn ? inZoomIn : inZoomOut, TRUE);
-
- ::SetPort(curGrafPort);
- }
-
- #endif
-