Se que hay mas gente que ha variado la clase, si disponemos de _ mejoraremos la clase entre todos.
Code: Select all
METHOD Edit( uVar, nCell, nKey, nKeyFlags, cPicture, bValid, nClrFore, ;
nClrBack ) CLASS TSBrowse
Local nRow, nHeight, oFont, cType, uValue, nI, aGet, oCol, cMsg, aRct, ;
cError, bChange, lSpinner, bUp, bDown, bMin, bMax, nStartX, ;
nWidth, lCombo, lMulti, nCol, lLogicDrop, nTxtHeight, ;
nFireKey := ::nFireKey
Default nCell := ::nCell, ;
::lPostEdit := .F., ;
::lNoPaint := .F.
oCol := ::aColumns[ nCell ]
Default ::nHeightSuper := 0, ;
nKey := VK_RETURN, ;
nKeyFlags := 0, ;
nFireKey := VK_F2, ;
uVar := Eval( oCol:bData ), ;
cPicture := oCol:cPicture, ;
bValid := oCol:bValid, ;
nClrFore := oCol:nClrEditFore, ;
nClrBack := oCol:nClrEditBack
uValue := uVar
cType := If( Empty( oCol:cDataType ), ValType( uValue ), oCol:cDataType )
cMsg := oCol:cMsgEdit
cError := oCol:cError
bChange := oCol:bChange
lSpinner := oCol:lSpinner
bUp := oCol:bUp
bDown := oCol:bDown
bMin := oCol:bMin
bMax := oCol:bMax
nStartX := 0
lCombo := lMulti := .F.
::oGet := ::oWnd:bValid
::oWnd:bValid := { || ! ::lEditing }
If oCol:bPassWord != Nil
If ! Eval( oCol:bPassWord, uValue, nCell, ::nAt, Self )
Return Nil
EndIf
EndIf
::lEditing := .T.
::lHitBottom := .F.
If ::nLen > 0
::lNoPaint := .T.
EndIf
If oCol:bPrevEdit != Nil
Eval( oCol:bPrevEdit, uValue, Self )
EndIf
cMsg := If( ValType( cMsg ) == "B", Eval( cMsg, Self, nCell ), cMsg )
If cType == "L" .and. oCol:lCheckBox
If nKey != VK_RETURN
If Upper( Chr( nKey ) ) $ "YCST1"
::lChanged := uVar == .F.
uVar := .T.
ElseIf Upper( Chr( nKey ) ) $ "FN0"
::lChanged := uVar == .T.
uVar := .F.
ElseIf nKey == VK_SPACE
uVar := ! uVar
::lChanged := .T.
Else
Return 0
EndIf
::lHasChanged := If( ::lChanged, .T., ::lHasChanged )
::oWnd:nLastKey := VK_RETURN
::PostEdit( uVar, nCell, bValid ) //... fgondi. Añadido parametro bValid
::lPostEdit := .F.
Return 0
Else
::lPostEdit := .T.
::lChanged := .F.
::oWnd:nLastKey := nKey
::PostEdit( uVar, nCell, bValid ) //... fgondi. Añadido parametro bValid
::lPostEdit := .F.
Return 0
EndIf
EndIf
If oCol:bExtEdit != Nil // external edition
::lNoPaint := ::lEditing := .F.
uVar := Eval( oCol:bExtEdit, uValue, Self )
::lChanged := ValType( uVar ) != ValType( uValue ) .or. uVar != uValue
::lPostEdit := .T.
::oWnd:nLastKey := VK_RETURN
::PostEdit( uVar, nCell, bValid )
Return Nil
EndIf
oFont := If( oCol:oFontEdit != Nil, oCol:oFontEdit, ;
If( oCol:oFont != Nil, oCol:oFont, ::oFont ) )
If oCol:oEdit != Nil
oCol:oEdit:End()
Endif
If ::nFreeze > 0
For nI := 1 To Min( ::nFreeze , nCell - 1 )
nStartX += ::GetColSizes()[ nI ]
Next
EndIf
For nI := ::nColPos To nCell - 1
nStartX += ::GetColSizes()[ nI ]
Next
nClrFore := If( ValType( nClrFore ) == "B", ;
Eval( nClrFore, ::nAt, nCell, Self ), nClrFore )
nClrBack := If( ValType( nClrBack ) == "B", ;
Eval( nClrBack, ::nAt, nCell, Self ), nClrBack )
nRow := ::nRowPos - 1
nRow := ( nRow * ::nHeightCell ) + ::nHeightHead + ;
::nHeightSuper + If( oCol:l3DLook, 2, 0 )
nCol := nStartX + If( oCol:l3DLook, 2, 0 )
nWidth := ::GetColSizes()[ nCell ] - If( oCol:l3DLook, 4, 2 )
nHeight := ::nHeightCell - If( oCol:l3DLook, 3, 1 )
If oCol:cResName != Nil
oCol:oEdit := TSBtnGet():New( 0, 0, bSETGET( uValue ), Self, 0, 0, ;
cPicture,, nClrFore, nClrBack, oFont,,,, ;
cMsg,,,,, bChange,,, .T.,, ;
oCol:cResName, oCol:bAction, ;
lSpinner .and. cType $ "ND", bUp, bDown, ;
bMin, bMax, oCol:nBmpWidth )
oCol:oEdit:Hide()
oCol:oEdit:nFireKey := nFireKey
oCol:oEdit:aFill := oCol:aFill
oCol:oEdit:lFixCaret := ::lFixCaret
ElseIf ( cType == "C" .and. Chr( 13 ) $ uValue ) .or. cType == "M"
Default uValue := ""
If ::nMemoHE == Nil
If ! Empty( uValue )
nHeight := Max( 4, StrCharCount( uValue, Chr( 10 ) ) )
Else
nHeight := 4
EndIf
Else
nHeight := ::nMemoHE
EndIf
aRct := GetClientRect( ::hWnd )
If ::nMemoWE == Nil .or. Empty( ::nMemoWE )
nWidth := Max( nWidth, GetTextWidth( 0, SubStr( uValue, 1, ;
At( Chr( 13 ), uValue ) - 1 ), ;
If( oFont != Nil, oFont:hFont, 0 ) ) )
nWidth := Min( nWidth, Int( aRct[ 4 ] * .8 ) )
Else
nWidth := ::nMemoWE
EndIf
nTxtHeight := SBGetHeight( ::hWnd, If( oFont != Nil, oFont:hFont, 0 ), 0 )
While ( nRow + ( nTxtHeight * nHeight ) ) > aRct[ 3 ]
nRow -= nTxtHeight
EndDo
nI := nCol + nWidth - aRct[ 4 ]
nCol -= If( nI < 0, 0, nI )
nCol := Max( 10, nCol )
nHeight *= nTxtHeight
If SubStr( uValue, 1, 4 ) == GTF5
oCol:oEdit := TSFGet():New( 0, 0, bSETGET( uValue ), Self, 0, 0, oFont )
oCol:oEdit:OnResize := {||oCol:oEdit:VScrAdjust()}
Else
oCol:oEdit := TSMulti():New( 0, 0, bSETGET( uValue ), Self, 0, 0, ;
oFont,,nClrFore, nClrBack )
oCol:oEdit:bGotFocus := { || oCol:oEdit:HideSel(), oCol:oEdit:SetPos( 0 ) }
EndIf
lMulti := .T.
oCol:oEdit:Hide()
SetWindowLong( oCol:oEdit:hWnd, GWL_STYLE, nOr( oCol:oEdit:nStyle, WS_THICKFRAME ) )
ElseIf ( cType == "L" .and. ::lLogicDrop ) .or. oCol:lComboBox
lCombo := .T.
If oCol:lComboBox
aGet := oCol:aItems
If Empty( aGet )
Return Nil
EndIf
If nKey == VK_RETURN
If oCol:cDataType != Nil .and. oCol:cDataType == "N"
uValue := Max( 1, AScan( aGet, AllTrim( uValue ) ) )
Else
uValue := aGet[ Max( 1, AScan( aGet, AllTrim( uValue ) ) ) ]
EndIf
Else
If oCol:cDataType != Nil .and. oCol:cDataType == "N"
uValue := Max( 1, AScan( aGet, Upper( Chr( nKey ) ) ) )
Else
uValue := aGet[ Max( 1, AScan( aGet, Upper( Chr( nKey ) ) ) ) ]
EndIf
EndIf
nHeight := Max( 10, Min( 10, Len( aGet ) ) ) * ::nHeightCell
Else
aGet := { ::aMsg[ 1 ], ::aMsg[ 2 ] }
If nKey == VK_RETURN
uValue := If( uValue, 1, 2 )
EndIf
nHeight := ::nHeightCell * 2
EndIf
nRow -= 4
oCol:oEdit := TSCombo():New( 1000, 0, bSETGET( uValue ), aGet, ;
0, 0, Self,,bChange,, nClrFore, ;
nClrBack, .T., oFont, cMsg )
oCol:oEdit:bCloseUp := {|o|o:PostMsg( WM_KEYDOWN, VK_RETURN, 0 )}
oCol:oEdit:lAppend := ::lAppendMode
oCol:oEdit:Hide()
Else
oCol:oEdit := TSGet():New( 0, 0, bSETGET( uValue ), Self, 0, 0, ;
cPicture,, nClrFore, nClrBack, oFont,,,, ;
cMsg,,,,, bChange,,, .T.,, ;
lSpinner .and. cType $ "ND", bUp, bDown, ;
bMin, bMax )
oCol:oEdit:Hide()
oCol:oEdit:aFill := oCol:aFill
oCol:oEdit:lFixCaret := ::lFixCaret
EndIf
oCol:oEdit:bLostFocus := { | nKey | ::EditExit( nCell, nKey, uValue, ;
bValid, .T. ) }
oCol:oEdit:bKeyDown := { | nKey, nFlags, lExit | ;
If( lExit != Nil .and. lExit, ;
::EditExit( nCell, nKey, uValue, bValid ), ;
Nil ) }
oCol:oEdit:oJump := Self
oCol:oEdit:Move( nRow, nCol, nWidth, nHeight, ! lCombo )
If oCol:cResName != Nil
oCol:oEdit:Default()
EndIf
oCol:oEdit:SetFocus()
if oCol:oEdit=NIL
return NIL
endif
If nKey != Nil .and. nKey > 31
If ! lCombo .and. ! lMulti
oCol:oEdit:lRightLeftExit := .T.
oCol:oEdit:KeyChar( nKey, nKeyFlags )
EndIf
Endif
oCol:oEdit:Show()
::SetMsg( oCol:cMsgEdit )
If oCol:bEditing != Nil
Eval( oCol:bEditing, uVar, Self )
EndIf
Return Nil
Code: Select all
#ifdef __OLE__
METHOD ExcelOle( cXlsFile, lActivate, oMeter, cTitle, ;
oFont, lSave ) CLASS TSBrowse
Local oExcel, oBook, oSheet, nRow, nCol, uData, nEvery, oRange, cRange, cCell, ;
bError, cText, oClip, nStart, ;
nLine := 1, ;
nCount := 0, ;
nRecNo := ( ::cAlias )->( RecNo() ), ;
nAt := ::nAt
Default lActivate := Empty( cXlsFile ), ;
cTitle := "", ;
lSave := .F.
CursorWait()
::lNoPaint := .F.
If oMeter != Nil
oMeter:nTotal := ( ::nLen + 1 ) * Len( ::aColumns ) + 30
oMeter:Set( 0 )
oMeter:Refresh()
nEvery := Max( 1, Int( oMeter:nTotal * .02 ) ) // refresh ometer every 2 %
EndIf
cXlsFile := AllTrim( StrTran( Upper( cXlsFile ), ".XLS" ) )
cTitle := AllTrim( cTitle )
bError := ErrorBlock( { | x | Break( x ) } )
Begin Sequence
oExcel := TOleAuto():New("Excel.Application")
Recover
ErrorBlock( bError )
CursorArrow()
MsgStop( "No Ole.lib searched", "Error" )
Return Nil
End Sequence
ErrorBlock( bError )
If oMeter != Nil
nCount -= 15
oMeter:Set( nCount )
EndIf
oExcel:WorkBooks:Add()
oBook := oExcel:Get( "ActiveWorkBook")
oSheet := oExcel:Get( "ActiveSheet" )
If oMeter != Nil
nCount -= 15
oMeter:Set( nCount )
EndIf
( ::cAlias )->( Eval( ::bGoTop ) )
cText := ""
For nRow := 1 To ::nLen
If nRow == 1
If ! Empty( cTitle )
oSheet:Cells( nLine++, 1 ):Value := AllTrim( cTitle )
oSheet:Range( "A1:" + Chr( 64 + Len( ::aColumns ) ) + ;
"1" ):Set( "HorizontalAlignment", 7 )
++nLine
nStart := nLine
Else
nStart := 1
EndIf
For nCol := 1 To Len( ::aColumns )
If ::aColumns[ nCol ]:lBitMap .or. (nCol=1 .and. !Empty(::hBmpCursor))
Loop
EndIf
uData := If( ValType( ::aColumns[ nCol ]:cHeading ) == "B", ;
Eval( ::aColumns[ nCol ]:cHeading ), ;
::aColumns[ nCol ]:cHeading )
If ValType( uData ) != "C"
Loop
EndIf
uData := StrTran( uData, CRLF, ' ' ) // fgondi. Cambio chr(10) por ' '
cText += uData + Chr( 9 )
If oMeter != Nil
If nCount % nEvery == 0
oMeter:Set( nCount )
EndIf
nCount ++
EndIf
Next
cText += Chr( 13 )
EndIf
For nCol := 1 To Len( ::aColumns )
If ::aColumns[ nCol ]:lBitMap .or. (nCol=1 .and. !Empty(::hBmpCursor))
Loop
EndIf
uData := Eval( ::aColumns[ nCol ]:bData )
If ValType( uData ) == "C"
uData := StrTran( uData, CRLF, ' ' ) // fgondi. Cambio chr(10) por ' '
EndIf
If ::aColumns[ nCol ]:cPicture != Nil
uData := Transform( uData, ::aColumns[ nCol ]:cPicture )
EndIf
if nRow == 1 .and. ValType( uData )=="C" // fgondi. Formatear las columnas con texto para poder ver textos como '192492456'
oRange := cMakeRange( 2, nCol, 65536, nCol )
oRange := oSheet:Range( oRange )
oRange:Set("NumberFormat", '@' )
endif
uData := IIF( ValType( uData )=="D", DtoC( uData ), ;
IIF( ValType( uData )=="N", Str( uData ) , ;
IIF( ValType( uData )=="L", IIF( uData ,".T." ,".F." ), uData ) ) )
cText+=alltrim( uData ) + Chr( 9 )
If oMeter != Nil
If nCount % nEvery == 0
oMeter:Set( nCount )
EndIf
nCount ++
EndIf
Next
::Skip( 1 )
cText += Chr( 13 )
++nLine
/*
Cada 20k volcamos el texto a la hoja de Excel , usando el portapapeles , algo muy rapido y facil ;-)
Every 20k set text into excel sheet , using Clipboard , very easy and faster.
*/
IF Len( cText ) > 20000
oClip := TClipBoard():New()
oClip:Clear()
oClip:SetText( cText )
cCell := "A" + Alltrim( Str( nStart ) )
oRange := oSheet:Range( cCell )
oRange:Select()
oSheet:Paste()
oClip:End()
cText := ""
nStart := nLine + 1
EndIf
Next
If ::lIsDbf
( ::cAlias )->( DbGoTo( nRecNo ) )
EndIf
::nAt := nAt
If Len( cText ) > 0
oClip := TClipBoard():New()
oClip:Clear()
oClip:SetText( cText )
cCell := "A" + Alltrim( Str( nStart ) )
oRange := oSheet:Range( cCell )
oRange:Select()
oSheet:Paste()
oClip:End()
cText := ""
EndIf
cRange := "A3:" + Chr( 64 + Len( ::aColumns ) ) + ;
Alltrim( Str( oSheet:UsedRange:Rows:Count() ) )
oRange := oSheet:Range( cRange )
If oFont != Nil // let the programmer to decide the font he wants, otherwise use Excel's default
oRange:Font:Name := oFont:cFaceName
oRange:Font:Size := oFont:nSize()
oRange:Font:Bold := oFont:lBold
EndIf
oRange:Borders():LineStyle := 1
oRange:Columns:AutoFit()
If oMeter != Nil
oMeter:Set( oMeter:nTotal )
EndIf
If cXlsFile != Nil .and. lSave
oBook:SaveAs( cXlsFile, -4143 ) // -4143 = Normal
EndIf
oSheet:Range( "A1" ):Select()
CursorArrow()
If lActivate
oExcel:Visible := .T.
EndIf
OleUninitialize()
Return Nil
#endif // __OLE__
Code: Select all
METHOD LDblClick( nRowPix, nColPix, nKeyFlags ) CLASS TSBrowse
Local uTemp, uVal, nBParam, ;
nLines := ::nRowCount(), ;
nClickRow := ::GetTxtRow( nRowPix ), ;
nCol := ::nAtCol( nColPix ), ;
uPar1 := nRowPix, ;
uPar2 := nColPix, ;
aMoveCell := { {|| ::GoRight() }, {|| ::GoDown() }, ;
{|| ::goLeft() }, {|| ::GoUp() }, ;
{|| ::GoNext() } }, ;
bRecLock := If( ! Empty( ::bRecLock ), ::bRecLock, ;
{|| ( ::cAlias )->( RLock() ) } ), ;
bAddRec := If( ! Empty( ::bAddRec ), ::bAddRec, ;
{|| ( ::cAlias )->( dbAppend() ), ! NetErr() } )
If ::lDrag
Return Super:LDblClick( nRowPix, nColPix, nKeyFlags )
EndIf
nBParam := ::aColumns[ nCol ]:nBParam
::oWnd:nLastKey := 0
uPar1 := If( nBParam == 2, TSPoint():New( uPar1, uPar2 ), ;
If( nBParam == 1, nClickRow, uPar1 ) )
uPar2 := If( nBParam == 2, TSPoint():New( nClickRow, nCol ), ;
If( nBParam == 1, nCol, uPar2 ) )
If ( nClickRow == ::nRowPos .and. nClickRow > 0 ) .or. ;
( nClickRow == ::nRowPos .and. ! ::lDrawHeaders )
If ::lCellBrw .and. ::IsEditable( nCol )
If ValType( Eval( ::aColumns[ nCol ]:bData ) ) == "L" .and. ;
::aColumns[ nCol ]:lCheckBox // virtual checkbox
::PostMsg( WM_CHAR, VK_SPACE, 0 )
Else
::PostMsg( WM_KEYDOWN, VK_RETURN, 0 )
EndIf
Return 0
ElseIf ::lCanSelect
uVal := If( ::lIsDbf, ( ::cAlias )->( RecNo() ), ::nAt )
If ( uTemp := AScan( ::aSelected, uVal ) ) > 0
ADel( ::aSelected, uTemp )
ASize( ::aSelected, ( Len( ::aSelected ) - 1 ) )
::DrawSelect()
If ::bSelected != Nil
Eval( ::bSelected, Self, uVal, .F. )
EndIf
Else
AAdd( ::aSelected, uVal )
::DrawSelect()
If ::bSelected != Nil
Eval( ::bSelected, Self, uVal, .T. )
EndIf
EndIf
If ::bLDblClick != Nil
Eval( ::bLDblClick, uPar1, uPar2, nKeyFlags )
EndIf
ElseIf ::bLDblClick != nil
Eval( ::bLDblClick, uPar1, uPar2, nKeyFlags )
EndIf
ElseIf nClickRow == 0 .and. ::lDrawHeaders
::SetOrder( nCol ) // fgondi. ::SetOrder( ::nAtCol( nColPix, .T. ) )
EndIf
Return Self