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