-- from Ex06.exw by David Cuny
-- This opens a window with a populated list in it.
-- Wolf added onChange[] to show it's use.
-- then added a button and an SLE to "fill" the listbox.

include win32lib.ew

constant
    Win   = create( Window, "List ++", 0, Default, Default, 160, 190, 0 ),
    List1 = create( List, "", Win, 10, 10, 120, 58, LBS_NOINTEGRALHEIGHT ),    
--  ^^ create a listbox window.
    Label1 = create(RText, "", Win, 10, 75, 120, 20, 0),
--  ^^ create a right-justified text display window.
    Sle1    = create( EditText, "", Win, 10, 96, 110, 20, 0 ),
--  ^^ create a little single-line-list_entry window.
    Button1 = create( PushButton, "ADD", Win, 10, 126, 60, 20, 0 )
--  ^^ and last, add a button to do something.

procedure onLoad_Win( integer self, integer event, sequence params )
  -- add these items to the listbox    
  addItem( List1, "one" )
  addItem( List1, "two" )
  addItem( List1, "three" )
  addItem( List1, "four" )
  setIndex(List1,1)
  setFocus(Sle1) -- we could have added this line to lesson 5's example.
end procedure

procedure show_it(integer here)
-- show the selected list item in the text window.
sequence this
this=getItem(List1,here)
setText(Label1, this)
end procedure

procedure onChange_List1( integer self, integer event, sequence params )
-- get the latest index from the listbox, then show it.
atom where
where=getIndex(List1)
show_it(where)
end procedure

procedure onClick_Button1( integer self, integer event, sequence params )
  sequence list_entry  list_entry = getText( Sle1 )
  
  addItem( List1, list_entry )
  setText(Sle1, {} )
  setFocus(Sle1)
  
end procedure

setHandler( Win, w32HOpen, routine_id( "onLoad_Win" ) )
setHandler( List1, w32HChange, routine_id("onChange_List") )
-- ^^ this event handler is triggered whenever List1 changes state.
setHandler( Button1, w32HClick, routine_id("onClick_Button1") )

WinMain( Win,Normal )
