summaryrefslogtreecommitdiff
path: root/win/terrctrl.h
blob: ee6f16f1f6e6050efc2706beb6e48d6030b885d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#if !defined(AFX_TERRCTRL_H__15B2D2A1_D2FF_11D2_8204_EEB0809D9016__INCLUDED_)
#define AFX_TERRCTRL_H__15B2D2A1_D2FF_11D2_8204_EEB0809D9016__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// TerrCtrl.h : header file
//

#include <afxtempl.h>

#define TERRAINCTRL_CLASSNAME _T("TerrainCtrl")

typedef struct {
	UINT state; // Cell state (selected/focus etc)
//	float height;
} GRIDCELL; 

typedef struct CELLID {
	int row, col;
    CELLID(int nRow = -1, int nCol = -1)
		: row(nRow), col(nCol) {}
	BOOL operator==(const CELLID rhs)
		{ return (row == rhs.row && col == rhs.col); }
	BOOL operator!=(const CELLID rhs)
		{ return (row != rhs.row || col != rhs.col); }
} CELLID;


// Cell states
#define GS_FOCUSED			0x0001
#define GS_SELECTED			0x0002
#define GS_DROPHILITED		0x0004
#define GS_READONLY			0x0008

// storage typedef for each row in the grid
typedef CArray<GRIDCELL, GRIDCELL> GRID_ROW;

/////////////////////////////////////////////////////////////////////////////
// CTerrainCtrl window

class CTerrainCtrl : public CWnd
{
// Construction
public:
	CTerrainCtrl();
	BOOL Create(const RECT& rect, CWnd* pParentWnd, UINT nID, DWORD dwStyle = WS_CHILD | WS_BORDER | WS_TABSTOP | WS_VISIBLE);
	BOOL SubclassWindow(HWND hWnd);

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CTerrainCtrl)
	protected:
	virtual void PreSubclassWindow();
	//}}AFX_VIRTUAL

// Implementation
public:
	void SetControlPoints(int uCount, int vCount, float** pControl);
	virtual ~CTerrainCtrl();

	// Generated message map functions
protected:
	void EditCell(int nRow, int nCol, UINT nChar);
	BOOL GetCellRect(int nRow, int nCol, LPRECT pRect);
	BOOL GetCellRect(CELLID cell, LPRECT pRect);
	BOOL GetCellOrigin(int nRow, int nCol, LPPOINT p);
	BOOL GetCellOrigin(CELLID cell, LPPOINT p);
	BOOL RedrawCell(int nRow, int nCol, CDC* pDC = NULL);
	BOOL RedrawCell(CELLID cell, CDC* pDC = NULL);
	BOOL IsValid(CELLID cell);
	BOOL IsValid(int nRow, int nCol);
	BOOL IsCellVisible(CELLID cell);
	BOOL IsCellVisible(int nRow, int nCol);
	void EnsureVisible(CELLID cell);
	void EnsureVisible(int nRow, int nCol);
	void SetFocusCell(CELLID cell);
	void SetFocusCell(int nRow, int nCol);
	BOOL SetRowCount(int nRows);
	BOOL SetColumnCount(int nCols);

	CELLID GetCellFromPt(CPoint point, BOOL bAllowFixedCellCheck = TRUE);
	CELLID GetTopleftNonFixedCell();
	BOOL RegisterWindowClass();

	void OnDraw(CDC* pDC);
	void EraseBkgnd(CDC* pDC);
	BOOL DrawCell(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBk = FALSE);
	BOOL DrawFixedCell(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBk = FALSE);

	void ResetScrollBars();
	int  GetScrollPos32(int nBar, BOOL bGetTrackPos = FALSE);
	BOOL SetScrollPos32(int nBar, int nPos, BOOL bRedraw = TRUE);

	CFont m_Font;

	COLORREF m_crFixedBkColour;
	COLORREF m_crFixedTextColour;
	COLORREF m_crTextBkColour;

//	m_crTextColour, m_crGridColour;

	int m_nRows;
	int m_nCols;
	int m_nVScrollMax;
	int m_nHScrollMax;

	float** m_pControl;

	int m_MouseMode;

	CELLID m_idCurrentCell;
	CELLID m_LeftClickDownCell;
	CPoint m_LeftClickDownPoint;
	
	// Cell data
	CArray<GRID_ROW, GRID_ROW> m_RowData;

	//{{AFX_MSG(CTerrainCtrl)
	afx_msg void OnPaint();
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg UINT OnGetDlgCode();
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	//}}AFX_MSG
	afx_msg LRESULT OnGetFont(WPARAM hFont, LPARAM lParam);
	afx_msg LRESULT OnEditClosed(WPARAM hFont, LPARAM lParam);

	DECLARE_MESSAGE_MAP()

	enum eMouseModes { MOUSE_NOTHING, MOUSE_SELECT_ALL, MOUSE_SELECT_COL, MOUSE_SELECT_ROW,
					   MOUSE_SELECT_CELLS, MOUSE_SCROLLING_CELLS,
					   MOUSE_PREPARE_EDIT, MOUSE_PREPARE_DRAG, MOUSE_DRAGGING };
};

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

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_TERRCTRL_H__15B2D2A1_D2FF_11D2_8204_EEB0809D9016__INCLUDED_)