home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-20 | 4.3 KB | 192 lines | [TEXT/CWIE] |
- //
- // CAppSite.cpp
- //
- // Copyright (C) Microsoft Corporation, 1996
- //
-
- #include "headers.h"
- #include "CSimpleAppSite.h"
- #include "CActiveXScheduler.h"
- #include "App.h"
-
- //
- // CSimpleAppSite::CBaseSite::AcquireContext
- //
-
- STDMETHODIMP
- CSimpleAppSite::AcquireContext(Uint32 inContextID, DrawContext* outContext)
- {
- AppData* AppDataPtr = (AppData*) mContainerData;
- ErrorCode Result = S_OK;
- Rect ClipRect;
-
- // Don't allow the object to nest calls to AcquireContext.
- if ( !mHavePort )
- {
- // Set up the context
- switch (inContextID)
- {
- case WindowContextID:
- // Save off the current port state
- if (AppDataPtr->Window)
- {
- SavePortState((GrafPtr) AppDataPtr->Window);
- outContext->Port = AppDataPtr->Window;
- outContext->PortType = QDWindowPortType;
- }
- else
- Result = E_FAIL;
- break;
- #ifdef USE_OFFSCREEN
- case OffscreenContextID:
- if (AppDataPtr->Offscreen)
- {
- ::GetPort(&mSavePort);
- ::SetGWorld(AppDataPtr->Offscreen, NULL);
- mOldPortState.PortRect = AppDataPtr->Offscreen->portRect;
- mOldPortState.ClipRgn = NewRgn();
- ::GetClip(mOldPortState.ClipRgn);
-
- // Save off the pen state
- ::GetPenState(&mOldPortState.PenState);
- mOldPortState.TextFont = AppDataPtr->Offscreen->txFont;
- mOldPortState.TextMode = AppDataPtr->Offscreen->txMode;
- mOldPortState.TextSize = AppDataPtr->Offscreen->txSize;
- mOldPortState.TextFace = AppDataPtr->Offscreen->txFace;
- ::GetForeColor(&mOldPortState.ForeColor);
- ::GetBackColor(&mOldPortState.BackColor);
- outContext->Port = (GrafPtr) AppDataPtr->Offscreen;
- outContext->PortType = QDOffscreenPortType;
- }
- else
- Result = E_FAIL;
- break;
- #endif // USE_OFFSCREEN
- default:
- Result = E_FAIL;
- break;
- }
- }
- else
- Result = E_FAIL;
-
- if (Result == S_OK)
- {
- outContext->ContextID = inContextID; // okay, since we allow only one context above
- outContext->ContainerRef = 0; // we don't use this
- outContext->DrawAspect = DVASPECT_CONTENT;
-
- // Location of the control
- outContext->Location.left = 0;
- outContext->Location.right = gControlRect.right - gControlRect.left;
- outContext->Location.top = 0;
- outContext->Location.bottom = gControlRect.bottom - gControlRect.top;
-
- ::SetRect(&ClipRect, 0, 0, outContext->Location.right, outContext->Location.bottom);
-
- // Initialize the port to a known state
- ::SetOrigin(-(gControlRect.left), -(gControlRect.top));
- ::ClipRect(&ClipRect);
-
- mHavePort = true;
- }
- else
- outContext->Port = NULL;
-
- return Result;
- }
-
-
- //
- // CSimpleAppSite::CBaseSite::OnChange
- //
- // how controls tell us that they changed something
- //
-
- STDMETHODIMP
- CSimpleAppSite::OnChange(ChangeType inChangeType)
- {
- CXSite::OnChange(inChangeType);
- #ifdef USE_OFFSCREEN
- if (inChangeType == ViewChange)
- {
- Rect DestRect = { 0, 300, 290, 496};
-
- // blit to the screen
- ::ForeColor(blackColor);
- ::BackColor(whiteColor);
- CopyBits((BitMap*)(*(gAppData.Offscreen->portPixMap)),
- &((GrafPtr)gAppData.Window)->portBits, &gControlRect, &DestRect, srcCopy, NULL);
- }
- #endif // USE_OFFSCREEN
- return S_OK;
- }
-
-
- //
- // CSimpleAppSite::CBaseSite::RequestSizeChange
- //
- // how to change the controls size
- //
-
- STDMETHODIMP
- CSimpleAppSite::RequestSizeChange ( Point* ioSize )
- {
- ErrorCode Result = S_OK;
- GrafPtr StartPort;
- Point BeginSize;
- Point MaxSize;
-
- BeginSize.h = gControlRect.right - gControlRect.left;
- BeginSize.v = gControlRect.bottom - gControlRect.top;
-
- MaxSize.h = gAppData.Window->portRect.right - gControlRect.left - 10;
- MaxSize.v = gAppData.Window->portRect.bottom - gControlRect.top - 10;
-
- if (ioSize->v > MaxSize.v)
- {
- ioSize->v = MaxSize.v;
- Result = S_FALSE;
- }
-
- if (ioSize->h > MaxSize.h)
- {
- ioSize->h = MaxSize.h;
- Result = S_FALSE;
- }
-
- gControlRect.bottom = gControlRect.top + ioSize->v;
- gControlRect.right = gControlRect.left + ioSize->h;
-
- ::GetPort(&StartPort);
- ::SetPort(gAppData.Window);
- ::InvalRect(&gAppData.Window->portRect);
- ::SetPort(StartPort);
-
- return Result;
- }
-
-
- //
- // CSimpleAppSite::GetContextID
- //
-
- Boolean8
- CSimpleAppSite::GetContextID(Int32 inContextIndex, UInt32* outContextID)
- {
- // Since we only support 1 context, and we use the index (1)
- // to map to that context, we can just use the AcquireContextByIndex method
- if ( inContextIndex <= 1 )
- {
- *outContextID = 1;
- return true;
- }
- else
- {
- *outContextID = InvalidContextID;
- return false;
- }
- }
-
-
-