The second common use is for handling pop-up menus. An event handler is added for the ButtonMenuMask event. When the event handler is called, the application pops the menu up.Mouse button 3 is used as the menu button. However, some platforms trigger the button menu event when the button is pressed, and others when the button is released. The ButtonMenuMask event hides this difference. It should be used, rather than the other button events, to support pop-up menus in a platform-independent manner.Register event handlers using the addEventHandler:receiver:selector:clientData: method.The argBlock argument of a widget-creation message can only be used to set widget resources. The addEventHandler: message cannot be used within the create argBlock. Event handlers are usually registered immediately after the widget has been created, and before it is realized.The addEventHandler:receiver:selector:clientData: method takes four parameters:The eventMask is specified as the bitwise-OR of one or more of the bit masks described in the following table.
The following table describes the class hierarchy for event objects. Classes in italics are abstract classes.
An expose event handler cannot be explicitly added to a widget. A CwExposeEvent object is passed to an application as part of the call data for an exposeCallback.The following messages can be sent to the event object to retrieve information about the event. The methods for all events (CwEvent) include the following:
The type of event that occurred. This has one of the following values: ButtonPress, ButtonRelease, Expose, KeyPress, KeyRelease, and MotionNotify. The CgWindow associated with the widget for which the event was generated. The CgDisplay associated with the event.For expose events (CwExposeEvent), the method include the following:
The number of expose events which remain for the affected CgWindow. A simple application might want to ignore all expose events with a nonzero count, and perform a full redisplay if the count is zero.
A bit mask representing the logical state of modifier keys and pointer buttons just prior to the event. Possible bit masks include: ControlMask, ShiftMask, LockMask, Mod1Mask to Mod5Mask, and Button1Mask to Button3Mask. For mouse button events (CwButtonEvent), the methods are as follows:
For key events (CwKeyEvent), the methods are as follows:
A constant describing the keyboard key that was pressed or released. These constants are found in the e CwConstants pool dictionary, and are prefixed with 'XK.' The Character describing the keyboard key that was pressed or released, or nil if it does not represent a valid character.In the following example, a drawing area is created, and an event handler is added to notify the application of mouse button presses, key presses, and pointer motion. Label widgets are used to display information about the events. The variable labels would be implemented as an instance variable for the class.When an event occurs, the following method is run. Information about the event is determined from the event argument and is displayed in the label widgets.
|