//---------------------------------------------------------------------------
/*
Remote Train Control Program for Windows

© Copyright 2019 by Mark DiVecchio

    This file is part of Remote Train Control.

    Remote Train Control is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Remote Train Control is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Remote Train Control.  If not, see <http://www.gnu.org/licenses/>.

*/
// Home Page : http://www.silogic.com/trains/RTC_Running.html
//---------------------------------------------------------------------------
#ifndef Setup_ControlH
#define Setup_ControlH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "QuitButton.h"
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include "AbNumEdit.hpp"
#include <Dialogs.hpp>
#include "_GClass.hpp"
#include "AbLED.hpp"
#include <Menus.hpp>
#include "SyncListBox.h"
#include <ComCtrls.hpp>

#define BRAKEBOOSTSTAY (Setup->BrakeBoost->ItemIndex == 0)
#define BRAKEBOOSTRETURN (Setup->BrakeBoost->ItemIndex == 1)

//---------------------------------------------------------------------------
class PlaybackFile;			// needed because of circular reference in PBFileThread.cpp
//---------------------------------------------------------------------------
class TSetup : public TForm
{
__published:	// IDE-managed Components
	TLabel *Setup_Label;
	TButton *HideButton;
	TSaveDialog *RecordSaveDialog;
	TOpenDialog *PlaybackDialog;
	TPopupMenu *SetupPopupMenu;
	TMenuItem *EnumerateSerialPorts1;
	TGroupBox *SerialPortGroup;
	TGroupBox *GroupBox2;
	TRadioGroup *BrakeBoost;
	TGroupBox *PlaybackGroup;
	TAbLED *RecordingLED;
	TButton *PlaybackStartButton;
	TButton *PlaybackStopButton;
	TButton *RecordStopButton;
	TButton *RecordStartButton;
	TCheckBox *EncodedRecordFormat;
	TCheckBox *RepeatPlayback;
	TCheckBox *AutoCoupler;
	TCheckBox *AutoBell;
	TCheckBox *ShortBellWhistleSequence;
	TCheckBox *ExtendedSUSD;
	TCheckBox *KeepEngines;
	TCheckBox *Speed_Mode;
	TCheckBox *StandardAccDec;
	TCheckBox *AutoConnect;
	TCheckBox *AutoPFA;
	TCheckBox *DisableEmergencyStopButton;
	TCheckBox *CRC_Trace;
	TCheckBox *AllowZero;
	TLabel *Label1;
	TAbNumSpin *MaxSpeed;
	TLabel *Label2;
	TLabel *Label3;
	TAbNumSpin *MPHScaling;
	TPanel *SerialDebugPanel;
	TCheckBox *Echo;
	TCheckBox *Hex;
	TCheckBox *SpareCheckbox;
	TCheckBox *Ignore_FF;
	TCheckBox *Duplex;
	TCheckBox *TXOnlyComm;
	TLabel *NumRetriesLabel;
	TAbNumSpin *NumRetries;
	TImage *Copyright;
	TCheckBox *AutoHotButtons;
	TPopupMenu *RateSet;
	TMenuItem *ManuallysetSpeed1;
	TMenuItem *AutomaticallysetSpeed1;
	TCheckBox *Allow255Sounds;
	TButton *SuperModeSetupButton;
	TLabel *Label5;
	TAbNumSpin *Quick_Ctrl_Scaling;
	TCheckBox *AutoQuickControls;
	TAbNumSpin *TransparentSpin;
	TLabel *Label6;
	TLabel *Label7;
	TCheckBox *AutoSoundCtrls;
	TCheckBox *SmokeOFFatStartup;
    TPopupMenu *TIUPopupMenu;
	TMenuItem *ScanModem;
	TMenuItem *ScanOTA;
	TMenuItem *OOKRadioHelp;
	TMenuItem *RFIDTagsHelp1;
	TMenuItem *RTCHelp1;
	TPopupMenu *WiFiPopupMenu;
	TMenuItem *WiFiInformation1;
	TMenuItem *WiFiInformation2;
	TMenuItem *ScanMaster;
	TMenuItem *mDNSServer;
	TCheckBox *Safety_Mode;
	TCheckBox *AutoWhistle;
	TMenuItem *ScanEngine;
	TPageControl *CommSetupPageControl;
    TTabSheet *TIUPortSetup;
	TRadioGroup *StopSel;
	TRadioGroup *ParitySel;
	TRadioGroup *BitsSel;
	TRadioGroup *BaudRateSel;
    TGroupBox *TIUSelGroup;
    TLabel *RadioCOMLabel;
    TAbNumSpin *RadioCOMPortNum;
	TCheckBox *Radio_COM_Mode;
    TGroupBox *TIUPortListGroup;
    TListBox *WTIUListBox;
    TTabSheet *RFIDPortsSetup;
    TGroupBox *RFIDSelGroup;
    TGroupBox *RFIDListGroup;
    TListBox *RFIDListBox;
    TTabSheet *AIUEmulatorPortsSetup;
	TGroupBox *WiFiAIUIPListGroup;
    TListBox *AIUListBox;
    TGroupBox *AIUSelGroup;
	TLabel *AIUWiFiLabel;
	TCheckBox *AIU_WiFi_Mode;
	TCheckBox *AIU_WiFi_Multicast;
	TEdit *AIUIP;
	TEdit *AIUPort;
	TMenuItem *ScanHost;
	TTabSheet *HostIPPage;
	TLabel *Label4;
	TComboBox *IPComboBox;
	TButton *ScanHostIPButton;
	TCheckBox *GeneralSounds;
    TCheckBox *AutoBellOff;
    TMenuItem *ScanMSG;
    TCheckBox *NoSleep;
    TAbNumSpin *BellOffTime;
    TLabel *Label8;
    TLabel *RFIDCOMLabel;
    TAbNumSpin *RFIDCOMPortNum;
    TCheckBox *RFID_COM_Mode;
    TLabel *WTIULabel;
    TCheckBox *WTIU_WiFi_Mode;
    TLabel *RFIDWiFiLabel;
    TCheckBox *RFID_WiFi_Mode;
    TMenuItem *ScanTIUWIUtcp;
    TPopupMenu *RFIDPopupMenu;
    TPopupMenu *AIUPopupMenu;
    TMenuItem *ScanforAIUWiFiDevices1;
    TMenuItem *WiFiInformation;
    TMenuItem *WiFiInfoAIU;
    TMenuItem *ScanforRFIDudpDevices1;
    TMenuItem *ScanforRFIDtcpDevices1;
    TMenuItem *WiFiInfo2;
    TMenuItem *EnumerateSerialPorts10;
    TMenuItem *EnumerateSerialPorts6;
    TPopupMenu *IPPortsPopUp;
    TMenuItem *Scan1;
    TLabel *Hidden;
    TButton *TIUSelectionButton;
    TPopupMenu *RecordingPopupMenu;
    TMenuItem *EditthisRecording1;
    TButton *ScanTIUWTIUButton;
    TButton *ScanRFIDButton;
    TButton *ScanAIUButton;
    TCheckBox *AutoFindEngines;
    TTabSheet *SignalsPage;
    TGroupBox *GroupBox1;
    TListBox *SignalsListBox;
    TGroupBox *SignalsGroupBox;
    TLabel *SignalsWiFiLabel;
    TCheckBox *Signals_WiFi_Mode;
    TButton *ScanSignalsButton;
    TMenuItem *ScanSignal;
    TLabel *Label61;
    TAbNumEdit *NumDetectors;
    TLabel *Label62;
    TAbNumEdit *NumReaders;
    TAbNumEdit *NumSignals;
    TLabel *Label9;
    TLabel *WLabel10;
    TAbNumEdit *NumWTIU;
    TCheckBox *ShutdownOnRead;
	void __fastcall HideButtonClick(TObject *Sender);
	void __fastcall AllowZeroClick(TObject *Sender);
	void __fastcall RFID_COM_ModeClick(TObject *Sender);
	void __fastcall RecordStartButtonClick(TObject *Sender);
	void __fastcall RecordStopButtonClick(TObject *Sender);
	void __fastcall PlaybackStartButtonClick(TObject *Sender);
	void __fastcall PlaybackStopButtonClick(TObject *Sender);
	void __fastcall NumRetriesChange(TObject *Sender);
	void __fastcall MaxSpeedChange(TObject *Sender);
	void __fastcall EnumerateSerialPorts1Click(TObject *Sender);
	void __fastcall WTIUListBoxClick(TObject *Sender);
	void __fastcall RadioCOMPortNumValueChanged(TObject *Sender);
	void __fastcall FormShow(TObject *Sender);
	void __fastcall ManuallysetSpeed1Click(TObject *Sender);
	void __fastcall AutomaticallysetSpeed1Click(TObject *Sender);
	void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
	void __fastcall DisableEmergencyStopButtonClick(TObject *Sender);
	void __fastcall SuperModeSetupButtonClick(TObject *Sender);
	void __fastcall TransparentSpinChange(TObject *Sender);
	void __fastcall RFIDCOMPortNumValueChanged(TObject *Sender);
	void __fastcall Ignore_FFClick(TObject *Sender);
	void __fastcall EncodedRecordFormatClick(TObject *Sender);
	void __fastcall PlaybackDialogShow(TObject *Sender);
	void __fastcall MPHScalingChange(TObject *Sender);
	void __fastcall CopyrightClick(TObject *Sender);
	void __fastcall DTRAlwaysOnClick(TObject *Sender);
	void __fastcall Radio_WiFi_ModeClick(TObject *Sender);
	void __fastcall Radio_COM_ModeClick(TObject *Sender);
	void __fastcall RFID_WiFi_ModeClick(TObject *Sender);
	void __fastcall RFIDListBoxClick(TObject *Sender);
	void __fastcall ScanModemClick(TObject *Sender);
	void __fastcall ScanOTAClick(TObject *Sender);
	void __fastcall OOKRadioHelpClick(TObject *Sender);
	void __fastcall RFIDTagsHelp1Click(TObject *Sender);
	void __fastcall RTCHelp1Click(TObject *Sender);
	void __fastcall ScanRFIDButtonClick(TObject *Sender);
	void __fastcall WiFiInformation1Click(TObject *Sender);
	void __fastcall ScanMasterClick(TObject *Sender);
	void __fastcall mDNSServerClick(TObject *Sender);
	void __fastcall ScanEngineClick(TObject *Sender);
	void __fastcall ScanAIUButtonClick(TObject *Sender);
	void __fastcall AIU_WiFi_ModeClick(TObject *Sender);
	void __fastcall ScanTIUWTIUButtonClick(TObject *Sender);
	void __fastcall AIUListBoxClick(TObject *Sender);
	void __fastcall ScanHostClick(TObject *Sender);
	void __fastcall ScanHostIPButtonClick(TObject *Sender);
    void __fastcall ScanMSGClick(TObject *Sender);
    void __fastcall NoSleepClick(TObject *Sender);
    void __fastcall WTIU_WiFi_ModeClick(TObject *Sender);
    void __fastcall ScanTIUWIUtcpClick(TObject *Sender);
    void __fastcall FormCloseQuery(TObject *Sender, bool &CanClose);
    void __fastcall ScanforAIUWiFiDevices1Click(TObject *Sender);
    void __fastcall ScanforRFIDudpDevices1Click(TObject *Sender);
    void __fastcall ScanforRFIDtcpDevices1Click(TObject *Sender);
    void __fastcall EnumerateSerialPorts10Click(TObject *Sender);
    void __fastcall EnumerateSerialPorts6Click(TObject *Sender);
    void __fastcall ListBoxDrawItem(TWinControl *Control, int Index,
          TRect &Rect, TOwnerDrawState State);
    void __fastcall HiddenClick(TObject *Sender);
    void __fastcall IPComboBoxClick(TObject *Sender);
    void __fastcall DisableEmergencyStopButtonMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
    void __fastcall TIUSelectionButtonClick(TObject *Sender);
    void __fastcall EditthisRecording1Click(TObject *Sender);
    void __fastcall ScanSignalsButtonClick(TObject *Sender);
    void __fastcall Signals_WiFi_ModeClick(TObject *Sender);
    void __fastcall SignalsListBoxClick(TObject *Sender);
    void __fastcall ScanSignalClick(TObject *Sender);

protected:
    void __fastcall WMDropFiles(TWMDropFiles &message);
    void __fastcall CMStopPlayback(TMessage &Message);

	BEGIN_MESSAGE_MAP
		MESSAGE_HANDLER(WM_DROPFILES, TWMDropFiles, WMDropFiles)
		MESSAGE_HANDLER(CM_STOPPLAYBACK, TMessage, CMStopPlayback)
	END_MESSAGE_MAP (TForm)

private:	// User declarations
	//int TIUNo;
    int RemoteNo;
    String RegFileRootKey;
    __fastcall TSetup(TComponent* Owner);
   	void __fastcall Scan(String Service, TListBox * MyListBox);
    void __fastcall Set_Comment();
    String RecordingFileName;

public:		// User declarations
   	__fastcall TSetup(TComponent* Owner, int TIU, int Remote);
	__fastcall ~TSetup(void);

    HWND ParentHandle;
    BOOL __fastcall EnumerateComPorts(TListBox * ListBox);
	// Variables set by config.lua
	bool Show_Pause_Button;		// if true (set by config.lua) then show the pause button on Program Control
    bool Comm_Not_Required;		// enables some windows even without communications - use with care
    String SwitchStraight, SwitchDiverge;	// words used for Switch when the straight/diverge positions
    void __fastcall StartmDNSServices(bool RTCMaster, bool RTCHost);
    void __fastcall StopmDNSServices();
    int __fastcall FindIPs();

    int RFIDDetectorCount, RFIDReaderCount, SignalCount;

};
//---------------------------------------------------------------------------
extern PACKAGE TSetup *Setup;
//---------------------------------------------------------------------------
#endif
