aboutsummaryrefslogtreecommitdiff
path: root/xapp.h
blob: 7ba0e1a2e4e806609fdc3398c299dc8e68ecbce7 (plain) (blame)
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248

#ifndef XAPP_H
#define XAPP_H

class CFreeDoc;
class CFreeView;

/******************************************************************************
**  Painting utility functions
*/

#define ColorWindowBack (GetSysColorBrush(COLOR_APPWORKSPACE))
#define ColorText (GetSysColorBrush(COLOR_WINDOWTEXT))
#define ColorTextBack (GetSysColorBrush(COLOR_WINDOW))
#define ColorBright (GetSysColorBrush(COLOR_3DHIGHLIGHT))
#define ColorFlat (GetSysColorBrush(COLOR_3DFACE))
#define ColorDark (GetSysColorBrush(COLOR_3DSHADOW))
#define ColorBorder (GetSysColorBrush(COLOR_3DDKSHADOW))
#define ColorActive (GetSysColorBrush(COLOR_ACTIVECAPTION))
#define ColorInactive (GetSysColorBrush(COLOR_INACTIVECAPTION))
	
/*
**  DrawHLine
**    Draw a horizontal line in a given brush.
*/

inline static void DrawHLine(HDC dc, HBRUSH brush, int x, int y, int length)
{
	RECT rect;
	rect.top = y, rect.bottom = y + 1;
	rect.left = x, rect.right = x + length;
	FillRect(dc, &rect, brush);
}

/*
**  DrawVLine
**    Draw a vertical line in a given brush.
*/

inline static void DrawVLine(HDC dc, HBRUSH brush, int x, int y, int length)
{
	RECT rect;
	rect.top = y, rect.bottom = y + length;
	rect.left = x, rect.right = x + 1;
	FillRect(dc, &rect, brush);
}

/*
**  FillBox
**    Fill a rectangle in a given brush.
*/

inline static void FillBox(HDC dc, HBRUSH brush, int x, int y, int width, int height)
{
	RECT rect;
	rect.top = y, rect.bottom = y + height;
	rect.left = x, rect.right = x + width;
	FillRect(dc, &rect, brush);
}

/*
**  DrawBox
**    Draw a rectangle in a given brush.
*/

inline static void DrawBox(HDC dc, HBRUSH brush, int x, int y, int width, int height)
{
	RECT rect;
	rect.top = y, rect.bottom = y + height;
	rect.left = x, rect.right = x + width;
	FrameRect(dc, &rect, brush);
}

/*
**  DrawDualBox
**    Draw a two-color rectangle in a given pair of brushes.
*/

inline static void DrawDualBox(HDC dc, HBRUSH topleft, HBRUSH bottomright,
	int x, int y, int width, int height)
{
	RECT rect;

	rect.top = y, rect.bottom = y + 1;
	rect.left = x, rect.right = x + width;
	FillRect(dc, &rect, topleft);
	rect.top = y + height - 1, rect.bottom = y + height;
	FillRect(dc, &rect, bottomright);
	rect.top = y, rect.bottom = y + height;
	rect.left = x, rect.right = x + 1;
	FillRect(dc, &rect, topleft);
	rect.left = x + width - 1, rect.right = x + width;
	FillRect(dc, &rect, bottomright);
}

/*
**  FillDualBox
**    Draw a two-color rectangle in a given pair of brushes, and fill
**    in the area it encloses with a third color.
*/

inline static void FillDualBox(HDC dc, HBRUSH topleft, HBRUSH bottomright,
	HBRUSH fill, int x, int y, int width, int height)
{
	RECT rect;

	rect.top = y, rect.bottom = y + 1;
	rect.left = x, rect.right = x + width;
	FillRect(dc, &rect, topleft);
	rect.top = y + height - 1, rect.bottom = y + height;
	FillRect(dc, &rect, bottomright);
	rect.top = y, rect.bottom = y + height;
	rect.left = x, rect.right = x + 1;
	FillRect(dc, &rect, topleft);
	rect.left = x + width - 1, rect.right = x + width;
	FillRect(dc, &rect, bottomright);
	rect.top = y + 1, rect.bottom = y + width - 2;
	rect.left = x + 1, rect.right = x + width - 2;
	FillRect(dc, &rect, fill);
}

/*
**  Macros to build some common UI objects
*/

#define DrawRaisedBox(dc, x, y, width, height) \
	(DrawDualBox(dc, ColorBright, ColorDark, x, y, width, height))

#define DrawLoweredBox(dc, x, y, width, height) \
	(DrawDualBox(dc, ColorDark, ColorBright, x, y, width, height))

#define DrawEditBox(dc, x, y, width, height) \
	(DrawDualBox(dc, ColorDark, ColorBright, x, y, width, height), \
	 DrawDualBox(dc, ColorBorder, ColorFlat, (x)+1, (y)+1, (width)-2, (height)-2))

#define DrawWindowBorder(dc, x, y, width, height) \
	(DrawDualBox(dc, ColorFlat, ColorBorder, x, y, width, height), \
	 DrawDualBox(dc, ColorBright, ColorDark, (x)+1, (y)+1, (width)-2, (height)-2))

#define FillWindowBorder(dc, x, y, width, height) \
	(DrawDualBox(dc, ColorFlat, ColorBorder, x, y, width, height), \
	 FillDualBox(dc, ColorBright, ColorDark, ColorFlat, (x)+1, (y)+1, (width)-2, (height)-2))

#define DrawButtonUp(dc, x, y, width, height) \
	(DrawDualBox(dc, ColorBright, ColorBorder, x, y, width, height), \
	 DrawDualBox(dc, ColorFlat, ColorDark, (x)+1, (y)+1, (width)-2, (height)-2))

#define DrawButtonDown(dc, x, y, width, height) \
	(DrawDualBox(dc, ColorDark, ColorBorder, x, y, width, height), \
	 DrawBox(dc, ColorFlat, (x)+1, (y)+1, (width)-2, (height)-2))

#define FillRaisedBox(dc, x, y, width, height) \
	(FillDualBox(dc, ColorBright, ColorDark, ColorFlat, x, y, width, height))

#define FillLoweredBox(dc, x, y, width, height) \
	(FillDualBox(dc, ColorDark, ColorBright, ColorFlat, x, y, width, height))

#define FillButtonUp(dc, x, y, width, height) \
	(DrawDualBox(dc, ColorBright, ColorBorder, x, y, width, height), \
	 FillDualBox(dc, ColorFlat, ColorDark, ColorFlat, (x)+1, (y)+1, (width)-2, (height)-2))

#define FillButtonDown(dc, x, y, width, height) \
	(DrawDualBox(dc, ColorDark, ColorBorder, x, y, width, height), \
	 FillBox(dc, ColorFlat, (x)+1, (y)+1, (width)-2, (height)-2))


/******************************************************************************
**  The "liberated document" class
*/

class CFreeDoc {
public:
	CFreeDoc();
	virtual ~CFreeDoc();

	virtual BOOL Create(void);

	virtual const CString &GetTitle(void) const
		{ return(m_strTitle); }
	virtual void SetTitle(const CString &string);
	virtual const CString &GetPathName(void) const
		{ return(m_strPathName); }
	virtual void SetPathName(const CString &string);

	virtual BOOL IsModified(void) const;
	virtual void SetModifiedFlag(const BOOL modified = TRUE);

	virtual UINT GetViewCount(void) const;
	virtual void AddView(CFreeView *view);
	virtual void RemoveView(CFreeView *view);
	virtual POSITION GetFirstViewPosition(void) const;
	virtual CFreeView *GetNextView(POSITION &position) const;
	virtual void UpdateAllViews(void);
	virtual void UpdateView(CFreeView *view);

protected:
	virtual void OnChangedViewList(CFreeView *view, BOOL added);
	virtual BOOL OnCreate(void);
	virtual void OnDestroy(void);

protected:
	CString m_strTitle, m_strPathName;
	BOOL m_bModified, m_bCreated;
	CPtrList m_viewList;
};


/******************************************************************************
**  The "liberated document view" class
*/

#define AFX_FREEVIEW_ID 0xE888

class CFreeView : public CWnd {
	friend void CFreeDoc::AddView(CFreeView *view);
	friend void CFreeDoc::RemoveView(CFreeView *view);

protected:
	DECLARE_DYNCREATE(CFreeView)
	CFreeView();
	virtual ~CFreeView();

public:
	virtual BOOL Create(CWnd *wnd, BOOL show = 1);
	virtual void SetDocument(CFreeDoc *doc = NULL);
	virtual CFreeDoc *GetDocument(void);

	virtual void OnUpdate(CFreeDoc *doc);

	//{{AFX_VIRTUAL(CFreeView)
	protected:
	virtual void OnDraw(CDC* pDC);
	//}}AFX_VIRTUAL

protected:
	//{{AFX_MSG(CFreeView)
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnPaint();
	//}}AFX_MSG

protected:
	DECLARE_MESSAGE_MAP()

	int m_width, m_height;		// Width and height of view
	CFreeDoc *m_document;		// Document
};

#endif