home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / elvis184.zip / src / move4.c < prev    next >
C/C++ Source or Header  |  1994-03-26  |  4KB  |  228 lines

  1. /* move4.c */
  2.  
  3. /* Author:
  4.  *    Steve Kirkendall
  5.  *    1500 SW Park #326
  6.  *    Portland OR, 97201
  7.  *    kirkenda@cs.pdx.edu
  8.  */
  9.  
  10.  
  11. /* This file contains movement functions which are screen-relative */
  12.  
  13. #include "config.h"
  14. #include "vi.h"
  15.  
  16. /* This moves the cursor to a particular row on the screen */
  17. /*ARGSUSED*/
  18. MARK m_row(m, cnt, key)
  19.     MARK    m;    /* the cursor position */
  20.     long    cnt;    /* the row we'll move to */
  21.     int    key;    /* the keystroke of this move - H/L/M */
  22. {
  23.     DEFAULT(1);
  24.  
  25.     /* calculate destination line based on key */
  26.     cnt--;
  27.     switch (key)
  28.     {
  29.       case 'H':
  30.       case ctrl('_'):
  31.         cnt = topline + cnt;
  32.         break;
  33.  
  34.       case 'M':
  35.         cnt = topline + (LINES - 1) / 2;
  36.         break;
  37.  
  38.       case 'L':
  39.         cnt = botline - cnt;
  40.         break;
  41.     }
  42.  
  43.     /* return the mark of the destination line */
  44.     return MARK_AT_LINE(cnt);
  45. }
  46.  
  47.  
  48. /* This function repositions the current line to show on a given row */
  49. MARK m_z(m, cnt, key)
  50.     MARK    m;    /* the cursor */
  51.     long    cnt;    /* the line number we're repositioning */
  52.     int    key;    /* key struck after the z */
  53. {
  54.     long    newtop;
  55.     int    i;
  56.  
  57.     /* Which line are we talking about? */
  58.     if (cnt < 0 || cnt > nlines)
  59.     {
  60.         return MARK_UNSET;
  61.     }
  62.     if (cnt)
  63.     {
  64.         m = MARK_AT_LINE(cnt);
  65.         newtop = cnt;
  66.     }
  67.     else
  68.     {
  69.         newtop = markline(m);
  70.     }
  71.  
  72.     /* allow a "window size" number to be entered */
  73.     for (i = 0; key >= '0' && key <= '9'; key = getkey(0))
  74.     {
  75.         i = i * 10 + key - '0';
  76.     }
  77. #ifndef CRUNCH
  78.     if (i > 0 && i <= LINES - 1)
  79.     {
  80.         *o_window = i;
  81.     }
  82. #else
  83.     /* the number is ignored if -DCRUNCH */
  84. #endif
  85.  
  86.     /* figure out which line will have to be at the top of the screen */
  87.     switch (key)
  88.     {
  89.       case '\n':
  90. #if OSK
  91.       case '\l':
  92. #else
  93.       case '\r':
  94. #endif
  95.       case '+':
  96.         break;
  97.  
  98.       case '.':
  99.       case 'z':
  100.         newtop -= LINES / 2;
  101.         break;
  102.  
  103.       case '-':
  104.         newtop -= LINES - 1;
  105.         break;
  106.  
  107.       default:
  108.         return MARK_UNSET;
  109.     }
  110.  
  111.     /* make the new topline take effect */
  112.     redraw(MARK_UNSET, FALSE);
  113.     if (newtop >= 1)
  114.     {
  115.         topline = newtop;
  116.     }
  117.     else
  118.     {
  119.         topline = 1L;
  120.     }
  121.     redrawrange(0L, INFINITY, INFINITY);
  122.  
  123.     /* The cursor doesn't move */
  124.     return m;
  125. }
  126.  
  127.  
  128. /* This function scrolls the screen.  It does this by calling redraw() with
  129.  * an off-screen line as the argument.  It will move the cursor if necessary
  130.  * so that the cursor is on the new screen.
  131.  */
  132. /*ARGSUSED*/
  133. MARK m_scroll(m, cnt, key)
  134.     MARK    m;    /* the cursor position */
  135.     long    cnt;    /* for some keys: the number of lines to scroll */
  136.     int    key;    /* keystroke that causes this movement */
  137. {
  138.     MARK    tmp;    /* a temporary mark, used as arg to redraw() */
  139. #ifndef CRUNCH
  140.     int    savenearscroll;
  141.  
  142.     savenearscroll = *o_nearscroll;
  143.     *o_nearscroll = LINES;
  144. #endif
  145.  
  146.     /* adjust cnt, and maybe *o_scroll, depending on key */
  147.     switch (key)
  148.     {
  149.       case ctrl('F'):
  150.       case ctrl('B'):
  151.         DEFAULT(1);
  152.         redrawrange(0L, INFINITY, INFINITY); /* force complete redraw */
  153.         cnt = cnt * (LINES - 1) - 2; /* keeps two old lines on screen */
  154.         break;
  155.  
  156.       case ctrl('E'):
  157.       case ctrl('Y'):
  158.         DEFAULT(1);
  159.         break;
  160.  
  161.       case ctrl('U'):
  162.       case ctrl('D'):
  163.         if (cnt == 0) /* default */
  164.         {
  165.             cnt = *o_scroll;
  166.         }
  167.         else
  168.         {
  169.             if (cnt > LINES - 1)
  170.             {
  171.                 cnt = LINES - 1;
  172.             }
  173.             *o_scroll = cnt;
  174.         }
  175.         break;
  176.     }
  177.  
  178.     /* scroll up or down, depending on key */
  179.     switch (key)
  180.     {
  181.       case ctrl('B'):
  182.       case ctrl('Y'):
  183.       case ctrl('U'):
  184.         cnt = topline - cnt;
  185.         if (cnt < 1L)
  186.         {
  187.             cnt = 1L;
  188.             m = MARK_FIRST;
  189.         }
  190. #ifndef CRUNCH
  191.         if (key == ctrl('Y') && !has_AL && !has_SR)
  192.         {
  193.             topline = cnt;
  194.             redrawrange(0L, INFINITY, INFINITY);
  195.         }
  196. #endif
  197.         tmp = MARK_AT_LINE(cnt) + markidx(m);
  198.         redraw(tmp, FALSE);
  199.         if (markline(m) > botline)
  200.         {
  201.             m = MARK_AT_LINE(botline);
  202.         }
  203.         break;
  204.  
  205.       case ctrl('F'):
  206.       case ctrl('E'):
  207.       case ctrl('D'):
  208.         cnt = botline + cnt;
  209.         if (cnt > nlines)
  210.         {
  211.             cnt = nlines;
  212.             m = MARK_LAST;
  213.         }
  214.         tmp = MARK_AT_LINE(cnt) + markidx(m);
  215.         redraw(tmp, FALSE);
  216.         if (markline(m) < topline)
  217.         {
  218.             m = MARK_AT_LINE(topline);
  219.         }
  220.         break;
  221.     }
  222.  
  223. #ifndef CRUNCH
  224.     *o_nearscroll = savenearscroll;
  225. #endif
  226.     return m;
  227. }
  228.