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 theBeginRelinquishFocusmethod when another frame requests ownership of a focus of which the specified frame is the current owner. Generally, a part's response to theBeginRelinquishFocusmethod 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 theBeginRelinquishFocuscall.The
SamplePartobject's implementation ofBeginRelinquishFocusfirst 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
BeginRelinquishFocusmethod.Listing 2-32
BeginRelinquishFocusmethod
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 theCommitRelinquishFocusmethod when it is time for a frame to actually relinquish ownership of the specified focus, completing the process begun in response to a previousBeginRelinquishFocusmethod call. Generally, a part's response to theCommitRelinquishFocusmethod 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
SamplePartobject's implementation ofCommitRelinquishFocuscalls theFocusLostmethod to do the actual work. TheFocusLostmethod is shown in Listing 2-34.Listing 2-33 shows the implementation of the
CommitRelinquishFocusmethod.Listing 2-33
CommitRelinquishFocusmethod
void SamplePart::CommitRelinquishFocus( Environment* ev, ODTypeToken focus, ODFrame* ownerFrame, ODFrame* /* proposedFrame */ ) { SOM_Trace("SamplePart","CommitRelinquishFocus"); this->FocusLost(ev, focus, ownerFrame); }The FocusLost Method
TheSamplePartobject calls its ownFocusLostmethod to do the actual work of relinquishing a focus specified by theCommitRelinquishFocusmethod call. In addition, OpenDoc may call theFocusLostmethod directly when the arbitrator has transferred ownership of a specified focus from the specified frame to another due to events, without benefit of theBeginRelinquishFocusandCommitRelinquishFocusmethod calls.The
SamplePartobject's implementation ofFocusLostacts 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'sCFrameInfoobject.Listing 2-34 shows the implementation of the
FocusLostmethod.
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 theAbortRelinquishFocusmethod when it rescinds a previous request (made with aBeginRelinquishFocuscall) to relinquish ownership of a focus. Generally, a part's response to theAbortRelinquishFocusmethod call is to back out of any changes it initiated in response to the previousBeginRelinquishFocuscall.The
SamplePartobjects's implementation ofAbortRelinquishFocusdoes nothing.Listing 2-35 shows the implementation of the
AbortRelinquishFocusmethod.Listing 2-35
AbortRelinquishFocusmethod
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 theFocusAcquiredmethod when the arbitrator has transferred ownership of the specified focus to the specified frame without benefit of theBeginRelinquishFocusandCommitRelinquishFocusmethod calls. Generally, a part's response to theFocusAcquiredmethod 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
SamplePartobject's implementation ofFocusAcquiredcalls the arbitrator'sRequestFocusSetmethod to request the complete focus set it needs to be active. If that action succeeds, the method calls theSamplePartobject's internal methodPartActivated, which puts the part into an active state, as shown in Listing 2-37.Listing 2-36 shows the
SamplePartobject's implementation of theFocusAcquiredmethod.Listing 2-36
FocusAcquiredmethod
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
TheSamplePartobject calls its own internal methodPartActivatedto display the part's menu bar and set the active flag in the specified frame'sCFrameInfoobject 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
PartActivatedmethod.Listing 2-37
PartActivatedmethod
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
TheSamplePartobject calls its own internalActivateFramemethod 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
Initializemethod) and, if that request is granted, calls thePartActivatedmethod to display the menu bar and set the specified frame's active flag. If the method executes successfully, it returnskODTrueas a signal to the caller that the specified frame is now active; otherwise, it returnskODFalse.Listing 2-38 shows the implementation of the
ActivateFramemethod.Listing 2-38
ActivateFramemethod
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
TheSamplePartobject calls its own internalWindowActivatingmethod from itsHandleEventmethod 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
SamplePartobject's internalActivateFramemethod. 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
WindowActivatingmethod.Listing 2-39
WindowActivatingmethod
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 | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help