' Demonstrates some of the components found in Rapid-Q for Linux/Unix

$TYPECHECK ON
$INCLUDE "rapidq.inc"

DECLARE SUB ButtonDemo
DECLARE SUB TextDemo
DECLARE SUB SelectDemo
DECLARE SUB CheckAllBoxes
DECLARE SUB CheckNoBoxes
DECLARE SUB OpenButtonClick
DECLARE SUB MultiButtonClick (Sender AS QButton)
DECLARE SUB ExitItemClick
DECLARE SUB RunItem1Click
DECLARE SUB RunItem2Click

DIM ExitItem AS QMenuitem
    ExitItem.Caption = "Exit"
    ExitItem.OnClick = ExitItemClick
DIM ButtonItem AS QMenuitem
    ButtonItem.Caption = "1. Button Demo"
    ButtonItem.OnClick = ButtonDemo
DIM TextItem AS QMenuitem
    TextItem.Caption = "2. Text Demo"
    TextItem.OnClick = TextDemo
DIM SelectItem AS QMenuitem
    SelectItem.Caption = "3. Selection Demo"
    SelectItem.OnClick = SelectDemo
DIM RunItem1 AS QMenuitem
    RunItem1.Caption = "Columns Game"
    RunItem1.OnClick = RunItem1Click
DIM RunItem2 AS QMenuitem
    RunItem2.Caption = "ListBox Demo"
    RunItem2.OnClick = RunItem2Click

CREATE Form AS QForm
  Center
  CREATE MainMenu AS QMainMenu
    CREATE FileMenu AS QMenuItem
      Caption = "&File"
    END CREATE
    CREATE DemosMenu AS QMenuItem
      Caption = "&Demos"
    END CREATE
    CREATE RunnableMenu AS QMenuItem
      Caption = "&Runnables"
    END CREATE
  END CREATE
  CREATE Panel1 AS QPanel
    Top = 25: Height = Form.ClientHeight-25
    Left = 0: Width = Form.ClientWidth
    CREATE Button AS QButton
      Top = 20
      Left = 20: Width = 100
      Caption = "Regular &Button"
    END CREATE
    CREATE FlatButton AS QCoolBtn
      Top = 45: Height = 35
      Left = 40: Width = 50
      Flat = TRUE
      Caption = "&Cool Button"
      BMP = "open.xpm"
    END CREATE
    CREATE OvalButton AS QOvalBtn
      Top = 115: Height = 50
      Left = 20: Width = 80
      Caption = "&Oval Button"
      Color = &H66FF66
    END CREATE
    CREATE CheckBox1 AS QCheckBox
      Top = 10: Height = 30
      Left = 140: Width = 60
      Caption = "Check &1"
    END CREATE
    CREATE CheckBox2 AS QCheckBox
      Top = 45: Height = 30
      Left = 140: Width = 60
      Caption = "Check &2"
    END CREATE
    CREATE CheckBox3 AS QCheckBox
      Top = 80: Height = 30
      Left = 140: Width = 60
      Caption = "Check &3"
    END CREATE
    CREATE Radio1 AS QRadioButton
      Top = 120: Height = 30
      Left = 140: Width = 60
      Caption = "Radio 1"
    END CREATE
    CREATE Radio2 AS QRadioButton
      Top = 155: Height = 30
      Left = 140: Width = 60
      Caption = "Radio 2"
    END CREATE
    CREATE CheckAll AS QButton
      Top = 10: Height = 30
      Left = 230: Width = 75
      Caption = "Check All"
      OnClick = CheckAllBoxes
    END CREATE
    CREATE CheckNone AS QButton
      Top = 50: Height = 30
      Left = 230: Width = 75
      Caption = "Check None"
      OnClick = CheckNoBoxes
    END CREATE
  END CREATE
  CREATE Panel2 AS QPanel
    Top = 25: Height = Form.ClientHeight-25
    Left = 0: Width = Form.ClientWidth
    CREATE FileLabel AS QLabel
      Top = 5: Left = 5
      Caption = "Open:"
    END CREATE
    CREATE Edit AS QEdit
      Top = 3: Left = 45
      Width = 200
      Text = "demo.bas"
    END CREATE
    CREATE OpenButton AS QButton
      Left = 260: Top = 3
      Caption = "&Open"
      OnClick = OpenButtonClick
    END CREATE
    Visible = False
  END CREATE
  CREATE RichEdit AS QRichEdit    ''-- Can't attach to panel, bug in XForms?
      Top = 60: Left = 2
      Width = Form.Width - 6
      Height = Form.Height - 65
      Visible = False
  END CREATE
  CREATE Panel3 AS QPanel
    Top = 25: Height = Form.ClientHeight-25
    Left = 0: Width = Form.ClientWidth
    CREATE ComboBox AS QComboBox
      Top = 10
      Left = 160
      AddItems "Tissue", "Paper", "Loose Leaf", "Kleenex"
    END CREATE
    CREATE MultiButton AS QButton
      Top = 50: Left = 150
      Caption = "&Multi Select"
      Width = 80
      OnClick = MultiButtonClick
    END CREATE
    Visible = False
  END CREATE
  CREATE ListBox AS QListBox   ''-- Can't attach to Panel, <sigh>
      Left = 10
      Top = 50
      Width = 100
      Height = 180
      AddItems "Apples", "Oranges", "Bananas", "Gateau", "Kiwi"
      Visible = False
  END CREATE
END CREATE

FileMenu.AddItems ExitItem
DemosMenu.AddItems ButtonItem, TextItem, SelectItem
RunnableMenu.AddItems RunItem1, RunItem2

Form.ShowModal


SUB CheckAllBoxes
    CheckBox1.Checked = TRUE
    CheckBox2.Checked = TRUE
    CheckBox3.Checked = TRUE
END SUB

SUB CheckNoBoxes
    CheckBox1.Checked = FALSE
    CheckBox2.Checked = FALSE
    CheckBox3.Checked = FALSE
END SUB

SUB ButtonDemo
    Panel1.Visible = TRUE
    Panel2.Visible = FALSE
    Panel3.Visible = FALSE
    RichEdit.Visible = FALSE
    ListBox.Visible = FALSE
END SUB

SUB TextDemo
    Panel1.Visible = FALSE
    Panel2.Visible = TRUE
    Panel3.Visible = FALSE
    RichEdit.Visible = TRUE
    ListBox.Visible = FALSE
END SUB


SUB SelectDemo
    Panel1.Visible = FALSE
    Panel2.Visible = FALSE
    Panel3.Visible = TRUE
    RichEdit.Visible = FALSE
    ListBox.Visible = TRUE
END SUB

SUB OpenButtonClick
    DIM File AS QFileStream

    IF File.Open(Edit.Text, fmOpenRead) = 0 THEN
       ShowMessage("File "+Edit.Text+" not found!")
    ELSE
       File.Close
       RichEdit.LoadFromFile(Edit.Text)
    END IF
END SUB

SUB MultiButtonClick (Sender AS QButton)
    ListBox.MultiSelect = NOT (0-ListBox.MultiSelect)
    IF ListBox.MultiSelect THEN
      Sender.Caption = "&Single Select"
    ELSE
      Sender.Caption = "&Multi Select"
    END IF
END SUB

SUB RunItem1Click
   RUN "./columns"
END SUB

SUB RunItem2Click
   RUN "./list"
END SUB

SUB ExitItemClick
   Form.Close
END SUB
