-- child.exw by Wolf,Jan.26/99

include win32lib.ew
without warning

constant  
  ParentWin        = create( Window, "Parent window", 0, 0, 0, 320, 110, 0 ),
  List1            = create( List, "", ParentWin, 2, 2, 308, 60, 0 ),
  ParentCloseMenu  = create( Menu, "&Close", ParentWin, 0, 0, 0, 0, 0 ),
  CloseParentMenu  = create( MenuItem, "Parent window", ParentCloseMenu, 0, 0, 0, 0, 0 ),
  ParentCreateMenu = create( Menu, "C&reate", ParentWin, 0, 0, 0, 0, 0 ),
  CreateChildMenu  = create( MenuItem, "&Child Window", ParentCreateMenu, 0, 0, 0, 0, 0 ),
  CreateEntryMenu  = create( MenuItem, "&Entry Window", ParentCreateMenu, 0, 0, 0, 0, 0 ),

  ChildWin         = create( Window, "Child window", ParentWin, 30, 30, 320, 100, {WS_CAPTION,WS_SYSMENU,WS_THICKFRAME} ),
  ChildCloseMenu   = create( Menu, "&Close", ChildWin, 0, 0, 0, 0, 0 ), 
  EitherMenu       = create( Menu, "Either", ChildCloseMenu, 0, 0, 0, 0, 0 ),
  CloseChildMenu   = create( MenuItem, "C&hild window,", EitherMenu, 0, 0, 0, 0, 0 ),
  CloseBothMenu    = create( MenuItem, "or &Parent + Child.", EitherMenu, 0, 0, 0, 0, 0 ),

  EntryWindow      = create( Window, "Entry Window", ChildWin, 30, 30, 402, 85, {#C40000} ),
  Label1           = create( LText, "enter something!", EntryWindow, 1, 4, 110, 20, 0) ,
  Entry1           = create( EditText, "", EntryWindow, 115, 2, 277, 20, 32 ),
  btnAdd           = create( PushButton,"Add to List", EntryWindow, 2, 28, 90, 25, 0 ),
  btnQuit          = create( PushButton, "QUIT", EntryWindow, 302, 28, 90, 25, 0 )

  setWindowBackColor(EntryWindow, rgb(0,255,0))

procedure onMenu_Exit( integer self, integer event, sequence params)
  closeWindow(ChildWin)
  closeWindow(ParentWin)
end procedure

procedure onMenu_Exit_Child( integer self, integer event, sequence params)
  closeWindow(ChildWin)
end procedure

procedure paint_child()
  setPenPos(ChildWin,0,0)
  wPuts(ChildWin,"this child is MODAL, without min/max buttons.")
  setPenPos(ChildWin,0,20)
  wPuts(ChildWin,"  ..just perfect for entry forms!")
end procedure

procedure show_child( integer self, integer event, sequence params)
  openWindow(ChildWin,Modal)
  paint_child()
end procedure

procedure show_entry_form( integer self, integer event, sequence params)
  openWindow(EntryWindow,Modal)
  setFocus(Entry1)
end procedure

procedure onClick_btnAdd( integer self, integer event, sequence params)
  if length(getText(Entry1)) != 0 then
    addItem(List1,getText(Entry1))
  end if
  setFocus(Entry1)
  setText(Entry1,{})
end procedure

procedure onClick_btnQuit( integer self, integer event, sequence params )
  closeWindow(EntryWindow)
  if getCount(List1) > 0 then
    setIndex(List1,getCount(List1))
  end if
  setFocus(List1)
end procedure

procedure onKey_Entry1( integer self, integer event, sequence params)
 integer key = params[1]
 if key=13 then onClick_btnAdd( self, event, params )
 elsif key=27 then onClick_btnQuit( self, event, params )
 end if
end procedure

procedure onKey_btnAdd( integer self, integer event, sequence params)
 integer key = params[1]
 if key=13 then onClick_btnAdd( self, event, params ) else end if
end procedure

procedure onKey_btnQuit( integer self, integer event, sequence params)
 integer key = params[1]
 if key=13 then onClick_btnQuit( self, event, params ) else end if
end procedure

setHandler( CloseParentMenu, w32HClick, routine_id("onMenu_Exit") )
setHandler( CreateChildMenu, w32HClick, routine_id("show_child") )
setHandler( CloseChildMenu, w32HClick, routine_id("onMenu_Exit_Child") )
setHandler( CloseBothMenu, w32HClick, routine_id("onMenu_Exit") )
setHandler( CreateEntryMenu, w32HClick, routine_id("show_entry_form") )
setHandler( btnAdd, w32HClick, routine_id("onClick_btnAdd") )
setHandler( btnQuit, w32HClick, routine_id("onClick_btnQuit") )
setHandler( Entry1, w32HKeyDown, routine_id("onKey_Entry1") )
setHandler( btnAdd, w32HKeyDown, routine_id("onKey_btnAdd") )
setHandler( btnQuit, w32HKeyDown, routine_id("onKey_btnQuit") )

WinMain( ParentWin,Normal )
