'-- Listbox Demo for Rapid-Q beta/promo by William Yu
'-- To get total number of items, use ListBox.ItemCount
'-- This is meant for Rapid-Q Linux/Unix version, it may look slightly
'-- different under Windows.

$APPTYPE GUI

'-------- Here's our global data....
CONST False = 0
CONST True = NOT False

DIM MainForm AS QFORM
DIM Listbox1 as QLISTBOX
DIM Listbox2 as QLISTBOX
DIM AddButton AS QBUTTON
DIM EditButton AS QBUTTON
DIM DelButton AS QBUTTON
DIM OrderButton AS QBUTTON
DIM ClearButton AS QBUTTON
DIM Edit AS QEDIT
DIM Font AS QFont
    Font.Name = "Courier"
    Font.Size = 18
'    Font.Color = &HFF0000

'-------- Followed by our Subroutines

SUB ButtonClick
  ListBox1.AddItems Edit.Text
END SUB

SUB EditItemClick
  ListBox1.Item(ListBox1.ItemIndex) = Edit.Text
END SUB

SUB DelButtonClick
  ListBox1.DelItems ListBox1.ItemIndex
END SUB


SUB AddClick
  DIM AddForm AS QFORM
  DIM Label AS QLABEL
  DIM Button AS QBUTTON

  AddForm.Caption = "Add item"
  AddForm.Center
  AddForm.Width = 330
  AddForm.Height = 80

  Edit.Parent = AddForm
  Edit.Top = 16
  Edit.Left = 100
  Edit.Height = 20
  Edit.Width = 100

  Label.Parent = AddForm
  Label.Top = 20
  Label.Left = 10
  Label.Caption = "Add new item:"

  Button.Parent = AddForm
  Button.Top = 13
  Button.Left = 230
  Button.Width = 50
  Button.Caption = "OK"
  Button.OnClick = ButtonClick

  AddForm.ShowModal
END SUB

SUB EditClick
  IF ListBox1.ItemIndex = -1 THEN
    ShowMessage "Please select an item to edit"
    EXIT SUB
  END IF

  DIM EditForm AS QFORM
  DIM Label AS QLABEL
  DIM Button AS QBUTTON

  EditForm.Caption = "Edit item"
  EditForm.Center
  EditForm.Width = 330
  EditForm.Height = 80

  Label.Parent = EditForm
  Label.Top = 20
  Label.Left = 10
  Label.Width = 100
  Label.Caption = "Edit Existing Item:"

  Edit.Parent = EditForm
  Edit.Top = 16
  Edit.Left = 115
  Edit.Height = 20
  Edit.Text = ListBox1.Item(ListBox1.ItemIndex)

  Button.Parent = EditForm
  Button.Top = 13
  Button.Left = 250
  Button.Width = 50
  Button.Caption = "OK"
  Button.OnClick = EditItemClick

  EditForm.ShowModal
END SUB


SUB OrderClick
  IF ListBox1.ItemIndex <> -1 THEN
    ListBox2.AddItems ListBox1.Item(ListBox1.ItemIndex)
  END IF
END SUB

SUB ListBox1DblClick
  IF ListBox1.ItemIndex <> -1 THEN
    ListBox2.AddItems ListBox1.Item(ListBox1.ItemIndex)
  END IF
'  OrderClick ()
END SUB

SUB ClearClick
  ListBox2.Clear
END SUB


'-------- And finally, our main code
MainForm.Center
MainForm.Caption = "Simple Listbox Demo"
MainForm.Width = 322
MainForm.Height = 250


ListBox1.Parent = MainForm
ListBox1.Font = Font
ListBox1.Top = 10
ListBox1.Left = 10
ListBox1.Height = 200
ListBox1.Width = 100
ListBox1.AddItems("Apples", "Oranges", "Bananas", "Coconuts", "Pineapple")
ListBox1.InsertItem 2,"Kiwi Fruit"
ListBox1.Selected(1) = True
ListBox1.Color = &HFFFFFF
ListBox1.OnDblClick = ListBox1DblClick
listBox1.Visible = 1

ListBox2.Parent = MainForm
ListBox2.Top = ListBox1.Top
ListBox2.Left = 205
ListBox2.Height = ListBox1.Height
ListBox2.Width = ListBox1.Width
ListBox2.Color = &H30FF80

AddButton.Parent = MainForm
AddButton.Top = 20
AddButton.Left = 120
AddButton.Caption = "&Add"
AddButton.Hint = "Add a new item"   '-- No showhint under Linux
AddButton.OnClick = AddClick

EditButton.Parent = MainForm
EditButton.Top = 50
EditButton.Left = 120
EditButton.Caption = "&Edit"
EditButton.Hint = "Edit existing item"
EditButton.OnClick = EditClick

DelButton.Parent = MainForm
DelButton.Top = 80
DelButton.Left = 120
DelButton.Caption = "&Del"
DelButton.OnClick = DelButtonClick

OrderButton.Parent = MainForm
OrderButton.Top = 130
OrderButton.Left = 120
OrderButton.Caption = "&>>"
OrderButton.OnClick = OrderClick

ClearButton.Parent = MainForm
ClearButton.Top = 160
ClearButton.Left = 120
ClearButton.Caption = "&Clear ->"
ClearButton.OnClick = ClearClick

MainForm.ShowModal
