Activation
When the user clicks within the used shape of any frame belonging to the part, the frame should activate itself. The frame should also activate itself when its window opens or becomes active if the part has stored information specifying that the frame should become active in those situations. In addition, a frame should activate itself when the user drags and drops data on it. The frame activates itself by acquiring the selection focus.Methods illustrating the standard OpenDoc activation protocol are included in this section. These method implementations are short, so their descriptions are not shown as numbered steps.
The BeginRelinquishFocus Method
OpenDoc calls theBeginRelinquishFocus
method when another frame requests ownership of a focus of which the specified frame is the current owner. Generally, a part's response to theBeginRelinquishFocus
method call is to determine if it can safely relinquish the focus, in which case it returnskODTrue
. A part does not actually relinquish the focus in response to theBeginRelinquishFocus
call.The
SamplePart
object's implementation ofBeginRelinquishFocus
first determines if the focus in question is its modal focus. If so, unless the frame requesting the focus belongs to SamplePart itself, the method returnskODFalse
. That is, if another part wants to display a modal dialog box while SamplePart is displaying its own, SamplePart denies the request. Otherwise, the method returnskODTrue
.Listing 2-32 shows the implementation of the
BeginRelinquishFocus
method.Listing 2-32
BeginRelinquishFocus
method
ODBoolean SamplePart::BeginRelinquishFocus( Environment* ev, ODTypeToken focus, ODFrame* /* ownerFrame */, ODFrame* proposedFrame ) { SOM_Trace("SamplePart","BeginRelinquishFocus"); ODBoolean willRelinquish = kODTrue; if ( focus == gGlobals->fModalFocus ) { TempODPart proposedPart = ODAcquirePart(ev,proposedFrame); if ( ODObjectsAreEqual(ev, proposedPart, fSelf) == kODFalse ) willRelinquish = kODFalse; } return willRelinquish; }The CommitRelinquishFocus Method
OpenDoc calls theCommitRelinquishFocus
method when it is time for a frame to actually relinquish ownership of the specified focus, completing the process begun in response to a previousBeginRelinquishFocus
method call. Generally, a part's response to theCommitRelinquishFocus
method call is to remove any indications of the specified frame owning the focus; for example, the method could remove highlighting. If the focus is being transferred to a frame belonging to a different part, the part could do further actions, such as disabling menu items or removing a palette.The
SamplePart
object's implementation ofCommitRelinquishFocus
calls theFocusLost
method to do the actual work. TheFocusLost
method is shown in Listing 2-34.Listing 2-33 shows the implementation of the
CommitRelinquishFocus
method.Listing 2-33
CommitRelinquishFocus
method
void SamplePart::CommitRelinquishFocus( Environment* ev, ODTypeToken focus, ODFrame* ownerFrame, ODFrame* /* proposedFrame */ ) { SOM_Trace("SamplePart","CommitRelinquishFocus"); this->FocusLost(ev, focus, ownerFrame); }The FocusLost Method
TheSamplePart
object calls its ownFocusLost
method to do the actual work of relinquishing a focus specified by theCommitRelinquishFocus
method call. In addition, OpenDoc may call theFocusLost
method directly when the arbitrator has transferred ownership of a specified focus from the specified frame to another due to events, without benefit of theBeginRelinquishFocus
andCommitRelinquishFocus
method calls.The
SamplePart
object's implementation ofFocusLost
acts only if the lost focus is the selection focus. In that case, the specified frame is being deactivated, so the method removes the indication that the frame is active, which is stored in the frame'sCFrameInfo
object.Listing 2-34 shows the implementation of the
FocusLost
method.
void SamplePart::FocusLost( Environment* ev, ODTypeToken focus, ODFrame* ownerFrame ) { SOM_Trace("SamplePart","FocusLost"); if ( focus == gGlobals->fSelectionFocus ) { CFrameInfo* frameInfo = (CFrameInfo*) ownerFrame->GetPartInfo(ev); frameInfo->SetFrameActive(kODFalse); } }The AbortRelinquishFocus Method
OpenDoc calls theAbortRelinquishFocus
method when it rescinds a previous request (made with aBeginRelinquishFocus
call) to relinquish ownership of a focus. Generally, a part's response to theAbortRelinquishFocus
method call is to back out of any changes it initiated in response to the previousBeginRelinquishFocus
call.The
SamplePart
objects's implementation ofAbortRelinquishFocus
does nothing.Listing 2-35 shows the implementation of the
AbortRelinquishFocus
method.Listing 2-35
AbortRelinquishFocus
method
void SamplePart::AbortRelinquishFocus( Environment* ev, ODTypeToken /*focus*/, ODFrame* /*ownerFrame*/, ODFrame* /*proposedFrame*/ ) { SOM_Trace("SamplePart","AbortRelinquishFocus"); // Some parts may have suspended some events in the BeginRelinquishFocus // method. If so, they would resume those events here. }The FocusAcquired Method
OpenDoc calls theFocusAcquired
method when the arbitrator has transferred ownership of the specified focus to the specified frame without benefit of theBeginRelinquishFocus
andCommitRelinquishFocus
method calls. Generally, a part's response to theFocusAcquired
method call is to perform any actions needed to indicate that the specified frame now owns the focus. For example, if a frame acquired the selection focus, a part would highlight any selection within the frame.The
SamplePart
object's implementation ofFocusAcquired
calls the arbitrator'sRequestFocusSet
method to request the complete focus set it needs to be active. If that action succeeds, the method calls theSamplePart
object's internal methodPartActivated
, which puts the part into an active state, as shown in Listing 2-37.Listing 2-36 shows the
SamplePart
object's implementation of theFocusAcquired
method.Listing 2-36
FocusAcquired
method
void SamplePart::FocusAcquired( Environment* ev, ODTypeToken focus, ODFrame* ownerFrame ) { SOM_Trace("SamplePart","FocusAcquired"); ODArbitrator* arbitrator = ODGetSession(ev,fSelf)->GetArbitrator(ev); if ( arbitrator->RequestFocusSet(ev, gGlobals->fUIFocusSet, ownerFrame) ) { this->PartActivated(ev, ownerFrame); } }The PartActivated Method
TheSamplePart
object calls its own internal methodPartActivated
to display the part's menu bar and set the active flag in the specified frame'sCFrameInfo
object to true. Before displaying the menu bar, however, the method revalidates it, as described in "The AdjustMenus Method".Listing 2-37 shows the implementation of the
PartActivated
method.Listing 2-37
PartActivated
method
void SamplePart::PartActivated( Environment* ev, ODFrame* frame ) { SOM_Trace("SamplePart","PartActivated"); if ( gGlobals->fMenuBar->IsValid(ev) == kODFalse ) { ODReleaseObject(ev, gGlobals->fMenuBar); gGlobals->fMenuBar = ODGetSession(ev,fSelf)->GetWindowState(ev)->CopyBaseMenuBar(ev); } gGlobals->fMenuBar->Display(ev); CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev); frameInfo->SetFrameActive(kODTrue); }The ActivateFrame Method
TheSamplePart
object calls its own internalActivateFrame
method when a mouse-up event occurs in an inactive frame in an active window or when the window in which the frame is displayed is activated by the Mac OS.The method requests the user-interface focus set (defined in the
Initialize
method) and, if that request is granted, calls thePartActivated
method to display the menu bar and set the specified frame's active flag. If the method executes successfully, it returnskODTrue
as a signal to the caller that the specified frame is now active; otherwise, it returnskODFalse
.Listing 2-38 shows the implementation of the
ActivateFrame
method.Listing 2-38
ActivateFrame
method
ODBoolean SamplePart::ActivateFrame( Environment* ev, ODFrame* frame ) { SOM_Trace("SamplePart","ActivateFrame"); ODBoolean activated = kODFalse; if ( ODGetSession(ev,fSelf)->GetArbitrator(ev) ->RequestFocusSet(ev, gGlobals->fUIFocusSet, frame) ) { this->PartActivated(ev, frame); activated = kODTrue; } return activated; }The WindowActivating Method
TheSamplePart
object calls its own internalWindowActivating
method from itsHandleEvent
method when it receives an activate event from the Mac OS. The activate event (kODEvtActivate
) indicates that a window displaying the specified frame is being either activated or deactivated, as indicated by the Boolean parameteractivating
.If the window is being activated, and if the specified frame had the selection focus when it was deactivated, the method calls the
SamplePart
object's internalActivateFrame
method. If the window is being deactivated and the specified frame is active, the method marks the frame's reactivation flag true. By setting the flag in this way, the frame can reactivate itself if the window becomes active again later, using the previous block of this same method.Listing 2-39 shows the implementation of the
WindowActivating
method.Listing 2-39
WindowActivating
method
void SamplePart::WindowActivating( Environment* ev, ODFrame* frame, ODBoolean activating ) { SOM_Trace("SamplePart","WindowActivating"); CFrameInfo* frameInfo = (CFrameInfo*) frame->GetPartInfo(ev); if ( activating && frameInfo->FrameNeedsReactivating() ) { this->ActivateFrame(ev, frame); frameInfo->SetFrameReactivate(kODFalse); } else if ( !activating && frameInfo->IsFrameActive() ) { frameInfo->SetFrameReactivate(kODTrue); } }
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help