⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 movement.c

📁 一个开源著名的TDE编辑器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
 * Passed:  window:  pointer to current window */int  goto_bottom( TDE_WIN *window ){register TDE_WIN *win;   /* put window pointer in a register */int  diff;long line;int  empty;long length;   if (g_status.command_count == 0) {      win   = window;      diff  = win->bottom_line - win->cline;      line  = win->rline;      empty = ((length = win->file_info->length) == 0);      if ((diff && (line != length || empty)) || (line == length+1 && !empty)) {         if (un_copy_line( win->ll, win, TRUE, TRUE ) == ERROR)            return( ERROR );         undo_move( win, 0 );         if (line == length+1) {            dec_line( win, TRUE );            if (win->cline == win->top_line)               win->file_info->dirty = LOCAL;            else {               --win->cline;    /* we aren't at top of screen - so move up */               show_curl_line( win );            }         } else {            update_line( win );            if (line + diff > length)               diff = (int)(length - line);            line += diff;            win->cline += diff;            move_to_line( win, line, TRUE );            show_curl_line( win );         }      }      cursor_sync( win );   }   return( OK );}/* * Name:    page_up * Purpose: To move the cursor one (half) page up the window * Date:    June 5, 1991 * Passed:  window:  pointer to current window * Notes:   The cursor line is moved back the required number of lines *           towards the start of the file. *          If the start of the file is reached, then movement stops. * * jmh 020906: added the half-page function. */int  page_up( TDE_WIN *window ){int  i;                 /* count of lines scanned */int  rc = OK;           /* default return code */register TDE_WIN *win;  /* put window pointer in a register */long number;   win = window;   i   = win->cline - win->top_line;   if (win->rline != i) {      if (un_copy_line( win->ll, win, TRUE, TRUE ) == ERROR)         return( ERROR );      number = win->rline - ((g_status.command == ScreenUp) ? win->page                             : ((win->page + g_status.overlap) / 2));      if (number < i) {         number = i;         undo_move( win, 0 );      } else         undo_move( win, (g_status.command == ScreenUp) ? ScreenDown                                                        : HalfScreenDown );      move_to_line( win, number, TRUE );      win->file_info->dirty = LOCAL;   } else      rc = ERROR;   cursor_sync( win );   return( rc );}/* * Name:    page_down * Purpose: To move the cursor one (half) page down the window * Date:    June 5, 1991 * Passed:  window:  pointer to current window * Notes:   The cursor line is moved forwards the required number of lines *           towards the end of the file. *          If the end of the file is reached, then movement stops. * * jmh 020906: added the half-page function. */int  page_down( TDE_WIN *window ){int  rc = OK;long line;long last;register TDE_WIN *win;  /* put window pointer in a register */   win  = window;   line = win->rline;   last = win->file_info->length + 1;   if (line - (win->cline - win->top_line) <       last - (win->bottom_line - win->top_line)) {      if (un_copy_line( win->ll, win, TRUE, TRUE ) == ERROR)         return( ERROR );      line += (g_status.command == ScreenDown) ? win->page              : ((win->page + g_status.overlap) / 2);      if (line > last) {         win->cline -= (int)(line - last);         line = last;         undo_move( win, 0 );      } else         undo_move( win, (g_status.command == ScreenDown) ? ScreenUp                                                          : HalfScreenUp );      move_to_line( win, line, TRUE );      win->file_info->dirty = LOCAL;   } else      rc = ERROR;   cursor_sync( win );   return( rc );}/* * Name:    scroll_up * Purpose: To scroll the window up one line * Date:    June 5, 1991 * Passed:  window:  pointer to current window * Notes:   If this is the first page, then update screen here.  Else, make *           the window LOCAL dirty because we have to redraw screen. */int  scroll_up( TDE_WIN *window ){int  rc = OK;register TDE_WIN *win;   /* put window pointer in a register */   win = window;   if (win->rline > 0) {      if (un_copy_line( win->ll, win, TRUE, TRUE ) == ERROR)         return( ERROR );      if (win->rline == (win->cline - win->top_line)) {         undo_move( win, LineDown );         update_line( win );         dec_line( win, TRUE );         --win->cline;         show_curl_line( win );      } else {         if (win->cline == win->bottom_line) {            undo_move( win, LineDown );            dec_line( win, TRUE );         } else            ++win->cline;         win->file_info->dirty = LOCAL;      }   } else     rc = ERROR;   cursor_sync( win );   return( rc );}/* * Name:    scroll_down * Purpose: scroll window down one line * Date:    June 5, 1991 * Passed:  window:  pointer to current window * Notes:   If there is a line to scroll_down, make the window LOCAL dirty. *          We have to redraw the screen anyway, so don't update here. */int  scroll_down( TDE_WIN *window ){int  rc = OK;register TDE_WIN *win;   /* put window pointer in a register */   win = window;   if (win->cline == win->top_line) {      if (un_copy_line( win->ll, win, TRUE, TRUE ) == ERROR)         return( ERROR );      if (inc_line( win, TRUE )) {         undo_move( win, LineUp );         win->file_info->dirty = LOCAL;      } else         rc = ERROR;   } else {      --win->cline;      win->file_info->dirty = LOCAL;   }   cursor_sync( win );   return( rc );}/* * Name:    pan_up * Purpose: To leave cursor on same logical line and scroll text up * Date:    September 1, 1991 * Passed:  window:  pointer to current window * Notes:   If cursor is on first page then do not scroll. */int  pan_up( TDE_WIN *window ){int  rc = OK;register TDE_WIN *win;   /* put window pointer in a register */   win = window;   /*    * see if cursor is on the first page. if it's not then pan_up.    */   if (win->rline != (win->cline - win->top_line)) {      if (un_copy_line( win->ll, win, TRUE, TRUE ) == ERROR)         return( ERROR );      undo_move( win, PanDn );      dec_line( win, TRUE );      win->file_info->dirty = LOCAL;   } else      rc = ERROR;   cursor_sync( win );   return( rc );}/* * Name:    pan_down * Purpose: To leave cursor on same logical line and scroll text down * Date:    September 1, 1991 * Passed:  window:  pointer to current window * Notes:   If cursor is on last line in file then do not scroll. */int  pan_down( TDE_WIN *window ){int  rc = OK;register TDE_WIN *win;   /* put window pointer in a register */   win = window;   if (win->ll->next != NULL) {      if (un_copy_line( win->ll, win, TRUE, TRUE ) == ERROR)         return( ERROR );      undo_move( win, PanUp );      inc_line( win, TRUE );      win->file_info->dirty = LOCAL;   } else      rc = ERROR;   cursor_sync( win );   return( rc );}/* * Name:    move_up * Purpose: To move the cursor up one line * Date:    June 5, 1991 * Passed:  window:  pointer to current window * Notes:   If the cursor is at the top of the window, then the file must *           be scrolled down. * * jmh 991018: added drawing mode. */int  move_up( TDE_WIN *window ){int  rc = OK;register TDE_WIN *win;  /* put window pointer in a register */   win = window;   if (mode.draw && win->ll->len != EOF)      set_vert_g_char( win, G_UP );   rc = prepare_move_up( win );   if (mode.draw && rc == OK) {      if (win->rline == 0) {         g_status.command = AddLine;         rc = insert_newline( win );         prepare_move_down( win );      } else         set_vert_g_char( win, ~G_DN );   }   cursor_sync( win );   return( rc );}/* * Name:    move_down * Purpose: To move the cursor down one line * Date:    June 5, 1991 * Passed:  window:  pointer to current window * Notes:   If the cursor is at the bottom of the window, then the file must *           be scrolled up.   If the cursor is at the bottom of the file, *           then scroll line up until it is at top of screen. * * jmh 991018: added drawing mode. */int  move_down( TDE_WIN *window ){int  rc;register TDE_WIN *win;   /* put window pointer in a register */   win = window;   if (mode.draw) {      if (win->ll->len != EOF)         set_vert_g_char( win, G_DN );      if (win->rline == win->file_info->length) {         g_status.command = AddLine;         insert_newline( win );      }   }   rc = prepare_move_down( win );   if (mode.draw && win->ll->len != EOF)      set_vert_g_char( win, ~G_UP );   cursor_sync( win );   return( rc );}/* * Name:    beg_next_line * Purpose: To move the cursor to the beginning of the next line. * Date:    October 4, 1991 * Passed:  window:  pointer to current window */int  beg_next_line( TDE_WIN *window ){int  rc;   rc = prepare_move_down( window );   show_ruler_char( window );   check_virtual_col( window, 0, window->start_col );   cursor_sync( window );   return( rc );}/* * Name:    next_line * Purpose: To move the cursor to the first character of the next line. * Date:    October 4, 1991 * Passed:  window:  pointer to current window * * jmh 990504: match indentation/margin if the next line is blank. * jmh 031114: indent mode overrides fixed wrap mode. */int  next_line( TDE_WIN *window ){register int rcol;register TDE_WIN *win;   /* put window pointer in a register */line_list_ptr ll;int  tabs;int  tab_size;int  rc;   win = window;   tabs = win->file_info->inflate_tabs;   tab_size = win->file_info->ptab_size;   rc = prepare_move_down( win );   ll = win->ll;   rcol =  (mode.indent || mode.word_wrap == DYNAMIC_WRAP) ?          find_left_margin( ll, DYNAMIC_WRAP, tabs, tab_size ) :          first_non_blank( ll->line, ll->len, tabs, tab_size );   show_ruler_char( win );   check_virtual_col( win, rcol, win->ccol );   cursor_sync( win );   return( rc );}/* * Name:    move_left * Purpose: To move the cursor left one character * Date:    June 5, 1991 * Passed:  window:  pointer to current window * Notes:   If the cursor is already at the left of the screen, then *           scroll horizontally if we're not at beginning of line. * jmh 980724: update cursor cross * jmh 991018: added drawing mode. * jmh 991123: return ERROR if already at BOL; *             skip ccol == start_col test; *             don't bother showing the ruler after the sync. * jmh 030302: recognise the stream version. * jmh 031114: for the stream version treat beyond EOL as EOL. */int  move_left( TDE_WIN *window ){register TDE_WIN *win;text_ptr p;int  len;int  rc = OK;   win = window;   if (win->rcol > 0) {      if (mode.cursor_cross)         win->file_info->dirty = LOCAL;      if (mode.draw && win->ll->len != EOF)         set_horz_g_char( win, G_LF );      undo_move( win, CharRight );      if (g_status.command == StreamCharLeft  &&  !mode.draw) {         if (g_status.copied && win->file_info == g_status.current_file) {            p   = g_status.line_buff;            len = g_status.line_buff_len;         } else {            p   = win->ll->line;            len = win->ll->len;         }         len = find_end( p, len, win->file_info->inflate_tabs,                                 win->file_info->ptab_size );         if (len == 0)            goto prev_line;         if (win->rcol >= len)            rc = goto_eol( win );      }      if (win->ccol > win->start_col) {         show_ruler_char( win );         --win->ccol;      } else { /* (win->ccol == win->start_col) */         --win->bcol;         win->file_info->dirty = LOCAL | RULER;      }      --win->rcol;   } else if (g_status.command == StreamCharLeft  &&  !mode.draw) {prev_line:      rc = prepare_move_up( win );      if (rc == OK)         rc = goto_eol( win );   } else      rc = ERROR;   cursor_sync( win );   return( rc );}/* * Name:    move_right * Purpose: To move the cursor right one character * Date:    June 5, 1991 * Passed:  window:  pointer to current window * Notes:   If the cursor is already at the right of the screen (logical *          column 80) then scroll horizontally right. * jmh 980724: update cursor cross * jmh 991018: added drawing mode.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -