home *** CD-ROM | disk | FTP | other *** search
- /* 20-Sep-1988 Jahns SET_MOUSE_WND() deleted */
-
-
- /* (c) 1985, Phoenix Computer Products Corp. and Novum Organum, Inc. */
- /***
- * (C) Novum Organum, Inc. 1985
- *
- * THIS MODULE CONTAINS FUNCTIONS WHICH OPERATE ON THE ACTIVE WINDOW.
- * FUNCTIONS CONTAINED ARE:
- *
- * wndsetactv( wnd ) /+ set a new active window +/
- * wndgetactv() /+ return active window's handle +/
- *
- * _wacpok( row, col ) /+ cursor on a visible window position? +/
- * _wagetloc(&row,&col) /+ retrieve current cursor location +/
- * _wakbmov( key ) /+ move window with keystrokes +/
- * _waloc() /+ update the hardware cursor position +/
- * _wamset() /+ refresh the bit map +/
- * _wamupd( avl ) /+ mark changes in the bit map +/
- * _wasetloc(row,col) /+ set current cursor position +/
- * _waupd() /+ redraws the active window +/
- * _waupdbdr() /+ redraws the active window's border +/
- * _wavpoff(&row,&col) /+ get offset to physical window +/
- * _wawrite(...) /+ update information in window +/
- *
- ***/
-
-
- #include "cptpdf.h"
- #include "psys.h"
-
- #define _H_ACT ((struct _WND *)_h_act)
-
- #define PROWOFF ( _H_ACT->prow - _H_ACT->vrow )
- #define PCOLOFF ( _H_ACT->pcol - _H_ACT->vcol )
-
- static HDL _h_act; /* active window -- the one written to */
-
-
- /***
- * Name: _wa3cbuf -- create a border buffer
- *
- * Synopsis: void _wa3cbuf();
- * int *bf;
- * char *str3c[3];
- * int ninside, attr;
- * int bf[160];
-
- * _wa3cbuf( str3c, ninside, attr, bf );
- *
- * Description: Creates a border buffer.
- *
- * Returns: a pointer to the buffer
- *
- * (C) Novum Organum, Inc. 1985
- *
- ***/
-
- static void _wa3cbuf( char *str3c, int ninside, int attr, int *buf )
- {
-
- buf[0] = MAKEWORD( attr, str3c[0] );
- mempw( &buf[1], MAKEWORD( attr, str3c[1] ), ninside );
- buf[ninside+1] = MAKEWORD( attr, str3c[2] );
-
- }
-
-
-
- /***
- * Name: wndsetactv -- set the active window
- *
- * Synopsis: HDL oldwnd, newwnd, wndsetactv();
- *
- * oldwnd = wndsetactv( newwnd );
- *
- * Description: sets the active window
- *
- * Returns: the formerly active window's handle
- *
- * (C) Novum Organum, Inc. 1985
- *
- ***/
-
- #define H_OLDACT ((WND *)h_oldact)
-
-
-
-
-
- int GetWindowColor(void)
- {
-
- return(_wndstarted() ? _H_ACT->state : 0);
-
- } /* GetWindowColor */
-
-
-
-
- HDL wndsetactv( HDL h_wnd )
- {
- HDL h_oldact;
- HDL wmactv(), wndhbase(), wbactv();
- int state;
-
- h_oldact = _h_act; /* save old active handle */
-
- if (_wndstarted())
- {
- if ( !h_wnd )
- h_wnd = wndhbase();
-
- adtverify( (HDL)&H_WND->adt, ADT_WND );
-
- _h_act = h_wnd; /* make it active */
- wbactv( _H_ACT->hwb ); /* make its buffer active */
- wmactv( _H_ACT->hwm ); /* make its map active */
- _waloc(); /* locate the cursor */
- state = vstsetcur( _H_ACT->state ); /* set active state */
-
- #ifdef old
- if ( h_oldact )
- H_OLDACT->state = state; /* set final state for old */
- #endif
-
- if ( h_oldact == wndhbase() )
- h_oldact = NULLHDL;
-
- }
- return ( h_oldact ); /* return old handle */
- }
-
-
- /***
- * Name: wndgetactv -- return the active window's handle
- *
- * Synopsis: HDL h_wnd, wndgetactv();
- *
- * h_wnd = wndgetactv();
- *
- * Description: returns the active window's handle
- *
- * Returns: the active window's handle
- *
- * (C) Novum Organum, Inc. 1985
- *
- ***/
-
- HDL wndgetactv(void)
- {
- HDL wndhbase();
- return ( _h_act==wndhbase() ? NULLHDL : _h_act );
- }
-
-
- /***
- * Name: _wacpok -- is cursor visible?
- *
- * Synopsis: int row, col, rc, _wacpok();
- *
- * rc = _wacpok( row, col );
- *
- * Description: returns YES if cursor is visible
- *
- * (C) Novum Organum, Inc. 1985
- *
- ***/
-
- static int _wacpok( int row, int col )
- {
- int rc = NO;
- if ( wmtest(row,col) )
- {
- row -= _H_ACT->prow;
- col -= _H_ACT->pcol;
- if ( (row >= 0 && row < _H_ACT->pnrows)
- && (col >= 0 && col < _H_ACT->pncols)
- )
- rc = YES;
- }
- return ( rc );
- }
-
-
- /***
- * Name: _wagetloc -- get the cursor location
- *
- * Synopsis: void _wagetloc();
- * int row, col;
- *
- * _wagetloc(&row,&col);
- *
- * Description: Retrieves the active window's cursor position.
- *
- * Returns: nothing
- *
- * (C) Novum Organum, Inc. 1985
- *
- ***/
-
- /*VOID*/_wagetloc( int *prow, int *pcol )
- {
- *prow = _H_ACT->crow;
- *pcol = _H_ACT->ccol;
- }
-
-
- #ifdef use
-
- /***
- * Name: _wakbmov -- interpret keystrokes and move window
- *
- * Synopsis: int rc, key, _wakbmov();
- * rc = _wakbmov( key )
- *
- * Description: Scans vector for keystroke. If found, keystroke is
- * eaten and window is moved appropriately. If not, the
- * keystroke is echoed for use by kbnec().
- *
- * Returns: The keystroke, or 0.
- *
- * (C) Novum Organum, Inc. 1985
- *
- ***/
-
- int _wakbmov( key )
- int key;
- {
- int indx, *pvct, *_wndgkbv(), nnn;
- static int _mult = 1;
-
- if ( kbshift() & KBS_SCROLLLOCK )
- key |= 0x8000;
-
- pvct = _wndgkbv();
- if ( !pvct )
- goto end;
-
- indx = -1;
- while ( ++indx < W_KBVCTLEN )
- if ( key == *pvct++ )
- {
- key = 0;
- break;
- }
-
- if ( indx < 12 ) /* move 1 row or col */
- wndmove(TIMES2(indx>>2)+1, _mult*((indx%4-1)%2), _mult*((2-indx%4)%2) );
- else
- if ( indx < 16 ) /* move to corner */
- wndmove( W_POSABS, indx&1 ? _wndsnr()-_H_ACT->pnrows : 0,
- indx&2 ? _wndsnc()-_H_ACT->pncols : 0);
- else
- if ( indx < 20 ) /* move to corner */
- wndmove( W_BUFABS, indx&1 ? wbnrows()-_H_ACT->pnrows : 0 ,
- indx&2 ? wbncols()-_H_ACT->pncols : 0 );
- else
- if ( indx == 20 ) /* expand to right edge */
- {
- nnn = _wndsnc() - _H_ACT->rncols + _H_ACT->rcol - _H_ACT->pcol;
- wndmove( W_SIZABS, _H_ACT->pnrows, nnn);
- }
- else
- if ( indx == 21 ) /* expand to bottom edge */
- {
- nnn = _wndsnr() - _H_ACT->rnrows + _H_ACT->rrow - _H_ACT->prow;
- wndmove( W_SIZABS, nnn, _H_ACT->pncols );
- }
- else
- if ( indx == 22 )
- _mult = _mult==1 ? 5 : 1;
- end:
- return ( key&0x7FFF );
- }
-
- #endif
-
-
- /***
- * Name: _waloc -- move the cursor
- *
- * Synopsis: void _waloc();
- * _waloc();
- *
- * Description: Updates the active window's cursor position.
- *
- * Returns: nothing
- *
- * (C) Novum Organum, Inc. 1985
- *
- ***/
-
- /*VOID*/_waloc(void)
- {
- int row, col, drow, dcol, ok;
- int test;
-
- if ( wndgetupd() && wndgetcsrupd() ) /* if updates are enabled */
- {
- row = _H_ACT->crow + PROWOFF;
- col = _H_ACT->ccol + PCOLOFF;
- ok = _wacpok(row,col);
- if ( !ok && (_H_ACT->flags&W_CSRONSCR) )
- {
- drow = dcol = 0;
-
- test = _H_ACT->crow - _H_ACT->vrow - _H_ACT->pnrows;
- if ( test >= 0 )
- {
- drow = _H_ACT->pnrows>>1;
- if ( drow < test )
- drow = test;
- }
- test += _H_ACT->pnrows;
- if ( test < 0 )
- {
- drow = -(_H_ACT->pnrows>>1);
- if ( drow > test )
- drow = test;
- }
- test = _H_ACT->ccol - _H_ACT->vcol - _H_ACT->pncols;
- if ( test >= 0 )
- {
- dcol = _H_ACT->pncols>>1;
- if ( dcol < test )
- dcol = test;
- }
- test += _H_ACT->pncols;
- if ( test < 0 )
- {
- dcol = -(_H_ACT->pncols>>1);
- if ( dcol > test )
- dcol = test;
- }
-
- if ( drow | dcol )
- {
- wndmove( W_BUFREL, drow, dcol );
- row = _H_ACT->crow + PROWOFF;
- col = _H_ACT->ccol + PCOLOFF;
- ok = _wacpok(row,col);
- }
- }
-
- if ( !ok )
- {
- row = _wndsnr(); /* hide the cursor */
- col = 0;
- }
- _wndsloc(row,col);
- }
- }
-
-
- /***
- * Name: _wamset -- resets the active window's bit map
- *
- * Synopsis: void _wamset();
- * HDL avl;
- *
- * _wamset( avl );
- *
- * Description: Takes a bit map showing what character positions on screen
- * are occupied by windows in front of the active window.
- * After checking the windows bounds, resets the active window's
- * bit map to use only unoccupied cells within the window's
- * rectangular bounds. Resets the input bit map to reserve
- * the cells in use by the active window.
- *
- * Returns: nothing
- *
- * (C) Novum Organum, Inc. 1985
- *
- ***/
-
- void _wamset(void)
- {
- wmmask( _H_ACT->prow-_H_ACT->rrow, _H_ACT->pcol-_H_ACT->rcol,
- _H_ACT->pnrows+_H_ACT->rnrows, _H_ACT->pncols+_H_ACT->rncols );
- }
-
-
- /***
- * Name: _wamupd -- marks changes in the active window's bit map
- *
- * Synopsis: VOID _wamupd();
- * HDL avl;
- *
- * _wamupd( avl );
- *
- * Description: Takes a bit map showing what character positions on screen
- * are occupied by windows in front of the active window.
- * After checking the window's bounds, resets the active window's
- * bit map to leave on only those cells which were off in the
- * old map, but are now on. Returns a new bit map with all the
- * cells owned by the window on. This is useful in updating a
- * window as a consequence of window system reorganization, for
- * example, pulling a window to the front with wndtotop(). One
- * updates with the difference map, and then plugs in the new map.
- *
- * Returns: nothing
- *
- * (C) Novum Organum, Inc. 1985
- *
- ***/
-
- void _wamupd(void)
- {
- wmupd( _H_ACT->prow-_H_ACT->rrow, _H_ACT->pcol-_H_ACT->rcol,
- _H_ACT->pnrows+_H_ACT->rnrows, _H_ACT->pncols+_H_ACT->rncols );
- }
-
-
- /***
- * Name: _wasetloc -- set the cursor position
- *
- * Synopsis: void _wasegloc();
- * int row, col;
- *
- * _wasetloc(row,col);
- *
- * Description: Sets the active window's cursor position.
- *
- * Returns: nothing
- *
- * (C) Novum Organum, Inc. 1985
- *
- ***/
-
- /*VOID*/_wasetloc(int row, int col )
- {
- _H_ACT->crow = row;
- _H_ACT->ccol = col;
- }
-
-
-
- /***
- * Name: _waupd -- redraws the active window
- *
- * Synopsis: void _waupd();
- *
- * _waupd();
- *
- * Description: If updates are not disabled, it redraws the entire active
- * window.
- *
- * Returns: nothing
- *
- * (C) Novum Organum, Inc. 1985
- *
- ***/
-
- /*VOID*/_waupd(void)
- {
- int *wbgetlin(), *wmpos();
- int vrow, vcol, prow, pcol, nrows, ncols, wmoff, *bf, *wm;
-
- if ( wndgetupd() ) /* if updates are enabled */
- {
- vrow = _H_ACT->vrow; /* get the window's dimensions */
- vcol = _H_ACT->vcol;
- prow = _H_ACT->prow;
- pcol = _H_ACT->pcol;
- nrows = _H_ACT->pnrows;
- ncols = _H_ACT->pncols;
-
- while ( nrows-- > 0 ) /* for each physical row */
- {
- bf = wbgetlin( vrow++ ) + vcol; /* get the row */
- wm = wmpos( prow, pcol, &wmoff ); /* get the map */
- _wnddsp(bf,prow++,pcol,ncols,wm,wmoff);/* display row */
- }
- }
- }
-
- /***
- * Name: _waupdbdr -- paint the border
- *
- * Synopsis: void _waupdbdr();
- *
- * _waupdbdr();
- *
- * Description: Paints the box around the window.
- *
- * Returns: nothing
- *
- * (C) Novum Organum, Inc. 1985
- *
- ***/
-
- /*VOID*/_waupdbdr(void)
- {
- HDL wmactv();
- int row, col, nrows, ncols;
- int attr;
- int oldstate, wmoff;
- int *wm, *wmpos();
- int buf[160];
- char *boxs;
-
- if ( !(_H_ACT->flags&W_ISBORDERD) || !wndgetupd() )
- goto end;
-
- wmborder( _H_ACT->prow, _H_ACT->pcol, _H_ACT->pnrows, _H_ACT->pncols );
-
- oldstate = vstsetcur( _H_ACT->bstate );
- attr = _vdspattr();
- vstsetcur( oldstate );
-
- row = _H_ACT->prow - _H_ACT->rrow;
- col = _H_ACT->pcol - _H_ACT->rcol;
- ncols = _H_ACT->pncols + _H_ACT->rncols;
- nrows = _H_ACT->pnrows + _H_ACT->rnrows - 2;
- boxs = _H_ACT->boxs;
- wm = wmpos( row, col, &wmoff );
- _wa3cbuf( boxs, ncols-2, attr, buf );
- _wnddsp( buf, row++, col, ncols, wm, wmoff );
- boxs += 3;
- _wa3cbuf( boxs, ncols-2, attr, buf );
- while (nrows--)
- {
- wm = wmpos( row, col, &wmoff );
- _wnddsp( buf, row++, col, ncols, wm, wmoff );
- }
- boxs += 3;
- _wa3cbuf( boxs, ncols-2, attr, buf );
- wm = wmpos( row, col, &wmoff );
- _wnddsp( buf, row++, col, ncols, wm, wmoff );
-
- if ( _H_ACT->flags & W_ISTITLED )
- {
- row = _H_ACT->prow - _H_ACT->rrow + _H_ACT->trow - 1;
- if ( _H_ACT->trow < 0 )
- row += _H_ACT->pnrows + _H_ACT->rnrows + 1;
-
- if ( _H_ACT->tjust == STR_LJUST )
- col += 1;
- else
- if ( _H_ACT->tjust == STR_CENTER )
- col += (ncols - _H_ACT->tlen) >> 1;
- else
- col += ncols - _H_ACT->tlen - 1;
-
- wm = wmpos( row, col, &wmoff );
- memwpb( (char *)_H_ACT->title+1, attr, _H_ACT->tlen );
- _wnddsp(_H_ACT->title, row,col, _H_ACT->tlen, wm, wmoff);
- }
- wmactv(_H_ACT->hwm);
- end:
- return;
- }
-
- /***
- * Name: _wavpoff -- get offset to physical window
- *
- * Synopsis: void _wavpoff();
- * int row, col;
- *
- * _wavpoff( &row, &col );
- *
- * Description: Gets offset to physical location from virtual location.
- *
- * Returns: nothing
- *
- * (C) Novum Organum, Inc. 1985
- *
- ***/
-
- /*VOID*/_wavpoff(int *prow, int *pcol )
- {
- *prow = PROWOFF;
- *pcol = PCOLOFF;
- }
-
-
- /***
- * Name: _wawrite -- update characters in window
- *
- * Synopsis: void _wawrite();
- * int mode, nchars, chr, attr;
- *
- * _wawrite( mode, nchars, chr, attr );
- *
- * Description: Updates information in the active window.
- *
- * Returns: nothing
- *
- * (C) Novum Organum, Inc. 1985
- *
- ***/
-
- /*VOID*/_wawrite( int mode, int nchars, char *str, int attr )
- {
- int nmax, prow, pcol, wmoff;
- int *bf, *wbupd();
- int *wm, *wmpos();
-
- prow = _H_ACT->crow;
- if ( prow >= 0 && prow < wbnrows() )
- {
- pcol = _H_ACT->ccol; /* correct for off-left */
- if ( pcol < 0 )
- {
- nchars += pcol;
- pcol = 0;
- }
- nmax = wbncols() - pcol; /* max number to write */
- if ( nchars > nmax ) /* don't write too many */
- nchars = nmax;
-
- if ( nchars > 0 ) /* if there's anything left */
- { /* update the buffer */
- bf = wbupd( mode, prow, pcol, nchars, str, attr );
- if ( wndgetupd() ) /* if updates are permitted */
- {
- prow -= _H_ACT->vrow;
- if ( prow >= 0 && prow < _H_ACT->pnrows )
- {
- prow += _H_ACT->prow;
-
- pcol -= _H_ACT->vcol;
- if ( pcol < 0 )
- {
- nchars += pcol;
- pcol = 0;
- }
- nmax = _H_ACT->pncols - pcol;
- if ( nchars > nmax )
- nchars = nmax;
-
- if ( nchars > 0 )
- {
- pcol += _H_ACT->pcol;
- /* get the bit map buffer */
- wm = wmpos( prow, pcol, &wmoff );
- /* update the screen */
- _wnddsp(bf,prow,pcol,nchars,wm,wmoff );
- }
- }
- }
- }
- }
- }
-
-
-