| 1 |
'\" |
| 2 |
'\" Copyright (c) 1990-1992 The Regents of the University of California. |
| 3 |
'\" Copyright (c) 1994-1996 Sun Microsystems, Inc. |
| 4 |
'\" |
| 5 |
'\" See the file "license.terms" for information on usage and redistribution |
| 6 |
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 7 |
'\" |
| 8 |
.TH Tcl_DoOneEvent 3 7.5 Tcl "Tcl Library Procedures" |
| 9 |
.so man.macros |
| 10 |
.BS |
| 11 |
.SH NAME |
| 12 |
Tcl_DoOneEvent \- wait for events and invoke event handlers |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
\fB#include <tcl.h>\fR |
| 16 |
.sp |
| 17 |
int |
| 18 |
\fBTcl_DoOneEvent\fR(\fIflags\fR) |
| 19 |
.SH ARGUMENTS |
| 20 |
.AS int flags |
| 21 |
.AP int flags in |
| 22 |
This parameter is normally zero. It may be an OR-ed combination |
| 23 |
of any of the following flag bits: |
| 24 |
\fBTCL_WINDOW_EVENTS\fR, \fBTCL_FILE_EVENTS\fR, |
| 25 |
\fBTCL_TIMER_EVENTS\fR, \fBTCL_IDLE_EVENTS\fR, \fBTCL_ALL_EVENTS\fR, |
| 26 |
or \fBTCL_DONT_WAIT\fR. |
| 27 |
.BE |
| 28 |
|
| 29 |
.SH DESCRIPTION |
| 30 |
.PP |
| 31 |
This procedure is the entry point to Tcl's event loop; it is responsible for |
| 32 |
waiting for events and dispatching event handlers created with |
| 33 |
procedures such as \fBTk_CreateEventHandler\fR, \fBTcl_CreateFileHandler\fR, |
| 34 |
\fBTcl_CreateTimerHandler\fR, and \fBTcl_DoWhenIdle\fR. |
| 35 |
\fBTcl_DoOneEvent\fR checks to see if |
| 36 |
events are already present on the Tcl event queue; if so, |
| 37 |
it calls the handler(s) for the first (oldest) event, removes it from |
| 38 |
the queue, and returns. |
| 39 |
If there are no events ready to be handled, then \fBTcl_DoOneEvent\fR |
| 40 |
checks for new events from all possible sources. |
| 41 |
If any are found, it puts all of them on Tcl's event queue, calls |
| 42 |
handlers for the first event on the queue, and returns. |
| 43 |
If no events are found, \fBTcl_DoOneEvent\fR checks for \fBTcl_DoWhenIdle\fR |
| 44 |
callbacks; if any are found, it invokes all of them and returns. |
| 45 |
Finally, if no events or idle callbacks have been found, then |
| 46 |
\fBTcl_DoOneEvent\fR sleeps until an event occurs; then it adds any |
| 47 |
new events to the Tcl event queue, calls handlers for the first event, |
| 48 |
and returns. |
| 49 |
The normal return value is 1 to signify that some event |
| 50 |
was processed (see below for other alternatives). |
| 51 |
.PP |
| 52 |
If the \fIflags\fR argument to \fBTcl_DoOneEvent\fR is non-zero, |
| 53 |
it restricts the kinds of events that will be processed by |
| 54 |
\fBTcl_DoOneEvent\fR. |
| 55 |
\fIFlags\fR may be an OR-ed combination of any of the following bits: |
| 56 |
.TP 27 |
| 57 |
\fBTCL_WINDOW_EVENTS\fR \- |
| 58 |
Process window system events. |
| 59 |
.TP 27 |
| 60 |
\fBTCL_FILE_EVENTS\fR \- |
| 61 |
Process file events. |
| 62 |
.TP 27 |
| 63 |
\fBTCL_TIMER_EVENTS\fR \- |
| 64 |
Process timer events. |
| 65 |
.TP 27 |
| 66 |
\fBTCL_IDLE_EVENTS\fR \- |
| 67 |
Process idle callbacks. |
| 68 |
.TP 27 |
| 69 |
\fBTCL_ALL_EVENTS\fR \- |
| 70 |
Process all kinds of events: equivalent to OR-ing together all of the |
| 71 |
above flags or specifying none of them. |
| 72 |
.TP 27 |
| 73 |
\fBTCL_DONT_WAIT\fR \- |
| 74 |
Do not sleep: process only events that are ready at the time of the |
| 75 |
call. |
| 76 |
.LP |
| 77 |
If any of the flags \fBTCL_WINDOW_EVENTS\fR, \fBTCL_FILE_EVENTS\fR, |
| 78 |
\fBTCL_TIMER_EVENTS\fR, or \fBTCL_IDLE_EVENTS\fR is set, then the only |
| 79 |
events that will be considered are those for which flags are set. |
| 80 |
Setting none of these flags is equivalent to the value |
| 81 |
\fBTCL_ALL_EVENTS\fR, which causes all event types to be processed. |
| 82 |
If an application has defined additional event sources with |
| 83 |
\fBTcl_CreateEventSource\fR, then additional \fIflag\fR values |
| 84 |
may also be valid, depending on those event sources. |
| 85 |
.PP |
| 86 |
The \fBTCL_DONT_WAIT\fR flag causes \fBTcl_DoOneEvent\fR not to put |
| 87 |
the process to sleep: it will check for events but if none are found |
| 88 |
then it returns immediately with a return value of 0 to indicate |
| 89 |
that no work was done. |
| 90 |
\fBTcl_DoOneEvent\fR will also return 0 without doing anything if |
| 91 |
the only alternative is to block forever (this can happen, for example, |
| 92 |
if \fIflags\fR is \fBTCL_IDLE_EVENTS\fR and there are no |
| 93 |
\fBTcl_DoWhenIdle\fR callbacks pending, or if no event handlers or |
| 94 |
timer handlers exist). |
| 95 |
.PP |
| 96 |
\fBTcl_DoOneEvent\fR may be invoked recursively. For example, |
| 97 |
it is possible to invoke \fBTcl_DoOneEvent\fR recursively |
| 98 |
from a handler called by \fBTcl_DoOneEvent\fR. This sort |
| 99 |
of operation is useful in some modal situations, such |
| 100 |
as when a |
| 101 |
notification dialog has been popped up and an application wishes to |
| 102 |
wait for the user to click a button in the dialog before |
| 103 |
doing anything else. |
| 104 |
|
| 105 |
.SH KEYWORDS |
| 106 |
callback, event, handler, idle, timer |