home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-15 | 9.1 KB | 347 lines | [TEXT/CWIE] |
- // =================================================================================
- // CControlSite.cpp ©1996-97 Microsoft Corporation All rights reserved.
- // =================================================================================
- //
- // A site for a container control
-
- #include "ocheaders.h"
- #include "CControlContainer.h"
- #include "CControlSite.h"
-
- //======================================================================
- //
- // Public Methods
- //
-
- #pragma mark === CControlSite::Construction & Destruction ===
-
- // ---------------------------------------------------------------------------
- // • CControlSite::CControlSite
- // ---------------------------------------------------------------------------
- // Default Constructor
-
- CControlSite::CControlSite(void) : CXSite()
- {
- mContainerP = NULL;
- mLocation.h = 0;
- mLocation.v = 0;
- mDimensions.h = 0;
- mDimensions.v = 0;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CControlSite::CControlSite(CControlContainer*, Uint32, Uint32, Uint32, Uint32)
- // ---------------------------------------------------------------------------
- // Construct site at the location specified within the container.
-
- CControlSite::CControlSite(CControlContainer* inContainer, Uint32 inTop, Uint32 inLeft, Uint32 inHeight, Uint32 inWidth)
- : CXSite()
- {
- mContainerP = inContainer;
- mLocation.h = inLeft;
- mLocation.v = inTop;
- mDimensions.h = inWidth;
- mDimensions.v = inHeight;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CControlSite::~CControlSite
- // ---------------------------------------------------------------------------
- // Destructor
-
- CControlSite::~CControlSite()
- {
- }
-
-
- #pragma mark === CControlSite ===
-
- // ---------------------------------------------------------------------------
- // • CControlSite::Contains
- // ---------------------------------------------------------------------------
- // Is the control hit by the point?
-
- Boolean8 CControlSite::Contains (Point inWhere)
- {
- // If point falls within the bounding rectangle of the site, then it's a hit.
- if ((inWhere.h >= mLocation.h) &&
- (inWhere.h <= mLocation.h + mDimensions.h) &&
- (inWhere.v >= mLocation.v) &&
- (inWhere.v <= mLocation.v + mDimensions.v))
- return true;
- else
- return false;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CControlSite::EstablishContext
- // ---------------------------------------------------------------------------
- // Set up the drawing environment for the control
-
- ErrorCode CControlSite::EstablishContext(DrawContext* inContext, DrawContext* outContext)
- {
- ErrorCode theResult;
-
- if (!mHavePort)
- {
- Rect clipRect;
- RgnHandle inClipRgn, controlClipRgn, outClipRgn;
-
- // Save off the current port state
- SavePortState(inContext->Port);
- mHavePort = true;
-
- // Figure out the clip rect
- clipRect.top = inContext->Location.top;
- clipRect.left = inContext->Location.left;
- clipRect.bottom = clipRect.top + mDimensions.v;
- clipRect.right = clipRect.left + mDimensions.h;
-
- // Set up the context
- outContext->PortType = inContext->PortType;
- outContext->DrawAspect = inContext->DrawAspect;
- outContext->ContextID = inContext->ContextID;
- outContext->Port = inContext->Port;
- outContext->Location.left = clipRect.left;
- outContext->Location.right = clipRect.right;
- outContext->Location.top = clipRect.top;
- outContext->Location.bottom = clipRect.bottom;
- outContext->PrintRec = inContext->PrintRec;
- outContext->ContainerRef = inContext->ContainerRef;
-
- // Initialize the port to a known state
- ::SetOrigin(inContext->Port->portRect.left - mLocation.h,
- inContext->Port->portRect.top - mLocation.v);
-
- // Adjust the clip
- inClipRgn = ::NewRgn();
- ::GetClip(inClipRgn);
- ::OffsetRgn(inClipRgn, -(mLocation.h), -(mLocation.v));
- controlClipRgn = ::NewRgn();
- ::RectRgn(controlClipRgn, &clipRect);
- outClipRgn = ::NewRgn();
- ::SectRgn(inClipRgn, controlClipRgn, outClipRgn);
- ::SetClip(outClipRgn);
-
- // Dispose of temporary data structures
- ::DisposeRgn(outClipRgn);
- outClipRgn = NULL;
- ::DisposeRgn(controlClipRgn);
- controlClipRgn = NULL;
- ::DisposeRgn(inClipRgn);
- inClipRgn = NULL;
-
- theResult = S_OK;
- }
- else
- theResult = E_FAIL;
-
- return theResult;
- }
-
-
- //----------------------------------------------------------------------
- //
- // IContainerSite Methods
- //
-
- #pragma mark === CControlSite::IContainerSite ===
-
- // ---------------------------------------------------------------------------
- // • CControlSite::IContainerSite::RequestFocus
- // ---------------------------------------------------------------------------
- // Pass request to container
-
- STDMETHODIMP
- CControlSite::RequestFocus ( Boolean inAcquire, FocusSet inFocus)
- {
- ErrorCode theResult;
-
- if (mContainerP)
- theResult = mContainerP->RequestFocus(this, inAcquire, inFocus);
- else
- theResult = E_FAIL;
-
- return theResult;
- }
-
- // ---------------------------------------------------------------------------
- // • CControlSite::IContainerSite::AcquireContext
- // ---------------------------------------------------------------------------
- // Set up drawing environment for control within context of container's environment.
-
- STDMETHODIMP
- CControlSite::AcquireContext(Uint32 inContextID, DrawContext* outContext)
- {
- ErrorCode theResult = S_OK;
- IContainerSite* siteP;
-
- if (!mHavePort &&
- mUnkOuter &&
- SUCCEEDED(mUnkOuter->QueryInterface(IID_IContainerSite, &siteP)))
- {
- if (siteP->AcquireContext(inContextID, &mContext) == S_OK)
- {
- theResult = EstablishContext(&mContext, outContext);
- }
- else
- {
- outContext->Port = NULL;
- theResult = E_FAIL;
- }
-
- siteP->Release();
- }
- else
- {
- outContext->Port = NULL;
- theResult = E_FAIL;
- }
-
- return theResult;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CControlSite::IContainerSite::ReleaseContext
- // ---------------------------------------------------------------------------
- // Restore the drawing environment and release our container's context
-
- STDMETHODIMP
- CControlSite::ReleaseContext(DrawContext* inContext)
- {
- ErrorCode theResult;
- IContainerSite* siteP;
-
- theResult = inherited::ReleaseContext(inContext);
- if ( theResult == S_OK)
- {
- if (SUCCEEDED(mUnkOuter->QueryInterface(IID_IContainerSite, &siteP)))
- {
- theResult = siteP->ReleaseContext(&mContext);
- siteP->Release();
- }
- }
-
- return theResult;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CControlSite::IContainerSite::SetIdleTime
- // ---------------------------------------------------------------------------
- // schedule some idle time for the control
-
- STDMETHODIMP
- CControlSite::SetIdleTime(Int32 inWaitTicks, Uint32 inIdleRefCon)
- {
- ErrorCode theResult;
-
- if (mContainerP)
- theResult = mContainerP->SetIdleTime(this, inWaitTicks, inIdleRefCon);
- else
- theResult = E_FAIL;
-
- return theResult;
- }
-
-
- //----------------------------------------------------------------------
- //
- // IControl Methods
- //
-
- #pragma mark === CControlSite::IControl ===
-
- // ---------------------------------------------------------------------------
- // • CControlSite::IControl::Draw
- // ---------------------------------------------------------------------------
- // Set up the control's drawing environment and tell it to draw
-
- STDMETHODIMP
- CControlSite::Draw(DrawContext* inContext)
- {
- ErrorCode theResult = S_OK;
-
- if ( mControlP )
- {
- DrawContext outContext = {BeginPortType};
-
- if (EstablishContext(inContext, &outContext) == S_OK)
- {
- theResult = mControlP->Draw(&outContext);
- inherited::ReleaseContext(&outContext);
- }
- else
- {
- theResult = E_FAIL;
- }
- }
- else
- mCachedDraw = true;
-
- return theResult;
- }
-
- // ---------------------------------------------------------------------------
- // • CControlSite::IControl::OnContextChange
- // ---------------------------------------------------------------------------
- // Set up the control's drawing environment and pass on the context change command
-
- STDMETHODIMP
- CControlSite::OnContextChange(UInt32 inContextID, ContextCommand inCommand)
- {
- ErrorCode theResult = S_OK;
-
- if ( mControlP )
- {
- DrawContext outContext = {BeginPortType};
-
- //if (EstablishContext(inContext, &outContext) == S_OK)
- {
- theResult = mControlP->OnContextChange(inContextID, inCommand);
- //inherited::ReleaseContext(&outContext);
- }
- //else
- //{
- // theResult = E_FAIL;
- //}
- }
- else
- mCachedContextChange = true;
-
- return theResult;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CControlSite::IControl::DoActivate
- // ---------------------------------------------------------------------------
- // Set up the control's drawing environment and pass on the activate command
-
- STDMETHODIMP
- CControlSite::DoActivate(ActivateEventType inActiveET, UInt32 inContextID, PlatformEvent* inEvent)
- {
- ErrorCode theResult = S_OK;
-
- if ( mControlP )
- {
- DrawContext outContext = {BeginPortType};
-
- //if (EstablishContext(inContext, &outContext) == S_OK)
- {
- theResult = mControlP->DoActivate(inActiveET, inContextID, inEvent);
- //inherited::ReleaseContext(&outContext);
- }
- //else
- //{
- // theResult = E_FAIL;
- //}
- }
-
- return theResult;
- }
-