#include once "fltk-c.bi"

'test of:
' Fl_Tree_ItemSetWidget 

sub TreeCB cdecl (wgt as Fl_Widget ptr, pdata as any ptr)
  dim as Fl_Tree ptr tr = cptr(Fl_Tree ptr,wgt)
  dim as Fl_Tree_Item ptr item = Fl_TreeGetCallbackItem(tr)
  if (item=0) then exit sub
  
  dim as const zstring ptr label = Fl_Tree_ItemGetLabel(item)
  select case Fl_TreeGetCallbackReason(tr)
  case FL_TREE_REASON_SELECTED    : print "FL_TREE_REASON_SELECTED   " & *label
  case FL_TREE_REASON_DESELECTED  : print "FL_TREE_REASON_DESELECTED " & *label
  case FL_TREE_REASON_OPENED      : print "FL_TREE_REASON_OPENED     " & *label
  case FL_TREE_REASON_CLOSED      : print "FL_TREE_REASON_CLOSED     " & *label
  end select
end sub

sub ButtonCB cdecl (wgt as Fl_Widget ptr, pdata as any ptr)
  ? "ButtonCB"
end sub


'
' main
'
#define MAX_FIELDS   5
#define FIELD_WIDTH  70
#define FIELD_HEIGHT 30


dim as Fl_Tree_Item ptr item
dim as Fl_Group ptr grp

dim as Fl_Window ptr win = Fl_WindowNew(320,200, "Fl_Tree03.bas")
Fl_WindowBegin(win)

  dim as Fl_Tree ptr tree = Fl_TreeNew(10,20,300,170,"Fl_Tree")
  Fl_TreeSetShowRoot(tree,0) ' don't show root of tree
  Fl_WidgetSetCallback(tree,@TreeCB) ' setup a callback for the treeview

  Fl_GroupBegin(tree)

    Fl_TreeAdd(tree,"Flintstones/Fred") ' add some items
    Fl_TreeAdd(tree,"Flintstones/Wilma")
    Fl_TreeAdd(tree,"Flintstones/Pebbles")
    Fl_TreeClose(tree,"Flintstones")
    
    Fl_TreeAdd(tree,"Simpsons/Homer")
    Fl_TreeAdd(tree,"Simpsons/Marge")
    Fl_TreeAdd(tree,"Simpsons/Bart")
    Fl_TreeAdd(tree,"Simpsons/Lisa")
    Fl_TreeClose(tree,"Simpsons")

    item = Fl_TreeAdd(tree,"Widgets/Fields")
    grp=Fl_GroupNew(0,0,FIELD_WIDTH*MAX_FIELDS, FIELD_HEIGHT)
      for i as  integer = 0 to MAX_FIELDS-1
        Fl_InputNew(i*FIELD_WIDTH,0,FIELD_WIDTH,FIELD_HEIGHT)
      next
    Fl_GroupEnd(grp)
    Fl_Tree_ItemSetWidget item,grp

    item = Fl_TreeAdd(tree,"Widgets/Button")
    grp=Fl_GroupNew(0,0,160,16)
      dim as Fl_ButtonEx ptr Btn = Fl_ButtonExNew(0,0,160,16,"ok")
      Fl_WidgetSetCallback Btn,@ButtonCB
    Fl_GroupEnd(grp)
    Fl_Tree_ItemSetWidget item,grp
    Fl_TreeClose(tree,"Widgets")

  Fl_GroupEnd(tree)

Fl_WindowEnd(win)

Fl_GroupSetResizable(win,win)

Fl_WindowShow win

Fl_Run
