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

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

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

// LashUp Data File Rows
#define LASHUP_LABEL_ROW 0
#define LASHUP_TOPROW 1

// LashUp Data File Columns - NOTE that all of these columns are Strings
// https://stackoverflow.com/questions/53671394/c-builder-allows-string-comparison-with-int-why
// "As RemyLebeau said: Note that String is not an actual type, it is an
// alias for either AnsiString (C++Builder 2007 and earlier) or UnicodeString
// (C++Builder 2009 and later). Both do implement implicit conversions from numeric types."
#define LASHUP_NUM 0
#define LASHUP_NAME 1
#define LASHUP_LIST 2

// LashUp Data File Initial Values
#define LASHUPDAT_TITLE "\"#\",\"LashUp Name\",\"Consist\""
#define LASHUPDAT_INIT       ",*,              \" \""
#define LASHUPDAT_COUNT 3

#define LASHUPUPDOWNLIMIT  (LashUpData->RowCount)

//---------------------------------------------------------------------------
class TLashUp : public TForm
{
__published:	// IDE-managed Components
	TButton *HideButton;
	TLabel *LashUp_Controls_Label;
	TPageControl *LashUpPageControl;
	TTabSheet *SelectLashUpSheet;
	TTabSheet *CreateLashUpSheet;
	TLabel *Label4;
	TLabel *Label5;
	TSyncListBox *MiddleEngineSelected;
	TLabel *Label12;
	TCheckListBox *HERevCheckListBox;
	TCheckListBox *MERevCheckListBox;
	TCheckListBox *TERevCheckListBox;
	TLabel *Label11;
	TLabel *Label6;
	TLabel *Label2;
	TButton *HeadEngineButton;
	TLabel *Label8;
	TLabel *Label9;
	TButton *MiddleEngineButton;
	TLabel *Label7;
	TLabel *Label3;
	TButton *TailEngineButton;
	TListBox *EngineListBox;
	TLabel *Label1;
	TEdit *LashUpEncodedEdit;
	TLabel *Label13;
	TEdit *LashUpName;
	TLabel *Label10;
	TButton *BuildConsistButton;
	TLabel *Label15;
	TStringGrid *LashUpData;
	TSyncListBox *EnginesinLashUpListBox;
	TCheckListBox *RevCheckListBox;
    TLabel *LashUp_List_Label;
    TGroupBox *ActionBox;
	TButton *SaveLashUpButton;
	TLabel *Label47;
    TAbNumSpin *LUpSpin;
	TEdit *NameofLashUp;
	TLabel *Label16;
	TPopupMenu *LashUpDataPopupMenu;
	TMenuItem *CreateNewLashUp;
	TMenuItem *EditLashUp;
	TMenuItem *BreakUpLashUp;
	TButton *LashUpStartUpButton;
	TButton *LashUpVolButton;
	TButton *LashUpShutdownButton;
	TButton *LashUpOpButton;
	TLabel *Label17;
	TButton *CancelLashUpButton;
	TButton *CreateLU;
	TButton *EditLU;
	TButton *BreakUpLU;
	TButton *ReloadButton;
	TLabel *Label18;
	TButton *StartupAllButton;
	TButton *ShutdownAllButton;
	TButton *RemoveMiddleEnginefromListButton;
	TSyncListBox *HeadEngineSelected;
	TSyncListBox *TailEngineSelected;
	TButton *ClearHeadEngineListButton;
	TButton *ClearTailEngineListButton;
	TLabel *OptionalLabel;
	TImage *Copyright;
	TUpDown *LashUpUpDown;
	TLabel *Label19;
	TAbColBitBtn *ESTOP;
    TMenuItem *OpenPopOutLashUpList;
    TButton *SaveEditsButton;
    TLabel *Label14;
    TLabel *Label20;
	void __fastcall HideButtonClick(TObject *Sender);
	void __fastcall MiddleEngineButtonClick(TObject *Sender);
	void __fastcall BuildConsistButtonClick(TObject *Sender);
	void __fastcall HeadEngineButtonClick(TObject *Sender);
	void __fastcall TailEngineButtonClick(TObject *Sender);
	void __fastcall SaveLashUpButtonClick(TObject *Sender);
	void __fastcall LashUpStartUpButtonClick(TObject *Sender);
	void __fastcall RevCheckListBoxClickCheck(TObject *Sender);
	void __fastcall LashUpVolButtonClick(TObject *Sender);
	void __fastcall CreateNewLashUpClick(TObject *Sender);
	void __fastcall EditLashUpClick(TObject *Sender);
	void __fastcall BreakUpLashUpClick(TObject *Sender);
	void __fastcall LUpSpinValueChanged(TObject *Sender);
	void __fastcall LashUpOpButtonClick(TObject *Sender);
	void __fastcall LashUpShutdownButtonClick(TObject *Sender);
	void __fastcall CancelLashUpButtonClick(TObject *Sender);
	void __fastcall ReloadButtonClick(TObject *Sender);
	void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
	void __fastcall ShutdownAllButtonClick(TObject *Sender);
	void __fastcall StartupAllButtonClick(TObject *Sender);
	void __fastcall LashUpDataDrawCell(TObject *Sender, int ACol, int ARow,
          TRect &Rect, TGridDrawState State);
	void __fastcall RemoveMiddleEnginefromListButtonClick(TObject *Sender);
	void __fastcall ClearHeadEngineListButtonClick(TObject *Sender);
	void __fastcall ClearTailEngineListButtonClick(TObject *Sender);
	void __fastcall EnginesinLashUpListBoxClick(TObject *Sender);
	void __fastcall LashUpDataKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
	void __fastcall LashUpDataDblClick(TObject *Sender);
	void __fastcall LashUpUpDownClick(TObject *Sender, TUDBtnType Button);
	void __fastcall FormDeactivate(TObject *Sender);
	void __fastcall FormActivate(TObject *Sender);
	void __fastcall LashUp_Controls_LabelClick(TObject *Sender);
	void __fastcall LashUpDataMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall LashUpDataClick(TObject *Sender);
	void __fastcall CopyrightClick(TObject *Sender);
	void __fastcall ESTOPClick(TObject *Sender);
    void __fastcall OpenPopOutLashUpListClick(TObject *Sender);
    void __fastcall SaveEditsButtonClick(TObject *Sender);
    void __fastcall HERevCheckListBoxClick(TObject *Sender);
    void __fastcall MERevCheckListBoxClick(TObject *Sender);
    void __fastcall TERevCheckListBoxClick(TObject *Sender);

private:	// User declarations
    int RemoteNo, LashUpNo;
    void __fastcall CopySelectedList(TListBox *, TSyncListBox *, TCheckListBox * DestCLB, bool);
    bool bLashUpDataCorrupt, bLashUpDataLoaded;
    String LashUpDataFile;
    String RegFileRootKey;
    int __fastcall ValidateLashUpData(TStringGrid * LD, int LashUpNum);
	void __fastcall LoadLashUpData(TStringGrid * LD);
	void __fastcall SaveLashUpData(TStringGrid * LD);
   	unsigned char LashUpCommand[LASHUP_ENGINE_LIST_LENGTH];

    bool LocalTransparencyOverride;

public:		// User declarations
   	__fastcall TLashUp(TComponent* Owner);
    __fastcall ~TLashUp(void);
	void __fastcall ParseLashUpEngine(String, TSyncListBox *, TCheckListBox *);
};
//---------------------------------------------------------------------------
extern PACKAGE TLashUp *LashUp;
//---------------------------------------------------------------------------
#endif
