#ifndef IFSCHOOSERWINDOW_HPP
#define IFSCHOOSERWINDOW_HPP

#include "windows.h"
#include "ifs.hpp"

enum {
CHILD_FUNCTIONSLISTVIEW,
CHILD_DRAWINGPROGRESSBAR,
CHILD_MERGEPAINTBUTTON,
CHILD_REPAINTBUTTON,
CHILD_ADDBUTTON,
CHILD_EDITBUTTON,
CHILD_DELETEBUTTON,
CHILD_LOADIFSBUTTON,
CHILD_SAVEIFSBUTTON,
ENTRYCHILD_FUNCTIONTITLEEDITBOX,
ENTRYCHILD_INPUTMETHODTABS,
ENTRYCHILD_XCOMPONENTEDITBOX,
ENTRYCHILD_YCOMPONENTEDITBOX,
ENTRYCHILD_PROBABILITYTRACKBAR,
ENTRYCHILD_PROBABILITYEDITBOX,
ENTRYCHILD_OKBUTTON,
ENTRYCHILD_CANCELBUTTON
};

/*#define CHILD_FUNCTIONSLISTVIEW 1
#define CHILD_DRAWINGPROGRESSBAR 2
#define CHILD_MERGEPAINTBUTTON 3
#define CHILD_REPAINTBUTTON 4
#define CHILD_ADDBUTTON 5
#define CHILD_EDITBUTTON 6
#define CHILD_DELETEBUTTON 7
#define CHILD_LOADIFSBUTTON 8
#define CHILD_SAVEIFSBUTTON 9*/

typedef enum {MODE_ADD, MODE_EDIT} TIFSEntryWindowMode;
typedef enum {METHOD_AFFINE, METHOD_GENERAL} TIFSEntryWindowMethod;

class TIFSChooserWindow {
private:
HINSTANCE AppInst;
HANDLE RePaintEvent, MergePaintEvent;
TIFS *IFS;

HWND Handle;
HDC DC;
void ConstructIFSChooserWindow(char *Title);
void DestroyIFSChooserWindow();
HWND CreateIFSChooserWindow(char *Title);

HWND FunctionsListView;
int ItemSelected;
int ItemsInList;
HWND CreateFunctionsListView();
void CreateListViewColumns();
void AddFunction(char *FunctionTitle, TAffineTransformation t, float p);
void AddFunction(char *FunctionTitle, char *sx, char *sy, float p);
void AddFunctionToList(char *NumberString, char *NameString, char *ProbString);
void ChangeFunctionSelected();
void DeleteSelectedFunction();

HWND DrawingProgressBar;
HWND CreateDrawingProgressBar();
int *ProgressPtr;

HWND MergePaintButton, RePaintButton;
HWND AddButton, EditButton, DeleteButton;
HWND LoadIFSButton, SaveIFSButton;
HWND CreateIFSChooserWindowButton(char *s, int ID, int x, int y, int Width);

HWND IFSEntryWindow;
RECT IFSEntryWindowRect;
int IFSEntryWindowWidth, IFSEntryWindowHeight;
TIFSEntryWindowMode IFSEntryWindowMode;
TIFSEntryWindowMethod IFSEntryWindowMethod;
void ConstructIFSEntryWindow();
void DestroyIFSEntryWindow();
HWND CreateIFSEntryWindow();
void ClearIFSEntryWindow();
void HideIFSEntryWindow();

HWND InputMethodTabs;
HWND CreateInputMethodTabs();
int CreateInputMethodTab(char *s, int i);

int AffineTransformationTab;
int GeneralTab;
void ProcessTabChange();

HWND OKButton, CancelButton;
HWND CreateIFSEntryWindowButton(char *s, int ID, int x, int y, int Width);
void CallAddFunction();
void CallEditFunction();

HWND ProbabilityTrackbar;
HWND CreateProbabilityTrackbar();
void UpdateProbabilityTrackbar();
void UpdateProbabilityEditBox();

HWND FunctionTitleEditBox;
HWND XComponentEditBox;
HWND YComponentEditBox;
HWND ProbabilityEditBox;
HWND CreateIFSEntryWindowEditBox(int ID, int x, int y, int Width, bool PartOfTabs);

public:
TIFSChooserWindow(HINSTANCE xAppInst, int ShowCommand, char *Title);
~TIFSChooserWindow();
HANDLE GetMergePaintEvent();
HANDLE GetRePaintEvent();
TReadOnlyIFS *ReadOnlyIFS;

static LRESULT CALLBACK GlobalWndProc(HWND hwnd, UINT MsgIdent, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK WndProc(HWND hwnd, UINT MsgIdent, WPARAM wParam, LPARAM lParam);

static LRESULT CALLBACK GlobalEntryWndProc(HWND hwnd, UINT MsgIdent, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK EntryWndProc(HWND hwnd, UINT MsgIdent, WPARAM wParam, LPARAM lParam);

void SetProgressPtr(int *xProgressPtr);
void BringToTop();
void SetupTriangle();
};

#endif
