PageItemFocus manages switches between page item event handling (PageItemEventHandler) and text event handling (FrameEventHandler). Page items and text selection have different event handlers: i.e. arrow key left moves a page item to the left on the spread if the PageItemEventHandler is active while the same key event moves the caret by one character to the left if the FrameEventHandler is activated. If the user switches from page item selection to text selection or vice versa the corresponding event handler needs to be registered as the current event handler. This is done via KeyFocusHandler::SetCurrentTargetEventHandler in three steps:
- calling IEventHandler::GiveUpKeyFocus() on the current event handler.
- replacing the current event handler with the new one.
- calling IEventHandler::GetKeyFocus() on the new event handler.
There are several situations that require a change of event handlers and a call toKeyFocusHandler::SetCurrentTargetEventHandler:
- Activation of TextSelection after creating a new TextFrame
- Deactivation of TextSelection after switching to pointer tool.
- Activation of TextSelection after clicking with pointer tool into TextFrame.
PageItemFocus offers a convenient API for activating and deactivating. PageItemFocus is implemented in PublicLib with kPageItemFocusImpl. It is only used by kStandOffBoss. FrameViewFocus is derived from PageItemFocus and is implemented in TextEditor with kFrameViewFocusImpl. It is only used by kTextEditorBoss:
- kStandOffBoss uses kPageItemFocusImpl
- kTextEditorBoss uses kFrameViewFocusImpl
This interface is part of the PageItem widget. It helps to differentiate between several cases of deactivation. Grant/RevokePageItemFocus is called, when the pageitem has the focus (i.e. if the user edits it). The selection would be visible and a TextCaret would blink. Suspend/ResumePageItemFocus is called when the window or the layout control view is deactivated. The selection would be shadowed, but a TextCaret would disappear.
These are possible cases for Grant/Revoke and Suspend/Resume: 1) Deactivate Window => Suspend( kTrue ) 2) Reactivate Window => Resume 3) Change the tool => Suspend( kFalse ) 4) Change back to the first tool => Resume 5) Close Document => Revoke 6) Create new PageItem => Grant 7) Place a story => Revoke 8) Change to an EditBox in a Panel => Suspend( kTrue )