home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 1.ddi / CLIBSRC.ZIP / CONSTREA.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.3 KB  |  173 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - constrea.cpp
  3.  *-----------------------------------------------------------------------*/
  4.  
  5. /*
  6.  *      C/C++ Run Time Library - Version 5.0
  7.  *
  8.  *      Copyright (c) 1991, 1992 by Borland International
  9.  *      All Rights Reserved.
  10.  *
  11.  */
  12.  
  13.  
  14. #if !defined( __CONSTREA_H )
  15. #include "constrea.h"
  16. #endif  // __CONSTREA_H
  17.  
  18. #if !defined( __IOSTREAM_H )
  19. #include <iostream.h>
  20. #endif  // __IOSTREAM_H
  21.  
  22. conbuf *conbuf::current = 0;
  23. long constream::isCon_ = 0L;
  24.  
  25. conbuf::conbuf()
  26. {
  27.     ::gettextinfo( &data );
  28.     cursortype = _NORMALCURSOR;
  29. }
  30.  
  31. int conbuf::overflow( int c )
  32. {
  33.     activate();
  34.     if( c == '\n' )
  35.         putch( '\r' );
  36.     return putch( c );
  37. }
  38.  
  39. void conbuf::makeActive()
  40. {
  41.     ::window( data.winleft, data.wintop, data.winright, data.winbottom );
  42.     ::textattr( data.attribute );
  43.     ::gotoxy( data.curx, data.cury );
  44.     ::_setcursortype( cursortype );
  45. }
  46.  
  47. void conbuf::makeInactive()
  48. {
  49.     ::gettextinfo( &data );
  50. }
  51.  
  52. void conbuf::swap()
  53. {
  54.     if( current != 0 )
  55.         current->deactivate();
  56.     makeActive();
  57.     current = this;
  58. }
  59.  
  60. constream::constream() : ostream( &buf )
  61. {
  62.     cin.tie( this );
  63.     setf( ios::unitbuf );
  64.     if( !isCon_ )
  65.         isCon_ = bitalloc();
  66.     setf( isCon_ );
  67. }
  68.  
  69. ostream& _Cdecl clreol( ostream& o )
  70. {
  71.     if( constream::isCon( o ) )
  72.         ((constream&)o).rdbuf()->clreol();
  73.     return o;
  74. }
  75.  
  76. ostream& _Cdecl highvideo( ostream& o )
  77. {
  78.     if( constream::isCon( o ) )
  79.         ((constream&)o).rdbuf()->highvideo();
  80.     return o;
  81. }
  82.  
  83. ostream& _Cdecl lowvideo( ostream& o )
  84. {
  85.     if( constream::isCon( o ) )
  86.         ((constream&)o).rdbuf()->lowvideo();
  87.     return o;
  88. }
  89.  
  90. ostream& _Cdecl normvideo( ostream& o )
  91. {
  92.     if( constream::isCon( o ) )
  93.         ((constream&)o).rdbuf()->normvideo();
  94.     return o;
  95. }
  96.  
  97. ostream& _Cdecl delline( ostream& o )
  98. {
  99.     if( constream::isCon( o ) )
  100.         ((constream&)o).rdbuf()->delline();
  101.     return o;
  102. }
  103.  
  104. ostream& _Cdecl insline( ostream& o )
  105. {
  106.     if( constream::isCon( o ) )
  107.         ((constream&)o).rdbuf()->insline();
  108.     return o;
  109. }
  110.  
  111. static ostream& scrsr( ostream& o, int c )
  112. {
  113.     if( constream::isCon( o ) )
  114.         ((constream&)o).rdbuf()->setcursortype( c );
  115.     return o;
  116. }
  117.  
  118. omanip_int cdecl setcrsrtype( int c )
  119. {
  120.     return omanip_int( scrsr, c );
  121. }
  122.  
  123.  
  124. static ostream& sattr( ostream& o, int a )
  125. {
  126.     if( constream::isCon( o ) )
  127.         ((constream&)o).rdbuf()->textattr( a );
  128.     return o;
  129. }
  130.  
  131. omanip_int cdecl setattr( int a )
  132. {
  133.     return omanip_int( sattr, a );
  134. }
  135.  
  136. static ostream& sxy( ostream& o, int x, int y )
  137. {
  138.     if( constream::isCon( o ) )
  139.         ((constream&)o).rdbuf()->gotoxy( x, y );
  140.     return o;
  141. }
  142.  
  143. omanip_int_int cdecl setxy( int a, int b )
  144. {
  145.     return omanip_int_int( sxy, a, b );
  146. }
  147.  
  148. static ostream& sbk( ostream& o, int a )
  149. {
  150.     if( constream::isCon( o ) )
  151.         ((constream&)o).rdbuf()->textbackground( a );
  152.     return o;
  153. }
  154.  
  155. omanip_int cdecl setbk( int a )
  156. {
  157.     return omanip_int( sbk, a );
  158. }
  159.  
  160. static ostream& sclr( ostream& o, int a )
  161. {
  162.     if( constream::isCon( o ) )
  163.         ((constream&)o).rdbuf()->textcolor( a );
  164.     return o;
  165. }
  166.  
  167. omanip_int cdecl setclr( int a )
  168. {
  169.     return omanip_int( sclr, a );
  170. }
  171.  
  172.  
  173.