home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / the25.zip / thesrc251.zip / scroll.c < prev    next >
C/C++ Source or Header  |  1997-11-10  |  12KB  |  297 lines

  1. /***********************************************************************/
  2. /* SCROLL.C - SCROLL commands                                          */
  3. /* This file contains all commands that can be assigned to function    */
  4. /* keys or typed on the command line.                                  */
  5. /***********************************************************************/
  6. /*
  7.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  8.  * Copyright (C) 1991-1997 Mark Hessling
  9.  *
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License as
  12.  * published by the Free Software Foundation; either version 2 of
  13.  * the License, or any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to:
  22.  *
  23.  *    The Free Software Foundation, Inc.
  24.  *    675 Mass Ave,
  25.  *    Cambridge, MA 02139 USA.
  26.  *
  27.  *
  28.  * If you make modifications to this software that you feel increases
  29.  * it usefulness for the rest of the community, please email the
  30.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  31.  * This software is going to be maintained and enhanced as deemed
  32.  * necessary by the community.
  33.  *
  34.  * Mark Hessling                 Email:             M.Hessling@qut.edu.au
  35.  * PO Box 203                    Phone:                    +617 3802 0800
  36.  * Bellara                       http://www.gu.edu.au/gext/the/markh.html
  37.  * QLD 4507                      **** Maintainer PDCurses & REXX/SQL ****
  38.  * Australia                     ************* Author of THE ************
  39.  */
  40.  
  41. /*
  42. $Id: scroll.c 2.1 1995/06/24 16:31:12 MH Rel MH $
  43. */
  44.  
  45. #include <the.h>
  46. #include <proto.h>
  47.  
  48. /***********************************************************************/
  49. #ifdef HAVE_PROTO
  50. short scroll_page(short direction,LINETYPE num_pages,bool scrollbar)
  51. #else
  52. short scroll_page(direction,num_pages,scrollbar)
  53. short direction;
  54. LINETYPE num_pages;
  55. bool scrollbar;
  56. #endif
  57. /***********************************************************************/
  58. {
  59. /*-------------------------- external data ----------------------------*/
  60.  extern bool scroll_cursor_stay;
  61.  extern bool curses_started;
  62. /*--------------------------- local data ------------------------------*/
  63.  short y=0,x=0,save_y=0;
  64.  bool save_scroll_cursor_stay=scroll_cursor_stay;
  65. /*--------------------------- processing ------------------------------*/
  66. #ifdef TRACE
  67.  trace_function("scroll.c:  scroll_page");
  68. #endif
  69. /*---------------------------------------------------------------------*/
  70. /* If scrolling backward and already on TOF, return.                   */
  71. /* If scrolling forward and already on EOF, return.                    */
  72. /*---------------------------------------------------------------------*/
  73.  if ((direction == DIRECTION_BACKWARD
  74.       && CURRENT_TOF)
  75.  ||  (direction == DIRECTION_FORWARD
  76.       && CURRENT_BOF))
  77.    {
  78. #ifdef TRACE
  79.     trace_return();
  80. #endif
  81.     return(RC_TOF_EOF_REACHED);
  82.    }
  83. /*---------------------------------------------------------------------*/
  84. /* If scrolling via the scroll bars, ALWAYS leave the cursor on the    */
  85. /* screen line.                                                        */
  86. /*---------------------------------------------------------------------*/
  87.  if (scrollbar)
  88.     save_scroll_cursor_stay = TRUE;
  89. /*---------------------------------------------------------------------*/
  90. /* Get current focus row if cursor is to stay on current focus line... */
  91. /*---------------------------------------------------------------------*/
  92.  if (save_scroll_cursor_stay)
  93.     save_y = get_row_for_focus_line(current_screen,CURRENT_VIEW->focus_line,CURRENT_VIEW->current_row);
  94. /*---------------------------------------------------------------------*/
  95. /* Find the new current line, num_pages away...                        */
  96. /*---------------------------------------------------------------------*/
  97.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  98.  CURRENT_VIEW->current_line = find_next_current_line(num_pages,direction);
  99.  build_screen(current_screen);
  100.  if (save_scroll_cursor_stay)
  101.    {
  102.     save_y = get_row_for_tof_eof(save_y,current_screen);
  103.     CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[save_y].line_number;
  104.     pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  105.     build_screen(current_screen);
  106.    }
  107.  else
  108.    {
  109.     CURRENT_VIEW->focus_line = calculate_focus_line(CURRENT_VIEW->focus_line,
  110.                                                     CURRENT_VIEW->current_line);
  111.     pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  112.    }
  113. /*---------------------------------------------------------------------*/
  114. /* If curses has started, display screen and sort out cursor position..*/
  115. /*---------------------------------------------------------------------*/
  116.  if (curses_started)
  117.    {
  118.     getyx(CURRENT_WINDOW,y,x);
  119.     display_screen(current_screen);
  120.     if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  121.       {
  122.        y = get_row_for_focus_line(current_screen,CURRENT_VIEW->focus_line,
  123.                                CURRENT_VIEW->current_row);
  124.        wmove(CURRENT_WINDOW,y,x);
  125.        if (scrollbar)
  126.           wrefresh(CURRENT_WINDOW);
  127.       }
  128.    }
  129. #ifdef TRACE
  130.  trace_return();
  131. #endif
  132.  if (CURRENT_TOF || CURRENT_BOF)
  133.     return(RC_TOF_EOF_REACHED);
  134.  else
  135.     return(RC_OK);
  136. }
  137. /***********************************************************************/
  138. #ifdef HAVE_PROTO
  139. short scroll_line(short direction,LINETYPE num_lines,bool scrollbar,bool escreen)
  140. #else
  141. short scroll_line(direction,num_lines,scrollbar,escreen)
  142. short direction;
  143. LINETYPE num_lines;
  144. bool scrollbar;
  145. bool escreen;
  146. #endif
  147. /***********************************************************************/
  148. {
  149. /*-------------------------- external data ----------------------------*/
  150. /*--------------------------- local data ------------------------------*/
  151.  short rc=RC_OK;
  152.  unsigned short x=0,y=0;
  153.  bool on_file_edge=FALSE,on_screen_edge=FALSE;
  154.  short number_focus_rows=0;
  155.  bool leave_cursor=FALSE;
  156.  LINETYPE new_focus_line=0L,new_current_line=0L,edge_line=0L;
  157.  LINETYPE longy=0L,longx=0L;
  158.  ROWTYPE yoff1=0,yoff2=0;
  159. /*--------------------------- processing ------------------------------*/
  160. #ifdef TRACE
  161.  trace_function("scroll.c:  scroll_line");
  162. #endif
  163. /*---------------------------------------------------------------------*/
  164. /* If this function is called via scrollbar...                         */
  165. /* If scrolling backward and already on TOF, return.                   */
  166. /* If scrolling forward and already on EOF, return.                    */
  167. /*---------------------------------------------------------------------*/
  168.  if (scrollbar)
  169.    {
  170.     if ((direction == DIRECTION_BACKWARD
  171.          && CURRENT_TOF)
  172.     ||  (direction == DIRECTION_FORWARD
  173.          && CURRENT_BOF))
  174.       {
  175. #ifdef TRACE
  176.        trace_return();
  177. #endif
  178.        return(RC_TOF_EOF_REACHED);
  179.       }
  180.    }
  181.  calculate_scroll_values(&number_focus_rows,&new_focus_line,
  182.                          &new_current_line,
  183.                          &on_screen_edge,&on_file_edge,
  184.                          &leave_cursor,direction);
  185.  switch(scrollbar)
  186.    {
  187.     case FALSE:
  188.          getyx(CURRENT_WINDOW,y,x);
  189.          if (direction == DIRECTION_FORWARD)
  190.            {
  191.             edge_line = CURRENT_FILE->number_lines+1L;
  192.             yoff1 = y - ((leave_cursor) ? 0 : 1);
  193.             yoff2 = y + number_focus_rows;
  194.            }
  195.          else
  196.            {
  197.             edge_line = 0L;
  198.             yoff1 = y + ((leave_cursor) ? 0 : 1);
  199.             yoff2 = y - number_focus_rows;
  200.            }
  201. /*---------------------------------------------------------------------*/
  202. /* If the cursor is on the edgs of the window or on the edge of the    */
  203. /* file and tabbing to the command line is set, tab to the command line*/
  204. /* provided the command line is ON.                                    */
  205. /*---------------------------------------------------------------------*/
  206.          if (!escreen
  207.          && (on_screen_edge || on_file_edge))
  208.            {
  209.             if (CURRENT_WINDOW_COMMAND == NULL)
  210.               {
  211.                getyx(CURRENT_WINDOW,y,x);
  212.                if (direction == DIRECTION_FORWARD)
  213.                   rc = find_first_focus_line(&y);
  214.                else
  215.                   rc = find_last_focus_line(&y);
  216.                if (rc == RC_OK)
  217.                  {
  218.                   CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[y].line_number;
  219.                   pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  220.                   wmove(CURRENT_WINDOW,y,x);
  221.                  }
  222.                break;
  223.               }
  224.             cursor_cmdline(1);
  225.             break;
  226.            }
  227. /*---------------------------------------------------------------------*/
  228. /* If the cursor is on the edge of the file...                         */
  229. /*---------------------------------------------------------------------*/
  230.          if (on_file_edge)
  231.            {
  232. /*---------------------------------------------------------------------*/
  233. /* ... and the current row is the edge of the file, stay there.        */
  234. /*---------------------------------------------------------------------*/
  235.             if (CURRENT_VIEW->current_line == edge_line)
  236.                break;
  237. /*---------------------------------------------------------------------*/
  238. /* ... and the edge of the file is above or below the current row,     */
  239. /* scroll the window.                                                  */
  240. /*---------------------------------------------------------------------*/
  241.             CURRENT_VIEW->current_line = new_current_line;
  242.             build_screen(current_screen);
  243.             display_screen(current_screen);
  244.             y = get_row_for_focus_line(current_screen,CURRENT_VIEW->focus_line,CURRENT_VIEW->current_row);
  245.             wmove(CURRENT_WINDOW,y,x);
  246.             break;
  247.            }
  248. /*---------------------------------------------------------------------*/
  249. /* If on the edge of the window, scroll the window.                    */
  250. /*---------------------------------------------------------------------*/
  251.          if (on_screen_edge)
  252.            {
  253.             CURRENT_VIEW->current_line = new_current_line;
  254.             post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  255.             CURRENT_VIEW->focus_line = new_focus_line;
  256.             pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  257.                                 build_screen(current_screen);
  258.             display_screen(current_screen);
  259.             wmove(CURRENT_WINDOW,yoff1,x);
  260.             break;
  261.            }
  262. /*---------------------------------------------------------------------*/
  263. /* We are in the middle of the window, so just move the cursor up or   */
  264. /* down 1 line.                                                        */
  265. /*---------------------------------------------------------------------*/
  266.          wmove(CURRENT_WINDOW,yoff2,x);
  267.          rc = post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL,TRUE);
  268.          CURRENT_VIEW->focus_line = new_focus_line;
  269.          pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line,(LINE *)NULL);
  270.          build_screen(current_screen);
  271.          if (CURRENT_VIEW->highlight
  272.          &&  rc != RC_NO_LINES_CHANGED)
  273.             display_screen(current_screen);
  274.          break;
  275.     case TRUE:
  276.          if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  277.             get_cursor_position(&longy,&longx,&new_focus_line,&new_current_line);
  278.          rc = advance_current_line((direction == DIRECTION_FORWARD) ? num_lines : -num_lines);
  279.          if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  280.            {
  281.             cursor_move(TRUE,(short)longy,(short)longx);
  282.             show_heading(current_screen);
  283.             if (CURRENT_VIEW->id_line)
  284.                wnoutrefresh(CURRENT_WINDOW_IDLINE);
  285.             wrefresh(CURRENT_WINDOW);
  286.            }
  287.          break;
  288.         }
  289. #ifdef TRACE
  290.  trace_return();
  291. #endif
  292.  if (CURRENT_TOF || CURRENT_BOF)
  293.     return(RC_TOF_EOF_REACHED);
  294.  else
  295.     return(RC_OK);
  296. }
  297.