The IFocusHandler class handles events occurring when a control gains or loses the input focus, such as when the user tabs to or from an entry field. These objects handle the processing of focus change events for the following controls:
Create a handler derived from IFocusHandler and attach it to the control that gets or loses the input focus, or to the owner window of the control. You can do this by calling IHandler::handleEventsFor to pass this control or owner window to the focus handler.
When the focus handler receives a focus event, it creates an object of class IControlEvent and routes that object to the appropriate IFocusHandler virtual function. You can override these "Event Processing" virtual functions to supply your own specialized processing of a focus event.
The return value from the virtual functions specifies whether the focus event is passed on for additional processing, as follows:
In Motif, IFocusHandlers cannot handle the processing of focus change events for ISlider controls.
You can construct and destruct objects of this class.
![]() |
public:
virtual ~IFocusHandler()
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
public:
IFocusHandler()
Constructs the default focus handler.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
The Open Class Library dispatches events that have been sent or posted to a window to the handlers attached to that window. It does this by calling the event-dispatching function of the handler objects. An IFocusHandler object processes only focus-change events.
![]() |
protected:
virtual bool dispatchHandlerEvent(IEvent& event)
If a focus event is received, this function calls the appropriate virtual function.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
A focus handler allows you to process focus changes through its event-processing members. Override at least one of these virtual functions in a derived class.
![]() |
protected:
virtual bool gotFocus(IControlEvent& event)
Implemented by a derived class to process a gain-focus event. Avoid trying to set focus to another window from within this method; attempting to change focus while a previous focus change is being processed has unpredictable results. An alternative is to post yourself another event from within this method and reset the focus during processing of this other event.
Windows | OS/2 | AIX |
Yes | Yes | Yes |
![]() |
protected:
virtual bool lostFocus(IControlEvent& event)
Implemented by a derived class to process a lost-focus event. As is true for most virtual methods of handler classes, you should not typically perform any long-running operations in your implementation of this method. This particular virtual method is especially sensitive to long delays in returning to the caller; doing so has unpredictable results including hanging your system. If you must perform a long-running operation, spin off a separate thread to do it and return from this method as soon as possible to free up the thread this method was called on..
Avoid trying to set focus to another window from within this method; attempting to change focus
while a previous focus change is being processed has unpredictable results. An alternative is to post
yourself another event from within this method and reset the focus during processing of this other event.
Note:
Windows | OS/2 | AIX |
Yes | Yes | Yes |
virtual ~IHandler()
virtual IString asDebugInfo() const
virtual IString asString() const
virtual IHandler& disable()
virtual IHandler& enable(bool enable = true)
virtual IHandler& handleEventsFor(IWindow* window)
IHandler()
bool isEnabled() const
virtual IHandler& stopHandlingEventsFor(IWindow* window)
virtual IEventResult defaultProcedure(IEvent& event)
virtual bool dispatchHandlerEvent(IEvent& event) = 0