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