#pragma once
#include "skinnablewindow.h"
#include "verticalscrollbar.h"
#include "embeddableimage.h"
#include <comutil.h>
#include <Richedit.h>
#include <Richole.h>

class TextBox : 
	public SkinnableWindow
{
public:
	TextBox(void);
	~TextBox(void);
	virtual void OnPaint(HWND hWnd, HDC hdc);
	virtual void OnLButtonDown();
	virtual void OnLButtonUp();
	virtual void OnMouseMove();
	virtual int OnChar(WPARAM wParam, LPARAM lParam);
	virtual void OnKeyDown(WPARAM wParam, LPARAM lParam);
	virtual void OnSize(int cx, int cy);
	virtual void OnScroll(HWND h);
	virtual HWND GetTabToTarget(){ return hEditCtrl;};
	virtual HWND GetTabFromTarget(){ return hEditCtrl;};
	virtual void OnDestroy();

	virtual void Load(const char * base);

	// set the msg that will be sent upon pressing enter in this textbox (e.g. activate a button)
	void SetMsgOnCarriageReturn(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
	int Create(HWND parent = 0, DWORD style = ES_LEFT); // add Edit Control styles for other options
	static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
	void GetText(std::wstring& buffer);
	const TCHAR * Data();
	void SetText(const TCHAR * buffer);
	void AppendText(const TCHAR * buffer);
	void GrabFocus();

	void Select(int start, int end);
	void SelectAll();

	// for the current selection...
	void SetForegroundColor(Color c);
	void SetBackgroundColor(Color c);

	// images
	void InsertBitmap(Bitmap * bmp);

	// Data
	HWND hEditCtrl;
	IRichEditOle * pOle;
	int textheight;

	void ShowScrollBar();
	void HideScrollBar();
	VerticalScrollBar scrollbar;

	// the text box will send this message on carriage returns
	HWND ncrhWnd;
	UINT ncrMsg;
	WPARAM ncrwParam;
	LPARAM ncrlParam;

	// num of pixels around the edit ctrl
	int padding;
private:
	WNDPROC DefEditCtrlWndProc;
	void FitText(int scrolltoend = 1);
	int multiline;
	_bstr_t buffer;

};