Every OCX has a set of event notifications that it can send to its container. OCX events encompass both event and callback notions of Common Widgets. That is, OCX events can be fine-grained (such as mouse-clicks or key-presses), or they can be notifications of some higher-level action (such as a Cancel button being selected). The events that a particular OCX support are normally described in the OCX's type library or in the documentation that is shipped with it. Each event that is supported by an OCX is identified by a unique name and a unique DISPID.An OCX container must register a method for each OCX event it will handle. The name of the event, the selector of the event-handler method, and the object that receives the notification are registered with an OleControl through its addOleEventHandler:receiver:selector: instance method. For example, the track bar OCX sends an event called 'Change' whenever the user moves its slider. The handler for this event is registered using:An OLE event handler is deregistered from an OleControl through its instance method removeOleEventHandler:receiver:selector:.There is a set of predefined OLE event names and DISPIDs for the base mouse and keyboard events that are used by most OCXs. These predefined events overlap the Common Widgets event masks that are inherited by OleControl. As a convenience, OleControl registers handlers for the corresponding OLE predefined events and automatically reroutes them through the Common Widgets event-handler mechanism. For example, the mouse-down OLE event handler registered in the previous example can be rewritten to use a Common Widgets event handler:OleControl registers OLE event handlers for these predefined events:
•
•
• If a container registers for one of the predefined OLE events using addOleEventHandler:receiver:selector:, its handler supersedes the OleControl widget's registered predefined event.
![]() |