routine ANIMAL.CTL given FIELD.ID, FORM yielding STATUS
''
''    AUTHOR: Steve Bailey
''    CREATED: 12-6-96
''    DESCRIPTION:
''     The "tree control" contains tree items which in turn contain tree
''     items allowing you display a large list of alternatives
''     hierachially. In the example below, we want two
''     categories of animals: birds and mammels.  While the "birds"
''     tree item contains 3 leaf items,  mammels item has sub
''     items "Dogs", "Cats", "Rats", and "Elephants" which also contain
''     leaf items.  
'' 
''     The "/" character has a special meaning.  It separates an item
''     from its sub items and is simialar in behavior to file path
''     specification.  The "\" character is a delimiter allowing you
''     to include characters like "|" and "/" in your labels.
'' 
''     The "|" character is optional an is used to separate the label name
''     from the icon name for that item.
        
    define FIELD.ID as a text variable
    define FORM as a pointer variable
    define STATUS as an integer variable
    define FIELD.PTR as a pointer variable
    define ITEMS as a 1-dim text array

    let FIELD.PTR = DFIELD.F(FIELD.ID, FORM)

    select case FIELD.ID
      case "INITIALIZE"
        let FIELD.PTR = DFIELD.F("TREE", FORM)

        '' set the contents of the tree
        reserve ITEMS(*) as 14
        let ITEMS(1) = "Mammels|cat"
        let ITEMS(2) = "Mammels/Dogs/Beagle \/ (loves children)"
        let ITEMS(3) = "Mammels/Dogs/Collie \/ (loves children)"
        let ITEMS(4) = "Mammels/Dogs/Pit Bull \/ (eats children)"
        let ITEMS(5) = "Mammels/Cats/Siamese|cat"
        let ITEMS(6) = "Mammels/Cats/Manx|cat"
        let ITEMS(7) = "Mammels/Cats/Persian|cat"
        let ITEMS(8) = "Mammels|horse"
        let ITEMS(9) = "Mammels/Elephants/African|elephant"
        let ITEMS(10) = "Mammels/Elephants/Asian|elephant"
        let ITEMS(11) = "Birds|bird"
        let ITEMS(12) = "Birds/Dove|bird"
        let ITEMS(13) = "Birds/Vulture|bird"
        let ITEMS(14) = "Birds/Yellow Bellied Sap Sucker|bird"
        
        '' initialze the tree using DARY.A attribute
        let DARY.A(DFIELD.F("TREE", FORM)) = ITEMS(*)

      case "TREE"
        '' if an item is selected, show its name in the text box
        '' DTVAL.A will contain the path to the item while DDVAL.A
        '' is the index into the list ITEMS(*) array
        let DTVAL.A(DFIELD.F("SELECTED_ITEM", FORM)) = DTVAL.A(FIELD.PTR)
        let DDVAL.A(DFIELD.F("SELECTED_ITEM_INDEX", FORM)) = DDVAL.A(FIELD.PTR)
        display DFIELD.F("SELECTED_ITEM", FORM)
        display DFIELD.F("SELECTED_ITEM_INDEX", FORM)

      case "REPLACE.ITEMS"
        '' want to change the array of items shown in the tree.
        reserve ITEMS(*) as 8
        let ITEMS(1) = "Mammels|cat"
        let ITEMS(2) = "Mammels/Dogs/Rover \/ (loves children)"
        let ITEMS(3) = "Mammels/Dogs/Killer \/ (eats children)"
        let ITEMS(4) = "Mammels/Cats/Morris|cat"
        let ITEMS(5) = "Mammels/Cats/Felix|cat"
        let ITEMS(6) = "Mammels/Cats/Itchy|cat"
        let ITEMS(7) = "Mammels/Elephants/Rush Limbaugh|elephant"
        let ITEMS(8) = "Mammels/Elephants/Rosie O'Donald|elephant"
        let DARY.A(DFIELD.F("TREE", FORM)) = ITEMS(*)

        '' to update the tree, redisplay its field
        display DFIELD.F("TREE", FORM)
       
      case "QUIT"
        let STATUS = 1

      default
    endselect
end
