//----------------------------------------------------------------------------//
METHOD LButtonUp( nRow, nCol ) CLASS TBtnBmp
local oWnd
local lClick := IsOverWnd( ::hWnd, nRow, nCol )
if ::lDrag .or. ! Empty( ::oDragCursor )
return ::Super:LButtonUp( nRow, nCol )
endif
if ::bLButtonUp != nil
Eval( ::bLButtonUp, nRow, nCol)
endif
::lBtnUp = .T.
if ! ::lWorking
if ::lCaptured
::lCaptured = .F.
ReleaseCapture()
if ! ::lPressed
if ::lBtnDown
::lPressed = .T.
::Refresh()
endif
else
if ! ::lBtnDown
::lPressed = .F.
::Refresh()
endif
endif
if lClick
if ::oPopup != nil
if nCol >= ::nWidth() - 13
if ::oWnd:oWnd != nil .and. Upper( ::oWnd:oWnd:Classname() ) == "TBAR"
oWnd := ::oWnd:oWnd
else
oWnd := ::oWnd
endif
oWnd:NcMouseMove() // close the tooltip
oWnd:oPopup = If( ValType( ::oPopup ) == 'B', Eval( ::oPopUp, Self ), ::oPopUp )
// ::Activate( ::nTop + ::nHeight(), ::nLeft, oWnd, .F. )
oWnd:oPopup:Activate( ::nTop + ::nHeight(), Max( ::nLeft, 1 ), oWnd, .F. )
if ValType( ::oPopUp ) == 'B'
oWnd:oPopUp:End()
endif
oWnd:oPopup = nil
::Refresh()
else
::Click()
endif
else
::Click()
endif
endif
endif
endif
return 0
//----------------------------------------------------------------------------//
METHOD Destroy() CLASS TBtnBmp
::FreeBitmaps()
if ValType( ::oPopUp ) == 'O'
::oPopup:End()
endif
if ! Empty( ::hRgn )
DeleteObject( ::hRgn )
endif
return ::Super:Destroy()
//----------------------------------------------------------------------------//
METHOD DrawEllipse( hDC, nRGBColor, n ) CLASS TBtnBmp
local hOldBrush := SelectObject( hDC, GetStockObject( NULL_BRUSH ) )
local hPen := CreatePen( hDC, 1, nRGBColor )
DEFAULT n := 0
Ellipse( hDC, n, n, ::nWidth - 1 - n, ::nHeight - 1 - n, hPen )
SelectObject( ::hDC, hOldBrush )
DeleteObject( hPen )
return nil
//----------------------------------------------------------------------------//
METHOD DrawFocusEllipse( hDC ) CLASS TBtnBmp
local nPoints := 1.83 * SQRT( ( ( ::nWidth / 2 ) * ( ::nWidth / 2 ) + ;
( ::nHeight / 2 ) * ( ::nHeight / 2 ) ) / 2 )
DrawFocusEllipse( ::hWnd, hDC, 10, nPoints )
return nil
//----------------------------------------------------------------------------//
METHOD SetFile( cBmpUpFile, cBmpDownFile ) CLASS TBtnBmp
::FreeBitmaps()
::LoadBitmaps( nil, nil, cBmpUpFile, cBmpDownFile )
::Refresh()
return nil
//----------------------------------------------------------------------------//
METHOD FreeBitmaps() CLASS TBtnBmp
if ::hBitmap1 != 0
PalBmpFree( ::hBitmap1, ::hPalette1 )
endif
if ::hBitmap2 != 0
PalBmpFree( ::hBitmap2, ::hPalette2 )
endif
if ::hBitmap3 != 0
PalBmpFree( ::hBitmap3, ::hPalette3 )
endif
if ::hBitmap4 != 0
PalBmpFree( ::hBitmap4, ::hPalette4 )
endif
::hBitmap1 = 0
::hPalette1 = 0
::hBitmap2 = 0
::hPalette2 = 0
::hBitmap3 = 0
::hPalette3 = 0
::hBitmap4 = 0
::hPalette4 = 0
afill( ::aAlpha, .F. )
return nil
//----------------------------------------------------------------------------//
METHOD LoadBitmaps( cResName1, cResName2, cBmpFile1, cBmpFile2,;
cResName3, cBmpFile3, cResName4, cBmpFile4 ) CLASS TBtnBmp
local aBmpPal
if ! Empty( cResName1 )
IF FindResource( GetResources(), cResName1 , 10 ) != 0
::hBitmap1 = FILoadFromMemory( cResToStr( cResName1, 10 ), 10 )
::hPalette1 = 0
::cResName1 = cResName1
ELSE
aBmpPal = PalBmpLoad( cResName1 )
::hBitmap1 = aBmpPal[ 1 ]
::hPalette1 = aBmpPal[ 2 ]
::cBmpFile1 = cResName1
endif
::HasAlpha( ::hBitmap1, BTN_UP )
endif
if ! Empty( cResName2 )
IF FindResource( GetResources(), cResName2 , 10 ) != 0
::hBitmap2 = FILoadFromMemory( cResToStr( cResName2, 10 ), 10 )
::hPalette2 = 0
::cResName2 = cResName2
ELSE
aBmpPal = PalBmpLoad( cResName2 )
::hBitmap2 = aBmpPal[ 1 ]
::hPalette2 = aBmpPal[ 2 ]
::cBmpFile2 = cResName2
endif
::HasAlpha( ::hBitmap2, BTN_DOWN )
endif
if ! Empty( cResName3 )
IF FindResource( GetResources(), cResName3 , 10 ) != 0
::hBitmap3 = FILoadFromMemory( cResToStr( cResName3, 10 ), 10 )
::hPalette3 = 0
::cResName3 = cResName3
ELSE
aBmpPal = PalBmpLoad( cResName3 )
::hBitmap3 = aBmpPal[ 1 ]
::hPalette3 = aBmpPal[ 2 ]
::cBmpFile3 = cResName3
endif
::HasAlpha( ::hBitmap3, BTN_DISABLE )
endif
if ! Empty( cResName4 )
IF FindResource( GetResources(), cResName4 , 10 ) != 0
::hBitmap4 = FILoadFromMemory( cResToStr( cResName4, 10 ), 10 )
::hPalette4 = 0
::cResName4 = cResName4
ELSE
aBmpPal = PalBmpLoad( cResName4 )
::hBitmap4 = aBmpPal[ 1 ]
::hPalette4 = aBmpPal[ 2 ]
::cBmpFile4 = cResName4
endif
::HasAlpha( ::hBitmap4, BTN_OVERMOUSE )
endif
if ! Empty( cBmpFile1 )
if File( cBmpFile1 )
::cBmpFile1 = cBmpFile1
if Upper( Right( cBmpFile1, 3 ) ) == "PNG"
::hBitmap1 = FWOpenPngFile( cBmpFile1 )
::hPalette1 = 0
else
aBmpPal = PalBmpRead( ::GetDC(), cBmpFile1 )
::hBitmap1 = aBmpPal[ 1 ]
::hPalette1 = aBmpPal[ 2 ]
::ReleaseDC()
endif
::cBmpFile1 = cBmpFile1
::HasAlpha( ::hBitmap1, BTN_UP )
endif
endif
if ! Empty( cBmpFile2 )
if File( cBmpFile2 )
::cBmpFile2 = cBmpFile2
if Upper( Right( cBmpFile2, 3 ) ) == "PNG"
::hBitmap2 = FWOpenPngFile( cBmpFile2 )
::hPalette2 = 0
else
aBmpPal = PalBmpRead( ::GetDC(), cBmpFile2 )
::hBitmap2 = aBmpPal[ 1 ]
::hPalette2 = aBmpPal[ 2 ]
::ReleaseDC()
endif
::HasAlpha( ::hBitmap2, BTN_DOWN )
::cBmpFile2 = cBmpFile2
endif
endif
if ! Empty( cBmpFile3 )
if File( cBmpFile3 )
::cBmpFile3 = cBmpFile3
if Upper( Right( cBmpFile3, 3 ) ) == "PNG"
::hBitmap3 = FWOpenPngFile( cBmpFile3 )
::hPalette3 = 0
else
aBmpPal = PalBmpRead( ::GetDC(), cBmpFile3 )
::hBitmap3 = aBmpPal[ 1 ]
::hPalette3 = aBmpPal[ 2 ]
::ReleaseDC()
endif
::HasAlpha( ::hBitmap3, BTN_DISABLE )
::cBmpFile3 = cBmpFile3
endif
endif
if ! Empty( cBmpFile4 )
if File( cBmpFile4 )
::cBmpFile4 = cBmpFile4
if Upper( Right( cBmpFile4, 3 ) ) == "PNG"
::hBitmap4 = FWOpenPngFile( cBmpFile4 )
::hPalette4 = 0
else
aBmpPal = PalBmpRead( ::GetDC(), cBmpFile4 )
::hBitmap4 = aBmpPal[ 1 ]
::hPalette4 = aBmpPal[ 2 ]
::ReleaseDC()
endif
::HasAlpha( ::hBitmap4, BTN_OVERMOUSE )
::cBmpFile4 = cBmpFile4
endif
endif
if ! Empty( ::hBitmap1 )
PalBmpNew( ::hWnd, ::hBitmap1, ::hPalette1 )
endif
if ! Empty( ::hBitmap2 )
PalBmpNew( ::hWnd, ::hBitmap2, ::hPalette2 )
endif
if ! Empty( ::hBitmap3 )
PalBmpNew( ::hWnd, ::hBitmap3, ::hPalette3 )
endif
if ! Empty( ::hBitmap4 )
PalBmpNew( ::hWnd, ::hBitmap4, ::hPalette4 )
endif
return nil
//----------------------------------------------------------------------------//
METHOD MouseMove( nRow, nCol, nKeyFlags ) CLASS TBtnBmp
if ! ::lMOver
::lMOver = .T.
::Refresh()
endif
if ::lDrag .or. ! Empty( ::oDragCursor )
return ::Super:MouseMove( nRow, nCol, nKeyFlags )
endif
::Super:MouseMove( nRow, nCol, nKeyFlags )
if ! ( ::l2007 .or. ::l2010 )
if IsOverWnd( ::hWnd, nRow, nCol )
if !::lCaptured
if ::l97Look
::Capture()
if ! ::lBorder
::lBorder = .T.
::Refresh()
endif
endif
else
if ! ::lPressed
::lPressed = .T.
::Refresh()
endif
endif
else
if ! ::lCaptured
if ::l97Look
ReleaseCapture()
if ::lBorder
::lBorder = .F.
::Refresh()
endif
endif
else
if ::lPressed
::lBorder = ! ::l97Look
::lPressed = .F.
::Refresh()
endif
endif
endif
endif
::oWnd:SetMsg( ::cMsg )
TrackMouseEvent( ::hWnd, TME_LEAVE )
return 0
//----------------------------------------------------------------------------//
METHOD Paint() CLASS TBtnBmp
local hOldFont, nRow, nCol, nWidth, nHeight
local hDC, hPen, hOldPen, hDarkPen, hLightPen, lDlg
local aInfo := ::DispBegin()
local hBmpOld, nZeroZeroClr, nOldClr, oFont, hBmp, nClr
local nTop, nLeft, hOlFont
local nBmpHeight := 0, nBmpWidth := 0, nBmpTop := 0, nBmpLeft := 0
local nTxtTop := 0, nTxtLeft := 6, nTxtRight := ::nWidth - 6, nTxtHeight
local nFontHeight := 11, nStyle := 0
local lMultiLine := .F.
local hBlackBrush, hOldBrush
local nAdjustBorder := 0, nAdjust := 0, nAlphaLevel
local nBtn := 1, nLine:=1, nOffset := 0, nMaxWidth := 0
local cWord := "", cWord2 := "", nLayOut := 1
local aRect
if ::oPopup != nil
nTxtRight -= 12
endif
if ::lBarBtn
::lRound = .F.
endif
if ! Empty( ::cCaption )
if ::oFont == nil
::SetFont( ::oWnd:oFont )
if ::oFont == nil .and. ! Empty( ::oWnd )
::SetFont( ::oWnd:oWnd:oFont )
endif
endif
endif
hBmp = if ( ::lPressed, if( empty( ::hBitmap2 ), if ( ::lMOver .and. !empty( ::hBitmap4 ), ::hBitmap4, ::hBitmap1 ),;
::hBitmap2 ), if ( ! IsWindowEnabled( ::hWnd ) .and. ! Empty( ::hBitmap3 ),;
::hBitmap3, if ( ::lMOver .and. !empty( ::hBitmap4 ), ::hBitmap4, ::hBitmap1 ) ) )
nBtn = if ( ::lPressed, if( empty( ::hBitmap2 ), if ( ::lMOver .and. !empty( ::hBitmap4 ), 4, 1 ),;
2 ), if ( ! IsWindowEnabled( ::hWnd ) .and. ! Empty( ::hBitmap3 ),;
3, if ( ::lMOver .and. !empty( ::hBitmap4 ), 4, 1 ) ) )
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
endif
if ! Empty( hBmp )
if SetAlpha() .and. ::aAlpha[ nBtn ]
::nAlphaLevel()
if ::lAdjust
hBmp = ResizeBmp( hBmp, ::nWidth, ::nHeight )
endif
endif
nBmpWidth := nBmpWidth( hBmp )
nBmpHeight := nBmpHeight( hBmp )
nBmpLeft := ( ::nWidth - nBmpWidth ) / 2
nBmpTop := ( ::nHeight - nBmpHeight ) / 2
if ! Empty( ::cCaption )
DEFAULT ::nLayOut := 1
do case
case ::nLayOut == 1 // top
nBmpTop = ::nHeight / 2 - ( nBmpHeight + nLine * ::nGetChrHeight() ) / 2 - 4
case ::nLayOut == 2 // left
nBmpLeft = ::nWidth / 2 - ( nBmpWidth + ::GetWidth( cWord ) ) / 2 + 4
case ::nLayOut == 3 // bottom
nBmpTop = ( ::nHeight / 2 ) - ( nBmpHeight / 2 ) + ( nLine * ::nGetChrHeight() ) / 2 + 4
case ::nLayOut == 4 // right
nBmpLeft = ( ::nWidth / 2 ) - ( nBmpWidth / 2 ) + ( ::GetWidth( cWord ) ) / 2 - 4
otherwise
endcase
endif
endif
nLayOut = ::nLayOut
if ! Empty( ::cCaption )
DEFAULT ::nLayOut := 1
do case
case ::nLayOut == 1 // top
if !empty( hBmp )
nTxtTop := nBmpTop + nBmpHeight + 4
else
nTxtTop := ::nHeight - ( nLine * ::nGetChrHeight() ) - 4
endif
case ::nLayOut == 2 // left
nTxtTop := ::nHeight / 2 - ( ::nGetChrHeight() * nLine ) / 2
if ::lAdjust
nTxtLeft := 4
else
if !empty( hBmp )
nTxtLeft := nBmpLeft + nBmpWidth + 4
nLayOut := 4
else
nTxtLeft := 4
endif
endif
case ::nLayOut == 3 // bottom
if !empty( hBmp )
nTxtTop := nBmpTop - ( nLine * ::nGetChrHeight() ) - 4
else
nTxtTop := 4
endif
case ::nLayOut == 4 // right
nTxtTop := ::nHeight / 2 - ( ::nGetChrHeight() * nLine ) / 2
if ::lAdjust
nTxtRight := ::nWidth - 4
else
if !empty( hBmp )
nTxtRight := nBmpLeft - 4
nLayOut := 2
else
nTxtRight := ::nWidth
endif
endif
otherwise
nTxtTop = ::nHeight / 2 - ( ::nGetChrHeight() * nLine ) / 2
endcase
endif
if ::l2007 .or. ::l2010
if ::lPressed
nBmpTop++
nBmpLeft++
nAdjust := 1
endif
if ! ::lBarBtn
if Empty( ::hRgn ) .and. ::lEllipse
::hRgn := CreateEllipticRgnIndirect( GetClientRect( ::hWnd ) )
SetWindowRgn( ::hWnd, ::hRgn )
endif
if Empty( ::hRgn ) .and. ::lRound
::hRgn := CreateRoundRectRgn( GetClientRect( ::hWnd ), 6, 6 )
SetWindowRgn( ::hWnd, ::hRgn )
endif
nAdjustBorder = If( ::lBorder, If( ::lBarBtn, 0, 3 ), 0 )
if ! Empty( ::aGrad )
GradientFill( ::hDC, 0,0, ::nHeight, ::nWidth, ::aGrad )
endif
if ::lBorder
do case
case ::lEllipse
::DrawEllipse( ::hDC, RGB( 141, 178, 227 ), 0 )
::DrawEllipse( ::hDC, RGB( 237, 242, 248 ), 1 )
if ::lFocused
::DrawFocusEllipse( ::hDC )
endif
case ::lRound
RoundBox( ::hDC, 1, 1, ::nWidth, ::nHeight, 6, 6, RGB( 237, 242, 248 ) )
RoundBox( ::hDC, 0, 0, ::nWidth - 1, ::nHeight, 6, 6, RGB( 141, 178, 227 ), 1 )
otherwise
Rectangle( ::hDC, 0, 0, ::nHeight, ::nWidth )
if ::aGrad != nil
GradientFill( ::hDC, 1, 1, ::nHeight - 2, ::nWidth - 1, ::aGrad )
endif
endcase
endif
else
if ::aGrad != nil
GradientFill( ::hDC, 0, 0, ::nHeight, ::nWidth, ::aGrad )
endif
endif
if ::oPopUp != nil
if ::nLayOut != 2 // left
nBmpLeft -= 6
endif
endif
hBmpOld = SelectObject( ::hDC, hBmp )
nZeroZeroClr = GetPixel( ::hDC, 0, 0 )
SelectObject( ::hDC, hBmpOld )
if ! Empty( hBmp )
if SetAlpha() .and. ::aAlpha[ nBtn ]
ABPaint( ::hDC, if( ::lAdjust, nAdjust, nBmpLeft ),;
If( ::lAdjust, nAdjust, nBmpTop ), hBmp, ::nAlphaLevel() )
else
nOldClr = SetBkColor( ::hDC, nRGB( 255, 255, 255 ) )
TransBmp( hBmp, nBmpWidth, nBmpHeight, nZeroZeroClr, ::hDC,;
if( ::lAdjust, nAdjust, nBmpLeft ), ;
if( ::lAdjust, nAdjust, nBmpTop ),;
if (::lAdjust, ::nWidth, nBmpWidth ) ,;
if( ::lAdjust, ::nHeight, nBmpHeight ) )
SetBkColor( ::hDC, nOldClr )
endif
endif
if ! Empty( ::cCaption )
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, If( ::lBarBtn, If( ::oWnd:oFont != nil, ::oWnd:oFont:hFont, ::oFont:hFont ), ::oFont:hFont ) )
endif
aRect := { nTxtTop + nAdjust, nTxtLeft + nAdjust, ::nHeight + nAdjust - 4, nTxtRight + nAdjust }
lMultiLine := ( nTxtHeight := DrawText( ::hDC, ::cCaption, aRect, nOr( DT_WORDBREAK, DT_CALCRECT ) ) ) > ;
DrawText( ::hDC, ::cCaption, aRect, nOr( DT_SINGLELINE, DT_CALCRECT ) )
if ::nLayOut == 1
nStyle := nOr( DT_CENTER, DT_WORDBREAK )
aRect[ 1 ] := aRect[ 3 ] - nTxtHeight
endif
if ::nLayOut == 3
aRect[ 1 ] := 2
endif
DrawText( ::hDC, ::cCaption, aRect, nStyle )
SelectObject( ::hDC, hOldFont )
endif
if ( ::lMOver .and. ::lBoxSelect )
if ! ::lRound .and. ! ::lEllipse
WndBox2007( ::hDC, nAdjustBorder, nAdjustBorder, ::nHeight - nAdjustBorder-1, ::nWidth - nAdjustBorder-1, nRGB( 221, 207, 155 ) )
else
if ::lEllipse
::DrawEllipse( ::hDC, nRGB( 221, 207, 155 ), 2 )
else
RoundBox( ::hDC, 2, 2, ::nWidth - 3, ::nHeight - 3, 6, 6, nRGB( 221, 207, 155 ) )
endif
endif
endif
if ::oPopup != nil
nHeight = ::nHeight
nWidth = ::nWidth
hDC = ::hDC
hBlackBrush = GetStockObject( 4 )
hOldBrush = SelectObject( hDC, hBlackBrush )
PolyPolygon( hDC, { { nWidth - 9 + If( ::lPressed, 1, 0 ), nHeight / 2 - 1 + If( ::lPressed, 1, 0 )},;
{ nWidth - 7 + If( ::lPressed, 1, 0 ), nHeight / 2 + 1 + If( ::lPressed, 1, 0 )},;
{ nWidth - 5 + If( ::lPressed, 1, 0 ), nHeight / 2 - 1 + If( ::lPressed, 1, 0 )},;
{ nWidth - 9 + If( ::lPressed, 1, 0 ), nHeight / 2 - 1 + If( ::lPressed, 1, 0 )} } )
if ::lBorder .or. ::lPressed .or. ::lMOver
hDarkPen = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNSHADOW ) )
hLightPen = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNHIGHLIGHT ) )
hOldPen = SelectObject( hDC, hLightPen )
MoveTo( hDC, nWidth - 12 + If( ::lPressed, 1, 0 ), 1 )
LineTo( hDC, nWidth - 12 + If( ::lPressed, 1, 0 ), nHeight - 1 )
SelectObject( hDC, hDarkPen )
MoveTo( hDC, nWidth - 13 + If( ::lPressed, 1, 0 ), 1 )
LineTo( hDC, nWidth - 13 + If( ::lPressed, 1, 0 ), nHeight - 1 )
SelectObject( hDC, hOldPen )
DeleteObject( hDarkPen )
DeleteObject( hLightPen )
endif
SelectObject( hDC, hOldBrush )
DeleteObject( hBlackBrush )
endif
if ! IsWindowEnabled( ::hWnd ) .and. Empty( ::hBitmap3 )
// BtnDisable( ::hWnd, ::hDC )
endif
if lAnd( GetWindowLong( ::hWnd, GWL_STYLE ), WS_TABSTOP ) .and. ::lFocused .and. ! ::lBarBtn
if ( nWidth := ::nWidth() ) > NO_FOCUSWIDTH
lDlg = ::oWnd:IsKindOf( "TDIALOG" )
if ::lEllipse
::DrawFocusEllipse( ::hDC )
else
if lDlg
DrawFocusRect( ::hDC, 2, 2, ::nHeight() - 2, nWidth - 2 )
else
DrawFocusRect( ::hDC, 4, 4, ::nHeight() - 4, nWidth - 4 )
endif
endif
endif
endif
::DispEnd( aInfo )
return nil
endif
if ::lPressed
nBmpTop++
nBmpLeft++
nAdjust = 1
endif
if ::lTransparent // .and. ! Empty( ::hBitmap )
SetBrushOrgEx( ::hDC, nBmpWidth( ::oWnd:oBrush:hBitmap ) - ::nLeft, nBmpHeight( ::oWnd:oBrush:hBitmap ) - ::nTop )
FillRect( ::hDC, GetClientRect( ::hWnd ), ::oWnd:oBrush:hBrush )
else
if Empty( ::bClrGrad )
FillRect( ::hDC, GetClientRect( ::hWnd ), ::oBrush:hBrush )
else
if ::aGrad != nil
GradientFill( ::hDC, 0, 0, ::nHeight, ::nWidth, ::aGrad() )
endif
if ! ::lPressed
WndRaised( ::hWnd, ::hDC )
else
WndInset( ::hWnd, ::hDC )
endif
endif
endif
IF ! Empty( hBmp )
if SetAlpha() .and. ::aAlpha[ nBtn ]
ABPaint( ::hDC, If( ::lAdjust, nAdjust, nBmpLeft ),;
If( ::lAdjust, nAdjust, nBmpTop ),;
hBmp, ::nAlphaLevel() )
elseif IsAppThemed() .or. ! ::lTransparent
if ! ::lTransparent
if ! Empty( ::bClrGrad )
// DrawTransparent( ::hDC, hBmp, nBmpTop, ::nWidth / 4 - nBmpWidth / 2 + nAdjust )
DrawTransparent( ::hDC, hBmp, nBmpTop, nBmpLeft + nAdjust )
else
PalBtnPaint( ::hWnd, if( ::lMOver .and. ! Empty( ::hBitmap4 ), ::hBitmap4, ::hBitmap1 ),;
if( ::lMOver .and. !Empty( ::hBitmap4 ), ::hPalette4, ::hPalette1 ),;
if ( ::lAdjust .and. empty( ::hBitmap2 ), ::hBitmap1,::hBitmap2 ),;
if ( ::lAdjust .and. empty( ::hBitmap2 ), ::hPalette1,::hPalette2),;
::hBitmap3, ::hPalette3, ::lPressed, ::lAdjust, ::lBorder,;
::oPopup != nil,;
::nClrPane, if ( ::cCaption == "...", ::cCaption,) , ::nLayout,;
If( ::oFont != nil, ::oFont:hFont, 0 ),;
If( ValType( ::nClrText ) == "B", Eval( ::nClrText, ::lMOver ), ::nClrText ), ::hDC,;
Upper( ::oWnd:ClassName() ) != "TBAR" )
endif
else
hBmpOld = SelectObject( ::hDC, hBmp )
nZeroZeroClr = GetPixel( ::hDC, 0, 0 )
SelectObject( ::hDC, hBmpOld )
nOldClr = SetBkColor( ::hDC, nRGB( 255, 255, 255 ) )
TransBmp( hBmp, nBmpWidth, nBmpHeight, nZeroZeroClr, ::hDC,;
if( ::lAdjust, nAdjust, nBmpLeft + nAdjust ), ;
if( ::lAdjust, nAdjust, nBmpTop + nAdjust ),;
if (::lAdjust, ::nWidth, nBmpWidth ) ,;
if( ::lAdjust, ::nHeight, nBmpHeight ) )
SetBkColor( ::hDC, nOldClr )
endif
else
hBmpOld = SelectObject( ::hDC, hBmp )
nZeroZeroClr = GetPixel( ::hDC, 0, 0 )
SelectObject( ::hDC, hBmpOld )
nOldClr = SetBkColor( ::hDC, nRGB( 255, 255, 255 ) )
TransBmp( hBmp, nBmpWidth, nBmpHeight, nZeroZeroClr, ::hDC,;
if( ::lAdjust, nAdjust, nBmpLeft + nAdjust ), ;
if( ::lAdjust, nAdjust, nBmpTop + nAdjust ),;
if (::lAdjust, ::nWidth, nBmpWidth ) ,;
if( ::lAdjust, ::nHeight, nBmpHeight ) )
SetBkColor( ::hDC, nOldClr )
endif
else
PalBtnPaint( ::hWnd, if( ::lMOver .and. !Empty( ::hBitmap4 ), ::hBitmap4, ::hBitmap1 ),;
if( ::lMOver .and. !Empty( ::hBitmap4 ), ::hPalette4, ::hPalette1 ),;
if ( ::lAdjust .and. empty( ::hBitmap2 ), ::hBitmap1,::hBitmap2 ),;
if ( ::lAdjust .and. empty( ::hBitmap2 ), ::hPalette1,::hPalette2),;
::hBitmap3, ::hPalette3, ::lPressed, ::lAdjust, ::lBorder,;
::oPopup != nil,;
::nClrPane, if ( ::cCaption == "...", ::cCaption,) , ::nLayout,;
If( ::oFont != nil, ::oFont:hFont, 0 ),;
If( ValType( ::nClrText ) == "B", Eval( ::nClrText, ::lMOver ), ::nClrText ), ::hDC,;
::oWnd:IsKindOf( "TBAR" ) )
endif
if ! Empty( ::cCaption ) .and. ::cCaption != "..."
/*
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 )
hOldFont = SelectObject( ::hDC, If( ::lBarBtn, ::hFont, ::hFont ) )
DrawText( ::hDC, ::cCaption,{nTxtTop+nAdjust, nTxtLeft+nAdjust, ::nHeight+nAdjust-4, nTxtRight+nAdjust},nStyle )
SelectObject( ::hDC, hOldFont )
DeleteObject( hOldFont )
*/
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 )
hOldFont = SelectObject( ::hDC, ::oFont:hFont ) // If( ::lBarBtn, ::hFont, ::hFont ) )
aRect := { nTxtTop + nAdjust, nTxtLeft + nAdjust, ::nHeight + nAdjust - 4, nTxtRight + nAdjust }
lMultiLine := ( nTxtHeight := DrawText( ::hDC, ::cCaption, aRect, nOr( DT_WORDBREAK, DT_CALCRECT ) ) ) > ;
DrawText( ::hDC, ::cCaption, aRect, nOr( DT_SINGLELINE, DT_CALCRECT ) )
if ::nLayOut == 1
nStyle := nOr( DT_CENTER, DT_WORDBREAK )
aRect[ 1 ] := aRect[ 3 ] - nTxtHeight
endif
if ::nLayOut == 3
aRect[ 1 ] := 2
endif
DrawText( ::hDC, ::cCaption, aRect, nStyle )
SelectObject( ::hDC, hOldFont )
endif
if ::oPopup != nil
nHeight = ::nHeight
nWidth = ::nWidth
hDC = ::hDC
hBlackBrush = GetStockObject( 4 )
hOldBrush = SelectObject( hDC, hBlackBrush )
PolyPolygon( hDC, { { nWidth - 9 + If( ::lPressed, 1, 0 ), nHeight / 2 - 1 + If( ::lPressed, 1, 0 )},;
{ nWidth - 7 + If( ::lPressed, 1, 0 ), nHeight / 2 + 1 + If( ::lPressed, 1, 0 )},;
{ nWidth - 5 + If( ::lPressed, 1, 0 ), nHeight / 2 - 1 + If( ::lPressed, 1, 0 )},;
{ nWidth - 9 + If( ::lPressed, 1, 0 ), nHeight / 2 - 1 + If( ::lPressed, 1, 0 )} } )
if ::lBorder .or. ::lPressed
hDarkPen = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNSHADOW ) )
hLightPen = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNHIGHLIGHT ) )
hOldPen = SelectObject( hDC, hLightPen )
MoveTo( hDC, nWidth - 12 + If( ::lPressed, 1, 0 ), 1 )
LineTo( hDC, nWidth - 12 + If( ::lPressed, 1, 0 ), nHeight - 1 )
SelectObject( hDC, hDarkPen )
MoveTo( hDC, nWidth - 13 + If( ::lPressed, 1, 0 ), 1 )
LineTo( hDC, nWidth - 13 + If( ::lPressed, 1, 0 ), nHeight - 1 )
SelectObject( hDC, hOldPen )
DeleteObject( hDarkPen )
DeleteObject( hLightPen )
endif
SelectObject( hDC, hOldBrush )
DeleteObject( hBlackBrush )
endif
if ! IsWindowEnabled( ::hWnd ) .and. Empty( ::hBitmap3 )
BtnDisable( ::hWnd, ::hDC )
endif
if lAnd( GetWindowLong( ::hWnd, GWL_STYLE ), WS_TABSTOP ) .and. ::lFocused
if ( nWidth := ::nWidth() ) > NO_FOCUSWIDTH
lDlg = ::oWnd:IsKindOf( "TDIALOG" )
if ::lEllipse
::DrawFocusEllipse( ::hDC )
else
DrawFocusRect( ::hDC, 2, 2, ::nHeight() - 4, nWidth - 4 )
endif
endif
endif
::DispEnd( aInfo )
return nil
//----------------------------------------------------------------------------//
METHOD KeyDown( nKey, nFlags ) CLASS TBtnBmp
do case
case nKey == VK_UP .or. nKey == VK_LEFT
::oWnd:GoPrevCtrl( ::hWnd )
case nKey == VK_DOWN .or. nKey == VK_RIGHT
::oWnd:GoNextCtrl( ::hWnd )
endcase
return ::Super:KeyDown( nKey, nFlags )
//----------------------------------------------------------------------------//
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TBtnBmp
if nMsg == WM_MOUSELEAVE
return ::MouseLeave( nHiWord( nLParam ), nLoWord( nLParam ), nWParam )
endif
if nMsg == WM_SYSCHAR
return ::SysChar( nWParam, nLParam )
endif
if nMsg == WM_KEYUP
if ::lPressed
::lPressed := .F.
::Refresh()
::click()
endif
endif
return ::Super:HandleEvent( nMsg, nWParam, nLParam )
//----------------------------------------------------------------------------//
METHOD MouseLeave( nRow, nCol, nFlags ) CLASS TBtnBmp
::lMOver = .F.
::Refresh()
return nil
//----------------------------------------------------------------------------//
METHOD ShowPopup() CLASS TBtnBmp
local oWnd
if ::oPopup != nil
if ::oWnd:oWnd != nil .and. Upper( ::oWnd:oWnd:Classname() ) == "TBAR"
oWnd := ::oWnd:oWnd
else
oWnd := ::oWnd
endif
if GetClassName( GetParent( Self:hWnd ) ) != "TBAR"
oWnd = oWndFromhWnd( GetParent( Self:hWnd ) )
endif
oWnd:NcMouseMove() // close the tooltip
oWnd:oPopup = If( ValType( ::oPopup ) == 'B', Eval( ::oPopUp, Self ), ::oPopUp )
// ::Activate( ::nTop + ::nHeight(), ::nLeft, oWnd, .F. )
oWnd:oPopup:Activate( ::nTop + ::nHeight(), Max( ::nLeft, 1 ), oWnd, .F. )
if ValType( ::oPopUp ) == 'B'
oWnd:oPopUp:End()
endif
oWnd:oPopup = nil
::Refresh()
endif
return nil
//----------------------------------------------------------------------------//
METHOD SetColor( nClrText, nClrPane ) CLASS TBtnBmp
local nOldClrText := ::nClrText
::Super:SetColor( nClrText, nClrPane )
if ValType( nOldClrText ) == "B"
::nClrText = nOldClrText
endif
return nil
//----------------------------------------------------------------------------//
static function CheckArray( aArray )
local nI
local aRet := {}
if ValType( aArray ) == 'A' .and. ;
Len( aArray ) == 1 .and. ;
ValType( aArray[ 1 ] ) == 'A'
aArray := aArray[ 1 ]
endif
for nI = 1 to 4
if nI > len( aArray )
aadd( aRet, 0 )
else
aadd( aRet, if( empty( aArray[ nI ] ), 0, aArray[ nI ] ) )
endif
next
return aRet