home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / progut~1 / stdwin.zoo / doc / report.ms < prev   
Encoding:
Text File  |  1989-10-17  |  49.4 KB  |  1,381 lines

  1. .\" Typeset using refer -e -n | (di)troff -ms.
  2. .\" You may have to change the CW (Constant Width) macro define below
  3. .\" if you aren't typesetting on a PostScript printer.
  4. .\" Your best bet is to change ".ft C" by ".ft I" and "\fC" by "\fI".
  5. .\" Each occurs exactly once in the macro definition.
  6. .de CW
  7. .if t .if "\\$1"" .ft C
  8. .if t .if !"\\$1"" \fC\\$1\fP\\$2
  9. .if n .B "\\$1" "\\$2"
  10. ..
  11. .TL
  12. .DA
  13. .nr PD 0
  14. .nr PI 2n
  15. STDWIN \- A Standard Window System Interface
  16. .AU
  17. Guido van Rossum
  18. .AI
  19. Center for Mathematics and Computer Science (CWI)
  20. P.O. Box 4079, 1009 AB Amsterdam, The Netherlands
  21. E-mail: guido@cwi.nl or mcvax!guido
  22. .AB
  23. .LP
  24. STDWIN is an interface layer placed between an application written in C
  25. and arbitrary window system, making the use of windows both easier and
  26. more portable.
  27. For applications using STDWIN
  28. for their window management requirements, adaptation to a
  29. different window system is as easy as linking with an appropriate
  30. version of the STDWIN library.
  31. So far, STDWIN libraries are available
  32. for the Apple Macintosh,
  33. for the Whitechapel MG-1 (running Oriel),
  34. for MIT's X Window System version 11,
  35. for the Atari ST,
  36. and (subsets) for alphanumeric terminals on
  37. .UX
  38. and MS-DOS.
  39. New implementations are easily written.
  40. .PP
  41. Like STDIO, C's Standard I/O library, STDWIN's aim is to give
  42. a simple interface, high-level functionality, and portability.
  43. It does not attempt to allow access to all possible features of window
  44. management systems; rather, it provides the programmer with a
  45. model which allows easy construction of that part of the program which
  46. is concerned with window management.
  47. .PP
  48. STDWIN's high-level operations include automatic window positioning
  49. and resizing, scrolling, menus, keyboard shortcuts, and multiple-click
  50. detection.
  51. .AE
  52. .LP
  53. .NH
  54. Introduction
  55. .LP
  56. First, some history.
  57. STDWIN's conception was motivated by the desire to add a more modern
  58. user interface (i.e., one using windows and a mouse)
  59. to the programming environment for the language ABC,
  60. developed here at CWI.
  61. .[
  62. %A Leo Geurts, Lambert Meertens, Steven Pemberton
  63. %T The ABC Programmer's Handbook
  64. %I CWI
  65. %C Amsterdam
  66. %D to be published in 1988
  67. .]
  68. The ABC programming environment, consisting of a syntax-directed editor,
  69. an interpreter and a source file manager, is a large body of C
  70. code which, through careful isolation of system-dependent modules, has
  71. proven to be quite portable, both to different versions of
  72. .UX
  73. and to non-\c
  74. .UX
  75. systems such as MS-DOS and the Apple Macintosh.
  76. Naturally, we did not want to lose its portability by tying
  77. it closely to one particular window system.
  78. .PP
  79. Only after having looked closely at a few existing window systems, we
  80. became fully aware of the problems.
  81. Most window systems offer a large range of facilities, apparently
  82. intended to enable programmers to create beautiful user interfaces,
  83. but often resulting in total chaos.
  84. .[
  85. %A Mike O'Dell
  86. %B EUUG Conference Proceedings, September 1987, Dublin, Ireland
  87. %T What They Don't Tell You About Window Systems
  88. .]
  89. One of the problems appears to be the low level of most window system
  90. interfaces.
  91. For example, on the Apple Macintosh, all tools are provided to
  92. work with scroll bars (bit-scrolling operations, routines to draw scroll
  93. bars, routines to detect user interaction with a scroll bar), but the
  94. amount of code needed to glue these together and create a scrollable
  95. view on a document is horrendous.
  96. .[
  97. %T Inside Macintosh
  98. %A Apple Computer
  99. %I Addison-Wesley
  100. %C Reading, Mass.
  101. %D 1985
  102. .]
  103. Similarly, again on the Macintosh, double-clicking the mouse button is
  104. a frequent form of user input, but there is no library routine available
  105. to detects double-clicks, leading to much code duplication and
  106. gratuitous differences between programs.*
  107. .FS
  108. * In all fairness it should be said that the Macintosh is still miles
  109. ahead of most of its competitors, simply because there are at least
  110. standards for many aspects of the interaction between application
  111. and user, such as the placement of scroll bars, the use of double clicks
  112. or the shape of the mouse cursor.
  113. .FE
  114. .PP
  115. With these considerations in mind, we set out to design a `generic'
  116. window system interface.
  117. .sp
  118. .IP \(bu
  119. The interface should be general enough to suit the needs of many
  120. different programs.
  121. Thus, it should be reasonably rich in functionality, e.g., provide both
  122. textual and graphical output, handle keyboard, mouse and menu-based
  123. input, support multiple windows, etc.
  124. .IP \(bu
  125. It should be simple to use.
  126. Including one header file and calling a
  127. small number of routines (with not too many parameters!) should suffice
  128. for the creation of a full-function window and the definition of its
  129. contents.
  130. As much as possible, the programmer should only be bothered with issues
  131. that matter from the program's point of view.
  132. In other words, the interface should be `high level'.
  133. .IP \(bu
  134. And most of all, it should be realistically portable; each potential
  135. feature should be weighed in the light of its implementability using
  136. different systems, including several popular micros.
  137. .sp
  138. .LP
  139. The requirement of portability is necessarily both good and bad.
  140. It is bad because it can sometimes make an elegant solution unfeasible,
  141. imposing seemingly random restrictions.
  142. But it is good because it makes the design stick to reality, and limits
  143. it to the `essence' of window systems, rather than allowing the
  144. designers to invent yet another incompatible paradigm.
  145. And sometimes the `helicopter view' gained from looking at
  146. solutions chosen by vastly different window systems for a particular
  147. problem has shown the way to an entirely new view, simplifying it by
  148. generalization.
  149. .sp
  150. .LP
  151. A large part of the paper is devoted to a detailed description of
  152. STDWIN's functionality from a programmer's point of view.
  153. First the `core' of the package is described, explaining the basic
  154. output and input facilities;
  155. then some extra facilities are briefly discussed.
  156. Interspersed are comments on the rationale for particular solutions,
  157. some hints on the implementation, and warnings about non-portable uses.
  158. At the end the paper returns to the more philosophical issues:
  159. experiences, future developments, food for thought.
  160. .NH
  161. Description
  162. .LP
  163. .NH 2
  164. Header file
  165. .LP
  166. Applications wishing to use STDWIN must place a line saying
  167. .CW "#include <stdwin.h>"
  168. near the top of their source file(s).
  169. All user-visible external names defined in this header file start with
  170. .CW w
  171. or
  172. .CW W .
  173. external names used internally by implementations begin with
  174. .CW _w
  175. or
  176. .CW _W .
  177. .NH 2
  178. Initialization and clean-up
  179. .LP
  180. Before starting to use STDWIN, the initialization routine
  181. .CW "winit()"
  182. must be called.
  183. Before exiting, the application should call
  184. .CW "wdone()"
  185. to perform any necessary clean-up operations.
  186. .PP
  187. These calls can't be repeated; after
  188. .CW "wdone()"
  189. has been called the application cannot call
  190. .CW "winit()"
  191. again and `return to life'.
  192. .NH 2
  193. Creating and destroying windows
  194. .LP
  195. A new window is created by calling
  196. .CW "wopen(title, drawproc)" .
  197. .I Title
  198. is a string identifying the window to the user; it is usually displayed
  199. by STDWIN in the window's border, e.g., in a title bar.
  200. .I Drawproc
  201. is the address of the window's draw procedure (see next section), or
  202. NULL if the window is not to have a draw procedure.
  203. STDWIN windows look like windows in the usual style of the underlying
  204. window system, usually with a title bar, scroll bars etc.
  205. Position, size and other characteristics of the new window are
  206. determined by STDWIN (but see below).
  207. .PP
  208. .CW "Wopen"
  209. returns a
  210. .I "window pointer" ,
  211. of type
  212. .CW "WINDOW *" ,
  213. to be used to identify the window in subsequent operations.
  214. If creation of the window failed, a NULL pointer is returned.
  215. .PP
  216. STDWIN allows an application to have multiple windows open simultaneously.
  217. Implementations usually impose a limit on the number of open
  218. windows; when this limit is reached,
  219. .CW "wopen"
  220. returns NULL, and the application should try to close other windows
  221. (or prompt the end user to close them).
  222. .PP
  223. A window is deleted permanently by calling
  224. .CW "wclose(win)" .
  225. Windows can be deleted only by the application.
  226. The end user can send a request to the application to close a window,
  227. but the application may ignore the request or postpone its execution.
  228. .PP
  229. There is no explicit way to iconize
  230. a window (i.e., to temporarily close it, leaving an icon in its place).
  231. On systems where window iconization is built into the window system,
  232. STDWIN may support it silently; all the application notices is that no
  233. input is received for iconized windows.
  234. .NH 3
  235. Changing defaults
  236. .LP
  237. When a window is opened STDWIN determines
  238. a default size and position for it.
  239. Usually this is convenient for the application (which needn't
  240. have its own algorithm for placing multiple windows, for example),
  241. but sometimes finer control is desirable.
  242. Therefore, a number of default-setting routines are provided:
  243. .LP
  244. .CW "wsetdefwinsize(width, height)"
  245. .IP
  246. Changes the default window size.
  247. This sets the net size, excluding borders, scroll bars etc.
  248. .LP
  249. .CW "wsetdefwinpos(h, v)"
  250. .IP
  251. Changes the default window position.
  252. This default is usually not a constant but a dynamically computed value.
  253. The next opened window will be placed at
  254. .I "(h, v)" ;
  255. the position of windows opened after that may be a more complicated
  256. function of
  257. .I h
  258. and
  259. .I v .
  260. .LP
  261. These routines may be called at any time; they affect only windows
  262. opened after their call.
  263. A negative or zero parameter restores the default for that
  264. dimension.
  265. Other values are clipped or rounded to reasonable and implementable
  266. values; these routines are best seen as giving hints to STDWIN, which
  267. may be ignored by some implementations.
  268. .NH 2
  269. The output model
  270. .LP
  271. A STDWIN window is a view on a possibly much larger area,
  272. a rectangle referred to as its
  273. .I document ,
  274. in which the application draws its output.
  275. The document's size is chosen by the application, and can be changed at
  276. any time by calling
  277. .CW "wsetdocsize(win, width, height)" .
  278. It is not limited by window or screen size, nor indeed by available
  279. memory; the entire document's contents are not stored directly.
  280. The end user has the freedom to `pan' the window over the document's
  281. surface, using scroll bars or a similar mechanism.
  282. When a particular part of the document is to be visible in the window,
  283. STDWIN asks the application to repaint that area.
  284. It is not forbidden to draw outside the document, but the end
  285. user normally can't pan outside the document (unless the window is
  286. larger than the document).
  287. .PP
  288. There are two mechanisms for repainting: a low-level mechanism using
  289. DRAW events, and a higher-level mechanism using a
  290. .I "draw procedure" .
  291. .PP
  292. DRAW events are merged with the general event stream (see below); when
  293. no other events are in the event queue, STDWIN looks to see if
  294. there is any window needing a repaint, and if so, it passes a DRAW event
  295. for that window to the application.
  296. A DRAW event includes as additional information the rectangle
  297. that is to be repainted.
  298. The application should react by erasing and repainting that rectangle
  299. (or a larger part of the document).
  300. .PP
  301. Normally, however, windows have an associated
  302. .I "draw procedure" .
  303. This is a procedure (defined by the application) which knows how to draw
  304. the entire document, or any sub-rectangle of it.
  305. When STDWIN is about to generate a DRAW event for a window with a draw
  306. procedure, it prepares the window for drawing, erases the rectangle
  307. that needs repainting, and calls the draw procedure with the window and
  308. the rectangle as parameters.
  309. The advantage of this mechanism over DRAW events is the possibility for
  310. certain STDWIN implementations to clip the output to a smaller,
  311. non-rectangular area that really needs a repaint; also somewhat simpler
  312. event decoding logic for the application.
  313. .PP
  314. Usually, the end user controls which part of the document is visible in
  315. the window (by manipulating the scroll bars).
  316. However, there are times when an application wants to display a particular
  317. part of the document, e.g. to show the effect of a search operation.
  318. It can then call
  319. .CW "wshow(win, <rectangle>)"
  320. to indicate that the given rectangle should be visible, if at all
  321. possible.
  322. STDWIN will check whether this is already the case, and if not, move
  323. the window with respect to the document to make it visible.
  324. There is also a lower-level call,
  325. .CW "wsetorigin(win, <point>)"
  326. which makes the given point in the document the top left corner of the
  327. window.
  328. .PP
  329. When the application wants to change part of the document, it can
  330. directly paint the changes (after preparing for drawing in that
  331. particular window).
  332. However, it is often more appropriate to delay the actual painting until
  333. after other input has been processed.
  334. It is possible to tell STDWIN that a particular area of the document
  335. needs repainting by calling
  336. .CW "wchange(win, <rectangle>)" .
  337. At the appropriate time, a DRAW event for this rectangle (possibly
  338. merged with other areas that need repainting) will be generated, or the
  339. window's draw procedure will be called.
  340. .PP
  341. When the repaint area is non-rectangular (e.g., it is the union of
  342. several rectangles), the application is asked to repaint the smallest
  343. rectangle that encloses the repaint area.
  344. This may occasionally cause more repainting than absolutely necessary,
  345. resulting in extra delays; since the repainting is limited to the window
  346. size, however, the costs won't be excessive in most cases.
  347. The choice was made here for a simple interface to the draw procedure,
  348. avoiding dynamic data structures.
  349. For the needs of the highest-demanding applications, an enquiry routine
  350. returning the exact repaint area may have to be be added
  351. (or a function telling
  352. whether a particular rectangle intersects the repaint area).
  353. .NH 2
  354. Drawing in a document
  355. .NH 3
  356. The coordinate system
  357. .LP
  358. STDWIN provides a single coordinate system per window.
  359. Coordinates are integers, with the X axis pointing right and the Y axis
  360. pointing down.
  361. In order to avoid confusion with other conventions, the axes
  362. are never called X and Y axis but h and v axis.
  363. H coordinates are always listed first.
  364. The origin (0, 0) is the top left corner of the document.
  365. Unit size equals pixel size on the screen; thus, documents inherit the
  366. screen's aspect ratio.
  367. Pixels on different machines can vastly differ in size; e.g.,
  368. on alphanumerical terminals,
  369. pixel size might well equal character cell size.
  370. Therefore, applications should scale their drawings accordingly.
  371. STDWIN provides enquiry functions to tell the physical size of a pixel.
  372. An alternative approach, suitable for applications that display mostly
  373. text, is to scale the drawing accordingly to the dimensions of
  374. characters drawn on the screen.
  375. Text measuring functions are available for this purpose (see below).
  376. .NH 3
  377. Preparation for drawing
  378. .LP
  379. Since a picture is usually built out of a large number of calls to
  380. primitive drawing operations, it would be annoying to have to specify
  381. a window parameter on each call.
  382. STDWIN requires the application to say in which window it wants to
  383. draw before using any drawing primitives, by calling
  384. .CW "wbegin\%draw\%ing(win)" .
  385. After the drawing is done, the application should call
  386. .CW "wend\%draw\%ing(win)" ,
  387. telling STDWIN to flush the output to the screen.
  388. .PP
  389. In a draw procedure these calls are unnecessary; there, all drawing
  390. operations apply to the given window, and output is flushed when the
  391. draw procedure returns.
  392. .NH 3
  393. Graphical primitives
  394. .LP
  395. STDWIN currently provides a small set of graphical primitives.
  396. This set will be extended when the need arises.
  397. All primitives except
  398. .CW werase
  399. and
  400. .CW winvert
  401. draw in OR mode, i.e., they only add black pixels to the drawing
  402. and never erase pixels.
  403. Note that points are actually given as two integer parameters, h and v;
  404. rectangles are given as four integer parameters:
  405. left, top, right and bottom.
  406. Rectangles always refer to the area enclosed by infinitely thin
  407. boundary lines; e.g., the rectangle (0, 0, 1, 1) encloses a 1 by 1
  408. square whose top left corner is the origin (0, 0).
  409. .PP
  410. Functions currently defined are:
  411. .LP
  412. .CW "wdrawline(<point1>, <point2>)"
  413. .IP
  414. Draws a line from point1 to point2.
  415. .LP
  416. .CW "wdrawbox(<rectangle>)"
  417. .IP
  418. Draws a box (i.e., a rectangle) inside the given rectangle.
  419. .LP
  420. .CW "wdrawcircle(<point>, radius)"
  421. .IP
  422. Draws a circle with the specified radius around the given point as
  423. center.
  424. .LP
  425. .CW "wpaint(<rectangle>)"
  426. .IP
  427. Paints the area inside the given rectangle black.
  428. .LP
  429. .CW "werase(<rectangle>)"
  430. .IP
  431. Erases the area inside the given rectangle.
  432. .LP
  433. .CW "winvert(<rectangle>)"
  434. .IP
  435. Inverts the pixels in the given rectangle.
  436. .LP
  437. .CW "wshade(<rectangle>, percentage)"
  438. .IP
  439. Adds a shading pattern to the given rectangle, approximately making the
  440. given percentage of all pixels black.
  441. Thus, a percentage of 0 has no effect;
  442. a percentage of 50 sets every other pixel;
  443. a percentage of 100 is equivalent to
  444. .CW "wpaint(<rectangle)" .
  445. The exact shading pattern used is implementation-dependent, as are the
  446. values to which percentages are rounded.
  447. .NH 3
  448. Text drawing primitives
  449. .LP
  450. STDWIN supports the drawing of characters in a font which may be
  451. proportionally spaced, depending on the implementation.
  452. The exact shape and size of the characters are implementation-dependent.
  453. STDWIN does not use the notion of a `base line' on which characters are
  454. drawn; rather, when a character or string is to be drawn, the top left
  455. corner of the box around it is given.
  456. All boxes have the same height, and a width appropriate for the
  457. character, so characters drawn in adjacent boxes `look right'.
  458. This approach has the advantage that the application needn't be
  459. concerned with such font parameters as base line, ascent, descent and
  460. leading; it can simply start drawing characters at (0, 0) and they
  461. will come out `right'.
  462. (This advantage for simplistic applications may turn into a disadvantage
  463. for programs wishing precise control over the placement of characters.
  464. In that case, additional enquiry functions will have to be defined
  465. to remedy this situation.)
  466. .PP
  467. The call
  468. .CW "wdrawchar(<point>, character)"
  469. draws the given character with its top left corner at the given point.
  470. It returns the h coordinate of the right edge of the box in which the
  471. character is drawn; this is the `natural' h coordinate for a character
  472. to be drawn next to it.
  473. .PP
  474. The call
  475. .CW "wdrawtext(<point>, string, length)"
  476. draws the characters of the given string starting with the top left
  477. corner at the given point.
  478. .I Length
  479. indicates the number of characters in the string;
  480. if negative, the string ends with a NUL character.
  481. .CW Wdrawtext
  482. returns the h coordinate of the right edge of the box in which the
  483. last character is drawn.
  484. Note that no special interpretation is given to characters like
  485. .CW \&'\en'
  486. or
  487. .CW \&'\et' ;
  488. they may be displayed as spaces or funny graphics.
  489. .NH 3
  490. Text measuring primitives
  491. .LP
  492. The dimensions of characters drawn by the above functions depend on the
  493. font used.
  494. Future versions may implement font and size changes under application
  495. control; currently these are fixed by the implementation.
  496. For applications that want to know in advance how big the strings they
  497. are drawing will be, there are functions to measure text dimensions.
  498. Unlike the drawing primitives,
  499. the text measuring primitives and the style-changing primitives
  500. described in the next section can be called anywhere.
  501. .PP
  502. The following text-measuring functions are defined:
  503. .LP
  504. .CW "wlineheight()"
  505. .IP
  506. Gives the vertical height of the boxes in which characters are drawn.
  507. This is the same for all characters, and the value delivered gives a
  508. `natural-looking' line spacing when lines are drawn at v coordinates
  509. with increments of this value.
  510. .LP
  511. .CW "wcharwidth(character)"
  512. .IP
  513. Computes the width of the box in which the given character will be drawn.
  514. .LP
  515. .CW "wtextwidth(string, length)"
  516. .IP
  517. Computes the width of the box in which the string will be drawn.
  518. .I Length
  519. indicates the number of characters in the string;
  520. if negative, the string ends with a NUL character.
  521. .LP
  522. .CW "wtextbreak(string, length, width)"
  523. .IP
  524. Computes the number of characters from the string that will fit in a box
  525. of the given width (in pixels).
  526. .I Length
  527. is interpreted as above.
  528. .NH 3
  529. Text style
  530. .LP
  531. Future versions of STDWIN will have to worry about mixing fonts,
  532. type sizes and text styles.
  533. Currently applications have no control over the font and size used, and
  534. can only control one aspect of text style;
  535. different window systems differ so much
  536. in their support of font names, font scaling, style combinations and so
  537. on, that it seemed wise to avoid these issues in the
  538. first version (however, some implementations have a way to influence
  539. the font, size or style used at initialization time).
  540. The only calls currently available are those to change between normal,
  541. black on white characters and inverse, white on black characters; this
  542. is needed to display the focus in the text-editing package (see below).
  543. .PP
  544. The call
  545. .CW "wsetinverse()"
  546. sets the text style to inverse characters; the call
  547. .CW "wsetplain()"
  548. reverts the text style back to normal.
  549. The text style is a global attribute, so draw procedures that change it
  550. should reset it to normal before leaving.
  551. .NH 3
  552. Scrolling
  553. .LP
  554. Applications like text editors often have a need for deleting a
  555. horizontal or vertical slice from their document; e.g., after a text
  556. editor has deleted a couple of lines, the remaining lines must be moved
  557. up in the document.
  558. Although it is theoretically possible to do this by calling
  559. .CW "wchange"
  560. for the remaining part of the document (assuming the draw procedure
  561. knows that the v coordinates of the affected lines have changed),
  562. this often involves a lot of drawing which could have been avoided by
  563. applying a `bit copy' operation as available in many systems,
  564. combined with only a little bit of redrawing
  565. (e.g., for lines `scrolled in' from below the window border).
  566. .PP
  567. The call
  568. .CW "wscroll(win, <rectangle>, dh, dv)"
  569. is provided to help in situation.
  570. It should be called outside the drawing procedure,
  571. where the call to
  572. .CW wchange
  573. would otherwise be placed.
  574. If the particular STDWIN implementation supports the requested type of
  575. bit scroll operation, it will scroll the bits inside the given
  576. rectangle by an amount of
  577. .I dh
  578. to the right and by
  579. .I dv
  580. downward.
  581. (Negative values mean scrolling to the left or upward, respectively.)
  582. No bits outside the given rectangle are affected or used:
  583. bits `scrolled out' of the rectangle will simply be thrown away; for
  584. the area that is to be `scrolled in' from outside the rectangle,
  585. .CW wchange
  586. is called internally.
  587. If the particular form of bit scrolling required isn't supported,
  588. the entire call is equivalent to
  589. .CW "wchange(win, <rectangle>)" ,
  590. relying on the normal repaint mechanism to update the window.
  591. .NH 2
  592. The input model
  593. .LP
  594. Interactive input is presented to the application in the form of
  595. .I events .
  596. Examples of events are `a character has been typed' or `the mouse button
  597. has been pressed'.
  598. Some other information generated asynchronously by STDWIN is also passed
  599. in the form of events.
  600. .PP
  601. Events are queued internally; the routine
  602. .CW "wgetevent"
  603. gets the next event from the queue and passes it to the application.
  604. If the queue is empty, it waits until an event arrives first.
  605. (Certain events, like DRAW events, are not really queued but constructed
  606. on the fly when the queue is empty.)
  607. .PP
  608. Some applications don't want to wait when no event is ready, but do want
  609. to process events that are already queued.
  610. For such cases there is the alternative routine
  611. .CW "wpollevent"
  612. which acts like
  613. .CW "wgetevent"
  614. when an event is available from the queue, but returns immediately with
  615. a dummy NULL event when the queue is empty.
  616. .PP
  617. An event always applies to a particular window.
  618. This means that an application which has no window open is blind and deaf.
  619. When an application calls
  620. .CW "wgetevent"
  621. in this state, it is terminated.
  622. Therefore, applications should make sure to always open a window before
  623. calling
  624. .CW wgetevent .
  625. .PP
  626. STDWIN implementations may limit the size of the event queue; when the
  627. queue is filled up events may get lost without notification.
  628. (There is no way to prevent this, since the problem usually occurs in
  629. the underlying operating system.)
  630. .NH 2
  631. Events
  632. .LP
  633. Events are typically read in a `main event loop', which might look
  634. something like this:
  635. .DS
  636. .CW
  637. int stop= 0;
  638. while (!stop) {
  639.     EVENT e;
  640.     wgetevent(&e);
  641.     switch (e.type) {
  642.         ...
  643.     }
  644. }
  645. .R
  646. .DE
  647. The variable
  648. .CW e
  649. is called the
  650. .I "event record" .
  651. The information placed in the event record depends on the event type.
  652. For all event types, the type is available as
  653. .CW "e.type" ,
  654. and the window to which the event applies as
  655. .CW "e.window" ;
  656. additional information is listed with the individual event descriptions.
  657. This additional information is stored in a
  658. union named
  659. .CW e.u ,
  660. e.g.,
  661. .CW e.u.character
  662. for character input events.
  663. .PP
  664. For clarity, events are always referred to by their `informal' names in this
  665. paper, e.g., MOUSE DOWN.
  666. The actual constants defined by STDWIN are derived from the informal
  667. name by prepending
  668. .CW WE_
  669. and replacing spaces by underscores, yielding, e.g.,
  670. .CW WE_MOUSE_DOWN .
  671. .PP
  672. Events can be classified as mouse events, other user input events and
  673. STDWIN-generated events.
  674. .NH 3
  675. Mouse events
  676. .LP
  677. Mouse events are generated when the user presses a mouse button inside
  678. the visible part of a document displayed in a window.
  679. There are separate event types for a press of a button, moves while
  680. a button is held down, and a release of a button.
  681. The position of the mouse cursor at the time the event was generated is
  682. reported in (\c
  683. .CW e.u.where.h ,
  684. .CW e.u.where.v ).
  685. The button number
  686. (1, 2 or 3 on a three-button mouse; always 1 on a one-button mouse)
  687. is reported in
  688. .CW e.u.where.button .
  689. .PP
  690. Mouse events allows easy detection of
  691. .I "multiple clicks" ,
  692. to which many applications want to assign a special meaning.
  693. Successive presses on a mouse button are considered to be part of a
  694. click sequence if they are `close together' in space and time.
  695. When a mouse button is pressed, STDWIN checks whether it is close enough
  696. to the previous press to be considered a continuation of the same click
  697. sequence, and if so, notes the number of the current click in
  698. .CW e.u.where.click .
  699. A click that is unrelated to previous clicks has click number 1;
  700. a following related click has click number 2, the next one has number
  701. 3, and so on, until the mouse is moved too far away or the user waits
  702. too long, in which case the click number is reset to 1 at the next
  703. mouse event.
  704. This way of reporting multiple clicks requires no delay to see whether a
  705. click is part of a multiple-click sequence; mouse events are reported as
  706. soon as they happen.
  707. .PP
  708. Not all STDWIN implementations run on machines whose mouse has more than
  709. one button; it is therefore unwise to write an application which can
  710. perform certain operations only through buttons 2 or 3.
  711. If multiple buttons are held down simultaneously, only events for the
  712. button pressed first are generated.
  713. .PP
  714. The mouse event types are
  715. MOUSE DOWN
  716. for a button press,
  717. MOUSE MOVE
  718. for a move of the mouse cursor while a button is still depressed, and
  719. MOUSE UP for a button release.
  720. The click number for MOUSE MOVE events is always zero.
  721. In order to prevent filling up the event queue, multiple MOUSE MOVE
  722. events may be collapsed to a single event, giving only the last mouse
  723. position.
  724. When the user moves the mouse outside the window with a button held
  725. down, the mouse remains associated with the window, and its position is
  726. reported relative to the origin of the window's document.
  727. The click number for a MOUSE UP event is the same as that of the
  728. corresponding MOUSE DOWN event if the mouse wasn't moved too far from
  729. its original position, or zero if it was moved further (and in this case
  730. this event is the end of its click sequence).
  731. .NH 3
  732. Other user input events
  733. .IP CHAR
  734. .br
  735. The user has typed a character at the keyboard.
  736. Its ASCII value is reported in
  737. .CW e.u.character .
  738. Note that some special keys (like RETURN, TAB, BACKSPACE) do not send
  739. CHAR events but COMMAND events.
  740. .IP COMMAND
  741. .br
  742. .RS
  743. This event is sent for special keys on the keyboard, and for certain
  744. special actions recognized by STDWIN.
  745. Some keys do not generate CHAR events but COMMAND events, because they
  746. do not send the same ASCII code on all keyboards (e.g., Enter), or
  747. because there are no standard ASCII codes for them (e.g., arrows and
  748. function keys).
  749. A code telling which special command was meant is reported in
  750. .CW e.u.command .
  751. Possible values represent the following keys and standard actions:
  752. CANCEL, TAB, RETURN, BACKSPACE, LEFT, RIGHT, UP, DOWN and CLOSE; this
  753. list may be extended in the future.
  754. The constants are actually called
  755. .CW WC_CANCEL
  756. etc.
  757. .PP
  758. CLOSE is to be interpreted as a request to close the window; the key
  759. or other action that generates it is system-dependent.
  760. The application should close the window, possibly after verifying that
  761. any changes the user has made to the file displayed in the window have
  762. been saved, in which case it may ignore the request,
  763. or put up a dialogue box asking what should be done to the file.
  764. .RE
  765. .IP MENU
  766. .br
  767. .RS
  768. A menu item was selected.
  769. The menu id and item number of the selected item are reported in
  770. .CW e.u.m.id
  771. and
  772. .CW e.u.m.item ;
  773. menu items are numbered starting at 0
  774. (see below for the definition of menus).
  775. .PP
  776. The interaction technique used to select menu items is not defined by
  777. STDWIN; a suitable technique is chosen by each implementation, e.g.
  778. pop-up, push-down or permanently present menus.
  779. Keyboard shortcuts are usually also available.
  780. The application cannot distinguish between the various ways of selecting
  781. a particular menu item; all it sees is which item is selected.
  782. .RE
  783. .NH 3
  784. STDWIN-generated events
  785. .IP NULL
  786. .br
  787. Nothing happened.
  788. This is a dummy event reported only by
  789. .CW "wpollevent"
  790. when the event queue is empty.
  791. .IP ACTIVATE
  792. .br
  793. A window has been `activated'.
  794. This is usually caused by the end user selecting an inactive window with
  795. the mouse.
  796. Only one window can be active at any time.
  797. This usually means that all subsequent keyboard input applies to
  798. the active window; some applications want to change the highlighting of
  799. selected objects in a document when its window is active.
  800. (Highlighting of the window's title, etc. is done
  801. automatically by STDWIN.)
  802. After a window is opened, the first event applying to it is
  803. usually an ACTIVATE event (because windows are opened in an unactivated
  804. state).
  805. Applications needn't monitor ACTIVATE events if all they want
  806. is determining to which window keyboard input applies; the relevant
  807. window is reported with each event in
  808. .CW e.window .
  809. .IP DEACTIVATE
  810. .br
  811. A window has been `deactivated'.
  812. This usually occurs just before another window is activated.
  813. In many implementations of STDWIN it is possible for the user to
  814. activate a window not belonging to the current application; in this case
  815. the current application receives only a DEACTIVATE event until one of
  816. its windows is reactivated.
  817. Note that closing a window does not generate a DEACTIVATE event for it,
  818. since the window has already disappeared by the time the application can
  819. call
  820. .CW "wgetevent" .
  821. .IP SIZE
  822. .br
  823. .RS
  824. A window's size has changed.
  825. This is usually done by the user explicitly resizing the window;
  826. in some (`tiling') STDWIN implementations it can also be caused by
  827. opening or closing other windows.
  828. .PP
  829. Some applications want to format their documents to fit exactly in the
  830. window.
  831. SIZE events make it possible for such applications to monitor window
  832. size changes.
  833. The new window size is not reported in the event record; the application
  834. can use the enquiry function
  835. .CW wgetwinzize
  836. for this purpose (see below).
  837. .PP
  838. Note that window moves don't generate events
  839. (except possibly DRAW events).
  840. .RE
  841. .IP DRAW
  842. .br
  843. This event is reported only for windows without an associated draw
  844. procedure.
  845. It means that part of the window needs to be repainted.
  846. The smallest rectangle enclosing the area to be repainted is reported in
  847. .CW e.u.area ,
  848. a struct with four fields
  849. .CW left ,
  850. .CW top ,
  851. .CW right
  852. and
  853. .CW bottom .
  854. .IP TIMER
  855. .br
  856. The window's alarm timer has gone off.
  857. For each window, an alarm may be set with the call
  858. .CW "wsettimer(win, dsecs)" .
  859. The alarm will go off, causing a TIMER event,
  860. aproximately
  861. .I dsecs/10
  862. seconds in the future (\c
  863. .I dsecs
  864. meaning deciseconds).
  865. Only one alarm per window is maintained; a new call overrides the
  866. previously set alarm.
  867. A value of 0 cancels the alarm.
  868. Timer values may be rounded up to whole seconds by some implementations.
  869. The maximum timer value that is guaranteed to be supported is
  870. 32000 dsecs.
  871. .NH 2
  872. Pushing events back
  873. .LP
  874. Occasionally, an application may want to postpone processing of an event
  875. till later.
  876. E.g., a subroutine may be getting events in a loop until it
  877. receives an event which shouldn't be handled locally but in the main
  878. event loop.
  879. The routine
  880. .CW "wungetevent(&eventrecord)"
  881. allows an event to be pushed back onto the event queue; the next
  882. call to
  883. .CW wgetevent
  884. or
  885. .CW wpollevent
  886. will report the event just pushed back.
  887. Only a single event can be pushed back (some implementations save the
  888. pushed back event in a separate buffer).
  889. It is possible to modify the event before pushing it back, or to
  890. synthesize events entirely.
  891. .NH 2
  892. Getting and setting the active window
  893. .LP
  894. A pointer to the active window is returned by the function
  895. .CW "wactive()" .
  896. The application can also make a different window active by calling
  897. .CW "wsetactive(win)" .
  898. This call does not take effect immediately; some time in the future, a
  899. DEACTIVATE event for the currently active window and an ACTIVATE event
  900. for the newly activated will be received.
  901. .NH 2
  902. Menus
  903. .LP
  904. Most window systems provide a simple way to set up and manipulate menus,
  905. in their simplest form lists of text strings which can be selected by
  906. the user by clicking on a string with the mouse.
  907. Menus may `pop up' when a particular mouse button is pressed in a
  908. particular screen area, or be `pulled down' from a `menu bar', etc.
  909. STDWIN provides a consistent, simple way for the application to
  910. interface with standard menus, or with menus defined entirely by the
  911. STDWIN library (if the window system provides no usable menus).
  912. .PP
  913. A
  914. .I menu
  915. contains a number of
  916. .I items ,
  917. numbered starting at 0.
  918. A menu has a
  919. .I title ,
  920. a text string displayed to identify the menu to the user, and a
  921. .I "menu id" ,
  922. a small positive integer identifying the menu to the application.
  923. Each item contains a text string, an optional
  924. .I "check mark"
  925. (which may be set by the application to indicate whether an option
  926. controlled by a menu item is active), and can be
  927. .I enabled
  928. or
  929. .I disabled .
  930. Only enabled items are selectable.
  931. When the user selects an enabled item, a MENU event is queued containing
  932. the menu id and item number in the event record.
  933. Because of the way events are queued, it is possible to receive MENU
  934. events for disabled menu items
  935. (if the selection was made before the menu item was disabled);
  936. applications should be prepared to receive spurious menu selection events.
  937. .PP
  938. A menu is created by a call to
  939. .CW "wmenucreate(id, title)" ;
  940. this returns a
  941. .I "menu pointer"
  942. which must be used for all further manipulations with the menu.
  943. .I Id
  944. is the menu id, which should be in the range [1..255].
  945. Menu ids should be unique within an application.
  946. .PP
  947. Initially, a menu contains no items.
  948. Items are added by calling
  949. .CW "wmenuadditem(mp, text, shortcut)" .
  950. The new item's number equals the number of items in the menu before this
  951. call; it is returned as the function value.
  952. .I Mp
  953. is the menu pointer;
  954. .I text
  955. is the item text.
  956. The item is initially enabled and unchecked.
  957. .I Shortcut
  958. is a character used to construct a `keyboard shortcut' for the
  959. menu item; \-1 means the item is not to have a shortcut.
  960. (The interpretation of keyboard shortcuts is implementation-dependent.
  961. In a typical STDWIN implementation,
  962. a menu item with shortcut `X' might be selected by typing ESC-X
  963. or Meta-X (but not Control-X).
  964. All printable characters are acceptable as shortcuts,
  965. but on some systems lower case and upper case are indistinguishable.)
  966. Adding an item with an empty string as text adds a disabled
  967. `separator' item.
  968. .PP
  969. The text of an existing menu item can be changed by calling
  970. .CW "wmenusetitem(mp, number, text)" .
  971. Items can be enabled or disabled by calling
  972. .CW "wmenuenable(mp, number, flag)" .
  973. The check mark for an item can be set or cleared by calling
  974. .CW "wmenucheck(mp, number, flag)" .
  975. .PP
  976. A menu can be deleted by calling
  977. .CW "wmenudelete(mp)" .
  978. Note that individual menu items, once added, cannot be removed, nor can
  979. new items be inserted in the middle.
  980. This is due to restrictions in many window systems' menu interfaces;
  981. usually menus are sufficiently static that it doesn't matter.
  982. .PP
  983. For a menu's items to be selectable, the menu must be attached to a
  984. window and the window must be activated.
  985. Normally, STDWIN automatically attaches all menus to all windows, so all
  986. menus become selectable as soon as the first window is activated.
  987. To change this behaviour, the call
  988. .CW "wmenusetdeflocal(TRUE)"
  989. causes subsequently created menus to be `local', requiring
  990. explicit attachment and detachment.
  991. The call
  992. .CW "wmenuattach(win, mp)"
  993. attaches the menu
  994. .I mp
  995. to the window
  996. .I win .
  997. The call
  998. .CW "wmenudetach(win, mp)"
  999. reverses this effect.
  1000. A menu may be attached to multiple windows; multiple menus may be
  1001. attached to a window.
  1002. After calling
  1003. .CW "wmenusetdeflocal(FALSE)" ,
  1004. future menus will be `global' again, i.e., automatically attached to all
  1005. (existing and new) windows.
  1006. .NH
  1007. Additional facilities
  1008. .LP
  1009. .NH 2
  1010. Enquiry functions
  1011. .LP
  1012. Some enquiry functions are available to interrogate the system state.
  1013. .LP
  1014. .CW "wgetscrsize(&width, &height)"
  1015. .IP
  1016. Returns the screen size measured in pixels into the integer variables
  1017. whose addresses are passed.
  1018. .LP
  1019. .CW "wgetscrmm(&mmwidth, &mmheight)"
  1020. .IP
  1021. Returns the approximate screen size measured in millimeters.
  1022. By combining this information with the outcome of
  1023. .CW wgetscrsize ,
  1024. pixel size and aspect ratio can conveniently be computed.
  1025. In some (most?) implementations, the numbers returned may be
  1026. approximations or guesses.
  1027. .LP
  1028. .CW "wgetwinsize(win, &width, &height)"
  1029. .IP
  1030. Returns the size of the drawable area of a window, measured in pixels.
  1031. (Due to the presence of borders, a maximally-sized window is usually
  1032. smaller than the screen.)
  1033. .NH 2
  1034. The text caret
  1035. .LP
  1036. In documents that deal with text it is often useful to have some form of
  1037. `text cursor', indicating the position where characters typed at the
  1038. keyboard will be inserted.
  1039. The call
  1040. .CW "wsetcaret(win, h, v)"
  1041. causes a `caret' to appear just to the left of the character
  1042. position (\c
  1043. .I h ,
  1044. .I v )
  1045. in the document.
  1046. The caret appears immediately before any character that
  1047. would be drawn by
  1048. .CW "wdrawtext(h, v, ...)" .
  1049. The caret has a system-defined shape; it is often a blinking vertical
  1050. bar.
  1051. .PP
  1052. Each window has its own caret; the caret in the active window may be
  1053. the only one that is visible, or it may blink while the carets in other
  1054. windows are static.
  1055. At any time a window has at most one caret; the old caret is removed
  1056. when a new one is specified.
  1057. The caret can be removed altogether with the call
  1058. .CW "wnocaret(win)" .
  1059. .NH 2
  1060. Dialogue tools
  1061. .LP
  1062. A
  1063. .I "dialogue box"
  1064. is a `mini-window' containing a simple message or question,
  1065. and requiring
  1066. the user to respond, e.g. by pressing a key or clicking the mouse in a
  1067. particular area.
  1068. As long as the dialogue box is present, the application is blocked.
  1069. After answering the question or acknowledging the message, the dialogue
  1070. box disappears and normal interaction with the application continues.
  1071. Dialogue boxes may be presented even when no windows are open yet.
  1072. The following calls put up dialogue boxes and wait for a response:
  1073. .sp
  1074. .LP
  1075. .CW "wmessage(string)"
  1076. .IP
  1077. Displays a message and waits until the user acknowledges it.
  1078. The precise form of acknowledgement required
  1079. is implementation-dependent;
  1080. it could be pressing the Return key or clicking an `OK button' with the
  1081. mouse.
  1082. .LP
  1083. .CW "waskstr(question, replybuf, buflength)"
  1084. .IP
  1085. Displays a question and waits until the user has finished typing a
  1086. reply.
  1087. The initial contents of the reply buffer are used as a default reply.
  1088. The function normally returns TRUE; if the user aborts the dialogue
  1089. (e.g., by pressing the CANCEL button) it returns FALSE.
  1090. .LP
  1091. .CW "waskync(question, dflt)"
  1092. .IP
  1093. Displays a question which gives the user the possibility to answer with
  1094. Yes, No or Cancel only.
  1095. The return value is 1 (Yes), 0 (No) or -1 (Cancel).
  1096. .I Dflt
  1097. is the suggested (default) return value.
  1098. .LP
  1099. .CW "waskfile(prompt, replybuf, buflength, new)"
  1100. .IP
  1101. Displays a dialogue box asking for a file name.
  1102. .I Replybuf
  1103. initially contains a default or suggested file name.
  1104. The boolean parameter
  1105. .I new
  1106. specifies whether a new (not yet existing) or old (existing) file is
  1107. required.
  1108. When a new file is asked for, the user may specify an existing file,
  1109. but in this case explicit permission is asked to overwrite it.
  1110. The function returns TRUE, or FALSE if the user aborts the dialogue.
  1111. The file name is returned in a form acceptable to the STDIO function
  1112. .CW fopen .
  1113. STDWIN implementations may provide additional support, e.g. file name
  1114. completion or file system browsing; the fact that some systems provide
  1115. elaborate standard file-selection dialogues (which is highly appreciated
  1116. by the end users) was a strong motivation to include this function in
  1117. STDWIN.
  1118. .LP
  1119. .CW "wperror(string)"
  1120. .IP
  1121. Displays an error message similar to that printed by the standard C
  1122. function
  1123. .I perror (3),
  1124. and waits for an acknowledgement as for
  1125. .CW wmessage .
  1126. .sp
  1127. .LP
  1128. It should be noted that
  1129. .CW "waskstr"
  1130. is the most general of the above functions; in theory, versions of the
  1131. others can be implemented with the help of
  1132. .CW "waskstr"
  1133. and other existing tools.
  1134. .NH 2
  1135. The text-editing package
  1136. .LP
  1137. The
  1138. .I text-editing
  1139. package is a set of routines implemented entirely `on top of' STDWIN,
  1140. without using any implementation-dependent functions or data structures.
  1141. The availability of this package
  1142. is important because it provides a standard way to tackle the
  1143. non-trivial problem of editing multi-line text blocks.
  1144. It is clearly influenced by the TextEdit routines available in the Apple
  1145. Macintosh's ROM Toolbox (but contains only original code).
  1146. .PP
  1147. The text-editing package displays a paragraph of text in a rectangle of
  1148. a given width, breaking the lines at spaces between words as necessary.
  1149. It gives the application complete control over what happens to the text,
  1150. but provides an easy way to handle user input intended to edit it.
  1151. .PP
  1152. The call
  1153. .CW "tecreate(win, <rectangle>)"
  1154. returns a pointer to a text-editing block at the specified position in
  1155. the given window's document.
  1156. (A text-editing block is not a portion of the document but a data
  1157. structure.)
  1158. Any number of text-editing blocks may be created, although usually at
  1159. most one block per window should be editable at any time.
  1160. .PP
  1161. Initially, the block contains no text.
  1162. The call
  1163. .CW "tesettext(tp, string)"
  1164. sets the text to be edited, replacing any existing text in the block.
  1165. The call
  1166. .CW "tegettext(tp)"
  1167. returns a pointer to the text string (which remains valid only until the
  1168. next call to a text-editing routine).
  1169. .PP
  1170. The text block is not automatically drawn.
  1171. When a text-editing routine changes the edited text (or other aspects of
  1172. its appearance), it calls
  1173. .CW wchange
  1174. for the appropriate area of the window; the window's draw procedure
  1175. should call
  1176. .CW "tedraw(tp)"
  1177. for each block which overlaps the repaint area.
  1178. .PP
  1179. Besides the edited string, a text-editing block contains a
  1180. .I focus ,
  1181. indicating which text is selected
  1182. for deletion or at which position new text will be inserted.
  1183. The focus can be set by the application with the call
  1184. .CW "tesetfocus(tp, first, last)" ,
  1185. telling that the characters in the range [first..last-1] are selected,
  1186. or, if first equals last, that the text insertion point is at that
  1187. position (characters are counted starting at 0).
  1188. If the focus is an insert position, the window's caret is set at that
  1189. position in the document.
  1190. Text can be inserted at the focus (replacing its previous contents) by
  1191. calling
  1192. .CW "tereplace(tp, string)" ;
  1193. specifying an empty string deletes any text in the focus.
  1194. .PP
  1195. The simplest way to let the user edit the text in a text-editing block
  1196. is to call
  1197. .CW "teevent(tp, &event\%record)"
  1198. for each event.
  1199. This call returns TRUE if the event is applicable to the text-editing
  1200. block (e.g., it is a CHAR event, or a mouse click within the block's
  1201. bounding rectangle), and in that case the event is processed by the
  1202. text-editing package (e.g., a character is inserted, or the focus is
  1203. moved to the point where the mouse was clicked).
  1204. If the event is not applicable to the particular block, the function
  1205. does nothing and returns FALSE; in this case the application should
  1206. further decide what to do to the event.
  1207. Of course, the application is free to decide whether to offer an event
  1208. to a text-editing block at all; e.g., it might have a different
  1209. interpretation for the Return key (for which the text-editing package
  1210. inserts a new-line character in the text string).
  1211. .PP
  1212. There are more text-editing calls, e.g. to move a text-editing block to
  1213. a new position, to enquire about the focus, to perform individual
  1214. editing operations, to ask for the height of the rectangle minimally
  1215. needed to display the text entirely, etc.
  1216. .PP
  1217. The following call displays a text string in exactly the same way as
  1218. the text-editing package would do (breaking it into lines at the same
  1219. places, etc.), but without creating a text-editing block, and thus
  1220. without a focus:
  1221. .CW "wdrawpar(<point>, string, width)" .
  1222. It returns the v coordinate of the bottom of the text paragraph.
  1223. To compute the height of a text paragraph thus drawn without actually
  1224. drawing it, one can call
  1225. .CW "wparheight(string, width)" .
  1226. .NH
  1227. A complete example
  1228. .LP
  1229. The program below is a complete STDWIN application.
  1230. It is presented here to give a feel for the use of some of the routines
  1231. described above.
  1232. The program displays a window in which a text-edit block is placed;
  1233. all events recognized by the text-edit package are handled correctly,
  1234. and so are several ways of quitting.
  1235. Other events are ignored.
  1236. .if t .sp .5v
  1237. .DS L
  1238. .CW
  1239. #include <stdwin.h>
  1240.  
  1241. TEXTEDIT *tp; /* Global so drawproc can reference it */
  1242.  
  1243. void drawproc(w, left, top, right, bottom)
  1244.     WINDOW *w;
  1245.     int left, top, right, bottom;
  1246. {
  1247.     tedraw(tp);
  1248. }
  1249. .R
  1250. .DE
  1251. .DS L
  1252. .CW
  1253. main()
  1254. {
  1255.     MENU *m;
  1256.     WINDOW *w;
  1257.     int stop;
  1258.     int width, height;
  1259. .R
  1260. .DE
  1261. .DS L
  1262. .CW
  1263.     winit();
  1264.     
  1265.     m= wmenucreate(1, "Sample");
  1266.     wmenuadditem(m, "Quit", 'Q'); /* Item 0 */
  1267.     
  1268.     w= wopen("Sample window", drawproc);
  1269.     wgetwinsize(w, &width, &height);
  1270.     tp= tecreate(w, 0, 0, width, height);
  1271. .R
  1272. .DE
  1273. .DS L
  1274. .CW
  1275.     stop= 0;
  1276.     while (!stop) {
  1277.         EVENT e;
  1278.         wgetevent(&e);
  1279.         if (teevent(tp, &e))
  1280.             wsetdocsize(w, width, tegetbottom(tp));
  1281.         else {
  1282.             switch (e.type) {
  1283.             case WE_COMMAND:
  1284.                 if (e.u.command == WC_CLOSE || e.u.command == WC_CANCEL)
  1285.                     stop= 1;
  1286.                 break;
  1287.             case WE_MENU:
  1288.                 if (e.u.m.id == 1 && e.u.m.item == 0) /* Quit */
  1289.                     stop= 1;
  1290.                 break;
  1291.             }
  1292.         }
  1293.     }
  1294. .R
  1295. .DE
  1296. .DS L
  1297. .CW
  1298.     wclose(w);
  1299.     wdone();
  1300.     exit(0);
  1301. }
  1302. .R
  1303. .DE
  1304. .if t .sp -.5v
  1305. .NH
  1306. Experiences
  1307. .LP
  1308. Five distinct STDWIN implementations have been created so far:
  1309. for the Apple Macintosh,
  1310. for the Whitechapel MG-1,
  1311. for X version 11,
  1312. for the Atari ST,
  1313. and a subset for alphanumeric displays
  1314. (which runs both under Unix and MS-DOS).
  1315. .PP
  1316. Once a STDWIN version for a target system is available,
  1317. application portability is high.
  1318. Most portability problems that crop up
  1319. (besides the usual problems like word size, byte order,
  1320. data alignment or following NULL pointers)
  1321. have to do with differences in other parts of the operating system
  1322. interface, e.g. use of the file system.
  1323. One portability problem encountered with the STDWIN interface was that
  1324. some programs developed for alphanumeric terminals expected a
  1325. fixed-width font; in general most problems were caused by insufficiently
  1326. precise specification of STDWIN.
  1327. .PP
  1328. The time needed to create a STDWIN version for a particular target
  1329. system is moderate.
  1330. An experienced C programmer who did not know anything about STDWIN or
  1331. the Atari ST in advance
  1332. created a working Atari ST version in two months.
  1333. So far, each version has been created more or less from scratch
  1334. (except for the common parts like the textedit package).
  1335. We have now gained enough experience with different target systems to be
  1336. able to create an intermediate layer containing code which remains more
  1337. or less constant between target systems.
  1338. .NH
  1339. Future developments
  1340. .LP
  1341. To date, the applications that use STDWIN have been mostly text-based.
  1342. Undoubtedly, this has influenced the direction of development of drawing
  1343. facilities in STDWIN.
  1344. It is sufficiently easy to add graphical primitives to an
  1345. implementation, though, that we expect to add several as demand grows,
  1346. e.g., bitblt, clipping, line styles, filling.
  1347. The existing facilities set a sort of standard for the form of future
  1348. ones.
  1349. The requirement that they be implementable on top of a large variety of
  1350. window systems will ensure that only more or less generally accepted
  1351. primitives will be included in STDWIN; a useful sort of conservatism for
  1352. a package that wants to enhance application portability.
  1353. .PP
  1354. Besides the need to add more drawing primitives, there are several areas
  1355. where STDWIN requires, and will probably get, extensions: fonts, sizes
  1356. and styles; the mouse cursor; drawing in off-screen bitmaps (not
  1357. associated with a window); error handling (which is currently virtually
  1358. absent); event queue manipulations and an `event mask'; `clipboard' or
  1359. `cut buffer' operations.
  1360. .PP
  1361. A development in a different direction, independent of the addition of
  1362. graphical primitives, may be the addition of more toolboxes built on
  1363. top of the exiting facilities, like the text editing package.
  1364. Tools are needed
  1365. to manipulate higher-order graphical objects,
  1366. to implement specific interaction techniques,
  1367. to provide `canned applications' like text-editing windows,
  1368. etc.
  1369. .PP
  1370. A third, potentially very useful, extension would be the addition of
  1371. drawable
  1372. `borders' to the window that aren't scrolled together with the document.
  1373. In such borders, interaction tools could be placed like palettes and
  1374. buttons, or rulers around the document.
  1375. The design of such an extension should be the topic of further research,
  1376. in order to achieve the largest possible generality.
  1377. .\" Filter troff input through refer -e -n
  1378. .[
  1379. $LIST$
  1380. .]
  1381.