EW_Event

EW_Event

ew

1998 12-05


CLASS

EW_Event - abstracted event


SYNOPSIS

Class EW_Event is the event object passed to widgets during the their descent operation to react to window-system incidents. The source of the event is where the event was initiated from. The item of the event is what aspect of the source was acted upon. The state of the event is the new status of that item. As the event passes through the widget hierarchy, widgets can alter the used value as they consume some aspect of the event. This can prevent multiple widgets from improperly acting on the same event. However, it is flexible enough that multiple widgets can sometimes act on somewhat independent aspects of the same event.


PUBLIC MEMBER FUNCTIONS


void SetSource(long x)

long GetSource(void)
Set/Get the source of the event. Enumeration values are given for clarity; they are subject to change.



EW_EVENT_NONE 0x000 NULL event, the default after construction.
EW_EVENT_MOUSEPOSITION 0x001 The mouse has been moved.
EW_EVENT_MOUSEBUTTON 0x002 A mouse button was pressed or released. The item indicates which button was acted on and the state indicates whether it was pressed or released.
EW_EVENT_KEYBOARD 0x004 A key was pressed, released, or repeated. The item indicates which key was acted on and the state indicates whether it was pressed, released, or repeated.
EW_EVENT_CLIPBOARD 0x008 Interaction with the native text clipboard has occured.
EW_EVENT_FOCUS 0x010 Mouse focus has changed in some way, by moving either inside or outside the window.
EW_EVENT_PERIODIC 0x020 A periodic event has occured, such as timer or work function.
EW_EVENT_SYSTEM 0x040 A window-system-related event has occured.
EW_EVENT_WIDGET 0x080 Reserved for use by the widget system. EW will never generate an event from this source.
EW_EVENT_APPLICATION 0x100 Reserved for use by the end application. EW will never generate an event from this source.
EW_EVENT_ANY 0xFFFFFFFF Any event. Used for comparisons where the source is being wildcarded.



void SetItem(long x)

long GetItem(void)
Set/Get the item on which the event occured. For special groupings in certain cases, multiple items can be OR'ed together. However, most events generated from the event loop contain a single item and single new state. Enumeration values and mappings are given for clarity; they are subject to change.



EW_ITEM(x) as (x>=0 && x<32)? (1<<x): 0 General purpose OR'able enumeration of items.
EW_ITEM_NONE 0 No item associated with the event.



EW_ITEM_LEFT EW_ITEM(0) Left mouse button has changed state
(for source==EW_EVENT_MOUSEBUTTON).
EW_ITEM_MIDDLE EW_ITEM(1) Middle mouse button has changed state
(for source==EW_EVENT_MOUSEBUTTON).
EW_ITEM_RIGHT EW_ITEM(2) Right mouse button has changed state
(for source==EW_EVENT_MOUSEBUTTON).



EW_ITEM_X EW_ITEM(0) The x position has changed
(for source==EW_EVENT_MOUSEPOSITION).
EW_ITEM_Y EW_ITEM(1) The y position has changed
(for source==EW_EVENT_MOUSEPOSITION).



EW_ITEM_CLIPBOARD_FAIL EW_ITEM(0) Information requested from the clipboard was not successfull received.
EW_ITEM_CLIPBOARD_READY EW_ITEM(1) Information requested from the clipboard was successful received and is ready to be used.



EW_ITEM_CLOSEWINDOW EW_ITEM(0) The currently focused window has been closed
(for source==EW_EVENT_SYSTEM). This event is sent just prior to closing the window. It is acceptable to close the window during the processing of the event since the event loop will only try to close it if it is still open.
EW_ITEM_EXPOSURE EW_ITEM(1) The currently focused window been exposed
(for source==EW_EVENT_SYSTEM).
EW_ITEM_QUIT_APP EW_ITEM(0) The currently application has been killed
(for source==EW_EVENT_SYSTEM). This event is sent after calling EW_Window::DoKillCallback(TRUE) which should never return, and as such, applications should only receive this event when the callback failed to exit the application.



EW_ITEM_WORK EW_ITEM(0) Passed when there are no events pending so that self-operating widgets can do simple background work and/or update themselves
(for source==EW_EVENT_PERIODIC ). These events are activated through EW_Window::SetDoWork().
EW_ITEM_TIMER EW_ITEM(1) A user specified timer has reached its interval
(for source==EW_EVENT_PERIODIC). These events are activated through EW_EventContext::AppendTimerInterval().



EW_ITEM_FOCUSCHANGE EW_ITEM(0) Mouse focus has changed to a different window. The state indicates the unique window identifier for the window that has acquired focus. If that window does not belong to the application, a NULL identifier is used
(for source==EW_EVENT_FOCUS).
EW_ITEM_IDLEMOUSE EW_ITEM(1) There are no events pending and the mouse has moved since the last EW_ITEM_IDLEMOUSE event
(for source==EW_EVENT_FOCUS).



EW_ITEM_ALL 0xFFFFFFFF Any/all items. Used for comparisons where the item is being wildcarded.


The following items are used when source==EW_EVENT_KEYBOARD. Note that most keys will use the item number equal their ASCII value. Groupings of acsii keys are done with special values, not by OR'ing ascii values together.



EW_KEY_BACKSPACE 8 Backspace key.
EW_KEY_RETURN 13 Return key.
EW_KEY_ESC 27 Escape key.
EW_KEY_DELETE 127 Delete key.
EW_KEY_ALL_ASCII 0x0000007F Any/all ASCII keys. OR'able with below.



EW_KEY_NUMBERS (1<< 8) Any/all numerical keys. OR'able.
EW_KEY_LETTERS (1<< 9) Any/all alphabetical keys. OR'able.
EW_KEY_NONALPHANUM (1<<10) Any/all non-alphanumeric keys. OR'able.



EW_KEY_NON_ASCII_FLAG (1<<10)
EW_KEY_NON_ASCII ( EW_KEY_NON_ASCII_FLAG | EW_KEY_NONALPHANUM )
EW_KEY_NONALPHANUM (1<<10)
EW_KEY_HOME (EW_KEY_NON_ASCII+1)
EW_KEY_END (EW_KEY_NON_ASCII+2)
EW_KEY_INSERT (EW_KEY_NON_ASCII+3)
EW_KEY_TAB (EW_KEY_NON_ASCII+4)
EW_KEY_PAUSE (EW_KEY_NON_ASCII+5)
EW_KEY_PAGE_UP (EW_KEY_NON_ASCII+6)
EW_KEY_PAGE_DOWN (EW_KEY_NON_ASCII+7) Normal keyboard keys not neccessarily defined under ASCII. These keys are enumerated, not OR'able.



EW_KEY_F_KEYS 0x000F0000 Mask for all function keys. OR'able.
EW_KEY_F(x) defined as ((((x)&15)<<EW_KEY_F_KEY_SHIFT)| EW_KEY_NONALPHANUM) where EW_KEY_F_KEY_SHIFT=16 Specific function key x. OR'able. Programmers are cautioned that function keys tend to be a source of trouble since they are often not mapped properly or potentially don't exist on a particular platform. The macro recognizes 16 function keys, but the system only produces events up to F10 since some Suns do not properly map F11 and F12.



EW_KEY_CURSOR_UP ((1<<20)| EW_KEY_NONALPHANUM) Cursor-Up key. OR'able.
EW_KEY_CURSOR_DOWN ((1<<21)| EW_KEY_NONALPHANUM) Cursor-Down key. OR'able.
EW_KEY_CURSOR_LEFT ((1<<22)| EW_KEY_NONALPHANUM) Cursor-Left key. OR'able.
EW_KEY_CURSOR_RIGHT ((1<<23)| EW_KEY_NONALPHANUM) Cursor-Right key. OR'able.
EW_KEY_ALL_CURSOR (EW_KEY_CURSOR_UP| EW_KEY_CURSOR_DOWN| EW_KEY_CURSOR_LEFT| EW_KEY_CURSOR_RIGHT) All cursor keys (mask).



EW_KEY_SHIFT (1<<24) Shift modifier key. OR'able.
EW_KEY_CAPS_LOCK (1<<25) Caps-Lock modifier key. OR'able.
EW_KEY_CONTROL (1<<26) Control modifier key. OR'able.



EW_KEY_ALL EW_ITEM_ALL Any/all keys. Used for comparisons where the item is being wildcarded.



void SetState(long x)

long GetState(void)
Set/Get the new state of the item(s). Enumeration values are given for clarity; they are subject to change.



EW_STATE_NULL 0 Items state is not relevant.
EW_STATE_PRESS 1 The item has been pressed.
EW_STATE_REPEAT 2 The item has been held and is repeating.
EW_STATE_RELEASE 4 The item has been released.
EW_STATE_ANY 0xFFFFFFFF Any state. Used for comparisons where the state is being wildcarded.



void SetTimeAutomatically(void)

void SetTime(long set)

long GetTime(void)
Set/Get the time index stamp, assumed to be in milliseconds and only intended for relative comparisons. Setting the time is usually only done in the event loop. The automatic version uses osdTimer() to set the time. The loop period of 2 billion milliseconds is fairly large (about two weeks).



void SetClipRegion(EW_ClipRegion *set)

EW_ClipRegion *GetClipRegion(void)
Set/Get a clipping region associated with the event, presumably an exposure. The region given by set must be created with new by the caller and will be automatically deleted by EW_Event upon the event's destruction or by replacement by another clip region. These operations should generally be limited to EW's internal event processing, where the event loop may need to put exposures and other events in a queue. Not that this separate from the state of the clipping region stack encountered during the drawing phase.



void SetRepetition(long set)

long GetRepetition(void)
Set/Get the number of times this event has been repeated, not including the current event. For example, a repetition of 2 indicates a triple-click. Setting the repetition is usually only done in the event loop. Only certain events, such as key and mouse button presses, are marked as such. Repeating events do not have to occur at the same mouse location.



void SetChoice(EW_Widget *set)

EW_Widget *GetChoice(void)
Set/Get the descendent-most widget reached thus far. Since this changes through descension, it is probably only meaningful during a EW_Widget::PostOperate(), and then only on locational events. Setting the choice is taken care of during the default EW_Widget::Descend().



void SetLastChoice(EW_Widget *set)

EW_Widget *GetLastChoice(void)
Set/Get the choice of a previous event, not neccessarily the most recent event. This is set automatically only when a repeating event is detected. This information is useful to determine if the previous occurance of the repeating event happened in the same widget. Since repetition does not require the exact same mouse location (in case of slight mouse slippage), it is the resposibility of the widget to determine if it received the entire multi-click. EW_Window::ProcessEvent() will clear repetitions of events of different choices, but it can only do so after the choice is found, which is after the choice would have had to already reacted to the multi-click.



void SetDislocated(long set)

long GetDislocated(void)
Set/Get a flag indicating that an event not constrained by widget geometries would have otherwise not reached the widget operating on the event. For example, idle-mouse events could potentially be sent to every widget in a window, even the widgets which are not positioned under the mouse. For those widgets not positioned under the mouse, they would recieve the idle-mouse event as dislocated. Setting this value is usually only done in the event descension.



void SetUsed(long x)

long GetUsed(void)
Set/Get part of the event as being consumed. This is generally done by widgets as they operate to indicate to other widgets that all or part of the event is no longer available. Simple widgets can just call SetUsed(TRUE) when they receive events. More intelligent widgets can examine events after their children have had the chance to consume them. If the event is not completely consumed, the parent may use it for something like a background drag. The events are also X-Y separable so that widgets with unidirectional functionality can operate independently and simutaneously. Enumeration values are given for clarity; they are subject to change.



EW_USED_NONE FALSE Event is completely available.
EW_USED_TRUE TRUE Event is completely consumed. Equivalent to EW_USED_ALL.



EW_USED_GRABX 2
EW_USED_GRABY 4
The event can no longer be used to grab a widget. (X-Y independent)



EW_USED_DRAGX 8
EW_USED_DRAGY 16
The event can no longer be used to drag a widget. (X-Y independent) The distinction is made between grabbing and dragging so that a mouse motion that hit some barrier can be picked up by another widget. For example, a horizontally-based grouping widget with background dragging capabilites can set EW_USED_GRABX during its EW_Widget::Operate() phase to prevent simple descendents from taking the event. However, it leaves the EW_USED_DRAGX untouched until the EW_Widget::PostOperate() phase. If no descendent has then consumed EW_USED_DRAGX, the widget can use it as a drag. Even if the widget never got the original exclusive grab, it can still use unused drag events during EW_Widget::PostOperate(). Note that another widget could be acting similarily on the vertical component with no conflict. A good example is the WDS_Partition in the WDS widget set.



EW_USED_X (EW_USED_GRABX| EW_USED_DRAGX) All X aspects of the event have been consumed.
EW_USED_Y (EW_USED_GRABY| EW_USED_DRAGY) All Y aspects of the event have been consumed.



EW_USED_ALL 0xFFFFFFFF Event is completely consumed. Generally prefered over EW_USED_TRUE.



void SetMousePosition(long x,long y)

void GetMousePosition(long *x,long *y)
Set/Get the mouse position where the event occurred. SetMousePosition() is general only called by the event loop itself.



void InvertMousePosition(long windowheight)
Invert the y mouse position from a top-down to a bottom-up frame of reference, or vica-versa. This is general only called by internal EW functions to adjust for differences in windowing systems.



void SetMouseButtons(long x)

long GetMouseButtons(void)
Set/Get the state of all the mouse buttons as the OR'ed sum of EW_MOUSEBUTTONS_LEFT , EW_MOUSEBUTTONS_MIDDLE , and EW_MOUSEBUTTONS_RIGHT .



void SetWidgetFlags(long x)

long GetWidgetFlags(void)
Set/Get widget-system-specific data for the event. EW never uses or changes this data except to reset it to 0, such as in the constructor. The use of this value is reserved for the widget system, such as WDS.



void Reset(void)
Reset all data members to default values as done in the constructor.



void CopyFrom(EW_Event *other)
Copies the data from the other event into this event.


CONVENIENCE FUNCTIONS (built from other functions)


Application writers should read the event header file to understand how each of the convenience functions work. All the convenience functions are nearly trivial and are used for consistency and clarity.



void SetSIS(long source,long item,long state)

void SetSISW(long source,long item,long state,long widget_flags)
Set the source, item, state, and (optionally) widget_flags in one call.



long InBounds(long x,long y,long sx,long sy)


long InWidget(EW_Widget *widget)
Returns non-zero if the event is within the specified rectanglar bounds, either from the lower-left corner of x,y and of size sx,sy or inside the specified widget.



long Is(long source,long item,long state)
Returns TRUE if the given source, item, and state intersect that of the event. The source, item, and state of EW_EVENT_ANY, EW_ITEM_ALL, and EW_STATE_ANY always result in a match of that part.



long IsOnly(long source,long item,long state)
Returns TRUE if the given source, item, and state are exactly the same as the event. This can be different than Is() when multiple items and/or states are grouped together.



long IsUsed(long part)
Returns non-zero if the there is an intersection of the used values in the event and the OR'ed sum of used flags specified by part.



long IsDragged(void)
Returns TRUE if the used flags indicate a drag.



long Matches(EW_Event *other)
Returns TRUE if the other event has the exact same source, item, and state.



long Intersects(EW_Event *mask)
Returns TRUE if the event intersects the given mask comparing the source, item, state, and widget flags. If the incoming event has no widget flags set, it is considered a match to any widget flag mask. (This deviates somewhat from the conceptual AND operation that this function implies.) This is an expansion of Is().



long IsKeyOfState(long key,long state)

long IsKeyTyped(long key)

long IsKeyPressed(long key)

long IsKeyRepeated(long key)

long IsKeyReleased(long key)
Returns TRUE if the event corresponds to an action on the specified key. Most key values corresponds to the equivalent ASCII of the character. Note that in a grouping, other keys may be included in the event as well. IsKeyOfState() is the function that the other calls map to. The others correspond to press-or-repeat, press-only, repeat-only, and release-only, respectively.



long IsMouseMotion(void)
Returns TRUE if the event corresponds to mouse motion of some kind.



long IsMouseButton(void)
Returns TRUE if the event corresponds to a mouse button change.



long IsMouse(void)
Returns TRUE if the event corresponds to a mouse change (motion or button).



long IsLeftMousePress(void)

long IsMiddleMousePress(void)

long IsRightMousePress(void)
Returns TRUE if the event contains the pressing of the specific mouse button. Note that other mouse buttons may already be pressed as well.



long IsLeftMouseRelease(void)

long IsMiddleMouseRelease(void)

long IsRightMouseRelease(void)
Returns TRUE if the event contains the release of the specific mouse button. Note that other mouse buttons may be pressed.



long IsLeftMouseMotion(void)

long IsMiddleMouseMotion(void)

long IsRightMouseMotion(void)
Returns TRUE if the event corresponds mouse motion of some kind while the specific mouse button is being held. Note that other mouse buttons may be pressed as well.



long IsClipboard(void)

long IsClipboardReady(void)

long IsClipboardFail(void)

long IsSystem(void)

long IsCloseWindow(void)

long IsQuitApplication(void)

long IsExposure(void)

long IsWork(void)

long IsTimer(void)

long IsIdleMouse(void)

long IsFocusChange(void)
Returns TRUE if the event corresponds to the respective source and, potentially, item.



long Print(long hexcode)
Print verbose debugging text about the event using the EW_PRINT() macro to ewPrint(). Note that the output may ANSI color codes for clarification. The hexcode is printed with the message in hex. It could be used, for example, to indicate which window the event occurred in. Returns TRUE if the event was printed (not masked out).


FILES

ew/event.h Event header file


SEE ALSO

EW_intro(3), WDS_Partition(3), ewPrint(3)


NOTES

There are not yet any macros to provide the special functionality of the item groups EW_KEY_NUMBERS, EW_KEY_LETTERS, and EW_KEY_NONALPHANUM. These can be considered reserved.