home *** CD-ROM | disk | FTP | other *** search
- // Tb03.prg
- //
- // Simple database browse with added cosmetics
- // Allows user to resize and move the display
- // Compile with /a /m /n /w
- // Link with Nantucket's Dict.obj for the dictionary routines
-
- #include "Inkey.ch"
- #include "Tbutils.ch" // For DEF_ .. Separator characters
-
- // Key press to enter move mode
- #define K_MOVE_KEY K_F2
-
- FUNCTION Tb03
-
- FIELD Lname, Fname, Addr1, Addr2, Addr3, Addr4 IN TbDbf1
-
- LOCAL oTbr := TBrowseDb(10, 20, 20, 60)
- LOCAL oTbc1 := TBColumnNew("Last name", {|| Lname })
- LOCAL oTbc2 := TBColumnNew("First name", {|| Fname })
- LOCAL oTbc3 := TBColumnNew("Address 1", {|| Addr1 })
- LOCAL oTbc4 := TBColumnNew("Address 2", {|| Addr2 })
- LOCAL oTbc5 := TBColumnNew("Address 3", {|| Addr3 })
- LOCAL oTbc6 := TBColumnNew("Address 4", {|| Addr4 })
- LOCAL nKey
- LOCAL lExitRequested
- LOCAL aWin
-
- oTbr:colSep := DEF_CSEP
- oTbr:headSep := DEF_HSEP
- oTbr:footSep := DEF_FSEP
-
- CLEAR SCREEN
-
- // First save the tbrowse window in the tbrowse object's
- // cargo instance variable
- oTbr:cargo := DictNew()
- aWin := { oTbr:nTop - 1, oTbr:nLeft - 1, ;
- oTbr:nBottom + 1, oTbr:nRight + 1, ;
- SaveScreen(oTbr:nTop - 1, oTbr:nLeft - 1, ;
- oTbr:nBottom + 1, oTbr:nRight + 1) }
-
- DictPut(oTbr:cargo, "Tbrowse Window", aWin)
-
- // Frame the tbrowse window
- @ oTbr:nTop - 1, oTbr:nLeft - 1 TO ;
- oTbr:nBottom + 1, oTbr:nRight + 1
-
- USE TbDbf1
-
- oTbr:addColumn(oTbc1)
- oTbr:addColumn(oTbc2)
- oTbr:addColumn(oTbc3)
- oTbr:addColumn(oTbc4)
- oTbr:addColumn(oTbc5)
- oTbr:addColumn(oTbc6)
-
- lExitRequested := .F.
- DO WHILE !lExitRequested
- DO WHILE !oTbr:stabilize()
- ENDDO
- nKey := InKey(0)
-
- DO CASE
- CASE nKey == K_DOWN; oTbr:down()
- CASE nKey == K_UP; oTbr:up()
- CASE nKey == K_PGDN; oTbr:pageDown()
- CASE nKey == K_PGUP; oTbr:pageUp()
- CASE nKey == K_CTRL_PGUP; oTbr:goTop()
- CASE nKey == K_CTRL_PGDN; oTbr:goBottom()
- CASE nKey == K_RIGHT; oTbr:right()
- CASE nKey == K_LEFT; oTbr:left()
- CASE nKey == K_HOME; oTbr:home()
- CASE nKey == K_END; oTbr:end()
- CASE nKey == K_CTRL_LEFT; oTbr:panLeft()
- CASE nKey == K_CTRL_RIGHT; oTbr:panRight()
- CASE nKey == K_CTRL_HOME; oTbr:panHome()
- CASE nKey == K_CTRL_END; oTbr:panEnd()
- CASE nKey == K_MOVE_KEY; TBMove(oTbr)
- CASE nKey == K_ESC; lExitRequested := .T.
- ENDCASE
- ENDDO
-
- RETURN NIL
-
-
- FUNCTION TBMove(oTbr)
-
- TBTopLeftMove(oTbr)
- TBBottRightMove(oTbr)
-
- RETURN NIL
-
-
- FUNCTION TBTopLeftMove(oTbr)
-
- LOCAL nKey, lMoved, nDictEntry, aWin
-
- // first redraw the top and left frame blinking
- @ oTbr:nTop - 1, oTbr:nLeft - 1, ;
- oTbr:nTop - 1, oTbr:nRight + 1 ;
- BOX chr(218) + chr(196) + chr(191) COLOR "N/W*,W/N"
-
- @ oTbr:nTop - 1, oTbr:nLeft - 1, ;
- oTbr:nBottom + 1, oTbr:nLeft - 1 ;
- BOX chr(191) + chr(179) + chr(217) COLOR "N/W*,W/N"
-
- nKey := inkey(0)
- lMoved := .F.
- DO WHILE !(nKey == K_ESC)
- DO CASE
- CASE nKey == K_UP
- IF oTbr:nTop > 1
- oTbr:nTop--
- lMoved := .T.
- ENDIF
-
- CASE nKey == K_DOWN
- IF oTbr:nTop < oTbr:nBottom
- oTbr:nTop++
- lMoved := .T.
- ENDIF
-
- CASE nKey == K_LEFT
- IF oTbr:nLeft > 1
- oTbr:nLeft--
- lMoved := .T.
- ENDIF
-
- CASE nKey == K_RIGHT
- IF oTbr:nLeft < oTbr:nRight
- oTbr:nLeft++
- lMoved := .T.
- ENDIF
- ENDCASE
-
- IF lMoved
- // First get our window from cargo dictionary
- aWin := DictAt(oTbr:cargo, "Tbrowse Window")
- Restscreen(aWin[1], aWin[2], ;
- aWin[3], aWin[4], ;
- aWin[5])
-
- // First save the tbrowse window in the tbrowse object's
- // cargo instance variable
- aWin := { oTbr:nTop - 1, oTbr:nLeft - 1, ;
- oTbr:nBottom + 1, oTbr:nRight + 1, ;
- SaveScreen(oTbr:nTop - 1, oTbr:nLeft - 1, ;
- oTbr:nBottom + 1, oTbr:nRight + 1) }
- DictPut(oTbr:cargo, "Tbrowse Window", aWin)
-
- // test here
- DO WHILE NextKey() = 0 .AND. !oTbr:stabilize()
- ENDDO
-
- // Redraw the top and left frame blinking
- @ oTbr:nTop - 1, oTbr:nLeft - 1 TO ;
- oTbr:nTop - 1, oTbr:nRight + 1 COLOR "N/W*,W/N"
-
- @ oTbr:nTop - 1, oTbr:nLeft - 1 TO ;
- oTbr:nBottom + 1, oTbr:nLeft - 1 COLOR "N/W*,W/N"
- lMoved := .F.
-
- ENDIF
-
- nKey := InKey(0)
- ENDDO
-
- // Now redraw the frame
- @ oTbr:nTop - 1, oTbr:nLeft - 1 TO ;
- oTbr:nBottom + 1, oTbr:nRight + 1
-
- RETURN NIL
-
-
- FUNCTION TBBottRightMove(oTbr)
-
- LOCAL nKey, lMoved, aWin
-
- // first redraw the frame blinking
-
- @ oTbr:nTop - 1, oTbr:nRight + 1 TO ;
- oTbr:nBottom + 1, oTbr:nRight + 1 COLOR "N/W*,W/N"
-
- @ oTbr:nBottom + 1, oTbr:nLeft - 1 TO ;
- oTbr:nBottom + 1, oTbr:nRight + 1 COLOR "N/W*,W/N"
-
- nKey := InKey(0)
- lMoved := .F.
- DO WHILE !(nKey == K_ESC)
- DO CASE
- CASE nKey == K_UP
- IF oTbr:nBottom > oTbr:nTop
- oTbr:nBottom--
- lMoved := .T.
- ENDIF
-
- CASE nKey == K_DOWN
- IF oTbr:nBottom < maxrow() - 1
- oTbr:nBottom++
- lMoved := .T.
- ENDIF
-
- CASE nKey == K_LEFT
- IF oTbr:nRight > oTbr:nLeft
- oTbr:nRight--
- lMoved := .T.
- ENDIF
-
- CASE nKey == K_RIGHT
- IF oTbr:nRight < maxcol() - 1
- oTbr:nRight++
- lMoved := .T.
- ENDIF
- ENDCASE
-
- IF lMoved
- // First get our window from cargo dictionary
- aWin := DictAt(oTbr:cargo, "Tbrowse Window")
- RestScreen(aWin[1], aWin[2], ;
- aWin[3], aWin[4], ;
- aWin[5])
-
- // First save the tbrowse window in the tbrowse object's
- // cargo instance variable
- aWin := { oTbr:nTop - 1, oTbr:nLeft - 1, ;
- oTbr:nBottom + 1, oTbr:nRight + 1, ;
- SaveScreen(oTbr:nTop - 1, oTbr:nLeft - 1, ;
- oTbr:nBottom + 1, oTbr:nRight + 1) }
-
- DictPut(oTbr:cargo, "Tbrowse Window", aWin)
-
- DO WHILE !oTbr:stabilize()
- ENDDO
-
- @ oTbr:nTop - 1, oTbr:nRight + 1 TO ;
- oTbr:nBottom + 1, oTbr:nRight + 1 COLOR "N/W*,W/N"
-
- @ oTbr:nBottom + 1, oTbr:nLeft - 1 TO ;
- oTbr:nBottom + 1, oTbr:nRight + 1 COLOR "N/W*,W/N"
-
- lMoved := .F.
-
- ENDIF
-
- nKey := InKey(0)
- ENDDO
-
- // Now redraw the frame
- @ oTbr:nTop - 1, oTbr:nLeft - 1 TO ;
- oTbr:nBottom + 1, oTbr:nRight + 1
-
- RETURN NIL