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

📄 window.c

📁 包含对应于实例1~实例190的程序源代码xxx.c和可执行文件xxx.exe
💻 C
📖 第 1 页 / 共 2 页
字号:
            /*
             * record that the current window has lost some columns from
             *  the window to the left for the new window
             */
            win->ccol = win->end_col = win->ccol - 1;
            win->rcol--;
            win->vertical = TRUE;
            show_window_header( win );
            show_vertical_separator( win );
            display_current_window( win );
            make_ruler( win );
            show_ruler( win );
            show_ruler_pointer( win );

            /*
             * set up the new cursor position as appropriate
             */
            wp->rcol = win->rcol;
            wp->ccol = wp->start_col + win->ccol - win->start_col;
            if (wp->ccol > wp->end_col)
               wp->ccol = wp->end_col;
            wp->bcol  = win->bcol;
            wp->rline = win->rline;
            wp->bin_offset = win->bin_offset;
            wp->ll       = win->ll;
            wp->cline    = win->cline;
            wp->visible  = TRUE;
            wp->vertical = TRUE;
            wp->letter   = file->next_letter++;
            wp->ruler    = mode.ruler;

            /*
             * the new window becomes the current window.
             */
            g_status.current_window = wp;

            check_virtual_col( wp, wp->rcol, wp->ccol );
            wp->file_info->dirty = FALSE;
            show_window_count( g_status.window_count );
            show_window_header( wp );
            display_current_window( wp );
            make_ruler( wp );
            show_ruler( wp );
         }
      }
   } else
      rc = ERROR;
   return( rc );
}


/*
 * Name:    show_vertical_separator
 * Purpose: To separate vertical screens
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 */
void show_vertical_separator( WINDOW *window )
{
int  i;
int  line;
int  col;

   line = window->top_line - 1;
   col  = window->end_col + 1;
   if (col < g_display.ncols - 1) {
      i = window->bottom_line - line;

      assert( i <= g_display.nlines );

      while (i-- >= 0)
         c_output( VERTICAL_CHAR, col, line++, g_display.head_color );
   }
}


/*
 * Name:    size_window
 * Purpose: To change the size of the current and one other window.
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   Use the Up and Down arrow keys to make the current window
 *           bigger or smaller.  The window above will either grow
 *           or contract accordingly.
 */
int  size_window( WINDOW *window )
{
char line_buff[(MAX_COLS+1)*2]; /* buffer for char and attribute  */
int  func;
int  c;
int  resize;
int  show_above_ruler;
int  old_bottom_line;
int  old_top_line;
int  new_bottom_line;
int  new_top_line;
register WINDOW *above;
register WINDOW *win;

   win = window;
   if (win->top_line != 1 && !win->vertical) {
      entab_linebuff( );
      un_copy_line( win->ll, win, TRUE );
      save_screen_line( 0, win->bottom_line, line_buff );

      /*
       * press up or down to change window size
       */
      set_prompt( win4, win->bottom_line );

      /*
       * resizing only affects current window and above visible window
       */
      above = g_status.window_list;
      while (above->bottom_line + 2 != win->top_line || !above->visible)
         above = above->next;
      if (above->vertical)
         /*
          * cannot resize vertical window
          */
         error( WARNING, win->bottom_line, win5 );
      else {
         old_top_line = win->top_line;
         old_bottom_line = above->bottom_line;
         show_above_ruler = FALSE;
         for (func=0; func != AbortCommand && func != Rturn; ) {

            /*
             * If user has redined the ESC and Return keys, make them Rturn and
             *  AbortCommand in this function.
             */
            c = getkey( );
            func = getfunc( c );
            if (c == RTURN || func == NextLine || func == BegNextLine)
               func = Rturn;
            else if (c == ESC)
               func = AbortCommand;
            resize = FALSE;

            /*
             * if LineUp, make current window top line grow and bottom line
             *  of above window shrink.  if window movement covers up current
             *  line of window then we must adjust logical line and real line.
             */
            if (func == LineUp) {
               if (above->bottom_line > above->top_line + above->ruler) {
                  if (win->rline == (win->cline - (win->top_line+win->ruler-1)))
                     --win->cline;
                  --win->top_line;
                  if (above->cline == above->bottom_line)
                     --above->cline;
                  --above->bottom_line;
                  resize = TRUE;
                  if (mode.ruler) {
                     if (win->ruler == FALSE) {
                        if (win->cline == win->top_line)
                           ++win->cline;
                        if (win->cline > win->bottom_line)
                           win->cline = win->bottom_line;
                        win->ruler = TRUE;
                     }
                  }
               }

            /*
             * if LineDown, make current window top line shrink and bottom line
             *  of above window grow.  if window movement covers up current
             *  line of window then we must adjust logical line and real line.
             */
            } else if (func == LineDown) {
               if (win->bottom_line > win->top_line + win->ruler) {
                  if (win->cline == win->top_line + win->ruler)
                     ++win->cline;
                  ++win->top_line;
                  ++above->bottom_line;
                  resize = TRUE;
                  if (mode.ruler) {
                     if (above->ruler == FALSE) {
                        if (above->cline == above->top_line)
                           ++above->cline;
                        if (above->cline > above->bottom_line)
                           above->cline = above->bottom_line;
                        above->ruler = TRUE;
                        make_ruler( above );
                        show_above_ruler = TRUE;
                     }
                  }
               }
            }

            /*
             * if we resize a window, then update window size and current and
             *  real lines if needed.
             */
            if (resize == TRUE) {
               setup_window( above );
               display_current_window( above );
               if (show_above_ruler) {
                  show_ruler( above );
                  show_ruler_pointer( above );
                  show_above_ruler = FALSE;
               }
               setup_window( win );
               show_window_header( win );
               win->ruler = mode.ruler;
               make_ruler( win );
               show_ruler( win );
               show_ruler_pointer( win );
               display_current_window( win );
               save_screen_line( 0, win->bottom_line, line_buff );

               /*
                * press up or down to change window size
                */
               set_prompt( win4, win->bottom_line );
            }
         }
         new_top_line = win->top_line;
         new_bottom_line = above->bottom_line;
         for (above=g_status.window_list; above != NULL; above=above->next) {
            if (!above->visible) {
               if (above->bottom_line == old_bottom_line) {
                  above->bottom_line = new_bottom_line;
                  if (above->cline < new_bottom_line)
                     above->cline = new_bottom_line;
                  setup_window( above );
               } else if (above->top_line == old_top_line) {
                  above->top_line = new_top_line;
                  if (above->cline < new_top_line)
                     above->cline = new_top_line;
                  if ((long)(above->cline+1L - (above->top_line+above->ruler)) >
                                                                above->rline)
                     above->cline = (int)above->rline + above->top_line +
                                     above->ruler - 1;
                  setup_window( above );
               }
            }
         }
      }
      restore_screen_line( 0, win->bottom_line, line_buff );
   } else {
     if (win->vertical)
        /*
         * cannot resize vertical window
         */
        error( WARNING, win->bottom_line, win5 );
     else
        /*
         * cannot resize top window
         */
        error( WARNING, win->bottom_line, win6 );
   }
   return( OK );
}


/*
 * Name:    zoom_window
 * Purpose: To blow-up current window.
 * Date:    September 1, 1991
 * Passed:  window:  pointer to current window
 * Notes:   Make all windows, visible and hidden, full size.
 */
int  zoom_window( WINDOW *window )
{
register WINDOW *wp;

   if (window != NULL) {
      entab_linebuff( );
      un_copy_line( window->ll, window, TRUE );
      for (wp=g_status.window_list; wp != NULL; wp=wp->next) {
         if (wp != window && wp->visible)
            wp->visible = FALSE;

         /*
          * can't diff one window, reset the diff
          */
         diff.defined = FALSE;
         if (wp->top_line != 1)
            wp->cline = wp->cline - (wp->top_line+wp->ruler) + 1;
         wp->top_line = 1;
         wp->bottom_line = g_display.nlines;
         wp->end_col   = g_display.ncols - 1;
         wp->start_col = 0;
         wp->vertical  = FALSE;
         check_virtual_col( wp, wp->rcol, wp->ccol );
         make_ruler( wp );
      }
      redraw_screen( window );
      show_ruler( window );
   }
   return( OK );
}


/*
 * Name:    next_hidden_window
 * Purpose: To display the window that is "behind" current window.
 * Date:    September 1, 1991
 * Passed:  window:  pointer to current window
 */
int  next_hidden_window( WINDOW *window )
{
int  poof = FALSE;
register WINDOW *wp;

   if (window != NULL) {

      /*
       * look for next hidden window starting with current window.
       */
      wp = window;
      for (wp=window->next; wp != NULL && !poof; ) {
         if (!wp->visible)
            poof = TRUE;
         else
            wp = wp->next;
      }

      /*
       * if we haven't found an invisible window yet, start looking
       *  for a hidden window from the beginning of the window list.
       */
      if (!poof) {
         for (wp=g_status.window_list; wp != NULL && !poof; ) {
            if (!wp->visible)
               poof = TRUE;
            else
               wp = wp->next;
         }
      }

      if (poof) {
         entab_linebuff( );
         un_copy_line( window->ll, window, TRUE );
         wp->cline = window->top_line + window->ruler +
                       (wp->cline - (wp->top_line + wp->ruler));
         wp->top_line = window->top_line;
         wp->bottom_line = window->bottom_line;
         wp->start_col = window->start_col;
         wp->end_col   = window->end_col;
         wp->vertical  = window->vertical;
         if (wp->cline < wp->top_line + wp->ruler)
            wp->cline = wp->top_line + wp->ruler;
         if (wp->cline > wp->bottom_line)
            wp->cline = wp->bottom_line;
         if ((wp->cline+1L - (wp->top_line+wp->ruler)) > wp->rline)
            wp->cline = (int)wp->rline + wp->top_line + wp->ruler - 1;
         check_virtual_col( wp, wp->rcol, wp->ccol );
         wp->visible = TRUE;
         window->visible = FALSE;
         if (diff.defined  &&  (diff.w1 == window  ||  diff.w2 == window))
            diff.defined = FALSE;
         g_status.current_window = wp;
         redraw_current_window( wp );
         make_ruler( wp );
         show_ruler( wp );
      }
   }
   return( OK );
}


/*
 * Name:    setup_window
 * Purpose: To set the page length and the center line of a window, based
 *           on the top and bottom lines.
 * Date:    June 5, 1991
 * Passed:  window: window to be set up
 */
void setup_window( WINDOW *window )
{
   window->page = window->bottom_line - (window->top_line + window->ruler) -
                  g_status.overlap + 1;
   if (window->page < 1)
      window->page = 1;
}


/*
 * Name:    finish
 * Purpose: To remove the current window and terminate the program if no
 *           more windows are left.
 * Date:    June 5, 1991
 * Passed:  window:  pointer to current window
 * Notes:   Order of deciding which window becomes current window:
 *          1) If any invisible window with same top and bottom line,
 *          and start_col and end_col, then first invisible one becomes
 *          current window.
 *          2) window above if it exists becomes current window
 *          3) window below if it exists becomes current window
 *          4) window right if it exists becomes current window
 *          5) window left  if it exists becomes current window
 *          6) first available invisible window becomes current window.
 *          When I added vertical windows, this routine became a LOT
 *           more complicated.  To keep things reasonably sane, let's
 *           only close windows that have three common edges, eg.
 *
 *                    谀哪哪穆哪哪哪哪哪

⌨️ 快捷键说明

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