EW_EventContext

EW_EventContext

ew

1998 12-05


CLASS

EW_EventContext - event loop context


SYNOPSIS

Class EW_EventContext is the event context to which all of the application's windows should belong. Generally, each EW-based application will have a single event context.


PUBLIC MEMBER FUNCTIONS



void AddWindow(EW_Window *window)

void RemoveWindow(EW_Window *window)
Add/Remove a window to the event context. A window must be added to the event context in order to receive events.



void BeginLoop()

void EndLoop()
Start/End the event loop. EndLoop() presumably is called during BeginLoop(), otherwise it has no effect. EndLoop() flags BeginLoop() to return at the end of the current event. Another BeginLoop() may be started afterwards, but most applications would probably terminate soon after BeginLoop() returns.



EW_WindowList *GetWindowList(void)
Return the linked list of windows.



long AppendTimerInterval(long identifier,long interval,EW_Window *target)

long RemoveTimerInterval(long identifier)
Add/Remove a timer of period interval milliseconds to send EW_ITEM_TIMER events to the target window. The identifier, a positive integer, can be used to remove the timer and will also be state of the EW_ITEM_TIMER event. AppendTimerInterval() returns the actual identifier assigned. This may not be the same as the requested identifier if that identifier was already in use. RemoveTimerInterval() returns TRUE if the identified timer existed and could be removed.



void ClearTimerIntervals(EW_Window *target)
Remove all timers to the specified target window. If target is NULL, all timers from all windows are cleared.



EW_TimerIntervalList *GetTimerIntervalList(void)
Return the timer list, a GPL_DoubleList of EW_TimerInterval. This list should only be modified through EW_EventContext member functions.



long SetCursorIndex(long index)

long GetCursorIndex(void)
Set/Get the current cursor index from the following. Note that OS's can change the images used for the cursors, so the descriptions are just common possibilites.



EW_CURSOR_NORMAL 0 unaltered default arrow
EW_CURSOR_WAIT 1 clock or hourglass
EW_CURSOR_HELP 2 question mark
EW_CURSOR_IBEAM 3 vertical line for text entry
EW_CURSOR_CROSSHAIR 4 plus-like and lightweight
EW_CURSOR_NS 5 vertical two-way arrow
EW_CURSOR_WE 6 horizontal two-way arrow
EW_CURSOR_FOURWAY 7 four-way arrow; more heavyweight than crosshair
EW_CURSOR_UPARROW 8 vertical up-only arrow
EW_CURSOR_INVALID 9 circle-sash or skull and crossbones Note that this is not an indication of an invalid cursor, but a cursor indicating a potentially invalid situation.



void SetWorkFunction(EW_WorkFunction *set)

EW_WorkFunction *GetWorkFunction(void)

void CallWorkFunction(void)
Set/Get/Call the general work function. Each application can have one current work function. This is independent of work events and timers that widgets generally use. CallWorkFunction() is only intended to be used internally from the event loop when free time is available.



long AppendWindowToModalStack(EW_Window *window,long exclusive)

long RemoveWindowFromModalStack(EW_Window *window)
Append/Remove a widget from the modal stack. If the stack is not empty, the topmost mapped window on the stack gets special treatment. The window will be placed above all other windows belonging to the application. Input from the mouse and keyboard will be blocked from all other windows. Windows are automatically removed from the stack when unmapped. Care should be taken not to overuse this feature since blocking input can annoy users significantly.


The optionally argument exclusive, defaulting to TRUE, specifies if other modals will be blocked when this modal is topmost. Non-modals are always blocked when a mapped modal exists. To allow other modals to operate freely is a neccessity for popup windows, like menus and picklists, when they operate off of a modal window.


These functions are intended for internal use. The acceptable manner to specify modals is through EW_Window::SetFlags() prior to opening the window.



EW_Window *GetTopMappedModalWindow(void)
Returns the topmost mapped window on the modal stack, potentially NULL.



long CopyTextToClipboard(char *data)
Send of copy of the given text data to the native clipboard. the event context retains a local copy of the string in case the native clipboard operations fail. Returns non-zero if the native clipboard operations fail.



void RequestTextFromClipboard(EW_Window *requestor)
Requests a copy of any text on the native clipboard. When the data becomes available, it is copied into the event context's internal buffer and the requestor window receives a clipboard event, specifically:
<EW_EVENT_CLIPBOARD,EW_ITEM_CLIPBOARD_READY,EW_STATE_NULL> or
<EW_EVENT_CLIPBOARD,EW_ITEM_CLIPBOARD_FAIL,EW_STATE_NULL>.



EW_String *GetClipboardString(void)

char *CopyTextFromClipboard(void)
Access the buffer holding the clipboard data, either directly or by making a copy. Note that this data is not neccessarily current except after receiving a clipboard event resulting from RequestTextFromClipboard() described above. If using CopyTextFromClipboard(), the returned data can be free'd by the caller using osdFree().



void SetEventRedirection(EW_Window *target)

EW_Window *GetEventRedirection(void)
Set/Get a window that receives all events regardless of original target. A setting of NULL restores normal operation. This is intended as an internal operation.



EW_Window *GetPhantom(void)
The phantom window is opened upon contstruction of the event context. It should never be made visible and is intended for operations which require an open window when no other "normal" windows are available. A good example is to determine font information, especially when that information is required to determine window geometry prior to opening, like with menus and picklists.



void Dump(long code,long brief)
Print information about all windows by calling EW_Window::Dump(long brief) for every window in the context. The code is printed somewhere in the output, but has no other effect.


EXAMPLE


The following example creates a context, window, and widget. note that it uses the WDS widget set. During the BeginLoop(), events will pass from the context, through the window, and to the single widget. The defaults of the EW_Widget class has no substantial functionality, so a real application would use widget classes derived from EW_Widget.



#include "wds.h"

int main(int argc,char **argv,char **envp)
    {
    WDS_NullApplication application;
    EW_EventContext     event_context;
    EW_Window           window;
    WDS_Button          button;

    window.Open("Hello Window");

    EW_PRINT(EW_APP,EW_LOG,"Hello Text.");

    button.SetLabel("Hello World!");
    button.SetBounds(EW_BOUNDS_FILL_PARENT);

    event_context.AddWindow(&window);
    window.AddWidget(&button);

    event_context.BeginLoop();
    return 0;
    }


FILES

ew/eventcxt.h Event context header file


SEE ALSO

EW_intro(3), EW_Event(3), EW_TimerIntervalList(3), EW_WorkFunction(3) EW_WindowList(3)


NOTES

Under Win32, the clipboard data is actually ready immediately after RequestTextFromClipboard(). The clipboard event is sent almost immediately following. However, to maintain consistancy with X-based operations, you should never depend on CopyTextFromClipboard() or GetClipboardString() immediately after RequestTextFromClipboard(). You should always wait for the clipboard event.