#ifndef _COMMON_OPENDIALOG_HPP_
#define _COMMON_OPENDIALOG_HPP_
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif
#ifndef _COMMON_COMMDLG_HPP_
#include <common/commdlg.hpp>
#endif
#ifndef _COMMON_STRING_HPP_
#include <common/string.hpp>
#endif
#ifndef _COMMON_BLOCK_HPP_
#include <common/block.hpp>
#endif

class GUIWindow;

class OpenDialog : private OPENFILENAME
{
public:
	enum Flags{ALLOWMULTISELECT=OFN_ALLOWMULTISELECT,
						 CREATEPROMPT=OFN_CREATEPROMPT,
						 ENABLEHOOK=OFN_ENABLEHOOK,
						 ENABLETEMPLATE=OFN_ENABLETEMPLATE,
						 ENABLETEMPLATEHANDLE=OFN_ENABLETEMPLATEHANDLE,
						 EXPLORER=OFN_EXPLORER,
						 EXTENSIONDIFFERENT=OFN_EXTENSIONDIFFERENT,
						 FILEMUSTEXIST=OFN_FILEMUSTEXIST,
						 HIDEREADONLY=OFN_HIDEREADONLY,
						 LONGNAMES=OFN_LONGNAMES,
						 NOCHANGEDIR=OFN_NOCHANGEDIR,
						 NODEREFERENCELINKS=OFN_NODEREFERENCELINKS,
						 NOLONGNAMES=OFN_NOLONGNAMES,
						 NONETWORKBUTTON=OFN_NONETWORKBUTTON,
						 NOREADONLYRETURN=OFN_NOREADONLYRETURN,
						 NOTESTFILECREATE=OFN_NOTESTFILECREATE,
						 NOVALIDATE=OFN_NOVALIDATE,
						 OVERWRITEPROMPT=OFN_OVERWRITEPROMPT,
						 PATHMUSTEXIST=OFN_PATHMUSTEXIST,
						 READONLY=OFN_READONLY,
						 SHAREAWARE=OFN_SHAREAWARE,
						 SHOWHELP=OFN_SHOWHELP};
	OpenDialog(void);
	OpenDialog(const OpenDialog &someOpenDialog);
	virtual ~OpenDialog();
	OpenDialog &operator=(const OpenDialog &someOpenDialog);
	BOOL operator==(const OpenDialog &someOpenDialog)const;
	BOOL getOpenFileName(GUIWindow &parentWindow,const String &filterPatternString,const String &titleString,const String &fileTitleString,String &pathFileName);
	BOOL getSaveFileName(GUIWindow &parentWindow,const String &filterPatternString,const String &titleString,const String &fileTitleString,String &pathFileName);
	BOOL getOpenFileName(const String &filterPatternString,const String &titleString,const String &fileTitleString,String &pathFileName);
  BOOL getOpenFileName(const String &filterPatternString,const String &titleString,const String &fileTitleString,Block<String> &strFileNames);
	BOOL getSaveFileName(const String &filterPatternString,const String &titleString,const String &fileTitleString,String &pathFileName);
	BOOL getSaveFileName(void);
	BOOL getOpenFileName(void);
	HWND owner(void)const;
	void owner(HWND hwndOwner);
	HINSTANCE instance(void)const;
	void instance(HINSTANCE hInstance);
	const String &filter(void)const;
	void filter(const String &filter);
	const String &filterPattern(void)const;
	void filterPattern(const String &filterPattern);
	const String &customFilter(void)const;
	void customFilter(const String &customFilter);
	DWORD filterIndex(void)const;
	void filterIndex(DWORD filterIndex);
	const String &fileName(void)const;
	void fileName(const String &fileName);
	const String &fileTitle(void)const;
	void fileTitle(const String &fileTitle);
	const String &initialDirectory(void)const;
	void initialDirectory(const String &initialDirectory);
	const String &title(void)const;
	void title(const String &title);
	DWORD creationFlags(void)const;
	void creationFlags(DWORD creationFlags);
	const String &defaultExtension(void)const;
	void defaultExtension(const String &defaultExtension);
	const String &templateName(void)const;
	void templateName(const String &templateName);
  LPOFNHOOKPROC hookProc(void)const;
	void hookProc(LPOFNHOOKPROC pHookProc);
	DWORD customData(void)const;
	void customData(DWORD customData);
	int size(void)const;
	const String &operator[](int index);
private:
	enum {MaxLength=32768,MaxMultiSelect=65536,MaxTitle=512,MaxSaveLength=512};
	void setZero(void);
	void setLength(void);
  void parseFileNames(const String &nameBuffer,Block<String> &fileNames);
  String parseLine(int &index,const String &strLine);

	String mFilter;
  String mFilterPattern;
	String mCustomFilter;
	String mFileName;
	String mFileTitle;
  String mTitle;
	String mInitialDirectory;
	String mDefaultExtension;
	String mTemplateName;
	String mFileNameBuffer;
	String mFileTitleBuffer;
	Block<String> mFileNames;
};

inline
int OpenDialog::size(void)const
{
  return mFileNames.size();
}

inline
const String &OpenDialog::operator[](int index)
{
  return mFileNames[index];
}
#endif

