// LMainWindow.h
// `````````````

#pragma once
#include "stdafx.h"
#include "LSettingsWindow.h"

struct listItemData;

class LMainWindow : public MGWindow {
public:

	// Constants

	enum modes {
		MODE_REPEATLIST = 0,
		MODE_REPEATFILE,
		MODE_PLAYLIST,
		MODE_PLAYFILE,
		MODE_SHUFFLE,
		MODE_COUNT_MODES
	};
	enum display_modes {
		DISPLAY_FULLPATH,
		DISPLAY_NAMEONLY,
		DISPLAY_COUNT_MODES
	};

private:

	// BASSlib handles for currently playing file/channel

	HSTREAM hCurrent;
	long    lBitrate;
	TCHAR*  tFormat;
	QWORD   qwChannelLength;
	int     curListIndex;

	// File switching and display modes	

	int     displayMode;
	int		currentMode;
	TCHAR*	tCurrentMode;
	std::deque<int> qIndexes;

	// Child windows
	// TODO: the `find' window, help windows etc

	LSettingsWindow* wndSettings;	

	// Child controls

	MGTimer       *tmrBASS;
	MGListBox     *lbMain;
	MGProgressBar *pbProgress, *pbVolume, *pbLevelLeft, *pbLevelRight;
	MGLabel       *llProgress, *llVolume;
	MGHotkey      *hkNextSong, *hkPlayPause, *hkFocusWindow;	
	MGMenuItem
		*mnuFile,
			*mnuFileOpenFolder, *mnuFileAddFolder, *mnuFileAddFiles,
			*mnuFileOpenPlaylist, *mnuFileSavePlaylist,
			*mnuFileExit,
		*mnuEdit,
			*mnuEditProperties, *mnuEditRemove,
			*mnuEditTools,
				*mnuTSelectCurrent,
				*mnuTClearAll,
			*mnuEditFind,
		*mnuPlay,
			*mnuPlayPlay, *mnuPlayPause, *mnuPlayStop,
			*mnuPlayNext, *mnuPlayPrevious, *mnuPlayQueue,
		*mnuFavorites,
			*mnuFavsAdd,
		*mnuOptions,
			*mnuOptSettings,
			*mnuOptRepeatList, *mnuOptRepeatFile, *mnuOptPlayList, *mnuOptPlayFile,
			*mnuOptShuffle,    *mnuOptToggle,
		*mnuView,
			*mnuViewFilenames, *mnuViewFullpath, *mnuViewRelpath,
			*mnuViewToggle,
			*mnuViewControls, *mnuViewProgress,
		*mnuHelp,
			*mnuHelpOverview, *mnuHelpHomepage,
			*mnuHelpAbout
	;

	// Functions

	void addFolder(TSTRING &path);
	void playFile(int listIndex);
	void playNext();	
	void setShuffleMode(int newMode);
	void setDisplayMode(int newMode);
	void formatListItem(int idx, listItemData* d);
	void formatListItemColour(int idx, listItemData* d);
	void formatQueuedListItem(int idx, listItemData* d, int queue_pos);	
	void formatQueuedListItems();

	// Cosmetic Functions

	void repopulateStatusBar();

	// Event callbacks

	void OnWindowResize();
	void OnWindowClosing();
	void OnBASSTimer();
	void OnListDoubleClick();
	void OnProgressDragged();
	void OnProgressMDown();
	void OnHotkeyFocusWindow();

	// Menu commands

	void OnFileOpenFolder();
	void OnFileAddFolder();
	void OnFileAddFiles();
	void OnFileExit();
	void OnToolsSelectCurrent();
	void OnPlayPlay();
	void OnPlayPause();
	void OnPlayStop();
	void OnPlayQueue();
	void OnViewFilenames();
	void OnViewFullpath();
	void OnViewToggle();
	void OnOptionsSettings();
	void OnOptionsRepeatList();
	void OnOptionsRepeatFile();
	void OnOptionsPlayList();
	void OnOptionsPlayFile();
	void OnOptionsShuffle();
	void OnOptionsToggle();
	void OnHelpAbout();

public:
	
	// Constructor / Deconstructor

	LMainWindow();
	~LMainWindow();
	
	// Public functions

	void doChildWindowEvents();	
	static void CALLBACK EventProc(HSYNC handle, DWORD channel, DWORD data, void* user);

};