METHOD PaintCell( nRow, nCol, nHeight, lHighLite, lSelected, nOrder, nPaintRow ) CLASS TXBrwColumn
local hDC, oBrush, hBrush, nOldColor, hBmp
local oBrush1, oBrush2, hBrush1, hBrush2, aColor2, nWidth1
local oFont
local aColors, aBitmap, aBmpPal
local cData, nTxtHeight, aRect
local nWidth, nTop, nBottom, nBmpRow, nBmpCol, nBmpNo, nButtonRow, nButtonCol,nBtnWidth,;
nRectWidth, nRectCol, nStyle, nType, nIndent, nBtnBmp, nFontHeight
local lTransparent := .f.
local lStretch := .f.
local lBrush := .f.
local cImagen, nBmpW, nBmpH
DEFAULT lHighLite := .f.,;
lSelected := .f.,;
nOrder := 0
nBtnBmp := 0
if ( ::oEditGet != nil .and. nPaintRow == ::oBrw:nRowSel ) .or. ::oEditLbx != nil .or. ::oBrw:nLen == 0
return nil
endif
if nCol != nil
::nDisplayCol := nCol
else
nCol := ::nDisplayCol
endif
if ValType( ::bStrData ) == 'B'
cData := Eval( ::bStrData, nil, Self )
if ValType( cData ) != 'C'
cData := cValToChar( cData )
endif
if ! Empty( ::nDataStrAlign )
cData := AllTrim( cData )
endif
if isrtf( cData )
cData := "<RichText>"
elseif isGtf( cData )
cData := GtfToTxt( cData )
endif
else
cData := ""
endif
if ::bBmpData != nil
nBmpNo := Eval( ::bBmpData, ::Value() )
else
nBmpNo := 0
endif
if lHighLite
if ::oBrw:hWnd == GetFocus()
if lSelected
if nOrder == ::oBrw:nColSel
aColors := Eval( ::bClrSelFocus ) // Eval( ::oBrw:bClrSelFocus )
else
aColors := Eval( If( ::oBrw:bClrRowFocus != nil, ::oBrw:bClrRowFocus, ::bClrSelFocus ) )
endif
else
aColors := Eval( If( ::oBrw:bClrRowFocus != nil, ::oBrw:bClrRowFocus, ::bClrSelFocus ) )
endif
else
aColors := Eval( ::bClrSel )
endif
else
aColors := Eval( ::bClrStd )
lTransparent := IfNil( ::lColTransparent, ::oBrw:lTransparent )
endif
hDC := ::oBrw:GetDC()
oFont := ::oDataFont
if ValType( oFont ) == "B"
oFont = Eval( oFont, Self )
endif
nWidth := ::nWidth
if ::oBrw:lTransparent .and. Empty( ::oBrw:nColDividerStyle )
nWidth -= COL_EXTRAWIDTH
endif
if ::oBrush != nil
if ValType( ::oBrush ) == "B"
oBrush := Eval( ::oBrush, Self )
else
oBrush := ::oBrush
endif
endif
if oBrush != nil
hBrush := oBrush:hBrush
lBrush := .t.
lTransparent:= .f.
// elseif ! lTransparent .and. !::lColTransparent
elseif ! IfNil( ::lColTransparent, lTransparent )
hBrush := CreateColorBrush( aColors[ 2 ] )
elseif ::lColTransparent == .t.
hBrush := CreateColorBrush( 0 )
lTransparent := .t.
endif
nStyle := ::oBrw:nColDividerStyle
nType := ::nEditType
if nStyle == 0
nRectWidth := nWidth + 2
nRectCol := nCol
elseif nStyle < 5 .and. nOrder > 1
nRectWidth := nWidth + 1
nRectCol := nCol - 1
else
nRectWidth := nWidth
nRectCol := nCol
endif
nBottom := nRow + nHeight
if ! lTransparent
nTop := nRow
if ::lMergeVert .and. lHighLite .and. lSelected .and. nOrder == ::oBrw:nColSel
::MergeArea( @nTop, @nBottom, nPaintRow )
endif
if ValType( aColors[ 2 ] ) == 'A'
GradientFill( hDC, nTop, nRectCol, nBottom-1, Min( nRectCol + nRectWidth, ::oBrw:BrwWidth() ), aColors[ 2 ], .t. )
else
FillRect( hDC, { nTop, nRectCol, nBottom, Min( nRectCol + nRectWidth, ::oBrw:BrwWidth() ) }, hBrush )
endif
endif
if ::bIndent != nil
nIndent := Eval( ::bIndent, Self )
if ! Empty( nIndent )
nCol += nIndent
nWidth -= nIndent
endif
endif
nCol += ( COL_EXTRAWIDTH / 2 )
nWidth -= COL_EXTRAWIDTH
nRow += ( ROW_EXTRAHEIGHT / 2 )
nHeight -= ROW_EXTRAHEIGHT
// if nType > 1
// nButtonRow := nRow
// nButtonCol := nCol + nWidth - 10
// nWidth -= 15
// endif
if nType > 1
if ! Empty( aBitmap := ::aBitmap( ::nBtnBmp ) )
nBtnWidth := aBitMap[ BITMAP_WIDTH ] + 1
aBitmap := nil
else
nBtnWidth := IfNil( ::nBtnWidth, 10 )
endif
nButtonRow := nRow
nButtonCol := nCol + nWidth - nBtnWidth
nWidth -= ( nBtnWidth + 5 )
else
if ::lWillShowABtn // to avoid the "dancing" of column data to the left
nWidth -= ( IfNil( ::nBtnWidth, 10 ) + 5 )
endif
endif
if ::lProgBar
aColor2 := Eval( ::bClrProg )
hBrush1 := CreateColorBrush( aColor2[ 1 ] )
hBrush2 := CreateColorBrush( aColor2[ 2 ] )
nWidth1 := Min( ::Value() * nWidth / ;
Max( 1, If( ValType( ::nProgTot ) == 'B', Eval( ::nProgTot, Self ), ::nProgTot ) ), ;
nWidth )
FillRect( hDC, { nRow, nCol, nRow + nHeight, Min( nCol + nWidth1, ::oBrw:BrwWidth() - 4 ) }, hBrush1 )
if nCol + nWidth1 < ::oBrw:BrwWidth() - 4
FillRect( hDC, { nRow, nCol + nWidth1 + 1, nRow + nHeight, ;
Min( nCol + nWidth, ::oBrw:BrwWidth() - 4 ) }, hBrush2 )
endif
DeleteObject( hBrush1 )
DeleteObject( hBrush2 )
endif
if !Empty( aBitmap := ::aBitmap( nBmpNo ) )
nWidth -= aBitmap[ BITMAP_WIDTH ]
if ::bStrData == nil .OR. ::nDataBmpAlign == AL_CENTER // Align Imagen SetCheck
nBmpCol := Max( 0, nCol + nWidth / 2 )
lStretch := ::lBmpStretch
elseif ::nDataBmpAlign == AL_LEFT
nBmpCol := nCol
nCol += aBitmap[ BITMAP_WIDTH ] + BMP_EXTRAWIDTH
else
nBmpCol := nCol + nWidth
endif
nWidth -= BMP_EXTRAWIDTH
nBmpRow := nRow + ( ( nHeight - aBitmap[ BITMAP_HEIGHT ] ) / 2 )
if ::lMergeVert
nTop := nRow
nBottom := nRow + nHeight - 1
::MergeArea( @nTop, @nBottom, nPaintRow )
nBmpRow := nTop + ( ( ( nBottom - nTop + 1 ) - aBitmap[ BITMAP_HEIGHT ] ) / 2 )
endif
// Paint bitmaps
/*DEFAULT*/ aBitmap[ BITMAP_ZEROCLR ] := GetZeroZeroClr( hDC, aBitmap[ BITMAP_HANDLE ] )
if lStretch
if SetAlpha() .and. aBitmap[ BITMAP_ALPHA ]
hBmp := ResizeImg( aBitmap[ BITMAP_HANDLE ], Min( nRectWidth,::oBrw:BrwWidth() - nRectCol - 4 ), nBottom - nRow )
ABPaint( hDC, nRectCol, nRow, hBmp, ::nAlphaLevel() )
else
nOldColor := SetBkColor( hDC, nRGB( 255, 255, 255 ) )
TransBmp( aBitmap[ BITMAP_HANDLE ], aBitmap[ BITMAP_WIDTH ], aBitmap[ BITMAP_HEIGHT ],;
aBitmap[ BITMAP_ZEROCLR ], hDC, nRectCol, nRow, Min( nRectWidth,::oBrw:BrwWidth() - nRectCol - 4 ), ;
nBottom - nRow )
SetBkColor( hDC, nOldcolor )
endif
else
if SetAlpha() .and. aBitmap[ BITMAP_ALPHA ]
ABPaint( hDC, nBmpCol, nBmpRow,aBitmap[ BITMAP_HANDLE ], ::nAlphaLevel() )
else
if ::oBrw:lTransparent .or. ValType( aColors[ 2 ] ) == 'A' // transparent bitmaps with brush
nOldColor := SetBkColor( hDC, nRGB( 255, 255, 255 ) )
TransBmp( aBitmap[ BITMAP_HANDLE ], aBitmap[ BITMAP_WIDTH ], aBitmap[ BITMAP_HEIGHT ],;
aBitmap[ BITMAP_ZEROCLR ], hDC, nBmpCol, nBmpRow, aBitmap[ BITMAP_WIDTH ], ;
aBitmap[ BITMAP_HEIGHT ] )
SetBkColor( hDC, nOldColor )
else
PalBmpDraw( hDC, nBmpRow, nBmpCol,;
aBitmap[ BITMAP_HANDLE ],;
aBitmap[ BITMAP_PALETTE ],;
aBitmap[ BITMAP_WIDTH ],;
aBitmap[ BITMAP_HEIGHT ];
,, ::lBmpTransparent, aColors[ 2 ] )
endif
endif
endif
endif
if ! Empty( cData ) .and. IsBinaryData( cData )
if IfNil( FITypeFromMemory( cData ), -1 ) >= 0
cImagen := cData
cData := ''
else
cData := RangeRepl( Chr(0), Chr(31), cData, '.' )
// cData := '<binary>'
endif
endif
if ! Empty( cImagen ) .or. ::cDataType $ "FP" // IMAGE
if ! Empty( cImagen )
hBmp := FILoadFromMemory( cImagen )
else
if ::bStrImage == NIL
cImagen := ::Value()
else
cImagen := Eval( ::bStrImage, Self, ::oBrw )
endif
if ::cDataType == 'F' .and. File( cImagen )
hBmp := FILoadImg( cImagen )
else
hBmp := FILoadFromMemory( IfNil( cImagen, '' ) )
endif
endif
aBmpPal := { hBmp, 0 }
if aBmpPal[ BITMAP_HANDLE ] == 0
aBmpPal := PalBmpLoad( cImagen )
endif
if aBmpPal[ BITMAP_HANDLE ] != 0
Aadd(aBmpPal, nBmpWidth( aBmpPal[ BITMAP_HANDLE ] ) )
Aadd(aBmpPal, nBmpHeight( aBmpPal[ BITMAP_HANDLE ] ) )
Aadd(aBmpPal, if ( ::lBmpTransparent, GetZeroZeroClr( hDC, aBmpPal[ BITMAP_HANDLE ] ),0) )
Aadd(aBmpPal, HasAlpha( aBmpPal[ BITMAP_HANDLE ] ) )
if ::lBmpStretch
nBmpW := nWidth - 2
nBmpH := nBottom - nRow - 2
nBmpCol := nCol + 1
nBmpRow := nRow + 1
else
nBmpW := aBmpPal[ BITMAP_WIDTH ]
nBmpH := aBmpPal[ BITMAP_HEIGHT ]
if nBmpW > ( nWidth - 4 )
nBmpH *= ( ( nWidth - 4 ) / nBmpW )
nBmpW := nWidth - 4
endif
if nBmpH > ( nBottom - nRow - 4 )
nBmpW *= ( ( nBottom - nRow - 4 ) / nBmpH )
nBmpH := ( nBottom - nRow ) - 4
endif
nBmpRow := nRow + ( nHeight - nBmpH ) / 2 + 2
nBmpCol := nCol + 2
if ::nDataBmpAlign == AL_CENTER
nBmpCol := nCol + ( nWidth - nBmpW ) / 2
elseif ::nDataBmpAlign == AL_RIGHT
nBmpCol := nCol + nWidth - nBmpW
endif
endif
if SetAlpha() .and. aBmpPal[ BITMAP_ALPHA ]
hBmp := ResizeImg( aBmpPal[ BITMAP_HANDLE ], nBmpW, nBmpH )
ABPaint( hDC, nBmpCol, nBmpRow, hBmp, ::nAlphaLevel() )
DeleteObject( hBmp )
elseif ::lBmpTransparent
nOldColor := SetBkColor( hDC, nRGB( 255, 255, 255 ) )
TransBmp( aBmpPal[ BITMAP_HANDLE ], aBmpPal[ BITMAP_WIDTH ], aBmpPal[ BITMAP_HEIGHT ],;
aBmpPal[ BITMAP_ZEROCLR ], hDC, nBmpCol, nBmpRow, nBmpW, nBmpH )
SetBkColor( hDC, nOldColor )
else
if nBmpW != aBmpPal[ BITMAP_WIDTH ] .or. nBmpH != aBmpPal[ BITMAP_HEIGHT ]
hBmp := ResizeImg( aBmpPal[ BITMAP_HANDLE ], nBmpW, nBmpH )
DrawBitmap( hDC, hBmp, nBmpRow, nBmpCol )
DeleteObject( hBmp )
else
DrawBitmap( hDC, aBmpPal[ BITMAP_HANDLE ], nBmpRow, nBmpCol )
endif
endif
endif
endif
if ! Empty( cData ) .and. ! ( ::cDataType $ "PF" ) //.and. nType >= 0
oFont:Activate( hDC )
nFontHeight := GetTextHeight( ::oBrw:hWnd, hDC )
if ::oBrw:lTransparent .and. ::oBrw:lContrastClr
SetTextColor( hDC, ContrastColor( hDC, nCol, nRow, ;
Min( nWidth, ::oBrw:BrwWidth() - nCol ), ;
nHeight, aColors[ 1 ] ) )
else
SetTextColor( hDC, aColors[ 1 ] )
endif
if lTransparent .or. lBrush .or. ::lProgBar .or. ValType( aColors[ 2 ] ) == 'A'
SetBkMode( hDC, 1 )
else
nOldColor := SetBkColor( hDC, aColors[ 2 ] )
endif
nTop := nRow
nBottom := nRow + nHeight
if ::lMergeVert
::MergeArea( @nTop, @nBottom, nPaintRow )
endif
aRect := { nTop, nCol, nBottom, Min( nCol + nWidth, ::oBrw:BrwWidth() - 5 ) }
if ::bPaintText == nil
nStyle := ::nDataStyle
if ::oBrw:nDataType == DATATYPE_ARRAY .and. ;
::nDataStrAlign == AL_LEFT .and. ;
ValType( ::Value ) $ 'ND'
nStyle := ::DefStyle( AL_RIGHT, .t. )
endif
/*
if ::cDataType == 'M' .and. ::nDataLines == nil
if ::oBrw:nDataLines > 1
::nDataLines := ::oBrw:nDataLines
elseif ( ::oBrw:nRowHeight >= 2 * nFontHeight + 4 )
::nDataLines := 2
::nDataStyle := ;
nStyle := ::DefStyle( ::nDataStrAlign, .f. )
endif
endif
*/
if CRLF $ cData .or. ( ::cDataType != nil .and. ::cDataType $ 'CM' .and. lAnd( nStyle, DT_SINGLELINE ) .and. ;
::oBrw:nRowHeight > 2 * nFontHeight + 2 )
cData := Trim( cData )
if ( nTxtHeight := DrawTextEx( hDC, cData, aRect, nOr( DT_CALCRECT, DT_WORDBREAK ) ) ) > ;
DrawTextEx( hDC, cData, aRect, nOr( DT_CALCRECT, DT_SINGLELINE ) )
nStyle := nOr( nAnd( nStyle, nNot( DT_SINGLELINE ) ), DT_WORDBREAK )
if lAnd( ::nDataStrAlign, AL_TOP )
// aRect[ 1 ] += 0 // nothing to be done.
elseif lAnd( ::nDataStrAlign, AL_BOTTOM )
aRect[ 1 ] += Max( 0, Int( ( nHeight - nTxtHeight - 1 ) ) )
else
aRect[ 1 ] += Max( 0, Int( ( nHeight - nTxtHeight ) / 2 ) )
endif
if ::nDataLines == nil .and. ::cDataType == 'M'
::nDataLines := 2
endif
endif
endif
DrawTextEx( hDC, cData, aRect, nStyle )
else
Eval( ::bPaintText, Self, hDC, cData, aRect, aColors, lHighLite )
endif
if nOldColor != nil
SetBkcolor( hDC, nOldColor )
nOldColor := nil
endif
oFont:Deactivate( hDC )
else
aRect := { nRow, nCol, nRow + nHeight, Min( nCol + nWidth, ::oBrw:BrwWidth() - 5 ) }
if ::bPaintText != nil
Eval( ::bPaintText, Self, hDC, "", aRect, aColors, lHighLite )
endif
endif
if nType > 1 .and. nType < EDIT_DATE
if lSelected
if !::lBtnTransparent
WndBoxRaised(hDC, nButtonRow -1 , nButtonCol - 1,;
nButtonRow + nHeight, nButtonCol + nBtnWidth + 1 ) // ButtonGet
endif
if nType == EDIT_LISTBOX .or. nType == EDIT_GET_LISTBOX
::oBtnElip:Hide()
::oBtnList:Move( nButtonRow, nButtonCol, nBtnWidth + 1, nHeight, .f.) // ButtonGet
::oBtnList:Show()
::oBtnList:GetDC()
if ::lBtnTransparent
::oBtnList:SetColor( aColors[ 1 ],aColors[ 2 ] )
else
FillRect( hDC, {nButtonRow, nButtonCol, nButtonRow + nHeight , nButtonCol + nBtnWidth + 1 } ,; // ButtonGet
::oBtnList:oBrush:hBrush )
endif
::oBtnList:Paint()
::oBtnList:ReleaseDC()
else
::oBtnList:Hide()
::oBtnElip:Move( nButtonRow, nButtonCol, nBtnWidth + 1, nHeight, .f.) // ButtonGet
::oBtnElip:Show()
::oBtnElip:GetDC()
if ::lBtnTransparent
::oBtnElip:SetColor( aColors[ 1 ],aColors[ 2 ] )
else
FillRect( hDC, {nButtonRow, nButtonCol, nButtonRow + nHeight , nButtonCol + nBtnWidth + 1 },; // ButtonGet
::oBtnElip:oBrush:hBrush )
endif
::oBtnElip:Paint()
::oBtnElip:ReleaseDC()
endif
endif
endif
if hBrush != nil .and. ! lBrush
DeleteObject( hBrush )
endif
if aBmpPal != nil
DeleteObject( aBmpPal[ BITMAP_HANDLE ] )
endif
::oBrw:ReleaseDC()
return nil