XBROWSE y CHECKBOXES
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
Hola, Antonio:
No sé si tuviste alguna razón específica para no dotar a las columnas de TXBrowse con la facilidad de mostar checkboxes típicos, aunque sé que los mismos pueden ser simulados con un par de bitmaps.
Estuve examinando la clase y encontré que, con pequeñas modificaciones en tres métodos, una data lCheckBox para txBrwColumn y una función más, DrawFrameControl() (escrita en C), se puede dotar a una columna de la propiedad de mostrar checkboxes, sólo haciendo oColumn:lCheckbox:=.T.
Agrego el código de modificar tXBrowse para este objetivo. Como evito cambiar los códigos fuentes originales, lo hago a través de OVERRIDE METHOD y EXTEND CLASS. Tuve que duplicar los #defines y las funciones estáticas utilizados por los métodos sobre-escritos. Sin estos el código sería mucho más corto y sencillo de revisar.
Los valores de un checkbox se cambian al pulsar [Enter] o [Space] o al hacer doble click sobre ellos. Al final hay un ejemplo probado.
Saludos cordiales
César Lozada
EJEMPLO DE USO:
No sé si tuviste alguna razón específica para no dotar a las columnas de TXBrowse con la facilidad de mostar checkboxes típicos, aunque sé que los mismos pueden ser simulados con un par de bitmaps.
Estuve examinando la clase y encontré que, con pequeñas modificaciones en tres métodos, una data lCheckBox para txBrwColumn y una función más, DrawFrameControl() (escrita en C), se puede dotar a una columna de la propiedad de mostrar checkboxes, sólo haciendo oColumn:lCheckbox:=.T.
Agrego el código de modificar tXBrowse para este objetivo. Como evito cambiar los códigos fuentes originales, lo hago a través de OVERRIDE METHOD y EXTEND CLASS. Tuve que duplicar los #defines y las funciones estáticas utilizados por los métodos sobre-escritos. Sin estos el código sería mucho más corto y sencillo de revisar.
Los valores de un checkbox se cambian al pulsar [Enter] o [Space] o al hacer doble click sobre ellos. Al final hay un ejemplo probado.
Saludos cordiales
César Lozada
- Code: Select all Expand view
- //
// Modificaciones en tXBrowse para pintar checkboxes en columnas
// César Lozada, Oct 2009
//
// Para localizar cambios, busque @CHECKBOX
//
#include "Fivewin.ch"
#include "xbrowse.ch"
#include "hbclass.ch"
#include "inkey.ch"
#define DFC_BUTTON 0x0004
#define DFCS_BUTTONCHECK 0x0000
#define DFCS_INACTIVE 0x0100
#define DFCS_CHECKED 0x0400
Function txBrowse_Modify()
EXTEND CLASS TXBrwColumn WITH DATA lCheckBox
OVERRIDE METHOD PaintData CLASS TXBrwColumn WITH PaintData
OVERRIDE METHOD Edit CLASS TXBrwColumn WITH Edit
OVERRIDE METHOD KeyChar CLASS txBrowse WITH KeyChar
return nil
*=======================================================================================
#xtranslate MinMax( <xValue>, <nMin>, <nMax> ) => ;
Min( Max( <xValue>, <nMin> ), <nMax> )
#define GWL_STYLE -16
#define GW_HWNDFIRST 0
#define GW_HWNDNEXT 2
#define SM_CYVSCROLL 20
#define SM_CYHSCROLL 3
#define CS_DBLCLKS 8
#define COLOR_SCROLLBAR 0
#define COLOR_BACKGROUND 1
#define COLOR_ACTIVECAPTION 2
#define COLOR_INACTIVECAPTION 3
#define COLOR_MENU 4
#define COLOR_WINDOW 5
#define COLOR_WINDOWFRAME 6
#define COLOR_MENUTEXT 7
#define COLOR_WINDOWTEXT 8
#define COLOR_CAPTIONTEXT 9
#define COLOR_ACTIVEBORDER 10
#define COLOR_INACTIVEBORDER 11
#define COLOR_APPWORKSPACE 12
#define COLOR_HIGHLIGHT 13
#define COLOR_HIGHLIGHTTEXT 14
#define COLOR_BTNFACE 15
#define COLOR_BTNSHADOW 16
#define COLOR_GRAYTEXT 17
#define COLOR_BTNTEXT 18
#define COLOR_INACTIVECAPTIONTEXT 19
#define COLOR_BTNHIGHLIGHT 20
#define DT_TOP 0x00000000
#define DT_LEFT 0x00000000
#define DT_CENTER 0x00000001
#define DT_RIGHT 0x00000002
#define DT_VCENTER 0x00000004
#define DT_BOTTOM 0x00000008
#define DT_WORDBREAK 0x00000010
#define DT_SINGLELINE 0x00000020
#define DT_EXPANDTABS 0x00000040
#define DT_TABSTOP 0x00000080
#define DT_NOCLIP 0x00000100
#define DT_EXTERNALLEADING 0x00000200
#define DT_CALCRECT 0x00000400
#define DT_NOPREFIX 0x00000800
#define DT_INTERNAL 0x00001000
#define DT_EDITCONTROL 0x00002000
#define DT_PATH_ELLIPSIS 0x00004000
#define DT_END_ELLIPSIS 0x00008000
#define DT_MODIFYSTRING 0x00010000
#define DT_RTLREADING 0x00020000
#define DT_WORD_ELLIPSIS 0x00040000
#define DT_NOFULLWIDTHCHARBREAK 0x00080000
#define DT_HIDEPREFIX 0x00100000
#define MK_MBUTTON 0x0010
#define COL_EXTRAWIDTH 6
#define ROW_EXTRAHEIGHT 4
#define COL_SEPARATOR 2
#define BMP_EXTRAWIDTH 5
#define RECORDSELECTOR_WIDTH 25
#define BITMAP_HANDLE 1
#define BITMAP_PALETTE 2
#define BITMAP_WIDTH 3
#define BITMAP_HEIGHT 4
#define BITMAP_ZEROCLR 5
#define VSCROLL_MAXVALUE 10000 // never set values above 32767
Static Function PaintData( nRow, nCol, nHeight, lHighLite, lSelected, nOrder, nPaintRow ) //CLASS TXBrwColumn
LOCAL Self:=HB_QSELF()
local hDC, oBrush, hBrush, nOldColor
local oBrush1, oBrush2, hBrush1, hBrush2, aColor2, nWidth1
local oFont
local aColors, aBitmap
local cData
local nWidth, nBmpRow, nBmpCol, nBmpNo, nButtonRow, nButtonCol,;
nRectWidth, nRectHeight, nRectCol, nStyle, nType, nIndent
local lTransparent := .f.
local lStretch := .f.
local lBrush := .f.
*-------------------------------------
*@CHECKBOX - César Lozada, Oct 2009
*-------------------------------------
LOCAL lCheckBox:=::lCheckBox, aRect, lChecked, lEnabled
DEFAULT lCheckBox:=.F.
*--------------------------------------
*@CHECKBOX - FINAL
*--------------------------------------
DEFAULT lHighLite := .f.,;
lSelected := .f.,;
nOrder := 0
if ( ::oEditGet != nil .and. nRow == ::oBrw:nRowSel ) .or. ::oEditLbx != nil .or. ::oBrw:nLen == 0
return nil
endif
if nCol != nil
::nDisplayCol := nCol
else
nCol := ::nDisplayCol
endif
if ::bStrData != nil
cData := Eval( ::bStrData )
if ! Empty( ::nDataStrAlign )
cData := AllTrim( cData )
endif
if isrtf( cData )
cData := "<RichText>"
endif
else
cData := ""
endif
if ::bBmpData != nil
nBmpNo := Eval( ::bBmpData )
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 := ( ::oBrw:lTransparent == .t. )
endif
hDC := ::oBrw:GetDC()
oFont := ::oDataFont
if ValType( oFont ) == "B"
oFont = Eval( oFont, Self )
endif
nWidth := ::nWidth
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
hBrush := CreateSolidBrush( aColors[ 2 ] )
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
nRectHeight := nRow + nHeight
if ! lTransparent
FillRect( hDC, {nRow, nRectCol, nRectHeight, Min( nRectCol + nRectWidth, ::oBrw:BrwWidth() - 4 ) }, hBrush )
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
*-------------------------------------
*@CHECKBOX - César Lozada, Oct 2009
*-------------------------------------
IF lCheckbox
aRect:={nRow,nCol,nRow+nHeight,nCol+nWidth}
lChecked:=Eval(::bEditValue)
lChecked:=ValType(lChecked)="L" .and. lChecked
lEnabled:=Empty(::bEditWhen) .or. Eval(::bEditWhen)
DrawFrameControl(hDC,aRect,DFC_BUTTON,;
nOr(DFCS_BUTTONCHECK,if(lChecked,DFCS_CHECKED,0),if(!lEnabled,DFCS_INACTIVE,0)))
//hDC, aRect, uType, uState
::bLDClickData:={|nR,nC,nF,oCol| ::oBrw:KeyChar(32) }
ELSE
*--------------------------------------
*@CHECKBOX - FINAL
*--------------------------------------
if nType > 1
nButtonRow := nRow
nButtonCol := nCol + nWidth - 10
nWidth -= 15
endif
if ::lProgBar
aColor2 := Eval( ::bClrProg )
hBrush1 := CreateSolidBrush( aColor2[ 1 ] )
hBrush2 := CreateSolidBrush( aColor2[ 2 ] )
nWidth1 := Min( ::Value() * nWidth / ::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 nBmpNo > 0 .and. nBmpNo <= Len( ::aBitmaps )
aBitmap := ::aBitmaps[ nBmpNo ]
nWidth -= aBitmap[ BITMAP_WIDTH ]
if ::bStrData == nil
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 )
DEFAULT aBitmap[ BITMAP_ZEROCLR ] := GetZeroZeroClr( hDC, aBitmap[ BITMAP_HANDLE ] )
if lStretch
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 ), ;
nRectHeight - nRow )
SetBkColor( hDC, nOldcolor )
/*
elseif lTransparent .or. lBrush
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 ];
,, .t., aColors[ 2 ] )
endif
endif
if !Empty( cData )
oFont:Activate( hDC )
SetTextColor( hDC, aColors[ 1 ] )
if lTransparent .or. lBrush .or. ::lProgBar
SetBkMode( hDC, 1 )
else
nOldColor := SetBkColor( hDC, aColors[ 2 ] )
endif
if ::bPaintText == nil
DrawTextEx( hDC, cData,;
{nRow, nCol, nRow + nHeight, Min( nCol + nWidth, ::oBrw:BrwWidth() - 5 ) },;
::nDataStyle )
else
Eval( ::bPaintText, Self, hDC, cData, { nRow, nCol, nRow + nHeight,Min( nCol + nWidth, ::oBrw:BrwWidth() - 5 ) } )
endif
if nOldColor != nil
SetBkcolor( hDC, nOldColor )
nOldColor := nil
endif
oFont:Deactivate( hDC )
endif
if nType > 1
if lSelected
WndBoxRaised(hDC, nButtonRow -1 , nButtonCol - 1,;
nButtonRow + nHeight, nButtonCol + 11 )
if nType == EDIT_LISTBOX .or. nType == EDIT_GET_LISTBOX
::oBtnElip:Hide()
::oBtnList:Move( nButtonRow, nButtonCol, 11, nHeight, .f.)
::oBtnList:Show()
::oBtnList:GetDC()
FillRect( hDC, {nButtonRow, nButtonCol, nButtonRow + nHeight , nButtonCol + 11 },;
::oBtnList:oBrush:hBrush )
::oBtnList:Paint()
::oBtnList:ReleaseDC()
else
::oBtnList:Hide()
::oBtnElip:Move( nButtonRow, nButtonCol, 11, nHeight, .f.)
::oBtnElip:Show()
::oBtnElip:GetDC()
FillRect( hDC, {nButtonRow, nButtonCol, nButtonRow + nHeight , nButtonCol + 11 },;
::oBtnElip:oBrush:hBrush )
::oBtnElip:Paint()
::oBtnElip:ReleaseDC()
endif
endif
endif
*-------------------------------------
*@CHECKBOX - César Lozada, Oct 2009
*-------------------------------------
ENDIF
*-------------------------------------
*@CHECKBOX - FINAL
*-------------------------------------
if hBrush != nil .and. ! lBrush
DeleteObject( hBrush )
endif
::oBrw:ReleaseDC()
return nil
*=======================================================================================
Static Function Edit( nKey ) //CLASS TXBrwColumn
LOCAL Self := HB_QSelf()
local aColors
local uValue, cPic
local nRow, nCol, nWidth, nHeight
local hBrush
local lCenter, lRight
LOCAL lCheckbox:=::lCheckbox
DEFAULT lCheckbox:=.F.
if ::bOnPostEdit == nil
MsgStop( "oCol:bOnPostEdit not defined",;
"Fivewin: Class TXBrwColumn" )
return .f.
endif
*-------------------------------------
*@CHECKBOX - César Lozada, Oct 2009
*-------------------------------------
IF lCheckbox
uValue := Eval( ::bEditValue )
IF ValType(uValue)="L" .and. (Empty(::bEditWhen) .or. Eval(::bEditWhen))
Eval( ::bEditValue, !uValue )
::oBrw:nLastEditCol := ::nPos
return .T.
ELSE
return .F.
ENDIF
ENDIF
*-------------------------------------
*@CHECKBOX - FINAL
*-------------------------------------
if ::nEditType == EDIT_LISTBOX
IF !Empty(::bEditWhen) .and. !Eval(::bEditWhen)
return .F.
ELSE
return ::ShowBtnList( nKey )
ENDIF
endif
if ::nEditType == EDIT_BUTTON
return ::RunBtnAction()
endif
if ::oEditGet != nil
::oEditGet:End()
endif
if ::bEditValue == nil
::bEditValue := ::bStrData
endif
cPic := ::cEditPicture
IF ValType(::bEditPicture)="B"
cPic:=Eval(::bEditPicture,Self:oBrw)
ENDIF
DEFAULT cPic := ""
uValue := Eval( ::bEditValue )
if ValType( uValue ) == 'D'
if !Empty( cPic ) .and. !( cPic = '@' )
cPic := '@D'
endif
if cPic = '@T'
cPic := '@D'
endif
endif
aColors := Eval( ::bClrEdit )
lCenter := ( ::nDataStrAlign == AL_CENTER )
lRight := ( ::nDataStrAlign == AL_RIGHT )
nRow := ( ( ::oBrw:nRowSel - 1 ) * ::oBrw:nRowHeight ) + ::oBrw:HeaderHeight()
hBrush := CreateSolidBrush( aColors[ 2 ] )
::EraseData( nRow, ::nDisplayCol, ::oBrw:nRowHeight , hBrush )
DeleteObject( hBrush )
if Empty( cPic ) .and. ::oBrw:nDataLines > 1
::oEditGet := TMultiGet():New( 0,0,{ | u | If(PCount()==0,uValue,uValue:= u ) },;
::oBrw,0,0,,.F.,aColors[ 1 ],aColors[ 2 ];
,,.F.,,.F.,,lCenter,lRight,.F.,,,.F.,.T.,.T. )
else
::oEditGet := TGet():New( 0,0,{ | u | If(PCount()==0,uValue,uValue:= u ) },;
::oBrw,0,0,cPic,,aColors[ 1 ],aColors[ 2 ];
,,.F.,,.F.,,.F.,,lCenter,lRight,,.F.,.f.,.T.,,.F.,,,,)
endif
IF ::oBrw:lFastEdit .and. !Empty(nKey) .and. Chr(nKey)>32
WITH OBJECT ::oEditGet
:HideSel()
:SetPos(1)
:KeyChar(nKey)
END
ENDIF
nRow := ( ( ::oBrw:nRowSel - 1 ) * ::oBrw:nRowHeight ) + ::oBrw:HeaderHeight() + 2
nCol := ::nDisplayCol + 3
nWidth := ::nWidth - 4 - 2
nHeight := ::oBrw:nRowHeight - 4 - 2
if ::nEditType > 2
nWidth -= 13
endif
if ::bEditValid != nil
::oEditGet:bValid := { | oGet, lRet | oGet:lValidating := .T., lRet := Eval( ::bEditValid, oGet, Self ), oGet:lValidating := .F., If( ! lRet, oGet:SetFocus(),), lRet }
endif
::oEditGet:bKeyDown := { | nKey | EditGetkeyDown( Self, nKey ) }
::oEditGet:bLostFocus := { | oGet, hWndFocus | EditGetLostFocus( oGet, hWndFocus, ::oBrw, ::oEditGet, Self ) }
::oEditGet:bChange := { | k, f, o | ::oBrw:nLastKey := k, .t. }
::oEditGet:nLastKey := 0
::oEditGet:Move( nRow, nCol, nWidth, nHeight, .t. )
::oEditGet:SetFocus()
****
IF !(::oBrw:lFastEdit .and. !Empty(nKey) .and. Chr(nKey)>32)
::oEditGet:SelectAll()
ENDIF
****
::oBrw:lEditMode := .T.
if ::oBtnElip != nil
::oBtnElip:Refresh()
endif
if ::oBtnList != nil
::oBtnList:Refresh()
endif
if ::lEditBorder
WndBoxIn( ::oBrw:GetDC(), nRow-1, nCol-1, nRow + nHeight + 1, nCol + nWidth + 1)
::oBrw:ReleaseDC()
endif
if nKey != nil
PostMessage( ::oEditGet:hWnd, WM_CHAR, nKey )
endif
::oBrw:nLastEditCol := ::nPos
return .t.
*=======================================================================================
Static Function KeyChar( nKey, nFlags ) //CLASS TXBrowse
LOCAL Self := HB_QSelf()
local oCol, cKey
*-------------------------------------
*@CHECKBOX - César Lozada, Oct 2009
*-------------------------------------
LOCAL lCheckbox
*-------------------------------------
*@CHECKBOX - FINAL
*-------------------------------------
if ::bKeyChar != nil
Eval( ::bKeyChar, nKey, nFlags )
endif
do case
*-------------------------------------
*@CHECKBOX - César Lozada, Oct 2009
*-------------------------------------
CASE (nKey=32 .or. nKey=VK_RETURN) .and.;
Valtype((oCol:=::SelectedCol(),lCheckbox:=oCol:lCheckbox))="L" .and. lCheckbox
IF oCol:Edit()
::DrawLine(.T.)
IF !Empty(oCol:bOnPostEdit)
Eval( oCol:bOnPostEdit, oCol, Eval( oCol:bEditValue ), 13 )
ENDIF
ENDIF
*-------------------------------------
*@CHECKBOX - FINAL
*-------------------------------------
case nKey == VK_ESCAPE
if Upper( ::oWnd:ClassName() ) == "TDIALOG" .and. ! ::lEditMode
// PostMessage( ::oWnd:hWnd, WM_KEYDOWN, VK_ESCAPE )
else
// Avoid exiting on Mdichild windows
endif
if ::lEditMode
oCol := ::SelectedCol()
if oCol:oEditLbx != nil
oCol:oEditLbx:nLastKey = VK_ESCAPE
endif
::CancelEdit()
endif
case nKey == VK_RETURN
oCol := ::SelectedCol()
if oCol:nEditType > 0
if oCol:oEditGet == nil
if oCol:bEditWhen == nil .or. Eval( oCol:bEditWhen, oCol )
return oCol:Edit()
endif
else
PostMessage( oCol:oEditGet:hWnd, WM_KEYDOWN, nKey ) //VK_RETURN )
endif
endif
case nKey == K_PGUP
::oVScroll:PageUp()
case nKey == K_PGDN
::oVScroll:PageDown()
otherwise
cKey := Chr( nKey )
oCol := ::SelectedCol()
if nKey == 32 .and. ::nMarqueeStyle <= MARQSTYLE_HIGHLCELL .and. ;
oCol:hChecked .and. oCol:bOnPostEdit != nil .and. ;
( oCol:bEditWhen == nil .or. Eval( oCol:bEditWhen, oCol ) )
Eval( oCol:bOnPostEdit, oCol, ! Eval( oCol:bEditValue ), 13 )
::DrawLine( .t. )
elseif ::lFastEdit .and. /*::nMarqueeStyle <= MARQSTYLE_HIGHLCELL .and.*/ ;
oCol:nEditType > 0 .and. oCol:IsEditKey( cKey ) .and. ;
( oCol:bEditWhen == nil .or. Eval( oCol:bEditWhen, oCol ) )
oCol:Edit( nKey )
else
If nKey == VK_BACK .and. !Empty( ::cSeek )
::Seek( Left( ::cSeek, Len( ::cSeek ) -1 ) )
elseIf nKey > 31
::Seek( ::cSeek + cKey )
Endif
Endif
endcase
return 0
//
// Static Function(s) en xBrowse.prg
*=======================================================================================
static function EditGetLostFocus( oGet, hWndFocus, oBrw, oEditGet, oCol )
local oWnd
// focus goes to another control in the same application, and not to the browse
if ( oWnd := oWndFromHwnd( hWndFocus ) ) != nil .and. ! ( oWnd == oBrw ) .and. ;
Upper( oWnd:ClassName() ) != "TGET"
oBrw:CancelEdit()
SetFocus( hWndFocus )
return nil
endif
// focus goes to another application
if GetWindowThreadProcessId( hWndFocus ) != GetWindowThreadProcessId( oBrw:hWnd )
oBrw:CancelEdit()
return nil
endif
if oEditGet != nil .and. ! oEditGet:lValidating
oCol:PostEdit()
endif
return nil
//----------------------------------------------------------------------------//
static function EditGetkeyDown( Self, nKey )
local lExit
Local cEditPicture:=::cEditPicture
IF ValType(::cEditPicture)="B"
::cEditPicture:=Eval(::cEditPicture,Self)
ENDIF
lExit := .f.
do case
case nKey == VK_ESCAPE
lExit := .t.
::oEditGet:bValid = nil
case nKey == VK_RETURN
if Empty( ::cEditPicture ) .and. ::oBrw:nDataLines > 1
if ! GetKeyState( VK_CONTROL )
lExit := .t.
endif
else
lExit := .t.
endif
case nKey == VK_DOWN .or. nKey == VK_UP
lExit := .t.
endcase
If lExit
::oEditGet:nLastKey := nKey
::oEditGet:End()
Endif
::cEditPicture:=cEditPicture
return nil
//----------------------------------------------------------------------------//
static function GetZeroZeroClr( hDC, hBmp )
local hDCMem, hOldBmp, nZeroZeroClr
hDCMem = CreateCompatibleDC( hDC )
hOldBmp = SelectObject( hDCMem, hBmp )
nZeroZeroClr = GetPixel( hDCMem,0,0)
SelectObject( hDCMem, hOldBmp )
DeleteDC( hDCMem )
return nZerozeroClr
//----------------------------------------------------------------------------//
#pragma BEGINDUMP
#include <hbapi.h>
#include <hbapiitm.h>
#include <windows.h>
HB_FUNC_STATIC ( DRAWFRAMECONTROL ) // hDC, aRect, uType, uState
{
HDC hdc = ( HDC ) hb_parnl(1); // handle to device context
UINT uType = hb_parni(3) ; // frame-control type
UINT uState = hb_parni(4); // frame-control state
RECT rct;
rct.top = hb_parnl(2,1);
rct.left = hb_parnl(2,2);
rct.bottom = hb_parnl(2,3);
rct.right = hb_parnl(2,4);
hb_retnl ( DrawFrameControl(hdc,&rct,uType,uState) );
}
#pragma ENDDUMP
// FIN DE CODIGO
//===============================================
EJEMPLO DE USO:
- Code: Select all Expand view
- #include "Fivewin.ch"
FUNCTION TEST
Local oDlg, oBrw
Local aFiles:=Directory("*.*","AD"), n
tXBrowse_Modify()
dbCreate("TestChk.dbf",{{"FILE","C",32,0},{"SIZE","N",8,0},;
{"DATE","D",8,0},{"TIME","C",8,0},{"IS_DIR","L",1,0}})
USE TestChk.dbf NEW ALIAS TEST
FOR n:=1 TO Len(aFiles)
dbAppend()
repla TEST->FILE with aFiles[n,1],TEST->SIZE with aFiles[n,2],;
TEST->DATE with aFiles[n,3],TEST->TIME with aFiles[n,4],;
TEST->IS_DIR with ("D"$aFiles[n,5])
NEXT
DEFINE DIALOG oDlg FROM 0,0 TO 20,80 TITLE "XBROWSE with CheckBoxes"
oBrw := TXBrowse():New( oDlg )
oBrw:CreateFromCode()
ACTIVATE DIALOG oDlg CENTERED;
ON INIT (oDlg:SetControl(oBrw), oBrw:aCols[5]:lCheckBox:=.T., oBrw:Gotop())
USE
return nil
//===============================================