home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_01 / funcs.doc < prev    next >
Text File  |  1991-04-11  |  66KB  |  2,104 lines

  1. /*
  2. HEADER:         documentation file - FUNCS.DOC
  3. TITLE:        FUNCS.DOC
  4. VERSION:    1.0
  5. DATE:        5/1/90
  6.  
  7. DESCRIPTION: documentation of procedure calls for windows routines - 
  8.              functions are grouped in related 'families' 
  9.  
  10. KEYWORDS:    windows, keyboard, mouse, text, graphics, expanded memory, menus;
  11. SYSTEM:        MS-DOS v3.0, probably works with v2.0 but untested;
  12. FILENAME:    FUNCS.DOC
  13.  
  14. WARNINGS:    
  15.  
  16. SEE-ALSO:   WTWG.DOC, DEFINE.DOC    
  17.                 
  18. AUTHOR:    David Blum
  19. COMPILERS:    Turbo C v2.0, Microsoft C v5.1
  20. */
  21.  
  22.  
  23.  
  24.  
  25. /*--------------------- Initialization routines ----------------*
  26.  *                                        
  27.  *    winit, deskview, 50line mode, SysRq, 
  28.  *     palette and clock routines             
  29.  *                                      
  30.  *                                      
  31.  *--------------------------------------------------------------*/
  32.  
  33.  
  34.  
  35. /*! winit ()
  36.  *    Set a video mode. Open a full screen window.
  37.  *
  38.  *    Parms:     newmode = 'T' or 'G' to set text or graphics.
  39.  *
  40.  *        On VGA, in graphics mode, selects mode 0x12 (=640x480)
  41.  */
  42. void winit ( char newmode );
  43.  
  44. /*! winit_pages()
  45.  *     Sets a video mode and opens a full screen window.
  46.  *    Also clears video memory for the higher pages
  47.  *        (may contain garbage otherwise)
  48.  *    and provides for mouse use for multiple pages (Hercules monitors)
  49.  *      
  50.  *       On VGA, selects mode 0x10 (=640x350)
  51.  */
  52. void winit_pages ( char newmode );
  53.  
  54.  
  55. /* wdvinit() 
  56.  *         Initialization code for DeskView aware programming.
  57.  *        Call this routine immediately after call to winit()
  58.  *        ...ie, BEFORE any direct screen writes.
  59.  *         Incompatible with multiple page display (winit_pages)
  60.  *        Tested only in text mode, one page. untested in all graphics modes.
  61.  *
  62.  *    RETURNS: 0     = not a DeskView task
  63.  *             non_0 = a DeskView task (#is DeskView (major) version number 
  64.  */
  65. int wdvinit (void);
  66.  
  67.  
  68.  
  69. /* w50line()
  70.  *         SET VGA 50 (EGA 43) line video mode, or restore 25-line mode.
  71.  *        PARAMETERS: want_50 =     0 (OFF) to restore 25-line mode
  72.  *                                non-0 to set 50/43 line modes
  73.  *        RETURNS:    0 if new mode is 25 line mode (ie, call failed)
  74.  *                    non-0 if new mode is 50/43 line mode (call succeeded)
  75.  *
  76.  *        NOTES:    
  77.  *        1)     when switching from 25 to 50 line mode the first time,
  78.  *               the program clears the lower  25 lines (or 18 lines EGA)
  79.  *            to the color of the current window.
  80.  *        2)  MOUSE movement is changed to match new screen size.
  81.  *        3)  25 line mode automatically restored on exit() or return from main()
  82.  *        4)  Multiple pages are supported, and size of page is changed. 
  83.  *            but page numbers will be wrong for any old windows above page 0.
  84.  *            ALSO, number of pages reduced in 50 line mode from 8 to 4. 
  85.  *                (be sure to recheck wlastpage)
  86.  *        5)  BE SURE CURSOR IS OFF BEFORE CALLING THIS ROUTINE.
  87.  *            (usually not a problem if you didn't specifically turn it ON)
  88.  *        6)  When switching from 50-line mode to 25 line mode,
  89.  *            windows displayed below line #24 will be invisible,
  90.  *            but still saved on the screen.
  91.  */
  92. int w50line ( int want_50 );
  93.  
  94.  
  95.  
  96. /* w_ega_color() 
  97.  *    tells you if an ega card is connected to a monochrome or color monitor.
  98.  *     useful if wmonitor =='E', which is an EGA
  99.  *    cannot tell if an VGA is connected to a color or gray-scale monitor
  100.  *    and cannot tell what kind of monitor is connected to a CGA
  101.  *    RETURNS:  OFF if monochrome monitor (or Hercules or MDA)
  102.  *              ON  if VGA, EGA/color, or CGA
  103.  *        
  104.  */
  105. int w_ega_color(void);
  106.  
  107.  
  108.  
  109. /* palette routines
  110.  *
  111.  *        wsetpalette() sets the EGA/VGA palette from 17-byte save area.
  112.  *        wgetpalette() gets palette data into 17-byte save area 
  113.  *
  114.  *        The palette is 17 bytes, ie  16 colors and a border color
  115.  *                    valid color choices are 0-255.
  116.  *                    default is border =0, colors 0 to 15 = 0 to 15.
  117.  *
  118.  *        EGA/VGA only. NO TESTING FOR MONITOR TYPE IS DONE IN THE ROUTINES.
  119.  *
  120.  *        PARAMETER: 
  121.  *            unsigned char palette[17] = array of 17 bytes to hold palette data.
  122.  *        RETURNS: void.
  123.  *                
  124.  */
  125. void wsetpalette( unsigned char palette[17] );
  126. void wgetpalette( unsigned char palette[17] );
  127.  
  128. /* wSysRrq_install() and remove.
  129.  *
  130.  *      Sys Rq interrupt handler - on AT and PS/2 or newer XTs only
  131.  *
  132.  *        When user presses SysRq (=ALT_PrintScreen), an interrupt is generated.
  133.  *            This can be used as a replacement for CTRL_, which is ignored
  134.  *        
  135.  *        The routines describe here install/remove an interrupt handler
  136.  *            (and install an atexit() routine to remove same handler)
  137.  *
  138.  *    wSysRq_install ():
  139.  *        PARAMETERS: u_func is a function to be called when SysRq is pressed.
  140.  *                    should be prototyped as 'void u_func(void)'
  141.  *        RETURNS: void. Program halts if unsuccessful.
  142.  *    wSysRq_remove ():
  143.  *        removes any existing SysRq interrupt handler.
  144.  *        PARAMS & RETURNS: void.
  145.  *    wSysRq_ask ():
  146.  *        a sample interrupt handler. Asks 'Do you want to quit?'
  147.  *
  148.  *
  149.  *    example:
  150.  *        winit ('T');
  151.  *        wSysRq_install ( wSysRq_ask );
  152.  *        ...    
  153.  *
  154.  *  NOTES: 
  155.  *        1) ONLY available in TurboC version. 
  156.  *        2) BE CAREFUL HOW YOU COMPILE THIS ROUTINE. See source file wsysrq.c
  157.  *        2) You may have to increase the stack size... 
  158.  *            if your use a complex function as your SysRq handler.
  159.  *        3) Your interrupt routine will be ignored
  160.  *             ...when running as a virtual task under DeskView 
  161.  *            ...or if you read keyboard using any of these 'non-windows' funcs:
  162.  *                getch(), gets, cgets, or  DOS interupt 0x21
  163.  *            (works if all keyboard reads are done using wgetc() or wreadc() )
  164.  *        5) USER has to press SysRq again to unlock keyboard.
  165.  */
  166. void wSysRq_install ( void (*user_func)(void) );
  167. void wSysRq_remove (void);
  168. void wSysRq_ask (void);
  169.  
  170.  
  171.  
  172. /* w_inDOS() 
  173.  *        test the inDos flag. (useful for writing interrupt handlers) 
  174.  *        Interrupt handler routines sometimes have to test the system state
  175.  *        (ie, cannot ask for DOS services if interrupt occured while in DOS)
  176.  *        In most programming environments, this is very complex.
  177.  *    
  178.  *        In this windows environment, it is easy IF you exclusively use wgetc()
  179.  *            (or related wreadc(), wread_kbd(), wgets(), or mouse funcs)
  180.  *        (caution: may not work well if you mix methods of keyboard access)
  181.  *
  182.  *        RETURNS: zero if not in DOS, so is safe to ask for DOS services/
  183.  *                 non_zero if in DOS, do not proceed with DOS calls.
  184.  *
  185.  *        NOT AVAILABLE in microsoft c.
  186.  *        example:
  187.  *
  188.  *        void  interrupt my_handler (void)    
  189.  *                {
  190.  *                if ( ! w_inDOS () )
  191.  *                    {
  192.  *                    ... do whatever you want...
  193.  *                    }         
  194.  *                }
  195.  */
  196. char w_inDOS (void);
  197.  
  198.  
  199.  
  200.  
  201.  
  202. /* wclockinstall() and wclockremove()
  203.  *    pass the on-screen clock a pair of screen co-ords
  204.  *    where you would like the clock to be. CLOCK format is HH:MM = 5 bytes.
  205.  *
  206.  *  the clock is automatically removed at program termination. (atexit func)
  207.  *
  208.  *
  209.  *    NOTE: this clock will run in both text and graphic modes, 
  210.  *        but in graphics modes on EGA/VGA you can get garbage onscreen
  211.  *        unless you UNINSTALL the clock before doing any graphics output
  212.  *               and REINSTALL the clock when ready for user keystrokes.
  213.  *        works OK on hercules cards graphics, though
  214.  *
  215.  *    TURBOC only.
  216.  */
  217. void wclockinstall (int x, int y);
  218. void wclockremove  (void);
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228. /*--------------- window definitions and manipulation ----------------*
  229.  *                                                             
  230.  *  Window definition
  231.  *    wdefine, wabandon ---> create and destroy windows.
  232.  *                no actual screen access
  233.  *                (such as saves/restores, draw frame, clear...)
  234.  *
  235.  *                usually these functions are less useful
  236.  *
  237.  *
  238.  *
  239.  *    wopen, wclose  -----> create & destroy windows.
  240.  *                            accesses screen:
  241.  *                    wopen saves underlying image
  242.  *                            draws frame.
  243.  *                    wclose restores old image.
  244.  *
  245.  *  alter window priority
  246.  *    wreopen, wbury
  247.  *
  248.  *
  249.  *  window display
  250.  *    whide, wshow
  251.  *
  252.  *
  253.  *  Window appearance
  254.  *    wframe(), wtitle, wps
  255.  *
  256.  *  change display page.
  257.  *    wturnpage()  wsetvisualpage() ------> change displayed page.
  258.  *
  259.  *  Window lovation
  260.  *    wrelocate, wdrag, wmsdrag   -----> move windows
  261.  *
  262.  *  Screen image
  263.  *    wsave, wrestore       -----> save/restore window images.
  264.  *                                                                    *
  265.  *--------------------------------------------------------------------*/
  266.  
  267.  
  268.  
  269. /*! wopen, wclose, wdefine, wabandon
  270.  *
  271.  *    wopen - saves the underlying screen contents, attributes and cursor
  272.  *            opens a new window at specified location, draws border,
  273.  *            returns the address of the window it opens,
  274.  *            which you may ignore, or may use to wreopen or wrelocate.
  275.  *              In (BGI) graphics mode, sets viewport, activepage, etc...
  276.  *        PARAMETERS:
  277.  *        left, top = screen coords of upper left corner of text portion
  278.  *                     note that any border is above and to left of this.
  279.  *                    Start counting at 0,0
  280.  *        xmax, ymax = number of columns and rows in window. 
  281.  *                    Starts counting at 1,1. 
  282.  *                    w0->winxmax will be set to this number -1.
  283.  *        attr = color for text. first 4 bits = background. low 4 bits = text.
  284.  *        box  = type of border. SINGLE_BORDER, DOUBLE_BORDER, etc.. 
  285.  *        boxattr = color for border.
  286.  *
  287.  *         save2 =WSAVE2NULL ==> no save
  288.  *               =WSAVE2RAM  ==> save underlying contents
  289.  *
  290.  *        To setup output to a new page,
  291.  *            change wnextpage before calling wopen().
  292.  *
  293.  *        If no border is specified, the new window is not cleared.
  294.  *        If a  border is specified, the window is cleared
  295.  *
  296.  *
  297.  *    wdefine - same as wopen, but does not save underlying image
  298.  *        and does not clear window or draw frame.
  299.  *
  300.  *
  301.  *
  302.  *    wclose - restore screen contents, close the current window
  303.  *
  304.  *
  305.  *    wdefine  - allocates storage and sets up window, ready for
  306.  *           ouptut, but no screen access takes place,
  307.  *           save areas not allocated, no frame is drawn.
  308.  *
  309.  *    wabandon - remove the current window from memory,
  310.  *           but leave its image on the screen.
  311.  *           note: identical to wclose() but doesn't restore screen.
  312.  *
  313.  *        see also: wunlink, wlink, wreopen, wbury
  314.  */
  315. WINDOW    *wopen
  316.         (int x, int y, int xmax, int ymax,
  317.          unsigned char attr, int box, unsigned char box_attr,
  318.          unsigned char save2 );
  319.  
  320.  
  321.  
  322.     /* save modes for wopen
  323.      */
  324.     #define WSAVE2NULL    0    /* don't save window */
  325.     #define WSAVE2RAM    1    /* save to RAM */
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. WINDOW *wdefine (int x, int y, int xmax, int ymax,
  335.          unsigned char attr, int box, unsigned char box_attr );
  336.  
  337.  
  338.  
  339. void    wabandon (void);
  340.  
  341. #define wclose()    ( wrestore(), wabandon() )
  342.  
  343.  
  344. /*! wreopen, wbury
  345.  *
  346.  *    wreopen - make the indicated window the current window.
  347.  *          the previously open window becomes the second
  348.  *          window on the chain.
  349.  *        DOES NOT check for overlapping windows.
  350.  *        you can get screen garbage by reopenning a window
  351.  *        with other windows on top of it.
  352.  *
  353.  *    wbury  - make the current window  the second-to-last window
  354.  *        (the last window is the full-screen window)
  355.  *        this allows reuse of one common window while
  356.  *          ... maintaining priority relationships amoung other windows
  357.  *
  358.  *
  359.  *    NOTE: you can wreopen() or wbury() the initial window  (wfullscreen)
  360.  *            but when you bury this window it becomes the last window
  361.  *          and if you try to wclose(), it will be burried instead.
  362.  *          That way the wfullscreen window is never closed.
  363.  *
  364.  */
  365. void     wreopen ( WINDOW *new );
  366. void    wbury   ( void );
  367.  
  368.  
  369.  
  370.  
  371. /*! wrelocate()
  372.  *    move a window to a new location
  373.  *    the window must have been created with WSAVE2RAM.
  374.  *
  375.  *    RETURNS: 0 if successful
  376.  *        -1 if failure. Can fail because:
  377.  *            wndow was openned with WSAVE2NULL - cannot restore
  378.  *            new address out of bounds
  379.  *            not enough memory to save images of screen
  380.  *
  381.  *
  382.  *
  383.  */
  384. int     wrelocate (int x, int y);
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391. /*! wlocate(), wsetlocation(), wstrrowcol()
  392.  *
  393.  *    tools for automatically sizing and placing windows
  394.  *    ( commonly used code placed in one spot and easy to use )
  395.  *
  396.  *    wlocate() : This function determines where to put the top left corner
  397.  *            based on the type of location specified in wlocation.
  398.  *            See the definition of struct wlocation.
  399.  *                wlocation.wloc_type sets allowable places:
  400.  *                    WLOC_CENTER = center of screen
  401.  *                    WLOC_ATCUR  = current cursor position
  402.  *                                      WLOC_ATWIN  = at top.left of window
  403.  *                    WLOC_ATXY   = at screen co-ords x,y.
  404.  *                wlocation.wloc_x  and .wloc_y give offset
  405.  *
  406.  *                example: wlocation.wloc_type = LWOC_ATCUR
  407.  *                     and .wloc_x = 2, wloc_y = -1
  408.  *                    will place window above and to right
  409.  *                    of current screen location.
  410.  *
  411.  *            Set the desired location prior to calling wlocate().
  412.  *
  413.  *
  414.  *            The following functions use wlocate()
  415.  *                wpromptc, wprompts, wpicklist, wform
  416.  *            so you can change where these windows will appear
  417.  *                by setting new values in wlocation before call
  418.  *
  419.  *                 NOTE: the value of wlocation is reset after each call
  420.  *                the default is center of screen.
  421.  *
  422.  *            PARAMETERS: left, top = address of (int)
  423.  *                    new co-ords  will be placed in these
  424.  *                                  xmax, ymax = size of desired window.
  425.  *
  426.  *            RETURNS: void.
  427.  *
  428.  *    wsetlocation(): a macro that sets up the data
  429.  *            in the wlocation structure
  430.  *                      Simplifies auto-locating windows.
  431.  *
  432.  *            PARAMETERS:
  433.  *                location type, x, y -- as above.
  434.  *
  435.  *            example:
  436.  *                wsetlocation (WLOC_ATCUR, 1, 1);
  437.  *
  438.  *    wstrrowcol(): This function is like a 2-dimensional strlen.
  439.  *            It determines the number of rows and columns
  440.  *               for a string. It finds the longest row,
  441.  *               and counts the number of lines.
  442.  *            IGNORES: \t character, assumes WPUTWRAP is off.
  443.  *            parameters: text = string to check.
  444.  *                    rows, cols= address of (ints) = answers
  445.  *
  446.  *
  447.  */
  448.  
  449. void wlocate ( int *aleft, int *atop, int xmax, int ymax );
  450.  
  451.  
  452. #define wsetlocation(LOC, X, Y)        \
  453.      wlocation.wloc_type=(LOC), \
  454.      wlocation.wloc_x   =(X),   \
  455.      wlocation.wloc_y   =(Y)
  456.  
  457.  
  458. void wstrrowcol ( char *text, int *rows, int *cols );
  459.  
  460.  
  461.  
  462.  
  463. /*! whide() and wshow()
  464.  *
  465.  *      whide restores the original screen contents,
  466.  *        which effectively hides the current window
  467.  *    wshow restores the curren screen contents
  468.  *
  469.  *    obviously, whide must be called before wshow,
  470.  *        and if another window is openned in between,
  471.  *        chaos will result.
  472.  *
  473.  *    whide() : PARAMETER none,  RETURNS void far *
  474.  *    wshow() : PARAMETER void far *, RETURNS none.
  475.  *
  476.  *            you have to provide wshow the pointer
  477.  *                that was returned by whide.
  478.  */
  479. void far *whide ( void );
  480. void wshow ( void far *hideptr );
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490. /*! wframe, wtitle, wps
  491.  *
  492.  *     draw a box on the screen
  493.  *        The style types are defined in this header file
  494.  *            ( see NO_BORDER, SINGLE_BORDER, etc...)
  495.  *    place a 'title' in the top line of the box
  496.  *    place a trailing message (like P.S. for a letter) in the bottom line
  497.  */
  498. void         wframe  (int l, int t, int r, int b,
  499.              int style, unsigned char color);
  500. #define    wtitle(title) wborderwrite ('t', 'c', (title))
  501. #define    wps(footnote) wborderwrite ('b', 'r', (footnote))
  502.  
  503. void wborderwrite (char line, char justify, char *title);
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510. /*! wsetvisualpage () or wturnpage()
  511.  *
  512.  *    changes the displayed page.
  513.  *    does not change which page wputc/wputs etc write to...
  514.  *      the visual page does not have to match the page of the current
  515.  *      window
  516.  */
  517. void     wsetvisualpage (int page);
  518. #define wturnpage(new)    wsetvisualpage( (new) )
  519.  
  520.  
  521.  
  522.  
  523.  
  524. /*! wsave, wrestore
  525.  *
  526.  *
  527.  * wsave saves current contents of screen indicated by window pointer
  528.  *     and stores the far * pointer to the save area in winsave.
  529.  *      NOTE if w0->winsave is not NULL on entry, wsave will use that area.
  530.  *        to hold the screen image,without checking for area size.
  531.  *        BE CAREFUL.
  532.  *
  533.  * wrestore restores the screen contents from the save area pointed to
  534.  *    in the window. Does not free the storage.
  535.  */
  536. void     wsave    (void);
  537. void     wrestore (void);
  538.  
  539.  
  540.  
  541. /*! wdrag()
  542.  *    Allow user to move a window by keystrokes (arrows, page up/down, etc)
  543.  *        requires WSAVE2RAM when the window is opened.
  544.  *
  545.  *     Parameter: keystroke may be any of the ARROWs, HOME, END, PAGE UP/DN
  546.  *    The current window is moved as indicated by the keystroke.
  547.  *        ( ARROWs move 5 spaces in that direction,
  548.  *          HOME moves to left edge, END moves to right edge
  549.  *          PAGE UP to top of screen, PAGE DN to bottom )
  550.  *    RETURNS: non-zero (original keystroke) if move was successful.
  551.  *               0 if move was not successful, which may be because:
  552.  *            invalid keystroke, outside screen edge, or WSAVE2NULL
  553.  *
  554.  *        SEE wmsdrag() below, for improved version.
  555.  */
  556. int    wdrag (int  keystroke);
  557.  
  558.  
  559.  
  560. /* wmsdrag()
  561.  *        A keytrap routine to increase mouse usefullness.
  562.  *        Call this routine once at startup to allow user to drag any window
  563.  *        Windows which are draggable include:
  564.  *            1) must have a border.
  565.  *            2) must be called with WSAVE2RAM (underlying image stored)
  566.  *            3) in VGA graphics mode, total image size < 64k.
  567.  *
  568.  *        User activates dragging by clicking on upper left corner of window.
  569.  *        
  570.  *        To use, call wmsdrag() once at beginning of program 
  571.  *            to install the mouse-drag keytrap routine.
  572.  *        
  573.  */
  574. void wmsdrag (void);
  575.  
  576. /*    wmspopup () 
  577.  *        install func to be executed whenever the mouse center button is pressed
  578.  *        func is  function that takes no arguments and returns a keyvalue
  579.  *            (simplest example: just return FKEY(1) to trigger help screen)
  580.  *            
  581.  *        This allows the center mouse key to act like a hotkey. 
  582.  *        second calls are OK, they just change which function is called.
  583.  *        calling with NULL inactivates the keytrap.
  584.  */
  585. void wmspopup ( int (*func)(void) );
  586.  
  587.  
  588. /* wpopfkey() -
  589.  *        another keytrap routine to increase mouse usefullness.
  590.  *        Call once at startup to install this routine.
  591.  *            (second calls are OK, and can change the FKEY labels used)
  592.  *        Click center button of mouse brings a popup menu of FKEY 1-12
  593.  *        This allows mouse to generate FKEY commands.
  594.  *
  595.  *        PARAMETERS:  a NULL terminated list of string ptrs for labels.
  596.  *        RETURNS: void.
  597.  *
  598.  *    see DEMOMOUS.C
  599.  */
  600.  void wpopfkey ( char ** fkey_labels );
  601.  
  602.  
  603.  
  604.  
  605.  
  606. /*--------------- control of window contents -------------------------*
  607.  *
  608.  *   text output:
  609.  *    wputc(), wputs(), wprintf(), werror()
  610.  *    wsetattr(), wbright() wdim(), wreverseattr(), wgetattr()
  611.  *   clear areas of window:
  612.  *    wclear(), wclearline() wsetc()
  613.  *   location of text:
  614.  *    wgoto()  wherex() wherey()
  615.  *   miscellaneous:
  616.  *    wscroll()
  617.  *      wgoto()
  618.  *
  619.  *                                                                    
  620.  *--------------------------------------------------------------------*/
  621.  
  622.  
  623.  
  624.  
  625.  
  626. /*! wputc, wputs, wprintf, werror
  627.  *
  628.  *    put char or string to current window
  629.  *
  630.  *    see defines for WPUT... to affect the operation of these routines.
  631.  *    you can change whether the routines:
  632.  *         wrap or clip at the right hand edge
  633.  *            (w0->winputstyle  |= WPUTWRAP )
  634.  *         scroll or goto top of window after last line fills
  635.  *            (w0->winputstyle |= WINPUTSCROLL )
  636.  *         use ANSI formatting codes or put IBM-screen graphics
  637.  *             (w0->winputstyle |= WPUTANSI )
  638.  *         use \n to return\linefeed or just linefeed
  639.  *            (w0->winputstyle  |= WPUTN2RN )
  640.  *            (NOTE TurboC cputs/cputc do not \r\n when they see \n
  641.  *                  but puts/putc and all other compilers do \r\n)
  642.  *               use embedded screen attribute bytes (next byte in string)
  643.  *            (w0->winputstyle |= WPUTATTR )
  644.  *                this only works if WPUTALARM is OFF.
  645.  *
  646.  *
  647.  *
  648.  *
  649.  *
  650.  *
  651.  * wputc will puts a char to the screen.
  652.  *    RETURNS  1 if ok to put next character
  653.  *         0 if you've hit the window boundary and
  654.  *               0 == winputstyle & WPUTSCROLL (bottom edge)
  655.  *            or 0 == winputsyle  & WPUTWRAP   (right edge)
  656.  *
  657.  *
  658.  * wputs puts a string, following all the ANSI escape codes as defined
  659.  *    (unless winputstyle & WPUTANSI == 0)
  660.  *
  661.  *    wputfl puts a 'fixed' size of string. If the provided string is 
  662.  *        too long, it is truncated, if it is too short, the remaining
  663.  *        length is printed as blanks. 
  664.  *        PARMS: char *s= string, int l= number of bytes to put. RETURNS void.
  665.  *
  666.  * wprintf works is like printf, limits text output to window,
  667.  *        follows rules set in winputstyle,
  668.  *       EXCEPTIONS:
  669.  *        does NOT work in tiny model.
  670.  *              limits total number of bytes to size set by WPRINTF_LIMIT
  671.  *            ( for longer strings, allocate a buffer, use sprintf)
  672.  *
  673.  *
  674.  * werror is like perror for fatal messages.
  675.  *    If in graphics mode, restores CRT.
  676.  *    TERMINATES execution.
  677.  */
  678. int     wputc        (char c);
  679. int      wputs        (char *s);
  680. void    wputfl         (char *s, int l);
  681. int     wprintf         (char *format, ...);
  682.  
  683.     #define     WPRINTF_LIMIT    250
  684.  
  685. void    werror        (int errcode, char *errmsg);
  686.  
  687.  
  688.  
  689.  
  690.  
  691. /*! attr
  692.  *
  693.  *    wsetattr() -set screen attributes, set bright or dim letters
  694.  *        attribute = (background color << 4) + foreground color
  695.  *                valid colors are 0 --> 7
  696.  *                fourth bit is blink(background) bright(foreground)
  697.  *                see the enum COLORS above.
  698.  *    wbright - sets ON highlighting
  699.  *    wdim    -      OFF
  700.  *
  701.  *      wreverseattr() - macro which returns the reversed value of an attr.
  702.  *            use as follows: wsetattr(wreverseattr(BLUE));
  703.  *                (sets a BLUE background)
  704.  *
  705.  *
  706.  *
  707.  */
  708. #define wsetattr(x)       ( w0-> winattr = (x)  )
  709. #define wbright()       ( w0-> winattr |=  BRIGHT )
  710. #define wdim()        ( w0-> winattr &=  (0xff - BRIGHT) )
  711. #define wgetattr()      ( w0-> winattr )
  712.  
  713. #define wreverseattr(xx)  (  ( ((xx)&0x0f)<<4 ) | ( ((xx)&0xf0)>>4) )
  714.  
  715.  
  716. /*! wclear, wclearline
  717.  *
  718.  *    clear current window using current attribute.
  719.  *    and clear to end of current line.
  720.  *      these call wlear abs, which clears an area of screen
  721.  *        specified in absolute (not window) co-ords.
  722.  */
  723. void wclear     (void);
  724. void wclearline (void);
  725.  
  726.  
  727. #define wclearln() wclearline()
  728.  
  729.  
  730.  
  731. /*! wsetc
  732.  *     
  733.  *   sets contents of window to a specific character,
  734.  *        beginning at the current position, 
  735.  *        to the right/bottom corner. Uses current attribute
  736.  *
  737.  *     PARAMETER:  char c = character to set. 
  738.  *                            recommend   176 = speckle pattern.
  739.  *                                        206 = double intersecting bars.
  740.  */
  741. void     wsetc (char c);
  742.  
  743.  
  744.  
  745. /*! wscroll
  746.  *
  747.  *       insert a blank line at current cursor postion. scroll up
  748.  */
  749. void     wscroll    (void);
  750.  
  751.  
  752.  
  753.  
  754.  
  755.  
  756. /*! wgoto
  757.  *
  758.  *    goto a specified row =x, col =y.  (0- winxmax, 0-winymax, inclusive)
  759.  *        if x = -1, stays in same row    (moves up/down)
  760.  *        if y = -1, stays in same column (moves across)
  761.  */
  762. void     wgoto (int row, int col);
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771. /*! wherex() wherey()
  772.  *    these are pseudofunctions  -
  773.  *     more efficient to use extern globals, cuts out function calls
  774.  */
  775.     #define wherex()     ( w0-> winx )
  776.     #define wherey()     ( w0-> winy )
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797. /*------------------------  Keyboard input ---------------------------*
  798.  *
  799.  *  get input
  800.  *    wgetc(), wgets()
  801.  *  keyboard status
  802.  *    wkbd_enhanced(), wready(), wflush()
  803.  *  keyboard buffer stuff routine
  804.  *    wpushc() wungetc()
  805.  *  cursor control
  806.  *    wcursor()
  807.  *
  808.  *  wpipe_in(), wpipe_out()
  809.  *  wmacro_install(), wmacro_select, wmacro_names()
  810.  *
  811.  *---------------------------------------------------------------------*/
  812.  
  813.  
  814.  
  815.  
  816.  
  817. /*! wgetc, wgets
  818.  *
  819.  *    get characters from the keyboard and or mouse.
  820.  *
  821.  *    The lowest level routine is wreadc(). This routine does the following:
  822.  *        Checks to see if an input pipe (ie, macro) is active. if so, Uses that.
  823.  *        check mouse to see if it's moved or button clicked.
  824.  *            NOTE: DOES NOT TURN MOUSE CURSOR ON.
  825.  *            if so,     maps right button to ESCAPE key value.
  826.  *                    looks for left click on an onscreen 'push button'
  827.  *                        and translates that into appropriate button value.
  828.  *                    returns key value = MOUSE
  829.  *        checks for keyboard (if not MOUSE).
  830.  *                    maps ordinary keys, scan code keys, and enhanced keys
  831.  *        passes key value to any active output pipes (ie, macro recorder)
  832.  *        
  833.  *
  834.  *
  835.  *
  836.  *    wgetc() does the following:
  837.  *          TURNS ON the mouse cursor
  838.  *            checks to see if either key or mouse hit. If not, waits 
  839.  *                and after 3 minutes, blanks out screen.
  840.  *            When a user action is available, calls wreadc() to get that action.
  841.  *          TURNS OFF the mouse cursor.
  842.  *            passes user key/mouse on to any 'Hotkey' routines.
  843.  *            If key was used by a hotkey routine, repeats process until
  844.  *                ...a key is ready to return.
  845.  *
  846.  *    For most purposes, use wgetc().
  847.  *            .. you don't have to mess with mouse, it's done for you.
  848.  *    Use wreadc() if you want to bypass active hotkey routines or menus.
  849.  *            ... but turn mouse ON first then turn OFF when done.
  850.  *            ex:   wmouse_turn(ON);
  851.  *                  key= wreadc();
  852.  *                  wmouse_turn(OFF); 
  853.  *
  854.  *
  855.  *
  856.  *    wgets uses the arrow keys to provide simple editing, insertion, etc
  857.  *        nbytes is sizeof(buffer) and includes the terminal \0
  858.  *        The typed characters are placed correctly in the window.
  859.  *        Returns the keypress that stopped input (ESCAPE, ENTER, etc)
  860.  *
  861.  *        The following flags change the behavior of wgets (new for version 2.0):
  862.  *
  863.  *     WGETS_FORM    -     used internally by wscanform 
  864.  *    WGETS_INT    -     accept integer input only, +- signs OK 
  865.  *    WGETS_DEC    -     accept integers and a single decimal pt
  866.  *    WGETS_SKIP    -     auto return when buffer is filled, dont wait for ENTER key 
  867.  *
  868.  */
  869. int     wgetc       (void);
  870. int     wreadc         (void);
  871. int        wgets       (int nbytes, char *buffer, char behavior);
  872.  
  873.  
  874.  
  875.  
  876.  
  877. /*! wready
  878.  *     returns 1 if a key (including MOUSE) is ready to read
  879.  *        Tests enhanced kbd if present.
  880.  *        0 if user hasn't typed anything
  881.  *
  882.  */
  883. int     wready(void);
  884.  
  885.  
  886.  
  887. /*! wflush
  888.  *      flushes keyboard and mouse of any prior input.
  889.  *    does nothing if input pipe (redirection is in effect.
  890.  *    does not touch the unget buffer.
  891.  */
  892. void wflush (void);
  893.  
  894.  
  895.  
  896.  
  897. /* wkbd_enhanced() - RETURN 0 if standard (PC/XT) keyboard.
  898.  *                   RETURN non-zero if enchanced (AT) keyboard.
  899.  */
  900. int  wkbd_enhanced (void);
  901.  
  902.  
  903.  
  904.  
  905.  
  906. /*! keyboard only routines.
  907.  *        These routines ONLY poll the keyboard. Ignores mouse, pipes, macros,
  908.  *            and hotkeys. No screen blackout, No 'buttons'.
  909.  */
  910. int wready_kbd(void);        /* returns 0 if no key hit (like TurboC kbhit() )*/
  911. int wread_kbd(void);        /* returns key value. Maps extended keys */
  912. void wflush_kbd(void);        /* flushes input keyboard buffer */
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919. /*! wcursor
  920.  *
  921.  *    turn cursor ON/OFF. Sets w0->winputstyle |= WPUTCURSOR.
  922.  *
  923.  */
  924. void        wcursor     (int);
  925.  
  926.  
  927.  
  928.  
  929. /* keyboard pipes
  930.  *    input pipes accept input from the pipe rather than the keyboard
  931.  *    output pipes trap all keyboard/mouse acivity and save keystorkes
  932.  *
  933.  *    recurrent calls are not supported.
  934.  *
  935.  *    wpipefin() -     provide program input from a file.
  936.  *                    the file stores keys as int (=2bytes each)
  937.  *            MOUSE input also stores value of wmouse
  938.  *            PARAMETERS:  char *filename    - name of file to read
  939.  *                     void (*whendone)(void) - routine to call
  940.  *                    this routine is called at end of file.
  941.  *                    not called if NULL.
  942.  *            RETURNS: 0 if sucessful installation.
  943.  *                -1 if file not found, -2 if already installed.
  944.  *
  945.  *
  946.  *    wpipefout() -     record keyboard/mouse activity in a file
  947.  *            whenever the mouse is used, wmouse is also saved.
  948.  *            PARAMETERS:  char *filename
  949.  *                     int  stopcode = key that stops recording
  950.  */
  951. int      wpipefin  ( char *filename, void (*whendone)(void) );
  952. void    wpipefout ( char *filename, int  stopcode );
  953.  
  954.  
  955.  
  956.  
  957. /* keyboard macros
  958.  *    a simple keyboard macro system, uses pipes as above
  959.  *
  960.  *    wmacro_install ()    - install the macro system.
  961.  *
  962.  *    wmacro_select  ()       - display list of defined macros,
  963.  *                   RETURNS: ALT_n value of choice or ESCAPE
  964.  *
  965.  *    wmacro_names   ()    - display list of macros, user chooses one.
  966.  *                  PARAMETERS: a message to display in the box
  967.  *                  RETURNS: ptr to table of macro names.
  968.  *              macro names are stored in a table of 10 names, each 9 bytes
  969.  *            WMACRO_NAMES *m_n;
  970.  *            m_n = wmacro_names();
  971.  *            puts ( (*m_n)[0] );    prints the 1st macro name
  972.  *
  973.  *    wmacro_assign  ()    - assign a macro file to an ALT_n key
  974.  *                PARAMETERS: char *name = 8 letter filename
  975.  *                        (extension .mcr assumed)
  976.  *                        int  key = ALT_1 to ALT_0
  977.  *                                                     assign to this key.
  978.  *                NOTE: routine does not check if file exists!!
  979.  */
  980. void    wmacro_install  (void);
  981. int     wmacro_select    (char *message);
  982. WMACRO_NAMES *wmacro_names (void);
  983. void     wmacro_assign    (char *filename, int key);
  984.  
  985.  
  986.  
  987. /*------------------------  MOUSE functions --------------------------
  988.  *
  989.  *    wmouse_init, wmouse_textmask, wmouse_limit, wmouse_move, wmouse_location
  990.  *
  991.  */
  992.  
  993. /*    mouse initialization - used internally, called by winit() 
  994.  */
  995. void          wmouse_init     (void);
  996.  
  997. /* wmouse_turn () - turn the mouse cursor ON/OFF
  998.  *            BE SURE that calls to this are accurately paired
  999.  *            or the mouse driver will go bonkers and loose track.
  1000.  *
  1001.  *            NOTE: in EGA/VGA graphics... 
  1002.  *                    you should always have the mouse OFF before drawing.
  1003.  *                    ...including text output in graphics mode.
  1004.  *                    Otherwise, you'll get garbage onscreen.
  1005.  *
  1006.  *                    If you use wgetc() or wgets() to get input, 
  1007.  *                        this is done for you. 
  1008.  *                    If you use wreadc() or wmouse_location()
  1009.  *                         you should have paired calls
  1010.  *
  1011.  *            Usually, you never need to call this function.                    
  1012.  *
  1013.  *    example:  wmouse_turn (ON);        /* MOUSE cursor visible onscreen */
  1014.  *              delay (100);    
  1015.  *              wmouse_location();    /* check for input */
  1016.  *              wmouse_turn (OFF);    /* MOUSE cursor no longer visible */
  1017.  *
  1018.  *
  1019.  */
  1020. void                wmouse_turn     (int state );
  1021.  
  1022.  
  1023. /* wmouse_move () - move mouse to desired x/y position
  1024.  *                  works in either text or graphics mode.
  1025.  * 
  1026.  *    PARAMETERS: x,y = character position in current window.
  1027.  *    RETURNS:     void. 
  1028.  */
  1029. void wmouse_move ( int x, int y );
  1030.  
  1031. /* wmouse_move_pixel () - move mouse to desired px/py pixel position
  1032.  *                        NOTE unpredictable if currently in text mode.
  1033.  * 
  1034.  *    PARAMETERS: px,py = pixel position in current window.
  1035.  *    RETURNS:     void. 
  1036.  */
  1037. void wmouse_move_pixel ( int px, int py );
  1038.  
  1039.  
  1040. /* wmouse_limit ()
  1041.  *     limit mouse movement to current window ( any mode, any video page )
  1042.  *    does not interfere with functions wmouse_location() or wmouse_move...()
  1043.  *
  1044.  *    WARNING: be very careful with this function if your program has 'hotkeys'
  1045.  *             or uses pulldown menus, mouse limitations may get messed up.
  1046.  *
  1047.  *  PARAMETERS: int ON_OFF:  0= remove limits on movement (full screen)
  1048.  *                             non-0= set limits on movement. 
  1049.  */
  1050. void wmouse_limit (int ON_OFF);
  1051.  
  1052.  
  1053.  
  1054.  
  1055. /* wmouse_location ()
  1056.  *  check current mouse state, 
  1057.  *    accumulate button presses in wmouse structure
  1058.  *    compute mouse location in all coord systems (window/absolute/pixels)
  1059.  *    
  1060.  *    called by wgetc() and wreadc(). 
  1061.  *
  1062.  *    can be called if you want to query mouse independently of keyboard.
  1063.  *    after done with mouse, set wmouse.wms_internal = 0;
  1064.  *        (this resets mouse 'use' flags 
  1065.  *        so wgetc() will ignore mouse use that you processed independently)
  1066.  */
  1067. void          wmouse_location (void);
  1068.  
  1069.  
  1070. /* wmouse_flush ()
  1071.  *        flush mouse of pending button events  (press, release, etc...)
  1072.  *        and wait for any currently depressed buttons to be released.
  1073.  *        (recognizes all three mouse buttons)
  1074.  */
  1075. void wmouse_flush (void);
  1076.  
  1077.  
  1078. /*  wmouse_textmask ()
  1079.  *         allows you to set a different type of mouse cursor.
  1080.  *        The mouse mask is moved into the screen buffer at the mouse location.
  1081.  *        The screen buffer is 2 bytes per display character.
  1082.  *            First byte = attribute, Second byte = character.
  1083.  *
  1084.  *    WORKS ONLY IN TEXT MODE.
  1085.  *        
  1086.  *    PARAMETERS: 
  1087.  *        unsigned int screen = "screen mask" is AND'ED onto 2 bytes in buffer
  1088.  *        unsigned int cursor = "cursor mask" is OR'ED  onto 2 bytes in buffer 
  1089.  *
  1090.  *    Example: setup software cursor = invert underlying character
  1091.  *            wmouse_textmask ( 0xffff, 0x7f00 );
  1092.  *             setup a character that overlies display 
  1093.  *            wmouse_textmask ( 0x0000, 0x07xx );    
  1094.  *                where xx = hex code for desired char ( ie: '*' = 42 = 0x2a )
  1095.  */
  1096. void         wmouse_textmask (unsigned int screen, unsigned int cursor);
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103. /*---------------- keyboard UNGET ----------------------------
  1104.  *
  1105.  *     'unget' a character into the keyboard buffer
  1106.  *    note that this keyboard buffer can also hold MOUSE information
  1107.  *    and is not the same as the ANSI C/DOS ungetc() function.
  1108.  *
  1109.  *    also note that the unget buffer is only 1 character long.
  1110.  *
  1111.  */
  1112. #define wpushc(xx)      wunget_buffer = (xx)
  1113.  
  1114. #define wungetc(xx)    wunget_buffer = (xx)
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123. /*--------------------- 'BUTTON'  functions -----------------------------*
  1124.  *
  1125.  *    buttons are selectable choices onscreen
  1126.  *        associated with either mouse or keyboard action.
  1127.  *
  1128.  *
  1129.  *    wbutton_add ()         - add a button to the list.
  1130.  *                     install button handler if not yet done
  1131.  *                     add new button to linked list
  1132.  *                     draws the button onscreen.
  1133.  *
  1134.  *        PARAMETERS:
  1135.  *            char *text  = text to place in button.
  1136.  *                    may be longer or shorter than button
  1137.  *            int  x, y   = x,y position of button in open window.
  1138.  *            int len        = length of button, include terminal NULL.
  1139.  *            int value = keyboard bvalue of button.
  1140.  *            unsinged char style = WBTN_BOX to draw a box.
  1141.  *
  1142.  *        RETURNS: void.
  1143.  *
  1144.  *              OPTIONS:
  1145.  *            WBTN_BOX = draw a box around button
  1146.  *
  1147.  *    wbutton_mark ()        - places a 'mark' to left of a button
  1148.  *                     specify the button by the 'button value'
  1149.  *                     and the 1-character mark, and attr.
  1150.  *                     (Remove the mark by using ' ')
  1151.  *
  1152.  *
  1153.  *    wbutton_delete()     - remove specified button.
  1154.  *                     redaw screen without button.
  1155.  *        PARAMETERS:
  1156.  *            int    value = keyboard value of button
  1157.  *                  int     how   = 0= clear screen area
  1158.  *                    1= rewrite text in current attr
  1159.  *        RETURNS void.
  1160.  *
  1161.  *    wbutton_inactivate()    - temporarily inactivate button.
  1162.  *                     redraws button in current attribute.
  1163.  *        PARAMETERS:
  1164.  *            int    value = button value
  1165.  *            int     how   = 0= clear screen area
  1166.  *                    1= rewrite text in current attr
  1167.  *        RETURNS: void.
  1168.  *
  1169.  *    wbutton_activate()    - reactivate the button.
  1170.  *                     redraws button in wbutton_attr.
  1171.  *        PARAMETERS:
  1172.  *            int value = button value.
  1173.  *        RETURNS: void.
  1174.  *
  1175.  *    wbutton_getptr()    - returns ptr to button that matches a value
  1176.  *                    or NULL if not an active button.
  1177.  *
  1178.  *        PARAMETERS:
  1179.  *            int value = keystroke or MOUSE
  1180.  *        RETURNS:
  1181.  *            WBUTTON *ptr = ptr to button if key is an active btn.
  1182.  *                     NULL if key is not an active button.
  1183.  *
  1184.  *        NOTES:    this function is mostly for internal use,
  1185.  *            but can be used to validate keystrokes.
  1186.  *
  1187.  *    wbutton_test()        - returns button value or 0 if not a button
  1188.  *        PARAMETERS:
  1189.  *            int value = keystroke or MOUSE
  1190.  *        RETURNS:
  1191.  *            int value = (value) if is a button
  1192.  *                          0 if VALUE is not a button.
  1193.  *
  1194.  *
  1195.  *    METHOD:
  1196.  *
  1197.  *
  1198.  *    these routines keep linked lists list of currently active buttons
  1199.  *
  1200.  *    one list is maintianed for each window.
  1201.  *
  1202.  *    when a button is added, wbutton_add()
  1203.  *        checks to see if button-handler is installed
  1204.  *            (less overhead if you never use buttons)
  1205.  *                and installs button handler if needed.
  1206.  *        allocates memory for BUTTON struct and adds to linked list.
  1207.  *        draws button onscreen.
  1208.  *
  1209.  *
  1210.  *      after buttons have been defined, wgetc() calls the button manager
  1211.  *        and compares mouse use against buttons,
  1212.  *        translates mouse into button value,
  1213.  *        invokes callback function...
  1214.  *
  1215.  *
  1216.  *
  1217.  *
  1218.  *
  1219.  *    NOTES:
  1220.  *      1)    buttons are released by wclose() when window is closed.
  1221.  *
  1222.  *        2)    Be sure the same window is active when the
  1223.  *        buttons are created as when keyboard/mouse input is read
  1224.  *        (The routine computes all button positions relative to
  1225.  *        the current window).
  1226.  *
  1227.  *      3)    It's OK to wrelocate() or wdrag() the active window.
  1228.  *
  1229.  *
  1230.  *      5)    multi-line buttons: not allowed.
  1231.  *
  1232.  *
  1233.  *
  1234.  *    Example:
  1235.  *
  1236.  *        wopen (10,10, 20,10, WHITE, SINGLE_BORDER, WHITE, WSAVE2RAM);
  1237.  *        wputs ("Are you having fun?");
  1238.  *
  1239.  *
  1240.  *        wbutton_add ( "YES",   10, 5, 3, 'Y', WBTN_BOX );
  1241.  *        wbutton_add ( "NO",    15, 5, 3, 'N', WBTN_BOX );
  1242.  *        wbutton_add ( "MAYBE", 20, 5, 5, 'M', WBTN_BOX );
  1243.  *
  1244.  *        answer = wbutton_test( wgetc() );
  1245.  *
  1246.  *        wclose();
  1247.  *
  1248.  *        This code is roughly equivalent to the single line:
  1249.  *
  1250.  *        key = wpromptc (NULL, "are we having fun?",
  1251.  *            "YES", "NO", "MAYBE", NULL ):
  1252.  *
  1253.  */
  1254. void wbutton_add (char *btext, int bx, int by, int blen,
  1255.         int bval, unsigned char bstyle );
  1256.  
  1257. void wbutton_delete (int bval, int how);
  1258.  
  1259. void wbutton_inactivate (int bval, int how);
  1260.  
  1261. void wbutton_activate (int bval);
  1262.  
  1263. void wbutton_mark ( int bval, char mark );
  1264.  
  1265. WBUTTON *wbutton_getptr ( int bval );
  1266.  
  1267. int wbutton_test ( int bval );
  1268.  
  1269.  
  1270.  
  1271.  
  1272.     /* internal button functions
  1273.      */
  1274.     void wbutton_draw ( WBUTTON *, unsigned char  );
  1275.     void wbutton_frame ( WBUTTON *, unsigned char , unsigned char );
  1276.  
  1277.  
  1278.  
  1279.  
  1280. /* WSCROLLBAR - routines for vertical mouse-driven scrollbars.
  1281.  *
  1282.  *        screen co-ords are mapped into 'virtual' values
  1283.  *        virtual values may go from 0...range set as param to wscrollbar_add()
  1284.  *        to allow user to drag the scrollbar icon, call wscrollbar_scroll()
  1285.  *            (be sure the LEFT MOUSE BUTTON has been pressed)
  1286.  *        
  1287.  *
  1288.  *         wscrollbar_add () - create a scrollbar
  1289.  *            PARAMS: key = a non-keyboard keyvalue (negative is best) for ID
  1290.  *                              This value will be returned by wgetc()
  1291.  *                            when the mouse clicks on the scrollbar image area.
  1292.  *                    x    = x-location in window for scrollbar.
  1293.  *                    y1, y2= top and bottom locations of scrollbar.
  1294.  *                    range = unsigned int value giving virtual position of ptr
  1295.  *                            when ptr=y1, virtual position is 0.
  1296.  *                            when ptr=y2, virtual value is 'range'
  1297.  *                    start = unsigned int = starting virtual value of scrollbar.
  1298.  *            RETURNS: WBUTTON *Bptr = ptr to the scrollbar data, used below.
  1299.  *
  1300.  *        wscrollbar_draw() - draw, or redraw scrollbar    (ie, after wclear())
  1301.  *            PARAMS:  WBUTTON *Bptr = pts to the scrollbar data.
  1302.  *            RETURNS: void.
  1303.  *
  1304.  *         wscrollbar_scroll() - allow mouse to move scrollbar ptr onscreen.
  1305.  *            USE: when wgetc() returns the key that identifies the scrollbar,
  1306.  *                the mouse state is: LEFT BUTTON newly pressed, on scrollbar.
  1307.  *                Call wscrollbar_scroll() to track the mouse mvt and get new ptr
  1308.  *            PARAMS: WBUTTON *Bptr = ptr to scrollbar data area
  1309.  *                                    (obtained from wscrollbar_add() )
  1310.  *            RETURNS: unsigned int newval = new virtual position 
  1311.  *                        0 <= newval <= range
  1312.  *                            
  1313.  *        wscrollbar_reset() - provide new virtual position for the scrollbar 
  1314.  *                             and redraw the ptr onscreen.
  1315.  *            PARAMS: WBUTTON *Bptr = ptr to scrollbar data.
  1316.  *                    unsigned int newval = new virtual value.
  1317.  *
  1318.  *    NOTES: no error checking is performed. Be careful of following:
  1319.  *            The scrollbar must be AT LEAST 4 bytes long (y2 > y1+3)
  1320.  *            The range must be > 2.
  1321.  *            The key assigned should not be producable on a PC/AT keyboard
  1322.  *                (prog. will lock if a keyboard press activates the scrollbar)
  1323.  *                (negative key values are guaranteed to work)
  1324.  *            
  1325.  *    EXAMPLE: see DEMOMOUS.C
  1326.  */
  1327. WBUTTON *wscrollbar_add ( int key, 
  1328.             unsigned char x, unsigned char ytop, unsigned char ybottom,
  1329.             unsigned int virtual_range, unsigned int virtual_start );
  1330.             
  1331. void             wscrollbar_draw   ( WBUTTON *Bptr );
  1332. unsigned int     wscrollbar_scroll ( WBUTTON *Bptr );  /*returns virtual_val */
  1333. void             wscrollbar_reset  ( WBUTTON *Bptr, unsigned int new_val );
  1334.  
  1335.  
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342.  
  1343.  
  1344.  
  1345. /*---------------------- dialog routines --------------------------*
  1346.  *
  1347.  *  wpromptc ()
  1348.  *  wprompts ()
  1349.  *  wpicklist()
  1350.  *  wscanform()
  1351.  *
  1352.  *------------------------------------------------------------------*/
  1353.  
  1354.  
  1355. /*! wpromptc()
  1356.  *    dialog box routines. - prompt user for a single keystroke
  1357.  *
  1358.  *    displays a message in a window, waits for the user to press a key
  1359.  *    validates the keypress against the specified response parameter.
  1360.  *    Integrates mouse and keyboard.
  1361.  *
  1362.  *    auto_sizing and auto_centering
  1363.  *        you may change location by calling wsetlocation first.
  1364.  *
  1365.  *    parameters:
  1366.  *        title = ptr to title string. Ignored if null
  1367.  *        msg   = ptr to message for main body of window.
  1368.  *            may be multiple lines. Window sized to fit.
  1369.  *        responses = ptrs to response prompts.
  1370.  *            One 'button' is created for each response.
  1371.  *            an ESCPAE button is automatically created.
  1372.  *            The first character ( alpha or numeric )
  1373.  *            of each string is returned if that string is chosen
  1374.  *
  1375.  *                      Terminate the list with NULL
  1376.  *
  1377.  *
  1378.  *    RETURNS: The keypressed by the user, as limitted by response choices
  1379.  *            lowercase is translated to uppercase.
  1380.  *
  1381.  *    example:  key = wpromptc ("title", "are we having fun",
  1382.  *            "Yes", "No", ESCAPE);
  1383.  *        The only possible return values are ESCAPE, 'Y' 'N'
  1384.  *
  1385.  */
  1386.  
  1387. int wpromptc(char *title, char *msg, ...);
  1388.  
  1389.  
  1390.  
  1391.  
  1392. /*! wprompts ()
  1393.  *
  1394.  *    prompt user for a string
  1395.  *    works like wpromptc()
  1396.  *    but allows user to type a longer answer.
  1397.  *    the answer is returned in reply
  1398.  *    RETURNS:
  1399.  *    the key used to terminate input (ENTER, ESCAPE, etc)
  1400.  */
  1401. int wprompts ( char *title, char *msg, char *reply, int nbytes );
  1402.  
  1403.  
  1404.  
  1405.  
  1406.  
  1407.  
  1408.  
  1409.  
  1410. /*! wpicklist()
  1411.  *    user selection from a list of strings; pop-up menu style
  1412.  *
  1413.  *      parms:  title will be written on the top of the box.
  1414.  *              list  is a char **, a pointer to a list of strings
  1415.  *                    terminated by a NULL
  1416.  *
  1417.  *    RETURNS the offset number for the choice made
  1418.  *        or the offset to the terminating NULLif ESCAPE
  1419.  *
  1420.  *        the returned offset to ptr can be used 2 ways:
  1421.  *            1) char *answer;
  1422.  *               answer = list[ wpicklist (title,list) ] ;
  1423.  *               wputs (answer);  <=== answer is a string.
  1424.  *
  1425.  *            2) int n;
  1426.  *               n= wpicklist (title,list);
  1427.  *                              (n is the number of the choice 0,1,2,3...)
  1428.  *            neither of these code fragments checked for NULL.
  1429.  *
  1430.  *    Long lists ( >10 lines )
  1431.  *    will automatically allow PAGE UP/PAGE DN choices.
  1432.  *
  1433.  *
  1434.  *
  1435.  *    example:
  1436.  *
  1437.  *              char *list[] = { "one", "two", "three", "four", NULL };
  1438.  *
  1439.  *        response = wpicklist ("<PICK A NUMBER>", list);
  1440.  *
  1441.  *        in this example, response will be the choice number
  1442.  *            0= first element on list, 1=second, etc...
  1443.  *            will index the terminal NULL if ESCAPE was selected.
  1444.  *
  1445.  *
  1446.  *    NOTE: in large or compact memory models,
  1447.  *        you must be sure entire list is in one segment.
  1448.  *        or list[n] may point to wild data.
  1449.  *        (ie, use a normalized pointer)
  1450.  */
  1451. int wpicklist ( char *title, char **list );
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.  
  1460. /*! wscanform() and wprintform()
  1461.  *
  1462.  *
  1463.  *    interactive versions of printf() and scanf()
  1464.  *                        that allow more flexible formatting/interaction
  1465.  *
  1466.  *      table-driven -- see definition of WFORM
  1467.  *                       the table consists of multipple entries of type WFORM
  1468.  *                      example:
  1469.  *            WFORM sample_form [] = {  <<< simplified
  1470.  *                data item,
  1471.  *                (optional labels, no data),
  1472.  *                data item,
  1473.  *                last line  };
  1474.  *
  1475.  *
  1476.  *    parameters:  title for form and pointer to form table.
  1477.  *
  1478.  *
  1479.  *
  1480.  *
  1481.  *
  1482.  *
  1483.  * the last line terminates the table with a NULL in the wflabel position.
  1484.  *    the last line also gives the xmax and ymax for the form window
  1485.  *    (be sure to leave enough room for all data & text )
  1486.  *
  1487.  *    A validation function may be specified for the whole form.
  1488.  *        See below for description of validation functions.
  1489.  *        If the validation function for the whole form returns non-zero,
  1490.  *            no updating will take place.
  1491.  *
  1492.  * data items may be any type supported by printf/scanf
  1493.  *    EXCEPT: longs, doubles, long doubles and pointers are NOT supported
  1494.  *        variable lengths (%*i) is NOT supported.
  1495.  *        item count reporting (%ni) is NOT supported.
  1496.  *
  1497.  *      a picklist may be specified instead of hand-typed entry.
  1498.  *
  1499.  *      a form item may be a 'pure label' ie, only the wflabel is printed,
  1500.  *        ie, leave the wfuser field NULL.
  1501.  *
  1502.  * CAUTION:    DO NOT MAKE THE FIRST OR LAST FIELDS OF THE FORM A LABEL !!!!
  1503.  *
  1504.  * validation functions: Each entry in the WFORM table can call a function
  1505.  *    The pointer to the function is specified in the 'wfvalidate' entry.
  1506.  *    The function prototype MUST look like this:
  1507.  *        int func_name (WFORM *form, char *buffer)
  1508.  *    The function is called each time data is entered into the field.
  1509.  *    Parameters passed to the function:
  1510.  *        WFORM *form     ptr to the WFORM entry for this filed.
  1511.  *        char  *buffer   ptr to the string holding the new value
  1512.  *                The string is AT MOST (form->wflen) bytes.
  1513.  *    The function may optionally communicate errors to the user.
  1514.  *    See below, Tools for form validation functions.
  1515.  *
  1516.  *        validation func RETURN: 0 if the data is valid, non-zero if not valid.
  1517.  *
  1518.  *
  1519.  *
  1520.  * you must specify the length of onscreen display for data items
  1521.  *    length must be enough to hold the data in string form with terminal 0
  1522.  *    length MUST include terminal NULL (ie, 1 more than number bytes to show).
  1523.  *    for string data, length is # bytes that will be returned,
  1524.  *        incl. terminal NULL.
  1525.  *
  1526.  * the x,y positions for data items determine the screen start of the data
  1527.  *    the label is placed before the data.
  1528.  *    Be sure the label fits on current line in the space you provided.
  1529.  *
  1530.  * you can control border color attributes of various form items, see wfmatr_....
  1531.  * you can control autoskip (=move to next field automatically or wait for TAB)
  1532.  *            by setting wfm_autoskip = WFM_AUTOSKIP; or reset to 0.
  1533.  *            DO NOT use other values.
  1534.  *
  1535.  * wprintform() opens a window, draws the form, and leaves the window open
  1536.  *    with data showing. No data entry or chages to data values occur.
  1537.  *
  1538.  */
  1539. int wscanform  (char *title, WFORM *form);
  1540. void wprintform (char *title, WFORM *form);
  1541.  
  1542.     /* WFORM attributes showing defaults */
  1543. char wfmatr_lbl,        /* CYAN for         labels                             */
  1544.      wfmatr_lbl_active,    /* BLACK on WHITE      label indicating active data item */
  1545.      wfmatr_border,        /* CYAN                form border                     */
  1546.      wfmatr_title,        /* CYAN                form title                        */
  1547.      wfmatr_data,         /* CYAN                inactive data                    */
  1548.      wfmatr_data_active;/* BLACK on WHITE   active data item (while typing) */
  1549.  
  1550. int wfm_border_type;    /* DOUBLE_BORDER */
  1551.  
  1552. char wfm_autoskip;        /* set to 0 for no autoskip, 
  1553.                          * set to WFM_AUTOSKIP for auto skip to next field
  1554.                          */
  1555.  
  1556. /* Tools for form validation functions
  1557.  *
  1558.  * When a form validation function (see above) is called, it is passed
  1559.  * a ptr to the form table for the current entry and a ptr to the char *
  1560.  * buffer holding the current value.
  1561.  *
  1562.  * Form validation functions may call the following sub-procedures
  1563.  * to simplify work.
  1564.  *
  1565.  * wform_showerror() - display an error msg under the field
  1566.  *        If NULL is passed, a standard error message is displayed.
  1567.  *        The error msg must be 1 line and short enough to fit onscreen
  1568.  *        (it is located starting below and to the left of the data)
  1569.  *
  1570.  * wfvall () - pass the start address of the form, and buffer.
  1571.  *        This routine loops through all the fields and calls all
  1572.  *        validation routines one at a time, keeping track of errors.
  1573.  *        Use this function as all or part of the total form validation
  1574.  *        (ie, name the function on the form header line)
  1575.  */
  1576.  
  1577. void wform_showerror(WFORM *form, char *errmsg);
  1578. int  wfvall (WFORM *form, char *buffer);
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584. /* miscellaneous form-oriented routines
  1585.  *        date and time validation functions for forms.
  1586.  *        These functions may be specified in WFORM tables.
  1587.  */
  1588. int wfvdate (WFORM *form, char *buffer);
  1589. int wfvtime (WFORM *form, char *buffer);
  1590.  
  1591.  
  1592.  
  1593. /*validate a string date in form mm/dd/yy or mm/dd/yyyy
  1594.  * returns 0 if valid, nonzero otherwise.
  1595.  *    also changes contents of the string to eliminate extra spaces, digits,
  1596.  *    etc (result stirng may be shorter than original but will not be longer)
  1597.  *
  1598.  * or validate a time string in the form hh:mm:ss
  1599.  *        WARNING: you must provide at least 9 bytes for this routine's arg
  1600.  *                 as the seconds field is filled in if it was left blank.
  1601.  *                ie: "10:30" is converted to "10:30:00" 
  1602.  */
  1603. int wval_date (char *date);
  1604. int wval_time (char *time);
  1605.  
  1606. void wdtparse ( unsigned int *, char **, char );    /* internal routine */
  1607.  
  1608.  
  1609. /*! wfscanform() wfprintform()  - file oriented form processing.
  1610.  *
  1611.  *
  1612.  *
  1613.  *  wfscanform - parse a file using a WFORM table.
  1614.  * 
  1615.  *      parameters: wfscanform(FILE *infile, WFORM *form, char *stopcode)
  1616.  *                        infile = ptr to file to parse (already opened)
  1617.  *                        form   = ptr to WFORM table
  1618.  *                        stopcode= ptr to string to stop parsing.
  1619.  *
  1620.  *    This procedure is a file-header parser.
  1621.  *    Text files are read and each line is checked to see if
  1622.  *    it matches an item in the WFORM table. If so, the data is
  1623.  *    formatted and placed in the calling program's storage area
  1624.  *    ...as indicated by the table.
  1625.  *
  1626.  *    The input file may be in the format:
  1627.  *        KEYWORDdata\r\n
  1628.  *        KEYWORDdata\r\n
  1629.  *        STOPCODE\r\n
  1630.  *    The KEYWORD may have a punctuation mark or whitespace at the end,
  1631.  *        these are ignored for the purposes of comparison.
  1632.  *        So the file may be in any of the following forms:
  1633.  *        KEYWORD: filedata\r\n
  1634.  *        KEYWORD:filedata\r\n
  1635.  *        KEYWORD filedata\r\n
  1636.  *        KEYWORD-filedata\r\n
  1637.  *        KEYWORD$  filedata\r\n
  1638.  *
  1639.  *
  1640.  *        ONLY 1 punctuation mark may be used as a delimiter,
  1641.  *            but it doesn't have to be the same one each time.
  1642.  *
  1643.  *
  1644.  *        in each of these cases, the data that will be returned
  1645.  *              will be 'filedata' without the punctuation or leading space.
  1646.  *
  1647.  *    However, if no delimiter or space is indicated in the WFORM label,
  1648.  *        then any delimiter found will be included in the data.
  1649.  *
  1650.  *    Data may continue to the next line if the last line is a + - or \
  1651.  *        ex: col 0123456789....
  1652.  *              KEYWORD: This is dat+\r\n
  1653.  *              a for the program\r\n
  1654.  *        will be read as This is data for the program.
  1655.  *
  1656.  *
  1657.  *    Open the input file in either text or binary mode,
  1658.  *        This routine actively ignores \n\r
  1659.  *        and does not depend on fgets() to remove these codes.
  1660.  *
  1661.  *
  1662.  *    If a KEYWORD is not found in the file, no values are moved to the
  1663.  *        calling program's data area.
  1664.  *
  1665.  *    Input stops on FEOF or on an input line entirely contained in STOPCODE
  1666.  *        OK if you specify STOPCODE as DATA: and the input line is DATA\r\n
  1667.  *            or OK if stopcode is DATA and input line is DATA:\r\n (any punct.)
  1668.  *        ie: for a header record, STOPCODE might be DATA: or DATA- or DATA
  1669.  *            as long as the word DATA is all that shows on the line.
  1670.  *            if STOPCODE is DATA: and the input file says DATA- it won't work.
  1671.  *
  1672.  *    to display the KEYWORDdata information onscreen, use the same WFORM[]
  1673.  *        and call WPRINTFORM ()
  1674.  *    to create compatible file headers, use the same WFORM[]
  1675.  *        and call WFPRINTFORM[]
  1676.  *
  1677.  *
  1678.  *    validation functions are not called by wfscanform
  1679.  *--------------------------------------------------------------
  1680.  *
  1681.  *  wfprintform -
  1682.  *    the data and labels are printed to a file, one line at a time
  1683.  *        in the order of the table.
  1684.  *
  1685.  *
  1686.  *  partial example:
  1687.  *    if the table entry is "NAME: ", your_name, ... "%s",  ...
  1688.  *    then wfscanform will identify any line beginning with "NAME: "
  1689.  *    and will place the following string data into the buffer your_name.
  1690.  *
  1691.  *    for output, wfprintform will type a line that reads: "NAME: John\n"
  1692.  */
  1693. void wfscanform ( FILE *infile,  WFORM *formtable, char *stopcode );
  1694.  
  1695. void wfprintform (FILE *outfile, WFORM *formtable );
  1696.  
  1697.  
  1698.  
  1699.  
  1700. /*----------------------------- HOTKEYS -----------------------------
  1701.  *
  1702.  *     HOTKEYS are specific keys which automatically call up 
  1703.  *         functions. When the key is pressed, the function is 
  1704.  *         automatically called, and then that key is 'swallowed up'
  1705.  *        so the original function doesn't have to process it.
  1706.  *        F1 for context sensitive help is an example of a hotkey 
  1707.  *            routine.
  1708.  *
  1709.  *
  1710.  *    You associate a key with a function by calling whotkey_install()
  1711.  *    The function should be declared as 
  1712.  *            void myfunc(void);
  1713.  *    To associate myfunc() with a key, say the HOME key, call...
  1714.  *            whotkey_install ( HOME, myfunc );
  1715.  *  NOTES:
  1716.  *    1) You cannot de-install a hotkey... you must provide your own 
  1717.  *        means for inactivating it if you need to.
  1718.  *    2) The function will not be called more often than once at a 
  1719.  *        time. If the function is currently active the key will be 
  1720.  *        'regular' not hot.
  1721.  *
  1722.  */
  1723. void whotkey_install ( int HOTKEY_keyvalue,  void (*myfunc)(void) );
  1724.  
  1725.  
  1726.  
  1727.  
  1728. /*-------------------------- TOP MENU LINE ---------------------------*
  1729.  *
  1730.  * wpulldown (), wpulldown_draw(), wpulldown_pages() -
  1731.  *    provide for pulldown menus.
  1732.  *    these functions should be called to install the menu manager
  1733.  *    after winit() but before any other functions.
  1734.  *
  1735.  *
  1736.  *
  1737.  * parameters:
  1738.  *
  1739.  *    WMENU *topmenu  = address of NULL-terminated array of WMENU.
  1740.  *              any level of nesting is allowed.
  1741.  *
  1742.  *
  1743.  * NOTES:
  1744.  *
  1745.  *    use wpulldown() for programs on only one video page.
  1746.  *    use wpulldown_pages() for programs that use mult. video pages.
  1747.  *
  1748.  *     install these soon after winit () or winit_pages()
  1749.  *
  1750.  *     both functions replace the top 2 lines of the screen with menus
  1751.  *    and 'shorten' the fullscreen window to protect the top two lines.
  1752.  *
  1753.  *     use one or the other, but not both.
  1754.  *
  1755.  *    for wpulldown, the menu is activated whenever an ALT_letter or
  1756.  *                FKEY() in the topmenu is pressed, or by mouse
  1757.  *
  1758.  *
  1759.  * !!!    any function called by the menu MUST quit when ESCAPE is pressed.
  1760.  *        internally,
  1761.  *            the menu routine uses wungetc(ESCAPE)
  1762.  *                      to force functions to quit for moving horizontally
  1763.  *
  1764.  *    use wpulldown_draw() to redraw top lines of menu
  1765.  *
  1766.  *  set wpulldown_enable to 0 to temporarily turn off menu functions.
  1767.  *
  1768.  *---------------------------------------------------------------------*/
  1769. void wpulldown         ( WMENU *topmenu );
  1770. void wpulldown_pages    ( WMENU *topmenu );
  1771. void wpulldown_draw     ( void );
  1772.  
  1773. int  wpulldown_enable;                    /* 0=turns off menu default=1*/ 
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779. /*! function key functions
  1780.  *    defined here so they can be used in a wfkey[10] table.
  1781.  *     see the header wfkey.h for example of how to link these into
  1782.  *         a program
  1783.  */
  1784.  
  1785.  
  1786. /*-------------------------- HELP system  ------------------------------*
  1787.  *    F1 activates context-sensitive help.
  1788.  *        You tell the help system which file has help text when you install help.
  1789.  *        You tell the system which topic to display by setting the whelp_ptr.
  1790.  *        If you are use pulldown menus (wpulldown) or form data entry (wscanform)
  1791.  *            .. the system automatically sets whelp_ptr to the current topic.
  1792.  *
  1793.  *
  1794.  *     whelp_ptr is a global variable,pts to a help string.
  1795.  *        new ptrs may be assigned to it at any time.
  1796.  *
  1797.  *    whelp_install() installs a hotkey- activated help display routine.
  1798.  *            the string pointed to by whelp_ptr is displayed.
  1799.  *                      PARAMETERS: the helpfile name (no extension)
  1800.  *                          looks for filename.hlp & filename.hx
  1801.  *
  1802.  *    STEP BY STEP GUIDE TO CREATING HELP FOR YOUR PROGRAM MYPROG.EXE:
  1803.  *    1)    you type a standard ASCI file with help text in it.
  1804.  *            each topic starts with '@' in column 1,
  1805.  *            then name of topic (up to 15 bytes), then <CR><LF>
  1806.  *            then up to 5 lines of 50 bytes each of help text.
  1807.  *    sample of a 2 topic help text file: filename MYHELP.HLP
  1808.  @TOPIC 1
  1809.  This is help text for topic 1.
  1810.  This is a second line of help for topic 1.
  1811.  @TOPIC 2
  1812.  This is help for second topic.
  1813.  <END_OF_FILE, CTRL Z>
  1814.  *    2) run MAKEHX.EXE - makehx.exe is a utility that makes help index files.
  1815.  *       'C:\>makehx MYHELP' which creates file MYHELP.HX
  1816.  *    3) In your program MYPROG.C, you call 'whelp_install ("MYHELP");
  1817.  *
  1818.  *    4) Set whelp_ptr to "TOPIC 1" or "TOPIC 2" at various pts in your program.
  1819.  *    
  1820.  *    EXAMPLES: .C programs that use help: demomenu, demoform, demohkey.
  1821.  *             help text files: demomenu.hlp, demoform.hlp, demohkey.hlp.
  1822.  *---------------------------------------------------------------------*/
  1823. void whelp_install(char *filename);
  1824.  
  1825.  
  1826.  
  1827.  
  1828. /*! wdos
  1829.  *     a menu or fkey choice, allows execution of DOS commands
  1830.  *    ( NOT available in graphics mode).
  1831.  */
  1832. void    wdos        (void);
  1833.  
  1834.  
  1835. /*! wexit
  1836.  *    ask user if he/she wants to quit, and exit if 'Y'
  1837.  */
  1838. void     wexit         (void);
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847. /*! wunlink(), wlink()
  1848.  *    unlink the current window from the chain of windows.
  1849.  *        the image of the window is saved (pointer winsave).
  1850.  *        the screen is not changed.
  1851.  *      this function is used just before changing modes
  1852.  *               or just before wcloseall
  1853.  *    allows subsequent wlink to re-establish this window
  1854.  *          when you come back to the window's mode.
  1855.  *
  1856.  *        RETURNS: pointer to the window if successful, NULL if error
  1857.  *
  1858.  *
  1859.  *    wlink opens the specified window, restores its image to the screen
  1860.  *        parameter = window pointer obtained by wunlink ()
  1861.  *
  1862.  *        windows are linked into the same page as the current window.
  1863.  *
  1864.  *    do NOT place a text-mode window on a graphics mode screen
  1865.  *        or vice-versa.
  1866.  *
  1867.  *      do not unlink either the last window or the fullscreen window.
  1868.  *
  1869.  *    example:     winit ('T');
  1870.  *                      wopen (... );
  1871.  *            wputs ("A bunch of stuff...");
  1872.  *            my_textwindow = wunlink ();
  1873.  *            init ('G');
  1874.  *                do graphics things...
  1875.  *            winit ('T');
  1876.  *            wlink ( my_textwindow );
  1877.  *
  1878.  *
  1879.  */
  1880.  
  1881. WINDOW     *wunlink (void);
  1882. void    wlink (WINDOW  *new);
  1883.  
  1884.  
  1885. /* WDRAW() - only available in TurboC version.
  1886.  *        allows user to draw an object onscreen.
  1887.  *        returns ptr to allocated data area of type WOBJECT_D_ART
  1888.  *        which contains description of drawn object.
  1889.  *        PARAMETERS:
  1890.  *            type =     type of object to draw.
  1891.  *                    see definition of WOBJECT_D_ART for values of type.    
  1892.  *            color, linestyle, thickness = as defined by TURBO C.
  1893.  *        RETURNS: ptr to WOBJECT_D_ART, see funcs.doc
  1894.  */
  1895.  
  1896.  
  1897. WOBJECT_D_ART *wdraw ( char type, int color, int linestyle, int thickness );
  1898.  
  1899.  
  1900. /*------------- HEAP MANAGEMENT --------------------- */
  1901.  
  1902.     /* This package includes routines to allocate chunks of memory
  1903.      * to expanded memory, and when that is no longer available, to RAM, 
  1904.      * and when that is used up, to the hard disk. Large chunks of memory 
  1905.      * are especially important for saving underlying graphics images
  1906.      * when you open a window.
  1907.      *
  1908.      * You can use these 'heap' routines for things other than window storage.
  1909.      * Expanded memory and disk storage are inefficient ways to handle small
  1910.      *     chunks of data, use farmalloc() ( or in msc, _fmalloc ) for those.
  1911.      *
  1912.      * The largest size chunk that can be allocated as one heap element is
  1913.      * 64k-16 bytes, given in WHEAP_MAX. 
  1914.      */
  1915.  
  1916.  
  1917.     /*
  1918.      * The amount of far ram used is limitted by the global variable
  1919.      * wheap_ramlimit. 
  1920.      * Setting wheap_ramlimit to 0 shuts off use of ram (only xms & disk used)
  1921.      * Setting wheap_ramlimit to very large (1 MEG) allows use of all avail ram
  1922.      * If you have data that MUST be stored in regular (far) ram,
  1923.      * or in LARGE model want enough ram left over for important data, 
  1924.      *        set wheap_limit large enough to hold that data.
  1925.      *  
  1926.      */
  1927.     extern unsigned long      wheap_ramlimit;   /* default is 256k */
  1928.  
  1929.  
  1930.  
  1931.  
  1932. void          wheap_init ( void );        /* internal use only */
  1933.  
  1934.  
  1935. /*  wheap_alloc() requests a chunk of heap memory.
  1936.  *    parameters:
  1937.  *         priority (0-255) relates to where it will be stored
  1938.  *             0 = always stored to disk. Dont clutter up ram with this.
  1939.  *             1-254 = stored to expanded or ram if room
  1940.  *                     if no room, objects of lower priority are swapped to disk
  1941.  *                            until room is made.
  1942.  *                     if still no room after low priority items are swapped,
  1943.  *                            item is allocated on disk drive.
  1944.  *            255 = never store on disk. very important data item.
  1945.  *        errmsg if NULL, and no storage obtained,  wheap_alloc returns NULL
  1946.  *            else, pts to name of module, will be identified as source of error
  1947.  *            ie msg: "Out of heap memory, call from  xxxxxxx" is printed
  1948.  *            
  1949.  *    RETURNS: ptr to WHEAP ( ie to control block for the allocated memory )
  1950.  *             this is NOT the ptr to the memory itself.
  1951.  *             (the memory allocated may not even be in RAM)
  1952.  *            returns NULL only if: No memory on heap and errmsg == NULL
  1953.  *    
  1954.  */
  1955.  
  1956. WHEAP         *wheap_alloc
  1957.            (size_t numbytes, unsigned char priority, char *errmsg );
  1958.  
  1959.  
  1960. /* wheap_access and wheap_deaccess 
  1961.  *         USE: after wheap_alloc() creates a heap element,
  1962.  *             call wheap_access() to bring data into ram (from disk or wherever)
  1963.  *             when done with it, call wheap_deaccess() to free up ram
  1964.  *        PARAMETERS:
  1965.  *            heap_ptr = ptr returned by call to wheap_alloc.
  1966.  *            readwrite = a flag. 
  1967.  *                for wheap_access() - readwrite= 1 means read data from disk
  1968.  *                                                (ie: re-accessing prior data)
  1969.  *                                     readwrite= 0 means don't access disk
  1970.  *                                                (ie: creating data first time)
  1971.  *                for wheap_deaccess() - readwrite=1 means write data to disk
  1972.  *                                                =0 means don't save data 
  1973.  *            The first time you access data, set readwrite=0.
  1974.  *            When you deaccess it, to save new values set readwrite =1.
  1975.  *            The last time it is de-accessed, just before free(), set=0
  1976.  *
  1977.  */
  1978. void far     *wheap_access   ( WHEAP *,  int readwrite );
  1979. void          wheap_deaccess ( WHEAP *,  int readwrite );
  1980.  
  1981. /* free heap element.
  1982.  */
  1983. void         wheap_free  ( WHEAP * );
  1984.  
  1985.  
  1986.  
  1987.  
  1988. /* wheap_avail() & similar funcitons
  1989.  *     determine amount of RAM available ( ram+xms, ram alone or xms alone )
  1990.  *     returned value does NOT include the amount specified
  1991.  *        by wheap_cushion
  1992.  */
  1993. unsigned long     wheap_availxms ( void );
  1994. unsigned long    wheap_avail    ( void );
  1995.  
  1996.  
  1997.  
  1998. /* wheap_swap2dsk()
  1999.  *     swap specified WHEAP object to disk
  2000.  */
  2001. void         wheap_swap2dsk ( WHEAP * );
  2002.  
  2003. /* wheap_swapall2dsk()
  2004.  *    swap all WHEAP objects of specified priority to disk
  2005.  */
  2006. void         wheap_swapall2dsk ( int priority );
  2007.  
  2008.  
  2009.  
  2010. /* wheap_unlink ()
  2011.  *    swaps from expanded or disk storage to main ram.
  2012.  *    removes control block from heap manager.
  2013.  *
  2014.  *    returned address can be released by free() (farfree() in small model)
  2015.  *
  2016.  */
  2017. void far     *wheap_unlink ( WHEAP * );
  2018.  
  2019.  
  2020.  
  2021.  
  2022. /* wheap_freeall ()
  2023.  *     cleanup heap, release xms blocks, free main storage, delete disk file
  2024.  *    called internally at program shutdown.
  2025.  */
  2026. void         wheap_freeall ( void );
  2027.  
  2028. /* wmalloc ()
  2029.  *        this is a 'shell' routine to malloc()
  2030.  *        alleviates need to always check for successful allocation
  2031.  *        and takes care of segmentation/normalization in LARGE model.
  2032.  *
  2033.  *        PARAMETERS: nbytes = number of bytes to allocate
  2034.  *                    errmsg = if no memory allocated, issue this msg and exit
  2035.  *                             if errmsg is NULL, and no memory avail,
  2036.  *                                 ... then return to caller.
  2037.  *                            errmsg should be less than 12 bytes.
  2038.  *        RETURNS: ptr to allocated data.
  2039.  *                 NULL if no memory AND errmsg was NULL.
  2040.  */
  2041. void *wmalloc ( size_t nbytes, char *errmsg );
  2042.  
  2043. /* wfarmalloc ()
  2044.  *     allocate far memory, NORMALIZE pointer, test for error
  2045.  *    if no memory obtained && errmsg!=NULL, print msg and exit.
  2046.  *                  && errmsg==NULL, return NULL to caller.
  2047.  *                errmsg should be less than 12 bytes.
  2048.  */
  2049. void  far *wfarmalloc ( unsigned long nbytes,  char *errmsg );
  2050.  
  2051.  
  2052.  
  2053.  
  2054. /*wrealloc()
  2055.  *        just like ANSI-realloc, except:
  2056.  *        PARAMETERS: void * ptr  - ptr to reallocate.
  2057.  *                    size_t nbytes - new size.
  2058.  *                    char * err_msg - if not NULL and memory not avail,
  2059.  *                                        wrealloc() halts program & writes errmsg
  2060.  *                                    errmsg should be less than 12 bytes. long.
  2061.  *
  2062.  */
  2063. void *wrealloc ( void *ptr, size_t nbytes, char *errmsg ); 
  2064.  
  2065.  
  2066.  
  2067. /* whplj_dump()
  2068.  * FAST screen dump routine for laserjet II printers.
  2069.  * USES Printer Control Language level III (PCL) for HP and compatible ptrs.
  2070.  *    NOTES:
  2071.  *        1) this screen dump uses 2 features to make it FAST
  2072.  *                A) reads one byte (=8pixels) at a time from the screen
  2073.  *                    (most commercial drivers seem to read 1 pixel at a time)
  2074.  *                B) writes to printer using compaction mode 1
  2075.  *        2) routine dumps screen for any text mode or any graphics mode.
  2076.  *                (automatically senses mode)    
  2077.  *        3) on color monitors in graphics dithering is same as for hercules:
  2078.  *                any pixel with either GREEN or BLUE is printed
  2079.  *                    ie: GREEN, CYAN, YELLOW, PURPLE are;   RED is not.
  2080.  *        4) print resolution and aspect ratio set automatically 
  2081.  *            to print image of screen as large as possible inside 8*11 paper
  2082.  *        5) VGA 50 line text mode: entire 50 line screen is printed (or EGA 43)
  2083.  *        6) multiple video page programs: printing is the active page
  2084.  *            (not necessarily the display page)
  2085.  *            NOTE: limitation of DOS PrtScrn always prints page 0.
  2086.  *
  2087.  *    usage: pass routine a FILE pointer. Use stdprn to get DOS printer
  2088.  *            Use a pointer to an open BINARY mode output file 
  2089.  *                to save a set of HPLJ commands to a disk file
  2090.  *            then later execute dos command:  TYPE  FILENAME > LPT1:
  2091.  *
  2092.  *
  2093.  *    function whplj_install () installs screen dump routine as a hotkey activated.
  2094.  *            asks if dump should be to printer or file
  2095.  *            files are named "HPLJ###.PCL" and numbered up from 0.
  2096.  */
  2097. void whplj_dump (FILE *f);
  2098. void whplj_install (int key);
  2099.  
  2100.  
  2101.  
  2102. /* ---------------------- End of FUNCS.DOC ---------------------------- */
  2103.  
  2104.