📄 window.c
字号:
/******************* start of original comments ********************//* * Written by Douglas Thomson (1989/1990) * * This source code is released into the public domain. *//* * Name: dte - Doug's Text Editor program - window module * Purpose: This file contains the code associated with opening and sizing * windows, and also displaying the help window. * File: window.c * Author: Douglas Thomson * System: this file is intended to be system-independent * Date: October 12, 1989 *//********************* end of original comments ********************//* * The window routines have been EXTENSIVELY rewritten. Some routines were * changed so only one logical function is carried out, eg. 'initialize_window'. * I like the Microsoft way of resizing windows - just press the up and down * arrows to adjust the window to desired size. I also like pressing one key * to change windows. All of which are implemented in TDE. * * In TDE, version 1.4, I added support for vertical windows. * * New editor name: TDE, the Thomson-Davis Editor. * Author: Frank Davis * Date: June 5, 1991, version 1.0 * Date: July 29, 1991, version 1.1 * Date: October 5, 1991, version 1.2 * Date: January 20, 1992, version 1.3 * Date: February 17, 1992, version 1.4 * Date: April 1, 1992, version 1.5 * Date: June 5, 1992, version 2.0 * Date: October 31, 1992, version 2.1 * Date: April 1, 1993, version 2.2 * Date: June 5, 1993, version 3.0 * Date: August 29, 1993, version 3.1 * Date: November 13, 1993, version 3.2 * Date: June 5, 1994, version 4.0 * Date: December 5, 1998, version 5.0 (jmh) * * This modification of Douglas Thomson's code is released into the * public domain, Frank Davis. You may distribute it freely. */#include "tdestr.h"#include "common.h"#include "define.h"#include "tdefunc.h"int make_window; /* tell other functions not to redraw */extern TDE_WIN *results_window; /* defined in findrep.c */extern file_infos *results_file;extern TDE_WIN *browser_window; /* defined in movement.c */static TDE_WIN *find_make_window( TDE_WIN * );/* * Name: next_window * Purpose: To move to the next visible/hidden window. * Date: June 5, 1991 * Passed: window: pointer to current window * Notes: Start with current window. If next window exists then go to it * else go to the first (top) window on screen. * When I added vertical windows, finding the "correct" next * window became extremely, unnecessarily, unmanageably complicated. * let's just use a simple procedure to find the first available, * visible, next window. * * jmh 990502: incorporated next_hidden_window(). */int next_window( TDE_WIN *window ){register TDE_WIN *wp;int change;int visibility; change = FALSE; visibility = (g_status.command == NextWindow); /* * start with current window and look for the next appropriate window */ wp = window->next; while (wp != NULL) { if (wp->visible == visibility) { change = TRUE; break; } wp = wp->next; } /* * if we haven't found a window yet, go to the beginning of * the list until we find a visible/hidden window. */ if (!change) { wp = g_status.window_list; while (wp != window) { if (wp->visible == visibility) { change = TRUE; break; } wp = wp->next; } } if (change) change_window( window, wp ); return( OK );}/* * Name: prev_window * Purpose: To move to the previous visible/hidden window. * Date: June 5, 1991 * Passed: window: pointer to current window * Notes: Start with current window. If previous window exists then go to * it else go to the last (bottom) window on screen. Opposite of * next_window. * when I added vertical windows, finding the "correct" previous * window became extremely, unnecessarily, unmanageably complicated. * let's just use a simple procedure to find the first available, * visible, previous window. * * jmh 990502: incorporated prev_hidden_window(). */int prev_window( TDE_WIN *window ){register TDE_WIN *wp;register TDE_WIN *win;int visibility; visibility = (g_status.command == PreviousWindow); /* * start with current window and look for the previous appropriate window */ win = window->prev; while (win != NULL) { if (win->visible == visibility) break; win = win->prev; } /* * if we haven't found an appropriate window yet, keep searching right * to the end of the list, remembering the last one found */ if (win == NULL) { wp = window->next; while (wp != NULL) { if (wp->visible == visibility) win = wp; wp = wp->next; } } if (win) change_window( window, win ); return( OK );}/* * Name: goto_window * Purpose: To select a new window by number or file name * Author: Jason Hood * Date: May 2, 1999 * Passed: window: pointer to current window * * jmh 060829: blank answer will bring up a window list. */int goto_window( TDE_WIN *window ){char answer[MAX_COLS+2];TDE_WIN *win;int rc;LIST *wlist;DIRECTORY dir;char path[PATH_MAX];char *name;int len; *answer = '\0'; rc = get_name( win20, window->bottom_line, answer, &h_win ); if (rc > 0) { rc = find_window( &win, answer, window->bottom_line ); if (rc == OK) change_window( window, win ); } else if (rc == 0) { wlist = malloc( g_status.window_count * sizeof(*wlist) ); if (wlist == NULL) return( ERROR ); len = numlen( g_status.window_count ); for (win = g_status.window_list; win != NULL; win = win->next) { if (win->title) name = win->title; else if (*win->file_info->file_name == '\0') name = win->file_info->file_name + 1; else name = relative_path( path, win, FALSE ); reduce_string( path, name, g_display.ncols-4-4-8-len, MIDDLE ); sprintf( answer, "%c %*d%c %c%c%c %s", win == window ? '!' : (win->visible ? '+' : '-'), len, win->file_info->file_no, win->letter, win->file_info->read_only ? '!' : ' ', win->file_info->scratch ? '#' : ' ', win->file_info->modified ? '*' : ' ', path ); wlist[rc].name = my_strdup( answer ); if (wlist[rc].name == NULL) break; wlist[rc].color = Color( Dialog ); wlist[rc].data = win; ++rc; } shell_sort( wlist, rc ); setup_directory_window( &dir, wlist, rc ); write_directory_list( wlist, &dir ); xygoto( -1, -1 ); rc = select_file( wlist, "", &dir ); redraw_screen( window ); if (rc == OK) change_window( window, wlist[dir.select].data ); for (len = g_status.window_count; --len >= 0;) my_free( wlist[len].name ); free( wlist ); } return( rc );}/* * Name: change_window * Purpose: helper function to change to a new window * Date: May 2, 1999 * Passed: window: current window * wp: new window * * jmh 020730: call setup_window(). * jmh 021021: track the path. */void change_window( TDE_WIN *window, TDE_WIN *wp ){int redraw = FALSE; if (window == wp) return; un_copy_line( window->ll, window, TRUE, TRUE ); g_status.current_window = wp; g_status.current_file = wp->file_info; if (wp->visible) show_tab_modes( ); else { wp->cline += window->top_line - wp->top_line; wp->top = window->top; wp->bottom_line = window->bottom_line; wp->left = window->left; wp->end_col = window->end_col; wp->vertical = window->vertical; wp->ruler = window->ruler; setup_window( wp ); check_cline( wp, wp->cline ); check_virtual_col( wp, wp->rcol, wp->ccol ); wp->visible = TRUE; if (!make_window) { window->visible = FALSE; if (diff.defined && (diff.w1 == window || diff.w2 == window)) diff.defined = FALSE; redraw = TRUE; } } if (mode.track_path) set_path( wp ); if (redraw) redraw_current_window( wp );#if defined( __WIN32__ ) else if (!make_window) show_window_fname( wp ); /* update console title */#endif}/* * Name: split_horizontal * Purpose: To split screen horizontally at the cursor. * Date: June 5, 1991 * Modified: November 13, 1993, Frank Davis per Byrial Jensen * Passed: window: pointer to current window * Notes: split the screen horizontally at the cursor position. * * jmh 991109: the cursor position is the new header. * jmh 020823: move the old window up a line instead of scrolling. * jmh 030227: added NewHorizontal function to load the next file instead of * splitting the current. * jmh 030323: removed NewHorizontal; * added Half version to split the window in half, leaving the * cursor where it is. * jmh 030324: do an "actual" split - the top window has everything before * the cursor, the bottom everything after (ie. the top and * bottom lines do not change). */int split_horizontal( TDE_WIN *window ){register TDE_WIN *wp;register TDE_WIN *win; /* register pointer for window */TDE_WIN *temp;file_infos *file; /* file structure for file belonging to new window */int half;int top_line;int change;const char *errmsg;int rc; rc = ERROR; win = window; if (win != NULL) { /* * check that there is room for the window */ errmsg = NULL; half = (g_status.command == SplitHalfHorizontal); top_line = (half) ? ((win->top_line + win->bottom_line + 1) / 2) : win->cline; if (top_line == win->top_line) /* * move cursor down first */ errmsg = win1a; else if (top_line == win->bottom_line) /* * move cursor up first */ errmsg = win1; if (errmsg) { if (half) /* * window too small */ errmsg = win1b; error( WARNING, win->bottom_line, errmsg ); } else { file = win->file_info; assert( file != NULL ); rc = create_window( &temp, top_line, win->bottom_line, win->left, win->end_col, file ); if (rc == OK) { wp = temp; wp->visible = FALSE; un_copy_line( win->ll, win, TRUE, TRUE ); wp->visible = TRUE; /* * set up the new cursor position as appropriate */ wp->rcol = win->rcol; wp->ccol = win->ccol; wp->bcol = win->bcol; wp->rline = win->rline; wp->bin_offset = win->bin_offset; wp->ll = win->ll; wp->syntax = win->syntax; wp->vertical = win->vertical; if (win->title) wp->title = my_strdup( win->title ); change = win->cline - top_line; if (half && change) { if (change < 0) { if (file->length < top_line - win->top_line - 1) { check_cline( wp, wp->cline + win->cline - win->top_line ); file->dirty = LOCAL; } else { move_to_line( wp, wp->rline - change + wp->ruler, TRUE ); inc_line( wp, TRUE ); } } else { move_to_line( win, win->rline - change - 1, TRUE ); wp->cline = win->cline; win->cline = top_line - 1; } } else { --win->cline; dec_line( win, TRUE ); inc_line( wp, TRUE ); if (wp->ruler) inc_line( wp, TRUE ); } /* * record that the current window has lost some lines from * the bottom for the new window, and adjust its page size * etc accordingly. */ win->bottom_line = top_line - 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -