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

📄 util.c

📁 源码,标准c++用力
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *	$XConsortium: util.c,v 1.31 91/06/20 18:34:47 gildea Exp $ *//* * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. * *                         All Rights Reserved * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, * provided that the above copyright notice appear in all copies and that * both that copyright notice and this permission notice appear in * supporting documentation, and that the name of Digital Equipment * Corporation not be used in advertising or publicity pertaining to * distribution of the software without specific, written prior permission. * * * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS * SOFTWARE. *//* util.c */#include "ptyx.h"#include "data.h"#include "error.h"#include "menu.h"#include <stdio.h>static void horizontal_copy_area();static void vertical_copy_area();/* * These routines are used for the jump scroll feature */FlushScroll(screen)register TScreen *screen;{	register int i;	register int shift = -screen->topline;	register int bot = screen->max_row - shift;	register int refreshtop;	register int refreshheight;	register int scrolltop;	register int scrollheight;	if(screen->cursor_state)		HideCursor();	if(screen->scroll_amt > 0) {		refreshheight = screen->refresh_amt;		scrollheight = screen->bot_marg - screen->top_marg -		 refreshheight + 1;		if((refreshtop = screen->bot_marg - refreshheight + 1 + shift) >		 (i = screen->max_row - screen->scroll_amt + 1))			refreshtop = i;		if(screen->scrollWidget && !screen->alternate		 && screen->top_marg == 0) {			scrolltop = 0;			if((scrollheight += shift) > i)				scrollheight = i;			if((i = screen->bot_marg - bot) > 0 &&			 (refreshheight -= i) < screen->scroll_amt)				refreshheight = screen->scroll_amt;			if((i = screen->savedlines) < screen->savelines) {				if((i += screen->scroll_amt) >				  screen->savelines)					i = screen->savelines;				screen->savedlines = i;				ScrollBarDrawThumb(screen->scrollWidget);			}		} else {			scrolltop = screen->top_marg + shift;			if((i = bot - (screen->bot_marg - screen->refresh_amt +			 screen->scroll_amt)) > 0) {				if(bot < screen->bot_marg)					refreshheight = screen->scroll_amt + i;			} else {				scrollheight += i;				refreshheight = screen->scroll_amt;				if((i = screen->top_marg + screen->scroll_amt -				 1 - bot) > 0) {					refreshtop += i;					refreshheight -= i;				}			}		}	} else {		refreshheight = -screen->refresh_amt;		scrollheight = screen->bot_marg - screen->top_marg -		 refreshheight + 1;		refreshtop = screen->top_marg + shift;		scrolltop = refreshtop + refreshheight;		if((i = screen->bot_marg - bot) > 0)			scrollheight -= i;		if((i = screen->top_marg + refreshheight - 1 - bot) > 0)			refreshheight -= i;	}	scrolling_copy_area(screen, scrolltop+screen->scroll_amt,			    scrollheight, screen->scroll_amt);	ScrollSelection(screen, -(screen->scroll_amt));	screen->scroll_amt = 0;	screen->refresh_amt = 0;	if(refreshheight > 0) {		XClearArea (		    screen->display,		    TextWindow(screen),		    (int) screen->border + screen->scrollbar,		    (int) refreshtop * FontHeight(screen) + screen->border,		    (unsigned) Width(screen),		    (unsigned) refreshheight * FontHeight(screen),		    FALSE);		ScrnRefresh(screen, refreshtop, 0, refreshheight,		 screen->max_col + 1, False);	}}AddToRefresh(screen)register TScreen *screen;{	register int amount = screen->refresh_amt;	register int row = screen->cur_row;	if(amount == 0)		return(0);	if(amount > 0) {		register int bottom;		if(row == (bottom = screen->bot_marg) - amount) {			screen->refresh_amt++;			return(1);		}		return(row >= bottom - amount + 1 && row <= bottom);	} else {		register int top;		amount = -amount;		if(row == (top = screen->top_marg) + amount) {			screen->refresh_amt--;			return(1);		}		return(row <= top + amount - 1 && row >= top);	}}/*  * scrolls the screen by amount lines, erases bottom, doesn't alter  * cursor position (i.e. cursor moves down amount relative to text). * All done within the scrolling region, of course.  * requires: amount > 0 */Scroll(screen, amount)register TScreen *screen;register int amount;{	register int i = screen->bot_marg - screen->top_marg + 1;	register int shift;	register int bot;	register int refreshtop = 0;	register int refreshheight;	register int scrolltop;	register int scrollheight;	if(screen->cursor_state)		HideCursor();	if (amount > i)		amount = i;    if(screen->jumpscroll) {	if(screen->scroll_amt > 0) {		if(screen->refresh_amt + amount > i)			FlushScroll(screen);		screen->scroll_amt += amount;		screen->refresh_amt += amount;	} else {		if(screen->scroll_amt < 0)			FlushScroll(screen);		screen->scroll_amt = amount;		screen->refresh_amt = amount;	}	refreshheight = 0;    } else {	ScrollSelection(screen, -(amount));	if (amount == i) {		ClearScreen(screen);		return;	}	shift = -screen->topline;	bot = screen->max_row - shift;	scrollheight = i - amount;	refreshheight = amount;	if((refreshtop = screen->bot_marg - refreshheight + 1 + shift) >	 (i = screen->max_row - refreshheight + 1))		refreshtop = i;	if(screen->scrollWidget && !screen->alternate	 && screen->top_marg == 0) {		scrolltop = 0;		if((scrollheight += shift) > i)			scrollheight = i;		if((i = screen->savedlines) < screen->savelines) {			if((i += amount) > screen->savelines)				i = screen->savelines;			screen->savedlines = i;			ScrollBarDrawThumb(screen->scrollWidget);		}	} else {		scrolltop = screen->top_marg + shift;		if((i = screen->bot_marg - bot) > 0) {			scrollheight -= i;			if((i = screen->top_marg + amount - 1 - bot) >= 0) {				refreshtop += i;				refreshheight -= i;			}		}	}	if (screen->multiscroll && amount == 1 &&	    screen->topline == 0 && screen->top_marg == 0 &&	    screen->bot_marg == screen->max_row) {	    if (screen->incopy < 0 && screen->scrolls == 0)		CopyWait(screen);	    screen->scrolls++;	}	scrolling_copy_area(screen, scrolltop+amount, scrollheight, amount);	if(refreshheight > 0) {		XClearArea (		   screen->display,		   TextWindow(screen),		   (int) screen->border + screen->scrollbar,		   (int) refreshtop * FontHeight(screen) + screen->border,		   (unsigned) Width(screen),		   (unsigned) refreshheight * FontHeight(screen),		   FALSE);		if(refreshheight > shift)			refreshheight = shift;	}    }	if(screen->scrollWidget && !screen->alternate && screen->top_marg == 0)		ScrnDeleteLine(screen->allbuf, screen->bot_marg +		 screen->savelines, 0, amount, screen->max_col + 1);	else		ScrnDeleteLine(screen->buf, screen->bot_marg, screen->top_marg,		 amount, screen->max_col + 1);	if(refreshheight > 0)		ScrnRefresh(screen, refreshtop, 0, refreshheight,		 screen->max_col + 1, False);}/* * Reverse scrolls the screen by amount lines, erases top, doesn't alter * cursor position (i.e. cursor moves up amount relative to text). * All done within the scrolling region, of course. * Requires: amount > 0 */RevScroll(screen, amount)register TScreen *screen;register int amount;{	register int i = screen->bot_marg - screen->top_marg + 1;	register int shift;	register int bot;	register int refreshtop;	register int refreshheight;	register int scrolltop;	register int scrollheight;	if(screen->cursor_state)		HideCursor();	if (amount > i)		amount = i;    if(screen->jumpscroll) {	if(screen->scroll_amt < 0) {		if(-screen->refresh_amt + amount > i)			FlushScroll(screen);		screen->scroll_amt -= amount;		screen->refresh_amt -= amount;	} else {		if(screen->scroll_amt > 0)			FlushScroll(screen);		screen->scroll_amt = -amount;		screen->refresh_amt = -amount;	}    } else {	shift = -screen->topline;	bot = screen->max_row - shift;	refreshheight = amount;	scrollheight = screen->bot_marg - screen->top_marg -	 refreshheight + 1;	refreshtop = screen->top_marg + shift;	scrolltop = refreshtop + refreshheight;	if((i = screen->bot_marg - bot) > 0)		scrollheight -= i;	if((i = screen->top_marg + refreshheight - 1 - bot) > 0)		refreshheight -= i;	if (screen->multiscroll && amount == 1 &&	    screen->topline == 0 && screen->top_marg == 0 &&	    screen->bot_marg == screen->max_row) {	    if (screen->incopy < 0 && screen->scrolls == 0)		CopyWait(screen);	    screen->scrolls++;	}	scrolling_copy_area(screen, scrolltop-amount, scrollheight, -amount);	if(refreshheight > 0)		XClearArea (		    screen->display,		    TextWindow(screen),		    (int) screen->border + screen->scrollbar,		    (int) refreshtop * FontHeight(screen) + screen->border,		    (unsigned) Width(screen),		    (unsigned) refreshheight * FontHeight(screen),		    FALSE);    }	ScrnInsertLine (screen->buf, screen->bot_marg, screen->top_marg,			amount, screen->max_col + 1);}/* * If cursor not in scrolling region, returns.  Else, * inserts n blank lines at the cursor's position.  Lines above the * bottom margin are lost. */InsertLine (screen, n)register TScreen *screen;register int n;{	register int i;	register int shift;	register int bot;	register int refreshtop;	register int refreshheight;	register int scrolltop;	register int scrollheight;	if (screen->cur_row < screen->top_marg ||	 screen->cur_row > screen->bot_marg)		return;	if(screen->cursor_state)		HideCursor();	screen->do_wrap = 0;	if (n > (i = screen->bot_marg - screen->cur_row + 1))		n = i;    if(screen->jumpscroll) {	if(screen->scroll_amt <= 0 &&	 screen->cur_row <= -screen->refresh_amt) {		if(-screen->refresh_amt + n > screen->max_row + 1)			FlushScroll(screen);		screen->scroll_amt -= n;		screen->refresh_amt -= n;	} else if(screen->scroll_amt)		FlushScroll(screen);    }    if(!screen->scroll_amt) {	shift = -screen->topline;	bot = screen->max_row - shift;	refreshheight = n;	scrollheight = screen->bot_marg - screen->cur_row - refreshheight + 1;	refreshtop = screen->cur_row + shift;	scrolltop = refreshtop + refreshheight;	if((i = screen->bot_marg - bot) > 0)		scrollheight -= i;	if((i = screen->cur_row + refreshheight - 1 - bot) > 0)		refreshheight -= i;	vertical_copy_area(screen, scrolltop-n, scrollheight, -n);	if(refreshheight > 0)		XClearArea (		    screen->display,		    TextWindow(screen),		    (int) screen->border + screen->scrollbar,		    (int) refreshtop * FontHeight(screen) + screen->border,		    (unsigned) Width(screen),

⌨️ 快捷键说明

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