home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_02 / wtwg.doc < prev    next >
Text File  |  1991-06-07  |  44KB  |  1,025 lines

  1. /*
  2. HEADER:        MAIN documentation file for  'WTWG' windows system;
  3. TITLE:        Window Text/Window Graphics
  4.  
  5. VERSION:    1.2
  6. DATE:        6/31/90
  7.  
  8. DESCRIPTION:    This file contains an overview of the windows routines 
  9.     provided on these disks, installation instructions and use notes.
  10.  
  11. KEYWORDS:    windows, keyboard, mouse, text, graphics, expanded memory, menus;
  12. SYSTEM:        MS-DOS v3.0, probably works with v2.0 but untested;
  13. FILENAME:    WINDOW.DOC
  14.  
  15. SEE-ALSO:    files on this disk named *.doc, demo*.c
  16.  
  17.                 defines.doc - documentation of struct, typedef, #defines etc
  18.                 funcs.doc   - documentation of specific function calls.
  19.                 
  20.                 demo*.c     - demo programs showing main features.
  21.                 
  22. AUTHOR:    David Blum
  23.         
  24.         old address:
  25.         1710 Glyndon Ave
  26.         Venice, CA 90291
  27.         
  28.         new address:
  29.         
  30.         8039 North 1st Street
  31.         Phoenix, AZ  85020
  32.         
  33. COMPILERS:    Turbo C v2.0, Microsoft C v5.1
  34. */
  35.  
  36.  
  37.  
  38.                     INTRODUCTION to WT/WG ROUTINES
  39.  
  40. The routines in these libraries provide screen, keyboard, and  
  41. mouse management in either text or graphics modes for Turbo C 
  42. version 2, TurboC++ and Microsoft C v5.
  43.  
  44. This file is an introduction to the ideas behind WTWG, providing 
  45. definitions of basic terms (like window, MOUSE, and BUTTON), and 
  46. an overview of the available functions. More detailed 
  47. documentation is in the other .DOC files ( FUNCS.DOC, 
  48. DEFINES.DOC, etc ). There are several demo programs as well. 
  49.                 
  50.                 
  51.                 
  52.                          DISK CONTENTS.
  53.  
  54. NOTE: complete package actually spans several disks.
  55.  
  56. HEADER.DSK - C Users group standard submission header
  57.                          
  58. .DOC files - Documentation is in this file and define.doc and funcs.doc
  59.  
  60. .H files: #include "window.h" - used by all program
  61.     
  62. Demonstration programs are in demo*.*
  63.     Source for the demos is demo*.c. 
  64.     TurboC project files are demo*.prj
  65.         (Microsoft C - create similar *.mak for quick C)
  66.     On-line Help for the demonstration programs is in demo*.HLP and demo*.HX
  67.     The .BAT files Tdemo.BAT / Mdemo.BAT make and run the demos 
  68.         using the command line compilers 
  69.         for Turbo and Microsoft C respectively.
  70.  
  71. Several utility programs are included:
  72.     makehx.exe - create help 'index' file from help text file
  73.                             (used by online-help functions)
  74.                             (input: filename.HLP output: filename.HX )
  75.     txt2mcr.exe - convert ASCII text file to key macro
  76.                             (input: filename.TXT output: filename.MCR )
  77.                             (see DEMOMACR.C for examples)
  78.     dir2bat.com - filter for directory listings.
  79.                             (see TMAKE.BAT or WMAKE.BAT for example of use)
  80.     type the prog name without arguments for help.
  81.  
  82. LIBRARIES:
  83.     The lib files provided are W*.LIB ( for TurboC ) and MW*.LIB ( MSC )
  84.  
  85.     WTS.LIB, WGS.lIB -two small-model libraries for TurboC are on disk. 
  86.     WTS.LIB provides almost all of the routines in the larger library 
  87.         but is specific for text mode, and will run on CGA, EGA/VGA, 
  88.         or HERCULES monitors. If WTS.LIB is specified in a .PRJ or 
  89.         .MAK file, no graphics mode functions will be linked in, 
  90.         providing a smaller .EXE
  91.  
  92.     WGS.LIB (TurboC) contains all the routines for both text and graphics 
  93.         modes. In almost all cases the use of the routines is transparent. 
  94.         This is accomplished by creating a 'text-mode' coordinate system 
  95.         and superimposing it on the grpahics-mode cordinates. The two 
  96.         cordinate systems may be referenced independently. 
  97.  
  98.     WGL.LIB (TurboC) is the large model graphics and text library.
  99.  
  100.     WGY.LIB and WGYO.LIB are large model VROOM-compatible libs 
  101.                 for resident- and overlaid modules, respectively.
  102.     
  103.     MWGM.LIB is the microsoft medium model graphics and text library. 
  104.                              
  105. The source disk includes:
  106.     w*.c - source for all windows routines. The source code is HEAVILY 
  107.             commented, honest. 100% C no assembly code.
  108.     wsys.h and wscreen.h  - headers used only by the w*.c routines
  109.     whelp.h - used internally by help routines whelp.c and makehx.c
  110.     msc.h   - irons out some diferences between TurboC and Microsoft C
  111.     'utility' source code:  dir2bat.c, makehx.c, text2mcr.c
  112.     .BAT files for building the libraries from the source code
  113.         (Twmake.bat, Mwmake.bat, Mnewmake.bat, Mblank.bat)
  114.         
  115.     The source disk is archived, and includes the extraction utility.    
  116.                              
  117.                              
  118.                         INSTALLATION - TURBO C
  119.                              
  120. Make a subdirectory under \tc named windows, copy this disk into the 
  121. subdirectory.
  122.  
  123. The graphics routines initialize the BGI assuming that the .BGI and 
  124. .CHR files are in a directory named "C:\\TC". A global variable, 
  125. wpath_BGI, points to the string "C:\\TC". If you keep the BGI files in a 
  126. different directory, you should change the global variable prior to 
  127. initializing with winit('G');
  128.  
  129.  
  130. Tell TurboC how to find these libraries:
  131.     command line compiler:
  132.             create a TURBOC.CFG file (or modify your current file)
  133.             (in the C:\TC directory)
  134.                 with the lines: -IC:\TC\INCLUDE;C:\TC\WINDOWS
  135.                                 -LC:\TC\LIB;C:\TC\WINDOWS
  136.                 and use the DOS command PATH C:\;C:\DOS;\C:\TC
  137.                     (modified for your disk setup)
  138.     integrated environment:
  139.         slightly different for TurboC and TurboC++, essentially like this:
  140.             select OPTIONS/COMPILER/DIRECTORY, type in 
  141.                                 C:\TC\INCLUDE;C:\TC\WINDOWS
  142.             select OPTIONS/LINKER/DIRECTORY, type in 
  143.                                 C:\TC\LIB;C:\TC\WINDOWS
  144.             and then OPTIONS/SAVE
  145.  
  146.  
  147. Compile and run the demo programs either by:
  148.     Command line: run TDEMO.BAT
  149.     integrated environment: select project file demo*.prj, 
  150.                             be sure 'use registers' is ON 
  151.                             be sure 'link graphics lib' is ON
  152.                             Run -> Run
  153.  
  154.     If you have TurboC++, use PRJCNVT.EXE to make new-style .PRJ files.
  155.             See the TurboC documentation.
  156.  
  157.                       INSTALLATION - Microsoft C ( "msc" )
  158.  
  159.  
  160. Make a subdirectory named windows under \msc ( or wherever msc is located ),
  161.      copy the WTWG files into the subdirectory.
  162.  
  163. Make sure that environment variables LIB and INCLUDE are defined as 
  164. done in the msc installation, and add the \msc\windows directory.
  165.  
  166. These routines were ported to microsoft C from TurboC. Microsoft C 
  167. lacks some of the ammenities of TurboC. If you recompile the source 
  168. code in a model other than MEDIUM, be sure to define a symbol stating 
  169. the memory model, ie: __SMALL__ or __LARGE__. See the header file 
  170. wsys.h (on the source code disk) for details.
  171.  
  172. Use MDEMO.BAT to compile, link and run the demos.
  173.  
  174.                         INSTALLATION - QUICK C
  175.                         
  176. Same as Microsoft C. The library provided, MWGM.LIB can be referenced 
  177. on the QCL command line (be sure to specify /AM and graphics.lib), or 
  178. you can use LIB to extract the medium-model object modules and then 
  179. QLIB to create a QUICK LIBRARY. Tell Quick C environment which directories
  180. too look in. 
  181.  
  182. The quick C preprocessor has some unpleasant quirks and will not 
  183. compile the demo program demomenu.c. 
  184.  
  185.                            OTHER COMPILERS
  186.  
  187. This package was written using TurboC v2.0. In Turbo C, the 
  188. symbol __TURBOC__ is defined (unless STDC is selected). If the 
  189. preprocessor symbol __TURBOC__ is not defined, the programs assume 
  190. Microsoft C is the compiler, and will include msc.h. Differences 
  191. between msc and TC are spelled out in msc.h. 
  192.  
  193. For the most part, the code is plain-ANSI compatible and should be 
  194. easy to port. A few noteworthy exceptions:
  195.     1) In-line interrupts and registers. See WSYS.H for explanation of 
  196.     methods used for in-line interrupts and register assignements. 
  197.     This method should be transparent in porting to any other compiler 
  198.     that uses a Microsoft-C like 'int86(intno, ®struct, ®struct)'
  199.     method of generating interrupts. Just redefine INTERRUPT(intno) macro. 
  200.     2) outport () in Microsoft C is outp(). 
  201.     3) file WBGI.C contains the code for interfacing these routines 
  202.     with the compiler-provided graphics package (in this case, BGI). 
  203.     The overall layout  of the file is:
  204.             ...start of file
  205.             #ifdef __TURBOC__
  206.                 ...code for TC version
  207.             #else
  208.                 ...code for MSC version
  209.             #endif
  210.             ...end of file
  211.     To port to some other C compiler, replace the MSC version and be 
  212.     sure __TURBOC__ is undefined
  213.  
  214.     4) wdraw() contains some TurboC specific graphics calls and data 
  215.     types. These should be very easy to port if your graphics package 
  216.     supports XOR pixel drawing in graphics mode. MSC doesn't. I 
  217.     couldn't get them to work with Microsfoft C.
  218.     
  219.     5) wclockinstall() uses interrupts to install an onscreen clock
  220.     This doesn't work right in Microsoft C, because of 'stack' errors.
  221.     It should be easy to fix for someone who knows more microsoft C than
  222.     I do. The routine works, but is quirky, in EGA/VGA graphics modes
  223.     but works well in any text mode and hercules graphics. Also, wsysrq.c 
  224.     did not work in MSC, you may need to make changes there if 
  225.     you want this feature.
  226.     
  227.     6) Quick C - the QC preprocessor is non-standard and some of the 
  228.     routines will not compile correctly; at least they generate error 
  229.     messages. MSC 5 preprocessor works, though.
  230.     
  231.     
  232.     
  233.                       COMPILING AND LINKING - TurboC
  234.  
  235. These routines were tested with the following TurboC options:
  236.     -r = register variables. MUST BE ON in all modules that call 
  237.             these routines. Your computer will lock up if not.
  238.     -K = default char is unsigned. Conform to ANSI standard.
  239.     -N- and -k- Use non-standard stack frame.
  240.     -1 = generates 80x86 code. older machines may not run these 
  241.         routines  as provided, they would need to be recompiled.
  242.         IF YOU HAVE AN OLD PC (ie, 8088 not 8086), buy the source 
  243.             code and recompile.    
  244.     alignment - the routines were compiled with alignment OFF.
  245.             However, all of the data structures are self-aligning,
  246.             so it shouldn't matter.
  247.             
  248. Specify either WTS.LIB or WG$.LIB where $=model (L/S)
  249.  
  250.                     VROOM overlays (TURBO C and C++)
  251.  
  252. The batch file twmakey.bat makes two separate __LARGE__ libraries for 
  253. VROOM:     wgy.lib contains portions that stay resident,
  254.         wgyo.lib contains overlay / swappable modules.
  255.         
  256. I arbitrarily made the choice that resident routines should be a 
  257. mininum support for basic input and output. This allows some 
  258. basic functions to be used in interrupt handlers and 
  259. time-critical code. You can open/close windows, save/restore, 
  260. clear, draw borders and titles, write chars and strings using 
  261. wputc/wputs (not wprintf), and get user input using wkbd_ 
  262. functions. No higher level kbd input is supported (mouse, wgetc, 
  263. buttons, wpromptc, wgets, wprompts, wpicklist, wscanform,...)
  264.  
  265. The interrupt routines wSysRq, wclock, and winDOS are resident.
  266.  
  267. Fancier routines for screen configuration (paging, 43/50 line 
  268. toggle, palette manipulation), and keyboard manipulation keyboard 
  269. pipes, traps, macros, online help, wungetc(), as well as all 
  270. mouse routines, are all overlaid.
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.                      COMPILING AND LINKING - MSC 
  278.                      
  279. These routines are compiled with size optimization and byte alignment.
  280. They should work even if word alignment is selected. Specify /J for unsigned 
  281. characters. If you get the source code, and recompile in other memory models,
  282. you should #define a symbol specifying the model ( ie: __LARGE__ or __SMALL__ )
  283.  
  284.  
  285.  
  286.         
  287.  
  288. ---------------------HOW TO USE THESE ROUTINES-----------------------------
  289.  
  290.  
  291.                    INITIALIZATION and SHUTDOWN
  292.  
  293. At the start of your program winit('T') or winit('G').
  294.  
  295. Be sure to use capital letters -- winit ('t') will  NOT work. 
  296.  
  297. Special initializations:
  298.     * mulitple video pages: call winit_pages( mode ) instead of winit.
  299.                             you may call one and then the other.
  300.     * DeskView programs: IMMEDIATELY after call to winit(mode), call wdvinit().
  301.                             tested only with one video page, text mode.    
  302.     
  303. Shutdown is automatic. Never call _exit() or abort(). Use exit() 
  304. instead. On return from main() or on execution of an exit() 
  305. function, the video state will be restored, cursor turned on, 
  306. expanded memory returned to the system, and any disk storage 
  307. ('virtual memory') used will be erased. 
  308.  
  309.  
  310.  
  311.  
  312.                          ERROR HANDLING
  313.  
  314. The routine werror() assigns an exit code, restores the video 
  315. mode, and writes an error message, then shuts down the program.
  316.  
  317. If you use perror(), or puts(), or even wputs() in a graphics 
  318. mode program, or on a high video page, then your error message 
  319. will be lost when the video mode is restored. Even worse, using 
  320. some other windows packages, if you call exit() from a bizarre 
  321. video mode, your PC screen will be unreadable (especially 
  322. hercules). The werror() routine solves all these problems.
  323.  
  324. If you run out of memory, malloc() returns NULL. If you test for 
  325. this and then write an error message, and then exit, your message 
  326. might get lost (when the graphics mode changes back to text mode 
  327. the screen is erased). The shutdown routine requires some 
  328. available memory. Instead, use wmalloc() or wfarmalloc() or 
  329. wrealloc() to correctly handle the situation of running out of 
  330. memory. Testing is done for you, and error messages are dealt with 
  331. correctly.
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.                    MEMORY USE and REQUIREMENTS
  339.                    
  340. Most windows packages for the IBM PC operate in text mode only. It 
  341. takes about 4k of ram to save a text-mode full screen image, so memory 
  342. isn't a big deal for text mode. For graphics mode, especially on color 
  343. monitors (depending on resolution, etc) it can take > 100 k to save a 
  344. screen. This is an impractical amount of ram to use for most serious 
  345. graphics programs. Most large graphics-oriented programs require 
  346. expanded memory, but not all PC's have this feature. The solution is a 
  347. 'heap' composed of 'virtual' memory.
  348.    
  349. The libraries include a memory management routine that allocates 
  350. 'heap' memory from expanded memory, the DOS far heap, or a disk file, as 
  351. needed. The actual location of the data is transparent to the calling 
  352. routines.  Memory use is ultimately limitted only by available disk space. 
  353.  
  354. The routines that manage this service are named wheap..., and are 
  355. described in detail in funcs.doc. 
  356.  
  357. Unfortunately, to achieve this the manager allocates a 64k buffer 
  358. for disk I/O. This means that you can't debug programs using the 
  359. TurboC integrated environment unless you have expanded memory 
  360. in your system. To allow for debugging, a separate version of the 
  361. memory management routine, heapdbg.c, is provided. Place this 
  362. module name in your .PRJ/.MAK file ahead of the WG$.LIB name. Ignore 
  363. the 'duplicate module' linker warnings. This module doesn't do disk 
  364. allocation or exp. mem. and so allocatable memory is limitted, but 
  365. with it you can run the integrated debugger, TD, or CodeView.
  366.  
  367. Finally, for programs in the large memory model, the routines 
  368. wmalloc() and wrealloc() guarantee a return of a NORMALIZED 
  369. pointer. If you use these routines exclusively, and never call 
  370. malloc, calloc, realloc, or similar, you will avoid segmentation 
  371. errors (very difficult to debug, intermittant errors in large 
  372. pgms). The file WSYS.H (intended only for compiling the WTWG 
  373. source code) contains a NORMALIZE macro that adjusts the 
  374. segment/offset values of far *ptrs to help completely avoid these 
  375. problems. If you always use wmalloc() or wfarmalloc() you 
  376. shouldn't have to worry about it, as the pointers are NORMALIZED 
  377. for you.  NOTE added 6/31/91 for version 1.2: If you use C++ the 
  378. NORMALIZE macro has to be redefined to include a typecast. All 
  379. WTWG routines are written in C. Future releases will be in C++ 
  380. but will use a separate NORMALIZE macro. 
  381.  
  382.                     
  383.                     
  384.                             NAMING CONVENTIONS
  385.                             
  386. All the public symbols in this package begin with 'w...' and are declared 
  387. in window.h. You should have no problems with duplicate names. 
  388.  
  389. x refers to horizontal co-ordinates. y refers to vertical 
  390. co-ordinates. Counting starts at 0.
  391.  
  392. Members of structures all have names that imply their parentage.
  393.     (ie, member of structure WMOUSE giving x position is wms_x)
  394. Defined values for flags all have names that imply which flag they refer to
  395.     (ie, flag governing style for text output is winputsyle
  396.          flag value setting wrapping to next line is WPUTWRAP)
  397.  
  398.  
  399.  
  400.  
  401.                        OPENNING AND CLOSING WINDOWS
  402.  
  403. In some windows systems (especially Microsoft WINDOWS) your 
  404. windows are asked to 'redraw' themselves. This makes for complex 
  405. programs. Other window systems keep in-memory images of the 
  406. window and redraw the windows for you. This system does neither. 
  407. Programming effort and execution overhead (both speed and RAM) 
  408. are less than other systems. The disadvantage is you can't write 
  409. true multitasking programs using this package.
  410.                   
  411. After initialization, a full-screen window is automatically open. Full 
  412. screen operation using wputs() wprintf() wputc() can proceed 
  413. identically to ANSI stream output. Alternatively, smaller windows can 
  414. be openned and closed.
  415.  
  416. The global variable w0 always points to the current open window.
  417. Members of the WINDOW structure can be accessed. For instance, 
  418.     w0-> winx gives the current x position (starts at 0). 
  419.     w0-> winxmax gives the highest valid x position.
  420.     w0-> winattr gives the current attribute.
  421.     etc. see WINDOW.H
  422.     
  423. Windows are kept on a LIFO stack. Calling wopen() creates a window, 
  424. wclose() closes the most recently created window. The most recently created 
  425. window is the active window. Be sure your sub-routines close any 
  426. windows they open, leaving the stack set up correctly for calling routines.
  427.  
  428. The order of the stack can be changed by calling wreopen() to 
  429. place an older window on top of the stack, or wbury() to place 
  430. the current window on the bottom of the stack. This obviously 
  431. requires some caution. You can wreopen() the full screen window at any 
  432. time by calling wreopen (wfullscreen). Be sure to wbury() it when 
  433. done. 
  434.  
  435.  
  436.  
  437.                             CO-ORDINATE SYSTEM
  438.  
  439. A consistent co-ordinate system is used. Variable names 
  440. containing the three letters 'abs' refer to screen coordinates 
  441. (0,0 = top left). Position variables without 'abs' in them are 
  442. relative to the current window. In all function prototypes, 
  443. x=horizontal, y=vertical and the order is always x,y. Coordinate 
  444. numbering starts with 0 (NOT 1) and ends with winxmax/winymax  
  445. (or wxabsmax/wyabsmax). Variables with 'max' in the name specify 
  446. the largest valid value for that co-ord, ie: wxabsmax is the 
  447. largest valid x-value which is typically 79 for an 80-column 
  448. screen. Do not assume that wxabsmax is always 79: on Hercules 
  449. monitors in graphics modes it is 89 (720 pixels = 90 characters 
  450. accross). If you add Super VGA support (800*600 is easy), then 
  451. wpxabsmax =799 and wxabsmax=99. winxmax refers only to the 
  452. current window and is referenced as a member of the WINDOW 
  453. structure (ie: w0->winxmax). Variables with 'px' or 'py' refer to 
  454. pixels rather than text-mode character counts; ie, w0->wpxmax is 
  455. the largest valid horizontal pixel number in the current window 
  456. and wpxabsmax is the largest valid horizontal pixel on the 
  457. screen.  
  458.  
  459.  
  460. For all routines that refer to absolute positions (wxabs, wyabs), x 
  461. is horizontal and y is vertical. Counting begins at (0,0) in the 
  462. upper left corner of the screen. In graphics modes, wpxabs, wpyabs 
  463. values refer to absolute pixel count, (0,0) being top left corner of 
  464. screen.
  465.  
  466. Within a window, a local co-ordinate system is used with (0,0) 
  467. being the upper left corner of the open window, wherever that is 
  468. on screen. For a window that has 10 columns, the value of w0->winxmax 
  469. would be 9. Text output would take place at the current position in 
  470. the window which is given by w0->winx and w0->winy. The same sort 
  471. of coordinates apply in graphics modes, counting pixels.
  472.  
  473. Example:( w0->winxmax ) is the last valid x value in the current window.
  474.         ( w0->winx )    is the current x co-ord in the current window.
  475.         
  476.         
  477. The first 2 parameters to wopen() specify x,y of left top postion 
  478. of first text byte in the window. Any borders are above and to 
  479. left of this spot. The next 2 parameters are the number of 
  480. columns ( xmax+1 ) and number of rows (ymax +1) in the window, 
  481. again not counting borders. Window co-ordinates are referenced 
  482. starting at 0, but the number of rows/columns desired is 
  483. referenced starting at 1. 
  484.  
  485. wsetlocation() and wlocate() can be used to automatically place a 
  486. window using co-ordinates relative to screen top/left; screen 
  487. center, current window, or current cursor position. These 
  488. functions simplify coding self-centering windows or windows that 
  489. should be located at the current text location. Routines which 
  490. create self-adjusting windows include wgets() wpromptc() wform(). 
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.                                 TEXT OUPTUT
  498.  
  499. Text can be sent to the screen via wputc() wputs() or wprintf(). The 
  500. 'current location' is updated appropriately. You can discover the 
  501. current location by referencing w0->winx and w0->winy. The next byte 
  502. of text ouput will take place at that spot. You can change that spot 
  503. with wgoto(new_x, new_y). 
  504.  
  505. The behavior of wputc/wputs/wprintf at line endings and at the bottom 
  506. of a window is called the 'put style' and is controlled by the 
  507. variable (w0->winputstyle). The 'put style' for the current window can be 
  508. changed. By default these behave exactly like their ANSI   
  509. counterparts putc/puts/printf, ie at the last column text wraps to 
  510. the beginning of the next line, and after the last line the window is 
  511. scrolled up one line. ANSI escape code are honored. Within each window, 
  512. different text behavoirs can be specified. Text wrapping at the end of 
  513. a line and window scrolling after the last line can be turned off. ANSI 
  514. escape sequences can be processed or ignored and printed. \n can generate 
  515. a CR/LF or just a LF. All these choices are set with the flag w0->winputstyle. 
  516. When the window is closed, the previous window's put style  is restored. 
  517. See defines.doc for more details.
  518.  
  519. Window colors are specified as 'unsigned char.' The first 4 bits 
  520. specify the background, the low 4 bits set the foreground. See the 
  521. definitions in WINDOW.H. For example, 
  522.     wsetattr(  (RED<<4)+YELLOW  ) sets yellow letters on red bkgnd. 
  523.     wgetattr() returns the current attribute as 'unsigned char'
  524.     
  525. On hercules monitors, in text mode, the colors behave just like for 
  526. other programs ( GREEN = white, BLUE=underline, RED=invisible ). In 
  527. graphics mode, only colors that include GREEN or BLUE will be white, 
  528. all others will be black. So, (GREEN<<4)+YELLOW is a bad choice 
  529. becuase in Hercules graphics mode it will show up as solid 
  530. (unreadable). This is called 'dithering.' The HP laserjet driver 
  531. whplj_dump() uses the same dithering scheme so if you are 
  532. consistent in you choice of colors your programs will look OK on 
  533. HERCULES, PAPER and also VGA.
  534.  
  535. The cursor is managed automatically: it is off by default and turned 
  536. on by wgets() when the user has to type something. On exit it is 
  537. turned on again. In graphics modes for user input (typing) a 
  538. pseudo-cursor is created. In text mode, if you really want a cursor,
  539. you can call wturn_cursor (ON) or wturn_cursor (OFF), but most of 
  540. the time it is handled for you. 
  541.  
  542.                             
  543.                             KEYBOARD INPUT
  544.                             
  545. The program detects the enhanced keyboard at startup. The 
  546. nonsense about character/scan code (see TurboC manual for 
  547. getch()) is handled automatically - a single call to wgetc() 
  548. always returns a single character. Becuase the number of 
  549. characters available on the enh. kbd is large, the return type of 
  550. wgetc() is an 'int'. The range is -32k to +32k. For actual keys 
  551. on the keyboard, only 1 thru about 300 are used. Value 128 is 
  552. reserved for the mouse. All routines that ask for or return 
  553. keyboard values expect 'int' data; if you use 'char' or 'unsigned 
  554. char' errors may occur.
  555.  
  556. Wgetc() does several things: 
  557.     1) mouse and keyboard are 'merged' into one virtual device. 
  558.     2) hotkeys are searched for and specified routines called.
  559.         (examples are in demomenu, demomacr, demohkey)
  560.     3) keyboard input can be trapped and sent to a file, or 
  561.     redirection can be done to read a file as keyboard input.
  562.     4) If the user doesn't press a key after 3 minutes the screen is 
  563.     blanked. This happens in text or graphics, EGA/VGA/HERCULES.
  564.     
  565. Example:      int keystroke;            /* 'char keystroke' would be wrong */ 
  566.             keystroke = wgetc();
  567.             if ( keystroke == FKEY(1) ) {...}
  568.             else
  569.             if ( keystroke == ESCAPE ) {...}
  570.             else
  571.             if ( keystroke == ALT_TAB ) {...} /* actual value is 293 */
  572.             else
  573.             if ( keystroke == WMOUSE )  {...} /* mouse used */
  574.             else
  575.             ...etc...
  576.             
  577.     
  578. MOUSE use is automatic. 2- and 3-button mice are supported. The mouse is 
  579. turned off when not actually accepting user input to allow graphic-mode 
  580. screen drawing without garbage onscreen (try turning mouse ON and drawing 
  581. a circle with the mouse moving on a VGA/EGA screen). When the video display 
  582. is changed to a high page number the mouse is disabled if the monitor/
  583. mode combination requires that (not all monitors and mode support the 
  584. mouse on pages higher than page 0). If you want to display the mouse cursor 
  585. at other times, use wmouse_turn (ON) and wmouse_turn(OFF) but BE SURE to 
  586. use these calls in pairs or the poor little critter will get confused.
  587.  
  588. If you add a  Super VGA 800*600 driver (available thru 3rd 
  589. parties for TurboC), you need to code a mouse driver. Most mouse 
  590. drivers do not work in 800*600 mode. My version was written by a 
  591. friend for me and I can't release it. I might rewrite using 
  592. different methods in the future and if I do I will release that 
  593. version.
  594.  
  595. When the mouse is used, wgetc() returns the value MOUSE. If the right 
  596. button on the mouse is pressed, wgetc() returns ESCAPE (ie: right 
  597. button always performs ESCAPE key function) After testing for 
  598. (keystroke==MOUSE), you should check the global structure 'wmouse' to 
  599. see what was done with the mouse. The elements contained in wmouse are 
  600. documented in define.doc.
  601.  
  602.             keystroke = wgetc();
  603.             if ( keystroke == MOUSE ) 
  604.                 {
  605.                 if ( wmouse.wms_inwindow )
  606.                     ...mouse is inside current window
  607.                 if ( wmouse.wms_used & WMS_LEFT_RLS ) 
  608.                     ... released left button
  609.                 if ( wmouse.wms_x == 3 )
  610.                     ...mouse is at x=3 in current window co-ords 
  611.                 ...etc...
  612.                 }
  613.  
  614.             See demomous for other examples.
  615.             
  616.  
  617. wgets() allows typing of text into an area of screen, and places results in 
  618. a string that you specify. You set the maximum length of the input field. 
  619. Don't forget the string size MUST include the terminal \0. ie YES=4 bytes long.
  620. The original contents of the string are displayed before the user types 
  621. anything. Text input begins at the current location and 'wraps' around to 
  622. next line if needed. Simple editting includes 
  623.     insert/delete, 
  624.     CTRL-Y (delete to end), 
  625.     CTRL-O (replace with original version). 
  626.     ESCAPE quits text entry without changing the contents of the original data.
  627. This function works in either text- or graphics- modes. In graphics modes, 
  628. a pseudo-cursor is created. In text mode, the PC hardware cursor is 
  629. temporarily turned ON, then turned off at exit. 
  630.  
  631.  
  632.  
  633.  
  634.  
  635. BUTTONS are areas onscreen that the mouse can point to and select. 
  636. Mouse selection of a BUTTON is translated to a key value that you 
  637. associated with the button. See demomous (or calls to wpromptc() in 
  638. any of the demos). Ex:
  639.  
  640.             wbutton_add ( "Press Me", 3, 5, 9, 'P', WBTN_BOX );
  641.                     /* The words Press Me are placed at x=3, y=5 in a 
  642.                        box of length 8+1. (1 is for terminal NULL) 
  643.                        The value 'P' is assigned to the button. 
  644.                      */
  645.             wbutton_add ( "F10 - QUIT", 3, 8, 11, FKEY(10), 0 );
  646.                     /* The words F10 - QUIT are placed at x=3, y=8
  647.                        for length 10+1. No box is drawn.
  648.                        The value FKEY(10) is assigned to the button. 
  649.                      */
  650.             keystroke = wgetc ();
  651.                     /* if the left button was released with the mouse in 
  652.                        ...the 1st button area defined above, keystroke='P'
  653.                        ...the 2nd button area, keystroke= FKEY(10) 
  654.                        NOTE also:
  655.                        if P was pressed on the keyboard, keystroke='P', not 'p'
  656.                        if F10 was pressed, keystroke = FKEY(10)
  657.                      */
  658.             if ( keystroke == 'P' )
  659.                     ... either mouse click in button or 'P' on 
  660.                     keyboard...
  661.             else 
  662.             if ( keystroke == FKEY(10) )
  663.                     ...
  664.                     
  665. SCROLLBARS are vertical bars that can be set to a 'value' by 
  666. positioning on them with the mouse. Scrollbars are created with 
  667. wscrollbar_add(), just like wbutton_add(). A unique keystorke code is 
  668. assigned to the scrollbar, which should not be a valid keyboard key (ie, -1 
  669. works, so does 600) You specify screen location and length of scrollbar, 
  670. and a 'virtual range'. The 'value' of the scrollbar will then be a 
  671. 'long int' between 0 and the virtual range. The function wscrollbar_scroll() 
  672. tracks the mouse while the left button is down and returns the new value for 
  673. the scrollbar. You can redraw the pointer on the scrollbar to show a new 
  674. value by calling wscrollbar_reset().  See demomous.c for example.
  675.                     
  676.                     
  677.                     
  678.                     
  679. Higher level interaction with the user is done with: 
  680.     wpromptc() - prompt for a single keystroke.
  681.                  CAUTION: remember to give NULL as the lst argument!!!
  682.     wprompts() - prompt for a string of specified lenght.
  683.     wpicklist()- chose an item from a NULL terminated list of strings.
  684.     wscanform()- get multiple items of data, with validation.                          
  685.     wscrollbar_scroll() - mouse scrollbars.
  686.     wdraw ()   - TurboC graphics mode only - draw lines, rectangles, etc
  687.                     
  688.                     
  689.                     
  690.  
  691.                                HOTKEYS
  692.                                
  693. HOTKEYS are keys that activate a routine independent of the main 
  694. program. If you have TurboC, in the integrated environment, the 
  695. F-keys are all hotkeys. Similar for QuickC. 
  696.  
  697. The easy way to install a hotkey handler is to call the 
  698. whotkey_install() function, specifying both the key value and the 
  699. function.
  700.         
  701.         void myfunc (void);        /* function that does something */
  702.  
  703.  
  704.         winit ( mode );
  705.         whotkey_install ( HOME, myfunc );
  706.         
  707. The function myfunc will be called whenever the HOME key is 
  708. pressed. If the function is already active at the time of the 
  709. keypress, it will not be called twice, and the keystroke will be 
  710. passed thru. See demohkey for examples. 
  711.  
  712. A number of useful hotkey routines are provided in the WTWG 
  713. package including: context sensitive help ( whelp_install ), 
  714. pulldown menus ( wpulldown ), HP laserjet screen dump ( 
  715. whplj_install ), and ability to use the mouse center button to 
  716. act like a hotkey ( wmspopup & wpopfkey ) and a simple keyboard 
  717. macro recorder ( wmacro_install ).
  718.         
  719. Note that this allows you to write traditional programs (the 
  720. program controls when keyboard action takes place and what is 
  721. done with user actions) or 'event-driven' programs (the keyboard 
  722. manager gets a key and decides which routine should be given the 
  723. new input). If your program has one main routine that asks the 
  724. user a series of questions and then takes action, there is no 
  725. need for hotkeys, menus, etc... If the majority of your program 
  726. is reached by hotkeys (or pulldown menus, which are implemented 
  727. as a hotkey) then it is 'event-driven.' Such programs are made up 
  728. of many void funcs(void) that communicate with each other by way 
  729. of global-scope variables.  
  730.         
  731. A more complex, and more flexible, way to install hotkeys is to 
  732. point the global variable 'wkeytrap' to the function that scans 
  733. for the key and executes the sub-task. Be sure to hang on to the 
  734. addresses any previously installed hotkey routines and 'chain' to 
  735. them in your hotkey routine, otherwise the help and menu systems 
  736. won't work (or any other hotkeys you invent). If your hotkey is 
  737. pressed, the routine that handles it should return 0, indicating 
  738. that another keystroke is needed. If the key is not your hotkey, 
  739. return the key itself.  If you use the first method, you won't 
  740. have to worry about this stuff.
  741.                 
  742.             static int (*prev)(int) =NULL;        
  743.                     /* save previous hotkey routine for chaining */
  744.             static int installed    =0;            
  745.                     /* prevent mult. installations */
  746.     
  747.     
  748.             int hotkey (int key)
  749.                 {
  750.                 if ( prev )
  751.                     {
  752.                     /* chain to previous hotkey routine.
  753.                        which may return '0' (ie, swallows the key.)    
  754.                      */
  755.                     key = (*prev)(key);
  756.                     }
  757.                 
  758.                 
  759.                 /* routine handles hot key functions  */
  760.                 if (key == HOTKEY_VALUE)
  761.                     {
  762.                     /* do something interesting */
  763.                     return (0);            /* swallow hotkey, get another key */
  764.                     }
  765.                 else
  766.                     return (key);        /* return key */
  767.                 
  768.                 }
  769.             
  770.             void install_hotkey (void)    
  771.                 {
  772.                 if ( installed ) return;
  773.                 prev = wkeytrap;            /* save previous hotkey */
  774.                 wkeytrap = hotkey;
  775.                 installed =1;
  776.                 }
  777.     
  778.     
  779. Within the source code of the library, example programs that use 
  780. the complex method of creating hotkeys may be found in wpulldn.c 
  781. (pulldn menus - checks for ALT_letter and for mouse click on menu 
  782. bar) and wmspopup.c (checks for mouse center button).             
  783.      
  784.      
  785.                            POPUP MENUS
  786.  
  787. Popup menus are lists of choices that the user can make. In WTWG, 
  788. popup menus are created by the function wpicklist(). You pass the 
  789. function a title for your menu, and a pointer to an array of 
  790. strings (one string for each choice), terminated by NULL. 
  791. wpicklist(title, list) displays the lsit, allows the user to 
  792. choose one element, and returns the element number (first element 
  793. is #0). If the user presses ESCAPE, the return value is equal to 
  794. the number of choices. You can use the return value as an index 
  795. to the list of choices. 
  796.  
  797.  
  798. Example:
  799.  
  800.         int  choice;
  801.         char *my_list[] = {"ONE","TWO","THREE","FOUR",NULL};
  802.         
  803.         choice = wpicklist ( "Choose a number", my_list );
  804.                         /* a box with the choices pops on the screen
  805.                          * and disappears after a choice is made
  806.                          */
  807.  
  808.         
  809.         if ( my_list [choice] == NULL )
  810.             {
  811.             ... user pressed ESCAPE...
  812.             }
  813.         else
  814.             {
  815.             ... choice=0 means selection was "ONE", etc...
  816.             }    
  817.             
  818. If you have TurboC++ you can also use some WTWG-extension 
  819. functions released separately to C users group. These functions 
  820. will create file directory lists as pop-up menus, etc...
  821.  
  822.              
  823.                     
  824.                          PULLDOWN MENUS 
  825.  
  826. Large programs are neatly organized by pulldown menus. Each 
  827. choice in a menu is either a sub-menu or a function. The 
  828. functions are declared as: void menu_func (void); The menu 
  829. manager then acts as an event-driven interface, so your functions 
  830. are called only when the user activates the menu.  
  831.  
  832. Pulldown menus are created from a tree of tables, organized 
  833. hierarchically. Each table is an array of the type WMENU ( 
  834. a typedef defined in window.h). One table element produces one 
  835. menu choice. Nested menus are created by setting a pointer in the 
  836. WMENU structure to another table of WMENUs. Each table element 
  837. references a function of type void with no parameters (ie: void 
  838. menu-func(void) ), these functions do the indicated tasks. You 
  839. can place all the startup code and menu tables in one file, and 
  840. place the functions in other files, and so build complex programs 
  841. by a mix-and-match approach. At program startup, call 
  842. wpulldown_install() to setup the menu onscreen. This routine also 
  843. places a 'trap' in wgetc() so any 'hotkey' from the menu table is 
  844. recognized and control is passed to the menu. Menu items may also 
  845. be selected by mouse. F1 gives context-sensitive help for each 
  846. item in the menu tree. See the example in demomenu.c.
  847.  
  848.  
  849.  
  850.                         DATA ENTRY FORMS
  851.                               
  852. Complex data-entry forms are supported using a table-driven 
  853. approach. Each element in a WFORM table is of type WFORM ( a 
  854. typedef defined in window.h ). The WFORM table also specifies the 
  855. size of the form onscreen. Many data types are supported, and 
  856. provision is made for custom data validation, allowing 
  857. arbitrarily complex data types. Some simple macros are provided 
  858. to allow WFORM tables to be created easily. These include string, 
  859. integer, float, date, and time. Data items can automatically 
  860. invoke a pop-up list of choices. Context-sensitive help is 
  861. integrated into the form manager; F1 provides help for each 
  862. individual item in the form. See the examples in demoform.c.
  863.                         
  864.                                  HELP
  865.                                 
  866. Online context-sensitive help is supported.  Place the text of 
  867. your help in a file called helpfile.HLP. Help topics are 
  868. identified by starting with the character '@'in column 1. The 
  869. text for that topic follows. Text should be 50 columns by 5 
  870. lines, per topic. Examples of help files are demomenu.hlp.
  871.     
  872. The next step is to use the program MAKEHX.EXE to create a 'help 
  873. index' file which will be named helpfile.HX. From the DOS prompt 
  874. type: makehx helpfile<Entrer>. Then, in your 'C' program, install 
  875. the online help program with:  whelp_install ( "helpfile" ); The 
  876. help topic changes appropriately with different choices in 
  877. pulldown menus or with different input lines in FORMS. You can 
  878. also change the help index explicitly. See the sample files on 
  879. the disk (*.HLP) and the demo programs DEMOFORM.C and DEMOMENU.C
  880.  
  881.                             COMMON ERRORS
  882.  
  883. 0) Starting counts incorrectly at 1, rather than 0. In this coordinate 
  884.     system, the upper left corner of a window is 0,0 and winxmax is 
  885.     the actual value of last valid x-byte not 1 higher, etc. 
  886.     Correctly coded loop:  for(n=0; n<= w0->winxmax; ++n) 
  887.  
  888. 1) forgetting to call winit() or using lower case letters in call to 
  889.     winit(). System hangs. Correct: winit('G') for graphics mode or 
  890.     winit('T') for text mode. Incorrect: winit('t'); 
  891.  
  892. 2) requesting 1 byte too few in call to wopen becuase wopen needs 
  893.     actual number of rows and columns. should be winxmax+1. Also, 
  894.     the border is not counted in the request for window size, but 
  895.     does affect window placement and whether window fits 
  896.     onscreen.
  897.     
  898. 3) forgetting terminal NULL argument in call to wpromptc(). Program 
  899.     terminates with message 'window out of bounds' or junk onscreen.
  900.     Correct call:  
  901.         key= wpromptc("TITLE", "QUESTION?", "ANSWER 1", "2", NULL);
  902.     Incorrect call: 
  903.         key = wpromptc ( "QUESTION", "1", "2" );
  904.     
  905.     Similarly, don't forget terminal NULL on list of ptrs to wpicklist(),    
  906.     and don't forget NULL terminating entries for menus and forms.
  907.     
  908. 4) creating a 'hotkey' routine by the complex method and 
  909.     forgetting to chain to previous hotkeys. Use whotkey_install() instead.
  910.     See wmsdrag.c for example of how to do it the complex way.
  911.                 
  912. 5) function called by pulldown menu program MUST quit if ESCAPE key is 
  913.     typed, but may require multiple ESCAPEs for confirmation. If you     
  914.     forget this, and do not return after ESCAPE, program may go into 
  915.     infinite loop.
  916.  
  917. 6) Forgetting to wclose() a window - you eventually run out of memory, 
  918.     or subsequent calls to wclose() will close the wrong window, and 
  919.     then output will go the the wrong window, garbage will show up 
  920.     onscreen, etc... Some functions return ptrs to windows wopen()ed 
  921.     by that function call, so the window has to be wclose() 'd by you 
  922.     after return. ie, wdraw() returns a ptr to a structure it allocates 
  923.     (see demomous), and wfprintfm() returns a ptr to a window it openned 
  924.     that needs to be closed (see demoform()). Etc...
  925.     
  926. 7) Using wreopen() to place an earlier window on top of the stack, and 
  927.     then returning. The window stack order is confused, and the wrong 
  928.     window gets wclose()'d.
  929.  
  930. 8) Forgetting the terminal NULL when specifying string sizes. The 
  931.     standard C function strlen() returns the number of bytes NOT 
  932.     COUNTING the terminal \0. You should add 1. This affects the 
  933.     following: wgets(), wbuttton_add(), data entry forms, many 
  934.     others
  935.  
  936. 9) WFORM - onscreen form abruptly scrolls out of view and program hangs.
  937.     3 possibilities:     1) bug in wscanform() fixed in version 1.2
  938.                         2) first or last item in WFORM table[] is a label
  939.                             (ie: no data item). Move labels to center of table.
  940.                         3) lengths of labels are too long 
  941.                             Labels must fit on line to left of start of data.
  942.  
  943. 10) garbge onscreen when using wgets() or wprompts()  ( or wscanform )
  944.         You did not initialize the string storage area to blanks or \0.
  945.         
  946. 11) compiler errors: unable to open file 'wtwg.h' or 'stdio.h'
  947.         You installed WTWG into its own directory (a good idea)
  948.         but didn't tell the compiler about it.
  949.         To fix this problem: 
  950.             Microsoft users: either switch to TurboC 
  951.                              or set environment variables LIB= and INCLUDE=
  952.             TurboC users: IDE: set OPTIONS/COMPILER/DIRECTORIES
  953.                                and OPTIONS/LINK/DIRECTORIES
  954.                           command line version: write a TURBOC.CFG file
  955.                                   with -L and -I options.
  956.                                 
  957. 12) Linker errors:
  958.     -forgetting to specify the graphics libraries if you use wgs.lib, mwgm.lib
  959.         (even if your program doesn't do any graphics, in which case you 
  960.             should use wts.lib for text-only library)
  961.     -floating-point errors: 
  962.         you have a float-type data element in a data entry form
  963.         but your program doesn't do any floating point math. see demoform.c
  964.     -duplicate symbol: you are using heapdbg to create a simplified version
  965.         for testing, and the linker gives about ten thousand 'duplicate'
  966.         warning messages: ignore them all.
  967.     -symbol not found: _LXMUL and similar names.  
  968.         You are using a WTWG library compiled using Turbo C++
  969.         but you are still using the pre-C++ version of TURBO C. 
  970.         You should upgrade.    
  971.  
  972. 13) mysterious program crash, message "Memory Allocation Error, 
  973. Cannot load COMMAND.COM, System Halted" or onscreen garbage in 
  974. hercules graphics mode program and system hangs: Either your 
  975. program has exceeded the 4k default stack in TurboC (in which 
  976. case, add the line "unsigned _stklen=20000;" at the start of your 
  977. program) or your small model program has grown too large (rebuild 
  978. using large model), or you have a floating point math error or an 
  979. integer zero divide (see TurboC routine matherr()). 
  980. Alternatively, there is a memory overwrite in a large model 
  981. program somewhere, good luck finding it.
  982.  
  983. 14) garbage onscreen when you move the mouse (especially in VGA): 
  984. You turned ON the mouse cursor and left it on when doing screen 
  985. output. If you use wgetc() and higher-level input functions only, 
  986. you should never have to worry about this. If you need to 
  987. manipulate the mouse, make sure you turn it OFF immediately after 
  988. use and don't mix mouse routines with screen output.
  989.  
  990.         
  991.                         ACKNOWLEDGEMENTS
  992.  
  993. The overall plan of the routines is somewhat unique. The idea of 
  994. a mode-independent windows system is wholly my own. The 8-bit 
  995. character size and the simplifications and speed enhancements it 
  996. allows are my own idea and as far as I know are unduplicated 
  997. anywhere. The scheme of linked lists, with the current window on 
  998. top, is fairly common, but was developed independently by me. The 
  999. method of mouse and keyboard integration is, to my knowledge, 
  1000. unique. The idea of BUTTONS and HOTKEYS comes from a simplified 
  1001. understanding of the X-WINDOWS widget.
  1002.                         
  1003. Most of the low-level video access methods come from TURBO C 
  1004. PROGRAMMING ON THE IBM PC, by LAFORE. The EGA routines for write 
  1005. mode 1 (used in wscroll() and wclear()) come from trial and 
  1006. error. Other IBM PC hardware routines, especially cursor, 
  1007. keyboard, mouse, and expanded memory calls, come from DOS 
  1008. PROGRAMMERS GUIDE by Dettman. The basics of the 43/50 line EGA 
  1009. mode logic comes from DOS POWER TOOLS by SOMERSON, but as far as 
  1010. I know there is no resource for handling mouse and multiple 
  1011. video pages in 43/50 line mode; that was trial and error. The 
  1012. revised logic for using the enhanced keyboard in wkbd.c comes 
  1013. from an article in the July 1990 C User's Journal by by STEVE 
  1014. GRUEL. The printer driver commands for the laserjet comes from the 
  1015. HP manual.
  1016.  
  1017. The text of these routines was written using VEDIT, an excellent 
  1018. editor. All the main development and debugging was done in 
  1019. TurboC. 
  1020.  
  1021.  
  1022. Contact me for any problems.
  1023. Enjoy.
  1024.  
  1025.