//---------------------------------------------------------------------------
/*
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/>.

*/
//---------------------------------------------------------------------------
#ifndef Quick_ControlsH
#define Quick_ControlsH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "_GClass.hpp"
#include "AbCBitBt.hpp"
#include "AbNumEdit.hpp"
#include "AbSwitch.hpp"
#include "HideButton.h"
#include <ExtCtrls.hpp>
#include <ComCtrls.hpp>
#include <Graphics.hpp>
#include <Menus.hpp>
#include "AbLED.hpp"
#include "AbHSlide.hpp"
#include "ColorButton.hpp"
#include <Mask.hpp>
#include "QuitButton.h"

#define QUICKCOUNT 10		// maxium number of Quick Control segments

enum Consist_Type {ENGINECONSIST=0, LASHUPCONSIST=1, ALLCONSIST=2};

#if __BORLANDC__ >= 0x720
enum DECLSPEC_DENUM TButtonStyle : unsigned char { bsPushButton, bsCommandLink, bsSplitButton };
#endif
//---------------------------------------------------------------------------
class TQuickCtrl : public TForm
{
__published:	// IDE-managed Components
	TGroupBox *EngineBox1;
	THideButton *HideButton;
    TButton *ShutdownButton1;
	TButton *StartupButton1;
	TAbColBitBtn *WhistleButton1;
	TAbColBitBtn *SFSButton1;
	TAbColBitBtn *SRSButton1;
	TAbColBitBtn *SXSButton1;
	TAbToggleSwitch *DIRToggle1;
	TLabel *EngineName1;
	TAbRockerSwitch *BellSwitch1;
	TLabel *SLabel1;
	TButton *ButtonPlusOne1;
	TButton *ButtonPlusFive1;
	TAbNumEdit *SpeedEdit1;
	TPopupMenu *EnginePopUpMenu1;
	TMenuItem *VolumetoMax1;
	TMenuItem *VolumetoMed1;
	TMenuItem *VolumeMute1;
	TAbRockerSwitch *SmokeSwitch1;
	TAbColBitBtn *CPLRRButton1;
	TAbColBitBtn *CPLRFButton1;
	TButton *ButtonMinusOne1;
	TButton *ButtonMinusFive1;
	TAbColBitBtn *NewControlWindow;
	TAbColBitBtn *DeleteControlWindow;
	TAbColBitBtn *ESTOP;
	TButton *ClearPreferencesButton;
	TAbColBitBtn *HornButton1;
	TAbHSlider *VolumeSlider1;
	TColorButton *StopButton1;
	TImage *Copyright;
	TMaskEdit *EngNumber1;
	TUpDown *UpDown1;
	TAbColBitBtn *PreviousPage;
	TAbColBitBtn *NextPage;
	TPopupMenu *QuickPopupMenu;
	TMenuItem *RescanEnginesLashups1;
    TQuitButton *CloseButton;
	void __fastcall HideButtonClick(TObject *Sender);
	void __fastcall ConstructNewQuickControlWindow(TObject *Sender);
	void __fastcall StartupButtonClick(TObject *Sender);
	void __fastcall ShutdownClick(TObject *Sender);
	void __fastcall WhistleButtonMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall WhistleButtonMouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall BellSwitchStatusChanged(TObject *Sender);
	void __fastcall SFSButton1MouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall SRSButton1MouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall SXSButtonMouse1Down(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall StopButtonMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall ButtonPlusOneClick(TObject *Sender);
	void __fastcall ButtonPlusFiveClick(TObject *Sender);
	void __fastcall ButtonMinusOneClick(TObject *Sender);
	void __fastcall ButtonMinusFiveClick(TObject *Sender);
	void __fastcall SpeedEditValueChanged(TObject *Sender);
	void __fastcall VolumetoMaximumClick(TObject *Sender);
	void __fastcall VolumetoMediumClick(TObject *Sender);
	void __fastcall VolumeMuteClick(TObject *Sender);
	void __fastcall SmokeSwitchStatusChanged(TObject *Sender);
	void __fastcall CPLRFButton1MouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall CPLRRButton1MouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall NewControlWindowClick(TObject *Sender);
	void __fastcall ESTOPClick(TObject *Sender);
	void __fastcall DeleteControlWindowClick(TObject *Sender);
	void __fastcall ClearPreferencesButtonClick(TObject *Sender);
	void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
	void __fastcall VolumeSliderValueChange(TObject *Sender);
	void __fastcall DIRToggleStatusChanged(TObject *Sender);
	void __fastcall EngNumber1Change(TObject *Sender);
	void __fastcall FormActivate(TObject *Sender);
	void __fastcall FormDeactivate(TObject *Sender);
	void __fastcall EngineBox1Click(TObject *Sender);
	void __fastcall CopyrightClick(TObject *Sender);
	void __fastcall PreviousPageClick(TObject *Sender);
	void __fastcall NextPageClick(TObject *Sender);
	void __fastcall RescanEnginesLashups1Click(TObject *Sender);
	void __fastcall SFSButton1MouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall SRSButton1MouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall SXSButton1MouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall CPLRRButton1MouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall CPLRFButton1MouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall UpDown1Changing(TObject *Sender, bool &AllowChange);
    void __fastcall CloseButtonClick(TObject *Sender);


protected:
    void __fastcall CMWhistle(TMessage &Message);
    void __fastcall CMCPLRF(TMessage &Message);
    void __fastcall CMCPLRR(TMessage &Message);

    void __fastcall CMSFS(TMessage &Message);
    void __fastcall CMSRS(TMessage &Message);
    void __fastcall CMSXS(TMessage &Message);

    BEGIN_MESSAGE_MAP
        MESSAGE_HANDLER(CM_WHISTLE, TMessage, CMWhistle)
        MESSAGE_HANDLER(CM_CPLRF, TMessage, CMCPLRF)
        MESSAGE_HANDLER(CM_CPLRR, TMessage, CMCPLRR)
        MESSAGE_HANDLER(CM_SFS, TMessage, CMSFS)
        MESSAGE_HANDLER(CM_SRS, TMessage, CMSRS)
        MESSAGE_HANDLER(CM_SXS, TMessage, CMSXS)
    END_MESSAGE_MAP(TForm)

private:	// User declarations
	__fastcall TQuickCtrl(TComponent* Owner);
 	int RemoteNo;
    int PageNo;
    String RegFileRootKey;
    void __fastcall SetEngineName(int, TLabel *, TButton *, int ConsistNo);
    TMouseButton LastButton; // last mouse button pushed
    int __fastcall PickControlNumber(TObject *Sender);
    TUpDown * UpDownContainer[QUICKCOUNT];
    TGroupBox * EngineBoxContainer[QUICKCOUNT];
    TLabel * EngineNameContainer[QUICKCOUNT];
    int LastSpeedContainer[QUICKCOUNT];		// speed just before a change
    int EngineBoxWidth;
    int iCtrlCount;
    void __fastcall SetRunningState(int ConsistNo, TColor ColorState);
    bool bSetupComplete;
    int EngTypeContainer[ABSOLUTEMAX];
    String EngNameContainer[ABSOLUTEMAX];
    String LashupListContainer[ABSOLUTEMAX];
	void __fastcall ScaleControl(TControl * CC, float SF);
	float SF;
    bool LocalTransparencyOverride;
    unsigned char LashUpCommand[LASHUP_ENGINE_LIST_LENGTH];
    void __fastcall ConvertCSVString(int ConsistNo, int ControlNo);


public:		// User declarations
    __fastcall TQuickCtrl(TComponent* Owner, int Remote, int TIU, float ScaleFactor);
    __fastcall ~TQuickCtrl(void);
    HWND ParentHandle; 		// accessed by Train_Control.cpp
    TColor RunningState[ABSOLUTEMAX];
    int TotalCtrlCount;
    TMaskEdit * EngNumberContainer[QUICKCOUNT];
    TAbHSlider * VolumeSliderContainer[QUICKCOUNT];
    TAbToggleSwitch * DIRToggleContainer[QUICKCOUNT];
    TAbRockerSwitch * BellSwitchContainer[QUICKCOUNT];
    TAbRockerSwitch * SmokeSwitchContainer[QUICKCOUNT];
    TAbNumEdit * SpeedEditContainer[QUICKCOUNT];
    TButton * StartupButtonContainer[QUICKCOUNT];
    TButton * ShutdownButtonContainer[QUICKCOUNT];

    // Expand common controls to whistles and couplers
    TAbColBitBtn * WhistleButtonContainer[QUICKCOUNT];
    TAbColBitBtn * HornButtonContainer[QUICKCOUNT];
    TAbColBitBtn * SFSButtonContainer[QUICKCOUNT];
    TAbColBitBtn * SRSButtonContainer[QUICKCOUNT];
    TAbColBitBtn * SXSButtonContainer[QUICKCOUNT];
    TAbColBitBtn * CPLRFButtonContainer[QUICKCOUNT];
    TAbColBitBtn * CPLRRButtonContainer[QUICKCOUNT];

    int TIUNo[ABSOLUTEMAX];          // TIU number for each engine and lashup

	void __fastcall GetEngData(void);
    void __fastcall GetLashUpData();    // called only from LashUp_Selection.cpp
};
//---------------------------------------------------------------------------
extern PACKAGE TQuickCtrl *QuickCtrl;
//---------------------------------------------------------------------------
#endif
