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

*/
//---------------------------------------------------------------------------
#ifndef Route_SceneH
#define Route_SceneH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include "AbNumEdit.hpp"
#include "SyncListBox.h"
#include <ComCtrls.hpp>
#include <Grids.hpp>
#include <Menus.hpp>
#include <ImgList.hpp>

#define RS_FILENAME "RouteScene.ini"
// Route/Scene Data File Rows
#define RS_LABEL_ROW 0
#define RS_TOPROW 1

// Route/Scene 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 RS_NUM 0
#define RS_NAME 1
#define RS_LIST 2	// this is not used

// Route/Scene Data File Initial Values
#define RSDAT_TITLE "\"#\",\"Route/Scene Name\",\"Spare\""
#define RSDAT_INIT       ",*                   ,\" \""
#define RSDAT_COUNT 3

#define RSCONTROL_COUNT 5

#define RSUPDOWNLIMIT  (RSData->RowCount)

//---------------------------------------------------------------------------
class TRouteScene : public TForm
{
__published:	// IDE-managed Components
	TButton *HideButton;
	TLabel *RS_Controls_Label;
	TPageControl *RSPageControl;
	TTabSheet *SelectRSSheet;
    TLabel *Route_Scene_List_Label;
	TLabel *Label47;
	TLabel *Label16;
	TStringGrid *RSData;
	TSyncListBox *RSinSelectedListBox;
    TAbNumSpin *RSSpin;
	TEdit *NameofRS;
	TButton *RSActivateButton;
    TButton *RSResetButton;
	TButton *CreateRS;
	TButton *EditRS;
	TButton *DeleteRS;
	TTabSheet *CreateRSSheet;
	TLabel *Label5;
	TLabel *Label6;
	TLabel *Label2;
	TLabel *Label1;
	TLabel *Label13;
	TLabel *Label18;
	TSyncListBox *SWACCinSelectedRSListBox;
	TButton *SelectButton;
	TListBox *SwitchAccessoryListBox;
	TEdit *RSName;
	TGroupBox *GroupBox2;
	TButton *SaveRSButton;
	TButton *CancelRSButton;
	TButton *ReloadButton;
	TButton *ClearSelectionButton;
	TLabel *Label15;
	TLabel *Label3;
	TPopupMenu *RSDataPopupMenu;
	TMenuItem *CreateNewRouteScene;
	TMenuItem *EditRouteScene;
	TMenuItem *DeleteRouteScene;
	TEdit *SelectedSwAcc;
	TImage *ImageOff;
	TImage *ImageOn;
	TImage *ImageDiverge;
	TImage *ImageStraight;
	TLabel *Label4;
	TLabel *Label7;
    TLabel *DivergeLabel1;
    TLabel *StraightLabel1;
	TImage *ImageOff1;
	TImage *ImageOn1;
	TImage *ImageDiverge1;
	TImage *ImageStraight1;
    TLabel *StraightLabel;
    TLabel *DivergeLabel;
	TLabel *Label12;
	TLabel *Label17;
    TPanel *DetailsPanel;
	TLabel *TIUNumber;
	TLabel *ChannelNumber;
	TLabel *AIUNumber;
	TPopupMenu *RSPopupMenu;
	TMenuItem *Help1;
	TLabel *Label19;
	TLabel *Legend;
	TLabel *Label20;
	TImage *Copyright;
	TUpDown *RSUpDown;
	TMenuItem *RestoreScrollBarsforRouteScenelist1;
    TLabel *Label8;
    TButton *AllSwNormalButton;
    TButton *AllAccyOffButton;
    TButton *AllAccyOnButton;
    TButton *SaveEditsButton;
    TMenuItem *OpenPopoutRouteSceneList1;
	void __fastcall HideButtonClick(TObject *Sender);
	void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
	void __fastcall CancelRSButtonClick(TObject *Sender);
	void __fastcall CreateRSClick(TObject *Sender);
	void __fastcall EditRSClick(TObject *Sender);
	void __fastcall DeleteRSClick(TObject *Sender);
	void __fastcall RSDataDrawCell(TObject *Sender, int ACol, int ARow,
          TRect &Rect, TGridDrawState State);
	void __fastcall SaveRSButtonClick(TObject *Sender);
	void __fastcall RSDataClick(TObject *Sender);
	void __fastcall RSSpinValueChanged(TObject *Sender);
	void __fastcall ReloadButtonClick(TObject *Sender);
	void __fastcall SelectButtonClick(TObject *Sender);
	void __fastcall UnSelectButtonClick(TObject *Sender);
	void __fastcall RSResetButtonClick(TObject *Sender);
	void __fastcall RSActivateButtonClick(TObject *Sender);
	void __fastcall SwitchAccessoryListBoxClick(TObject *Sender);
	void __fastcall SWACCinSelectedRSListBoxDrawItem(TWinControl *Control,
          int Index, TRect &Rect, TOwnerDrawState State);
	void __fastcall SWACCinSelectedRSListBoxClick(TObject *Sender);
	void __fastcall SWACCinSelectedRSListBoxDblClick(TObject *Sender);
	void __fastcall Help1Click(TObject *Sender);
	void __fastcall RSDataKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
	void __fastcall RSDataDblClick(TObject *Sender);
	void __fastcall RSUpDownClick(TObject *Sender, TUDBtnType Button);
	void __fastcall RestoreScrollBarsforRouteScenelist1Click(TObject *Sender);
	void __fastcall FormActivate(TObject *Sender);
	void __fastcall FormDeactivate(TObject *Sender);
	void __fastcall RS_Controls_LabelClick(TObject *Sender);
	void __fastcall FormShow(TObject *Sender);
	void __fastcall CopyrightClick(TObject *Sender);
    void __fastcall AllSwNormalButtonClick(TObject *Sender);
    void __fastcall AllAccyOnButtonClick(TObject *Sender);
    void __fastcall AllAccyOffButtonClick(TObject *Sender);
    void __fastcall SaveEditsButtonClick(TObject *Sender);
    void __fastcall OpenPopoutRouteSceneList1Click(TObject *Sender);
    void __fastcall RSDataMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);

private:	// User declarations
	void __fastcall LoadRSData(TStringGrid * RSD);
	void __fastcall SaveRSData(TStringGrid * RSD);
    bool bRSDataCorrupt, bRSDataLoaded;
    int RSNo, RemoteNo;
    String RegFileRootKey;
    int __fastcall ValidateRSData(TStringGrid *RSD, int RSNum);
    void __fastcall ProcessReload(TSearchRec sr);
	void __fastcall LoadSwitchAccessoryData(int RSNo, TSyncListBox *SAList);
	void __fastcall SaveSwitchAccessoryData(int RSNo, TSyncListBox *SAList);
    void __fastcall CopySelectedList(TListBox *, TSyncListBox *, bool);
	int AccDataFileCounter;	// Number of AccDataXY.ini files found

    bool LocalTransparencyOverride;

public:		// User declarations
   	__fastcall TRouteScene(TComponent* Owner);
    __fastcall ~TRouteScene(void);

};
//---------------------------------------------------------------------------
extern PACKAGE TRouteScene *RouteScene;
//---------------------------------------------------------------------------
#endif
