Debian Codegraph @

pod/pTk/DoOneEvent.pod

raw
1 # Copyright (c) 1990-1992 The Regents of the University of California.
2 # Copyright (c) 1994-1995 Sun Microsystems, Inc.
3 # See the file "license.terms" for information on usage and redistribution
4 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
5 #
6 # @(#) DoOneEvent.3 1.12 95/05/06 15:29:18
7 #
8
9 =head1 NAME
10
11 Tk_DoOneEvent, Tk_MainLoop, Tk_HandleEvent - wait for events and
12 invoke event handlers
13
14 =for category C Programming
15
16 =head1 SYNOPSIS
17
18 B<#include E<lt>tk.hE<gt>>
19
20 int
21 B<Tk_DoOneEvent>(I<flags>)
22
23 B<Tk_MainLoop>()
24
25 B<Tk_HandleEvent>(I<eventPtr>)
26
27 =head1 ARGUMENTS
28
29 =over 4
30
31 =item int flags (in)
32
33 This parameter is normally zero. It may be an OR-ed combination
34 of any of the following flag bits: TK_X_EVENTS, TK_FILE_EVENTS,
35 TK_TIMER_EVENTS, TK_IDLE_EVENTS, TK_ALL_EVENTS, or TK_DONT_WAIT.
36
37 =item XEvent *eventPtr (in)
38
39 Pointer to X event to dispatch to relevant handler(s).
40
41 =back
42
43 =head1 DESCRIPTION
44
45 These three procedures are responsible for waiting for events
46 and dispatching to event handlers created with the procedures
47 B<Tk_CreateEventHandler>, B<Tk_CreateFileHandler>,
48 B<Tk_CreateTimerHandler>, and B<Tk_DoWhenIdle>.
49 B<Tk_DoOneEvent> is the key procedure. It waits for a single
50 event of any sort to occur, invokes the handler(s) for that
51 event, and then returns. B<Tk_DoOneEvent> first checks
52 for X events and file-related events; if one is found then
53 it calls the handler(s) for the event and returns. If there
54 are no X or file events pending, then B<Tk_DoOneEvent>
55 checks to see if timer callbacks are ready; if so, it
56 makes a single callback and returns. If no timer callbacks
57 are ready, B<Tk_DoOneEvent> checks for B<Tk_DoWhenIdle>
58 callbacks; if any are found, it invokes all of them and returns.
59 Finally, if no events or work have been found, B<Tk_DoOneEvent>
60 sleeps until a timer, file, or X event occurs; then it processes
61 the first event found (in the order given above) and returns.
62 The normal return value is 1 to signify that some event or callback
63 was processed.
64 If no event or callback is processed (under various conditions
65 described below), then 0 is returned.
66
67 If the I<flags> argument to B<Tk_DoOneEvent> is non-zero then
68 it restricts the kinds of events that will be processed by
69 B<Tk_DoOneEvent>.
70 I<Flags> may be an OR-ed combination of any of the following bits:
71
72 =over 4
73
74 =item B<TK_X_EVENTS> -
75
76 Process X events.
77
78 =item B<TK_FILE_EVENTS> -
79
80 Process file events.
81
82 =item B<TK_TIMER_EVENTS> -
83
84 Process timer events.
85
86 =item B<TK_IDLE_EVENTS> -
87
88 Process B<Tk_DoWhenIdle> callbacks.
89
90 =item B<TK_ALL_EVENTS> -
91
92 Process all kinds of events: equivalent to OR-ing together all of the
93 above flags or specifying none of them.
94
95 =item B<TK_DONT_WAIT> -
96
97 Don't sleep: process only events that are ready at the time of the
98 call.
99
100 =back
101
102 If any of the flags B<TK_X_EVENTS>, B<TK_FILE_EVENTS>,
103 B<TK_TIMER_EVENTS>, or B<TK_IDLE_EVENTS> is set, then the only
104 events that will be considered are those for which flags are set.
105 Setting none of these flags is equivalent to the value
106 B<TK_ALL_EVENTS>, which causes all event types to be processed.
107
108 The B<TK_DONT_WAIT> flag causes B<Tk_DoWhenIdle> not to put
109 the process to sleep: it will check for events but if none are found
110 then it returns immediately with a return value of 0 to indicate
111 that no work was done.
112 B<Tk_DoOneEvent> will also return 0 without doing anything if
113 I<flags> is B<TK_IDLE_EVENTS> and there are no
114 B<Tk_DoWhenIdle> callbacks pending.
115 Lastly, B<Tk_DoOneEvent> will return 0 without doing anything
116 if there are no events or work found and if there are no files,
117 displays, or timer handlers to wait for.
118
119 B<Tk_MainLoop> is a procedure that loops repeatedly
120 calling B<Tk_DoOneEvent>. It returns only when there
121 are no applications left in this process (i.e. no main windows
122 exist anymore). Most X applications will
123 call B<Tk_MainLoop> after initialization; the main
124 execution of the application will consist entirely of
125 callbacks invoked by B<Tk_DoOneEvent>.
126
127 B<Tk_HandleEvent> is a lower-level procedure invoked
128 by B<Tk_DoOneEvent>. It makes callbacks to any event
129 handlers (created by calls to B<Tk_CreateEventHandler>)
130 that match I<eventPtr> and then returns. In some cases
131 it may be useful for an application to read events directly
132 from X and dispatch them by calling B<Tk_HandleEvent>,
133 without going through the additional mechanism provided
134 by B<Tk_DoOneEvent>.
135
136 These procedures may be invoked recursively. For example,
137 it is possible to invoke B<Tk_DoOneEvent> recursively
138 from a handler called by B<Tk_DoOneEvent>. This sort
139 of operation is useful in some modal situations, such
140 as when a
141 notifier has been popped up and an application wishes to
142 wait for the user to click a button in the notifier before
143 doing anything else.
144
145 =head1 KEYWORDS
146
147 callback, event, handler, idle, timer