home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 25 / IOPROG_25.ISO / SOFT / TCSBROWS.ZIP / TCBFUNCS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-31  |  8.3 KB  |  288 lines

  1. /*    Last revision: March 31, 1995 at 11:38  */
  2.  
  3. /***************************************************************
  4.  
  5. This file contains the special C routines used TCBrowse Class
  6.  
  7. The original idea of using the excess bottom space in the header is
  8. by Selim Anter of Istanbul, Turkey. He if the father of the DrawCell
  9. routine. I added aTCBrwPosR function, and renamed em all so that there
  10. should be no interference with similar routines use by TWBrowse.
  11.  
  12. Harry Van Tassell
  13.  
  14. ***************************************************************/
  15.  
  16.  
  17.  
  18. #include <d:\5Win\include\WinTen.h>
  19. #include <d:\5win\include\Windows.h>
  20. #include <d:\5Win\include\ClipApi.h>
  21.  
  22. extern void WndDrawBox( HDC, LPRECT, HPEN, HPEN );
  23. extern void DrawBitmap( HDC, HBITMAP, WORD wCol, WORD wRow, WORD wWidth, \
  24.                         WORD wHeight, DWORD dwRaster );
  25.  
  26. typedef unsigned long DWORD;
  27. extern void  _retnl( LONG lNumber );
  28.  
  29. //---------------------------------------------------------------------------//
  30.  
  31. CLIPPER TCDrawCell( ) // ( hWnd, hDC, nRow, nColumn , nWidth ,
  32.                       //   uData, nAlign , nClrFore, nClrBack , 
  33.                       //   hFont, nBitmap, dwRaster )
  34.  
  35. {
  36.    HWND hWnd        = _parni( 1 ) ;
  37.    HDC  hDC         = _parni( 2 ) ;
  38.    int  nRow        = _parni( 3 ) ;
  39.    int  nColumn     = _parni( 4 ) ;
  40.    int  nWidth      = _parni( 5 ) ;
  41.    LPSTR cData      = _parc( 6 ) ;
  42.    int  nLen        = _parclen( 6 ) ;
  43.    UINT nAlign      = _parni( 7 ) ;
  44.    COLORREF clrFore = ( PCOUNT() > 7 ? _parnl( 8 ): 0 );
  45.    COLORREF clrBack = ( PCOUNT() > 8 ? _parnl( 9 ): RGB( 255, 255, 255 ) );
  46.    HFONT hFont      = _parni( 10 ) ;
  47.    int     nBitMap  = _parni( 11 ) ;
  48.    HBITMAP hBitMap  = _parni( 6 ) ;  // redefine parm 6 as possible bitmap
  49.  
  50.    //DWORD dwRaster   = ( PCOUNT() > 11 ? _parnl( 12 ) : 0x5A0049 );
  51.    
  52.    HFONT hOldFont ;
  53.    BOOL bDestroyDC  = FALSE ;
  54.    HPEN hGrayPen    = CreatePen( PS_SOLID, 1, RGB( 128, 128, 128 ) ) ;
  55.    HPEN hWhitePen   = GetStockObject( WHITE_PEN ) ;
  56.  
  57.    TEXTMETRIC tm ;
  58.    RECT rct ;
  59.    int LineCount, HeaderHeight ;
  60.  
  61.    if( ! hDC )
  62.    {
  63.       bDestroyDC = TRUE ;
  64.       hDC = GetDC( hWnd ) ;
  65.    }
  66.  
  67.    if( hFont )
  68.       hOldFont = SelectObject( hDC, hFont ) ;
  69.  
  70.    GetClientRect( hWnd, &rct ) ;
  71.    GetTextMetrics( hDC, &tm ) ;
  72.  
  73.    /* Calculate number of lines available to this Client Rect. */
  74.    LineCount = ( ( rct.bottom - rct.top ) / tm.tmHeight ) - 1 ;
  75.  
  76.    /* Add the extra space that will be left over on the bottom of the screen
  77.       to the header. */
  78.    HeaderHeight = ( ( rct.bottom - rct.top ) - ( LineCount * tm.tmHeight ) ) ;
  79.  
  80.    SetTextColor( hDC, clrFore ) ;
  81.    SetBkColor( hDC, clrBack ) ;
  82.  
  83.    if( nRow == 0 )
  84.    {
  85.       rct.top = 0 ;
  86.       rct.bottom = HeaderHeight ;
  87.    }
  88.    else
  89.    {
  90.       rct.top    = HeaderHeight + ( tm.tmHeight * ( nRow - 1 ) ) ;
  91.       rct.bottom = rct.top + tm.tmHeight ;
  92.    }
  93.  
  94.    /* Don't let left side go beyond rct.right of Client Rect. */
  95.    if( nColumn - ( rct.right - rct.left) <= 0 )
  96.    {
  97.       rct.left   = nColumn ;
  98.  
  99.         /* if nWidth == -1, it indicates the last column so go to limit, 
  100.          Don't let right side go beyond rct.right of Client Rect. */
  101.       if( ( nWidth != -1 ) && ((rct.left + nWidth - rct.right) <= 0) )
  102.          rct.right  = rct.left + nWidth ;
  103.  
  104.       rct.right += 2;
  105.  
  106.       ExtTextOut( hDC, rct.left, rct.top, ETO_OPAQUE | ETO_CLIPPED, \
  107.                     &rct, "", 0, 0  ) ;
  108.  
  109.       rct.left += 2 ;
  110.       rct.right -= 4 ;
  111.  
  112.       if(nBitMap)
  113.           {
  114.  
  115.          // use this next code to use ROPs, disable the 4 lines code below
  116.          // also uncomment the dwRaster code in the begining of the function
  117.           // if ( nBitMap == 1 )
  118.          //   dwRaster = 0;
  119.          // DrawBitmap( hDC, hBitMap,  rct.top + 1, rct.left - 1, \
  120.          //         rct.right - rct.left + 1,  rct.bottom - rct.top - 1, dwRaster );
  121.  
  122.               DrawBitmap( hDC, hBitMap,  rct.top + 1, rct.left - 1, \
  123.                    rct.right - rct.left + 1,  rct.bottom - rct.top - 1, 0 );
  124.  
  125.               if ( nBitMap == 2 )
  126.                    InvertRect( hDC,  &rct) ;
  127.          }
  128.       else
  129.           DrawText( hDC, cData, nLen, &rct, nAlign | DT_VCENTER | \
  130.                    DT_SINGLELINE) ;
  131.  
  132.       rct.left -= 2 ;
  133.       rct.right += 1 ;
  134.       rct.bottom -= 1 ;
  135.  
  136.       WndDrawBox( hDC, &rct, hWhitePen, hGrayPen ) ;
  137.    }
  138.    DeleteObject( hGrayPen ) ;
  139.    if( hFont )
  140.       SelectObject( hDC, hOldFont ) ;
  141.  
  142.    if( bDestroyDC )
  143.        ReleaseDC( hWnd, hDC ) ;
  144. }
  145.  
  146. //---------------------------------------------------------------------------//
  147.  
  148. CLIPPER TCBrwScrol()  // 
  149. {
  150.    HWND hWnd   = _parni( 1 );
  151.    WORD wRows  = _parni( 2 );
  152.    HFONT hFont = _parni( 3 );
  153.    HFONT hOldFont;
  154.    HDC hDC     = GetDC( hWnd );
  155.    RECT rct;
  156.    TEXTMETRIC tm;
  157.     int LineCount, HeaderHeight ;
  158.    
  159.    if( hFont )
  160.       hOldFont = SelectObject( hDC, hFont );
  161.  
  162.    GetClientRect( hWnd, &rct );
  163.    GetTextMetrics( hDC, &tm );
  164.  
  165.    /* Calculate number of lines available to this Client Rect. */
  166.    LineCount = ( ( rct.bottom - rct.top ) / tm.tmHeight ) - 1 ;
  167.  
  168.    /* Add the extra space that will be left over on the bottom of the screen
  169.       to the header. */
  170.    HeaderHeight = ( ( rct.bottom - rct.top -1) - ( LineCount * tm.tmHeight ) ) ;
  171.  
  172.    rct.top += HeaderHeight ;
  173.    //rct.bottom += tm.tmHeight ;
  174.    ScrollWindow( hWnd, 0, -( tm.tmHeight * wRows ), 0, &rct );
  175.  
  176.    if( hFont )
  177.       SelectObject( hDC, hOldFont );
  178.  
  179.    ReleaseDC( hWnd, hDC );
  180. }
  181.  
  182. //---------------------------------------------------------------------------//
  183.  
  184. static WORD near GetWindowRow( HWND hWnd, HDC hDC, WORD wGraphRow, \
  185.                                HFONT hFont ) // -> wTextRow
  186. {
  187.    TEXTMETRIC tm;
  188.    RECT rct;
  189.    WORD wRow;
  190.    BOOL bDCDestroy = FALSE;
  191.    HFONT hOldFont;
  192.     int LineCount, HeaderHeight ;
  193.  
  194.    if( ! hDC )
  195.    {
  196.       bDCDestroy = TRUE;
  197.       hDC = GetDC( hWnd );
  198.    }
  199.  
  200.    if( hFont )
  201.       hOldFont = SelectObject( hDC, hFont );
  202.  
  203.    GetTextMetrics( hDC, &tm );
  204.    GetClientRect( hWnd, &rct );
  205.  
  206.    /* Calculate number of lines available to this Client Rect. */
  207.    LineCount = ( ( rct.bottom - rct.top ) / tm.tmHeight ) - 1 ;
  208.  
  209.    /* Add the extra space that will be left over on the bottom of the screen
  210.       to the header. */
  211.    HeaderHeight = ( ( rct.bottom - rct.top ) - ( LineCount * tm.tmHeight ) ) ;
  212.  
  213.    /*   wRow = ( wGraphRow - rct.top ) / tm.tmHeight;*/
  214.    if( wGraphRow - rct.top <= HeaderHeight )
  215.       wRow = 0 ;
  216.    else
  217.       wRow = ( ( wGraphRow - rct.top - HeaderHeight ) / tm.tmHeight ) + 1 ;
  218.  
  219.  
  220.    if( hFont )
  221.       SelectObject( hDC, hOldFont );
  222.  
  223.    if( bDCDestroy )
  224.       ReleaseDC( hWnd, hDC );
  225.  
  226.    return wRow;
  227. }
  228.  
  229. CLIPPER nTCWRow()        // hWnd, hDC, nGraphRow, hFont -> nTextRow
  230. {
  231.    _retni( GetWindowRow( _parni( 1 ), _parni( 2 ), _parni( 3 ), _parni( 4 ) ) );
  232. }
  233.  
  234. //---------------------------------------------------------------------------//
  235.  
  236. CLIPPER aTCBrwPosR() // ect( hWnd, nRow, nCol, nWidth, hFont )
  237. {
  238.    HWND hWnd        = _parni( 1 );
  239.    WORD wRow        = _parni( 2 );
  240.    WORD wCol        = _parni( 3 );
  241.    WORD wWidth      = _parni( 4 );
  242.    HFONT hFont      = _parni( 5 );
  243.    HDC hDC          = GetDC( hWnd );
  244.    HFONT hOldFont;
  245.    WORD wMaxRight;
  246.    TEXTMETRIC tm;
  247.    RECT rct;
  248.    int LineCount, HeaderHeight ;
  249.  
  250.    if( hFont )
  251.       hOldFont = SelectObject( hDC, hFont );
  252.  
  253.    GetWindowRect( hWnd, &rct );
  254.    wMaxRight = rct.right;
  255.  
  256.    GetTextMetrics( hDC, &tm );
  257.  
  258.  
  259.    /* Calculate number of lines available to this Client Rect. */
  260.    LineCount = ( ( rct.bottom - rct.top ) / tm.tmHeight ) - 1 ;
  261.  
  262.    /* Add the extra space that will be left over on the bottom of the screen
  263.       to the header. */
  264.    HeaderHeight = ( ( rct.bottom - rct.top ) - ( LineCount * tm.tmHeight ) ) ;
  265.  
  266.    rct.top    += HeaderHeight + ( tm.tmHeight * ( wRow - 1 ) ) ;
  267.  
  268.    rct.bottom = rct.top + tm.tmHeight;
  269.  
  270.    rct.left   += wCol;
  271.    rct.right  = rct.left + wWidth;
  272.  
  273.    if( hFont )
  274.       SelectObject( hDC, hOldFont );
  275.  
  276.    ReleaseDC( hWnd, hDC );
  277.  
  278.    _reta( 4 );
  279.  
  280.    _storni( rct.top,    -1, 1 );
  281.    _storni( rct.left,   -1, 2 );
  282.    _storni( rct.bottom, -1, 3 );
  283.    _storni( ( wMaxRight <= rct.right ) ? wMaxRight - 18: rct.right, -1, 4 );
  284. }
  285.  
  286. //---------------------------------------------------------------------------//
  287.  
  288.