#ifndef __FILECONTROL_H__
#define __FILECONTROL_H__

#include <wx/wx.h>
#include <wx/bmpbuttn.h>
#include <wx/xrc/xmlres.h>
#include "VrutApi.h"


namespace VRUT
{
	class VRUT_CORE_API FileControl: public wxWindow
	{
		wxTextCtrl *textCtrl;
		wxBitmapButton *button;
		wxString message;
		wxString wildcard;
		long style;
		bool type;

		void OnClick(wxCommandEvent &evt);

		void OnTextEnter(wxCommandEvent &evt)
		{
			SendEvent();
		}

		void SendEvent();

		void LocalInit(const wxString &newValue = wxEmptyString, long newStyle = wxFD_DEFAULT_STYLE, const wxString &newWildcard = wxFileSelectorDefaultWildcardStr, bool newType = true);

	public:
		FileControl() : wxWindow(), textCtrl(NULL), button(NULL), style(wxFD_DEFAULT_STYLE), type(true) {}

		FileControl(wxWindow *parent, wxWindowID id, const wxString &value = wxEmptyString, long style = wxFD_DEFAULT_STYLE, const wxString &wildcard = wxFileSelectorDefaultWildcardStr, bool type = true);

		bool Create(wxWindow * parent, wxWindowID id, const wxPoint & pos = wxDefaultPosition, const wxSize & size = wxDefaultSize, long style = 0, const wxString & name = wxPanelNameStr);

		void SetToolTip(const wxString &toolTip)
		{
			message = toolTip;
			textCtrl->SetToolTip(toolTip);
			button->SetToolTip(toolTip);
		}

		static wxString ConvertToNativePath(const wxString &path);

		void SetValue(const wxString &value)
		{
			textCtrl->SetValue(ConvertToNativePath(value));
		}

		wxString GetValue() const
		{
			return textCtrl->GetValue();
		}

		void SetMode(long newStyle);

		void SetWildcard(const wxString &newWildcard = wxFileSelectorDefaultWildcardStr)
		{
			wildcard = newWildcard;
		}

		void SetDialogType(bool fileDialog = true)
		{
			type = fileDialog;
		}

	DECLARE_DYNAMIC_CLASS(FileControl)
	};

	class FileControlXmlHandler: public wxXmlResourceHandler
	{
	public:
		// Constructor.
		FileControlXmlHandler()
		{
			AddWindowStyles();
		}

		// Creates the control and returns a pointer to it.
		virtual wxObject *DoCreateResource()
		{
			XRC_MAKE_INSTANCE(control, FileControl)

			control->Create(m_parentAsWindow, GetID(), GetPosition(), GetSize(), GetStyle(wxT("style")), GetName());

			SetupWindow(control);

			return control;
		}

		// Returns true if we know how to create a control for the given node.
		virtual bool CanHandle(wxXmlNode *node)
		{
			// this function tells XRC system that this handler can parse
			// the <object class="MyControl"> tags
			return IsOfClass(node, wxT("FileControl"));
		}

		// Register with wxWidgets' dynamic class subsystem.
		DECLARE_DYNAMIC_CLASS(FileControlXmlHandler)
	};
}

#endif
