require 'phi'
include Phi

form1 = Form.new :form1
form1.height = 400
status_panel = Panel.new form1
status_panel.align = AL_TOP
status_panel.height = 25

tree_view = TreeView.new form1
tree_view.align = AL_CLIENT
tree_view.hide_selection = false

root_node = tree_view.items.add(nil, 'test1')
tree_view.items.add(nil, 'test2')
tree_view.items.add_child(root_node, 'child1')
tree_view.items.add_child(root_node, 'child2')
tree_view.items.add_child(root_node, 'child3')
tree_view.items.add_child(root_node, 'child4')
tree_view.items.add_child(root_node, 'child5')
tree_view.items.add_child(root_node, 'child6')
tree_view.items.add_child(root_node, 'child7')

def display_expaned(tree_view,status_panel)
  if tree_view.selected
    if tree_view.selected.expanded
      status_panel.caption = tree_view.selected.text + " is expanded"
    else
      status_panel.caption = tree_view.selected.text + " is collapsed"
    end
  end
end

tree_view.on_key_up = proc {
|sender,key,shift|
  display_expaned(tree_view,status_panel)
  key
}

tree_view.on_click = proc {
  display_expaned(tree_view,status_panel)
}

first_child = Button.new form1, "first_child"
first_child.align = AL_BOTTOM
first_child.on_click = proc {
  if !tree_view.selected.nil?
    if !tree_view.selected.first_child.nil?
      status_panel.caption = "first_child is " + 
        tree_view.selected.first_child.text
    else
      status_panel.caption = "first_child is nil"
    end
  end
}
last_child = Button.new form1, "last_child"
last_child.align = AL_BOTTOM
last_child.on_click = proc {
  if !tree_view.selected.nil?
    if !tree_view.selected.last_child.nil?
      status_panel.caption = "last_child is " + 
        tree_view.selected.last_child.text
    else
      status_panel.caption = "last_child is nil"
    end
  end
}
btn_next = Button.new form1, "next"
btn_next.align = AL_BOTTOM
btn_next.on_click = proc {
  if !tree_view.selected.nil?
    if !tree_view.selected.next.nil?
      status_panel.caption = "next is " + tree_view.selected.next.text
    else
      status_panel.caption = "next is nil"
    end
  end
}
next_sibling = Button.new form1, "next_sibling"
next_sibling.align = AL_BOTTOM
next_sibling.on_click = proc {
  if !tree_view.selected.nil?
    if !tree_view.selected.next_sibling.nil?
      status_panel.caption = "next_sibling is " + 
        tree_view.selected.next_sibling.text
    else
      status_panel.caption = "next_sibling is nil"
    end
  end
}
next_visible = Button.new form1, "next_visible"
next_visible.align = AL_BOTTOM
next_visible.on_click = proc {
  if !tree_view.selected.nil?
    if !tree_view.selected.next_visible.nil?
      status_panel.caption = "next_visible is " + 
        tree_view.selected.next_visible.text
    else
      status_panel.caption = "next_visible is nil"
    end
  end
}
prev = Button.new form1, "prev"
prev.align = AL_BOTTOM
prev.on_click = proc {
  if !tree_view.selected.nil?
    if !tree_view.selected.prev.nil?
      status_panel.caption = "prev is " + 
        tree_view.selected.prev.text
    else
      status_panel.caption = "prev is nil"
    end
  end
}
prev_sibling = Button.new form1, "prev_sibling"
prev_sibling.align = AL_BOTTOM
prev_sibling.on_click = proc {
  if !tree_view.selected.nil?
    if !tree_view.selected.prev_sibling.nil?
      status_panel.caption = "prev_sibling is " + 
        tree_view.selected.prev_sibling.text
    else
      status_panel.caption = "prev_sibling is nil"
    end
  end
}
prev_visible = Button.new form1, "prev_visible"
prev_visible.align = AL_BOTTOM
prev_visible.on_click = proc {
  if !tree_view.selected.nil?
    if !tree_view.selected.prev_visible.nil?
      status_panel.caption = "prev_visible is " + 
        tree_view.selected.prev_visible.text
    else
      status_panel.caption = "prev_visible is nil"
    end
  end
}

form1.show

Phi.mainloop

=begin
next_child = Button.new form1, "next_child"
next_child.align = AL_BOTTOM
next_child.on_click = proc {
  if !tree_view.selected.nil?
    if !tree_view.selected.next_child.nil?
      status_panel.caption = "next_child is " + tree_view.selected.next_child.text
    else
      status_panel.caption = "next_child is nil"
    end
  end
}
prev_child = Button.new form1, "prev_child"
prev_child.align = AL_BOTTOM
prev_child.on_click = proc {
  if !tree_view.selected.nil?
    if !tree_view.selected.prev_child.nil?
      status_panel.caption = "prev_child is " + tree_view.selected.prev_child.text
    else
      status_panel.caption = "prev_child is nil"
    end
  end
}
=end
