// AsTable.h : header file
//
#if !defined(_ASTABLE_H_)
#define _ASTABLE_H_

#include <vector>

using namespace std;

class CAsTableRow;
class CAsBaseCell;

/////////////////////////////////////////////////////////////////////////////
// CAsTable window

class CAsTable : public CWnd
{
// Construction / destruction
public:
	CAsTable();
	virtual ~CAsTable();

// Attributes
public:
	void SetFixedRowsNumber(int number);
	int GetFixedRowsNumber() const;

	void SetFixedColumnsNumber(int number);
	int GetFixedColumnsNumber() const;

	void SetColumnWidth(int index, int width);
	int GetColumnWidth(int index);

	void SetColumnsNumber(int number, int width = 80);
	int GetColumnsNumber() const;


// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAsTable)
	public:
	virtual BOOL Create(const CRect& rc, CWnd* parentWnd, DWORD style, UINT nID);
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	//}}AFX_VIRTUAL

// Implementation
public:
	CAsTableRow* AppendRow(int numColumns, bool redraw = true);
	CAsTableRow* InsertRow(int index, int numColumns, bool redraw = true);
	CAsTableRow* GetRow(int index);
	void DeleteRow(int index, bool redraw = true);
	long GetRowCount() const;
	void DeleteAll();
	void DeleteNonFixedRows();
	bool GetSelectedItem(CAsTableRow** row, CAsBaseCell** cell, int& rowIndex, int& cellIndex);

	void SetBkColor(COLORREF bkColor, bool redraw = true);
	COLORREF GetBkColor() const;

	// Generated message map functions
protected:
	//{{AFX_MSG(CAsTable)
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnPaint();
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP();

	void Clear();
	void UpdateWindowSize(bool redraw = true);
	void UpdateFirstNonFixedRowIndex();
	void UpdateFirstNonFixedColumnIndex();
	void UpdateDrawArea();

	void DrawBackground(CDC* pDC);
	void DrawBorders(CDC* pDC);
	void DrawRows(CDC* pDC);

	int GetNonFixedRowsPerPage();
	int GetNonFixedColumnsPerPage();
	
	CRect GetFixedRowsArea();
	CRect GetFixedColsArea();
	int HitSplitter(const CPoint& point);

	bool MoveSelection(int horizontalShift, int verticalShift, bool redraw = true);
	bool GetFocusedItem(CAsTableRow** row, CAsBaseCell** cell, int& rowIndex, int& cellIndex);
	void SetCellFocus(bool redraw = true);
	void KillCellFocus(bool storeData);
	void EnsureVisible(int rowIndex, int cellIndex, bool redraw = true);

	vector<CAsTableRow*> rows_;

	COLORREF bkColor_;
	COLORREF borderColor_;
	int defaultRowHeight_;
	int defaultCellWidth_;

	int horizontalOffset_;
	int rowsNumber_;
	int fixedRowsNumber_;
	int columnsNumber_;
	int fixedColumnsNumber_;

	int firstNonFixedRowIndex_;
	int firstNonFixedColumnIndex_;

	int vScrollMinPos_;
	int vScrollMaxPos_;
	int vScrollPageSize_;

	int hScrollMinPos_;
	int hScrollMaxPos_;
	int hScrollPageSize_;

	vector<int> colWidth_;

	int selSplitterIndex_;
	bool draggingSplitter_;
	int splitterRowIndex_;
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(_ASTABLE_H_)
