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(int ID, int x, int y, int width, int height)

BBjTree

addTree(int ID, int x, int y, int width, int height, string 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.

width

Width of the tree control.

height

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.

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)
FI

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$+"."
FI

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
RETURN

See Also

BBjAPI

BBjSysGui

BBjControl

BBjWindow

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