xHarbour Reference Documentation > Class Reference (textmode) |
|
|
TBrowse()
Creates a new TBrowse object.
Syntax
TBrowse():new( [<nTop>] , ;
[<nLeft>] , ;
[<nBottom>], ;
[<nRight>] ) --> oTBrowse
Arguments
- <nTop>
- This is the numeric screen coordinate for the top row of the browse display.
It defaults to zero and is assigned to the instance variable :nTop.
- <nLeft>
- This is the numeric screen coordinate for the left column of the browse display.
It defaults to zero and is assigned to the instance variable :nLeft.
- <nBottom>
- This is the numeric screen coordinate for the bottom row of the browse display.
It defaults to MaxRow() and is assigned to the instance variable :nBottom.
- <nRight>
- This is the numeric screen coordinate for the right column of the browse display.
It defaults to MaxCol() and is assigned to the instance variable :nRight.
Return
Function TBrowse() returns a new TBrowse object and method :new() initializes
the object.
Description
TBrowse objects are used in text mode applications to display tabular data organized
in rows and columns in a rectangular area on the screen. Common data sources for TBrowse
objects are database files or arrays. In order to display such data, a TBrowse object must
receive objects of the TBColumn() class which contain all information
required for displaying a single column in a browse view. In addition, a TBrowse
object must be assigned code blocks required for navigating the row pointer
of the data source as a response to user input. The example below demonstrates
all steps required to create a fully functional browse view with TBrowse and TBColumn
objects.
Instance variables
- :autoLite
- Logical value for automatic highlighting of the browse cursor.
- :border
- Character string defining a border to display around the browse display.
- :cargo
- Instance variable for user-defined purposes.
- :colCount
- Number of columns maintained by the TBrowse object
- :colorSpec
- Color string for the TBrowse display.
- :colPos
- Numeric column position of the browse cursor.
- :colSep
- Characters used as vertical column separator.
- :footSep
- Characters used as horizontal separator for column footings.
- :freeze
- Number of columns to freeze in the browse display.
- :goBottomBlock
- Code block that navigates the data source to the last row.
- :goTopBlock
- Code block that navigates the data source to the first row.
- :headSep
- Character used as horizontal separator for column headings.
- :hitBottom
- Indicates that the browser reached the end of the data source.
- :hitTop
- Indicates that the browser reached the beginning of the data source.
- :leftVisible
- Numeric position of the leftmost unfrozen column in the browse display.
- :mColPos
- Numeric column position of the mouse cursor within the browse display.
- :message
- Character string to display in the Get system's status line
- :mRowPos
- Numeric row position of the mouse cursor within the browse display.
- :nBottom
- Numeric bottom row coordinate of the browse display.
- :nLeft
- Numeric left column coordinate of the browse display
- :nRight
- Numeric right column coordinate of the browse display
- :nTop
- Numeric top row coordinate of the browse display
- :rightVisible
- Numeric position of the rightmost unfrozen column in the browse display.
- :rowCount
- Number of data rows in the browse display.
- :rowPos
- Numeric row position of the browse cursor.
- :skipBlock
- Code block that navigates the row pointer of the data source.
- :stable
- Indicates that the browse display is stable.
Methods for columns
- :addColumn( <oTBColumn> ) --> oTBColumn
- Adds a TBColumn object to a TBrowse object.
- :colWidth( <nColPos> ) --> nColumnWidth
- Returns the width of a column in the browse display.
- :delColumn( <nColPos> ) --> oTBColumn
- Removes a TBColumn object from a TBrowse object.
- :getColumn( <nColPos> ) --> oTBColumn
- Retrieves a TBColumn object from a TBrowse object.
- :insColumn( <nColPos>, <oTBColumn> ) --> oTBColumn
- Inserts a TBColumn object into a TBrowse object.
- :setColumn( <nColPos>, <oTBColumnNew> ) --> oTBColumnOld
- Replaces a TBColumn object within a TBrowse object
Display methods
- :colorRect( <aTLBR>, <aColorIndex> ) --> self
- Changes the color of a group of cells in the browse display.
- :configure() --> self
- Reconfigures the internal data of a TBrowse object.
- :deHilite() --> self
- Dehighlights the browse cursor.
- :forceStable() --> self
- Performs a complete stabilization of the browse display.
- :hilite() --> self
- Highlights the browse cursor.
- :invalidate() --> self
- Invalidates the entire browse display.
- :refreshAll() --> self
- Invalidates all data rows of the browse display.
- :refreshCurrent() --> self
- Invalidates the current data row of the browse display.
- :setStyle( <nStyle>, [<lNewOnOff>] ) --> lOldOnOff
- Retrieves or changes a browse style.
- :stabilize() --> lIsStable
- Performs one incremental stabilization cycle.
Cursor navigation
- :down() --> self
- Navigates the cursor to the next row.
- :end() --> self
- Navigates the cursor to the rightmost visible data column.
- :goBottom() --> self
- Navigates the cursor to the last row in the data source.
- :goTop() --> self
- Navigates the cursor to the first row in the data source.
- :home() --> self
- Navigates the cursor to the leftmost visible data column.
- :left() --> self
- Navigates the cursor left one column.
- :pageDown() --> self
- Navigates the cursor to the next page in the data source.
- :pageUp() --> self
- Navigates the cursor to the previous page in the data source.
- :panEnd() --> self
- Navigates the cursor to the rightmost data column.
- :panHome() --> self
- Navigates the cursor to the leftmost visible data column.
- :panLeft() --> self
- Pans the browse display left without changing the cursor position.
- :panRight() --> self
- Pans the browse display right without changing the cursor position.
- :right() --> self
- Navigates the cursor right one column.
- :up() --> self
- Navigates the cursor to the previous row.
Event handling
- :applyKey( <nInkey> ) --> nReturnCode
- Evaluates a code block associated with a navigation key.
- :hitTest( <nMouseRow>, <nMouseCol> ) --> nHitCode
- Tests if a TBrowse is hit by the mouse cursor.
- :setKey( <nInkey>, [<bNewBlock>] ) --> bOldBlock
- Sets or retrieves a code block associated with a navigation key.
Info
Examples
// The example demonstrates the steps required for creating a
// browse view for a database file.
#include "TBrowse.ch"
PROCEDURE Main
LOCAL oTBrowse, oTBColumn
LOCAL bFieldBlock, cFieldName, i, nKey
USE Customer ALIAS Cust
// create TBrowse object
oTBrowse := TBrowse():new( 2,2, MaxRow()-2, MaxCol()-2 )
oTBrowse:headSep := "-"
oTBrowse:colorSpec := "N/BG,W+/R"
// add code blocks for navigating the record pointer
oTBrowse:goTopBlock := {|| DbGoTop() }
oTBrowse:goBottomBlock := {|| DbGoBottom() }
oTBrowse:skipBlock := {|nSkip| DbSkipper(nSkip) }
// create TBColumn objects and add them to TBrowse object
FOR i:=1 TO FCount()
cFieldName := FieldName( i )
bFieldBlock := FieldBlock( cFieldName )
oTBColumn := TBColumn():new( cFieldName, bFieldBlock )
oTBrowse:addColumn( oTBColumn )
NEXT
// display browser and process user input
DO WHILE .T.
oTBrowse:forceStable()
nKey := Inkey(0)
IF oTBrowse:applyKey( nKey ) == TBR_EXIT
EXIT
ENDIF
ENDDO
USE
RETURN
// The example demonstrates the steps required for creating a
// browse view for a two dimensional array. Note that the data
// source and row pointer of the data source are stored in
// oTBrowse:cargo. The pseudo instance variables :data and :recno
// are translated by the preprocessor.
#include "TBrowse.ch"
#xtrans :data => :cargo\[1]
#xtrans :recno => :cargo\[2]
PROCEDURE Main
LOCAL i, nKey, bBlock, oTBrowse, oTBColumn
LOCAL aHeading := { "File Name", ;
"File Size", ;
"File Date", ;
"File Time", ;
"File Attr" }
LOCAL aWidth := { 20, 10, 9, 9, 9 }
// Create TBrowse object
// data source is the Directory() array
oTBrowse := TBrowse():new( 2, 2, MaxRow()-2, MaxCol()-2 )
oTBrowse:cargo := { Directory( "*.*" ), 1 }
oTBrowse:headSep := "-"
oTBrowse:colorSpec := "N/BG,W+/R"
// Navigation code blocks for array
oTBrowse:goTopBlock := {|| oTBrowse:recno := 1 }
oTBrowse:goBottomBlock := {|| oTBrowse:recno := Len( oTBrowse:data ) }
oTBrowse:skipBlock := {|nSkip| ArraySkipper( nSkip, oTBrowse ) }
// create TBColumn objects and add them to TBrowse object
FOR i:=1 TO Len( aHeading )
// code block for individual columns of the array
bBlock := ArrayBlock( oTBrowse, i )
oTBColumn := TBColumn():new( aHeading[i], bBlock )
oTBColumn:width := aWidth[i]
oTBrowse:addColumn( oTBColumn )
NEXT
// display browser and process user input
DO WHILE .T.
oTBrowse:forceStable()
nKey := Inkey(0)
IF oTBrowse:applyKey( nKey ) == TBR_EXIT
EXIT
ENDIF
ENDDO
RETURN
// This code block uses detached LOCAL variables to
// access single elements of a two-dimensional array.
FUNCTION ArrayBlock( oTBrowse, nSubScript )
RETURN {|| oTBrowse:data[ oTBrowse:recno, nSubScript ] }
// This function navigates the row pointer of the
// the data source (array)
FUNCTION ArraySkipper( nSkipRequest, oTBrowse )
LOCAL nSkipped
LOCAL nLastRec := Len( oTBrowse:data ) // Length of array
IF oTBrowse:recno + nSkipRequest < 1
// skip requested that navigates past first array element
nSkipped := 1 - oTBrowse:recno
ELSEIF oTBrowse:recno + nSkipRequest > nLastRec
// skip requested that navigates past last array element
nSkipped := nLastRec - oTBrowse:recno
ELSE
// skip requested that navigates within array
nSkipped := nSkipRequest
ENDIF
// adjust row pointer
oTBrowse:recno += nSkipped
// tell TBrowse how many rows are actually skipped.
RETURN nSkipped
Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe