home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-17 | 25.7 KB | 891 lines | [TEXT/CWIE] |
- // =================================================================================
- //
- // CTextEditControl.cpp ©1996 Microsoft Corporation All rights reserved.
- //
- // =================================================================================
-
- #include <LArray.h>
- #include "ocheaders.h"
- #include <PlatformControlGuid.h>
- #include "CTextEditControl.h"
- #include "CTextEditBSC.h"
-
- const Int32 TEIdleTickCount = 5;
- const Uint32 TEIdleRefCon = 0;
- const Int32 QueryTickCount = 60;
- const Uint32 QueryRefCon = 1;
-
- #pragma mark === CTextEditControl Construction & Destruction ===
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::CTextEditControl
- //=--------------------------------------------------------------------------=
-
- CTextEditControl::CTextEditControl(void) : CBaseControl()
- {
- mOwnedFoci = EmptyFocusSet;
-
- mScrollBarInfo.ConnectionPoint = NULL;
- mPostButtonInfo.ConnectionPoint = NULL;
- mScrollBarInfo.Unknown = NULL;
- mPostButtonInfo.Unknown = NULL;
- *(mScrollBarInfo.Name) = 0;
- *(mPostButtonInfo.Name) = 0;
-
- *mID = 0;
- mNewText = NULL;
- mScrollLines = 0;
- mOldScrollPosition = 0;
-
- mFont = 1;
- mSize = 10;
- mFace = 0;
- }
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::~CTextEditControl
- //=--------------------------------------------------------------------------=
-
- CTextEditControl::~CTextEditControl()
- {
- ReleaseAllPlatformControls();
- }
-
-
- #pragma mark === CButtonControl::IUnknown methods ===
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::IUnknown::QueryInterface::
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CTextEditControl::QueryInterface(REFIID inRefID, void** outObj)
- {
- if ( inRefID == IID_IPlatformControlListener )
- {
- *outObj = (void*) (IPlatformControlListener*) this;
- AddRef();
-
- return S_OK;
- }
- else
- return CBaseControl::QueryInterface(inRefID, outObj);
- }
-
-
- #pragma mark === CTextEditControl::IControl ===
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::IControl::Draw
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CTextEditControl::Draw( DrawContext* inContext)
- {
- CTextEditContextInfo* TEInfo;
- Rect drawRect;
-
- if (inContext->DrawAspect != DVASPECT_CONTENT)
- return DV_E_DVASPECT;
-
- drawRect = inContext->Location;
-
- // Erase and frame the drawing area
- ::EraseRect(&drawRect);
- ::FrameRect(&drawRect);
- ::InsetRect(&drawRect, 2, 2);
-
- if ((TEInfo = (CTextEditContextInfo*)GetContextInfoByID(inContext->ContextID)) != NULL)
- ::TEUpdate(&drawRect, TEInfo->GetTEHandle());
- #if BE_STRICT
- else
- DebugStr("\pTextEditControl draw - can't get context info!");
- #endif // BE_STRICT
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::IControl::Draw
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CTextEditControl::OnContextChange(UInt32 inContextID, ContextCommand inCommand)
- {
- ErrorCode Result;
- Int32 InCount = mContextInfo->GetCount();
- Int32 OutCount;
-
- Result = CBaseControl::OnContextChange(inContextID, inCommand);
-
- OutCount = mContextInfo->GetCount();
-
- // changing from no to some draw contexts is a good time to re-attach controls
- if (!InCount && OutCount)
- BeginAttachPlatformControls();
- // and going from some to no draw contexts is a good time to release
- else if (InCount && !OutCount)
- ReleaseAllPlatformControls();
-
- return Result;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::IControl::GetID
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CTextEditControl::GetID(Int32 inBufferSize, Char8* outID)
- {
- if (*mID)
- {
- if (*mID < inBufferSize)
- inBufferSize = *mID;
- ::BlockMove(mID + 1, outID, inBufferSize);
- *(outID + inBufferSize) = 0;
- }
- else
- return CBaseControl::GetID(inBufferSize, outID);
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::IControl::DoMouse
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CTextEditControl::DoMouse(MouseEventType inMouseET, PlatformEvent* inEvent)
- {
- Boolean8 NewlyFocused = false;
- ErrorCode ReturnValue = S_OK;
-
- if (inMouseET == MouseDown)
- {
- // if we don't have the keyboard focus then attempt to gain it
- if (!(mOwnedFoci & KeyboardFocus) && (mContainerSiteP->RequestFocus(true, KeyboardFocus) == S_OK))
- {
- mOwnedFoci = FocusSet(mOwnedFoci | KeyboardFocus);
- NewlyFocused = true;
- }
-
- // if we have the keyboard focus then process the click
- if (mOwnedFoci & KeyboardFocus)
- {
- DrawContext Context = { BeginPortType };
-
- if (mContainerSiteP->AcquireContext(mActiveContext->GetContextID(), &Context) == S_OK)
- {
- if (NewlyFocused)
- mActiveContext->Activate(true);
-
- {
- CTextEditContextInfo* OtherContextInfo;
- Int16 Index = 1;
- Point localPt;
- TEHandle ActiveTEH = ((CTextEditContextInfo*)mActiveContext)->GetTEHandle();
-
- // pass the click to the active TEHandle
- localPt = inEvent->where;
- ::GlobalToLocal(&localPt);
- ::TEClick(localPt, (inEvent->modifiers & shiftKey) , ActiveTEH);
- mStartSelection = (*ActiveTEH)->selStart;
- mEndSelection = (*ActiveTEH)->selEnd;
-
- // pass the click to the other TEHandles
- mContainerSiteP->ReleaseContext(&Context);
- while ( (OtherContextInfo = (CTextEditContextInfo*)GetContextInfoByIndex(Index++)) != NULL )
- {
- if (OtherContextInfo != mActiveContext)
- {
- Uint32 ContextID = OtherContextInfo->GetContextID();
- if ( mContainerSiteP->AcquireContext(ContextID, &Context) )
- {
- ::TESetSelect(mStartSelection, mEndSelection, OtherContextInfo->GetTEHandle());
- mContainerSiteP->ReleaseContext(&Context);
- }
- }
- }
- }
- mContainerSiteP->ReleaseContext(&Context);
- }
- #if BE_STRICT
- else DebugStr("\pTextEditControl mouseDown - couldn't acquire default context!");
- #endif // BE_STRICT
- }
- }
-
- return ReturnValue;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::IControl::DoKeyEvent
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CTextEditControl::DoKey(KeyEventType inKeyET, Char8 inChar, PlatformEvent* inEvent)
- {
- ErrorCode ReturnValue = S_FALSE;
-
- if ((inKeyET == KeyDown) || (inKeyET == AutoKey))
- {
- // If we have the keyboard focus and an active context then do the key
- if (mOwnedFoci & KeyboardFocus && mActiveContext)
- {
- Boolean8 CursorKey = false;
- Boolean8 ExtendSelection = false;
- DrawContext Context = { BeginPortType };
- Int16 StartSelection;
- Int16 EndSelection;
- Uint32 ActiveContextID = mActiveContext->GetContextID();
-
- // figure out if we have anything special here
- CursorKey = inChar == 0x1c || inChar == 0x1d || inChar == 0x1e || inChar == 0x1f;
- if (CursorKey)
- ExtendSelection = (inEvent->modifiers & 0x0200) != 0;
-
- if (mContainerSiteP->AcquireContext(ActiveContextID, &Context) == S_OK)
- {
- // pass the key to the active draw context
- TEHandle ActiveTEH = ((CTextEditContextInfo*)mActiveContext)->GetTEHandle();
-
- // save off the starting selection
- StartSelection = (*ActiveTEH)->selStart;
- EndSelection = (*ActiveTEH)->selEnd;
- // allow text edit to process the character
- ::TEKey(inChar, ActiveTEH);
- // note the ending selection
- mStartSelection = (*ActiveTEH)->selStart;
- mEndSelection = (*ActiveTEH)->selEnd;
- // if we have an shift-cursor key then make the selection extend
- if (ExtendSelection)
- {
- if (StartSelection < mStartSelection)
- mStartSelection = StartSelection;
- if (EndSelection > mEndSelection)
- mEndSelection = EndSelection;
- ::TESetSelect(mStartSelection, mEndSelection, ActiveTEH);
- }
- ReturnValue = S_OK;
-
- // pass the key to the other draw contexts
- {
- CTextEditContextInfo* OtherContext;
- Int16 i = 1;
-
- mContainerSiteP->ReleaseContext(&Context);
-
- while ((OtherContext = ((CTextEditContextInfo*)GetContextInfoByIndex(i++))) != NULL)
- {
- if (OtherContext != mActiveContext)
- {
- if (mContainerSiteP->AcquireContext(OtherContext->GetContextID(), &Context) == S_OK)
- {
- TEHandle TextH = OtherContext->GetTEHandle();
-
- // don't pass cursor keys through as it causes a static i-beam to display
- if (!CursorKey)
- {
- ::TESetSelect(StartSelection, EndSelection, TextH);
- ::TEKey(inEvent->message & charCodeMask, TextH);
- }
- ::TESetSelect(mStartSelection, mEndSelection, TextH);
- mContainerSiteP->ReleaseContext(&Context);
- }
- }
- }
- }
- }
- #if BE_STRICT
- else DebugStr("\pTextEditControl couldn't acquire active draw context.");
- #endif // BE_STRICT
- }
- #if BE_STRICT
- else DebugStr("\pTextEditControl getting key events without the keyboard focus or active context.");
- #endif // BE_STRICT
- }
-
- return ReturnValue;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::IControl::DoIdle
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CTextEditControl::DoIdle(Uint32 IdleRefCon)
- {
- ErrorCode ReturnValue = S_OK;
-
- if (IdleRefCon == TEIdleRefCon)
- {
- // If we have the focus and an active TEHandle, blink the caret
- if ( mOwnedFoci & KeyboardFocus)
- {
- if (mActiveContext)
- {
- DrawContext Context = {BeginPortType};
- if (mContainerSiteP->AcquireContext(mActiveContext->GetContextID(), &Context) == S_OK)
- {
- ::TEIdle(((CTextEditContextInfo*)mActiveContext)->GetTEHandle());
- ReturnValue = S_OK;
- mContainerSiteP->ReleaseContext(&Context);
- }
- #if BE_STRICT
- else DebugStr("\pTextEditControl couldn't acquire draw context for idle.");
- #endif // BE_STRICT
- }
- #if BE_STRICT
- else DebugStr("\pTextEditControl has idle, keyboard foci, but no active TEHandle.");
- #endif // BE_STRICT
- }
- #if BE_STRICT
- else DebugStr("\pTextEditControl is being idled when it shouldn't be.");
- #endif // BE_STRICT
- }
- // until we find all of our controls, keep polling
- else if (IdleRefCon == QueryRefCon)
- {
- if (!mScrollBarInfo.Unknown && *(mScrollBarInfo.Name))
- AttachPlatformControl(&mScrollBarInfo);
-
- if (!mPostButtonInfo.Unknown && *(mPostButtonInfo.Name))
- AttachPlatformControl(&mPostButtonInfo);
-
- if ((mScrollBarInfo.Unknown || !*(mScrollBarInfo.Name)) &&
- (mPostButtonInfo.Unknown || !*(mPostButtonInfo.Name)))
- mContainerSiteP->SetIdleTime(RemoveIdler, QueryRefCon);
- }
- #if BE_STRICT
- else
- DebugStr("\pTextEditControl got unrecognized IdleRefCon.");
- #endif
-
-
- return ReturnValue;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::IControl::SetFocus
- //=--------------------------------------------------------------------------=
- STDMETHODIMP
- CTextEditControl::SetFocus(FocusCommand inCommand, FocusSet inFocus)
- {
- DrawContext Context = {BeginPortType};
- ErrorCode ReturnValue = S_OK;
- FocusSet InOwnedFoci = mOwnedFoci;
-
- // a TakeNext or TakePrev if we don't have the focus, means take it
- if ((inCommand == TakeNextCommand || inCommand == TakePrevCommand) && !mOwnedFoci)
- {
- // if the container is offering us the one focus we want, take all of them
- if (inFocus & KeyboardFocus)
- mOwnedFoci = inFocus;
- else
- // otherwise, say no thanks
- ReturnValue = E_FAIL;
- }
- // a TakeNext or a TakePrev on a control which doesn't embed and has the focus should fail
- else if (inCommand == TakeNextCommand || inCommand == TakePrevCommand)
- {
- ReturnValue = E_FAIL;
- }
- // we're being asked/told to release our foci - always comply
- else // if (Spec == ReleaseRequest || Spec == ReleaseCommand)
- {
- #if BE_STRICT
- if (inFocus & mOwnedFoci != inFocus)
- DebugStr("\pWhat are you doing asking to release foci TextEditControl doesn't have?");
- #endif // BE_STRICT
- mOwnedFoci = FocusSet(mOwnedFoci & ~inFocus); // really easy for us
- }
-
-
- // if we gained the foci and we have an active context, then activate the TEHandle
- if ((mOwnedFoci & KeyboardFocus) && !(InOwnedFoci & KeyboardFocus) && mActiveContext)
- {
- if (mContainerSiteP->AcquireContext(mActiveContext->GetContextID(), &Context) == S_OK)
- {
- ::TEActivate(((CTextEditContextInfo*)mActiveContext)->GetTEHandle());
- ::InvalRect(&Context.Location);
- mContainerSiteP->ReleaseContext(&Context);
- }
- mContainerSiteP->SetIdleTime(TEIdleTickCount, TEIdleRefCon);
- }
- // else if we have an active TEHandle and we lost the keyboard focus, then deactivate the TEHandle
- else if (mActiveContext && (InOwnedFoci & KeyboardFocus) && !(mOwnedFoci & KeyboardFocus))
- {
- if (mContainerSiteP->AcquireContext(mActiveContext->GetContextID(), &Context) == S_OK)
- {
- ::TEDeactivate(((CTextEditContextInfo*)mActiveContext)->GetTEHandle());
- ::InvalRect(&Context.Location);
- mContainerSiteP->ReleaseContext(&Context);
- }
- mContainerSiteP->SetIdleTime(RemoveIdler, TEIdleRefCon);
- }
-
- return ReturnValue;
- }
-
-
- #pragma mark === CButtonControl::IPersistPropertyBag methods ===
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::IPersistPropertyBag::Load
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CTextEditControl::Load(IPropertyBag* PropertyBag, IErrorLog* ErrorLog)
- {
- VARIANT v;
-
- v.vt = VT_BSTR;
- v.bstrVal = NULL;
-
- ReleaseAllPlatformControls(); // a LoadTextState completely resets the controls attached
-
- CBaseControl::Load(PropertyBag, ErrorLog);
-
- if (PropertyBag->Read("start", &v, ErrorLog) == S_OK && v.bstrVal)
- {
- Int16 TextLen = *((Uint32*) v.bstrVal);
-
- mNewText = ::NewHandle(TextLen);
- ::HLock(mNewText);
- ::BlockMove(v.bstrVal + sizeof(Uint32), *mNewText, TextLen);
- ::HUnlock(mNewText);
- TouchAllContexts(TextControlProperty);
- }
-
- if (PropertyBag->Read("postcontrol", &v, ErrorLog) == S_OK && v.bstrVal)
- {
- Int16 NameLen = *((Uint32*) v.bstrVal);
-
- if (NameLen > 255)
- NameLen = 255;
- ::BlockMove(v.bstrVal + sizeof(Uint32), mPostButtonInfo.Name + 1, NameLen);
- *(mPostButtonInfo.Name) = NameLen;
- CoTaskMemFree(v.bstrVal);
- }
-
- if (PropertyBag->Read("scrollcontrol", &v, ErrorLog) == S_OK && v.bstrVal)
- {
- Int16 NameLen = *((Uint32*) v.bstrVal);
-
- if (NameLen > 255)
- NameLen = 255;
- ::BlockMove(v.bstrVal + sizeof(Uint32), mScrollBarInfo.Name + 1, NameLen);
- *(mScrollBarInfo.Name) = NameLen;
- CoTaskMemFree(v.bstrVal);
- }
-
- BeginAttachPlatformControls();
-
- return S_OK;
- }
-
-
- #pragma mark === CTextEditContextInfo::IPlatformControlListener ===
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::IPlatformControlListener::OnControlValueChange
- //=--------------------------------------------------------------------------=
-
- STDMETHODIMP
- CTextEditControl::OnControlValueChange(IUnknown* inSource, Int32 ControlValue)
- {
- Handle TextData = NULL;
- OSErr Error;
-
- if (inSource == mScrollBarInfo.Unknown)
- {
- mScrollLines = ControlValue - mOldScrollPosition;
- mOldScrollPosition = ControlValue;
-
- TouchAllContexts(ScrollControlProperty);
- }
- else if (inSource == mPostButtonInfo.Unknown)
- {
- TEHandle ActiveTEH = ((CTextEditContextInfo*)mActiveContext)->GetTEHandle();
-
- TextData = ::TEGetText(ActiveTEH);
- Error = ::HandToHand(&TextData);
- if(!Error)
- {
- if(!mPostStream)
- mPostStream = new CTextEditBSC();
-
- mPostStream->OpenPostStream(mContainerSiteP, (char*)mPostUrl, TextData);
- }
- }
-
- return S_OK;
- }
-
- #pragma mark === CTextEditContextInfo::CBaseControl ===
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::CBaseControl::NewContext
- //=--------------------------------------------------------------------------=
-
- CBaseContextInfo*
- CTextEditControl::NewContext(Uint32 inContextID)
- {
- CTextEditContextInfo* ContextInfo = new CTextEditContextInfo(this, inContextID);
-
- if (ContextInfo)
- {
- if (!ContextInfo->GetTEHandle())
- {
- delete ContextInfo;
- ContextInfo = NULL;
- }
- }
-
- return ContextInfo;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::TouchAllContexts
- //=--------------------------------------------------------------------------=
-
- void
- CTextEditControl::TouchAllContexts(ControlPropertyType PropertyType)
- {
- Boolean8 UsedTheText = false;
- CTextEditContextInfo* ContextInfo;
- Int16 Index = 1;
-
- while ((ContextInfo = (CTextEditContextInfo*)GetContextInfoByIndex(Index++)) != NULL)
- {
- DrawContext Context = { BeginPortType };
-
- if (mContainerSiteP->AcquireContext(ContextInfo->GetContextID(), &Context) == S_OK)
- {
- TEHandle TEH = ContextInfo->GetTEHandle();
-
- if (PropertyType & TextControlProperty && mNewText)
- {
- ::HLock(mNewText);
- ::TESetText(*mNewText, ::GetHandleSize(mNewText), TEH);
- ::HUnlock(mNewText);
- UsedTheText = true;
- }
-
- if (PropertyType & ScrollControlProperty)
- ::TEScroll(0, (*TEH)->lineHeight * mScrollLines, TEH);
-
- // don't do SelectionControlProperty here - can't see where it would be useful
-
- mContainerSiteP->ReleaseContext(&Context);
- }
- }
-
- if (UsedTheText && mNewText)
- {
- ::DisposeHandle(mNewText);
- mNewText = NULL;
- }
-
- mScrollLines = 0;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::BeginAttachPlatformControls
- //=--------------------------------------------------------------------------=
-
- void
- CTextEditControl::BeginAttachPlatformControls(void)
- {
- Boolean8 SetIdle = false;
-
- if (*mScrollBarInfo.Name && !mScrollBarInfo.Unknown)
- SetIdle = true;
-
- if (*mPostButtonInfo.Name && !mPostButtonInfo.Unknown)
- SetIdle = true;
-
- if (SetIdle)
- mContainerSiteP->SetIdleTime(QueryTickCount, QueryRefCon);
- }
-
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::ReleaseAllPlatformControls
- //=--------------------------------------------------------------------------=
-
- void
- CTextEditControl::ReleaseAllPlatformControls(void)
- {
- ReleasePlatformControl(&mScrollBarInfo);
- ReleasePlatformControl(&mPostButtonInfo);
- }
-
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::AttachPlatformControl
- //=--------------------------------------------------------------------------=
-
- void
- CTextEditControl::AttachPlatformControl(PlatformControlInfo* inControlInfo)
- {
- Boolean8 Found = false;
-
- // look for someone who supports IID_IPlatformControl and has the desired name
- if (mContainerSiteP)
- {
- // if we don't have a container then get one
- if (!mContainerP)
- {
- mContainerSiteP->GetContainer(&mContainerP);
- mContainerP->AddRef();
- }
-
- // if we have a container continue
- if (mContainerP)
- {
- IEnumUnknown* UnknownEnum;
-
- // get an enumerator of other embedded controls
- if (mContainerP->EnumControls(NULL, OLECONTF_EMBEDDINGS, &UnknownEnum) == S_OK)
- {
- IUnknown* UnknownP = NULL;
-
- // while we have more controls to check
- while (UnknownEnum->Next(1, &UnknownP, NULL) == S_OK && !Found)
- {
- IConnectionPointContainer* ConPointContainer = NULL;
- UnknownP->QueryInterface(IID_IConnectionPointContainer, &ConPointContainer);
-
- // if the control has a connection point container then see if it has our interface
- if (ConPointContainer)
- {
- IConnectionPoint* ConPoint = NULL;
- ConPointContainer->FindConnectionPoint(IID_IPlatformControlListener, &ConPoint);
-
- // the control has our interface, see if it has the right name
- if (ConPoint)
- {
- IControl* ControlP = NULL;
- UnknownP->QueryInterface(IID_IControl, &ControlP);
- if (ControlP)
- {
- Str255 ControlName;
- if (ControlP->GetID(sizeof(ControlName)-1, (Char8*)ControlName+1) == S_OK)
- {
- *ControlName = strlen((Char8*)ControlName+1);
- if (::EqualString(inControlInfo->Name, ControlName, false, true))
- {
- IPlatformControl* PlatformControlP = NULL;
- UnknownP->QueryInterface(IID_IPlatformControl, &PlatformControlP);
- if (PlatformControlP)
- {
- Found = true;
- ConPoint->Advise((IControl*) this, &inControlInfo->Cookie);
- inControlInfo->ConnectionPoint = ConPoint;
- inControlInfo->ConnectionPoint->AddRef();
- inControlInfo->Unknown = UnknownP;
- inControlInfo->Unknown->AddRef();
- PlatformControlP->Release();
- }
- }
- }
-
- ControlP->Release();
- }
-
- ConPoint->Release();
- }
-
- ConPointContainer->Release();
- }
-
- UnknownP->Release(); // Next does an AddRef()
- }
- UnknownEnum->Release();
- }
- }
- }
- }
-
-
- //=--------------------------------------------------------------------------=
- // CTextEditControl::ReleasePlatformControl
- //=--------------------------------------------------------------------------=
-
- void
- CTextEditControl::ReleasePlatformControl(PlatformControlInfo* inPCInfo)
- {
- if (inPCInfo->Unknown)
- {
- inPCInfo->ConnectionPoint->Unadvise(inPCInfo->Cookie);
- inPCInfo->ConnectionPoint->Release();
- inPCInfo->ConnectionPoint = NULL;
- inPCInfo->Unknown->Release();
- inPCInfo->Unknown = NULL;
- inPCInfo->Cookie = 0;
- }
- }
-
-
- #pragma mark === CTextEditContextInfo Constructor & Destructor ===
-
- //=--------------------------------------------------------------------------=
- // CTextEditContextInfo::CTextEditContextInfo
- //=--------------------------------------------------------------------------=
- CTextEditContextInfo::CTextEditContextInfo(CTextEditControl* inControlP, Uint32 inContextID) :
- CBaseContextInfo (inControlP, inContextID)
- {
- CTextEditControl* TEControlP = (CTextEditControl*) mControlP;
- DrawContext Context = {BeginPortType};
-
- mTextEditH = NULL;
-
- if (TEControlP->mContainerSiteP->AcquireContext(inContextID, &Context) == S_OK)
- {
- Rect ViewRect, DestRect;
-
- ViewRect = DestRect = Context.Location;
- ::InsetRect(&DestRect, 2, 2);
- ::InsetRect(&ViewRect, 2, 2);
- ::TextFace(TEControlP->mFace);
- ::TextFont(TEControlP->mFont);
- ::TextSize(TEControlP->mSize);
- if ((mTextEditH = ::TENew(&DestRect, &ViewRect)) != NULL)
- {
- CTextEditContextInfo* AnyOtherContext = (CTextEditContextInfo*)(TEControlP->GetContextInfoByIndex(1));
- Handle StartText = TEControlP->mNewText;
-
- // if there there is start text and no other contexts then install the start text
- if (StartText)
- {
- if (!AnyOtherContext)
- {
- ::HLock(StartText);
- ::TESetText(*StartText, ::GetHandleSize(StartText), mTextEditH);
- ::HUnlock(StartText);
- }
- ::DisposeHandle(StartText);
- TEControlP->mNewText = NULL;
- }
- // if there are already non-empty TERecs, then duplicate the text, sel state, etc
- if ((AnyOtherContext ) != NULL)
- {
- TEHandle TextHOrig = AnyOtherContext->GetTEHandle();
- CharsHandle CharsH = ::TEGetText(TextHOrig);
- if (CharsH)
- {
- ::HLock(CharsH);
- ::TESetText(*CharsH, (*TextHOrig)->teLength, mTextEditH);
- ::HUnlock(CharsH);
- }
- else
- {
- ::TEDispose(mTextEditH);
- mTextEditH = NULL;
- }
- }
- }
-
- TEControlP->mContainerSiteP->ReleaseContext(&Context);
- }
- }
-
-
- //=--------------------------------------------------------------------------=
- // CTextEditContextInfo::~CTextEditContextInfo
- //=--------------------------------------------------------------------------=
- CTextEditContextInfo::~CTextEditContextInfo(void)
- {
- if (mTextEditH)
- {
- CTextEditControl* TEControlP = (CTextEditControl*) mControlP;
- DrawContext Context = {BeginPortType};
-
- if ((this == TEControlP->mActiveContext) && (TEControlP->mOwnedFoci & KeyboardFocus) &&
- (TEControlP->mContainerSiteP->AcquireContext(mContextID, &Context) == S_OK))
- {
- ::TEDeactivate(mTextEditH);
- TEControlP->mContainerSiteP->SetIdleTime(RemoveIdler, TEIdleRefCon);
- TEControlP->mContainerSiteP->ReleaseContext(&Context);
- }
- ::TEDispose(mTextEditH);
- mTextEditH = NULL;
- }
- }
-
-
- #pragma mark === CTextEditContextInfo::CBaseContextInfo ===
-
- //=--------------------------------------------------------------------------=
- // CTextEditContextInfo::Update
- //=--------------------------------------------------------------------------=
- ErrorCode
- CTextEditContextInfo::Update(Boolean8 Acquired)
- {
- #pragma unused (Acquired)
- // do whatever updating we want to do
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CTextEditContextInfo::Activate
- //=--------------------------------------------------------------------------=
- ErrorCode
- CTextEditContextInfo::Activate(Boolean8 Acquired)
- {
- CTextEditControl* TEControlP = (CTextEditControl*) mControlP;
-
- if (TEControlP->mOwnedFoci & KeyboardFocus)
- {
- DrawContext Context = { BeginPortType };
-
- if (Acquired || TEControlP->mContainerSiteP->AcquireContext(mContextID, &Context) == S_OK)
- {
- ::TESetSelect(TEControlP->mStartSelection, TEControlP->mEndSelection, mTextEditH);
- ::TEActivate(mTextEditH);
- TEControlP->mContainerSiteP->SetIdleTime(TEIdleTickCount, TEIdleRefCon);
- if (!Acquired)
- TEControlP->mContainerSiteP->ReleaseContext(&Context);
- }
- }
-
- return S_OK;
- }
-
-
- //=--------------------------------------------------------------------------=
- // CTextEditContextInfo::CTextEditContextInfo
- //=--------------------------------------------------------------------------=
- ErrorCode
- CTextEditContextInfo::Deactivate(Boolean8 Acquired)
- {
- CTextEditControl* TEControlP = (CTextEditControl*) mControlP;
-
- if (TEControlP->mOwnedFoci & KeyboardFocus)
- {
- DrawContext Context = { BeginPortType };
-
- TEControlP->mStartSelection = (*mTextEditH)->selStart;
- TEControlP->mEndSelection = (*mTextEditH)->selEnd;
- TEControlP->mContainerSiteP->SetIdleTime(RemoveIdler, TEIdleRefCon);
- if (Acquired || TEControlP->mContainerSiteP->AcquireContext(mContextID, &Context) == S_OK)
- {
- ::TEDeactivate(mTextEditH);
- if (!Acquired)
- TEControlP->mContainerSiteP->ReleaseContext(&Context);
- }
- }
-
- return S_OK;
- }
-