📄 wactiv.c
字号:
/* CXL - Copyright (c) 1987-1989 by Mike Smedley - All Rights Reserved */
/* WACTIV.C - activates a window */
#include <conio.h>
#include <dos.h>
#include "cxldef.h"
#include "cxlvid.h"
#include "cxlwin.h"
static int bshadow_blocking(void);
static short int *calc_bshadow(struct _wrec_t *wrec);
static short int *calc_rshadow(struct _wrec_t *wrec);
static short int *calc_window(struct _wrec_t *wrec);
static int rshadow_blocking(void);
static void swap_contents(short int *pfound,short int *pcurr,int shadow);
static int window_blocking(void);
static struct _wrec_t *curr,*found;
static int crow,ccol;
int wactiv(WINDOW whandle)
{
register int startcol,stopcol;
struct _wrec_t *prev,*next;
/* check for active window */
if(!_winfo.total) return(_winfo.errno=W_NOACTIVE);
/* if window is already active, ignore request */
if(whandle==_winfo.active->whandle) return(_winfo.errno=W_NOERROR);
/* find address of window's record */
found=wfindrec(whandle);
if(found==NULL) return(_winfo.errno=W_NOTFOUND);
/* check every character position in window to activate */
for(crow=found->srow;crow<=found->erow;crow++) {
for(ccol=found->scol;ccol<=found->ecol;ccol++) {
/* check all window records "above" window to activate */
for(curr=found->next;curr!=NULL;curr=curr->next) {
/* see if current position in window to activate */
/* is blocked by same position in test window */
if(window_blocking()) {
/* calculate buffer addresses and swap contents */
swap_contents(calc_window(found),calc_window(curr),0);
break;
}
/* see if test window has a shadow */
if(curr->wsbuf!=NULL) {
/* see if shadow to the right of test window is */
/* blocking the current position of window to activate */
if(rshadow_blocking()) {
swap_contents(calc_window(found),calc_rshadow(curr),1);
break;
}
/* see if shadow to the bottom of test window is */
/* blocking the current position of window to activate */
if(bshadow_blocking()) {
swap_contents(calc_window(found),calc_bshadow(curr),1);
break;
}
}
}
}
}
/* if window to activate has a shadow, then check */
/* every character position in the shadow to see */
/* if it is blocked by another window or window shadow */
if(found->wsbuf!=NULL) {
/* search the right shadow of window to activiate */
startcol=found->ecol+1;
stopcol=startcol+1;
for(crow=found->srow+1;crow<=found->erow;crow++) {
for(ccol=startcol;ccol<=stopcol;ccol++) {
/* check all window records "above" shadow to activate */
for(curr=found->next;curr!=NULL;curr=curr->next) {
/* see if current position in shadow to activate */
/* is blocked by same position in current window */
if(window_blocking()) {
/* calculate buffer addresses and swap contents */
swap_contents(calc_rshadow(found),calc_window(curr),2);
break;
}
/* see if test window has a shadow */
if(curr->wsbuf!=NULL) {
/* see if current position of window to activate is */
/* blocked by the right shadow of the test window */
if(rshadow_blocking()) {
swap_contents(calc_rshadow(found),
calc_rshadow(curr),3);
break;
}
/* see if current position of window to activate is */
/* blocked by the bottom shadow of the test window */
if(bshadow_blocking()) {
swap_contents(calc_rshadow(found),
calc_bshadow(curr),3);
break;
}
}
}
}
}
/* search bottom shadow */
startcol=found->scol+2;
stopcol=found->ecol+2;
crow=found->erow+1;
for(ccol=startcol;ccol<=stopcol;ccol++) {
/* check all window records "above" shadow to activate */
for(curr=found->next;curr!=NULL;curr=curr->next) {
/* see if current position in shadow to activate */
/* is blocked by same position in test window */
if(window_blocking()) {
/* calculate buffer addresses and swap contents */
swap_contents(calc_bshadow(found),calc_window(curr),2);
break;
}
/* see if test window has a shadow */
if(curr->wsbuf!=NULL) {
if(rshadow_blocking()) {
swap_contents(calc_bshadow(found),calc_rshadow(curr),
3);
break;
}
if(bshadow_blocking()) {
swap_contents(calc_bshadow(found),calc_bshadow(curr),
3);
break;
}
}
}
}
}
/* re-link pointer to window record to be activated */
prev=found->prev;
next=found->next;
if(prev!=NULL) prev->next=next;
next->prev=prev;
_winfo.active->next=found;
found->prev=_winfo.active;
found->next=NULL;
_winfo.active=found;
/* update help category */
if(_winfo.active->help) _winfo.help=_winfo.active->help;
/* reset cursor position */
gotoxy_(_winfo.active->row,_winfo.active->column);
/* return normally */
return(_winfo.errno=W_NOERROR);
}
/*---------------------------------------------------------------------------*/
/* this function detects if a given window's bottom shadow is blocking */
/* the current window or its shadow at specified coordinates */
static int bshadow_blocking(void)
{
register int isblocking=NO;
if(crow==(curr->erow+1))
if((ccol>=(curr->scol+2))&&(ccol<=(curr->ecol+2)))
isblocking=YES;
return(isblocking);
}
/*---------------------------------------------------------------------------*/
static short int *calc_bshadow(struct _wrec_t *wrec)
{
return(wrec->wsbuf+((((crow-wrec->srow-1)*2)+(ccol-wrec->scol-2))));
}
/*---------------------------------------------------------------------------*/
static short int *calc_rshadow(struct _wrec_t *wrec)
{
return(wrec->wsbuf+((((crow-wrec->srow-1)*2)+(ccol-wrec->ecol-1))));
}
/*---------------------------------------------------------------------------*/
static short int *calc_window(struct _wrec_t *wrec)
{
return(wrec->wbuf+4+((crow-wrec->srow)*(wrec->ecol-wrec->scol+1))+
(ccol-wrec->scol));
}
/*---------------------------------------------------------------------------*/
/* this function detects if a given window's right shadow is blocking */
/* the current window or its shadow at specified coordinates */
static int rshadow_blocking(void)
{
register int isblocking=NO;
if(ccol==(curr->ecol+1)||ccol==(curr->ecol+2))
if((crow>=(curr->srow+1))&&(crow<=curr->erow))
isblocking=YES;
return(isblocking);
}
/*---------------------------------------------------------------------------*/
/* this function will exchange the contents of the applicable buffers */
static void swap_contents(short int *pfound,short int *pcurr,int shadow)
{
register struct _wrec_t *wptr;
register int temp;
USHORT chat,attr;
FARPTR pscreen;
/* display character from current position in window to */
/* activate on the screen. if character is part of a */
/* shadow, reflect the character on the screen. */
#ifdef COMMENT_OUT
gotoxy_(crow,ccol);
temp=readchat();
if(shadow&2) *pcurr=(*pcurr&0xff00)|(temp&0x00ff);
attr=*pcurr>>8;
attr=((temp&0x8000&&shadow)?(attr|BLINK):attr);
putchat(*pcurr,attr);
#else
FP_SET(pscreen, (crow*_vinfo.numcols+ccol)*2, SS_SCREEN);
temp = PeekFarWord(pscreen);
if(shadow&2) *pcurr=(*pcurr&0xff00)|(temp&0x00ff);
chat=((temp&0x8000&&shadow)?(*pcurr|0x8000):*pcurr);
PokeFarWord(pscreen, chat);
#endif
/* let window position directly above position */
/* to activate have the character that it holds */
*pcurr=*pfound;
/* if current character position to activate will */
/* activate over a shadow in another window */
if(shadow&1) {
/* resolve all shadows upwards */
wptr=curr;
chat=(curr->wsattr<<8)|(*pfound&0x00ff);
for(curr=curr->next;curr!=NULL;curr=curr->next) {
if(window_blocking()) {
*(calc_window(curr))=chat;
chat=temp;
break;
}
else {
if(bshadow_blocking())
*(calc_bshadow(curr))=chat;
else
if(rshadow_blocking())
*(calc_rshadow(curr))=chat;
}
}
temp=chat;
curr=wptr;
}
/* let character position activated hold character */
/* that was on the screen in the same position */
*pfound=temp;
}
/*---------------------------------------------------------------------------*/
/* this function dectects if given window is blocking the */
/* current window or its shadow at specified coordinates */
static int window_blocking(void)
{
register int isblocking=NO;
if(crow>=curr->srow&&crow<=curr->erow&&ccol>=curr->scol&&ccol<=curr->ecol)
isblocking=YES;
return(isblocking);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -