METHOD PaintCaption() CLASS TBtnBmp
local nStyle, nClr
local hOldFont, aRect, lMultiline, cWord, cWord2
local nOffset, nMaxWidth, nLine
local nTxtTop, nTxtLeft, nTxtRight
local nTxtHeight, nAdjust := 0
local nLayOut := ::nLayOut
if ! Empty( ::cCaption )
if ::oFont == nil
::GetFont()
endif
lMultiLine = ! Empty( ::cCaption ) .and. CRLF $ ::cCaption
if lMultiLine
cWord = cStrWord( ::cCaption, nOffset, CRLF )
while nOffset < Len( ::cCaption )
nMaxWidth = Max( nMaxWidth,;
Len( cWord2 := cStrWord( ::cCaption, @nOffset, CRLF ) ) )
if Len( cWord ) < nMaxWidth
cWord = cWord2
endif
end
nLine = MLCount( ::cCaption )
else
cWord = ::cCaption
nTxtHeight = GetTextHeight( ::hWnd, ::hDC )
nTxtTop = ::nHeight / 2 - nTxtHeight / 2
nMaxWidth = GetTextWidth( 0, cWord, ::oFont:hFont )
nTxtLeft = ::nWidth / 2 - nMaxWidth / 2
nTxtRight = ::nWidth / 2 + nMaxWidth / 2
endif
if ::nLayOut == 1 // TOP
nTxtLeft -= 3
endif
if ::nLayout == 2 // LEFT
nTxtLeft += 5
nTxtRight += nBmpWidth( ::hBmp ) / 2 - 5
endif
if ::nLayout == 4 // RIGHT
nTxtLeft -= nBmpWidth( ::hBmp ) / 2 - 5
nTxtRight -= nBmpWidth( ::hBmp ) / 2 - 5
endif
nStyle = nOr( If( ::nLayOut == 0, DT_CENTER, nLayOut ), DT_WORDBREAK,;
If( ::nLayOut % 2 == 0, DT_VCENTER, DT_TOP ) )
nClr = If( IsWindowEnabled( ::hWnd ), ::nClrText,;
If( ::lDisColor, CLR_HGRAY, ::nClrTextDis ) )
SetTextColor( ::hDC, If( ValType( nClr ) == "B", Eval( nClr, ::lMOver ), nClr ) )
SetBkMode( ::hDC, 1 )
if ::oWnd:oFont != nil .or. ::oFont != nil
hOldFont = SelectObject( ::hDC, ::oFont:hFont )
endif
if ::oPopup != nil
nTxtRight -= 12
endif
aRect = { nTxtTop, nTxtLeft, ::nHeight - 4, nTxtRight }
lMultiLine = ( nTxtHeight := DrawText( ::hDC, ::cCaption, aRect,;
nOr( DT_WORDBREAK, DT_CALCRECT ) ) ) > ;
DrawText( ::hDC, ::cCaption, aRect, nOr( DT_SINGLELINE, DT_CALCRECT ) )
if ::nLayOut == 1 // TOP
nStyle = nOr( DT_CENTER, DT_WORDBREAK )
aRect[ 1 ] = aRect[ 3 ] - nTxtHeight
endif
if ::nLayOut == 3
aRect[ 1 ] = 2
endif
if ::lPressed
aRect[ 1 ]++
aRect[ 2 ]++
aRect[ 3 ]++
aRect[ 4 ]++
endif
DrawText( ::hDC, ::cCaption, aRect, nStyle )
SelectObject( ::hDC, hOldFont )
endif
return nil