home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / s / s001 / 1.ddi / PFC / SRC / WNDACTV.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-29  |  16.7 KB  |  649 lines

  1. /* 20-Sep-1988 Jahns    SET_MOUSE_WND() deleted             */
  2.  
  3.  
  4. /* (c) 1985, Phoenix Computer Products Corp. and Novum Organum, Inc. */
  5. /***
  6. * (C) Novum Organum, Inc. 1985
  7. *
  8. * THIS MODULE CONTAINS FUNCTIONS WHICH OPERATE ON THE ACTIVE WINDOW.
  9. * FUNCTIONS CONTAINED ARE:
  10. *
  11. *   wndsetactv( wnd )       /+ set a new active window              +/
  12. *   wndgetactv()            /+ return active window's handle        +/
  13. *
  14. *   _wacpok( row, col )     /+ cursor on a visible window position? +/
  15. *   _wagetloc(&row,&col)    /+ retrieve current cursor location     +/
  16. *   _wakbmov( key )         /+ move window with keystrokes          +/
  17. *   _waloc()                /+ update the hardware cursor position  +/
  18. *   _wamset()               /+ refresh the bit map                  +/
  19. *   _wamupd( avl )          /+ mark changes in the bit map          +/
  20. *   _wasetloc(row,col)      /+ set current cursor position          +/
  21. *   _waupd()                /+ redraws the active window            +/
  22. *   _waupdbdr()             /+ redraws the active window's border   +/
  23. *   _wavpoff(&row,&col)     /+ get offset to physical window        +/
  24. *   _wawrite(...)           /+ update information in window         +/
  25. *
  26. ***/
  27.  
  28.  
  29. #include "cptpdf.h"
  30. #include "psys.h"
  31.  
  32. #define _H_ACT    ((struct _WND *)_h_act)
  33.  
  34. #define PROWOFF ( _H_ACT->prow - _H_ACT->vrow )
  35. #define PCOLOFF ( _H_ACT->pcol - _H_ACT->vcol )
  36.  
  37. static  HDL    _h_act;       /* active window -- the one written to */
  38.  
  39.  
  40. /***
  41. * Name:         _wa3cbuf -- create a border buffer
  42. *
  43. * Synopsis:    void    _wa3cbuf();
  44. *               int     *bf;
  45. *               char    *str3c[3];
  46. *               int     ninside, attr;
  47. *        int    bf[160];
  48.  
  49. *        _wa3cbuf( str3c, ninside, attr, bf );
  50. *
  51. * Description:  Creates a border buffer.
  52. *
  53. * Returns:      a pointer to the buffer
  54. *
  55. * (C) Novum Organum, Inc. 1985
  56. *
  57. ***/
  58.  
  59. static void _wa3cbuf( char *str3c, int ninside, int attr, int *buf )
  60. {
  61.  
  62.     buf[0] = MAKEWORD( attr, str3c[0] );
  63.     mempw( &buf[1], MAKEWORD( attr, str3c[1] ), ninside );
  64.     buf[ninside+1] = MAKEWORD( attr, str3c[2] );
  65.  
  66. }
  67.  
  68.  
  69.  
  70. /***
  71. * Name:         wndsetactv -- set the active window
  72. *
  73. * Synopsis:     HDL oldwnd, newwnd, wndsetactv();
  74. *
  75. *               oldwnd = wndsetactv( newwnd );
  76. *
  77. * Description:  sets the active window
  78. *
  79. * Returns:      the formerly active window's handle
  80. *
  81. * (C) Novum Organum, Inc. 1985
  82. *
  83. ***/
  84.  
  85. #define    H_OLDACT    ((WND *)h_oldact)
  86.  
  87.  
  88.  
  89.  
  90.  
  91. int GetWindowColor(void)
  92. {
  93.  
  94.   return(_wndstarted() ? _H_ACT->state : 0);
  95.  
  96. }    /* GetWindowColor */
  97.  
  98.  
  99.  
  100.  
  101. HDL wndsetactv( HDL h_wnd )
  102. {
  103.     HDL    h_oldact;
  104.     HDL wmactv(), wndhbase(), wbactv();
  105.     int state;
  106.  
  107.     h_oldact = _h_act;                      /* save old active handle   */
  108.  
  109.     if  (_wndstarted())
  110.     {
  111.         if  ( !h_wnd )
  112.         h_wnd = wndhbase();
  113.  
  114.     adtverify( (HDL)&H_WND->adt, ADT_WND );
  115.  
  116.     _h_act = h_wnd;                      /* make it active           */
  117.     wbactv( _H_ACT->hwb );                /* make its buffer active   */
  118.     wmactv( _H_ACT->hwm );                /* make its map active      */
  119.     _waloc();                           /* locate the cursor        */
  120.     state = vstsetcur( _H_ACT->state );    /* set active state         */
  121.  
  122. #ifdef old
  123.     if  ( h_oldact )
  124.         H_OLDACT->state = state;          /* set final state for old  */
  125. #endif
  126.  
  127.     if  ( h_oldact == wndhbase() )
  128.         h_oldact = NULLHDL;
  129.  
  130.     }
  131.     return  ( h_oldact );            /* return old handle        */
  132. }
  133.  
  134.  
  135. /***
  136. * Name:         wndgetactv -- return the active window's handle
  137. *
  138. * Synopsis:     HDL h_wnd, wndgetactv();
  139. *
  140. *               h_wnd = wndgetactv();
  141. *
  142. * Description:  returns the active window's handle
  143. *
  144. * Returns:      the active window's handle
  145. *
  146. * (C) Novum Organum, Inc. 1985
  147. *
  148. ***/
  149.  
  150. HDL wndgetactv(void)
  151. {
  152.     HDL wndhbase();
  153.     return  ( _h_act==wndhbase() ? NULLHDL : _h_act );
  154. }
  155.  
  156.  
  157. /***
  158. * Name:         _wacpok -- is cursor visible?
  159. *
  160. * Synopsis:     int row, col, rc, _wacpok();
  161. *
  162. *               rc = _wacpok( row, col );
  163. *
  164. * Description:  returns YES if cursor is visible
  165. *
  166. * (C) Novum Organum, Inc. 1985
  167. *
  168. ***/
  169.  
  170. static    int _wacpok( int row, int col )
  171. {
  172.     int rc = NO;
  173.     if  ( wmtest(row,col) )
  174.         {
  175.         row -= _H_ACT->prow;
  176.         col -= _H_ACT->pcol;
  177.         if  (  (row >= 0 && row < _H_ACT->pnrows)
  178.             && (col >= 0 && col < _H_ACT->pncols)
  179.             )
  180.             rc = YES;
  181.         }
  182.     return  ( rc );
  183. }
  184.  
  185.  
  186. /***
  187. * Name:         _wagetloc -- get the cursor location
  188. *
  189. * Synopsis:     void    _wagetloc();
  190. *               int     row, col;
  191. *
  192. *               _wagetloc(&row,&col);
  193. *
  194. * Description:  Retrieves the active window's cursor position.
  195. *
  196. * Returns:      nothing
  197. *
  198. * (C) Novum Organum, Inc. 1985
  199. *
  200. ***/
  201.  
  202. /*VOID*/_wagetloc( int *prow, int *pcol )
  203. {
  204.     *prow = _H_ACT->crow;
  205.     *pcol = _H_ACT->ccol;
  206. }
  207.  
  208.  
  209. #ifdef use
  210.  
  211. /***
  212. * Name:         _wakbmov -- interpret keystrokes and move window
  213. *
  214. * Synopsis:     int rc, key, _wakbmov();
  215. *               rc = _wakbmov( key )
  216. *
  217. * Description:  Scans vector for keystroke.  If found, keystroke is
  218. *               eaten and window is moved appropriately.  If not, the
  219. *               keystroke is echoed for use by kbnec().
  220. *
  221. * Returns:      The keystroke, or 0.
  222. *
  223. * (C) Novum Organum, Inc. 1985
  224. *
  225. ***/
  226.  
  227. int _wakbmov( key )
  228.     int key;
  229. {
  230.     int indx, *pvct, *_wndgkbv(), nnn;
  231.     static  int _mult = 1;
  232.  
  233.     if  ( kbshift() & KBS_SCROLLLOCK )
  234.         key |= 0x8000;
  235.  
  236.     pvct = _wndgkbv();
  237.     if  ( !pvct )
  238.         goto end;
  239.  
  240.     indx = -1;
  241.     while   ( ++indx < W_KBVCTLEN )
  242.         if  ( key == *pvct++ )
  243.             {
  244.             key = 0;
  245.             break;
  246.             }
  247.  
  248.     if  ( indx < 12 )    /* move 1 row or col */
  249.         wndmove(TIMES2(indx>>2)+1, _mult*((indx%4-1)%2), _mult*((2-indx%4)%2) );
  250.     else 
  251.     if ( indx < 16 )    /* move to corner */
  252.         wndmove( W_POSABS, indx&1 ? _wndsnr()-_H_ACT->pnrows : 0,
  253.                                 indx&2 ? _wndsnc()-_H_ACT->pncols : 0);
  254.     else 
  255.     if ( indx < 20 )    /* move to corner */
  256.         wndmove( W_BUFABS, indx&1 ? wbnrows()-_H_ACT->pnrows : 0 ,
  257.                                 indx&2 ? wbncols()-_H_ACT->pncols : 0 );
  258.     else
  259.     if ( indx == 20 )   /* expand to right edge */
  260.     {
  261.     nnn = _wndsnc() - _H_ACT->rncols + _H_ACT->rcol - _H_ACT->pcol;
  262.         wndmove( W_SIZABS, _H_ACT->pnrows, nnn);
  263.     }
  264.     else 
  265.     if ( indx == 21 )   /* expand to bottom edge */              
  266.     {
  267.     nnn = _wndsnr() - _H_ACT->rnrows + _H_ACT->rrow - _H_ACT->prow;
  268.         wndmove( W_SIZABS, nnn, _H_ACT->pncols );
  269.     }
  270.     else 
  271.     if ( indx == 22 )
  272.         _mult = _mult==1 ? 5 : 1;
  273. end:
  274.     return  ( key&0x7FFF );
  275. }
  276.  
  277. #endif
  278.  
  279.  
  280. /***
  281. * Name:         _waloc -- move the cursor
  282. *
  283. * Synopsis:     void    _waloc();
  284. *               _waloc();
  285. *
  286. * Description:  Updates the active window's cursor position.
  287. *
  288. * Returns:      nothing
  289. *
  290. * (C) Novum Organum, Inc. 1985
  291. *
  292. ***/
  293.  
  294. /*VOID*/_waloc(void)
  295. {
  296.     int row, col, drow, dcol, ok;
  297.     int test;
  298.  
  299.     if  ( wndgetupd() && wndgetcsrupd() )      /* if updates are enabled  */
  300.         {
  301.         row = _H_ACT->crow + PROWOFF;
  302.         col = _H_ACT->ccol + PCOLOFF;
  303.         ok = _wacpok(row,col);
  304.         if  ( !ok && (_H_ACT->flags&W_CSRONSCR) )
  305.             {
  306.             drow = dcol = 0;
  307.  
  308.             test = _H_ACT->crow - _H_ACT->vrow - _H_ACT->pnrows;
  309.             if  ( test >= 0 )
  310.                 {
  311.                 drow = _H_ACT->pnrows>>1;
  312.                 if ( drow < test )
  313.                    drow = test;
  314.                 }
  315.             test += _H_ACT->pnrows;
  316.             if  ( test < 0 )
  317.                 {
  318.                 drow = -(_H_ACT->pnrows>>1);
  319.                 if ( drow > test )
  320.                     drow = test;
  321.                 }
  322.             test = _H_ACT->ccol - _H_ACT->vcol - _H_ACT->pncols;
  323.             if  ( test >= 0 )
  324.                 {
  325.                 dcol = _H_ACT->pncols>>1;
  326.                 if ( dcol < test )
  327.                    dcol = test;
  328.                 }
  329.             test += _H_ACT->pncols;
  330.             if  ( test < 0 )
  331.                 {
  332.                 dcol = -(_H_ACT->pncols>>1);
  333.                 if ( dcol > test )
  334.                     dcol = test;
  335.                 }
  336.  
  337.             if  ( drow | dcol )
  338.                 {
  339.                 wndmove( W_BUFREL, drow, dcol );
  340.                 row = _H_ACT->crow + PROWOFF;
  341.                 col = _H_ACT->ccol + PCOLOFF;
  342.                 ok = _wacpok(row,col);
  343.                 }
  344.             }
  345.  
  346.         if  ( !ok )
  347.             {
  348.             row = _wndsnr();    /* hide the cursor */
  349.             col = 0;
  350.             }
  351.         _wndsloc(row,col);
  352.         }
  353. }
  354.  
  355.  
  356. /***
  357. * Name:         _wamset -- resets the active window's bit map
  358. *
  359. * Synopsis:     void    _wamset();
  360. *               HDL     avl;
  361. *
  362. *               _wamset( avl );
  363. *
  364. * Description:  Takes a bit map showing what character positions on screen
  365. *               are occupied by windows in front of the active window.
  366. *               After checking the windows bounds, resets the active window's
  367. *               bit map to use only unoccupied cells within the window's
  368. *               rectangular bounds.  Resets the input bit map to reserve
  369. *               the cells in use by the active window.
  370. *
  371. * Returns:      nothing
  372. *
  373. * (C) Novum Organum, Inc. 1985
  374. *
  375. ***/
  376.  
  377. void _wamset(void)
  378. {
  379.     wmmask( _H_ACT->prow-_H_ACT->rrow, _H_ACT->pcol-_H_ACT->rcol,
  380.                 _H_ACT->pnrows+_H_ACT->rnrows, _H_ACT->pncols+_H_ACT->rncols );
  381. }
  382.  
  383.  
  384. /***
  385. * Name:         _wamupd -- marks changes in the active window's bit map
  386. *
  387. * Synopsis:     VOID     _wamupd();
  388. *               HDL     avl;
  389. *
  390. *               _wamupd( avl );
  391. *
  392. * Description:  Takes a bit map showing what character positions on screen
  393. *               are occupied by windows in front of the active window.
  394. *               After checking the window's bounds, resets the active window's
  395. *               bit map to leave on only those cells which were off in the
  396. *               old map, but are now on.  Returns a new bit map with all the
  397. *               cells owned by the window on.  This is useful in updating a
  398. *               window as a consequence of window system reorganization, for
  399. *               example, pulling a window to the front with wndtotop().  One
  400. *               updates with the difference map, and then plugs in the new map.
  401. *
  402. * Returns:      nothing
  403. *
  404. * (C) Novum Organum, Inc. 1985
  405. *
  406. ***/
  407.  
  408. void _wamupd(void)
  409. {
  410.     wmupd( _H_ACT->prow-_H_ACT->rrow, _H_ACT->pcol-_H_ACT->rcol,
  411.                 _H_ACT->pnrows+_H_ACT->rnrows, _H_ACT->pncols+_H_ACT->rncols );
  412. }
  413.  
  414.  
  415. /***
  416. * Name:         _wasetloc -- set the cursor position
  417. *
  418. * Synopsis:     void    _wasegloc();
  419. *               int     row, col;
  420. *
  421. *               _wasetloc(row,col);
  422. *
  423. * Description:  Sets the active window's cursor position.
  424. *
  425. * Returns:      nothing
  426. *
  427. * (C) Novum Organum, Inc. 1985
  428. *
  429. ***/
  430.  
  431. /*VOID*/_wasetloc(int row, int col )
  432. {
  433.     _H_ACT->crow = row;
  434.     _H_ACT->ccol = col;
  435. }
  436.  
  437.  
  438.  
  439. /***
  440. * Name:         _waupd -- redraws the active window
  441. *
  442. * Synopsis:     void    _waupd();
  443. *
  444. *               _waupd();
  445. *
  446. * Description:  If updates are not disabled, it redraws the entire active
  447. *               window.
  448. *
  449. * Returns:      nothing
  450. *
  451. * (C) Novum Organum, Inc. 1985
  452. *
  453. ***/
  454.  
  455. /*VOID*/_waupd(void)
  456. {
  457.     int *wbgetlin(), *wmpos();
  458.     int vrow, vcol, prow, pcol, nrows, ncols, wmoff, *bf, *wm;
  459.  
  460.     if  ( wndgetupd() )             /* if updates are enabled       */
  461.         {
  462.         vrow  = _H_ACT->vrow;         /* get the window's dimensions  */
  463.         vcol  = _H_ACT->vcol;
  464.         prow = _H_ACT->prow;
  465.         pcol = _H_ACT->pcol;
  466.         nrows = _H_ACT->pnrows;
  467.         ncols = _H_ACT->pncols;
  468.  
  469.         while   ( nrows-- > 0 )     /* for each physical row        */
  470.             {
  471.             bf = wbgetlin( vrow++ ) + vcol;        /* get the row   */
  472.             wm = wmpos( prow, pcol, &wmoff );      /* get the map   */
  473.             _wnddsp(bf,prow++,pcol,ncols,wm,wmoff);/* display row   */
  474.             }
  475.         }
  476. }
  477.  
  478. /***
  479. * Name:         _waupdbdr -- paint the border
  480. *
  481. * Synopsis:     void    _waupdbdr();
  482. *
  483. *               _waupdbdr();
  484. *
  485. * Description:  Paints the box around the window.
  486. *
  487. * Returns:      nothing
  488. *
  489. * (C) Novum Organum, Inc. 1985
  490. *
  491. ***/
  492.  
  493. /*VOID*/_waupdbdr(void)
  494. {
  495.     HDL wmactv();
  496.     int row, col, nrows, ncols;
  497.     int attr;
  498.     int oldstate, wmoff;
  499.     int *wm, *wmpos();
  500.     int buf[160];
  501.     char *boxs;
  502.  
  503.     if  ( !(_H_ACT->flags&W_ISBORDERD) ||  !wndgetupd() ) 
  504.         goto end;
  505.  
  506.     wmborder( _H_ACT->prow, _H_ACT->pcol, _H_ACT->pnrows, _H_ACT->pncols );
  507.  
  508.     oldstate = vstsetcur( _H_ACT->bstate );
  509.     attr = _vdspattr();
  510.     vstsetcur( oldstate );
  511.  
  512.     row   = _H_ACT->prow - _H_ACT->rrow;
  513.     col   = _H_ACT->pcol - _H_ACT->rcol;
  514.     ncols = _H_ACT->pncols + _H_ACT->rncols;
  515.     nrows = _H_ACT->pnrows + _H_ACT->rnrows - 2;
  516.     boxs  = _H_ACT->boxs;
  517.     wm    = wmpos( row, col, &wmoff );
  518.     _wa3cbuf( boxs, ncols-2, attr, buf );
  519.     _wnddsp( buf, row++, col, ncols, wm, wmoff );
  520.     boxs += 3;
  521.     _wa3cbuf( boxs, ncols-2, attr, buf );
  522.     while   (nrows--)
  523.         {
  524.         wm = wmpos( row, col, &wmoff );
  525.     _wnddsp( buf, row++, col, ncols, wm, wmoff );
  526.         }
  527.     boxs += 3;
  528.     _wa3cbuf( boxs, ncols-2, attr, buf );
  529.     wm    = wmpos( row, col, &wmoff );
  530.     _wnddsp( buf, row++, col, ncols, wm, wmoff );
  531.  
  532.     if  ( _H_ACT->flags & W_ISTITLED )
  533.         {
  534.         row = _H_ACT->prow - _H_ACT->rrow + _H_ACT->trow - 1;
  535.         if  ( _H_ACT->trow < 0 )
  536.             row += _H_ACT->pnrows + _H_ACT->rnrows + 1;
  537.  
  538.         if  ( _H_ACT->tjust == STR_LJUST )
  539.             col += 1;
  540.         else 
  541.         if ( _H_ACT->tjust == STR_CENTER )
  542.             col += (ncols - _H_ACT->tlen) >> 1;
  543.         else
  544.             col += ncols - _H_ACT->tlen - 1;
  545.  
  546.         wm = wmpos( row, col, &wmoff );
  547.         memwpb( (char *)_H_ACT->title+1, attr, _H_ACT->tlen );
  548.         _wnddsp(_H_ACT->title, row,col, _H_ACT->tlen, wm, wmoff);
  549.         }
  550.     wmactv(_H_ACT->hwm);
  551. end:
  552.     return;
  553. }
  554.  
  555. /***
  556. * Name:         _wavpoff -- get offset to physical window
  557. *
  558. * Synopsis:     void    _wavpoff();
  559. *               int     row, col;
  560. *
  561. *               _wavpoff( &row, &col );
  562. *
  563. * Description:  Gets offset to physical location from virtual location.
  564. *
  565. * Returns:      nothing
  566. *
  567. * (C) Novum Organum, Inc. 1985
  568. *
  569. ***/
  570.  
  571. /*VOID*/_wavpoff(int *prow, int *pcol )
  572. {
  573.     *prow = PROWOFF;
  574.     *pcol = PCOLOFF;
  575. }
  576.  
  577.  
  578. /***
  579. * Name:         _wawrite -- update characters in window
  580. *
  581. * Synopsis:     void    _wawrite();
  582. *               int     mode, nchars, chr, attr;
  583. *
  584. *               _wawrite( mode, nchars, chr, attr );
  585. *
  586. * Description:  Updates information in the active window.
  587. *
  588. * Returns:      nothing
  589. *
  590. * (C) Novum Organum, Inc. 1985
  591. *
  592. ***/
  593.  
  594. /*VOID*/_wawrite( int mode, int nchars, char *str, int attr )
  595. {
  596.     int nmax, prow, pcol, wmoff;
  597.     int *bf, *wbupd();
  598.     int *wm, *wmpos();
  599.  
  600.     prow = _H_ACT->crow;
  601.     if  ( prow >= 0 && prow < wbnrows() )
  602.         {
  603.         pcol = _H_ACT->ccol;                  /* correct for off-left     */
  604.         if  ( pcol < 0 )
  605.             {
  606.             nchars += pcol;
  607.             pcol = 0;
  608.             }
  609.         nmax = wbncols() - pcol;            /* max number to write      */
  610.         if  ( nchars > nmax )               /* don't write too many     */
  611.             nchars = nmax;
  612.  
  613.         if  ( nchars > 0 )                  /* if there's anything left */
  614.             {                               /* update the buffer        */
  615.             bf = wbupd( mode, prow, pcol, nchars, str, attr );
  616.             if  ( wndgetupd() )             /* if updates are permitted */
  617.                 {
  618.                 prow -= _H_ACT->vrow;
  619.                 if  ( prow >= 0 && prow < _H_ACT->pnrows )
  620.                     {
  621.                     prow += _H_ACT->prow;
  622.  
  623.                     pcol -= _H_ACT->vcol;
  624.                     if  ( pcol < 0 )
  625.                         {
  626.                         nchars += pcol;
  627.                         pcol = 0;
  628.                         }
  629.                     nmax = _H_ACT->pncols - pcol;
  630.                     if  ( nchars > nmax )
  631.                         nchars = nmax;
  632.  
  633.                     if  ( nchars > 0 )
  634.                         {
  635.                         pcol += _H_ACT->pcol;
  636.                                         /* get the bit map buffer   */
  637.                         wm = wmpos( prow, pcol, &wmoff );
  638.                                         /* update the screen        */
  639.                         _wnddsp(bf,prow,pcol,nchars,wm,wmoff );
  640.                         }
  641.                     }
  642.                 }
  643.             }
  644.         }
  645. }
  646.  
  647.  
  648. 
  649.