BBjWindow::addTree

Description

Adds a tree control in the BBjWindow, which displays a set of hierarchical data as an outline.

Syntax

Return Value Method
BBjTree addTree()
BBjTree addTree(byte[] flags)
BBjTree addTree(int ID)
BBjTree addTree(int ID, byte[] flags)
BBjTree addTree(int ID, number x, number y, number w, number h)
BBjTree addTree(int ID, number x, number y, number w, number h, byte[] flags)

Parameters

Variable

Description

ID

Control ID number. It must be an integer between 1 and 32767 and be unique within a given top-level window.

x

Horizontal position of the upper-left corner of the tree control.

y

Vertical position of the upper-left corner of the tree control.

w

Width of the tree control.

h

Height of the tree control

flags

Control flags, as follows:

Flag Description
$0001$ Sets the control to be initially disabled.
$0010$ Sets the control to be initially invisible.
$0800$ Draws a recessed client edge around the control.
$1000$ Draws a raised edge around the control.

Return Value

Returns the created BBjTree object.

Remarks

The creation of a BBjTree control does not use flags.

If the ID parameter is not specified, a control ID is assigned dynamically using getAvailableControlID().

If the x, y, width, and height parameters are not specified, they are all initialized to 0. This is typically for use with DWC windows that dynamically arrange their contents (window creation flag $00100000$).

Example

rem 'Add a tree control to a window

rem 'Obtain the instance of the BBjAPI object
let myAPI! = BBjAPI()

rem 'Open the SysGui device
SYSGUI = UNT
OPEN (SYSGUI) "X0"

rem 'Obtain the instance of the BBjSysGui object
let mySysGui! = myAPI!.getSysGui()

rem 'Constants
WINDOW_X = 200,WINDOW_Y = 200
WINDOW_W = 300,WINDOW_H = 200

TREE_ID = 101
TREE_X = 0,TREE_Y = 0
TREE_W = WINDOW_W,TREE_H = WINDOW_H

PARENT_ID = 0
NODE_ID = 0
TITLE$="Musical Tree"

TRUE = 1
FALSE = 0
OK = 0
QOUTE$ = CHR(34)

rem 'Create array to hold ARTIST and songs
DIM MUSIC$[2,4]
MUSIC$[0,0]="The Beatles"
MUSIC$[0,1]="Hey Jude",MUSIC$[0,2]="Let It Be",MUSIC$[0,3]="Twist and Shout",MUSIC$[0,4]="Yesterday"
MUSIC$[1,0]="Paul Simon"
MUSIC$[1,1]="Bridge Over Troubled Waters",MUSIC$[1,2]="Hearts and Bones",MUSIC$[1,3]="Kathy's Song",MUSIC$[1,4]="The Sound of Silence"
MUSIC$[2,0]="Willie Nelson"
MUSIC$[2,1]="Always On My Mind",MUSIC$[2,2]="Getting Over You",MUSIC$[2,3]="Old Fords and Natural Stone",MUSIC$[2,4]="This Morning"

rem 'Create the main window
myWindow! = mySysGui!.addWindow(WINDOW_X,WINDOW_Y,WINDOW_W,WINDOW_H,TITLE$,$0093$,$02$)

rem 'Create the tree control on the window
myMusicalTree! = myWindow!.addTree(TREE_ID,TREE_X,TREE_Y,TREE_W,TREE_H)

rem 'Create root node of tree
myMusicalTree!.setRoot(PARENT_ID,TITLE$)

rem 'Add nodes to tree
FOR ARTIST = 0 TO 2
    NODE_ID = NODE_ID+1
    myMusicalTree!.addExpandableNode(NODE_ID,PARENT_ID,MUSIC$[ARTIST,0])
    SONG_PARENT_ID = NODE_ID
    FOR SONG = 1 TO 4
        NODE_ID = NODE_ID+1
        myMusicalTree!.addNode(NODE_ID,SONG_PARENT_ID,MUSIC$[ARTIST,SONG])
    NEXT SONG
NEXT ARTIST

rem 'Show the window
myWindow!.setVisible(TRUE)

rem 'Register the CALLBACK routines
CALLBACK(ON_TREE_SELECT,DO_SELECTION,mySysGui!.getContext(),myMusicalTree!.getID())
CALLBACK(ON_CLOSE,APP_CLOSE,mySysGui!.getContext())

rem 'Process Events
process_events

rem 'Callback routine called when the user selects a node of the tree control
DO_SELECTION:
    rem 'Get the selected node
    let NODE = myMusicalTree!.getSelectedNode()

    rem 'Get the node text
    let NODE_DATA$ = myMusicalTree!.getNodeText(NODE)

    rem 'Check if node is a child
    let CHILD_NODE = myMusicalTree!.isNodeLeaf(NODE)

    if (CHILD_NODE) then
        rem 'If child node get the parent node
        CHILD_DATA$ = NODE_DATA$
        NODE = myMusicalTree!.getParentNode(NODE)
        NODE_DATA$ = myMusicalTree!.getNodeText(NODE)
    endif

    rem 'Create the selected display message
    MESSAGE$="You have selected "+NODE_DATA$
    if (CHILD_NODE) then
        MESSAGE$ = MESSAGE$+"'s hit song, "+QOUTE$+CHILD_DATA$+"."+QOUTE$
    else
        MESSAGE$ = MESSAGE$+"."
    endif

    rem 'Display the user selection
    X = MSGBOX(MESSAGE$,OK,TITLE$)
return

rem 'Callback routine called when the user closes the application window
APP_CLOSE:
release

See Also

BBjAPI

BBjSysGui

BBjControl

BBjWindow

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.