home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2963 < prev    next >
Internet Message Format  |  1991-03-04  |  55KB

  1. From: guido@cwi.nl (Guido van Rossum)
  2. Newsgroups: alt.sources
  3. Subject: STDWIN 0.9.5, Part 02/19
  4. Message-ID: <3066@charon.cwi.nl>
  5. Date: 4 Mar 91 11:57:33 GMT
  6.  
  7. Archive-name: stdwin/part02
  8.  
  9. #! /bin/sh
  10. # This is a shell archive.  Remove anything before this line, then unpack
  11. # it by saving it into a file and typing "sh file".  To overwrite existing
  12. # files, type "sh file -c".  You can also feed this as standard input via
  13. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  14. # will see the following message at the end:
  15. #        "End of archive 2 (of 19)."
  16. # Contents:  Doc/paper.ms Ports/mac/pstring.c
  17. # Wrapped by guido@voorn.cwi.nl on Mon Mar  4 12:37:23 1991
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. if test -f 'Doc/paper.ms' -a "${1}" != "-c" ; then 
  20.   echo shar: Will not clobber existing file \"'Doc/paper.ms'\"
  21. else
  22. echo shar: Extracting \"'Doc/paper.ms'\" \(51068 characters\)
  23. sed "s/^X//" >'Doc/paper.ms' <<'END_OF_FILE'
  24. X.\" Typeset using refer -e -n | (di)troff -ms.
  25. X.\" You may have to change the CW (Constant Width) macro define below
  26. X.\" if you aren't typesetting on a PostScript printer.
  27. X.\" Your best bet is to change ".ft C" by ".ft I" and "\fC" by "\fI".
  28. X.\" Each occurs exactly once in the macro definition.
  29. X.de CW
  30. X.if t .if "\\$1"" .ft C
  31. X.if t .if !"\\$1"" \fC\\$1\fP\\$2
  32. X.if n .B "\\$1" "\\$2"
  33. X..
  34. X.TL
  35. X.nr PD 0
  36. X.nr PI 2n
  37. X.ft H
  38. X.ps 14
  39. XSTDWIN \- A Standard Window System Interface
  40. X.ps
  41. X.ft
  42. X.AU
  43. X.ft H
  44. XGuido van Rossum
  45. X.ft
  46. X.AI
  47. X.ft HO
  48. X.ps 8
  49. X.vs 10
  50. XCenter for Mathematics and Computer Science
  51. XP.O. Box 4079, 1009 AB Amsterdam, The Netherlands
  52. XE-mail: guido@cwi.nl or mcvax!guido
  53. X.vs
  54. X.ps
  55. X.ft
  56. X.AB
  57. X.LP
  58. XSTDWIN is an interface layer placed between an application written in C
  59. Xand arbitrary window system, making the use of windows both easier and
  60. Xmore portable.
  61. XFor applications using STDWIN
  62. Xfor their window management requirements, adaptation to a
  63. Xdifferent window system is as easy as linking with an appropriate
  64. Xversion of the STDWIN library.
  65. XSo far, STDWIN libraries are available
  66. Xfor the Apple Macintosh,
  67. Xfor the Whitechapel MG-1 (running Oriel),
  68. Xfor MIT's X Window System version 11,
  69. Xfor the Atari ST,
  70. Xand (subsets) for alphanumeric terminals on
  71. X.UX
  72. Xand MS-DOS.
  73. X.FS
  74. X.ft H
  75. X.sp
  76. XReport CS-R8817
  77. X.br
  78. XCentre for Mathematics and Computer Science
  79. X.br
  80. XP.O. Box 4079, 1009 AB Amsterdam, The Netherlands
  81. X.ft
  82. X.FE
  83. XNew implementations are easily written.
  84. X.PP
  85. XLike STDIO, C's Standard I/O library, STDWIN's aim is to give
  86. Xa simple interface, high-level functionality, and portability.
  87. XIt does not attempt to allow access to all possible features of window
  88. Xmanagement systems; rather, it provides the programmer with a
  89. Xmodel which allows easy construction of that part of the program which
  90. Xis concerned with window management.
  91. X.PP
  92. XSTDWIN's high-level operations include automatic window positioning
  93. Xand resizing, scrolling, menus, keyboard shortcuts, and multiple-click
  94. Xdetection.
  95. X.sp
  96. X.ps 8
  97. X.vs 10
  98. X.ft HO
  99. X1980 Mathematics Subject Classification:
  100. X.ft
  101. X.ft H
  102. X68B20.
  103. X.ft
  104. X.br
  105. X.ft HO
  106. X1982 CR Categories:
  107. X.ft
  108. X.ft H
  109. XD.2.2, I.3.4, I.3.6.
  110. X.ft
  111. X.br
  112. X.ft HO
  113. XKey Words & Phrases:
  114. X.ft
  115. X.ft H
  116. Xwindow systems, user interfaces, portability.
  117. X.ft
  118. X.br
  119. X.ft HO
  120. XNote:
  121. X.ft
  122. X.ft H
  123. XThis paper has been submitted for publication elsewhere.
  124. X.ft
  125. X.vs
  126. X.ps
  127. X.AE
  128. X.LP
  129. X.NH
  130. XIntroduction
  131. X.LP
  132. XFirst, some history.
  133. XSTDWIN's conception was motivated by the desire to add a more modern
  134. Xuser interface (i.e., one using windows and a mouse)
  135. Xto the programming environment for the language ABC,
  136. Xdeveloped here at CWI.
  137. X.[
  138. X%A Leo Geurts, Lambert Meertens, Steven Pemberton
  139. X%T The ABC Programmer's Handbook
  140. X%I CWI
  141. X%C Amsterdam
  142. X%D to be published in 1988
  143. X.]
  144. XThe ABC programming environment, consisting of a syntax-directed editor,
  145. Xan interpreter and a source file manager, is a large body of C
  146. Xcode which, through careful isolation of system-dependent modules, has
  147. Xproven to be quite portable, both to different versions of
  148. X.UX
  149. Xand to non-\c
  150. X.UX
  151. Xsystems such as MS-DOS and the Apple Macintosh.
  152. XNaturally, we did not want to lose its portability by tying
  153. Xit closely to one particular window system.
  154. X.PP
  155. XOnly after having looked closely at a few existing window systems, we
  156. Xbecame fully aware of the problems.
  157. XMost window systems offer a large range of facilities, apparently
  158. Xintended to enable programmers to create beautiful user interfaces,
  159. Xbut often resulting in total chaos.
  160. X.[
  161. X%A Mike O'Dell
  162. X%B EUUG Conference Proceedings, September 1987, Dublin, Ireland
  163. X%T What They Don't Tell You About Window Systems
  164. X.]
  165. XOne of the problems appears to be the low level of most window system
  166. Xinterfaces.
  167. XFor example, on the Apple Macintosh, all tools are provided to
  168. Xwork with scroll bars (bit-scrolling operations, routines to draw scroll
  169. Xbars, routines to detect user interaction with a scroll bar), but the
  170. Xamount of code needed to glue these together and create a scrollable
  171. Xview on a document is horrendous.
  172. X.[
  173. X%T Inside Macintosh
  174. X%A Apple Computer
  175. X%I Addison-Wesley
  176. X%C Reading, Mass.
  177. X%D 1985
  178. X.]
  179. XSimilarly, again on the Macintosh, double-clicking the mouse button is
  180. Xa frequent form of user input, but there is no library routine available
  181. Xto detects double-clicks, leading to much code duplication and
  182. Xgratuitous differences between programs.*
  183. X.FS
  184. X* In all fairness it should be said that the Macintosh is still miles
  185. Xahead of most of its competitors, simply because there are at least
  186. Xstandards for many aspects of the interaction between application
  187. Xand user, such as the placement of scroll bars, the use of double clicks
  188. Xor the shape of the mouse cursor.
  189. X.FE
  190. X.PP
  191. XWith these considerations in mind, we set out to design a `generic'
  192. Xwindow system interface.
  193. X.sp
  194. X.IP \(bu
  195. XThe interface should be general enough to suit the needs of many
  196. Xdifferent programs.
  197. XThus, it should be reasonably rich in functionality, e.g., provide both
  198. Xtextual and graphical output, handle keyboard, mouse and menu-based
  199. Xinput, support multiple windows, etc.
  200. X.IP \(bu
  201. XIt should be simple to use.
  202. XIncluding one header file and calling a
  203. Xsmall number of routines (with not too many parameters!) should suffice
  204. Xfor the creation of a full-function window and the definition of its
  205. Xcontents.
  206. XAs much as possible, the programmer should only be bothered with issues
  207. Xthat matter from the program's point of view.
  208. XIn other words, the interface should be `high level'.
  209. X.IP \(bu
  210. XAnd most of all, it should be realistically portable; each potential
  211. Xfeature should be weighed in the light of its implementability using
  212. Xdifferent systems, including several popular micros.
  213. X.sp
  214. X.LP
  215. XThe requirement of portability is necessarily both good and bad.
  216. XIt is bad because it can sometimes make an elegant solution unfeasible,
  217. Ximposing seemingly random restrictions.
  218. XBut it is good because it makes the design stick to reality, and limits
  219. Xit to the `essence' of window systems, rather than allowing the
  220. Xdesigners to invent yet another incompatible paradigm.
  221. XAnd sometimes the `helicopter view' gained from looking at
  222. Xsolutions chosen by vastly different window systems for a particular
  223. Xproblem has shown the way to an entirely new view, simplifying it by
  224. Xgeneralization.
  225. X.sp
  226. X.LP
  227. XA large part of the paper is devoted to a detailed description of
  228. XSTDWIN's functionality from a programmer's point of view.
  229. XFirst the `core' of the package is described, explaining the basic
  230. Xoutput and input facilities;
  231. Xthen some extra facilities are briefly discussed.
  232. XInterspersed are comments on the rationale for particular solutions,
  233. Xsome hints on the implementation, and warnings about non-portable uses.
  234. XAt the end the paper returns to the more philosophical issues:
  235. Xexperiences, future developments, food for thought.
  236. X.NH
  237. XDescription
  238. X.LP
  239. X.NH 2
  240. XHeader file
  241. X.LP
  242. XApplications wishing to use STDWIN must place a line saying
  243. X.CW "#include <stdwin.h>"
  244. Xnear the top of their source file(s).
  245. XAll user-visible external names defined in this header file start with
  246. X.CW w
  247. Xor
  248. X.CW W .
  249. Xexternal names used internally by implementations begin with
  250. X.CW _w
  251. Xor
  252. X.CW _W .
  253. X.NH 2
  254. XInitialization and clean-up
  255. X.LP
  256. XBefore starting to use STDWIN, the initialization routine
  257. X.CW "winit()"
  258. Xmust be called.
  259. XBefore exiting, the application should call
  260. X.CW "wdone()"
  261. Xto perform any necessary clean-up operations.
  262. X.PP
  263. XThese calls can't be repeated; after
  264. X.CW "wdone()"
  265. Xhas been called the application cannot call
  266. X.CW "winit()"
  267. Xagain and `return to life'.
  268. X.NH 2
  269. XCreating and destroying windows
  270. X.LP
  271. XA new window is created by calling
  272. X.CW "wopen(title, drawproc)" .
  273. X.I Title
  274. Xis a string identifying the window to the user; it is usually displayed
  275. Xby STDWIN in the window's border, e.g., in a title bar.
  276. X.I Drawproc
  277. Xis the address of the window's draw procedure (see next section), or
  278. XNULL if the window is not to have a draw procedure.
  279. XSTDWIN windows look like windows in the usual style of the underlying
  280. Xwindow system, usually with a title bar, scroll bars etc.
  281. XPosition, size and other characteristics of the new window are
  282. Xdetermined by STDWIN (but see below).
  283. X.PP
  284. X.CW "Wopen"
  285. Xreturns a
  286. X.I "window pointer" ,
  287. Xof type
  288. X.CW "WINDOW *" ,
  289. Xto be used to identify the window in subsequent operations.
  290. XIf creation of the window failed, a NULL pointer is returned.
  291. X.PP
  292. XSTDWIN allows an application to have multiple windows open simultaneously.
  293. XImplementations usually impose a limit on the number of open
  294. Xwindows; when this limit is reached,
  295. X.CW "wopen"
  296. Xreturns NULL, and the application should try to close other windows
  297. X(or prompt the end user to close them).
  298. X.PP
  299. XA window is deleted permanently by calling
  300. X.CW "wclose(win)" .
  301. XWindows can be deleted only by the application.
  302. XThe end user can send a request to the application to close a window,
  303. Xbut the application may ignore the request or postpone its execution.
  304. X.PP
  305. XThere is no explicit way to iconize
  306. Xa window (i.e., to temporarily close it, leaving an icon in its place).
  307. XOn systems where window iconization is built into the window system,
  308. XSTDWIN may support it silently; all the application notices is that no
  309. Xinput is received for iconized windows.
  310. X.NH 3
  311. XChanging defaults
  312. X.LP
  313. XWhen a window is opened STDWIN determines
  314. Xa default size and position for it.
  315. XUsually this is convenient for the application (which needn't
  316. Xhave its own algorithm for placing multiple windows, for example),
  317. Xbut sometimes finer control is desirable.
  318. XTherefore, a number of default-setting routines are provided:
  319. X.LP
  320. X.CW "wsetdefwinsize(width, height)"
  321. X.IP
  322. XChanges the default window size.
  323. XThis sets the net size, excluding borders, scroll bars etc.
  324. X.LP
  325. X.CW "wsetdefwinpos(h, v)"
  326. X.IP
  327. XChanges the default window position.
  328. XThis default is usually not a constant but a dynamically computed value.
  329. XThe next opened window will be placed at
  330. X.I "(h, v)" ;
  331. Xthe position of windows opened after that may be a more complicated
  332. Xfunction of
  333. X.I h
  334. Xand
  335. X.I v .
  336. X.LP
  337. XThese routines may be called at any time; they affect only windows
  338. Xopened after their call.
  339. XA negative or zero parameter restores the default for that
  340. Xdimension.
  341. XOther values are clipped or rounded to reasonable and implementable
  342. Xvalues; these routines are best seen as giving hints to STDWIN, which
  343. Xmay be ignored by some implementations.
  344. X.NH 2
  345. XThe output model
  346. X.LP
  347. XA STDWIN window is a view on a possibly much larger area,
  348. Xa rectangle referred to as its
  349. X.I document ,
  350. Xin which the application draws its output.
  351. XThe document's size is chosen by the application, and can be changed at
  352. Xany time by calling
  353. X.CW "wsetdocsize(win, width, height)" .
  354. XIt is not limited by window or screen size, nor indeed by available
  355. Xmemory; the entire document's contents are not stored directly.
  356. XThe end user has the freedom to `pan' the window over the document's
  357. Xsurface, using scroll bars or a similar mechanism.
  358. XWhen a particular part of the document is to be visible in the window,
  359. XSTDWIN asks the application to repaint that area.
  360. XIt is not forbidden to draw outside the document, but the end
  361. Xuser normally can't pan outside the document (unless the window is
  362. Xlarger than the document).
  363. X.PP
  364. XThere are two mechanisms for repainting: a low-level mechanism using
  365. XDRAW events, and a higher-level mechanism using a
  366. X.I "draw procedure" .
  367. X.PP
  368. XDRAW events are merged with the general event stream (see below); when
  369. Xno other events are in the event queue, STDWIN looks to see if
  370. Xthere is any window needing a repaint, and if so, it passes a DRAW event
  371. Xfor that window to the application.
  372. XA DRAW event includes as additional information the rectangle
  373. Xthat is to be repainted.
  374. XThe application should react by erasing and repainting that rectangle
  375. X(or a larger part of the document).
  376. X.PP
  377. XNormally, however, windows have an associated
  378. X.I "draw procedure" .
  379. XThis is a procedure (defined by the application) which knows how to draw
  380. Xthe entire document, or any sub-rectangle of it.
  381. XWhen STDWIN is about to generate a DRAW event for a window with a draw
  382. Xprocedure, it prepares the window for drawing, erases the rectangle
  383. Xthat needs repainting, and calls the draw procedure with the window and
  384. Xthe rectangle as parameters.
  385. XThe advantage of this mechanism over DRAW events is the possibility for
  386. Xcertain STDWIN implementations to clip the output to a smaller,
  387. Xnon-rectangular area that really needs a repaint; also somewhat simpler
  388. Xevent decoding logic for the application.
  389. X.PP
  390. XUsually, the end user controls which part of the document is visible in
  391. Xthe window (by manipulating the scroll bars).
  392. XHowever, there are times when an application wants to display a particular
  393. Xpart of the document, e.g. to show the effect of a search operation.
  394. XIt can then call
  395. X.CW "wshow(win, <rectangle>)"
  396. Xto indicate that the given rectangle should be visible, if at all
  397. Xpossible.
  398. XSTDWIN will check whether this is already the case, and if not, move
  399. Xthe window with respect to the document to make it visible.
  400. XThere is also a lower-level call,
  401. X.CW "wsetorigin(win, <point>)"
  402. Xwhich makes the given point in the document the top left corner of the
  403. Xwindow.
  404. X.PP
  405. XWhen the application wants to change part of the document, it can
  406. Xdirectly paint the changes (after preparing for drawing in that
  407. Xparticular window).
  408. XHowever, it is often more appropriate to delay the actual painting until
  409. Xafter other input has been processed.
  410. XIt is possible to tell STDWIN that a particular area of the document
  411. Xneeds repainting by calling
  412. X.CW "wchange(win, <rectangle>)" .
  413. XAt the appropriate time, a DRAW event for this rectangle (possibly
  414. Xmerged with other areas that need repainting) will be generated, or the
  415. Xwindow's draw procedure will be called.
  416. X.PP
  417. XWhen the repaint area is non-rectangular (e.g., it is the union of
  418. Xseveral rectangles), the application is asked to repaint the smallest
  419. Xrectangle that encloses the repaint area.
  420. XThis may occasionally cause more repainting than absolutely necessary,
  421. Xresulting in extra delays; since the repainting is limited to the window
  422. Xsize, however, the costs won't be excessive in most cases.
  423. XThe choice was made here for a simple interface to the draw procedure,
  424. Xavoiding dynamic data structures.
  425. XFor the needs of the highest-demanding applications, an enquiry routine
  426. Xreturning the exact repaint area may have to be be added
  427. X(or a function telling
  428. Xwhether a particular rectangle intersects the repaint area).
  429. X.NH 2
  430. XDrawing in a document
  431. X.NH 3
  432. XThe coordinate system
  433. X.LP
  434. XSTDWIN provides a single coordinate system per window.
  435. XCoordinates are integers, with the X axis pointing right and the Y axis
  436. Xpointing down.
  437. XIn order to avoid confusion with other conventions, the axes
  438. Xare never called X and Y axis but h and v axis.
  439. XH coordinates are always listed first.
  440. XThe origin (0, 0) is the top left corner of the document.
  441. XUnit size equals pixel size on the screen; thus, documents inherit the
  442. Xscreen's aspect ratio.
  443. XPixels on different machines can vastly differ in size; e.g.,
  444. Xon alphanumerical terminals,
  445. Xpixel size might well equal character cell size.
  446. XTherefore, applications should scale their drawings accordingly.
  447. XSTDWIN provides enquiry functions to tell the physical size of a pixel.
  448. XAn alternative approach, suitable for applications that display mostly
  449. Xtext, is to scale the drawing accordingly to the dimensions of
  450. Xcharacters drawn on the screen.
  451. XText measuring functions are available for this purpose (see below).
  452. X.NH 3
  453. XPreparation for drawing
  454. X.LP
  455. XSince a picture is usually built out of a large number of calls to
  456. Xprimitive drawing operations, it would be annoying to have to specify
  457. Xa window parameter on each call.
  458. XSTDWIN requires the application to say in which window it wants to
  459. Xdraw before using any drawing primitives, by calling
  460. X.CW "wbegin\%draw\%ing(win)" .
  461. XAfter the drawing is done, the application should call
  462. X.CW "wend\%draw\%ing(win)" ,
  463. Xtelling STDWIN to flush the output to the screen.
  464. X.PP
  465. XIn a draw procedure these calls are unnecessary; there, all drawing
  466. Xoperations apply to the given window, and output is flushed when the
  467. Xdraw procedure returns.
  468. X.NH 3
  469. XGraphical primitives
  470. X.LP
  471. XSTDWIN currently provides a small set of graphical primitives.
  472. XThis set will be extended when the need arises.
  473. XAll primitives except
  474. X.CW werase
  475. Xand
  476. X.CW winvert
  477. Xdraw in OR mode, i.e., they only add black pixels to the drawing
  478. Xand never erase pixels.
  479. XNote that points are actually given as two integer parameters, h and v;
  480. Xrectangles are given as four integer parameters:
  481. Xleft, top, right and bottom.
  482. XRectangles always refer to the area enclosed by infinitely thin
  483. Xboundary lines; e.g., the rectangle (0, 0, 1, 1) encloses a 1 by 1
  484. Xsquare whose top left corner is the origin (0, 0).
  485. X.PP
  486. XFunctions currently defined are:
  487. X.LP
  488. X.CW "wdrawline(<point1>, <point2>)"
  489. X.IP
  490. XDraws a line from point1 to point2.
  491. X.LP
  492. X.CW "wdrawbox(<rectangle>)"
  493. X.IP
  494. XDraws a box (i.e., a rectangle) inside the given rectangle.
  495. X.LP
  496. X.CW "wdrawcircle(<point>, radius)"
  497. X.IP
  498. XDraws a circle with the specified radius around the given point as
  499. Xcenter.
  500. X.LP
  501. X.CW "wpaint(<rectangle>)"
  502. X.IP
  503. XPaints the area inside the given rectangle black.
  504. X.LP
  505. X.CW "werase(<rectangle>)"
  506. X.IP
  507. XErases the area inside the given rectangle.
  508. X.LP
  509. X.CW "winvert(<rectangle>)"
  510. X.IP
  511. XInverts the pixels in the given rectangle.
  512. X.LP
  513. X.CW "wshade(<rectangle>, percentage)"
  514. X.IP
  515. XAdds a shading pattern to the given rectangle, approximately making the
  516. Xgiven percentage of all pixels black.
  517. XThus, a percentage of 0 has no effect;
  518. Xa percentage of 50 sets every other pixel;
  519. Xa percentage of 100 is equivalent to
  520. X.CW "wpaint(<rectangle)" .
  521. XThe exact shading pattern used is implementation-dependent, as are the
  522. Xvalues to which percentages are rounded.
  523. X.NH 3
  524. XText drawing primitives
  525. X.LP
  526. XSTDWIN supports the drawing of characters in a font which may be
  527. Xproportionally spaced, depending on the implementation.
  528. XThe exact shape and size of the characters are implementation-dependent.
  529. XSTDWIN does not use the notion of a `base line' on which characters are
  530. Xdrawn; rather, when a character or string is to be drawn, the top left
  531. Xcorner of the box around it is given.
  532. XAll boxes have the same height, and a width appropriate for the
  533. Xcharacter, so characters drawn in adjacent boxes `look right'.
  534. XThis approach has the advantage that the application needn't be
  535. Xconcerned with such font parameters as base line, ascent, descent and
  536. Xleading; it can simply start drawing characters at (0, 0) and they
  537. Xwill come out `right'.
  538. X(This advantage for simplistic applications may turn into a disadvantage
  539. Xfor programs wishing precise control over the placement of characters.
  540. XIn that case, additional enquiry functions will have to be defined
  541. Xto remedy this situation.)
  542. X.PP
  543. XThe call
  544. X.CW "wdrawchar(<point>, character)"
  545. Xdraws the given character with its top left corner at the given point.
  546. XIt returns the h coordinate of the right edge of the box in which the
  547. Xcharacter is drawn; this is the `natural' h coordinate for a character
  548. Xto be drawn next to it.
  549. X.PP
  550. XThe call
  551. X.CW "wdrawtext(<point>, string, length)"
  552. Xdraws the characters of the given string starting with the top left
  553. Xcorner at the given point.
  554. X.I Length
  555. Xindicates the number of characters in the string;
  556. Xif negative, the string ends with a NUL character.
  557. X.CW Wdrawtext
  558. Xreturns the h coordinate of the right edge of the box in which the
  559. Xlast character is drawn.
  560. XNote that no special interpretation is given to characters like
  561. X.CW \&'\en'
  562. Xor
  563. X.CW \&'\et' ;
  564. Xthey may be displayed as spaces or funny graphics.
  565. X.NH 3
  566. XText measuring primitives
  567. X.LP
  568. XThe dimensions of characters drawn by the above functions depend on the
  569. Xfont used.
  570. XFuture versions may implement font and size changes under application
  571. Xcontrol; currently these are fixed by the implementation.
  572. XFor applications that want to know in advance how big the strings they
  573. Xare drawing will be, there are functions to measure text dimensions.
  574. XUnlike the drawing primitives,
  575. Xthe text measuring primitives and the style-changing primitives
  576. Xdescribed in the next section can be called anywhere.
  577. X.PP
  578. XThe following text-measuring functions are defined:
  579. X.LP
  580. X.CW "wlineheight()"
  581. X.IP
  582. XGives the vertical height of the boxes in which characters are drawn.
  583. XThis is the same for all characters, and the value delivered gives a
  584. X`natural-looking' line spacing when lines are drawn at v coordinates
  585. Xwith increments of this value.
  586. X.LP
  587. X.CW "wcharwidth(character)"
  588. X.IP
  589. XComputes the width of the box in which the given character will be drawn.
  590. X.LP
  591. X.CW "wtextwidth(string, length)"
  592. X.IP
  593. XComputes the width of the box in which the string will be drawn.
  594. X.I Length
  595. Xindicates the number of characters in the string;
  596. Xif negative, the string ends with a NUL character.
  597. X.LP
  598. X.CW "wtextbreak(string, length, width)"
  599. X.IP
  600. XComputes the number of characters from the string that will fit in a box
  601. Xof the given width (in pixels).
  602. X.I Length
  603. Xis interpreted as above.
  604. X.NH 3
  605. XText style
  606. X.LP
  607. XFuture versions of STDWIN will have to worry about mixing fonts,
  608. Xtype sizes and text styles.
  609. XCurrently applications have no control over the font and size used, and
  610. Xcan only control one aspect of text style;
  611. Xdifferent window systems differ so much
  612. Xin their support of font names, font scaling, style combinations and so
  613. Xon, that it seemed wise to avoid these issues in the
  614. Xfirst version (however, some implementations have a way to influence
  615. Xthe font, size or style used at initialization time).
  616. XThe only calls currently available are those to change between normal,
  617. Xblack on white characters and inverse, white on black characters; this
  618. Xis needed to display the focus in the text-editing package (see below).
  619. X.PP
  620. XThe call
  621. X.CW "wsetinverse()"
  622. Xsets the text style to inverse characters; the call
  623. X.CW "wsetplain()"
  624. Xreverts the text style back to normal.
  625. XThe text style is a global attribute, so draw procedures that change it
  626. Xshould reset it to normal before leaving.
  627. X.NH 3
  628. XScrolling
  629. X.LP
  630. XApplications like text editors often have a need for deleting a
  631. Xhorizontal or vertical slice from their document; e.g., after a text
  632. Xeditor has deleted a couple of lines, the remaining lines must be moved
  633. Xup in the document.
  634. XAlthough it is theoretically possible to do this by calling
  635. X.CW "wchange"
  636. Xfor the remaining part of the document (assuming the draw procedure
  637. Xknows that the v coordinates of the affected lines have changed),
  638. Xthis often involves a lot of drawing which could have been avoided by
  639. Xapplying a `bit copy' operation as available in many systems,
  640. Xcombined with only a little bit of redrawing
  641. X(e.g., for lines `scrolled in' from below the window border).
  642. X.PP
  643. XThe call
  644. X.CW "wscroll(win, <rectangle>, dh, dv)"
  645. Xis provided to help in situation.
  646. XIt should be called outside the drawing procedure,
  647. Xwhere the call to
  648. X.CW wchange
  649. Xwould otherwise be placed.
  650. XIf the particular STDWIN implementation supports the requested type of
  651. Xbit scroll operation, it will scroll the bits inside the given
  652. Xrectangle by an amount of
  653. X.I dh
  654. Xto the right and by
  655. X.I dv
  656. Xdownward.
  657. X(Negative values mean scrolling to the left or upward, respectively.)
  658. XNo bits outside the given rectangle are affected or used:
  659. Xbits `scrolled out' of the rectangle will simply be thrown away; for
  660. Xthe area that is to be `scrolled in' from outside the rectangle,
  661. X.CW wchange
  662. Xis called internally.
  663. XIf the particular form of bit scrolling required isn't supported,
  664. Xthe entire call is equivalent to
  665. X.CW "wchange(win, <rectangle>)" ,
  666. Xrelying on the normal repaint mechanism to update the window.
  667. X.NH 2
  668. XThe input model
  669. X.LP
  670. XInteractive input is presented to the application in the form of
  671. X.I events .
  672. XExamples of events are `a character has been typed' or `the mouse button
  673. Xhas been pressed'.
  674. XSome other information generated asynchronously by STDWIN is also passed
  675. Xin the form of events.
  676. X.PP
  677. XEvents are queued internally; the routine
  678. X.CW "wgetevent"
  679. Xgets the next event from the queue and passes it to the application.
  680. XIf the queue is empty, it waits until an event arrives first.
  681. X(Certain events, like DRAW events, are not really queued but constructed
  682. Xon the fly when the queue is empty.)
  683. X.PP
  684. XSome applications don't want to wait when no event is ready, but do want
  685. Xto process events that are already queued.
  686. XFor such cases there is the alternative routine
  687. X.CW "wpollevent"
  688. Xwhich acts like
  689. X.CW "wgetevent"
  690. Xwhen an event is available from the queue, but returns immediately with
  691. Xa dummy NULL event when the queue is empty.
  692. X.PP
  693. XAn event always applies to a particular window.
  694. XThis means that an application which has no window open is blind and deaf.
  695. XWhen an application calls
  696. X.CW "wgetevent"
  697. Xin this state, it is terminated.
  698. XTherefore, applications should make sure to always open a window before
  699. Xcalling
  700. X.CW wgetevent .
  701. X.PP
  702. XSTDWIN implementations may limit the size of the event queue; when the
  703. Xqueue is filled up events may get lost without notification.
  704. X(There is no way to prevent this, since the problem usually occurs in
  705. Xthe underlying operating system.)
  706. X.NH 2
  707. XEvents
  708. X.LP
  709. XEvents are typically read in a `main event loop', which might look
  710. Xsomething like this:
  711. X.DS
  712. X.CW
  713. Xint stop= 0;
  714. Xwhile (!stop) {
  715. X    EVENT e;
  716. X    wgetevent(&e);
  717. X    switch (e.type) {
  718. X        ...
  719. X    }
  720. X}
  721. X.R
  722. X.DE
  723. XThe variable
  724. X.CW e
  725. Xis called the
  726. X.I "event record" .
  727. XThe information placed in the event record depends on the event type.
  728. XFor all event types, the type is available as
  729. X.CW "e.type" ,
  730. Xand the window to which the event applies as
  731. X.CW "e.window" ;
  732. Xadditional information is listed with the individual event descriptions.
  733. XThis additional information is stored in a
  734. Xunion named
  735. X.CW e.u ,
  736. Xe.g.,
  737. X.CW e.u.character
  738. Xfor character input events.
  739. X.PP
  740. XFor clarity, events are always referred to by their `informal' names in this
  741. Xpaper, e.g., MOUSE DOWN.
  742. XThe actual constants defined by STDWIN are derived from the informal
  743. Xname by prepending
  744. X.CW WE_
  745. Xand replacing spaces by underscores, yielding, e.g.,
  746. X.CW WE_MOUSE_DOWN .
  747. X.PP
  748. XEvents can be classified as mouse events, other user input events and
  749. XSTDWIN-generated events.
  750. X.NH 3
  751. XMouse events
  752. X.LP
  753. XMouse events are generated when the user presses a mouse button inside
  754. Xthe visible part of a document displayed in a window.
  755. XThere are separate event types for a press of a button, moves while
  756. Xa button is held down, and a release of a button.
  757. XThe position of the mouse cursor at the time the event was generated is
  758. Xreported in (\c
  759. X.CW e.u.where.h ,
  760. X.CW e.u.where.v ).
  761. XThe button number
  762. X(1, 2 or 3 on a three-button mouse; always 1 on a one-button mouse)
  763. Xis reported in
  764. X.CW e.u.where.button .
  765. X.PP
  766. XMouse events allows easy detection of
  767. X.I "multiple clicks" ,
  768. Xto which many applications want to assign a special meaning.
  769. XSuccessive presses on a mouse button are considered to be part of a
  770. Xclick sequence if they are `close together' in space and time.
  771. XWhen a mouse button is pressed, STDWIN checks whether it is close enough
  772. Xto the previous press to be considered a continuation of the same click
  773. Xsequence, and if so, notes the number of the current click in
  774. X.CW e.u.where.click .
  775. XA click that is unrelated to previous clicks has click number 1;
  776. Xa following related click has click number 2, the next one has number
  777. X3, and so on, until the mouse is moved too far away or the user waits
  778. Xtoo long, in which case the click number is reset to 1 at the next
  779. Xmouse event.
  780. XThis way of reporting multiple clicks requires no delay to see whether a
  781. Xclick is part of a multiple-click sequence; mouse events are reported as
  782. Xsoon as they happen.
  783. X.PP
  784. XNot all STDWIN implementations run on machines whose mouse has more than
  785. Xone button; it is therefore unwise to write an application which can
  786. Xperform certain operations only through buttons 2 or 3.
  787. XIf multiple buttons are held down simultaneously, only events for the
  788. Xbutton pressed first are generated.
  789. X.PP
  790. XThe mouse event types are
  791. XMOUSE DOWN
  792. Xfor a button press,
  793. XMOUSE MOVE
  794. Xfor a move of the mouse cursor while a button is still depressed, and
  795. XMOUSE UP for a button release.
  796. XThe click number for MOUSE MOVE events is always zero.
  797. XIn order to prevent filling up the event queue, multiple MOUSE MOVE
  798. Xevents may be collapsed to a single event, giving only the last mouse
  799. Xposition.
  800. XWhen the user moves the mouse outside the window with a button held
  801. Xdown, the mouse remains associated with the window, and its position is
  802. Xreported relative to the origin of the window's document.
  803. XThe click number for a MOUSE UP event is the same as that of the
  804. Xcorresponding MOUSE DOWN event if the mouse wasn't moved too far from
  805. Xits original position, or zero if it was moved further (and in this case
  806. Xthis event is the end of its click sequence).
  807. X.NH 3
  808. XOther user input events
  809. X.IP CHAR
  810. X.br
  811. XThe user has typed a character at the keyboard.
  812. XIts ASCII value is reported in
  813. X.CW e.u.character .
  814. XNote that some special keys (like RETURN, TAB, BACKSPACE) do not send
  815. XCHAR events but COMMAND events.
  816. X.IP COMMAND
  817. X.br
  818. X.RS
  819. XThis event is sent for special keys on the keyboard, and for certain
  820. Xspecial actions recognized by STDWIN.
  821. XSome keys do not generate CHAR events but COMMAND events, because they
  822. Xdo not send the same ASCII code on all keyboards (e.g., Enter), or
  823. Xbecause there are no standard ASCII codes for them (e.g., arrows and
  824. Xfunction keys).
  825. XA code telling which special command was meant is reported in
  826. X.CW e.u.command .
  827. XPossible values represent the following keys and standard actions:
  828. XCANCEL, TAB, RETURN, BACKSPACE, LEFT, RIGHT, UP, DOWN and CLOSE; this
  829. Xlist may be extended in the future.
  830. XThe constants are actually called
  831. X.CW WC_CANCEL
  832. Xetc.
  833. X.PP
  834. XCLOSE is to be interpreted as a request to close the window; the key
  835. Xor other action that generates it is system-dependent.
  836. XThe application should close the window, possibly after verifying that
  837. Xany changes the user has made to the file displayed in the window have
  838. Xbeen saved, in which case it may ignore the request,
  839. Xor put up a dialogue box asking what should be done to the file.
  840. X.RE
  841. X.IP MENU
  842. X.br
  843. X.RS
  844. XA menu item was selected.
  845. XThe menu id and item number of the selected item are reported in
  846. X.CW e.u.m.id
  847. Xand
  848. X.CW e.u.m.item ;
  849. Xmenu items are numbered starting at 0
  850. X(see below for the definition of menus).
  851. X.PP
  852. XThe interaction technique used to select menu items is not defined by
  853. XSTDWIN; a suitable technique is chosen by each implementation, e.g.
  854. Xpop-up, push-down or permanently present menus.
  855. XKeyboard shortcuts are usually also available.
  856. XThe application cannot distinguish between the various ways of selecting
  857. Xa particular menu item; all it sees is which item is selected.
  858. X.RE
  859. X.NH 3
  860. XSTDWIN-generated events
  861. X.IP NULL
  862. X.br
  863. XNothing happened.
  864. XThis is a dummy event reported only by
  865. X.CW "wpollevent"
  866. Xwhen the event queue is empty.
  867. X.IP ACTIVATE
  868. X.br
  869. XA window has been `activated'.
  870. XThis is usually caused by the end user selecting an inactive window with
  871. Xthe mouse.
  872. XOnly one window can be active at any time.
  873. XThis usually means that all subsequent keyboard input applies to
  874. Xthe active window; some applications want to change the highlighting of
  875. Xselected objects in a document when its window is active.
  876. X(Highlighting of the window's title, etc. is done
  877. Xautomatically by STDWIN.)
  878. XAfter a window is opened, the first event applying to it is
  879. Xusually an ACTIVATE event (because windows are opened in an unactivated
  880. Xstate).
  881. XApplications needn't monitor ACTIVATE events if all they want
  882. Xis determining to which window keyboard input applies; the relevant
  883. Xwindow is reported with each event in
  884. X.CW e.window .
  885. X.IP DEACTIVATE
  886. X.br
  887. XA window has been `deactivated'.
  888. XThis usually occurs just before another window is activated.
  889. XIn many implementations of STDWIN it is possible for the user to
  890. Xactivate a window not belonging to the current application; in this case
  891. Xthe current application receives only a DEACTIVATE event until one of
  892. Xits windows is reactivated.
  893. XNote that closing a window does not generate a DEACTIVATE event for it,
  894. Xsince the window has already disappeared by the time the application can
  895. Xcall
  896. X.CW "wgetevent" .
  897. X.IP SIZE
  898. X.br
  899. X.RS
  900. XA window's size has changed.
  901. XThis is usually done by the user explicitly resizing the window;
  902. Xin some (`tiling') STDWIN implementations it can also be caused by
  903. Xopening or closing other windows.
  904. X.PP
  905. XSome applications want to format their documents to fit exactly in the
  906. Xwindow.
  907. XSIZE events make it possible for such applications to monitor window
  908. Xsize changes.
  909. XThe new window size is not reported in the event record; the application
  910. Xcan use the enquiry function
  911. X.CW wgetwinzize
  912. Xfor this purpose (see below).
  913. X.PP
  914. XNote that window moves don't generate events
  915. X(except possibly DRAW events).
  916. X.RE
  917. X.IP DRAW
  918. X.br
  919. XThis event is reported only for windows without an associated draw
  920. Xprocedure.
  921. XIt means that part of the window needs to be repainted.
  922. XThe smallest rectangle enclosing the area to be repainted is reported in
  923. X.CW e.u.area ,
  924. Xa struct with four fields
  925. X.CW left ,
  926. X.CW top ,
  927. X.CW right
  928. Xand
  929. X.CW bottom .
  930. X.IP TIMER
  931. X.br
  932. XThe window's alarm timer has gone off.
  933. XFor each window, an alarm may be set with the call
  934. X.CW "wsettimer(win, dsecs)" .
  935. XThe alarm will go off, causing a TIMER event,
  936. Xaproximately
  937. X.I dsecs/10
  938. Xseconds in the future (\c
  939. X.I dsecs
  940. Xmeaning deciseconds).
  941. XOnly one alarm per window is maintained; a new call overrides the
  942. Xpreviously set alarm.
  943. XA value of 0 cancels the alarm.
  944. XTimer values may be rounded up to whole seconds by some implementations.
  945. XThe maximum timer value that is guaranteed to be supported is
  946. X32000 dsecs.
  947. X.NH 2
  948. XPushing events back
  949. X.LP
  950. XOccasionally, an application may want to postpone processing of an event
  951. Xtill later.
  952. XE.g., a subroutine may be getting events in a loop until it
  953. Xreceives an event which shouldn't be handled locally but in the main
  954. Xevent loop.
  955. XThe routine
  956. X.CW "wungetevent(&eventrecord)"
  957. Xallows an event to be pushed back onto the event queue; the next
  958. Xcall to
  959. X.CW wgetevent
  960. Xor
  961. X.CW wpollevent
  962. Xwill report the event just pushed back.
  963. XOnly a single event can be pushed back (some implementations save the
  964. Xpushed back event in a separate buffer).
  965. XIt is possible to modify the event before pushing it back, or to
  966. Xsynthesize events entirely.
  967. X.NH 2
  968. XGetting and setting the active window
  969. X.LP
  970. XA pointer to the active window is returned by the function
  971. X.CW "wactive()" .
  972. XThe application can also make a different window active by calling
  973. X.CW "wsetactive(win)" .
  974. XThis call does not take effect immediately; some time in the future, a
  975. XDEACTIVATE event for the currently active window and an ACTIVATE event
  976. Xfor the newly activated will be received.
  977. X.NH 2
  978. XMenus
  979. X.LP
  980. XMost window systems provide a simple way to set up and manipulate menus,
  981. Xin their simplest form lists of text strings which can be selected by
  982. Xthe user by clicking on a string with the mouse.
  983. XMenus may `pop up' when a particular mouse button is pressed in a
  984. Xparticular screen area, or be `pulled down' from a `menu bar', etc.
  985. XSTDWIN provides a consistent, simple way for the application to
  986. Xinterface with standard menus, or with menus defined entirely by the
  987. XSTDWIN library (if the window system provides no usable menus).
  988. X.PP
  989. XA
  990. X.I menu
  991. Xcontains a number of
  992. X.I items ,
  993. Xnumbered starting at 0.
  994. XA menu has a
  995. X.I title ,
  996. Xa text string displayed to identify the menu to the user, and a
  997. X.I "menu id" ,
  998. Xa small positive integer identifying the menu to the application.
  999. XEach item contains a text string, an optional
  1000. X.I "check mark"
  1001. X(which may be set by the application to indicate whether an option
  1002. Xcontrolled by a menu item is active), and can be
  1003. X.I enabled
  1004. Xor
  1005. X.I disabled .
  1006. XOnly enabled items are selectable.
  1007. XWhen the user selects an enabled item, a MENU event is queued containing
  1008. Xthe menu id and item number in the event record.
  1009. XBecause of the way events are queued, it is possible to receive MENU
  1010. Xevents for disabled menu items
  1011. X(if the selection was made before the menu item was disabled);
  1012. Xapplications should be prepared to receive spurious menu selection events.
  1013. X.PP
  1014. XA menu is created by a call to
  1015. X.CW "wmenucreate(id, title)" ;
  1016. Xthis returns a
  1017. X.I "menu pointer"
  1018. Xwhich must be used for all further manipulations with the menu.
  1019. X.I Id
  1020. Xis the menu id, which should be in the range [1..255].
  1021. XMenu ids should be unique within an application.
  1022. X.PP
  1023. XInitially, a menu contains no items.
  1024. XItems are added by calling
  1025. X.CW "wmenuadditem(mp, text, shortcut)" .
  1026. XThe new item's number equals the number of items in the menu before this
  1027. Xcall; it is returned as the function value.
  1028. X.I Mp
  1029. Xis the menu pointer;
  1030. X.I text
  1031. Xis the item text.
  1032. XThe item is initially enabled and unchecked.
  1033. X.I Shortcut
  1034. Xis a character used to construct a `keyboard shortcut' for the
  1035. Xmenu item; \-1 means the item is not to have a shortcut.
  1036. X(The interpretation of keyboard shortcuts is implementation-dependent.
  1037. XIn a typical STDWIN implementation,
  1038. Xa menu item with shortcut `X' might be selected by typing ESC-X
  1039. Xor Meta-X (but not Control-X).
  1040. XAll printable characters are acceptable as shortcuts,
  1041. Xbut on some systems lower case and upper case are indistinguishable.)
  1042. XAdding an item with an empty string as text adds a disabled
  1043. X`separator' item.
  1044. X.PP
  1045. XThe text of an existing menu item can be changed by calling
  1046. X.CW "wmenusetitem(mp, number, text)" .
  1047. XItems can be enabled or disabled by calling
  1048. X.CW "wmenuenable(mp, number, flag)" .
  1049. XThe check mark for an item can be set or cleared by calling
  1050. X.CW "wmenucheck(mp, number, flag)" .
  1051. X.PP
  1052. XA menu can be deleted by calling
  1053. X.CW "wmenudelete(mp)" .
  1054. XNote that individual menu items, once added, cannot be removed, nor can
  1055. Xnew items be inserted in the middle.
  1056. XThis is due to restrictions in many window systems' menu interfaces;
  1057. Xusually menus are sufficiently static that it doesn't matter.
  1058. X.PP
  1059. XFor a menu's items to be selectable, the menu must be attached to a
  1060. Xwindow and the window must be activated.
  1061. XNormally, STDWIN automatically attaches all menus to all windows, so all
  1062. Xmenus become selectable as soon as the first window is activated.
  1063. XTo change this behaviour, the call
  1064. X.CW "wmenusetdeflocal(TRUE)"
  1065. Xcauses subsequently created menus to be `local', requiring
  1066. Xexplicit attachment and detachment.
  1067. XThe call
  1068. X.CW "wmenuattach(win, mp)"
  1069. Xattaches the menu
  1070. X.I mp
  1071. Xto the window
  1072. X.I win .
  1073. XThe call
  1074. X.CW "wmenudetach(win, mp)"
  1075. Xreverses this effect.
  1076. XA menu may be attached to multiple windows; multiple menus may be
  1077. Xattached to a window.
  1078. XAfter calling
  1079. X.CW "wmenusetdeflocal(FALSE)" ,
  1080. Xfuture menus will be `global' again, i.e., automatically attached to all
  1081. X(existing and new) windows.
  1082. X.NH
  1083. XAdditional facilities
  1084. X.LP
  1085. X.NH 2
  1086. XEnquiry functions
  1087. X.LP
  1088. XSome enquiry functions are available to interrogate the system state.
  1089. X.LP
  1090. X.CW "wgetscrsize(&width, &height)"
  1091. X.IP
  1092. XReturns the screen size measured in pixels into the integer variables
  1093. Xwhose addresses are passed.
  1094. X.LP
  1095. X.CW "wgetscrmm(&mmwidth, &mmheight)"
  1096. X.IP
  1097. XReturns the approximate screen size measured in millimeters.
  1098. XBy combining this information with the outcome of
  1099. X.CW wgetscrsize ,
  1100. Xpixel size and aspect ratio can conveniently be computed.
  1101. XIn some (most?) implementations, the numbers returned may be
  1102. Xapproximations or guesses.
  1103. X.LP
  1104. X.CW "wgetwinsize(win, &width, &height)"
  1105. X.IP
  1106. XReturns the size of the drawable area of a window, measured in pixels.
  1107. X(Due to the presence of borders, a maximally-sized window is usually
  1108. Xsmaller than the screen.)
  1109. X.NH 2
  1110. XThe text caret
  1111. X.LP
  1112. XIn documents that deal with text it is often useful to have some form of
  1113. X`text cursor', indicating the position where characters typed at the
  1114. Xkeyboard will be inserted.
  1115. XThe call
  1116. X.CW "wsetcaret(win, h, v)"
  1117. Xcauses a `caret' to appear just to the left of the character
  1118. Xposition (\c
  1119. X.I h ,
  1120. X.I v )
  1121. Xin the document.
  1122. XThe caret appears immediately before any character that
  1123. Xwould be drawn by
  1124. X.CW "wdrawtext(h, v, ...)" .
  1125. XThe caret has a system-defined shape; it is often a blinking vertical
  1126. Xbar.
  1127. X.PP
  1128. XEach window has its own caret; the caret in the active window may be
  1129. Xthe only one that is visible, or it may blink while the carets in other
  1130. Xwindows are static.
  1131. XAt any time a window has at most one caret; the old caret is removed
  1132. Xwhen a new one is specified.
  1133. XThe caret can be removed altogether with the call
  1134. X.CW "wnocaret(win)" .
  1135. X.NH 2
  1136. XDialogue tools
  1137. X.LP
  1138. XA
  1139. X.I "dialogue box"
  1140. Xis a `mini-window' containing a simple message or question,
  1141. Xand requiring
  1142. Xthe user to respond, e.g. by pressing a key or clicking the mouse in a
  1143. Xparticular area.
  1144. XAs long as the dialogue box is present, the application is blocked.
  1145. XAfter answering the question or acknowledging the message, the dialogue
  1146. Xbox disappears and normal interaction with the application continues.
  1147. XDialogue boxes may be presented even when no windows are open yet.
  1148. XThe following calls put up dialogue boxes and wait for a response:
  1149. X.sp
  1150. X.LP
  1151. X.CW "wmessage(string)"
  1152. X.IP
  1153. XDisplays a message and waits until the user acknowledges it.
  1154. XThe precise form of acknowledgement required
  1155. Xis implementation-dependent;
  1156. Xit could be pressing the Return key or clicking an `OK button' with the
  1157. Xmouse.
  1158. X.LP
  1159. X.CW "waskstr(question, replybuf, buflength)"
  1160. X.IP
  1161. XDisplays a question and waits until the user has finished typing a
  1162. Xreply.
  1163. XThe initial contents of the reply buffer are used as a default reply.
  1164. XThe function normally returns TRUE; if the user aborts the dialogue
  1165. X(e.g., by pressing the CANCEL button) it returns FALSE.
  1166. X.LP
  1167. X.CW "waskync(question, dflt)"
  1168. X.IP
  1169. XDisplays a question which gives the user the possibility to answer with
  1170. XYes, No or Cancel only.
  1171. XThe return value is 1 (Yes), 0 (No) or -1 (Cancel).
  1172. X.I Dflt
  1173. Xis the suggested (default) return value.
  1174. X.LP
  1175. X.CW "waskfile(prompt, replybuf, buflength, new)"
  1176. X.IP
  1177. XDisplays a dialogue box asking for a file name.
  1178. X.I Replybuf
  1179. Xinitially contains a default or suggested file name.
  1180. XThe boolean parameter
  1181. X.I new
  1182. Xspecifies whether a new (not yet existing) or old (existing) file is
  1183. Xrequired.
  1184. XWhen a new file is asked for, the user may specify an existing file,
  1185. Xbut in this case explicit permission is asked to overwrite it.
  1186. XThe function returns TRUE, or FALSE if the user aborts the dialogue.
  1187. XThe file name is returned in a form acceptable to the STDIO function
  1188. X.CW fopen .
  1189. XSTDWIN implementations may provide additional support, e.g. file name
  1190. Xcompletion or file system browsing; the fact that some systems provide
  1191. Xelaborate standard file-selection dialogues (which is highly appreciated
  1192. Xby the end users) was a strong motivation to include this function in
  1193. XSTDWIN.
  1194. X.LP
  1195. X.CW "wperror(string)"
  1196. X.IP
  1197. XDisplays an error message similar to that printed by the standard C
  1198. Xfunction
  1199. X.I perror (3),
  1200. Xand waits for an acknowledgement as for
  1201. X.CW wmessage .
  1202. X.sp
  1203. X.LP
  1204. XIt should be noted that
  1205. X.CW "waskstr"
  1206. Xis the most general of the above functions; in theory, versions of the
  1207. Xothers can be implemented with the help of
  1208. X.CW "waskstr"
  1209. Xand other existing tools.
  1210. X.NH 2
  1211. XThe text-editing package
  1212. X.LP
  1213. XThe
  1214. X.I text-editing
  1215. Xpackage is a set of routines implemented entirely `on top of' STDWIN,
  1216. Xwithout using any implementation-dependent functions or data structures.
  1217. XThe availability of this package
  1218. Xis important because it provides a standard way to tackle the
  1219. Xnon-trivial problem of editing multi-line text blocks.
  1220. XIt is clearly influenced by the TextEdit routines available in the Apple
  1221. XMacintosh's ROM Toolbox (but contains only original code).
  1222. X.PP
  1223. XThe text-editing package displays a paragraph of text in a rectangle of
  1224. Xa given width, breaking the lines at spaces between words as necessary.
  1225. XIt gives the application complete control over what happens to the text,
  1226. Xbut provides an easy way to handle user input intended to edit it.
  1227. X.PP
  1228. XThe call
  1229. X.CW "tecreate(win, <rectangle>)"
  1230. Xreturns a pointer to a text-editing block at the specified position in
  1231. Xthe given window's document.
  1232. X(A text-editing block is not a portion of the document but a data
  1233. Xstructure.)
  1234. XAny number of text-editing blocks may be created, although usually at
  1235. Xmost one block per window should be editable at any time.
  1236. X.PP
  1237. XInitially, the block contains no text.
  1238. XThe call
  1239. X.CW "tesettext(tp, string)"
  1240. Xsets the text to be edited, replacing any existing text in the block.
  1241. XThe call
  1242. X.CW "tegettext(tp)"
  1243. Xreturns a pointer to the text string (which remains valid only until the
  1244. Xnext call to a text-editing routine).
  1245. X.PP
  1246. XThe text block is not automatically drawn.
  1247. XWhen a text-editing routine changes the edited text (or other aspects of
  1248. Xits appearance), it calls
  1249. X.CW wchange
  1250. Xfor the appropriate area of the window; the window's draw procedure
  1251. Xshould call
  1252. X.CW "tedraw(tp)"
  1253. Xfor each block which overlaps the repaint area.
  1254. X.PP
  1255. XBesides the edited string, a text-editing block contains a
  1256. X.I focus ,
  1257. Xindicating which text is selected
  1258. Xfor deletion or at which position new text will be inserted.
  1259. XThe focus can be set by the application with the call
  1260. X.CW "tesetfocus(tp, first, last)" ,
  1261. Xtelling that the characters in the range [first..last-1] are selected,
  1262. Xor, if first equals last, that the text insertion point is at that
  1263. Xposition (characters are counted starting at 0).
  1264. XIf the focus is an insert position, the window's caret is set at that
  1265. Xposition in the document.
  1266. XText can be inserted at the focus (replacing its previous contents) by
  1267. Xcalling
  1268. X.CW "tereplace(tp, string)" ;
  1269. Xspecifying an empty string deletes any text in the focus.
  1270. X.PP
  1271. XThe simplest way to let the user edit the text in a text-editing block
  1272. Xis to call
  1273. X.CW "teevent(tp, &event\%record)"
  1274. Xfor each event.
  1275. XThis call returns TRUE if the event is applicable to the text-editing
  1276. Xblock (e.g., it is a CHAR event, or a mouse click within the block's
  1277. Xbounding rectangle), and in that case the event is processed by the
  1278. Xtext-editing package (e.g., a character is inserted, or the focus is
  1279. Xmoved to the point where the mouse was clicked).
  1280. XIf the event is not applicable to the particular block, the function
  1281. Xdoes nothing and returns FALSE; in this case the application should
  1282. Xfurther decide what to do to the event.
  1283. XOf course, the application is free to decide whether to offer an event
  1284. Xto a text-editing block at all; e.g., it might have a different
  1285. Xinterpretation for the Return key (for which the text-editing package
  1286. Xinserts a new-line character in the text string).
  1287. X.PP
  1288. XThere are more text-editing calls, e.g. to move a text-editing block to
  1289. Xa new position, to enquire about the focus, to perform individual
  1290. Xediting operations, to ask for the height of the rectangle minimally
  1291. Xneeded to display the text entirely, etc.
  1292. X.PP
  1293. XThe following call displays a text string in exactly the same way as
  1294. Xthe text-editing package would do (breaking it into lines at the same
  1295. Xplaces, etc.), but without creating a text-editing block, and thus
  1296. Xwithout a focus:
  1297. X.CW "wdrawpar(<point>, string, width)" .
  1298. XIt returns the v coordinate of the bottom of the text paragraph.
  1299. XTo compute the height of a text paragraph thus drawn without actually
  1300. Xdrawing it, one can call
  1301. X.CW "wparheight(string, width)" .
  1302. X.NH
  1303. XA complete example
  1304. X.LP
  1305. XThe program below is a complete STDWIN application.
  1306. XIt is presented here to give a feel for the use of some of the routines
  1307. Xdescribed above.
  1308. XThe program displays a window in which a text-edit block is placed;
  1309. Xall events recognized by the text-edit package are handled correctly,
  1310. Xand so are several ways of quitting.
  1311. XOther events are ignored.
  1312. X.if t .sp .5v
  1313. X.DS L
  1314. X.CW
  1315. X#include <stdwin.h>
  1316. X
  1317. XTEXTEDIT *tp; /* Global so drawproc can reference it */
  1318. X
  1319. Xvoid drawproc(w, left, top, right, bottom)
  1320. X    WINDOW *w;
  1321. X    int left, top, right, bottom;
  1322. X{
  1323. X    tedraw(tp);
  1324. X}
  1325. X.R
  1326. X.DE
  1327. X.DS L
  1328. X.CW
  1329. Xmain()
  1330. X{
  1331. X    MENU *m;
  1332. X    WINDOW *w;
  1333. X    int stop;
  1334. X    int width, height;
  1335. X.R
  1336. X.DE
  1337. X.DS L
  1338. X.CW
  1339. X    winit();
  1340. X    
  1341. X    m= wmenucreate(1, "Sample");
  1342. X    wmenuadditem(m, "Quit", 'Q'); /* Item 0 */
  1343. X    
  1344. X    w= wopen("Sample window", drawproc);
  1345. X    wgetwinsize(w, &width, &height);
  1346. X    tp= tecreate(w, 0, 0, width, height);
  1347. X.R
  1348. X.DE
  1349. X.DS L
  1350. X.CW
  1351. X    stop= 0;
  1352. X    while (!stop) {
  1353. X        EVENT e;
  1354. X        wgetevent(&e);
  1355. X        if (teevent(tp, &e))
  1356. X            wsetdocsize(w, width, tegetbottom(tp));
  1357. X        else {
  1358. X            switch (e.type) {
  1359. X            case WE_COMMAND:
  1360. X                if (e.u.command == WC_CLOSE || e.u.command == WC_CANCEL)
  1361. X                    stop= 1;
  1362. X                break;
  1363. X            case WE_MENU:
  1364. X                if (e.u.m.id == 1 && e.u.m.item == 0) /* Quit */
  1365. X                    stop= 1;
  1366. X                break;
  1367. X            }
  1368. X        }
  1369. X    }
  1370. X.R
  1371. X.DE
  1372. X.DS L
  1373. X.CW
  1374. X    wclose(w);
  1375. X    wdone();
  1376. X    exit(0);
  1377. X}
  1378. X.R
  1379. X.DE
  1380. X.if t .sp -.5v
  1381. X.NH
  1382. XExperiences
  1383. X.LP
  1384. XFive distinct STDWIN implementations have been created so far:
  1385. Xfor the Apple Macintosh,
  1386. Xfor the Whitechapel MG-1,
  1387. Xfor X version 11,
  1388. Xfor the Atari ST,
  1389. Xand a subset for alphanumeric displays
  1390. X(which runs both under Unix and MS-DOS).
  1391. X.PP
  1392. XOnce a STDWIN version for a target system is available,
  1393. Xapplication portability is high.
  1394. XMost portability problems that crop up
  1395. X(besides the usual problems like word size, byte order,
  1396. Xdata alignment or following NULL pointers)
  1397. Xhave to do with differences in other parts of the operating system
  1398. Xinterface, e.g. use of the file system.
  1399. XOne portability problem encountered with the STDWIN interface was that
  1400. Xsome programs developed for alphanumeric terminals expected a
  1401. Xfixed-width font; in general most problems were caused by insufficiently
  1402. Xprecise specification of STDWIN.
  1403. X.PP
  1404. XThe time needed to create a STDWIN version for a particular target
  1405. Xsystem is moderate.
  1406. XAn experienced C programmer who did not know anything about STDWIN or
  1407. Xthe Atari ST in advance
  1408. Xcreated a working Atari ST version in two months.
  1409. XSo far, each version has been created more or less from scratch
  1410. X(except for the common parts like the textedit package).
  1411. XWe have now gained enough experience with different target systems to be
  1412. Xable to create an intermediate layer containing code which remains more
  1413. Xor less constant between target systems.
  1414. X.NH
  1415. XFuture developments
  1416. X.LP
  1417. XTo date, the applications that use STDWIN have been mostly text-based.
  1418. XUndoubtedly, this has influenced the direction of development of drawing
  1419. Xfacilities in STDWIN.
  1420. XIt is sufficiently easy to add graphical primitives to an
  1421. Ximplementation, though, that we expect to add several as demand grows,
  1422. Xe.g., bitblt, clipping, line styles, filling.
  1423. XThe existing facilities set a sort of standard for the form of future
  1424. Xones.
  1425. XThe requirement that they be implementable on top of a large variety of
  1426. Xwindow systems will ensure that only more or less generally accepted
  1427. Xprimitives will be included in STDWIN; a useful sort of conservatism for
  1428. Xa package that wants to enhance application portability.
  1429. X.PP
  1430. XBesides the need to add more drawing primitives, there are several areas
  1431. Xwhere STDWIN requires, and will probably get, extensions: fonts, sizes
  1432. Xand styles; the mouse cursor; drawing in off-screen bitmaps (not
  1433. Xassociated with a window); error handling (which is currently virtually
  1434. Xabsent); event queue manipulations and an `event mask'; `clipboard' or
  1435. X`cut buffer' operations.
  1436. X.PP
  1437. XA development in a different direction, independent of the addition of
  1438. Xgraphical primitives, may be the addition of more toolboxes built on
  1439. Xtop of the exiting facilities, like the text editing package.
  1440. XTools are needed
  1441. Xto manipulate higher-order graphical objects,
  1442. Xto implement specific interaction techniques,
  1443. Xto provide `canned applications' like text-editing windows,
  1444. Xetc.
  1445. X.PP
  1446. XA third, potentially very useful, extension would be the addition of
  1447. Xdrawable
  1448. X`borders' to the window that aren't scrolled together with the document.
  1449. XIn such borders, interaction tools could be placed like palettes and
  1450. Xbuttons, or rulers around the document.
  1451. XThe design of such an extension should be the topic of further research,
  1452. Xin order to achieve the largest possible generality.
  1453. X.\" Filter troff input through refer -e -n
  1454. X.[
  1455. X$LIST$
  1456. X.]
  1457. END_OF_FILE
  1458. if test 51068 -ne `wc -c <'Doc/paper.ms'`; then
  1459.     echo shar: \"'Doc/paper.ms'\" unpacked with wrong size!
  1460. fi
  1461. # end of 'Doc/paper.ms'
  1462. fi
  1463. if test -f 'Ports/mac/pstring.c' -a "${1}" != "-c" ; then 
  1464.   echo shar: Will not clobber existing file \"'Ports/mac/pstring.c'\"
  1465. else
  1466. echo shar: Extracting \"'Ports/mac/pstring.c'\" \(497 characters\)
  1467. sed "s/^X//" >'Ports/mac/pstring.c' <<'END_OF_FILE'
  1468. X/* Function to convert a C string to a Pascal string.
  1469. X   The conversion is not in-line, but returns a pointer to a static buffer.
  1470. X   This is needed when calling some toolbox routines.
  1471. X   MPW does the conversion in the glue.
  1472. X*/
  1473. X
  1474. X#include "macwin.h"
  1475. X
  1476. X#ifndef CLEVERGLUE
  1477. X
  1478. Xchar *
  1479. XPSTRING(src)
  1480. X    register char *src;
  1481. X{
  1482. X    static char buf[256];
  1483. X    register char *dst;
  1484. X    
  1485. X    dst = &buf[1];
  1486. X    while ((*dst++ = *src++) != '\0' && dst < &buf[256])
  1487. X        ;
  1488. X    buf[0] = dst - &buf[1];
  1489. X    return buf;
  1490. X}
  1491. X
  1492. X#endif /* CLEVERGLUE */
  1493. END_OF_FILE
  1494. if test 497 -ne `wc -c <'Ports/mac/pstring.c'`; then
  1495.     echo shar: \"'Ports/mac/pstring.c'\" unpacked with wrong size!
  1496. fi
  1497. # end of 'Ports/mac/pstring.c'
  1498. fi
  1499. echo shar: End of archive 2 \(of 19\).
  1500. cp /dev/null ark2isdone
  1501. MISSING=""
  1502. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ; do
  1503.     if test ! -f ark${I}isdone ; then
  1504.     MISSING="${MISSING} ${I}"
  1505.     fi
  1506. done
  1507. if test "${MISSING}" = "" ; then
  1508.     echo You have unpacked all 19 archives.
  1509.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1510. else
  1511.     echo You still need to unpack the following archives:
  1512.     echo "        " ${MISSING}
  1513. fi
  1514. ##  End of shell archive.
  1515. exit 0
  1516.