home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MODEM / UWPC201.ZIP / UW-SRC.ZIP / CLIENT.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-14  |  6.9 KB  |  218 lines

  1. //-------------------------------------------------------------------------
  2. //
  3. // CLIENT.H - Declarations for creating UW clients within UW/PC.
  4. // 
  5. //  This file is part of UW/PC - a multi-window comms package for the PC.
  6. //  Copyright (C) 1990-1991  Rhys Weatherley
  7. //
  8. //  This program is free software; you can redistribute it and/or modify
  9. //  it under the terms of the GNU General Public License as published by
  10. //  the Free Software Foundation; either version 1, or (at your option)
  11. //  any later version.
  12. //
  13. //  This program is distributed in the hope that it will be useful,
  14. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. //  GNU General Public License for more details.
  17. //
  18. //  You should have received a copy of the GNU General Public License
  19. //  along with this program; if not, write to the Free Software
  20. //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. //
  22. // Revision History:
  23. // ================
  24. //
  25. //  Version  DD/MM/YY  By  Description
  26. //  -------  --------  --  --------------------------------------
  27. //    1.0    20/03/91  RW  Original Version of CLIENT.H
  28. //    1.1    08/06/91  RW  Add declarations for mouse handling.
  29. //
  30. // You may contact the author by:
  31. // =============================
  32. //
  33. //  e-mail: rhys@cs.uq.oz.au
  34. //    mail: Rhys Weatherley
  35. //          5 Horizon Drive
  36. //          Jamboree Heights
  37. //          Queensland 4074
  38. //        Australia
  39. //
  40. //-------------------------------------------------------------------------
  41.  
  42. #ifndef __CLIENT_H__
  43. #define    __CLIENT_H__
  44.  
  45. #pragma    warn    -par        // Turn off parameter checking.
  46.  
  47. //
  48. // Define forward declarations of some classes.
  49. //
  50. class    UWDisplay;
  51. class    UWTerminal;
  52.  
  53. //
  54. // Define the structure of a UW window client.  When a client is
  55. // created, it is assumed that its window is open and ready for
  56. // interaction, and when it is destroyed, the window has already
  57. // been killed and no more interactions are possible with it.  This
  58. // client is not actually used by the UW program - only those
  59. // classes that inherit from this one are used.
  60. //
  61. class    UWClient {
  62.  
  63. protected:
  64.  
  65.     UWDisplay    *window;    // Display window assoc with client.
  66.     UWClient    *underneath;    // Client running underneath (or NULL)
  67.     int        capture;    // Non-zero if client has capturing.
  68.  
  69.     // Send a character to the remote UW server for the
  70.     // window this client is executing under.
  71.     void    send    (int ch);
  72.  
  73.     // Process a default keypress.  This should be called
  74.     // by the client for any keys it cannot process when
  75.     // "key" is called, and that are deemed to be control
  76.     // keys for the UW client program.
  77.     void    defkey    (int keypress);
  78.  
  79.     // Determine if a client has capture on //
  80.     int    hascapture (void) { if (capture || !underneath)
  81.                       return (capture);
  82.                      else
  83.                       return (underneath -> hascapture ());
  84.                   }
  85.  
  86. public:
  87.  
  88.     int    isaterminal;        // Non-zero if a UWTermDesc type.
  89.  
  90.     // Create a client that is attached to a particular
  91.     // display window.
  92.     UWClient (UWDisplay *wind)
  93.            { window = wind; underneath = 0;
  94.              isaterminal = 0; capture = 0; };
  95.  
  96.     // Set the pointer to the client underneath.
  97.     void    setunder (UWClient *under) { underneath = under; };
  98.  
  99.     // Retrieve the name of the client (terminal type, etc).
  100.     virtual    char far *name    () { return ((char far *)"CLNT"); };
  101.  
  102.     // Retrieve the pointer to the client running under this one.
  103.     UWClient *under    (void) { return (underneath); };
  104.  
  105.     // Process a user's keypress.  This will only be called
  106.     // if this client is using the top-most displayed window.
  107.     virtual    void    key    (int keypress) { defkey (keypress); };
  108.  
  109.     // Process a character from the remote server.  This may
  110.     // be called at any time while the client is active.
  111.     virtual    void    remote    (int ch) { /* do nothing here */ };
  112.  
  113.     // This function is called periodically to give the client
  114.     // some "dead time" to do some work.
  115.     virtual    void    tick    (void) { if (underneath)
  116.                        underneath -> tick (); };
  117.  
  118.     // Get the status line for this client.  Returns NULL for
  119.     // the ordinary configuration status line.
  120.     virtual    char    *getstatus    (void) { return (0); };
  121.  
  122.     // Get an argument for the %0-%9 status line escape codes.
  123.     virtual    int    getstatarg    (int digit) { return (0); };
  124.  
  125.     // Process an event from the mouse.  This will be called
  126.     // whenever the mouse is detected to move or the button
  127.     // status of the mouse changes.  Note that the co-ordinates
  128.     // given are screen co-ordinates - not window co-ordinates.
  129.     // Mouse events are sent to the top-most window always.
  130.     virtual    void    mouse    (int x,int y,int buttons)
  131.           { if (underneath) underneath -> mouse (x,y,buttons); };
  132.  
  133. };
  134.  
  135. //
  136. // Define a terminal handling client class.  Objects of this
  137. // class or its subclasses correspond to terminal emulations
  138. // executing in windows.  This class is an extremely dumb
  139. // terminal that does no translation of control sequences.
  140. //
  141. class    UWTerminal : public UWClient {
  142.  
  143. public:
  144.  
  145.     UWTerminal (UWDisplay *wind) : UWClient (wind) {};
  146.  
  147.     virtual    char far *name    () { return ((char far *)" TTY"); };
  148.     virtual    void    key    (int keypress);
  149.     virtual    void    remote    (int ch);
  150.     virtual    void    mouse    (int x,int y,int buttons);
  151.  
  152. };
  153.  
  154. //
  155. // Define a terminal emulation class that uses neutral
  156. // terminal descriptions.
  157. //
  158. #define    STACK_SIZE    10
  159. #define    TERM_ARGS    8
  160. class    UWTermDesc : public UWTerminal {
  161.  
  162. protected:
  163.  
  164.     unsigned char far *description;    // Description buffer.
  165.     int    PC;            // Current program counter.
  166.     int    keys;            // Start of key mappings.
  167.     int    acc,regx,regy;        // Description registers.
  168.     int    flags;            // Terminal mode flags.
  169.     int    compare;        // Comparison flag.
  170.     int    stack[STACK_SIZE];    // Return stack for subroutines.
  171.     int    SP;            // Stack pointer.
  172.     int    savex,savey;        // Save positions for X and Y.
  173.     int    saveattr;        // Saved attribute value.
  174.     int    argarray[TERM_ARGS];    // Array of arguments for esc seqs.
  175.     int    index;            // Index into argument array.
  176.     int    base;            // Base of array for extraction.
  177.  
  178.     // Jump to the currently stored location.
  179.     void    jump        (void);
  180.  
  181.     // Interpret a terminal description until the next
  182.     // character request, starting with the given character.
  183.     void    interpret    (int ch);
  184.  
  185. public:
  186.  
  187.     UWTermDesc (UWDisplay *wind) : UWTerminal (wind)
  188.         { description = 0; isaterminal = 1; };
  189.  
  190.     virtual    char    far *name (void) { if (description)
  191.                          return ((char far *)description);
  192.                         else
  193.                          return (UWTerminal::name ());
  194.                      };
  195.     virtual    void    key    (int keypress);
  196.     virtual    void    remote    (int ch);
  197.  
  198.     // Set the description to be used for the terminal
  199.     // emulation of this terminal object, and start it up.
  200.     void    setemul    (unsigned char far *desc);
  201.  
  202. };
  203.  
  204. extern "C" {
  205.  
  206. //
  207. // Define the linked-in terminal emulation drivers.
  208. //
  209. extern    unsigned char far cdecl VT52_Driver;
  210. extern    unsigned char far cdecl ADM31_Driver;
  211. extern    unsigned char far cdecl ANSI_Driver;
  212.  
  213. }
  214.  
  215. #pragma    warn    +par        // Turn on parameter checking.
  216.  
  217. #endif    /* __CLIENT_H__ */
  218.