#!../tree_wish -f
# -*-Tcl-*-
# This file contains a simple demonstration program for Itk Tree widget class.
#
# Usage: simple
#
# Author: Allan Brighton (abrighto@eso.org) 

if {[catch {class X {}}]} {
    puts "This demo requires itcl2.0/itk2.0."
    puts "Install itcl2.0 and then rerun configure and make here..."
    exit
}

lappend auto_path ../library 

# This is an example of a simple "application" class, i.e.: 
# this program does nothing but create an instance of this class.

class Simple {
    inherit iwidgets::Dialog
    
    # constructor: create a toplevel window for the demo

    constructor {args} {

	wm withdraw .

	# create an instance of the Itk "Tree" widget
	# (based on the C++ "tree" widget)
	itk_component add tree {
	    Tree $itk_interior.tree
	}
	pack $itk_component(tree) -fill both -expand 1

	eval itk_initialize $args
	wm title $itk_component(hull) {Simple [incr Tcl] Tree Demo}
    }

    
    # draw a tree in the canvas for demonstration purposes

    method draw_tree {} {
	# add some nodes to the tree
	add_nodes {} root
	add_nodes root node1 node2 node3 node4
	add_nodes node1 node1.1 node1.2 node1.3
	add_nodes node2 node2.1 node2.2 node2.3
	add_nodes node3 node3.1 node3.2
    }


    # Add one or more subnodes to the given parent node.
    # In this case, the label is just the same as the node's tag

    method add_nodes {parent args} {
	foreach node $args {
	    $itk_component(tree) addnode $parent $node \
		    -bitmap @$bitmap \
		    -text $node
	}
    }

    
    private variable bitmap "../bitmaps/node.xbm"
}


# Start the demo:
Simple .s -modality application
.s center
.s draw_tree
.s activate
exit
