Debian Codegraph @

wdoc/graphInternals.html

raw
1 <HTML>
2
3 <HEAD>
4 <TITLE> ACEDB source code documentation: graph package internals </TITLE>
5
6 <LINK rel=stylesheet type="text/css"
7 href="./wdoc.css"
8 title="Style sheet for wdoc developer documents">
9
10 </HEAD>
11
12 <BODY>
13
14 <H1> Programmers' guide to graph package internals </H1>
15
16
17 <H2>Overview</H2>
18 This document describes various aspects to graph package internals.
19 It is intended to be updated each time some new bit of design is done, some
20 new facility is added, or some old part is better documented. It is meant
21 to be a place where the graph package developer can go and look up how/why
22 bits of the graph package are the way they are. Each design section should have
23 a separate header and be cross referenced to other sections where appropriate.
24
25
26 <H2>The busy cursor</H2>
27 When windows are displayed on the screen we want to be able to tell the user that
28 the application is busy and they should not try to interact with it. The easiest
29 way to do this is to change the mouse pointer (aka 'cursor') to a watch shape, this
30 has become a de-facto standard for saying the application is busy. The original graph
31 package interface was through a single call, <CODE>graphBusyCursorAll</CODE>, which
32 was intended to display a busy cursor on all acedb windows. The intention was that
33 the application code or the graph package could show this cursor when required.
34
35 <P>
36 To avoid the application having to know when to turn cursors on/off the busy cursors
37 were shown every time an Xevent was dispatched, the intention being that an event dispatch
38 would often mean some significant work was being done by the application.
39 This method had two major flaws:
40 <OL>
41 <LI>It meant a large number of extra requests to the server every time
42 an event was dispatched, whether that event resulted in significant work or not.
43 <LI>It did not work properly in that any new window which took a long time to construct
44 would not have a busy cursor because no event processing (and hence no cursor setting)
45 could be done while the window was being constructed.
46 </OL>
47 The excess number of extra requests often resulted in annoying cursor flashing when links
48 between X server & client were slow.
49
50 <P>
51 To get round this problem the way cursors are set on/off was changed.
52
53
54 <H4>The busy cursor implementation</H4>
55 We would like busy cursors to be shown whenever the application has sufficient work to do that
56 it cannot respond to the users interactions. In acedb graphical applications this includes:
57 <UL>
58 <LI>graph creation
59 <LI>potentially all application code callback routines
60 <LI>graph redraw/resize
61 </UL>
62 The obvious places to put busy cursor calls are in the graph creation, redraw, resize routines
63 and in the set of graph routines that deal with events as these routines are the ones that
64 call the applications callback routines. There are several problems with doing this:
65 <OL>
66 <LI>unfortunately there is no one 'layer' of the graph package that contains these calls
67 <LI>more seriously, some of the routines that respond to events then set up another layer
68 of callbacks which will then go on the do the serious work, e.g. the menu routines
69 set up callbacks that will then call the applications callback routines once the user
70 has selected an item from the menu.
71 <LI>sometimes routines start an action that will only be completed some time later by a
72 registered callback (this happens with graph creation).
73 <LI>some application callbacks or graph callbacks are called often and for a very short
74 time so setting a busy cursor would not be appropriate, e.g. in text entry boxes.
75 </OL>
76 Fortunately these problems can be solved in a reasonably satisfactory way, the following sections
77 detail what was done.
78
79 <H4>Graph layers and where to put the calls</H4>
80 Places where busy cursors must be set on/off are restricted to just a few places:
81 <UL>
82 <LI>The routine where a window is created
83 <LI>The points where application callbacks are called, these points are identified
84 by code of the form: <CODE>(*gActive->func[*****])() ;</CODE>, where <CODE>*****</CODE>
85 is the type of callback.
86 <LI>The routines dealing with window redraw/resize
87 </UL>
88 busy cursor calls were added to:
89 <PRE><CODE>
90 w2/graphcon.c: graphCreate
91 w2/graphsub.c: gLeftDown, gMiddleDown,
92 w2/graphxlib.c: graphClipDraw
93 w2/graphxt.c: resizeCall, mouseCall, keyboardCall
94 w2/xtsubs.c: freeMenuSelect, oldMenuSelect
95 </CODE></PRE>
96 Although calls have had to be added at conceptually 3 layers, at least the number
97 of calls is small (11 on/off pairs of busy cursor setting). This exercise reveals that
98 the layering in the graph package has broken down, there is no fixed layer that just
99 contains graph interface calls, the graph interface calls are embedded throughout the
100 graph code.
101
102
103 <H4>Graph creation</H4>
104 Whenever a new graph is built this happens in several phases:
105 <OL>
106 <LI>create graph structures and display a blank window
107 <LI>call an application callback to stack up drawing requests to the window
108 <LI>call the graph redisplay function to actually draw into the window
109 </OL>
110 We want the user to see the cursor go on at the beginning of the phases and go off at the end.
111 In this case we are lucky because all new windows are created by one routine and are drawn
112 by one routine, we can thus turn on the busy cursor in <CODE>graphCreate</CODE> and then
113 turn it off again in <CODE>graphClipDraw</CODE>. In fact in <CODE>graphClipDraw</CODE> the
114 busy cursor is turned and then turned off but no harm is done by turning on the busy cursor
115 twice.
116
117 <H4>Graph resize/redisplay</H4>
118 Both resize and redisplay happen in two phases:
119 <OL>
120 <LI>call an application callback to either recalculate and stack up drawing requests to the window
121 (for a resize), or to do any updating for redisplay
122 <LI>call the graph redisplay/resize function to actually size/draw into the window
123 </OL>
124 These activties happen in just two routines: <CODE>resizeCall, graphClipDraw</CODE>. In fact
125 <CODE>resizeCall</CODE> does not do any drawing, it leaves that to <CODE>graphClipDraw</CODE>,
126 resizing is just a special case of redrawing.
127
128
129 <H4>Setting busy cursors for application callbacks</H4>
130 At first site the obvious place is to put calls in the all of the graph routines that
131 are callback routines for windows (generally called <CODE><B>nnnnn</B>Call</CODE> and
132 mostly defined in <CODE>graphxt.c</CODE>, see the translation tables).
133 But this is not always correct because these routines sometimes just register routines
134 to be called later so showing a busy cursor would be inappropriate:
135 <UL>
136 <LI>in <CODE>pickCall</CODE> and <CODE>middleCall</CODE> the busy cursor needs to be set
137 in routines they call directly
138 <LI><CODE>menuCall</CODE> just posts a menu, it's in the general callback that gets called when
139 when a menu item is selected that we need the busy cursor
140 <LI>in <CODE>mouseCall</CODE> and <CODE>resizeCall</CODE> the busy cursor is set directly the routine
141 </UL>
142 The solution to finding where to put the busy cursor calls was to look for where
143 the application callbacks where actually called from rather than in the graph callbacks
144 themselves. This was easy to do because the application callbacks are all kept in an
145 array called <CODE>func</CODE> which is part of the graph structure. Searching through the
146 code produced a very places where the application callbacks were invoked which all
147 looked like this:
148
149 <PRE><CODE>
150 (*gActive->func[*****])() ;
151 </CODE></PRE>
152
153 All calls like this were bracketed with the calls to turn on/off the busy cursor, e.g.
154
155 <PRE><CODE>
156 if (isResize && gActive->func[RESIZE])
157 {
158 graphBusyCursorAll (TRUE);
159
160 (*gActive->func[RESIZE])() ;
161
162 graphBusyCursorAll (FALSE) ;
163 }
164 </CODE></PRE>
165
166
167 <H4>Dealing with application callbacks that don't need a busy cursor</H4>
168 Some application and graph callbacks should not have a busy cursor associated with them,
169 a good example of this is <CODE>keyboardCall</CODE> in <CODE>graphxt.c</CODE>.
170 We don't really want a busy cursor to shown for every key press, e.g.
171 just typing letters, so no busy cursor should be set in this routine for these key presses.
172 Unfortunately it is not enough to just not
173 do the busy cursor call here because every key press also causes an expose handler to be
174 called, the expose handler calls the redraw code which correctly shows the busy cursor !!
175 To avoid polluting the redraw routine, I've added a call to the busy cursor routines that will
176 make the normal busy cursor call do nothing. This should be used with
177 care and in paired calls to start/stop disabling (as below) otherwise
178 the busy cursor stuff will get completely screwed up. This allows us to selectively stop
179 the normal busy cursor calls from doing anything when needs be:
180 <PRE><CODE>
181 if (kval && gActive->func[KEYBOARD])
182 {
183 if (((keysym >= XK_KP_Space) && (keysym <= XK_KP_9)) /* Keypad keys */
184 || ((keysym >= XK_space) && (keysym <= XK_asciitilde)) /* normal keyboard keys */
185 || keysym == XK_BackSpace || keysym == XK_Delete /* delete keys */
186 || keysym == XK_Left || keysym == XK_Right) /* left/right arrow keys */
187 graphSetBusyCursorInactive(TRUE) ;
188
189 graphBusyCursorAll (TRUE);
190
191 (*gActive->func[KEYBOARD])(kval, modifier) ;
192
193 graphBusyCursorAll (FALSE) ;
194
195 graphSetBusyCursorInactive(FALSE) ;
196 }
197 </CODE></PRE>
198 A caveat to the above code is that the above works because the expose handler is called in between
199 the cursor setting calls, this may not happen for other sections of code and may not even be
200 guaranteed to happen here, careful experimentation is required.
201
202 <P>
203 A more serious caveat to the current implementation of selective busy cursor setting in
204 the keyboard callback is that I have done this generally for <B>ALL</B> keyboard input,
205 assuming that no other part of the code has done something like set a translation for a
206 common letter such as "q" that launches some long running bit of code. If this happened
207 the application would be locked up with a busy cursor. It would be possible to add the busy
208 cursor calls to the text entry routines but this is not nearly so clean.
209
210
211 <H4>Summary</H4>
212 The busy cursor is now only set on and off when the application is doing significant work, it is
213 not set on/off repeatedly as it used to be. Text entry/deletion is now possible without the
214 flickering cursor. The busy cursor calls have only had to be added to the graph package in
215 about 10 places and this is entirely internal to the graph package thus maintaining the system
216 that the application code need not be responsible for this.
217
218
219 </BODY>
220 </HTML>
221
222