home *** CD-ROM | disk | FTP | other *** search
- #include "xclass.ch"
- #include "inkey.ch"
- #include "set.ch"
-
- #ifndef DEFAULT
- #command DEFAULT <var> = <valor> =>;
- <var> := if( <var> == NIL, <valor>, <var> )
- #endif
-
- //Sintaxis de la clase Manten:
- // Creación: Manten( nArriba, nIzquierda, nAbajo, nDerecha, bValorARetornar,
- // lPermisoAppend, lEditable, lPermisoBorrar )
- //
- // obj:InsColumn( nPosición, objetoTBColumn )
- // Inserta una columna
- //
- // obj:DelColumn( nPosicion )
- // Borra una columna
-
- // obj:AddKey( numeroTecla, bAcción )
- // Añade una Acción a una tecla
-
- // obj:DelKey( numeroTecla )
- // Elimina la acción de una tecla
-
- // obj:DoGet()
- // Efectúa un READ sobre la casilla del cursor
-
-
- CLASS Manten
- VAR Fondo
- VAR oB
- VAR lAppend
- VAR lAppMode
- VAR lEdit
- VAR lDel
- VAR Freeze
- VAR bReturn
- VAR Tecla
- VAR bStable
- VAR aGets
- VAR aKeys
- VAR bInkey
- CONSTRUCTOR New METHOD ManNew( nTop, nLeft, nBottom, nRight, bReturn, lAppend, lEdit, lDel )
- MESSAGE Exec METHOD ManExec
- MESSAGE InsColumn METHOD ManIColumn( nPos, oCol )
- MESSAGE DelColumn BLOCK {| Self, nCol | Self:oB:delcolumn( nCol ), adel( ::aGets, nCol ), ::oB:configure() }
- MESSAGE AddKey BLOCK {| Self, nKey, bAction | aadd( ::aKeys, nKey ), aadd( ::aKeys, bAction ) }
- MESSAGE DelKey METHOD ManDelKey( nKey )
- MESSAGE DoGet METHOD ManDoGet
- END CLASS
-
- METHOD ManNew( nTop, nLeft, nBottom, nRight, bReturn, lAppend, lEdit, lDel )
- LOCAL n
- DEFAULT lAppend = .f.
- DEFAULT lEdit = .f.
- DEFAULT lDel = .f.
- DEFAULT bReturn = {|| recno() }
- ::bInkey := {|| Inkey( 0 ) }
- ::oB := tbrowsedb( nTop, nLeft, nBottom, nRight )
- ::oB:HeadSep := "═╤═"
- ::oB:colsep := " │ "
- ::oB:footSep := "═╧═"
- ::oB:ColorSpec := "W+/GB, W+/B, R+/BG, R+/B, GR+/BG, GR+/B"
- ::lAppend := lAppend
- ::lEdit := lEdit
- ::lDel := lDel
- ::bReturn := bReturn
- ::freeze := 0
- ::bStable := {|| NIL }
- ::lAppMode := .f.
- ::oB:skipblock := {|x| Skipper( x, Self ) }
- for n := 1 to fcount()
- ::oB:addcolumn( tbcolumnnew( fieldname( n ), fieldblock( fieldname(n) ) ) )
- next
- ::aGets := array( ::oB:ColCount )
- for n := 1 to ::oB:ColCount
- ::aGets[ n ]:= GetNew( 0,0, ::oB:getcolumn( n ):block, ::oB:getcolumn( n ):heading )
- next
- ::aKeys := ;
- { K_DOWN , {|obj| obj:oB:down() },;
- K_UP , {|obj| obj:oB:up() },;
- K_PGDN , {|obj| obj:oB:pageDown() },;
- K_PGUP , {|obj| obj:oB:pageUp() },;
- K_CTRL_PGUP , {|obj| obj:oB:goTop() },;
- K_CTRL_PGDN , {|obj| obj:oB:goBottom() },;
- K_RIGHT , {|obj| obj:oB:right() },;
- K_LEFT , {|obj| obj:oB:left() },;
- K_HOME , {|obj| obj:oB:home() },;
- K_END , {|obj| obj:oB:end() },;
- K_CTRL_LEFT , {|obj| obj:oB:panLeft() },;
- K_CTRL_RIGHT, {|obj| obj:oB:panRight() },;
- K_CTRL_HOME , {|obj| obj:oB:panHome() },;
- K_CTRL_END , {|obj| obj:oB:panEnd() }, ;
- K_ENTER , {|obj| obj:DoGet() }, ;
- K_DEL , {|obj| ManDel( obj ) } }
- RETURN Self
-
- METHOD ManIColumn( nPos, oCol )
- ::oB:InsColumn( nPos, oCol )
- ains( ::aGets, nPos )
- ::aGets[ nPos ] := GetNew( 0, 0, ::oB:getcolumn( nPos ):block, ::oB:getcolumn( nPos ):heading )
- ::oB:Invalidate()
- Return Self
-
- METHOD ManExec()
- LOCAL OldColor, OldCur, nFound
- ::Fondo := savescreen( ::oB:nTop, ::oB:nLeft, ::oB:nBottom + 1, ::oB:nRight + 2)
- OldColor := setcolor( ::ob:colorspec )
- OldCur := setcursor( 0 )
- Sombra( ::oB:nTop + 1, ::oB:nLeft + 2, ::oB:nBottom + 1, ::oB:nRight + 2 )
- @ ::oB:nTop, ::oB:nLeft clear to ::oB:nBottom, ::oB:nRight
- while .t.
- while( ::oB:colpos <= ::oB:freeze )
- ::oB:colpos++
- end
- ::Tecla := 0
- while ( ::Tecla := Inkey() ) == 0 .and. !::oB:stabilize()
- end
- if ::oB:stable
- if ::oB:hitbottom .and. ::lAppend .and. .not. ::lAppMode
- ::lAppMode := .t.
- ::Tecla := K_DOWN
- else
- eval( ::bStable, Self )
- ::Tecla := eval( ::bInkey )
- endif
- endif
- if ::Tecla == K_ESC
- exit
- endif
- if( nFound := ASCAN( ::aKeys, ::Tecla ) ) != 0
- EVAL( ::aKeys[ ++nFound ], Self )
- endif
- do case
- case ::Tecla == K_UP .or. ::Tecla == K_PGUP
- if ::lAppMode
- ::lAppMode := .f.
- ::oB:refreshall()
- endif
- case ::Tecla == K_CTRL_PGDN .or. ::Tecla == K_CTRL_PGUP
- ::lAppMode := .f.
- endcase
- end
- setcolor( OldColor )
- restscreen( ::oB:nTop, ::oB:nLeft, ::oB:nBottom + 1, ::oB:nRight + 2, ::Fondo)
- setcursor( OldCur )
- RETURN eval( ::bReturn, ::oB )
-
- STATIC FUNCTION Skipper( n, o )
- LOCAL i := 0
- if n == 0 .or. lastrec() == 0
- dbskip( 0 )
- elseif n > 0 .and. recno() != lastrec() + 1
- do while i < n
- dbskip( 1 )
- if ( eof() )
- if ( o:lAppMode .and. o:lAppend )
- i++
- else
- dbskip( -1 )
- endif
-
- exit
- endif
- i++
- enddo
- elseif n < 0
- do while i > n
- dbskip( -1 )
- if ( bof() )
- exit
- endif
- i--
- enddo
- endif
- return i
-
- METHOD ManDoGet()
- LOCAL Get, OldCursor := setcursor( 1 )
- if ::lEdit .or. ( ::lAppend .and. ::lAppMode )
- while !::oB:stabilize()
- end
- if ::lAppMode .and. recno() == Lastrec() + 1
- dbappend()
- endif
- Get := ::aGets[ ::oB:colpos ]
- get:row := row()
- get:col := col()
- readmodal( {get} )
- setcursor( OldCursor )
- if lastkey() != 27 .and. upper( Get:name ) $ upper( indexkey() )
- ::oB:refreshall()
- else
- ::oB:refreshcurrent()
- endif
- endif
- if lastkey() != 27
- keyboard( chr( K_RIGHT ) )
- endif
- Return NIL
-
- METHOD ManDelKey( nKey )
- LOCAL n, bRes
- if( n := ascan( ::aKeys, nKey ) ) != 0
- adel( ::aKeys, n )
- bRes := ::aKeys[ n ]
- adel( ::aKeys, n )
- else
- bRes := NIL
- endif
- RETURN bRes
-
- STATIC PROCEDURE ManDel( oMan )
- if oMan:lDel
- dbdelete()
- dbskip()
- if eof()
- dbskip( -1 )
- endif
- oMan:oB:refreshall()
- endif
- RETURN
-
- #define PARAMS nTop, nLeft, nBottom, nRight
-
- FUNCTION Sombra( PARAMS )
- LOCAL cFondo := savescreen( PARAMS )
- restscreen( PARAMS, transform( cFondo, replicate( "X" + chr( 7 ), ;
- len( cFondo ) / 2 ) ) )
- RETURN cFondo
-
-