home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-30 | 5.5 KB | 280 lines | [TEXT/KAHL] |
- /***************************************
- "CColorBitMapPane.cp"
-
- by John A. Love, III [Ph.D. student]
-
- using Symantec's "THINK C / C++", v 6/7
- based on Symantec's "Art Class"
- ***************************************/
-
-
-
-
- #include <Global.h>
- #include <LongQD.h>
- #include <TCLUtilities.h>
-
- #include "CColorBitMap.h"
- #include "CColorBitMapPane.h"
-
-
-
- void CColorBitMapPane::IColorBitMapPane (CView *anEnclosure,
- CBureaucrat *aSupervisor,
- short aWidth, short aHeight,
- short aHEncl, short aVEncl,
- SizingOption aHSizing,
- SizingOption aVSizing,
- LongRect *aBounds,
- CColorBitMap *aBitMap,
- Boolean makePort)
- {
- Rect globalBoundsR;
- GDHandle currMaxDevice;
- RgnHandle desktop;
-
-
- CPanorama::IPanorama( anEnclosure, aSupervisor,
- aWidth, aHeight,
- aHEncl, aVEncl,
- aHSizing, aVSizing );
-
- bounds = *aBounds;
- position.h = bounds.left;
- position.v = bounds.top;
-
- itsBitMap = NULL;
- bitsUnderPane = NULL;
- gdOption = kDeepestScreen;
-
- /* Since FrameToGlobalR accesses CPane's hOrigin & vOrigin: */
- CPane::Prepare();
-
- FrameToGlobalR( aBounds, &globalBoundsR );
-
- if ( !gSystem.hasColorQD )
- {
- currentDepth = 1;
- }
- else
- {
- currMaxDevice = GetScreenDevice( &globalBoundsR );
- if (currMaxDevice != nil)
- currentDepth = (**( (**currMaxDevice).gdPMap )).pixelSize;
- else
- FailOSErr( NilGDeviceError );
-
- } /* has Color Quickdraw */
-
- if (aBitMap == NULL)
- {
- TRY
- {
- aBitMap = new (CColorBitMap);
- /*
- IColorBitMap calls ForceNextPrepare().
- See other comments within "CColorBitMap.h":
- */
- aBitMap->IColorBitMap( (short) (aBounds->right - aBounds->left),
- (short) (aBounds->bottom - aBounds->top),
- makePort );
- itsBitMap = aBitMap;
- }
- CATCH
- {
- ForgetObject( aBitMap );
- }
- ENDTRY;
-
- /*
- ** I "roll my own" bounds within IColorBitMap:
- ** itsBitMap->SetBoundsOrigin( aBounds->left, aBounds->top );
- */
-
- }
-
- else itsBitMap = aBitMap;
-
- TRY
- {
- bitsUnderPane = new (CColorBitMap);
- bitsUnderPane->IColorBitMap( (short) (aBounds->right - aBounds->left),
- (short) (aBounds->bottom - aBounds->top),
- makePort );
- }
- CATCH
- {
- ForgetObject( bitsUnderPane ); /* Can't have one ... */
- ForgetObject( itsBitMap ); /* ... without the other. */
- }
- ENDTRY;
-
- autoRefresh = FALSE;
-
- } /* IColorBitMapPane */
-
-
-
- /* OVERRIDE: */
- void CColorBitMapPane::Dispose (void)
- {
-
- ForgetObject( bitsUnderPane );
-
- CBitMapPane::Dispose();
-
- } /* Dispose */
-
-
-
- /* OVERRIDE: */
- void CColorBitMapPane::Draw (Rect *area)
- {
- /* Shhhh!! - don't say "macBitMap": */
-
- LongRect theLBounds, lArea;
- Rect theSBounds;
-
-
- if (itsBitMap != NULL)
- {
- if ( BitMapsNeedUpdating() )
- {
- ((CColorBitMap*) itsBitMap)->Update();
- if (bitsUnderPane) bitsUnderPane->Update();
- }
-
- itsBitMap->GetBounds( &theLBounds );
- LongToQDRect( &theLBounds, &theSBounds );
- SectRect( area, &theSBounds, area );
-
- QDToFrameR( area, &lArea );
- itsBitMap->CopyFrom( &lArea, &lArea, NULL );
- }
-
- } /* Draw */
-
-
-
-
- Boolean CColorBitMapPane::BitMapsNeedUpdating (void)
- {
- LongRect theBoundsRect;
- Rect globalBoundsR;
- GDHandle newMaxDevice;
- short newDepth;
-
-
- if ( !gSystem.hasColorQD )
- {
- return (FALSE);
- }
- else
- {
- Prepare();
-
- itsBitMap->GetBounds( &theBoundsRect );
- FrameToGlobalR( &theBoundsRect, &globalBoundsR );
-
- newMaxDevice = GetScreenDevice( &globalBoundsR );
- if (newMaxDevice == nil)
- {
- return (FALSE); /* May be literally off the screen. */
- }
- else
- {
- newDepth = (**( (**newMaxDevice).gdPMap )).pixelSize;
- if (newDepth > currentDepth)
- {
- currentDepth = newDepth;
- return (TRUE);
- }
- else
- {
- return (FALSE);
- }
-
- } /* newMaxDevice ≠ nil */
-
- } /* has Color Quickdraw */
-
- } /* BitMapsNeedUpdating */
-
-
-
- GDHandle CColorBitMapPane::GetScreenDevice (Rect *globalRect)
- {
- RgnHandle desktop;
- long area, maxArea;
- GDHandle device, result = nil;
- Rect intersection;
-
-
- /* Different screen options require different algorithms: */
-
- if (gdOption == kDeepestScreen)
- {
- result = GetMaxDevice( globalRect );
- }
-
- else if (gdOption == kLargestAreaScreen)
- {
- /* Get a Handle to the first GDevice in the GDevice list: */
- device = GetDeviceList();
-
- /* Keep looping until all GDevices have been checked: */
- maxArea = 0;
- while (device != nil)
- {
- if ( TestDeviceAttribute( device, screenDevice ) )
- {
- if ( TestDeviceAttribute( device, screenActive ) )
- {
- /* Do screen and passed Rect intersect? */
- if ( SectRect( globalRect, &((**device).gdRect), &intersection ) )
- {
- /* Yup, so calculate the interection: */
- area = (long)(intersection.right - intersection.left) *
- (long)(intersection.bottom - intersection.top);
-
- /* Keep track of largest interection area found so far: */
- if (area > maxArea)
- {
- result = device;
- maxArea = area;
- }
-
- } /* if SectRect ... */
-
- device = GetNextDevice( device );
-
- } /* screenActive */
-
- } /* screenDevice */
-
- } /* while */
-
- } /* else: kLargestAreaScreen */
-
- if (result == nil)
- {
- /*
- ** We're literally OFF the screen, so effect a DeviceOption
- ** = "kLargestAreaScreen" based on the total Desktop region.
- ** Change the object's "gdOption" instance variable since
- ** we may have passed "kLargestAreaScreen":
- */
- desktop = GetGrayRgn();
- result = GetMaxDevice( &(**desktop).rgnBBox );
- if (result != nil) gdOption = kDeepestScreen;
- }
-
- return (result);
-
- } /* GetScreenDevice */
-
-
-
-
- /* end: "CColorBitMapPane.cp" */
-