home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / cbw / part03 / window.h < prev   
Encoding:
C/C++ Source or Header  |  1987-06-16  |  5.9 KB  |  176 lines

  1. /* 
  2.  * Structure definitions for the window and keyboard routines.
  3.  * The first half of this file contains structure declarations.
  4.  * The second half contains functions, static variables, and
  5.  * key value declarations.
  6.  *
  7.  * Robert W. Baldwin,  December 1984
  8.  */
  9.  
  10.  
  11. /* Parameters */
  12.  
  13. #define    MAXWIDTH    80        /* Max width of a display line. */
  14. #define    MAXHEIGHT    24        /* Max height of a window. */
  15.  
  16.  
  17. /* Key stroke handler structure.
  18.  * The table is searched to find a key that matches the command typed
  19.  * by the user.  The corresponding keyproc is then invoked.
  20.  * The last entry in the table can have keychar == 0  or  -1.
  21.  * If it is -1, that entry's corresponding
  22.  * procedure is invoked with any characacter not previously matched.
  23.  * If it is 0, then the table driver knows it should look at 
  24.  * another table (if any).
  25.  * See terminal.h and .c for more info on command keys.
  26.  */
  27.  
  28. #define    key    int        /* Command code in high byte, arg in low. */
  29. #define    keyer    struct xkeyer    /* Typically have a table of these. */
  30.  
  31. struct    xkeyer    {
  32.     key    keychar;    /* Must be -1 or 0 for last entry in table. */
  33.     int    (*keyproc)();    /* Called with: window and key arg. */
  34.     };
  35.  
  36.  
  37. /* Common window definition. */
  38.  
  39. #define zwindow \
  40.     int    worg_row;    /* Row and column of the upper lefthand corner */\
  41.     int    worg_col;    /* of this window in global screen coordinates */\
  42.     int    wheight;    /* Number of rows in window. */\
  43.     int    wwidth;        /* Number of columns. */\
  44.     int    wcur_row;    /* Location of cursor relative to the origin. */\
  45.     int    wcur_col;    /* Equals (1,1) if at window's origin. */\
  46.     char    *wprivate;    /* Ptr to window's private data. */\
  47.     int    (*wfirst)();    /* Called when cursor enters window. */\
  48.     int    (*wlast)();    /* Called after cursor leaves window. */\
  49.     int    (*wredraw)();    /* Called to redraw window over junk. */\
  50.     int    (*wkey)();    /* Called when key pressed and window is active*/\
  51.     keyer    *wkeyprocs    /* Procs that perform key stroke actions. */
  52.  
  53.  
  54. /* Specification of window procedures. */
  55.  
  56. /* The follow declarations are assumed: gwindow *w;  key k;  keyer *ktab;
  57.  * int    currow, curcol;  (cursor location in local coordinates).
  58.  *
  59.  * wfirst(w, currow, curcol)
  60.  *    Called when cursor first enters window,
  61.  *      Responsible for setting w->wcur_row, w->wcur_col to desired value.
  62.  *      The display's cursor is already at the given coordinates.
  63.  *
  64.  * wlast(w)
  65.  *    Called when the driving loop notices that the cursor is no longer
  66.  *    in the currently active window.  Responsible for any cleanup needed
  67.  *    before another window can become active.
  68.  *
  69.  * wredraw(w)
  70.  *    Called to cleanup junk on the screen, usually at the user's request.
  71.  *    The routine should set every character within its window.
  72.  *      It should leave the cursor at some reasonable place, such as the
  73.  *    place it last was within this window.
  74.  *
  75.  * wkey(w, k)
  76.  *    Called when a key is pressed, and this window is active.
  77.  *    Responsible for performing the desired action.  Sub-windows
  78.  *    can assume that common keystrokes (like arrow movement) have
  79.  *    already been handled.
  80.  */
  81.  
  82. /* General purpose window. */
  83.  
  84. #define    gwindow        struct    xgwindow
  85.  
  86. struct     xgwindow    {
  87.     zwindow;
  88.     };
  89.  
  90.  
  91. /* Display line for fixed and editable strings. */
  92.  
  93. #define    displine    struct    xdispline
  94.  
  95. struct    xdispline    {
  96.     zwindow;
  97.     int    dl_min_col;    /* Min location of cursor relative to origin */
  98.     int    dl_max_col;    /* Max location of cursor relative to origin */
  99.     int    dl_length;    /* Last non-blank column in line. */
  100.     char    dl_chars[MAXWIDTH+1];    /* Null terminated string whose len */
  101.                     /*  always == the width of the line. */
  102.     };
  103.  
  104.  
  105. /* Window containing changeable lines of text. */
  106.  
  107. #define    twindow        struct    xtwindow
  108.  
  109. struct    xtwindow    {
  110.     zwindow;
  111.     displine    **dlines;    /* Null terminated array of lines. */
  112.     };
  113.  
  114.  
  115. /* Procedures from windowlib.c */
  116.  
  117. extern    int    wl_driver(/* wtab */);    /* Run window system. */
  118. extern    int    wl_refresh(/* wtab */);    /* Redraw all windows. */
  119. extern    int    wl_rcursor(/* w */);    /* Restore old cursor position. */
  120. extern    int    wl_setcur(/* w, row, col */);    /* Set cursor relative. */
  121. extern    int    wl_noop(/* w */);    /* Do nothing. */
  122. extern    int    wl_hascur(/* w */);    /* Return TRUE if cursor in window. */
  123. extern    int    wl_draw(/* w */);    /* Invoke window's redraw routine. */
  124. extern    int    wl_twdraw(/* w */);    /* Redraw for twindow. */
  125. extern    int    wl_dldraw(/* w */);    /* Redraw for displine. */
  126. extern    wl_dlleft(/* w */), wl_dlright(/* w */);
  127. extern    wl_dlfdel(/* w */), wl_dlbdel(/* w */), wl_dlclr(/* w */);
  128. extern    wl_dlinsert(/* w, k */);
  129. extern    wl_dlgetvar(/* w, buf */);    /* Fill buf with variable part. */
  130. extern    wl_dlsetvar(/* w, str */);    /* Set variable part from string. */
  131. extern    wl_nxtarg(/* line */);        /* Adv to next %. */
  132. extern    int    clrdline(/* dl */);    /* Blankout all chars in displine. */
  133. extern    int    setdline(/* dl */);    /* Set first chars of displine. */
  134. extern    int    wl_erase(/* w */);    /* Blank out a window. */
  135. extern    int    wl_outline(/* w */);    /* Outline w/o changing insides. */
  136. extern    int    key2graphic(/* c */);    /* Returns key to represent char c. */
  137.  
  138.  
  139. /* Procedures from keylib.c */
  140. extern    int    getkey();        /* Get a key stroke from the user. */
  141. extern    int    dokey(/* w, k */);    /* Invokes window's keyproc for k. */
  142. extern    int    ddokey(/* w,k,ktab */);    /* Invokes keyproc for k found in ktab. */
  143. extern    int    noopkey(/* w, k */);    /* A do-nothing keyproc. */
  144.  
  145.  
  146. /* These four routines move the cursor and if it is still within
  147.  * the window, w, they update the window's cursor position field.
  148.  * They can be used as keyprocs.
  149.  */
  150. extern    int    jogleft(/* w, k */);
  151. extern    int    jogright(/* w, k */);
  152. extern    int    jogup(/* w, k */);
  153. extern    int    jogdown(/* w, k */);
  154.  
  155.  
  156. /* Static variables from keylib.c */
  157.  
  158. extern    keyer    arwktab[];        /* Default key table for arrow keys. */
  159.                     /* They call the correct jog routine */
  160.  
  161.  
  162.  
  163. /* ASCII character definitions
  164.  */
  165. #define    CNTRL        037
  166. #define CTRL_P        (CNTRL & 'P')
  167. #define CTRL_N        (CNTRL & 'N')
  168. #define CTRL_B        (CNTRL & 'B')
  169. #define CTRL_F        (CNTRL & 'F')
  170. #define CTRL_C        (CNTRL & 'C')   /* added by slg */
  171. #define    RETURN        (CNTRL & 'M')
  172. #define    LINEFEED    (CNTRL & 'J')
  173. #define    TAB        (CNTRL & 'I')
  174. #define    SPACE        (' ')
  175.  
  176.