home *** CD-ROM | disk | FTP | other *** search
- /* Last revision: March 31, 1995 at 11:38 */
-
- /***************************************************************
-
- This file contains the special C routines used TCBrowse Class
-
- The original idea of using the excess bottom space in the header is
- by Selim Anter of Istanbul, Turkey. He if the father of the DrawCell
- routine. I added aTCBrwPosR function, and renamed em all so that there
- should be no interference with similar routines use by TWBrowse.
-
- Harry Van Tassell
-
- ***************************************************************/
-
-
-
- #include <d:\5Win\include\WinTen.h>
- #include <d:\5win\include\Windows.h>
- #include <d:\5Win\include\ClipApi.h>
-
- extern void WndDrawBox( HDC, LPRECT, HPEN, HPEN );
- extern void DrawBitmap( HDC, HBITMAP, WORD wCol, WORD wRow, WORD wWidth, \
- WORD wHeight, DWORD dwRaster );
-
- typedef unsigned long DWORD;
- extern void _retnl( LONG lNumber );
-
- //---------------------------------------------------------------------------//
-
- CLIPPER TCDrawCell( ) // ( hWnd, hDC, nRow, nColumn , nWidth ,
- // uData, nAlign , nClrFore, nClrBack ,
- // hFont, nBitmap, dwRaster )
-
- {
- HWND hWnd = _parni( 1 ) ;
- HDC hDC = _parni( 2 ) ;
- int nRow = _parni( 3 ) ;
- int nColumn = _parni( 4 ) ;
- int nWidth = _parni( 5 ) ;
- LPSTR cData = _parc( 6 ) ;
- int nLen = _parclen( 6 ) ;
- UINT nAlign = _parni( 7 ) ;
- COLORREF clrFore = ( PCOUNT() > 7 ? _parnl( 8 ): 0 );
- COLORREF clrBack = ( PCOUNT() > 8 ? _parnl( 9 ): RGB( 255, 255, 255 ) );
- HFONT hFont = _parni( 10 ) ;
- int nBitMap = _parni( 11 ) ;
- HBITMAP hBitMap = _parni( 6 ) ; // redefine parm 6 as possible bitmap
-
- //DWORD dwRaster = ( PCOUNT() > 11 ? _parnl( 12 ) : 0x5A0049 );
-
- HFONT hOldFont ;
- BOOL bDestroyDC = FALSE ;
- HPEN hGrayPen = CreatePen( PS_SOLID, 1, RGB( 128, 128, 128 ) ) ;
- HPEN hWhitePen = GetStockObject( WHITE_PEN ) ;
-
- TEXTMETRIC tm ;
- RECT rct ;
- int LineCount, HeaderHeight ;
-
- if( ! hDC )
- {
- bDestroyDC = TRUE ;
- hDC = GetDC( hWnd ) ;
- }
-
- if( hFont )
- hOldFont = SelectObject( hDC, hFont ) ;
-
- GetClientRect( hWnd, &rct ) ;
- GetTextMetrics( hDC, &tm ) ;
-
- /* Calculate number of lines available to this Client Rect. */
- LineCount = ( ( rct.bottom - rct.top ) / tm.tmHeight ) - 1 ;
-
- /* Add the extra space that will be left over on the bottom of the screen
- to the header. */
- HeaderHeight = ( ( rct.bottom - rct.top ) - ( LineCount * tm.tmHeight ) ) ;
-
- SetTextColor( hDC, clrFore ) ;
- SetBkColor( hDC, clrBack ) ;
-
- if( nRow == 0 )
- {
- rct.top = 0 ;
- rct.bottom = HeaderHeight ;
- }
- else
- {
- rct.top = HeaderHeight + ( tm.tmHeight * ( nRow - 1 ) ) ;
- rct.bottom = rct.top + tm.tmHeight ;
- }
-
- /* Don't let left side go beyond rct.right of Client Rect. */
- if( nColumn - ( rct.right - rct.left) <= 0 )
- {
- rct.left = nColumn ;
-
- /* if nWidth == -1, it indicates the last column so go to limit,
- Don't let right side go beyond rct.right of Client Rect. */
- if( ( nWidth != -1 ) && ((rct.left + nWidth - rct.right) <= 0) )
- rct.right = rct.left + nWidth ;
-
- rct.right += 2;
-
- ExtTextOut( hDC, rct.left, rct.top, ETO_OPAQUE | ETO_CLIPPED, \
- &rct, "", 0, 0 ) ;
-
- rct.left += 2 ;
- rct.right -= 4 ;
-
- if(nBitMap)
- {
-
- // use this next code to use ROPs, disable the 4 lines code below
- // also uncomment the dwRaster code in the begining of the function
- // if ( nBitMap == 1 )
- // dwRaster = 0;
- // DrawBitmap( hDC, hBitMap, rct.top + 1, rct.left - 1, \
- // rct.right - rct.left + 1, rct.bottom - rct.top - 1, dwRaster );
-
- DrawBitmap( hDC, hBitMap, rct.top + 1, rct.left - 1, \
- rct.right - rct.left + 1, rct.bottom - rct.top - 1, 0 );
-
- if ( nBitMap == 2 )
- InvertRect( hDC, &rct) ;
- }
- else
- DrawText( hDC, cData, nLen, &rct, nAlign | DT_VCENTER | \
- DT_SINGLELINE) ;
-
- rct.left -= 2 ;
- rct.right += 1 ;
- rct.bottom -= 1 ;
-
- WndDrawBox( hDC, &rct, hWhitePen, hGrayPen ) ;
- }
- DeleteObject( hGrayPen ) ;
- if( hFont )
- SelectObject( hDC, hOldFont ) ;
-
- if( bDestroyDC )
- ReleaseDC( hWnd, hDC ) ;
- }
-
- //---------------------------------------------------------------------------//
-
- CLIPPER TCBrwScrol() //
- {
- HWND hWnd = _parni( 1 );
- WORD wRows = _parni( 2 );
- HFONT hFont = _parni( 3 );
- HFONT hOldFont;
- HDC hDC = GetDC( hWnd );
- RECT rct;
- TEXTMETRIC tm;
- int LineCount, HeaderHeight ;
-
- if( hFont )
- hOldFont = SelectObject( hDC, hFont );
-
- GetClientRect( hWnd, &rct );
- GetTextMetrics( hDC, &tm );
-
- /* Calculate number of lines available to this Client Rect. */
- LineCount = ( ( rct.bottom - rct.top ) / tm.tmHeight ) - 1 ;
-
- /* Add the extra space that will be left over on the bottom of the screen
- to the header. */
- HeaderHeight = ( ( rct.bottom - rct.top -1) - ( LineCount * tm.tmHeight ) ) ;
-
- rct.top += HeaderHeight ;
- //rct.bottom += tm.tmHeight ;
- ScrollWindow( hWnd, 0, -( tm.tmHeight * wRows ), 0, &rct );
-
- if( hFont )
- SelectObject( hDC, hOldFont );
-
- ReleaseDC( hWnd, hDC );
- }
-
- //---------------------------------------------------------------------------//
-
- static WORD near GetWindowRow( HWND hWnd, HDC hDC, WORD wGraphRow, \
- HFONT hFont ) // -> wTextRow
- {
- TEXTMETRIC tm;
- RECT rct;
- WORD wRow;
- BOOL bDCDestroy = FALSE;
- HFONT hOldFont;
- int LineCount, HeaderHeight ;
-
- if( ! hDC )
- {
- bDCDestroy = TRUE;
- hDC = GetDC( hWnd );
- }
-
- if( hFont )
- hOldFont = SelectObject( hDC, hFont );
-
- GetTextMetrics( hDC, &tm );
- GetClientRect( hWnd, &rct );
-
- /* Calculate number of lines available to this Client Rect. */
- LineCount = ( ( rct.bottom - rct.top ) / tm.tmHeight ) - 1 ;
-
- /* Add the extra space that will be left over on the bottom of the screen
- to the header. */
- HeaderHeight = ( ( rct.bottom - rct.top ) - ( LineCount * tm.tmHeight ) ) ;
-
- /* wRow = ( wGraphRow - rct.top ) / tm.tmHeight;*/
- if( wGraphRow - rct.top <= HeaderHeight )
- wRow = 0 ;
- else
- wRow = ( ( wGraphRow - rct.top - HeaderHeight ) / tm.tmHeight ) + 1 ;
-
-
- if( hFont )
- SelectObject( hDC, hOldFont );
-
- if( bDCDestroy )
- ReleaseDC( hWnd, hDC );
-
- return wRow;
- }
-
- CLIPPER nTCWRow() // hWnd, hDC, nGraphRow, hFont -> nTextRow
- {
- _retni( GetWindowRow( _parni( 1 ), _parni( 2 ), _parni( 3 ), _parni( 4 ) ) );
- }
-
- //---------------------------------------------------------------------------//
-
- CLIPPER aTCBrwPosR() // ect( hWnd, nRow, nCol, nWidth, hFont )
- {
- HWND hWnd = _parni( 1 );
- WORD wRow = _parni( 2 );
- WORD wCol = _parni( 3 );
- WORD wWidth = _parni( 4 );
- HFONT hFont = _parni( 5 );
- HDC hDC = GetDC( hWnd );
- HFONT hOldFont;
- WORD wMaxRight;
- TEXTMETRIC tm;
- RECT rct;
- int LineCount, HeaderHeight ;
-
- if( hFont )
- hOldFont = SelectObject( hDC, hFont );
-
- GetWindowRect( hWnd, &rct );
- wMaxRight = rct.right;
-
- GetTextMetrics( hDC, &tm );
-
-
- /* Calculate number of lines available to this Client Rect. */
- LineCount = ( ( rct.bottom - rct.top ) / tm.tmHeight ) - 1 ;
-
- /* Add the extra space that will be left over on the bottom of the screen
- to the header. */
- HeaderHeight = ( ( rct.bottom - rct.top ) - ( LineCount * tm.tmHeight ) ) ;
-
- rct.top += HeaderHeight + ( tm.tmHeight * ( wRow - 1 ) ) ;
-
- rct.bottom = rct.top + tm.tmHeight;
-
- rct.left += wCol;
- rct.right = rct.left + wWidth;
-
- if( hFont )
- SelectObject( hDC, hOldFont );
-
- ReleaseDC( hWnd, hDC );
-
- _reta( 4 );
-
- _storni( rct.top, -1, 1 );
- _storni( rct.left, -1, 2 );
- _storni( rct.bottom, -1, 3 );
- _storni( ( wMaxRight <= rct.right ) ? wMaxRight - 18: rct.right, -1, 4 );
- }
-
- //---------------------------------------------------------------------------//
-