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

(c) Copyright 2015 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 AIU_ControlH
#define AIU_ControlH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Grids.hpp>
#include "HideButton.h"
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <Menus.hpp>
#include "_GClass.hpp"
#include "AbCBitBt.hpp"
#include "AbSwitch.hpp"

// ACC Data File Columns
#define ACC_NUM 0
#define ACC_NAME 1
#define ACC_STATE 2
#define SW_NAME 3
#define SW_STATE 4

// Acc Data File Rows
#define ACC_LABEL_ROW 0
#define ACC_TOPROW 1

#define ACC_COUNT 5

//---------------------------------------------------------------------------
class TAIUControl : public TForm
{
__published:	// IDE-managed Components
	TStringGrid *AccData;
    THideButton *HideButton;
	TLabel *Accessory_Controls_Label;
	TPopupMenu *AIUPopupMenu;
	TMenuItem *EditACCSwName;
	TPanel *ACCGroup;
	TLabel *Label1;
	TEdit *SelectedAcc;
	TEdit *SelectedSw;
	TLabel *Label2;
	TButton *SwDivergeButton;
	TButton *SwStraightButton;
	TButton *AccActivateButton;
	TButton *AccOffButton;
	TButton *AccOnButton;
	TButton *MakeItSoButton;
	TMenuItem *DeleteACCSwitch;
	TButton *SaveEditsButton;
	TImage *ImageOff;
	TLabel *Label17;
	TImage *ImageOn;
	TLabel *Label12;
	TImage *ImageDiverge;
	TLabel *DivergeLabel;
	TImage *ImageStraight;
	TLabel *StraightLabel;
	TImage *Copyright;
	TAbColBitBtn *NextAIU;
	TAbColBitBtn *PrevAIU;
	TAbColBitBtn *NextTIU;
	TAbColBitBtn *PrevTIU;
    TAbToggleSwitch *AllToggleSwitch;
    TLabel *Label3;
    TLabel *Label4;
    TAbToggleSwitch *WatchdogToggleSwitch;
	void __fastcall AccDataDrawCell(TObject *Sender, int ACol, int ARow,
          TRect &Rect, TGridDrawState State);
	void __fastcall AccDataKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
	void __fastcall AccDataMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall EditACCSwNameClick(TObject *Sender);
	void __fastcall AccActivateButtonMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall AccActivateButtonMouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall AccOnButtonMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall AccOffButtonMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall SwStraightButtonMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall SwDivergeButtonMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall AccDataClick(TObject *Sender);
	void __fastcall MakeItSoButtonClick(TObject *Sender);
	void __fastcall DeleteAccSw(TObject *Sender);
	void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
	void __fastcall SaveEditsButtonClick(TObject *Sender);
	void __fastcall AccDataDblClick(TObject *Sender);
	void __fastcall FormDeactivate(TObject *Sender);
	void __fastcall FormActivate(TObject *Sender);
	void __fastcall Accessory_Controls_LabelClick(TObject *Sender);
	void __fastcall CopyrightClick(TObject *Sender);
	void __fastcall NextAIUClick(TObject *Sender);
	void __fastcall PrevAIUClick(TObject *Sender);
	void __fastcall AccOnButtonClick(TObject *Sender);
	void __fastcall AccOffButtonClick(TObject *Sender);
	void __fastcall AccActivateButtonClick(TObject *Sender);
	void __fastcall SwStraightButtonClick(TObject *Sender);
	void __fastcall SwDivergeButtonClick(TObject *Sender);
	void __fastcall NextTIUClick(TObject *Sender);
	void __fastcall PrevTIUClick(TObject *Sender);

protected:
	void __fastcall CMAct(TMessage &Message);
    BEGIN_MESSAGE_MAP
        MESSAGE_HANDLER(CM_ACT, TMessage, CMAct)
	END_MESSAGE_MAP(TForm)

private:	// User declarations
    int EngineNo, TIUNo, RemoteNo, AIUNo;
    String ACCDataFile;
    bool bACCSWDataCorrupt, bACCSWDataLoaded;
    int __fastcall ValidateACCDat(int ACCNum);
    void __fastcall SaveACCDat(void);

    bool LocalTransparencyOverride;
    String RegFileRootKey;

public:		// User declarations
	__fastcall TAIUControl(TComponent* Owner);
    __fastcall TAIUControl(TComponent* Owner, int Remote, int Engine, int TIU, int AIU);
    __fastcall ~TAIUControl(void);
	HWND ParentHandle; 		// accessed by Train_Control.cpp
    TObject * Requester;    // accessed ty Train_Control.cpp
};
//---------------------------------------------------------------------------
extern PACKAGE TAIUControl *AIUControl;
//---------------------------------------------------------------------------
#endif
